pasemi_mac_ethtool.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <linux/inet_lro.h>
  22. #include <asm/pasemi_dma.h>
  23. #include "pasemi_mac.h"
  24. static struct {
  25. const char str[ETH_GSTRING_LEN];
  26. } ethtool_stats_keys[] = {
  27. { "rx-drops" },
  28. { "rx-bytes" },
  29. { "rx-packets" },
  30. { "rx-broadcast-packets" },
  31. { "rx-multicast-packets" },
  32. { "rx-crc-errors" },
  33. { "rx-undersize-errors" },
  34. { "rx-oversize-errors" },
  35. { "rx-short-fragment-errors" },
  36. { "rx-jabber-errors" },
  37. { "rx-64-byte-packets" },
  38. { "rx-65-127-byte-packets" },
  39. { "rx-128-255-byte-packets" },
  40. { "rx-256-511-byte-packets" },
  41. { "rx-512-1023-byte-packets" },
  42. { "rx-1024-1518-byte-packets" },
  43. { "rx-pause-frames" },
  44. { "tx-bytes" },
  45. { "tx-packets" },
  46. { "tx-broadcast-packets" },
  47. { "tx-multicast-packets" },
  48. { "tx-collisions" },
  49. { "tx-late-collisions" },
  50. { "tx-excessive-collisions" },
  51. { "tx-crc-errors" },
  52. { "tx-undersize-errors" },
  53. { "tx-oversize-errors" },
  54. { "tx-64-byte-packets" },
  55. { "tx-65-127-byte-packets" },
  56. { "tx-128-255-byte-packets" },
  57. { "tx-256-511-byte-packets" },
  58. { "tx-512-1023-byte-packets" },
  59. { "tx-1024-1518-byte-packets" },
  60. };
  61. static int
  62. pasemi_mac_ethtool_get_settings(struct net_device *netdev,
  63. struct ethtool_cmd *cmd)
  64. {
  65. struct pasemi_mac *mac = netdev_priv(netdev);
  66. struct phy_device *phydev = mac->phydev;
  67. if (!phydev)
  68. return -EOPNOTSUPP;
  69. return phy_ethtool_gset(phydev, cmd);
  70. }
  71. static int
  72. pasemi_mac_ethtool_set_settings(struct net_device *netdev,
  73. struct ethtool_cmd *cmd)
  74. {
  75. struct pasemi_mac *mac = netdev_priv(netdev);
  76. struct phy_device *phydev = mac->phydev;
  77. if (!phydev)
  78. return -EOPNOTSUPP;
  79. return phy_ethtool_sset(phydev, cmd);
  80. }
  81. static u32
  82. pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
  83. {
  84. struct pasemi_mac *mac = netdev_priv(netdev);
  85. return mac->msg_enable;
  86. }
  87. static void
  88. pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
  89. u32 level)
  90. {
  91. struct pasemi_mac *mac = netdev_priv(netdev);
  92. mac->msg_enable = level;
  93. }
  94. static void
  95. pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
  96. struct ethtool_ringparam *ering)
  97. {
  98. struct pasemi_mac *mac = netdev_priv(netdev);
  99. ering->tx_max_pending = TX_RING_SIZE/2;
  100. ering->tx_pending = RING_USED(mac->tx)/2;
  101. ering->rx_max_pending = RX_RING_SIZE/4;
  102. ering->rx_pending = RING_USED(mac->rx)/4;
  103. }
  104. static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
  105. {
  106. switch (sset) {
  107. case ETH_SS_STATS:
  108. return ARRAY_SIZE(ethtool_stats_keys);
  109. default:
  110. return -EOPNOTSUPP;
  111. }
  112. }
  113. static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
  114. struct ethtool_stats *stats, u64 *data)
  115. {
  116. struct pasemi_mac *mac = netdev_priv(netdev);
  117. int i;
  118. data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
  119. >> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
  120. for (i = 0; i < 32; i++)
  121. data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
  122. }
  123. static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
  124. u8 *data)
  125. {
  126. memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
  127. }
  128. const struct ethtool_ops pasemi_mac_ethtool_ops = {
  129. .get_settings = pasemi_mac_ethtool_get_settings,
  130. .set_settings = pasemi_mac_ethtool_set_settings,
  131. .get_msglevel = pasemi_mac_ethtool_get_msglevel,
  132. .set_msglevel = pasemi_mac_ethtool_set_msglevel,
  133. .get_link = ethtool_op_get_link,
  134. .get_ringparam = pasemi_mac_ethtool_get_ringparam,
  135. .get_strings = pasemi_mac_get_strings,
  136. .get_sset_count = pasemi_mac_get_sset_count,
  137. .get_ethtool_stats = pasemi_mac_get_ethtool_stats,
  138. };