From patchwork Sun Oct 16 11:36:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yen ChunChao X-Patchwork-Id: 616014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CEC6C4332F for ; Sun, 16 Oct 2022 11:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbiJPLgv (ORCPT ); Sun, 16 Oct 2022 07:36:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229594AbiJPLgu (ORCPT ); Sun, 16 Oct 2022 07:36:50 -0400 Received: from AUS01-ME3-obe.outbound.protection.outlook.com (mail-me3aus01olkn2157.outbound.protection.outlook.com [40.92.63.157]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE36939BA1 for ; Sun, 16 Oct 2022 04:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qxza6E6fVICpJ/JyINI6BLCxrbw5gDC2m7LCBjshKgLWiZ6H5uOXO4M/UGQy8urvm2Rc9rZq0E1GWB781XDVYIKZZkg+CYhwL6T6o0EMIBnHG4wwMq9OMEh0K8uF+7N4plDUd7LQHdn154BMt/jZWrenrGP1plnfvMCPIUARotJ9NoCfKyoxf3RDbHUmAeX+MXfmZzgH56FKQO0nEUmtEaK0s8tMG49GG/XTmIg+giL1jxW0rC2qKBLrNWzv0pd1cCPvGijrQA/ta0O/R27FksGdN2EivvWEkj7sVI/VPDjBjYiWEHLtgGJrsWY6CZ4MVME9/Kio3boEVkwIaYXWsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Omn5NIDMedQ0BB3et8V13wjnLYUbDdDCUMCMQjAYpKk=; b=FSOPLUckVCEVidKJuMCAKNyftT8WQ7GTLODUHKH/yxqBKy+LKv0HVPqin/YvYtekp4SdsX8cYjWrw5c6XGIU9AYgKH/HMbPC01E/rI4W0n9ktBF8ZHYdlcGegswJ4Ye4/r3EqL0hLoMAlSYeNK2rMmotpd/064tHUpN0BgOQqYmsAzqxDKW6dOqW+jEjvNLrbGiR6J6hU1MJPXLzhbL5DuMFxGifyqoBCLdTG0kMT0jcMec894CHwjWarWmh5xkNiZtb3nvTlY7jiPWBJvry/miWjKIlJ8Ar/dhVJ5cTKPP/gMo/T7EcaVl3MywNkEwmJd1IKuZQV+IgU5QFp2aMiw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Omn5NIDMedQ0BB3et8V13wjnLYUbDdDCUMCMQjAYpKk=; b=AHbfMjTNM5Ov6E3XSD5n/2DFiKA2nxZ+1u26Bay2RZ7dslD9X/2xLsDLAq/1ld6jrm02dSS6lBwhdMGC5DCNra6WxyhNiIbAkhy/W0uBlcXAQhcx/W2WOCIXuvAQjmrU5dubni8womK9rLW5n8uRbku+mKZv3NllfQpcYPV3xNHgwwbFm4Xu4wpHpl1sOR63cV5vFU0cq5jcDDku7OHfPjzfJVOake6V/lSR4jhAb7JP14igtkqRCJnuUaGtrp6fKZXMeKDbFZe7+9ET8VXlC/49CFM2NG1D4uZrKX3G+jfEgcvc5qSGoGru8+3phF7psML9jdMShK5eBvH+1+j8zA== Received: from ME3P282MB2827.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:13c::13) by SY4P282MB2790.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:159::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.29; Sun, 16 Oct 2022 11:36:40 +0000 Received: from ME3P282MB2827.AUSP282.PROD.OUTLOOK.COM ([fe80::d403:bdaa:515:ae06]) by ME3P282MB2827.AUSP282.PROD.OUTLOOK.COM ([fe80::d403:bdaa:515:ae06%8]) with mapi id 15.20.5723.032; Sun, 16 Oct 2022 11:36:40 +0000 From: Chun-Chao Yen To: pabeni@redhat.com Cc: davem@davemloft.net, linux-usb@vger.kernel.org Subject: [PATCH 2/3 (RESENT)] net: usb: ax88179_178a: Enable AX_RX_CTL_IPE only when NET_IP_ALIGN != 0 Date: Sun, 16 Oct 2022 19:36:26 +0800 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221016113628.4176189-1-nothingstopsme@hotmail.com> References: <20221016113628.4176189-1-nothingstopsme@hotmail.com> X-TMN: [okkWM+/gY+KAe8EqFBR5usze8SbaXojo] X-ClientProxiedBy: TYCP286CA0120.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:29c::20) To ME3P282MB2827.AUSP282.PROD.OUTLOOK.COM (2603:10c6:220:13c::13) X-Microsoft-Original-Message-ID: <20221016113628.4176189-2-nothingstopsme@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: ME3P282MB2827:EE_|SY4P282MB2790:EE_ X-MS-Office365-Filtering-Correlation-Id: 12602520-2533-42d8-f104-08daaf6ab144 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U8X8TT00YMo4QnuWfSOpm3+yQjItVjMlEgxvDq+1WSXQPnCTHsq3n/yOW4jIdPWmkYTiHV+60O3R9GuPnuiFOWr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elU+za2PCJP7QmPuyv6dghgcWaYxWPM3B+65QiSl33jYd+A5GG4Qi5hqzGoXCJtDaNdFBl4nSDUSolmvIvE/C/sGfxnu6ZAKYvWWjA39E0lzx4jDiiJKBb/hYki7bUWv8Dt2I9Gg6eTjXf4bxEeUP7/R3JRr8Bk+6dbiQeSPMVMPSuYBDHNI08pN5pxnp/GQfVUWWh1O4F6F34+Z6hVyvYsCOUxtxyXv3bhVbZek8DwWz+umrRlqOOi0thMUaUag0kSPg0wfoCWJF5WMTO3v+UXmlhgZifNAua2hcMcHSRKnqiH+EfCr1uawEaDEfAVa/PZRCDdmxfkzHXUiD51mqGvTXocavF84s0js+Q5papzE5a/ci96Z+rWemZKO4trky7k1ACDtIqYexTKYLlbwn59eNNHPEMDmKQ6vG+9DZk4JImjr7PvbOXyYjGagxSfyGOQl8/nrrGW2acJp9uX68AJlRNyYK6a67IVflolJSD2gezjeB56775Z/piBT5mfoUh8yGLuikhdqzEyQk5+SIsbgaKULN9lUOktJPW9oG3joxfFN5YVKU4voDxrx8v4nTAf1jahc7fxaGRmW3Fwd+qi1JfVGwtVnxscWSTG4lNveh+GnbuUb/wilhVnuNl1NKqhzW4dRPtfw6wdZpUbL7DNneAc98F2WcbZci6BSID353Lh2p4HqGRad0yqCofwY/LZuRnL+uShLagA5+D2P2Sy4BK/BjMsNICYCHiU6QAOLoA1sD8NixQtCU4YJndCedhGqArtOQNwMD6A+J3Y7UfncJyiLgxx+pQKtS6Z2Kb6XbNlNC8Tw1qew== X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-746f3.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 12602520-2533-42d8-f104-08daaf6ab144 X-MS-Exchange-CrossTenant-AuthSource: ME3P282MB2827.AUSP282.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2022 11:36:40.4495 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY4P282MB2790 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Problem Description: According to the comments in the hardware vendor's outdated source code [1], AX_RX_CTL_IPE signals the hardware to do 32-bit(4-byte) IP header alignment; such alignment is equivalent to the concept of NET_IP_ALIGN = 2 (an extra 2-byte "pesudo header" at the beginning of each etherner frame), as described in skbuff.h. In the current implementation, however, AX_RX_CTL_IPE is always enabled regardless of the value of NET_IP_ALIGN; this can introduce waste in many aspects, such as 1. hardware internal resource 2. USB bandwidth 3. host memory 4. cpu cycles (for updating frame start pointers and frame size variables) when alignment is completely unnecessary, i.e. NET_IP_ALIGN = 0. Solution: Enable AX_RX_CTL_IPE and process pesudo headers only when NET_IP_ALIGN != 0. Verification: Only tested on a platform where NET_IP_ALIGN = 0, with this device: 0b95:1790 ASIX Electronics Corp. AX88179 Gigabit Ethernet References: [1] https://www.asix.com.tw/en/support/download/file/120 (AX88179 USB3.0 to 10/100/1000M Gigabit Ethernet Controller, version 1.20.0) Signed-off-by: Chun-Chao Yen --- drivers/net/usb/ax88179_178a.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index b50748b3776c..96ede3a131d4 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -858,7 +858,10 @@ static void ax88179_set_multicast(struct net_device *net) struct ax88179_data *data = dev->driver_priv; u8 *m_filter = ((u8 *)dev->data); - data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); + data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB); + + if (NET_IP_ALIGN) + data->rxctl |= AX_RX_CTL_IPE; if (net->flags & IFF_PROMISC) { data->rxctl |= AX_RX_CTL_PRO; @@ -1424,7 +1427,7 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) /* Check CRC or runt packet */ if ((*pkt_hdr & (AX_RXHDR_CRC_ERR | AX_RXHDR_DROP_ERR)) || - pkt_len < 2 + ETH_HLEN) { + pkt_len < (NET_IP_ALIGN ? 2 : 0) + ETH_HLEN) { dev->net->stats.rx_errors++; goto advance_data_ptr; } @@ -1438,8 +1441,13 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb) } skb_trim(ax_skb, pkt_len); - /* Skip IP alignment pseudo header */ - skb_pull(ax_skb, 2); + if (NET_IP_ALIGN) { + /* Skip the pseudo header, 2 bytes at the start of each + * ethernet frame, resulting from hardware 4-byte + * IP header alignment (triggered by AX_RX_CTL_IPE) + */ + skb_pull(ax_skb, 2); + } ax_skb->truesize = SKB_TRUESIZE(pkt_len); ax88179_rx_checksum(ax_skb, pkt_hdr); @@ -1609,8 +1617,10 @@ static int ax88179_reset(struct usbnet *dev) ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); /* Configure RX control register => start operation */ - *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | + *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; + if (NET_IP_ALIGN) + *tmp16 |= AX_RX_CTL_IPE; ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL |