enic_ethtool.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. void enic_intr_coal_set_rx(struct enic *enic, u32 timer)
  74. {
  75. int i;
  76. int intr;
  77. for (i = 0; i < enic->rq_count; i++) {
  78. intr = enic_msix_rq_intr(enic, i);
  79. vnic_intr_coalescing_timer_set(&enic->intr[intr], timer);
  80. }
  81. }
  82. static int enic_get_settings(struct net_device *netdev,
  83. struct ethtool_cmd *ecmd)
  84. {
  85. struct enic *enic = netdev_priv(netdev);
  86. ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  87. ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
  88. ecmd->port = PORT_FIBRE;
  89. ecmd->transceiver = XCVR_EXTERNAL;
  90. if (netif_carrier_ok(netdev)) {
  91. ethtool_cmd_speed_set(ecmd, vnic_dev_port_speed(enic->vdev));
  92. ecmd->duplex = DUPLEX_FULL;
  93. } else {
  94. ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
  95. ecmd->duplex = DUPLEX_UNKNOWN;
  96. }
  97. ecmd->autoneg = AUTONEG_DISABLE;
  98. return 0;
  99. }
  100. static void enic_get_drvinfo(struct net_device *netdev,
  101. struct ethtool_drvinfo *drvinfo)
  102. {
  103. struct enic *enic = netdev_priv(netdev);
  104. struct vnic_devcmd_fw_info *fw_info;
  105. enic_dev_fw_info(enic, &fw_info);
  106. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  107. strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
  108. strlcpy(drvinfo->fw_version, fw_info->fw_version,
  109. sizeof(drvinfo->fw_version));
  110. strlcpy(drvinfo->bus_info, pci_name(enic->pdev),
  111. sizeof(drvinfo->bus_info));
  112. }
  113. static void enic_get_strings(struct net_device *netdev, u32 stringset,
  114. u8 *data)
  115. {
  116. unsigned int i;
  117. switch (stringset) {
  118. case ETH_SS_STATS:
  119. for (i = 0; i < enic_n_tx_stats; i++) {
  120. memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
  121. data += ETH_GSTRING_LEN;
  122. }
  123. for (i = 0; i < enic_n_rx_stats; i++) {
  124. memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
  125. data += ETH_GSTRING_LEN;
  126. }
  127. break;
  128. }
  129. }
  130. static int enic_get_sset_count(struct net_device *netdev, int sset)
  131. {
  132. switch (sset) {
  133. case ETH_SS_STATS:
  134. return enic_n_tx_stats + enic_n_rx_stats;
  135. default:
  136. return -EOPNOTSUPP;
  137. }
  138. }
  139. static void enic_get_ethtool_stats(struct net_device *netdev,
  140. struct ethtool_stats *stats, u64 *data)
  141. {
  142. struct enic *enic = netdev_priv(netdev);
  143. struct vnic_stats *vstats;
  144. unsigned int i;
  145. enic_dev_stats_dump(enic, &vstats);
  146. for (i = 0; i < enic_n_tx_stats; i++)
  147. *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].index];
  148. for (i = 0; i < enic_n_rx_stats; i++)
  149. *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].index];
  150. }
  151. static u32 enic_get_msglevel(struct net_device *netdev)
  152. {
  153. struct enic *enic = netdev_priv(netdev);
  154. return enic->msg_enable;
  155. }
  156. static void enic_set_msglevel(struct net_device *netdev, u32 value)
  157. {
  158. struct enic *enic = netdev_priv(netdev);
  159. enic->msg_enable = value;
  160. }
  161. static int enic_get_coalesce(struct net_device *netdev,
  162. struct ethtool_coalesce *ecmd)
  163. {
  164. struct enic *enic = netdev_priv(netdev);
  165. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  166. ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
  167. ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
  168. if (rxcoal->use_adaptive_rx_coalesce)
  169. ecmd->use_adaptive_rx_coalesce = 1;
  170. ecmd->rx_coalesce_usecs_low = rxcoal->small_pkt_range_start;
  171. ecmd->rx_coalesce_usecs_high = rxcoal->range_end;
  172. return 0;
  173. }
  174. static int enic_set_coalesce(struct net_device *netdev,
  175. struct ethtool_coalesce *ecmd)
  176. {
  177. struct enic *enic = netdev_priv(netdev);
  178. u32 tx_coalesce_usecs;
  179. u32 rx_coalesce_usecs;
  180. u32 rx_coalesce_usecs_low;
  181. u32 rx_coalesce_usecs_high;
  182. u32 coalesce_usecs_max;
  183. unsigned int i, intr;
  184. struct enic_rx_coal *rxcoal = &enic->rx_coalesce_setting;
  185. coalesce_usecs_max = vnic_dev_get_intr_coal_timer_max(enic->vdev);
  186. tx_coalesce_usecs = min_t(u32, ecmd->tx_coalesce_usecs,
  187. coalesce_usecs_max);
  188. rx_coalesce_usecs = min_t(u32, ecmd->rx_coalesce_usecs,
  189. coalesce_usecs_max);
  190. rx_coalesce_usecs_low = min_t(u32, ecmd->rx_coalesce_usecs_low,
  191. coalesce_usecs_max);
  192. rx_coalesce_usecs_high = min_t(u32, ecmd->rx_coalesce_usecs_high,
  193. coalesce_usecs_max);
  194. switch (vnic_dev_get_intr_mode(enic->vdev)) {
  195. case VNIC_DEV_INTR_MODE_INTX:
  196. if (tx_coalesce_usecs != rx_coalesce_usecs)
  197. return -EINVAL;
  198. if (ecmd->use_adaptive_rx_coalesce ||
  199. ecmd->rx_coalesce_usecs_low ||
  200. ecmd->rx_coalesce_usecs_high)
  201. return -EOPNOTSUPP;
  202. intr = enic_legacy_io_intr();
  203. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  204. tx_coalesce_usecs);
  205. break;
  206. case VNIC_DEV_INTR_MODE_MSI:
  207. if (tx_coalesce_usecs != rx_coalesce_usecs)
  208. return -EINVAL;
  209. if (ecmd->use_adaptive_rx_coalesce ||
  210. ecmd->rx_coalesce_usecs_low ||
  211. ecmd->rx_coalesce_usecs_high)
  212. return -EOPNOTSUPP;
  213. vnic_intr_coalescing_timer_set(&enic->intr[0],
  214. tx_coalesce_usecs);
  215. break;
  216. case VNIC_DEV_INTR_MODE_MSIX:
  217. for (i = 0; i < enic->wq_count; i++) {
  218. intr = enic_msix_wq_intr(enic, i);
  219. vnic_intr_coalescing_timer_set(&enic->intr[intr],
  220. tx_coalesce_usecs);
  221. }
  222. if (rxcoal->use_adaptive_rx_coalesce) {
  223. if (!ecmd->use_adaptive_rx_coalesce) {
  224. rxcoal->use_adaptive_rx_coalesce = 0;
  225. enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
  226. }
  227. } else {
  228. if (ecmd->use_adaptive_rx_coalesce)
  229. rxcoal->use_adaptive_rx_coalesce = 1;
  230. else
  231. enic_intr_coal_set_rx(enic, rx_coalesce_usecs);
  232. }
  233. if (ecmd->rx_coalesce_usecs_high) {
  234. if (rx_coalesce_usecs_high <
  235. (rx_coalesce_usecs_low + ENIC_AIC_LARGE_PKT_DIFF))
  236. return -EINVAL;
  237. rxcoal->range_end = rx_coalesce_usecs_high;
  238. rxcoal->small_pkt_range_start = rx_coalesce_usecs_low;
  239. rxcoal->large_pkt_range_start = rx_coalesce_usecs_low +
  240. ENIC_AIC_LARGE_PKT_DIFF;
  241. }
  242. break;
  243. default:
  244. break;
  245. }
  246. enic->tx_coalesce_usecs = tx_coalesce_usecs;
  247. enic->rx_coalesce_usecs = rx_coalesce_usecs;
  248. return 0;
  249. }
  250. static const struct ethtool_ops enic_ethtool_ops = {
  251. .get_settings = enic_get_settings,
  252. .get_drvinfo = enic_get_drvinfo,
  253. .get_msglevel = enic_get_msglevel,
  254. .set_msglevel = enic_set_msglevel,
  255. .get_link = ethtool_op_get_link,
  256. .get_strings = enic_get_strings,
  257. .get_sset_count = enic_get_sset_count,
  258. .get_ethtool_stats = enic_get_ethtool_stats,
  259. .get_coalesce = enic_get_coalesce,
  260. .set_coalesce = enic_set_coalesce,
  261. };
  262. void enic_set_ethtool_ops(struct net_device *netdev)
  263. {
  264. netdev->ethtool_ops = &enic_ethtool_ops;
  265. }