From patchwork Fri Sep 11 19:52:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 261030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE049C433E2 for ; Fri, 11 Sep 2020 19:53:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9228B21D40 for ; Fri, 11 Sep 2020 19:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599854005; bh=Ph/f4f3N+/51J9/281WZCk71daYOTWMjONLYjZH7HtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RWk04UMgmprin0pg0C0NsyVG+G7tt0IZdAz8GPXHywZNfaKgroBJAO/m+EuaOVPvD 7x0QLNBkXXXw6sNwobgCg0v2GhE2We4HX38UowaMdTGkjRXzgZinhHJGWWoNTzPbNX 0koO725S/9n77xlYxNHcOnbJ6sF+udxdaBgoxfak= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725855AbgIKTxX (ORCPT ); Fri, 11 Sep 2020 15:53:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:49170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbgIKTxI (ORCPT ); Fri, 11 Sep 2020 15:53:08 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9BD45221E5; Fri, 11 Sep 2020 19:53:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599853988; bh=Ph/f4f3N+/51J9/281WZCk71daYOTWMjONLYjZH7HtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=itVntQN13YBy2/eXJCxDFOdW6vCswFF+DJ5FFBPw7nyk+EkKgYWwKWlhvTINU3BWx gObCt36BR+L3AhEMP8aOfMDIc6csfmJ4C7V+2hyFzQbxuhu+ZhSnnldxFmvZPN9Ahm MCOcIadmMVvA8JQFOlK47Ohtic3V9JuD7tLh85MM= From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, mkubecek@suse.cz, michael.chan@broadcom.com, tariqt@nvidia.com, saeedm@nvidia.com, alexander.duyck@gmail.com, andrew@lunn.ch, Jakub Kicinski Subject: [PATCH net-next 2/8] docs: net: include the new ethtool pause stats in the stats doc Date: Fri, 11 Sep 2020 12:52:52 -0700 Message-Id: <20200911195258.1048468-3-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911195258.1048468-1-kuba@kernel.org> References: <20200911195258.1048468-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Tell people that there now is an interface for querying pause frames. A little bit of restructuring is needed given this is a first source of such statistics. Signed-off-by: Jakub Kicinski --- Documentation/networking/statistics.rst | 57 ++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/statistics.rst b/Documentation/networking/statistics.rst index d490b535cd14..8e15bc98830b 100644 --- a/Documentation/networking/statistics.rst +++ b/Documentation/networking/statistics.rst @@ -4,16 +4,23 @@ Interface statistics ==================== +Overview +======== + This document is a guide to Linux network interface statistics. -There are two main sources of interface statistics in Linux: +There are three main sources of interface statistics in Linux: - standard interface statistics based on - :c:type:`struct rtnl_link_stats64 `; and + :c:type:`struct rtnl_link_stats64 `; + - protocol-specific statistics; and - driver-defined statistics available via ethtool. -There are multiple interfaces to reach the former. Most commonly used -is the `ip` command from `iproute2`:: +Standard interface statistics +----------------------------- + +There are multiple interfaces to reach the standard statistics. +Most commonly used is the `ip` command from `iproute2`:: $ ip -s -s link show dev ens4u1u1 6: ens4u1u1: mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 @@ -34,7 +41,26 @@ If `-s` is specified once the detailed errors won't be shown. `ip` supports JSON formatting via the `-j` option. -Ethtool statistics can be dumped using `ethtool -S $ifc`, e.g.:: +Protocol-specific statistics +---------------------------- + +Some of the interfaces used for configuring devices are also able +to report related statistics. For example ethtool interface used +to configure pause frames can report corresponding hardware counters:: + + $ ethtool --include-statistics -a eth0 + Pause parameters for eth0: + Autonegotiate: on + RX: on + TX: on + Statistics: + tx_pause_frames: 1 + rx_pause_frames: 1 + +Driver-defined statistics +------------------------- + +Driver-defined ethtool statistics can be dumped using `ethtool -S $ifc`, e.g.:: $ ethtool -S ens4u1u1 NIC statistics: @@ -94,6 +120,17 @@ Identifiers via `ETHTOOL_GSTRINGS` with `string_set` set to `ETH_SS_STATS`, and values via `ETHTOOL_GSTATS`. User space should use `ETHTOOL_GDRVINFO` to retrieve the number of statistics (`.n_stats`). +ethtool-netlink +--------------- + +Ethtool netlink is a replacement for the older IOCTL interface. + +Protocol-related statistics can be requested in get commands by setting +the `ETHTOOL_FLAG_STATS` flag in `ETHTOOL_A_HEADER_FLAGS`. Currently +statistics are supported in the following commands: + + - `ETHTOOL_MSG_PAUSE_GET` + debugfs ------- @@ -130,3 +167,13 @@ user space trying to read them. Statistics must persist across routine operations like bringing the interface down and up. + +Kernel-internal data structures +------------------------------- + +The following structures are internal to the kernel, their members are +translated to netlink attributes when dumped. Drivers must not overwrite +the statistics they don't report with 0. + +.. kernel-doc:: include/linux/ethtool.h + :identifiers: ethtool_pause_stats From patchwork Fri Sep 11 19:52:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 261027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F33BC433E2 for ; Fri, 11 Sep 2020 19:53:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A7DF21D47 for ; Fri, 11 Sep 2020 19:53:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599854037; bh=KJF7bJVcFHTp+5exX6TlKst7sG/NZgxplJI4PAsSJCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=RUmcAjIP7H6dnZksRZu4DnUgq0r00UjbIGngf9lo9LV9OKnMqVCgqS2sCTFKZFTPI T0Ixm3CYz1r3dRzabJ7UH6HOYf08d9LlgFdwGEXZ+iDD2BjGF5PE7naf216V/WYvot cvXpaTwlfiLLuDVfo5crtBngfTmL1tNUQW25NVJw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725931AbgIKTxz (ORCPT ); Fri, 11 Sep 2020 15:53:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:49244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725802AbgIKTxJ (ORCPT ); Fri, 11 Sep 2020 15:53:09 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F5DE22209; Fri, 11 Sep 2020 19:53:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599853988; bh=KJF7bJVcFHTp+5exX6TlKst7sG/NZgxplJI4PAsSJCQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y8G2J5M9aumFjVfygDWvN+wxOLMJaCZt+R10ChBHTuOusf2IRa8FdwIzAMzM/WrtL kXtusrSNrJbIkzvlXj9U7pnT9n9obLLCza23ladM/GnGuYXpJPvp+okkiYuHvSYntR fLOz4M9JLjIzRa34ukPjPCN5DD8ivoqdbui0kU9U= From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, mkubecek@suse.cz, michael.chan@broadcom.com, tariqt@nvidia.com, saeedm@nvidia.com, alexander.duyck@gmail.com, andrew@lunn.ch, Jakub Kicinski Subject: [PATCH net-next 3/8] netdevsim: add pause frame stats Date: Fri, 11 Sep 2020 12:52:53 -0700 Message-Id: <20200911195258.1048468-4-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911195258.1048468-1-kuba@kernel.org> References: <20200911195258.1048468-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add minimal ethtool interface for testing ethtool pause stats. Signed-off-by: Jakub Kicinski --- drivers/net/netdevsim/Makefile | 2 +- drivers/net/netdevsim/ethtool.c | 64 +++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdev.c | 1 + drivers/net/netdevsim/netdevsim.h | 11 ++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 drivers/net/netdevsim/ethtool.c diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile index 4dfb389dbfd8..ade086eed955 100644 --- a/drivers/net/netdevsim/Makefile +++ b/drivers/net/netdevsim/Makefile @@ -3,7 +3,7 @@ obj-$(CONFIG_NETDEVSIM) += netdevsim.o netdevsim-objs := \ - netdev.o dev.o fib.o bus.o health.o udp_tunnels.o + netdev.o dev.o ethtool.o fib.o bus.o health.o udp_tunnels.o ifeq ($(CONFIG_BPF_SYSCALL),y) netdevsim-objs += \ diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c new file mode 100644 index 000000000000..7c016edfbcee --- /dev/null +++ b/drivers/net/netdevsim/ethtool.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2020 Facebook + +#include +#include +#include + +#include "netdevsim.h" + +static void +nsim_get_pause_stats(struct net_device *dev, + struct ethtool_pause_stats *pause_stats) +{ + struct netdevsim *ns = netdev_priv(dev); + + if (ns->ethtool.report_stats_rx) + pause_stats->rx_pause_frames = 1; + if (ns->ethtool.report_stats_tx) + pause_stats->tx_pause_frames = 2; +} + +static void +nsim_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) +{ + struct netdevsim *ns = netdev_priv(dev); + + pause->autoneg = 0; /* We don't support ksettings, so can't pretend */ + pause->rx_pause = ns->ethtool.rx; + pause->tx_pause = ns->ethtool.tx; +} + +static int +nsim_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) +{ + struct netdevsim *ns = netdev_priv(dev); + + if (pause->autoneg) + return -EINVAL; + + ns->ethtool.rx = pause->rx_pause; + ns->ethtool.tx = pause->tx_pause; + return 0; +} + +const struct ethtool_ops nsim_ethtool_ops = { + .get_pause_stats = nsim_get_pause_stats, + .get_pauseparam = nsim_get_pauseparam, + .set_pauseparam = nsim_set_pauseparam, +}; + +void nsim_ethtool_init(struct netdevsim *ns) +{ + struct dentry *ethtool, *dir; + + ns->netdev->ethtool_ops = &nsim_ethtool_ops; + + ethtool = debugfs_create_dir("ethtool", ns->nsim_dev->ddir); + + dir = debugfs_create_dir("pause", ethtool); + debugfs_create_bool("report_stats_rx", 0600, dir, + &ns->ethtool.report_stats_rx); + debugfs_create_bool("report_stats_tx", 0600, dir, + &ns->ethtool.report_stats_tx); +} diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 97cfb015a50b..7178468302c8 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -301,6 +301,7 @@ nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) ns->nsim_bus_dev = nsim_dev->nsim_bus_dev; SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev); dev->netdev_ops = &nsim_netdev_ops; + nsim_ethtool_init(ns); err = nsim_udp_tunnels_info_create(nsim_dev, dev); if (err) diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 284f7092241d..0c86561e6d8d 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -50,6 +50,13 @@ struct nsim_ipsec { u32 ok; }; +struct nsim_ethtool { + bool rx; + bool tx; + bool report_stats_rx; + bool report_stats_tx; +}; + struct netdevsim { struct net_device *netdev; struct nsim_dev *nsim_dev; @@ -80,12 +87,16 @@ struct netdevsim { u32 ports[2][NSIM_UDP_TUNNEL_N_PORTS]; struct debugfs_u32_array dfs_ports[2]; } udp_ports; + + struct nsim_ethtool ethtool; }; struct netdevsim * nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port); void nsim_destroy(struct netdevsim *ns); +void nsim_ethtool_init(struct netdevsim *ns); + void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev); int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev, struct net_device *dev); From patchwork Fri Sep 11 19:52:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 261029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 644E1C43461 for ; Fri, 11 Sep 2020 19:53:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2664421D47 for ; Fri, 11 Sep 2020 19:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599854019; bh=9mnPGUv9uaaxuD+AUwBraGGLo2itRuGs+sBhGxoa66k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iFQBt6eJZqwHjS6CBBA2v513SdRunMlB6g56EGyagaXZCZGTBU8ypMfXy8euTgcR+ v351tezaSvIGVVUOd99r5u6wk7iYi7i9szr/K1l2qWIjYgqg4Y/AUImLiLBxF3y5WK 8/AqAyuuZxmutY/JnfgCJitfgV9NMW7FDJd1mT+Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725895AbgIKTxg (ORCPT ); Fri, 11 Sep 2020 15:53:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:49376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbgIKTxK (ORCPT ); Fri, 11 Sep 2020 15:53:10 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 379AE2220F; Fri, 11 Sep 2020 19:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599853989; bh=9mnPGUv9uaaxuD+AUwBraGGLo2itRuGs+sBhGxoa66k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=otMWIVdEZ5t7BCurqde2Q2KuPDgPURvWJWgUPkBuXhmj6Sl5BwqpInLHAeoO9NeJD dKb7qMGkunGa4ete85Rc4onHcgnxTuO273vX4i4hWcdNfHYqhH7iJSy+2evQlaA9Y5 qcYmmyRz7UzqIj38s/q5Y1pMB31c1wO5X6JK9HaQ= From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, mkubecek@suse.cz, michael.chan@broadcom.com, tariqt@nvidia.com, saeedm@nvidia.com, alexander.duyck@gmail.com, andrew@lunn.ch, Jakub Kicinski Subject: [PATCH net-next 5/8] bnxt: add pause frame stats Date: Fri, 11 Sep 2020 12:52:55 -0700 Message-Id: <20200911195258.1048468-6-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911195258.1048468-1-kuba@kernel.org> References: <20200911195258.1048468-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org These stats are already reported in ethtool -S. Hopefully they are equivalent to standard stats? Signed-off-by: Jakub Kicinski --- .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c index d0928334bdc8..b5de242766e3 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c @@ -1778,6 +1778,24 @@ static void bnxt_get_pauseparam(struct net_device *dev, epause->tx_pause = !!(link_info->req_flow_ctrl & BNXT_LINK_PAUSE_TX); } +static void bnxt_get_pause_stats(struct net_device *dev, + struct ethtool_pause_stats *epstat) +{ + struct bnxt *bp = netdev_priv(dev); + struct rx_port_stats *rx_stats; + struct tx_port_stats *tx_stats; + + if (BNXT_VF(bp) || !(bp->flags & BNXT_FLAG_PORT_STATS)) + return; + + rx_stats = (void *)bp->port_stats.sw_stats; + tx_stats = (void *)((unsigned long)bp->port_stats.sw_stats + + BNXT_TX_PORT_STATS_BYTE_OFFSET); + + epstat->rx_pause_frames = rx_stats->rx_pause_frames; + epstat->tx_pause_frames = tx_stats->tx_pause_frames; +} + static int bnxt_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause) { @@ -3645,6 +3663,7 @@ const struct ethtool_ops bnxt_ethtool_ops = { ETHTOOL_COALESCE_USE_ADAPTIVE_RX, .get_link_ksettings = bnxt_get_link_ksettings, .set_link_ksettings = bnxt_set_link_ksettings, + .get_pause_stats = bnxt_get_pause_stats, .get_pauseparam = bnxt_get_pauseparam, .set_pauseparam = bnxt_set_pauseparam, .get_drvinfo = bnxt_get_drvinfo, From patchwork Fri Sep 11 19:52:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Kicinski X-Patchwork-Id: 261028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6504C43461 for ; Fri, 11 Sep 2020 19:53:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9EE3321D91 for ; Fri, 11 Sep 2020 19:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599854026; bh=SgGaruUhbNKZhfT9Vgnq5KsepX5ELpF/tfeZ83x7HnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=A3MNHV90YzHJ622D8NL1lfSB1KTEGaHT6RIvZShWVMReeiP1uF+1vlTsE170y0q9/ dug9y1wlIiRgI5sWCPw8W7vM8w+SEl/5MXIn7xxZ14RJHc5rlfs3ILFl0Iw1bqY0mH lxWjpB80zIsgvJ9+oV7dqe5isPuQg/W2pngsGTbA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725921AbgIKTxn (ORCPT ); Fri, 11 Sep 2020 15:53:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgIKTxL (ORCPT ); Fri, 11 Sep 2020 15:53:11 -0400 Received: from kicinski-fedora-PC1C0HJN.thefacebook.com (unknown [163.114.132.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C011B21D40; Fri, 11 Sep 2020 19:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599853990; bh=SgGaruUhbNKZhfT9Vgnq5KsepX5ELpF/tfeZ83x7HnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JaeOIdazLrQvmCSHCqJ1O84MUF4rViYtRNrVYj6u/Im3oiQN96eRBRZ9K7Qz5/6ax 7ZbCBqxz4L6gux37Ra3PPhvsn/ALilWypXSzyp9uh8/K3hIdW5koX6wrW7LpNrTbif QIYa3nOg4nlDfi24aaz+c033/QVW+oWnS+/kyTKw= From: Jakub Kicinski To: davem@davemloft.net Cc: netdev@vger.kernel.org, mkubecek@suse.cz, michael.chan@broadcom.com, tariqt@nvidia.com, saeedm@nvidia.com, alexander.duyck@gmail.com, andrew@lunn.ch, Jakub Kicinski Subject: [PATCH net-next 6/8] mlx5: add pause frame stats Date: Fri, 11 Sep 2020 12:52:56 -0700 Message-Id: <20200911195258.1048468-7-kuba@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200911195258.1048468-1-kuba@kernel.org> References: <20200911195258.1048468-1-kuba@kernel.org> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Plumb through all the indirection and copy some code from ethtool -S. The names of the group indicate that these are the stats we are after. Signed-off-by: Jakub Kicinski --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 ++ .../ethernet/mellanox/mlx5/core/en_ethtool.c | 15 ++++++++++ .../net/ethernet/mellanox/mlx5/core/en_rep.c | 9 ++++++ .../ethernet/mellanox/mlx5/core/en_stats.c | 30 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en_stats.h | 3 ++ 5 files changed, 59 insertions(+) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 4f33658da25a..615ac0dc248e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -1053,6 +1053,8 @@ int mlx5e_ethtool_get_ts_info(struct mlx5e_priv *priv, struct ethtool_ts_info *info); int mlx5e_ethtool_flash_device(struct mlx5e_priv *priv, struct ethtool_flash *flash); +void mlx5e_ethtool_get_pause_stats(struct mlx5e_priv *priv, + struct ethtool_pause_stats *pause_stats); void mlx5e_ethtool_get_pauseparam(struct mlx5e_priv *priv, struct ethtool_pauseparam *pauseparam); int mlx5e_ethtool_set_pauseparam(struct mlx5e_priv *priv, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index 5cb1e4839eb7..c9fb3c018b96 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -1341,6 +1341,20 @@ static int mlx5e_set_tunable(struct net_device *dev, return err; } +void mlx5e_ethtool_get_pause_stats(struct mlx5e_priv *priv, + struct ethtool_pause_stats *pause_stats) +{ + mlx5e_stats_pause_get(priv, pause_stats); +} + +static void mlx5e_get_pause_stats(struct net_device *netdev, + struct ethtool_pause_stats *pause_stats) +{ + struct mlx5e_priv *priv = netdev_priv(netdev); + + mlx5e_ethtool_get_pause_stats(priv, pause_stats); +} + void mlx5e_ethtool_get_pauseparam(struct mlx5e_priv *priv, struct ethtool_pauseparam *pauseparam) { @@ -2033,6 +2047,7 @@ const struct ethtool_ops mlx5e_ethtool_ops = { .set_rxnfc = mlx5e_set_rxnfc, .get_tunable = mlx5e_get_tunable, .set_tunable = mlx5e_set_tunable, + .get_pause_stats = mlx5e_get_pause_stats, .get_pauseparam = mlx5e_get_pauseparam, .set_pauseparam = mlx5e_set_pauseparam, .get_ts_info = mlx5e_get_ts_info, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index 135ee26881c9..856ae4c8cb25 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -288,6 +288,14 @@ static u32 mlx5e_rep_get_rxfh_indir_size(struct net_device *netdev) return mlx5e_ethtool_get_rxfh_indir_size(priv); } +static void mlx5e_uplink_rep_get_pause_stats(struct net_device *netdev, + struct ethtool_pause_stats *stats) +{ + struct mlx5e_priv *priv = netdev_priv(netdev); + + mlx5e_ethtool_get_pause_stats(priv, stats); +} + static void mlx5e_uplink_rep_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pauseparam) { @@ -362,6 +370,7 @@ static const struct ethtool_ops mlx5e_uplink_rep_ethtool_ops = { .set_rxfh = mlx5e_set_rxfh, .get_rxnfc = mlx5e_get_rxnfc, .set_rxnfc = mlx5e_set_rxnfc, + .get_pause_stats = mlx5e_uplink_rep_get_pause_stats, .get_pauseparam = mlx5e_uplink_rep_get_pauseparam, .set_pauseparam = mlx5e_uplink_rep_set_pauseparam, }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c index e3b2f59408e6..97b03aa7535f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.c @@ -677,6 +677,36 @@ static MLX5E_DECLARE_STATS_GRP_OP_UPDATE_STATS(802_3) mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); } +#define MLX5E_READ_CTR64_BE_F(ptr, c) \ + be64_to_cpu(*(__be64 *)((char *)ptr + \ + MLX5_BYTE_OFF(ppcnt_reg, \ + counter_set.eth_802_3_cntrs_grp_data_layout.c##_high))) + +void mlx5e_stats_pause_get(struct mlx5e_priv *priv, + struct ethtool_pause_stats *pause_stats) +{ + struct mlx5e_pport_stats *pstats = &priv->stats.pport; + struct mlx5_core_dev *mdev = priv->mdev; + u32 in[MLX5_ST_SZ_DW(ppcnt_reg)] = {0}; + int sz = MLX5_ST_SZ_BYTES(ppcnt_reg); + void *out; + + if (!MLX5_BASIC_PPCNT_SUPPORTED(mdev)) + return; + + MLX5_SET(ppcnt_reg, in, local_port, 1); + out = pstats->IEEE_802_3_counters; + MLX5_SET(ppcnt_reg, in, grp, MLX5_IEEE_802_3_COUNTERS_GROUP); + mlx5_core_access_reg(mdev, in, sz, out, sz, MLX5_REG_PPCNT, 0, 0); + + pause_stats->tx_pause_frames = + MLX5E_READ_CTR64_BE_F(&priv->stats.pport.IEEE_802_3_counters, + a_pause_mac_ctrl_frames_transmitted); + pause_stats->rx_pause_frames = + MLX5E_READ_CTR64_BE_F(&priv->stats.pport.IEEE_802_3_counters, + a_pause_mac_ctrl_frames_received); +} + #define PPORT_2863_OFF(c) \ MLX5_BYTE_OFF(ppcnt_reg, \ counter_set.eth_2863_cntrs_grp_data_layout.c##_high) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h index 2e1cca1923b9..9d9ee269a041 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h @@ -104,6 +104,9 @@ void mlx5e_stats_update(struct mlx5e_priv *priv); void mlx5e_stats_fill(struct mlx5e_priv *priv, u64 *data, int idx); void mlx5e_stats_fill_strings(struct mlx5e_priv *priv, u8 *data); +void mlx5e_stats_pause_get(struct mlx5e_priv *priv, + struct ethtool_pause_stats *pause_stats); + /* Concrete NIC Stats */ struct mlx5e_sw_stats {