From: Dennis Chen <dechen@redhat.com>
To: netdev@vger.kernel.org
Cc: dechen@redhat.com, dchen27@ncsu.edu, kuba@kernel.org,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, petrm@nvidia.com,
Kamal Heib <kheib@redhat.com>
Subject: [PATCH net-next 1/3] netdevsim: Support ethtool stats
Date: Tue, 5 Aug 2025 17:33:54 -0400 [thread overview]
Message-ID: <20250805213356.3348348-2-dechen@redhat.com> (raw)
In-Reply-To: <20250805213356.3348348-1-dechen@redhat.com>
From: Kamal Heib <kheib@redhat.com>
Add support for reporting the netdevsim stats via ethtool.
Signed-off-by: Kamal Heib <kheib@redhat.com>
---
drivers/net/netdevsim/ethtool.c | 58 +++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/net/netdevsim/ethtool.c b/drivers/net/netdevsim/ethtool.c
index f631d90c428a..33d39dfdd6d9 100644
--- a/drivers/net/netdevsim/ethtool.c
+++ b/drivers/net/netdevsim/ethtool.c
@@ -7,6 +7,26 @@
#include "netdevsim.h"
+struct nsim_stat_desc {
+ char desc[ETH_GSTRING_LEN];
+ size_t offset;
+};
+
+#define NSIM_STAT_ENTRY(s) { \
+ .desc = #s, \
+ .offset = offsetof(struct rtnl_link_stats64, s) }
+
+static const struct nsim_stat_desc nsim_stats_desc[] = {
+ NSIM_STAT_ENTRY(tx_packets),
+ NSIM_STAT_ENTRY(rx_packets),
+ NSIM_STAT_ENTRY(tx_bytes),
+ NSIM_STAT_ENTRY(rx_bytes),
+ NSIM_STAT_ENTRY(tx_dropped),
+ NSIM_STAT_ENTRY(rx_dropped),
+};
+
+#define NSIM_STATS_LEN ARRAY_SIZE(nsim_stats_desc)
+
static void
nsim_get_pause_stats(struct net_device *dev,
struct ethtool_pause_stats *pause_stats)
@@ -182,6 +202,41 @@ static int nsim_get_ts_info(struct net_device *dev,
return 0;
}
+static int nsim_sset_count(struct net_device *dev, int sset)
+{
+ switch (sset) {
+ case ETH_SS_STATS:
+ return NSIM_STATS_LEN;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+static void nsim_get_strings(struct net_device *dev, u32 sset, u8 *data)
+{
+ int i;
+
+ switch (sset) {
+ case ETH_SS_STATS:
+ for (i = 0; i < NSIM_STATS_LEN; i++)
+ ethtool_puts(&data, nsim_stats_desc[i].desc);
+ break;
+ }
+}
+
+static void nsim_get_ethtool_stats(struct net_device *dev,
+ struct ethtool_stats *stats,
+ u64 *data)
+{
+ struct rtnl_link_stats64 rtstats = {};
+ int i;
+
+ dev_get_stats(dev, &rtstats);
+
+ for (i = 0; i < NSIM_STATS_LEN; i++)
+ data[i] = *(u64 *)((u8 *)&rtstats + nsim_stats_desc[i].offset);
+}
+
static const struct ethtool_ops nsim_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_ALL_PARAMS,
.supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT |
@@ -199,6 +254,9 @@ static const struct ethtool_ops nsim_ethtool_ops = {
.set_fecparam = nsim_set_fecparam,
.get_fec_stats = nsim_get_fec_stats,
.get_ts_info = nsim_get_ts_info,
+ .get_sset_count = nsim_sset_count,
+ .get_strings = nsim_get_strings,
+ .get_ethtool_stats = nsim_get_ethtool_stats,
};
static void nsim_ethtool_ring_init(struct netdevsim *ns)
--
2.50.1
next prev parent reply other threads:[~2025-08-05 21:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-05 21:33 [PATCH net-next 0/3] netdevsim: Add support for ethtool stats and add Dennis Chen
2025-08-05 21:33 ` Dennis Chen [this message]
2025-08-05 21:33 ` [PATCH net-next 2/3] netdevsim: Add mock stats for ethtool Dennis Chen
2025-08-05 21:33 ` [PATCH net-next 3/3] selftests: netdevsim: Add test for ethtool stats Dennis Chen
2025-08-05 22:55 ` [PATCH net-next 0/3] netdevsim: Add support for ethtool stats and add Jakub Kicinski
2025-08-06 14:05 ` Dennis Chen
2025-08-06 14:48 ` Jakub Kicinski
2025-08-07 9:48 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250805213356.3348348-2-dechen@redhat.com \
--to=dechen@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dchen27@ncsu.edu \
--cc=edumazet@google.com \
--cc=kheib@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.