Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760119AbbLCLQS (ORCPT ); Thu, 3 Dec 2015 06:16:18 -0500 Received: from mail-bn1on0092.outbound.protection.outlook.com ([157.56.110.92]:24612 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1759239AbbLCLLo (ORCPT ); Thu, 3 Dec 2015 06:11:44 -0500 Authentication-Results: spf=none (sender IP is 192.88.168.50) smtp.helo=tx30smr01.am.freescale.net; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=; From: <> To: CC: , , , , , , , , , , Madalin Bucur Subject: [net-next v5 5/8] dpaa_eth: add ethtool functionality Date: Thu, 3 Dec 2015 14:09:03 +0200 Message-ID: <1449144546-25438-6-git-send-email-madalin.bucur@freescale.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1449144546-25438-1-git-send-email-madalin.bucur@freescale.com> References: <1449144546-25438-1-git-send-email-madalin.bucur@freescale.com> Reply-To: X-EOPAttributedMessage: 0 X-Matching-Connectors: 130936147015205687;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD042;1:TrHJF/d/4kA7GWvUBIWuIfxsIW8ma9CRtq6R3B8zdt7XMl9BumdVVq+J+Bx8grYdULhLGkRu+uvbbEVTuFrWFeeG08CECysxJ3vPgAHwjooxpSuJeM57lq+zhSxP4MyMnBjO1tmzuwTdu1NK4BOICdMx/esjQZH7ABiLmnnvQcX93Cuk+vQqbsYTl2HDHhPbZoFWjDxmLSAThn1+fbVLZ3xntuMj/PmctJf67hoLBJuodi9e1TE/ZsozNq80C8at4Jl0f6hrMAzCDBv9ZbBuN5jU9IAi4nEq0qDNxeo0ej7lf05NGkhTLmHoJnVXGZtLfuFBK1QuQSdwkk4dd6AOA2oYGuKC2T9srdjqA7pTp/wdjmV/+sX2RufNjU6MXlivrFWBUr1J2RZE8DFVtdykw7y0am74dgH+6bVfhL3kpqpwZDIH7l0dCH/nuImWttI8G7VXU5JkxMX7K2y65UyYZHnC1bdq2Z2bKVK+v2rAoAM= X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2970300002)(428002)(189002)(199003)(5001960100002)(5003940100001)(78992003)(43066003)(101416001)(110136002)(53806999)(50986999)(107886002)(76176999)(189998001)(77096005)(2950100001)(960300001)(97736004)(81156007)(50226001)(106466001)(105586002)(5005630100001)(33646002)(586003)(2351001)(50466002)(229853001)(6806005)(104016004)(19580405001)(11100500001)(48376002)(87936001)(4001430100002)(36756003)(49486002)(5008740100001)(1096002)(1220700001)(47776003)(19580395003)(60522002)(2004002)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB2123;H:tx30smr01.am.freescale.net;FPR:;SPF:None;PTR:InfoDomainNonexistent;MX:0;A:0;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2123;2:xZ3A+lvdUqsMSWFjHMpWIA83mZyqnaubbTb+JTP+EB5YKx1ZvvmTS3c3IrimoYTOQZHE6xSe0gIjYaIA4/VGoQC9WKWrb5CbPYrkJxXqFN8MonKI/0paH1ZlCSr6fdXVgKI9N/KitZozAwUTFgeuWg==;3:e+RB5rYmLSLT2l98dz8VjICY6bFVdg6QPbTJfM4RaQKRjWDz79U7JbTdmraAcO/mlXagZaVg2eH3ktpuS+BgUcsqC+nIXzcg2UvNLC47IffZQFSDuR4LfZT1tFuM5Dizltp4il7Dp7uUN7NIH/hwopYaz2ea6yg4CPSayFkMBC8FgP/esDyJzTK/vLZ6ssEw9gBNbBFHIiqjQveOrlQ7A/uO6Z0GABOhe++DbR3wsa8=;25:QCV9wL8jzVExrQ9eWo/61Yh1UU+LGAHfhOUChyXHJDeyHvNxa3yXi3eIwV+YfBMyTZA9m4OFOF0Pppa99L4uSqA/0LEIH6n4YAGko/24A/oSmsLSTNjk6nqcZNonorrKKFssnRoUrvsaNdlvrqF4mz6LqQLM19IPi8y4M7TA7vQxmtKxuwTWA/9572KUFrKYeqYbhX/+g+hTs/d6DK4CJ3cchAfKfa8Cv6zQ3kzA9MrqFyC1mxcCX+lnUlrLjF9h0pjKDkl45JNWbAWzTI3BRQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB2123; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001);SRVR:CY1PR0301MB2123;BCL:0;PCL:0;RULEID:(400006);SRVR:CY1PR0301MB2123; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2123;4:hp2yMQep47Z3r1UsXBN6OaCb4pu2EbplkwcU4XDN+YNha79t4Gb2G2r96lZBFHa+yXzcXPeJOyIiFhhBkUm3tzqbP9rJQgcxDLuZ838Z2p9LkgBvP2UCogPO4r1vbVNSWF0vDRYXNt+ZoZ38LY7p/CD4tKlhetiz2NJdWZlV+PvHxZkJIiihpPDoXMLno8tGasf0dDQ52dkkJf96W6UTa/1X6SEpvkAGfi+tBK+1+7qMEf/SZs8lQ4bPuxTMWE1n7RA+8gu0AmPPenmVvpBKLzcjd71zNgmVo1TPoySfHUZSg5kwofg4nE7GE3ywrKVEtXoy7FcABlClfIfLDoiD6dE+YYo8TxYK0Iw4AO/rueboVowbCYTKQt30M/c7nTKouNCCtvrzxKrdxZpGW1KtnKT3syJC+MxPpNkfYYHy8bUkGDTOx6RqXm90OrInb0Jn X-Forefront-PRVS: 077929D941 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB2123;23:hzOFBlsceLLSzdOmjtGSDo2N5PjX9JzJxyc7yvo?= =?us-ascii?Q?W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TxE25Vek?= =?us-ascii?Q?Ldjz50ayjbBxVljazTMfXt6WfmfkicGaMjFc9/dUc/4r1oF+1tSs5kHmTdxh?= =?us-ascii?Q?nzzPKNslyufinNupxETEWYyz8fK11d/dqRVFijwZBPhqvIAtigkjmwgO98iS?= =?us-ascii?Q?LcFAy7jqUs5yHpZxvD+zR39kCMMrVb0A2WNM+3mBI1Zfe873UA2yPBpuKFi0?= =?us-ascii?Q?98GKSPfJM5vUgPcTbE0P6BdQ3gDckwAO4pBpkSsp5672W0Q7LUd+JFVM5aAR?= =?us-ascii?Q?QpxuJwVoeMXP57EErREudqVU2iDV0GKOrbhK7Ao6NtxsTiULuDKjJMomd+A?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB2123;5:5WiZYn3/UoNm5lWfpA5snlHdUsMPiHh5HkebHhSocI40R1OxVJLRPzMdwK+oGsFPEwhLDdaRWTIOPB84eB9n08b90Z3E2KtOMW4bvNUjLg7+ekoZfjuy/cPCuvOpYKv/o2DCqkkzERvgwSolitiHAgkSI6jUVWCURTiUWxirJ3I=;24:2Mz2ggM0KM9lVQPU7v1KJ5uIl3qL+O6dbqHGgf2fEiFxD4wgSatGBcfm7U4YCyS2XPhqtpoUHCMuKIWxTkbYHgb/2whPEW1I7JxBay6Uops= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2015 11:11:36.8093 (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: CY1PR0301MB2123 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9610 Lines: 294 From: Madalin Bucur Add support for basic ethtool operations. Signed-off-by: Madalin Bucur --- drivers/net/ethernet/freescale/dpaa/Makefile | 2 +- .../net/ethernet/freescale/dpaa/dpaa_eth_common.c | 2 + .../net/ethernet/freescale/dpaa/dpaa_eth_common.h | 3 + drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c | 230 +++++++++++++++++++++ 4 files changed, 236 insertions(+), 1 deletion(-) create mode 100644 drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c diff --git a/drivers/net/ethernet/freescale/dpaa/Makefile b/drivers/net/ethernet/freescale/dpaa/Makefile index 3847ec7..9b75d52 100644 --- a/drivers/net/ethernet/freescale/dpaa/Makefile +++ b/drivers/net/ethernet/freescale/dpaa/Makefile @@ -8,4 +8,4 @@ ccflags-y += -I$(FMAN) obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o -fsl_dpa-objs += dpaa_eth.o dpaa_eth_sg.o dpaa_eth_common.o +fsl_dpa-objs += dpaa_eth.o dpaa_eth_sg.o dpaa_eth_common.o dpaa_ethtool.o diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c index 59a1920..656c5a8 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c @@ -133,6 +133,8 @@ int dpa_netdev_init(struct net_device *net_dev, memcpy(net_dev->perm_addr, mac_addr, net_dev->addr_len); memcpy(net_dev->dev_addr, mac_addr, net_dev->addr_len); + net_dev->ethtool_ops = &dpa_ethtool_ops; + net_dev->needed_headroom = priv->tx_headroom; net_dev->watchdog_timeo = msecs_to_jiffies(tx_timeout); diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h index 20facd1..8564bfa 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h @@ -43,6 +43,9 @@ /* used in napi related functions */ extern u16 qman_portal_max; +/* from dpa_ethtool.c */ +extern const struct ethtool_ops dpa_ethtool_ops; + int dpa_netdev_init(struct net_device *net_dev, const struct net_device_ops *dpaa_ops, u16 tx_timeout); int dpa_start(struct net_device *net_dev); diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c new file mode 100644 index 0000000..ebf049f --- /dev/null +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c @@ -0,0 +1,230 @@ +/* Copyright 2008-2015 Freescale Semiconductor, Inc. + * + * 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. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include + +#include "dpaa_eth.h" +#include "mac.h" +#include "dpaa_eth_common.h" + +static int dpa_get_settings(struct net_device *net_dev, + struct ethtool_cmd *et_cmd) +{ + int err; + struct dpa_priv *priv; + + priv = netdev_priv(net_dev); + + if (!priv->mac_dev->phy_dev) { + netdev_dbg(net_dev, "phy device not initialized\n"); + return 0; + } + + err = phy_ethtool_gset(priv->mac_dev->phy_dev, et_cmd); + + return err; +} + +static int dpa_set_settings(struct net_device *net_dev, + struct ethtool_cmd *et_cmd) +{ + int err; + struct dpa_priv *priv; + + priv = netdev_priv(net_dev); + + if (!priv->mac_dev->phy_dev) { + netdev_err(net_dev, "phy device not initialized\n"); + return -ENODEV; + } + + err = phy_ethtool_sset(priv->mac_dev->phy_dev, et_cmd); + if (err < 0) + netdev_err(net_dev, "phy_ethtool_sset() = %d\n", err); + + return err; +} + +static void dpa_get_drvinfo(struct net_device *net_dev, + struct ethtool_drvinfo *drvinfo) +{ + int len; + + strlcpy(drvinfo->driver, KBUILD_MODNAME, + sizeof(drvinfo->driver)); + len = snprintf(drvinfo->version, sizeof(drvinfo->version), + "%X", 0); + len = snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), + "%X", 0); + + if (len >= sizeof(drvinfo->fw_version)) { + /* Truncated output */ + netdev_notice(net_dev, "snprintf() = %d\n", len); + } + strlcpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent), + sizeof(drvinfo->bus_info)); +} + +static u32 dpa_get_msglevel(struct net_device *net_dev) +{ + return ((struct dpa_priv *)netdev_priv(net_dev))->msg_enable; +} + +static void dpa_set_msglevel(struct net_device *net_dev, + u32 msg_enable) +{ + ((struct dpa_priv *)netdev_priv(net_dev))->msg_enable = msg_enable; +} + +static int dpa_nway_reset(struct net_device *net_dev) +{ + int err; + struct dpa_priv *priv; + + priv = netdev_priv(net_dev); + + if (!priv->mac_dev->phy_dev) { + netdev_err(net_dev, "phy device not initialized\n"); + return -ENODEV; + } + + err = 0; + if (priv->mac_dev->phy_dev->autoneg) { + err = phy_start_aneg(priv->mac_dev->phy_dev); + if (err < 0) + netdev_err(net_dev, "phy_start_aneg() = %d\n", + err); + } + + return err; +} + +static void dpa_get_pauseparam(struct net_device *net_dev, + struct ethtool_pauseparam *epause) +{ + struct dpa_priv *priv; + struct mac_device *mac_dev; + struct phy_device *phy_dev; + + priv = netdev_priv(net_dev); + mac_dev = priv->mac_dev; + + phy_dev = mac_dev->phy_dev; + if (!phy_dev) { + netdev_err(net_dev, "phy device not initialized\n"); + return; + } + + epause->autoneg = mac_dev->autoneg_pause; + epause->rx_pause = mac_dev->rx_pause_active; + epause->tx_pause = mac_dev->tx_pause_active; +} + +static int dpa_set_pauseparam(struct net_device *net_dev, + struct ethtool_pauseparam *epause) +{ + struct dpa_priv *priv; + struct mac_device *mac_dev; + struct phy_device *phy_dev; + int err; + u32 newadv, oldadv; + bool rx_pause, tx_pause; + + priv = netdev_priv(net_dev); + mac_dev = priv->mac_dev; + + phy_dev = mac_dev->phy_dev; + if (!phy_dev) { + netdev_err(net_dev, "phy device not initialized\n"); + return -ENODEV; + } + + if (!(phy_dev->supported & SUPPORTED_Pause) || + (!(phy_dev->supported & SUPPORTED_Asym_Pause) && + (epause->rx_pause != epause->tx_pause))) + return -EINVAL; + + /* The MAC should know how to handle PAUSE frame autonegotiation before + * adjust_link is triggered by a forced renegotiation of sym/asym PAUSE + * settings. + */ + mac_dev->autoneg_pause = !!epause->autoneg; + mac_dev->rx_pause_req = !!epause->rx_pause; + mac_dev->tx_pause_req = !!epause->tx_pause; + + /* Determine the sym/asym advertised PAUSE capabilities from the desired + * rx/tx pause settings. + */ + newadv = 0; + if (epause->rx_pause) + newadv = ADVERTISED_Pause | ADVERTISED_Asym_Pause; + if (epause->tx_pause) + newadv |= ADVERTISED_Asym_Pause; + + oldadv = phy_dev->advertising & + (ADVERTISED_Pause | ADVERTISED_Asym_Pause); + + /* If there are differences between the old and the new advertised + * values, restart PHY autonegotiation and advertise the new values. + */ + if (oldadv != newadv) { + phy_dev->advertising &= ~(ADVERTISED_Pause + | ADVERTISED_Asym_Pause); + phy_dev->advertising |= newadv; + if (phy_dev->autoneg) { + err = phy_start_aneg(phy_dev); + if (err < 0) + netdev_err(net_dev, "phy_start_aneg() = %d\n", + err); + } + } + + fman_get_pause_cfg(mac_dev, &rx_pause, &tx_pause); + err = fman_set_mac_active_pause(mac_dev, rx_pause, tx_pause); + if (err < 0) + netdev_err(net_dev, "set_mac_active_pause() = %d\n", err); + + return err; +} + +const struct ethtool_ops dpa_ethtool_ops = { + .get_settings = dpa_get_settings, + .set_settings = dpa_set_settings, + .get_drvinfo = dpa_get_drvinfo, + .get_msglevel = dpa_get_msglevel, + .set_msglevel = dpa_set_msglevel, + .nway_reset = dpa_nway_reset, + .get_pauseparam = dpa_get_pauseparam, + .set_pauseparam = dpa_set_pauseparam, + .get_link = ethtool_op_get_link, +}; -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/