i40evf_ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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_25GB:
  81. #ifdef SPEED_25000
  82. ethtool_cmd_speed_set(ecmd, SPEED_25000);
  83. #else
  84. netdev_info(netdev,
  85. "Speed is 25G, display not supported by this version of ethtool.\n");
  86. #endif
  87. break;
  88. case I40E_LINK_SPEED_20GB:
  89. ethtool_cmd_speed_set(ecmd, SPEED_20000);
  90. break;
  91. case I40E_LINK_SPEED_10GB:
  92. ethtool_cmd_speed_set(ecmd, SPEED_10000);
  93. break;
  94. case I40E_LINK_SPEED_1GB:
  95. ethtool_cmd_speed_set(ecmd, SPEED_1000);
  96. break;
  97. case I40E_LINK_SPEED_100MB:
  98. ethtool_cmd_speed_set(ecmd, SPEED_100);
  99. break;
  100. default:
  101. break;
  102. }
  103. ecmd->duplex = DUPLEX_FULL;
  104. return 0;
  105. }
  106. /**
  107. * i40evf_get_sset_count - Get length of string set
  108. * @netdev: network interface device structure
  109. * @sset: id of string set
  110. *
  111. * Reports size of string table. This driver only supports
  112. * strings for statistics.
  113. **/
  114. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  115. {
  116. if (sset == ETH_SS_STATS)
  117. return I40EVF_STATS_LEN(netdev);
  118. else
  119. return -EINVAL;
  120. }
  121. /**
  122. * i40evf_get_ethtool_stats - report device statistics
  123. * @netdev: network interface device structure
  124. * @stats: ethtool statistics structure
  125. * @data: pointer to data buffer
  126. *
  127. * All statistics are added to the data buffer as an array of u64.
  128. **/
  129. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  130. struct ethtool_stats *stats, u64 *data)
  131. {
  132. struct i40evf_adapter *adapter = netdev_priv(netdev);
  133. int i, j;
  134. char *p;
  135. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  136. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  137. data[i] = *(u64 *)p;
  138. }
  139. for (j = 0; j < adapter->num_active_queues; j++) {
  140. data[i++] = adapter->tx_rings[j].stats.packets;
  141. data[i++] = adapter->tx_rings[j].stats.bytes;
  142. }
  143. for (j = 0; j < adapter->num_active_queues; j++) {
  144. data[i++] = adapter->rx_rings[j].stats.packets;
  145. data[i++] = adapter->rx_rings[j].stats.bytes;
  146. }
  147. }
  148. /**
  149. * i40evf_get_strings - Get string set
  150. * @netdev: network interface device structure
  151. * @sset: id of string set
  152. * @data: buffer for string data
  153. *
  154. * Builds stats string table.
  155. **/
  156. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  157. {
  158. struct i40evf_adapter *adapter = netdev_priv(netdev);
  159. u8 *p = data;
  160. int i;
  161. if (sset == ETH_SS_STATS) {
  162. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  163. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  164. ETH_GSTRING_LEN);
  165. p += ETH_GSTRING_LEN;
  166. }
  167. for (i = 0; i < adapter->num_active_queues; i++) {
  168. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  169. p += ETH_GSTRING_LEN;
  170. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  171. p += ETH_GSTRING_LEN;
  172. }
  173. for (i = 0; i < adapter->num_active_queues; i++) {
  174. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  175. p += ETH_GSTRING_LEN;
  176. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  177. p += ETH_GSTRING_LEN;
  178. }
  179. }
  180. }
  181. /**
  182. * i40evf_get_msglevel - Get debug message level
  183. * @netdev: network interface device structure
  184. *
  185. * Returns current debug message level.
  186. **/
  187. static u32 i40evf_get_msglevel(struct net_device *netdev)
  188. {
  189. struct i40evf_adapter *adapter = netdev_priv(netdev);
  190. return adapter->msg_enable;
  191. }
  192. /**
  193. * i40evf_set_msglevel - Set debug message level
  194. * @netdev: network interface device structure
  195. * @data: message level
  196. *
  197. * Set current debug message level. Higher values cause the driver to
  198. * be noisier.
  199. **/
  200. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  201. {
  202. struct i40evf_adapter *adapter = netdev_priv(netdev);
  203. if (I40E_DEBUG_USER & data)
  204. adapter->hw.debug_mask = data;
  205. adapter->msg_enable = data;
  206. }
  207. /**
  208. * i40evf_get_drvinfo - Get driver info
  209. * @netdev: network interface device structure
  210. * @drvinfo: ethool driver info structure
  211. *
  212. * Returns information about the driver and device for display to the user.
  213. **/
  214. static void i40evf_get_drvinfo(struct net_device *netdev,
  215. struct ethtool_drvinfo *drvinfo)
  216. {
  217. struct i40evf_adapter *adapter = netdev_priv(netdev);
  218. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  219. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  220. strlcpy(drvinfo->fw_version, "N/A", 4);
  221. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  222. }
  223. /**
  224. * i40evf_get_ringparam - Get ring parameters
  225. * @netdev: network interface device structure
  226. * @ring: ethtool ringparam structure
  227. *
  228. * Returns current ring parameters. TX and RX rings are reported separately,
  229. * but the number of rings is not reported.
  230. **/
  231. static void i40evf_get_ringparam(struct net_device *netdev,
  232. struct ethtool_ringparam *ring)
  233. {
  234. struct i40evf_adapter *adapter = netdev_priv(netdev);
  235. ring->rx_max_pending = I40EVF_MAX_RXD;
  236. ring->tx_max_pending = I40EVF_MAX_TXD;
  237. ring->rx_pending = adapter->rx_desc_count;
  238. ring->tx_pending = adapter->tx_desc_count;
  239. }
  240. /**
  241. * i40evf_set_ringparam - Set ring parameters
  242. * @netdev: network interface device structure
  243. * @ring: ethtool ringparam structure
  244. *
  245. * Sets ring parameters. TX and RX rings are controlled separately, but the
  246. * number of rings is not specified, so all rings get the same settings.
  247. **/
  248. static int i40evf_set_ringparam(struct net_device *netdev,
  249. struct ethtool_ringparam *ring)
  250. {
  251. struct i40evf_adapter *adapter = netdev_priv(netdev);
  252. u32 new_rx_count, new_tx_count;
  253. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  254. return -EINVAL;
  255. new_tx_count = clamp_t(u32, ring->tx_pending,
  256. I40EVF_MIN_TXD,
  257. I40EVF_MAX_TXD);
  258. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  259. new_rx_count = clamp_t(u32, ring->rx_pending,
  260. I40EVF_MIN_RXD,
  261. I40EVF_MAX_RXD);
  262. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  263. /* if nothing to do return success */
  264. if ((new_tx_count == adapter->tx_desc_count) &&
  265. (new_rx_count == adapter->rx_desc_count))
  266. return 0;
  267. adapter->tx_desc_count = new_tx_count;
  268. adapter->rx_desc_count = new_rx_count;
  269. if (netif_running(netdev)) {
  270. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  271. schedule_work(&adapter->reset_task);
  272. }
  273. return 0;
  274. }
  275. /**
  276. * __i40evf_get_coalesce - get per-queue coalesce settings
  277. * @netdev: the netdev to check
  278. * @ec: ethtool coalesce data structure
  279. * @queue: which queue to pick
  280. *
  281. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  282. * are per queue. If queue is <0 then we default to queue 0 as the
  283. * representative value.
  284. **/
  285. static int __i40evf_get_coalesce(struct net_device *netdev,
  286. struct ethtool_coalesce *ec,
  287. int queue)
  288. {
  289. struct i40evf_adapter *adapter = netdev_priv(netdev);
  290. struct i40e_vsi *vsi = &adapter->vsi;
  291. struct i40e_ring *rx_ring, *tx_ring;
  292. ec->tx_max_coalesced_frames = vsi->work_limit;
  293. ec->rx_max_coalesced_frames = vsi->work_limit;
  294. /* Rx and Tx usecs per queue value. If user doesn't specify the
  295. * queue, return queue 0's value to represent.
  296. */
  297. if (queue < 0)
  298. queue = 0;
  299. else if (queue >= adapter->num_active_queues)
  300. return -EINVAL;
  301. rx_ring = &adapter->rx_rings[queue];
  302. tx_ring = &adapter->tx_rings[queue];
  303. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  304. ec->use_adaptive_rx_coalesce = 1;
  305. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  306. ec->use_adaptive_tx_coalesce = 1;
  307. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  308. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  309. return 0;
  310. }
  311. /**
  312. * i40evf_get_coalesce - Get interrupt coalescing settings
  313. * @netdev: network interface device structure
  314. * @ec: ethtool coalesce structure
  315. *
  316. * Returns current coalescing settings. This is referred to elsewhere in the
  317. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  318. * this functionality. Note that if per-queue settings have been modified this
  319. * only represents the settings of queue 0.
  320. **/
  321. static int i40evf_get_coalesce(struct net_device *netdev,
  322. struct ethtool_coalesce *ec)
  323. {
  324. return __i40evf_get_coalesce(netdev, ec, -1);
  325. }
  326. /**
  327. * i40evf_get_per_queue_coalesce - get coalesce values for specific queue
  328. * @netdev: netdev to read
  329. * @ec: coalesce settings from ethtool
  330. * @queue: the queue to read
  331. *
  332. * Read specific queue's coalesce settings.
  333. **/
  334. static int i40evf_get_per_queue_coalesce(struct net_device *netdev,
  335. u32 queue,
  336. struct ethtool_coalesce *ec)
  337. {
  338. return __i40evf_get_coalesce(netdev, ec, queue);
  339. }
  340. /**
  341. * i40evf_set_itr_per_queue - set ITR values for specific queue
  342. * @vsi: the VSI to set values for
  343. * @ec: coalesce settings from ethtool
  344. * @queue: the queue to modify
  345. *
  346. * Change the ITR settings for a specific queue.
  347. **/
  348. static void i40evf_set_itr_per_queue(struct i40evf_adapter *adapter,
  349. struct ethtool_coalesce *ec,
  350. int queue)
  351. {
  352. struct i40e_vsi *vsi = &adapter->vsi;
  353. struct i40e_hw *hw = &adapter->hw;
  354. struct i40e_q_vector *q_vector;
  355. u16 vector;
  356. adapter->rx_rings[queue].rx_itr_setting = ec->rx_coalesce_usecs;
  357. adapter->tx_rings[queue].tx_itr_setting = ec->tx_coalesce_usecs;
  358. if (ec->use_adaptive_rx_coalesce)
  359. adapter->rx_rings[queue].rx_itr_setting |= I40E_ITR_DYNAMIC;
  360. else
  361. adapter->rx_rings[queue].rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  362. if (ec->use_adaptive_tx_coalesce)
  363. adapter->tx_rings[queue].tx_itr_setting |= I40E_ITR_DYNAMIC;
  364. else
  365. adapter->tx_rings[queue].tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  366. q_vector = adapter->rx_rings[queue].q_vector;
  367. q_vector->rx.itr = ITR_TO_REG(adapter->rx_rings[queue].rx_itr_setting);
  368. vector = vsi->base_vector + q_vector->v_idx;
  369. wr32(hw, I40E_VFINT_ITRN1(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  370. q_vector = adapter->tx_rings[queue].q_vector;
  371. q_vector->tx.itr = ITR_TO_REG(adapter->tx_rings[queue].tx_itr_setting);
  372. vector = vsi->base_vector + q_vector->v_idx;
  373. wr32(hw, I40E_VFINT_ITRN1(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  374. i40e_flush(hw);
  375. }
  376. /**
  377. * __i40evf_set_coalesce - set coalesce settings for particular queue
  378. * @netdev: the netdev to change
  379. * @ec: ethtool coalesce settings
  380. * @queue: the queue to change
  381. *
  382. * Sets the coalesce settings for a particular queue.
  383. **/
  384. static int __i40evf_set_coalesce(struct net_device *netdev,
  385. struct ethtool_coalesce *ec,
  386. int queue)
  387. {
  388. struct i40evf_adapter *adapter = netdev_priv(netdev);
  389. struct i40e_vsi *vsi = &adapter->vsi;
  390. int i;
  391. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  392. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  393. if (ec->rx_coalesce_usecs == 0) {
  394. if (ec->use_adaptive_rx_coalesce)
  395. netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  396. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  397. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  398. netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  399. return -EINVAL;
  400. }
  401. else
  402. if (ec->tx_coalesce_usecs == 0) {
  403. if (ec->use_adaptive_tx_coalesce)
  404. netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  405. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  406. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  407. netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  408. return -EINVAL;
  409. }
  410. /* Rx and Tx usecs has per queue value. If user doesn't specify the
  411. * queue, apply to all queues.
  412. */
  413. if (queue < 0) {
  414. for (i = 0; i < adapter->num_active_queues; i++)
  415. i40evf_set_itr_per_queue(adapter, ec, i);
  416. } else if (queue < adapter->num_active_queues) {
  417. i40evf_set_itr_per_queue(adapter, ec, queue);
  418. } else {
  419. netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  420. adapter->num_active_queues - 1);
  421. return -EINVAL;
  422. }
  423. return 0;
  424. }
  425. /**
  426. * i40evf_set_coalesce - Set interrupt coalescing settings
  427. * @netdev: network interface device structure
  428. * @ec: ethtool coalesce structure
  429. *
  430. * Change current coalescing settings for every queue.
  431. **/
  432. static int i40evf_set_coalesce(struct net_device *netdev,
  433. struct ethtool_coalesce *ec)
  434. {
  435. return __i40evf_set_coalesce(netdev, ec, -1);
  436. }
  437. /**
  438. * i40evf_set_per_queue_coalesce - set specific queue's coalesce settings
  439. * @netdev: the netdev to change
  440. * @ec: ethtool's coalesce settings
  441. * @queue: the queue to modify
  442. *
  443. * Modifies a specific queue's coalesce settings.
  444. */
  445. static int i40evf_set_per_queue_coalesce(struct net_device *netdev,
  446. u32 queue,
  447. struct ethtool_coalesce *ec)
  448. {
  449. return __i40evf_set_coalesce(netdev, ec, queue);
  450. }
  451. /**
  452. * i40evf_get_rxnfc - command to get RX flow classification rules
  453. * @netdev: network interface device structure
  454. * @cmd: ethtool rxnfc command
  455. *
  456. * Returns Success if the command is supported.
  457. **/
  458. static int i40evf_get_rxnfc(struct net_device *netdev,
  459. struct ethtool_rxnfc *cmd,
  460. u32 *rule_locs)
  461. {
  462. struct i40evf_adapter *adapter = netdev_priv(netdev);
  463. int ret = -EOPNOTSUPP;
  464. switch (cmd->cmd) {
  465. case ETHTOOL_GRXRINGS:
  466. cmd->data = adapter->num_active_queues;
  467. ret = 0;
  468. break;
  469. case ETHTOOL_GRXFH:
  470. netdev_info(netdev,
  471. "RSS hash info is not available to vf, use pf.\n");
  472. break;
  473. default:
  474. break;
  475. }
  476. return ret;
  477. }
  478. /**
  479. * i40evf_get_channels: get the number of channels supported by the device
  480. * @netdev: network interface device structure
  481. * @ch: channel information structure
  482. *
  483. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  484. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  485. **/
  486. static void i40evf_get_channels(struct net_device *netdev,
  487. struct ethtool_channels *ch)
  488. {
  489. struct i40evf_adapter *adapter = netdev_priv(netdev);
  490. /* Report maximum channels */
  491. ch->max_combined = adapter->num_active_queues;
  492. ch->max_other = NONQ_VECS;
  493. ch->other_count = NONQ_VECS;
  494. ch->combined_count = adapter->num_active_queues;
  495. }
  496. /**
  497. * i40evf_get_rxfh_key_size - get the RSS hash key size
  498. * @netdev: network interface device structure
  499. *
  500. * Returns the table size.
  501. **/
  502. static u32 i40evf_get_rxfh_key_size(struct net_device *netdev)
  503. {
  504. struct i40evf_adapter *adapter = netdev_priv(netdev);
  505. return adapter->rss_key_size;
  506. }
  507. /**
  508. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  509. * @netdev: network interface device structure
  510. *
  511. * Returns the table size.
  512. **/
  513. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  514. {
  515. struct i40evf_adapter *adapter = netdev_priv(netdev);
  516. return adapter->rss_lut_size;
  517. }
  518. /**
  519. * i40evf_get_rxfh - get the rx flow hash indirection table
  520. * @netdev: network interface device structure
  521. * @indir: indirection table
  522. * @key: hash key
  523. *
  524. * Reads the indirection table directly from the hardware. Always returns 0.
  525. **/
  526. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  527. u8 *hfunc)
  528. {
  529. struct i40evf_adapter *adapter = netdev_priv(netdev);
  530. u16 i;
  531. if (hfunc)
  532. *hfunc = ETH_RSS_HASH_TOP;
  533. if (!indir)
  534. return 0;
  535. memcpy(key, adapter->rss_key, adapter->rss_key_size);
  536. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  537. for (i = 0; i < adapter->rss_lut_size; i++)
  538. indir[i] = (u32)adapter->rss_lut[i];
  539. return 0;
  540. }
  541. /**
  542. * i40evf_set_rxfh - set the rx flow hash indirection table
  543. * @netdev: network interface device structure
  544. * @indir: indirection table
  545. * @key: hash key
  546. *
  547. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  548. * returns 0 after programming the table.
  549. **/
  550. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  551. const u8 *key, const u8 hfunc)
  552. {
  553. struct i40evf_adapter *adapter = netdev_priv(netdev);
  554. u16 i;
  555. /* We do not allow change in unsupported parameters */
  556. if (key ||
  557. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  558. return -EOPNOTSUPP;
  559. if (!indir)
  560. return 0;
  561. if (key) {
  562. memcpy(adapter->rss_key, key, adapter->rss_key_size);
  563. }
  564. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  565. for (i = 0; i < adapter->rss_lut_size; i++)
  566. adapter->rss_lut[i] = (u8)(indir[i]);
  567. return i40evf_config_rss(adapter);
  568. }
  569. static const struct ethtool_ops i40evf_ethtool_ops = {
  570. .get_settings = i40evf_get_settings,
  571. .get_drvinfo = i40evf_get_drvinfo,
  572. .get_link = ethtool_op_get_link,
  573. .get_ringparam = i40evf_get_ringparam,
  574. .set_ringparam = i40evf_set_ringparam,
  575. .get_strings = i40evf_get_strings,
  576. .get_ethtool_stats = i40evf_get_ethtool_stats,
  577. .get_sset_count = i40evf_get_sset_count,
  578. .get_msglevel = i40evf_get_msglevel,
  579. .set_msglevel = i40evf_set_msglevel,
  580. .get_coalesce = i40evf_get_coalesce,
  581. .set_coalesce = i40evf_set_coalesce,
  582. .get_per_queue_coalesce = i40evf_get_per_queue_coalesce,
  583. .set_per_queue_coalesce = i40evf_set_per_queue_coalesce,
  584. .get_rxnfc = i40evf_get_rxnfc,
  585. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  586. .get_rxfh = i40evf_get_rxfh,
  587. .set_rxfh = i40evf_set_rxfh,
  588. .get_channels = i40evf_get_channels,
  589. .get_rxfh_key_size = i40evf_get_rxfh_key_size,
  590. };
  591. /**
  592. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  593. * @netdev: network interface device structure
  594. *
  595. * Sets ethtool ops struct in our netdev so that ethtool can call
  596. * our functions.
  597. **/
  598. void i40evf_set_ethtool_ops(struct net_device *netdev)
  599. {
  600. netdev->ethtool_ops = &i40evf_ethtool_ops;
  601. }