Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netdevsim: add pause frame stats

Add minimal ethtool interface for testing ethtool pause stats.

v2: add missing static on nsim_ethtool_ops

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Reviewed-by: Saeed Mahameed <saeedm@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
ff1f7c17 8c00bd93

+77 -1
+1 -1
drivers/net/netdevsim/Makefile
··· 3 3 obj-$(CONFIG_NETDEVSIM) += netdevsim.o 4 4 5 5 netdevsim-objs := \ 6 - netdev.o dev.o fib.o bus.o health.o udp_tunnels.o 6 + netdev.o dev.o ethtool.o fib.o bus.o health.o udp_tunnels.o 7 7 8 8 ifeq ($(CONFIG_BPF_SYSCALL),y) 9 9 netdevsim-objs += \
+64
drivers/net/netdevsim/ethtool.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // Copyright (c) 2020 Facebook 3 + 4 + #include <linux/debugfs.h> 5 + #include <linux/ethtool.h> 6 + #include <linux/random.h> 7 + 8 + #include "netdevsim.h" 9 + 10 + static void 11 + nsim_get_pause_stats(struct net_device *dev, 12 + struct ethtool_pause_stats *pause_stats) 13 + { 14 + struct netdevsim *ns = netdev_priv(dev); 15 + 16 + if (ns->ethtool.report_stats_rx) 17 + pause_stats->rx_pause_frames = 1; 18 + if (ns->ethtool.report_stats_tx) 19 + pause_stats->tx_pause_frames = 2; 20 + } 21 + 22 + static void 23 + nsim_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) 24 + { 25 + struct netdevsim *ns = netdev_priv(dev); 26 + 27 + pause->autoneg = 0; /* We don't support ksettings, so can't pretend */ 28 + pause->rx_pause = ns->ethtool.rx; 29 + pause->tx_pause = ns->ethtool.tx; 30 + } 31 + 32 + static int 33 + nsim_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause) 34 + { 35 + struct netdevsim *ns = netdev_priv(dev); 36 + 37 + if (pause->autoneg) 38 + return -EINVAL; 39 + 40 + ns->ethtool.rx = pause->rx_pause; 41 + ns->ethtool.tx = pause->tx_pause; 42 + return 0; 43 + } 44 + 45 + static const struct ethtool_ops nsim_ethtool_ops = { 46 + .get_pause_stats = nsim_get_pause_stats, 47 + .get_pauseparam = nsim_get_pauseparam, 48 + .set_pauseparam = nsim_set_pauseparam, 49 + }; 50 + 51 + void nsim_ethtool_init(struct netdevsim *ns) 52 + { 53 + struct dentry *ethtool, *dir; 54 + 55 + ns->netdev->ethtool_ops = &nsim_ethtool_ops; 56 + 57 + ethtool = debugfs_create_dir("ethtool", ns->nsim_dev->ddir); 58 + 59 + dir = debugfs_create_dir("pause", ethtool); 60 + debugfs_create_bool("report_stats_rx", 0600, dir, 61 + &ns->ethtool.report_stats_rx); 62 + debugfs_create_bool("report_stats_tx", 0600, dir, 63 + &ns->ethtool.report_stats_tx); 64 + }
+1
drivers/net/netdevsim/netdev.c
··· 301 301 ns->nsim_bus_dev = nsim_dev->nsim_bus_dev; 302 302 SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev); 303 303 dev->netdev_ops = &nsim_netdev_ops; 304 + nsim_ethtool_init(ns); 304 305 305 306 err = nsim_udp_tunnels_info_create(nsim_dev, dev); 306 307 if (err)
+11
drivers/net/netdevsim/netdevsim.h
··· 50 50 u32 ok; 51 51 }; 52 52 53 + struct nsim_ethtool { 54 + bool rx; 55 + bool tx; 56 + bool report_stats_rx; 57 + bool report_stats_tx; 58 + }; 59 + 53 60 struct netdevsim { 54 61 struct net_device *netdev; 55 62 struct nsim_dev *nsim_dev; ··· 87 80 u32 ports[2][NSIM_UDP_TUNNEL_N_PORTS]; 88 81 struct debugfs_u32_array dfs_ports[2]; 89 82 } udp_ports; 83 + 84 + struct nsim_ethtool ethtool; 90 85 }; 91 86 92 87 struct netdevsim * 93 88 nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port); 94 89 void nsim_destroy(struct netdevsim *ns); 90 + 91 + void nsim_ethtool_init(struct netdevsim *ns); 95 92 96 93 void nsim_udp_tunnels_debugfs_create(struct nsim_dev *nsim_dev); 97 94 int nsim_udp_tunnels_info_create(struct nsim_dev *nsim_dev,