1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
10 #include "ice_dcb_lib.h"
11 #include <net/dcbnl.h>
14 char stat_string[ETH_GSTRING_LEN];
19 #define ICE_STAT(_type, _name, _stat) { \
20 .stat_string = _name, \
21 .sizeof_stat = sizeof_field(_type, _stat), \
22 .stat_offset = offsetof(_type, _stat) \
25 #define ICE_VSI_STAT(_name, _stat) \
26 ICE_STAT(struct ice_vsi, _name, _stat)
27 #define ICE_PF_STAT(_name, _stat) \
28 ICE_STAT(struct ice_pf, _name, _stat)
30 static int ice_q_stats_len(struct net_device *netdev)
32 struct ice_netdev_priv *np = netdev_priv(netdev);
34 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
35 (sizeof(struct ice_q_stats) / sizeof(u64)));
38 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
39 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
41 #define ICE_PFC_STATS_LEN ( \
42 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
43 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
44 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
45 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
47 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
48 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
50 static const struct ice_stats ice_gstrings_vsi_stats[] = {
51 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
52 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
53 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
54 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
55 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
56 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
57 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
58 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
59 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
60 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
61 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
62 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
63 ICE_VSI_STAT("rx_gro_dropped", rx_gro_dropped),
64 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
65 ICE_VSI_STAT("tx_linearize", tx_linearize),
66 ICE_VSI_STAT("tx_busy", tx_busy),
67 ICE_VSI_STAT("tx_restart", tx_restart),
70 enum ice_ethtool_test_id {
78 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
79 "Register test (offline)",
80 "EEPROM test (offline)",
81 "Interrupt test (offline)",
82 "Loopback test (offline)",
83 "Link test (on/offline)",
86 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
88 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
89 * but they aren't. This device is capable of supporting multiple
90 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
91 * netdevs whereas the PF_STATs are for the physical function that's
92 * hosting these netdevs.
94 * The PF_STATs are appended to the netdev stats only when ethtool -S
95 * is queried on the base PF netdev.
97 static const struct ice_stats ice_gstrings_pf_stats[] = {
98 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
99 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
100 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
101 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
102 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
103 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
104 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
105 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
106 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
107 ICE_PF_STAT("tx_timeout.nic", tx_timeout_count),
108 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
109 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
110 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
111 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
112 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
113 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
114 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
115 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
116 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
117 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
118 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
119 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
120 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
121 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
122 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
123 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
124 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
125 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
126 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
127 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
128 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
129 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
130 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
131 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
132 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
133 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
134 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
135 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
136 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
137 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
138 ICE_PF_STAT("fdir_sb_match.nic", stats.fd_sb_match),
139 ICE_PF_STAT("fdir_sb_status.nic", stats.fd_sb_status),
142 static const u32 ice_regs_dump_list[] = {
152 struct ice_priv_flag {
153 char name[ETH_GSTRING_LEN];
154 u32 bitno; /* bit position in pf->flags */
157 #define ICE_PRIV_FLAG(_name, _bitno) { \
162 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
163 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
164 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
165 ICE_PRIV_FLAG("vf-true-promisc-support",
166 ICE_FLAG_VF_TRUE_PROMISC_ENA),
167 ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
168 ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
171 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
174 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
176 struct ice_netdev_priv *np = netdev_priv(netdev);
177 struct ice_vsi *vsi = np->vsi;
178 struct ice_pf *pf = vsi->back;
179 struct ice_hw *hw = &pf->hw;
180 struct ice_orom_info *orom;
181 struct ice_nvm_info *nvm;
186 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
188 /* Display NVM version (from which the firmware version can be
189 * determined) which contains more pertinent information.
191 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
192 "%x.%02x 0x%x %d.%d.%d", nvm->major_ver, nvm->minor_ver,
193 nvm->eetrack, orom->major, orom->build, orom->patch);
195 strscpy(drvinfo->bus_info, pci_name(pf->pdev),
196 sizeof(drvinfo->bus_info));
197 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
200 static int ice_get_regs_len(struct net_device __always_unused *netdev)
202 return sizeof(ice_regs_dump_list);
206 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
208 struct ice_netdev_priv *np = netdev_priv(netdev);
209 struct ice_pf *pf = np->vsi->back;
210 struct ice_hw *hw = &pf->hw;
211 u32 *regs_buf = (u32 *)p;
216 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
217 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
220 static u32 ice_get_msglevel(struct net_device *netdev)
222 struct ice_netdev_priv *np = netdev_priv(netdev);
223 struct ice_pf *pf = np->vsi->back;
225 #ifndef CONFIG_DYNAMIC_DEBUG
226 if (pf->hw.debug_mask)
227 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
229 #endif /* !CONFIG_DYNAMIC_DEBUG */
231 return pf->msg_enable;
234 static void ice_set_msglevel(struct net_device *netdev, u32 data)
236 struct ice_netdev_priv *np = netdev_priv(netdev);
237 struct ice_pf *pf = np->vsi->back;
239 #ifndef CONFIG_DYNAMIC_DEBUG
240 if (ICE_DBG_USER & data)
241 pf->hw.debug_mask = data;
243 pf->msg_enable = data;
245 pf->msg_enable = data;
246 #endif /* !CONFIG_DYNAMIC_DEBUG */
249 static int ice_get_eeprom_len(struct net_device *netdev)
251 struct ice_netdev_priv *np = netdev_priv(netdev);
252 struct ice_pf *pf = np->vsi->back;
254 return (int)pf->hw.nvm.flash_size;
258 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
261 struct ice_netdev_priv *np = netdev_priv(netdev);
262 struct ice_vsi *vsi = np->vsi;
263 struct ice_pf *pf = vsi->back;
264 struct ice_hw *hw = &pf->hw;
265 enum ice_status status;
270 dev = ice_pf_to_dev(pf);
272 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
273 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
274 eeprom->cmd, eeprom->offset, eeprom->len);
276 buf = kzalloc(eeprom->len, GFP_KERNEL);
280 status = ice_acquire_nvm(hw, ICE_RES_READ);
282 dev_err(dev, "ice_acquire_nvm failed, err %s aq_err %s\n",
283 ice_stat_str(status),
284 ice_aq_str(hw->adminq.sq_last_status));
289 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
292 dev_err(dev, "ice_read_flat_nvm failed, err %s aq_err %s\n",
293 ice_stat_str(status),
294 ice_aq_str(hw->adminq.sq_last_status));
299 memcpy(bytes, buf, eeprom->len);
308 * ice_active_vfs - check if there are any active VFs
309 * @pf: board private structure
311 * Returns true if an active VF is found, otherwise returns false
313 static bool ice_active_vfs(struct ice_pf *pf)
317 ice_for_each_vf(pf, i) {
318 struct ice_vf *vf = &pf->vf[i];
320 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
328 * ice_link_test - perform a link test on a given net_device
329 * @netdev: network interface device structure
331 * This function performs one of the self-tests required by ethtool.
332 * Returns 0 on success, non-zero on failure.
334 static u64 ice_link_test(struct net_device *netdev)
336 struct ice_netdev_priv *np = netdev_priv(netdev);
337 enum ice_status status;
338 bool link_up = false;
340 netdev_info(netdev, "link test\n");
341 status = ice_get_link_status(np->vsi->port_info, &link_up);
343 netdev_err(netdev, "link query error, status = %s\n",
344 ice_stat_str(status));
355 * ice_eeprom_test - perform an EEPROM test on a given net_device
356 * @netdev: network interface device structure
358 * This function performs one of the self-tests required by ethtool.
359 * Returns 0 on success, non-zero on failure.
361 static u64 ice_eeprom_test(struct net_device *netdev)
363 struct ice_netdev_priv *np = netdev_priv(netdev);
364 struct ice_pf *pf = np->vsi->back;
366 netdev_info(netdev, "EEPROM test\n");
367 return !!(ice_nvm_validate_checksum(&pf->hw));
371 * ice_reg_pattern_test
372 * @hw: pointer to the HW struct
373 * @reg: reg to be tested
374 * @mask: bits to be touched
376 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
378 struct ice_pf *pf = (struct ice_pf *)hw->back;
379 struct device *dev = ice_pf_to_dev(pf);
380 static const u32 patterns[] = {
381 0x5A5A5A5A, 0xA5A5A5A5,
382 0x00000000, 0xFFFFFFFF
387 orig_val = rd32(hw, reg);
388 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
389 u32 pattern = patterns[i] & mask;
391 wr32(hw, reg, pattern);
395 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
396 , __func__, reg, pattern, val);
400 wr32(hw, reg, orig_val);
402 if (val != orig_val) {
403 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
404 , __func__, reg, orig_val, val);
412 * ice_reg_test - perform a register test on a given net_device
413 * @netdev: network interface device structure
415 * This function performs one of the self-tests required by ethtool.
416 * Returns 0 on success, non-zero on failure.
418 static u64 ice_reg_test(struct net_device *netdev)
420 struct ice_netdev_priv *np = netdev_priv(netdev);
421 struct ice_hw *hw = np->vsi->port_info->hw;
422 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
423 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
424 struct ice_diag_reg_test_info {
430 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
431 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
432 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
433 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
434 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
435 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
436 {GLINT_CTL, 0xffff0001, 1, 0}
440 netdev_dbg(netdev, "Register test\n");
441 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
444 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
445 u32 mask = ice_reg_list[i].mask;
446 u32 reg = ice_reg_list[i].address +
447 (j * ice_reg_list[i].elem_size);
449 /* bail on failure (non-zero return) */
450 if (ice_reg_pattern_test(hw, reg, mask))
459 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
460 * @vsi: pointer to the VSI structure
462 * Function configures rings of a VSI for loopback test without
463 * enabling interrupts or informing the kernel about new queues.
465 * Returns 0 on success, negative on failure.
467 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
471 status = ice_vsi_setup_tx_rings(vsi);
473 goto err_setup_tx_ring;
475 status = ice_vsi_setup_rx_rings(vsi);
477 goto err_setup_rx_ring;
479 status = ice_vsi_cfg(vsi);
481 goto err_setup_rx_ring;
483 status = ice_vsi_start_all_rx_rings(vsi);
485 goto err_start_rx_ring;
490 ice_vsi_free_rx_rings(vsi);
492 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
494 ice_vsi_free_tx_rings(vsi);
500 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
501 * @vsi: pointer to the VSI structure
503 * Function stops and frees VSI rings after a loopback test.
504 * Returns 0 on success, negative on failure.
506 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
510 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
512 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
513 vsi->vsi_num, status);
515 status = ice_vsi_stop_all_rx_rings(vsi);
517 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
518 vsi->vsi_num, status);
520 ice_vsi_free_tx_rings(vsi);
521 ice_vsi_free_rx_rings(vsi);
527 * ice_lbtest_create_frame - create test packet
528 * @pf: pointer to the PF structure
529 * @ret_data: allocated frame buffer
530 * @size: size of the packet data
532 * Function allocates a frame with a test pattern on specific offsets.
533 * Returns 0 on success, non-zero on failure.
535 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
542 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
546 /* Since the ethernet test frame should always be at least
547 * 64 bytes long, fill some octets in the payload with test data.
549 memset(data, 0xFF, size);
561 * ice_lbtest_check_frame - verify received loopback frame
562 * @frame: pointer to the raw packet data
564 * Function verifies received test frame with a pattern.
565 * Returns true if frame matches the pattern, false otherwise.
567 static bool ice_lbtest_check_frame(u8 *frame)
569 /* Validate bytes of a frame under offsets chosen earlier */
570 if (frame[32] == 0xDE &&
581 * ice_diag_send - send test frames to the test ring
582 * @tx_ring: pointer to the transmit ring
583 * @data: pointer to the raw packet data
584 * @size: size of the packet to send
586 * Function sends loopback packets on a test Tx ring.
588 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
590 struct ice_tx_desc *tx_desc;
591 struct ice_tx_buf *tx_buf;
595 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
596 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
598 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
599 if (dma_mapping_error(tx_ring->dev, dma))
602 tx_desc->buf_addr = cpu_to_le64(dma);
604 /* These flags are required for a descriptor to be pushed out */
605 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
606 tx_desc->cmd_type_offset_bsz =
607 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
608 (td_cmd << ICE_TXD_QW1_CMD_S) |
609 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
610 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
611 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
613 tx_buf->next_to_watch = tx_desc;
615 /* Force memory write to complete before letting h/w know
616 * there are new descriptors to fetch.
620 tx_ring->next_to_use++;
621 if (tx_ring->next_to_use >= tx_ring->count)
622 tx_ring->next_to_use = 0;
624 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
626 /* Wait until the packets get transmitted to the receive queue. */
627 usleep_range(1000, 2000);
628 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
633 #define ICE_LB_FRAME_SIZE 64
635 * ice_lbtest_receive_frames - receive and verify test frames
636 * @rx_ring: pointer to the receive ring
638 * Function receives loopback packets and verify their correctness.
639 * Returns number of received valid frames.
641 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
643 struct ice_rx_buf *rx_buf;
649 for (i = 0; i < rx_ring->count; i++) {
650 union ice_32b_rx_flex_desc *rx_desc;
652 rx_desc = ICE_RX_DESC(rx_ring, i);
654 if (!(rx_desc->wb.status_error0 &
655 (cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S)) |
656 cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)))))
659 rx_buf = &rx_ring->rx_buf[i];
660 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
662 if (ice_lbtest_check_frame(received_buf))
670 * ice_loopback_test - perform a loopback test on a given net_device
671 * @netdev: network interface device structure
673 * This function performs one of the self-tests required by ethtool.
674 * Returns 0 on success, non-zero on failure.
676 static u64 ice_loopback_test(struct net_device *netdev)
678 struct ice_netdev_priv *np = netdev_priv(netdev);
679 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
680 struct ice_pf *pf = orig_vsi->back;
681 struct ice_ring *tx_ring, *rx_ring;
682 u8 broadcast[ETH_ALEN], ret = 0;
683 int num_frames, valid_frames;
688 dev = ice_pf_to_dev(pf);
689 netdev_info(netdev, "loopback test\n");
691 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
693 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
697 test_vsi->netdev = netdev;
698 tx_ring = test_vsi->tx_rings[0];
699 rx_ring = test_vsi->rx_rings[0];
701 if (ice_lbtest_prepare_rings(test_vsi)) {
703 goto lbtest_vsi_close;
706 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
708 goto lbtest_rings_dis;
711 /* Enable MAC loopback in firmware */
712 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
717 /* Test VSI needs to receive broadcast packets */
718 eth_broadcast_addr(broadcast);
719 if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
724 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
726 goto remove_mac_filters;
729 num_frames = min_t(int, tx_ring->count, 32);
730 for (i = 0; i < num_frames; i++) {
731 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
733 goto lbtest_free_frame;
737 valid_frames = ice_lbtest_receive_frames(rx_ring);
740 else if (valid_frames != num_frames)
744 devm_kfree(dev, tx_frame);
746 if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
747 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
749 /* Disable MAC loopback after the test is completed. */
750 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
751 netdev_err(netdev, "Could not disable MAC loopback\n");
753 if (ice_lbtest_disable_rings(test_vsi))
754 netdev_err(netdev, "Could not disable test rings\n");
756 test_vsi->netdev = NULL;
757 if (ice_vsi_release(test_vsi))
758 netdev_err(netdev, "Failed to remove the test VSI\n");
764 * ice_intr_test - perform an interrupt test on a given net_device
765 * @netdev: network interface device structure
767 * This function performs one of the self-tests required by ethtool.
768 * Returns 0 on success, non-zero on failure.
770 static u64 ice_intr_test(struct net_device *netdev)
772 struct ice_netdev_priv *np = netdev_priv(netdev);
773 struct ice_pf *pf = np->vsi->back;
774 u16 swic_old = pf->sw_int_count;
776 netdev_info(netdev, "interrupt test\n");
778 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
779 GLINT_DYN_CTL_SW_ITR_INDX_M |
780 GLINT_DYN_CTL_INTENA_MSK_M |
781 GLINT_DYN_CTL_SWINT_TRIG_M);
783 usleep_range(1000, 2000);
784 return (swic_old == pf->sw_int_count);
788 * ice_self_test - handler function for performing a self-test by ethtool
789 * @netdev: network interface device structure
790 * @eth_test: ethtool_test structure
791 * @data: required by ethtool.self_test
793 * This function is called after invoking 'ethtool -t devname' command where
794 * devname is the name of the network device on which ethtool should operate.
795 * It performs a set of self-tests to check if a device works properly.
798 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
801 struct ice_netdev_priv *np = netdev_priv(netdev);
802 bool if_running = netif_running(netdev);
803 struct ice_pf *pf = np->vsi->back;
806 dev = ice_pf_to_dev(pf);
808 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
809 netdev_info(netdev, "offline testing starting\n");
811 set_bit(__ICE_TESTING, pf->state);
813 if (ice_active_vfs(pf)) {
814 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
815 data[ICE_ETH_TEST_REG] = 1;
816 data[ICE_ETH_TEST_EEPROM] = 1;
817 data[ICE_ETH_TEST_INTR] = 1;
818 data[ICE_ETH_TEST_LOOP] = 1;
819 data[ICE_ETH_TEST_LINK] = 1;
820 eth_test->flags |= ETH_TEST_FL_FAILED;
821 clear_bit(__ICE_TESTING, pf->state);
824 /* If the device is online then take it offline */
826 /* indicate we're in test mode */
829 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
830 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
831 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
832 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
833 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
835 if (data[ICE_ETH_TEST_LINK] ||
836 data[ICE_ETH_TEST_EEPROM] ||
837 data[ICE_ETH_TEST_LOOP] ||
838 data[ICE_ETH_TEST_INTR] ||
839 data[ICE_ETH_TEST_REG])
840 eth_test->flags |= ETH_TEST_FL_FAILED;
842 clear_bit(__ICE_TESTING, pf->state);
845 int status = ice_open(netdev);
848 dev_err(dev, "Could not open device %s, err %d\n",
849 pf->int_name, status);
854 netdev_info(netdev, "online testing starting\n");
856 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
857 if (data[ICE_ETH_TEST_LINK])
858 eth_test->flags |= ETH_TEST_FL_FAILED;
860 /* Offline only tests, not run in online; pass by default */
861 data[ICE_ETH_TEST_REG] = 0;
862 data[ICE_ETH_TEST_EEPROM] = 0;
863 data[ICE_ETH_TEST_INTR] = 0;
864 data[ICE_ETH_TEST_LOOP] = 0;
868 netdev_info(netdev, "testing finished\n");
871 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
873 struct ice_netdev_priv *np = netdev_priv(netdev);
874 struct ice_vsi *vsi = np->vsi;
875 char *p = (char *)data;
880 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
881 snprintf(p, ETH_GSTRING_LEN, "%s",
882 ice_gstrings_vsi_stats[i].stat_string);
883 p += ETH_GSTRING_LEN;
886 ice_for_each_alloc_txq(vsi, i) {
887 snprintf(p, ETH_GSTRING_LEN,
888 "tx_queue_%u_packets", i);
889 p += ETH_GSTRING_LEN;
890 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
891 p += ETH_GSTRING_LEN;
894 ice_for_each_alloc_rxq(vsi, i) {
895 snprintf(p, ETH_GSTRING_LEN,
896 "rx_queue_%u_packets", i);
897 p += ETH_GSTRING_LEN;
898 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
899 p += ETH_GSTRING_LEN;
902 if (vsi->type != ICE_VSI_PF)
905 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
906 snprintf(p, ETH_GSTRING_LEN, "%s",
907 ice_gstrings_pf_stats[i].stat_string);
908 p += ETH_GSTRING_LEN;
911 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
912 snprintf(p, ETH_GSTRING_LEN,
913 "tx_priority_%u_xon.nic", i);
914 p += ETH_GSTRING_LEN;
915 snprintf(p, ETH_GSTRING_LEN,
916 "tx_priority_%u_xoff.nic", i);
917 p += ETH_GSTRING_LEN;
919 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
920 snprintf(p, ETH_GSTRING_LEN,
921 "rx_priority_%u_xon.nic", i);
922 p += ETH_GSTRING_LEN;
923 snprintf(p, ETH_GSTRING_LEN,
924 "rx_priority_%u_xoff.nic", i);
925 p += ETH_GSTRING_LEN;
929 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
931 case ETH_SS_PRIV_FLAGS:
932 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
933 snprintf(p, ETH_GSTRING_LEN, "%s",
934 ice_gstrings_priv_flags[i].name);
935 p += ETH_GSTRING_LEN;
944 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
946 struct ice_netdev_priv *np = netdev_priv(netdev);
950 case ETHTOOL_ID_ACTIVE:
953 case ETHTOOL_ID_INACTIVE:
960 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
967 * ice_set_fec_cfg - Set link FEC options
968 * @netdev: network interface device structure
969 * @req_fec: FEC mode to configure
971 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
973 struct ice_netdev_priv *np = netdev_priv(netdev);
974 struct ice_aqc_set_phy_cfg_data config = { 0 };
975 struct ice_vsi *vsi = np->vsi;
976 struct ice_port_info *pi;
982 /* Changing the FEC parameters is not supported if not the PF VSI */
983 if (vsi->type != ICE_VSI_PF) {
984 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
988 /* Proceed only if requesting different FEC mode */
989 if (pi->phy.curr_user_fec_req == req_fec)
992 /* Copy the current user PHY configuration. The current user PHY
993 * configuration is initialized during probe from PHY capabilities
994 * software mode, and updated on set PHY configuration.
996 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
998 ice_cfg_phy_fec(pi, &config, req_fec);
999 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1001 if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL))
1004 /* Save requested FEC config */
1005 pi->phy.curr_user_fec_req = req_fec;
1011 * ice_set_fecparam - Set FEC link options
1012 * @netdev: network interface device structure
1013 * @fecparam: Ethtool structure to retrieve FEC parameters
1016 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1018 struct ice_netdev_priv *np = netdev_priv(netdev);
1019 struct ice_vsi *vsi = np->vsi;
1020 enum ice_fec_mode fec;
1022 switch (fecparam->fec) {
1023 case ETHTOOL_FEC_AUTO:
1026 case ETHTOOL_FEC_RS:
1029 case ETHTOOL_FEC_BASER:
1030 fec = ICE_FEC_BASER;
1032 case ETHTOOL_FEC_OFF:
1033 case ETHTOOL_FEC_NONE:
1037 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1042 return ice_set_fec_cfg(netdev, fec);
1046 * ice_get_fecparam - Get link FEC options
1047 * @netdev: network interface device structure
1048 * @fecparam: Ethtool structure to retrieve FEC parameters
1051 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1053 struct ice_netdev_priv *np = netdev_priv(netdev);
1054 struct ice_aqc_get_phy_caps_data *caps;
1055 struct ice_link_status *link_info;
1056 struct ice_vsi *vsi = np->vsi;
1057 struct ice_port_info *pi;
1058 enum ice_status status;
1061 pi = vsi->port_info;
1065 link_info = &pi->phy.link_info;
1067 /* Set FEC mode based on negotiated link info */
1068 switch (link_info->fec_info) {
1069 case ICE_AQ_LINK_25G_KR_FEC_EN:
1070 fecparam->active_fec = ETHTOOL_FEC_BASER;
1072 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1073 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1074 fecparam->active_fec = ETHTOOL_FEC_RS;
1077 fecparam->active_fec = ETHTOOL_FEC_OFF;
1081 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1085 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1092 /* Set supported/configured FEC modes based on PHY capability */
1093 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1094 fecparam->fec |= ETHTOOL_FEC_AUTO;
1095 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1096 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1097 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1098 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1099 fecparam->fec |= ETHTOOL_FEC_BASER;
1100 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1101 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1102 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1103 fecparam->fec |= ETHTOOL_FEC_RS;
1104 if (caps->link_fec_options == 0)
1105 fecparam->fec |= ETHTOOL_FEC_OFF;
1113 * ice_nway_reset - restart autonegotiation
1114 * @netdev: network interface device structure
1116 static int ice_nway_reset(struct net_device *netdev)
1118 struct ice_netdev_priv *np = netdev_priv(netdev);
1119 struct ice_vsi *vsi = np->vsi;
1120 struct ice_port_info *pi;
1121 enum ice_status status;
1123 pi = vsi->port_info;
1124 /* If VSI state is up, then restart autoneg with link up */
1125 if (!test_bit(__ICE_DOWN, vsi->back->state))
1126 status = ice_aq_set_link_restart_an(pi, true, NULL);
1128 status = ice_aq_set_link_restart_an(pi, false, NULL);
1131 netdev_info(netdev, "link restart failed, err %s aq_err %s\n",
1132 ice_stat_str(status),
1133 ice_aq_str(pi->hw->adminq.sq_last_status));
1141 * ice_get_priv_flags - report device private flags
1142 * @netdev: network interface device structure
1144 * The get string set count and the string set should be matched for each
1145 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1148 * Returns a u32 bitmap of flags.
1150 static u32 ice_get_priv_flags(struct net_device *netdev)
1152 struct ice_netdev_priv *np = netdev_priv(netdev);
1153 struct ice_vsi *vsi = np->vsi;
1154 struct ice_pf *pf = vsi->back;
1155 u32 i, ret_flags = 0;
1157 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1158 const struct ice_priv_flag *priv_flag;
1160 priv_flag = &ice_gstrings_priv_flags[i];
1162 if (test_bit(priv_flag->bitno, pf->flags))
1163 ret_flags |= BIT(i);
1170 * ice_set_priv_flags - set private flags
1171 * @netdev: network interface device structure
1172 * @flags: bit flags to be set
1174 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1176 struct ice_netdev_priv *np = netdev_priv(netdev);
1177 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1178 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1179 struct ice_vsi *vsi = np->vsi;
1180 struct ice_pf *pf = vsi->back;
1185 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1188 dev = ice_pf_to_dev(pf);
1189 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1191 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1192 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1193 const struct ice_priv_flag *priv_flag;
1195 priv_flag = &ice_gstrings_priv_flags[i];
1198 set_bit(priv_flag->bitno, pf->flags);
1200 clear_bit(priv_flag->bitno, pf->flags);
1203 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1205 /* Do not allow change to link-down-on-close when Total Port Shutdown
1208 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) &&
1209 test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) {
1210 dev_err(dev, "Setting link-down-on-close not supported on this port\n");
1211 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1216 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1217 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1218 enum ice_status status;
1220 /* Disable FW LLDP engine */
1221 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1223 /* If unregistering for LLDP events fails, this is
1224 * not an error state, as there shouldn't be any
1225 * events to respond to.
1228 dev_info(dev, "Failed to unreg for LLDP events\n");
1230 /* The AQ call to stop the FW LLDP agent will generate
1231 * an error if the agent is already stopped.
1233 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1235 dev_warn(dev, "Fail to stop LLDP agent\n");
1236 /* Use case for having the FW LLDP agent stopped
1237 * will likely not need DCB, so failure to init is
1238 * not a concern of ethtool
1240 status = ice_init_pf_dcb(pf, true);
1242 dev_warn(dev, "Fail to init DCB\n");
1244 pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED;
1245 pf->dcbx_cap |= DCB_CAP_DCBX_HOST;
1247 enum ice_status status;
1248 bool dcbx_agent_status;
1250 /* AQ command to start FW LLDP agent will return an
1251 * error if the agent is already started
1253 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1255 dev_warn(dev, "Fail to start LLDP Agent\n");
1257 /* AQ command to start FW DCBX agent will fail if
1258 * the agent is already started
1260 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1264 dev_dbg(dev, "Failed to start FW DCBX\n");
1266 dev_info(dev, "FW DCBX agent is %s\n",
1267 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1269 /* Failure to configure MIB change or init DCB is not
1270 * relevant to ethtool. Print notification that
1271 * registration/init failed but do not return error
1274 status = ice_init_pf_dcb(pf, true);
1276 dev_dbg(dev, "Fail to init DCB\n");
1278 /* Remove rule to direct LLDP packets to default VSI.
1279 * The FW LLDP engine will now be consuming them.
1281 ice_cfg_sw_lldp(vsi, false, false);
1283 /* Register for MIB change events */
1284 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1286 dev_dbg(dev, "Fail to enable MIB change events\n");
1288 pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST;
1289 pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
1291 ice_nway_reset(netdev);
1294 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1295 /* down and up VSI so that changes of Rx cfg are reflected. */
1299 /* don't allow modification of this flag when a single VF is in
1300 * promiscuous mode because it's not supported
1302 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1303 ice_is_any_vf_in_promisc(pf)) {
1304 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1305 /* toggle bit back to previous state */
1306 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1310 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1314 static int ice_get_sset_count(struct net_device *netdev, int sset)
1318 /* The number (and order) of strings reported *must* remain
1319 * constant for a given netdevice. This function must not
1320 * report a different number based on run time parameters
1321 * (such as the number of queues in use, or the setting of
1322 * a private ethtool flag). This is due to the nature of the
1323 * ethtool stats API.
1325 * Userspace programs such as ethtool must make 3 separate
1326 * ioctl requests, one for size, one for the strings, and
1327 * finally one for the stats. Since these cross into
1328 * userspace, changes to the number or size could result in
1329 * undefined memory access or incorrect string<->value
1330 * correlations for statistics.
1332 * Even if it appears to be safe, changes to the size or
1333 * order of strings will suffer from race conditions and are
1336 return ICE_ALL_STATS_LEN(netdev);
1338 return ICE_TEST_LEN;
1339 case ETH_SS_PRIV_FLAGS:
1340 return ICE_PRIV_FLAG_ARRAY_SIZE;
1347 ice_get_ethtool_stats(struct net_device *netdev,
1348 struct ethtool_stats __always_unused *stats, u64 *data)
1350 struct ice_netdev_priv *np = netdev_priv(netdev);
1351 struct ice_vsi *vsi = np->vsi;
1352 struct ice_pf *pf = vsi->back;
1353 struct ice_ring *ring;
1358 ice_update_pf_stats(pf);
1359 ice_update_vsi_stats(vsi);
1361 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1362 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1363 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1364 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1367 /* populate per queue stats */
1370 ice_for_each_alloc_txq(vsi, j) {
1371 ring = READ_ONCE(vsi->tx_rings[j]);
1373 data[i++] = ring->stats.pkts;
1374 data[i++] = ring->stats.bytes;
1381 ice_for_each_alloc_rxq(vsi, j) {
1382 ring = READ_ONCE(vsi->rx_rings[j]);
1384 data[i++] = ring->stats.pkts;
1385 data[i++] = ring->stats.bytes;
1394 if (vsi->type != ICE_VSI_PF)
1397 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1398 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1399 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1400 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1403 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1404 data[i++] = pf->stats.priority_xon_tx[j];
1405 data[i++] = pf->stats.priority_xoff_tx[j];
1408 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1409 data[i++] = pf->stats.priority_xon_rx[j];
1410 data[i++] = pf->stats.priority_xoff_rx[j];
1414 #define ICE_PHY_TYPE_LOW_MASK_MIN_1G (ICE_PHY_TYPE_LOW_100BASE_TX | \
1415 ICE_PHY_TYPE_LOW_100M_SGMII)
1417 #define ICE_PHY_TYPE_LOW_MASK_MIN_25G (ICE_PHY_TYPE_LOW_MASK_MIN_1G | \
1418 ICE_PHY_TYPE_LOW_1000BASE_T | \
1419 ICE_PHY_TYPE_LOW_1000BASE_SX | \
1420 ICE_PHY_TYPE_LOW_1000BASE_LX | \
1421 ICE_PHY_TYPE_LOW_1000BASE_KX | \
1422 ICE_PHY_TYPE_LOW_1G_SGMII | \
1423 ICE_PHY_TYPE_LOW_2500BASE_T | \
1424 ICE_PHY_TYPE_LOW_2500BASE_X | \
1425 ICE_PHY_TYPE_LOW_2500BASE_KX | \
1426 ICE_PHY_TYPE_LOW_5GBASE_T | \
1427 ICE_PHY_TYPE_LOW_5GBASE_KR | \
1428 ICE_PHY_TYPE_LOW_10GBASE_T | \
1429 ICE_PHY_TYPE_LOW_10G_SFI_DA | \
1430 ICE_PHY_TYPE_LOW_10GBASE_SR | \
1431 ICE_PHY_TYPE_LOW_10GBASE_LR | \
1432 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \
1433 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \
1434 ICE_PHY_TYPE_LOW_10G_SFI_C2C)
1436 #define ICE_PHY_TYPE_LOW_MASK_100G (ICE_PHY_TYPE_LOW_100GBASE_CR4 | \
1437 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \
1438 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \
1439 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \
1440 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \
1441 ICE_PHY_TYPE_LOW_100G_CAUI4 | \
1442 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \
1443 ICE_PHY_TYPE_LOW_100G_AUI4 | \
1444 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \
1445 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \
1446 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \
1447 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \
1448 ICE_PHY_TYPE_LOW_100GBASE_DR)
1450 #define ICE_PHY_TYPE_HIGH_MASK_100G (ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \
1451 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\
1452 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \
1453 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \
1454 ICE_PHY_TYPE_HIGH_100G_AUI2)
1457 * ice_mask_min_supported_speeds
1458 * @phy_types_high: PHY type high
1459 * @phy_types_low: PHY type low to apply minimum supported speeds mask
1461 * Apply minimum supported speeds mask to PHY type low. These are the speeds
1462 * for ethtool supported link mode.
1465 void ice_mask_min_supported_speeds(u64 phy_types_high, u64 *phy_types_low)
1467 /* if QSFP connection with 100G speed, minimum supported speed is 25G */
1468 if (*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G ||
1469 phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G)
1470 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G;
1472 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G;
1475 #define ice_ethtool_advertise_link_mode(aq_link_speed, ethtool_link_mode) \
1477 if (req_speeds & (aq_link_speed) || \
1479 (adv_phy_type_lo & phy_type_mask_lo || \
1480 adv_phy_type_hi & phy_type_mask_hi))) \
1481 ethtool_link_ksettings_add_link_mode(ks, advertising,\
1482 ethtool_link_mode); \
1486 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1487 * @netdev: network interface device structure
1488 * @ks: ethtool link ksettings struct to fill out
1491 ice_phy_type_to_ethtool(struct net_device *netdev,
1492 struct ethtool_link_ksettings *ks)
1494 struct ice_netdev_priv *np = netdev_priv(netdev);
1495 struct ice_vsi *vsi = np->vsi;
1496 struct ice_pf *pf = vsi->back;
1497 u64 phy_type_mask_lo = 0;
1498 u64 phy_type_mask_hi = 0;
1499 u64 adv_phy_type_lo = 0;
1500 u64 adv_phy_type_hi = 0;
1501 u64 phy_types_high = 0;
1502 u64 phy_types_low = 0;
1505 req_speeds = vsi->port_info->phy.link_info.req_speeds;
1507 /* Check if lenient mode is supported and enabled, or in strict mode.
1509 * In lenient mode the Supported link modes are the PHY types without
1510 * media. The Advertising link mode is either 1. the user requested
1511 * speed, 2. the override PHY mask, or 3. the PHY types with media.
1513 * In strict mode Supported link mode are the PHY type with media,
1514 * and Advertising link modes are the media PHY type or the speed
1515 * requested by user.
1517 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
1518 struct ice_link_default_override_tlv *ldo;
1520 ldo = &pf->link_dflt_override;
1521 phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo);
1522 phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi);
1524 ice_mask_min_supported_speeds(phy_types_high, &phy_types_low);
1526 /* If override enabled and PHY mask set, then
1527 * Advertising link mode is the intersection of the PHY
1528 * types without media and the override PHY mask.
1530 if (ldo->options & ICE_LINK_OVERRIDE_EN &&
1531 (ldo->phy_type_low || ldo->phy_type_high)) {
1533 le64_to_cpu(pf->nvm_phy_type_lo) &
1536 le64_to_cpu(pf->nvm_phy_type_hi) &
1540 phy_types_low = vsi->port_info->phy.phy_type_low;
1541 phy_types_high = vsi->port_info->phy.phy_type_high;
1544 /* If Advertising link mode PHY type is not using override PHY type,
1545 * then use PHY type with media.
1547 if (!adv_phy_type_lo && !adv_phy_type_hi) {
1548 adv_phy_type_lo = vsi->port_info->phy.phy_type_low;
1549 adv_phy_type_hi = vsi->port_info->phy.phy_type_high;
1552 ethtool_link_ksettings_zero_link_mode(ks, supported);
1553 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1555 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100BASE_TX |
1556 ICE_PHY_TYPE_LOW_100M_SGMII;
1557 if (phy_types_low & phy_type_mask_lo) {
1558 ethtool_link_ksettings_add_link_mode(ks, supported,
1561 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100MB,
1565 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_T |
1566 ICE_PHY_TYPE_LOW_1G_SGMII;
1567 if (phy_types_low & phy_type_mask_lo) {
1568 ethtool_link_ksettings_add_link_mode(ks, supported,
1570 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1574 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_KX;
1575 if (phy_types_low & phy_type_mask_lo) {
1576 ethtool_link_ksettings_add_link_mode(ks, supported,
1578 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1582 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_SX |
1583 ICE_PHY_TYPE_LOW_1000BASE_LX;
1584 if (phy_types_low & phy_type_mask_lo) {
1585 ethtool_link_ksettings_add_link_mode(ks, supported,
1587 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1591 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_T;
1592 if (phy_types_low & phy_type_mask_lo) {
1593 ethtool_link_ksettings_add_link_mode(ks, supported,
1595 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_2500MB,
1599 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_X |
1600 ICE_PHY_TYPE_LOW_2500BASE_KX;
1601 if (phy_types_low & phy_type_mask_lo) {
1602 ethtool_link_ksettings_add_link_mode(ks, supported,
1604 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_2500MB,
1608 phy_type_mask_lo = ICE_PHY_TYPE_LOW_5GBASE_T |
1609 ICE_PHY_TYPE_LOW_5GBASE_KR;
1610 if (phy_types_low & phy_type_mask_lo) {
1611 ethtool_link_ksettings_add_link_mode(ks, supported,
1613 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_5GB,
1617 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_T |
1618 ICE_PHY_TYPE_LOW_10G_SFI_DA |
1619 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC |
1620 ICE_PHY_TYPE_LOW_10G_SFI_C2C;
1621 if (phy_types_low & phy_type_mask_lo) {
1622 ethtool_link_ksettings_add_link_mode(ks, supported,
1624 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1628 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_KR_CR1;
1629 if (phy_types_low & phy_type_mask_lo) {
1630 ethtool_link_ksettings_add_link_mode(ks, supported,
1632 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1636 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_SR;
1637 if (phy_types_low & phy_type_mask_lo) {
1638 ethtool_link_ksettings_add_link_mode(ks, supported,
1640 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1644 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_LR;
1645 if (phy_types_low & phy_type_mask_lo) {
1646 ethtool_link_ksettings_add_link_mode(ks, supported,
1648 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1652 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_T |
1653 ICE_PHY_TYPE_LOW_25GBASE_CR |
1654 ICE_PHY_TYPE_LOW_25GBASE_CR_S |
1655 ICE_PHY_TYPE_LOW_25GBASE_CR1 |
1656 ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC |
1657 ICE_PHY_TYPE_LOW_25G_AUI_C2C;
1658 if (phy_types_low & phy_type_mask_lo) {
1659 ethtool_link_ksettings_add_link_mode(ks, supported,
1661 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1665 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_SR |
1666 ICE_PHY_TYPE_LOW_25GBASE_LR;
1667 if (phy_types_low & phy_type_mask_lo) {
1668 ethtool_link_ksettings_add_link_mode(ks, supported,
1670 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1674 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_KR |
1675 ICE_PHY_TYPE_LOW_25GBASE_KR_S |
1676 ICE_PHY_TYPE_LOW_25GBASE_KR1;
1677 if (phy_types_low & phy_type_mask_lo) {
1678 ethtool_link_ksettings_add_link_mode(ks, supported,
1680 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1684 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_KR4;
1685 if (phy_types_low & phy_type_mask_lo) {
1686 ethtool_link_ksettings_add_link_mode(ks, supported,
1688 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1692 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_CR4 |
1693 ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC |
1694 ICE_PHY_TYPE_LOW_40G_XLAUI;
1695 if (phy_types_low & phy_type_mask_lo) {
1696 ethtool_link_ksettings_add_link_mode(ks, supported,
1698 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1702 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_SR4;
1703 if (phy_types_low & phy_type_mask_lo) {
1704 ethtool_link_ksettings_add_link_mode(ks, supported,
1706 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1710 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_LR4;
1711 if (phy_types_low & phy_type_mask_lo) {
1712 ethtool_link_ksettings_add_link_mode(ks, supported,
1714 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1718 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_CR2 |
1719 ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC |
1720 ICE_PHY_TYPE_LOW_50G_LAUI2 |
1721 ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC |
1722 ICE_PHY_TYPE_LOW_50G_AUI2 |
1723 ICE_PHY_TYPE_LOW_50GBASE_CP |
1724 ICE_PHY_TYPE_LOW_50GBASE_SR |
1725 ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC |
1726 ICE_PHY_TYPE_LOW_50G_AUI1;
1727 if (phy_types_low & phy_type_mask_lo) {
1728 ethtool_link_ksettings_add_link_mode(ks, supported,
1730 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB,
1734 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_KR2 |
1735 ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4;
1736 if (phy_types_low & phy_type_mask_lo) {
1737 ethtool_link_ksettings_add_link_mode(ks, supported,
1739 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB,
1743 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_SR2 |
1744 ICE_PHY_TYPE_LOW_50GBASE_LR2 |
1745 ICE_PHY_TYPE_LOW_50GBASE_FR |
1746 ICE_PHY_TYPE_LOW_50GBASE_LR;
1747 if (phy_types_low & phy_type_mask_lo) {
1748 ethtool_link_ksettings_add_link_mode(ks, supported,
1750 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB,
1754 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_CR4 |
1755 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC |
1756 ICE_PHY_TYPE_LOW_100G_CAUI4 |
1757 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC |
1758 ICE_PHY_TYPE_LOW_100G_AUI4 |
1759 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 |
1760 ICE_PHY_TYPE_LOW_100GBASE_CP2;
1761 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |
1762 ICE_PHY_TYPE_HIGH_100G_CAUI2 |
1763 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC |
1764 ICE_PHY_TYPE_HIGH_100G_AUI2;
1765 if (phy_types_low & phy_type_mask_lo ||
1766 phy_types_high & phy_type_mask_hi) {
1767 ethtool_link_ksettings_add_link_mode(ks, supported,
1768 100000baseCR4_Full);
1769 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1770 100000baseCR4_Full);
1773 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_SR4 |
1774 ICE_PHY_TYPE_LOW_100GBASE_SR2;
1775 if (phy_types_low & phy_type_mask_lo) {
1776 ethtool_link_ksettings_add_link_mode(ks, supported,
1777 100000baseSR4_Full);
1778 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1779 100000baseSR4_Full);
1782 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_LR4 |
1783 ICE_PHY_TYPE_LOW_100GBASE_DR;
1784 if (phy_types_low & phy_type_mask_lo) {
1785 ethtool_link_ksettings_add_link_mode(ks, supported,
1786 100000baseLR4_ER4_Full);
1787 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1788 100000baseLR4_ER4_Full);
1791 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_KR4 |
1792 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4;
1793 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4;
1794 if (phy_types_low & phy_type_mask_lo ||
1795 phy_types_high & phy_type_mask_hi) {
1796 ethtool_link_ksettings_add_link_mode(ks, supported,
1797 100000baseKR4_Full);
1798 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1799 100000baseKR4_Full);
1803 #define TEST_SET_BITS_TIMEOUT 50
1804 #define TEST_SET_BITS_SLEEP_MAX 2000
1805 #define TEST_SET_BITS_SLEEP_MIN 1000
1808 * ice_get_settings_link_up - Get Link settings for when link is up
1809 * @ks: ethtool ksettings to fill in
1810 * @netdev: network interface device structure
1813 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1814 struct net_device *netdev)
1816 struct ice_netdev_priv *np = netdev_priv(netdev);
1817 struct ice_port_info *pi = np->vsi->port_info;
1818 struct ice_link_status *link_info;
1819 struct ice_vsi *vsi = np->vsi;
1821 link_info = &vsi->port_info->phy.link_info;
1823 /* Get supported and advertised settings from PHY ability with media */
1824 ice_phy_type_to_ethtool(netdev, ks);
1826 switch (link_info->link_speed) {
1827 case ICE_AQ_LINK_SPEED_100GB:
1828 ks->base.speed = SPEED_100000;
1830 case ICE_AQ_LINK_SPEED_50GB:
1831 ks->base.speed = SPEED_50000;
1833 case ICE_AQ_LINK_SPEED_40GB:
1834 ks->base.speed = SPEED_40000;
1836 case ICE_AQ_LINK_SPEED_25GB:
1837 ks->base.speed = SPEED_25000;
1839 case ICE_AQ_LINK_SPEED_20GB:
1840 ks->base.speed = SPEED_20000;
1842 case ICE_AQ_LINK_SPEED_10GB:
1843 ks->base.speed = SPEED_10000;
1845 case ICE_AQ_LINK_SPEED_5GB:
1846 ks->base.speed = SPEED_5000;
1848 case ICE_AQ_LINK_SPEED_2500MB:
1849 ks->base.speed = SPEED_2500;
1851 case ICE_AQ_LINK_SPEED_1000MB:
1852 ks->base.speed = SPEED_1000;
1854 case ICE_AQ_LINK_SPEED_100MB:
1855 ks->base.speed = SPEED_100;
1858 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1859 link_info->link_speed);
1862 ks->base.duplex = DUPLEX_FULL;
1864 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1865 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1868 /* Set flow control negotiated Rx/Tx pause */
1869 switch (pi->fc.current_mode) {
1871 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1873 case ICE_FC_TX_PAUSE:
1874 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1875 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1878 case ICE_FC_RX_PAUSE:
1879 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1884 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1885 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1892 * ice_get_settings_link_down - Get the Link settings when link is down
1893 * @ks: ethtool ksettings to fill in
1894 * @netdev: network interface device structure
1896 * Reports link settings that can be determined when link is down
1899 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1900 struct net_device *netdev)
1902 /* link is down and the driver needs to fall back on
1903 * supported PHY types to figure out what info to display
1905 ice_phy_type_to_ethtool(netdev, ks);
1907 /* With no link, speed and duplex are unknown */
1908 ks->base.speed = SPEED_UNKNOWN;
1909 ks->base.duplex = DUPLEX_UNKNOWN;
1913 * ice_get_link_ksettings - Get Link Speed and Duplex settings
1914 * @netdev: network interface device structure
1915 * @ks: ethtool ksettings
1917 * Reports speed/duplex settings based on media_type
1920 ice_get_link_ksettings(struct net_device *netdev,
1921 struct ethtool_link_ksettings *ks)
1923 struct ice_netdev_priv *np = netdev_priv(netdev);
1924 struct ice_aqc_get_phy_caps_data *caps;
1925 struct ice_link_status *hw_link_info;
1926 struct ice_vsi *vsi = np->vsi;
1927 enum ice_status status;
1930 ethtool_link_ksettings_zero_link_mode(ks, supported);
1931 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1932 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1933 hw_link_info = &vsi->port_info->phy.link_info;
1935 /* set speed and duplex */
1936 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1937 ice_get_settings_link_up(ks, netdev);
1939 ice_get_settings_link_down(ks, netdev);
1941 /* set autoneg settings */
1942 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1943 AUTONEG_ENABLE : AUTONEG_DISABLE;
1945 /* set media type settings */
1946 switch (vsi->port_info->phy.media_type) {
1947 case ICE_MEDIA_FIBER:
1948 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1949 ks->base.port = PORT_FIBRE;
1951 case ICE_MEDIA_BASET:
1952 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1953 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1954 ks->base.port = PORT_TP;
1956 case ICE_MEDIA_BACKPLANE:
1957 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1958 ethtool_link_ksettings_add_link_mode(ks, advertising,
1960 ks->base.port = PORT_NONE;
1963 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1964 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1965 ks->base.port = PORT_DA;
1968 ks->base.port = PORT_OTHER;
1972 /* flow control is symmetric and always supported */
1973 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1975 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1979 status = ice_aq_get_phy_caps(vsi->port_info, false,
1980 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
1986 /* Set the advertised flow control based on the PHY capability */
1987 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
1988 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
1989 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1990 ethtool_link_ksettings_add_link_mode(ks, advertising,
1992 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
1993 ethtool_link_ksettings_add_link_mode(ks, advertising,
1995 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
1996 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1997 ethtool_link_ksettings_add_link_mode(ks, advertising,
2000 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2001 ethtool_link_ksettings_del_link_mode(ks, advertising,
2005 /* Set advertised FEC modes based on PHY capability */
2006 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2008 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2009 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2010 ethtool_link_ksettings_add_link_mode(ks, advertising,
2012 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2013 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2014 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2016 status = ice_aq_get_phy_caps(vsi->port_info, false,
2017 ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL);
2023 /* Set supported FEC modes based on PHY capability */
2024 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2026 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2027 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2028 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2029 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2030 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2032 /* Set supported and advertised autoneg */
2033 if (ice_is_phy_caps_an_enabled(caps)) {
2034 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2035 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2044 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2045 * @ks: ethtool ksettings
2048 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2050 u16 adv_link_speed = 0;
2052 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2054 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2055 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2057 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2058 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2060 ethtool_link_ksettings_test_link_mode(ks, advertising,
2062 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2063 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2065 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2066 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2068 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2069 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2071 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2072 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2074 ethtool_link_ksettings_test_link_mode(ks, advertising,
2076 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2077 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2078 10000baseSR_Full) ||
2079 ethtool_link_ksettings_test_link_mode(ks, advertising,
2081 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2082 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2083 25000baseCR_Full) ||
2084 ethtool_link_ksettings_test_link_mode(ks, advertising,
2085 25000baseSR_Full) ||
2086 ethtool_link_ksettings_test_link_mode(ks, advertising,
2088 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2089 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2090 40000baseCR4_Full) ||
2091 ethtool_link_ksettings_test_link_mode(ks, advertising,
2092 40000baseSR4_Full) ||
2093 ethtool_link_ksettings_test_link_mode(ks, advertising,
2094 40000baseLR4_Full) ||
2095 ethtool_link_ksettings_test_link_mode(ks, advertising,
2097 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2098 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2099 50000baseCR2_Full) ||
2100 ethtool_link_ksettings_test_link_mode(ks, advertising,
2102 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2103 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2105 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2106 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2107 100000baseCR4_Full) ||
2108 ethtool_link_ksettings_test_link_mode(ks, advertising,
2109 100000baseSR4_Full) ||
2110 ethtool_link_ksettings_test_link_mode(ks, advertising,
2111 100000baseLR4_ER4_Full) ||
2112 ethtool_link_ksettings_test_link_mode(ks, advertising,
2113 100000baseKR4_Full))
2114 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2116 return adv_link_speed;
2122 * @ks: ethtool_link_ksettings
2123 * @config: configuration that will be sent down to FW
2124 * @autoneg_enabled: autonegotiation is enabled or not
2125 * @autoneg_changed: will there a change in autonegotiation
2126 * @netdev: network interface device structure
2128 * Setup PHY autonegotiation feature
2131 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2132 struct ice_aqc_set_phy_cfg_data *config,
2133 u8 autoneg_enabled, u8 *autoneg_changed,
2134 struct net_device *netdev)
2138 *autoneg_changed = 0;
2141 if (autoneg_enabled == AUTONEG_ENABLE) {
2142 /* If autoneg was not already enabled */
2143 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2144 /* If autoneg is not supported, return error */
2145 if (!ethtool_link_ksettings_test_link_mode(ks,
2148 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2151 /* Autoneg is allowed to change */
2152 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2153 *autoneg_changed = 1;
2157 /* If autoneg is currently enabled */
2158 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2159 /* If autoneg is supported 10GBASE_T is the only PHY
2160 * that can disable it, so otherwise return error
2162 if (ethtool_link_ksettings_test_link_mode(ks,
2165 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2168 /* Autoneg is allowed to change */
2169 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2170 *autoneg_changed = 1;
2179 * ice_set_phy_type_from_speed - set phy_types based on speeds
2180 * and advertised modes
2181 * @ks: ethtool link ksettings struct
2182 * @phy_type_low: pointer to the lower part of phy_type
2183 * @phy_type_high: pointer to the higher part of phy_type
2184 * @adv_link_speed: targeted link speeds bitmap
2187 ice_set_phy_type_from_speed(const struct ethtool_link_ksettings *ks,
2188 u64 *phy_type_low, u64 *phy_type_high,
2191 /* Handle 1000M speed in a special way because ice_update_phy_type
2192 * enables all link modes, but having mixed copper and optical
2193 * standards is not supported.
2195 adv_link_speed &= ~ICE_AQ_LINK_SPEED_1000MB;
2197 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2199 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_T |
2200 ICE_PHY_TYPE_LOW_1G_SGMII;
2202 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2204 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_KX;
2206 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2208 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_SX |
2209 ICE_PHY_TYPE_LOW_1000BASE_LX;
2211 ice_update_phy_type(phy_type_low, phy_type_high, adv_link_speed);
2215 * ice_set_link_ksettings - Set Speed and Duplex
2216 * @netdev: network interface device structure
2217 * @ks: ethtool ksettings
2219 * Set speed/duplex per media_types advertised/forced
2222 ice_set_link_ksettings(struct net_device *netdev,
2223 const struct ethtool_link_ksettings *ks)
2225 struct ice_netdev_priv *np = netdev_priv(netdev);
2226 struct ethtool_link_ksettings safe_ks, copy_ks;
2227 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT;
2228 struct ice_aqc_get_phy_caps_data *phy_caps;
2229 struct ice_aqc_set_phy_cfg_data config;
2230 u16 adv_link_speed, curr_link_speed;
2231 struct ice_pf *pf = np->vsi->back;
2232 struct ice_port_info *pi;
2233 u8 autoneg_changed = 0;
2234 enum ice_status status;
2235 u64 phy_type_high = 0;
2236 u64 phy_type_low = 0;
2240 pi = np->vsi->port_info;
2245 if (pi->phy.media_type != ICE_MEDIA_BASET &&
2246 pi->phy.media_type != ICE_MEDIA_FIBER &&
2247 pi->phy.media_type != ICE_MEDIA_BACKPLANE &&
2248 pi->phy.media_type != ICE_MEDIA_DA &&
2249 pi->phy.link_info.link_info & ICE_AQ_LINK_UP)
2252 phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL);
2256 /* Get the PHY capabilities based on media */
2257 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2264 /* copy the ksettings to copy_ks to avoid modifying the original */
2265 memcpy(©_ks, ks, sizeof(copy_ks));
2267 /* save autoneg out of ksettings */
2268 autoneg = copy_ks.base.autoneg;
2270 memset(&safe_ks, 0, sizeof(safe_ks));
2272 /* Get link modes supported by hardware.*/
2273 ice_phy_type_to_ethtool(netdev, &safe_ks);
2275 /* and check against modes requested by user.
2276 * Return an error if unsupported mode was set.
2278 if (!bitmap_subset(copy_ks.link_modes.advertising,
2279 safe_ks.link_modes.supported,
2280 __ETHTOOL_LINK_MODE_MASK_NBITS)) {
2281 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags))
2282 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2287 /* get our own copy of the bits to check against */
2288 memset(&safe_ks, 0, sizeof(safe_ks));
2289 safe_ks.base.cmd = copy_ks.base.cmd;
2290 safe_ks.base.link_mode_masks_nwords =
2291 copy_ks.base.link_mode_masks_nwords;
2292 ice_get_link_ksettings(netdev, &safe_ks);
2294 /* set autoneg back to what it currently is */
2295 copy_ks.base.autoneg = safe_ks.base.autoneg;
2296 /* we don't compare the speed */
2297 copy_ks.base.speed = safe_ks.base.speed;
2299 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2300 * trying to set something that we do not support.
2302 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) {
2307 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2313 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2316 /* Copy the current user PHY configuration. The current user PHY
2317 * configuration is initialized during probe from PHY capabilities
2318 * software mode, and updated on set PHY configuration.
2320 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
2322 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2325 err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed,
2331 /* Call to get the current link speed */
2332 pi->phy.get_link_info = true;
2333 status = ice_get_link_status(pi, &linkup);
2339 curr_link_speed = pi->phy.curr_user_speed_req;
2340 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2342 /* If speed didn't get set, set it to what it currently is.
2343 * This is needed because if advertise is 0 (as it is when autoneg
2344 * is disabled) then speed won't get set.
2346 if (!adv_link_speed)
2347 adv_link_speed = curr_link_speed;
2349 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2350 ice_set_phy_type_from_speed(ks, &phy_type_low, &phy_type_high,
2353 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2354 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2358 /* save the requested speeds */
2359 pi->phy.link_info.req_speeds = adv_link_speed;
2361 /* set link and auto negotiation so changes take effect */
2362 config.caps |= ICE_AQ_PHY_ENA_LINK;
2364 /* check if there is a PHY type for the requested advertised speed */
2365 if (!(phy_type_low || phy_type_high)) {
2366 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2371 /* intersect requested advertised speed PHY types with media PHY types
2372 * for set PHY configuration
2374 config.phy_type_high = cpu_to_le64(phy_type_high) &
2375 phy_caps->phy_type_high;
2376 config.phy_type_low = cpu_to_le64(phy_type_low) &
2377 phy_caps->phy_type_low;
2379 if (!(config.phy_type_high || config.phy_type_low)) {
2380 /* If there is no intersection and lenient mode is enabled, then
2381 * intersect the requested advertised speed with NVM media type
2384 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2385 config.phy_type_high = cpu_to_le64(phy_type_high) &
2386 pf->nvm_phy_type_hi;
2387 config.phy_type_low = cpu_to_le64(phy_type_low) &
2388 pf->nvm_phy_type_lo;
2390 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2396 /* If link is up put link down */
2397 if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2398 /* Tell the OS link is going down, the link will go
2399 * back up when fw says it is ready asynchronously
2401 ice_print_link_msg(np->vsi, false);
2402 netif_carrier_off(netdev);
2403 netif_tx_stop_all_queues(netdev);
2406 /* make the aq call */
2407 status = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL);
2409 netdev_info(netdev, "Set phy config failed,\n");
2414 /* Save speed request */
2415 pi->phy.curr_user_speed_req = adv_link_speed;
2418 clear_bit(__ICE_CFG_BUSY, pf->state);
2424 * ice_parse_hdrs - parses headers from RSS hash input
2425 * @nfc: ethtool rxnfc command
2427 * This function parses the rxnfc command and returns intended
2428 * header types for RSS configuration
2430 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2432 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2434 switch (nfc->flow_type) {
2436 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2439 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2442 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2445 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2448 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2451 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2459 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2460 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2461 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2462 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2463 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2464 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2465 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2466 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2467 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2468 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2469 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2470 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2473 * ice_parse_hash_flds - parses hash fields from RSS hash input
2474 * @nfc: ethtool rxnfc command
2476 * This function parses the rxnfc command and returns intended
2477 * hash fields for RSS configuration
2479 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2481 u64 hfld = ICE_HASH_INVALID;
2483 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2484 switch (nfc->flow_type) {
2488 if (nfc->data & RXH_IP_SRC)
2489 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2490 if (nfc->data & RXH_IP_DST)
2491 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2496 if (nfc->data & RXH_IP_SRC)
2497 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2498 if (nfc->data & RXH_IP_DST)
2499 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2506 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2507 switch (nfc->flow_type) {
2510 if (nfc->data & RXH_L4_B_0_1)
2511 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2512 if (nfc->data & RXH_L4_B_2_3)
2513 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2517 if (nfc->data & RXH_L4_B_0_1)
2518 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2519 if (nfc->data & RXH_L4_B_2_3)
2520 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2524 if (nfc->data & RXH_L4_B_0_1)
2525 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2526 if (nfc->data & RXH_L4_B_2_3)
2527 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2538 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2539 * @vsi: the VSI being configured
2540 * @nfc: ethtool rxnfc command
2542 * Returns Success if the flow input set is supported.
2545 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2547 struct ice_pf *pf = vsi->back;
2548 enum ice_status status;
2553 dev = ice_pf_to_dev(pf);
2554 if (ice_is_safe_mode(pf)) {
2555 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2560 hashed_flds = ice_parse_hash_flds(nfc);
2561 if (hashed_flds == ICE_HASH_INVALID) {
2562 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2567 hdrs = ice_parse_hdrs(nfc);
2568 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2569 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2574 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2576 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %s\n",
2577 vsi->vsi_num, ice_stat_str(status));
2585 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2586 * @vsi: the VSI being configured
2587 * @nfc: ethtool rxnfc command
2590 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2592 struct ice_pf *pf = vsi->back;
2597 dev = ice_pf_to_dev(pf);
2600 if (ice_is_safe_mode(pf)) {
2601 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2606 hdrs = ice_parse_hdrs(nfc);
2607 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2608 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2613 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2614 if (hash_flds == ICE_HASH_INVALID) {
2615 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2620 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2621 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2622 nfc->data |= (u64)RXH_IP_SRC;
2624 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2625 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2626 nfc->data |= (u64)RXH_IP_DST;
2628 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2629 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2630 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2631 nfc->data |= (u64)RXH_L4_B_0_1;
2633 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2634 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2635 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2636 nfc->data |= (u64)RXH_L4_B_2_3;
2640 * ice_set_rxnfc - command to set Rx flow rules.
2641 * @netdev: network interface device structure
2642 * @cmd: ethtool rxnfc command
2644 * Returns 0 for success and negative values for errors
2646 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2648 struct ice_netdev_priv *np = netdev_priv(netdev);
2649 struct ice_vsi *vsi = np->vsi;
2652 case ETHTOOL_SRXCLSRLINS:
2653 return ice_add_fdir_ethtool(vsi, cmd);
2654 case ETHTOOL_SRXCLSRLDEL:
2655 return ice_del_fdir_ethtool(vsi, cmd);
2657 return ice_set_rss_hash_opt(vsi, cmd);
2665 * ice_get_rxnfc - command to get Rx flow classification rules
2666 * @netdev: network interface device structure
2667 * @cmd: ethtool rxnfc command
2668 * @rule_locs: buffer to rturn Rx flow classification rules
2670 * Returns Success if the command is supported.
2673 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2674 u32 __always_unused *rule_locs)
2676 struct ice_netdev_priv *np = netdev_priv(netdev);
2677 struct ice_vsi *vsi = np->vsi;
2678 int ret = -EOPNOTSUPP;
2681 hw = &vsi->back->hw;
2684 case ETHTOOL_GRXRINGS:
2685 cmd->data = vsi->rss_size;
2688 case ETHTOOL_GRXCLSRLCNT:
2689 cmd->rule_cnt = hw->fdir_active_fltr;
2690 /* report total rule count */
2691 cmd->data = ice_get_fdir_cnt_all(hw);
2694 case ETHTOOL_GRXCLSRULE:
2695 ret = ice_get_ethtool_fdir_entry(hw, cmd);
2697 case ETHTOOL_GRXCLSRLALL:
2698 ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs);
2701 ice_get_rss_hash_opt(vsi, cmd);
2712 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2714 struct ice_netdev_priv *np = netdev_priv(netdev);
2715 struct ice_vsi *vsi = np->vsi;
2717 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2718 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2719 ring->rx_pending = vsi->rx_rings[0]->count;
2720 ring->tx_pending = vsi->tx_rings[0]->count;
2722 /* Rx mini and jumbo rings are not supported */
2723 ring->rx_mini_max_pending = 0;
2724 ring->rx_jumbo_max_pending = 0;
2725 ring->rx_mini_pending = 0;
2726 ring->rx_jumbo_pending = 0;
2730 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2732 struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2733 struct ice_netdev_priv *np = netdev_priv(netdev);
2734 struct ice_ring *xdp_rings = NULL;
2735 struct ice_vsi *vsi = np->vsi;
2736 struct ice_pf *pf = vsi->back;
2737 int i, timeout = 50, err = 0;
2738 u16 new_rx_cnt, new_tx_cnt;
2740 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2741 ring->tx_pending < ICE_MIN_NUM_DESC ||
2742 ring->rx_pending > ICE_MAX_NUM_DESC ||
2743 ring->rx_pending < ICE_MIN_NUM_DESC) {
2744 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2745 ring->tx_pending, ring->rx_pending,
2746 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2747 ICE_REQ_DESC_MULTIPLE);
2751 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2752 if (new_tx_cnt != ring->tx_pending)
2753 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2755 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2756 if (new_rx_cnt != ring->rx_pending)
2757 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2760 /* if nothing to do return success */
2761 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2762 new_rx_cnt == vsi->rx_rings[0]->count) {
2763 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2767 /* If there is a AF_XDP UMEM attached to any of Rx rings,
2768 * disallow changing the number of descriptors -- regardless
2769 * if the netdev is running or not.
2771 if (ice_xsk_any_rx_ring_ena(vsi))
2774 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2778 usleep_range(1000, 2000);
2781 /* set for the next time the netdev is started */
2782 if (!netif_running(vsi->netdev)) {
2783 for (i = 0; i < vsi->alloc_txq; i++)
2784 vsi->tx_rings[i]->count = new_tx_cnt;
2785 for (i = 0; i < vsi->alloc_rxq; i++)
2786 vsi->rx_rings[i]->count = new_rx_cnt;
2787 if (ice_is_xdp_ena_vsi(vsi))
2788 for (i = 0; i < vsi->num_xdp_txq; i++)
2789 vsi->xdp_rings[i]->count = new_tx_cnt;
2790 vsi->num_tx_desc = (u16)new_tx_cnt;
2791 vsi->num_rx_desc = (u16)new_rx_cnt;
2792 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2796 if (new_tx_cnt == vsi->tx_rings[0]->count)
2799 /* alloc updated Tx resources */
2800 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2801 vsi->tx_rings[0]->count, new_tx_cnt);
2803 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2809 ice_for_each_txq(vsi, i) {
2810 /* clone ring and setup updated count */
2811 tx_rings[i] = *vsi->tx_rings[i];
2812 tx_rings[i].count = new_tx_cnt;
2813 tx_rings[i].desc = NULL;
2814 tx_rings[i].tx_buf = NULL;
2815 err = ice_setup_tx_ring(&tx_rings[i]);
2818 ice_clean_tx_ring(&tx_rings[i]);
2824 if (!ice_is_xdp_ena_vsi(vsi))
2827 /* alloc updated XDP resources */
2828 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2829 vsi->xdp_rings[0]->count, new_tx_cnt);
2831 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2837 for (i = 0; i < vsi->num_xdp_txq; i++) {
2838 /* clone ring and setup updated count */
2839 xdp_rings[i] = *vsi->xdp_rings[i];
2840 xdp_rings[i].count = new_tx_cnt;
2841 xdp_rings[i].desc = NULL;
2842 xdp_rings[i].tx_buf = NULL;
2843 err = ice_setup_tx_ring(&xdp_rings[i]);
2846 ice_clean_tx_ring(&xdp_rings[i]);
2850 ice_set_ring_xdp(&xdp_rings[i]);
2854 if (new_rx_cnt == vsi->rx_rings[0]->count)
2857 /* alloc updated Rx resources */
2858 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2859 vsi->rx_rings[0]->count, new_rx_cnt);
2861 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2867 ice_for_each_rxq(vsi, i) {
2868 /* clone ring and setup updated count */
2869 rx_rings[i] = *vsi->rx_rings[i];
2870 rx_rings[i].count = new_rx_cnt;
2871 rx_rings[i].desc = NULL;
2872 rx_rings[i].rx_buf = NULL;
2873 /* this is to allow wr32 to have something to write to
2874 * during early allocation of Rx buffers
2876 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2878 err = ice_setup_rx_ring(&rx_rings[i]);
2882 /* allocate Rx buffers */
2883 err = ice_alloc_rx_bufs(&rx_rings[i],
2884 ICE_DESC_UNUSED(&rx_rings[i]));
2889 ice_free_rx_ring(&rx_rings[i]);
2898 /* Bring interface down, copy in the new ring info, then restore the
2899 * interface. if VSI is up, bring it down and then back up
2901 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2905 ice_for_each_txq(vsi, i) {
2906 ice_free_tx_ring(vsi->tx_rings[i]);
2907 *vsi->tx_rings[i] = tx_rings[i];
2913 ice_for_each_rxq(vsi, i) {
2914 ice_free_rx_ring(vsi->rx_rings[i]);
2915 /* copy the real tail offset */
2916 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2917 /* this is to fake out the allocation routine
2918 * into thinking it has to realloc everything
2919 * but the recycling logic will let us re-use
2920 * the buffers allocated above
2922 rx_rings[i].next_to_use = 0;
2923 rx_rings[i].next_to_clean = 0;
2924 rx_rings[i].next_to_alloc = 0;
2925 *vsi->rx_rings[i] = rx_rings[i];
2931 for (i = 0; i < vsi->num_xdp_txq; i++) {
2932 ice_free_tx_ring(vsi->xdp_rings[i]);
2933 *vsi->xdp_rings[i] = xdp_rings[i];
2938 vsi->num_tx_desc = new_tx_cnt;
2939 vsi->num_rx_desc = new_rx_cnt;
2945 /* error cleanup if the Rx allocations failed after getting Tx */
2947 ice_for_each_txq(vsi, i)
2948 ice_free_tx_ring(&tx_rings[i]);
2953 clear_bit(__ICE_CFG_BUSY, pf->state);
2958 * ice_get_pauseparam - Get Flow Control status
2959 * @netdev: network interface device structure
2960 * @pause: ethernet pause (flow control) parameters
2962 * Get requested flow control status from PHY capability.
2963 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2964 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2965 * the negotiated Rx/Tx pause via lp_advertising.
2968 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2970 struct ice_netdev_priv *np = netdev_priv(netdev);
2971 struct ice_port_info *pi = np->vsi->port_info;
2972 struct ice_aqc_get_phy_caps_data *pcaps;
2973 struct ice_dcbx_cfg *dcbx_cfg;
2974 enum ice_status status;
2976 /* Initialize pause params */
2977 pause->rx_pause = 0;
2978 pause->tx_pause = 0;
2980 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
2982 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2986 /* Get current PHY config */
2987 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2992 pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
2995 if (dcbx_cfg->pfc.pfcena)
2996 /* PFC enabled so report LFC as off */
2999 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
3000 pause->tx_pause = 1;
3001 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
3002 pause->rx_pause = 1;
3009 * ice_set_pauseparam - Set Flow Control parameter
3010 * @netdev: network interface device structure
3011 * @pause: return Tx/Rx flow control status
3014 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3016 struct ice_netdev_priv *np = netdev_priv(netdev);
3017 struct ice_aqc_get_phy_caps_data *pcaps;
3018 struct ice_link_status *hw_link_info;
3019 struct ice_pf *pf = np->vsi->back;
3020 struct ice_dcbx_cfg *dcbx_cfg;
3021 struct ice_vsi *vsi = np->vsi;
3022 struct ice_hw *hw = &pf->hw;
3023 struct ice_port_info *pi;
3024 enum ice_status status;
3030 pi = vsi->port_info;
3031 hw_link_info = &pi->phy.link_info;
3032 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3033 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
3035 /* Changing the port's flow control is not supported if this isn't the
3038 if (vsi->type != ICE_VSI_PF) {
3039 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
3043 /* Get pause param reports configured and negotiated flow control pause
3044 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
3045 * defined get pause param pause->autoneg reports SW configured setting,
3046 * so compare pause->autoneg with SW configured to prevent the user from
3047 * using set pause param to chance autoneg.
3049 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3053 /* Get current PHY config */
3054 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3061 is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3066 if (pause->autoneg != is_an) {
3067 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
3071 /* If we have link and don't have autoneg */
3072 if (!test_bit(__ICE_DOWN, pf->state) &&
3073 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
3074 /* Send message that it might not necessarily work*/
3075 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
3078 if (dcbx_cfg->pfc.pfcena) {
3079 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
3082 if (pause->rx_pause && pause->tx_pause)
3083 pi->fc.req_mode = ICE_FC_FULL;
3084 else if (pause->rx_pause && !pause->tx_pause)
3085 pi->fc.req_mode = ICE_FC_RX_PAUSE;
3086 else if (!pause->rx_pause && pause->tx_pause)
3087 pi->fc.req_mode = ICE_FC_TX_PAUSE;
3088 else if (!pause->rx_pause && !pause->tx_pause)
3089 pi->fc.req_mode = ICE_FC_NONE;
3093 /* Set the FC mode and only restart AN if link is up */
3094 status = ice_set_fc(pi, &aq_failures, link_up);
3096 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
3097 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %s aq_err %s\n",
3098 ice_stat_str(status),
3099 ice_aq_str(hw->adminq.sq_last_status));
3101 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
3102 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %s aq_err %s\n",
3103 ice_stat_str(status),
3104 ice_aq_str(hw->adminq.sq_last_status));
3106 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
3107 netdev_info(netdev, "Set fc failed on the get_link_info call with err %s aq_err %s\n",
3108 ice_stat_str(status),
3109 ice_aq_str(hw->adminq.sq_last_status));
3117 * ice_get_rxfh_key_size - get the RSS hash key size
3118 * @netdev: network interface device structure
3120 * Returns the table size.
3122 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3124 return ICE_VSIQF_HKEY_ARRAY_SIZE;
3128 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3129 * @netdev: network interface device structure
3131 * Returns the table size.
3133 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3135 struct ice_netdev_priv *np = netdev_priv(netdev);
3137 return np->vsi->rss_table_size;
3141 * ice_get_rxfh - get the Rx flow hash indirection table
3142 * @netdev: network interface device structure
3143 * @indir: indirection table
3145 * @hfunc: hash function
3147 * Reads the indirection table directly from the hardware.
3150 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3152 struct ice_netdev_priv *np = netdev_priv(netdev);
3153 struct ice_vsi *vsi = np->vsi;
3154 struct ice_pf *pf = vsi->back;
3159 *hfunc = ETH_RSS_HASH_TOP;
3164 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3165 /* RSS not supported return error here */
3166 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3170 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3174 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3179 for (i = 0; i < vsi->rss_table_size; i++)
3180 indir[i] = (u32)(lut[i]);
3188 * ice_set_rxfh - set the Rx flow hash indirection table
3189 * @netdev: network interface device structure
3190 * @indir: indirection table
3192 * @hfunc: hash function
3194 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3195 * returns 0 after programming the table.
3198 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3201 struct ice_netdev_priv *np = netdev_priv(netdev);
3202 struct ice_vsi *vsi = np->vsi;
3203 struct ice_pf *pf = vsi->back;
3207 dev = ice_pf_to_dev(pf);
3208 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3211 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3212 /* RSS not supported return error here */
3213 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3218 if (!vsi->rss_hkey_user) {
3219 vsi->rss_hkey_user =
3220 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3222 if (!vsi->rss_hkey_user)
3225 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3226 seed = vsi->rss_hkey_user;
3229 if (!vsi->rss_lut_user) {
3230 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3232 if (!vsi->rss_lut_user)
3236 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3240 for (i = 0; i < vsi->rss_table_size; i++)
3241 vsi->rss_lut_user[i] = (u8)(indir[i]);
3243 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3247 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3254 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3257 static int ice_get_max_txq(struct ice_pf *pf)
3259 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3260 (u16)pf->hw.func_caps.common_cap.num_txq);
3264 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3267 static int ice_get_max_rxq(struct ice_pf *pf)
3269 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3270 (u16)pf->hw.func_caps.common_cap.num_rxq);
3274 * ice_get_combined_cnt - return the current number of combined channels
3275 * @vsi: PF VSI pointer
3277 * Go through all queue vectors and count ones that have both Rx and Tx ring
3280 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3285 ice_for_each_q_vector(vsi, q_idx) {
3286 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3288 if (q_vector->rx.ring && q_vector->tx.ring)
3296 * ice_get_channels - get the current and max supported channels
3297 * @dev: network interface device structure
3298 * @ch: ethtool channel data structure
3301 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3303 struct ice_netdev_priv *np = netdev_priv(dev);
3304 struct ice_vsi *vsi = np->vsi;
3305 struct ice_pf *pf = vsi->back;
3307 /* report maximum channels */
3308 ch->max_rx = ice_get_max_rxq(pf);
3309 ch->max_tx = ice_get_max_txq(pf);
3310 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3312 /* report current channels */
3313 ch->combined_count = ice_get_combined_cnt(vsi);
3314 ch->rx_count = vsi->num_rxq - ch->combined_count;
3315 ch->tx_count = vsi->num_txq - ch->combined_count;
3317 /* report other queues */
3318 ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
3319 ch->max_other = ch->other_count;
3323 * ice_get_valid_rss_size - return valid number of RSS queues
3324 * @hw: pointer to the HW structure
3325 * @new_size: requested RSS queues
3327 static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size)
3329 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3331 return min_t(int, new_size, BIT(caps->rss_table_entry_width));
3335 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3336 * @vsi: VSI to reconfigure RSS LUT on
3337 * @req_rss_size: requested range of queue numbers for hashing
3339 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3341 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3343 struct ice_pf *pf = vsi->back;
3344 enum ice_status status;
3350 dev = ice_pf_to_dev(pf);
3356 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3360 /* set RSS LUT parameters */
3361 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3364 vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size);
3366 /* create/set RSS LUT */
3367 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3368 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type, lut,
3369 vsi->rss_table_size);
3371 dev_err(dev, "Cannot set RSS lut, err %s aq_err %s\n",
3372 ice_stat_str(status),
3373 ice_aq_str(hw->adminq.sq_last_status));
3382 * ice_set_channels - set the number channels
3383 * @dev: network interface device structure
3384 * @ch: ethtool channel data structure
3386 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3388 struct ice_netdev_priv *np = netdev_priv(dev);
3389 struct ice_vsi *vsi = np->vsi;
3390 struct ice_pf *pf = vsi->back;
3391 int new_rx = 0, new_tx = 0;
3394 /* do not support changing channels in Safe Mode */
3395 if (ice_is_safe_mode(pf)) {
3396 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3399 /* do not support changing other_count */
3400 if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U))
3403 if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) {
3404 netdev_err(dev, "Cannot set channels when Flow Director filters are active\n");
3408 curr_combined = ice_get_combined_cnt(vsi);
3410 /* these checks are for cases where user didn't specify a particular
3411 * value on cmd line but we get non-zero value anyway via
3412 * get_channels(); look at ethtool.c in ethtool repository (the user
3413 * space part), particularly, do_schannels() routine
3415 if (ch->rx_count == vsi->num_rxq - curr_combined)
3417 if (ch->tx_count == vsi->num_txq - curr_combined)
3419 if (ch->combined_count == curr_combined)
3420 ch->combined_count = 0;
3422 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3423 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3427 new_rx = ch->combined_count + ch->rx_count;
3428 new_tx = ch->combined_count + ch->tx_count;
3430 if (new_rx > ice_get_max_rxq(pf)) {
3431 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3432 ice_get_max_rxq(pf));
3435 if (new_tx > ice_get_max_txq(pf)) {
3436 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3437 ice_get_max_txq(pf));
3441 ice_vsi_recfg_qs(vsi, new_rx, new_tx);
3443 if (!netif_is_rxfh_configured(dev))
3444 return ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3446 /* Update rss_size due to change in Rx queues */
3447 vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx);
3453 * ice_get_wol - get current Wake on LAN configuration
3454 * @netdev: network interface device structure
3455 * @wol: Ethtool structure to retrieve WoL settings
3457 static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3459 struct ice_netdev_priv *np = netdev_priv(netdev);
3460 struct ice_pf *pf = np->vsi->back;
3462 if (np->vsi->type != ICE_VSI_PF)
3463 netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
3465 /* Get WoL settings based on the HW capability */
3466 if (ice_is_wol_supported(&pf->hw)) {
3467 wol->supported = WAKE_MAGIC;
3468 wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
3476 * ice_set_wol - set Wake on LAN on supported device
3477 * @netdev: network interface device structure
3478 * @wol: Ethtool structure to set WoL
3480 static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3482 struct ice_netdev_priv *np = netdev_priv(netdev);
3483 struct ice_vsi *vsi = np->vsi;
3484 struct ice_pf *pf = vsi->back;
3486 if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw))
3489 /* only magic packet is supported */
3490 if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
3493 /* Set WoL only if there is a new value */
3494 if (pf->wol_ena != !!wol->wolopts) {
3495 pf->wol_ena = !!wol->wolopts;
3496 device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
3497 netdev_dbg(netdev, "WoL magic packet %sabled\n",
3498 pf->wol_ena ? "en" : "dis");
3504 enum ice_container_type {
3510 * ice_get_rc_coalesce - get ITR values for specific ring container
3511 * @ec: ethtool structure to fill with driver's coalesce settings
3512 * @c_type: container type, Rx or Tx
3513 * @rc: ring container that the ITR values will come from
3515 * Query the device for ice_ring_container specific ITR values. This is
3516 * done per ice_ring_container because each q_vector can have 1 or more rings
3517 * and all of said ring(s) will have the same ITR values.
3519 * Returns 0 on success, negative otherwise.
3522 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3523 struct ice_ring_container *rc)
3529 case ICE_RX_CONTAINER:
3530 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3531 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3532 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3534 case ICE_TX_CONTAINER:
3535 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3536 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3539 dev_dbg(ice_pf_to_dev(rc->ring->vsi->back), "Invalid c_type %d\n", c_type);
3547 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3548 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3549 * @ec: coalesce settings to program the device with
3550 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3552 * Return 0 on success, and negative under the following conditions:
3553 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3554 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3557 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3559 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3560 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3561 &vsi->rx_rings[q_num]->q_vector->rx))
3563 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3564 &vsi->tx_rings[q_num]->q_vector->tx))
3566 } else if (q_num < vsi->num_rxq) {
3567 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3568 &vsi->rx_rings[q_num]->q_vector->rx))
3570 } else if (q_num < vsi->num_txq) {
3571 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3572 &vsi->tx_rings[q_num]->q_vector->tx))
3582 * __ice_get_coalesce - get ITR/INTRL values for the device
3583 * @netdev: pointer to the netdev associated with this query
3584 * @ec: ethtool structure to fill with driver's coalesce settings
3585 * @q_num: queue number to get the coalesce settings for
3587 * If the caller passes in a negative q_num then we return coalesce settings
3588 * based on queue number 0, else use the actual q_num passed in.
3591 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3594 struct ice_netdev_priv *np = netdev_priv(netdev);
3595 struct ice_vsi *vsi = np->vsi;
3600 if (ice_get_q_coalesce(vsi, ec, q_num))
3607 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3609 return __ice_get_coalesce(netdev, ec, -1);
3613 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3614 struct ethtool_coalesce *ec)
3616 return __ice_get_coalesce(netdev, ec, q_num);
3620 * ice_set_rc_coalesce - set ITR values for specific ring container
3621 * @c_type: container type, Rx or Tx
3622 * @ec: ethtool structure from user to update ITR settings
3623 * @rc: ring container that the ITR values will come from
3624 * @vsi: VSI associated to the ring container
3626 * Set specific ITR values. This is done per ice_ring_container because each
3627 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3630 * Returns 0 on success, negative otherwise.
3633 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3634 struct ice_ring_container *rc, struct ice_vsi *vsi)
3636 const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3637 u32 use_adaptive_coalesce, coalesce_usecs;
3638 struct ice_pf *pf = vsi->back;
3645 case ICE_RX_CONTAINER:
3646 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3647 (ec->rx_coalesce_usecs_high &&
3648 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3649 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3650 c_type_str, pf->hw.intrl_gran,
3654 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3655 rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3656 wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3657 ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3658 pf->hw.intrl_gran));
3661 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3662 coalesce_usecs = ec->rx_coalesce_usecs;
3665 case ICE_TX_CONTAINER:
3666 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3667 coalesce_usecs = ec->tx_coalesce_usecs;
3671 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3676 itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3677 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3678 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3679 c_type_str, c_type_str);
3683 if (coalesce_usecs > ICE_ITR_MAX) {
3684 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3685 c_type_str, ICE_ITR_MAX);
3689 if (use_adaptive_coalesce) {
3690 rc->itr_setting |= ICE_ITR_DYNAMIC;
3692 /* save the user set usecs */
3693 rc->itr_setting = coalesce_usecs;
3694 /* device ITR granularity is in 2 usec increments */
3695 rc->target_itr = ITR_REG_ALIGN(rc->itr_setting);
3702 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3703 * @vsi: VSI associated to the queue that need updating
3704 * @ec: coalesce settings to program the device with
3705 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3707 * Return 0 on success, and negative under the following conditions:
3708 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3709 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3712 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3714 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3715 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3716 &vsi->rx_rings[q_num]->q_vector->rx,
3720 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3721 &vsi->tx_rings[q_num]->q_vector->tx,
3724 } else if (q_num < vsi->num_rxq) {
3725 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3726 &vsi->rx_rings[q_num]->q_vector->rx,
3729 } else if (q_num < vsi->num_txq) {
3730 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3731 &vsi->tx_rings[q_num]->q_vector->tx,
3742 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3743 * @netdev: netdev used for print
3744 * @itr_setting: previous user setting
3745 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3746 * @coalesce_usecs: requested value of [tx|rx]-usecs
3747 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3750 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3751 u32 use_adaptive_coalesce, u32 coalesce_usecs,
3752 const char *c_type_str)
3754 if (use_adaptive_coalesce)
3757 itr_setting = ITR_TO_REG(itr_setting);
3759 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3760 netdev_info(netdev, "User set %s-usecs to %d, device only supports even values. Rounding down and attempting to set %s-usecs to %d\n",
3761 c_type_str, coalesce_usecs, c_type_str,
3762 ITR_REG_ALIGN(coalesce_usecs));
3766 * __ice_set_coalesce - set ITR/INTRL values for the device
3767 * @netdev: pointer to the netdev associated with this query
3768 * @ec: ethtool structure to fill with driver's coalesce settings
3769 * @q_num: queue number to get the coalesce settings for
3771 * If the caller passes in a negative q_num then we set the coalesce settings
3772 * for all Tx/Rx queues, else use the actual q_num passed in.
3775 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3778 struct ice_netdev_priv *np = netdev_priv(netdev);
3779 struct ice_vsi *vsi = np->vsi;
3782 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3786 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3787 ec->use_adaptive_rx_coalesce,
3788 ec->rx_coalesce_usecs, "rx");
3790 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3791 ec->use_adaptive_tx_coalesce,
3792 ec->tx_coalesce_usecs, "tx");
3795 ice_for_each_q_vector(vsi, v_idx) {
3796 /* In some cases if DCB is configured the num_[rx|tx]q
3797 * can be less than vsi->num_q_vectors. This check
3798 * accounts for that so we don't report a false failure
3800 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3803 if (ice_set_q_coalesce(vsi, ec, v_idx))
3809 if (ice_set_q_coalesce(vsi, ec, q_num))
3818 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3820 return __ice_set_coalesce(netdev, ec, -1);
3824 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3825 struct ethtool_coalesce *ec)
3827 return __ice_set_coalesce(netdev, ec, q_num);
3830 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
3831 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
3832 #define ICE_MODULE_TYPE_SFP 0x03
3833 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
3834 #define ICE_MODULE_TYPE_QSFP28 0x11
3835 #define ICE_MODULE_SFF_ADDR_MODE 0x04
3836 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
3837 #define ICE_MODULE_REVISION_ADDR 0x01
3838 #define ICE_MODULE_SFF_8472_COMP 0x5E
3839 #define ICE_MODULE_SFF_8472_SWAP 0x5C
3840 #define ICE_MODULE_QSFP_MAX_LEN 640
3843 * ice_get_module_info - get SFF module type and revision information
3844 * @netdev: network interface device structure
3845 * @modinfo: module EEPROM size and layout information structure
3848 ice_get_module_info(struct net_device *netdev,
3849 struct ethtool_modinfo *modinfo)
3851 struct ice_netdev_priv *np = netdev_priv(netdev);
3852 struct ice_vsi *vsi = np->vsi;
3853 struct ice_pf *pf = vsi->back;
3854 struct ice_hw *hw = &pf->hw;
3855 enum ice_status status;
3856 u8 sff8472_comp = 0;
3857 u8 sff8472_swap = 0;
3861 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3862 0, &value, 1, 0, NULL);
3867 case ICE_MODULE_TYPE_SFP:
3868 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3869 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3870 &sff8472_comp, 1, 0, NULL);
3873 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3874 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3875 &sff8472_swap, 1, 0, NULL);
3879 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
3880 modinfo->type = ETH_MODULE_SFF_8079;
3881 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3882 } else if (sff8472_comp &&
3883 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
3884 modinfo->type = ETH_MODULE_SFF_8472;
3885 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3887 modinfo->type = ETH_MODULE_SFF_8079;
3888 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3891 case ICE_MODULE_TYPE_QSFP_PLUS:
3892 case ICE_MODULE_TYPE_QSFP28:
3893 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3894 ICE_MODULE_REVISION_ADDR, 0x00, 0,
3895 &sff8636_rev, 1, 0, NULL);
3898 /* Check revision compliance */
3899 if (sff8636_rev > 0x02) {
3900 /* Module is SFF-8636 compliant */
3901 modinfo->type = ETH_MODULE_SFF_8636;
3902 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3904 modinfo->type = ETH_MODULE_SFF_8436;
3905 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3909 netdev_warn(netdev, "SFF Module Type not recognized.\n");
3916 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
3917 * @netdev: network interface device structure
3918 * @ee: EEPROM dump request structure
3919 * @data: buffer to be filled with EEPROM contents
3922 ice_get_module_eeprom(struct net_device *netdev,
3923 struct ethtool_eeprom *ee, u8 *data)
3925 struct ice_netdev_priv *np = netdev_priv(netdev);
3926 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
3927 struct ice_vsi *vsi = np->vsi;
3928 struct ice_pf *pf = vsi->back;
3929 struct ice_hw *hw = &pf->hw;
3930 enum ice_status status;
3931 bool is_sfp = false;
3937 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0,
3938 &value, 1, 0, NULL);
3942 if (!ee || !ee->len || !data)
3945 if (value == ICE_MODULE_TYPE_SFP)
3948 for (i = 0; i < ee->len; i++) {
3949 offset = i + ee->offset;
3951 /* Check if we need to access the other memory page */
3953 if (offset >= ETH_MODULE_SFF_8079_LEN) {
3954 offset -= ETH_MODULE_SFF_8079_LEN;
3955 addr = ICE_I2C_EEPROM_DEV_ADDR2;
3958 while (offset >= ETH_MODULE_SFF_8436_LEN) {
3959 /* Compute memory page number and offset. */
3960 offset -= ETH_MODULE_SFF_8436_LEN / 2;
3965 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, !is_sfp,
3966 &value, 1, 0, NULL);
3974 static const struct ethtool_ops ice_ethtool_ops = {
3975 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
3976 ETHTOOL_COALESCE_USE_ADAPTIVE |
3977 ETHTOOL_COALESCE_RX_USECS_HIGH,
3978 .get_link_ksettings = ice_get_link_ksettings,
3979 .set_link_ksettings = ice_set_link_ksettings,
3980 .get_drvinfo = ice_get_drvinfo,
3981 .get_regs_len = ice_get_regs_len,
3982 .get_regs = ice_get_regs,
3983 .get_wol = ice_get_wol,
3984 .set_wol = ice_set_wol,
3985 .get_msglevel = ice_get_msglevel,
3986 .set_msglevel = ice_set_msglevel,
3987 .self_test = ice_self_test,
3988 .get_link = ethtool_op_get_link,
3989 .get_eeprom_len = ice_get_eeprom_len,
3990 .get_eeprom = ice_get_eeprom,
3991 .get_coalesce = ice_get_coalesce,
3992 .set_coalesce = ice_set_coalesce,
3993 .get_strings = ice_get_strings,
3994 .set_phys_id = ice_set_phys_id,
3995 .get_ethtool_stats = ice_get_ethtool_stats,
3996 .get_priv_flags = ice_get_priv_flags,
3997 .set_priv_flags = ice_set_priv_flags,
3998 .get_sset_count = ice_get_sset_count,
3999 .get_rxnfc = ice_get_rxnfc,
4000 .set_rxnfc = ice_set_rxnfc,
4001 .get_ringparam = ice_get_ringparam,
4002 .set_ringparam = ice_set_ringparam,
4003 .nway_reset = ice_nway_reset,
4004 .get_pauseparam = ice_get_pauseparam,
4005 .set_pauseparam = ice_set_pauseparam,
4006 .get_rxfh_key_size = ice_get_rxfh_key_size,
4007 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
4008 .get_rxfh = ice_get_rxfh,
4009 .set_rxfh = ice_set_rxfh,
4010 .get_channels = ice_get_channels,
4011 .set_channels = ice_set_channels,
4012 .get_ts_info = ethtool_op_get_ts_info,
4013 .get_per_queue_coalesce = ice_get_per_q_coalesce,
4014 .set_per_queue_coalesce = ice_set_per_q_coalesce,
4015 .get_fecparam = ice_get_fecparam,
4016 .set_fecparam = ice_set_fecparam,
4017 .get_module_info = ice_get_module_info,
4018 .get_module_eeprom = ice_get_module_eeprom,
4021 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
4022 .get_link_ksettings = ice_get_link_ksettings,
4023 .set_link_ksettings = ice_set_link_ksettings,
4024 .get_drvinfo = ice_get_drvinfo,
4025 .get_regs_len = ice_get_regs_len,
4026 .get_regs = ice_get_regs,
4027 .get_wol = ice_get_wol,
4028 .set_wol = ice_set_wol,
4029 .get_msglevel = ice_get_msglevel,
4030 .set_msglevel = ice_set_msglevel,
4031 .get_link = ethtool_op_get_link,
4032 .get_eeprom_len = ice_get_eeprom_len,
4033 .get_eeprom = ice_get_eeprom,
4034 .get_strings = ice_get_strings,
4035 .get_ethtool_stats = ice_get_ethtool_stats,
4036 .get_sset_count = ice_get_sset_count,
4037 .get_ringparam = ice_get_ringparam,
4038 .set_ringparam = ice_set_ringparam,
4039 .nway_reset = ice_nway_reset,
4040 .get_channels = ice_get_channels,
4044 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
4045 * @netdev: network interface device structure
4047 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
4049 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
4053 * ice_set_ethtool_ops - setup netdev ethtool ops
4054 * @netdev: network interface device structure
4056 * setup netdev ethtool ops with ice specific ops
4058 void ice_set_ethtool_ops(struct net_device *netdev)
4060 netdev->ethtool_ops = &ice_ethtool_ops;