pasemi_mac_ethtool.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2006-2008 PA Semi, Inc
  4. *
  5. * Ethtool hooks for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
  6. */
  7. #include <linux/netdevice.h>
  8. #include <linux/ethtool.h>
  9. #include <linux/pci.h>
  10. #include <asm/pasemi_dma.h>
  11. #include "pasemi_mac.h"
  12. static struct {
  13. const char str[ETH_GSTRING_LEN];
  14. } ethtool_stats_keys[] = {
  15. { "rx-drops" },
  16. { "rx-bytes" },
  17. { "rx-packets" },
  18. { "rx-broadcast-packets" },
  19. { "rx-multicast-packets" },
  20. { "rx-crc-errors" },
  21. { "rx-undersize-errors" },
  22. { "rx-oversize-errors" },
  23. { "rx-short-fragment-errors" },
  24. { "rx-jabber-errors" },
  25. { "rx-64-byte-packets" },
  26. { "rx-65-127-byte-packets" },
  27. { "rx-128-255-byte-packets" },
  28. { "rx-256-511-byte-packets" },
  29. { "rx-512-1023-byte-packets" },
  30. { "rx-1024-1518-byte-packets" },
  31. { "rx-pause-frames" },
  32. { "tx-bytes" },
  33. { "tx-packets" },
  34. { "tx-broadcast-packets" },
  35. { "tx-multicast-packets" },
  36. { "tx-collisions" },
  37. { "tx-late-collisions" },
  38. { "tx-excessive-collisions" },
  39. { "tx-crc-errors" },
  40. { "tx-undersize-errors" },
  41. { "tx-oversize-errors" },
  42. { "tx-64-byte-packets" },
  43. { "tx-65-127-byte-packets" },
  44. { "tx-128-255-byte-packets" },
  45. { "tx-256-511-byte-packets" },
  46. { "tx-512-1023-byte-packets" },
  47. { "tx-1024-1518-byte-packets" },
  48. };
  49. static u32
  50. pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
  51. {
  52. struct pasemi_mac *mac = netdev_priv(netdev);
  53. return mac->msg_enable;
  54. }
  55. static void
  56. pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
  57. u32 level)
  58. {
  59. struct pasemi_mac *mac = netdev_priv(netdev);
  60. mac->msg_enable = level;
  61. }
  62. static void
  63. pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
  64. struct ethtool_ringparam *ering,
  65. struct kernel_ethtool_ringparam *kernel_ering,
  66. struct netlink_ext_ack *extack)
  67. {
  68. struct pasemi_mac *mac = netdev_priv(netdev);
  69. ering->tx_max_pending = TX_RING_SIZE/2;
  70. ering->tx_pending = RING_USED(mac->tx)/2;
  71. ering->rx_max_pending = RX_RING_SIZE/4;
  72. ering->rx_pending = RING_USED(mac->rx)/4;
  73. }
  74. static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
  75. {
  76. switch (sset) {
  77. case ETH_SS_STATS:
  78. return ARRAY_SIZE(ethtool_stats_keys);
  79. default:
  80. return -EOPNOTSUPP;
  81. }
  82. }
  83. static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
  84. struct ethtool_stats *stats, u64 *data)
  85. {
  86. struct pasemi_mac *mac = netdev_priv(netdev);
  87. int i;
  88. data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
  89. >> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
  90. for (i = 0; i < 32; i++)
  91. data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
  92. }
  93. static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
  94. u8 *data)
  95. {
  96. memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
  97. }
  98. const struct ethtool_ops pasemi_mac_ethtool_ops = {
  99. .get_msglevel = pasemi_mac_ethtool_get_msglevel,
  100. .set_msglevel = pasemi_mac_ethtool_set_msglevel,
  101. .get_link = ethtool_op_get_link,
  102. .get_ringparam = pasemi_mac_ethtool_get_ringparam,
  103. .get_strings = pasemi_mac_get_strings,
  104. .get_sset_count = pasemi_mac_get_sset_count,
  105. .get_ethtool_stats = pasemi_mac_get_ethtool_stats,
  106. .get_link_ksettings = phy_ethtool_get_link_ksettings,
  107. .set_link_ksettings = phy_ethtool_set_link_ksettings,
  108. };