pasemi_mac_ethtool.c 4.4 KB

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