Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751455AbdISJCA (ORCPT ); Tue, 19 Sep 2017 05:02:00 -0400 Received: from mail-bl2nam02on0043.outbound.protection.outlook.com ([104.47.38.43]:64962 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751340AbdISJBy (ORCPT ); Tue, 19 Sep 2017 05:01:54 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Razvan Stefanescu To: CC: , , , , , , , , , Subject: [PATCH 3/6] staging: fsl-dpaa2/ethsw: Add ethtool support Date: Tue, 19 Sep 2017 12:01:35 +0300 Message-ID: <1505811698-7338-4-git-send-email-razvan.stefanescu@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505811698-7338-1-git-send-email-razvan.stefanescu@nxp.com> References: <1505811698-7338-1-git-send-email-razvan.stefanescu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131502853117691451;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7966004)(336005)(346002)(376002)(39380400002)(39860400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(104016004)(68736007)(8936002)(81156014)(81166006)(33646002)(50226002)(77096006)(48376002)(50986999)(316002)(76176999)(50466002)(5660300001)(498600001)(16586007)(2351001)(106466001)(97736004)(4326008)(8656003)(53936002)(54906002)(86362001)(356003)(305945005)(7416002)(2950100002)(6916009)(36756003)(6666003)(5003940100001)(8676002)(2906002)(39060400002)(85426001)(189998001)(47776003)(105606002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:SN2PR03MB2368;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD040;1:I/KZXzzWWyA3KzItD/HeoP2r7cLX0/UlsNVZMjnktRxjrhrFNE9D/wgkm2q56LBaPuIgSHIqtfZSGzaCpBkzF/dZMAYl29pI997GpUQ9uJwO9kQGXbQ2n21pY+uMERwt MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b392459f-8e09-43e8-59c9-08d4ff3d1169 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:SN2PR03MB2368; X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2368;3:P3xROWoo9yFje9zqwowzOKeoVkedM53uPjmHuPzm5mnU5t6l9S8itmJv3qNPlGL7jL8AuRE3OBd1FHMlc7Us2zeegjFM1de4J7bFcd1ck3linqjADl1kIwIDtvSjgfNLotqiICNa8dKDJ0yxOaqHpDeJUoCAlgHbxTi6FtGJxKDglxoAbek2WkhIy8kA70XO9Tpp+5AtFPW881tDKwVHkq4LczYQnGWL9N2Cg5BBxnmME/f+9MQ29tH2jlZdlSh3KavMoTqdYEwSax486jIo/wShSHT4e1lWVBPJS5rWcLLYNRmLNe9UWgdpjpj4H419d+/jEe9wfBaL5Ya0wnnD144383r7Vs5uaWAqOtT4GlU=;25:H5Vv1ti/dmjXFGGl6/1ECrSrddDW1EvNeuR9NbCyiyRMxsGhIvfZg8HZcrwP17tzHXw/LV6y9pmFeU/LS5LIAEtx1JwkAcgL7e71KtVDgzJlFMnmKktNe1QPH9nz84UlO57bfBmqVYILxLmaOZwbnti+mLYjNGptTkHzl7Ms2ghhq9DHX3afdlYYz+7TztJ1QYTG561Jwj2x88i/W3y3IbNWwsx2kKRMBEqOA7rj2tSuYOJHHwMfwpaSntvk3+8XC0leCyIqK5oO3GutehAQIxQG7ls0VyRyIKB5xBu+kYaz+24w+P6Z0QfraPHXRBJyEZPc7gPKpB0t3aPeLkvOSw== X-MS-TrafficTypeDiagnostic: SN2PR03MB2368: X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2368;31:m3JEWPBMlA9Pmbw8v89WiH4aGk7PgTjxJVP8NJp+v77cYcmU6Xg5xFmXIZRK5E95gE7Vbj6UFbMzCSv50Fx9aV9bZrXgwc40n6D+qKH804gc9othPAkNUTlsyeWa7++syHt70pS7fn36+ERjIk+c3chXBzt+4ZvXLQ6MzTrll/S6wlr2gARX4us86VpZZZgNYSEgjKwn13JVldQWKaP1kJ7TTX4LMqXEIOiCEkGumjU=;4:ac77Ok03H6r7V6YbiI4aMWTKb9n0Hf781k5ytMOPf8WdFsUZb2QmHPHoe2LQ0J90FJdU4lF3SKwu4RcLti/HMtrAc8gTiZIn3BWaduVMlE14OWLZCsR3LQndDbnDbRK01H2uOxLSasmGma+T8zRsbev9jfOu3l0TK6FSB2TIIUiE6SWXY7kyj73yGbWmONpzl8nSBAF5YRaY5ZZSDkqZbI9dmrc1bW9wRYbI3owzjFp4Jx/mNN9XZ2liLV1JZ9aqcc09XF/6YqLPqmDY6+x5/EekJzjkF7fNUX3RMwfPyfYEB3O1ecTrtLbX62GQMCBaSzfG7SBfYaKlJie5BJgRXg== X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(275809806118684); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6055026)(6096035)(20161123561025)(20161123563025)(20161123556025)(20161123565025)(20161123559100)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:SN2PR03MB2368;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:SN2PR03MB2368; X-Forefront-PRVS: 04359FAD81 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN2PR03MB2368;23:7ZFuEWc9Mb621wiqWUSl+jFqJDQIxaNLR+Y7MtFYb?= =?us-ascii?Q?GSDchJOlaA3Ekskahcv+lxM9WzrH1n0R5TVtwFR8jzbgEIxGA6IFH2VOv3Jh?= =?us-ascii?Q?obL4MJqIgsiXBExCLHi/LinjUDxKiZxhC/uwHYlefHTaIDN90ztMQDcKF1oX?= =?us-ascii?Q?gUShUP3tzERQDW9XULnFlQVqcr4Ho6wZ72/opcbUbgml5Wm5T5am+mLAAUKT?= =?us-ascii?Q?BxtmB/mkxRAVFfR5d54dkZWe5YoSwvyBVAHF8UrOHS2jPdPTtLOfyC2P4xus?= =?us-ascii?Q?IMqNhQ7oK+ZPVmoNxDbGfnfvukXohU8Ulupmuk8HAwL64bXX/CwvaSkUktX4?= =?us-ascii?Q?Q0eSoL+SRH70Mk7ZH17s3yMeecJHvZ7iS1rWP8TGBSWAo+6urSa3/TT1vA+7?= =?us-ascii?Q?T5fl2pRuga1AUqnWkw0XHw+AXG8T8aOpRbxmvIGUox0FD5BMdVGE52oxUKP1?= =?us-ascii?Q?OKgMunJjnGf/UcfAA38KVYDfLXECV8CQJZiplDGERYoNoDY15nSL5MJtdwd8?= =?us-ascii?Q?Kg4sTpMCzkPzdofQo28LPzKBdCTNyUr5WJUogu292rVSFD/Sj7xvoNmvxI2Y?= =?us-ascii?Q?TfsuOt4NWGXPnXGEY+Gp67FbY9Zj7zKAdk3VTWPryrr83cfayL+RgVCQLeYa?= =?us-ascii?Q?Iv8GixnGiADDZF+2+NpZADbPhDVhkZzizFvtsWpsBecAth8O3NhC3pORq3fR?= =?us-ascii?Q?WqF1/lUc8hLTgtwwyth1tNHOZj5biONYMbRBcIx0Cv8KFlG7mfboXNox8o72?= =?us-ascii?Q?ZkxJDShOoirSPF3YBpC5gwo03KsDQZJ1nLqa9pb9b8WW9Zy764nuXStMpXqi?= =?us-ascii?Q?IzKV8KC8aYzEahkPxJSX6keAB/86oNCLgx+3TkxPR+XzSyYij6Oh9kqFp794?= =?us-ascii?Q?OggWj2Y3yFQozcwRsBm2x5XLnkJiZ5ybUlr703xhISUaJ9WE30K8zyG0h+6b?= =?us-ascii?Q?mpFBMUDK4qhAGd50m6xQdRzow3g2RlOBfH4C6IsiQY5ruEPudJmnrbA56TTj?= =?us-ascii?Q?b2qPrWa1wXo0Vc3hED6dnWkpNmf6WwD19S/FFWF0TuC/3KXeHP1ARvkYfG+l?= =?us-ascii?Q?ODSnpBzVZr4wpsQY2w+4SYULTWrXw6ZHptyq5jyYLvylGLdBsYwGgONCz9c2?= =?us-ascii?Q?LLQz4SkPiq6P0167nYPQt/dCBxZF9/FJnnp+dKCledyHsFnrl79DvZhed3Bv?= =?us-ascii?Q?roH4d17f7fnlWmUXOOKp/9gXvF+rud1wRTAVo+U58HKTnkzgQ3smUyfcWX7O?= =?us-ascii?Q?9craSETG5+rxZ6XWfs=3D?= X-Microsoft-Exchange-Diagnostics: 1;SN2PR03MB2368;6:LPpBPTKczNTUpm3S/Ee1bD/h7PI8Bnny8APd0ObLQImZ59mhLeOMfjo/mWrHL/CnAhZbgKVdGbXOis2VYx6FlhZiicUUSa2pwofXMtlyJGpYyexCTN5gmuOBFnG04SwuAEQzCaKodZoIP017q6B+g9V1cPUyG5d95FfeijYs3490hUng333dezxK8TsA0h/VjIL2lfJQlc+GQiecKfZKtZXl2U9JHgpNzgTIdIICkJRImU5W7pjS2gufWbFoLryTYqikfoXGZOnrqrvvfAjV7O6AMW7DUr7qVhZEAtI8+/bHw1Zu2NjwDmEuzLm/VpCu034RtEetIwiVHQ110uyceQ==;5:CaaDoMLr3Q1ivqT8gA1qfP6uDlx5C834OFJKP9A+L8KcASduQeWcUL2q5zmoMKM1fJQjwYFGykXXU+IjTlYeiZxYUJuIXAEzVCB+AvNUE+yjJN3vLvzuwhIb9Fa9AyhZKjCbXVmCN00BhhaiegHcXQ==;24:uZFLz9lumA01w2U0c9oTaUX8NAnhYrRKUyunsByiqvuDjm+XFlnKdqCO6CloLrhvJFjaMoAr1zT8ER9rUGL9Ej/XZ5JD8g4ECGOCnM/xlac=;7:1Zr0roUaLx7YumGj9Dwk+vRr/1Y7kSLkVgA3IDN03vQwigBL3NiMBNO+Utrl5QJlb/KF4icGC63hIZ6EjKAwNxZ+fCbygiJut0H6JfCftLdOPw5kHsxiBOShrzvjCgxaXwv7UDFe4y9Eqr0zacCaRyovA0sxjvWyOo1NmFSjn5yt66ngJIzj7RqbIO9O5CICZ2Z34vQ4lw46pPzOVBNM+gdF4CuGtHPRS1/Ro4J5zog= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2017 09:01:51.4727 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2368 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 13188 Lines: 392 Add driver information, link details and hardware statistics to be reported via ethtool -S. Signed-off-by: Razvan Stefanescu --- drivers/staging/fsl-dpaa2/ethsw/Makefile | 2 +- drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h | 13 ++ drivers/staging/fsl-dpaa2/ethsw/dpsw.c | 32 ++++ drivers/staging/fsl-dpaa2/ethsw/dpsw.h | 32 ++++ drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c | 207 ++++++++++++++++++++++++ drivers/staging/fsl-dpaa2/ethsw/ethsw.c | 3 + drivers/staging/fsl-dpaa2/ethsw/ethsw.h | 3 + 7 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c diff --git a/drivers/staging/fsl-dpaa2/ethsw/Makefile b/drivers/staging/fsl-dpaa2/ethsw/Makefile index a6d72d1..de92cd9 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/Makefile +++ b/drivers/staging/fsl-dpaa2/ethsw/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_FSL_DPAA2_ETHSW) += dpaa2-ethsw.o -dpaa2-ethsw-objs := ethsw.o dpsw.o +dpaa2-ethsw-objs := ethsw.o ethsw-ethtool.o dpsw.o diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h b/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h index ddfd820..06b71122 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h +++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw-cmd.h @@ -74,6 +74,8 @@ #define DPSW_CMDID_IF_SET_FLOODING DPSW_CMD_ID(0x047) #define DPSW_CMDID_IF_SET_BROADCAST DPSW_CMD_ID(0x048) +#define DPSW_CMDID_IF_SET_LINK_CFG DPSW_CMD_ID(0x04C) + #define DPSW_CMDID_VLAN_ADD DPSW_CMD_ID(0x060) #define DPSW_CMDID_VLAN_ADD_IF DPSW_CMD_ID(0x061) #define DPSW_CMDID_VLAN_ADD_IF_UNTAGGED DPSW_CMD_ID(0x062) @@ -262,6 +264,17 @@ struct dpsw_cmd_if_set_max_frame_length { __le16 frame_length; }; +struct dpsw_cmd_if_set_link_cfg { + /* cmd word 0 */ + __le16 if_id; + u8 pad[6]; + /* cmd word 1 */ + __le32 rate; + __le32 pad1; + /* cmd word 2 */ + __le64 options; +}; + struct dpsw_cmd_if_get_link_state { __le16 if_id; }; diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw.c b/drivers/staging/fsl-dpaa2/ethsw/dpsw.c index f36b92b..601172a 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/dpsw.c +++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw.c @@ -383,6 +383,38 @@ int dpsw_get_attributes(struct fsl_mc_io *mc_io, } /** + * dpsw_if_set_link_cfg() - Set the link configuration. + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPSW object + * @if_id: Interface id + * @cfg: Link configuration + * + * Return: '0' on Success; Error code otherwise. + */ +int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, + u32 cmd_flags, + u16 token, + u16 if_id, + struct dpsw_link_cfg *cfg) +{ + struct mc_command cmd = { 0 }; + struct dpsw_cmd_if_set_link_cfg *cmd_params; + + /* prepare command */ + cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LINK_CFG, + cmd_flags, + token); + cmd_params = (struct dpsw_cmd_if_set_link_cfg *)cmd.params; + cmd_params->if_id = cpu_to_le16(if_id); + cmd_params->rate = cpu_to_le32(cfg->rate); + cmd_params->options = cpu_to_le64(cfg->options); + + /* send command to mc*/ + return mc_send_command(mc_io, &cmd); +} + +/** * dpsw_if_get_link_state - Return the link state * @mc_io: Pointer to MC portal's I/O object * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' diff --git a/drivers/staging/fsl-dpaa2/ethsw/dpsw.h b/drivers/staging/fsl-dpaa2/ethsw/dpsw.h index e9c2906..5feadc2 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/dpsw.h +++ b/drivers/staging/fsl-dpaa2/ethsw/dpsw.h @@ -245,6 +245,38 @@ enum dpsw_action { }; /** + * Enable auto-negotiation + */ +#define DPSW_LINK_OPT_AUTONEG 0x0000000000000001ULL +/** + * Enable half-duplex mode + */ +#define DPSW_LINK_OPT_HALF_DUPLEX 0x0000000000000002ULL +/** + * Enable pause frames + */ +#define DPSW_LINK_OPT_PAUSE 0x0000000000000004ULL +/** + * Enable a-symmetric pause frames + */ +#define DPSW_LINK_OPT_ASYM_PAUSE 0x0000000000000008ULL + +/** + * struct dpsw_link_cfg - Structure representing DPSW link configuration + * @rate: Rate + * @options: Mask of available options; use 'DPSW_LINK_OPT_' values + */ +struct dpsw_link_cfg { + u32 rate; + u64 options; +}; + +int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, + u32 cmd_flags, + u16 token, + u16 if_id, + struct dpsw_link_cfg *cfg); +/** * struct dpsw_link_state - Structure representing DPSW link state * @rate: Rate * @options: Mask of available options; use 'DPSW_LINK_OPT_' values diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c new file mode 100644 index 0000000..dcd49d2 --- /dev/null +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw-ethtool.c @@ -0,0 +1,207 @@ +/* Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright 2017 NXP + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the above-listed copyright holders nor the + * names of any contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "ethsw.h" + +static struct { + enum dpsw_counter id; + char name[ETH_GSTRING_LEN]; +} ethsw_ethtool_counters[] = { + {DPSW_CNT_ING_FRAME, "rx frames"}, + {DPSW_CNT_ING_BYTE, "rx bytes"}, + {DPSW_CNT_ING_FLTR_FRAME, "rx filtered frames"}, + {DPSW_CNT_ING_FRAME_DISCARD, "rx discarded frames"}, + {DPSW_CNT_ING_BCAST_FRAME, "rx b-cast frames"}, + {DPSW_CNT_ING_BCAST_BYTES, "rx b-cast bytes"}, + {DPSW_CNT_ING_MCAST_FRAME, "rx m-cast frames"}, + {DPSW_CNT_ING_MCAST_BYTE, "rx m-cast bytes"}, + {DPSW_CNT_EGR_FRAME, "tx frames"}, + {DPSW_CNT_EGR_BYTE, "tx bytes"}, + {DPSW_CNT_EGR_FRAME_DISCARD, "tx discarded frames"}, + +}; + +#define ETHSW_NUM_COUNTERS ARRAY_SIZE(ethsw_ethtool_counters) + +static void ethsw_get_drvinfo(struct net_device *netdev, + struct ethtool_drvinfo *drvinfo) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + u16 version_major, version_minor; + int err; + + strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); + strlcpy(drvinfo->version, ethsw_drv_version, sizeof(drvinfo->version)); + + err = dpsw_get_api_version(port_priv->ethsw_data->mc_io, 0, + &version_major, + &version_minor); + if (err) + strlcpy(drvinfo->fw_version, "N/A", + sizeof(drvinfo->fw_version)); + else + snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), + "%u.%u", version_major, version_minor); + + strlcpy(drvinfo->bus_info, dev_name(netdev->dev.parent->parent), + sizeof(drvinfo->bus_info)); +} + +static int +ethsw_get_link_ksettings(struct net_device *netdev, + struct ethtool_link_ksettings *link_ksettings) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + struct dpsw_link_state state = {0}; + int err = 0; + + err = dpsw_if_get_link_state(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + &state); + if (err) { + netdev_err(netdev, "ERROR %d getting link state", err); + goto out; + } + + /* At the moment, we have no way of interrogating the DPMAC + * from the DPSW side or there may not exist a DPMAC at all. + * Report only autoneg state, duplexity and speed. + */ + if (state.options & DPSW_LINK_OPT_AUTONEG) + link_ksettings->base.autoneg = AUTONEG_ENABLE; + if (!(state.options & DPSW_LINK_OPT_HALF_DUPLEX)) + link_ksettings->base.duplex = DUPLEX_FULL; + link_ksettings->base.speed = state.rate; + +out: + return err; +} + +static int +ethsw_set_link_ksettings(struct net_device *netdev, + const struct ethtool_link_ksettings *link_ksettings) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + struct dpsw_link_cfg cfg = {0}; + int err = 0; + + netdev_dbg(netdev, "Setting link parameters..."); + + /* Due to a temporary MC limitation, the DPSW port must be down + * in order to be able to change link settings. Taking steps to let + * the user know that. + */ + if (netif_running(netdev)) { + netdev_info(netdev, "Sorry, interface must be brought down first.\n"); + return -EACCES; + } + + cfg.rate = link_ksettings->base.speed; + if (link_ksettings->base.autoneg == AUTONEG_ENABLE) + cfg.options |= DPSW_LINK_OPT_AUTONEG; + else + cfg.options &= ~DPSW_LINK_OPT_AUTONEG; + if (link_ksettings->base.duplex == DUPLEX_HALF) + cfg.options |= DPSW_LINK_OPT_HALF_DUPLEX; + else + cfg.options &= ~DPSW_LINK_OPT_HALF_DUPLEX; + + err = dpsw_if_set_link_cfg(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + &cfg); + if (err) + /* ethtool will be loud enough if we return an error; no point + * in putting our own error message on the console by default + */ + netdev_dbg(netdev, "ERROR %d setting link cfg", err); + + return err; +} + +static int ethsw_ethtool_get_sset_count(struct net_device *dev, int sset) +{ + switch (sset) { + case ETH_SS_STATS: + return ETHSW_NUM_COUNTERS; + default: + return -EOPNOTSUPP; + } +} + +static void ethsw_ethtool_get_strings(struct net_device *netdev, + u32 stringset, u8 *data) +{ + int i; + + switch (stringset) { + case ETH_SS_STATS: + for (i = 0; i < ETHSW_NUM_COUNTERS; i++) + memcpy(data + i * ETH_GSTRING_LEN, + ethsw_ethtool_counters[i].name, ETH_GSTRING_LEN); + break; + } +} + +static void ethsw_ethtool_get_stats(struct net_device *netdev, + struct ethtool_stats *stats, + u64 *data) +{ + struct ethsw_port_priv *port_priv = netdev_priv(netdev); + int i, err; + + memset(data, 0, + sizeof(u64) * ETHSW_NUM_COUNTERS); + + for (i = 0; i < ETHSW_NUM_COUNTERS; i++) { + err = dpsw_if_get_counter(port_priv->ethsw_data->mc_io, 0, + port_priv->ethsw_data->dpsw_handle, + port_priv->idx, + ethsw_ethtool_counters[i].id, + &data[i]); + if (err) + netdev_err(netdev, "dpsw_if_get_counter[%s] err %d\n", + ethsw_ethtool_counters[i].name, err); + } +} + +const struct ethtool_ops ethsw_port_ethtool_ops = { + .get_drvinfo = ethsw_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_link_ksettings = ethsw_get_link_ksettings, + .set_link_ksettings = ethsw_set_link_ksettings, + .get_strings = ethsw_ethtool_get_strings, + .get_ethtool_stats = ethsw_ethtool_get_stats, + .get_sset_count = ethsw_ethtool_get_sset_count, +}; diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c index ae86078..12bf88a 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.c +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.c @@ -44,6 +44,8 @@ static struct workqueue_struct *ethsw_owq; +const char ethsw_drv_version[] = "0.1"; + /* Minimal supported DPSW version */ #define DPSW_MIN_VER_MAJOR 8 #define DPSW_MIN_VER_MINOR 0 @@ -1389,6 +1391,7 @@ static int ethsw_probe_port(struct ethsw_core *ethsw, u16 port_idx) SET_NETDEV_DEV(port_netdev, dev); port_netdev->netdev_ops = ðsw_port_ops; + port_netdev->ethtool_ops = ðsw_port_ethtool_ops; port_netdev->switchdev_ops = ðsw_port_switchdev_ops; /* Set MTU limits */ diff --git a/drivers/staging/fsl-dpaa2/ethsw/ethsw.h b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h index 8c1d645..ba53cc5 100644 --- a/drivers/staging/fsl-dpaa2/ethsw/ethsw.h +++ b/drivers/staging/fsl-dpaa2/ethsw/ethsw.h @@ -57,6 +57,9 @@ #define ETHSW_MAX_FRAME_LENGTH (DPAA2_MFL - VLAN_ETH_HLEN - ETH_FCS_LEN) #define ETHSW_L2_MAX_FRM(mtu) ((mtu) + VLAN_ETH_HLEN + ETH_FCS_LEN) +extern const char ethsw_drv_version[]; +extern const struct ethtool_ops ethsw_port_ethtool_ops; + struct ethsw_core; /* Per port private data */ -- 1.9.1