From patchwork Tue Nov 13 14:45:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10680873 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 BD4A714D6 for ; Tue, 13 Nov 2018 14:45:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABA221FF62 for ; Tue, 13 Nov 2018 14:45:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A009128E66; Tue, 13 Nov 2018 14:45:18 +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 1D9441FF62 for ; Tue, 13 Nov 2018 14:45:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387880AbeKNAnn (ORCPT ); Tue, 13 Nov 2018 19:43:43 -0500 Received: from mail-eopbgr710063.outbound.protection.outlook.com ([40.107.71.63]:18515 "EHLO NAM05-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387650AbeKNAnm (ORCPT ); Tue, 13 Nov 2018 19:43:42 -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=owFMuRjRVNfqtBfpO0SvvwhVKeQDrBlwo5e22mSwHis=; b=sVzPTZAJyQeKf83p/Y2Ry3reTmlIgT2WMddBCbeXak/RZJoB+K5Fhnj+yH1wGU9+RLk71XSEjH/e9wQkB3XRjU4crZRyk4pKmQRlwKBH8ANIbsSz7KilxqBgZDVedPTEmPIFWhJaGaasm5Brht1tlO+uDmPZ7bMYdkW7LbfWtPM= 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:45:14 +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:45:14 +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 18/21] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Topic: [PATCH v2 net-next 18/21] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Index: AQHUe198ogkAI2kxp0uwSLmZcNI3sQ== Date: Tue, 13 Nov 2018 14:45:13 +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:ZzKSpy0YHtar+hw9HzZrn3ZUA4hmFPveqB0OKUmGr4hhnwh7akxTSd/jR86D36CH1lf+ov8UFVxVpcouxHFNNGzYa0oqXKScjVi0hWGxT6887D7rbj9WpxjyreuQosaTK4bvJ3T/kv7+GSqeNqIa++pE043rEaX9x0BDeZYNpRRbA8XnG2W+Q0qlVW5iDrzzKn6ESSE/b8IicMMN5j4TjR6T2nUuy3K6MPGaL/+itayQ4CYFQOtY90Mu/hwVKmNl3tsbQ4AquETOwV+jaliTP3hPJR+WvISQDWQAxrt4j3YW6CmFv7DwHTfPoyw5dvUESoDGhZ75pFP1ixjda+Z0zsVdVMSlnAyH9YYjPFORFQDofhb5WQQ7xNvMNt+wVMC06uXJRft9lXEam1S+KjIpzV5/OnzjvJpOmcAgghwT4GDJ8JVW4VVGhPVNoqEErNjiP/VTKZmDQttftNmq26n/5w==;5:vdbTbv4IWxFnrz88AM9G6wA7tln0uSs6V1GskEPpcXJ7Dz+g5qTT803Kx9BnKZ98U/1bRjQ6xkSZoJnuKIVasrD/mC3DGON8XRISckqlm6E5HDr6dAojnKj4BftPaJS6Nj9yK9GOcE2KgKGNhEb1RM6ZK4BwJvKwcm8WObepG+g=;7:nVa+7/rMs61YqjHVksnhpvEm6XR1WYU+QxuxstEQLku3P7wfZoSGwhENa/L48JlquU+krGwo7lbrW9TjuuUNtzczx51DPRSlGP0ezs21xuESwnOS6DiC9fo8FW7c+pV4agdBfhHOVFKZBhfbd886HA== x-ms-office365-filtering-correlation-id: 5a0860e1-db63-4ea1-efe5-08d649769e88 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)(72206003)(305945005)(107886003)(2616005)(66066001)(6512007)(8936002)(2900100001)(256004)(25786009)(6916009)(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: wW0lD/dakLoLHRhuzu4AG30ID+u3jGXFZaCD8cU+h+FaZwbgmuOZJPBX1cZGSC5ssHE+CPBIv1oMLEifYt7gIU9a1LIGvMnIxBf49KCp/oIc6QifZzeMclrx+YNhx3bAlAFn23BuKeAsP76BWJtnvgvuorA3/nW+O5X4B/5CKnwHJkg8ZXlyKyI0leXYq1fuiRsoyaydUG+3OUzO8RqSrD4B66AuZSSsNWiik75quLez3Wr1XH0v69+TpVQPzeSNZKr4gfxJX4airp26o2BhlUji9d0Pb22V5tzILUa/v4kr9Gn2Yy+NRQMFf+/rQOw1IwiI6PhHlWkGCB/aZ6dcWqZJsR3YKIVsunwPNYj68ho= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a0860e1-db63-4ea1-efe5-08d649769e88 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Nov 2018 14:45:13.9090 (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 | 124 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index b3160b0320eb..80fedf2ab2dd 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -209,6 +209,85 @@ static void aqc111_get_drvinfo(struct net_device *net, info->regdump_len = 0x00; } +static void aqc111_speed_to_link_mode(u32 speed, + struct ethtool_link_ksettings *elk) +{ + switch (speed) { + case SPEED_5000: + ethtool_link_ksettings_add_link_mode(elk, advertising, + 5000baseT_Full); + break; + case SPEED_2500: + ethtool_link_ksettings_add_link_mode(elk, advertising, + 2500baseT_Full); + break; + case SPEED_1000: + ethtool_link_ksettings_add_link_mode(elk, advertising, + 1000baseT_Full); + break; + case SPEED_100: + ethtool_link_ksettings_add_link_mode(elk, advertising, + 100baseT_Full); + break; + } +} + +static int aqc111_get_link_ksettings(struct net_device *net, + struct ethtool_link_ksettings *elk) +{ + struct usbnet *dev = netdev_priv(net); + struct aqc111_data *aqc111_data = dev->driver_priv; + enum usb_device_speed usb_speed = dev->udev->speed; + u32 speed = SPEED_UNKNOWN; + + ethtool_link_ksettings_zero_link_mode(elk, supported); + ethtool_link_ksettings_add_link_mode(elk, supported, + 100baseT_Full); + ethtool_link_ksettings_add_link_mode(elk, supported, + 1000baseT_Full); + if (usb_speed == USB_SPEED_SUPER) { + ethtool_link_ksettings_add_link_mode(elk, supported, + 2500baseT_Full); + ethtool_link_ksettings_add_link_mode(elk, supported, + 5000baseT_Full); + } + ethtool_link_ksettings_add_link_mode(elk, supported, TP); + ethtool_link_ksettings_add_link_mode(elk, supported, Autoneg); + + elk->base.port = PORT_TP; + elk->base.transceiver = XCVR_INTERNAL; + + elk->base.mdio_support = 0x00; /*Not supported*/ + + if (aqc111_data->autoneg) + bitmap_copy(elk->link_modes.advertising, + elk->link_modes.supported, + __ETHTOOL_LINK_MODE_MASK_NBITS); + else + aqc111_speed_to_link_mode(aqc111_data->advertised_speed, elk); + + elk->base.autoneg = aqc111_data->autoneg; + + switch (aqc111_data->link_speed) { + case AQ_INT_SPEED_5G: + speed = SPEED_5000; + break; + case AQ_INT_SPEED_2_5G: + speed = SPEED_2500; + break; + case AQ_INT_SPEED_1G: + speed = SPEED_1000; + break; + case AQ_INT_SPEED_100M: + speed = SPEED_100; + break; + } + elk->base.duplex = DUPLEX_FULL; + elk->base.speed = speed; + + return 0; +} + static void aqc111_set_phy_speed_fw_iface(struct usbnet *dev, struct aqc111_data *aqc111_data) { @@ -325,11 +404,56 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed) aqc111_set_phy_speed_fw_iface(dev, aqc111_data); } +static int aqc111_set_link_ksettings(struct net_device *net, + const struct ethtool_link_ksettings *elk) +{ + struct usbnet *dev = netdev_priv(net); + struct aqc111_data *aqc111_data = dev->driver_priv; + enum usb_device_speed usb_speed = dev->udev->speed; + u8 autoneg = elk->base.autoneg; + u32 speed = elk->base.speed; + + if (autoneg == AUTONEG_ENABLE) { + if (aqc111_data->autoneg != AUTONEG_ENABLE) { + aqc111_data->autoneg = AUTONEG_ENABLE; + aqc111_data->advertised_speed = + (usb_speed == USB_SPEED_SUPER) ? + SPEED_5000 : SPEED_1000; + aqc111_set_phy_speed(dev, aqc111_data->autoneg, + aqc111_data->advertised_speed); + } + } else { + if (speed != SPEED_100 && + speed != SPEED_1000 && + speed != SPEED_2500 && + speed != SPEED_5000 && + speed != SPEED_UNKNOWN) + return -EINVAL; + + if (elk->base.duplex != DUPLEX_FULL) + return -EINVAL; + + if (usb_speed != USB_SPEED_SUPER && speed > SPEED_1000) + return -EINVAL; + + aqc111_data->autoneg = AUTONEG_DISABLE; + if (speed != SPEED_UNKNOWN) + aqc111_data->advertised_speed = speed; + + aqc111_set_phy_speed(dev, aqc111_data->autoneg, + aqc111_data->advertised_speed); + } + + return 0; +} + static const struct ethtool_ops aqc111_ethtool_ops = { .get_drvinfo = aqc111_get_drvinfo, .get_msglevel = usbnet_get_msglevel, .set_msglevel = usbnet_set_msglevel, .get_link = ethtool_op_get_link, + .get_link_ksettings = aqc111_get_link_ksettings, + .set_link_ksettings = aqc111_set_link_ksettings }; static int aqc111_change_mtu(struct net_device *net, int new_mtu)