i40evf_ethtool.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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. unsigned 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 < (int)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. u32 orig_flags, new_flags, changed_flags;
  238. u32 i;
  239. orig_flags = READ_ONCE(adapter->flags);
  240. new_flags = orig_flags;
  241. for (i = 0; i < I40EVF_PRIV_FLAGS_STR_LEN; i++) {
  242. const struct i40evf_priv_flags *priv_flags;
  243. priv_flags = &i40evf_gstrings_priv_flags[i];
  244. if (flags & BIT(i))
  245. new_flags |= priv_flags->flag;
  246. else
  247. new_flags &= ~(priv_flags->flag);
  248. if (priv_flags->read_only &&
  249. ((orig_flags ^ new_flags) & ~BIT(i)))
  250. return -EOPNOTSUPP;
  251. }
  252. /* Before we finalize any flag changes, any checks which we need to
  253. * perform to determine if the new flags will be supported should go
  254. * here...
  255. */
  256. /* Compare and exchange the new flags into place. If we failed, that
  257. * is if cmpxchg returns anything but the old value, this means
  258. * something else must have modified the flags variable since we
  259. * copied it. We'll just punt with an error and log something in the
  260. * message buffer.
  261. */
  262. if (cmpxchg(&adapter->flags, orig_flags, new_flags) != orig_flags) {
  263. dev_warn(&adapter->pdev->dev,
  264. "Unable to update adapter->flags as it was modified by another thread...\n");
  265. return -EAGAIN;
  266. }
  267. changed_flags = orig_flags ^ new_flags;
  268. /* Process any additional changes needed as a result of flag changes.
  269. * The changed_flags value reflects the list of bits that were changed
  270. * in the code above.
  271. */
  272. /* issue a reset to force legacy-rx change to take effect */
  273. if (changed_flags & I40EVF_FLAG_LEGACY_RX) {
  274. if (netif_running(netdev)) {
  275. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  276. schedule_work(&adapter->reset_task);
  277. }
  278. }
  279. return 0;
  280. }
  281. /**
  282. * i40evf_get_msglevel - Get debug message level
  283. * @netdev: network interface device structure
  284. *
  285. * Returns current debug message level.
  286. **/
  287. static u32 i40evf_get_msglevel(struct net_device *netdev)
  288. {
  289. struct i40evf_adapter *adapter = netdev_priv(netdev);
  290. return adapter->msg_enable;
  291. }
  292. /**
  293. * i40evf_set_msglevel - Set debug message level
  294. * @netdev: network interface device structure
  295. * @data: message level
  296. *
  297. * Set current debug message level. Higher values cause the driver to
  298. * be noisier.
  299. **/
  300. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  301. {
  302. struct i40evf_adapter *adapter = netdev_priv(netdev);
  303. if (I40E_DEBUG_USER & data)
  304. adapter->hw.debug_mask = data;
  305. adapter->msg_enable = data;
  306. }
  307. /**
  308. * i40evf_get_drvinfo - Get driver info
  309. * @netdev: network interface device structure
  310. * @drvinfo: ethool driver info structure
  311. *
  312. * Returns information about the driver and device for display to the user.
  313. **/
  314. static void i40evf_get_drvinfo(struct net_device *netdev,
  315. struct ethtool_drvinfo *drvinfo)
  316. {
  317. struct i40evf_adapter *adapter = netdev_priv(netdev);
  318. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  319. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  320. strlcpy(drvinfo->fw_version, "N/A", 4);
  321. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  322. drvinfo->n_priv_flags = I40EVF_PRIV_FLAGS_STR_LEN;
  323. }
  324. /**
  325. * i40evf_get_ringparam - Get ring parameters
  326. * @netdev: network interface device structure
  327. * @ring: ethtool ringparam structure
  328. *
  329. * Returns current ring parameters. TX and RX rings are reported separately,
  330. * but the number of rings is not reported.
  331. **/
  332. static void i40evf_get_ringparam(struct net_device *netdev,
  333. struct ethtool_ringparam *ring)
  334. {
  335. struct i40evf_adapter *adapter = netdev_priv(netdev);
  336. ring->rx_max_pending = I40EVF_MAX_RXD;
  337. ring->tx_max_pending = I40EVF_MAX_TXD;
  338. ring->rx_pending = adapter->rx_desc_count;
  339. ring->tx_pending = adapter->tx_desc_count;
  340. }
  341. /**
  342. * i40evf_set_ringparam - Set ring parameters
  343. * @netdev: network interface device structure
  344. * @ring: ethtool ringparam structure
  345. *
  346. * Sets ring parameters. TX and RX rings are controlled separately, but the
  347. * number of rings is not specified, so all rings get the same settings.
  348. **/
  349. static int i40evf_set_ringparam(struct net_device *netdev,
  350. struct ethtool_ringparam *ring)
  351. {
  352. struct i40evf_adapter *adapter = netdev_priv(netdev);
  353. u32 new_rx_count, new_tx_count;
  354. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  355. return -EINVAL;
  356. new_tx_count = clamp_t(u32, ring->tx_pending,
  357. I40EVF_MIN_TXD,
  358. I40EVF_MAX_TXD);
  359. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  360. new_rx_count = clamp_t(u32, ring->rx_pending,
  361. I40EVF_MIN_RXD,
  362. I40EVF_MAX_RXD);
  363. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  364. /* if nothing to do return success */
  365. if ((new_tx_count == adapter->tx_desc_count) &&
  366. (new_rx_count == adapter->rx_desc_count))
  367. return 0;
  368. adapter->tx_desc_count = new_tx_count;
  369. adapter->rx_desc_count = new_rx_count;
  370. if (netif_running(netdev)) {
  371. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  372. schedule_work(&adapter->reset_task);
  373. }
  374. return 0;
  375. }
  376. /**
  377. * __i40evf_get_coalesce - get per-queue coalesce settings
  378. * @netdev: the netdev to check
  379. * @ec: ethtool coalesce data structure
  380. * @queue: which queue to pick
  381. *
  382. * Gets the per-queue settings for coalescence. Specifically Rx and Tx usecs
  383. * are per queue. If queue is <0 then we default to queue 0 as the
  384. * representative value.
  385. **/
  386. static int __i40evf_get_coalesce(struct net_device *netdev,
  387. struct ethtool_coalesce *ec,
  388. int queue)
  389. {
  390. struct i40evf_adapter *adapter = netdev_priv(netdev);
  391. struct i40e_vsi *vsi = &adapter->vsi;
  392. struct i40e_ring *rx_ring, *tx_ring;
  393. ec->tx_max_coalesced_frames = vsi->work_limit;
  394. ec->rx_max_coalesced_frames = vsi->work_limit;
  395. /* Rx and Tx usecs per queue value. If user doesn't specify the
  396. * queue, return queue 0's value to represent.
  397. */
  398. if (queue < 0)
  399. queue = 0;
  400. else if (queue >= adapter->num_active_queues)
  401. return -EINVAL;
  402. rx_ring = &adapter->rx_rings[queue];
  403. tx_ring = &adapter->tx_rings[queue];
  404. if (ITR_IS_DYNAMIC(rx_ring->rx_itr_setting))
  405. ec->use_adaptive_rx_coalesce = 1;
  406. if (ITR_IS_DYNAMIC(tx_ring->tx_itr_setting))
  407. ec->use_adaptive_tx_coalesce = 1;
  408. ec->rx_coalesce_usecs = rx_ring->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  409. ec->tx_coalesce_usecs = tx_ring->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  410. return 0;
  411. }
  412. /**
  413. * i40evf_get_coalesce - Get interrupt coalescing settings
  414. * @netdev: network interface device structure
  415. * @ec: ethtool coalesce structure
  416. *
  417. * Returns current coalescing settings. This is referred to elsewhere in the
  418. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  419. * this functionality. Note that if per-queue settings have been modified this
  420. * only represents the settings of queue 0.
  421. **/
  422. static int i40evf_get_coalesce(struct net_device *netdev,
  423. struct ethtool_coalesce *ec)
  424. {
  425. return __i40evf_get_coalesce(netdev, ec, -1);
  426. }
  427. /**
  428. * i40evf_get_per_queue_coalesce - get coalesce values for specific queue
  429. * @netdev: netdev to read
  430. * @ec: coalesce settings from ethtool
  431. * @queue: the queue to read
  432. *
  433. * Read specific queue's coalesce settings.
  434. **/
  435. static int i40evf_get_per_queue_coalesce(struct net_device *netdev,
  436. u32 queue,
  437. struct ethtool_coalesce *ec)
  438. {
  439. return __i40evf_get_coalesce(netdev, ec, queue);
  440. }
  441. /**
  442. * i40evf_set_itr_per_queue - set ITR values for specific queue
  443. * @vsi: the VSI to set values for
  444. * @ec: coalesce settings from ethtool
  445. * @queue: the queue to modify
  446. *
  447. * Change the ITR settings for a specific queue.
  448. **/
  449. static void i40evf_set_itr_per_queue(struct i40evf_adapter *adapter,
  450. struct ethtool_coalesce *ec,
  451. int queue)
  452. {
  453. struct i40e_vsi *vsi = &adapter->vsi;
  454. struct i40e_hw *hw = &adapter->hw;
  455. struct i40e_q_vector *q_vector;
  456. u16 vector;
  457. adapter->rx_rings[queue].rx_itr_setting = ec->rx_coalesce_usecs;
  458. adapter->tx_rings[queue].tx_itr_setting = ec->tx_coalesce_usecs;
  459. if (ec->use_adaptive_rx_coalesce)
  460. adapter->rx_rings[queue].rx_itr_setting |= I40E_ITR_DYNAMIC;
  461. else
  462. adapter->rx_rings[queue].rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  463. if (ec->use_adaptive_tx_coalesce)
  464. adapter->tx_rings[queue].tx_itr_setting |= I40E_ITR_DYNAMIC;
  465. else
  466. adapter->tx_rings[queue].tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  467. q_vector = adapter->rx_rings[queue].q_vector;
  468. q_vector->rx.itr = ITR_TO_REG(adapter->rx_rings[queue].rx_itr_setting);
  469. vector = vsi->base_vector + q_vector->v_idx;
  470. wr32(hw, I40E_VFINT_ITRN1(I40E_RX_ITR, vector - 1), q_vector->rx.itr);
  471. q_vector = adapter->tx_rings[queue].q_vector;
  472. q_vector->tx.itr = ITR_TO_REG(adapter->tx_rings[queue].tx_itr_setting);
  473. vector = vsi->base_vector + q_vector->v_idx;
  474. wr32(hw, I40E_VFINT_ITRN1(I40E_TX_ITR, vector - 1), q_vector->tx.itr);
  475. i40e_flush(hw);
  476. }
  477. /**
  478. * __i40evf_set_coalesce - set coalesce settings for particular queue
  479. * @netdev: the netdev to change
  480. * @ec: ethtool coalesce settings
  481. * @queue: the queue to change
  482. *
  483. * Sets the coalesce settings for a particular queue.
  484. **/
  485. static int __i40evf_set_coalesce(struct net_device *netdev,
  486. struct ethtool_coalesce *ec,
  487. int queue)
  488. {
  489. struct i40evf_adapter *adapter = netdev_priv(netdev);
  490. struct i40e_vsi *vsi = &adapter->vsi;
  491. int i;
  492. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  493. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  494. if (ec->rx_coalesce_usecs == 0) {
  495. if (ec->use_adaptive_rx_coalesce)
  496. netif_info(adapter, drv, netdev, "rx-usecs=0, need to disable adaptive-rx for a complete disable\n");
  497. } else if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  498. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  499. netif_info(adapter, drv, netdev, "Invalid value, rx-usecs range is 0-8160\n");
  500. return -EINVAL;
  501. }
  502. else
  503. if (ec->tx_coalesce_usecs == 0) {
  504. if (ec->use_adaptive_tx_coalesce)
  505. netif_info(adapter, drv, netdev, "tx-usecs=0, need to disable adaptive-tx for a complete disable\n");
  506. } else if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  507. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1))) {
  508. netif_info(adapter, drv, netdev, "Invalid value, tx-usecs range is 0-8160\n");
  509. return -EINVAL;
  510. }
  511. /* Rx and Tx usecs has per queue value. If user doesn't specify the
  512. * queue, apply to all queues.
  513. */
  514. if (queue < 0) {
  515. for (i = 0; i < adapter->num_active_queues; i++)
  516. i40evf_set_itr_per_queue(adapter, ec, i);
  517. } else if (queue < adapter->num_active_queues) {
  518. i40evf_set_itr_per_queue(adapter, ec, queue);
  519. } else {
  520. netif_info(adapter, drv, netdev, "Invalid queue value, queue range is 0 - %d\n",
  521. adapter->num_active_queues - 1);
  522. return -EINVAL;
  523. }
  524. return 0;
  525. }
  526. /**
  527. * i40evf_set_coalesce - Set interrupt coalescing settings
  528. * @netdev: network interface device structure
  529. * @ec: ethtool coalesce structure
  530. *
  531. * Change current coalescing settings for every queue.
  532. **/
  533. static int i40evf_set_coalesce(struct net_device *netdev,
  534. struct ethtool_coalesce *ec)
  535. {
  536. return __i40evf_set_coalesce(netdev, ec, -1);
  537. }
  538. /**
  539. * i40evf_set_per_queue_coalesce - set specific queue's coalesce settings
  540. * @netdev: the netdev to change
  541. * @ec: ethtool's coalesce settings
  542. * @queue: the queue to modify
  543. *
  544. * Modifies a specific queue's coalesce settings.
  545. */
  546. static int i40evf_set_per_queue_coalesce(struct net_device *netdev,
  547. u32 queue,
  548. struct ethtool_coalesce *ec)
  549. {
  550. return __i40evf_set_coalesce(netdev, ec, queue);
  551. }
  552. /**
  553. * i40evf_get_rxnfc - command to get RX flow classification rules
  554. * @netdev: network interface device structure
  555. * @cmd: ethtool rxnfc command
  556. *
  557. * Returns Success if the command is supported.
  558. **/
  559. static int i40evf_get_rxnfc(struct net_device *netdev,
  560. struct ethtool_rxnfc *cmd,
  561. u32 *rule_locs)
  562. {
  563. struct i40evf_adapter *adapter = netdev_priv(netdev);
  564. int ret = -EOPNOTSUPP;
  565. switch (cmd->cmd) {
  566. case ETHTOOL_GRXRINGS:
  567. cmd->data = adapter->num_active_queues;
  568. ret = 0;
  569. break;
  570. case ETHTOOL_GRXFH:
  571. netdev_info(netdev,
  572. "RSS hash info is not available to vf, use pf.\n");
  573. break;
  574. default:
  575. break;
  576. }
  577. return ret;
  578. }
  579. /**
  580. * i40evf_get_channels: get the number of channels supported by the device
  581. * @netdev: network interface device structure
  582. * @ch: channel information structure
  583. *
  584. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  585. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  586. **/
  587. static void i40evf_get_channels(struct net_device *netdev,
  588. struct ethtool_channels *ch)
  589. {
  590. struct i40evf_adapter *adapter = netdev_priv(netdev);
  591. /* Report maximum channels */
  592. ch->max_combined = adapter->num_active_queues;
  593. ch->max_other = NONQ_VECS;
  594. ch->other_count = NONQ_VECS;
  595. ch->combined_count = adapter->num_active_queues;
  596. }
  597. /**
  598. * i40evf_get_rxfh_key_size - get the RSS hash key size
  599. * @netdev: network interface device structure
  600. *
  601. * Returns the table size.
  602. **/
  603. static u32 i40evf_get_rxfh_key_size(struct net_device *netdev)
  604. {
  605. struct i40evf_adapter *adapter = netdev_priv(netdev);
  606. return adapter->rss_key_size;
  607. }
  608. /**
  609. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  610. * @netdev: network interface device structure
  611. *
  612. * Returns the table size.
  613. **/
  614. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  615. {
  616. struct i40evf_adapter *adapter = netdev_priv(netdev);
  617. return adapter->rss_lut_size;
  618. }
  619. /**
  620. * i40evf_get_rxfh - get the rx flow hash indirection table
  621. * @netdev: network interface device structure
  622. * @indir: indirection table
  623. * @key: hash key
  624. *
  625. * Reads the indirection table directly from the hardware. Always returns 0.
  626. **/
  627. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  628. u8 *hfunc)
  629. {
  630. struct i40evf_adapter *adapter = netdev_priv(netdev);
  631. u16 i;
  632. if (hfunc)
  633. *hfunc = ETH_RSS_HASH_TOP;
  634. if (!indir)
  635. return 0;
  636. memcpy(key, adapter->rss_key, adapter->rss_key_size);
  637. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  638. for (i = 0; i < adapter->rss_lut_size; i++)
  639. indir[i] = (u32)adapter->rss_lut[i];
  640. return 0;
  641. }
  642. /**
  643. * i40evf_set_rxfh - set the rx flow hash indirection table
  644. * @netdev: network interface device structure
  645. * @indir: indirection table
  646. * @key: hash key
  647. *
  648. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  649. * returns 0 after programming the table.
  650. **/
  651. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  652. const u8 *key, const u8 hfunc)
  653. {
  654. struct i40evf_adapter *adapter = netdev_priv(netdev);
  655. u16 i;
  656. /* We do not allow change in unsupported parameters */
  657. if (key ||
  658. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  659. return -EOPNOTSUPP;
  660. if (!indir)
  661. return 0;
  662. if (key) {
  663. memcpy(adapter->rss_key, key, adapter->rss_key_size);
  664. }
  665. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  666. for (i = 0; i < adapter->rss_lut_size; i++)
  667. adapter->rss_lut[i] = (u8)(indir[i]);
  668. return i40evf_config_rss(adapter);
  669. }
  670. static const struct ethtool_ops i40evf_ethtool_ops = {
  671. .get_drvinfo = i40evf_get_drvinfo,
  672. .get_link = ethtool_op_get_link,
  673. .get_ringparam = i40evf_get_ringparam,
  674. .set_ringparam = i40evf_set_ringparam,
  675. .get_strings = i40evf_get_strings,
  676. .get_ethtool_stats = i40evf_get_ethtool_stats,
  677. .get_sset_count = i40evf_get_sset_count,
  678. .get_priv_flags = i40evf_get_priv_flags,
  679. .set_priv_flags = i40evf_set_priv_flags,
  680. .get_msglevel = i40evf_get_msglevel,
  681. .set_msglevel = i40evf_set_msglevel,
  682. .get_coalesce = i40evf_get_coalesce,
  683. .set_coalesce = i40evf_set_coalesce,
  684. .get_per_queue_coalesce = i40evf_get_per_queue_coalesce,
  685. .set_per_queue_coalesce = i40evf_set_per_queue_coalesce,
  686. .get_rxnfc = i40evf_get_rxnfc,
  687. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  688. .get_rxfh = i40evf_get_rxfh,
  689. .set_rxfh = i40evf_set_rxfh,
  690. .get_channels = i40evf_get_channels,
  691. .get_rxfh_key_size = i40evf_get_rxfh_key_size,
  692. .get_link_ksettings = i40evf_get_link_ksettings,
  693. };
  694. /**
  695. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  696. * @netdev: network interface device structure
  697. *
  698. * Sets ethtool ops struct in our netdev so that ethtool can call
  699. * our functions.
  700. **/
  701. void i40evf_set_ethtool_ops(struct net_device *netdev)
  702. {
  703. netdev->ethtool_ops = &i40evf_ethtool_ops;
  704. }