pasemi_mac_ethtool.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2006-2008 PA Semi, Inc
  3. *
  4. * Ethtool hooks for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/netdevice.h>
  19. #include <linux/ethtool.h>
  20. #include <linux/pci.h>
  21. #include <asm/pasemi_dma.h>
  22. #include "pasemi_mac.h"
  23. static struct {
  24. const char str[ETH_GSTRING_LEN];
  25. } ethtool_stats_keys[] = {
  26. { "rx-drops" },
  27. { "rx-bytes" },
  28. { "rx-packets" },
  29. { "rx-broadcast-packets" },
  30. { "rx-multicast-packets" },
  31. { "rx-crc-errors" },
  32. { "rx-undersize-errors" },
  33. { "rx-oversize-errors" },
  34. { "rx-short-fragment-errors" },
  35. { "rx-jabber-errors" },
  36. { "rx-64-byte-packets" },
  37. { "rx-65-127-byte-packets" },
  38. { "rx-128-255-byte-packets" },
  39. { "rx-256-511-byte-packets" },
  40. { "rx-512-1023-byte-packets" },
  41. { "rx-1024-1518-byte-packets" },
  42. { "rx-pause-frames" },
  43. { "tx-bytes" },
  44. { "tx-packets" },
  45. { "tx-broadcast-packets" },
  46. { "tx-multicast-packets" },
  47. { "tx-collisions" },
  48. { "tx-late-collisions" },
  49. { "tx-excessive-collisions" },
  50. { "tx-crc-errors" },
  51. { "tx-undersize-errors" },
  52. { "tx-oversize-errors" },
  53. { "tx-64-byte-packets" },
  54. { "tx-65-127-byte-packets" },
  55. { "tx-128-255-byte-packets" },
  56. { "tx-256-511-byte-packets" },
  57. { "tx-512-1023-byte-packets" },
  58. { "tx-1024-1518-byte-packets" },
  59. };
  60. static u32
  61. pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
  62. {
  63. struct pasemi_mac *mac = netdev_priv(netdev);
  64. return mac->msg_enable;
  65. }
  66. static void
  67. pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
  68. u32 level)
  69. {
  70. struct pasemi_mac *mac = netdev_priv(netdev);
  71. mac->msg_enable = level;
  72. }
  73. static void
  74. pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
  75. struct ethtool_ringparam *ering)
  76. {
  77. struct pasemi_mac *mac = netdev_priv(netdev);
  78. ering->tx_max_pending = TX_RING_SIZE/2;
  79. ering->tx_pending = RING_USED(mac->tx)/2;
  80. ering->rx_max_pending = RX_RING_SIZE/4;
  81. ering->rx_pending = RING_USED(mac->rx)/4;
  82. }
  83. static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
  84. {
  85. switch (sset) {
  86. case ETH_SS_STATS:
  87. return ARRAY_SIZE(ethtool_stats_keys);
  88. default:
  89. return -EOPNOTSUPP;
  90. }
  91. }
  92. static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
  93. struct ethtool_stats *stats, u64 *data)
  94. {
  95. struct pasemi_mac *mac = netdev_priv(netdev);
  96. int i;
  97. data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
  98. >> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
  99. for (i = 0; i < 32; i++)
  100. data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
  101. }
  102. static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
  103. u8 *data)
  104. {
  105. memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
  106. }
  107. const struct ethtool_ops pasemi_mac_ethtool_ops = {
  108. .get_msglevel = pasemi_mac_ethtool_get_msglevel,
  109. .set_msglevel = pasemi_mac_ethtool_set_msglevel,
  110. .get_link = ethtool_op_get_link,
  111. .get_ringparam = pasemi_mac_ethtool_get_ringparam,
  112. .get_strings = pasemi_mac_get_strings,
  113. .get_sset_count = pasemi_mac_get_sset_count,
  114. .get_ethtool_stats = pasemi_mac_get_ethtool_stats,
  115. .get_link_ksettings = phy_ethtool_get_link_ksettings,
  116. .set_link_ksettings = phy_ethtool_set_link_ksettings,
  117. };