enic_ethtool.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /**
  2. * Copyright 2013 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. *
  17. */
  18. #include <linux/netdevice.h>
  19. #include <linux/ethtool.h>
  20. #include "enic_res.h"
  21. #include "enic.h"
  22. #include "enic_dev.h"
  23. struct enic_stat {
  24. char name[ETH_GSTRING_LEN];
  25. unsigned int index;
  26. };
  27. #define ENIC_TX_STAT(stat) { \
  28. .name = #stat, \
  29. .index = offsetof(struct vnic_tx_stats, stat) / sizeof(u64) \
  30. }
  31. #define ENIC_RX_STAT(stat) { \
  32. .name = #stat, \
  33. .index = offsetof(struct vnic_rx_stats, stat) / sizeof(u64) \
  34. }
  35. static const struct enic_stat enic_tx_stats[] = {
  36. ENIC_TX_STAT(tx_frames_ok),
  37. ENIC_TX_STAT(tx_unicast_frames_ok),
  38. ENIC_TX_STAT(tx_multicast_frames_ok),
  39. ENIC_TX_STAT(tx_broadcast_frames_ok),
  40. ENIC_TX_STAT(tx_bytes_ok),
  41. ENIC_TX_STAT(tx_unicast_bytes_ok),
  42. ENIC_TX_STAT(tx_multicast_bytes_ok),
  43. ENIC_TX_STAT(tx_broadcast_bytes_ok),
  44. ENIC_TX_STAT(tx_drops),
  45. ENIC_TX_STAT(tx_errors),
  46. ENIC_TX_STAT(tx_tso),
  47. };
  48. static const struct enic_stat enic_rx_stats[] = {
  49. ENIC_RX_STAT(rx_frames_ok),
  50. ENIC_RX_STAT(rx_frames_total),
  51. ENIC_RX_STAT(rx_unicast_frames_ok),
  52. ENIC_RX_STAT(rx_multicast_frames_ok),
  53. ENIC_RX_STAT(rx_broadcast_frames_ok),
  54. ENIC_RX_STAT(rx_bytes_ok),
  55. ENIC_RX_STAT(rx_unicast_bytes_ok),
  56. ENIC_RX_STAT(rx_multicast_bytes_ok),
  57. ENIC_RX_STAT(rx_broadcast_bytes_ok),
  58. ENIC_RX_STAT(rx_drop),
  59. ENIC_RX_STAT(rx_no_bufs),
  60. ENIC_RX_STAT(rx_errors),
  61. ENIC_RX_STAT(rx_rss),
  62. ENIC_RX_STAT(rx_crc_errors),
  63. ENIC_RX_STAT(rx_frames_64),
  64. ENIC_RX_STAT(rx_frames_127),
  65. ENIC_RX_STAT(rx_frames_255),
  66. ENIC_RX_STAT(rx_frames_511),
  67. ENIC_RX_STAT(rx_frames_1023),
  68. ENIC_RX_STAT(rx_frames_1518),
  69. ENIC_RX_STAT(rx_frames_to_max),
  70. };
  71. static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
  72. static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
  73. static int enic_get_settings(struct net_device *netdev,
  74. struct ethtool_cmd *ecmd)
  75. {
  76. struct enic *enic = netdev_priv(netdev);
  77. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  78. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  79. ecmd->port = PORT_FIBRE;
  80. ecmd->transceiver = XCVR_EXTERNAL;
  81. if (netif_carrier_ok(netdev)) {
  82. ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev));
  83. ecmd->duplex = DUPLEX_FULL;
  84. } else {
  85. ethtool_cmd_speed_set(ecmd, -1);
  86. ecmd->duplex = -1;
  87. }
  88. ecmd->autoneg = AUTONEG_DISABLE;
  89. return 0;
  90. }
  91. static void enic_get_drvinfo(struct net_device *netdev,
  92. struct ethtool_drvinfo *drvinfo)
  93. {
  94. struct enic *enic = netdev_priv(netdev);
  95. struct vnic_devcmd_fw_info *fw_info;
  96. enic_dev_fw_info(enic, &fw_info);
  97. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  98. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  99. strlcpy(drvinfo->fw_version, fw_info->fw_version,
  100. sizeof(drvinfo->fw_version));
  101. strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
  102. sizeof(drvinfo->bus_info));
  103. }
  104. static void enic_get_strings(struct net_device *netdev, u32 stringset,
  105. u8 *data)
  106. {
  107. unsigned int i;
  108. switch (stringset) {
  109. case ETH_SS_STATS:
  110. for (i = 0; i < enic_n_tx_stats; i++) {
  111. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  112. data += ETH_GSTRING_LEN;
  113. }
  114. for (i = 0; i < enic_n_rx_stats; i++) {
  115. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  116. data += ETH_GSTRING_LEN;
  117. }
  118. break;
  119. }
  120. }
  121. static int enic_get_sset_count(struct net_device *netdev, int sset)
  122. {
  123. switch (sset) {
  124. case ETH_SS_STATS:
  125. return enic_n_tx_stats + enic_n_rx_stats;
  126. default:
  127. return -EOPNOTSUPP;
  128. }
  129. }
  130. static void enic_get_ethtool_stats(struct net_device *netdev,
  131. struct ethtool_stats *stats, u64 *data)
  132. {
  133. struct enic *enic = netdev_priv(netdev);
  134. struct vnic_stats *vstats;
  135. unsigned int i;
  136. enic_dev_stats_dump(enic, &vstats);
  137. for (i = 0; i < enic_n_tx_stats; i++)
  138. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
  139. for (i = 0; i < enic_n_rx_stats; i++)
  140. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
  141. }
  142. static u32 enic_get_msglevel(struct net_device *netdev)
  143. {
  144. struct enic *enic = netdev_priv(netdev);
  145. return enic->msg_enable;
  146. }
  147. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  148. {
  149. struct enic *enic = netdev_priv(netdev);
  150. enic->msg_enable = value;
  151. }
  152. static int enic_get_coalesce(struct net_device *netdev,
  153. struct ethtool_coalesce *ecmd)
  154. {
  155. struct enic *enic = netdev_priv(netdev);
  156. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  157. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  158. return 0;
  159. }
  160. static int enic_set_coalesce(struct net_device *netdev,
  161. struct ethtool_coalesce *ecmd)
  162. {
  163. struct enic *enic = netdev_priv(netdev);
  164. u32 tx_coalesce_usecs;
  165. u32 rx_coalesce_usecs;
  166. unsigned int i, intr;
  167. tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
  168. vnic_dev_get_intr_coal_timer_max(enic->vdev));
  169. rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
  170. vnic_dev_get_intr_coal_timer_max(enic->vdev));
  171. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  172. case VNIC_DEV_INTR_MODE_INTX:
  173. if (tx_coalesce_usecs != rx_coalesce_usecs)
  174. return -EINVAL;
  175. intr = enic_legacy_io_intr();
  176. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  177. tx_coalesce_usecs);
  178. break;
  179. case VNIC_DEV_INTR_MODE_MSI:
  180. if (tx_coalesce_usecs != rx_coalesce_usecs)
  181. return -EINVAL;
  182. vnic_intr_coalescing_timer_set(&enic->intr[0],
  183. tx_coalesce_usecs);
  184. break;
  185. case VNIC_DEV_INTR_MODE_MSIX:
  186. for (i = 0; i < enic->wq_count; i++) {
  187. intr = enic_msix_wq_intr(enic, i);
  188. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  189. tx_coalesce_usecs);
  190. }
  191. for (i = 0; i < enic->rq_count; i++) {
  192. intr = enic_msix_rq_intr(enic, i);
  193. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  194. rx_coalesce_usecs);
  195. }
  196. break;
  197. default:
  198. break;
  199. }
  200. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  201. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  202. return 0;
  203. }
  204. static const struct ethtool_ops enic_ethtool_ops = {
  205. .get_settings = enic_get_settings,
  206. .get_drvinfo = enic_get_drvinfo,
  207. .get_msglevel = enic_get_msglevel,
  208. .set_msglevel = enic_set_msglevel,
  209. .get_link = ethtool_op_get_link,
  210. .get_strings = enic_get_strings,
  211. .get_sset_count = enic_get_sset_count,
  212. .get_ethtool_stats = enic_get_ethtool_stats,
  213. .get_coalesce = enic_get_coalesce,
  214. .set_coalesce = enic_set_coalesce,
  215. };
  216. void enic_set_ethtool_ops(struct net_device *netdev)
  217. {
  218. SET_ETHTOOL_OPS(netdev, &enic_ethtool_ops);
  219. }