i40evf_ethtool.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Contact Information:
  19. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *
  22. ******************************************************************************/
  23. /* ethtool support for i40evf */
  24. #include "i40evf.h"
  25. #include <linux/uaccess.h>
  26. struct i40evf_stats {
  27. char stat_string[ETH_GSTRING_LEN];
  28. int stat_offset;
  29. };
  30. #define I40EVF_STAT(_name, _stat) { \
  31. .stat_string = _name, \
  32. .stat_offset = offsetof(struct i40evf_adapter, _stat) \
  33. }
  34. /* All stats are u64, so we don't need to track the size of the field. */
  35. static const struct i40evf_stats i40evf_gstrings_stats[] = {
  36. I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
  37. I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
  38. I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
  39. I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
  40. I40EVF_STAT("rx_discards", current_stats.rx_discards),
  41. I40EVF_STAT("rx_errors", current_stats.rx_errors),
  42. I40EVF_STAT("rx_missed", current_stats.rx_missed),
  43. I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
  44. I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
  45. I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
  46. I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
  47. I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
  48. I40EVF_STAT("tx_discards", current_stats.tx_discards),
  49. I40EVF_STAT("tx_errors", current_stats.tx_errors),
  50. };
  51. #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
  52. #define I40EVF_QUEUE_STATS_LEN \
  53. (((struct i40evf_adapter *) \
  54. netdev_priv(netdev))->vsi_res->num_queue_pairs * 4)
  55. #define I40EVF_STATS_LEN (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN)
  56. /**
  57. * i40evf_get_settings - Get Link Speed and Duplex settings
  58. * @netdev: network interface device structure
  59. * @ecmd: ethtool command
  60. *
  61. * Reports speed/duplex settings. Because this is a VF, we don't know what
  62. * kind of link we really have, so we fake it.
  63. **/
  64. static int i40evf_get_settings(struct net_device *netdev,
  65. struct ethtool_cmd *ecmd)
  66. {
  67. /* In the future the VF will be able to query the PF for
  68. * some information - for now use a dummy value
  69. */
  70. ecmd->supported = SUPPORTED_10000baseT_Full;
  71. ecmd->autoneg = AUTONEG_DISABLE;
  72. ecmd->transceiver = XCVR_DUMMY1;
  73. ecmd->port = PORT_NONE;
  74. return 0;
  75. }
  76. /**
  77. * i40evf_get_sset_count - Get length of string set
  78. * @netdev: network interface device structure
  79. * @sset: id of string set
  80. *
  81. * Reports size of string table. This driver only supports
  82. * strings for statistics.
  83. **/
  84. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  85. {
  86. if (sset == ETH_SS_STATS)
  87. return I40EVF_STATS_LEN;
  88. else
  89. return -ENOTSUPP;
  90. }
  91. /**
  92. * i40evf_get_ethtool_stats - report device statistics
  93. * @netdev: network interface device structure
  94. * @stats: ethtool statistics structure
  95. * @data: pointer to data buffer
  96. *
  97. * All statistics are added to the data buffer as an array of u64.
  98. **/
  99. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  100. struct ethtool_stats *stats, u64 *data)
  101. {
  102. struct i40evf_adapter *adapter = netdev_priv(netdev);
  103. int i, j;
  104. char *p;
  105. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  106. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  107. data[i] = *(u64 *)p;
  108. }
  109. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  110. data[i++] = adapter->tx_rings[j]->stats.packets;
  111. data[i++] = adapter->tx_rings[j]->stats.bytes;
  112. }
  113. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  114. data[i++] = adapter->rx_rings[j]->stats.packets;
  115. data[i++] = adapter->rx_rings[j]->stats.bytes;
  116. }
  117. }
  118. /**
  119. * i40evf_get_strings - Get string set
  120. * @netdev: network interface device structure
  121. * @sset: id of string set
  122. * @data: buffer for string data
  123. *
  124. * Builds stats string table.
  125. **/
  126. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  127. {
  128. struct i40evf_adapter *adapter = netdev_priv(netdev);
  129. u8 *p = data;
  130. int i;
  131. if (sset == ETH_SS_STATS) {
  132. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  133. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  134. ETH_GSTRING_LEN);
  135. p += ETH_GSTRING_LEN;
  136. }
  137. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  138. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  139. p += ETH_GSTRING_LEN;
  140. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  141. p += ETH_GSTRING_LEN;
  142. }
  143. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  144. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  145. p += ETH_GSTRING_LEN;
  146. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  147. p += ETH_GSTRING_LEN;
  148. }
  149. }
  150. }
  151. /**
  152. * i40evf_get_msglevel - Get debug message level
  153. * @netdev: network interface device structure
  154. *
  155. * Returns current debug message level.
  156. **/
  157. static u32 i40evf_get_msglevel(struct net_device *netdev)
  158. {
  159. struct i40evf_adapter *adapter = netdev_priv(netdev);
  160. return adapter->msg_enable;
  161. }
  162. /**
  163. * i40evf_get_msglevel - Set debug message level
  164. * @netdev: network interface device structure
  165. * @data: message level
  166. *
  167. * Set current debug message level. Higher values cause the driver to
  168. * be noisier.
  169. **/
  170. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  171. {
  172. struct i40evf_adapter *adapter = netdev_priv(netdev);
  173. adapter->msg_enable = data;
  174. }
  175. /**
  176. * i40evf_get_drvinto - Get driver info
  177. * @netdev: network interface device structure
  178. * @drvinfo: ethool driver info structure
  179. *
  180. * Returns information about the driver and device for display to the user.
  181. **/
  182. static void i40evf_get_drvinfo(struct net_device *netdev,
  183. struct ethtool_drvinfo *drvinfo)
  184. {
  185. struct i40evf_adapter *adapter = netdev_priv(netdev);
  186. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  187. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  188. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  189. }
  190. /**
  191. * i40evf_get_ringparam - Get ring parameters
  192. * @netdev: network interface device structure
  193. * @ring: ethtool ringparam structure
  194. *
  195. * Returns current ring parameters. TX and RX rings are reported separately,
  196. * but the number of rings is not reported.
  197. **/
  198. static void i40evf_get_ringparam(struct net_device *netdev,
  199. struct ethtool_ringparam *ring)
  200. {
  201. struct i40evf_adapter *adapter = netdev_priv(netdev);
  202. struct i40e_ring *tx_ring = adapter->tx_rings[0];
  203. struct i40e_ring *rx_ring = adapter->rx_rings[0];
  204. ring->rx_max_pending = I40EVF_MAX_RXD;
  205. ring->tx_max_pending = I40EVF_MAX_TXD;
  206. ring->rx_pending = rx_ring->count;
  207. ring->tx_pending = tx_ring->count;
  208. }
  209. /**
  210. * i40evf_set_ringparam - Set ring parameters
  211. * @netdev: network interface device structure
  212. * @ring: ethtool ringparam structure
  213. *
  214. * Sets ring parameters. TX and RX rings are controlled separately, but the
  215. * number of rings is not specified, so all rings get the same settings.
  216. **/
  217. static int i40evf_set_ringparam(struct net_device *netdev,
  218. struct ethtool_ringparam *ring)
  219. {
  220. struct i40evf_adapter *adapter = netdev_priv(netdev);
  221. u32 new_rx_count, new_tx_count;
  222. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  223. return -EINVAL;
  224. new_tx_count = clamp_t(u32, ring->tx_pending,
  225. I40EVF_MIN_TXD,
  226. I40EVF_MAX_TXD);
  227. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  228. new_rx_count = clamp_t(u32, ring->rx_pending,
  229. I40EVF_MIN_RXD,
  230. I40EVF_MAX_RXD);
  231. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  232. /* if nothing to do return success */
  233. if ((new_tx_count == adapter->txd_count) &&
  234. (new_rx_count == adapter->rxd_count))
  235. return 0;
  236. adapter->txd_count = new_tx_count;
  237. adapter->rxd_count = new_rx_count;
  238. if (netif_running(netdev))
  239. i40evf_reinit_locked(adapter);
  240. return 0;
  241. }
  242. /**
  243. * i40evf_get_coalesce - Get interrupt coalescing settings
  244. * @netdev: network interface device structure
  245. * @ec: ethtool coalesce structure
  246. *
  247. * Returns current coalescing settings. This is referred to elsewhere in the
  248. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  249. * this functionality.
  250. **/
  251. static int i40evf_get_coalesce(struct net_device *netdev,
  252. struct ethtool_coalesce *ec)
  253. {
  254. struct i40evf_adapter *adapter = netdev_priv(netdev);
  255. struct i40e_vsi *vsi = &adapter->vsi;
  256. ec->tx_max_coalesced_frames = vsi->work_limit;
  257. ec->rx_max_coalesced_frames = vsi->work_limit;
  258. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  259. ec->rx_coalesce_usecs = 1;
  260. else
  261. ec->rx_coalesce_usecs = vsi->rx_itr_setting;
  262. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  263. ec->tx_coalesce_usecs = 1;
  264. else
  265. ec->tx_coalesce_usecs = vsi->tx_itr_setting;
  266. return 0;
  267. }
  268. /**
  269. * i40evf_set_coalesce - Set interrupt coalescing settings
  270. * @netdev: network interface device structure
  271. * @ec: ethtool coalesce structure
  272. *
  273. * Change current coalescing settings.
  274. **/
  275. static int i40evf_set_coalesce(struct net_device *netdev,
  276. struct ethtool_coalesce *ec)
  277. {
  278. struct i40evf_adapter *adapter = netdev_priv(netdev);
  279. struct i40e_hw *hw = &adapter->hw;
  280. struct i40e_vsi *vsi = &adapter->vsi;
  281. struct i40e_q_vector *q_vector;
  282. int i;
  283. if (ec->tx_max_coalesced_frames || ec->rx_max_coalesced_frames)
  284. vsi->work_limit = ec->tx_max_coalesced_frames;
  285. switch (ec->rx_coalesce_usecs) {
  286. case 0:
  287. vsi->rx_itr_setting = 0;
  288. break;
  289. case 1:
  290. vsi->rx_itr_setting = (I40E_ITR_DYNAMIC
  291. | ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  292. break;
  293. default:
  294. if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  295. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  296. return -EINVAL;
  297. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  298. break;
  299. }
  300. switch (ec->tx_coalesce_usecs) {
  301. case 0:
  302. vsi->tx_itr_setting = 0;
  303. break;
  304. case 1:
  305. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC
  306. | ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
  307. break;
  308. default:
  309. if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  310. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  311. return -EINVAL;
  312. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  313. break;
  314. }
  315. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  316. q_vector = adapter->q_vector[i];
  317. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  318. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  319. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  320. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  321. i40e_flush(hw);
  322. }
  323. return 0;
  324. }
  325. static struct ethtool_ops i40evf_ethtool_ops = {
  326. .get_settings = i40evf_get_settings,
  327. .get_drvinfo = i40evf_get_drvinfo,
  328. .get_link = ethtool_op_get_link,
  329. .get_ringparam = i40evf_get_ringparam,
  330. .set_ringparam = i40evf_set_ringparam,
  331. .get_strings = i40evf_get_strings,
  332. .get_ethtool_stats = i40evf_get_ethtool_stats,
  333. .get_sset_count = i40evf_get_sset_count,
  334. .get_msglevel = i40evf_get_msglevel,
  335. .set_msglevel = i40evf_set_msglevel,
  336. .get_coalesce = i40evf_get_coalesce,
  337. .set_coalesce = i40evf_set_coalesce,
  338. };
  339. /**
  340. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  341. * @netdev: network interface device structure
  342. *
  343. * Sets ethtool ops struct in our netdev so that ethtool can call
  344. * our functions.
  345. **/
  346. void i40evf_set_ethtool_ops(struct net_device *netdev)
  347. {
  348. SET_ETHTOOL_OPS(netdev, &i40evf_ethtool_ops);
  349. }