i40evf_ethtool.c 23 KB

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