From patchwork Mon Jan 20 11:13:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Jensen X-Patchwork-Id: 3511611 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7AD479F2E9 for ; Mon, 20 Jan 2014 11:16:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9771E2013D for ; Mon, 20 Jan 2014 11:16:00 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BEA592010E for ; Mon, 20 Jan 2014 11:15:55 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5Coj-00058Z-Oy; Mon, 20 Jan 2014 11:14:58 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5CoZ-0001wl-Is; Mon, 20 Jan 2014 11:14:47 +0000 Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W5Co8-0001sE-Nu for linux-arm-kernel@lists.infradead.org; Mon, 20 Jan 2014 11:14:21 +0000 Received: by mail-lb0-f170.google.com with SMTP id u14so4778936lbd.15 for ; Mon, 20 Jan 2014 03:13:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RAhmJDN4TRpciQ0fWO14qWAk5CRs2b1OjbG8We7k0wA=; b=CXyQrcGfPnEOddLS40qr+NgM7IU/LlP/06QnQLDuLKoOEnFFmceG9Vj0HscQV85dKd bDsM/fBWiAcumH25Xm4ZGu6s1XP5uiYkfXK4Wdqusw8SLhwjfB8/WjtmXeBdS2NUJwHK 5//qvPEfJKIDG5dls2H0yifU4/jHo4B4vDmSWPDWtkNZbnh+7l1mUAYPcn/EGUw0z6gl TFJVy8baK6+gZCQfwwUfhQmiEEvXExjo0zcQNlMT9DT63Bme5RJkcGYnhJI3CqtlqkRL 8mVekh9pYmHorJaPRUjVc+sfJyN3ed3P8qk42Y/Z7NDzZ00j6qujF7ccHM7bIp7We+2e FjfQ== X-Received: by 10.112.45.108 with SMTP id l12mr11085491lbm.21.1390216437339; Mon, 20 Jan 2014 03:13:57 -0800 (PST) Received: from Ildjarn.ath.cx (static-213-115-41-10.sme.bredbandsbolaget.se. [213.115.41.10]) by mx.google.com with ESMTPSA id sv5sm551815lbb.9.2014.01.20.03.13.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 20 Jan 2014 03:13:56 -0800 (PST) From: Jonas Jensen To: netdev@vger.kernel.org Subject: [PATCH v3 4/7] net: moxa: add ethtool support Date: Mon, 20 Jan 2014 12:13:16 +0100 Message-Id: <1390216399-27028-4-git-send-email-jonas.jensen@gmail.com> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1390216399-27028-1-git-send-email-jonas.jensen@gmail.com> References: <1390216399-27028-1-git-send-email-jonas.jensen@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140120_061420_927593_5AFF8A44 X-CRM114-Status: GOOD ( 13.49 ) X-Spam-Score: -2.0 (--) Cc: f.fainelli@gmail.com, linux-kernel@vger.kernel.org, Jonas Jensen , bhutchings@solarflare.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add and assign ethtool_ops callback functions. Signed-off-by: Jonas Jensen --- Notes: Applies to next-20140120 drivers/net/ethernet/moxa/moxart_ether.c | 121 +++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/drivers/net/ethernet/moxa/moxart_ether.c b/drivers/net/ethernet/moxa/moxart_ether.c index c19bff2..ca892bb 100644 --- a/drivers/net/ethernet/moxa/moxart_ether.c +++ b/drivers/net/ethernet/moxa/moxart_ether.c @@ -31,6 +31,10 @@ #include "moxart_ether.h" +#define DRV_NAME "moxart-ethernet" +#define DRV_VERSION "0.2" +#define MOXART_NUM_STATS ARRAY_SIZE(ethtool_stats_keys) + static inline void moxart_emac_write(struct net_device *ndev, unsigned int reg, unsigned long value) { @@ -63,6 +67,122 @@ static int moxart_set_mac_address(struct net_device *ndev, void *addr) return 0; } +static struct { + const char str[ETH_GSTRING_LEN]; +} ethtool_stats_keys[] = { + { "tx_ok_mcol_2to15" }, + { "tx_ok_1col" }, + { "rx_frame_pause" }, + { "frame_align_err" }, + { "err_col_late_16" }, + { "err_col_16" }, + { "rx_runt" }, + { "late_col" }, + { "crc_err" }, + { "rx_ftl" }, + { "rx_fifo_full" }, + { "rx_col" }, + { "rx_bcast" }, + { "rx_mcast" }, + { "rx_ok" }, + { "tx_ok" }, +}; + +static void moxart_get_drvinfo(struct net_device *ndev, + struct ethtool_drvinfo *info) +{ + strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); + strlcpy(info->version, DRV_VERSION, sizeof(info->version)); + strlcpy(info->bus_info, dev_name(&ndev->dev), sizeof(info->bus_info)); +} + +static int moxart_get_settings(struct net_device *ndev, struct ethtool_cmd *cmd) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + + return phy_ethtool_gset(priv->phy_dev, cmd); +} + +static int moxart_set_settings(struct net_device *ndev, struct ethtool_cmd *cmd) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + + return phy_ethtool_sset(priv->phy_dev, cmd); +} + +static int moxart_nway_reset(struct net_device *ndev) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + + return genphy_restart_aneg(priv->phy_dev); +} + +static void moxart_get_ethtool_stats(struct net_device *ndev, + struct ethtool_stats *estats, + u64 *tmp_stats) +{ + struct moxart_mac_priv_t *priv = netdev_priv(ndev); + u32 s; + int i = 0; + + s = readl(priv->base + REG_TX_COL_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + s = readl(priv->base + REG_RPF_AEP_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + s = readl(priv->base + REG_XM_PG_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + s = readl(priv->base + REG_RUNT_TLC_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + s = readl(priv->base + REG_CRC_FTL_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + s = readl(priv->base + REG_RLC_RCC_COUNTER); + tmp_stats[i++] = s & 0xffff0000; + tmp_stats[i++] = s & 0x0000ffff; + tmp_stats[i++] = readl(priv->base + REG_BROC_COUNTER); + tmp_stats[i++] = readl(priv->base + REG_MULCA_COUNTER); + tmp_stats[i++] = readl(priv->base + REG_XP_COUNTER); + tmp_stats[i++] = readl(priv->base + REG_RP_COUNTER); +} + +static int moxart_get_sset_count(struct net_device *netdev, + int string_set) +{ + switch (string_set) { + case ETH_SS_STATS: + return MOXART_NUM_STATS; + default: + return -EINVAL; + } +} + +static void moxart_get_strings(struct net_device *dev, u32 stringset, u8 *data) +{ + switch (stringset) { + case ETH_SS_STATS: + memcpy(data, ðtool_stats_keys, sizeof(ethtool_stats_keys)); + break; + default: + WARN_ON(1); + break; + } +} + +static const struct ethtool_ops moxart_ethtool_ops = { + .set_settings = moxart_set_settings, + .get_settings = moxart_get_settings, + .get_drvinfo = moxart_get_drvinfo, + .nway_reset = moxart_nway_reset, + .get_link = ethtool_op_get_link, + .get_ethtool_stats = moxart_get_ethtool_stats, + .get_sset_count = moxart_get_sset_count, + .get_strings = moxart_get_strings, +}; + static int moxart_do_ioctl(struct net_device *ndev, struct ifreq *ir, int cmd) { struct moxart_mac_priv_t *priv = netdev_priv(ndev); @@ -612,6 +732,7 @@ static int moxart_mac_probe(struct platform_device *pdev) ndev->irq = irq; SET_NETDEV_DEV(ndev, &pdev->dev); + SET_ETHTOOL_OPS(ndev, &moxart_ethtool_ops); ret = register_netdev(ndev); if (ret) {