From patchwork Wed Nov 21 10:14:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Russkikh X-Patchwork-Id: 10692261 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 A39EB13BB for ; Wed, 21 Nov 2018 10:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91C552B8C6 for ; Wed, 21 Nov 2018 10:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 862322B8CA; Wed, 21 Nov 2018 10:14:05 +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 F28092B8C6 for ; Wed, 21 Nov 2018 10:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729143AbeKUUrx (ORCPT ); Wed, 21 Nov 2018 15:47:53 -0500 Received: from mail-eopbgr740085.outbound.protection.outlook.com ([40.107.74.85]:32160 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728512AbeKUUrx (ORCPT ); Wed, 21 Nov 2018 15:47:53 -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=hYo51P2mObp9sNtRROKBMMFafhg2VmLDO63NMrGwlJI=; b=vvz+piEuP4m3nJVYh7QwxKqXDMM5ig2mx6UWghHuB4vVSccnW8F/S7hcHhhATezw0vYTtnsZVDISI1XnrQkODCOR0u+2nWUcyzH2+Pvz40CS0UUiaAfyJdB6rR5G8LWO58FAM2vUfwQ5C7GVm3/gDMQ+qiziJNZoxwaeHoNsRR4= Received: from BY1PR0701MB1660.namprd07.prod.outlook.com (10.162.110.22) by BY1PR0701MB1287.namprd07.prod.outlook.com (10.160.108.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.26; Wed, 21 Nov 2018 10:14:00 +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:14:00 +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 18/21] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Topic: [PATCH v3 net-next 18/21] net: usb: aqc111: Implement get/set_link_ksettings callbacks Thread-Index: AQHUgYLrheJEkBCCEkKs9QjbR4R63g== Date: Wed, 21 Nov 2018 10:14:00 +0000 Message-ID: <55e86d1c69ac72eae0fbaff334e16ad3fee69531.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;BY1PR0701MB1287;6:RnmqEt8Hdh8S/8MuaPOJFuyVRHvn0WdnFkbsTg9z7gcurTdraPmJ4pV4/6Ktz+xkwITD+0zPhdtZyM+HJzf0hrvad0yJcXtFpWrUDXhL0sXvEoduEfP0McQU9syr2OpgimALXzPRX/vYN5e84oMtsp4/qsA90mVjFlpWfciKum94Ne/m9J6DDJbGW4UVaEMj3uh1DvgnuvnCwAcy2O85rQvi3i3du+jCHw59hoAYSNeSedeyCJ7LbaAHwAEr5EDWzKFh5cTTTdVIgS3Tmw4ALeC7mYWui5KlwvD02xb+CtS/UlgRlwcYWtrtc7KhLDTq8KTFsdL+9e5rJGtdtu5nb+zXINHbvmu8Y11uirIMgRFLDN3UvSAmba6/gs9s1HS7sY2JDNObSTdavYI9DBBUiaSq45HLD162kuV38c5GMcyfliywObglbLtVND2DXmLDK0+VzZiXOxZr0AS1focOtIgRZG5eYO5EuFPVgT56DiU=;5:6rd/VR/S4eIjawWWIYBgSYEUG+WWFX+AwrrnJ7Gr6N21itxcea/swLYSkG7gJW2lpOeloZf10jsNo2ZTzkq6wr0vhP+E7oKdo8o/tJPyoIJVwFRw5KYTU2oMRqe6CkC8hhzUGaT2ifh+HUbzwvXQw++Hkss/GG8W2aZ4Azs249s=;7:/gqL7hZ3KUU2+6Pyc2udostHUZn5G1PFYDXXGNxzzoRKAUMTeT1PiQE3WmifzCAQoHIlg2IXYEZFt9ym88wEaofKljdhj0a0nTAjHfMALW6TbJE43TvYMi1YTJa9f0jSLb6ebv6USOuu/1Q2MQYnaQ== x-ms-office365-filtering-correlation-id: 18a1a143-bab1-4200-4cab-08d64f9a0e11 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BY1PR0701MB1287; x-ms-traffictypediagnostic: BY1PR0701MB1287: x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(3231442)(944501410)(52105112)(148016)(149066)(150057)(6041310)(20161123560045)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:BY1PR0701MB1287;BCL:0;PCL:0;RULEID:;SRVR:BY1PR0701MB1287; x-forefront-prvs: 08635C03D4 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(39850400004)(396003)(346002)(136003)(366004)(376002)(189003)(199004)(106356001)(25786009)(66066001)(5660300001)(2906002)(7736002)(305945005)(97736004)(6512007)(2900100001)(2501003)(110136005)(2201001)(478600001)(36756003)(68736007)(54906003)(316002)(6436002)(14454004)(105586002)(72206003)(81156014)(386003)(6506007)(102836004)(4326008)(76176011)(81166006)(71200400001)(186003)(26005)(8676002)(8936002)(71190400001)(107886003)(99286004)(256004)(118296001)(52116002)(86362001)(44832011)(53936002)(6486002)(3846002)(6116002)(476003)(11346002)(486006)(2616005)(446003);DIR:OUT;SFP:1101;SCL:1;SRVR:BY1PR0701MB1287;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: p1K7+LvCD6MCsa9QAFLQcE8xH62Yyq1xMdeduIhoxXiJB3qaP+YV77JaZ+bHwebA9vuD/Fr+VwzfHKlQRRo5ZtyKTeo64H5fPS6Mtx5/JZwGoPbWsUNBLnLUOw9IT0tcH3bMaopl7nxk0gI0t3639bdJsVebk5vhNAY7/M6ix7haBsOvx8NL5y+xmz78T3hVSDXpCPpa45tfxv1DtD2DSGCKGQsMeMeKm8pk6LNuRiMGIbDykpa3w/LHTpHr8spDKN5QZFxn0f5V/OtaThZlDcHVECBWlHsZj/91h+f9HKeSI4XSShLpDgtwShALPSk2l5/xXGC5NNE4GtlRJWetX6o9v1QDotUErFbYkhRuZc8= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: aquantia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18a1a143-bab1-4200-4cab-08d64f9a0e11 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2018 10:14:00.4389 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 83e2e134-991c-4ede-8ced-34d47e38e6b1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR0701MB1287 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 2028db453df9..d96f8d4fb7a0 100644 --- a/drivers/net/usb/aqc111.c +++ b/drivers/net/usb/aqc111.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "aqc111.h" @@ -198,6 +199,84 @@ 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) + linkmode_copy(elk->link_modes.advertising, + elk->link_modes.supported); + 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(struct usbnet *dev, u8 autoneg, u16 speed) { struct aqc111_data *aqc111_data = dev->driver_priv; @@ -245,11 +324,56 @@ static void aqc111_set_phy_speed(struct usbnet *dev, u8 autoneg, u16 speed) aqc111_write32_cmd(dev, AQ_PHY_OPS, 0, 0, &aqc111_data->phy_cfg); } +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)