1 /*******************************************************************************
3 * Intel Ethernet Controller XL710 Family Linux Driver
4 * Copyright(c) 2013 - 2014 Intel Corporation.
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.
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
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/>.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
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
25 ******************************************************************************/
27 /* ethtool support for i40e */
30 #include "i40e_diag.h"
33 char stat_string[ETH_GSTRING_LEN];
38 #define I40E_STAT(_type, _name, _stat) { \
39 .stat_string = _name, \
40 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
41 .stat_offset = offsetof(_type, _stat) \
43 #define I40E_NETDEV_STAT(_net_stat) \
44 I40E_STAT(struct net_device_stats, #_net_stat, _net_stat)
45 #define I40E_PF_STAT(_name, _stat) \
46 I40E_STAT(struct i40e_pf, _name, _stat)
47 #define I40E_VSI_STAT(_name, _stat) \
48 I40E_STAT(struct i40e_vsi, _name, _stat)
50 static const struct i40e_stats i40e_gstrings_net_stats[] = {
51 I40E_NETDEV_STAT(rx_packets),
52 I40E_NETDEV_STAT(tx_packets),
53 I40E_NETDEV_STAT(rx_bytes),
54 I40E_NETDEV_STAT(tx_bytes),
55 I40E_NETDEV_STAT(rx_errors),
56 I40E_NETDEV_STAT(tx_errors),
57 I40E_NETDEV_STAT(rx_dropped),
58 I40E_NETDEV_STAT(tx_dropped),
59 I40E_NETDEV_STAT(multicast),
60 I40E_NETDEV_STAT(collisions),
61 I40E_NETDEV_STAT(rx_length_errors),
62 I40E_NETDEV_STAT(rx_crc_errors),
65 static const struct i40e_stats i40e_gstrings_misc_stats[] = {
66 I40E_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
67 I40E_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
68 I40E_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
71 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
72 struct ethtool_rxnfc *cmd);
74 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
75 * but they are separate. This device supports Virtualization, and
76 * as such might have several netdevs supporting VMDq and FCoE going
77 * through a single port. The NETDEV_STATs are for individual netdevs
78 * seen at the top of the stack, and the PF_STATs are for the physical
79 * function at the bottom of the stack hosting those netdevs.
81 * The PF_STATs are appended to the netdev stats only when ethtool -S
82 * is queried on the base PF netdev, not on the VMDq or FCoE netdev.
84 static struct i40e_stats i40e_gstrings_stats[] = {
85 I40E_PF_STAT("rx_bytes", stats.eth.rx_bytes),
86 I40E_PF_STAT("tx_bytes", stats.eth.tx_bytes),
87 I40E_PF_STAT("tx_errors", stats.eth.tx_errors),
88 I40E_PF_STAT("rx_dropped", stats.eth.rx_discards),
89 I40E_PF_STAT("tx_dropped", stats.eth.tx_discards),
90 I40E_PF_STAT("tx_dropped_link_down", stats.tx_dropped_link_down),
91 I40E_PF_STAT("crc_errors", stats.crc_errors),
92 I40E_PF_STAT("illegal_bytes", stats.illegal_bytes),
93 I40E_PF_STAT("mac_local_faults", stats.mac_local_faults),
94 I40E_PF_STAT("mac_remote_faults", stats.mac_remote_faults),
95 I40E_PF_STAT("tx_timeout", tx_timeout_count),
96 I40E_PF_STAT("rx_length_errors", stats.rx_length_errors),
97 I40E_PF_STAT("link_xon_rx", stats.link_xon_rx),
98 I40E_PF_STAT("link_xoff_rx", stats.link_xoff_rx),
99 I40E_PF_STAT("link_xon_tx", stats.link_xon_tx),
100 I40E_PF_STAT("link_xoff_tx", stats.link_xoff_tx),
101 I40E_PF_STAT("rx_size_64", stats.rx_size_64),
102 I40E_PF_STAT("rx_size_127", stats.rx_size_127),
103 I40E_PF_STAT("rx_size_255", stats.rx_size_255),
104 I40E_PF_STAT("rx_size_511", stats.rx_size_511),
105 I40E_PF_STAT("rx_size_1023", stats.rx_size_1023),
106 I40E_PF_STAT("rx_size_1522", stats.rx_size_1522),
107 I40E_PF_STAT("rx_size_big", stats.rx_size_big),
108 I40E_PF_STAT("tx_size_64", stats.tx_size_64),
109 I40E_PF_STAT("tx_size_127", stats.tx_size_127),
110 I40E_PF_STAT("tx_size_255", stats.tx_size_255),
111 I40E_PF_STAT("tx_size_511", stats.tx_size_511),
112 I40E_PF_STAT("tx_size_1023", stats.tx_size_1023),
113 I40E_PF_STAT("tx_size_1522", stats.tx_size_1522),
114 I40E_PF_STAT("tx_size_big", stats.tx_size_big),
115 I40E_PF_STAT("rx_undersize", stats.rx_undersize),
116 I40E_PF_STAT("rx_fragments", stats.rx_fragments),
117 I40E_PF_STAT("rx_oversize", stats.rx_oversize),
118 I40E_PF_STAT("rx_jabber", stats.rx_jabber),
119 I40E_PF_STAT("VF_admin_queue_requests", vf_aq_requests),
120 I40E_PF_STAT("rx_hwtstamp_cleared", rx_hwtstamp_cleared),
122 I40E_PF_STAT("tx_lpi_status", stats.tx_lpi_status),
123 I40E_PF_STAT("rx_lpi_status", stats.rx_lpi_status),
124 I40E_PF_STAT("tx_lpi_count", stats.tx_lpi_count),
125 I40E_PF_STAT("rx_lpi_count", stats.rx_lpi_count),
128 #define I40E_QUEUE_STATS_LEN(n) \
129 (((struct i40e_netdev_priv *)netdev_priv((n)))->vsi->num_queue_pairs \
130 * 2 /* Tx and Rx together */ \
131 * (sizeof(struct i40e_queue_stats) / sizeof(u64)))
132 #define I40E_GLOBAL_STATS_LEN ARRAY_SIZE(i40e_gstrings_stats)
133 #define I40E_NETDEV_STATS_LEN ARRAY_SIZE(i40e_gstrings_net_stats)
134 #define I40E_MISC_STATS_LEN ARRAY_SIZE(i40e_gstrings_misc_stats)
135 #define I40E_VSI_STATS_LEN(n) (I40E_NETDEV_STATS_LEN + \
136 I40E_MISC_STATS_LEN + \
137 I40E_QUEUE_STATS_LEN((n)))
138 #define I40E_PFC_STATS_LEN ( \
139 (FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_rx) + \
140 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_rx) + \
141 FIELD_SIZEOF(struct i40e_pf, stats.priority_xoff_tx) + \
142 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_tx) + \
143 FIELD_SIZEOF(struct i40e_pf, stats.priority_xon_2_xoff)) \
145 #define I40E_PF_STATS_LEN(n) (I40E_GLOBAL_STATS_LEN + \
146 I40E_PFC_STATS_LEN + \
147 I40E_VSI_STATS_LEN((n)))
149 enum i40e_ethtool_test_id {
150 I40E_ETH_TEST_REG = 0,
151 I40E_ETH_TEST_EEPROM,
153 I40E_ETH_TEST_LOOPBACK,
157 static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
158 "Register test (offline)",
159 "Eeprom test (offline)",
160 "Interrupt test (offline)",
161 "Loopback test (offline)",
162 "Link test (on/offline)"
165 #define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
168 * i40e_get_settings - Get Link Speed and Duplex settings
169 * @netdev: network interface device structure
170 * @ecmd: ethtool command
172 * Reports speed/duplex settings based on media_type
174 static int i40e_get_settings(struct net_device *netdev,
175 struct ethtool_cmd *ecmd)
177 struct i40e_netdev_priv *np = netdev_priv(netdev);
178 struct i40e_pf *pf = np->vsi->back;
179 struct i40e_hw *hw = &pf->hw;
180 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
181 bool link_up = hw_link_info->link_info & I40E_AQ_LINK_UP;
182 u32 link_speed = hw_link_info->link_speed;
184 /* hardware is either in 40G mode or 10G mode
185 * NOTE: this section initializes supported and advertising
187 switch (hw_link_info->phy_type) {
188 case I40E_PHY_TYPE_40GBASE_CR4:
189 case I40E_PHY_TYPE_40GBASE_CR4_CU:
190 ecmd->supported = SUPPORTED_40000baseCR4_Full;
191 ecmd->advertising = ADVERTISED_40000baseCR4_Full;
193 case I40E_PHY_TYPE_40GBASE_KR4:
194 ecmd->supported = SUPPORTED_40000baseKR4_Full;
195 ecmd->advertising = ADVERTISED_40000baseKR4_Full;
197 case I40E_PHY_TYPE_40GBASE_SR4:
198 ecmd->supported = SUPPORTED_40000baseSR4_Full;
199 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
201 case I40E_PHY_TYPE_40GBASE_LR4:
202 ecmd->supported = SUPPORTED_40000baseLR4_Full;
203 ecmd->advertising = ADVERTISED_40000baseLR4_Full;
205 case I40E_PHY_TYPE_10GBASE_KX4:
206 ecmd->supported = SUPPORTED_10000baseKX4_Full;
207 ecmd->advertising = ADVERTISED_10000baseKX4_Full;
209 case I40E_PHY_TYPE_10GBASE_KR:
210 ecmd->supported = SUPPORTED_10000baseKR_Full;
211 ecmd->advertising = ADVERTISED_10000baseKR_Full;
214 if (i40e_is_40G_device(hw->device_id)) {
215 ecmd->supported = SUPPORTED_40000baseSR4_Full;
216 ecmd->advertising = ADVERTISED_40000baseSR4_Full;
218 ecmd->supported = SUPPORTED_10000baseT_Full;
219 ecmd->advertising = ADVERTISED_10000baseT_Full;
224 ecmd->supported |= SUPPORTED_Autoneg;
225 ecmd->advertising |= ADVERTISED_Autoneg;
226 ecmd->autoneg = ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
227 AUTONEG_ENABLE : AUTONEG_DISABLE);
229 switch (hw->phy.media_type) {
230 case I40E_MEDIA_TYPE_BACKPLANE:
231 ecmd->supported |= SUPPORTED_Backplane;
232 ecmd->advertising |= ADVERTISED_Backplane;
233 ecmd->port = PORT_NONE;
235 case I40E_MEDIA_TYPE_BASET:
236 ecmd->supported |= SUPPORTED_TP;
237 ecmd->advertising |= ADVERTISED_TP;
238 ecmd->port = PORT_TP;
240 case I40E_MEDIA_TYPE_DA:
241 case I40E_MEDIA_TYPE_CX4:
242 ecmd->supported |= SUPPORTED_FIBRE;
243 ecmd->advertising |= ADVERTISED_FIBRE;
244 ecmd->port = PORT_DA;
246 case I40E_MEDIA_TYPE_FIBER:
247 ecmd->supported |= SUPPORTED_FIBRE;
248 ecmd->advertising |= ADVERTISED_FIBRE;
249 ecmd->port = PORT_FIBRE;
251 case I40E_MEDIA_TYPE_UNKNOWN:
253 ecmd->port = PORT_OTHER;
257 ecmd->transceiver = XCVR_EXTERNAL;
260 switch (link_speed) {
261 case I40E_LINK_SPEED_40GB:
262 /* need a SPEED_40000 in ethtool.h */
263 ethtool_cmd_speed_set(ecmd, 40000);
265 case I40E_LINK_SPEED_10GB:
266 ethtool_cmd_speed_set(ecmd, SPEED_10000);
271 ecmd->duplex = DUPLEX_FULL;
273 ethtool_cmd_speed_set(ecmd, SPEED_UNKNOWN);
274 ecmd->duplex = DUPLEX_UNKNOWN;
281 * i40e_get_pauseparam - Get Flow Control status
282 * Return tx/rx-pause status
284 static void i40e_get_pauseparam(struct net_device *netdev,
285 struct ethtool_pauseparam *pause)
287 struct i40e_netdev_priv *np = netdev_priv(netdev);
288 struct i40e_pf *pf = np->vsi->back;
289 struct i40e_hw *hw = &pf->hw;
290 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
293 ((hw_link_info->an_info & I40E_AQ_AN_COMPLETED) ?
294 AUTONEG_ENABLE : AUTONEG_DISABLE);
296 if (hw->fc.current_mode == I40E_FC_RX_PAUSE) {
298 } else if (hw->fc.current_mode == I40E_FC_TX_PAUSE) {
300 } else if (hw->fc.current_mode == I40E_FC_FULL) {
306 static u32 i40e_get_msglevel(struct net_device *netdev)
308 struct i40e_netdev_priv *np = netdev_priv(netdev);
309 struct i40e_pf *pf = np->vsi->back;
311 return pf->msg_enable;
314 static void i40e_set_msglevel(struct net_device *netdev, u32 data)
316 struct i40e_netdev_priv *np = netdev_priv(netdev);
317 struct i40e_pf *pf = np->vsi->back;
319 if (I40E_DEBUG_USER & data)
320 pf->hw.debug_mask = data;
321 pf->msg_enable = data;
324 static int i40e_get_regs_len(struct net_device *netdev)
329 for (i = 0; i40e_reg_list[i].offset != 0; i++)
330 reg_count += i40e_reg_list[i].elements;
332 return reg_count * sizeof(u32);
335 static void i40e_get_regs(struct net_device *netdev, struct ethtool_regs *regs,
338 struct i40e_netdev_priv *np = netdev_priv(netdev);
339 struct i40e_pf *pf = np->vsi->back;
340 struct i40e_hw *hw = &pf->hw;
345 /* Tell ethtool which driver-version-specific regs output we have.
347 * At some point, if we have ethtool doing special formatting of
348 * this data, it will rely on this version number to know how to
349 * interpret things. Hence, this needs to be updated if/when the
350 * diags register table is changed.
354 /* loop through the diags reg table for what to print */
356 for (i = 0; i40e_reg_list[i].offset != 0; i++) {
357 for (j = 0; j < i40e_reg_list[i].elements; j++) {
358 reg = i40e_reg_list[i].offset
359 + (j * i40e_reg_list[i].stride);
360 reg_buf[ri++] = rd32(hw, reg);
366 static int i40e_get_eeprom(struct net_device *netdev,
367 struct ethtool_eeprom *eeprom, u8 *bytes)
369 struct i40e_netdev_priv *np = netdev_priv(netdev);
370 struct i40e_hw *hw = &np->vsi->back->hw;
371 struct i40e_pf *pf = np->vsi->back;
372 int ret_val = 0, len;
376 #define I40E_NVM_SECTOR_SIZE 4096
377 if (eeprom->len == 0)
380 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
382 eeprom_buff = kzalloc(eeprom->len, GFP_KERNEL);
386 ret_val = i40e_acquire_nvm(hw, I40E_RESOURCE_READ);
388 dev_info(&pf->pdev->dev,
389 "Failed Acquiring NVM resource for read err=%d status=0x%x\n",
390 ret_val, hw->aq.asq_last_status);
394 sectors = eeprom->len / I40E_NVM_SECTOR_SIZE;
395 sectors += (eeprom->len % I40E_NVM_SECTOR_SIZE) ? 1 : 0;
396 len = I40E_NVM_SECTOR_SIZE;
398 for (i = 0; i < sectors; i++) {
399 if (i == (sectors - 1)) {
400 len = eeprom->len - (I40E_NVM_SECTOR_SIZE * i);
403 ret_val = i40e_aq_read_nvm(hw, 0x0,
404 eeprom->offset + (I40E_NVM_SECTOR_SIZE * i),
406 eeprom_buff + (I40E_NVM_SECTOR_SIZE * i),
409 dev_info(&pf->pdev->dev,
410 "read NVM failed err=%d status=0x%x\n",
411 ret_val, hw->aq.asq_last_status);
417 i40e_release_nvm(hw);
418 memcpy(bytes, eeprom_buff, eeprom->len);
424 static int i40e_get_eeprom_len(struct net_device *netdev)
426 struct i40e_netdev_priv *np = netdev_priv(netdev);
427 struct i40e_hw *hw = &np->vsi->back->hw;
430 val = (rd32(hw, I40E_GLPCI_LBARCTRL)
431 & I40E_GLPCI_LBARCTRL_FL_SIZE_MASK)
432 >> I40E_GLPCI_LBARCTRL_FL_SIZE_SHIFT;
433 /* register returns value in power of 2, 64Kbyte chunks. */
434 val = (64 * 1024) * (1 << val);
438 static void i40e_get_drvinfo(struct net_device *netdev,
439 struct ethtool_drvinfo *drvinfo)
441 struct i40e_netdev_priv *np = netdev_priv(netdev);
442 struct i40e_vsi *vsi = np->vsi;
443 struct i40e_pf *pf = vsi->back;
445 strlcpy(drvinfo->driver, i40e_driver_name, sizeof(drvinfo->driver));
446 strlcpy(drvinfo->version, i40e_driver_version_str,
447 sizeof(drvinfo->version));
448 strlcpy(drvinfo->fw_version, i40e_fw_version_str(&pf->hw),
449 sizeof(drvinfo->fw_version));
450 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
451 sizeof(drvinfo->bus_info));
454 static void i40e_get_ringparam(struct net_device *netdev,
455 struct ethtool_ringparam *ring)
457 struct i40e_netdev_priv *np = netdev_priv(netdev);
458 struct i40e_pf *pf = np->vsi->back;
459 struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
461 ring->rx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
462 ring->tx_max_pending = I40E_MAX_NUM_DESCRIPTORS;
463 ring->rx_mini_max_pending = 0;
464 ring->rx_jumbo_max_pending = 0;
465 ring->rx_pending = vsi->rx_rings[0]->count;
466 ring->tx_pending = vsi->tx_rings[0]->count;
467 ring->rx_mini_pending = 0;
468 ring->rx_jumbo_pending = 0;
471 static int i40e_set_ringparam(struct net_device *netdev,
472 struct ethtool_ringparam *ring)
474 struct i40e_ring *tx_rings = NULL, *rx_rings = NULL;
475 struct i40e_netdev_priv *np = netdev_priv(netdev);
476 struct i40e_vsi *vsi = np->vsi;
477 struct i40e_pf *pf = vsi->back;
478 u32 new_rx_count, new_tx_count;
481 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
484 if (ring->tx_pending > I40E_MAX_NUM_DESCRIPTORS ||
485 ring->tx_pending < I40E_MIN_NUM_DESCRIPTORS ||
486 ring->rx_pending > I40E_MAX_NUM_DESCRIPTORS ||
487 ring->rx_pending < I40E_MIN_NUM_DESCRIPTORS) {
489 "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d]\n",
490 ring->tx_pending, ring->rx_pending,
491 I40E_MIN_NUM_DESCRIPTORS, I40E_MAX_NUM_DESCRIPTORS);
495 new_tx_count = ALIGN(ring->tx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
496 new_rx_count = ALIGN(ring->rx_pending, I40E_REQ_DESCRIPTOR_MULTIPLE);
498 /* if nothing to do return success */
499 if ((new_tx_count == vsi->tx_rings[0]->count) &&
500 (new_rx_count == vsi->rx_rings[0]->count))
503 while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
504 usleep_range(1000, 2000);
506 if (!netif_running(vsi->netdev)) {
507 /* simple case - set for the next time the netdev is started */
508 for (i = 0; i < vsi->num_queue_pairs; i++) {
509 vsi->tx_rings[i]->count = new_tx_count;
510 vsi->rx_rings[i]->count = new_rx_count;
515 /* We can't just free everything and then setup again,
516 * because the ISRs in MSI-X mode get passed pointers
517 * to the Tx and Rx ring structs.
520 /* alloc updated Tx resources */
521 if (new_tx_count != vsi->tx_rings[0]->count) {
523 "Changing Tx descriptor count from %d to %d.\n",
524 vsi->tx_rings[0]->count, new_tx_count);
525 tx_rings = kcalloc(vsi->alloc_queue_pairs,
526 sizeof(struct i40e_ring), GFP_KERNEL);
532 for (i = 0; i < vsi->num_queue_pairs; i++) {
533 /* clone ring and setup updated count */
534 tx_rings[i] = *vsi->tx_rings[i];
535 tx_rings[i].count = new_tx_count;
536 err = i40e_setup_tx_descriptors(&tx_rings[i]);
540 i40e_free_tx_resources(&tx_rings[i]);
550 /* alloc updated Rx resources */
551 if (new_rx_count != vsi->rx_rings[0]->count) {
553 "Changing Rx descriptor count from %d to %d\n",
554 vsi->rx_rings[0]->count, new_rx_count);
555 rx_rings = kcalloc(vsi->alloc_queue_pairs,
556 sizeof(struct i40e_ring), GFP_KERNEL);
562 for (i = 0; i < vsi->num_queue_pairs; i++) {
563 /* clone ring and setup updated count */
564 rx_rings[i] = *vsi->rx_rings[i];
565 rx_rings[i].count = new_rx_count;
566 err = i40e_setup_rx_descriptors(&rx_rings[i]);
570 i40e_free_rx_resources(&rx_rings[i]);
580 /* Bring interface down, copy in the new ring info,
581 * then restore the interface
586 for (i = 0; i < vsi->num_queue_pairs; i++) {
587 i40e_free_tx_resources(vsi->tx_rings[i]);
588 *vsi->tx_rings[i] = tx_rings[i];
595 for (i = 0; i < vsi->num_queue_pairs; i++) {
596 i40e_free_rx_resources(vsi->rx_rings[i]);
597 *vsi->rx_rings[i] = rx_rings[i];
606 /* error cleanup if the Rx allocations failed after getting Tx */
608 for (i = 0; i < vsi->num_queue_pairs; i++)
609 i40e_free_tx_resources(&tx_rings[i]);
615 clear_bit(__I40E_CONFIG_BUSY, &pf->state);
620 static int i40e_get_sset_count(struct net_device *netdev, int sset)
622 struct i40e_netdev_priv *np = netdev_priv(netdev);
623 struct i40e_vsi *vsi = np->vsi;
624 struct i40e_pf *pf = vsi->back;
628 return I40E_TEST_LEN;
630 if (vsi == pf->vsi[pf->lan_vsi])
631 return I40E_PF_STATS_LEN(netdev);
633 return I40E_VSI_STATS_LEN(netdev);
639 static void i40e_get_ethtool_stats(struct net_device *netdev,
640 struct ethtool_stats *stats, u64 *data)
642 struct i40e_netdev_priv *np = netdev_priv(netdev);
643 struct i40e_ring *tx_ring, *rx_ring;
644 struct i40e_vsi *vsi = np->vsi;
645 struct i40e_pf *pf = vsi->back;
649 struct rtnl_link_stats64 *net_stats = i40e_get_vsi_stats_struct(vsi);
652 i40e_update_stats(vsi);
654 for (j = 0; j < I40E_NETDEV_STATS_LEN; j++) {
655 p = (char *)net_stats + i40e_gstrings_net_stats[j].stat_offset;
656 data[i++] = (i40e_gstrings_net_stats[j].sizeof_stat ==
657 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
659 for (j = 0; j < I40E_MISC_STATS_LEN; j++) {
660 p = (char *)vsi + i40e_gstrings_misc_stats[j].stat_offset;
661 data[i++] = (i40e_gstrings_misc_stats[j].sizeof_stat ==
662 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
665 for (j = 0; j < vsi->num_queue_pairs; j++) {
666 tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
671 /* process Tx ring statistics */
673 start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
674 data[i] = tx_ring->stats.packets;
675 data[i + 1] = tx_ring->stats.bytes;
676 } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
679 /* Rx ring is the 2nd half of the queue pair */
680 rx_ring = &tx_ring[1];
682 start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
683 data[i] = rx_ring->stats.packets;
684 data[i + 1] = rx_ring->stats.bytes;
685 } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
689 if (vsi == pf->vsi[pf->lan_vsi]) {
690 for (j = 0; j < I40E_GLOBAL_STATS_LEN; j++) {
691 p = (char *)pf + i40e_gstrings_stats[j].stat_offset;
692 data[i++] = (i40e_gstrings_stats[j].sizeof_stat ==
693 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
695 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
696 data[i++] = pf->stats.priority_xon_tx[j];
697 data[i++] = pf->stats.priority_xoff_tx[j];
699 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++) {
700 data[i++] = pf->stats.priority_xon_rx[j];
701 data[i++] = pf->stats.priority_xoff_rx[j];
703 for (j = 0; j < I40E_MAX_USER_PRIORITY; j++)
704 data[i++] = pf->stats.priority_xon_2_xoff[j];
708 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
711 struct i40e_netdev_priv *np = netdev_priv(netdev);
712 struct i40e_vsi *vsi = np->vsi;
713 struct i40e_pf *pf = vsi->back;
714 char *p = (char *)data;
719 for (i = 0; i < I40E_TEST_LEN; i++) {
720 memcpy(data, i40e_gstrings_test[i], ETH_GSTRING_LEN);
721 data += ETH_GSTRING_LEN;
725 for (i = 0; i < I40E_NETDEV_STATS_LEN; i++) {
726 snprintf(p, ETH_GSTRING_LEN, "%s",
727 i40e_gstrings_net_stats[i].stat_string);
728 p += ETH_GSTRING_LEN;
730 for (i = 0; i < I40E_MISC_STATS_LEN; i++) {
731 snprintf(p, ETH_GSTRING_LEN, "%s",
732 i40e_gstrings_misc_stats[i].stat_string);
733 p += ETH_GSTRING_LEN;
735 for (i = 0; i < vsi->num_queue_pairs; i++) {
736 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_packets", i);
737 p += ETH_GSTRING_LEN;
738 snprintf(p, ETH_GSTRING_LEN, "tx-%u.tx_bytes", i);
739 p += ETH_GSTRING_LEN;
740 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_packets", i);
741 p += ETH_GSTRING_LEN;
742 snprintf(p, ETH_GSTRING_LEN, "rx-%u.rx_bytes", i);
743 p += ETH_GSTRING_LEN;
745 if (vsi == pf->vsi[pf->lan_vsi]) {
746 for (i = 0; i < I40E_GLOBAL_STATS_LEN; i++) {
747 snprintf(p, ETH_GSTRING_LEN, "port.%s",
748 i40e_gstrings_stats[i].stat_string);
749 p += ETH_GSTRING_LEN;
751 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
752 snprintf(p, ETH_GSTRING_LEN,
753 "port.tx_priority_%u_xon", i);
754 p += ETH_GSTRING_LEN;
755 snprintf(p, ETH_GSTRING_LEN,
756 "port.tx_priority_%u_xoff", i);
757 p += ETH_GSTRING_LEN;
759 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
760 snprintf(p, ETH_GSTRING_LEN,
761 "port.rx_priority_%u_xon", i);
762 p += ETH_GSTRING_LEN;
763 snprintf(p, ETH_GSTRING_LEN,
764 "port.rx_priority_%u_xoff", i);
765 p += ETH_GSTRING_LEN;
767 for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
768 snprintf(p, ETH_GSTRING_LEN,
769 "port.rx_priority_%u_xon_2_xoff", i);
770 p += ETH_GSTRING_LEN;
773 /* BUG_ON(p - data != I40E_STATS_LEN * ETH_GSTRING_LEN); */
778 static int i40e_get_ts_info(struct net_device *dev,
779 struct ethtool_ts_info *info)
781 struct i40e_pf *pf = i40e_netdev_to_pf(dev);
783 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
784 SOF_TIMESTAMPING_RX_SOFTWARE |
785 SOF_TIMESTAMPING_SOFTWARE |
786 SOF_TIMESTAMPING_TX_HARDWARE |
787 SOF_TIMESTAMPING_RX_HARDWARE |
788 SOF_TIMESTAMPING_RAW_HARDWARE;
791 info->phc_index = ptp_clock_index(pf->ptp_clock);
793 info->phc_index = -1;
795 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
797 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
798 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
799 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
800 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
801 (1 << HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
802 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
803 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
804 (1 << HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
805 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
806 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
807 (1 << HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ) |
808 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
813 static int i40e_link_test(struct net_device *netdev, u64 *data)
815 struct i40e_netdev_priv *np = netdev_priv(netdev);
816 struct i40e_pf *pf = np->vsi->back;
818 netif_info(pf, hw, netdev, "link test\n");
819 if (i40e_get_link_status(&pf->hw))
827 static int i40e_reg_test(struct net_device *netdev, u64 *data)
829 struct i40e_netdev_priv *np = netdev_priv(netdev);
830 struct i40e_pf *pf = np->vsi->back;
832 netif_info(pf, hw, netdev, "register test\n");
833 *data = i40e_diag_reg_test(&pf->hw);
838 static int i40e_eeprom_test(struct net_device *netdev, u64 *data)
840 struct i40e_netdev_priv *np = netdev_priv(netdev);
841 struct i40e_pf *pf = np->vsi->back;
843 netif_info(pf, hw, netdev, "eeprom test\n");
844 *data = i40e_diag_eeprom_test(&pf->hw);
849 static int i40e_intr_test(struct net_device *netdev, u64 *data)
851 struct i40e_netdev_priv *np = netdev_priv(netdev);
852 struct i40e_pf *pf = np->vsi->back;
853 u16 swc_old = pf->sw_int_count;
855 netif_info(pf, hw, netdev, "interrupt test\n");
856 wr32(&pf->hw, I40E_PFINT_DYN_CTL0,
857 (I40E_PFINT_DYN_CTL0_INTENA_MASK |
858 I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
859 usleep_range(1000, 2000);
860 *data = (swc_old == pf->sw_int_count);
865 static int i40e_loopback_test(struct net_device *netdev, u64 *data)
867 struct i40e_netdev_priv *np = netdev_priv(netdev);
868 struct i40e_pf *pf = np->vsi->back;
870 netif_info(pf, hw, netdev, "loopback test not implemented\n");
876 static void i40e_diag_test(struct net_device *netdev,
877 struct ethtool_test *eth_test, u64 *data)
879 struct i40e_netdev_priv *np = netdev_priv(netdev);
880 struct i40e_pf *pf = np->vsi->back;
882 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
884 netif_info(pf, drv, netdev, "offline testing starting\n");
886 set_bit(__I40E_TESTING, &pf->state);
888 /* Link test performed before hardware reset
889 * so autoneg doesn't interfere with test result
891 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
892 eth_test->flags |= ETH_TEST_FL_FAILED;
894 if (i40e_eeprom_test(netdev, &data[I40E_ETH_TEST_EEPROM]))
895 eth_test->flags |= ETH_TEST_FL_FAILED;
897 if (i40e_intr_test(netdev, &data[I40E_ETH_TEST_INTR]))
898 eth_test->flags |= ETH_TEST_FL_FAILED;
900 if (i40e_loopback_test(netdev, &data[I40E_ETH_TEST_LOOPBACK]))
901 eth_test->flags |= ETH_TEST_FL_FAILED;
903 /* run reg test last, a reset is required after it */
904 if (i40e_reg_test(netdev, &data[I40E_ETH_TEST_REG]))
905 eth_test->flags |= ETH_TEST_FL_FAILED;
907 clear_bit(__I40E_TESTING, &pf->state);
908 i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
911 netif_info(pf, drv, netdev, "online testing starting\n");
913 if (i40e_link_test(netdev, &data[I40E_ETH_TEST_LINK]))
914 eth_test->flags |= ETH_TEST_FL_FAILED;
916 /* Offline only tests, not run in online; pass by default */
917 data[I40E_ETH_TEST_REG] = 0;
918 data[I40E_ETH_TEST_EEPROM] = 0;
919 data[I40E_ETH_TEST_INTR] = 0;
920 data[I40E_ETH_TEST_LOOPBACK] = 0;
923 netif_info(pf, drv, netdev, "testing finished\n");
926 static void i40e_get_wol(struct net_device *netdev,
927 struct ethtool_wolinfo *wol)
929 struct i40e_netdev_priv *np = netdev_priv(netdev);
930 struct i40e_pf *pf = np->vsi->back;
931 struct i40e_hw *hw = &pf->hw;
934 /* NVM bit on means WoL disabled for the port */
935 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
936 if ((1 << hw->port) & wol_nvm_bits) {
940 wol->supported = WAKE_MAGIC;
941 wol->wolopts = (pf->wol_en ? WAKE_MAGIC : 0);
945 static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
947 struct i40e_netdev_priv *np = netdev_priv(netdev);
948 struct i40e_pf *pf = np->vsi->back;
949 struct i40e_hw *hw = &pf->hw;
952 /* NVM bit on means WoL disabled for the port */
953 i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
954 if (((1 << hw->port) & wol_nvm_bits))
957 /* only magic packet is supported */
958 if (wol->wolopts && (wol->wolopts != WAKE_MAGIC))
961 /* is this a new value? */
962 if (pf->wol_en != !!wol->wolopts) {
963 pf->wol_en = !!wol->wolopts;
964 device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
970 static int i40e_nway_reset(struct net_device *netdev)
972 /* restart autonegotiation */
973 struct i40e_netdev_priv *np = netdev_priv(netdev);
974 struct i40e_pf *pf = np->vsi->back;
975 struct i40e_hw *hw = &pf->hw;
978 ret = i40e_aq_set_link_restart_an(hw, NULL);
980 netdev_info(netdev, "link restart failed, aq_err=%d\n",
981 pf->hw.aq.asq_last_status);
988 static int i40e_set_phys_id(struct net_device *netdev,
989 enum ethtool_phys_id_state state)
991 struct i40e_netdev_priv *np = netdev_priv(netdev);
992 struct i40e_pf *pf = np->vsi->back;
993 struct i40e_hw *hw = &pf->hw;
997 case ETHTOOL_ID_ACTIVE:
998 pf->led_status = i40e_led_get(hw);
1001 i40e_led_set(hw, 0xF, false);
1003 case ETHTOOL_ID_OFF:
1004 i40e_led_set(hw, 0x0, false);
1006 case ETHTOOL_ID_INACTIVE:
1007 i40e_led_set(hw, pf->led_status, false);
1014 /* NOTE: i40e hardware uses a conversion factor of 2 for Interrupt
1015 * Throttle Rate (ITR) ie. ITR(1) = 2us ITR(10) = 20 us, and also
1016 * 125us (8000 interrupts per second) == ITR(62)
1019 static int i40e_get_coalesce(struct net_device *netdev,
1020 struct ethtool_coalesce *ec)
1022 struct i40e_netdev_priv *np = netdev_priv(netdev);
1023 struct i40e_vsi *vsi = np->vsi;
1025 ec->tx_max_coalesced_frames_irq = vsi->work_limit;
1026 ec->rx_max_coalesced_frames_irq = vsi->work_limit;
1028 if (ITR_IS_DYNAMIC(vsi->rx_itr_setting))
1029 ec->use_adaptive_rx_coalesce = 1;
1031 if (ITR_IS_DYNAMIC(vsi->tx_itr_setting))
1032 ec->use_adaptive_tx_coalesce = 1;
1034 ec->rx_coalesce_usecs = vsi->rx_itr_setting & ~I40E_ITR_DYNAMIC;
1035 ec->tx_coalesce_usecs = vsi->tx_itr_setting & ~I40E_ITR_DYNAMIC;
1040 static int i40e_set_coalesce(struct net_device *netdev,
1041 struct ethtool_coalesce *ec)
1043 struct i40e_netdev_priv *np = netdev_priv(netdev);
1044 struct i40e_q_vector *q_vector;
1045 struct i40e_vsi *vsi = np->vsi;
1046 struct i40e_pf *pf = vsi->back;
1047 struct i40e_hw *hw = &pf->hw;
1051 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
1052 vsi->work_limit = ec->tx_max_coalesced_frames_irq;
1054 if ((ec->rx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1055 (ec->rx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
1056 vsi->rx_itr_setting = ec->rx_coalesce_usecs;
1060 if ((ec->tx_coalesce_usecs >= (I40E_MIN_ITR << 1)) &&
1061 (ec->tx_coalesce_usecs <= (I40E_MAX_ITR << 1)))
1062 vsi->tx_itr_setting = ec->tx_coalesce_usecs;
1066 if (ec->use_adaptive_rx_coalesce)
1067 vsi->rx_itr_setting |= I40E_ITR_DYNAMIC;
1069 vsi->rx_itr_setting &= ~I40E_ITR_DYNAMIC;
1071 if (ec->use_adaptive_tx_coalesce)
1072 vsi->tx_itr_setting |= I40E_ITR_DYNAMIC;
1074 vsi->tx_itr_setting &= ~I40E_ITR_DYNAMIC;
1076 vector = vsi->base_vector;
1077 for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
1078 q_vector = vsi->q_vectors[i];
1079 q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
1080 wr32(hw, I40E_PFINT_ITRN(0, vector - 1), q_vector->rx.itr);
1081 q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
1082 wr32(hw, I40E_PFINT_ITRN(1, vector - 1), q_vector->tx.itr);
1090 * i40e_get_rss_hash_opts - Get RSS hash Input Set for each flow type
1091 * @pf: pointer to the physical function struct
1092 * @cmd: ethtool rxnfc command
1094 * Returns Success if the flow is supported, else Invalid Input.
1096 static int i40e_get_rss_hash_opts(struct i40e_pf *pf, struct ethtool_rxnfc *cmd)
1100 /* Report default options for RSS on i40e */
1101 switch (cmd->flow_type) {
1104 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1105 /* fall through to add IP fields */
1107 case AH_ESP_V4_FLOW:
1111 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1115 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1116 /* fall through to add IP fields */
1118 case AH_ESP_V6_FLOW:
1122 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1132 * i40e_get_ethtool_fdir_all - Populates the rule count of a command
1133 * @pf: Pointer to the physical function struct
1134 * @cmd: The command to get or set Rx flow classification rules
1135 * @rule_locs: Array of used rule locations
1137 * This function populates both the total and actual rule count of
1138 * the ethtool flow classification command
1140 * Returns 0 on success or -EMSGSIZE if entry not found
1142 static int i40e_get_ethtool_fdir_all(struct i40e_pf *pf,
1143 struct ethtool_rxnfc *cmd,
1146 struct i40e_fdir_filter *rule;
1147 struct hlist_node *node2;
1150 /* report total rule count */
1151 cmd->data = i40e_get_fd_cnt_all(pf);
1153 hlist_for_each_entry_safe(rule, node2,
1154 &pf->fdir_filter_list, fdir_node) {
1155 if (cnt == cmd->rule_cnt)
1158 rule_locs[cnt] = rule->fd_id;
1162 cmd->rule_cnt = cnt;
1168 * i40e_get_ethtool_fdir_entry - Look up a filter based on Rx flow
1169 * @pf: Pointer to the physical function struct
1170 * @cmd: The command to get or set Rx flow classification rules
1172 * This function looks up a filter based on the Rx flow classification
1173 * command and fills the flow spec info for it if found
1175 * Returns 0 on success or -EINVAL if filter not found
1177 static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
1178 struct ethtool_rxnfc *cmd)
1180 struct ethtool_rx_flow_spec *fsp =
1181 (struct ethtool_rx_flow_spec *)&cmd->fs;
1182 struct i40e_fdir_filter *rule = NULL;
1183 struct hlist_node *node2;
1185 hlist_for_each_entry_safe(rule, node2,
1186 &pf->fdir_filter_list, fdir_node) {
1187 if (fsp->location <= rule->fd_id)
1191 if (!rule || fsp->location != rule->fd_id)
1194 fsp->flow_type = rule->flow_type;
1195 if (fsp->flow_type == IP_USER_FLOW) {
1196 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4;
1197 fsp->h_u.usr_ip4_spec.proto = 0;
1198 fsp->m_u.usr_ip4_spec.proto = 0;
1201 fsp->h_u.tcp_ip4_spec.psrc = rule->src_port;
1202 fsp->h_u.tcp_ip4_spec.pdst = rule->dst_port;
1203 fsp->h_u.tcp_ip4_spec.ip4src = rule->src_ip[0];
1204 fsp->h_u.tcp_ip4_spec.ip4dst = rule->dst_ip[0];
1205 fsp->ring_cookie = rule->q_index;
1211 * i40e_get_rxnfc - command to get RX flow classification rules
1212 * @netdev: network interface device structure
1213 * @cmd: ethtool rxnfc command
1215 * Returns Success if the command is supported.
1217 static int i40e_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
1220 struct i40e_netdev_priv *np = netdev_priv(netdev);
1221 struct i40e_vsi *vsi = np->vsi;
1222 struct i40e_pf *pf = vsi->back;
1223 int ret = -EOPNOTSUPP;
1226 case ETHTOOL_GRXRINGS:
1227 cmd->data = vsi->alloc_queue_pairs;
1231 ret = i40e_get_rss_hash_opts(pf, cmd);
1233 case ETHTOOL_GRXCLSRLCNT:
1234 cmd->rule_cnt = pf->fdir_pf_active_filters;
1235 /* report total rule count */
1236 cmd->data = i40e_get_fd_cnt_all(pf);
1239 case ETHTOOL_GRXCLSRULE:
1240 ret = i40e_get_ethtool_fdir_entry(pf, cmd);
1242 case ETHTOOL_GRXCLSRLALL:
1243 ret = i40e_get_ethtool_fdir_all(pf, cmd, rule_locs);
1253 * i40e_set_rss_hash_opt - Enable/Disable flow types for RSS hash
1254 * @pf: pointer to the physical function struct
1255 * @cmd: ethtool rxnfc command
1257 * Returns Success if the flow input set is supported.
1259 static int i40e_set_rss_hash_opt(struct i40e_pf *pf, struct ethtool_rxnfc *nfc)
1261 struct i40e_hw *hw = &pf->hw;
1262 u64 hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
1263 ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
1265 /* RSS does not support anything other than hashing
1266 * to queues on src and dst IPs and ports
1268 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1269 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1272 /* We need at least the IP SRC and DEST fields for hashing */
1273 if (!(nfc->data & RXH_IP_SRC) ||
1274 !(nfc->data & RXH_IP_DST))
1277 switch (nfc->flow_type) {
1279 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1281 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1283 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1284 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_TCP);
1291 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1293 hena &= ~((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1295 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1296 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_TCP);
1303 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1305 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1306 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1308 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1309 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |
1310 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4));
1317 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1319 hena &= ~(((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1320 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1322 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1323 hena |= (((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |
1324 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6));
1330 case AH_ESP_V4_FLOW:
1334 if ((nfc->data & RXH_L4_B_0_1) ||
1335 (nfc->data & RXH_L4_B_2_3))
1337 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER);
1339 case AH_ESP_V6_FLOW:
1343 if ((nfc->data & RXH_L4_B_0_1) ||
1344 (nfc->data & RXH_L4_B_2_3))
1346 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER);
1349 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |
1350 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV4);
1353 hena |= ((u64)1 << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |
1354 ((u64)1 << I40E_FILTER_PCTYPE_FRAG_IPV6);
1360 wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
1361 wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
1368 * i40e_match_fdir_input_set - Match a new filter against an existing one
1369 * @rule: The filter already added
1370 * @input: The new filter to comapre against
1372 * Returns true if the two input set match
1374 static bool i40e_match_fdir_input_set(struct i40e_fdir_filter *rule,
1375 struct i40e_fdir_filter *input)
1377 if ((rule->dst_ip[0] != input->dst_ip[0]) ||
1378 (rule->src_ip[0] != input->src_ip[0]) ||
1379 (rule->dst_port != input->dst_port) ||
1380 (rule->src_port != input->src_port))
1386 * i40e_update_ethtool_fdir_entry - Updates the fdir filter entry
1387 * @vsi: Pointer to the targeted VSI
1388 * @input: The filter to update or NULL to indicate deletion
1389 * @sw_idx: Software index to the filter
1390 * @cmd: The command to get or set Rx flow classification rules
1392 * This function updates (or deletes) a Flow Director entry from
1393 * the hlist of the corresponding PF
1395 * Returns 0 on success
1397 static int i40e_update_ethtool_fdir_entry(struct i40e_vsi *vsi,
1398 struct i40e_fdir_filter *input,
1400 struct ethtool_rxnfc *cmd)
1402 struct i40e_fdir_filter *rule, *parent;
1403 struct i40e_pf *pf = vsi->back;
1404 struct hlist_node *node2;
1410 hlist_for_each_entry_safe(rule, node2,
1411 &pf->fdir_filter_list, fdir_node) {
1412 /* hash found, or no matching entry */
1413 if (rule->fd_id >= sw_idx)
1418 /* if there is an old rule occupying our place remove it */
1419 if (rule && (rule->fd_id == sw_idx)) {
1420 if (input && !i40e_match_fdir_input_set(rule, input))
1421 err = i40e_add_del_fdir(vsi, rule, false);
1423 err = i40e_add_del_fdir(vsi, rule, false);
1424 hlist_del(&rule->fdir_node);
1426 pf->fdir_pf_active_filters--;
1429 /* If no input this was a delete, err should be 0 if a rule was
1430 * successfully found and removed from the list else -EINVAL
1435 /* initialize node and set software index */
1436 INIT_HLIST_NODE(&input->fdir_node);
1438 /* add filter to the list */
1440 hlist_add_after(&parent->fdir_node, &input->fdir_node);
1442 hlist_add_head(&input->fdir_node,
1443 &pf->fdir_filter_list);
1446 pf->fdir_pf_active_filters++;
1452 * i40e_del_fdir_entry - Deletes a Flow Director filter entry
1453 * @vsi: Pointer to the targeted VSI
1454 * @cmd: The command to get or set Rx flow classification rules
1456 * The function removes a Flow Director filter entry from the
1457 * hlist of the corresponding PF
1459 * Returns 0 on success
1461 static int i40e_del_fdir_entry(struct i40e_vsi *vsi,
1462 struct ethtool_rxnfc *cmd)
1464 struct ethtool_rx_flow_spec *fsp =
1465 (struct ethtool_rx_flow_spec *)&cmd->fs;
1466 struct i40e_pf *pf = vsi->back;
1469 ret = i40e_update_ethtool_fdir_entry(vsi, NULL, fsp->location, cmd);
1471 i40e_fdir_check_and_reenable(pf);
1476 * i40e_add_fdir_ethtool - Add/Remove Flow Director filters
1477 * @vsi: pointer to the targeted VSI
1478 * @cmd: command to get or set RX flow classification rules
1480 * Add Flow Director filters for a specific flow spec based on their
1481 * protocol. Returns 0 if the filters were successfully added.
1483 static int i40e_add_fdir_ethtool(struct i40e_vsi *vsi,
1484 struct ethtool_rxnfc *cmd)
1486 struct ethtool_rx_flow_spec *fsp;
1487 struct i40e_fdir_filter *input;
1496 if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
1499 if (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)
1502 fsp = (struct ethtool_rx_flow_spec *)&cmd->fs;
1504 if (fsp->location >= (pf->hw.func_caps.fd_filters_best_effort +
1505 pf->hw.func_caps.fd_filters_guaranteed)) {
1509 if (fsp->ring_cookie >= vsi->num_queue_pairs)
1512 input = kzalloc(sizeof(*input), GFP_KERNEL);
1517 input->fd_id = fsp->location;
1519 if (fsp->ring_cookie == RX_CLS_FLOW_DISC)
1520 input->dest_ctl = I40E_FILTER_PROGRAM_DESC_DEST_DROP_PACKET;
1523 I40E_FILTER_PROGRAM_DESC_DEST_DIRECT_PACKET_QINDEX;
1525 input->q_index = fsp->ring_cookie;
1526 input->flex_off = 0;
1528 input->dest_vsi = vsi->id;
1529 input->fd_status = I40E_FILTER_PROGRAM_DESC_FD_STATUS_FD_ID;
1530 input->cnt_index = 0;
1531 input->flow_type = fsp->flow_type;
1532 input->ip4_proto = fsp->h_u.usr_ip4_spec.proto;
1533 input->src_port = fsp->h_u.tcp_ip4_spec.psrc;
1534 input->dst_port = fsp->h_u.tcp_ip4_spec.pdst;
1535 input->src_ip[0] = fsp->h_u.tcp_ip4_spec.ip4src;
1536 input->dst_ip[0] = fsp->h_u.tcp_ip4_spec.ip4dst;
1538 ret = i40e_add_del_fdir(vsi, input, true);
1542 i40e_update_ethtool_fdir_entry(vsi, input, fsp->location, NULL);
1548 * i40e_set_rxnfc - command to set RX flow classification rules
1549 * @netdev: network interface device structure
1550 * @cmd: ethtool rxnfc command
1552 * Returns Success if the command is supported.
1554 static int i40e_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1556 struct i40e_netdev_priv *np = netdev_priv(netdev);
1557 struct i40e_vsi *vsi = np->vsi;
1558 struct i40e_pf *pf = vsi->back;
1559 int ret = -EOPNOTSUPP;
1563 ret = i40e_set_rss_hash_opt(pf, cmd);
1565 case ETHTOOL_SRXCLSRLINS:
1566 ret = i40e_add_fdir_ethtool(vsi, cmd);
1568 case ETHTOOL_SRXCLSRLDEL:
1569 ret = i40e_del_fdir_entry(vsi, cmd);
1579 * i40e_max_channels - get Max number of combined channels supported
1582 static unsigned int i40e_max_channels(struct i40e_vsi *vsi)
1584 /* TODO: This code assumes DCB and FD is disabled for now. */
1585 return vsi->alloc_queue_pairs;
1589 * i40e_get_channels - Get the current channels enabled and max supported etc.
1590 * @netdev: network interface device structure
1591 * @ch: ethtool channels structure
1593 * We don't support separate tx and rx queues as channels. The other count
1594 * represents how many queues are being used for control. max_combined counts
1595 * how many queue pairs we can support. They may not be mapped 1 to 1 with
1596 * q_vectors since we support a lot more queue pairs than q_vectors.
1598 static void i40e_get_channels(struct net_device *dev,
1599 struct ethtool_channels *ch)
1601 struct i40e_netdev_priv *np = netdev_priv(dev);
1602 struct i40e_vsi *vsi = np->vsi;
1603 struct i40e_pf *pf = vsi->back;
1605 /* report maximum channels */
1606 ch->max_combined = i40e_max_channels(vsi);
1608 /* report info for other vector */
1609 ch->other_count = (pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0;
1610 ch->max_other = ch->other_count;
1612 /* Note: This code assumes DCB is disabled for now. */
1613 ch->combined_count = vsi->num_queue_pairs;
1617 * i40e_set_channels - Set the new channels count.
1618 * @netdev: network interface device structure
1619 * @ch: ethtool channels structure
1621 * The new channels count may not be the same as requested by the user
1622 * since it gets rounded down to a power of 2 value.
1624 static int i40e_set_channels(struct net_device *dev,
1625 struct ethtool_channels *ch)
1627 struct i40e_netdev_priv *np = netdev_priv(dev);
1628 unsigned int count = ch->combined_count;
1629 struct i40e_vsi *vsi = np->vsi;
1630 struct i40e_pf *pf = vsi->back;
1633 /* We do not support setting channels for any other VSI at present */
1634 if (vsi->type != I40E_VSI_MAIN)
1637 /* verify they are not requesting separate vectors */
1638 if (!count || ch->rx_count || ch->tx_count)
1641 /* verify other_count has not changed */
1642 if (ch->other_count != ((pf->flags & I40E_FLAG_FD_SB_ENABLED) ? 1 : 0))
1645 /* verify the number of channels does not exceed hardware limits */
1646 if (count > i40e_max_channels(vsi))
1649 /* update feature limits from largest to smallest supported values */
1650 /* TODO: Flow director limit, DCB etc */
1653 if (count > pf->rss_size_max)
1654 count = pf->rss_size_max;
1656 /* use rss_reconfig to rebuild with new queue count and update traffic
1657 * class queue mapping
1659 new_count = i40e_reconfig_rss_queues(pf, count);
1666 static const struct ethtool_ops i40e_ethtool_ops = {
1667 .get_settings = i40e_get_settings,
1668 .get_drvinfo = i40e_get_drvinfo,
1669 .get_regs_len = i40e_get_regs_len,
1670 .get_regs = i40e_get_regs,
1671 .nway_reset = i40e_nway_reset,
1672 .get_link = ethtool_op_get_link,
1673 .get_wol = i40e_get_wol,
1674 .set_wol = i40e_set_wol,
1675 .get_eeprom_len = i40e_get_eeprom_len,
1676 .get_eeprom = i40e_get_eeprom,
1677 .get_ringparam = i40e_get_ringparam,
1678 .set_ringparam = i40e_set_ringparam,
1679 .get_pauseparam = i40e_get_pauseparam,
1680 .get_msglevel = i40e_get_msglevel,
1681 .set_msglevel = i40e_set_msglevel,
1682 .get_rxnfc = i40e_get_rxnfc,
1683 .set_rxnfc = i40e_set_rxnfc,
1684 .self_test = i40e_diag_test,
1685 .get_strings = i40e_get_strings,
1686 .set_phys_id = i40e_set_phys_id,
1687 .get_sset_count = i40e_get_sset_count,
1688 .get_ethtool_stats = i40e_get_ethtool_stats,
1689 .get_coalesce = i40e_get_coalesce,
1690 .set_coalesce = i40e_set_coalesce,
1691 .get_channels = i40e_get_channels,
1692 .set_channels = i40e_set_channels,
1693 .get_ts_info = i40e_get_ts_info,
1696 void i40e_set_ethtool_ops(struct net_device *netdev)
1698 netdev->ethtool_ops = &i40e_ethtool_ops;