i40evf_ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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. * 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))->vsi_res->num_queue_pairs \
  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. /* In the future the VF will be able to query the PF for
  71. * some information - for now use a dummy value
  72. */
  73. ecmd->supported = 0;
  74. ecmd->autoneg = AUTONEG_DISABLE;
  75. ecmd->transceiver = XCVR_DUMMY1;
  76. ecmd->port = PORT_NONE;
  77. return 0;
  78. }
  79. /**
  80. * i40evf_get_sset_count - Get length of string set
  81. * @netdev: network interface device structure
  82. * @sset: id of string set
  83. *
  84. * Reports size of string table. This driver only supports
  85. * strings for statistics.
  86. **/
  87. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  88. {
  89. if (sset == ETH_SS_STATS)
  90. return I40EVF_STATS_LEN(netdev);
  91. else
  92. return -EINVAL;
  93. }
  94. /**
  95. * i40evf_get_ethtool_stats - report device statistics
  96. * @netdev: network interface device structure
  97. * @stats: ethtool statistics structure
  98. * @data: pointer to data buffer
  99. *
  100. * All statistics are added to the data buffer as an array of u64.
  101. **/
  102. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  103. struct ethtool_stats *stats, u64 *data)
  104. {
  105. struct i40evf_adapter *adapter = netdev_priv(netdev);
  106. int i, j;
  107. char *p;
  108. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  109. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  110. data[i] = *(u64 *)p;
  111. }
  112. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  113. data[i++] = adapter->tx_rings[j]->stats.packets;
  114. data[i++] = adapter->tx_rings[j]->stats.bytes;
  115. }
  116. for (j = 0; j < adapter->vsi_res->num_queue_pairs; j++) {
  117. data[i++] = adapter->rx_rings[j]->stats.packets;
  118. data[i++] = adapter->rx_rings[j]->stats.bytes;
  119. }
  120. }
  121. /**
  122. * i40evf_get_strings - Get string set
  123. * @netdev: network interface device structure
  124. * @sset: id of string set
  125. * @data: buffer for string data
  126. *
  127. * Builds stats string table.
  128. **/
  129. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  130. {
  131. struct i40evf_adapter *adapter = netdev_priv(netdev);
  132. u8 *p = data;
  133. int i;
  134. if (sset == ETH_SS_STATS) {
  135. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  136. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  137. ETH_GSTRING_LEN);
  138. p += ETH_GSTRING_LEN;
  139. }
  140. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  141. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  142. p += ETH_GSTRING_LEN;
  143. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  144. p += ETH_GSTRING_LEN;
  145. }
  146. for (i = 0; i < adapter->vsi_res->num_queue_pairs; i++) {
  147. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  148. p += ETH_GSTRING_LEN;
  149. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  150. p += ETH_GSTRING_LEN;
  151. }
  152. }
  153. }
  154. /**
  155. * i40evf_get_msglevel - Get debug message level
  156. * @netdev: network interface device structure
  157. *
  158. * Returns current debug message level.
  159. **/
  160. static u32 i40evf_get_msglevel(struct net_device *netdev)
  161. {
  162. struct i40evf_adapter *adapter = netdev_priv(netdev);
  163. return adapter->msg_enable;
  164. }
  165. /**
  166. * i40evf_get_msglevel - Set debug message level
  167. * @netdev: network interface device structure
  168. * @data: message level
  169. *
  170. * Set current debug message level. Higher values cause the driver to
  171. * be noisier.
  172. **/
  173. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  174. {
  175. struct i40evf_adapter *adapter = netdev_priv(netdev);
  176. adapter->msg_enable = data;
  177. }
  178. /**
  179. * i40evf_get_drvinto - Get driver info
  180. * @netdev: network interface device structure
  181. * @drvinfo: ethool driver info structure
  182. *
  183. * Returns information about the driver and device for display to the user.
  184. **/
  185. static void i40evf_get_drvinfo(struct net_device *netdev,
  186. struct ethtool_drvinfo *drvinfo)
  187. {
  188. struct i40evf_adapter *adapter = netdev_priv(netdev);
  189. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  190. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  191. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  192. }
  193. /**
  194. * i40evf_get_ringparam - Get ring parameters
  195. * @netdev: network interface device structure
  196. * @ring: ethtool ringparam structure
  197. *
  198. * Returns current ring parameters. TX and RX rings are reported separately,
  199. * but the number of rings is not reported.
  200. **/
  201. static void i40evf_get_ringparam(struct net_device *netdev,
  202. struct ethtool_ringparam *ring)
  203. {
  204. struct i40evf_adapter *adapter = netdev_priv(netdev);
  205. ring->rx_max_pending = I40EVF_MAX_RXD;
  206. ring->tx_max_pending = I40EVF_MAX_TXD;
  207. ring->rx_pending = adapter->rx_desc_count;
  208. ring->tx_pending = adapter->tx_desc_count;
  209. }
  210. /**
  211. * i40evf_set_ringparam - Set ring parameters
  212. * @netdev: network interface device structure
  213. * @ring: ethtool ringparam structure
  214. *
  215. * Sets ring parameters. TX and RX rings are controlled separately, but the
  216. * number of rings is not specified, so all rings get the same settings.
  217. **/
  218. static int i40evf_set_ringparam(struct net_device *netdev,
  219. struct ethtool_ringparam *ring)
  220. {
  221. struct i40evf_adapter *adapter = netdev_priv(netdev);
  222. u32 new_rx_count, new_tx_count;
  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_desc_count) &&
  235. (new_rx_count == adapter->rx_desc_count))
  236. return 0;
  237. adapter->tx_desc_count = new_tx_count;
  238. adapter->rx_desc_count = new_rx_count;
  239. if (netif_running(netdev))
  240. i40evf_reinit_locked(adapter);
  241. return 0;
  242. }
  243. /**
  244. * i40evf_get_coalesce - Get interrupt coalescing settings
  245. * @netdev: network interface device structure
  246. * @ec: ethtool coalesce structure
  247. *
  248. * Returns current coalescing settings. This is referred to elsewhere in the
  249. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  250. * this functionality.
  251. **/
  252. static int i40evf_get_coalesce(struct net_device *netdev,
  253. struct ethtool_coalesce *ec)
  254. {
  255. struct i40evf_adapter *adapter = netdev_priv(netdev);
  256. struct i40e_vsi *vsi = &adapter->vsi;
  257. ec->tx_max_coalesced_frames = vsi->work_limit;
  258. ec->rx_max_coalesced_frames = vsi->work_limit;
  259. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  260. ec->use_adaptive_rx_coalesce = 1;
  261. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  262. ec->use_adaptive_tx_coalesce = 1;
  263. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  264. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  265. return 0;
  266. }
  267. /**
  268. * i40evf_set_coalesce - Set interrupt coalescing settings
  269. * @netdev: network interface device structure
  270. * @ec: ethtool coalesce structure
  271. *
  272. * Change current coalescing settings.
  273. **/
  274. static int i40evf_set_coalesce(struct net_device *netdev,
  275. struct ethtool_coalesce *ec)
  276. {
  277. struct i40evf_adapter *adapter = netdev_priv(netdev);
  278. struct i40e_hw *hw = &adapter->hw;
  279. struct i40e_vsi *vsi = &adapter->vsi;
  280. struct i40e_q_vector *q_vector;
  281. int i;
  282. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  283. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  284. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  285. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  286. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  287. else
  288. return -EINVAL;
  289. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  290. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  291. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  292. else if (ec->use_adaptive_tx_coalesce)
  293. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  294. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  295. else
  296. return -EINVAL;
  297. if (ec->use_adaptive_rx_coalesce)
  298. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  299. else
  300. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  301. if (ec->use_adaptive_tx_coalesce)
  302. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  303. else
  304. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  305. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  306. q_vector = adapter->q_vector[i];
  307. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  308. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  309. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  310. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  311. i40e_flush(hw);
  312. }
  313. return 0;
  314. }
  315. /**
  316. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  317. * @adapter: board private structure
  318. * @cmd: ethtool rxnfc command
  319. *
  320. * Returns Success if the flow is supported, else Invalid Input.
  321. **/
  322. static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
  323. struct ethtool_rxnfc *cmd)
  324. {
  325. struct i40e_hw *hw = &adapter->hw;
  326. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  327. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  328. /* We always hash on IP src and dest addresses */
  329. cmd->data = RXH_IP_SRC | RXH_IP_DST;
  330. switch (cmd->flow_type) {
  331. case TCP_V4_FLOW:
  332. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
  333. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  334. break;
  335. case UDP_V4_FLOW:
  336. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
  337. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  338. break;
  339. case SCTP_V4_FLOW:
  340. case AH_ESP_V4_FLOW:
  341. case AH_V4_FLOW:
  342. case ESP_V4_FLOW:
  343. case IPV4_FLOW:
  344. break;
  345. case TCP_V6_FLOW:
  346. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
  347. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  348. break;
  349. case UDP_V6_FLOW:
  350. if (hena & ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
  351. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  352. break;
  353. case SCTP_V6_FLOW:
  354. case AH_ESP_V6_FLOW:
  355. case AH_V6_FLOW:
  356. case ESP_V6_FLOW:
  357. case IPV6_FLOW:
  358. break;
  359. default:
  360. cmd->data = 0;
  361. return -EINVAL;
  362. }
  363. return 0;
  364. }
  365. /**
  366. * i40evf_get_rxnfc - command to get RX flow classification rules
  367. * @netdev: network interface device structure
  368. * @cmd: ethtool rxnfc command
  369. *
  370. * Returns Success if the command is supported.
  371. **/
  372. static int i40evf_get_rxnfc(struct net_device *netdev,
  373. struct ethtool_rxnfc *cmd,
  374. u32 *rule_locs)
  375. {
  376. struct i40evf_adapter *adapter = netdev_priv(netdev);
  377. int ret = -EOPNOTSUPP;
  378. switch (cmd->cmd) {
  379. case ETHTOOL_GRXRINGS:
  380. cmd->data = adapter->vsi_res->num_queue_pairs;
  381. ret = 0;
  382. break;
  383. case ETHTOOL_GRXFH:
  384. ret = i40evf_get_rss_hash_opts(adapter, cmd);
  385. break;
  386. default:
  387. break;
  388. }
  389. return ret;
  390. }
  391. /**
  392. * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  393. * @adapter: board private structure
  394. * @cmd: ethtool rxnfc command
  395. *
  396. * Returns Success if the flow input set is supported.
  397. **/
  398. static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
  399. struct ethtool_rxnfc *nfc)
  400. {
  401. struct i40e_hw *hw = &adapter->hw;
  402. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  403. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  404. /* RSS does not support anything other than hashing
  405. * to queues on src and dst IPs and ports
  406. */
  407. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  408. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  409. return -EINVAL;
  410. /* We need at least the IP SRC and DEST fields for hashing */
  411. if (!(nfc->data & RXH_IP_SRC) ||
  412. !(nfc->data & RXH_IP_DST))
  413. return -EINVAL;
  414. switch (nfc->flow_type) {
  415. case TCP_V4_FLOW:
  416. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  417. case 0:
  418. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  419. break;
  420. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  421. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  422. break;
  423. default:
  424. return -EINVAL;
  425. }
  426. break;
  427. case TCP_V6_FLOW:
  428. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  429. case 0:
  430. hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  431. break;
  432. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  433. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  434. break;
  435. default:
  436. return -EINVAL;
  437. }
  438. break;
  439. case UDP_V4_FLOW:
  440. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  441. case 0:
  442. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  443. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  444. break;
  445. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  446. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  447. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
  448. break;
  449. default:
  450. return -EINVAL;
  451. }
  452. break;
  453. case UDP_V6_FLOW:
  454. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  455. case 0:
  456. hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  457. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  458. break;
  459. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  460. hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  461. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
  462. break;
  463. default:
  464. return -EINVAL;
  465. }
  466. break;
  467. case AH_ESP_V4_FLOW:
  468. case AH_V4_FLOW:
  469. case ESP_V4_FLOW:
  470. case SCTP_V4_FLOW:
  471. if ((nfc->data & RXH_L4_B_0_1) ||
  472. (nfc->data & RXH_L4_B_2_3))
  473. return -EINVAL;
  474. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  475. break;
  476. case AH_ESP_V6_FLOW:
  477. case AH_V6_FLOW:
  478. case ESP_V6_FLOW:
  479. case SCTP_V6_FLOW:
  480. if ((nfc->data & RXH_L4_B_0_1) ||
  481. (nfc->data & RXH_L4_B_2_3))
  482. return -EINVAL;
  483. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  484. break;
  485. case IPV4_FLOW:
  486. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  487. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
  488. break;
  489. case IPV6_FLOW:
  490. hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  491. ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
  492. break;
  493. default:
  494. return -EINVAL;
  495. }
  496. wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
  497. wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
  498. i40e_flush(hw);
  499. return 0;
  500. }
  501. /**
  502. * i40evf_set_rxnfc - command to set RX flow classification rules
  503. * @netdev: network interface device structure
  504. * @cmd: ethtool rxnfc command
  505. *
  506. * Returns Success if the command is supported.
  507. **/
  508. static int i40evf_set_rxnfc(struct net_device *netdev,
  509. struct ethtool_rxnfc *cmd)
  510. {
  511. struct i40evf_adapter *adapter = netdev_priv(netdev);
  512. int ret = -EOPNOTSUPP;
  513. switch (cmd->cmd) {
  514. case ETHTOOL_SRXFH:
  515. ret = i40evf_set_rss_hash_opt(adapter, cmd);
  516. break;
  517. default:
  518. break;
  519. }
  520. return ret;
  521. }
  522. /**
  523. * i40evf_get_channels: get the number of channels supported by the device
  524. * @netdev: network interface device structure
  525. * @ch: channel information structure
  526. *
  527. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  528. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  529. **/
  530. static void i40evf_get_channels(struct net_device *netdev,
  531. struct ethtool_channels *ch)
  532. {
  533. struct i40evf_adapter *adapter = netdev_priv(netdev);
  534. /* Report maximum channels */
  535. ch->max_combined = adapter->vsi_res->num_queue_pairs;
  536. ch->max_other = NONQ_VECS;
  537. ch->other_count = NONQ_VECS;
  538. ch->combined_count = adapter->vsi_res->num_queue_pairs;
  539. }
  540. /**
  541. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  542. * @netdev: network interface device structure
  543. *
  544. * Returns the table size.
  545. **/
  546. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  547. {
  548. return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
  549. }
  550. /**
  551. * i40evf_get_rxfh - get the rx flow hash indirection table
  552. * @netdev: network interface device structure
  553. * @indir: indirection table
  554. * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
  555. *
  556. * Reads the indirection table directly from the hardware. Always returns 0.
  557. **/
  558. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key)
  559. {
  560. struct i40evf_adapter *adapter = netdev_priv(netdev);
  561. struct i40e_hw *hw = &adapter->hw;
  562. u32 hlut_val;
  563. int i, j;
  564. for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX; i++) {
  565. hlut_val = rd32(hw, I40E_VFQF_HLUT(i));
  566. indir[j++] = hlut_val & 0xff;
  567. indir[j++] = (hlut_val >> 8) & 0xff;
  568. indir[j++] = (hlut_val >> 16) & 0xff;
  569. indir[j++] = (hlut_val >> 24) & 0xff;
  570. }
  571. return 0;
  572. }
  573. /**
  574. * i40evf_set_rxfh - set the rx flow hash indirection table
  575. * @netdev: network interface device structure
  576. * @indir: indirection table
  577. * @key: hash key (will be %NULL until get_rxfh_key_size is implemented)
  578. *
  579. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  580. * returns 0 after programming the table.
  581. **/
  582. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  583. const u8 *key)
  584. {
  585. struct i40evf_adapter *adapter = netdev_priv(netdev);
  586. struct i40e_hw *hw = &adapter->hw;
  587. u32 hlut_val;
  588. int i, j;
  589. for (i = 0, j = 0; i < I40E_VFQF_HLUT_MAX_INDEX + 1; i++) {
  590. hlut_val = indir[j++];
  591. hlut_val |= indir[j++] << 8;
  592. hlut_val |= indir[j++] << 16;
  593. hlut_val |= indir[j++] << 24;
  594. wr32(hw, I40E_VFQF_HLUT(i), hlut_val);
  595. }
  596. return 0;
  597. }
  598. static const struct ethtool_ops i40evf_ethtool_ops = {
  599. .get_settings = i40evf_get_settings,
  600. .get_drvinfo = i40evf_get_drvinfo,
  601. .get_link = ethtool_op_get_link,
  602. .get_ringparam = i40evf_get_ringparam,
  603. .set_ringparam = i40evf_set_ringparam,
  604. .get_strings = i40evf_get_strings,
  605. .get_ethtool_stats = i40evf_get_ethtool_stats,
  606. .get_sset_count = i40evf_get_sset_count,
  607. .get_msglevel = i40evf_get_msglevel,
  608. .set_msglevel = i40evf_set_msglevel,
  609. .get_coalesce = i40evf_get_coalesce,
  610. .set_coalesce = i40evf_set_coalesce,
  611. .get_rxnfc = i40evf_get_rxnfc,
  612. .set_rxnfc = i40evf_set_rxnfc,
  613. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  614. .get_rxfh = i40evf_get_rxfh,
  615. .set_rxfh = i40evf_set_rxfh,
  616. .get_channels = i40evf_get_channels,
  617. };
  618. /**
  619. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  620. * @netdev: network interface device structure
  621. *
  622. * Sets ethtool ops struct in our netdev so that ethtool can call
  623. * our functions.
  624. **/
  625. void i40evf_set_ethtool_ops(struct net_device *netdev)
  626. {
  627. netdev->ethtool_ops = &i40evf_ethtool_ops;
  628. }