Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754531AbbKBQt7 (ORCPT ); Mon, 2 Nov 2015 11:49:59 -0500 Received: from mail-bn1on0143.outbound.protection.outlook.com ([157.56.110.143]:18332 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754513AbbKBQtw (ORCPT ); Mon, 2 Nov 2015 11:49:52 -0500 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;freescale.mail.onmicrosoft.com; dmarc=none action=none header.from=freescale.com; From: Madalin Bucur To: CC: , , , , , , , , , , , Madalin Bucur Subject: [net-next v4 5/8] dpaa_eth: add ethtool functionality Date: Mon, 2 Nov 2015 19:31:37 +0200 Message-ID: <1446485500-9782-6-git-send-email-madalin.bucur@freescale.com> X-Mailer: git-send-email 1.5.6.5 In-Reply-To: <1446485500-9782-1-git-send-email-madalin.bucur@freescale.com> References: <1446485500-9782-1-git-send-email-madalin.bucur@freescale.com> Reply-To: X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;BL2FFO11FD014;1:5rkW5V4ECaGCv27wi8v2TaT5g6rqgVMws8h30uSAPRgTrm6T/RHKJpHDNyeedd0Xdmt8XoCQKD09RNWirizknMSNat8Xip44e3Ev7f65om/lCsznqJgtBfD4IBJeKDWiun/f6/h6ZM20c8hFUX2JWEhHP15D0erakn0y9+g+TOq5JvV/qnKy3UMb72Yk6BCaZrmi1pKo2tq/AafViNM0zrnrWS6lszLVPcck016MzKy8WFjDRy+rcB3F+9IRn+r++AV/j6iSPCV5nr5eDnCoc320QimGh0w8/gcL0EC+uVDzSyZVYaG9pO1Bo5+HQmIUfD/+MU+SnwF+0XTJFsz8bto06shSXxrFLBt6fSMdGgk5PaE8J42m7vb3OqlIgfJBECK6Zv+u3gwvv0mlS29osg== X-Forefront-Antispam-Report: CIP:192.88.168.50;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(19580405001)(19580395003)(87936001)(50466002)(50986999)(11100500001)(76176999)(36756003)(5007970100001)(33646002)(104016004)(47776003)(48376002)(50226001)(4001430100002)(6806005)(53806999)(2351001)(107886002)(229853001)(2950100001)(85426001)(105606002)(49486002)(106466001)(5003940100001)(110136002)(97736004)(81156007)(5001960100002)(43066003)(189998001)(77096005)(86362001)(5008740100001)(2004002)(309714004);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB507;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;BY2PR03MB507;2:Fq9xJDsf2CWSa8yHMhyp10CDK8L9SyTkz5EnlyT7ra2xidSgPTepGCi19IWu5PkMdMaJ6WuvuAV/TH0cy1rWSmDU0QxH9CblG26K91nZafDTUktBA+NEgMgPlRUey6bMfIVxlgjm0IASOcqOTObHJS/OzUCgstrXci0k4J3yL1Y=;3:wcRh3yWsk7pqo9r4txANDB0Az4cqxfXnYLj6f/XhmbSClMSF+DACXqB7BCXislc5fzVttPG3owZ3/FWTDtWYog92zRgTHss47vE71QFbkd3sds49NgEaxnFUkiVuJ69ODtW4tqcczDQc5Dz+8R46mf7OIDYHV1Zu/5uXIfjyfFbpOTK6mdAFUnhX4zzdOqD5plYSQr+Yop5Sr42RyBOIse/D+57yUkCNyAPktZBcNSg=;25:bXPyrMBJaYhh/3B68pET9SWHrlt32fmy/Mp9Q13hvatZ6N+TaKOEABZKSu/CmNCM3yjWz3N+5SrXhCyUtkjYLFXknJV3nOwhx39pdKd5QmT6qtJ/GwdSFoCpSSnVK5g6OZmrehozMC19X0uiao2fXFa61ekqhZEFDxNWOCy+wWLcnMraoRFiw5NKz1DzEokWbOsLascjRqTwPZvBa6xfHSlAVUhZzJQizmASw2s4Kr5z+D2TRwLzy3b9VnnPerlwTSJ9lwR6x2RhF77ETdD+XA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB507; X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB507;20:eyPbV1g604RwWvcxTwRP6QFgBNeliYWaNHj7QqhWURQC2+4fUwMqtBbonDIAGW26bzBUGaUrmR8D6PKGdArI7eYMjI0hyOVJ+U27gAlflBEX5qRxHvF591B9aRDMnRa9F2Sv8cQAAwXyUEyVnhaQnEp7O8ix9XtE/JePNd4IuT9G9YPTlNKECqRcguxBiP4KBizx5mdI8QU1Db3T9gcPsiguCYGOgs6bVdJ1Gl3GvNMbUuFLMeLiMEUyVZGrw2Vh20N6sqcglHy01IeJpLau+6ocDSzAZUPWZTHHBwgTVdT5VWCab7S9iH2k0gC2w00goBO13MWJer1UqMXg0f3mmSALmU6xkgGkc8fLiWLYGzk=;4:RSd86+UFv44JpI0NH/naSDr+ulF/delFXXFAzgR65/opQN0ckjeS10sDHeMCZLbJOWXFzWUOAW98xktnIZOOhsD8L1MsylalKbKBA3H36iwwcUGECzxyfIR+cYY/4VaTKzx9T13G60fXM3EOY3wZ/Lc1yaJDDepqHEneX9zsvGJS9J+CLgFl7mF5FBJLWmAmXS70bX+QT5ZdYhbUIdYubiqf88Ljr1a+pWldzoGtbKZBeobeZpYmMpZnnt2WJ+DR8f/VcBiVF7rw8aS2HeY1IaIXPc9gWq3sRbYZe/fhJaCMEz4JYqA2Mygr75geIl054T6PqdWSmGwq+J0PDtdrZf4AB3E/PCJHkEa9fOTn0BijmN/OIdXQK8ooDkNhumT/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(101931422205132); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(520078)(5005006)(8121501046)(10201501046)(3002001);SRVR:BY2PR03MB507;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB507; X-Forefront-PRVS: 0748FF9A04 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR03MB507;23:cPadSNWA3jrnOSXvyh7syzLjaK8AKsLjF5x4b1DB9V?= =?us-ascii?Q?eFxQ2JG2co3JTRT5HB7jWuouSOXyud/4tmVWqqTVJ73RN5j3XwSSiOz6Xyxi?= =?us-ascii?Q?Cz+NBqTKlk470VLhx2gnv5vzMNf18C+T+3aQeo9KpGphhMfcVntIoYyKuSwV?= =?us-ascii?Q?LWQacQUwOrsm4NqhRREqNfytIF3mJnfxheGOSQw0qOspk6cJZjjdvCow73yD?= =?us-ascii?Q?HlzN3EShfN4PTF8hN1epGbYRhwD3JSCRsurXgPgZzWXmWUMaFPv2Tl7BnTCv?= =?us-ascii?Q?6xItGYpepz52XDPA8jd4ovYCrCeu4PTuyF/ta/EV+bP0xLmmE3g42ySU+x1V?= =?us-ascii?Q?3W+qgxkTw8wBjY+RAuQWMp7dTiz4iAjhztXsmV/djXT3s8xLVFfRhL1dWCGe?= =?us-ascii?Q?Nycfcziw2krBz/DzTc1oz0FKCyTzQxt6swZ/eIKpvbV2URZxtU9p20JQJEWG?= =?us-ascii?Q?He7Rla3S21TZ09QHrEr2mFFwk830JmRjeVc5wn+54uWmbuyKYYskxfDuNC+o?= =?us-ascii?Q?Ok+GG+RTmcYdViNgJZyA+8SoSH9+ia/xOjOs1yZK+G55hMhyrqtPBcvJHatV?= =?us-ascii?Q?dkNV/ZTSXTz4SLZKbdd/jQsdZFVE4U0vWRxzVu8Ed4jpgFKdFpavya/589ZM?= =?us-ascii?Q?+uBCwVtNd+472UcmOFKwbE/39h++dZmkm/7EWk5VFU+qu3aFF9DoCKm29vP1?= =?us-ascii?Q?efq50JbV17wfK6n6JNcVVPFRm8smyhwpTWBkZXUhnaWXvmL8Cuc9egupvPvG?= =?us-ascii?Q?WdziSQyqUHGEtkeRWfA+ktmFGD9fVAp2Xw0wbL8v0Gn80ooaExBtiieSWEB2?= =?us-ascii?Q?AtLLjHQ6qN59tblJLji9Euy8KVeFstwyn40jVH66qYd98M8kqwyuwgYfqUQo?= =?us-ascii?Q?UmIaZRIZ6rIkXetp1da8iegNY9kRSviiIQeF3IGIcH0N+RqePrITFerzK0cB?= =?us-ascii?Q?klD36Dw6wE4y2Z+Q+77/i3d9ngpZth8M8DuS16UNsdvI2BXsyM59ZTYShMB/?= =?us-ascii?Q?bWkN1Od1IhZVplaIQDFiZOOkv1HXJIH+6sLApJMzG9GKjWOIS+RhyhqJXIUd?= =?us-ascii?Q?cUInH2u6KxTTIAj3SWu2vYHr86Fnv5SGJTY7Tg7SbeTc2ktHEdiO/hP1MEOb?= =?us-ascii?Q?u20HMtU43HlxipGc0MU8udCMcD8AE01eoe8zmYrhUDr5IgIs8ohjnLUVPRgS?= =?us-ascii?Q?pHx/HbNkcnHc4=3D?= X-Microsoft-Exchange-Diagnostics: 1;BY2PR03MB507;5:E7Q10Tnm3R72AOo//VU/ICGWSwVj8YI3hGccPDLwc0Ktzm8BPNwtKsUe/fwC3LMPPyUXtUyeOLepROliExkc1AKYzoHzhR8pp8rI1enwEzi111xN1Oa1+McOaIXTcKTddTFjT1i/mqRVDxTNK4k0Lg==;24:YPfO8GnVQ+HZVCDV/pwJKtcJc0h2zCRDwTofcaSCS0yiLNSh6E5QCAIOrdSq+4WDAW8I4SHcqio2FnBUdy+xEvixGc5NdCyByMrTAghGK2c=;20:myVb+YoaPYnWrwCHW75zQP9AD9Vn+UdXBxlrnBgPLZWtia1nu3xTQK8CbCIcZrW9P+YcMqhV5unilb5cgJ4G9w== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Nov 2015 16:34:07.3845 (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: BY2PR03MB507 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9516 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 89f3b1f..2b95696 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth_common.c @@ -102,6 +102,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 2e9471d..160a018 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 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..fa8ba69 --- /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); + } + } + + 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/