From patchwork Tue Nov 13 14:44:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10680881 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 CE63A1759 for ; Tue, 13 Nov 2018 14:45:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC7DD1FF62 for ; Tue, 13 Nov 2018 14:45:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0A3C28E66; Tue, 13 Nov 2018 14:45:31 +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 2E4141FF62 for ; Tue, 13 Nov 2018 14:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387489AbeKNAnw (ORCPT ); Tue, 13 Nov 2018 19:43:52 -0500 Received: from mail-eopbgr810040.outbound.protection.outlook.com ([40.107.81.40]:18907 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732577AbeKNAnu (ORCPT ); Tue, 13 Nov 2018 19:43:50 -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=2N8zTTNmPFyI3Nuu+3OFXZWTTLHUZEp1jWGR1ny4JUI=; b=N/C2xRWtCdkyAsArZTu7ztzF2Jmzx73+hnRJBaufrZKTh2ysoaiMijGeVDWGwmH/HKW2eKejqpweG0GuW7mzkzfmMd/RebANTLha1GiGbRakXKgfcl7W1IYz+BVukOAfMSPM6qmBRtQIdezjynrlms7SdDpEgYwlU0dWYMINc/c= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1208.namprd07.prod.outlook.com (10.160.105.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.36; Tue, 13 Nov 2018 14:44:49 +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:49 +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 08/21] net: usb: aqc111: Implement TX data path Thread-Topic: [PATCH v2 net-next 08/21] net: usb: aqc111: Implement TX data path Thread-Index: AQHUe19tZNQMEXYeyk6rOA8QyBCE1w== Date: Tue, 13 Nov 2018 14:44:49 +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;BY1PR0701MB1208;6:kueEuipsCkXFaNCKo77GoLJO4L+LREyNTzy3a41Xi7FYh07Huv+ouJzHnKdakP9/aWEB9VulzEi6qlMVKjho6JOvudQWj1wthrHndj1Ur+RkCYrYchxarXdu21iy+pNjJkoYU2Ey7lks7iOF0VozeWFaR05mvkIEOMPpc5saIE+rSVEcB4jta1TYmpcrdzVjeHSQfSG4gHtbY//Z8mGNdq4rqdeFXjophWoYJd38DnuFCx60AIN13QyKdOmts7RCmazsyQmsmT9JzPcSaLnmCRF2wJ71Bn1MTq1+cCxcUkeanGKFxFh17UsYR9jAH2HAiU6HSp2ngq4rQv8xM5Q0w3+B6ZCeSRQ1w/kxTUNxPScWjgcBDpnOxJEE/HVtmXERqfK4TK3OonijXzdQtxGxJ8tRkE9vUjYggEk27th9EMK+VhFBsB+9lCAs0QB7Gk7BElZjvNjpbmlbHmMul3xBWA==;5:hiVeXayN8WgkVFAregMHt8q5hFnC0mUsDXPm5iD1EeOU61jTWq0uAnuFjUHFEphFygJhEzzO3iuNU34SUI25hp37/CgTDtXoZ6G3vVIXLXeCsDLDApJYzTBP/qzY5NEbIU18WGdszIPs4U9WbkM/ajsfAm9Tuq8vqHzu/F2qb4Y=;7:l/0A+1t0yVnXVZVYahoupruO28erMnslc4BeC+Ryj0CT1XJ1pZXfc3SJjeYy498sKXxW142KGB0XrdOr+dQ6OSql7UQmLZNEA06H9TYwPiyFcSQp0Uuqv8cjIDMTEzRYOsd7c9/1xtQhtH9ZMFQ9xw== x-ms-office365-filtering-correlation-id: 59ce6afc-4429-4007-951e-08d64976902d x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390060)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1208; x-ms-traffictypediagnostic: BY1PR0701MB1208: 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)(3231406)(944501410)(52105112)(10201501046)(93006095)(93001095)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1208;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1208; x-forefront-prvs: 085551F5A8 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39850400004)(346002)(376002)(396003)(366004)(136003)(199004)(189003)(71190400001)(71200400001)(54906003)(72206003)(44832011)(305945005)(2906002)(66066001)(4326008)(118296001)(107886003)(105586002)(106356001)(36756003)(99286004)(52116002)(2900100001)(76176011)(476003)(14454004)(2616005)(6916009)(6506007)(186003)(575784001)(386003)(486006)(86362001)(8676002)(8936002)(102836004)(11346002)(446003)(5660300001)(6486002)(256004)(81156014)(14444005)(81166006)(53936002)(25786009)(68736007)(26005)(97736004)(316002)(7736002)(3846002)(478600001)(6116002)(6436002)(6512007);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1208;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: MGz+RwMLtlUIE4aTqfENjiIjwBV/9+Wf3punB1P6E2xb05jp/szUCwwgsL0xoLIdCogkc8WyJkj9qmi9hp57usff5rGTFo7a4eZhiBGedAyz4kykvBSNAoNgANzzzmIZ5cbk8GXHdvDgxOCAAksmnEzl8MHenwqsaBcxMTrleOuB86OHxwOhXZl7JkOPTJVWU0sEVDQP86LLlWkMHi/5Ln8tCBv4KXpfTKj4X64HXOUak4iTlLden/QnCNhW1TRBpsn8Q6UqXbI3pxzKCzgTi6uDhS2C3WQBdYtT5UxqWfQRlZCz6CeL4GlEV+QRMseNBftoJkH4m17ScDqvRpZMj8yfwYy+iGJ6fyR/yaYpn3Q= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59ce6afc-4429-4007-951e-08d64976902d X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2018 14:44:49.7722 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1208 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 15b86dee7bca..b630a8342ef2 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -302,6 +302,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, }; @@ -372,8 +375,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) ? @@ -603,6 +617,12 @@ static int aqc111_reset(struct usbnet *dev) u16 reg16 = 0; 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; if (aqc111_data->dpa) { @@ -679,6 +699,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, @@ -687,6 +756,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 a6359ff759cd..a3d9d7dde240 100644 --- a/drivers/net/usb/aqc111.h +++ b/drivers/net/usb/aqc111.h @@ -60,6 +60,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 @@ -192,6 +196,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;