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("tx_errors", eth_stats.tx_errors),
64 ICE_VSI_STAT("tx_linearize", tx_linearize),
65 ICE_VSI_STAT("tx_busy", tx_busy),
66 ICE_VSI_STAT("tx_restart", tx_restart),
69 enum ice_ethtool_test_id {
77 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
78 "Register test (offline)",
79 "EEPROM test (offline)",
80 "Interrupt test (offline)",
81 "Loopback test (offline)",
82 "Link test (on/offline)",
85 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
87 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
88 * but they aren't. This device is capable of supporting multiple
89 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
90 * netdevs whereas the PF_STATs are for the physical function that's
91 * hosting these netdevs.
93 * The PF_STATs are appended to the netdev stats only when ethtool -S
94 * is queried on the base PF netdev.
96 static const struct ice_stats ice_gstrings_pf_stats[] = {
97 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
98 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
99 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
100 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
101 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
102 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
103 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
104 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
105 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
106 ICE_PF_STAT("tx_timeout.nic", tx_timeout_count),
107 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
108 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
109 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
110 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
111 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
112 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
113 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
114 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
115 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
116 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
117 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
118 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
119 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
120 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
121 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
122 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
123 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
124 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
125 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
126 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
127 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
128 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
129 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
130 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
131 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
132 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
133 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
134 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
135 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
136 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
137 ICE_PF_STAT("fdir_sb_match.nic", stats.fd_sb_match),
138 ICE_PF_STAT("fdir_sb_status.nic", stats.fd_sb_status),
141 static const u32 ice_regs_dump_list[] = {
151 struct ice_priv_flag {
152 char name[ETH_GSTRING_LEN];
153 u32 bitno; /* bit position in pf->flags */
156 #define ICE_PRIV_FLAG(_name, _bitno) { \
161 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
162 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
163 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
164 ICE_PRIV_FLAG("vf-true-promisc-support",
165 ICE_FLAG_VF_TRUE_PROMISC_ENA),
166 ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
167 ICE_PRIV_FLAG("vf-vlan-pruning", ICE_FLAG_VF_VLAN_PRUNING),
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,
177 struct ice_pf *pf = vsi->back;
178 struct ice_hw *hw = &pf->hw;
179 struct ice_orom_info *orom;
180 struct ice_nvm_info *nvm;
182 nvm = &hw->flash.nvm;
183 orom = &hw->flash.orom;
185 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
187 /* Display NVM version (from which the firmware version can be
188 * determined) which contains more pertinent information.
190 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
191 "%x.%02x 0x%x %d.%d.%d", nvm->major, nvm->minor,
192 nvm->eetrack, orom->major, orom->build, orom->patch);
194 strscpy(drvinfo->bus_info, pci_name(pf->pdev),
195 sizeof(drvinfo->bus_info));
199 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
201 struct ice_netdev_priv *np = netdev_priv(netdev);
203 __ice_get_drvinfo(netdev, drvinfo, np->vsi);
204 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
207 static int ice_get_regs_len(struct net_device __always_unused *netdev)
209 return sizeof(ice_regs_dump_list);
213 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
215 struct ice_netdev_priv *np = netdev_priv(netdev);
216 struct ice_pf *pf = np->vsi->back;
217 struct ice_hw *hw = &pf->hw;
218 u32 *regs_buf = (u32 *)p;
223 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
224 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
227 static u32 ice_get_msglevel(struct net_device *netdev)
229 struct ice_netdev_priv *np = netdev_priv(netdev);
230 struct ice_pf *pf = np->vsi->back;
232 #ifndef CONFIG_DYNAMIC_DEBUG
233 if (pf->hw.debug_mask)
234 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
236 #endif /* !CONFIG_DYNAMIC_DEBUG */
238 return pf->msg_enable;
241 static void ice_set_msglevel(struct net_device *netdev, u32 data)
243 struct ice_netdev_priv *np = netdev_priv(netdev);
244 struct ice_pf *pf = np->vsi->back;
246 #ifndef CONFIG_DYNAMIC_DEBUG
247 if (ICE_DBG_USER & data)
248 pf->hw.debug_mask = data;
250 pf->msg_enable = data;
252 pf->msg_enable = data;
253 #endif /* !CONFIG_DYNAMIC_DEBUG */
256 static int ice_get_eeprom_len(struct net_device *netdev)
258 struct ice_netdev_priv *np = netdev_priv(netdev);
259 struct ice_pf *pf = np->vsi->back;
261 return (int)pf->hw.flash.flash_size;
265 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
268 struct ice_netdev_priv *np = netdev_priv(netdev);
269 struct ice_vsi *vsi = np->vsi;
270 struct ice_pf *pf = vsi->back;
271 struct ice_hw *hw = &pf->hw;
276 dev = ice_pf_to_dev(pf);
278 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
279 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
280 eeprom->cmd, eeprom->offset, eeprom->len);
282 buf = kzalloc(eeprom->len, GFP_KERNEL);
286 ret = ice_acquire_nvm(hw, ICE_RES_READ);
288 dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %s\n",
289 ret, ice_aq_str(hw->adminq.sq_last_status));
293 ret = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
296 dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %s\n",
297 ret, ice_aq_str(hw->adminq.sq_last_status));
301 memcpy(bytes, buf, eeprom->len);
310 * ice_active_vfs - check if there are any active VFs
311 * @pf: board private structure
313 * Returns true if an active VF is found, otherwise returns false
315 static bool ice_active_vfs(struct ice_pf *pf)
322 ice_for_each_vf_rcu(pf, bkt, vf) {
323 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
334 * ice_link_test - perform a link test on a given net_device
335 * @netdev: network interface device structure
337 * This function performs one of the self-tests required by ethtool.
338 * Returns 0 on success, non-zero on failure.
340 static u64 ice_link_test(struct net_device *netdev)
342 struct ice_netdev_priv *np = netdev_priv(netdev);
343 bool link_up = false;
346 netdev_info(netdev, "link test\n");
347 status = ice_get_link_status(np->vsi->port_info, &link_up);
349 netdev_err(netdev, "link query error, status = %d\n",
361 * ice_eeprom_test - perform an EEPROM test on a given net_device
362 * @netdev: network interface device structure
364 * This function performs one of the self-tests required by ethtool.
365 * Returns 0 on success, non-zero on failure.
367 static u64 ice_eeprom_test(struct net_device *netdev)
369 struct ice_netdev_priv *np = netdev_priv(netdev);
370 struct ice_pf *pf = np->vsi->back;
372 netdev_info(netdev, "EEPROM test\n");
373 return !!(ice_nvm_validate_checksum(&pf->hw));
377 * ice_reg_pattern_test
378 * @hw: pointer to the HW struct
379 * @reg: reg to be tested
380 * @mask: bits to be touched
382 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
384 struct ice_pf *pf = (struct ice_pf *)hw->back;
385 struct device *dev = ice_pf_to_dev(pf);
386 static const u32 patterns[] = {
387 0x5A5A5A5A, 0xA5A5A5A5,
388 0x00000000, 0xFFFFFFFF
393 orig_val = rd32(hw, reg);
394 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
395 u32 pattern = patterns[i] & mask;
397 wr32(hw, reg, pattern);
401 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
402 , __func__, reg, pattern, val);
406 wr32(hw, reg, orig_val);
408 if (val != orig_val) {
409 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
410 , __func__, reg, orig_val, val);
418 * ice_reg_test - perform a register test on a given net_device
419 * @netdev: network interface device structure
421 * This function performs one of the self-tests required by ethtool.
422 * Returns 0 on success, non-zero on failure.
424 static u64 ice_reg_test(struct net_device *netdev)
426 struct ice_netdev_priv *np = netdev_priv(netdev);
427 struct ice_hw *hw = np->vsi->port_info->hw;
428 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
429 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
430 struct ice_diag_reg_test_info {
436 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
437 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
438 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
439 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
440 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
441 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
442 {GLINT_CTL, 0xffff0001, 1, 0}
446 netdev_dbg(netdev, "Register test\n");
447 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
450 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
451 u32 mask = ice_reg_list[i].mask;
452 u32 reg = ice_reg_list[i].address +
453 (j * ice_reg_list[i].elem_size);
455 /* bail on failure (non-zero return) */
456 if (ice_reg_pattern_test(hw, reg, mask))
465 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
466 * @vsi: pointer to the VSI structure
468 * Function configures rings of a VSI for loopback test without
469 * enabling interrupts or informing the kernel about new queues.
471 * Returns 0 on success, negative on failure.
473 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
477 status = ice_vsi_setup_tx_rings(vsi);
479 goto err_setup_tx_ring;
481 status = ice_vsi_setup_rx_rings(vsi);
483 goto err_setup_rx_ring;
485 status = ice_vsi_cfg(vsi);
487 goto err_setup_rx_ring;
489 status = ice_vsi_start_all_rx_rings(vsi);
491 goto err_start_rx_ring;
496 ice_vsi_free_rx_rings(vsi);
498 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
500 ice_vsi_free_tx_rings(vsi);
506 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
507 * @vsi: pointer to the VSI structure
509 * Function stops and frees VSI rings after a loopback test.
510 * Returns 0 on success, negative on failure.
512 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
516 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
518 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
519 vsi->vsi_num, status);
521 status = ice_vsi_stop_all_rx_rings(vsi);
523 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
524 vsi->vsi_num, status);
526 ice_vsi_free_tx_rings(vsi);
527 ice_vsi_free_rx_rings(vsi);
533 * ice_lbtest_create_frame - create test packet
534 * @pf: pointer to the PF structure
535 * @ret_data: allocated frame buffer
536 * @size: size of the packet data
538 * Function allocates a frame with a test pattern on specific offsets.
539 * Returns 0 on success, non-zero on failure.
541 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
548 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
552 /* Since the ethernet test frame should always be at least
553 * 64 bytes long, fill some octets in the payload with test data.
555 memset(data, 0xFF, size);
567 * ice_lbtest_check_frame - verify received loopback frame
568 * @frame: pointer to the raw packet data
570 * Function verifies received test frame with a pattern.
571 * Returns true if frame matches the pattern, false otherwise.
573 static bool ice_lbtest_check_frame(u8 *frame)
575 /* Validate bytes of a frame under offsets chosen earlier */
576 if (frame[32] == 0xDE &&
587 * ice_diag_send - send test frames to the test ring
588 * @tx_ring: pointer to the transmit ring
589 * @data: pointer to the raw packet data
590 * @size: size of the packet to send
592 * Function sends loopback packets on a test Tx ring.
594 static int ice_diag_send(struct ice_tx_ring *tx_ring, u8 *data, u16 size)
596 struct ice_tx_desc *tx_desc;
597 struct ice_tx_buf *tx_buf;
601 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
602 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
604 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
605 if (dma_mapping_error(tx_ring->dev, dma))
608 tx_desc->buf_addr = cpu_to_le64(dma);
610 /* These flags are required for a descriptor to be pushed out */
611 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
612 tx_desc->cmd_type_offset_bsz =
613 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
614 (td_cmd << ICE_TXD_QW1_CMD_S) |
615 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
616 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
617 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
619 tx_buf->next_to_watch = tx_desc;
621 /* Force memory write to complete before letting h/w know
622 * there are new descriptors to fetch.
626 tx_ring->next_to_use++;
627 if (tx_ring->next_to_use >= tx_ring->count)
628 tx_ring->next_to_use = 0;
630 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
632 /* Wait until the packets get transmitted to the receive queue. */
633 usleep_range(1000, 2000);
634 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
639 #define ICE_LB_FRAME_SIZE 64
641 * ice_lbtest_receive_frames - receive and verify test frames
642 * @rx_ring: pointer to the receive ring
644 * Function receives loopback packets and verify their correctness.
645 * Returns number of received valid frames.
647 static int ice_lbtest_receive_frames(struct ice_rx_ring *rx_ring)
649 struct ice_rx_buf *rx_buf;
655 for (i = 0; i < rx_ring->count; i++) {
656 union ice_32b_rx_flex_desc *rx_desc;
658 rx_desc = ICE_RX_DESC(rx_ring, i);
660 if (!(rx_desc->wb.status_error0 &
661 (cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S)) |
662 cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)))))
665 rx_buf = &rx_ring->rx_buf[i];
666 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
668 if (ice_lbtest_check_frame(received_buf))
676 * ice_loopback_test - perform a loopback test on a given net_device
677 * @netdev: network interface device structure
679 * This function performs one of the self-tests required by ethtool.
680 * Returns 0 on success, non-zero on failure.
682 static u64 ice_loopback_test(struct net_device *netdev)
684 struct ice_netdev_priv *np = netdev_priv(netdev);
685 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
686 struct ice_pf *pf = orig_vsi->back;
687 u8 broadcast[ETH_ALEN], ret = 0;
688 int num_frames, valid_frames;
689 struct ice_tx_ring *tx_ring;
690 struct ice_rx_ring *rx_ring;
695 dev = ice_pf_to_dev(pf);
696 netdev_info(netdev, "loopback test\n");
698 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
700 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
704 test_vsi->netdev = netdev;
705 tx_ring = test_vsi->tx_rings[0];
706 rx_ring = test_vsi->rx_rings[0];
708 if (ice_lbtest_prepare_rings(test_vsi)) {
710 goto lbtest_vsi_close;
713 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
715 goto lbtest_rings_dis;
718 /* Enable MAC loopback in firmware */
719 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
724 /* Test VSI needs to receive broadcast packets */
725 eth_broadcast_addr(broadcast);
726 if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
731 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
733 goto remove_mac_filters;
736 num_frames = min_t(int, tx_ring->count, 32);
737 for (i = 0; i < num_frames; i++) {
738 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
740 goto lbtest_free_frame;
744 valid_frames = ice_lbtest_receive_frames(rx_ring);
747 else if (valid_frames != num_frames)
751 devm_kfree(dev, tx_frame);
753 if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
754 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
756 /* Disable MAC loopback after the test is completed. */
757 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
758 netdev_err(netdev, "Could not disable MAC loopback\n");
760 if (ice_lbtest_disable_rings(test_vsi))
761 netdev_err(netdev, "Could not disable test rings\n");
763 test_vsi->netdev = NULL;
764 if (ice_vsi_release(test_vsi))
765 netdev_err(netdev, "Failed to remove the test VSI\n");
771 * ice_intr_test - perform an interrupt test on a given net_device
772 * @netdev: network interface device structure
774 * This function performs one of the self-tests required by ethtool.
775 * Returns 0 on success, non-zero on failure.
777 static u64 ice_intr_test(struct net_device *netdev)
779 struct ice_netdev_priv *np = netdev_priv(netdev);
780 struct ice_pf *pf = np->vsi->back;
781 u16 swic_old = pf->sw_int_count;
783 netdev_info(netdev, "interrupt test\n");
785 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
786 GLINT_DYN_CTL_SW_ITR_INDX_M |
787 GLINT_DYN_CTL_INTENA_MSK_M |
788 GLINT_DYN_CTL_SWINT_TRIG_M);
790 usleep_range(1000, 2000);
791 return (swic_old == pf->sw_int_count);
795 * ice_self_test - handler function for performing a self-test by ethtool
796 * @netdev: network interface device structure
797 * @eth_test: ethtool_test structure
798 * @data: required by ethtool.self_test
800 * This function is called after invoking 'ethtool -t devname' command where
801 * devname is the name of the network device on which ethtool should operate.
802 * It performs a set of self-tests to check if a device works properly.
805 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
808 struct ice_netdev_priv *np = netdev_priv(netdev);
809 bool if_running = netif_running(netdev);
810 struct ice_pf *pf = np->vsi->back;
813 dev = ice_pf_to_dev(pf);
815 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
816 netdev_info(netdev, "offline testing starting\n");
818 set_bit(ICE_TESTING, pf->state);
820 if (ice_active_vfs(pf)) {
821 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
822 data[ICE_ETH_TEST_REG] = 1;
823 data[ICE_ETH_TEST_EEPROM] = 1;
824 data[ICE_ETH_TEST_INTR] = 1;
825 data[ICE_ETH_TEST_LOOP] = 1;
826 data[ICE_ETH_TEST_LINK] = 1;
827 eth_test->flags |= ETH_TEST_FL_FAILED;
828 clear_bit(ICE_TESTING, pf->state);
831 /* If the device is online then take it offline */
833 /* indicate we're in test mode */
836 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
837 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
838 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
839 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
840 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
842 if (data[ICE_ETH_TEST_LINK] ||
843 data[ICE_ETH_TEST_EEPROM] ||
844 data[ICE_ETH_TEST_LOOP] ||
845 data[ICE_ETH_TEST_INTR] ||
846 data[ICE_ETH_TEST_REG])
847 eth_test->flags |= ETH_TEST_FL_FAILED;
849 clear_bit(ICE_TESTING, pf->state);
852 int status = ice_open(netdev);
855 dev_err(dev, "Could not open device %s, err %d\n",
856 pf->int_name, status);
861 netdev_info(netdev, "online testing starting\n");
863 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
864 if (data[ICE_ETH_TEST_LINK])
865 eth_test->flags |= ETH_TEST_FL_FAILED;
867 /* Offline only tests, not run in online; pass by default */
868 data[ICE_ETH_TEST_REG] = 0;
869 data[ICE_ETH_TEST_EEPROM] = 0;
870 data[ICE_ETH_TEST_INTR] = 0;
871 data[ICE_ETH_TEST_LOOP] = 0;
875 netdev_info(netdev, "testing finished\n");
879 __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
887 for (i = 0; i < ICE_VSI_STATS_LEN; i++)
889 ice_gstrings_vsi_stats[i].stat_string);
891 if (ice_is_port_repr_netdev(netdev))
894 ice_for_each_alloc_txq(vsi, i) {
895 ethtool_sprintf(&p, "tx_queue_%u_packets", i);
896 ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
899 ice_for_each_alloc_rxq(vsi, i) {
900 ethtool_sprintf(&p, "rx_queue_%u_packets", i);
901 ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
904 if (vsi->type != ICE_VSI_PF)
907 for (i = 0; i < ICE_PF_STATS_LEN; i++)
909 ice_gstrings_pf_stats[i].stat_string);
911 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
912 ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
913 ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
915 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
916 ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
917 ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
921 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
923 case ETH_SS_PRIV_FLAGS:
924 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
925 ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
932 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
934 struct ice_netdev_priv *np = netdev_priv(netdev);
936 __ice_get_strings(netdev, stringset, data, np->vsi);
940 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
942 struct ice_netdev_priv *np = netdev_priv(netdev);
946 case ETHTOOL_ID_ACTIVE:
949 case ETHTOOL_ID_INACTIVE:
956 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
963 * ice_set_fec_cfg - Set link FEC options
964 * @netdev: network interface device structure
965 * @req_fec: FEC mode to configure
967 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
969 struct ice_netdev_priv *np = netdev_priv(netdev);
970 struct ice_aqc_set_phy_cfg_data config = { 0 };
971 struct ice_vsi *vsi = np->vsi;
972 struct ice_port_info *pi;
978 /* Changing the FEC parameters is not supported if not the PF VSI */
979 if (vsi->type != ICE_VSI_PF) {
980 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
984 /* Proceed only if requesting different FEC mode */
985 if (pi->phy.curr_user_fec_req == req_fec)
988 /* Copy the current user PHY configuration. The current user PHY
989 * configuration is initialized during probe from PHY capabilities
990 * software mode, and updated on set PHY configuration.
992 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
994 ice_cfg_phy_fec(pi, &config, req_fec);
995 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
997 if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL))
1000 /* Save requested FEC config */
1001 pi->phy.curr_user_fec_req = req_fec;
1007 * ice_set_fecparam - Set FEC link options
1008 * @netdev: network interface device structure
1009 * @fecparam: Ethtool structure to retrieve FEC parameters
1012 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1014 struct ice_netdev_priv *np = netdev_priv(netdev);
1015 struct ice_vsi *vsi = np->vsi;
1016 enum ice_fec_mode fec;
1018 switch (fecparam->fec) {
1019 case ETHTOOL_FEC_AUTO:
1022 case ETHTOOL_FEC_RS:
1025 case ETHTOOL_FEC_BASER:
1026 fec = ICE_FEC_BASER;
1028 case ETHTOOL_FEC_OFF:
1029 case ETHTOOL_FEC_NONE:
1033 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1038 return ice_set_fec_cfg(netdev, fec);
1042 * ice_get_fecparam - Get link FEC options
1043 * @netdev: network interface device structure
1044 * @fecparam: Ethtool structure to retrieve FEC parameters
1047 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1049 struct ice_netdev_priv *np = netdev_priv(netdev);
1050 struct ice_aqc_get_phy_caps_data *caps;
1051 struct ice_link_status *link_info;
1052 struct ice_vsi *vsi = np->vsi;
1053 struct ice_port_info *pi;
1056 pi = vsi->port_info;
1060 link_info = &pi->phy.link_info;
1062 /* Set FEC mode based on negotiated link info */
1063 switch (link_info->fec_info) {
1064 case ICE_AQ_LINK_25G_KR_FEC_EN:
1065 fecparam->active_fec = ETHTOOL_FEC_BASER;
1067 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1068 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1069 fecparam->active_fec = ETHTOOL_FEC_RS;
1072 fecparam->active_fec = ETHTOOL_FEC_OFF;
1076 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1080 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1085 /* Set supported/configured FEC modes based on PHY capability */
1086 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1087 fecparam->fec |= ETHTOOL_FEC_AUTO;
1088 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1089 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1090 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1091 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1092 fecparam->fec |= ETHTOOL_FEC_BASER;
1093 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1094 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1095 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1096 fecparam->fec |= ETHTOOL_FEC_RS;
1097 if (caps->link_fec_options == 0)
1098 fecparam->fec |= ETHTOOL_FEC_OFF;
1106 * ice_nway_reset - restart autonegotiation
1107 * @netdev: network interface device structure
1109 static int ice_nway_reset(struct net_device *netdev)
1111 struct ice_netdev_priv *np = netdev_priv(netdev);
1112 struct ice_vsi *vsi = np->vsi;
1115 /* If VSI state is up, then restart autoneg with link up */
1116 if (!test_bit(ICE_DOWN, vsi->back->state))
1117 err = ice_set_link(vsi, true);
1119 err = ice_set_link(vsi, false);
1125 * ice_get_priv_flags - report device private flags
1126 * @netdev: network interface device structure
1128 * The get string set count and the string set should be matched for each
1129 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1132 * Returns a u32 bitmap of flags.
1134 static u32 ice_get_priv_flags(struct net_device *netdev)
1136 struct ice_netdev_priv *np = netdev_priv(netdev);
1137 struct ice_vsi *vsi = np->vsi;
1138 struct ice_pf *pf = vsi->back;
1139 u32 i, ret_flags = 0;
1141 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1142 const struct ice_priv_flag *priv_flag;
1144 priv_flag = &ice_gstrings_priv_flags[i];
1146 if (test_bit(priv_flag->bitno, pf->flags))
1147 ret_flags |= BIT(i);
1154 * ice_set_priv_flags - set private flags
1155 * @netdev: network interface device structure
1156 * @flags: bit flags to be set
1158 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1160 struct ice_netdev_priv *np = netdev_priv(netdev);
1161 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1162 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1163 struct ice_vsi *vsi = np->vsi;
1164 struct ice_pf *pf = vsi->back;
1169 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1172 dev = ice_pf_to_dev(pf);
1173 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1175 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1176 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1177 const struct ice_priv_flag *priv_flag;
1179 priv_flag = &ice_gstrings_priv_flags[i];
1182 set_bit(priv_flag->bitno, pf->flags);
1184 clear_bit(priv_flag->bitno, pf->flags);
1187 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1189 /* Do not allow change to link-down-on-close when Total Port Shutdown
1192 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) &&
1193 test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) {
1194 dev_err(dev, "Setting link-down-on-close not supported on this port\n");
1195 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1200 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1201 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1204 /* Disable FW LLDP engine */
1205 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1207 /* If unregistering for LLDP events fails, this is
1208 * not an error state, as there shouldn't be any
1209 * events to respond to.
1212 dev_info(dev, "Failed to unreg for LLDP events\n");
1214 /* The AQ call to stop the FW LLDP agent will generate
1215 * an error if the agent is already stopped.
1217 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1219 dev_warn(dev, "Fail to stop LLDP agent\n");
1220 /* Use case for having the FW LLDP agent stopped
1221 * will likely not need DCB, so failure to init is
1222 * not a concern of ethtool
1224 status = ice_init_pf_dcb(pf, true);
1226 dev_warn(dev, "Fail to init DCB\n");
1228 pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED;
1229 pf->dcbx_cap |= DCB_CAP_DCBX_HOST;
1231 bool dcbx_agent_status;
1234 if (ice_get_pfc_mode(pf) == ICE_QOS_MODE_DSCP) {
1235 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
1236 dev_err(dev, "QoS in L3 DSCP mode, FW Agent not allowed to start\n");
1241 /* Remove rule to direct LLDP packets to default VSI.
1242 * The FW LLDP engine will now be consuming them.
1244 ice_cfg_sw_lldp(vsi, false, false);
1246 /* AQ command to start FW LLDP agent will return an
1247 * error if the agent is already started
1249 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1251 dev_warn(dev, "Fail to start LLDP Agent\n");
1253 /* AQ command to start FW DCBX agent will fail if
1254 * the agent is already started
1256 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1260 dev_dbg(dev, "Failed to start FW DCBX\n");
1262 dev_info(dev, "FW DCBX agent is %s\n",
1263 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1265 /* Failure to configure MIB change or init DCB is not
1266 * relevant to ethtool. Print notification that
1267 * registration/init failed but do not return error
1270 status = ice_init_pf_dcb(pf, true);
1272 dev_dbg(dev, "Fail to init DCB\n");
1274 /* Register for MIB change events */
1275 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1277 dev_dbg(dev, "Fail to enable MIB change events\n");
1279 pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST;
1280 pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
1282 ice_nway_reset(netdev);
1285 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1286 /* down and up VSI so that changes of Rx cfg are reflected. */
1287 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
1292 /* don't allow modification of this flag when a single VF is in
1293 * promiscuous mode because it's not supported
1295 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1296 ice_is_any_vf_in_unicast_promisc(pf)) {
1297 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1298 /* toggle bit back to previous state */
1299 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1303 if (test_bit(ICE_FLAG_VF_VLAN_PRUNING, change_flags) &&
1305 dev_err(dev, "vf-vlan-pruning: VLAN pruning cannot be changed while VFs are active.\n");
1306 /* toggle bit back to previous state */
1307 change_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags);
1311 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1315 static int ice_get_sset_count(struct net_device *netdev, int sset)
1319 /* The number (and order) of strings reported *must* remain
1320 * constant for a given netdevice. This function must not
1321 * report a different number based on run time parameters
1322 * (such as the number of queues in use, or the setting of
1323 * a private ethtool flag). This is due to the nature of the
1324 * ethtool stats API.
1326 * Userspace programs such as ethtool must make 3 separate
1327 * ioctl requests, one for size, one for the strings, and
1328 * finally one for the stats. Since these cross into
1329 * userspace, changes to the number or size could result in
1330 * undefined memory access or incorrect string<->value
1331 * correlations for statistics.
1333 * Even if it appears to be safe, changes to the size or
1334 * order of strings will suffer from race conditions and are
1337 return ICE_ALL_STATS_LEN(netdev);
1339 return ICE_TEST_LEN;
1340 case ETH_SS_PRIV_FLAGS:
1341 return ICE_PRIV_FLAG_ARRAY_SIZE;
1348 __ice_get_ethtool_stats(struct net_device *netdev,
1349 struct ethtool_stats __always_unused *stats, u64 *data,
1350 struct ice_vsi *vsi)
1352 struct ice_pf *pf = vsi->back;
1353 struct ice_tx_ring *tx_ring;
1354 struct ice_rx_ring *rx_ring;
1359 ice_update_pf_stats(pf);
1360 ice_update_vsi_stats(vsi);
1362 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1363 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1364 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1365 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1368 if (ice_is_port_repr_netdev(netdev))
1371 /* populate per queue stats */
1374 ice_for_each_alloc_txq(vsi, j) {
1375 tx_ring = READ_ONCE(vsi->tx_rings[j]);
1377 data[i++] = tx_ring->stats.pkts;
1378 data[i++] = tx_ring->stats.bytes;
1385 ice_for_each_alloc_rxq(vsi, j) {
1386 rx_ring = READ_ONCE(vsi->rx_rings[j]);
1388 data[i++] = rx_ring->stats.pkts;
1389 data[i++] = rx_ring->stats.bytes;
1398 if (vsi->type != ICE_VSI_PF)
1401 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1402 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1403 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1404 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1407 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1408 data[i++] = pf->stats.priority_xon_tx[j];
1409 data[i++] = pf->stats.priority_xoff_tx[j];
1412 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1413 data[i++] = pf->stats.priority_xon_rx[j];
1414 data[i++] = pf->stats.priority_xoff_rx[j];
1419 ice_get_ethtool_stats(struct net_device *netdev,
1420 struct ethtool_stats __always_unused *stats, u64 *data)
1422 struct ice_netdev_priv *np = netdev_priv(netdev);
1424 __ice_get_ethtool_stats(netdev, stats, data, np->vsi);
1427 #define ICE_PHY_TYPE_LOW_MASK_MIN_1G (ICE_PHY_TYPE_LOW_100BASE_TX | \
1428 ICE_PHY_TYPE_LOW_100M_SGMII)
1430 #define ICE_PHY_TYPE_LOW_MASK_MIN_25G (ICE_PHY_TYPE_LOW_MASK_MIN_1G | \
1431 ICE_PHY_TYPE_LOW_1000BASE_T | \
1432 ICE_PHY_TYPE_LOW_1000BASE_SX | \
1433 ICE_PHY_TYPE_LOW_1000BASE_LX | \
1434 ICE_PHY_TYPE_LOW_1000BASE_KX | \
1435 ICE_PHY_TYPE_LOW_1G_SGMII | \
1436 ICE_PHY_TYPE_LOW_2500BASE_T | \
1437 ICE_PHY_TYPE_LOW_2500BASE_X | \
1438 ICE_PHY_TYPE_LOW_2500BASE_KX | \
1439 ICE_PHY_TYPE_LOW_5GBASE_T | \
1440 ICE_PHY_TYPE_LOW_5GBASE_KR | \
1441 ICE_PHY_TYPE_LOW_10GBASE_T | \
1442 ICE_PHY_TYPE_LOW_10G_SFI_DA | \
1443 ICE_PHY_TYPE_LOW_10GBASE_SR | \
1444 ICE_PHY_TYPE_LOW_10GBASE_LR | \
1445 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \
1446 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \
1447 ICE_PHY_TYPE_LOW_10G_SFI_C2C)
1449 #define ICE_PHY_TYPE_LOW_MASK_100G (ICE_PHY_TYPE_LOW_100GBASE_CR4 | \
1450 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \
1451 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \
1452 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \
1453 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \
1454 ICE_PHY_TYPE_LOW_100G_CAUI4 | \
1455 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \
1456 ICE_PHY_TYPE_LOW_100G_AUI4 | \
1457 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \
1458 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \
1459 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \
1460 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \
1461 ICE_PHY_TYPE_LOW_100GBASE_DR)
1463 #define ICE_PHY_TYPE_HIGH_MASK_100G (ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \
1464 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\
1465 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \
1466 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \
1467 ICE_PHY_TYPE_HIGH_100G_AUI2)
1470 * ice_mask_min_supported_speeds
1471 * @phy_types_high: PHY type high
1472 * @phy_types_low: PHY type low to apply minimum supported speeds mask
1474 * Apply minimum supported speeds mask to PHY type low. These are the speeds
1475 * for ethtool supported link mode.
1478 void ice_mask_min_supported_speeds(u64 phy_types_high, u64 *phy_types_low)
1480 /* if QSFP connection with 100G speed, minimum supported speed is 25G */
1481 if (*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G ||
1482 phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G)
1483 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G;
1485 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G;
1488 #define ice_ethtool_advertise_link_mode(aq_link_speed, ethtool_link_mode) \
1490 if (req_speeds & (aq_link_speed) || \
1492 (advert_phy_type_lo & phy_type_mask_lo || \
1493 advert_phy_type_hi & phy_type_mask_hi))) \
1494 ethtool_link_ksettings_add_link_mode(ks, advertising,\
1495 ethtool_link_mode); \
1499 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1500 * @netdev: network interface device structure
1501 * @ks: ethtool link ksettings struct to fill out
1504 ice_phy_type_to_ethtool(struct net_device *netdev,
1505 struct ethtool_link_ksettings *ks)
1507 struct ice_netdev_priv *np = netdev_priv(netdev);
1508 struct ice_vsi *vsi = np->vsi;
1509 struct ice_pf *pf = vsi->back;
1510 u64 advert_phy_type_lo = 0;
1511 u64 advert_phy_type_hi = 0;
1512 u64 phy_type_mask_lo = 0;
1513 u64 phy_type_mask_hi = 0;
1514 u64 phy_types_high = 0;
1515 u64 phy_types_low = 0;
1518 req_speeds = vsi->port_info->phy.link_info.req_speeds;
1520 /* Check if lenient mode is supported and enabled, or in strict mode.
1522 * In lenient mode the Supported link modes are the PHY types without
1523 * media. The Advertising link mode is either 1. the user requested
1524 * speed, 2. the override PHY mask, or 3. the PHY types with media.
1526 * In strict mode Supported link mode are the PHY type with media,
1527 * and Advertising link modes are the media PHY type or the speed
1528 * requested by user.
1530 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
1531 phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo);
1532 phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi);
1534 ice_mask_min_supported_speeds(phy_types_high, &phy_types_low);
1535 /* determine advertised modes based on link override only
1536 * if it's supported and if the FW doesn't abstract the
1537 * driver from having to account for link overrides
1539 if (ice_fw_supports_link_override(&pf->hw) &&
1540 !ice_fw_supports_report_dflt_cfg(&pf->hw)) {
1541 struct ice_link_default_override_tlv *ldo;
1543 ldo = &pf->link_dflt_override;
1544 /* If override enabled and PHY mask set, then
1545 * Advertising link mode is the intersection of the PHY
1546 * types without media and the override PHY mask.
1548 if (ldo->options & ICE_LINK_OVERRIDE_EN &&
1549 (ldo->phy_type_low || ldo->phy_type_high)) {
1550 advert_phy_type_lo =
1551 le64_to_cpu(pf->nvm_phy_type_lo) &
1553 advert_phy_type_hi =
1554 le64_to_cpu(pf->nvm_phy_type_hi) &
1560 phy_types_low = vsi->port_info->phy.phy_type_low;
1561 phy_types_high = vsi->port_info->phy.phy_type_high;
1564 /* If Advertising link mode PHY type is not using override PHY type,
1565 * then use PHY type with media.
1567 if (!advert_phy_type_lo && !advert_phy_type_hi) {
1568 advert_phy_type_lo = vsi->port_info->phy.phy_type_low;
1569 advert_phy_type_hi = vsi->port_info->phy.phy_type_high;
1572 ethtool_link_ksettings_zero_link_mode(ks, supported);
1573 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1575 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100BASE_TX |
1576 ICE_PHY_TYPE_LOW_100M_SGMII;
1577 if (phy_types_low & phy_type_mask_lo) {
1578 ethtool_link_ksettings_add_link_mode(ks, supported,
1581 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100MB,
1585 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_T |
1586 ICE_PHY_TYPE_LOW_1G_SGMII;
1587 if (phy_types_low & phy_type_mask_lo) {
1588 ethtool_link_ksettings_add_link_mode(ks, supported,
1590 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1594 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_KX;
1595 if (phy_types_low & phy_type_mask_lo) {
1596 ethtool_link_ksettings_add_link_mode(ks, supported,
1598 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1602 phy_type_mask_lo = ICE_PHY_TYPE_LOW_1000BASE_SX |
1603 ICE_PHY_TYPE_LOW_1000BASE_LX;
1604 if (phy_types_low & phy_type_mask_lo) {
1605 ethtool_link_ksettings_add_link_mode(ks, supported,
1607 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_1000MB,
1611 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_T;
1612 if (phy_types_low & phy_type_mask_lo) {
1613 ethtool_link_ksettings_add_link_mode(ks, supported,
1615 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_2500MB,
1619 phy_type_mask_lo = ICE_PHY_TYPE_LOW_2500BASE_X |
1620 ICE_PHY_TYPE_LOW_2500BASE_KX;
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_2500MB,
1628 phy_type_mask_lo = ICE_PHY_TYPE_LOW_5GBASE_T |
1629 ICE_PHY_TYPE_LOW_5GBASE_KR;
1630 if (phy_types_low & phy_type_mask_lo) {
1631 ethtool_link_ksettings_add_link_mode(ks, supported,
1633 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_5GB,
1637 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_T |
1638 ICE_PHY_TYPE_LOW_10G_SFI_DA |
1639 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC |
1640 ICE_PHY_TYPE_LOW_10G_SFI_C2C;
1641 if (phy_types_low & phy_type_mask_lo) {
1642 ethtool_link_ksettings_add_link_mode(ks, supported,
1644 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1648 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_KR_CR1;
1649 if (phy_types_low & phy_type_mask_lo) {
1650 ethtool_link_ksettings_add_link_mode(ks, supported,
1652 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1656 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_SR;
1657 if (phy_types_low & phy_type_mask_lo) {
1658 ethtool_link_ksettings_add_link_mode(ks, supported,
1660 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1664 phy_type_mask_lo = ICE_PHY_TYPE_LOW_10GBASE_LR;
1665 if (phy_types_low & phy_type_mask_lo) {
1666 ethtool_link_ksettings_add_link_mode(ks, supported,
1668 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_10GB,
1672 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_T |
1673 ICE_PHY_TYPE_LOW_25GBASE_CR |
1674 ICE_PHY_TYPE_LOW_25GBASE_CR_S |
1675 ICE_PHY_TYPE_LOW_25GBASE_CR1 |
1676 ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC |
1677 ICE_PHY_TYPE_LOW_25G_AUI_C2C;
1678 if (phy_types_low & phy_type_mask_lo) {
1679 ethtool_link_ksettings_add_link_mode(ks, supported,
1681 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1685 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_SR |
1686 ICE_PHY_TYPE_LOW_25GBASE_LR;
1687 if (phy_types_low & phy_type_mask_lo) {
1688 ethtool_link_ksettings_add_link_mode(ks, supported,
1690 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1694 phy_type_mask_lo = ICE_PHY_TYPE_LOW_25GBASE_KR |
1695 ICE_PHY_TYPE_LOW_25GBASE_KR_S |
1696 ICE_PHY_TYPE_LOW_25GBASE_KR1;
1697 if (phy_types_low & phy_type_mask_lo) {
1698 ethtool_link_ksettings_add_link_mode(ks, supported,
1700 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_25GB,
1704 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_KR4;
1705 if (phy_types_low & phy_type_mask_lo) {
1706 ethtool_link_ksettings_add_link_mode(ks, supported,
1708 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1712 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_CR4 |
1713 ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC |
1714 ICE_PHY_TYPE_LOW_40G_XLAUI;
1715 if (phy_types_low & phy_type_mask_lo) {
1716 ethtool_link_ksettings_add_link_mode(ks, supported,
1718 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1722 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_SR4;
1723 if (phy_types_low & phy_type_mask_lo) {
1724 ethtool_link_ksettings_add_link_mode(ks, supported,
1726 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1730 phy_type_mask_lo = ICE_PHY_TYPE_LOW_40GBASE_LR4;
1731 if (phy_types_low & phy_type_mask_lo) {
1732 ethtool_link_ksettings_add_link_mode(ks, supported,
1734 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_40GB,
1738 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_CR2 |
1739 ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC |
1740 ICE_PHY_TYPE_LOW_50G_LAUI2 |
1741 ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC |
1742 ICE_PHY_TYPE_LOW_50G_AUI2 |
1743 ICE_PHY_TYPE_LOW_50GBASE_CP |
1744 ICE_PHY_TYPE_LOW_50GBASE_SR |
1745 ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC |
1746 ICE_PHY_TYPE_LOW_50G_AUI1;
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_50GBASE_KR2 |
1755 ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4;
1756 if (phy_types_low & phy_type_mask_lo) {
1757 ethtool_link_ksettings_add_link_mode(ks, supported,
1759 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB,
1763 phy_type_mask_lo = ICE_PHY_TYPE_LOW_50GBASE_SR2 |
1764 ICE_PHY_TYPE_LOW_50GBASE_LR2 |
1765 ICE_PHY_TYPE_LOW_50GBASE_FR |
1766 ICE_PHY_TYPE_LOW_50GBASE_LR;
1767 if (phy_types_low & phy_type_mask_lo) {
1768 ethtool_link_ksettings_add_link_mode(ks, supported,
1770 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_50GB,
1774 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_CR4 |
1775 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC |
1776 ICE_PHY_TYPE_LOW_100G_CAUI4 |
1777 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC |
1778 ICE_PHY_TYPE_LOW_100G_AUI4 |
1779 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 |
1780 ICE_PHY_TYPE_LOW_100GBASE_CP2;
1781 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |
1782 ICE_PHY_TYPE_HIGH_100G_CAUI2 |
1783 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC |
1784 ICE_PHY_TYPE_HIGH_100G_AUI2;
1785 if (phy_types_low & phy_type_mask_lo ||
1786 phy_types_high & phy_type_mask_hi) {
1787 ethtool_link_ksettings_add_link_mode(ks, supported,
1788 100000baseCR4_Full);
1789 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1790 100000baseCR4_Full);
1793 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_SR4 |
1794 ICE_PHY_TYPE_LOW_100GBASE_SR2;
1795 if (phy_types_low & phy_type_mask_lo) {
1796 ethtool_link_ksettings_add_link_mode(ks, supported,
1797 100000baseSR4_Full);
1798 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1799 100000baseSR4_Full);
1802 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_LR4 |
1803 ICE_PHY_TYPE_LOW_100GBASE_DR;
1804 if (phy_types_low & phy_type_mask_lo) {
1805 ethtool_link_ksettings_add_link_mode(ks, supported,
1806 100000baseLR4_ER4_Full);
1807 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1808 100000baseLR4_ER4_Full);
1811 phy_type_mask_lo = ICE_PHY_TYPE_LOW_100GBASE_KR4 |
1812 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4;
1813 phy_type_mask_hi = ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4;
1814 if (phy_types_low & phy_type_mask_lo ||
1815 phy_types_high & phy_type_mask_hi) {
1816 ethtool_link_ksettings_add_link_mode(ks, supported,
1817 100000baseKR4_Full);
1818 ice_ethtool_advertise_link_mode(ICE_AQ_LINK_SPEED_100GB,
1819 100000baseKR4_Full);
1823 #define TEST_SET_BITS_TIMEOUT 50
1824 #define TEST_SET_BITS_SLEEP_MAX 2000
1825 #define TEST_SET_BITS_SLEEP_MIN 1000
1828 * ice_get_settings_link_up - Get Link settings for when link is up
1829 * @ks: ethtool ksettings to fill in
1830 * @netdev: network interface device structure
1833 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1834 struct net_device *netdev)
1836 struct ice_netdev_priv *np = netdev_priv(netdev);
1837 struct ice_port_info *pi = np->vsi->port_info;
1838 struct ice_link_status *link_info;
1839 struct ice_vsi *vsi = np->vsi;
1841 link_info = &vsi->port_info->phy.link_info;
1843 /* Get supported and advertised settings from PHY ability with media */
1844 ice_phy_type_to_ethtool(netdev, ks);
1846 switch (link_info->link_speed) {
1847 case ICE_AQ_LINK_SPEED_100GB:
1848 ks->base.speed = SPEED_100000;
1850 case ICE_AQ_LINK_SPEED_50GB:
1851 ks->base.speed = SPEED_50000;
1853 case ICE_AQ_LINK_SPEED_40GB:
1854 ks->base.speed = SPEED_40000;
1856 case ICE_AQ_LINK_SPEED_25GB:
1857 ks->base.speed = SPEED_25000;
1859 case ICE_AQ_LINK_SPEED_20GB:
1860 ks->base.speed = SPEED_20000;
1862 case ICE_AQ_LINK_SPEED_10GB:
1863 ks->base.speed = SPEED_10000;
1865 case ICE_AQ_LINK_SPEED_5GB:
1866 ks->base.speed = SPEED_5000;
1868 case ICE_AQ_LINK_SPEED_2500MB:
1869 ks->base.speed = SPEED_2500;
1871 case ICE_AQ_LINK_SPEED_1000MB:
1872 ks->base.speed = SPEED_1000;
1874 case ICE_AQ_LINK_SPEED_100MB:
1875 ks->base.speed = SPEED_100;
1878 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1879 link_info->link_speed);
1882 ks->base.duplex = DUPLEX_FULL;
1884 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1885 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1888 /* Set flow control negotiated Rx/Tx pause */
1889 switch (pi->fc.current_mode) {
1891 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1893 case ICE_FC_TX_PAUSE:
1894 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1895 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1898 case ICE_FC_RX_PAUSE:
1899 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1904 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1905 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1912 * ice_get_settings_link_down - Get the Link settings when link is down
1913 * @ks: ethtool ksettings to fill in
1914 * @netdev: network interface device structure
1916 * Reports link settings that can be determined when link is down
1919 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1920 struct net_device *netdev)
1922 /* link is down and the driver needs to fall back on
1923 * supported PHY types to figure out what info to display
1925 ice_phy_type_to_ethtool(netdev, ks);
1927 /* With no link, speed and duplex are unknown */
1928 ks->base.speed = SPEED_UNKNOWN;
1929 ks->base.duplex = DUPLEX_UNKNOWN;
1933 * ice_get_link_ksettings - Get Link Speed and Duplex settings
1934 * @netdev: network interface device structure
1935 * @ks: ethtool ksettings
1937 * Reports speed/duplex settings based on media_type
1940 ice_get_link_ksettings(struct net_device *netdev,
1941 struct ethtool_link_ksettings *ks)
1943 struct ice_netdev_priv *np = netdev_priv(netdev);
1944 struct ice_aqc_get_phy_caps_data *caps;
1945 struct ice_link_status *hw_link_info;
1946 struct ice_vsi *vsi = np->vsi;
1949 ethtool_link_ksettings_zero_link_mode(ks, supported);
1950 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1951 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1952 hw_link_info = &vsi->port_info->phy.link_info;
1954 /* set speed and duplex */
1955 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1956 ice_get_settings_link_up(ks, netdev);
1958 ice_get_settings_link_down(ks, netdev);
1960 /* set autoneg settings */
1961 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1962 AUTONEG_ENABLE : AUTONEG_DISABLE;
1964 /* set media type settings */
1965 switch (vsi->port_info->phy.media_type) {
1966 case ICE_MEDIA_FIBER:
1967 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1968 ks->base.port = PORT_FIBRE;
1970 case ICE_MEDIA_BASET:
1971 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1972 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1973 ks->base.port = PORT_TP;
1975 case ICE_MEDIA_BACKPLANE:
1976 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1977 ethtool_link_ksettings_add_link_mode(ks, advertising,
1979 ks->base.port = PORT_NONE;
1982 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1983 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1984 ks->base.port = PORT_DA;
1987 ks->base.port = PORT_OTHER;
1991 /* flow control is symmetric and always supported */
1992 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1994 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1998 err = ice_aq_get_phy_caps(vsi->port_info, false,
1999 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
2003 /* Set the advertised flow control based on the PHY capability */
2004 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
2005 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
2006 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2007 ethtool_link_ksettings_add_link_mode(ks, advertising,
2009 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
2010 ethtool_link_ksettings_add_link_mode(ks, advertising,
2012 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
2013 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2014 ethtool_link_ksettings_add_link_mode(ks, advertising,
2017 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2018 ethtool_link_ksettings_del_link_mode(ks, advertising,
2022 /* Set advertised FEC modes based on PHY capability */
2023 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2025 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2026 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2027 ethtool_link_ksettings_add_link_mode(ks, advertising,
2029 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2030 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2031 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2033 err = ice_aq_get_phy_caps(vsi->port_info, false,
2034 ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL);
2038 /* Set supported FEC modes based on PHY capability */
2039 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2041 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2042 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2043 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2044 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2045 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2047 /* Set supported and advertised autoneg */
2048 if (ice_is_phy_caps_an_enabled(caps)) {
2049 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2050 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2059 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2060 * @ks: ethtool ksettings
2063 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2065 u16 adv_link_speed = 0;
2067 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2069 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2070 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2072 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2073 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2075 ethtool_link_ksettings_test_link_mode(ks, advertising,
2077 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2078 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2080 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2081 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2083 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2084 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2086 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2087 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2089 ethtool_link_ksettings_test_link_mode(ks, advertising,
2091 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2092 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2093 10000baseSR_Full) ||
2094 ethtool_link_ksettings_test_link_mode(ks, advertising,
2096 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2097 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2098 25000baseCR_Full) ||
2099 ethtool_link_ksettings_test_link_mode(ks, advertising,
2100 25000baseSR_Full) ||
2101 ethtool_link_ksettings_test_link_mode(ks, advertising,
2103 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2104 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2105 40000baseCR4_Full) ||
2106 ethtool_link_ksettings_test_link_mode(ks, advertising,
2107 40000baseSR4_Full) ||
2108 ethtool_link_ksettings_test_link_mode(ks, advertising,
2109 40000baseLR4_Full) ||
2110 ethtool_link_ksettings_test_link_mode(ks, advertising,
2112 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2113 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2114 50000baseCR2_Full) ||
2115 ethtool_link_ksettings_test_link_mode(ks, advertising,
2117 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2118 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2120 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2121 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2122 100000baseCR4_Full) ||
2123 ethtool_link_ksettings_test_link_mode(ks, advertising,
2124 100000baseSR4_Full) ||
2125 ethtool_link_ksettings_test_link_mode(ks, advertising,
2126 100000baseLR4_ER4_Full) ||
2127 ethtool_link_ksettings_test_link_mode(ks, advertising,
2128 100000baseKR4_Full))
2129 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2131 return adv_link_speed;
2137 * @ks: ethtool_link_ksettings
2138 * @config: configuration that will be sent down to FW
2139 * @autoneg_enabled: autonegotiation is enabled or not
2140 * @autoneg_changed: will there a change in autonegotiation
2141 * @netdev: network interface device structure
2143 * Setup PHY autonegotiation feature
2146 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2147 struct ice_aqc_set_phy_cfg_data *config,
2148 u8 autoneg_enabled, u8 *autoneg_changed,
2149 struct net_device *netdev)
2153 *autoneg_changed = 0;
2156 if (autoneg_enabled == AUTONEG_ENABLE) {
2157 /* If autoneg was not already enabled */
2158 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2159 /* If autoneg is not supported, return error */
2160 if (!ethtool_link_ksettings_test_link_mode(ks,
2163 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2166 /* Autoneg is allowed to change */
2167 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2168 *autoneg_changed = 1;
2172 /* If autoneg is currently enabled */
2173 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2174 /* If autoneg is supported 10GBASE_T is the only PHY
2175 * that can disable it, so otherwise return error
2177 if (ethtool_link_ksettings_test_link_mode(ks,
2180 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2183 /* Autoneg is allowed to change */
2184 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2185 *autoneg_changed = 1;
2194 * ice_set_phy_type_from_speed - set phy_types based on speeds
2195 * and advertised modes
2196 * @ks: ethtool link ksettings struct
2197 * @phy_type_low: pointer to the lower part of phy_type
2198 * @phy_type_high: pointer to the higher part of phy_type
2199 * @adv_link_speed: targeted link speeds bitmap
2202 ice_set_phy_type_from_speed(const struct ethtool_link_ksettings *ks,
2203 u64 *phy_type_low, u64 *phy_type_high,
2206 /* Handle 1000M speed in a special way because ice_update_phy_type
2207 * enables all link modes, but having mixed copper and optical
2208 * standards is not supported.
2210 adv_link_speed &= ~ICE_AQ_LINK_SPEED_1000MB;
2212 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2214 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_T |
2215 ICE_PHY_TYPE_LOW_1G_SGMII;
2217 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2219 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_KX;
2221 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2223 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_SX |
2224 ICE_PHY_TYPE_LOW_1000BASE_LX;
2226 ice_update_phy_type(phy_type_low, phy_type_high, adv_link_speed);
2230 * ice_set_link_ksettings - Set Speed and Duplex
2231 * @netdev: network interface device structure
2232 * @ks: ethtool ksettings
2234 * Set speed/duplex per media_types advertised/forced
2237 ice_set_link_ksettings(struct net_device *netdev,
2238 const struct ethtool_link_ksettings *ks)
2240 struct ice_netdev_priv *np = netdev_priv(netdev);
2241 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT;
2242 struct ethtool_link_ksettings copy_ks = *ks;
2243 struct ethtool_link_ksettings safe_ks = {};
2244 struct ice_aqc_get_phy_caps_data *phy_caps;
2245 struct ice_aqc_set_phy_cfg_data config;
2246 u16 adv_link_speed, curr_link_speed;
2247 struct ice_pf *pf = np->vsi->back;
2248 struct ice_port_info *pi;
2249 u8 autoneg_changed = 0;
2250 u64 phy_type_high = 0;
2251 u64 phy_type_low = 0;
2255 pi = np->vsi->port_info;
2260 if (pi->phy.media_type != ICE_MEDIA_BASET &&
2261 pi->phy.media_type != ICE_MEDIA_FIBER &&
2262 pi->phy.media_type != ICE_MEDIA_BACKPLANE &&
2263 pi->phy.media_type != ICE_MEDIA_DA &&
2264 pi->phy.link_info.link_info & ICE_AQ_LINK_UP)
2267 phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL);
2271 /* Get the PHY capabilities based on media */
2272 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2273 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2276 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2281 /* save autoneg out of ksettings */
2282 autoneg = copy_ks.base.autoneg;
2284 /* Get link modes supported by hardware.*/
2285 ice_phy_type_to_ethtool(netdev, &safe_ks);
2287 /* and check against modes requested by user.
2288 * Return an error if unsupported mode was set.
2290 if (!bitmap_subset(copy_ks.link_modes.advertising,
2291 safe_ks.link_modes.supported,
2292 __ETHTOOL_LINK_MODE_MASK_NBITS)) {
2293 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags))
2294 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");
2299 /* get our own copy of the bits to check against */
2300 memset(&safe_ks, 0, sizeof(safe_ks));
2301 safe_ks.base.cmd = copy_ks.base.cmd;
2302 safe_ks.base.link_mode_masks_nwords =
2303 copy_ks.base.link_mode_masks_nwords;
2304 ice_get_link_ksettings(netdev, &safe_ks);
2306 /* set autoneg back to what it currently is */
2307 copy_ks.base.autoneg = safe_ks.base.autoneg;
2308 /* we don't compare the speed */
2309 copy_ks.base.speed = safe_ks.base.speed;
2311 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2312 * trying to set something that we do not support.
2314 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) {
2319 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2325 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2328 /* Copy the current user PHY configuration. The current user PHY
2329 * configuration is initialized during probe from PHY capabilities
2330 * software mode, and updated on set PHY configuration.
2332 config = pi->phy.curr_user_phy_cfg;
2334 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2337 err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed,
2343 /* Call to get the current link speed */
2344 pi->phy.get_link_info = true;
2345 err = ice_get_link_status(pi, &linkup);
2349 curr_link_speed = pi->phy.curr_user_speed_req;
2350 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2352 /* If speed didn't get set, set it to what it currently is.
2353 * This is needed because if advertise is 0 (as it is when autoneg
2354 * is disabled) then speed won't get set.
2356 if (!adv_link_speed)
2357 adv_link_speed = curr_link_speed;
2359 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2360 ice_set_phy_type_from_speed(ks, &phy_type_low, &phy_type_high,
2363 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2364 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2368 /* save the requested speeds */
2369 pi->phy.link_info.req_speeds = adv_link_speed;
2371 /* set link and auto negotiation so changes take effect */
2372 config.caps |= ICE_AQ_PHY_ENA_LINK;
2374 /* check if there is a PHY type for the requested advertised speed */
2375 if (!(phy_type_low || phy_type_high)) {
2376 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");
2381 /* intersect requested advertised speed PHY types with media PHY types
2382 * for set PHY configuration
2384 config.phy_type_high = cpu_to_le64(phy_type_high) &
2385 phy_caps->phy_type_high;
2386 config.phy_type_low = cpu_to_le64(phy_type_low) &
2387 phy_caps->phy_type_low;
2389 if (!(config.phy_type_high || config.phy_type_low)) {
2390 /* If there is no intersection and lenient mode is enabled, then
2391 * intersect the requested advertised speed with NVM media type
2394 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2395 config.phy_type_high = cpu_to_le64(phy_type_high) &
2396 pf->nvm_phy_type_hi;
2397 config.phy_type_low = cpu_to_le64(phy_type_low) &
2398 pf->nvm_phy_type_lo;
2400 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");
2406 /* If link is up put link down */
2407 if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2408 /* Tell the OS link is going down, the link will go
2409 * back up when fw says it is ready asynchronously
2411 ice_print_link_msg(np->vsi, false);
2412 netif_carrier_off(netdev);
2413 netif_tx_stop_all_queues(netdev);
2416 /* make the aq call */
2417 err = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL);
2419 netdev_info(netdev, "Set phy config failed,\n");
2423 /* Save speed request */
2424 pi->phy.curr_user_speed_req = adv_link_speed;
2427 clear_bit(ICE_CFG_BUSY, pf->state);
2433 * ice_parse_hdrs - parses headers from RSS hash input
2434 * @nfc: ethtool rxnfc command
2436 * This function parses the rxnfc command and returns intended
2437 * header types for RSS configuration
2439 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2441 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2443 switch (nfc->flow_type) {
2445 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2448 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2451 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2454 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2457 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2460 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2468 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2469 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2470 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2471 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2472 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2473 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2474 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2475 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2476 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2477 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2478 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2479 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2482 * ice_parse_hash_flds - parses hash fields from RSS hash input
2483 * @nfc: ethtool rxnfc command
2485 * This function parses the rxnfc command and returns intended
2486 * hash fields for RSS configuration
2488 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2490 u64 hfld = ICE_HASH_INVALID;
2492 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2493 switch (nfc->flow_type) {
2497 if (nfc->data & RXH_IP_SRC)
2498 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2499 if (nfc->data & RXH_IP_DST)
2500 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2505 if (nfc->data & RXH_IP_SRC)
2506 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2507 if (nfc->data & RXH_IP_DST)
2508 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2515 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2516 switch (nfc->flow_type) {
2519 if (nfc->data & RXH_L4_B_0_1)
2520 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2521 if (nfc->data & RXH_L4_B_2_3)
2522 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2526 if (nfc->data & RXH_L4_B_0_1)
2527 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2528 if (nfc->data & RXH_L4_B_2_3)
2529 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2533 if (nfc->data & RXH_L4_B_0_1)
2534 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2535 if (nfc->data & RXH_L4_B_2_3)
2536 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2547 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2548 * @vsi: the VSI being configured
2549 * @nfc: ethtool rxnfc command
2551 * Returns Success if the flow input set is supported.
2554 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2556 struct ice_pf *pf = vsi->back;
2562 dev = ice_pf_to_dev(pf);
2563 if (ice_is_safe_mode(pf)) {
2564 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2569 hashed_flds = ice_parse_hash_flds(nfc);
2570 if (hashed_flds == ICE_HASH_INVALID) {
2571 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2576 hdrs = ice_parse_hdrs(nfc);
2577 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2578 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2583 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2585 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
2586 vsi->vsi_num, status);
2594 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2595 * @vsi: the VSI being configured
2596 * @nfc: ethtool rxnfc command
2599 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2601 struct ice_pf *pf = vsi->back;
2606 dev = ice_pf_to_dev(pf);
2609 if (ice_is_safe_mode(pf)) {
2610 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2615 hdrs = ice_parse_hdrs(nfc);
2616 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2617 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2622 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2623 if (hash_flds == ICE_HASH_INVALID) {
2624 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2629 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2630 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2631 nfc->data |= (u64)RXH_IP_SRC;
2633 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2634 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2635 nfc->data |= (u64)RXH_IP_DST;
2637 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2638 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2639 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2640 nfc->data |= (u64)RXH_L4_B_0_1;
2642 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2643 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2644 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2645 nfc->data |= (u64)RXH_L4_B_2_3;
2649 * ice_set_rxnfc - command to set Rx flow rules.
2650 * @netdev: network interface device structure
2651 * @cmd: ethtool rxnfc command
2653 * Returns 0 for success and negative values for errors
2655 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2657 struct ice_netdev_priv *np = netdev_priv(netdev);
2658 struct ice_vsi *vsi = np->vsi;
2661 case ETHTOOL_SRXCLSRLINS:
2662 return ice_add_fdir_ethtool(vsi, cmd);
2663 case ETHTOOL_SRXCLSRLDEL:
2664 return ice_del_fdir_ethtool(vsi, cmd);
2666 return ice_set_rss_hash_opt(vsi, cmd);
2674 * ice_get_rxnfc - command to get Rx flow classification rules
2675 * @netdev: network interface device structure
2676 * @cmd: ethtool rxnfc command
2677 * @rule_locs: buffer to rturn Rx flow classification rules
2679 * Returns Success if the command is supported.
2682 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2683 u32 __always_unused *rule_locs)
2685 struct ice_netdev_priv *np = netdev_priv(netdev);
2686 struct ice_vsi *vsi = np->vsi;
2687 int ret = -EOPNOTSUPP;
2690 hw = &vsi->back->hw;
2693 case ETHTOOL_GRXRINGS:
2694 cmd->data = vsi->rss_size;
2697 case ETHTOOL_GRXCLSRLCNT:
2698 cmd->rule_cnt = hw->fdir_active_fltr;
2699 /* report total rule count */
2700 cmd->data = ice_get_fdir_cnt_all(hw);
2703 case ETHTOOL_GRXCLSRULE:
2704 ret = ice_get_ethtool_fdir_entry(hw, cmd);
2706 case ETHTOOL_GRXCLSRLALL:
2707 ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs);
2710 ice_get_rss_hash_opt(vsi, cmd);
2721 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
2722 struct kernel_ethtool_ringparam *kernel_ring,
2723 struct netlink_ext_ack *extack)
2725 struct ice_netdev_priv *np = netdev_priv(netdev);
2726 struct ice_vsi *vsi = np->vsi;
2728 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2729 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2730 ring->rx_pending = vsi->rx_rings[0]->count;
2731 ring->tx_pending = vsi->tx_rings[0]->count;
2733 /* Rx mini and jumbo rings are not supported */
2734 ring->rx_mini_max_pending = 0;
2735 ring->rx_jumbo_max_pending = 0;
2736 ring->rx_mini_pending = 0;
2737 ring->rx_jumbo_pending = 0;
2741 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
2742 struct kernel_ethtool_ringparam *kernel_ring,
2743 struct netlink_ext_ack *extack)
2745 struct ice_netdev_priv *np = netdev_priv(netdev);
2746 struct ice_tx_ring *xdp_rings = NULL;
2747 struct ice_tx_ring *tx_rings = NULL;
2748 struct ice_rx_ring *rx_rings = NULL;
2749 struct ice_vsi *vsi = np->vsi;
2750 struct ice_pf *pf = vsi->back;
2751 int i, timeout = 50, err = 0;
2752 u16 new_rx_cnt, new_tx_cnt;
2754 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2755 ring->tx_pending < ICE_MIN_NUM_DESC ||
2756 ring->rx_pending > ICE_MAX_NUM_DESC ||
2757 ring->rx_pending < ICE_MIN_NUM_DESC) {
2758 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2759 ring->tx_pending, ring->rx_pending,
2760 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2761 ICE_REQ_DESC_MULTIPLE);
2765 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2766 if (new_tx_cnt != ring->tx_pending)
2767 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2769 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2770 if (new_rx_cnt != ring->rx_pending)
2771 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2774 /* if nothing to do return success */
2775 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2776 new_rx_cnt == vsi->rx_rings[0]->count) {
2777 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2781 /* If there is a AF_XDP UMEM attached to any of Rx rings,
2782 * disallow changing the number of descriptors -- regardless
2783 * if the netdev is running or not.
2785 if (ice_xsk_any_rx_ring_ena(vsi))
2788 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2792 usleep_range(1000, 2000);
2795 /* set for the next time the netdev is started */
2796 if (!netif_running(vsi->netdev)) {
2797 ice_for_each_alloc_txq(vsi, i)
2798 vsi->tx_rings[i]->count = new_tx_cnt;
2799 ice_for_each_alloc_rxq(vsi, i)
2800 vsi->rx_rings[i]->count = new_rx_cnt;
2801 if (ice_is_xdp_ena_vsi(vsi))
2802 ice_for_each_xdp_txq(vsi, i)
2803 vsi->xdp_rings[i]->count = new_tx_cnt;
2804 vsi->num_tx_desc = (u16)new_tx_cnt;
2805 vsi->num_rx_desc = (u16)new_rx_cnt;
2806 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2810 if (new_tx_cnt == vsi->tx_rings[0]->count)
2813 /* alloc updated Tx resources */
2814 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2815 vsi->tx_rings[0]->count, new_tx_cnt);
2817 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2823 ice_for_each_txq(vsi, i) {
2824 /* clone ring and setup updated count */
2825 tx_rings[i] = *vsi->tx_rings[i];
2826 tx_rings[i].count = new_tx_cnt;
2827 tx_rings[i].desc = NULL;
2828 tx_rings[i].tx_buf = NULL;
2829 err = ice_setup_tx_ring(&tx_rings[i]);
2832 ice_clean_tx_ring(&tx_rings[i]);
2838 if (!ice_is_xdp_ena_vsi(vsi))
2841 /* alloc updated XDP resources */
2842 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2843 vsi->xdp_rings[0]->count, new_tx_cnt);
2845 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2851 ice_for_each_xdp_txq(vsi, i) {
2852 /* clone ring and setup updated count */
2853 xdp_rings[i] = *vsi->xdp_rings[i];
2854 xdp_rings[i].count = new_tx_cnt;
2855 xdp_rings[i].next_dd = ICE_RING_QUARTER(&xdp_rings[i]) - 1;
2856 xdp_rings[i].next_rs = ICE_RING_QUARTER(&xdp_rings[i]) - 1;
2857 xdp_rings[i].desc = NULL;
2858 xdp_rings[i].tx_buf = NULL;
2859 err = ice_setup_tx_ring(&xdp_rings[i]);
2862 ice_clean_tx_ring(&xdp_rings[i]);
2866 ice_set_ring_xdp(&xdp_rings[i]);
2870 if (new_rx_cnt == vsi->rx_rings[0]->count)
2873 /* alloc updated Rx resources */
2874 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2875 vsi->rx_rings[0]->count, new_rx_cnt);
2877 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2883 ice_for_each_rxq(vsi, i) {
2884 /* clone ring and setup updated count */
2885 rx_rings[i] = *vsi->rx_rings[i];
2886 rx_rings[i].count = new_rx_cnt;
2887 rx_rings[i].desc = NULL;
2888 rx_rings[i].rx_buf = NULL;
2889 /* this is to allow wr32 to have something to write to
2890 * during early allocation of Rx buffers
2892 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2894 err = ice_setup_rx_ring(&rx_rings[i]);
2898 /* allocate Rx buffers */
2899 err = ice_alloc_rx_bufs(&rx_rings[i],
2900 ICE_DESC_UNUSED(&rx_rings[i]));
2905 ice_free_rx_ring(&rx_rings[i]);
2914 /* Bring interface down, copy in the new ring info, then restore the
2915 * interface. if VSI is up, bring it down and then back up
2917 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2921 ice_for_each_txq(vsi, i) {
2922 ice_free_tx_ring(vsi->tx_rings[i]);
2923 *vsi->tx_rings[i] = tx_rings[i];
2929 ice_for_each_rxq(vsi, i) {
2930 ice_free_rx_ring(vsi->rx_rings[i]);
2931 /* copy the real tail offset */
2932 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2933 /* this is to fake out the allocation routine
2934 * into thinking it has to realloc everything
2935 * but the recycling logic will let us re-use
2936 * the buffers allocated above
2938 rx_rings[i].next_to_use = 0;
2939 rx_rings[i].next_to_clean = 0;
2940 rx_rings[i].next_to_alloc = 0;
2941 *vsi->rx_rings[i] = rx_rings[i];
2947 ice_for_each_xdp_txq(vsi, i) {
2948 ice_free_tx_ring(vsi->xdp_rings[i]);
2949 *vsi->xdp_rings[i] = xdp_rings[i];
2954 vsi->num_tx_desc = new_tx_cnt;
2955 vsi->num_rx_desc = new_rx_cnt;
2961 /* error cleanup if the Rx allocations failed after getting Tx */
2963 ice_for_each_txq(vsi, i)
2964 ice_free_tx_ring(&tx_rings[i]);
2969 clear_bit(ICE_CFG_BUSY, pf->state);
2974 * ice_get_pauseparam - Get Flow Control status
2975 * @netdev: network interface device structure
2976 * @pause: ethernet pause (flow control) parameters
2978 * Get requested flow control status from PHY capability.
2979 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2980 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2981 * the negotiated Rx/Tx pause via lp_advertising.
2984 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2986 struct ice_netdev_priv *np = netdev_priv(netdev);
2987 struct ice_port_info *pi = np->vsi->port_info;
2988 struct ice_aqc_get_phy_caps_data *pcaps;
2989 struct ice_dcbx_cfg *dcbx_cfg;
2992 /* Initialize pause params */
2993 pause->rx_pause = 0;
2994 pause->tx_pause = 0;
2996 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
2998 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3002 /* Get current PHY config */
3003 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3008 pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3011 if (dcbx_cfg->pfc.pfcena)
3012 /* PFC enabled so report LFC as off */
3015 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
3016 pause->tx_pause = 1;
3017 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
3018 pause->rx_pause = 1;
3025 * ice_set_pauseparam - Set Flow Control parameter
3026 * @netdev: network interface device structure
3027 * @pause: return Tx/Rx flow control status
3030 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3032 struct ice_netdev_priv *np = netdev_priv(netdev);
3033 struct ice_aqc_get_phy_caps_data *pcaps;
3034 struct ice_link_status *hw_link_info;
3035 struct ice_pf *pf = np->vsi->back;
3036 struct ice_dcbx_cfg *dcbx_cfg;
3037 struct ice_vsi *vsi = np->vsi;
3038 struct ice_hw *hw = &pf->hw;
3039 struct ice_port_info *pi;
3045 pi = vsi->port_info;
3046 hw_link_info = &pi->phy.link_info;
3047 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3048 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
3050 /* Changing the port's flow control is not supported if this isn't the
3053 if (vsi->type != ICE_VSI_PF) {
3054 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
3058 /* Get pause param reports configured and negotiated flow control pause
3059 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
3060 * defined get pause param pause->autoneg reports SW configured setting,
3061 * so compare pause->autoneg with SW configured to prevent the user from
3062 * using set pause param to chance autoneg.
3064 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3068 /* Get current PHY config */
3069 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3076 is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3081 if (pause->autoneg != is_an) {
3082 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
3086 /* If we have link and don't have autoneg */
3087 if (!test_bit(ICE_DOWN, pf->state) &&
3088 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
3089 /* Send message that it might not necessarily work*/
3090 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
3093 if (dcbx_cfg->pfc.pfcena) {
3094 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
3097 if (pause->rx_pause && pause->tx_pause)
3098 pi->fc.req_mode = ICE_FC_FULL;
3099 else if (pause->rx_pause && !pause->tx_pause)
3100 pi->fc.req_mode = ICE_FC_RX_PAUSE;
3101 else if (!pause->rx_pause && pause->tx_pause)
3102 pi->fc.req_mode = ICE_FC_TX_PAUSE;
3103 else if (!pause->rx_pause && !pause->tx_pause)
3104 pi->fc.req_mode = ICE_FC_NONE;
3108 /* Set the FC mode and only restart AN if link is up */
3109 err = ice_set_fc(pi, &aq_failures, link_up);
3111 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
3112 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n",
3113 err, ice_aq_str(hw->adminq.sq_last_status));
3115 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
3116 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %s\n",
3117 err, ice_aq_str(hw->adminq.sq_last_status));
3119 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
3120 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %s\n",
3121 err, ice_aq_str(hw->adminq.sq_last_status));
3129 * ice_get_rxfh_key_size - get the RSS hash key size
3130 * @netdev: network interface device structure
3132 * Returns the table size.
3134 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3136 return ICE_VSIQF_HKEY_ARRAY_SIZE;
3140 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3141 * @netdev: network interface device structure
3143 * Returns the table size.
3145 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3147 struct ice_netdev_priv *np = netdev_priv(netdev);
3149 return np->vsi->rss_table_size;
3153 ice_get_rxfh_context(struct net_device *netdev, u32 *indir,
3154 u8 *key, u8 *hfunc, u32 rss_context)
3156 struct ice_netdev_priv *np = netdev_priv(netdev);
3157 struct ice_vsi *vsi = np->vsi;
3158 struct ice_pf *pf = vsi->back;
3163 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3164 netdev_warn(netdev, "RSS is not supported on this VSI!\n");
3168 if (rss_context && !ice_is_adq_active(pf)) {
3169 netdev_err(netdev, "RSS context cannot be non-zero when ADQ is not configured.\n");
3173 qcount = vsi->mqprio_qopt.qopt.count[rss_context];
3174 offset = vsi->mqprio_qopt.qopt.offset[rss_context];
3176 if (rss_context && ice_is_adq_active(pf)) {
3177 num_tc = vsi->mqprio_qopt.qopt.num_tc;
3178 if (rss_context >= num_tc) {
3179 netdev_err(netdev, "RSS context:%d > num_tc:%d\n",
3180 rss_context, num_tc);
3183 /* Use channel VSI of given TC */
3184 vsi = vsi->tc_map_vsi[rss_context];
3188 *hfunc = ETH_RSS_HASH_TOP;
3193 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3197 err = ice_get_rss_key(vsi, key);
3201 err = ice_get_rss_lut(vsi, lut, vsi->rss_table_size);
3205 if (ice_is_adq_active(pf)) {
3206 for (i = 0; i < vsi->rss_table_size; i++)
3207 indir[i] = offset + lut[i] % qcount;
3211 for (i = 0; i < vsi->rss_table_size; i++)
3220 * ice_get_rxfh - get the Rx flow hash indirection table
3221 * @netdev: network interface device structure
3222 * @indir: indirection table
3224 * @hfunc: hash function
3226 * Reads the indirection table directly from the hardware.
3229 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3231 return ice_get_rxfh_context(netdev, indir, key, hfunc, 0);
3235 * ice_set_rxfh - set the Rx flow hash indirection table
3236 * @netdev: network interface device structure
3237 * @indir: indirection table
3239 * @hfunc: hash function
3241 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3242 * returns 0 after programming the table.
3245 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3248 struct ice_netdev_priv *np = netdev_priv(netdev);
3249 struct ice_vsi *vsi = np->vsi;
3250 struct ice_pf *pf = vsi->back;
3254 dev = ice_pf_to_dev(pf);
3255 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3258 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3259 /* RSS not supported return error here */
3260 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3264 if (ice_is_adq_active(pf)) {
3265 netdev_err(netdev, "Cannot change RSS params with ADQ configured.\n");
3270 if (!vsi->rss_hkey_user) {
3271 vsi->rss_hkey_user =
3272 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3274 if (!vsi->rss_hkey_user)
3277 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3279 err = ice_set_rss_key(vsi, vsi->rss_hkey_user);
3284 if (!vsi->rss_lut_user) {
3285 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3287 if (!vsi->rss_lut_user)
3291 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3295 for (i = 0; i < vsi->rss_table_size; i++)
3296 vsi->rss_lut_user[i] = (u8)(indir[i]);
3298 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3302 err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size);
3310 ice_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
3312 struct ice_pf *pf = ice_netdev_to_pf(dev);
3314 /* only report timestamping if PTP is enabled */
3315 if (!test_bit(ICE_FLAG_PTP, pf->flags))
3316 return ethtool_op_get_ts_info(dev, info);
3318 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
3319 SOF_TIMESTAMPING_RX_SOFTWARE |
3320 SOF_TIMESTAMPING_SOFTWARE |
3321 SOF_TIMESTAMPING_TX_HARDWARE |
3322 SOF_TIMESTAMPING_RX_HARDWARE |
3323 SOF_TIMESTAMPING_RAW_HARDWARE;
3325 info->phc_index = ice_get_ptp_clock_index(pf);
3327 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
3329 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
3335 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3338 static int ice_get_max_txq(struct ice_pf *pf)
3340 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3341 (u16)pf->hw.func_caps.common_cap.num_txq);
3345 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3348 static int ice_get_max_rxq(struct ice_pf *pf)
3350 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3351 (u16)pf->hw.func_caps.common_cap.num_rxq);
3355 * ice_get_combined_cnt - return the current number of combined channels
3356 * @vsi: PF VSI pointer
3358 * Go through all queue vectors and count ones that have both Rx and Tx ring
3361 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3366 ice_for_each_q_vector(vsi, q_idx) {
3367 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3369 if (q_vector->rx.rx_ring && q_vector->tx.tx_ring)
3377 * ice_get_channels - get the current and max supported channels
3378 * @dev: network interface device structure
3379 * @ch: ethtool channel data structure
3382 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3384 struct ice_netdev_priv *np = netdev_priv(dev);
3385 struct ice_vsi *vsi = np->vsi;
3386 struct ice_pf *pf = vsi->back;
3388 /* report maximum channels */
3389 ch->max_rx = ice_get_max_rxq(pf);
3390 ch->max_tx = ice_get_max_txq(pf);
3391 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3393 /* report current channels */
3394 ch->combined_count = ice_get_combined_cnt(vsi);
3395 ch->rx_count = vsi->num_rxq - ch->combined_count;
3396 ch->tx_count = vsi->num_txq - ch->combined_count;
3398 /* report other queues */
3399 ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
3400 ch->max_other = ch->other_count;
3404 * ice_get_valid_rss_size - return valid number of RSS queues
3405 * @hw: pointer to the HW structure
3406 * @new_size: requested RSS queues
3408 static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size)
3410 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3412 return min_t(int, new_size, BIT(caps->rss_table_entry_width));
3416 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3417 * @vsi: VSI to reconfigure RSS LUT on
3418 * @req_rss_size: requested range of queue numbers for hashing
3420 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3422 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3424 struct ice_pf *pf = vsi->back;
3430 dev = ice_pf_to_dev(pf);
3436 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3440 /* set RSS LUT parameters */
3441 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3444 vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size);
3446 /* create/set RSS LUT */
3447 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3448 err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
3450 dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err,
3451 ice_aq_str(hw->adminq.sq_last_status));
3458 * ice_set_channels - set the number channels
3459 * @dev: network interface device structure
3460 * @ch: ethtool channel data structure
3462 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3464 struct ice_netdev_priv *np = netdev_priv(dev);
3465 struct ice_vsi *vsi = np->vsi;
3466 struct ice_pf *pf = vsi->back;
3467 int new_rx = 0, new_tx = 0;
3470 /* do not support changing channels in Safe Mode */
3471 if (ice_is_safe_mode(pf)) {
3472 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3475 /* do not support changing other_count */
3476 if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U))
3479 if (ice_is_adq_active(pf)) {
3480 netdev_err(dev, "Cannot set channels with ADQ configured.\n");
3484 if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) {
3485 netdev_err(dev, "Cannot set channels when Flow Director filters are active\n");
3489 curr_combined = ice_get_combined_cnt(vsi);
3491 /* these checks are for cases where user didn't specify a particular
3492 * value on cmd line but we get non-zero value anyway via
3493 * get_channels(); look at ethtool.c in ethtool repository (the user
3494 * space part), particularly, do_schannels() routine
3496 if (ch->rx_count == vsi->num_rxq - curr_combined)
3498 if (ch->tx_count == vsi->num_txq - curr_combined)
3500 if (ch->combined_count == curr_combined)
3501 ch->combined_count = 0;
3503 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3504 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3508 new_rx = ch->combined_count + ch->rx_count;
3509 new_tx = ch->combined_count + ch->tx_count;
3511 if (new_rx < vsi->tc_cfg.numtc) {
3512 netdev_err(dev, "Cannot set less Rx channels, than Traffic Classes you have (%u)\n",
3516 if (new_tx < vsi->tc_cfg.numtc) {
3517 netdev_err(dev, "Cannot set less Tx channels, than Traffic Classes you have (%u)\n",
3521 if (new_rx > ice_get_max_rxq(pf)) {
3522 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3523 ice_get_max_rxq(pf));
3526 if (new_tx > ice_get_max_txq(pf)) {
3527 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3528 ice_get_max_txq(pf));
3532 ice_vsi_recfg_qs(vsi, new_rx, new_tx);
3534 if (!netif_is_rxfh_configured(dev))
3535 return ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3537 /* Update rss_size due to change in Rx queues */
3538 vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx);
3544 * ice_get_wol - get current Wake on LAN configuration
3545 * @netdev: network interface device structure
3546 * @wol: Ethtool structure to retrieve WoL settings
3548 static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3550 struct ice_netdev_priv *np = netdev_priv(netdev);
3551 struct ice_pf *pf = np->vsi->back;
3553 if (np->vsi->type != ICE_VSI_PF)
3554 netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
3556 /* Get WoL settings based on the HW capability */
3557 if (ice_is_wol_supported(&pf->hw)) {
3558 wol->supported = WAKE_MAGIC;
3559 wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
3567 * ice_set_wol - set Wake on LAN on supported device
3568 * @netdev: network interface device structure
3569 * @wol: Ethtool structure to set WoL
3571 static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3573 struct ice_netdev_priv *np = netdev_priv(netdev);
3574 struct ice_vsi *vsi = np->vsi;
3575 struct ice_pf *pf = vsi->back;
3577 if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw))
3580 /* only magic packet is supported */
3581 if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
3584 /* Set WoL only if there is a new value */
3585 if (pf->wol_ena != !!wol->wolopts) {
3586 pf->wol_ena = !!wol->wolopts;
3587 device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
3588 netdev_dbg(netdev, "WoL magic packet %sabled\n",
3589 pf->wol_ena ? "en" : "dis");
3596 * ice_get_rc_coalesce - get ITR values for specific ring container
3597 * @ec: ethtool structure to fill with driver's coalesce settings
3598 * @rc: ring container that the ITR values will come from
3600 * Query the device for ice_ring_container specific ITR values. This is
3601 * done per ice_ring_container because each q_vector can have 1 or more rings
3602 * and all of said ring(s) will have the same ITR values.
3604 * Returns 0 on success, negative otherwise.
3607 ice_get_rc_coalesce(struct ethtool_coalesce *ec, struct ice_ring_container *rc)
3613 case ICE_RX_CONTAINER:
3614 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc);
3615 ec->rx_coalesce_usecs = rc->itr_setting;
3616 ec->rx_coalesce_usecs_high = rc->rx_ring->q_vector->intrl;
3618 case ICE_TX_CONTAINER:
3619 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc);
3620 ec->tx_coalesce_usecs = rc->itr_setting;
3623 dev_dbg(ice_pf_to_dev(rc->rx_ring->vsi->back), "Invalid c_type %d\n", rc->type);
3631 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3632 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3633 * @ec: coalesce settings to program the device with
3634 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3636 * Return 0 on success, and negative under the following conditions:
3637 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3638 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3641 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3643 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3644 if (ice_get_rc_coalesce(ec,
3645 &vsi->rx_rings[q_num]->q_vector->rx))
3647 if (ice_get_rc_coalesce(ec,
3648 &vsi->tx_rings[q_num]->q_vector->tx))
3650 } else if (q_num < vsi->num_rxq) {
3651 if (ice_get_rc_coalesce(ec,
3652 &vsi->rx_rings[q_num]->q_vector->rx))
3654 } else if (q_num < vsi->num_txq) {
3655 if (ice_get_rc_coalesce(ec,
3656 &vsi->tx_rings[q_num]->q_vector->tx))
3666 * __ice_get_coalesce - get ITR/INTRL values for the device
3667 * @netdev: pointer to the netdev associated with this query
3668 * @ec: ethtool structure to fill with driver's coalesce settings
3669 * @q_num: queue number to get the coalesce settings for
3671 * If the caller passes in a negative q_num then we return coalesce settings
3672 * based on queue number 0, else use the actual q_num passed in.
3675 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3678 struct ice_netdev_priv *np = netdev_priv(netdev);
3679 struct ice_vsi *vsi = np->vsi;
3684 if (ice_get_q_coalesce(vsi, ec, q_num))
3690 static int ice_get_coalesce(struct net_device *netdev,
3691 struct ethtool_coalesce *ec,
3692 struct kernel_ethtool_coalesce *kernel_coal,
3693 struct netlink_ext_ack *extack)
3695 return __ice_get_coalesce(netdev, ec, -1);
3699 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3700 struct ethtool_coalesce *ec)
3702 return __ice_get_coalesce(netdev, ec, q_num);
3706 * ice_set_rc_coalesce - set ITR values for specific ring container
3707 * @ec: ethtool structure from user to update ITR settings
3708 * @rc: ring container that the ITR values will come from
3709 * @vsi: VSI associated to the ring container
3711 * Set specific ITR values. This is done per ice_ring_container because each
3712 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3715 * Returns 0 on success, negative otherwise.
3718 ice_set_rc_coalesce(struct ethtool_coalesce *ec,
3719 struct ice_ring_container *rc, struct ice_vsi *vsi)
3721 const char *c_type_str = (rc->type == ICE_RX_CONTAINER) ? "rx" : "tx";
3722 u32 use_adaptive_coalesce, coalesce_usecs;
3723 struct ice_pf *pf = vsi->back;
3730 case ICE_RX_CONTAINER:
3732 struct ice_q_vector *q_vector = rc->rx_ring->q_vector;
3734 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3735 (ec->rx_coalesce_usecs_high &&
3736 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3737 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3738 c_type_str, pf->hw.intrl_gran,
3742 if (ec->rx_coalesce_usecs_high != q_vector->intrl &&
3743 (ec->use_adaptive_rx_coalesce || ec->use_adaptive_tx_coalesce)) {
3744 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high cannot be changed if adaptive-tx or adaptive-rx is enabled\n",
3748 if (ec->rx_coalesce_usecs_high != q_vector->intrl)
3749 q_vector->intrl = ec->rx_coalesce_usecs_high;
3751 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3752 coalesce_usecs = ec->rx_coalesce_usecs;
3756 case ICE_TX_CONTAINER:
3757 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3758 coalesce_usecs = ec->tx_coalesce_usecs;
3762 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3767 itr_setting = rc->itr_setting;
3768 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3769 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3770 c_type_str, c_type_str);
3774 if (coalesce_usecs > ICE_ITR_MAX) {
3775 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3776 c_type_str, ICE_ITR_MAX);
3780 if (use_adaptive_coalesce) {
3781 rc->itr_mode = ITR_DYNAMIC;
3783 rc->itr_mode = ITR_STATIC;
3784 /* store user facing value how it was set */
3785 rc->itr_setting = coalesce_usecs;
3786 /* write the change to the register */
3787 ice_write_itr(rc, coalesce_usecs);
3788 /* force writes to take effect immediately, the flush shouldn't
3789 * be done in the functions above because the intent is for
3790 * them to do lazy writes.
3799 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3800 * @vsi: VSI associated to the queue that need updating
3801 * @ec: coalesce settings to program the device with
3802 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3804 * Return 0 on success, and negative under the following conditions:
3805 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3806 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3809 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3811 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3812 if (ice_set_rc_coalesce(ec,
3813 &vsi->rx_rings[q_num]->q_vector->rx,
3817 if (ice_set_rc_coalesce(ec,
3818 &vsi->tx_rings[q_num]->q_vector->tx,
3821 } else if (q_num < vsi->num_rxq) {
3822 if (ice_set_rc_coalesce(ec,
3823 &vsi->rx_rings[q_num]->q_vector->rx,
3826 } else if (q_num < vsi->num_txq) {
3827 if (ice_set_rc_coalesce(ec,
3828 &vsi->tx_rings[q_num]->q_vector->tx,
3839 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3840 * @netdev: netdev used for print
3841 * @itr_setting: previous user setting
3842 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3843 * @coalesce_usecs: requested value of [tx|rx]-usecs
3844 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3847 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3848 u32 use_adaptive_coalesce, u32 coalesce_usecs,
3849 const char *c_type_str)
3851 if (use_adaptive_coalesce)
3854 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3855 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",
3856 c_type_str, coalesce_usecs, c_type_str,
3857 ITR_REG_ALIGN(coalesce_usecs));
3861 * __ice_set_coalesce - set ITR/INTRL values for the device
3862 * @netdev: pointer to the netdev associated with this query
3863 * @ec: ethtool structure to fill with driver's coalesce settings
3864 * @q_num: queue number to get the coalesce settings for
3866 * If the caller passes in a negative q_num then we set the coalesce settings
3867 * for all Tx/Rx queues, else use the actual q_num passed in.
3870 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3873 struct ice_netdev_priv *np = netdev_priv(netdev);
3874 struct ice_vsi *vsi = np->vsi;
3877 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3881 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3882 ec->use_adaptive_rx_coalesce,
3883 ec->rx_coalesce_usecs, "rx");
3885 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3886 ec->use_adaptive_tx_coalesce,
3887 ec->tx_coalesce_usecs, "tx");
3890 ice_for_each_q_vector(vsi, v_idx) {
3891 /* In some cases if DCB is configured the num_[rx|tx]q
3892 * can be less than vsi->num_q_vectors. This check
3893 * accounts for that so we don't report a false failure
3895 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3898 if (ice_set_q_coalesce(vsi, ec, v_idx))
3901 ice_set_q_vector_intrl(vsi->q_vectors[v_idx]);
3906 if (ice_set_q_coalesce(vsi, ec, q_num))
3909 ice_set_q_vector_intrl(vsi->q_vectors[q_num]);
3915 static int ice_set_coalesce(struct net_device *netdev,
3916 struct ethtool_coalesce *ec,
3917 struct kernel_ethtool_coalesce *kernel_coal,
3918 struct netlink_ext_ack *extack)
3920 return __ice_set_coalesce(netdev, ec, -1);
3924 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3925 struct ethtool_coalesce *ec)
3927 return __ice_set_coalesce(netdev, ec, q_num);
3931 ice_repr_get_drvinfo(struct net_device *netdev,
3932 struct ethtool_drvinfo *drvinfo)
3934 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3936 if (ice_check_vf_ready_for_cfg(repr->vf))
3939 __ice_get_drvinfo(netdev, drvinfo, repr->src_vsi);
3943 ice_repr_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
3945 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3947 /* for port representors only ETH_SS_STATS is supported */
3948 if (ice_check_vf_ready_for_cfg(repr->vf) ||
3949 stringset != ETH_SS_STATS)
3952 __ice_get_strings(netdev, stringset, data, repr->src_vsi);
3956 ice_repr_get_ethtool_stats(struct net_device *netdev,
3957 struct ethtool_stats __always_unused *stats,
3960 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3962 if (ice_check_vf_ready_for_cfg(repr->vf))
3965 __ice_get_ethtool_stats(netdev, stats, data, repr->src_vsi);
3968 static int ice_repr_get_sset_count(struct net_device *netdev, int sset)
3972 return ICE_VSI_STATS_LEN;
3978 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
3979 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
3980 #define ICE_MODULE_TYPE_SFP 0x03
3981 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
3982 #define ICE_MODULE_TYPE_QSFP28 0x11
3983 #define ICE_MODULE_SFF_ADDR_MODE 0x04
3984 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
3985 #define ICE_MODULE_REVISION_ADDR 0x01
3986 #define ICE_MODULE_SFF_8472_COMP 0x5E
3987 #define ICE_MODULE_SFF_8472_SWAP 0x5C
3988 #define ICE_MODULE_QSFP_MAX_LEN 640
3991 * ice_get_module_info - get SFF module type and revision information
3992 * @netdev: network interface device structure
3993 * @modinfo: module EEPROM size and layout information structure
3996 ice_get_module_info(struct net_device *netdev,
3997 struct ethtool_modinfo *modinfo)
3999 struct ice_netdev_priv *np = netdev_priv(netdev);
4000 struct ice_vsi *vsi = np->vsi;
4001 struct ice_pf *pf = vsi->back;
4002 struct ice_hw *hw = &pf->hw;
4003 u8 sff8472_comp = 0;
4004 u8 sff8472_swap = 0;
4009 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
4010 0, &value, 1, 0, NULL);
4015 case ICE_MODULE_TYPE_SFP:
4016 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4017 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
4018 &sff8472_comp, 1, 0, NULL);
4021 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4022 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
4023 &sff8472_swap, 1, 0, NULL);
4027 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
4028 modinfo->type = ETH_MODULE_SFF_8079;
4029 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4030 } else if (sff8472_comp &&
4031 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
4032 modinfo->type = ETH_MODULE_SFF_8472;
4033 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4035 modinfo->type = ETH_MODULE_SFF_8079;
4036 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4039 case ICE_MODULE_TYPE_QSFP_PLUS:
4040 case ICE_MODULE_TYPE_QSFP28:
4041 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4042 ICE_MODULE_REVISION_ADDR, 0x00, 0,
4043 &sff8636_rev, 1, 0, NULL);
4046 /* Check revision compliance */
4047 if (sff8636_rev > 0x02) {
4048 /* Module is SFF-8636 compliant */
4049 modinfo->type = ETH_MODULE_SFF_8636;
4050 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4052 modinfo->type = ETH_MODULE_SFF_8436;
4053 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4057 netdev_warn(netdev, "SFF Module Type not recognized.\n");
4064 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
4065 * @netdev: network interface device structure
4066 * @ee: EEPROM dump request structure
4067 * @data: buffer to be filled with EEPROM contents
4070 ice_get_module_eeprom(struct net_device *netdev,
4071 struct ethtool_eeprom *ee, u8 *data)
4073 struct ice_netdev_priv *np = netdev_priv(netdev);
4074 #define SFF_READ_BLOCK_SIZE 8
4075 u8 value[SFF_READ_BLOCK_SIZE] = { 0 };
4076 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
4077 struct ice_vsi *vsi = np->vsi;
4078 struct ice_pf *pf = vsi->back;
4079 struct ice_hw *hw = &pf->hw;
4080 bool is_sfp = false;
4086 if (!ee || !ee->len || !data)
4089 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
4094 if (value[0] == ICE_MODULE_TYPE_SFP)
4097 memset(data, 0, ee->len);
4098 for (i = 0; i < ee->len; i += SFF_READ_BLOCK_SIZE) {
4099 offset = i + ee->offset;
4102 /* Check if we need to access the other memory page */
4104 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4105 offset -= ETH_MODULE_SFF_8079_LEN;
4106 addr = ICE_I2C_EEPROM_DEV_ADDR2;
4109 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4110 /* Compute memory page number and offset. */
4111 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4116 /* Bit 2 of EEPROM address 0x02 declares upper
4117 * pages are disabled on QSFP modules.
4118 * SFP modules only ever use page 0.
4120 if (page == 0 || !(data[0x2] & 0x4)) {
4121 /* If i2c bus is busy due to slow page change or
4122 * link management access, call can fail. This is normal.
4123 * So we retry this a few times.
4125 for (j = 0; j < 4; j++) {
4126 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page,
4128 SFF_READ_BLOCK_SIZE,
4130 netdev_dbg(netdev, "SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%X)\n",
4131 addr, offset, page, is_sfp,
4132 value[0], value[1], value[2], value[3],
4133 value[4], value[5], value[6], value[7],
4136 usleep_range(1500, 2500);
4137 memset(value, 0, SFF_READ_BLOCK_SIZE);
4143 /* Make sure we have enough room for the new block */
4144 if ((i + SFF_READ_BLOCK_SIZE) < ee->len)
4145 memcpy(data + i, value, SFF_READ_BLOCK_SIZE);
4151 static const struct ethtool_ops ice_ethtool_ops = {
4152 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
4153 ETHTOOL_COALESCE_USE_ADAPTIVE |
4154 ETHTOOL_COALESCE_RX_USECS_HIGH,
4155 .get_link_ksettings = ice_get_link_ksettings,
4156 .set_link_ksettings = ice_set_link_ksettings,
4157 .get_drvinfo = ice_get_drvinfo,
4158 .get_regs_len = ice_get_regs_len,
4159 .get_regs = ice_get_regs,
4160 .get_wol = ice_get_wol,
4161 .set_wol = ice_set_wol,
4162 .get_msglevel = ice_get_msglevel,
4163 .set_msglevel = ice_set_msglevel,
4164 .self_test = ice_self_test,
4165 .get_link = ethtool_op_get_link,
4166 .get_eeprom_len = ice_get_eeprom_len,
4167 .get_eeprom = ice_get_eeprom,
4168 .get_coalesce = ice_get_coalesce,
4169 .set_coalesce = ice_set_coalesce,
4170 .get_strings = ice_get_strings,
4171 .set_phys_id = ice_set_phys_id,
4172 .get_ethtool_stats = ice_get_ethtool_stats,
4173 .get_priv_flags = ice_get_priv_flags,
4174 .set_priv_flags = ice_set_priv_flags,
4175 .get_sset_count = ice_get_sset_count,
4176 .get_rxnfc = ice_get_rxnfc,
4177 .set_rxnfc = ice_set_rxnfc,
4178 .get_ringparam = ice_get_ringparam,
4179 .set_ringparam = ice_set_ringparam,
4180 .nway_reset = ice_nway_reset,
4181 .get_pauseparam = ice_get_pauseparam,
4182 .set_pauseparam = ice_set_pauseparam,
4183 .get_rxfh_key_size = ice_get_rxfh_key_size,
4184 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
4185 .get_rxfh_context = ice_get_rxfh_context,
4186 .get_rxfh = ice_get_rxfh,
4187 .set_rxfh = ice_set_rxfh,
4188 .get_channels = ice_get_channels,
4189 .set_channels = ice_set_channels,
4190 .get_ts_info = ice_get_ts_info,
4191 .get_per_queue_coalesce = ice_get_per_q_coalesce,
4192 .set_per_queue_coalesce = ice_set_per_q_coalesce,
4193 .get_fecparam = ice_get_fecparam,
4194 .set_fecparam = ice_set_fecparam,
4195 .get_module_info = ice_get_module_info,
4196 .get_module_eeprom = ice_get_module_eeprom,
4199 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
4200 .get_link_ksettings = ice_get_link_ksettings,
4201 .set_link_ksettings = ice_set_link_ksettings,
4202 .get_drvinfo = ice_get_drvinfo,
4203 .get_regs_len = ice_get_regs_len,
4204 .get_regs = ice_get_regs,
4205 .get_wol = ice_get_wol,
4206 .set_wol = ice_set_wol,
4207 .get_msglevel = ice_get_msglevel,
4208 .set_msglevel = ice_set_msglevel,
4209 .get_link = ethtool_op_get_link,
4210 .get_eeprom_len = ice_get_eeprom_len,
4211 .get_eeprom = ice_get_eeprom,
4212 .get_strings = ice_get_strings,
4213 .get_ethtool_stats = ice_get_ethtool_stats,
4214 .get_sset_count = ice_get_sset_count,
4215 .get_ringparam = ice_get_ringparam,
4216 .set_ringparam = ice_set_ringparam,
4217 .nway_reset = ice_nway_reset,
4218 .get_channels = ice_get_channels,
4222 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
4223 * @netdev: network interface device structure
4225 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
4227 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
4230 static const struct ethtool_ops ice_ethtool_repr_ops = {
4231 .get_drvinfo = ice_repr_get_drvinfo,
4232 .get_link = ethtool_op_get_link,
4233 .get_strings = ice_repr_get_strings,
4234 .get_ethtool_stats = ice_repr_get_ethtool_stats,
4235 .get_sset_count = ice_repr_get_sset_count,
4239 * ice_set_ethtool_repr_ops - setup VF's port representor ethtool ops
4240 * @netdev: network interface device structure
4242 void ice_set_ethtool_repr_ops(struct net_device *netdev)
4244 netdev->ethtool_ops = &ice_ethtool_repr_ops;
4248 * ice_set_ethtool_ops - setup netdev ethtool ops
4249 * @netdev: network interface device structure
4251 * setup netdev ethtool ops with ice specific ops
4253 void ice_set_ethtool_ops(struct net_device *netdev)
4255 netdev->ethtool_ops = &ice_ethtool_ops;