Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759955AbbLCNH0 (ORCPT ); Thu, 3 Dec 2015 08:07:26 -0500 Received: from mail-bl2on0119.outbound.protection.outlook.com ([65.55.169.119]:4812 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754659AbbLCNHY (ORCPT ); Thu, 3 Dec 2015 08:07:24 -0500 Authentication-Results: spf=permerror (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: Madalin Bucur To: CC: , , , , , , , , , , Madalin Bucur Subject: [net-next v5 5/8] dpaa_eth: add ethtool functionality Date: Thu, 3 Dec 2015 15:49:46 +0200 Message-ID: <1449150589-26253-6-git-send-email-madalin.bucur@freescale.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1449150589-26253-1-git-send-email-madalin.bucur@freescale.com> References: <1449150589-26253-1-git-send-email-madalin.bucur@freescale.com> Reply-To: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC009;1:w3cwXYWeklcUOFrwxpNKtmmlbWjFg7Gsbd0Q3RN0v2UqzNTQsbvy4Oxrcq25D+jPcNpRtxxEiRcaNsZ+ScI8dFCsT04560kP4WQgyrvOQ7xTE5OPgz3f4WyKuuFfmI3DCYNtU1VcTUwf38XOZvDPqSS7Ki4cJ1qO1gr6Twiu1Q1F/s7vTJY7+d4ELjSDHGv6m5wsKPCKRH0vtzey41IPkZtfao9fswxz2PC70eHiHDKMscfptXwjp8uz8/UWHwuygBYb7z5P1VEnWAf4LVPafazufeMONsz0MpN67u2DNSmiXs0f8WjNXzKgsHmxXHO276ogeaonzduKJabuqWZdFRhrFWo0Q/r6Gcjt0j7acxrrZYUIzGhkPghs0X5cdUm4SwMdSymitE26eNaXlUUeyuHcMOIBofVScUjYPrI5VSk= X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(448002)(189002)(199003)(106466001)(19580405001)(19580395003)(48376002)(50986999)(76176999)(5003940100001)(36756003)(4001430100002)(107886002)(110136002)(5001960100002)(189998001)(1096002)(81156007)(5008740100001)(104016004)(97736004)(50466002)(6806005)(86362001)(77096005)(1220700001)(87936001)(2950100001)(49486002)(85326001)(586003)(229853001)(43066003)(53806999)(33646002)(2351001)(47776003)(50226001)(2004002)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR03MB510;H:tx30smr01.am.freescale.net;FPR:;SPF:PermError;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB510;2:cgoa3VmeqkJ7D8Lb44jMyEgchD2GfJew5sWiIiVp3/1Bo6TDwFW/O1eMlCjvUzeGVFL9LnA0+QLfCVoOYSjqOf/UdJcYPrDFcwfRN070oHg1NTBgfvsuzi1FrCkATrbPbo1DMK54vViiR5WOuXSOKQ==;3:34dgYM3dtJ/uu4QUEbyF6L5NwAtqFazMNDncryR0YlXemAjRxvDhWh/91g2EGhb+d/1FcqZqecy5xZZ9UT3M1tGbBr8F/5uWb3UlDJuFGKlkbr70JUpZC4R6HMqYnDEG7Hx1E+T9bzMYdRy60YFkgiZv4Cb9g4h5FxYssR4WMiGnn5bb1Ch3e5pec4i/yfq3cpZmRA2fXpgLv3cJBjrXYjo6GhNLSjmvx4msRjukM6E=;25:JLBXB2Q3veJGqENk/UtqODMBXsv/HhpBLD/NEZIP5RbV/9u7N85GHVZVU0E52mKa7egLOuTmQ3aCYAwGvUSsYCxVQraQYvQEHJ9df3M2Xnw6jWwF3sLirRrZpIETifV60pHx5kUBj52BMFyG1Ftk+hX6dCXtpXF//0uHiNGHhObCDzOYzFSBEzjrtS10MHPXDBNkZWrVb81fEiLgYW9pH0BnzQNjkA+rLKv+cQ0LUiWiqv6/MgsUOCs+C+yOxTFQMLRGA5zLSbFUO+cXPH1dOw== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB510; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB510;20:oMoIlsNabfkVN4tqsdQdbr2JW4Z+RNjf4DQAyUJf8gukJmsJ0gJ7KXfKy86LrYUPBREGm9NkF8NFXxY3Z/5fNk7YVb4g4Kq3907Ya8Cj39biN92bYyVLEwuTi7o02r2T27DrZoWk6uSYkDImv6jboNImgJm/cRsCjH6EQnu6pmJSbf7/8cq9UJhLmPf2p6W8N8JNaaCVWdxlJNNG+WFz0xg7w3ykbp/Hyqmzd8LjT3rb60jSjg2HaC/Mvo/m3TTi/I2IqPpL4WH1+1mPmh3VN3NONBBJlQ5GhJrfeHGvs8WU9OBBvRsC9ZZ0oaz3Ob7zJT5vs4E3IuDqBrqHiZdF0Wizp1/lzrN6kRJan8UP2+k=;4:rQOBYtrLR/nbOqa32TdY4I9FqTyiXZ5alWlTowXLlVyDN5ZLEUVeMc2uC+6ykLVLWFJ4IJViScrXZBSopZU0g5NYnVJCjIoXccGrj7h7JYBV+XgtuKqGXUw9v2SqBnEgsRqPtdOkgYWWcfU+NRuBzogSSKZviB8JXIhczmRsKIMToKnVNBZ3q7wTT0PzjdpScVEpjT6usf7jKsBN44H5/DR4IZ0LQE2uL/MlUARM3GeugN3u6/Ugtmd1dw8o8TLz93tmgVRRlQRBJpf6fyfbJA4cigfOl+Vg0VaUiCEcPJMbnfg8tNJAIjnRgVeHaV9wzim4KRBJrWYj0MRJokDk1vDhs36m7iIJY6foDqmm6yQADKK30VleVE4+x/NCELr90h/c5Btzyj9CBbhDxQrYIKUhRaVb1cxIQ+U4TMwriTyd3y7eOh24t5gLwsc+zsgs X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(520078)(5005006)(10201501046)(3002001);SRVR:DM2PR03MB510;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB510; X-Forefront-PRVS: 077929D941 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR03MB510;23:TuU06EwrZ5EI2S8EsRfFfzxTeLjd9lsOI0kdkw2WY8?= =?us-ascii?Q?VRBKcYR4s1+BNxpeHnjxX/5LkejGEjF8+bsJk7E9KGdS+znmUBlrtg1hXYU1?= =?us-ascii?Q?k+Qh3kFWGK6gc6EZoSkK6g+3d2gA6l3M9hTCMVn6ZLurMqj9a8p3EA8OIoTQ?= =?us-ascii?Q?8/T5RrlfaQTy7XkSWitrsyOTZYuDGD6UdTNhh6ER7dLCDowBY89oTI7q0lZV?= =?us-ascii?Q?EYJMCTwQhGKZ5ptwmt9USFfTPmSKJWOpicEWlZ1/Aptq1AbIKC7ZYpIowYUt?= =?us-ascii?Q?ZVnNVEhZJCEphTcNf3QGNRUZP4SIy8jj4NwZeexVrCsAvGvLa7WcAdNnyoJB?= =?us-ascii?Q?p3WOQ7CDDY/rogxVDt7ipfuwIq3MJPPqa6fJmZLof69SDPgVWCzXgMHgymOi?= =?us-ascii?Q?DdhA/ka9ngthz42jgURKf/iK043g2XO6k8FzMQjAuc+KIEaBPHkHW0RK6M2A?= =?us-ascii?Q?tvFp2vGTuetXkwPyQP8qP4z2P5SKm5tr0FhLxVtdef5kIXvVtWw0N6/lZt15?= =?us-ascii?Q?vakD3nMLFmey1lDUZ7oCv9M2tfn+vXOIpIdxFg2apNVUv0SGJFX7khtPgnRf?= =?us-ascii?Q?/rrioySiNCaZD2uFceKiLlMpcYC2c7NF2S09pPUkuGqCHzH7rCYQ8lbSdTz6?= =?us-ascii?Q?lmx1OVGUXqj1wN+EhqdA2ajdFIJ6DBjpdLu4bjsHG09Tfuc1uU2YQyGgEdXF?= =?us-ascii?Q?SxfxixLWf2QXzetvpD9kDFAIi8J51DWWU9n/3/yXPdUQgVaS/tN3vRHDnFxK?= =?us-ascii?Q?k3ucFNKHJ0w6aFYWrAELHpIwO8Ik770UZ7tBIZh+JRnsIkVpUEe0+FAnvL8X?= =?us-ascii?Q?IDpquoRvIpoitH742Go9soIgxBFAH60iEeWFvII+LpxmNbqtLHlAeSwaJK6F?= =?us-ascii?Q?LPCa/9zoQqHfTeIVqsUCSRqZYaSxvQzHfsbwvk5Z7mP5xEeB2dJJzDkDGo88?= =?us-ascii?Q?V+pKJ3GRYt5dn1J4xsP7ui/2C+/VzJdBwUfdzhioXVRi/MDedVjXjq5nDw6q?= =?us-ascii?Q?lGKBfgOByASZZkPq6VLQopZk217/YrnCFmm1NNPjA2kD44HS6jIzVf+rN+Hc?= =?us-ascii?Q?h2336KqIoCNXXFu7wHU2A36nXUT3Kd/ECGGj6NfPVBobH5/w=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB510;5:j/TKAr3yy1EfkBxpcBA6t8KecC8c+cKJHTRqwmqrnv5TQh3jSuXKdpWfj2E+6CYkO/Q/yGfuFcuZhY/vn2yQmklAR51iCqVTJhr5kpili173OysDkr6ZB9OoJ4NqJUh9Uk+gW0gKxDTfAYP2rKMr3g==;24:QHOWQAOge277Pt7FRbbHNyUHTEWqjMvSmJwSD4pcs7OF4Jd87b2OmsQiVRkA0Q/maCygR08Jh24qdSBNRlUmDtmtAOaCywWe0uzaPqQpg9c= X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Dec 2015 12:52:21.9308 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR03MB510 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9559 Lines: 292 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/