From patchwork Wed Nov 21 10:13:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10692273 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 A28D41869 for ; Wed, 21 Nov 2018 10:14:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90F682B8CA for ; Wed, 21 Nov 2018 10:14:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 857002B8DB; Wed, 21 Nov 2018 10:14:19 +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 E94E72B8CA for ; Wed, 21 Nov 2018 10:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729724AbeKUUsH (ORCPT ); Wed, 21 Nov 2018 15:48:07 -0500 Received: from mail-eopbgr790082.outbound.protection.outlook.com ([40.107.79.82]:39040 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729679AbeKUUsG (ORCPT ); Wed, 21 Nov 2018 15:48:06 -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=gWhly6hGiRAzI1l+RgTyFXumdOgjd5ctO3F2AnG8POI=; b=O3TKd+6lCmI+S6+MXajxCYFqprIu11Psa55AOw4uhjFCWcXhKAt2WUE7EpyzPRjPG7y6O7OFcslz+5Hm2w4FG6wCm4N1epJ7p5ff367jNrFfPnq+lzbk/8NW/dAmXlJ5MHKBHySEpniSbgoIIuO9Ax8sCKTjaiz8MNpveoPYm2M= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1159.namprd07.prod.outlook.com (10.160.105.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.36; Wed, 21 Nov 2018 10:13:37 +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.015; Wed, 21 Nov 2018 10:13:37 +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 v3 net-next 08/21] net: usb: aqc111: Implement TX data path Thread-Topic: [PATCH v3 net-next 08/21] net: usb: aqc111: Implement TX data path Thread-Index: AQHUgYLeqrzjcLeRu0CCkz598ydvWQ== Date: Wed, 21 Nov 2018 10:13:37 +0000 Message-ID: <8b6748790baa1b8034c9c46ecd438c1f392854c7.1542794577.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: AM6PR0402CA0007.eurprd04.prod.outlook.com (2603:10a6:209::20) 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;BY1PR0701MB1159;6:l4+SxDWsENoEQ4+Qkz//W7tCP6YLdt00EOSZL3m4jYYrlSR4y9KNsmolDlc8EQAjm3Cl2QaALDkV3B13jIqH9B6MKnEfA/Dv34bjgkA/vI6Hh3xuaZ/0glGvBY6XRaBmujm09dnN1WOH1nrvo1YKDkVfnUMwZ70RhbKEinCBdwsxXfoA2/dhRxFfgsfTjC8ylS+HMWcqfvT3Wl8bcd1teW1+RrVKsopEyeYVPbrwo/0c/TlJV2YxIsDHPK+Zajxs7y88NsDOLWTt8iGRFS/9nJnmkukChFlfRPs9abw581kDfMBjZ6CtzLmk+CLEB/d86IfT8mwg9MxYxWNszwJCYjLP/2ai728mXhodjIYJww3b5dny8vlCCKS1mL02IkSyszrr4n2tKI5b6uaV6lgQfHiMhne38WllG7mzfnYOsnunEuCbgmTA2oLIjqAbY0VARs9ppznlgM4acPWnnF5nkQ==;5:ygeXdLUyldEZgVGOejAwmNWdbwjfNwARkC+wMfLkXd1V2PFFi0hN+Ldocrxn70serTVp+FuX0/HeuklBo1ar+iALH3hr47vhFyoERB4UB++ee6YniVWGwKKmsavcoc+1m8jBBtoiRMJKWMIIZy16yllm8vy69+/9eIOJQPIyqhw=;7:KOTuzKfYsh1jC7Z38QsmT39W0oGfqy+WCfzcJpn0Ka2UfVXmUAhypBv+cUdENJSs/4WWvNbEqaIKpnvNphGR5TZbdQqjbRUM3K+FdjYeoa/KtPrS/0QoSU/5ckY7VRgfjMx4K/l3371GJz99zpwnBg== x-ms-office365-filtering-correlation-id: aad47637-976c-4ad2-36d5-08d64f9a0097 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1159; x-ms-traffictypediagnostic: BY1PR0701MB1159: 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)(8121501046)(5005006)(93006095)(93001095)(3231442)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1159;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1159; x-forefront-prvs: 08635C03D4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(346002)(39850400004)(396003)(376002)(366004)(136003)(189003)(199004)(186003)(386003)(446003)(44832011)(71200400001)(476003)(2616005)(66066001)(14444005)(256004)(6506007)(97736004)(71190400001)(81166006)(8936002)(102836004)(2900100001)(81156014)(118296001)(11346002)(68736007)(26005)(486006)(99286004)(52116002)(14454004)(305945005)(7736002)(2906002)(478600001)(6512007)(575784001)(86362001)(76176011)(5660300001)(3846002)(53936002)(6116002)(107886003)(106356001)(4326008)(105586002)(110136005)(316002)(25786009)(72206003)(36756003)(54906003)(8676002)(2201001)(2501003)(6436002)(6486002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1159;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: XbSboyTLU1DdlMmM3qCuoTuXu6bokbRXtKCU4c4q6MoQnZqWdkVLUmMxlLzKIWOHEPeBCqL58zD8hh5ACNYECgFsfak2PYfQSSI37KkteT8HhdKDu+9iYVJJWn3W2HZBuVF1tNrmcjWVos81gROys4drBAqK+28MxMpTWUnQ5j4oo5Cgs8g0oheGcEbY/Ykxb2xNC7E3hw9M7ibB/ssq4dTAvfYOybJKxXuNgpB+h9I+Ca5O4sAULRUzCCYXpShgieJRq+pL5pSespkOQFV2zUtutgni/eKsYDRdbppUsySkEbp629Zy7ARxQ/ENOzXKbKhyRGoR+EPuxDBnCusdoAtsE+oJeoyI8JeUK39GB6A= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: aad47637-976c-4ad2-36d5-08d64f9a0097 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2018 10:13:37.7034 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1159 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 | 72 ++++++++++++++++++++++++++++++++++++++++ drivers/net/usb/aqc111.h | 8 +++++ 2 files changed, 80 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index 390ed6cbc3fd..dc9f0996afaf 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -222,6 +222,9 @@ static int aqc111_set_mac_addr(struct net_device *net, void *p) static const struct net_device_ops aqc111_netdev_ops = { .ndo_open = usbnet_open, .ndo_stop = usbnet_stop, + .ndo_start_xmit = usbnet_start_xmit, + .ndo_tx_timeout = usbnet_tx_timeout, + .ndo_get_stats64 = usbnet_get_stats64, .ndo_set_mac_address = aqc111_set_mac_addr, .ndo_validate_addr = eth_validate_addr, }; @@ -290,8 +293,19 @@ static int aqc111_bind(struct usbnet *dev, struct usb_interface *intf) goto out; ether_addr_copy(dev->net->dev_addr, dev->net->perm_addr); + + /* Set TX needed headroom & tailroom */ + dev->net->needed_headroom += sizeof(u64); + dev->net->needed_tailroom += sizeof(u64); + dev->net->netdev_ops = &aqc111_netdev_ops; + if (usb_device_no_sg_constraint(dev->udev)) + dev->can_dma_sg = 1; + + dev->net->hw_features |= AQ_SUPPORT_HW_FEATURE; + dev->net->features |= AQ_SUPPORT_FEATURE; + aqc111_read_fw_version(dev, aqc111_data); aqc111_data->autoneg = AUTONEG_ENABLE; aqc111_data->advertised_speed = (usb_speed == USB_SPEED_SUPER) ? @@ -505,6 +519,12 @@ static int aqc111_reset(struct usbnet *dev) struct aqc111_data *aqc111_data = dev->driver_priv; u8 reg8 = 0; + if (usb_device_no_sg_constraint(dev->udev)) + dev->can_dma_sg = 1; + + dev->net->hw_features |= AQ_SUPPORT_HW_FEATURE; + dev->net->features |= AQ_SUPPORT_FEATURE; + /* Power up ethernet PHY */ aqc111_data->phy_cfg = AQ_PHY_POWER_EN; aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, @@ -558,6 +578,55 @@ static int aqc111_stop(struct usbnet *dev) return 0; } +static struct sk_buff *aqc111_tx_fixup(struct usbnet *dev, struct sk_buff *skb, + gfp_t flags) +{ + int frame_size = dev->maxpacket; + struct sk_buff *new_skb = NULL; + int padding_size = 0; + int headroom = 0; + int tailroom = 0; + u64 tx_desc = 0; + + /*Length of actual data*/ + tx_desc |= skb->len & AQ_TX_DESC_LEN_MASK; + + headroom = (skb->len + sizeof(tx_desc)) % 8; + if (headroom != 0) + padding_size = 8 - headroom; + + if (((skb->len + sizeof(tx_desc) + padding_size) % frame_size) == 0) { + padding_size += 8; + tx_desc |= AQ_TX_DESC_DROP_PADD; + } + + if (!dev->can_dma_sg && (dev->net->features & NETIF_F_SG) && + skb_linearize(skb)) + return NULL; + + headroom = skb_headroom(skb); + tailroom = skb_tailroom(skb); + + if (!(headroom >= sizeof(tx_desc) && tailroom >= padding_size)) { + new_skb = skb_copy_expand(skb, sizeof(tx_desc), + padding_size, flags); + dev_kfree_skb_any(skb); + skb = new_skb; + if (!skb) + return NULL; + } + if (padding_size != 0) + skb_put(skb, padding_size); + /* Copy TX header */ + skb_push(skb, sizeof(tx_desc)); + cpu_to_le64s(&tx_desc); + skb_copy_to_linear_data(skb, &tx_desc, sizeof(tx_desc)); + + usbnet_set_skb_tx_stats(skb, 1, 0); + + return skb; +} + static const struct driver_info aqc111_info = { .description = "Aquantia AQtion USB to 5GbE Controller", .bind = aqc111_bind, @@ -566,6 +635,9 @@ static const struct driver_info aqc111_info = { .link_reset = aqc111_link_reset, .reset = aqc111_reset, .stop = aqc111_stop, + .flags = FLAG_ETHER | FLAG_FRAMING_AX | + FLAG_AVOID_UNLINK_URBS | FLAG_MULTI_PACKET, + .tx_fixup = aqc111_tx_fixup, }; #define AQC111_USB_ETH_DEV(vid, pid, table) \ diff --git a/drivers/net/usb/aqc111.h b/drivers/net/usb/aqc111.h index 0c8e1ee29893..c09f188b9f3d 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -18,6 +18,10 @@ #define AQ_USB_PHY_SET_TIMEOUT 10000 #define AQ_USB_SET_TIMEOUT 4000 +/* Feature. ********************************************/ +#define AQ_SUPPORT_FEATURE (NETIF_F_SG) +#define AQ_SUPPORT_HW_FEATURE (NETIF_F_SG) + /* SFR Reg. ********************************************/ #define SFR_GENERAL_STATUS 0x03 @@ -149,6 +153,10 @@ struct aqc111_data { #define AQ_INT_SPEED_1G 0x0011 #define AQ_INT_SPEED_100M 0x0013 +/* TX Descriptor */ +#define AQ_TX_DESC_LEN_MASK 0x1FFFFF +#define AQ_TX_DESC_DROP_PADD BIT(28) + static struct { unsigned char ctrl; unsigned char timer_l;