^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) // Copyright (c) 2020 Facebook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "netdevsim.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) nsim_get_pause_stats(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) struct ethtool_pause_stats *pause_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) struct netdevsim *ns = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) if (ns->ethtool.report_stats_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) pause_stats->rx_pause_frames = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) if (ns->ethtool.report_stats_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) pause_stats->tx_pause_frames = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) nsim_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct netdevsim *ns = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pause->autoneg = 0; /* We don't support ksettings, so can't pretend */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) pause->rx_pause = ns->ethtool.rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) pause->tx_pause = ns->ethtool.tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) nsim_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct netdevsim *ns = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (pause->autoneg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ns->ethtool.rx = pause->rx_pause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) ns->ethtool.tx = pause->tx_pause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct ethtool_ops nsim_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .get_pause_stats = nsim_get_pause_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .get_pauseparam = nsim_get_pauseparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .set_pauseparam = nsim_set_pauseparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) void nsim_ethtool_init(struct netdevsim *ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct dentry *ethtool, *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ns->netdev->ethtool_ops = &nsim_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ethtool = debugfs_create_dir("ethtool", ns->nsim_dev_port->ddir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dir = debugfs_create_dir("pause", ethtool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) debugfs_create_bool("report_stats_rx", 0600, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) &ns->ethtool.report_stats_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) debugfs_create_bool("report_stats_tx", 0600, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) &ns->ethtool.report_stats_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }