spider_net_ethtool.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Network device driver for Cell Processor-Based Blade
  3. *
  4. * (C) Copyright IBM Corp. 2005
  5. *
  6. * Authors : Utz Bacher <utz.bacher@de.ibm.com>
  7. * Jens Osterkamp <Jens.Osterkamp@de.ibm.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/netdevice.h>
  24. #include <linux/ethtool.h>
  25. #include <linux/pci.h>
  26. #include "spider_net.h"
  27. static struct {
  28. const char str[ETH_GSTRING_LEN];
  29. } ethtool_stats_keys[] = {
  30. { "tx_packets" },
  31. { "tx_bytes" },
  32. { "rx_packets" },
  33. { "rx_bytes" },
  34. { "tx_errors" },
  35. { "tx_dropped" },
  36. { "rx_dropped" },
  37. { "rx_descriptor_error" },
  38. { "tx_timeouts" },
  39. { "alloc_rx_skb_error" },
  40. { "rx_iommu_map_error" },
  41. { "tx_iommu_map_error" },
  42. { "rx_desc_unk_state" },
  43. };
  44. static int
  45. spider_net_ethtool_get_settings(struct net_device *netdev,
  46. struct ethtool_cmd *cmd)
  47. {
  48. struct spider_net_card *card;
  49. card = netdev_priv(netdev);
  50. cmd->supported = (SUPPORTED_1000baseT_Full |
  51. SUPPORTED_FIBRE);
  52. cmd->advertising = (ADVERTISED_1000baseT_Full |
  53. ADVERTISED_FIBRE);
  54. cmd->port = PORT_FIBRE;
  55. ethtool_cmd_speed_set(cmd, card->phy.speed);
  56. cmd->duplex = DUPLEX_FULL;
  57. return 0;
  58. }
  59. static void
  60. spider_net_ethtool_get_drvinfo(struct net_device *netdev,
  61. struct ethtool_drvinfo *drvinfo)
  62. {
  63. struct spider_net_card *card;
  64. card = netdev_priv(netdev);
  65. /* clear and fill out info */
  66. strlcpy(drvinfo->driver, spider_net_driver_name,
  67. sizeof(drvinfo->driver));
  68. strlcpy(drvinfo->version, VERSION, sizeof(drvinfo->version));
  69. strlcpy(drvinfo->fw_version, "no information",
  70. sizeof(drvinfo->fw_version));
  71. strlcpy(drvinfo->bus_info, pci_name(card->pdev),
  72. sizeof(drvinfo->bus_info));
  73. }
  74. static void
  75. spider_net_ethtool_get_wol(struct net_device *netdev,
  76. struct ethtool_wolinfo *wolinfo)
  77. {
  78. /* no support for wol */
  79. wolinfo->supported = 0;
  80. wolinfo->wolopts = 0;
  81. }
  82. static u32
  83. spider_net_ethtool_get_msglevel(struct net_device *netdev)
  84. {
  85. struct spider_net_card *card;
  86. card = netdev_priv(netdev);
  87. return card->msg_enable;
  88. }
  89. static void
  90. spider_net_ethtool_set_msglevel(struct net_device *netdev,
  91. u32 level)
  92. {
  93. struct spider_net_card *card;
  94. card = netdev_priv(netdev);
  95. card->msg_enable = level;
  96. }
  97. static int
  98. spider_net_ethtool_nway_reset(struct net_device *netdev)
  99. {
  100. if (netif_running(netdev)) {
  101. spider_net_stop(netdev);
  102. spider_net_open(netdev);
  103. }
  104. return 0;
  105. }
  106. static void
  107. spider_net_ethtool_get_ringparam(struct net_device *netdev,
  108. struct ethtool_ringparam *ering)
  109. {
  110. struct spider_net_card *card = netdev_priv(netdev);
  111. ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
  112. ering->tx_pending = card->tx_chain.num_desc;
  113. ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
  114. ering->rx_pending = card->rx_chain.num_desc;
  115. }
  116. static int spider_net_get_sset_count(struct net_device *netdev, int sset)
  117. {
  118. switch (sset) {
  119. case ETH_SS_STATS:
  120. return ARRAY_SIZE(ethtool_stats_keys);
  121. default:
  122. return -EOPNOTSUPP;
  123. }
  124. }
  125. static void spider_net_get_ethtool_stats(struct net_device *netdev,
  126. struct ethtool_stats *stats, u64 *data)
  127. {
  128. struct spider_net_card *card = netdev_priv(netdev);
  129. data[0] = netdev->stats.tx_packets;
  130. data[1] = netdev->stats.tx_bytes;
  131. data[2] = netdev->stats.rx_packets;
  132. data[3] = netdev->stats.rx_bytes;
  133. data[4] = netdev->stats.tx_errors;
  134. data[5] = netdev->stats.tx_dropped;
  135. data[6] = netdev->stats.rx_dropped;
  136. data[7] = card->spider_stats.rx_desc_error;
  137. data[8] = card->spider_stats.tx_timeouts;
  138. data[9] = card->spider_stats.alloc_rx_skb_error;
  139. data[10] = card->spider_stats.rx_iommu_map_error;
  140. data[11] = card->spider_stats.tx_iommu_map_error;
  141. data[12] = card->spider_stats.rx_desc_unk_state;
  142. }
  143. static void spider_net_get_strings(struct net_device *netdev, u32 stringset,
  144. u8 *data)
  145. {
  146. memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
  147. }
  148. const struct ethtool_ops spider_net_ethtool_ops = {
  149. .get_settings = spider_net_ethtool_get_settings,
  150. .get_drvinfo = spider_net_ethtool_get_drvinfo,
  151. .get_wol = spider_net_ethtool_get_wol,
  152. .get_msglevel = spider_net_ethtool_get_msglevel,
  153. .set_msglevel = spider_net_ethtool_set_msglevel,
  154. .get_link = ethtool_op_get_link,
  155. .nway_reset = spider_net_ethtool_nway_reset,
  156. .get_ringparam = spider_net_ethtool_get_ringparam,
  157. .get_strings = spider_net_get_strings,
  158. .get_sset_count = spider_net_get_sset_count,
  159. .get_ethtool_stats = spider_net_get_ethtool_stats,
  160. };