i40evf_ethtool.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
  4. * Copyright(c) 2013 - 2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* ethtool support for i40evf */
  27. #include "i40evf.h"
  28. #include <linux/uaccess.h>
  29. struct i40evf_stats {
  30. char stat_string[ETH_GSTRING_LEN];
  31. int stat_offset;
  32. };
  33. #define I40EVF_STAT(_name, _stat) { \
  34. .stat_string = _name, \
  35. .stat_offset = offsetof(struct i40evf_adapter, _stat) \
  36. }
  37. /* All stats are u64, so we don't need to track the size of the field. */
  38. static const struct i40evf_stats i40evf_gstrings_stats[] = {
  39. I40EVF_STAT("rx_bytes", current_stats.rx_bytes),
  40. I40EVF_STAT("rx_unicast", current_stats.rx_unicast),
  41. I40EVF_STAT("rx_multicast", current_stats.rx_multicast),
  42. I40EVF_STAT("rx_broadcast", current_stats.rx_broadcast),
  43. I40EVF_STAT("rx_discards", current_stats.rx_discards),
  44. I40EVF_STAT("rx_unknown_protocol", current_stats.rx_unknown_protocol),
  45. I40EVF_STAT("tx_bytes", current_stats.tx_bytes),
  46. I40EVF_STAT("tx_unicast", current_stats.tx_unicast),
  47. I40EVF_STAT("tx_multicast", current_stats.tx_multicast),
  48. I40EVF_STAT("tx_broadcast", current_stats.tx_broadcast),
  49. I40EVF_STAT("tx_discards", current_stats.tx_discards),
  50. I40EVF_STAT("tx_errors", current_stats.tx_errors),
  51. };
  52. #define I40EVF_GLOBAL_STATS_LEN ARRAY_SIZE(i40evf_gstrings_stats)
  53. #define I40EVF_QUEUE_STATS_LEN(_dev) \
  54. (((struct i40evf_adapter *)\
  55. netdev_priv(_dev))->num_active_queues \
  56. * 2 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
  57. #define I40EVF_STATS_LEN(_dev) \
  58. (I40EVF_GLOBAL_STATS_LEN + I40EVF_QUEUE_STATS_LEN(_dev))
  59. /**
  60. * i40evf_get_settings - Get Link Speed and Duplex settings
  61. * @netdev: network interface device structure
  62. * @ecmd: ethtool command
  63. *
  64. * Reports speed/duplex settings. Because this is a VF, we don't know what
  65. * kind of link we really have, so we fake it.
  66. **/
  67. static int i40evf_get_settings(struct net_device *netdev,
  68. struct ethtool_cmd *ecmd)
  69. {
  70. /* 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->num_active_queues; 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->num_active_queues; 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->num_active_queues; 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->num_active_queues; 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_set_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. if (I40E_DEBUG_USER & data)
  177. adapter->hw.debug_mask = data;
  178. adapter->msg_enable = data;
  179. }
  180. /**
  181. * i40evf_get_drvinfo - Get driver info
  182. * @netdev: network interface device structure
  183. * @drvinfo: ethool driver info structure
  184. *
  185. * Returns information about the driver and device for display to the user.
  186. **/
  187. static void i40evf_get_drvinfo(struct net_device *netdev,
  188. struct ethtool_drvinfo *drvinfo)
  189. {
  190. struct i40evf_adapter *adapter = netdev_priv(netdev);
  191. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  192. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  193. strlcpy(drvinfo->fw_version, "N/A", 4);
  194. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  195. }
  196. /**
  197. * i40evf_get_ringparam - Get ring parameters
  198. * @netdev: network interface device structure
  199. * @ring: ethtool ringparam structure
  200. *
  201. * Returns current ring parameters. TX and RX rings are reported separately,
  202. * but the number of rings is not reported.
  203. **/
  204. static void i40evf_get_ringparam(struct net_device *netdev,
  205. struct ethtool_ringparam *ring)
  206. {
  207. struct i40evf_adapter *adapter = netdev_priv(netdev);
  208. ring->rx_max_pending = I40EVF_MAX_RXD;
  209. ring->tx_max_pending = I40EVF_MAX_TXD;
  210. ring->rx_pending = adapter->rx_desc_count;
  211. ring->tx_pending = adapter->tx_desc_count;
  212. }
  213. /**
  214. * i40evf_set_ringparam - Set ring parameters
  215. * @netdev: network interface device structure
  216. * @ring: ethtool ringparam structure
  217. *
  218. * Sets ring parameters. TX and RX rings are controlled separately, but the
  219. * number of rings is not specified, so all rings get the same settings.
  220. **/
  221. static int i40evf_set_ringparam(struct net_device *netdev,
  222. struct ethtool_ringparam *ring)
  223. {
  224. struct i40evf_adapter *adapter = netdev_priv(netdev);
  225. u32 new_rx_count, new_tx_count;
  226. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  227. return -EINVAL;
  228. new_tx_count = clamp_t(u32, ring->tx_pending,
  229. I40EVF_MIN_TXD,
  230. I40EVF_MAX_TXD);
  231. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  232. new_rx_count = clamp_t(u32, ring->rx_pending,
  233. I40EVF_MIN_RXD,
  234. I40EVF_MAX_RXD);
  235. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  236. /* if nothing to do return success */
  237. if ((new_tx_count == adapter->tx_desc_count) &&
  238. (new_rx_count == adapter->rx_desc_count))
  239. return 0;
  240. adapter->tx_desc_count = new_tx_count;
  241. adapter->rx_desc_count = new_rx_count;
  242. if (netif_running(netdev)) {
  243. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  244. schedule_work(&adapter->reset_task);
  245. }
  246. return 0;
  247. }
  248. /**
  249. * i40evf_get_coalesce - Get interrupt coalescing settings
  250. * @netdev: network interface device structure
  251. * @ec: ethtool coalesce structure
  252. *
  253. * Returns current coalescing settings. This is referred to elsewhere in the
  254. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  255. * this functionality.
  256. **/
  257. static int i40evf_get_coalesce(struct net_device *netdev,
  258. struct ethtool_coalesce *ec)
  259. {
  260. struct i40evf_adapter *adapter = netdev_priv(netdev);
  261. struct i40e_vsi *vsi = &adapter->vsi;
  262. ec->tx_max_coalesced_frames = vsi->work_limit;
  263. ec->rx_max_coalesced_frames = vsi->work_limit;
  264. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  265. ec->use_adaptive_rx_coalesce = 1;
  266. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  267. ec->use_adaptive_tx_coalesce = 1;
  268. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  269. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  270. return 0;
  271. }
  272. /**
  273. * i40evf_set_coalesce - Set interrupt coalescing settings
  274. * @netdev: network interface device structure
  275. * @ec: ethtool coalesce structure
  276. *
  277. * Change current coalescing settings.
  278. **/
  279. static int i40evf_set_coalesce(struct net_device *netdev,
  280. struct ethtool_coalesce *ec)
  281. {
  282. struct i40evf_adapter *adapter = netdev_priv(netdev);
  283. struct i40e_hw *hw = &adapter->hw;
  284. struct i40e_vsi *vsi = &adapter->vsi;
  285. struct i40e_q_vector *q_vector;
  286. int i;
  287. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  288. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  289. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  290. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  291. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  292. else
  293. return -EINVAL;
  294. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  295. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  296. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  297. else if (ec->use_adaptive_tx_coalesce)
  298. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  299. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  300. else
  301. return -EINVAL;
  302. if (ec->use_adaptive_rx_coalesce)
  303. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  304. else
  305. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  306. if (ec->use_adaptive_tx_coalesce)
  307. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  308. else
  309. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  310. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  311. q_vector = &adapter->q_vectors[i];
  312. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  313. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  314. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  315. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  316. i40e_flush(hw);
  317. }
  318. return 0;
  319. }
  320. /**
  321. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  322. * @adapter: board private structure
  323. * @cmd: ethtool rxnfc command
  324. *
  325. * Returns Success if the flow is supported, else Invalid Input.
  326. **/
  327. static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
  328. struct ethtool_rxnfc *cmd)
  329. {
  330. struct i40e_hw *hw = &adapter->hw;
  331. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  332. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  333. /* We always hash on IP src and dest addresses */
  334. cmd->data = RXH_IP_SRC | RXH_IP_DST;
  335. switch (cmd->flow_type) {
  336. case TCP_V4_FLOW:
  337. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
  338. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  339. break;
  340. case UDP_V4_FLOW:
  341. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
  342. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  343. break;
  344. case SCTP_V4_FLOW:
  345. case AH_ESP_V4_FLOW:
  346. case AH_V4_FLOW:
  347. case ESP_V4_FLOW:
  348. case IPV4_FLOW:
  349. break;
  350. case TCP_V6_FLOW:
  351. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
  352. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  353. break;
  354. case UDP_V6_FLOW:
  355. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
  356. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  357. break;
  358. case SCTP_V6_FLOW:
  359. case AH_ESP_V6_FLOW:
  360. case AH_V6_FLOW:
  361. case ESP_V6_FLOW:
  362. case IPV6_FLOW:
  363. break;
  364. default:
  365. cmd->data = 0;
  366. return -EINVAL;
  367. }
  368. return 0;
  369. }
  370. /**
  371. * i40evf_get_rxnfc - command to get RX flow classification rules
  372. * @netdev: network interface device structure
  373. * @cmd: ethtool rxnfc command
  374. *
  375. * Returns Success if the command is supported.
  376. **/
  377. static int i40evf_get_rxnfc(struct net_device *netdev,
  378. struct ethtool_rxnfc *cmd,
  379. u32 *rule_locs)
  380. {
  381. struct i40evf_adapter *adapter = netdev_priv(netdev);
  382. int ret = -EOPNOTSUPP;
  383. switch (cmd->cmd) {
  384. case ETHTOOL_GRXRINGS:
  385. cmd->data = adapter->num_active_queues;
  386. ret = 0;
  387. break;
  388. case ETHTOOL_GRXFH:
  389. ret = i40evf_get_rss_hash_opts(adapter, cmd);
  390. break;
  391. default:
  392. break;
  393. }
  394. return ret;
  395. }
  396. /**
  397. * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  398. * @adapter: board private structure
  399. * @cmd: ethtool rxnfc command
  400. *
  401. * Returns Success if the flow input set is supported.
  402. **/
  403. static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
  404. struct ethtool_rxnfc *nfc)
  405. {
  406. struct i40e_hw *hw = &adapter->hw;
  407. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  408. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  409. /* RSS does not support anything other than hashing
  410. * to queues on src and dst IPs and ports
  411. */
  412. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  413. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  414. return -EINVAL;
  415. /* We need at least the IP SRC and DEST fields for hashing */
  416. if (!(nfc->data & RXH_IP_SRC) ||
  417. !(nfc->data & RXH_IP_DST))
  418. return -EINVAL;
  419. switch (nfc->flow_type) {
  420. case TCP_V4_FLOW:
  421. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  422. case 0:
  423. hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  424. break;
  425. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  426. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  427. break;
  428. default:
  429. return -EINVAL;
  430. }
  431. break;
  432. case TCP_V6_FLOW:
  433. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  434. case 0:
  435. hena &= ~BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  436. break;
  437. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  438. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  439. break;
  440. default:
  441. return -EINVAL;
  442. }
  443. break;
  444. case UDP_V4_FLOW:
  445. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  446. case 0:
  447. hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  448. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  449. break;
  450. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  451. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  452. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  453. break;
  454. default:
  455. return -EINVAL;
  456. }
  457. break;
  458. case UDP_V6_FLOW:
  459. switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  460. case 0:
  461. hena &= ~(BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  462. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  463. break;
  464. case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
  465. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  466. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  467. break;
  468. default:
  469. return -EINVAL;
  470. }
  471. break;
  472. case AH_ESP_V4_FLOW:
  473. case AH_V4_FLOW:
  474. case ESP_V4_FLOW:
  475. case SCTP_V4_FLOW:
  476. if ((nfc->data & RXH_L4_B_0_1) ||
  477. (nfc->data & RXH_L4_B_2_3))
  478. return -EINVAL;
  479. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  480. break;
  481. case AH_ESP_V6_FLOW:
  482. case AH_V6_FLOW:
  483. case ESP_V6_FLOW:
  484. case SCTP_V6_FLOW:
  485. if ((nfc->data & RXH_L4_B_0_1) ||
  486. (nfc->data & RXH_L4_B_2_3))
  487. return -EINVAL;
  488. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  489. break;
  490. case IPV4_FLOW:
  491. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  492. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  493. break;
  494. case IPV6_FLOW:
  495. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  496. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  497. break;
  498. default:
  499. return -EINVAL;
  500. }
  501. wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
  502. wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
  503. i40e_flush(hw);
  504. return 0;
  505. }
  506. /**
  507. * i40evf_set_rxnfc - command to set RX flow classification rules
  508. * @netdev: network interface device structure
  509. * @cmd: ethtool rxnfc command
  510. *
  511. * Returns Success if the command is supported.
  512. **/
  513. static int i40evf_set_rxnfc(struct net_device *netdev,
  514. struct ethtool_rxnfc *cmd)
  515. {
  516. struct i40evf_adapter *adapter = netdev_priv(netdev);
  517. int ret = -EOPNOTSUPP;
  518. switch (cmd->cmd) {
  519. case ETHTOOL_SRXFH:
  520. ret = i40evf_set_rss_hash_opt(adapter, cmd);
  521. break;
  522. default:
  523. break;
  524. }
  525. return ret;
  526. }
  527. /**
  528. * i40evf_get_channels: get the number of channels supported by the device
  529. * @netdev: network interface device structure
  530. * @ch: channel information structure
  531. *
  532. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  533. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  534. **/
  535. static void i40evf_get_channels(struct net_device *netdev,
  536. struct ethtool_channels *ch)
  537. {
  538. struct i40evf_adapter *adapter = netdev_priv(netdev);
  539. /* Report maximum channels */
  540. ch->max_combined = adapter->num_active_queues;
  541. ch->max_other = NONQ_VECS;
  542. ch->other_count = NONQ_VECS;
  543. ch->combined_count = adapter->num_active_queues;
  544. }
  545. /**
  546. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  547. * @netdev: network interface device structure
  548. *
  549. * Returns the table size.
  550. **/
  551. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  552. {
  553. return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
  554. }
  555. /**
  556. * i40evf_get_rxfh - get the rx flow hash indirection table
  557. * @netdev: network interface device structure
  558. * @indir: indirection table
  559. * @key: hash key
  560. *
  561. * Reads the indirection table directly from the hardware. Always returns 0.
  562. **/
  563. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  564. u8 *hfunc)
  565. {
  566. struct i40evf_adapter *adapter = netdev_priv(netdev);
  567. struct i40e_vsi *vsi = &adapter->vsi;
  568. u8 *seed = NULL, *lut;
  569. int ret;
  570. u16 i;
  571. if (hfunc)
  572. *hfunc = ETH_RSS_HASH_TOP;
  573. if (!indir)
  574. return 0;
  575. seed = key;
  576. lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
  577. if (!lut)
  578. return -ENOMEM;
  579. ret = i40evf_get_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
  580. if (ret)
  581. goto out;
  582. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  583. for (i = 0; i < I40EVF_HLUT_ARRAY_SIZE; i++)
  584. indir[i] = (u32)lut[i];
  585. out:
  586. kfree(lut);
  587. return ret;
  588. }
  589. /**
  590. * i40evf_set_rxfh - set the rx flow hash indirection table
  591. * @netdev: network interface device structure
  592. * @indir: indirection table
  593. * @key: hash key
  594. *
  595. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  596. * returns 0 after programming the table.
  597. **/
  598. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  599. const u8 *key, const u8 hfunc)
  600. {
  601. struct i40evf_adapter *adapter = netdev_priv(netdev);
  602. struct i40e_vsi *vsi = &adapter->vsi;
  603. u8 *seed = NULL;
  604. u16 i;
  605. /* We do not allow change in unsupported parameters */
  606. if (key ||
  607. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  608. return -EOPNOTSUPP;
  609. if (!indir)
  610. return 0;
  611. if (key) {
  612. if (!vsi->rss_hkey_user) {
  613. vsi->rss_hkey_user = kzalloc(I40EVF_HKEY_ARRAY_SIZE,
  614. GFP_KERNEL);
  615. if (!vsi->rss_hkey_user)
  616. return -ENOMEM;
  617. }
  618. memcpy(vsi->rss_hkey_user, key, I40EVF_HKEY_ARRAY_SIZE);
  619. seed = vsi->rss_hkey_user;
  620. }
  621. if (!vsi->rss_lut_user) {
  622. vsi->rss_lut_user = kzalloc(I40EVF_HLUT_ARRAY_SIZE,
  623. GFP_KERNEL);
  624. if (!vsi->rss_lut_user)
  625. return -ENOMEM;
  626. }
  627. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  628. for (i = 0; i < I40EVF_HLUT_ARRAY_SIZE; i++)
  629. vsi->rss_lut_user[i] = (u8)(indir[i]);
  630. return i40evf_config_rss(vsi, seed, vsi->rss_lut_user,
  631. I40EVF_HLUT_ARRAY_SIZE);
  632. }
  633. static const struct ethtool_ops i40evf_ethtool_ops = {
  634. .get_settings = i40evf_get_settings,
  635. .get_drvinfo = i40evf_get_drvinfo,
  636. .get_link = ethtool_op_get_link,
  637. .get_ringparam = i40evf_get_ringparam,
  638. .set_ringparam = i40evf_set_ringparam,
  639. .get_strings = i40evf_get_strings,
  640. .get_ethtool_stats = i40evf_get_ethtool_stats,
  641. .get_sset_count = i40evf_get_sset_count,
  642. .get_msglevel = i40evf_get_msglevel,
  643. .set_msglevel = i40evf_set_msglevel,
  644. .get_coalesce = i40evf_get_coalesce,
  645. .set_coalesce = i40evf_set_coalesce,
  646. .get_rxnfc = i40evf_get_rxnfc,
  647. .set_rxnfc = i40evf_set_rxnfc,
  648. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  649. .get_rxfh = i40evf_get_rxfh,
  650. .set_rxfh = i40evf_set_rxfh,
  651. .get_channels = i40evf_get_channels,
  652. };
  653. /**
  654. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  655. * @netdev: network interface device structure
  656. *
  657. * Sets ethtool ops struct in our netdev so that ethtool can call
  658. * our functions.
  659. **/
  660. void i40evf_set_ethtool_ops(struct net_device *netdev)
  661. {
  662. netdev->ethtool_ops = &i40evf_ethtool_ops;
  663. }