Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751773AbdISMsC (ORCPT ); Tue, 19 Sep 2017 08:48:02 -0400 Received: from mail-co1nam03on0053.outbound.protection.outlook.com ([104.47.40.53]:22272 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751803AbdISMqN (ORCPT ); Tue, 19 Sep 2017 08:46:13 -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: [RESEND PATCH 3/6] staging: fsl-dpaa2/ethsw: Add ethtool support Date: Tue, 19 Sep 2017 15:45:55 +0300 Message-ID: <1505825158-8192-4-git-send-email-razvan.stefanescu@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505825158-8192-1-git-send-email-razvan.stefanescu@nxp.com> References: <1505825158-8192-1-git-send-email-razvan.stefanescu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131502987715419998;(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)(376002)(346002)(39860400002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(104016004)(76176999)(50986999)(85426001)(189998001)(77096006)(5003940100001)(8676002)(81156014)(8936002)(81166006)(50226002)(356003)(97736004)(8656003)(305945005)(68736007)(2906002)(105606002)(36756003)(50466002)(2351001)(316002)(33646002)(16586007)(106466001)(48376002)(47776003)(498600001)(4326008)(6916009)(54906002)(53936002)(39060400002)(7416002)(5660300001)(6666003)(2950100002)(86362001)(2004002)(217873001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR03MB2355;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD030;1:g2+Q2ezEcdOoLRf8EXJebUL99jKD9qyOYv71b26jECmiZrQIlrq8YhCpsy9S7TRIq/6XIs1FReAttXFg6sUwENpvNLW7QNjcMyO4cqFIZgk7+cn5IvnEazRm6TgD4+Jr MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0045ebc9-653d-4e18-bdfd-08d4ff5c6822 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:BN3PR03MB2355; X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2355;3:v3h3oquki0ZCHenbeWYzrpbD9Qb7qH447byshcPbPO2S3b1nVl+5ZO5VSS+9E6QUoMa3VmWiBp2wQxCMhiWtA9zfS3BMvprPBfLz89BajigQqeTJZCSmD71/PW++eccXlJeAGAA2MRAUnRxHZ1bcxPZ6A87mxmUMGtHpMYVc4FN4I9PVdU/UCdNycOcBW7Ht0buqM4S/3UoepnsFjvMQOjya9cZNQbSxkPvkIuYKNfVIbpT6ZLt+x3ppKFSUZpwsSQ1gxJkLU49IfrZ3JZyC2AjVnUtjOXqi8T+Br31LUjUK0VL1W9L+1scklmKqRMcxphwkKl+jzXMYsDP+239jeMnFxviIbIyElzhxK4lJMJg=;25:M2Zy2suLvV8OtTePdqlgZHb6MfrsgxTMMDFC76USZYh0tJChyP/kVs8PzavQGV92e2wBtyvLBNzYTUhkUtH3iL/d67xFyV78epD8ebv4hugsYpe4nbQWz/meKGFKbv0GgZHhjrIjRCHuB0mbmE2z5FROI1WZvgk1vyA0a7nwEUoPVcotjkLB7NdBiuji63dFvcvFn7wfxLPwqQLy6piHlfJDty6VEdKxuyNrFsWheIQ2XlQs7yCPDknmPA3DLGmsWun8ltwC9LCECBml2D6RpYZSTbQGSoHEMjen21YrSEzoMz1NSFwK4QWjS+ipVWmwFiKq9NvedlHzHmQX2yCdkA== X-MS-TrafficTypeDiagnostic: BN3PR03MB2355: X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2355;31:m8fTGvHg7Vi2AkbHekw52MiGhyDOWTgF6tRS9b76Rsvx772km310RDTCUuG7Hk4qrsLEQkKuZ/XRF2OkU7UturSyEo4G/KhbwYCuVjbbx0VHzBR5f1ud77oWvihSn6fIlzGUXDJJdkRMZu1obesc5NUZZ7SV8/l1dmgYdi9fqPBUTYxqm+F45jCOz+2s2HNOqBzap0funpua1025jp4RIqBxpI9zKnuQKp7sqJVBP0g=;4:7jETORJTShDa/G/kf+L/4xHpACmfIiFGeEZ5E/9OARAtZFTgIVkhgSaiVRvEXXQDzwrHs+wnG0IdI9U+JSyNoALftkSAy4WyWP+V+eAUFQtgy/GBbRzTtbWavdHYVHNQH5hGctVdTmRWGopURdq3KaH0a8QCYPA8DjlwkU64yD4Njm2oZ0rAAUH8V1BDlWwRdpp4s8JXyCJsMOwM8fvpoIS0ruiNrTfr8TMo/QN+Ob4f8ntmj0m7FOp5z0plrwR6DxIBFMbqasKzNNzcuPxxwjBCb+m91j3sNgnHlXgZrAPICIz1nXE0tEbJzoWe1PbfcVWBOckKyMQJ+YJnvVCr8Q== 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)(5005006)(8121501046)(3002001)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(6055026)(6096035)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123561025)(20161123563025)(20161123556025)(20161123565025)(20161123559100)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN3PR03MB2355;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN3PR03MB2355; X-Forefront-PRVS: 04359FAD81 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN3PR03MB2355;23:NGWBXnazjKvk4Mw5Gvb4uAI4pnIDH6ySAdpNQxvnG?= =?us-ascii?Q?P9a7rCSRaf78hJRUBFpniO3cM8LtzHK4ZfGsqB4ZNQTJRUcNahFvVcPE3A03?= =?us-ascii?Q?ZurvhtNbZIK7+2240haxAYfITRZzd6TMWRrLDnR0wlFYnu0wkNtWrTy6EmvD?= =?us-ascii?Q?InIWFF8YI5a5fqDXDGz4ByvzGUje6sLsjFcrfKfEZ+Qamd+Skk3uf0p3sBGW?= =?us-ascii?Q?zOBX68O7DsqIkxVbj4wjOWip29rRUVamrmGm8LILLNEil7rDkdMz3L8yg3Il?= =?us-ascii?Q?ki35azamRbNs3gEQgHSdVl3wlS/BQPnGPOt7MixQOUJi06zsWOYfAJymrvNs?= =?us-ascii?Q?PAmxKtmIDhXlsXgncW1ypibUAbTLNldCgH6LvBYh/LCtfDJJ2ln3rTH/XLuJ?= =?us-ascii?Q?y+gVZQHcpGNVgNVlPvuBWPp/EbjwiPcVw1jkT7dws0fGe7E5hOl4iMxB/KU5?= =?us-ascii?Q?pAtLZnJN156lEx7fkMC0WRs2fwDbqyfi5XO8alkq6KbgU4W1qJviGvDolj9q?= =?us-ascii?Q?A8DWNPj4Iy69vEoB3Nh6fHggKOzmmUWBJf0/BbbB5OC8Ll/rvlPmt4LCCcuc?= =?us-ascii?Q?fiFRDGb6S5U9cB1WQJMzVfRzGVRuAyP17+zpAzVxhyObrjWnpFwBJB+evP79?= =?us-ascii?Q?qVNEmEO4Hosfct08gQmyuZ1POKY0Eh0IPenTOpFC72pWWexBAAXdokiHzxJF?= =?us-ascii?Q?aqrd0WWIHjwr2GudaEU4uuKcmNGB3Vp5CBtp55rWPm09sX2NWbgwWiYMPaWI?= =?us-ascii?Q?v1Qb1+7G+LC271bFWyNP6veo7Y5XtTZKgyIdCdW+3oCyGMh4L9G67JWKqg85?= =?us-ascii?Q?myaH76DwZBZ1s9QPhfucgxtwN/vGBEuDWDFirlP8npdum4lsIOOhl8BD9JYr?= =?us-ascii?Q?2nDBNn8SoDhXSybFhtZwdRyBgMZbowZLFBleE6+TWac9ppBY/fUD9guthVub?= =?us-ascii?Q?Rsr5hOC1ZSFgUOJoCaO2oT5hZHX4yf3YjHDAsdh16ui6wgqG745jP90RW2Dp?= =?us-ascii?Q?yisvbpa8wjk7LEFBIhjZ0H2kTxnWIov7cyQOf+onDEp1db9X28ROtkLKUSVR?= =?us-ascii?Q?LFQI75RJP1c0gnjU7RhAoni7P5MzklaFKy7wb779kM9WCS0viUjOgl8KNI+i?= =?us-ascii?Q?ok8Epx0qrrAzhVpB6RZZdcHbaUQluJnPM7GixQX0pxQUxm4pooFG4D4DjQbN?= =?us-ascii?Q?dfJldW0UgmF74YClgGckVa8zkg6FHBfDKjgVQn67YTnBLj0uuz5DIEYuOIt6?= =?us-ascii?Q?Pobnm0tu8a8sE8GFwWiX/EWmR2gZf6/Xsg0xcup?= X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2355;6:oltFd5G27zoCHVjJJH4aBFV+w9r0k6106ni+hVsGcU/fv8hhw1JGxOUeIYSLH29Ttv5NooiFOg0O4dEBACGm02v2k3/wxrrTNUbLoK8tqyWq9KzY8w44Cd0FruO2VS9h/B6GGuPdpKX6kytKU3ZW1A09hh2pNtXz2QNjU+xD82fM9zYPCONkmRx0uJhpsknxvCDdXhElKXUNXsHJwcq85BWxg6VANfMj5/CG9RB+guMQeA+VyVzTfnk2No1tjC0N2/rAEyfhzJGtEn8BaiZm5HnDpG8xgKYwqHfDMXRfsniF6J62bZO+z+x/HYe1RaRuUo3JdYMgvXQOJ2GEjS4Xgw==;5:CRvHDsGIEo0jG3PeKpWRwWfV4VcNhFVat/Ra859FUbHoHaZ55stymEMGWM/TRESwlpRuWJue5/gD/R9ycK5NYJAAR6gsfBaXDK6HyI7I/6314y8Tpk4hWbR6Pd/H7bSJfGTBXvFcmNY4s56AFMRKKg==;24:c5Db4+fUABs9amXGRMCGOEg2zhCKYF9Zx38I+ry8iZ+OnLQ3rDvwBCBXeZI54DKI250vTfjpsvfbfIZncUPazFg9u5NbDLBfufuQDb14hX8=;7:9qr85kRpJXVY/bYEzEGrpkaRWVLj9fN2d9knn/PxmF0HwK8oAcZz1DSTr4wkgOMFiFAYB9qiC5GEChRyHBwyWx6xAAUD8vqXD/+TsG8tv3Hg0pLIdjh9nxHTZPWy/e1tN8lbOzyeYZ7zbmQvxyLk7996+FPV0BpdNPhJ35e0clOBFDALEjSAcGc2aPVb+xjnoATaIBX6xreC5axIqVhwBMvXGjl40Mm9YjqJ/zRwJ5A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2017 12:46:11.3079 (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: BN3PR03MB2355 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