From patchwork Tue Nov 13 14:44:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10680857 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 E7EE41759 for ; Tue, 13 Nov 2018 14:44:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D564628E66 for ; Tue, 13 Nov 2018 14:44:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C89872950F; Tue, 13 Nov 2018 14:44:59 +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 C538F29208 for ; Tue, 13 Nov 2018 14:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387668AbeKNAnW (ORCPT ); Tue, 13 Nov 2018 19:43:22 -0500 Received: from mail-eopbgr710067.outbound.protection.outlook.com ([40.107.71.67]:29081 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731422AbeKNAnV (ORCPT ); Tue, 13 Nov 2018 19:43:21 -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=kneskWxN0Yt2lnWAx3xwREKg/LKOmAFZ8jsUhcXlp2c=; b=UC3Jg6KCgKcV8nr3nE+RxsrFa47RsmF1Sc+BEb0OxDOLd4Px2VgUt/CN1VZTg0Nk0Rja1y1sEMEkP4vhDtNl10HNAit0wxOJ2++QUjSCYXz9u0IiwPF2r9XR3ex0sLBpqr318zZTXqu41QyXUllecxc5EcH2zmbijXSGr0pOXPo= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1349.namprd07.prod.outlook.com (10.160.109.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Tue, 13 Nov 2018 14:44:52 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::c031:16d9:9580:3d11]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::c031:16d9:9580:3d11%6]) with mapi id 15.20.1294.045; Tue, 13 Nov 2018 14:44:52 +0000 From: Igor Russkikh To: "David S . Miller" CC: "linux-usb@vger.kernel.org" , "netdev@vger.kernel.org" , Dmitry Bezrukov , Igor Russkikh Subject: [PATCH v2 net-next 09/21] net: usb: aqc111: Implement RX data path Thread-Topic: [PATCH v2 net-next 09/21] net: usb: aqc111: Implement RX data path Thread-Index: AQHUe19vPzIclL/zQE2kKspW/evXWg== Date: Tue, 13 Nov 2018 14:44:52 +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: AM5P189CA0013.EURP189.PROD.OUTLOOK.COM (2603:10a6:206:15::26) 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;BY1PR0701MB1349;6:XjoJ5sWkWbZpE9jYxQLT5+ai32Mq5EjW6xwRy3JYJ91eMxWsnnrzVL5V40ZztR4H6IR67DQ1j5T+kftPJGSeqqB7xiyjPR3qEsgxJATXXN2/6fyw/22xqsFqNPOPsVwgXm1lM7fQGaeqTainFueZtzOjX0s2f9JpC/EE77swtSjGSz2yUOydbce2+sxS5YLTpDC/kRBdV0l06sj/50yuK565j6ceIqBMt6rRukN/RJgZ4LhYcT02sSDvpefX4yF8yX98E5+NiVseDweOiKn8bsdl6LRLIVhoC3mFPVwmGlpqI+gv+wwlm2xPAZuVVR7iqz56odyFu8DEI38ymWA0OlBbLOKDO4x2mg1du74eRXTiU9U5TVsW03xJtWANbm1vD6YZMxFXf+kl/5wJiy+F8qVz+LVns/OOiVRxIt37kc2KnVeR7j/8dSnNJmQpq4M+s4cMI1s/IvHJJWJn0NENZg==;5:a4ofSor5a5nqEvA80H7wJPgK6wkuNptP9rsXfB7oAj+OkWnGeOdE36ILf3XZ8cXSHTME6a084/QT/WqPWLz3WlQoVyDD8Kg5hPDr8aP64am48E6WHRvA+s3AoL2A4IgoarbR/fEjLueaTHh6SRIQ2DlWXDtY+dvMdauuv634I84=;7:UBar6Ud4vl/g6jMDrIOfzAp8TL5D9T/TG6cJA/GHkMdBrxSLap5J3GKu/RbXW0G0viCv7J2n0p0bQ+sJNvILxSQx2AEwWMWsBLfdisk0c8PfBF9zAUQZIChqZQBk8xowAAOHaKjKgbRGARQyK/10Mw== x-ms-office365-filtering-correlation-id: 86da0ed0-ad27-4683-ae3f-08d649769193 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390060)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1349; x-ms-traffictypediagnostic: BY1PR0701MB1349: 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)(10201501046)(3002001)(3231382)(944501410)(52105112)(93006095)(93001095)(148016)(149066)(150057)(6041310)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1349;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1349; x-forefront-prvs: 085551F5A8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39850400004)(376002)(346002)(396003)(366004)(136003)(199004)(189003)(5660300001)(478600001)(54906003)(71200400001)(14454004)(71190400001)(6436002)(105586002)(76176011)(52116002)(36756003)(4326008)(68736007)(99286004)(97736004)(81166006)(81156014)(8676002)(2906002)(86362001)(7736002)(316002)(575784001)(72206003)(305945005)(107886003)(2616005)(66066001)(6512007)(8936002)(2900100001)(256004)(25786009)(6916009)(14444005)(106356001)(11346002)(44832011)(3846002)(6116002)(6486002)(53936002)(486006)(186003)(118296001)(6506007)(386003)(446003)(476003)(102836004)(26005);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1349;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: UbAT3B7MLW5/+apHJsVOrLldcXLQyGSr0IJzXb54s5fdUh1swGt9JzC5aqS1j3eZjkR3w8qgRG9k+SSgh+s6py2lIbB+/A14Ow7+FVIsTbmXYqMu1NQdanrEWQhRYyo/G9Pw+8DxRmYODjZakPkiiG45TxxBXsQLBrw0QZNIg2WrUIJJ/doc4eZxY2jcKx/b2VXS2P4qGQ7EXzKgk7Y3F7TI29njIpqBvBrqXaLo3zMrAXRrWDlFuR8rOqDQJVvB/1IkJrrioJJbYbleF288aKK2haQ77pAKM1M9/pn4fb1XIxQHbH5KQA6RUaEohCDn0/lvUcVL5PZcgfz5k8m74E4bm/nhXDB8eOKt8D0h1cI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86da0ed0-ad27-4683-ae3f-08d649769193 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2018 14:44:52.1440 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1349 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 | 103 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 15 +++++++ 2 files changed, 118 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index b630a8342ef2..ae101b44a109 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -376,6 +376,9 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) ether_addr_copy(dev->net->dev_addr, dev->net->perm_addr); + /* Set Rx urb size */ + dev->rx_urb_size = URB_SIZE; + /* Set TX needed headroom & tailroom */ dev->net->needed_headroom += sizeof(u64); dev->net->needed_tailroom += sizeof(u64); @@ -617,6 +620,8 @@ static int aqc111_reset(struct usbnet *dev) u16 reg16 = 0; u8 reg8 = 0; + dev->rx_urb_size = URB_SIZE; + if (usb_device_no_sg_constraint(dev->udev)) dev->can_dma_sg = 1; @@ -699,6 +704,103 @@ static int aqc111_stop(struct usbnet *dev) return 0; } +static int aqc111_rx_fixup(struct usbnet *dev, struct sk_buff *skb) +{ + struct sk_buff *new_skb = NULL; + u32 pkt_total_offset = 0; + u32 start_of_descs = 0; + u64 *pkt_desc = NULL; + u32 desc_offset = 0; /*RX Header Offset*/ + u16 pkt_count = 0; + u64 desc_hdr = 0; + u32 skb_len = 0; + + if (!skb) + goto err; + + if (skb->len == 0) + goto err; + + skb_len = skb->len; + /* RX Descriptor Header */ + skb_trim(skb, skb->len - sizeof(desc_hdr)); + desc_hdr = *(u64 *)skb_tail_pointer(skb); + le64_to_cpus(&desc_hdr); + + /* Check these packets */ + desc_offset = (desc_hdr & AQ_RX_DH_DESC_OFFSET_MASK) >> + AQ_RX_DH_DESC_OFFSET_SHIFT; + pkt_count = desc_hdr & AQ_RX_DH_PKT_CNT_MASK; + start_of_descs = skb_len - ((pkt_count + 1) * sizeof(desc_hdr)); + + /* self check descs position */ + if (start_of_descs != desc_offset) + goto err; + + /* self check desc_offset from header*/ + if (desc_offset >= skb_len) + goto err; + + if (pkt_count == 0) + goto err; + + /* Get the first RX packet descriptor */ + pkt_desc = (u64 *)(skb->data + desc_offset); + + while (pkt_count--) { + u32 pkt_len = 0; + u32 pkt_len_with_padd = 0; + + le64_to_cpus(pkt_desc); + pkt_len = (u32)((*pkt_desc & AQ_RX_PD_LEN_MASK) >> + AQ_RX_PD_LEN_SHIFT); + pkt_len_with_padd = ((pkt_len + 7) & 0x7FFF8); + + pkt_total_offset += pkt_len_with_padd; + if (pkt_total_offset > desc_offset || + (pkt_count == 0 && pkt_total_offset != desc_offset)) { + goto err; + } + + if (*pkt_desc & AQ_RX_PD_DROP || + !(*pkt_desc & AQ_RX_PD_RX_OK) || + pkt_len > (dev->hard_mtu + AQ_RX_HW_PAD)) { + skb_pull(skb, pkt_len_with_padd); + /* Next RX Packet Descriptor */ + pkt_desc++; + continue; + } + + /* Clone SKB */ + new_skb = skb_clone(skb, GFP_ATOMIC); + + if (!new_skb) + goto err; + + new_skb->len = pkt_len; + skb_pull(new_skb, AQ_RX_HW_PAD); + skb_set_tail_pointer(new_skb, new_skb->len); + + new_skb->truesize = new_skb->len + sizeof(struct sk_buff); + + usbnet_skb_return(dev, new_skb); + if (pkt_count == 0) + break; + + skb_pull(skb, pkt_len_with_padd); + + /* Next RX Packet Header */ + pkt_desc++; + + new_skb = NULL; + } + + return 1; + +err: + return 0; +} + static struct sk_buff *aqc111_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) { @@ -758,6 +860,7 @@ static const struct driver_info aqc111_info = { .stop = aqc111_stop, .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET, + .rx_fixup = aqc111_rx_fixup, .tx_fixup = aqc111_tx_fixup, }; diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index a3d9d7dde240..aa0b37ebabae 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -10,6 +10,8 @@ #ifndef __LINUX_USBNET_AQC111_H #define __LINUX_USBNET_AQC111_H +#define URB_SIZE (1024 * 62) + #define AQ_ACCESS_MAC 0x01 #define AQ_FLASH_PARAMETERS 0x20 #define AQ_PHY_POWER 0x31 @@ -200,6 +202,19 @@ struct aqc111_data { #define AQ_TX_DESC_LEN_MASK 0x1FFFFF #define AQ_TX_DESC_DROP_PADD BIT(28) +#define AQ_RX_HW_PAD 0x02 + +/* RX Packet Descriptor */ +#define AQ_RX_PD_RX_OK BIT(11) +#define AQ_RX_PD_DROP BIT(31) +#define AQ_RX_PD_LEN_MASK 0x7FFF0000 +#define AQ_RX_PD_LEN_SHIFT 0x10 + +/* RX Descriptor header */ +#define AQ_RX_DH_PKT_CNT_MASK 0x1FFF +#define AQ_RX_DH_DESC_OFFSET_MASK 0xFFFFE000 +#define AQ_RX_DH_DESC_OFFSET_SHIFT 0x0D + static struct { unsigned char ctrl; unsigned char timer_l;