ethtool.c 1.6 KB

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