From patchwork Fri Oct 5 10:25:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10627833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F35215A6 for ; Fri, 5 Oct 2018 10:25:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62E8E28FDE for ; Fri, 5 Oct 2018 10:25:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56CD728FE7; Fri, 5 Oct 2018 10:25:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3CFE28FD5 for ; Fri, 5 Oct 2018 10:25:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728301AbeJERXW (ORCPT ); Fri, 5 Oct 2018 13:23:22 -0400 Received: from mail-eopbgr720041.outbound.protection.outlook.com ([40.107.72.41]:60857 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727535AbeJERXW (ORCPT ); Fri, 5 Oct 2018 13:23:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=AQUANTIA1COM.onmicrosoft.com; s=selector1-aquantia-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ByB2WIlfkAONQzRzg2g+YZE5Bm82ImjoS1DeDls5Brk=; b=vsSKngAcFUYX6jfLSUFe6IVN/7D1b1AQP3TY4mFcKIfWo1aWte0r7v/pMCV4TIOHo0aAFcjf6kqXVwNidE58KAKup2tFJod1jpGsIwrrw3TSbwUtghbrje3OZF6P28D/wpU+4WK8cyl3WR9/aFmIlcyKtQyAo2liAk39L8TECuM= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1781.namprd07.prod.outlook.com (10.162.141.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.18; Fri, 5 Oct 2018 10:25:07 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17%2]) with mapi id 15.20.1207.021; Fri, 5 Oct 2018 10:25:07 +0000 From: Igor Russkikh To: "David S . Miller" CC: "linux-usb@vger.kernel.org" , "netdev@vger.kernel.org" , Igor Russkikh , Dmitry Bezrukov Subject: [PATCH net-next 10/19] net: usb: aqc111: Add checksum offload support Thread-Topic: [PATCH net-next 10/19] net: usb: aqc111: Add checksum offload support Thread-Index: AQHUXJWuUx/GcO0OH0WVD735gXlTEA== Date: Fri, 5 Oct 2018 10:25:05 +0000 Message-ID: <8252f068582078a8c56789d9cff72fc151c4723c.1538734658.git.igor.russkikh@aquantia.com> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5PR0602CA0024.eurprd06.prod.outlook.com (2603:10a6:203:a3::34) To BY1PR0701MB1660.namprd07.prod.outlook.com (2a01:111:e400:522a::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Igor.Russkikh@aquantia.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [95.79.108.179] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BY1PR0701MB1781;6:8ePKSOPCE5E8MlLmWzvg2N5UfJ6Q9z7EaRDxiimpC8X0WmPd0ilX015gWd9C+kHt0G4JFHJSF8PaPBmNDb575zC6JyA/u1PFk0r3K/cVSm9d3cQBXoXniePWCit5YtCtA5SQKT7L6YN3wFI0ldUZllLoDNYPjYcWK68C94FCc/YT8FjkIGS/iakA2SX4/u44r3kTzSp4SWISid1OVMJx1au3aiQc74Jc92E+ipvPqw1nd2sueoTRiK189kTiROkdF3PDsZsFcJt6/VqhPNqWAVBpkO4CjZanBF4IT58jSYE/7XchvGBpenxeRCRXVK3RplV4Xuuexl5g+vBpujrk0TvRx194syN3yvAL1eZgI6AE9z7E6tsnR6aPJHHRHw3ry+FQiprESdtlEaOaqxP9RMdH/dLwdFhXySbR4StgaMOfSGkWCS8cszTQ4iYYWx/7n0CWNXhbWXy3YD216Jk/dg==;5:TGgc1saMGOdUaUCMshxIRleLx04HrfG+rwswDlnyRClEeEZ69KPrcSpsTMTLivdcHPqWomGqMBd5Ri2+EsJhw3mzPVHQHBWDBje2twYklX/xvnVwwZlm53m/FZLHmn02C2FfK1MBt6nmJbiFzvZLg4cmjo9nNHfKLVIsh4V9d60=;7:TXQpcy+qP0FswOBNddsSrnRxZl2y13+n/fvyFhTsLwSJNhxCfT48CJxSOly3QS+aiOtm43+vA1Ii5RPoKhKrnZJ0uMBCK159RFN1kQTWctXXTQG2IkdeYKP/aJkzSbcR4rBRrtg1qttGepeEus7Cj5ndPk0j7m9y4QnhGMGQ1HOolGHDLT84hu1aVrpNFjrDv0fbzbxukbzbk7C0BStmv8IusaAa/PjUxjP8zzFUOUymv24JDG8eb/7MM4szimdO x-ms-office365-filtering-correlation-id: fe725c2e-fa4b-4034-ea4b-08d62aacd123 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1781; x-ms-traffictypediagnostic: BY1PR0701MB1781: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123562045)(201708071742011)(7699051);SRVR:BY1PR0701MB1781;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1781; x-forefront-prvs: 0816F1D86E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(376002)(136003)(366004)(39850400004)(346002)(189003)(199004)(305945005)(4326008)(7736002)(81166006)(81156014)(8676002)(97736004)(186003)(71200400001)(102836004)(6506007)(2906002)(386003)(76176011)(26005)(11346002)(107886003)(446003)(6512007)(2616005)(118296001)(476003)(5660300001)(6486002)(53936002)(68736007)(8936002)(5250100002)(44832011)(66066001)(105586002)(486006)(106356001)(25786009)(6916009)(6436002)(71190400001)(72206003)(478600001)(2900100001)(14454004)(575784001)(6116002)(3846002)(86362001)(316002)(36756003)(99286004)(256004)(52116002)(14444005)(54906003);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1781;H:BY1PR0701MB1660.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 6UkgwmcnDG4gCtEmOg7X9lbOjKWUUUcvA2O93AUM9MXmja3ffiu56b1tBrikgscT9lKTWXueyhxPgyTf3lKypaPajYGtAExaEQjKqxA1GsrwOMmrviaqpk2e/JchCqitkYQYSXTEQmoKdreMb20rxm39h+Jo91TpqlMPMb2kIw4gZCyxjElp3UFspzFFwR62U4fPczC1YD6VF5kQRB2YEsjkmMCTCLRIw2VryBOzP/ZflQs1MuUlEwUm+r0pB1AXQsSdsqber9Gn9sDo1cjUlBpVD3iENOYLoXPAJynBp7xRgAg8AaWwlSEX9wROvGn5GPWw5cx6WmSXxGYJILQQlgoix65rP8sSFpiNoFLGY7g= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe725c2e-fa4b-4034-ea4b-08d62aacd123 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2018 10:25:05.6662 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1781 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Dmitry Bezrukov Signed-off-by: Dmitry Bezrukov Signed-off-by: Igor Russkikh --- drivers/net/usb/aqc111.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 23 +++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index fc068e731335..5967f7adeab4 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -537,6 +537,26 @@ static void aqc111_configure_rx(struct usbnet *dev, netdev_info(dev->net, "Link Speed %d, USB %d", link_speed, usb_host); } +static void aqc111_configure_csum_offload(struct usbnet *dev) +{ + u8 reg8 = 0; + + if (dev->net->features & NETIF_F_RXCSUM) { + reg8 |= SFR_RXCOE_IP | SFR_RXCOE_TCP | SFR_RXCOE_UDP | + SFR_RXCOE_TCPV6 | SFR_RXCOE_UDPV6; + } + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_RXCOE_CTL, 1, 1, ®8); + + reg8 = 0; + if (dev->net->features & NETIF_F_IP_CSUM) + reg8 |= SFR_TXCOE_IP | SFR_TXCOE_TCP | SFR_TXCOE_UDP; + + if (dev->net->features & NETIF_F_IPV6_CSUM) + reg8 |= SFR_TXCOE_TCPV6 | SFR_TXCOE_UDPV6; + + aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_TXCOE_CTL, 1, 1, ®8); +} + static int aqc111_link_reset(struct usbnet *dev) { u8 reg8 = 0; @@ -580,6 +600,8 @@ static int aqc111_link_reset(struct usbnet *dev) aqc111_write_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); + aqc111_configure_csum_offload(dev); + aqc111_read_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, 2, 2, ®16); @@ -713,6 +735,21 @@ static int aqc111_stop(struct usbnet *dev) return 0; } +static void aqc111_rx_checksum(struct sk_buff *skb, void *pkt_hdr) +{ + struct aq_rx_packet_desc *hdr = (struct aq_rx_packet_desc *)pkt_hdr; + + skb->ip_summed = CHECKSUM_NONE; + /* checksum error bit is set */ + if (hdr->l4_err || hdr->l3_err) + return; + + /* It must be a TCP or UDP packet with a valid checksum */ + if (hdr->l4_pkt_type == AQ_RXHDR_L4_TYPE_TCP || + hdr->l4_pkt_type == AQ_RXHDR_L4_TYPE_UDP) + skb->ip_summed = CHECKSUM_UNNECESSARY; +} + static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) { struct sk_buff *new_skb = NULL; @@ -788,6 +825,7 @@ static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) skb_set_tail_pointer(new_skb, new_skb->len); new_skb->truesize = new_skb->len + sizeof(struct sk_buff); + aqc111_rx_checksum(new_skb, &pkt_desc); usbnet_skb_return(dev, new_skb); if (pkt_count == 0) diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index 679ca9f992f7..1632e78ebe9b 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -63,8 +63,11 @@ #define AQ_USB_SET_TIMEOUT 4000 /* Feature. ********************************************/ -#define AQ_SUPPORT_FEATURE (NETIF_F_SG) -#define AQ_SUPPORT_HW_FEATURE (NETIF_F_SG) +#define AQ_SUPPORT_FEATURE (NETIF_F_SG | NETIF_F_IP_CSUM |\ + NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM) + +#define AQ_SUPPORT_HW_FEATURE (NETIF_F_SG | NETIF_F_IP_CSUM |\ + NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM) /* SFR Reg. ********************************************/ @@ -230,6 +233,22 @@ struct aqc111_int_data { #define AQ_INT_SPEED_1G 0x11 #define AQ_INT_SPEED_100M 0x13 +#define AQ_RXHDR_L4_ERR BIT(8) +#define AQ_RXHDR_L3_ERR BIT(9) + +#define AQ_RXHDR_L4_TYPE_ICMP 0x02 +#define AQ_RXHDR_L4_TYPE_IGMP 0x03 +#define AQ_RXHDR_L4_TYPE_TCMPV6 0x05 + +#define AQ_RXHDR_L3_TYPE_IP 0x01 +#define AQ_RXHDR_L3_TYPE_IPV6 0x02 + +#define AQ_RXHDR_L4_TYPE_MASK 0x1c +#define AQ_RXHDR_L4_TYPE_UDP 0x04 +#define AQ_RXHDR_L4_TYPE_TCP 0x10 +#define AQ_RXHDR_L3CSUM_ERR 0x02 +#define AQ_RXHDR_L4CSUM_ERR 0x01 + #define AQ_RX_HW_PAD 0x02 struct aq_tx_packet_desc {