i40evf_ethtool.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. static const char i40evf_priv_flags_strings[][ETH_GSTRING_LEN] = {
  60. "packet-split",
  61. };
  62. #define I40EVF_PRIV_FLAGS_STR_LEN ARRAY_SIZE(i40evf_priv_flags_strings)
  63. /**
  64. * i40evf_get_settings - Get Link Speed and Duplex settings
  65. * @netdev: network interface device structure
  66. * @ecmd: ethtool command
  67. *
  68. * Reports speed/duplex settings. Because this is a VF, we don't know what
  69. * kind of link we really have, so we fake it.
  70. **/
  71. static int i40evf_get_settings(struct net_device *netdev,
  72. struct ethtool_cmd *ecmd)
  73. {
  74. /* In the future the VF will be able to query the PF for
  75. * some information - for now use a dummy value
  76. */
  77. ecmd->supported = 0;
  78. ecmd->autoneg = AUTONEG_DISABLE;
  79. ecmd->transceiver = XCVR_DUMMY1;
  80. ecmd->port = PORT_NONE;
  81. return 0;
  82. }
  83. /**
  84. * i40evf_get_sset_count - Get length of string set
  85. * @netdev: network interface device structure
  86. * @sset: id of string set
  87. *
  88. * Reports size of string table. This driver only supports
  89. * strings for statistics.
  90. **/
  91. static int i40evf_get_sset_count(struct net_device *netdev, int sset)
  92. {
  93. if (sset == ETH_SS_STATS)
  94. return I40EVF_STATS_LEN(netdev);
  95. else if (sset == ETH_SS_PRIV_FLAGS)
  96. return I40EVF_PRIV_FLAGS_STR_LEN;
  97. else
  98. return -EINVAL;
  99. }
  100. /**
  101. * i40evf_get_ethtool_stats - report device statistics
  102. * @netdev: network interface device structure
  103. * @stats: ethtool statistics structure
  104. * @data: pointer to data buffer
  105. *
  106. * All statistics are added to the data buffer as an array of u64.
  107. **/
  108. static void i40evf_get_ethtool_stats(struct net_device *netdev,
  109. struct ethtool_stats *stats, u64 *data)
  110. {
  111. struct i40evf_adapter *adapter = netdev_priv(netdev);
  112. int i, j;
  113. char *p;
  114. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  115. p = (char *)adapter + i40evf_gstrings_stats[i].stat_offset;
  116. data[i] = *(u64 *)p;
  117. }
  118. for (j = 0; j < adapter->num_active_queues; j++) {
  119. data[i++] = adapter->tx_rings[j].stats.packets;
  120. data[i++] = adapter->tx_rings[j].stats.bytes;
  121. }
  122. for (j = 0; j < adapter->num_active_queues; j++) {
  123. data[i++] = adapter->rx_rings[j].stats.packets;
  124. data[i++] = adapter->rx_rings[j].stats.bytes;
  125. }
  126. }
  127. /**
  128. * i40evf_get_strings - Get string set
  129. * @netdev: network interface device structure
  130. * @sset: id of string set
  131. * @data: buffer for string data
  132. *
  133. * Builds stats string table.
  134. **/
  135. static void i40evf_get_strings(struct net_device *netdev, u32 sset, u8 *data)
  136. {
  137. struct i40evf_adapter *adapter = netdev_priv(netdev);
  138. u8 *p = data;
  139. int i;
  140. if (sset == ETH_SS_STATS) {
  141. for (i = 0; i < I40EVF_GLOBAL_STATS_LEN; i++) {
  142. memcpy(p, i40evf_gstrings_stats[i].stat_string,
  143. ETH_GSTRING_LEN);
  144. p += ETH_GSTRING_LEN;
  145. }
  146. for (i = 0; i < adapter->num_active_queues; i++) {
  147. snprintf(p, ETH_GSTRING_LEN, "tx-%u.packets", i);
  148. p += ETH_GSTRING_LEN;
  149. snprintf(p, ETH_GSTRING_LEN, "tx-%u.bytes", i);
  150. p += ETH_GSTRING_LEN;
  151. }
  152. for (i = 0; i < adapter->num_active_queues; i++) {
  153. snprintf(p, ETH_GSTRING_LEN, "rx-%u.packets", i);
  154. p += ETH_GSTRING_LEN;
  155. snprintf(p, ETH_GSTRING_LEN, "rx-%u.bytes", i);
  156. p += ETH_GSTRING_LEN;
  157. }
  158. } else if (sset == ETH_SS_PRIV_FLAGS) {
  159. for (i = 0; i < I40EVF_PRIV_FLAGS_STR_LEN; i++) {
  160. memcpy(data, i40evf_priv_flags_strings[i],
  161. ETH_GSTRING_LEN);
  162. data += ETH_GSTRING_LEN;
  163. }
  164. }
  165. }
  166. /**
  167. * i40evf_get_msglevel - Get debug message level
  168. * @netdev: network interface device structure
  169. *
  170. * Returns current debug message level.
  171. **/
  172. static u32 i40evf_get_msglevel(struct net_device *netdev)
  173. {
  174. struct i40evf_adapter *adapter = netdev_priv(netdev);
  175. return adapter->msg_enable;
  176. }
  177. /**
  178. * i40evf_set_msglevel - Set debug message level
  179. * @netdev: network interface device structure
  180. * @data: message level
  181. *
  182. * Set current debug message level. Higher values cause the driver to
  183. * be noisier.
  184. **/
  185. static void i40evf_set_msglevel(struct net_device *netdev, u32 data)
  186. {
  187. struct i40evf_adapter *adapter = netdev_priv(netdev);
  188. if (I40E_DEBUG_USER & data)
  189. adapter->hw.debug_mask = data;
  190. adapter->msg_enable = data;
  191. }
  192. /**
  193. * i40evf_get_drvinfo - Get driver info
  194. * @netdev: network interface device structure
  195. * @drvinfo: ethool driver info structure
  196. *
  197. * Returns information about the driver and device for display to the user.
  198. **/
  199. static void i40evf_get_drvinfo(struct net_device *netdev,
  200. struct ethtool_drvinfo *drvinfo)
  201. {
  202. struct i40evf_adapter *adapter = netdev_priv(netdev);
  203. strlcpy(drvinfo->driver, i40evf_driver_name, 32);
  204. strlcpy(drvinfo->version, i40evf_driver_version, 32);
  205. strlcpy(drvinfo->fw_version, "N/A", 4);
  206. strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), 32);
  207. drvinfo->n_priv_flags = I40EVF_PRIV_FLAGS_STR_LEN;
  208. }
  209. /**
  210. * i40evf_get_ringparam - Get ring parameters
  211. * @netdev: network interface device structure
  212. * @ring: ethtool ringparam structure
  213. *
  214. * Returns current ring parameters. TX and RX rings are reported separately,
  215. * but the number of rings is not reported.
  216. **/
  217. static void i40evf_get_ringparam(struct net_device *netdev,
  218. struct ethtool_ringparam *ring)
  219. {
  220. struct i40evf_adapter *adapter = netdev_priv(netdev);
  221. ring->rx_max_pending = I40EVF_MAX_RXD;
  222. ring->tx_max_pending = I40EVF_MAX_TXD;
  223. ring->rx_pending = adapter->rx_desc_count;
  224. ring->tx_pending = adapter->tx_desc_count;
  225. }
  226. /**
  227. * i40evf_set_ringparam - Set ring parameters
  228. * @netdev: network interface device structure
  229. * @ring: ethtool ringparam structure
  230. *
  231. * Sets ring parameters. TX and RX rings are controlled separately, but the
  232. * number of rings is not specified, so all rings get the same settings.
  233. **/
  234. static int i40evf_set_ringparam(struct net_device *netdev,
  235. struct ethtool_ringparam *ring)
  236. {
  237. struct i40evf_adapter *adapter = netdev_priv(netdev);
  238. u32 new_rx_count, new_tx_count;
  239. if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
  240. return -EINVAL;
  241. new_tx_count = clamp_t(u32, ring->tx_pending,
  242. I40EVF_MIN_TXD,
  243. I40EVF_MAX_TXD);
  244. new_tx_count = ALIGN(new_tx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  245. new_rx_count = clamp_t(u32, ring->rx_pending,
  246. I40EVF_MIN_RXD,
  247. I40EVF_MAX_RXD);
  248. new_rx_count = ALIGN(new_rx_count, I40EVF_REQ_DESCRIPTOR_MULTIPLE);
  249. /* if nothing to do return success */
  250. if ((new_tx_count == adapter->tx_desc_count) &&
  251. (new_rx_count == adapter->rx_desc_count))
  252. return 0;
  253. adapter->tx_desc_count = new_tx_count;
  254. adapter->rx_desc_count = new_rx_count;
  255. if (netif_running(netdev)) {
  256. adapter->flags |= I40EVF_FLAG_RESET_NEEDED;
  257. schedule_work(&adapter->reset_task);
  258. }
  259. return 0;
  260. }
  261. /**
  262. * i40evf_get_coalesce - Get interrupt coalescing settings
  263. * @netdev: network interface device structure
  264. * @ec: ethtool coalesce structure
  265. *
  266. * Returns current coalescing settings. This is referred to elsewhere in the
  267. * driver as Interrupt Throttle Rate, as this is how the hardware describes
  268. * this functionality.
  269. **/
  270. static int i40evf_get_coalesce(struct net_device *netdev,
  271. struct ethtool_coalesce *ec)
  272. {
  273. struct i40evf_adapter *adapter = netdev_priv(netdev);
  274. struct i40e_vsi *vsi = &adapter->vsi;
  275. ec->tx_max_coalesced_frames = vsi->work_limit;
  276. ec->rx_max_coalesced_frames = vsi->work_limit;
  277. if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
  278. ec->use_adaptive_rx_coalesce = 1;
  279. if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
  280. ec->use_adaptive_tx_coalesce = 1;
  281. ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
  282. ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
  283. return 0;
  284. }
  285. /**
  286. * i40evf_set_coalesce - Set interrupt coalescing settings
  287. * @netdev: network interface device structure
  288. * @ec: ethtool coalesce structure
  289. *
  290. * Change current coalescing settings.
  291. **/
  292. static int i40evf_set_coalesce(struct net_device *netdev,
  293. struct ethtool_coalesce *ec)
  294. {
  295. struct i40evf_adapter *adapter = netdev_priv(netdev);
  296. struct i40e_hw *hw = &adapter->hw;
  297. struct i40e_vsi *vsi = &adapter->vsi;
  298. struct i40e_q_vector *q_vector;
  299. int i;
  300. if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
  301. vsi->work_limit = ec->tx_max_coalesced_frames_irq;
  302. if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  303. (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  304. vsi->rx_itr_setting = ec->rx_coalesce_usecs;
  305. else
  306. return -EINVAL;
  307. if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
  308. (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
  309. vsi->tx_itr_setting = ec->tx_coalesce_usecs;
  310. else if (ec->use_adaptive_tx_coalesce)
  311. vsi->tx_itr_setting = (I40E_ITR_DYNAMIC |
  312. ITR_REG_TO_USEC(I40E_ITR_RX_DEF));
  313. else
  314. return -EINVAL;
  315. if (ec->use_adaptive_rx_coalesce)
  316. vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
  317. else
  318. vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
  319. if (ec->use_adaptive_tx_coalesce)
  320. vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
  321. else
  322. vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
  323. for (i = 0; i < adapter->num_msix_vectors - NONQ_VECS; i++) {
  324. q_vector = &adapter->q_vectors[i];
  325. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  326. wr32(hw, I40E_VFINT_ITRN1(0, i), q_vector->rx.itr);
  327. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  328. wr32(hw, I40E_VFINT_ITRN1(1, i), q_vector->tx.itr);
  329. i40e_flush(hw);
  330. }
  331. return 0;
  332. }
  333. /**
  334. * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
  335. * @adapter: board private structure
  336. * @cmd: ethtool rxnfc command
  337. *
  338. * Returns Success if the flow is supported, else Invalid Input.
  339. **/
  340. static int i40evf_get_rss_hash_opts(struct i40evf_adapter *adapter,
  341. struct ethtool_rxnfc *cmd)
  342. {
  343. struct i40e_hw *hw = &adapter->hw;
  344. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  345. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  346. /* We always hash on IP src and dest addresses */
  347. cmd->data = RXH_IP_SRC | RXH_IP_DST;
  348. switch (cmd->flow_type) {
  349. case TCP_V4_FLOW:
  350. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP))
  351. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  352. break;
  353. case UDP_V4_FLOW:
  354. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP))
  355. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  356. break;
  357. case SCTP_V4_FLOW:
  358. case AH_ESP_V4_FLOW:
  359. case AH_V4_FLOW:
  360. case ESP_V4_FLOW:
  361. case IPV4_FLOW:
  362. break;
  363. case TCP_V6_FLOW:
  364. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP))
  365. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  366. break;
  367. case UDP_V6_FLOW:
  368. if (hena & BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP))
  369. cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  370. break;
  371. case SCTP_V6_FLOW:
  372. case AH_ESP_V6_FLOW:
  373. case AH_V6_FLOW:
  374. case ESP_V6_FLOW:
  375. case IPV6_FLOW:
  376. break;
  377. default:
  378. cmd->data = 0;
  379. return -EINVAL;
  380. }
  381. return 0;
  382. }
  383. /**
  384. * i40evf_get_rxnfc - command to get RX flow classification rules
  385. * @netdev: network interface device structure
  386. * @cmd: ethtool rxnfc command
  387. *
  388. * Returns Success if the command is supported.
  389. **/
  390. static int i40evf_get_rxnfc(struct net_device *netdev,
  391. struct ethtool_rxnfc *cmd,
  392. u32 *rule_locs)
  393. {
  394. struct i40evf_adapter *adapter = netdev_priv(netdev);
  395. int ret = -EOPNOTSUPP;
  396. switch (cmd->cmd) {
  397. case ETHTOOL_GRXRINGS:
  398. cmd->data = adapter->num_active_queues;
  399. ret = 0;
  400. break;
  401. case ETHTOOL_GRXFH:
  402. ret = i40evf_get_rss_hash_opts(adapter, cmd);
  403. break;
  404. default:
  405. break;
  406. }
  407. return ret;
  408. }
  409. /**
  410. * i40evf_set_rss_hash_opt - Enable/Disable flow types for RSS hash
  411. * @adapter: board private structure
  412. * @cmd: ethtool rxnfc command
  413. *
  414. * Returns Success if the flow input set is supported.
  415. **/
  416. static int i40evf_set_rss_hash_opt(struct i40evf_adapter *adapter,
  417. struct ethtool_rxnfc *nfc)
  418. {
  419. struct i40e_hw *hw = &adapter->hw;
  420. u32 flags = adapter->vf_res->vf_offload_flags;
  421. u64 hena = (u64)rd32(hw, I40E_VFQF_HENA(0)) |
  422. ((u64)rd32(hw, I40E_VFQF_HENA(1)) << 32);
  423. /* RSS does not support anything other than hashing
  424. * to queues on src and dst IPs and ports
  425. */
  426. if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
  427. RXH_L4_B_0_1 | RXH_L4_B_2_3))
  428. return -EINVAL;
  429. /* We need at least the IP SRC and DEST fields for hashing */
  430. if (!(nfc->data & RXH_IP_SRC) ||
  431. !(nfc->data & RXH_IP_DST))
  432. return -EINVAL;
  433. switch (nfc->flow_type) {
  434. case TCP_V4_FLOW:
  435. if (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  436. if (flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  437. hena |=
  438. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK);
  439. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
  440. } else {
  441. return -EINVAL;
  442. }
  443. break;
  444. case TCP_V6_FLOW:
  445. if (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  446. if (flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  447. hena |=
  448. BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK);
  449. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
  450. } else {
  451. return -EINVAL;
  452. }
  453. break;
  454. case UDP_V4_FLOW:
  455. if (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  456. if (flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  457. hena |=
  458. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) |
  459. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP);
  460. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
  461. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  462. } else {
  463. return -EINVAL;
  464. }
  465. break;
  466. case UDP_V6_FLOW:
  467. if (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
  468. if (flags & I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  469. hena |=
  470. BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) |
  471. BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP);
  472. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
  473. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  474. } else {
  475. return -EINVAL;
  476. }
  477. break;
  478. case AH_ESP_V4_FLOW:
  479. case AH_V4_FLOW:
  480. case ESP_V4_FLOW:
  481. case SCTP_V4_FLOW:
  482. if ((nfc->data & RXH_L4_B_0_1) ||
  483. (nfc->data & RXH_L4_B_2_3))
  484. return -EINVAL;
  485. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
  486. break;
  487. case AH_ESP_V6_FLOW:
  488. case AH_V6_FLOW:
  489. case ESP_V6_FLOW:
  490. case SCTP_V6_FLOW:
  491. if ((nfc->data & RXH_L4_B_0_1) ||
  492. (nfc->data & RXH_L4_B_2_3))
  493. return -EINVAL;
  494. hena |= BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
  495. break;
  496. case IPV4_FLOW:
  497. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
  498. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4));
  499. break;
  500. case IPV6_FLOW:
  501. hena |= (BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
  502. BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6));
  503. break;
  504. default:
  505. return -EINVAL;
  506. }
  507. wr32(hw, I40E_VFQF_HENA(0), (u32)hena);
  508. wr32(hw, I40E_VFQF_HENA(1), (u32)(hena >> 32));
  509. i40e_flush(hw);
  510. return 0;
  511. }
  512. /**
  513. * i40evf_set_rxnfc - command to set RX flow classification rules
  514. * @netdev: network interface device structure
  515. * @cmd: ethtool rxnfc command
  516. *
  517. * Returns Success if the command is supported.
  518. **/
  519. static int i40evf_set_rxnfc(struct net_device *netdev,
  520. struct ethtool_rxnfc *cmd)
  521. {
  522. struct i40evf_adapter *adapter = netdev_priv(netdev);
  523. int ret = -EOPNOTSUPP;
  524. switch (cmd->cmd) {
  525. case ETHTOOL_SRXFH:
  526. ret = i40evf_set_rss_hash_opt(adapter, cmd);
  527. break;
  528. default:
  529. break;
  530. }
  531. return ret;
  532. }
  533. /**
  534. * i40evf_get_channels: get the number of channels supported by the device
  535. * @netdev: network interface device structure
  536. * @ch: channel information structure
  537. *
  538. * For the purposes of our device, we only use combined channels, i.e. a tx/rx
  539. * queue pair. Report one extra channel to match our "other" MSI-X vector.
  540. **/
  541. static void i40evf_get_channels(struct net_device *netdev,
  542. struct ethtool_channels *ch)
  543. {
  544. struct i40evf_adapter *adapter = netdev_priv(netdev);
  545. /* Report maximum channels */
  546. ch->max_combined = adapter->num_active_queues;
  547. ch->max_other = NONQ_VECS;
  548. ch->other_count = NONQ_VECS;
  549. ch->combined_count = adapter->num_active_queues;
  550. }
  551. /**
  552. * i40evf_get_rxfh_indir_size - get the rx flow hash indirection table size
  553. * @netdev: network interface device structure
  554. *
  555. * Returns the table size.
  556. **/
  557. static u32 i40evf_get_rxfh_indir_size(struct net_device *netdev)
  558. {
  559. return (I40E_VFQF_HLUT_MAX_INDEX + 1) * 4;
  560. }
  561. /**
  562. * i40evf_get_rxfh - get the rx flow hash indirection table
  563. * @netdev: network interface device structure
  564. * @indir: indirection table
  565. * @key: hash key
  566. *
  567. * Reads the indirection table directly from the hardware. Always returns 0.
  568. **/
  569. static int i40evf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  570. u8 *hfunc)
  571. {
  572. struct i40evf_adapter *adapter = netdev_priv(netdev);
  573. struct i40e_vsi *vsi = &adapter->vsi;
  574. u8 *seed = NULL, *lut;
  575. int ret;
  576. u16 i;
  577. if (hfunc)
  578. *hfunc = ETH_RSS_HASH_TOP;
  579. if (!indir)
  580. return 0;
  581. seed = key;
  582. lut = kzalloc(I40EVF_HLUT_ARRAY_SIZE, GFP_KERNEL);
  583. if (!lut)
  584. return -ENOMEM;
  585. ret = i40evf_get_rss(vsi, seed, lut, I40EVF_HLUT_ARRAY_SIZE);
  586. if (ret)
  587. goto out;
  588. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  589. for (i = 0; i < I40EVF_HLUT_ARRAY_SIZE; i++)
  590. indir[i] = (u32)lut[i];
  591. out:
  592. kfree(lut);
  593. return ret;
  594. }
  595. /**
  596. * i40evf_set_rxfh - set the rx flow hash indirection table
  597. * @netdev: network interface device structure
  598. * @indir: indirection table
  599. * @key: hash key
  600. *
  601. * Returns -EINVAL if the table specifies an inavlid queue id, otherwise
  602. * returns 0 after programming the table.
  603. **/
  604. static int i40evf_set_rxfh(struct net_device *netdev, const u32 *indir,
  605. const u8 *key, const u8 hfunc)
  606. {
  607. struct i40evf_adapter *adapter = netdev_priv(netdev);
  608. struct i40e_vsi *vsi = &adapter->vsi;
  609. u8 *seed = NULL;
  610. u16 i;
  611. /* We do not allow change in unsupported parameters */
  612. if (key ||
  613. (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  614. return -EOPNOTSUPP;
  615. if (!indir)
  616. return 0;
  617. if (key) {
  618. if (!vsi->rss_hkey_user) {
  619. vsi->rss_hkey_user = kzalloc(I40EVF_HKEY_ARRAY_SIZE,
  620. GFP_KERNEL);
  621. if (!vsi->rss_hkey_user)
  622. return -ENOMEM;
  623. }
  624. memcpy(vsi->rss_hkey_user, key, I40EVF_HKEY_ARRAY_SIZE);
  625. seed = vsi->rss_hkey_user;
  626. }
  627. if (!vsi->rss_lut_user) {
  628. vsi->rss_lut_user = kzalloc(I40EVF_HLUT_ARRAY_SIZE,
  629. GFP_KERNEL);
  630. if (!vsi->rss_lut_user)
  631. return -ENOMEM;
  632. }
  633. /* Each 32 bits pointed by 'indir' is stored with a lut entry */
  634. for (i = 0; i < I40EVF_HLUT_ARRAY_SIZE; i++)
  635. vsi->rss_lut_user[i] = (u8)(indir[i]);
  636. return i40evf_config_rss(vsi, seed, vsi->rss_lut_user,
  637. I40EVF_HLUT_ARRAY_SIZE);
  638. }
  639. /**
  640. * i40evf_get_priv_flags - report device private flags
  641. * @dev: network interface device structure
  642. *
  643. * The get string set count and the string set should be matched for each
  644. * flag returned. Add new strings for each flag to the i40e_priv_flags_strings
  645. * array.
  646. *
  647. * Returns a u32 bitmap of flags.
  648. **/
  649. static u32 i40evf_get_priv_flags(struct net_device *dev)
  650. {
  651. struct i40evf_adapter *adapter = netdev_priv(dev);
  652. u32 ret_flags = 0;
  653. ret_flags |= adapter->flags & I40EVF_FLAG_RX_PS_ENABLED ?
  654. I40EVF_PRIV_FLAGS_PS : 0;
  655. return ret_flags;
  656. }
  657. /**
  658. * i40evf_set_priv_flags - set private flags
  659. * @dev: network interface device structure
  660. * @flags: bit flags to be set
  661. **/
  662. static int i40evf_set_priv_flags(struct net_device *dev, u32 flags)
  663. {
  664. struct i40evf_adapter *adapter = netdev_priv(dev);
  665. bool reset_required = false;
  666. if ((flags & I40EVF_PRIV_FLAGS_PS) &&
  667. !(adapter->flags & I40EVF_FLAG_RX_PS_ENABLED)) {
  668. adapter->flags |= I40EVF_FLAG_RX_PS_ENABLED;
  669. reset_required = true;
  670. } else if (!(flags & I40EVF_PRIV_FLAGS_PS) &&
  671. (adapter->flags & I40EVF_FLAG_RX_PS_ENABLED)) {
  672. adapter->flags &= ~I40EVF_FLAG_RX_PS_ENABLED;
  673. reset_required = true;
  674. }
  675. /* if needed, issue reset to cause things to take effect */
  676. if (reset_required)
  677. i40evf_schedule_reset(adapter);
  678. return 0;
  679. }
  680. static const struct ethtool_ops i40evf_ethtool_ops = {
  681. .get_settings = i40evf_get_settings,
  682. .get_drvinfo = i40evf_get_drvinfo,
  683. .get_link = ethtool_op_get_link,
  684. .get_ringparam = i40evf_get_ringparam,
  685. .set_ringparam = i40evf_set_ringparam,
  686. .get_strings = i40evf_get_strings,
  687. .get_ethtool_stats = i40evf_get_ethtool_stats,
  688. .get_sset_count = i40evf_get_sset_count,
  689. .get_priv_flags = i40evf_get_priv_flags,
  690. .set_priv_flags = i40evf_set_priv_flags,
  691. .get_msglevel = i40evf_get_msglevel,
  692. .set_msglevel = i40evf_set_msglevel,
  693. .get_coalesce = i40evf_get_coalesce,
  694. .set_coalesce = i40evf_set_coalesce,
  695. .get_rxnfc = i40evf_get_rxnfc,
  696. .set_rxnfc = i40evf_set_rxnfc,
  697. .get_rxfh_indir_size = i40evf_get_rxfh_indir_size,
  698. .get_rxfh = i40evf_get_rxfh,
  699. .set_rxfh = i40evf_set_rxfh,
  700. .get_channels = i40evf_get_channels,
  701. };
  702. /**
  703. * i40evf_set_ethtool_ops - Initialize ethtool ops struct
  704. * @netdev: network interface device structure
  705. *
  706. * Sets ethtool ops struct in our netdev so that ethtool can call
  707. * our functions.
  708. **/
  709. void i40evf_set_ethtool_ops(struct net_device *netdev)
  710. {
  711. netdev->ethtool_ops = &i40evf_ethtool_ops;
  712. }