spider_net_ethtool.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. #define SPIDER_NET_NUM_STATS 13
  28. static struct {
  29. const char str[ETH_GSTRING_LEN];
  30. } ethtool_stats_keys[] = {
  31. { "tx_packets" },
  32. { "tx_bytes" },
  33. { "rx_packets" },
  34. { "rx_bytes" },
  35. { "tx_errors" },
  36. { "tx_dropped" },
  37. { "rx_dropped" },
  38. { "rx_descriptor_error" },
  39. { "tx_timeouts" },
  40. { "alloc_rx_skb_error" },
  41. { "rx_iommu_map_error" },
  42. { "tx_iommu_map_error" },
  43. { "rx_desc_unk_state" },
  44. };
  45. static int
  46. spider_net_ethtool_get_settings(struct net_device *netdev,
  47. struct ethtool_cmd *cmd)
  48. {
  49. struct spider_net_card *card;
  50. card = netdev_priv(netdev);
  51. cmd->supported = (SUPPORTED_1000baseT_Full |
  52. SUPPORTED_FIBRE);
  53. cmd->advertising = (ADVERTISED_1000baseT_Full |
  54. ADVERTISED_FIBRE);
  55. cmd->port = PORT_FIBRE;
  56. cmd->speed = card->phy.speed;
  57. cmd->duplex = DUPLEX_FULL;
  58. return 0;
  59. }
  60. static void
  61. spider_net_ethtool_get_drvinfo(struct net_device *netdev,
  62. struct ethtool_drvinfo *drvinfo)
  63. {
  64. struct spider_net_card *card;
  65. card = netdev_priv(netdev);
  66. /* clear and fill out info */
  67. memset(drvinfo, 0, sizeof(struct ethtool_drvinfo));
  68. strncpy(drvinfo->driver, spider_net_driver_name, 32);
  69. strncpy(drvinfo->version, VERSION, 32);
  70. strcpy(drvinfo->fw_version, "no information");
  71. strncpy(drvinfo->bus_info, pci_name(card->pdev), 32);
  72. }
  73. static void
  74. spider_net_ethtool_get_wol(struct net_device *netdev,
  75. struct ethtool_wolinfo *wolinfo)
  76. {
  77. /* no support for wol */
  78. wolinfo->supported = 0;
  79. wolinfo->wolopts = 0;
  80. }
  81. static u32
  82. spider_net_ethtool_get_msglevel(struct net_device *netdev)
  83. {
  84. struct spider_net_card *card;
  85. card = netdev_priv(netdev);
  86. return card->msg_enable;
  87. }
  88. static void
  89. spider_net_ethtool_set_msglevel(struct net_device *netdev,
  90. u32 level)
  91. {
  92. struct spider_net_card *card;
  93. card = netdev_priv(netdev);
  94. card->msg_enable = level;
  95. }
  96. static int
  97. spider_net_ethtool_nway_reset(struct net_device *netdev)
  98. {
  99. if (netif_running(netdev)) {
  100. spider_net_stop(netdev);
  101. spider_net_open(netdev);
  102. }
  103. return 0;
  104. }
  105. static u32
  106. spider_net_ethtool_get_rx_csum(struct net_device *netdev)
  107. {
  108. struct spider_net_card *card = netdev->priv;
  109. return card->options.rx_csum;
  110. }
  111. static int
  112. spider_net_ethtool_set_rx_csum(struct net_device *netdev, u32 n)
  113. {
  114. struct spider_net_card *card = netdev->priv;
  115. card->options.rx_csum = n;
  116. return 0;
  117. }
  118. static uint32_t
  119. spider_net_ethtool_get_tx_csum(struct net_device *netdev)
  120. {
  121. return (netdev->features & NETIF_F_HW_CSUM) != 0;
  122. }
  123. static int
  124. spider_net_ethtool_set_tx_csum(struct net_device *netdev, uint32_t data)
  125. {
  126. if (data)
  127. netdev->features |= NETIF_F_HW_CSUM;
  128. else
  129. netdev->features &= ~NETIF_F_HW_CSUM;
  130. return 0;
  131. }
  132. static void
  133. spider_net_ethtool_get_ringparam(struct net_device *netdev,
  134. struct ethtool_ringparam *ering)
  135. {
  136. struct spider_net_card *card = netdev->priv;
  137. ering->tx_max_pending = SPIDER_NET_TX_DESCRIPTORS_MAX;
  138. ering->tx_pending = card->num_tx_desc;
  139. ering->rx_max_pending = SPIDER_NET_RX_DESCRIPTORS_MAX;
  140. ering->rx_pending = card->num_rx_desc;
  141. }
  142. static int spider_net_get_stats_count(struct net_device *netdev)
  143. {
  144. return SPIDER_NET_NUM_STATS;
  145. }
  146. static void spider_net_get_ethtool_stats(struct net_device *netdev,
  147. struct ethtool_stats *stats, u64 *data)
  148. {
  149. struct spider_net_card *card = netdev->priv;
  150. data[0] = card->netdev_stats.tx_packets;
  151. data[1] = card->netdev_stats.tx_bytes;
  152. data[2] = card->netdev_stats.rx_packets;
  153. data[3] = card->netdev_stats.rx_bytes;
  154. data[4] = card->netdev_stats.tx_errors;
  155. data[5] = card->netdev_stats.tx_dropped;
  156. data[6] = card->netdev_stats.rx_dropped;
  157. data[7] = card->spider_stats.rx_desc_error;
  158. data[8] = card->spider_stats.tx_timeouts;
  159. data[9] = card->spider_stats.alloc_rx_skb_error;
  160. data[10] = card->spider_stats.rx_iommu_map_error;
  161. data[11] = card->spider_stats.tx_iommu_map_error;
  162. data[12] = card->spider_stats.rx_desc_unk_state;
  163. }
  164. static void spider_net_get_strings(struct net_device *netdev, u32 stringset,
  165. u8 *data)
  166. {
  167. memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
  168. }
  169. const struct ethtool_ops spider_net_ethtool_ops = {
  170. .get_settings = spider_net_ethtool_get_settings,
  171. .get_drvinfo = spider_net_ethtool_get_drvinfo,
  172. .get_wol = spider_net_ethtool_get_wol,
  173. .get_msglevel = spider_net_ethtool_get_msglevel,
  174. .set_msglevel = spider_net_ethtool_set_msglevel,
  175. .nway_reset = spider_net_ethtool_nway_reset,
  176. .get_rx_csum = spider_net_ethtool_get_rx_csum,
  177. .set_rx_csum = spider_net_ethtool_set_rx_csum,
  178. .get_tx_csum = spider_net_ethtool_get_tx_csum,
  179. .set_tx_csum = spider_net_ethtool_set_tx_csum,
  180. .get_ringparam = spider_net_ethtool_get_ringparam,
  181. .get_strings = spider_net_get_strings,
  182. .get_stats_count = spider_net_get_stats_count,
  183. .get_ethtool_stats = spider_net_get_ethtool_stats,
  184. };