Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755151AbdDLQ3E (ORCPT ); Wed, 12 Apr 2017 12:29:04 -0400 Received: from mail-sn1nam01on0082.outbound.protection.outlook.com ([104.47.32.82]:18560 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752888AbdDLQZt (ORCPT ); Wed, 12 Apr 2017 12:25:49 -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 v2 5/9] staging: fsl-dpaa2/eth: Add ethtool support Date: Wed, 12 Apr 2017 11:25:34 -0500 Message-ID: <20170412162538.25302-6-ruxandra.radulescu@nxp.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170412162538.25302-1-ruxandra.radulescu@nxp.com> References: <20170412162538.25302-1-ruxandra.radulescu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131364879407213566;(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)(39410400002)(39450400003)(39840400002)(39380400002)(39850400002)(39400400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(9170700003)(54906002)(36756003)(39060400002)(6916009)(356003)(77096006)(8656002)(4326008)(6666003)(2950100002)(2906002)(110136004)(38730400002)(50466002)(76176999)(50986999)(53936002)(48376002)(5003940100001)(7416002)(86362001)(47776003)(33646002)(1076002)(106466001)(2351001)(105606002)(8676002)(305945005)(8936002)(85426001)(50226002)(81166006)(189998001)(104016004)(5660300001)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:BN3PR03MB2273;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;MLV:ovrnspm;A:1;MX:1;PTR:InfoDomainNonexistent;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD004;1:fXwoejheomKJxK6oY7p0ULqPlajur6jtb70SNhmgKTpy/wHnONeqmbqXsIP8Hjs5piGp+c9wmHAFePXQiCjadGnVEjhmX4b8ixsEpvzQQ2yvoPude3KkrmbcYCc8EbRCFmcyZqJY8CMeDv6WwJkbvYeQ2Cp3Mi0PEJORPOBmJEd0GiYYmRL1ux58ZRB/2DB60D9FHcrTQ7yzN7NBtLqNlrG6hDLNe/C5RF9/nsgubGwZ0F8jG2hA1Cpu7HckDM2a779HHp4C/Y3GFkervJK5ZfGH6fUoZRDlefMwugHr9x/3GiYYb5E1wNjxzrLHSd0x2wzBFe8PSgx1L6jsJxiuH96klzOcRUOCEFuEy8V6zAjndMc7Gext81d3wDtkFyWdFzjpS3GsdLZssPtjVvow3OyQbPFijV1fYv5fbbnVdDpwel/9gvB64wTurmYl+jyAQWwlmfYDPwk/6+D2s9FjvAM0ShxinPBtOLIp5LTsG7SadTDKso7oPZCSV4VCNfB6kxhAO5yKLhzndWIH4y4ah+xvPirZcl9u3tmAj/0LGsHd8/k225CuEspH8QJbaja/IHS+jS0pkOxprItsmCPhcTVoGoplEIdexGDiK4eQ5BNGRP0H9RLKJDt6zzQtyAR2J+hOtP+17EeNTUMbfZqpjG5oNoBWs6bfmz9qr7gSJKsKguF9FXukWzTNVNe8ie6reBwJtDnPXXc+OXD0xYFfxJb1ANBsEbFPl6sCxYvKPm0= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 4498f557-daf2-4116-6bfe-08d481c08f7e X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030255120)(201703131430075)(201703131517081);SRVR:BN3PR03MB2273; X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2273;3:omg12wp1pefVUOwTMhaghCnMUWuCKdXuKg2tkdU83c5G8Nr3Th+uYgoVrpzqS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TgWcOKJUh0FIMUs9nFqmgdbIzqFUqd9pN6XwvEPwkEaPmao52v2fQzni4JNERJG0DitparZcEy3p/SrdOMVtZ6khY0s4vETfvrBFY4MwxbXcgb6FfjJYg7lKqC1qHdlB4ymrsrA== 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)(13024025)(13023025)(13015025)(13018025)(5005006)(13017025)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6055026)(6096035)(20161123561025)(201703131430075)(201703131433075)(201703131448075)(201703161259075)(20161123556025)(20161123563025)(20161123565025);SRVR:BN3PR03MB2273;BCL:0;PCL:0;RULEID:(400006);SRVR:BN3PR03MB2273; X-Microsoft-Exchange-Diagnostics: 1;BN3PR03MB2273;4:7gSa2JLM2GkfSUTYnN1xnhcJ4rzEHVLhsNnmSfHQJ5P7Fgschep9+XyoVy2gR9L42M/2J8yeEeZa06Lv4kqOFcUHwqmMMon89WiAEGkamaFDHIdSgbHtYJ5uTQvm/Dqsk79zjBZZp8EdBizbZ9yJ92PKSZHEGqVhyq3RqI1Wrlp7SME0oBpN3gPxt6E+7l4s4lFyUth4in0Y1ZDxaKVnZMHG/I6cZ4IzANv9Qo5qPqA3ThUzg1AC0PMIzXkjRtri33Uo/fB8a07GHWHowOdR1KJZVcXkvghZaE5PU7RJQmob9N4PXMc852UBflvb+S0hmqvCwd3cS433bNQmODwYoQQzCw/TqMkgB/Yr2fc0a3RiNlXry0Tb5aEPaUMfsG2iMAjuPlDePr4/H5YdkZMBXWeDIO6XWXsljrcNXdgKgw0ZmvnbR3vQpk3USolgfV5Z8vf7jgh8ps6SPbhreYynMrWPpV4wI/ytrqxJroQbS7WftCAwpwPqVQgArUtyf9AKZOUT72lpQ33C4L7e/dZeYKp9XmRp2eHfeYBfInOfWe0EiJv9GuLasqiLw+iWIhOCeinP2kIk/SJD4B+O2kjxAo5UY1kG1JYSw4qmLao3eqbzHLrOusLo67otc4XC6LFa69hVaflSoXtgk/bblAyJ9S36QPQaELmEsNnUwdqrg4yUGFri24+xhzg197IV6WUEnaTX1v9XKA52hmVS4Mbm3asEv/wSWlmwL0NAksW6uCwAPe12iPR5Gi9bRotxMkMcgsjv/VHBvb7OYey/h9Shyn2XuyF2XGp+xmcXzX5EPSjyL9i3x4BrBSd0ja7ivP7YQ4/T5TFyHOS+W7u1iLdGfEasDJkKNz+yedoZgyAVgO3w/7avOJK0Z5Miy+K2H9G30fcLf0FKeA45Ja78COCSTw== X-Forefront-PRVS: 027578BB13 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN3PR03MB2273;23:vPDKa+flbKkEkdysBuMbX7l/nrmRzZiqMoffkjliX?= =?us-ascii?Q?aRTIOlb3COvkodd930IXD2uvPJPrF/GtpxsHW4KwwzcnG+XiLnV6D9dNnfdg?= =?us-ascii?Q?ivE1ll53Lg1Xr+uWQNmFSmJgBELJod7HwmH0mF76B9Pq1V9m2FFf/nBgyBC0?= =?us-ascii?Q?I1zlVQhn9GW2k04pt6UDmhDj+3rXexhtDpYJwl45ShIyjkGCTfwNLvlLBMzF?= =?us-ascii?Q?KLYv4gzjmCSrlP5OKSu9AQrbxb3o0JK6gg3qL3/RiMLP8MbEBGbkGMyA73FA?= =?us-ascii?Q?TmftVbqjpBbr72ed/y48Qq3Isys2CYhTHMEUY+E6zYjgHVfI+t5ycqDpufDS?= =?us-ascii?Q?2+eYAE2C93n4f/4AiahdHjewQImqddHE1mzffTgLOXJNXmQZ3TtHT1AZXrl9?= =?us-ascii?Q?gdRZsOpS5IIrvOUoiUE+NgtDyNa/JM9RhyHtG9nGkVfdJeQI2JUl2KvmtNny?= =?us-ascii?Q?dsoIHn3JVTiswTDKztxf8s2tNXqwyQ+4O0If+NQ0iB0wkjLAww0ZmSmE6mZF?= =?us-ascii?Q?Bf4g3msOnSZTKmFUlUlLaqiVZtgiWLdZdjmpKWruwdmeOGCHhHaMd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ossTenant-OriginalArrivalTime: 12 Apr 2017 16:25:40.5185 (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: BN3PR03MB2273 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 10866 Lines: 322 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 --- 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