From patchwork Mon Nov 26 09:33:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10697883 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 5B8FC15A8 for ; Mon, 26 Nov 2018 09:33:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B73729818 for ; Mon, 26 Nov 2018 09:33:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FC362981D; Mon, 26 Nov 2018 09:33:28 +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 B749329818 for ; Mon, 26 Nov 2018 09:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726428AbeKZU04 (ORCPT ); Mon, 26 Nov 2018 15:26:56 -0500 Received: from mail-eopbgr710046.outbound.protection.outlook.com ([40.107.71.46]:19443 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726282AbeKZU0z (ORCPT ); Mon, 26 Nov 2018 15:26:55 -0500 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=iVRyBJTMtBfFzUSSpO5Xsrchp2mbzXmdSULtt+Mmqw0=; b=OjUlCYYXNKF4dl56/ltsxkoxrZDhfLQqeHgMPR5Qm1+20VqdzRGDh27jP/T/YQVIj+zvYyMs8/k0vKaUyzyp0UFZTVOV4QkKoNfSgNmXwHdxDj4CjNSlRJL4DzZvGftq/NlfUn7QNjdG6dS9kK2RnAHOrQ+3UXuGbVBS9Y+NNEk= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1894.namprd07.prod.outlook.com (10.162.143.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1361.18; Mon, 26 Nov 2018 09:33:21 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::f8ee:2260:e410:fffd]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::f8ee:2260:e410:fffd%3]) with mapi id 15.20.1361.019; Mon, 26 Nov 2018 09:33:21 +0000 From: Igor Russkikh To: "linux-usb@vger.kernel.org" , "davem@davemloft.net" , "netdev@vger.kernel.org" CC: "andrew@lunn.ch" , Dmitry Bezrukov , Igor Russkikh Subject: [PATCH v4 net-next 10/21] net: usb: aqc111: Add checksum offload support Thread-Topic: [PATCH v4 net-next 10/21] net: usb: aqc111: Add checksum offload support Thread-Index: AQHUhWsSzsDmSCrF4kOoOW2PaQpN1A== Date: Mon, 26 Nov 2018 09:33:21 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR03CA0024.eurprd03.prod.outlook.com (2603:10a6:20b::37) 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;BY1PR0701MB1894;6:/l931l2mbR4dOkKkkbnQcXisSLWIoxIR/vWDjSkvnP4SeGnVWr0X0m+xkh6QZWahJP6tiN+/GFETXyI6n0a2IcnhHcUA/2deo2mgSoQ/oWpHSoYlEVt4lr+tsXAM88V255nEw59BB3TIfCKqjR36sMXPSJ8xcp14cwfeAeaYwbiDzJwta+D58LDIBl4IwIZLXbdGvLFxqCp9GlzyIkEHQsWNP8p97thVvoByxMBBH5bVhd2l5+BAW8g0FkqUgjDuanZkzFuyRLe2zVcJavoi/rpMEdj4Z9lZABrMJitKjYkU9FWOUEe5KgBMdjwC6QFUfSbd5QLSuM/ZqJ4H4bXHSnAh7rZdUZSjtEmBFzRozBXW6K4sJQCYq0FndNpiRC8E4pLmWczjnOmW7Ck1Lhg2L55Ot1XS1oBkaxBp31WC645hGAZ8Eg92w+Urk4cUDWoqpDumPjrOqUH3TnJPEi1ydQ==;5:pWY4WKvhUrcE3ykVpqN2gLRQJw7bXf53qS3onocYXSCz42rfQiP+BJvfZG9BWVD7WyItSvGa/82/lPITd4+hkzDJ22g/Q1eEMF/HhIx/rgcLAr94KgZjk/KF/ByHowL8p0zWW/UiSIEGXbW26bcuL/T4JGwE728HeAwIwtlXQJY=;7:KyxO48RxuRUwjh6WKGk+Vp9OFUaXweQW7wJ549nyN5DGFj8Bwwa5O2yA6xxNp6X423+HpwcAX3b1jNaoZjPCHKjaAZ679GdxQ4yxRfVkNxatW1zgyhj49Y0/FTDSMbh4e19bDvkMDITkFLM8ghlCew== x-ms-office365-filtering-correlation-id: b31b6adc-88dc-4037-3322-08d653823485 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1894; x-ms-traffictypediagnostic: BY1PR0701MB1894: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(3231443)(944501410)(52105112)(10201501046)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1894;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1894; x-forefront-prvs: 086831DFB4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39840400004)(376002)(396003)(136003)(366004)(346002)(199004)(189003)(14454004)(102836004)(97736004)(71200400001)(71190400001)(54906003)(6436002)(72206003)(105586002)(110136005)(11346002)(446003)(186003)(486006)(25786009)(2906002)(7736002)(575784001)(86362001)(5660300001)(316002)(305945005)(2201001)(2501003)(53936002)(99286004)(36756003)(52116002)(6506007)(6116002)(76176011)(386003)(4326008)(3846002)(68736007)(6512007)(107886003)(476003)(81166006)(478600001)(118296001)(26005)(106356001)(8676002)(256004)(81156014)(14444005)(2616005)(6486002)(66066001)(44832011)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1894;H:BY1PR0701MB1660.namprd07.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: aquantia.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: KSGjuyoYFpdyX76/+DTGhQPyhNFUEBYM6Gk5rucd/kaGbSmSTcD9VnzYuJ8Fl5xO98+T5C3dOR0gPowY5w9uJgfgnNgSzPARxUOThcRUUdNzqlsitXlx6G/AaMTqsdiS6GhGa4w/3FFswA0PjIVCZv1g9/xyLFwSAB7YfU8qZmyUo714iiWCR5MVBvQ6n5J4dSwdHbIMe9U2nNRzqAaITo+GLOgzwNPpsvJPM/30SHWfixbcCawCw4gXVecNTHWdagfFL7Ua2yh6mpAcioTyCkcwvYlx4OjCiN6jifNce6FhoCS4o7tL4H1csNBv3Z5zx7x5YmTF60HGOgqGcizeWOw3ihvE71JF77Bh91JxeE0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b31b6adc-88dc-4037-3322-08d653823485 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Nov 2018 09:33:21.6033 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1894 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 | 16 ++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 7a1976ecf294..1c8812e082bf 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -439,6 +439,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) { struct aqc111_data *aqc111_data = dev->driver_priv; @@ -482,6 +502,8 @@ static int aqc111_link_reset(struct usbnet *dev) aqc111_write16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, 2, ®16); + aqc111_configure_csum_offload(dev); + aqc111_read16_cmd(dev, AQ_ACCESS_MAC, SFR_MEDIUM_STATUS_MODE, 2, ®16); @@ -583,6 +605,21 @@ static int aqc111_stop(struct usbnet *dev) return 0; } +static void aqc111_rx_checksum(struct sk_buff *skb, u64 pkt_desc) +{ + u32 pkt_type = 0; + + skb->ip_summed = CHECKSUM_NONE; + /* checksum error bit is set */ + if (pkt_desc & AQ_RX_PD_L4_ERR || pkt_desc & AQ_RX_PD_L3_ERR) + return; + + pkt_type = pkt_desc & AQ_RX_PD_L4_TYPE_MASK; + /* It must be a TCP or UDP packet with a valid checksum */ + if (pkt_type == AQ_RX_PD_L4_TCP || pkt_type == AQ_RX_PD_L4_UDP) + skb->ip_summed = CHECKSUM_UNNECESSARY; +} + static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) { struct sk_buff *new_skb = NULL; @@ -660,6 +697,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 = SKB_TRUESIZE(new_skb->len); + 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 c5785f890022..ff43443bfd72 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -21,8 +21,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. ********************************************/ @@ -162,6 +165,15 @@ struct aqc111_data { #define AQ_RX_HW_PAD 0x02 /* RX Packet Descriptor */ +#define AQ_RX_PD_L4_ERR BIT(0) +#define AQ_RX_PD_L3_ERR BIT(1) +#define AQ_RX_PD_L4_TYPE_MASK 0x1C +#define AQ_RX_PD_L4_UDP 0x04 +#define AQ_RX_PD_L4_TCP 0x10 +#define AQ_RX_PD_L3_TYPE_MASK 0x60 +#define AQ_RX_PD_L3_IP 0x20 +#define AQ_RX_PD_L3_IP6 0x40 + #define AQ_RX_PD_RX_OK BIT(11) #define AQ_RX_PD_DROP BIT(31) #define AQ_RX_PD_LEN_MASK 0x7FFF0000