i40evf_ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Contact Information:
  19. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  20. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  21. *
  22. ******************************************************************************/
  23. /* ethtool support for i40evf */
  24. #include "i40evf.h"
  25. #include <linux/uaccess.h>
  26. struct i40evf_stats {
  27. char stat_string[ETH_GSTRING_LEN];
  28. int stat_offset;
  29. };
  30. #define I40EVF_STAT(_name, _stat) { \
  31. .stat_string = _name, \
  32. .stat_offset = offsetof(struct i40evf_adapter, _stat) \
  33. }
  34. /* All stats are u64, so we don't need to track the size of the field. */
  35. static const struct i40evf_stats i40evf_gstrings_stats[] = {
  36. I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
  37. I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
  38. I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
  39. I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
  40. I40EVF_STAT("rx_discards", current_stats.rx_discards),
  41. I40EVF_STAT("rx_errors", current_stats.rx_errors),
  42. I40EVF_STAT("rx_missed", current_stats.rx_missed),
  43. I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
  44. I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
  45. I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
  46. I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
  47. I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
  48. I40EVF_STAT("tx_discards", current_stats.tx_discards),
  49. I40EVF_STAT("tx_errors", current_stats.tx_errors),
  50. };
  51. #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
  52. #define I40EVF_QUEUE_STATS_LEN \
  53. (((struct i40evf_adapter *) \
  54. netdev_priv(netdev))->vsi_res->num_queue_pairs * 4)
  55. #define I40EVF_STATS_LEN (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN)
  56. /**
  57. * i40evf_get_settings - Get Link Speed and Duplex settings
  58. * @netdev: network interface device structure
  59. * @ecmd: ethtool command
  60. *
  61. * Reports speed/duplex settings. Because this is a VF, we don't know what
  62. * kind of link we really have, so we fake it.
  63. **/
  64. static int i40evf_get_settings(struct net_device *netdev,
  65. struct ethtool_cmd *ecmd)
  66. {
  67. /* In the future the VF will be able to query the PF for
  68. * some information - for now use a dummy value
  69. */
  70. ecmd->supported = SUPPORTED_10000baseT_Full;
  71. ecmd->autoneg = AUTONEG_DISABLE;
  72. ecmd->transceiver = XCVR_DUMMY1;
  73. ecmd->port = PORT_NONE;
  74. return 0;
  75. }
  76. /**
  77. * i40evf_get_sset_count - Get length of string set
  78. * @netdev: network interface device structure
  79. * @sset: id of string set
  80. *
  81. * Reports size of string table. This driver only supports
  82. * strings for statistics.
  83. **/
  84. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  85. {
  86. if (sset == ETH_SS_STATS)
  87. return I40EVF_STATS_LEN;
  88. else
  89. return -ENOTSUPP;
  90. }
  91. /**
  92. * i40evf_get_ethtool_stats - report device statistics
  93. * @netdev: network interface device structure
  94. * @stats: ethtool statistics structure
  95. * @data: pointer to data buffer
  96. *
  97. * All statistics are added to the data buffer as an array of u64.
  98. **/
  99. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  100. struct ethtool_stats *stats, u64 *data)
  101. {
  102. struct i40evf_adapter *adapter = netdev_priv(netdev);
  103. int i, j;
  104. char *p;
  105. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  106. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  107. data[i] = *(u64 *)p;
  108. }
  109. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  110. data[i++] = adapter->tx_rings[j]->stats.packets;
  111. data[i++] = adapter->tx_rings[j]->stats.bytes;
  112. }
  113. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  114. data[i++] = adapter->rx_rings[j]->stats.packets;
  115. data[i++] = adapter->rx_rings[j]->stats.bytes;
  116. }
  117. }
  118. /**
  119. * i40evf_get_strings - Get string set
  120. * @netdev: network interface device structure
  121. * @sset: id of string set
  122. * @data: buffer for string data
  123. *
  124. * Builds stats string table.
  125. **/
  126. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  127. {
  128. struct i40evf_adapter *adapter = netdev_priv(netdev);
  129. u8 *p = data;
  130. int i;
  131. if (sset == ETH_SS_STATS) {
  132. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  133. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  134. ETH_GSTRING_LEN);
  135. p += ETH_GSTRING_LEN;
  136. }
  137. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  138. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  139. p += ETH_GSTRING_LEN;
  140. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  141. p += ETH_GSTRING_LEN;
  142. }
  143. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  144. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  145. p += ETH_GSTRING_LEN;
  146. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  147. p += ETH_GSTRING_LEN;
  148. }
  149. }
  150. }
  151. /**
  152. * i40evf_get_msglevel - Get debug message level
  153. * @netdev: network interface device structure
  154. *
  155. * Returns current debug message level.
  156. **/
  157. static u32 i40evf_get_msglevel(struct net_device *netdev)
  158. {
  159. struct i40evf_adapter *adapter = netdev_priv(netdev);
  160. return adapter->msg_enable;
  161. }
  162. /**
  163. * i40evf_get_msglevel - Set debug message level
  164. * @netdev: network interface device structure
  165. * @data: message level
  166. *
  167. * Set current debug message level. Higher values cause the driver to
  168. * be noisier.
  169. **/
  170. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  171. {
  172. struct i40evf_adapter *adapter = netdev_priv(netdev);
  173. adapter->msg_enable = data;
  174. }
  175. /**
  176. * i40evf_get_drvinto - Get driver info
  177. * @netdev: network interface device structure
  178. * @drvinfo: ethool driver info structure
  179. *
  180. * Returns information about the driver and device for display to the user.
  181. **/
  182. static void i40evf_get_drvinfo(struct net_device *netdev,
  183. struct ethtool_drvinfo *drvinfo)
  184. {
  185. struct i40evf_adapter *adapter = netdev_priv(netdev);
  186. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  187. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  188. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  189. }
  190. /**
  191. * i40evf_get_ringparam - Get ring parameters
  192. * @netdev: network interface device structure
  193. * @ring: ethtool ringparam structure
  194. *
  195. * Returns current ring parameters. TX and RX rings are reported separately,
  196. * but the number of rings is not reported.
  197. **/
  198. static void i40evf_get_ringparam(struct net_device *netdev,
  199. struct ethtool_ringparam *ring)
  200. {
  201. struct i40evf_adapter *adapter = netdev_priv(netdev);
  202. struct i40e_ring *tx_ring = adapter->tx_rings[0];
  203. struct i40e_ring *rx_ring = adapter->rx_rings[0];
  204. ring->rx_max_pending = I40EVF_MAX_RXD;
  205. ring->tx_max_pending = I40EVF_MAX_TXD;
  206. ring->rx_pending = rx_ring->count;
  207. ring->tx_pending = tx_ring->count;
  208. }
  209. /**
  210. * i40evf_set_ringparam - Set ring parameters
  211. * @netdev: network interface device structure
  212. * @ring: ethtool ringparam structure
  213. *
  214. * Sets ring parameters. TX and RX rings are controlled separately, but the
  215. * number of rings is not specified, so all rings get the same settings.
  216. **/
  217. static int i40evf_set_ringparam(struct net_device *netdev,
  218. struct ethtool_ringparam *ring)
  219. {
  220. struct i40evf_adapter *adapter = netdev_priv(netdev);
  221. u32 new_rx_count, new_tx_count;
  222. int i;
  223. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  224. return -EINVAL;
  225. new_tx_count = clamp_t(u32, ring->tx_pending,
  226. I40EVF_MIN_TXD,
  227. I40EVF_MAX_TXD);
  228. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  229. new_rx_count = clamp_t(u32, ring->rx_pending,
  230. I40EVF_MIN_RXD,
  231. I40EVF_MAX_RXD);
  232. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  233. /* if nothing to do return success */
  234. if ((new_tx_count == adapter->tx_rings[0]->count) &&
  235. (new_rx_count == adapter->rx_rings[0]->count))
  236. return 0;
  237. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  238. adapter->tx_rings[0]->count = new_tx_count;
  239. adapter->rx_rings[0]->count = new_rx_count;
  240. }
  241. if (netif_running(netdev))
  242. i40evf_reinit_locked(adapter);
  243. return 0;
  244. }
  245. /**
  246. * i40evf_get_coalesce - Get interrupt coalescing settings
  247. * @netdev: network interface device structure
  248. * @ec: ethtool coalesce structure
  249. *
  250. * Returns current coalescing settings. This is referred to elsewhere in the
  251. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  252. * this functionality.
  253. **/
  254. static int i40evf_get_coalesce(struct net_device *netdev,
  255. struct ethtool_coalesce *ec)
  256. {
  257. struct i40evf_adapter *adapter = netdev_priv(netdev);
  258. struct i40e_vsi *vsi = &adapter->vsi;
  259. ec->tx_max_coalesced_frames = vsi->work_limit;
  260. ec->rx_max_coalesced_frames = vsi->work_limit;
  261. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  262. ec->rx_coalesce_usecs = 1;
  263. else
  264. ec->rx_coalesce_usecs = vsi->rx_itr_setting;
  265. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  266. ec->tx_coalesce_usecs = 1;
  267. else
  268. ec->tx_coalesce_usecs = vsi->tx_itr_setting;
  269. return 0;
  270. }
  271. /**
  272. * i40evf_set_coalesce - Set interrupt coalescing settings
  273. * @netdev: network interface device structure
  274. * @ec: ethtool coalesce structure
  275. *
  276. * Change current coalescing settings.
  277. **/
  278. static int i40evf_set_coalesce(struct net_device *netdev,
  279. struct ethtool_coalesce *ec)
  280. {
  281. struct i40evf_adapter *adapter = netdev_priv(netdev);
  282. struct i40e_hw *hw = &adapter->hw;
  283. struct i40e_vsi *vsi = &adapter->vsi;
  284. struct i40e_q_vector *q_vector;
  285. int i;
  286. if (ec->tx_max_coalesced_frames || ec->rx_max_coalesced_frames)
  287. vsi->work_limit = ec->tx_max_coalesced_frames;
  288. switch (ec->rx_coalesce_usecs) {
  289. case 0:
  290. vsi->rx_itr_setting = 0;
  291. break;
  292. case 1:
  293. vsi->rx_itr_setting = (I40E_ITR_DYNAMIC
  294. | ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  295. break;
  296. default:
  297. if ((ec->rx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  298. (ec->rx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  299. return -EINVAL;
  300. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  301. break;
  302. }
  303. switch (ec->tx_coalesce_usecs) {
  304. case 0:
  305. vsi->tx_itr_setting = 0;
  306. break;
  307. case 1:
  308. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC
  309. | ITR_REG_TO_USEC(I40E_ITR_TX_DEF));
  310. break;
  311. default:
  312. if ((ec->tx_coalesce_usecs < (I40E_MIN_ITR << 1)) ||
  313. (ec->tx_coalesce_usecs > (I40E_MAX_ITR << 1)))
  314. return -EINVAL;
  315. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  316. break;
  317. }
  318. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  319. q_vector = adapter->q_vector[i];
  320. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  321. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  322. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  323. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  324. i40e_flush(hw);
  325. }
  326. return 0;
  327. }
  328. /**
  329. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  330. * @adapter: board private structure
  331. * @cmd: ethtool rxnfc command
  332. *
  333. * Returns Success if the flow is supported, else Invalid Input.
  334. **/
  335. static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
  336. struct ethtool_rxnfc *cmd)
  337. {
  338. struct i40e_hw *hw = &adapter->hw;
  339. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  340. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  341. /* We always hash on IP src and dest addresses */
  342. cmd->data = RXH_IP_SRC | RXH_IP_DST;
  343. switch (cmd->flow_type) {
  344. case TCP_V4_FLOW:
  345. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
  346. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  347. break;
  348. case UDP_V4_FLOW:
  349. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
  350. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  351. break;
  352. case SCTP_V4_FLOW:
  353. case AH_ESP_V4_FLOW:
  354. case AH_V4_FLOW:
  355. case ESP_V4_FLOW:
  356. case IPV4_FLOW:
  357. break;
  358. case TCP_V6_FLOW:
  359. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
  360. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  361. break;
  362. case UDP_V6_FLOW:
  363. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
  364. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  365. break;
  366. case SCTP_V6_FLOW:
  367. case AH_ESP_V6_FLOW:
  368. case AH_V6_FLOW:
  369. case ESP_V6_FLOW:
  370. case IPV6_FLOW:
  371. break;
  372. default:
  373. cmd->data = 0;
  374. return -EINVAL;
  375. }
  376. return 0;
  377. }
  378. /**
  379. * i40evf_get_rxnfc - command to get RX flow classification rules
  380. * @netdev: network interface device structure
  381. * @cmd: ethtool rxnfc command
  382. *
  383. * Returns Success if the command is supported.
  384. **/
  385. static int i40evf_get_rxnfc(struct net_device *netdev,
  386. struct ethtool_rxnfc *cmd,
  387. u32 *rule_locs)
  388. {
  389. struct i40evf_adapter *adapter = netdev_priv(netdev);
  390. int ret = -EOPNOTSUPP;
  391. switch (cmd->cmd) {
  392. case ETHTOOL_GRXRINGS:
  393. cmd->data = adapter->vsi_res->num_queue_pairs;
  394. ret = 0;
  395. break;
  396. case ETHTOOL_GRXFH:
  397. ret = i40evf_get_rss_hash_opts(adapter, cmd);
  398. break;
  399. default:
  400. break;
  401. }
  402. return ret;
  403. }
  404. /**
  405. * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  406. * @adapter: board private structure
  407. * @cmd: ethtool rxnfc command
  408. *
  409. * Returns Success if the flow input set is supported.
  410. **/
  411. static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
  412. struct ethtool_rxnfc *nfc)
  413. {
  414. struct i40e_hw *hw = &adapter->hw;
  415. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  416. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  417. /* RSS does not support anything other than hashing
  418. * to queues on src and dst IPs and ports
  419. */
  420. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  421. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  422. return -EINVAL;
  423. /* We need at least the IP SRC and DEST fields for hashing */
  424. if (!(nfc->data & RXH_IP_SRC) ||
  425. !(nfc->data & RXH_IP_DST))
  426. return -EINVAL;
  427. switch (nfc->flow_type) {
  428. case TCP_V4_FLOW:
  429. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  430. case 0:
  431. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  432. break;
  433. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  434. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  435. break;
  436. default:
  437. return -EINVAL;
  438. }
  439. break;
  440. case TCP_V6_FLOW:
  441. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  442. case 0:
  443. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  444. break;
  445. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  446. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  447. break;
  448. default:
  449. return -EINVAL;
  450. }
  451. break;
  452. case UDP_V4_FLOW:
  453. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  454. case 0:
  455. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  456. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  457. break;
  458. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  459. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  460. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  461. break;
  462. default:
  463. return -EINVAL;
  464. }
  465. break;
  466. case UDP_V6_FLOW:
  467. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  468. case 0:
  469. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  470. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  471. break;
  472. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  473. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  474. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  475. break;
  476. default:
  477. return -EINVAL;
  478. }
  479. break;
  480. case AH_ESP_V4_FLOW:
  481. case AH_V4_FLOW:
  482. case ESP_V4_FLOW:
  483. case SCTP_V4_FLOW:
  484. if ((nfc->data & RXH_L4_B_0_1) ||
  485. (nfc->data & RXH_L4_B_2_3))
  486. return -EINVAL;
  487. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  488. break;
  489. case AH_ESP_V6_FLOW:
  490. case AH_V6_FLOW:
  491. case ESP_V6_FLOW:
  492. case SCTP_V6_FLOW:
  493. if ((nfc->data & RXH_L4_B_0_1) ||
  494. (nfc->data & RXH_L4_B_2_3))
  495. return -EINVAL;
  496. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  497. break;
  498. case IPV4_FLOW:
  499. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  500. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  501. break;
  502. case IPV6_FLOW:
  503. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  504. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  505. break;
  506. default:
  507. return -EINVAL;
  508. }
  509. wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
  510. wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
  511. i40e_flush(hw);
  512. return 0;
  513. }
  514. /**
  515. * i40evf_set_rxnfc - command to set RX flow classification rules
  516. * @netdev: network interface device structure
  517. * @cmd: ethtool rxnfc command
  518. *
  519. * Returns Success if the command is supported.
  520. **/
  521. static int i40evf_set_rxnfc(struct net_device *netdev,
  522. struct ethtool_rxnfc *cmd)
  523. {
  524. struct i40evf_adapter *adapter = netdev_priv(netdev);
  525. int ret = -EOPNOTSUPP;
  526. switch (cmd->cmd) {
  527. case ETHTOOL_SRXFH:
  528. ret = i40evf_set_rss_hash_opt(adapter, cmd);
  529. break;
  530. default:
  531. break;
  532. }
  533. return ret;
  534. }
  535. /**
  536. * i40evf_get_channels: get the number of channels supported by the device
  537. * @netdev: network interface device structure
  538. * @ch: channel information structure
  539. *
  540. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  541. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  542. **/
  543. static void i40evf_get_channels(struct net_device *netdev,
  544. struct ethtool_channels *ch)
  545. {
  546. struct i40evf_adapter *adapter = netdev_priv(netdev);
  547. /* Report maximum channels */
  548. ch->max_combined = adapter->vsi_res->num_queue_pairs;
  549. ch->max_other = NONQ_VECS;
  550. ch->other_count = NONQ_VECS;
  551. ch->combined_count = adapter->vsi_res->num_queue_pairs;
  552. }
  553. /**
  554. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  555. * @netdev: network interface device structure
  556. *
  557. * Returns the table size.
  558. **/
  559. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  560. {
  561. return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
  562. }
  563. /**
  564. * i40evf_get_rxfh - get the rx flow hash indirection table
  565. * @netdev: network interface device structure
  566. * @indir: indirection table
  567. * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
  568. *
  569. * Reads the indirection table directly from the hardware. Always returns 0.
  570. **/
  571. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key)
  572. {
  573. struct i40evf_adapter *adapter = netdev_priv(netdev);
  574. struct i40e_hw *hw = &adapter->hw;
  575. u32 hlut_val;
  576. int i, j;
  577. for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX; i++) {
  578. hlut_val = rd32(hw, I40E_VFQF_HLUT(i));
  579. indir[j++] = hlut_val & 0xff;
  580. indir[j++] = (hlut_val >> 8) & 0xff;
  581. indir[j++] = (hlut_val >> 16) & 0xff;
  582. indir[j++] = (hlut_val >> 24) & 0xff;
  583. }
  584. return 0;
  585. }
  586. /**
  587. * i40evf_set_rxfh - set the rx flow hash indirection table
  588. * @netdev: network interface device structure
  589. * @indir: indirection table
  590. * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
  591. *
  592. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  593. * returns 0 after programming the table.
  594. **/
  595. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  596. const u8 *key)
  597. {
  598. struct i40evf_adapter *adapter = netdev_priv(netdev);
  599. struct i40e_hw *hw = &adapter->hw;
  600. u32 hlut_val;
  601. int i, j;
  602. for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX + 1; i++) {
  603. hlut_val = indir[j++];
  604. hlut_val |= indir[j++] << 8;
  605. hlut_val |= indir[j++] << 16;
  606. hlut_val |= indir[j++] << 24;
  607. wr32(hw, I40E_VFQF_HLUT(i), hlut_val);
  608. }
  609. return 0;
  610. }
  611. static struct ethtool_ops i40evf_ethtool_ops = {
  612. .get_settings = i40evf_get_settings,
  613. .get_drvinfo = i40evf_get_drvinfo,
  614. .get_link = ethtool_op_get_link,
  615. .get_ringparam = i40evf_get_ringparam,
  616. .set_ringparam = i40evf_set_ringparam,
  617. .get_strings = i40evf_get_strings,
  618. .get_ethtool_stats = i40evf_get_ethtool_stats,
  619. .get_sset_count = i40evf_get_sset_count,
  620. .get_msglevel = i40evf_get_msglevel,
  621. .set_msglevel = i40evf_set_msglevel,
  622. .get_coalesce = i40evf_get_coalesce,
  623. .set_coalesce = i40evf_set_coalesce,
  624. .get_rxnfc = i40evf_get_rxnfc,
  625. .set_rxnfc = i40evf_set_rxnfc,
  626. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  627. .get_rxfh = i40evf_get_rxfh,
  628. .set_rxfh = i40evf_set_rxfh,
  629. .get_channels = i40evf_get_channels,
  630. };
  631. /**
  632. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  633. * @netdev: network interface device structure
  634. *
  635. * Sets ethtool ops struct in our netdev so that ethtool can call
  636. * our functions.
  637. **/
  638. void i40evf_set_ethtool_ops(struct net_device *netdev)
  639. {
  640. netdev->ethtool_ops = &i40evf_ethtool_ops;
  641. }