Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753813AbbHEPo6 (ORCPT ); Wed, 5 Aug 2015 11:44:58 -0400 Received: from mail-by2on0143.outbound.protection.outlook.com ([207.46.100.143]:22368 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752880AbbHEPnv (ORCPT ); Wed, 5 Aug 2015 11:43:51 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; From: Madalin Bucur To: CC: , , , , , , , , , Madalin Bucur Subject: [v2 5/9] dpaa_eth: add ethtool functionality Date: Wed, 5 Aug 2015 18:41:25 +0300 Message-ID: <1438789289-16304-6-git-send-email-madalin.bucur@freescale.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1438789289-16304-1-git-send-email-madalin.bucur@freescale.com> References: <1438789289-16304-1-git-send-email-madalin.bucur@freescale.com> Reply-To: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11OLC003;1:EYTnF34gMw0vRAZb6m9OuW/6cT7k6Yb40mWge7O+uemrQjDOSacaHZ6pQf2o1C/oNgk+7/xkeUwqq/o0mqdRTOxdvtvxDzwKSqhWWj3MvgjECG/wb9+5WEba2TyOsrJuLFBGv6xXX4qElBUziqg8eoCqhqYATEs5Ebj+CTOZuSIRKnTlY9uCHD2WXGuSju67b3L3cUtd/WGRoWstQmLAT8yhBUBw2G9X5VPh20UcHVUdebkfPNU6HOqKds+lsXXDsd+lbWFHh43BY24vMJ15LPX/Ybr40DM/vz90OBODPUvmy1lI9ayuMkOx2yKBmZGnLf+V1KoUh0mNiaToypgyrw== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(104016003)(5003940100001)(48376002)(33646002)(85426001)(229853001)(2351001)(76176999)(53806999)(46102003)(50466002)(86362001)(64706001)(50986999)(47776003)(105606002)(87936001)(106466001)(6806004)(43066003)(5001830100001)(2950100001)(19580395003)(97736004)(68736005)(110136002)(5001860100001)(77156002)(4001540100001)(81156007)(107886002)(19580405001)(5001960100002)(62966003)(36756003)(189998001)(77096005)(50226001)(2004002)(4001430100001)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:DM2PR03MB509;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB509;2:/WGGhEgENxOibGu2rHgwgRVDdm3a3OG03woa9jgQVpGGVDV4GvnfwexhB/MhZsEIWpcJnFaQTtG4dUr9G/YrftYxSqNl3PFl3zUU9JOCJm/hD035h3F2uFXq38bIxcyfsFoeQ+Jg/eM+UR9tKERFy5W4JSf7pI8N3NUTcDULLug=;3:yFIELwMPNHuDKZbX5JwPa558gHlITMkvqsgl8B0ATAxaLdqaVLIK64fAPjtikZf1cCMgnJ3WE2h1ePVejkXyCpXBadAI1ZG7Voxqatv4yY2D4l7tv3BczcQgvEbRJ9iLXEJYKGXVLtpCfRztFM1e0nOVG+JtXFqHN+uvFlp2pVzN99PE/gD01tEM+kk4JpZRNijFSEuMZ3H37imxeL7uu09arYoslluOpKH0qlUgaU4=;25:YwXpQqzvCzOZWF+UvBQGc/rJ10/R2XHyyEUNEZTQ5/6FWqPHScPsGgTfCYXcuNbSUpOTUwr50IWH9viNnpol/N6AE7Z141lRCb9Sdfs7QYcej4HqJw/LFRofE7LoFytf/UKs0RSJhbA/JtbJcuB7VRb3hRQRFAf4GfzzFPQU13nC3B/xEhnHbo3hRucri7c9QOSCYeloHC+/RoLHpUsZT97I0cqfoS4+pzJmFG88qp56P44+wG7suq9j8P7MZMhdM28f2eBHQtO1azXzM7V+DA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB509;20:IaD4o4Xsk4tQGsJ6v6qmW94AY5Ynozr68T+D+yxuKO+c0HaqpK4KbjumMYOzebZXnEkwSh/Fo0PeSsCpUHwGkL0CfOh1EDPD4seN+omrlxWlQu7vLadzFIIkimXm8RIe2QMbg1dGyawpmz1ObmXpb/Gte0A0wZRP57jj+uhqicBDltKPN2DmkNrbaXHco4moeJ7GuAzvi7i8A3PcQnasET412rzqqYL9YVjHquvYjp+xBceyc1GwBInNHEiffAoeCkNAMX5+qsIsPAPul+ic3Jrf5nL1C2jmEX78KsE5+kg+CFi510ngrRXpFMaNSCdQc+mRPlVEhTla30zCXBNWYE5/5aPfZQLejsUWlwqR5Mg=;4:9ax8JL8X+TiH5gPyRD/x+ffPMTdhDfLW7U9Q9zoLFczKAvCJ08Ch4gLDGyiJ1eOaM8OP34d1hw+35gIiG8k7XblUp4MNgCK57n0lnoYivf3mQbuxS89/86erBNBDDZ7FhX5VhQonPzseTqEc9jLBmsoIyNZBBV1/JIHUhMjjTV4JS0FLI7qGgpUWfUo9JY7DuJJEWpJrPTHQv1+rgWMvbE05+cZCeqvtAxvfBRBR3tu7g6GrONqjjWk1j0RohP2xNFfV+RDEthz8C2TUbl/nOhqVh9xO3UFtP7wwTtmFROg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:DM2PR03MB509;BCL:0;PCL:0;RULEID:;SRVR:DM2PR03MB509; X-Forefront-PRVS: 06592CCE58 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM2PR03MB509;23:I88iTByCiHA3ExOu5KbTTd/H7rp0TbDU5E3oaFo4RB?= =?us-ascii?Q?kt3e2Sne0+wZiIYcfuUzSbFVnoIMMigwFb549EXicQF5GaEqjArxMjL7k9wu?= =?us-ascii?Q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EwLNNhZsPxfpXvgY?= =?us-ascii?Q?kFUGmtcRMkLiDBm6L4gkLw/Pg0lvlh8a3u6+0vnZr3fZSOF+gSm1Pkjo6H2a?= =?us-ascii?Q?XKPCsfLCvoKpJgu8cNf4abdAhb1hDq3mH8dpCZ4eooFXOEDBvdQQ0BAfhbwU?= =?us-ascii?Q?nBo8i4y4ONA/6EXF/RAJmkKzTe+bg8hkYxRswYbZL6mA4FzwW6guAYYzIrRg?= =?us-ascii?Q?AmhKE/CE1X2A9W2ozdIJzRVlbQa+63Mlbs?= X-Microsoft-Exchange-Diagnostics: 1;DM2PR03MB509;5:I2UDQNrFemQuTuTDUanrFkLaN5I6SvlV8KcY1eGsFdXdUubRmitAIFFMdoh/gsS6npTVDHKW6Iv7HwG0x0BofGQaRv1JyZOHY14svrxA4jtNOwG3uqvG33TP9+6Hk+pOXIJ1VKr6DU2/iFtXdJTvlw==;24:szYEE6smG2gfw4tiFwuZIgMzXrX/HYeMAtM79TXHidVtuquNLcXsDM2LfgHSS1An2zEfaBd1Qbr2XzcmkRtj6zxUxpIR8Rogvpdk58laetg=;20:TsG5kslkBFy8NbucqiOT6/CivZPV0DiZShFIhb4KH8bUWDZl7IhALMQJP56NmcvAM4K4lKmIcVqMjhQKhcHIMw== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2015 15:43:45.0268 (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: DM2PR03MB509 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9511 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 cf126dd..e137146 100644 --- a/drivers/net/ethernet/freescale/dpaa/Makefile +++ b/drivers/net/ethernet/freescale/dpaa/Makefile @@ -10,4 +10,4 @@ ccflags-y += -I$(FMAN)/flib 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 1258683..ca6831a 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c @@ -81,6 +81,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 4581bfc..a940561 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.h @@ -58,6 +58,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 u8 *mac_addr, u16 tx_timeout); 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..069fcf1 --- /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_s *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_s *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_s *)netdev_priv(net_dev))->msg_enable; +} + +static void dpa_set_msglevel(struct net_device *net_dev, + u32 msg_enable) +{ + ((struct dpa_priv_s *)netdev_priv(net_dev))->msg_enable = msg_enable; +} + +static int dpa_nway_reset(struct net_device *net_dev) +{ + int err; + struct dpa_priv_s *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_s *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_s *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); + } + } + + get_pause_cfg(mac_dev, &rx_pause, &tx_pause); + err = 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/