1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
9 #include "ice_dcb_lib.h"
12 char stat_string[ETH_GSTRING_LEN];
17 #define ICE_STAT(_type, _name, _stat) { \
18 .stat_string = _name, \
19 .sizeof_stat = sizeof_field(_type, _stat), \
20 .stat_offset = offsetof(_type, _stat) \
23 #define ICE_VSI_STAT(_name, _stat) \
24 ICE_STAT(struct ice_vsi, _name, _stat)
25 #define ICE_PF_STAT(_name, _stat) \
26 ICE_STAT(struct ice_pf, _name, _stat)
28 static int ice_q_stats_len(struct net_device *netdev)
30 struct ice_netdev_priv *np = netdev_priv(netdev);
32 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
33 (sizeof(struct ice_q_stats) / sizeof(u64)));
36 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
37 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
39 #define ICE_PFC_STATS_LEN ( \
40 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
41 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
42 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
43 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
45 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
46 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
48 static const struct ice_stats ice_gstrings_vsi_stats[] = {
49 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
50 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
51 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
52 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
53 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
54 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
55 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
56 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
57 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
58 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
59 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
60 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
61 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
62 ICE_VSI_STAT("tx_linearize", tx_linearize),
65 enum ice_ethtool_test_id {
73 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
74 "Register test (offline)",
75 "EEPROM test (offline)",
76 "Interrupt test (offline)",
77 "Loopback test (offline)",
78 "Link test (on/offline)",
81 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
83 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
84 * but they aren't. This device is capable of supporting multiple
85 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
86 * netdevs whereas the PF_STATs are for the physical function that's
87 * hosting these netdevs.
89 * The PF_STATs are appended to the netdev stats only when ethtool -S
90 * is queried on the base PF netdev.
92 static const struct ice_stats ice_gstrings_pf_stats[] = {
93 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
94 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
95 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
96 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
97 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
98 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
99 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
100 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
101 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
102 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
103 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
104 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
105 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
106 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
107 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
108 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
109 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
110 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
111 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
112 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
113 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
114 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
115 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
116 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
117 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
118 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
119 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
120 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
121 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
122 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
123 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
124 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
125 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
126 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
127 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
128 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
129 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
130 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
131 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
134 static const u32 ice_regs_dump_list[] = {
147 struct ice_priv_flag {
148 char name[ETH_GSTRING_LEN];
149 u32 bitno; /* bit position in pf->flags */
152 #define ICE_PRIV_FLAG(_name, _bitno) { \
157 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
158 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
159 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
160 ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
163 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
166 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
168 struct ice_netdev_priv *np = netdev_priv(netdev);
169 u8 oem_ver, oem_patch, nvm_ver_hi, nvm_ver_lo;
170 struct ice_vsi *vsi = np->vsi;
171 struct ice_pf *pf = vsi->back;
172 struct ice_hw *hw = &pf->hw;
175 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
176 strlcpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
178 /* Display NVM version (from which the firmware version can be
179 * determined) which contains more pertinent information.
181 ice_get_nvm_version(hw, &oem_ver, &oem_build, &oem_patch,
182 &nvm_ver_hi, &nvm_ver_lo);
183 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
184 "%x.%02x 0x%x %d.%d.%d", nvm_ver_hi, nvm_ver_lo,
185 hw->nvm.eetrack, oem_ver, oem_build, oem_patch);
187 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
188 sizeof(drvinfo->bus_info));
189 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
192 static int ice_get_regs_len(struct net_device __always_unused *netdev)
194 return sizeof(ice_regs_dump_list);
198 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
200 struct ice_netdev_priv *np = netdev_priv(netdev);
201 struct ice_pf *pf = np->vsi->back;
202 struct ice_hw *hw = &pf->hw;
203 u32 *regs_buf = (u32 *)p;
208 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
209 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
212 static u32 ice_get_msglevel(struct net_device *netdev)
214 struct ice_netdev_priv *np = netdev_priv(netdev);
215 struct ice_pf *pf = np->vsi->back;
217 #ifndef CONFIG_DYNAMIC_DEBUG
218 if (pf->hw.debug_mask)
219 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
221 #endif /* !CONFIG_DYNAMIC_DEBUG */
223 return pf->msg_enable;
226 static void ice_set_msglevel(struct net_device *netdev, u32 data)
228 struct ice_netdev_priv *np = netdev_priv(netdev);
229 struct ice_pf *pf = np->vsi->back;
231 #ifndef CONFIG_DYNAMIC_DEBUG
232 if (ICE_DBG_USER & data)
233 pf->hw.debug_mask = data;
235 pf->msg_enable = data;
237 pf->msg_enable = data;
238 #endif /* !CONFIG_DYNAMIC_DEBUG */
241 static int ice_get_eeprom_len(struct net_device *netdev)
243 struct ice_netdev_priv *np = netdev_priv(netdev);
244 struct ice_pf *pf = np->vsi->back;
246 return (int)(pf->hw.nvm.sr_words * sizeof(u16));
250 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
253 struct ice_netdev_priv *np = netdev_priv(netdev);
254 u16 first_word, last_word, nwords;
255 struct ice_vsi *vsi = np->vsi;
256 struct ice_pf *pf = vsi->back;
257 struct ice_hw *hw = &pf->hw;
258 enum ice_status status;
263 dev = ice_pf_to_dev(pf);
265 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
267 first_word = eeprom->offset >> 1;
268 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
269 nwords = last_word - first_word + 1;
271 buf = devm_kcalloc(dev, nwords, sizeof(u16), GFP_KERNEL);
275 status = ice_read_sr_buf(hw, first_word, &nwords, buf);
277 dev_err(dev, "ice_read_sr_buf failed, err %d aq_err %d\n",
278 status, hw->adminq.sq_last_status);
279 eeprom->len = sizeof(u16) * nwords;
284 memcpy(bytes, (u8 *)buf + (eeprom->offset & 1), eeprom->len);
286 devm_kfree(dev, buf);
291 * ice_active_vfs - check if there are any active VFs
292 * @pf: board private structure
294 * Returns true if an active VF is found, otherwise returns false
296 static bool ice_active_vfs(struct ice_pf *pf)
300 ice_for_each_vf(pf, i) {
301 struct ice_vf *vf = &pf->vf[i];
303 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
311 * ice_link_test - perform a link test on a given net_device
312 * @netdev: network interface device structure
314 * This function performs one of the self-tests required by ethtool.
315 * Returns 0 on success, non-zero on failure.
317 static u64 ice_link_test(struct net_device *netdev)
319 struct ice_netdev_priv *np = netdev_priv(netdev);
320 enum ice_status status;
321 bool link_up = false;
323 netdev_info(netdev, "link test\n");
324 status = ice_get_link_status(np->vsi->port_info, &link_up);
326 netdev_err(netdev, "link query error, status = %d\n", status);
337 * ice_eeprom_test - perform an EEPROM test on a given net_device
338 * @netdev: network interface device structure
340 * This function performs one of the self-tests required by ethtool.
341 * Returns 0 on success, non-zero on failure.
343 static u64 ice_eeprom_test(struct net_device *netdev)
345 struct ice_netdev_priv *np = netdev_priv(netdev);
346 struct ice_pf *pf = np->vsi->back;
348 netdev_info(netdev, "EEPROM test\n");
349 return !!(ice_nvm_validate_checksum(&pf->hw));
353 * ice_reg_pattern_test
354 * @hw: pointer to the HW struct
355 * @reg: reg to be tested
356 * @mask: bits to be touched
358 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
360 struct ice_pf *pf = (struct ice_pf *)hw->back;
361 struct device *dev = ice_pf_to_dev(pf);
362 static const u32 patterns[] = {
363 0x5A5A5A5A, 0xA5A5A5A5,
364 0x00000000, 0xFFFFFFFF
369 orig_val = rd32(hw, reg);
370 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
371 u32 pattern = patterns[i] & mask;
373 wr32(hw, reg, pattern);
377 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
378 , __func__, reg, pattern, val);
382 wr32(hw, reg, orig_val);
384 if (val != orig_val) {
385 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
386 , __func__, reg, orig_val, val);
394 * ice_reg_test - perform a register test on a given net_device
395 * @netdev: network interface device structure
397 * This function performs one of the self-tests required by ethtool.
398 * Returns 0 on success, non-zero on failure.
400 static u64 ice_reg_test(struct net_device *netdev)
402 struct ice_netdev_priv *np = netdev_priv(netdev);
403 struct ice_hw *hw = np->vsi->port_info->hw;
404 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
405 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
406 struct ice_diag_reg_test_info {
412 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
413 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
414 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
415 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
416 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
417 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
418 {GLINT_CTL, 0xffff0001, 1, 0}
422 netdev_dbg(netdev, "Register test\n");
423 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
426 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
427 u32 mask = ice_reg_list[i].mask;
428 u32 reg = ice_reg_list[i].address +
429 (j * ice_reg_list[i].elem_size);
431 /* bail on failure (non-zero return) */
432 if (ice_reg_pattern_test(hw, reg, mask))
441 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
442 * @vsi: pointer to the VSI structure
444 * Function configures rings of a VSI for loopback test without
445 * enabling interrupts or informing the kernel about new queues.
447 * Returns 0 on success, negative on failure.
449 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
453 status = ice_vsi_setup_tx_rings(vsi);
455 goto err_setup_tx_ring;
457 status = ice_vsi_setup_rx_rings(vsi);
459 goto err_setup_rx_ring;
461 status = ice_vsi_cfg(vsi);
463 goto err_setup_rx_ring;
465 status = ice_vsi_start_rx_rings(vsi);
467 goto err_start_rx_ring;
472 ice_vsi_free_rx_rings(vsi);
474 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
476 ice_vsi_free_tx_rings(vsi);
482 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
483 * @vsi: pointer to the VSI structure
485 * Function stops and frees VSI rings after a loopback test.
486 * Returns 0 on success, negative on failure.
488 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
492 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
494 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
495 vsi->vsi_num, status);
497 status = ice_vsi_stop_rx_rings(vsi);
499 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
500 vsi->vsi_num, status);
502 ice_vsi_free_tx_rings(vsi);
503 ice_vsi_free_rx_rings(vsi);
509 * ice_lbtest_create_frame - create test packet
510 * @pf: pointer to the PF structure
511 * @ret_data: allocated frame buffer
512 * @size: size of the packet data
514 * Function allocates a frame with a test pattern on specific offsets.
515 * Returns 0 on success, non-zero on failure.
517 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
524 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
528 /* Since the ethernet test frame should always be at least
529 * 64 bytes long, fill some octets in the payload with test data.
531 memset(data, 0xFF, size);
543 * ice_lbtest_check_frame - verify received loopback frame
544 * @frame: pointer to the raw packet data
546 * Function verifies received test frame with a pattern.
547 * Returns true if frame matches the pattern, false otherwise.
549 static bool ice_lbtest_check_frame(u8 *frame)
551 /* Validate bytes of a frame under offsets chosen earlier */
552 if (frame[32] == 0xDE &&
563 * ice_diag_send - send test frames to the test ring
564 * @tx_ring: pointer to the transmit ring
565 * @data: pointer to the raw packet data
566 * @size: size of the packet to send
568 * Function sends loopback packets on a test Tx ring.
570 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
572 struct ice_tx_desc *tx_desc;
573 struct ice_tx_buf *tx_buf;
577 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
578 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
580 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
581 if (dma_mapping_error(tx_ring->dev, dma))
584 tx_desc->buf_addr = cpu_to_le64(dma);
586 /* These flags are required for a descriptor to be pushed out */
587 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
588 tx_desc->cmd_type_offset_bsz =
589 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
590 (td_cmd << ICE_TXD_QW1_CMD_S) |
591 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
592 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
593 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
595 tx_buf->next_to_watch = tx_desc;
597 /* Force memory write to complete before letting h/w know
598 * there are new descriptors to fetch.
602 tx_ring->next_to_use++;
603 if (tx_ring->next_to_use >= tx_ring->count)
604 tx_ring->next_to_use = 0;
606 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
608 /* Wait until the packets get transmitted to the receive queue. */
609 usleep_range(1000, 2000);
610 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
615 #define ICE_LB_FRAME_SIZE 64
617 * ice_lbtest_receive_frames - receive and verify test frames
618 * @rx_ring: pointer to the receive ring
620 * Function receives loopback packets and verify their correctness.
621 * Returns number of received valid frames.
623 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
625 struct ice_rx_buf *rx_buf;
631 for (i = 0; i < rx_ring->count; i++) {
632 union ice_32b_rx_flex_desc *rx_desc;
634 rx_desc = ICE_RX_DESC(rx_ring, i);
636 if (!(rx_desc->wb.status_error0 &
637 cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)))
640 rx_buf = &rx_ring->rx_buf[i];
641 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
643 if (ice_lbtest_check_frame(received_buf))
651 * ice_loopback_test - perform a loopback test on a given net_device
652 * @netdev: network interface device structure
654 * This function performs one of the self-tests required by ethtool.
655 * Returns 0 on success, non-zero on failure.
657 static u64 ice_loopback_test(struct net_device *netdev)
659 struct ice_netdev_priv *np = netdev_priv(netdev);
660 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
661 struct ice_pf *pf = orig_vsi->back;
662 struct ice_ring *tx_ring, *rx_ring;
663 u8 broadcast[ETH_ALEN], ret = 0;
664 int num_frames, valid_frames;
670 dev = ice_pf_to_dev(pf);
671 netdev_info(netdev, "loopback test\n");
673 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
675 netdev_err(netdev, "Failed to create a VSI for the loopback test");
679 test_vsi->netdev = netdev;
680 tx_ring = test_vsi->tx_rings[0];
681 rx_ring = test_vsi->rx_rings[0];
683 if (ice_lbtest_prepare_rings(test_vsi)) {
685 goto lbtest_vsi_close;
688 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
690 goto lbtest_rings_dis;
693 /* Enable MAC loopback in firmware */
694 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
699 /* Test VSI needs to receive broadcast packets */
700 eth_broadcast_addr(broadcast);
701 if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) {
706 if (ice_add_mac(&pf->hw, &tmp_list)) {
711 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
713 goto remove_mac_filters;
716 num_frames = min_t(int, tx_ring->count, 32);
717 for (i = 0; i < num_frames; i++) {
718 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
720 goto lbtest_free_frame;
724 valid_frames = ice_lbtest_receive_frames(rx_ring);
727 else if (valid_frames != num_frames)
731 devm_kfree(dev, tx_frame);
733 if (ice_remove_mac(&pf->hw, &tmp_list))
734 netdev_err(netdev, "Could not remove MAC filter for the test VSI");
736 ice_free_fltr_list(dev, &tmp_list);
738 /* Disable MAC loopback after the test is completed. */
739 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
740 netdev_err(netdev, "Could not disable MAC loopback\n");
742 if (ice_lbtest_disable_rings(test_vsi))
743 netdev_err(netdev, "Could not disable test rings\n");
745 test_vsi->netdev = NULL;
746 if (ice_vsi_release(test_vsi))
747 netdev_err(netdev, "Failed to remove the test VSI");
753 * ice_intr_test - perform an interrupt test on a given net_device
754 * @netdev: network interface device structure
756 * This function performs one of the self-tests required by ethtool.
757 * Returns 0 on success, non-zero on failure.
759 static u64 ice_intr_test(struct net_device *netdev)
761 struct ice_netdev_priv *np = netdev_priv(netdev);
762 struct ice_pf *pf = np->vsi->back;
763 u16 swic_old = pf->sw_int_count;
765 netdev_info(netdev, "interrupt test\n");
767 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
768 GLINT_DYN_CTL_SW_ITR_INDX_M |
769 GLINT_DYN_CTL_INTENA_MSK_M |
770 GLINT_DYN_CTL_SWINT_TRIG_M);
772 usleep_range(1000, 2000);
773 return (swic_old == pf->sw_int_count);
777 * ice_self_test - handler function for performing a self-test by ethtool
778 * @netdev: network interface device structure
779 * @eth_test: ethtool_test structure
780 * @data: required by ethtool.self_test
782 * This function is called after invoking 'ethtool -t devname' command where
783 * devname is the name of the network device on which ethtool should operate.
784 * It performs a set of self-tests to check if a device works properly.
787 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
790 struct ice_netdev_priv *np = netdev_priv(netdev);
791 bool if_running = netif_running(netdev);
792 struct ice_pf *pf = np->vsi->back;
795 dev = ice_pf_to_dev(pf);
797 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
798 netdev_info(netdev, "offline testing starting\n");
800 set_bit(__ICE_TESTING, pf->state);
802 if (ice_active_vfs(pf)) {
803 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
804 data[ICE_ETH_TEST_REG] = 1;
805 data[ICE_ETH_TEST_EEPROM] = 1;
806 data[ICE_ETH_TEST_INTR] = 1;
807 data[ICE_ETH_TEST_LOOP] = 1;
808 data[ICE_ETH_TEST_LINK] = 1;
809 eth_test->flags |= ETH_TEST_FL_FAILED;
810 clear_bit(__ICE_TESTING, pf->state);
813 /* If the device is online then take it offline */
815 /* indicate we're in test mode */
818 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
819 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
820 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
821 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
822 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
824 if (data[ICE_ETH_TEST_LINK] ||
825 data[ICE_ETH_TEST_EEPROM] ||
826 data[ICE_ETH_TEST_LOOP] ||
827 data[ICE_ETH_TEST_INTR] ||
828 data[ICE_ETH_TEST_REG])
829 eth_test->flags |= ETH_TEST_FL_FAILED;
831 clear_bit(__ICE_TESTING, pf->state);
834 int status = ice_open(netdev);
837 dev_err(dev, "Could not open device %s, err %d",
838 pf->int_name, status);
843 netdev_info(netdev, "online testing starting\n");
845 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
846 if (data[ICE_ETH_TEST_LINK])
847 eth_test->flags |= ETH_TEST_FL_FAILED;
849 /* Offline only tests, not run in online; pass by default */
850 data[ICE_ETH_TEST_REG] = 0;
851 data[ICE_ETH_TEST_EEPROM] = 0;
852 data[ICE_ETH_TEST_INTR] = 0;
853 data[ICE_ETH_TEST_LOOP] = 0;
857 netdev_info(netdev, "testing finished\n");
860 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
862 struct ice_netdev_priv *np = netdev_priv(netdev);
863 struct ice_vsi *vsi = np->vsi;
864 char *p = (char *)data;
869 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
870 snprintf(p, ETH_GSTRING_LEN, "%s",
871 ice_gstrings_vsi_stats[i].stat_string);
872 p += ETH_GSTRING_LEN;
875 ice_for_each_alloc_txq(vsi, i) {
876 snprintf(p, ETH_GSTRING_LEN,
877 "tx_queue_%u_packets", i);
878 p += ETH_GSTRING_LEN;
879 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
880 p += ETH_GSTRING_LEN;
883 ice_for_each_alloc_rxq(vsi, i) {
884 snprintf(p, ETH_GSTRING_LEN,
885 "rx_queue_%u_packets", i);
886 p += ETH_GSTRING_LEN;
887 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
888 p += ETH_GSTRING_LEN;
891 if (vsi->type != ICE_VSI_PF)
894 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
895 snprintf(p, ETH_GSTRING_LEN, "%s",
896 ice_gstrings_pf_stats[i].stat_string);
897 p += ETH_GSTRING_LEN;
900 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
901 snprintf(p, ETH_GSTRING_LEN,
902 "tx_priority_%u_xon.nic", i);
903 p += ETH_GSTRING_LEN;
904 snprintf(p, ETH_GSTRING_LEN,
905 "tx_priority_%u_xoff.nic", i);
906 p += ETH_GSTRING_LEN;
908 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
909 snprintf(p, ETH_GSTRING_LEN,
910 "rx_priority_%u_xon.nic", i);
911 p += ETH_GSTRING_LEN;
912 snprintf(p, ETH_GSTRING_LEN,
913 "rx_priority_%u_xoff.nic", i);
914 p += ETH_GSTRING_LEN;
918 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
920 case ETH_SS_PRIV_FLAGS:
921 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
922 snprintf(p, ETH_GSTRING_LEN, "%s",
923 ice_gstrings_priv_flags[i].name);
924 p += ETH_GSTRING_LEN;
933 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
935 struct ice_netdev_priv *np = netdev_priv(netdev);
939 case ETHTOOL_ID_ACTIVE:
942 case ETHTOOL_ID_INACTIVE:
949 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
956 * ice_set_fec_cfg - Set link FEC options
957 * @netdev: network interface device structure
958 * @req_fec: FEC mode to configure
960 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
962 struct ice_netdev_priv *np = netdev_priv(netdev);
963 struct ice_aqc_set_phy_cfg_data config = { 0 };
964 struct ice_aqc_get_phy_caps_data *caps;
965 struct ice_vsi *vsi = np->vsi;
966 u8 sw_cfg_caps, sw_cfg_fec;
967 struct ice_port_info *pi;
968 enum ice_status status;
975 /* Changing the FEC parameters is not supported if not the PF VSI */
976 if (vsi->type != ICE_VSI_PF) {
977 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
981 /* Get last SW configuration */
982 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
986 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
993 /* Copy SW configuration returned from PHY caps to PHY config */
994 ice_copy_phy_caps_to_cfg(caps, &config);
995 sw_cfg_caps = caps->caps;
996 sw_cfg_fec = caps->link_fec_options;
998 /* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
999 memset(caps, 0, sizeof(*caps));
1001 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1008 config.caps |= (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
1009 config.link_fec_opt = caps->link_fec_options;
1011 ice_cfg_phy_fec(&config, req_fec);
1013 /* If FEC mode has changed, then set PHY configuration and enable AN. */
1014 if ((config.caps & ICE_AQ_PHY_ENA_AUTO_FEC) !=
1015 (sw_cfg_caps & ICE_AQC_PHY_EN_AUTO_FEC) ||
1016 config.link_fec_opt != sw_cfg_fec) {
1017 if (caps->caps & ICE_AQC_PHY_AN_MODE)
1018 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1020 status = ice_aq_set_phy_cfg(pi->hw, pi->lport, &config, NULL);
1032 * ice_set_fecparam - Set FEC link options
1033 * @netdev: network interface device structure
1034 * @fecparam: Ethtool structure to retrieve FEC parameters
1037 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1039 struct ice_netdev_priv *np = netdev_priv(netdev);
1040 struct ice_vsi *vsi = np->vsi;
1041 enum ice_fec_mode fec;
1043 switch (fecparam->fec) {
1044 case ETHTOOL_FEC_AUTO:
1047 case ETHTOOL_FEC_RS:
1050 case ETHTOOL_FEC_BASER:
1051 fec = ICE_FEC_BASER;
1053 case ETHTOOL_FEC_OFF:
1054 case ETHTOOL_FEC_NONE:
1058 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1063 return ice_set_fec_cfg(netdev, fec);
1067 * ice_get_fecparam - Get link FEC options
1068 * @netdev: network interface device structure
1069 * @fecparam: Ethtool structure to retrieve FEC parameters
1072 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1074 struct ice_netdev_priv *np = netdev_priv(netdev);
1075 struct ice_aqc_get_phy_caps_data *caps;
1076 struct ice_link_status *link_info;
1077 struct ice_vsi *vsi = np->vsi;
1078 struct ice_port_info *pi;
1079 enum ice_status status;
1082 pi = vsi->port_info;
1086 link_info = &pi->phy.link_info;
1088 /* Set FEC mode based on negotiated link info */
1089 switch (link_info->fec_info) {
1090 case ICE_AQ_LINK_25G_KR_FEC_EN:
1091 fecparam->active_fec = ETHTOOL_FEC_BASER;
1093 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1095 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1096 fecparam->active_fec = ETHTOOL_FEC_RS;
1099 fecparam->active_fec = ETHTOOL_FEC_OFF;
1103 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1107 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1114 /* Set supported/configured FEC modes based on PHY capability */
1115 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1116 fecparam->fec |= ETHTOOL_FEC_AUTO;
1117 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1118 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1119 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1120 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1121 fecparam->fec |= ETHTOOL_FEC_BASER;
1122 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1123 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1124 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1125 fecparam->fec |= ETHTOOL_FEC_RS;
1126 if (caps->link_fec_options == 0)
1127 fecparam->fec |= ETHTOOL_FEC_OFF;
1135 * ice_get_priv_flags - report device private flags
1136 * @netdev: network interface device structure
1138 * The get string set count and the string set should be matched for each
1139 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1142 * Returns a u32 bitmap of flags.
1144 static u32 ice_get_priv_flags(struct net_device *netdev)
1146 struct ice_netdev_priv *np = netdev_priv(netdev);
1147 struct ice_vsi *vsi = np->vsi;
1148 struct ice_pf *pf = vsi->back;
1149 u32 i, ret_flags = 0;
1151 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1152 const struct ice_priv_flag *priv_flag;
1154 priv_flag = &ice_gstrings_priv_flags[i];
1156 if (test_bit(priv_flag->bitno, pf->flags))
1157 ret_flags |= BIT(i);
1164 * ice_set_priv_flags - set private flags
1165 * @netdev: network interface device structure
1166 * @flags: bit flags to be set
1168 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1170 struct ice_netdev_priv *np = netdev_priv(netdev);
1171 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1172 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1173 struct ice_vsi *vsi = np->vsi;
1174 struct ice_pf *pf = vsi->back;
1179 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1182 dev = ice_pf_to_dev(pf);
1183 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1185 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1186 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1187 const struct ice_priv_flag *priv_flag;
1189 priv_flag = &ice_gstrings_priv_flags[i];
1192 set_bit(priv_flag->bitno, pf->flags);
1194 clear_bit(priv_flag->bitno, pf->flags);
1197 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1199 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1200 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1201 enum ice_status status;
1203 /* Disable FW LLDP engine */
1204 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1206 /* If unregistering for LLDP events fails, this is
1207 * not an error state, as there shouldn't be any
1208 * events to respond to.
1211 dev_info(dev, "Failed to unreg for LLDP events\n");
1213 /* The AQ call to stop the FW LLDP agent will generate
1214 * an error if the agent is already stopped.
1216 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1218 dev_warn(dev, "Fail to stop LLDP agent\n");
1219 /* Use case for having the FW LLDP agent stopped
1220 * will likely not need DCB, so failure to init is
1221 * not a concern of ethtool
1223 status = ice_init_pf_dcb(pf, true);
1225 dev_warn(dev, "Fail to init DCB\n");
1227 enum ice_status status;
1228 bool dcbx_agent_status;
1230 /* AQ command to start FW LLDP agent will return an
1231 * error if the agent is already started
1233 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1235 dev_warn(dev, "Fail to start LLDP Agent\n");
1237 /* AQ command to start FW DCBX agent will fail if
1238 * the agent is already started
1240 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1244 dev_dbg(dev, "Failed to start FW DCBX\n");
1246 dev_info(dev, "FW DCBX agent is %s\n",
1247 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1249 /* Failure to configure MIB change or init DCB is not
1250 * relevant to ethtool. Print notification that
1251 * registration/init failed but do not return error
1254 status = ice_init_pf_dcb(pf, true);
1256 dev_dbg(dev, "Fail to init DCB\n");
1258 /* Remove rule to direct LLDP packets to default VSI.
1259 * The FW LLDP engine will now be consuming them.
1261 ice_cfg_sw_lldp(vsi, false, false);
1263 /* Register for MIB change events */
1264 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1266 dev_dbg(dev, "Fail to enable MIB change events\n");
1269 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1270 /* down and up VSI so that changes of Rx cfg are reflected. */
1274 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1278 static int ice_get_sset_count(struct net_device *netdev, int sset)
1282 /* The number (and order) of strings reported *must* remain
1283 * constant for a given netdevice. This function must not
1284 * report a different number based on run time parameters
1285 * (such as the number of queues in use, or the setting of
1286 * a private ethtool flag). This is due to the nature of the
1287 * ethtool stats API.
1289 * Userspace programs such as ethtool must make 3 separate
1290 * ioctl requests, one for size, one for the strings, and
1291 * finally one for the stats. Since these cross into
1292 * userspace, changes to the number or size could result in
1293 * undefined memory access or incorrect string<->value
1294 * correlations for statistics.
1296 * Even if it appears to be safe, changes to the size or
1297 * order of strings will suffer from race conditions and are
1300 return ICE_ALL_STATS_LEN(netdev);
1302 return ICE_TEST_LEN;
1303 case ETH_SS_PRIV_FLAGS:
1304 return ICE_PRIV_FLAG_ARRAY_SIZE;
1311 ice_get_ethtool_stats(struct net_device *netdev,
1312 struct ethtool_stats __always_unused *stats, u64 *data)
1314 struct ice_netdev_priv *np = netdev_priv(netdev);
1315 struct ice_vsi *vsi = np->vsi;
1316 struct ice_pf *pf = vsi->back;
1317 struct ice_ring *ring;
1322 ice_update_pf_stats(pf);
1323 ice_update_vsi_stats(vsi);
1325 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1326 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1327 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1328 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1331 /* populate per queue stats */
1334 ice_for_each_alloc_txq(vsi, j) {
1335 ring = READ_ONCE(vsi->tx_rings[j]);
1337 data[i++] = ring->stats.pkts;
1338 data[i++] = ring->stats.bytes;
1345 ice_for_each_alloc_rxq(vsi, j) {
1346 ring = READ_ONCE(vsi->rx_rings[j]);
1348 data[i++] = ring->stats.pkts;
1349 data[i++] = ring->stats.bytes;
1358 if (vsi->type != ICE_VSI_PF)
1361 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1362 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1363 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1364 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1367 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1368 data[i++] = pf->stats.priority_xon_tx[j];
1369 data[i++] = pf->stats.priority_xoff_tx[j];
1372 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1373 data[i++] = pf->stats.priority_xon_rx[j];
1374 data[i++] = pf->stats.priority_xoff_rx[j];
1379 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1380 * @netdev: network interface device structure
1381 * @ks: ethtool link ksettings struct to fill out
1384 ice_phy_type_to_ethtool(struct net_device *netdev,
1385 struct ethtool_link_ksettings *ks)
1387 struct ice_netdev_priv *np = netdev_priv(netdev);
1388 struct ice_link_status *hw_link_info;
1389 bool need_add_adv_mode = false;
1390 struct ice_vsi *vsi = np->vsi;
1394 hw_link_info = &vsi->port_info->phy.link_info;
1395 phy_types_low = vsi->port_info->phy.phy_type_low;
1396 phy_types_high = vsi->port_info->phy.phy_type_high;
1398 ethtool_link_ksettings_zero_link_mode(ks, supported);
1399 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1401 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1402 phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
1403 ethtool_link_ksettings_add_link_mode(ks, supported,
1405 if (!hw_link_info->req_speeds ||
1406 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
1407 ethtool_link_ksettings_add_link_mode(ks, advertising,
1410 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1411 phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
1412 ethtool_link_ksettings_add_link_mode(ks, supported,
1414 if (!hw_link_info->req_speeds ||
1415 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1416 ethtool_link_ksettings_add_link_mode(ks, advertising,
1419 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
1420 ethtool_link_ksettings_add_link_mode(ks, supported,
1422 if (!hw_link_info->req_speeds ||
1423 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1424 ethtool_link_ksettings_add_link_mode(ks, advertising,
1427 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
1428 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
1429 ethtool_link_ksettings_add_link_mode(ks, supported,
1431 if (!hw_link_info->req_speeds ||
1432 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1433 ethtool_link_ksettings_add_link_mode(ks, advertising,
1436 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
1437 ethtool_link_ksettings_add_link_mode(ks, supported,
1439 if (!hw_link_info->req_speeds ||
1440 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1441 ethtool_link_ksettings_add_link_mode(ks, advertising,
1444 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
1445 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
1446 ethtool_link_ksettings_add_link_mode(ks, supported,
1448 if (!hw_link_info->req_speeds ||
1449 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1450 ethtool_link_ksettings_add_link_mode(ks, advertising,
1453 if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1454 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
1455 ethtool_link_ksettings_add_link_mode(ks, supported,
1457 if (!hw_link_info->req_speeds ||
1458 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
1459 ethtool_link_ksettings_add_link_mode(ks, advertising,
1462 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1463 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
1464 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
1465 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
1466 ethtool_link_ksettings_add_link_mode(ks, supported,
1468 if (!hw_link_info->req_speeds ||
1469 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1470 ethtool_link_ksettings_add_link_mode(ks, advertising,
1473 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
1474 ethtool_link_ksettings_add_link_mode(ks, supported,
1476 if (!hw_link_info->req_speeds ||
1477 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1478 ethtool_link_ksettings_add_link_mode(ks, advertising,
1481 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
1482 ethtool_link_ksettings_add_link_mode(ks, supported,
1484 if (!hw_link_info->req_speeds ||
1485 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1486 ethtool_link_ksettings_add_link_mode(ks, advertising,
1489 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
1490 ethtool_link_ksettings_add_link_mode(ks, supported,
1492 if (!hw_link_info->req_speeds ||
1493 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1494 ethtool_link_ksettings_add_link_mode(ks, advertising,
1497 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1498 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1499 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1500 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1501 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
1502 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
1503 ethtool_link_ksettings_add_link_mode(ks, supported,
1505 if (!hw_link_info->req_speeds ||
1506 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1507 ethtool_link_ksettings_add_link_mode(ks, advertising,
1510 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
1511 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
1512 ethtool_link_ksettings_add_link_mode(ks, supported,
1514 if (!hw_link_info->req_speeds ||
1515 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1516 ethtool_link_ksettings_add_link_mode(ks, advertising,
1519 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1520 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1521 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
1522 ethtool_link_ksettings_add_link_mode(ks, supported,
1524 if (!hw_link_info->req_speeds ||
1525 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1526 ethtool_link_ksettings_add_link_mode(ks, advertising,
1529 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1530 ethtool_link_ksettings_add_link_mode(ks, supported,
1532 if (!hw_link_info->req_speeds ||
1533 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1534 ethtool_link_ksettings_add_link_mode(ks, advertising,
1537 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1538 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
1539 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
1540 ethtool_link_ksettings_add_link_mode(ks, supported,
1542 if (!hw_link_info->req_speeds ||
1543 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1544 ethtool_link_ksettings_add_link_mode(ks, advertising,
1547 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
1548 ethtool_link_ksettings_add_link_mode(ks, supported,
1550 if (!hw_link_info->req_speeds ||
1551 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1552 ethtool_link_ksettings_add_link_mode(ks, advertising,
1555 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
1556 ethtool_link_ksettings_add_link_mode(ks, supported,
1558 if (!hw_link_info->req_speeds ||
1559 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1560 ethtool_link_ksettings_add_link_mode(ks, advertising,
1563 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1564 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC ||
1565 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 ||
1566 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC ||
1567 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 ||
1568 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1569 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR ||
1570 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC ||
1571 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) {
1572 ethtool_link_ksettings_add_link_mode(ks, supported,
1574 if (!hw_link_info->req_speeds ||
1575 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1576 ethtool_link_ksettings_add_link_mode(ks, advertising,
1579 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1580 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1581 ethtool_link_ksettings_add_link_mode(ks, supported,
1583 if (!hw_link_info->req_speeds ||
1584 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1585 ethtool_link_ksettings_add_link_mode(ks, advertising,
1588 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 ||
1589 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 ||
1590 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR ||
1591 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) {
1592 ethtool_link_ksettings_add_link_mode(ks, supported,
1594 if (!hw_link_info->req_speeds ||
1595 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1596 ethtool_link_ksettings_add_link_mode(ks, advertising,
1599 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1600 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC ||
1601 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 ||
1602 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC ||
1603 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 ||
1604 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 ||
1605 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2 ||
1606 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC ||
1607 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 ||
1608 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC ||
1609 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) {
1610 ethtool_link_ksettings_add_link_mode(ks, supported,
1611 100000baseCR4_Full);
1612 if (!hw_link_info->req_speeds ||
1613 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1614 need_add_adv_mode = true;
1616 if (need_add_adv_mode) {
1617 need_add_adv_mode = false;
1618 ethtool_link_ksettings_add_link_mode(ks, advertising,
1619 100000baseCR4_Full);
1621 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 ||
1622 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) {
1623 ethtool_link_ksettings_add_link_mode(ks, supported,
1624 100000baseSR4_Full);
1625 if (!hw_link_info->req_speeds ||
1626 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1627 need_add_adv_mode = true;
1629 if (need_add_adv_mode) {
1630 need_add_adv_mode = false;
1631 ethtool_link_ksettings_add_link_mode(ks, advertising,
1632 100000baseSR4_Full);
1634 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 ||
1635 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) {
1636 ethtool_link_ksettings_add_link_mode(ks, supported,
1637 100000baseLR4_ER4_Full);
1638 if (!hw_link_info->req_speeds ||
1639 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1640 need_add_adv_mode = true;
1642 if (need_add_adv_mode) {
1643 need_add_adv_mode = false;
1644 ethtool_link_ksettings_add_link_mode(ks, advertising,
1645 100000baseLR4_ER4_Full);
1647 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1648 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1649 phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) {
1650 ethtool_link_ksettings_add_link_mode(ks, supported,
1651 100000baseKR4_Full);
1652 if (!hw_link_info->req_speeds ||
1653 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1654 need_add_adv_mode = true;
1656 if (need_add_adv_mode)
1657 ethtool_link_ksettings_add_link_mode(ks, advertising,
1658 100000baseKR4_Full);
1660 /* Autoneg PHY types */
1661 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1662 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1663 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
1664 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
1665 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
1666 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1667 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
1668 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1669 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
1670 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1671 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1672 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1673 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1674 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1675 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1676 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
1677 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1678 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1679 ethtool_link_ksettings_add_link_mode(ks, supported,
1681 ethtool_link_ksettings_add_link_mode(ks, advertising,
1684 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1685 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1686 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1687 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1688 ethtool_link_ksettings_add_link_mode(ks, supported,
1690 ethtool_link_ksettings_add_link_mode(ks, advertising,
1693 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1694 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1695 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1696 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) {
1697 ethtool_link_ksettings_add_link_mode(ks, supported,
1699 ethtool_link_ksettings_add_link_mode(ks, advertising,
1704 #define TEST_SET_BITS_TIMEOUT 50
1705 #define TEST_SET_BITS_SLEEP_MAX 2000
1706 #define TEST_SET_BITS_SLEEP_MIN 1000
1709 * ice_get_settings_link_up - Get Link settings for when link is up
1710 * @ks: ethtool ksettings to fill in
1711 * @netdev: network interface device structure
1714 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1715 struct net_device *netdev)
1717 struct ice_netdev_priv *np = netdev_priv(netdev);
1718 struct ice_port_info *pi = np->vsi->port_info;
1719 struct ice_link_status *link_info;
1720 struct ice_vsi *vsi = np->vsi;
1722 link_info = &vsi->port_info->phy.link_info;
1724 /* Get supported and advertised settings from PHY ability with media */
1725 ice_phy_type_to_ethtool(netdev, ks);
1727 switch (link_info->link_speed) {
1728 case ICE_AQ_LINK_SPEED_100GB:
1729 ks->base.speed = SPEED_100000;
1731 case ICE_AQ_LINK_SPEED_50GB:
1732 ks->base.speed = SPEED_50000;
1734 case ICE_AQ_LINK_SPEED_40GB:
1735 ks->base.speed = SPEED_40000;
1737 case ICE_AQ_LINK_SPEED_25GB:
1738 ks->base.speed = SPEED_25000;
1740 case ICE_AQ_LINK_SPEED_20GB:
1741 ks->base.speed = SPEED_20000;
1743 case ICE_AQ_LINK_SPEED_10GB:
1744 ks->base.speed = SPEED_10000;
1746 case ICE_AQ_LINK_SPEED_5GB:
1747 ks->base.speed = SPEED_5000;
1749 case ICE_AQ_LINK_SPEED_2500MB:
1750 ks->base.speed = SPEED_2500;
1752 case ICE_AQ_LINK_SPEED_1000MB:
1753 ks->base.speed = SPEED_1000;
1755 case ICE_AQ_LINK_SPEED_100MB:
1756 ks->base.speed = SPEED_100;
1759 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1760 link_info->link_speed);
1763 ks->base.duplex = DUPLEX_FULL;
1765 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1766 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1769 /* Set flow control negotiated Rx/Tx pause */
1770 switch (pi->fc.current_mode) {
1772 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1774 case ICE_FC_TX_PAUSE:
1775 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1776 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1779 case ICE_FC_RX_PAUSE:
1780 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1786 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1787 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1794 * ice_get_settings_link_down - Get the Link settings when link is down
1795 * @ks: ethtool ksettings to fill in
1796 * @netdev: network interface device structure
1798 * Reports link settings that can be determined when link is down
1801 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1802 struct net_device *netdev)
1804 /* link is down and the driver needs to fall back on
1805 * supported PHY types to figure out what info to display
1807 ice_phy_type_to_ethtool(netdev, ks);
1809 /* With no link, speed and duplex are unknown */
1810 ks->base.speed = SPEED_UNKNOWN;
1811 ks->base.duplex = DUPLEX_UNKNOWN;
1815 * ice_get_link_ksettings - Get Link Speed and Duplex settings
1816 * @netdev: network interface device structure
1817 * @ks: ethtool ksettings
1819 * Reports speed/duplex settings based on media_type
1822 ice_get_link_ksettings(struct net_device *netdev,
1823 struct ethtool_link_ksettings *ks)
1825 struct ice_netdev_priv *np = netdev_priv(netdev);
1826 struct ice_aqc_get_phy_caps_data *caps;
1827 struct ice_link_status *hw_link_info;
1828 struct ice_vsi *vsi = np->vsi;
1829 enum ice_status status;
1832 ethtool_link_ksettings_zero_link_mode(ks, supported);
1833 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1834 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1835 hw_link_info = &vsi->port_info->phy.link_info;
1837 /* set speed and duplex */
1838 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1839 ice_get_settings_link_up(ks, netdev);
1841 ice_get_settings_link_down(ks, netdev);
1843 /* set autoneg settings */
1844 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1845 AUTONEG_ENABLE : AUTONEG_DISABLE;
1847 /* set media type settings */
1848 switch (vsi->port_info->phy.media_type) {
1849 case ICE_MEDIA_FIBER:
1850 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1851 ks->base.port = PORT_FIBRE;
1853 case ICE_MEDIA_BASET:
1854 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1855 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1856 ks->base.port = PORT_TP;
1858 case ICE_MEDIA_BACKPLANE:
1859 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1860 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1861 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1862 ethtool_link_ksettings_add_link_mode(ks, advertising,
1864 ks->base.port = PORT_NONE;
1867 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1868 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1869 ks->base.port = PORT_DA;
1872 ks->base.port = PORT_OTHER;
1876 /* flow control is symmetric and always supported */
1877 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1879 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1883 status = ice_aq_get_phy_caps(vsi->port_info, false,
1884 ICE_AQC_REPORT_SW_CFG, caps, NULL);
1890 /* Set the advertised flow control based on the PHY capability */
1891 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
1892 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
1893 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1894 ethtool_link_ksettings_add_link_mode(ks, advertising,
1896 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
1897 ethtool_link_ksettings_add_link_mode(ks, advertising,
1899 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
1900 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1901 ethtool_link_ksettings_add_link_mode(ks, advertising,
1904 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
1905 ethtool_link_ksettings_del_link_mode(ks, advertising,
1909 /* Set advertised FEC modes based on PHY capability */
1910 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
1912 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1913 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1914 ethtool_link_ksettings_add_link_mode(ks, advertising,
1916 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1917 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
1918 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
1920 status = ice_aq_get_phy_caps(vsi->port_info, false,
1921 ICE_AQC_REPORT_TOPO_CAP, caps, NULL);
1927 /* Set supported FEC modes based on PHY capability */
1928 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
1930 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1931 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
1932 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
1933 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1934 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
1942 * ice_ksettings_find_adv_link_speed - Find advertising link speed
1943 * @ks: ethtool ksettings
1946 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
1948 u16 adv_link_speed = 0;
1950 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1952 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
1953 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1955 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
1956 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1958 ethtool_link_ksettings_test_link_mode(ks, advertising,
1960 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
1961 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1963 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
1964 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1966 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
1967 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1969 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
1970 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1972 ethtool_link_ksettings_test_link_mode(ks, advertising,
1974 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
1975 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1976 10000baseSR_Full) ||
1977 ethtool_link_ksettings_test_link_mode(ks, advertising,
1979 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
1980 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1981 25000baseCR_Full) ||
1982 ethtool_link_ksettings_test_link_mode(ks, advertising,
1983 25000baseSR_Full) ||
1984 ethtool_link_ksettings_test_link_mode(ks, advertising,
1986 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
1987 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1988 40000baseCR4_Full) ||
1989 ethtool_link_ksettings_test_link_mode(ks, advertising,
1990 40000baseSR4_Full) ||
1991 ethtool_link_ksettings_test_link_mode(ks, advertising,
1992 40000baseLR4_Full) ||
1993 ethtool_link_ksettings_test_link_mode(ks, advertising,
1995 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
1996 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
1997 50000baseCR2_Full) ||
1998 ethtool_link_ksettings_test_link_mode(ks, advertising,
2000 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2001 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2003 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2004 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2005 100000baseCR4_Full) ||
2006 ethtool_link_ksettings_test_link_mode(ks, advertising,
2007 100000baseSR4_Full) ||
2008 ethtool_link_ksettings_test_link_mode(ks, advertising,
2009 100000baseLR4_ER4_Full) ||
2010 ethtool_link_ksettings_test_link_mode(ks, advertising,
2011 100000baseKR4_Full))
2012 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2014 return adv_link_speed;
2020 * @ks: ethtool_link_ksettings
2021 * @config: configuration that will be sent down to FW
2022 * @autoneg_enabled: autonegotiation is enabled or not
2023 * @autoneg_changed: will there a change in autonegotiation
2024 * @netdev: network interface device structure
2026 * Setup PHY autonegotiation feature
2029 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2030 struct ice_aqc_set_phy_cfg_data *config,
2031 u8 autoneg_enabled, u8 *autoneg_changed,
2032 struct net_device *netdev)
2036 *autoneg_changed = 0;
2039 if (autoneg_enabled == AUTONEG_ENABLE) {
2040 /* If autoneg was not already enabled */
2041 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2042 /* If autoneg is not supported, return error */
2043 if (!ethtool_link_ksettings_test_link_mode(ks,
2046 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2049 /* Autoneg is allowed to change */
2050 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2051 *autoneg_changed = 1;
2055 /* If autoneg is currently enabled */
2056 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2057 /* If autoneg is supported 10GBASE_T is the only PHY
2058 * that can disable it, so otherwise return error
2060 if (ethtool_link_ksettings_test_link_mode(ks,
2063 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2066 /* Autoneg is allowed to change */
2067 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2068 *autoneg_changed = 1;
2077 * ice_set_link_ksettings - Set Speed and Duplex
2078 * @netdev: network interface device structure
2079 * @ks: ethtool ksettings
2081 * Set speed/duplex per media_types advertised/forced
2084 ice_set_link_ksettings(struct net_device *netdev,
2085 const struct ethtool_link_ksettings *ks)
2087 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
2088 struct ice_netdev_priv *np = netdev_priv(netdev);
2089 struct ethtool_link_ksettings safe_ks, copy_ks;
2090 struct ice_aqc_get_phy_caps_data *abilities;
2091 u16 adv_link_speed, curr_link_speed, idx;
2092 struct ice_aqc_set_phy_cfg_data config;
2093 struct ice_pf *pf = np->vsi->back;
2094 struct ice_port_info *p;
2095 u8 autoneg_changed = 0;
2096 enum ice_status status;
2102 p = np->vsi->port_info;
2107 /* Check if this is LAN VSI */
2108 ice_for_each_vsi(pf, idx)
2109 if (pf->vsi[idx]->type == ICE_VSI_PF) {
2110 if (np->vsi != pf->vsi[idx])
2115 if (p->phy.media_type != ICE_MEDIA_BASET &&
2116 p->phy.media_type != ICE_MEDIA_FIBER &&
2117 p->phy.media_type != ICE_MEDIA_BACKPLANE &&
2118 p->phy.media_type != ICE_MEDIA_DA &&
2119 p->phy.link_info.link_info & ICE_AQ_LINK_UP)
2122 /* copy the ksettings to copy_ks to avoid modifying the original */
2123 memcpy(©_ks, ks, sizeof(copy_ks));
2125 /* save autoneg out of ksettings */
2126 autoneg = copy_ks.base.autoneg;
2128 memset(&safe_ks, 0, sizeof(safe_ks));
2130 /* Get link modes supported by hardware.*/
2131 ice_phy_type_to_ethtool(netdev, &safe_ks);
2133 /* and check against modes requested by user.
2134 * Return an error if unsupported mode was set.
2136 if (!bitmap_subset(copy_ks.link_modes.advertising,
2137 safe_ks.link_modes.supported,
2138 __ETHTOOL_LINK_MODE_MASK_NBITS))
2141 /* get our own copy of the bits to check against */
2142 memset(&safe_ks, 0, sizeof(safe_ks));
2143 safe_ks.base.cmd = copy_ks.base.cmd;
2144 safe_ks.base.link_mode_masks_nwords =
2145 copy_ks.base.link_mode_masks_nwords;
2146 ice_get_link_ksettings(netdev, &safe_ks);
2148 /* set autoneg back to what it currently is */
2149 copy_ks.base.autoneg = safe_ks.base.autoneg;
2150 /* we don't compare the speed */
2151 copy_ks.base.speed = safe_ks.base.speed;
2153 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2154 * trying to set something that we do not support.
2156 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base)))
2159 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2163 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2166 abilities = kzalloc(sizeof(*abilities), GFP_KERNEL);
2170 /* Get the current PHY config */
2171 status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
2178 /* Copy abilities to config in case autoneg is not set below */
2179 memset(&config, 0, sizeof(config));
2180 config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
2181 if (abilities->caps & ICE_AQC_PHY_AN_MODE)
2182 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2185 err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
2191 /* Call to get the current link speed */
2192 p->phy.get_link_info = true;
2193 status = ice_get_link_status(p, &linkup);
2199 curr_link_speed = p->phy.link_info.link_speed;
2200 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2202 /* If speed didn't get set, set it to what it currently is.
2203 * This is needed because if advertise is 0 (as it is when autoneg
2204 * is disabled) then speed won't get set.
2206 if (!adv_link_speed)
2207 adv_link_speed = curr_link_speed;
2209 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2210 ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed);
2212 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2213 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2217 /* copy over the rest of the abilities */
2218 config.low_power_ctrl = abilities->low_power_ctrl;
2219 config.eee_cap = abilities->eee_cap;
2220 config.eeer_value = abilities->eeer_value;
2221 config.link_fec_opt = abilities->link_fec_options;
2223 /* save the requested speeds */
2224 p->phy.link_info.req_speeds = adv_link_speed;
2226 /* set link and auto negotiation so changes take effect */
2227 config.caps |= ICE_AQ_PHY_ENA_LINK;
2229 if (phy_type_low || phy_type_high) {
2230 config.phy_type_high = cpu_to_le64(phy_type_high) &
2231 abilities->phy_type_high;
2232 config.phy_type_low = cpu_to_le64(phy_type_low) &
2233 abilities->phy_type_low;
2236 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2240 /* If link is up put link down */
2241 if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2242 /* Tell the OS link is going down, the link will go
2243 * back up when fw says it is ready asynchronously
2245 ice_print_link_msg(np->vsi, false);
2246 netif_carrier_off(netdev);
2247 netif_tx_stop_all_queues(netdev);
2250 /* make the aq call */
2251 status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
2253 netdev_info(netdev, "Set phy config failed,\n");
2259 clear_bit(__ICE_CFG_BUSY, pf->state);
2265 * ice_parse_hdrs - parses headers from RSS hash input
2266 * @nfc: ethtool rxnfc command
2268 * This function parses the rxnfc command and returns intended
2269 * header types for RSS configuration
2271 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2273 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2275 switch (nfc->flow_type) {
2277 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2280 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2283 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2286 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2289 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2292 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2300 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2301 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2302 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2303 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2304 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2305 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2306 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2307 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2308 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2309 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2310 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2311 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2314 * ice_parse_hash_flds - parses hash fields from RSS hash input
2315 * @nfc: ethtool rxnfc command
2317 * This function parses the rxnfc command and returns intended
2318 * hash fields for RSS configuration
2320 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2322 u64 hfld = ICE_HASH_INVALID;
2324 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2325 switch (nfc->flow_type) {
2329 if (nfc->data & RXH_IP_SRC)
2330 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2331 if (nfc->data & RXH_IP_DST)
2332 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2337 if (nfc->data & RXH_IP_SRC)
2338 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2339 if (nfc->data & RXH_IP_DST)
2340 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2347 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2348 switch (nfc->flow_type) {
2351 if (nfc->data & RXH_L4_B_0_1)
2352 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2353 if (nfc->data & RXH_L4_B_2_3)
2354 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2358 if (nfc->data & RXH_L4_B_0_1)
2359 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2360 if (nfc->data & RXH_L4_B_2_3)
2361 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2365 if (nfc->data & RXH_L4_B_0_1)
2366 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2367 if (nfc->data & RXH_L4_B_2_3)
2368 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2379 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2380 * @vsi: the VSI being configured
2381 * @nfc: ethtool rxnfc command
2383 * Returns Success if the flow input set is supported.
2386 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2388 struct ice_pf *pf = vsi->back;
2389 enum ice_status status;
2394 dev = ice_pf_to_dev(pf);
2395 if (ice_is_safe_mode(pf)) {
2396 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2401 hashed_flds = ice_parse_hash_flds(nfc);
2402 if (hashed_flds == ICE_HASH_INVALID) {
2403 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2408 hdrs = ice_parse_hdrs(nfc);
2409 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2410 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2415 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2417 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
2418 vsi->vsi_num, status);
2426 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2427 * @vsi: the VSI being configured
2428 * @nfc: ethtool rxnfc command
2431 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2433 struct ice_pf *pf = vsi->back;
2438 dev = ice_pf_to_dev(pf);
2441 if (ice_is_safe_mode(pf)) {
2442 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2447 hdrs = ice_parse_hdrs(nfc);
2448 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2449 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2454 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2455 if (hash_flds == ICE_HASH_INVALID) {
2456 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2461 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2462 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2463 nfc->data |= (u64)RXH_IP_SRC;
2465 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2466 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2467 nfc->data |= (u64)RXH_IP_DST;
2469 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2470 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2471 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2472 nfc->data |= (u64)RXH_L4_B_0_1;
2474 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2475 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2476 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2477 nfc->data |= (u64)RXH_L4_B_2_3;
2481 * ice_set_rxnfc - command to set Rx flow rules.
2482 * @netdev: network interface device structure
2483 * @cmd: ethtool rxnfc command
2485 * Returns 0 for success and negative values for errors
2487 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2489 struct ice_netdev_priv *np = netdev_priv(netdev);
2490 struct ice_vsi *vsi = np->vsi;
2494 return ice_set_rss_hash_opt(vsi, cmd);
2502 * ice_get_rxnfc - command to get Rx flow classification rules
2503 * @netdev: network interface device structure
2504 * @cmd: ethtool rxnfc command
2505 * @rule_locs: buffer to rturn Rx flow classification rules
2507 * Returns Success if the command is supported.
2510 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2511 u32 __always_unused *rule_locs)
2513 struct ice_netdev_priv *np = netdev_priv(netdev);
2514 struct ice_vsi *vsi = np->vsi;
2515 int ret = -EOPNOTSUPP;
2518 case ETHTOOL_GRXRINGS:
2519 cmd->data = vsi->rss_size;
2523 ice_get_rss_hash_opt(vsi, cmd);
2534 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2536 struct ice_netdev_priv *np = netdev_priv(netdev);
2537 struct ice_vsi *vsi = np->vsi;
2539 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2540 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2541 ring->rx_pending = vsi->rx_rings[0]->count;
2542 ring->tx_pending = vsi->tx_rings[0]->count;
2544 /* Rx mini and jumbo rings are not supported */
2545 ring->rx_mini_max_pending = 0;
2546 ring->rx_jumbo_max_pending = 0;
2547 ring->rx_mini_pending = 0;
2548 ring->rx_jumbo_pending = 0;
2552 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2554 struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2555 struct ice_netdev_priv *np = netdev_priv(netdev);
2556 struct ice_ring *xdp_rings = NULL;
2557 struct ice_vsi *vsi = np->vsi;
2558 struct ice_pf *pf = vsi->back;
2559 int i, timeout = 50, err = 0;
2560 u32 new_rx_cnt, new_tx_cnt;
2562 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2563 ring->tx_pending < ICE_MIN_NUM_DESC ||
2564 ring->rx_pending > ICE_MAX_NUM_DESC ||
2565 ring->rx_pending < ICE_MIN_NUM_DESC) {
2566 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2567 ring->tx_pending, ring->rx_pending,
2568 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2569 ICE_REQ_DESC_MULTIPLE);
2573 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2574 if (new_tx_cnt != ring->tx_pending)
2575 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2577 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2578 if (new_rx_cnt != ring->rx_pending)
2579 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2582 /* if nothing to do return success */
2583 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2584 new_rx_cnt == vsi->rx_rings[0]->count) {
2585 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2589 /* If there is a AF_XDP UMEM attached to any of Rx rings,
2590 * disallow changing the number of descriptors -- regardless
2591 * if the netdev is running or not.
2593 if (ice_xsk_any_rx_ring_ena(vsi))
2596 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2600 usleep_range(1000, 2000);
2603 /* set for the next time the netdev is started */
2604 if (!netif_running(vsi->netdev)) {
2605 for (i = 0; i < vsi->alloc_txq; i++)
2606 vsi->tx_rings[i]->count = new_tx_cnt;
2607 for (i = 0; i < vsi->alloc_rxq; i++)
2608 vsi->rx_rings[i]->count = new_rx_cnt;
2609 if (ice_is_xdp_ena_vsi(vsi))
2610 for (i = 0; i < vsi->num_xdp_txq; i++)
2611 vsi->xdp_rings[i]->count = new_tx_cnt;
2612 vsi->num_tx_desc = new_tx_cnt;
2613 vsi->num_rx_desc = new_rx_cnt;
2614 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2618 if (new_tx_cnt == vsi->tx_rings[0]->count)
2621 /* alloc updated Tx resources */
2622 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2623 vsi->tx_rings[0]->count, new_tx_cnt);
2625 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2631 ice_for_each_txq(vsi, i) {
2632 /* clone ring and setup updated count */
2633 tx_rings[i] = *vsi->tx_rings[i];
2634 tx_rings[i].count = new_tx_cnt;
2635 tx_rings[i].desc = NULL;
2636 tx_rings[i].tx_buf = NULL;
2637 err = ice_setup_tx_ring(&tx_rings[i]);
2640 ice_clean_tx_ring(&tx_rings[i]);
2646 if (!ice_is_xdp_ena_vsi(vsi))
2649 /* alloc updated XDP resources */
2650 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2651 vsi->xdp_rings[0]->count, new_tx_cnt);
2653 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2659 for (i = 0; i < vsi->num_xdp_txq; i++) {
2660 /* clone ring and setup updated count */
2661 xdp_rings[i] = *vsi->xdp_rings[i];
2662 xdp_rings[i].count = new_tx_cnt;
2663 xdp_rings[i].desc = NULL;
2664 xdp_rings[i].tx_buf = NULL;
2665 err = ice_setup_tx_ring(&xdp_rings[i]);
2668 ice_clean_tx_ring(&xdp_rings[i]);
2672 ice_set_ring_xdp(&xdp_rings[i]);
2676 if (new_rx_cnt == vsi->rx_rings[0]->count)
2679 /* alloc updated Rx resources */
2680 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2681 vsi->rx_rings[0]->count, new_rx_cnt);
2683 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2689 ice_for_each_rxq(vsi, i) {
2690 /* clone ring and setup updated count */
2691 rx_rings[i] = *vsi->rx_rings[i];
2692 rx_rings[i].count = new_rx_cnt;
2693 rx_rings[i].desc = NULL;
2694 rx_rings[i].rx_buf = NULL;
2695 /* this is to allow wr32 to have something to write to
2696 * during early allocation of Rx buffers
2698 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2700 err = ice_setup_rx_ring(&rx_rings[i]);
2704 /* allocate Rx buffers */
2705 err = ice_alloc_rx_bufs(&rx_rings[i],
2706 ICE_DESC_UNUSED(&rx_rings[i]));
2711 ice_free_rx_ring(&rx_rings[i]);
2720 /* Bring interface down, copy in the new ring info, then restore the
2721 * interface. if VSI is up, bring it down and then back up
2723 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2727 ice_for_each_txq(vsi, i) {
2728 ice_free_tx_ring(vsi->tx_rings[i]);
2729 *vsi->tx_rings[i] = tx_rings[i];
2735 ice_for_each_rxq(vsi, i) {
2736 ice_free_rx_ring(vsi->rx_rings[i]);
2737 /* copy the real tail offset */
2738 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2739 /* this is to fake out the allocation routine
2740 * into thinking it has to realloc everything
2741 * but the recycling logic will let us re-use
2742 * the buffers allocated above
2744 rx_rings[i].next_to_use = 0;
2745 rx_rings[i].next_to_clean = 0;
2746 rx_rings[i].next_to_alloc = 0;
2747 *vsi->rx_rings[i] = rx_rings[i];
2753 for (i = 0; i < vsi->num_xdp_txq; i++) {
2754 ice_free_tx_ring(vsi->xdp_rings[i]);
2755 *vsi->xdp_rings[i] = xdp_rings[i];
2760 vsi->num_tx_desc = new_tx_cnt;
2761 vsi->num_rx_desc = new_rx_cnt;
2767 /* error cleanup if the Rx allocations failed after getting Tx */
2769 ice_for_each_txq(vsi, i)
2770 ice_free_tx_ring(&tx_rings[i]);
2775 clear_bit(__ICE_CFG_BUSY, pf->state);
2779 static int ice_nway_reset(struct net_device *netdev)
2781 /* restart autonegotiation */
2782 struct ice_netdev_priv *np = netdev_priv(netdev);
2783 struct ice_vsi *vsi = np->vsi;
2784 struct ice_port_info *pi;
2785 enum ice_status status;
2787 pi = vsi->port_info;
2788 /* If VSI state is up, then restart autoneg with link up */
2789 if (!test_bit(__ICE_DOWN, vsi->back->state))
2790 status = ice_aq_set_link_restart_an(pi, true, NULL);
2792 status = ice_aq_set_link_restart_an(pi, false, NULL);
2795 netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
2796 status, pi->hw->adminq.sq_last_status);
2804 * ice_get_pauseparam - Get Flow Control status
2805 * @netdev: network interface device structure
2806 * @pause: ethernet pause (flow control) parameters
2808 * Get requested flow control status from PHY capability.
2809 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2810 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2811 * the negotiated Rx/Tx pause via lp_advertising.
2814 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2816 struct ice_netdev_priv *np = netdev_priv(netdev);
2817 struct ice_port_info *pi = np->vsi->port_info;
2818 struct ice_aqc_get_phy_caps_data *pcaps;
2819 struct ice_dcbx_cfg *dcbx_cfg;
2820 enum ice_status status;
2822 /* Initialize pause params */
2823 pause->rx_pause = 0;
2824 pause->tx_pause = 0;
2826 dcbx_cfg = &pi->local_dcbx_cfg;
2828 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2832 /* Get current PHY config */
2833 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2838 pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2839 AUTONEG_ENABLE : AUTONEG_DISABLE);
2841 if (dcbx_cfg->pfc.pfcena)
2842 /* PFC enabled so report LFC as off */
2845 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2846 pause->tx_pause = 1;
2847 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2848 pause->rx_pause = 1;
2855 * ice_set_pauseparam - Set Flow Control parameter
2856 * @netdev: network interface device structure
2857 * @pause: return Tx/Rx flow control status
2860 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2862 struct ice_netdev_priv *np = netdev_priv(netdev);
2863 struct ice_aqc_get_phy_caps_data *pcaps;
2864 struct ice_link_status *hw_link_info;
2865 struct ice_pf *pf = np->vsi->back;
2866 struct ice_dcbx_cfg *dcbx_cfg;
2867 struct ice_vsi *vsi = np->vsi;
2868 struct ice_hw *hw = &pf->hw;
2869 struct ice_port_info *pi;
2870 enum ice_status status;
2876 pi = vsi->port_info;
2877 hw_link_info = &pi->phy.link_info;
2878 dcbx_cfg = &pi->local_dcbx_cfg;
2879 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
2881 /* Changing the port's flow control is not supported if this isn't the
2884 if (vsi->type != ICE_VSI_PF) {
2885 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
2889 /* Get pause param reports configured and negotiated flow control pause
2890 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2891 * defined get pause param pause->autoneg reports SW configured setting,
2892 * so compare pause->autoneg with SW configured to prevent the user from
2893 * using set pause param to chance autoneg.
2895 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2899 /* Get current PHY config */
2900 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2907 is_an = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2908 AUTONEG_ENABLE : AUTONEG_DISABLE);
2912 if (pause->autoneg != is_an) {
2913 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2917 /* If we have link and don't have autoneg */
2918 if (!test_bit(__ICE_DOWN, pf->state) &&
2919 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
2920 /* Send message that it might not necessarily work*/
2921 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2924 if (dcbx_cfg->pfc.pfcena) {
2925 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
2928 if (pause->rx_pause && pause->tx_pause)
2929 pi->fc.req_mode = ICE_FC_FULL;
2930 else if (pause->rx_pause && !pause->tx_pause)
2931 pi->fc.req_mode = ICE_FC_RX_PAUSE;
2932 else if (!pause->rx_pause && pause->tx_pause)
2933 pi->fc.req_mode = ICE_FC_TX_PAUSE;
2934 else if (!pause->rx_pause && !pause->tx_pause)
2935 pi->fc.req_mode = ICE_FC_NONE;
2939 /* Set the FC mode and only restart AN if link is up */
2940 status = ice_set_fc(pi, &aq_failures, link_up);
2942 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
2943 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2944 status, hw->adminq.sq_last_status);
2946 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
2947 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2948 status, hw->adminq.sq_last_status);
2950 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
2951 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2952 status, hw->adminq.sq_last_status);
2956 if (!test_bit(__ICE_DOWN, pf->state)) {
2957 /* Give it a little more time to try to come back. If still
2958 * down, restart autoneg link or reinitialize the interface.
2961 if (!test_bit(__ICE_DOWN, pf->state))
2962 return ice_nway_reset(netdev);
2972 * ice_get_rxfh_key_size - get the RSS hash key size
2973 * @netdev: network interface device structure
2975 * Returns the table size.
2977 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
2979 return ICE_VSIQF_HKEY_ARRAY_SIZE;
2983 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
2984 * @netdev: network interface device structure
2986 * Returns the table size.
2988 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
2990 struct ice_netdev_priv *np = netdev_priv(netdev);
2992 return np->vsi->rss_table_size;
2996 * ice_get_rxfh - get the Rx flow hash indirection table
2997 * @netdev: network interface device structure
2998 * @indir: indirection table
3000 * @hfunc: hash function
3002 * Reads the indirection table directly from the hardware.
3005 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3007 struct ice_netdev_priv *np = netdev_priv(netdev);
3008 struct ice_vsi *vsi = np->vsi;
3009 struct ice_pf *pf = vsi->back;
3014 *hfunc = ETH_RSS_HASH_TOP;
3019 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3020 /* RSS not supported return error here */
3021 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3025 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3029 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3034 for (i = 0; i < vsi->rss_table_size; i++)
3035 indir[i] = (u32)(lut[i]);
3043 * ice_set_rxfh - set the Rx flow hash indirection table
3044 * @netdev: network interface device structure
3045 * @indir: indirection table
3047 * @hfunc: hash function
3049 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3050 * returns 0 after programming the table.
3053 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3056 struct ice_netdev_priv *np = netdev_priv(netdev);
3057 struct ice_vsi *vsi = np->vsi;
3058 struct ice_pf *pf = vsi->back;
3062 dev = ice_pf_to_dev(pf);
3063 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3066 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3067 /* RSS not supported return error here */
3068 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3073 if (!vsi->rss_hkey_user) {
3074 vsi->rss_hkey_user =
3075 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3077 if (!vsi->rss_hkey_user)
3080 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3081 seed = vsi->rss_hkey_user;
3084 if (!vsi->rss_lut_user) {
3085 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3087 if (!vsi->rss_lut_user)
3091 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3095 for (i = 0; i < vsi->rss_table_size; i++)
3096 vsi->rss_lut_user[i] = (u8)(indir[i]);
3098 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3102 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3109 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3112 static int ice_get_max_txq(struct ice_pf *pf)
3114 return min_t(int, num_online_cpus(),
3115 pf->hw.func_caps.common_cap.num_txq);
3119 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3122 static int ice_get_max_rxq(struct ice_pf *pf)
3124 return min_t(int, num_online_cpus(),
3125 pf->hw.func_caps.common_cap.num_rxq);
3129 * ice_get_combined_cnt - return the current number of combined channels
3130 * @vsi: PF VSI pointer
3132 * Go through all queue vectors and count ones that have both Rx and Tx ring
3135 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3140 ice_for_each_q_vector(vsi, q_idx) {
3141 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3143 if (q_vector->rx.ring && q_vector->tx.ring)
3151 * ice_get_channels - get the current and max supported channels
3152 * @dev: network interface device structure
3153 * @ch: ethtool channel data structure
3156 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3158 struct ice_netdev_priv *np = netdev_priv(dev);
3159 struct ice_vsi *vsi = np->vsi;
3160 struct ice_pf *pf = vsi->back;
3162 /* check to see if VSI is active */
3163 if (test_bit(__ICE_DOWN, vsi->state))
3166 /* report maximum channels */
3167 ch->max_rx = ice_get_max_rxq(pf);
3168 ch->max_tx = ice_get_max_txq(pf);
3169 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3171 /* report current channels */
3172 ch->combined_count = ice_get_combined_cnt(vsi);
3173 ch->rx_count = vsi->num_rxq - ch->combined_count;
3174 ch->tx_count = vsi->num_txq - ch->combined_count;
3178 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3179 * @vsi: VSI to reconfigure RSS LUT on
3180 * @req_rss_size: requested range of queue numbers for hashing
3182 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3184 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3186 struct ice_pf *pf = vsi->back;
3187 enum ice_status status;
3193 dev = ice_pf_to_dev(pf);
3199 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3203 /* set RSS LUT parameters */
3204 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3207 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3209 vsi->rss_size = min_t(int, req_rss_size,
3210 BIT(caps->rss_table_entry_width));
3213 /* create/set RSS LUT */
3214 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3215 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type, lut,
3216 vsi->rss_table_size);
3218 dev_err(dev, "Cannot set RSS lut, err %d aq_err %d\n",
3219 status, hw->adminq.rq_last_status);
3228 * ice_set_channels - set the number channels
3229 * @dev: network interface device structure
3230 * @ch: ethtool channel data structure
3232 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3234 struct ice_netdev_priv *np = netdev_priv(dev);
3235 struct ice_vsi *vsi = np->vsi;
3236 struct ice_pf *pf = vsi->back;
3237 int new_rx = 0, new_tx = 0;
3240 /* do not support changing channels in Safe Mode */
3241 if (ice_is_safe_mode(pf)) {
3242 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3245 /* do not support changing other_count */
3246 if (ch->other_count)
3249 curr_combined = ice_get_combined_cnt(vsi);
3251 /* these checks are for cases where user didn't specify a particular
3252 * value on cmd line but we get non-zero value anyway via
3253 * get_channels(); look at ethtool.c in ethtool repository (the user
3254 * space part), particularly, do_schannels() routine
3256 if (ch->rx_count == vsi->num_rxq - curr_combined)
3258 if (ch->tx_count == vsi->num_txq - curr_combined)
3260 if (ch->combined_count == curr_combined)
3261 ch->combined_count = 0;
3263 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3264 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3268 new_rx = ch->combined_count + ch->rx_count;
3269 new_tx = ch->combined_count + ch->tx_count;
3271 if (new_rx > ice_get_max_rxq(pf)) {
3272 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3273 ice_get_max_rxq(pf));
3276 if (new_tx > ice_get_max_txq(pf)) {
3277 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3278 ice_get_max_txq(pf));
3282 ice_vsi_recfg_qs(vsi, new_rx, new_tx);
3284 if (new_rx && !netif_is_rxfh_configured(dev))
3285 return ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3290 enum ice_container_type {
3296 * ice_get_rc_coalesce - get ITR values for specific ring container
3297 * @ec: ethtool structure to fill with driver's coalesce settings
3298 * @c_type: container type, Rx or Tx
3299 * @rc: ring container that the ITR values will come from
3301 * Query the device for ice_ring_container specific ITR values. This is
3302 * done per ice_ring_container because each q_vector can have 1 or more rings
3303 * and all of said ring(s) will have the same ITR values.
3305 * Returns 0 on success, negative otherwise.
3308 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3309 struct ice_ring_container *rc)
3316 pf = rc->ring->vsi->back;
3319 case ICE_RX_CONTAINER:
3320 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3321 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3322 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3324 case ICE_TX_CONTAINER:
3325 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3326 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3329 dev_dbg(ice_pf_to_dev(pf), "Invalid c_type %d\n", c_type);
3337 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3338 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3339 * @ec: coalesce settings to program the device with
3340 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3342 * Return 0 on success, and negative under the following conditions:
3343 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3344 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3347 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3349 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3350 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3351 &vsi->rx_rings[q_num]->q_vector->rx))
3353 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3354 &vsi->tx_rings[q_num]->q_vector->tx))
3356 } else if (q_num < vsi->num_rxq) {
3357 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3358 &vsi->rx_rings[q_num]->q_vector->rx))
3360 } else if (q_num < vsi->num_txq) {
3361 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3362 &vsi->tx_rings[q_num]->q_vector->tx))
3372 * __ice_get_coalesce - get ITR/INTRL values for the device
3373 * @netdev: pointer to the netdev associated with this query
3374 * @ec: ethtool structure to fill with driver's coalesce settings
3375 * @q_num: queue number to get the coalesce settings for
3377 * If the caller passes in a negative q_num then we return coalesce settings
3378 * based on queue number 0, else use the actual q_num passed in.
3381 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3384 struct ice_netdev_priv *np = netdev_priv(netdev);
3385 struct ice_vsi *vsi = np->vsi;
3390 if (ice_get_q_coalesce(vsi, ec, q_num))
3397 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3399 return __ice_get_coalesce(netdev, ec, -1);
3403 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3404 struct ethtool_coalesce *ec)
3406 return __ice_get_coalesce(netdev, ec, q_num);
3410 * ice_set_rc_coalesce - set ITR values for specific ring container
3411 * @c_type: container type, Rx or Tx
3412 * @ec: ethtool structure from user to update ITR settings
3413 * @rc: ring container that the ITR values will come from
3414 * @vsi: VSI associated to the ring container
3416 * Set specific ITR values. This is done per ice_ring_container because each
3417 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3420 * Returns 0 on success, negative otherwise.
3423 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3424 struct ice_ring_container *rc, struct ice_vsi *vsi)
3426 const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3427 u32 use_adaptive_coalesce, coalesce_usecs;
3428 struct ice_pf *pf = vsi->back;
3435 case ICE_RX_CONTAINER:
3436 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3437 (ec->rx_coalesce_usecs_high &&
3438 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3439 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3440 c_type_str, pf->hw.intrl_gran,
3444 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3445 rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3446 wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3447 ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3448 pf->hw.intrl_gran));
3451 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3452 coalesce_usecs = ec->rx_coalesce_usecs;
3455 case ICE_TX_CONTAINER:
3456 if (ec->tx_coalesce_usecs_high) {
3457 netdev_info(vsi->netdev, "setting %s-usecs-high is not supported\n",
3462 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3463 coalesce_usecs = ec->tx_coalesce_usecs;
3467 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3472 itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3473 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3474 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3475 c_type_str, c_type_str);
3479 if (coalesce_usecs > ICE_ITR_MAX) {
3480 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3481 c_type_str, ICE_ITR_MAX);
3485 if (use_adaptive_coalesce) {
3486 rc->itr_setting |= ICE_ITR_DYNAMIC;
3488 /* save the user set usecs */
3489 rc->itr_setting = coalesce_usecs;
3490 /* device ITR granularity is in 2 usec increments */
3491 rc->target_itr = ITR_REG_ALIGN(rc->itr_setting);
3498 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3499 * @vsi: VSI associated to the queue that need updating
3500 * @ec: coalesce settings to program the device with
3501 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3503 * Return 0 on success, and negative under the following conditions:
3504 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3505 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3508 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3510 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3511 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3512 &vsi->rx_rings[q_num]->q_vector->rx,
3516 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3517 &vsi->tx_rings[q_num]->q_vector->tx,
3520 } else if (q_num < vsi->num_rxq) {
3521 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3522 &vsi->rx_rings[q_num]->q_vector->rx,
3525 } else if (q_num < vsi->num_txq) {
3526 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3527 &vsi->tx_rings[q_num]->q_vector->tx,
3538 * ice_is_coalesce_param_invalid - check for unsupported coalesce parameters
3539 * @netdev: pointer to the netdev associated with this query
3540 * @ec: ethtool structure to fill with driver's coalesce settings
3542 * Print netdev info if driver doesn't support one of the parameters
3543 * and return error. When any parameters will be implemented, remove only
3544 * this parameter from param array.
3547 ice_is_coalesce_param_invalid(struct net_device *netdev,
3548 struct ethtool_coalesce *ec)
3550 struct ice_ethtool_not_used {
3554 {ec->stats_block_coalesce_usecs, "stats-block-usecs"},
3555 {ec->rate_sample_interval, "sample-interval"},
3556 {ec->pkt_rate_low, "pkt-rate-low"},
3557 {ec->pkt_rate_high, "pkt-rate-high"},
3558 {ec->rx_max_coalesced_frames, "rx-frames"},
3559 {ec->rx_coalesce_usecs_irq, "rx-usecs-irq"},
3560 {ec->rx_max_coalesced_frames_irq, "rx-frames-irq"},
3561 {ec->tx_max_coalesced_frames, "tx-frames"},
3562 {ec->tx_coalesce_usecs_irq, "tx-usecs-irq"},
3563 {ec->tx_max_coalesced_frames_irq, "tx-frames-irq"},
3564 {ec->rx_coalesce_usecs_low, "rx-usecs-low"},
3565 {ec->rx_max_coalesced_frames_low, "rx-frames-low"},
3566 {ec->tx_coalesce_usecs_low, "tx-usecs-low"},
3567 {ec->tx_max_coalesced_frames_low, "tx-frames-low"},
3568 {ec->rx_max_coalesced_frames_high, "rx-frames-high"},
3569 {ec->tx_max_coalesced_frames_high, "tx-frames-high"}
3573 for (i = 0; i < ARRAY_SIZE(param); i++) {
3574 if (param[i].value) {
3575 netdev_info(netdev, "Setting %s not supported\n",
3585 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3586 * @netdev: netdev used for print
3587 * @itr_setting: previous user setting
3588 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3589 * @coalesce_usecs: requested value of [tx|rx]-usecs
3590 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3593 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3594 u32 use_adaptive_coalesce, u32 coalesce_usecs,
3595 const char *c_type_str)
3597 if (use_adaptive_coalesce)
3600 itr_setting = ITR_TO_REG(itr_setting);
3602 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3603 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",
3604 c_type_str, coalesce_usecs, c_type_str,
3605 ITR_REG_ALIGN(coalesce_usecs));
3609 * __ice_set_coalesce - set ITR/INTRL values for the device
3610 * @netdev: pointer to the netdev associated with this query
3611 * @ec: ethtool structure to fill with driver's coalesce settings
3612 * @q_num: queue number to get the coalesce settings for
3614 * If the caller passes in a negative q_num then we set the coalesce settings
3615 * for all Tx/Rx queues, else use the actual q_num passed in.
3618 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3621 struct ice_netdev_priv *np = netdev_priv(netdev);
3622 struct ice_vsi *vsi = np->vsi;
3624 if (ice_is_coalesce_param_invalid(netdev, ec))
3628 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3632 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3633 ec->use_adaptive_rx_coalesce,
3634 ec->rx_coalesce_usecs, "rx");
3636 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3637 ec->use_adaptive_tx_coalesce,
3638 ec->tx_coalesce_usecs, "tx");
3641 ice_for_each_q_vector(vsi, v_idx) {
3642 /* In some cases if DCB is configured the num_[rx|tx]q
3643 * can be less than vsi->num_q_vectors. This check
3644 * accounts for that so we don't report a false failure
3646 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3649 if (ice_set_q_coalesce(vsi, ec, v_idx))
3655 if (ice_set_q_coalesce(vsi, ec, q_num))
3664 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3666 return __ice_set_coalesce(netdev, ec, -1);
3670 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3671 struct ethtool_coalesce *ec)
3673 return __ice_set_coalesce(netdev, ec, q_num);
3676 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
3677 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
3678 #define ICE_MODULE_TYPE_SFP 0x03
3679 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
3680 #define ICE_MODULE_TYPE_QSFP28 0x11
3681 #define ICE_MODULE_SFF_ADDR_MODE 0x04
3682 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
3683 #define ICE_MODULE_REVISION_ADDR 0x01
3684 #define ICE_MODULE_SFF_8472_COMP 0x5E
3685 #define ICE_MODULE_SFF_8472_SWAP 0x5C
3686 #define ICE_MODULE_QSFP_MAX_LEN 640
3689 * ice_get_module_info - get SFF module type and revision information
3690 * @netdev: network interface device structure
3691 * @modinfo: module EEPROM size and layout information structure
3694 ice_get_module_info(struct net_device *netdev,
3695 struct ethtool_modinfo *modinfo)
3697 struct ice_netdev_priv *np = netdev_priv(netdev);
3698 struct ice_vsi *vsi = np->vsi;
3699 struct ice_pf *pf = vsi->back;
3700 struct ice_hw *hw = &pf->hw;
3701 enum ice_status status;
3702 u8 sff8472_comp = 0;
3703 u8 sff8472_swap = 0;
3707 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3708 0, &value, 1, 0, NULL);
3713 case ICE_MODULE_TYPE_SFP:
3714 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3715 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3716 &sff8472_comp, 1, 0, NULL);
3719 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3720 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3721 &sff8472_swap, 1, 0, NULL);
3725 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
3726 modinfo->type = ETH_MODULE_SFF_8079;
3727 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3728 } else if (sff8472_comp &&
3729 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
3730 modinfo->type = ETH_MODULE_SFF_8472;
3731 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3733 modinfo->type = ETH_MODULE_SFF_8079;
3734 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3737 case ICE_MODULE_TYPE_QSFP_PLUS:
3738 case ICE_MODULE_TYPE_QSFP28:
3739 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3740 ICE_MODULE_REVISION_ADDR, 0x00, 0,
3741 &sff8636_rev, 1, 0, NULL);
3744 /* Check revision compliance */
3745 if (sff8636_rev > 0x02) {
3746 /* Module is SFF-8636 compliant */
3747 modinfo->type = ETH_MODULE_SFF_8636;
3748 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3750 modinfo->type = ETH_MODULE_SFF_8436;
3751 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3755 netdev_warn(netdev, "SFF Module Type not recognized.\n");
3762 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
3763 * @netdev: network interface device structure
3764 * @ee: EEPROM dump request structure
3765 * @data: buffer to be filled with EEPROM contents
3768 ice_get_module_eeprom(struct net_device *netdev,
3769 struct ethtool_eeprom *ee, u8 *data)
3771 struct ice_netdev_priv *np = netdev_priv(netdev);
3772 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
3773 struct ice_vsi *vsi = np->vsi;
3774 struct ice_pf *pf = vsi->back;
3775 struct ice_hw *hw = &pf->hw;
3776 enum ice_status status;
3777 bool is_sfp = false;
3783 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0,
3784 &value, 1, 0, NULL);
3788 if (!ee || !ee->len || !data)
3791 if (value == ICE_MODULE_TYPE_SFP)
3794 for (i = 0; i < ee->len; i++) {
3795 offset = i + ee->offset;
3797 /* Check if we need to access the other memory page */
3799 if (offset >= ETH_MODULE_SFF_8079_LEN) {
3800 offset -= ETH_MODULE_SFF_8079_LEN;
3801 addr = ICE_I2C_EEPROM_DEV_ADDR2;
3804 while (offset >= ETH_MODULE_SFF_8436_LEN) {
3805 /* Compute memory page number and offset. */
3806 offset -= ETH_MODULE_SFF_8436_LEN / 2;
3811 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, !is_sfp,
3812 &value, 1, 0, NULL);
3820 static const struct ethtool_ops ice_ethtool_ops = {
3821 .get_link_ksettings = ice_get_link_ksettings,
3822 .set_link_ksettings = ice_set_link_ksettings,
3823 .get_drvinfo = ice_get_drvinfo,
3824 .get_regs_len = ice_get_regs_len,
3825 .get_regs = ice_get_regs,
3826 .get_msglevel = ice_get_msglevel,
3827 .set_msglevel = ice_set_msglevel,
3828 .self_test = ice_self_test,
3829 .get_link = ethtool_op_get_link,
3830 .get_eeprom_len = ice_get_eeprom_len,
3831 .get_eeprom = ice_get_eeprom,
3832 .get_coalesce = ice_get_coalesce,
3833 .set_coalesce = ice_set_coalesce,
3834 .get_strings = ice_get_strings,
3835 .set_phys_id = ice_set_phys_id,
3836 .get_ethtool_stats = ice_get_ethtool_stats,
3837 .get_priv_flags = ice_get_priv_flags,
3838 .set_priv_flags = ice_set_priv_flags,
3839 .get_sset_count = ice_get_sset_count,
3840 .get_rxnfc = ice_get_rxnfc,
3841 .set_rxnfc = ice_set_rxnfc,
3842 .get_ringparam = ice_get_ringparam,
3843 .set_ringparam = ice_set_ringparam,
3844 .nway_reset = ice_nway_reset,
3845 .get_pauseparam = ice_get_pauseparam,
3846 .set_pauseparam = ice_set_pauseparam,
3847 .get_rxfh_key_size = ice_get_rxfh_key_size,
3848 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
3849 .get_rxfh = ice_get_rxfh,
3850 .set_rxfh = ice_set_rxfh,
3851 .get_channels = ice_get_channels,
3852 .set_channels = ice_set_channels,
3853 .get_ts_info = ethtool_op_get_ts_info,
3854 .get_per_queue_coalesce = ice_get_per_q_coalesce,
3855 .set_per_queue_coalesce = ice_set_per_q_coalesce,
3856 .get_fecparam = ice_get_fecparam,
3857 .set_fecparam = ice_set_fecparam,
3858 .get_module_info = ice_get_module_info,
3859 .get_module_eeprom = ice_get_module_eeprom,
3862 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
3863 .get_link_ksettings = ice_get_link_ksettings,
3864 .set_link_ksettings = ice_set_link_ksettings,
3865 .get_drvinfo = ice_get_drvinfo,
3866 .get_regs_len = ice_get_regs_len,
3867 .get_regs = ice_get_regs,
3868 .get_msglevel = ice_get_msglevel,
3869 .set_msglevel = ice_set_msglevel,
3870 .get_eeprom_len = ice_get_eeprom_len,
3871 .get_eeprom = ice_get_eeprom,
3872 .get_strings = ice_get_strings,
3873 .get_ethtool_stats = ice_get_ethtool_stats,
3874 .get_sset_count = ice_get_sset_count,
3875 .get_ringparam = ice_get_ringparam,
3876 .set_ringparam = ice_set_ringparam,
3877 .nway_reset = ice_nway_reset,
3878 .get_channels = ice_get_channels,
3882 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
3883 * @netdev: network interface device structure
3885 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
3887 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
3891 * ice_set_ethtool_ops - setup netdev ethtool ops
3892 * @netdev: network interface device structure
3894 * setup netdev ethtool ops with ice specific ops
3896 void ice_set_ethtool_ops(struct net_device *netdev)
3898 netdev->ethtool_ops = &ice_ethtool_ops;