From patchwork Fri Oct 5 10:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10627851 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 60065184E for ; Fri, 5 Oct 2018 10:25:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5153728FE7 for ; Fri, 5 Oct 2018 10:25:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45DCE28FFB; Fri, 5 Oct 2018 10:25:40 +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 B0E6B28FEF for ; Fri, 5 Oct 2018 10:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728539AbeJERXr (ORCPT ); Fri, 5 Oct 2018 13:23:47 -0400 Received: from mail-bl2nam02on0073.outbound.protection.outlook.com ([104.47.38.73]:10992 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728461AbeJERXq (ORCPT ); Fri, 5 Oct 2018 13:23:46 -0400 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=yKC/gN/hTOFd3KFEeae/atZG0+5lQEiVETK/n96IvOI=; b=KUFWUOmNNJjpkY9mSp2Lk5XSLJI6aBHRzNR8iUtAIZi0esBCMMwJptajnWUIItvue+MbLsuN+f2VBM+x5uPQutUo8ZpIHvkADaGBZNZwOwUAuSCyi6TgYgMDQR7I8AauxpMxtOSJAGT5ciFGYNwhUhaaGQ4QwcvNGl3VrxtHSVY= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1641.namprd07.prod.outlook.com (10.162.110.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.21; Fri, 5 Oct 2018 10:25:33 +0000 Received: from BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17]) by BY1PR0701MB1660.namprd07.prod.outlook.com ([fe80::346d:e756:e70e:17%2]) with mapi id 15.20.1207.021; Fri, 5 Oct 2018 10:25:33 +0000 From: Igor Russkikh To: "David S . Miller" CC: "linux-usb@vger.kernel.org" , "netdev@vger.kernel.org" , Igor Russkikh , Dmitry Bezrukov Subject: [PATCH net-next 18/19] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Topic: [PATCH net-next 18/19] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Index: AQHUXJW/tPPOgFg2pkurQiABXvTsIw== Date: Fri, 5 Oct 2018 10:25:33 +0000 Message-ID: <694b148fa9e79d42fe8a815821ae5b0bc12c4aea.1538734658.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: AM5PR0602CA0024.eurprd06.prod.outlook.com (2603:10a6:203:a3::34) 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;BY1PR0701MB1641;6:xJgMqQKPWJ5QenzR1HXP4Ms0FWQ1BTnr4pzFA+mN8AJTPrZS//RYgHCvg9rf5EQE+fmiAjRwYKZa3cbE55lfghQzyeKnEhrg+/9uQd2YxIPlbO5FkuPsqpgZ1rnmFEF/FZhrqTsatf/5k+FUOiHb5VYMxDcSvXKY91NprxyUm+CnEfjQYmRoZRojdnnA59mdAxkIUPX8oxLEmIiyVNbBbhaa0R/gepstkOdLmx0XGihTDXpJvNQomLLPU10pcygXwR0lsNge901d0Bdic8HEvRibtkwnowBfU5Dn8q4+haMswYI1l1TEVnRksLgxy2AsBJdV+k/BxXX434K4nSMKgnqxzKH2BIeJStspZhCZ4fDDj0mp8YLkdi25i6O6/4krjkYaPpoYaSNRNZqLRXf38Ov9ihmHszkDA+4qIHrj3lcodyR53O2ctr56jo6nGh/vU6UzHNutuwqtzzCseN6yVA==;5:M9f4W07zW5HSyGzx3xVs7Fn5QGrsVsI1zKDJS5OUr1lDbcLkG0B+8RGJpoFiF7I0eBzSa2x4/ErIx1Mzdyy/TlvgfmZ0M6bgfbvRRtJkWjJi3hGxUJm/vPVaR202RmNX8Mnjlp+MYgTAawR3Sb2+bRT5oXqZbIrqMLJ7YKVXPWA=;7:mhqhZNlrTxtsZJCAifBYG2looa0rJt+PueGyoa590eBMZIS/O0DjpwzLkNz4XASMLhUYHM2vBKKRRbAhkAe3cJzWthX+6pphw2Wmd4aBH58eoIV1frEChthI2QIks3gBqRuoZGF9PmbIGfFgP1WBg/jc25rK8clrqzoiT0B6GfstN/WaiEbCDvgA66tvbkBTT/tuDSmKtXY5Q2JrBLzcoupAI+B3/bW9rShx6/r0biFqVWF/+2p7y5wFp0843j97 x-ms-office365-filtering-correlation-id: 1af61a90-1180-431b-988d-08d62aace1c8 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1641; x-ms-traffictypediagnostic: BY1PR0701MB1641: 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)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(149066)(150057)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051);SRVR:BY1PR0701MB1641;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1641; x-forefront-prvs: 0816F1D86E x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(376002)(366004)(346002)(136003)(39850400004)(396003)(199004)(189003)(81166006)(81156014)(6436002)(86362001)(8676002)(118296001)(316002)(14454004)(6512007)(8936002)(66066001)(256004)(386003)(2900100001)(11346002)(2906002)(6506007)(6486002)(52116002)(36756003)(107886003)(3846002)(486006)(53936002)(71190400001)(476003)(99286004)(105586002)(97736004)(26005)(44832011)(2616005)(68736007)(54906003)(186003)(5660300001)(5250100002)(71200400001)(446003)(76176011)(7736002)(4326008)(102836004)(106356001)(305945005)(478600001)(6116002)(6916009)(72206003)(25786009);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1641;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: 5CTUbvHh7km264effJOhUapmKbh3mMhD3L8tC9uXthhjLFtHJFzwSfW+RhO+q3m28BaF7FLj4USaoP8B7fiPjMRJwFlx0d/oxX8MsNpge8X/nnzRhAIl7km1PkSyxmRrlWprCAOsvHq/ngP7MSgGE7v9J2CpEf6hS9vYLpGRNXT0zMrWMNd8vfVXQko2vLLHbcFl0HwfPF+LvH6tloKahhe0TMfdnu2B82+gZ1jB5uM/OJJaLkxLF8zkozeu9ZeI6XIDrlMZjCSFOZXC1pqoqKzoQfQNI+venRdzxQGJ097xAVsAFJ2HpV19rkREG7kAmhTnXwSmVjlF8LmtKGdS5QCmup/kkjpVW6QAw3BbyQw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1af61a90-1180-431b-988d-08d62aace1c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Oct 2018 10:25:33.5109 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1641 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 | 133 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/drivers/net/usb/aqc111.c b/drivers/net/usb/aqc111.c index ade2b60b4811..20d4347ea3ad 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -192,6 +192,97 @@ 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); + enum usb_device_speed usb_speed = dev->udev->speed; + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + 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) { @@ -308,11 +399,53 @@ 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); + enum usb_device_speed usb_speed = dev->udev->speed; + struct aqc111_data *aqc111_data = (struct aqc111_data *)dev->data[0]; + u32 speed = elk->base.speed; + u8 autoneg = elk->base.autoneg; + + 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 (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)