Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1425633AbdD1Jvz (ORCPT ); Fri, 28 Apr 2017 05:51:55 -0400 Received: from mail-bn3nam01on0043.outbound.protection.outlook.com ([104.47.33.43]:37850 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1164134AbdD1Juj (ORCPT ); Fri, 28 Apr 2017 05:50:39 -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: Ioana Radulescu To: CC: , , , , , , , , , , , , Subject: [PATCH v3 5/9] staging: fsl-dpaa2/eth: Add ethtool support Date: Fri, 28 Apr 2017 04:50:30 -0500 Message-ID: <20170428095034.8842-6-ruxandra.radulescu@nxp.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170428095034.8842-1-ruxandra.radulescu@nxp.com> References: <20170428095034.8842-1-ruxandra.radulescu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131378466369672664;(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)(336005)(39450400003)(39860400002)(39850400002)(39840400002)(39410400002)(39380400002)(39400400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(9170700003)(8656002)(2950100002)(6916009)(53936002)(81166006)(48376002)(76176999)(50986999)(356003)(50466002)(6666003)(8676002)(77096006)(54906002)(36756003)(5003940100001)(189998001)(39060400002)(38730400002)(104016004)(110136004)(2906002)(33646002)(1076002)(105606002)(106466001)(47776003)(2351001)(4326008)(305945005)(8936002)(86362001)(85426001)(5660300001)(50226002)(7416002)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM2PR0301MB1199;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:ovrnspm;MX:1;A:1;PTR:InfoDomainNonexistent;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11OLC006;1:1pu/s1dl8lGqYgexjduGmwMxvUJz2Y1/X1OCr+70+p2TqyoeC2yzt6S9hGHiLATZMtbVZYgWN+fL8/FpCZTuQ2qmwwrbKFvNKk7kziAg6VwQWh1Vbn6uqQPtp8Dm531YnanjcwTWSECFL4kBcWX34QCS0HR0N/s/y+/VzkBp4MNiycMVXQ7RVG4OprN4J/c1W0c/3Pk5PMxhSLMrT3PF8b4TPyFCHPhRSUOVOQQ1dwxlTPly0pCqjPvTcIcaVOiUsams1a59nOsBf1CeEkvnxlOZy0Z7K4mlwXNNpNruWp1LYWcZ77cfVxes7vOinIRQFjJWiLmQlZ+jQ9QnDoE3rPVc1TPs4bW3AwLSUT5rJ6oEdG9HbD5kE3wkHmMWy+i4+5WRWrtSSJ2R6MAx6uj0yYCp+tQfQ/RQnfa+Uo57wLr4xEAkRH+VxUhRqO380uRuuOqEkx5ytP8WG+xSFDuFs2Xu8yYT8eSQEmztOLRRr9haEkN9Oif7MlEhAY2NR9AvqaAxMUAexj6tXOFepvDJ9PB0lfjfoqFF6EqyhuvEe/LHUbWeOgHu3DTZoR7I0Yc+3CgFSrlQxPCyzd9qNy2hxRO4KMpmme1vb5cYjuxpGtGBYC1ngmNXtxf0KulYI17Xna5e/cZv/r1ezqULOmFamP+1ZDXEGx2bp49URbiRoNEhIdt9FsjdB/F9T9+hFmYvzhKdjYq870/aEBp/Dh9ldUfwx8ZwRY3Fa+BE3NWOLGk= MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ca6e875-d2d5-492e-347a-08d48e1c058e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131430075)(201703131517081);SRVR:DM2PR0301MB1199; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1199;3:Sw8jZhIDouI3sIxB9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+mdBGkpD2Fnntncx/97WPWmJFOkpzw0IpDe6MBlzRkAAy8IUHnufahGSZQJ7jhXAb4hTd4OzDhf+vSPngZUDji53v7vIRUJY1PqQwJKiM6FtTxesDhYuhI4A4iyqBHlmLA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6095135)(601004)(2401047)(5005006)(13015025)(8121501046)(13023025)(13017025)(13018025)(13024025)(3002001)(10201501046)(93006095)(93001095)(6055026)(6096035)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(201703161259150)(20161123556025)(20161123561025)(20161123565025)(20161123563025);SRVR:DM2PR0301MB1199;BCL:0;PCL:0;RULEID:(400006);SRVR:DM2PR0301MB1199; X-Microsoft-Exchange-Diagnostics: 1;DM2PR0301MB1199;4:HZEVdjRQr6LDLXxzpxqYHkBAjDYHD9FsOTmTkWyic2V2VBtV6NW0LvGh3Nm0TCERsVmwyWpiZ8rp2pNFWxwEaaapJwCrwA2DwmCtxFpItyqhh9KmrkkLpJXKlwOzU86kWiUjrPO0yblk8NG9mOCFVIxSUbzUcdy+6wn1iNB/ynurzobSRJuL8DKHByG7DM1o1WhYbxBU4sL3HWQyCgKPSQbMrjzKrYTWYfvHQFk0BmQb+nA/M3q1sbVHm3Y3G8oH1ztarakbIUIhHYdYnKqTAljmgLJ14xUA/Q090UcqC+7ciiNmHpikDxLzAexmr+3ZsjmA21gql8THQnxKmUjy0cqndex1V8bdMcEssPCOgYtrxeYsaiVzh/wgZGN8MIsE7r+Wlr8poAW4iNDHzTIo14Apje3SArRFm5JhBpnMDPD88GVIHcWxrq+BOYnj/EAldv1+5QavubMWo6PnuDc5jU6EVQ0827AqXXYk8njjomCTCJLO8mPcnA2E5KkDW2UPfFn2SrzRoAfAhW1zCWNU6gLJqY+VJHOS6/oJ7WQAbMsCvAd6OqrPWJRT+SrTd/3gWLCtvaEBIRYM+ZAmhckS1OXVElej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uxoQ+kpnD9IpPKOD3T4hC/IXRD9sT2GiyDUUwGX70urZz4eMCgaW+lHYdj8c4SEuLBL0a/vDaysPPFGi5nNj+zbDjXfykF/RSs4JOOow== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2017 09:50:36.7956 (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: DM2PR0301MB1199 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10881 Lines: 323 Add support for several ethtool operations: show hardware statistics, get/set link settings, get hash configuration. Signed-off-by: Ioana Radulescu Signed-off-by: Bogdan Hamciuc --- v3: no changes v2: no changes drivers/staging/fsl-dpaa2/ethernet/Makefile | 2 +- drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 6 + drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h | 6 + drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c | 234 +++++++++++++++++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c diff --git a/drivers/staging/fsl-dpaa2/ethernet/Makefile b/drivers/staging/fsl-dpaa2/ethernet/Makefile index 4897d39a1c21..4327ebe803cb 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/Makefile +++ b/drivers/staging/fsl-dpaa2/ethernet/Makefile @@ -4,4 +4,4 @@ obj-$(CONFIG_FSL_DPAA2_ETH) += fsl-dpaa2-eth.o -fsl-dpaa2-eth-objs := dpaa2-eth.o dpni.o +fsl-dpaa2-eth-objs := dpaa2-eth.o dpaa2-ethtool.o dpni.o diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c index abd700e57aeb..f13f72f3dd9a 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c @@ -46,6 +46,8 @@ MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Freescale Semiconductor, Inc"); MODULE_DESCRIPTION("Freescale DPAA2 Ethernet Driver"); +const char dpaa2_eth_drv_version[] = "0.1"; + static void validate_rx_csum(struct dpaa2_eth_priv *priv, u32 fd_status, struct sk_buff *skb) @@ -1929,6 +1931,8 @@ int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags) key->extract.from_hdr.type = DPKG_FULL_FIELD; key->extract.from_hdr.field = hash_fields[i].cls_field; cls_cfg.num_extracts++; + + priv->rx_hash_fields |= hash_fields[i].rxnfc_field; } dma_mem = kzalloc(DPAA2_CLASSIFIER_DMA_SIZE, GFP_DMA | GFP_KERNEL); @@ -2360,6 +2364,8 @@ static int dpaa2_eth_probe(struct fsl_mc_device *dpni_dev) if (err) goto err_alloc_rings; + net_dev->ethtool_ops = &dpaa2_ethtool_ops; + err = setup_irqs(dpni_dev); if (err) { netdev_warn(net_dev, "Failed to set link interrupt, fall back to polling\n"); diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h index 7b194a47df2f..b30231891eef 100644 --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.h @@ -281,6 +281,9 @@ struct dpaa2_eth_priv { struct dpni_link_state link_state; bool do_link_poll; struct task_struct *poll_thread; + + /* enabled ethtool hashing bits */ + u64 rx_hash_fields; }; /* default Rx hash options, set during probing */ @@ -294,6 +297,9 @@ struct dpaa2_eth_priv { /* Required by struct dpni_rx_tc_dist_cfg::key_cfg_iova */ #define DPAA2_CLASSIFIER_DMA_SIZE 256 +extern const struct ethtool_ops dpaa2_ethtool_ops; +extern const char dpaa2_eth_drv_version[]; + int dpaa2_eth_set_hash(struct net_device *net_dev, u64 flags); static int dpaa2_eth_queue_count(struct dpaa2_eth_priv *priv) diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c new file mode 100644 index 000000000000..4378956a5527 --- /dev/null +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-ethtool.c @@ -0,0 +1,234 @@ +/* Copyright 2014-2016 Freescale Semiconductor Inc. + * Copyright 2016 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 Freescale Semiconductor nor the + * names of its 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 Freescale Semiconductor ``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 Freescale Semiconductor 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 "dpni.h" /* DPNI_LINK_OPT_* */ +#include "dpaa2-eth.h" + +/* To be kept in sync with DPNI statistics */ +char dpaa2_ethtool_stats[][ETH_GSTRING_LEN] = { + "rx frames", + "rx bytes", + "rx mcast frames", + "rx mcast bytes", + "rx bcast frames", + "rx bcast bytes", + "tx frames", + "tx bytes", + "tx mcast frames", + "tx mcast bytes", + "tx bcast frames", + "tx bcast bytes", + "rx filtered frames", + "rx discarded frames", + "rx nobuffer discards", + "tx discarded frames", + "tx confirmed frames", +}; + +#define DPAA2_ETH_NUM_STATS ARRAY_SIZE(dpaa2_ethtool_stats) + +static void dpaa2_eth_get_drvinfo(struct net_device *net_dev, + struct ethtool_drvinfo *drvinfo) +{ + strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); + strlcpy(drvinfo->version, dpaa2_eth_drv_version, + sizeof(drvinfo->version)); + strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version)); + strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent), + sizeof(drvinfo->bus_info)); +} + +static int +dpaa2_eth_get_link_ksettings(struct net_device *net_dev, + struct ethtool_link_ksettings *link_settings) +{ + struct dpni_link_state state = {0}; + int err = 0; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + err = dpni_get_link_state(priv->mc_io, 0, priv->mc_token, &state); + if (err) { + netdev_err(net_dev, "ERROR %d getting link state", err); + goto out; + } + + /* At the moment, we have no way of interrogating the DPMAC + * from the DPNI side - and for that matter there may exist + * no DPMAC at all. So for now we just don't report anything + * beyond the DPNI attributes. + */ + if (state.options & DPNI_LINK_OPT_AUTONEG) + link_settings->base.autoneg = AUTONEG_ENABLE; + if (!(state.options & DPNI_LINK_OPT_HALF_DUPLEX)) + link_settings->base.duplex = DUPLEX_FULL; + link_settings->base.speed = state.rate; + +out: + return err; +} + +static int +dpaa2_eth_set_link_ksettings(struct net_device *net_dev, + const struct ethtool_link_ksettings *link_settings) +{ + struct dpni_link_cfg cfg = {0}; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + int err = 0; + + netdev_dbg(net_dev, "Setting link parameters..."); + + /* Due to a temporary MC limitation, the DPNI must be down + * in order to be able to change link settings. Taking steps to let + * the user know that. + */ + if (netif_running(net_dev)) { + netdev_info(net_dev, "Sorry, interface must be brought down first.\n"); + return -EACCES; + } + + cfg.rate = link_settings->base.speed; + if (link_settings->base.autoneg == AUTONEG_ENABLE) + cfg.options |= DPNI_LINK_OPT_AUTONEG; + else + cfg.options &= ~DPNI_LINK_OPT_AUTONEG; + if (link_settings->base.duplex == DUPLEX_HALF) + cfg.options |= DPNI_LINK_OPT_HALF_DUPLEX; + else + cfg.options &= ~DPNI_LINK_OPT_HALF_DUPLEX; + + err = dpni_set_link_cfg(priv->mc_io, 0, priv->mc_token, &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(net_dev, "ERROR %d setting link cfg", err); + + return err; +} + +static void dpaa2_eth_get_strings(struct net_device *netdev, u32 stringset, + u8 *data) +{ + u8 *p = data; + int i; + + switch (stringset) { + case ETH_SS_STATS: + for (i = 0; i < DPAA2_ETH_NUM_STATS; i++) { + strlcpy(p, dpaa2_ethtool_stats[i], ETH_GSTRING_LEN); + p += ETH_GSTRING_LEN; + } + break; + } +} + +static int dpaa2_eth_get_sset_count(struct net_device *net_dev, int sset) +{ + switch (sset) { + case ETH_SS_STATS: /* ethtool_get_stats(), ethtool_get_drvinfo() */ + return DPAA2_ETH_NUM_STATS; + default: + return -EOPNOTSUPP; + } +} + +/** Fill in hardware counters, as returned by MC. + */ +static void dpaa2_eth_get_ethtool_stats(struct net_device *net_dev, + struct ethtool_stats *stats, + u64 *data) +{ + int i = 0; + int j, k, err; + int num_cnt; + union dpni_statistics dpni_stats; + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + memset(data, 0, sizeof(u64) * DPAA2_ETH_NUM_STATS); + + /* Print standard counters, from DPNI statistics */ + for (j = 0; j <= 2; j++) { + err = dpni_get_statistics(priv->mc_io, 0, priv->mc_token, + j, &dpni_stats); + if (err != 0) + netdev_warn(net_dev, "dpni_get_stats(%d) failed", j); + switch (j) { + case 0: + num_cnt = sizeof(dpni_stats.page_0) / sizeof(u64); + break; + case 1: + num_cnt = sizeof(dpni_stats.page_1) / sizeof(u64); + break; + case 2: + num_cnt = sizeof(dpni_stats.page_2) / sizeof(u64); + break; + default: + break; + } + for (k = 0; k < num_cnt; k++) + *(data + i++) = dpni_stats.raw.counter[k]; + } +} + +static int dpaa2_eth_get_rxnfc(struct net_device *net_dev, + struct ethtool_rxnfc *rxnfc, u32 *rule_locs) +{ + struct dpaa2_eth_priv *priv = netdev_priv(net_dev); + + switch (rxnfc->cmd) { + case ETHTOOL_GRXFH: + /* we purposely ignore cmd->flow_type for now, because the + * classifier only supports a single set of fields for all + * protocols + */ + rxnfc->data = priv->rx_hash_fields; + break; + case ETHTOOL_GRXRINGS: + rxnfc->data = dpaa2_eth_queue_count(priv); + break; + default: + return -EOPNOTSUPP; + } + + return 0; +} + +const struct ethtool_ops dpaa2_ethtool_ops = { + .get_drvinfo = dpaa2_eth_get_drvinfo, + .get_link = ethtool_op_get_link, + .get_link_ksettings = dpaa2_eth_get_link_ksettings, + .set_link_ksettings = dpaa2_eth_set_link_ksettings, + .get_sset_count = dpaa2_eth_get_sset_count, + .get_ethtool_stats = dpaa2_eth_get_ethtool_stats, + .get_strings = dpaa2_eth_get_strings, + .get_rxnfc = dpaa2_eth_get_rxnfc, +}; -- 2.11.0