i40evf_ethtool.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2016 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. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40evf */
  27. #include "i40evf.h"
  28. #include <linux/uaccess.h>
  29. struct i40evf_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int stat_offset;
  32. };
  33. #define I40EVF_STAT(_name, _stat) { \
  34. .stat_string = _name, \
  35. .stat_offset = offsetof(struct i40evf_adapter, _stat) \
  36. }
  37. /* All stats are u64, so we don't need to track the size of the field. */
  38. static const struct i40evf_stats i40evf_gstrings_stats[] = {
  39. I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
  40. I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
  41. I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
  42. I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
  43. I40EVF_STAT("rx_discards", current_stats.rx_discards),
  44. I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
  45. I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
  46. I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
  47. I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
  48. I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
  49. I40EVF_STAT("tx_discards", current_stats.tx_discards),
  50. I40EVF_STAT("tx_errors", current_stats.tx_errors),
  51. };
  52. #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
  53. #define I40EVF_QUEUE_STATS_LEN(_dev) \
  54. (((struct i40evf_adapter *)\
  55. netdev_priv(_dev))->num_active_queues \
  56. * 2 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  57. #define I40EVF_STATS_LEN(_dev) \
  58. (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN(_dev))
  59. /**
  60. * i40evf_get_settings - Get Link Speed and Duplex settings
  61. * @netdev: network interface device structure
  62. * @ecmd: ethtool command
  63. *
  64. * Reports speed/duplex settings. Because this is a VF, we don't know what
  65. * kind of link we really have, so we fake it.
  66. **/
  67. static int i40evf_get_settings(struct net_device *netdev,
  68. struct ethtool_cmd *ecmd)
  69. {
  70. struct i40evf_adapter *adapter = netdev_priv(netdev);
  71. ecmd->supported = 0;
  72. ecmd->autoneg = AUTONEG_DISABLE;
  73. ecmd->transceiver = XCVR_DUMMY1;
  74. ecmd->port = PORT_NONE;
  75. /* Set speed and duplex */
  76. switch (adapter->link_speed) {
  77. case I40E_LINK_SPEED_40GB:
  78. ethtool_cmd_speed_set(ecmd, SPEED_40000);
  79. break;
  80. case I40E_LINK_SPEED_20GB:
  81. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  82. break;
  83. case I40E_LINK_SPEED_10GB:
  84. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  85. break;
  86. case I40E_LINK_SPEED_1GB:
  87. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  88. break;
  89. case I40E_LINK_SPEED_100MB:
  90. ethtool_cmd_speed_set(ecmd, SPEED_100);
  91. break;
  92. default:
  93. break;
  94. }
  95. ecmd->duplex = DUPLEX_FULL;
  96. return 0;
  97. }
  98. /**
  99. * i40evf_get_sset_count - Get length of string set
  100. * @netdev: network interface device structure
  101. * @sset: id of string set
  102. *
  103. * Reports size of string table. This driver only supports
  104. * strings for statistics.
  105. **/
  106. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  107. {
  108. if (sset == ETH_SS_STATS)
  109. return I40EVF_STATS_LEN(netdev);
  110. else
  111. return -EINVAL;
  112. }
  113. /**
  114. * i40evf_get_ethtool_stats - report device statistics
  115. * @netdev: network interface device structure
  116. * @stats: ethtool statistics structure
  117. * @data: pointer to data buffer
  118. *
  119. * All statistics are added to the data buffer as an array of u64.
  120. **/
  121. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  122. struct ethtool_stats *stats, u64 *data)
  123. {
  124. struct i40evf_adapter *adapter = netdev_priv(netdev);
  125. int i, j;
  126. char *p;
  127. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  128. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  129. data[i] = *(u64 *)p;
  130. }
  131. for (j = 0; j < adapter->num_active_queues; j++) {
  132. data[i++] = adapter->tx_rings[j].stats.packets;
  133. data[i++] = adapter->tx_rings[j].stats.bytes;
  134. }
  135. for (j = 0; j < adapter->num_active_queues; j++) {
  136. data[i++] = adapter->rx_rings[j].stats.packets;
  137. data[i++] = adapter->rx_rings[j].stats.bytes;
  138. }
  139. }
  140. /**
  141. * i40evf_get_strings - Get string set
  142. * @netdev: network interface device structure
  143. * @sset: id of string set
  144. * @data: buffer for string data
  145. *
  146. * Builds stats string table.
  147. **/
  148. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  149. {
  150. struct i40evf_adapter *adapter = netdev_priv(netdev);
  151. u8 *p = data;
  152. int i;
  153. if (sset == ETH_SS_STATS) {
  154. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  155. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  156. ETH_GSTRING_LEN);
  157. p += ETH_GSTRING_LEN;
  158. }
  159. for (i = 0; i < adapter->num_active_queues; i++) {
  160. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  161. p += ETH_GSTRING_LEN;
  162. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  163. p += ETH_GSTRING_LEN;
  164. }
  165. for (i = 0; i < adapter->num_active_queues; i++) {
  166. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  167. p += ETH_GSTRING_LEN;
  168. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  169. p += ETH_GSTRING_LEN;
  170. }
  171. }
  172. }
  173. /**
  174. * i40evf_get_msglevel - Get debug message level
  175. * @netdev: network interface device structure
  176. *
  177. * Returns current debug message level.
  178. **/
  179. static u32 i40evf_get_msglevel(struct net_device *netdev)
  180. {
  181. struct i40evf_adapter *adapter = netdev_priv(netdev);
  182. return adapter->msg_enable;
  183. }
  184. /**
  185. * i40evf_set_msglevel - Set debug message level
  186. * @netdev: network interface device structure
  187. * @data: message level
  188. *
  189. * Set current debug message level. Higher values cause the driver to
  190. * be noisier.
  191. **/
  192. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  193. {
  194. struct i40evf_adapter *adapter = netdev_priv(netdev);
  195. if (I40E_DEBUG_USER & data)
  196. adapter->hw.debug_mask = data;
  197. adapter->msg_enable = data;
  198. }
  199. /**
  200. * i40evf_get_drvinfo - Get driver info
  201. * @netdev: network interface device structure
  202. * @drvinfo: ethool driver info structure
  203. *
  204. * Returns information about the driver and device for display to the user.
  205. **/
  206. static void i40evf_get_drvinfo(struct net_device *netdev,
  207. struct ethtool_drvinfo *drvinfo)
  208. {
  209. struct i40evf_adapter *adapter = netdev_priv(netdev);
  210. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  211. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  212. strlcpy(drvinfo->fw_version, "N/A", 4);
  213. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  214. }
  215. /**
  216. * i40evf_get_ringparam - Get ring parameters
  217. * @netdev: network interface device structure
  218. * @ring: ethtool ringparam structure
  219. *
  220. * Returns current ring parameters. TX and RX rings are reported separately,
  221. * but the number of rings is not reported.
  222. **/
  223. static void i40evf_get_ringparam(struct net_device *netdev,
  224. struct ethtool_ringparam *ring)
  225. {
  226. struct i40evf_adapter *adapter = netdev_priv(netdev);
  227. ring->rx_max_pending = I40EVF_MAX_RXD;
  228. ring->tx_max_pending = I40EVF_MAX_TXD;
  229. ring->rx_pending = adapter->rx_desc_count;
  230. ring->tx_pending = adapter->tx_desc_count;
  231. }
  232. /**
  233. * i40evf_set_ringparam - Set ring parameters
  234. * @netdev: network interface device structure
  235. * @ring: ethtool ringparam structure
  236. *
  237. * Sets ring parameters. TX and RX rings are controlled separately, but the
  238. * number of rings is not specified, so all rings get the same settings.
  239. **/
  240. static int i40evf_set_ringparam(struct net_device *netdev,
  241. struct ethtool_ringparam *ring)
  242. {
  243. struct i40evf_adapter *adapter = netdev_priv(netdev);
  244. u32 new_rx_count, new_tx_count;
  245. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  246. return -EINVAL;
  247. new_tx_count = clamp_t(u32, ring->tx_pending,
  248. I40EVF_MIN_TXD,
  249. I40EVF_MAX_TXD);
  250. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  251. new_rx_count = clamp_t(u32, ring->rx_pending,
  252. I40EVF_MIN_RXD,
  253. I40EVF_MAX_RXD);
  254. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  255. /* if nothing to do return success */
  256. if ((new_tx_count == adapter->tx_desc_count) &&
  257. (new_rx_count == adapter->rx_desc_count))
  258. return 0;
  259. adapter->tx_desc_count = new_tx_count;
  260. adapter->rx_desc_count = new_rx_count;
  261. if (netif_running(netdev)) {
  262. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  263. schedule_work(&adapter->reset_task);
  264. }
  265. return 0;
  266. }
  267. /**
  268. * i40evf_get_coalesce - Get interrupt coalescing settings
  269. * @netdev: network interface device structure
  270. * @ec: ethtool coalesce structure
  271. *
  272. * Returns current coalescing settings. This is referred to elsewhere in the
  273. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  274. * this functionality.
  275. **/
  276. static int i40evf_get_coalesce(struct net_device *netdev,
  277. struct ethtool_coalesce *ec)
  278. {
  279. struct i40evf_adapter *adapter = netdev_priv(netdev);
  280. struct i40e_vsi *vsi = &adapter->vsi;
  281. ec->tx_max_coalesced_frames = vsi->work_limit;
  282. ec->rx_max_coalesced_frames = vsi->work_limit;
  283. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  284. ec->use_adaptive_rx_coalesce = 1;
  285. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  286. ec->use_adaptive_tx_coalesce = 1;
  287. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  288. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  289. return 0;
  290. }
  291. /**
  292. * i40evf_set_coalesce - Set interrupt coalescing settings
  293. * @netdev: network interface device structure
  294. * @ec: ethtool coalesce structure
  295. *
  296. * Change current coalescing settings.
  297. **/
  298. static int i40evf_set_coalesce(struct net_device *netdev,
  299. struct ethtool_coalesce *ec)
  300. {
  301. struct i40evf_adapter *adapter = netdev_priv(netdev);
  302. struct i40e_hw *hw = &adapter->hw;
  303. struct i40e_vsi *vsi = &adapter->vsi;
  304. struct i40e_q_vector *q_vector;
  305. int i;
  306. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  307. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  308. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  309. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  310. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  311. else
  312. return -EINVAL;
  313. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  314. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  315. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  316. else if (ec->use_adaptive_tx_coalesce)
  317. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  318. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  319. else
  320. return -EINVAL;
  321. if (ec->use_adaptive_rx_coalesce)
  322. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  323. else
  324. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  325. if (ec->use_adaptive_tx_coalesce)
  326. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  327. else
  328. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  329. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  330. q_vector = &adapter->q_vectors[i];
  331. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  332. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  333. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  334. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  335. i40e_flush(hw);
  336. }
  337. return 0;
  338. }
  339. /**
  340. * i40evf_get_rxnfc - command to get RX flow classification rules
  341. * @netdev: network interface device structure
  342. * @cmd: ethtool rxnfc command
  343. *
  344. * Returns Success if the command is supported.
  345. **/
  346. static int i40evf_get_rxnfc(struct net_device *netdev,
  347. struct ethtool_rxnfc *cmd,
  348. u32 *rule_locs)
  349. {
  350. struct i40evf_adapter *adapter = netdev_priv(netdev);
  351. int ret = -EOPNOTSUPP;
  352. switch (cmd->cmd) {
  353. case ETHTOOL_GRXRINGS:
  354. cmd->data = adapter->num_active_queues;
  355. ret = 0;
  356. break;
  357. case ETHTOOL_GRXFH:
  358. netdev_info(netdev,
  359. "RSS hash info is not available to vf, use pf.\n");
  360. break;
  361. default:
  362. break;
  363. }
  364. return ret;
  365. }
  366. /**
  367. * i40evf_get_channels: get the number of channels supported by the device
  368. * @netdev: network interface device structure
  369. * @ch: channel information structure
  370. *
  371. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  372. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  373. **/
  374. static void i40evf_get_channels(struct net_device *netdev,
  375. struct ethtool_channels *ch)
  376. {
  377. struct i40evf_adapter *adapter = netdev_priv(netdev);
  378. /* Report maximum channels */
  379. ch->max_combined = adapter->num_active_queues;
  380. ch->max_other = NONQ_VECS;
  381. ch->other_count = NONQ_VECS;
  382. ch->combined_count = adapter->num_active_queues;
  383. }
  384. /**
  385. * i40evf_get_rxfh_key_size - get the RSS hash key size
  386. * @netdev: network interface device structure
  387. *
  388. * Returns the table size.
  389. **/
  390. static u32 i40evf_get_rxfh_key_size(struct net_device *netdev)
  391. {
  392. struct i40evf_adapter *adapter = netdev_priv(netdev);
  393. return adapter->rss_key_size;
  394. }
  395. /**
  396. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  397. * @netdev: network interface device structure
  398. *
  399. * Returns the table size.
  400. **/
  401. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  402. {
  403. struct i40evf_adapter *adapter = netdev_priv(netdev);
  404. return adapter->rss_lut_size;
  405. }
  406. /**
  407. * i40evf_get_rxfh - get the rx flow hash indirection table
  408. * @netdev: network interface device structure
  409. * @indir: indirection table
  410. * @key: hash key
  411. *
  412. * Reads the indirection table directly from the hardware. Always returns 0.
  413. **/
  414. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  415. u8 *hfunc)
  416. {
  417. struct i40evf_adapter *adapter = netdev_priv(netdev);
  418. u16 i;
  419. if (hfunc)
  420. *hfunc = ETH_RSS_HASH_TOP;
  421. if (!indir)
  422. return 0;
  423. memcpy(key, adapter->rss_key, adapter->rss_key_size);
  424. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  425. for (i = 0; i < adapter->rss_lut_size; i++)
  426. indir[i] = (u32)adapter->rss_lut[i];
  427. return 0;
  428. }
  429. /**
  430. * i40evf_set_rxfh - set the rx flow hash indirection table
  431. * @netdev: network interface device structure
  432. * @indir: indirection table
  433. * @key: hash key
  434. *
  435. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  436. * returns 0 after programming the table.
  437. **/
  438. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  439. const u8 *key, const u8 hfunc)
  440. {
  441. struct i40evf_adapter *adapter = netdev_priv(netdev);
  442. u16 i;
  443. /* We do not allow change in unsupported parameters */
  444. if (key ||
  445. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  446. return -EOPNOTSUPP;
  447. if (!indir)
  448. return 0;
  449. if (key) {
  450. memcpy(adapter->rss_key, key, adapter->rss_key_size);
  451. }
  452. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  453. for (i = 0; i < adapter->rss_lut_size; i++)
  454. adapter->rss_lut[i] = (u8)(indir[i]);
  455. return i40evf_config_rss(adapter);
  456. }
  457. static const struct ethtool_ops i40evf_ethtool_ops = {
  458. .get_settings = i40evf_get_settings,
  459. .get_drvinfo = i40evf_get_drvinfo,
  460. .get_link = ethtool_op_get_link,
  461. .get_ringparam = i40evf_get_ringparam,
  462. .set_ringparam = i40evf_set_ringparam,
  463. .get_strings = i40evf_get_strings,
  464. .get_ethtool_stats = i40evf_get_ethtool_stats,
  465. .get_sset_count = i40evf_get_sset_count,
  466. .get_msglevel = i40evf_get_msglevel,
  467. .set_msglevel = i40evf_set_msglevel,
  468. .get_coalesce = i40evf_get_coalesce,
  469. .set_coalesce = i40evf_set_coalesce,
  470. .get_rxnfc = i40evf_get_rxnfc,
  471. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  472. .get_rxfh = i40evf_get_rxfh,
  473. .set_rxfh = i40evf_set_rxfh,
  474. .get_channels = i40evf_get_channels,
  475. .get_rxfh_key_size = i40evf_get_rxfh_key_size,
  476. };
  477. /**
  478. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  479. * @netdev: network interface device structure
  480. *
  481. * Sets ethtool ops struct in our netdev so that ethtool can call
  482. * our functions.
  483. **/
  484. void i40evf_set_ethtool_ops(struct net_device *netdev)
  485. {
  486. netdev->ethtool_ops = &i40evf_ethtool_ops;
  487. }