1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
8 #include "ice_dcb_lib.h"
11 char stat_string[ETH_GSTRING_LEN];
16 #define ICE_STAT(_type, _name, _stat) { \
17 .stat_string = _name, \
18 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
19 .stat_offset = offsetof(_type, _stat) \
22 #define ICE_VSI_STAT(_name, _stat) \
23 ICE_STAT(struct ice_vsi, _name, _stat)
24 #define ICE_PF_STAT(_name, _stat) \
25 ICE_STAT(struct ice_pf, _name, _stat)
27 static int ice_q_stats_len(struct net_device *netdev)
29 struct ice_netdev_priv *np = netdev_priv(netdev);
31 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
32 (sizeof(struct ice_q_stats) / sizeof(u64)));
35 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
36 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
38 #define ICE_PFC_STATS_LEN ( \
39 (FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_rx) + \
40 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_rx) + \
41 FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_tx) + \
42 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_tx)) \
44 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
45 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
47 static const struct ice_stats ice_gstrings_vsi_stats[] = {
48 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
49 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
50 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
51 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
52 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
53 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
54 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
55 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
56 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
57 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
58 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
59 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
60 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
61 ICE_VSI_STAT("tx_linearize", tx_linearize),
64 enum ice_ethtool_test_id {
72 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
73 "Register test (offline)",
74 "EEPROM test (offline)",
75 "Interrupt test (offline)",
76 "Loopback test (offline)",
77 "Link test (on/offline)",
80 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
82 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
83 * but they aren't. This device is capable of supporting multiple
84 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
85 * netdevs whereas the PF_STATs are for the physical function that's
86 * hosting these netdevs.
88 * The PF_STATs are appended to the netdev stats only when ethtool -S
89 * is queried on the base PF netdev.
91 static const struct ice_stats ice_gstrings_pf_stats[] = {
92 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
93 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
94 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
95 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
96 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
97 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
98 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
99 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
100 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
101 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
102 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
103 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
104 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
105 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
106 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
107 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
108 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
109 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
110 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
111 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
112 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
113 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
114 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
115 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
116 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
117 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
118 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
119 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
120 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
121 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
122 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
123 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
124 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
125 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
126 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
127 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
128 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
129 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
130 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
133 static const u32 ice_regs_dump_list[] = {
146 struct ice_priv_flag {
147 char name[ETH_GSTRING_LEN];
148 u32 bitno; /* bit position in pf->flags */
151 #define ICE_PRIV_FLAG(_name, _bitno) { \
156 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
157 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
158 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
161 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
164 * ice_nvm_version_str - format the NVM version strings
165 * @hw: ptr to the hardware info
167 static char *ice_nvm_version_str(struct ice_hw *hw)
169 static char buf[ICE_ETHTOOL_FWVER_LEN];
174 full_ver = hw->nvm.oem_ver;
175 ver = (u8)((full_ver & ICE_OEM_VER_MASK) >> ICE_OEM_VER_SHIFT);
176 build = (u16)((full_ver & ICE_OEM_VER_BUILD_MASK) >>
177 ICE_OEM_VER_BUILD_SHIFT);
178 patch = (u8)(full_ver & ICE_OEM_VER_PATCH_MASK);
180 snprintf(buf, sizeof(buf), "%x.%02x 0x%x %d.%d.%d",
181 (hw->nvm.ver & ICE_NVM_VER_HI_MASK) >> ICE_NVM_VER_HI_SHIFT,
182 (hw->nvm.ver & ICE_NVM_VER_LO_MASK) >> ICE_NVM_VER_LO_SHIFT,
183 hw->nvm.eetrack, ver, build, patch);
189 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
191 struct ice_netdev_priv *np = netdev_priv(netdev);
192 struct ice_vsi *vsi = np->vsi;
193 struct ice_pf *pf = vsi->back;
195 strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
196 strlcpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
197 strlcpy(drvinfo->fw_version, ice_nvm_version_str(&pf->hw),
198 sizeof(drvinfo->fw_version));
199 strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
200 sizeof(drvinfo->bus_info));
201 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
204 static int ice_get_regs_len(struct net_device __always_unused *netdev)
206 return sizeof(ice_regs_dump_list);
210 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
212 struct ice_netdev_priv *np = netdev_priv(netdev);
213 struct ice_pf *pf = np->vsi->back;
214 struct ice_hw *hw = &pf->hw;
215 u32 *regs_buf = (u32 *)p;
220 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
221 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
224 static u32 ice_get_msglevel(struct net_device *netdev)
226 struct ice_netdev_priv *np = netdev_priv(netdev);
227 struct ice_pf *pf = np->vsi->back;
229 #ifndef CONFIG_DYNAMIC_DEBUG
230 if (pf->hw.debug_mask)
231 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
233 #endif /* !CONFIG_DYNAMIC_DEBUG */
235 return pf->msg_enable;
238 static void ice_set_msglevel(struct net_device *netdev, u32 data)
240 struct ice_netdev_priv *np = netdev_priv(netdev);
241 struct ice_pf *pf = np->vsi->back;
243 #ifndef CONFIG_DYNAMIC_DEBUG
244 if (ICE_DBG_USER & data)
245 pf->hw.debug_mask = data;
247 pf->msg_enable = data;
249 pf->msg_enable = data;
250 #endif /* !CONFIG_DYNAMIC_DEBUG */
253 static int ice_get_eeprom_len(struct net_device *netdev)
255 struct ice_netdev_priv *np = netdev_priv(netdev);
256 struct ice_pf *pf = np->vsi->back;
258 return (int)(pf->hw.nvm.sr_words * sizeof(u16));
262 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
265 struct ice_netdev_priv *np = netdev_priv(netdev);
266 u16 first_word, last_word, nwords;
267 struct ice_vsi *vsi = np->vsi;
268 struct ice_pf *pf = vsi->back;
269 struct ice_hw *hw = &pf->hw;
270 enum ice_status status;
275 dev = &pf->pdev->dev;
277 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
279 first_word = eeprom->offset >> 1;
280 last_word = (eeprom->offset + eeprom->len - 1) >> 1;
281 nwords = last_word - first_word + 1;
283 buf = devm_kcalloc(dev, nwords, sizeof(u16), GFP_KERNEL);
287 status = ice_read_sr_buf(hw, first_word, &nwords, buf);
289 dev_err(dev, "ice_read_sr_buf failed, err %d aq_err %d\n",
290 status, hw->adminq.sq_last_status);
291 eeprom->len = sizeof(u16) * nwords;
296 memcpy(bytes, (u8 *)buf + (eeprom->offset & 1), eeprom->len);
298 devm_kfree(dev, buf);
303 * ice_active_vfs - check if there are any active VFs
304 * @pf: board private structure
306 * Returns true if an active VF is found, otherwise returns false
308 static bool ice_active_vfs(struct ice_pf *pf)
310 struct ice_vf *vf = pf->vf;
313 for (i = 0; i < pf->num_alloc_vfs; i++, vf++)
314 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
320 * ice_link_test - perform a link test on a given net_device
321 * @netdev: network interface device structure
323 * This function performs one of the self-tests required by ethtool.
324 * Returns 0 on success, non-zero on failure.
326 static u64 ice_link_test(struct net_device *netdev)
328 struct ice_netdev_priv *np = netdev_priv(netdev);
329 enum ice_status status;
330 bool link_up = false;
332 netdev_info(netdev, "link test\n");
333 status = ice_get_link_status(np->vsi->port_info, &link_up);
335 netdev_err(netdev, "link query error, status = %d\n", status);
346 * ice_eeprom_test - perform an EEPROM test on a given net_device
347 * @netdev: network interface device structure
349 * This function performs one of the self-tests required by ethtool.
350 * Returns 0 on success, non-zero on failure.
352 static u64 ice_eeprom_test(struct net_device *netdev)
354 struct ice_netdev_priv *np = netdev_priv(netdev);
355 struct ice_pf *pf = np->vsi->back;
357 netdev_info(netdev, "EEPROM test\n");
358 return !!(ice_nvm_validate_checksum(&pf->hw));
362 * ice_reg_pattern_test
363 * @hw: pointer to the HW struct
364 * @reg: reg to be tested
365 * @mask: bits to be touched
367 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
369 struct ice_pf *pf = (struct ice_pf *)hw->back;
370 static const u32 patterns[] = {
371 0x5A5A5A5A, 0xA5A5A5A5,
372 0x00000000, 0xFFFFFFFF
377 orig_val = rd32(hw, reg);
378 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
379 u32 pattern = patterns[i] & mask;
381 wr32(hw, reg, pattern);
385 dev_err(&pf->pdev->dev,
386 "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
387 , __func__, reg, pattern, val);
391 wr32(hw, reg, orig_val);
393 if (val != orig_val) {
394 dev_err(&pf->pdev->dev,
395 "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
396 , __func__, reg, orig_val, val);
404 * ice_reg_test - perform a register test on a given net_device
405 * @netdev: network interface device structure
407 * This function performs one of the self-tests required by ethtool.
408 * Returns 0 on success, non-zero on failure.
410 static u64 ice_reg_test(struct net_device *netdev)
412 struct ice_netdev_priv *np = netdev_priv(netdev);
413 struct ice_hw *hw = np->vsi->port_info->hw;
414 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
415 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
416 struct ice_diag_reg_test_info {
422 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
423 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
424 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
425 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
426 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
427 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
428 {GLINT_CTL, 0xffff0001, 1, 0}
432 netdev_dbg(netdev, "Register test\n");
433 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
436 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
437 u32 mask = ice_reg_list[i].mask;
438 u32 reg = ice_reg_list[i].address +
439 (j * ice_reg_list[i].elem_size);
441 /* bail on failure (non-zero return) */
442 if (ice_reg_pattern_test(hw, reg, mask))
451 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
452 * @vsi: pointer to the VSI structure
454 * Function configures rings of a VSI for loopback test without
455 * enabling interrupts or informing the kernel about new queues.
457 * Returns 0 on success, negative on failure.
459 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
463 status = ice_vsi_setup_tx_rings(vsi);
465 goto err_setup_tx_ring;
467 status = ice_vsi_setup_rx_rings(vsi);
469 goto err_setup_rx_ring;
471 status = ice_vsi_cfg(vsi);
473 goto err_setup_rx_ring;
475 status = ice_vsi_start_rx_rings(vsi);
477 goto err_start_rx_ring;
482 ice_vsi_free_rx_rings(vsi);
484 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
486 ice_vsi_free_tx_rings(vsi);
492 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
493 * @vsi: pointer to the VSI structure
495 * Function stops and frees VSI rings after a loopback test.
496 * Returns 0 on success, negative on failure.
498 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
502 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
504 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
505 vsi->vsi_num, status);
507 status = ice_vsi_stop_rx_rings(vsi);
509 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
510 vsi->vsi_num, status);
512 ice_vsi_free_tx_rings(vsi);
513 ice_vsi_free_rx_rings(vsi);
519 * ice_lbtest_create_frame - create test packet
520 * @pf: pointer to the PF structure
521 * @ret_data: allocated frame buffer
522 * @size: size of the packet data
524 * Function allocates a frame with a test pattern on specific offsets.
525 * Returns 0 on success, non-zero on failure.
527 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
534 data = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
538 /* Since the ethernet test frame should always be at least
539 * 64 bytes long, fill some octets in the payload with test data.
541 memset(data, 0xFF, size);
553 * ice_lbtest_check_frame - verify received loopback frame
554 * @frame: pointer to the raw packet data
556 * Function verifies received test frame with a pattern.
557 * Returns true if frame matches the pattern, false otherwise.
559 static bool ice_lbtest_check_frame(u8 *frame)
561 /* Validate bytes of a frame under offsets chosen earlier */
562 if (frame[32] == 0xDE &&
573 * ice_diag_send - send test frames to the test ring
574 * @tx_ring: pointer to the transmit ring
575 * @data: pointer to the raw packet data
576 * @size: size of the packet to send
578 * Function sends loopback packets on a test Tx ring.
580 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
582 struct ice_tx_desc *tx_desc;
583 struct ice_tx_buf *tx_buf;
587 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
588 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
590 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
591 if (dma_mapping_error(tx_ring->dev, dma))
594 tx_desc->buf_addr = cpu_to_le64(dma);
596 /* These flags are required for a descriptor to be pushed out */
597 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
598 tx_desc->cmd_type_offset_bsz =
599 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
600 (td_cmd << ICE_TXD_QW1_CMD_S) |
601 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
602 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
603 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
605 tx_buf->next_to_watch = tx_desc;
607 /* Force memory write to complete before letting h/w know
608 * there are new descriptors to fetch.
612 tx_ring->next_to_use++;
613 if (tx_ring->next_to_use >= tx_ring->count)
614 tx_ring->next_to_use = 0;
616 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
618 /* Wait until the packets get transmitted to the receive queue. */
619 usleep_range(1000, 2000);
620 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
625 #define ICE_LB_FRAME_SIZE 64
627 * ice_lbtest_receive_frames - receive and verify test frames
628 * @rx_ring: pointer to the receive ring
630 * Function receives loopback packets and verify their correctness.
631 * Returns number of received valid frames.
633 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
635 struct ice_rx_buf *rx_buf;
641 for (i = 0; i < rx_ring->count; i++) {
642 union ice_32b_rx_flex_desc *rx_desc;
644 rx_desc = ICE_RX_DESC(rx_ring, i);
646 if (!(rx_desc->wb.status_error0 &
647 cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)))
650 rx_buf = &rx_ring->rx_buf[i];
651 received_buf = page_address(rx_buf->page);
653 if (ice_lbtest_check_frame(received_buf))
661 * ice_loopback_test - perform a loopback test on a given net_device
662 * @netdev: network interface device structure
664 * This function performs one of the self-tests required by ethtool.
665 * Returns 0 on success, non-zero on failure.
667 static u64 ice_loopback_test(struct net_device *netdev)
669 struct ice_netdev_priv *np = netdev_priv(netdev);
670 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
671 struct ice_pf *pf = orig_vsi->back;
672 struct ice_ring *tx_ring, *rx_ring;
673 u8 broadcast[ETH_ALEN], ret = 0;
674 int num_frames, valid_frames;
679 netdev_info(netdev, "loopback test\n");
681 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
683 netdev_err(netdev, "Failed to create a VSI for the loopback test");
687 test_vsi->netdev = netdev;
688 tx_ring = test_vsi->tx_rings[0];
689 rx_ring = test_vsi->rx_rings[0];
691 if (ice_lbtest_prepare_rings(test_vsi)) {
693 goto lbtest_vsi_close;
696 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
698 goto lbtest_rings_dis;
701 /* Enable MAC loopback in firmware */
702 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
707 /* Test VSI needs to receive broadcast packets */
708 eth_broadcast_addr(broadcast);
709 if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) {
714 if (ice_add_mac(&pf->hw, &tmp_list)) {
719 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
721 goto remove_mac_filters;
724 num_frames = min_t(int, tx_ring->count, 32);
725 for (i = 0; i < num_frames; i++) {
726 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
728 goto lbtest_free_frame;
732 valid_frames = ice_lbtest_receive_frames(rx_ring);
735 else if (valid_frames != num_frames)
739 devm_kfree(&pf->pdev->dev, tx_frame);
741 if (ice_remove_mac(&pf->hw, &tmp_list))
742 netdev_err(netdev, "Could not remove MAC filter for the test VSI");
744 ice_free_fltr_list(&pf->pdev->dev, &tmp_list);
746 /* Disable MAC loopback after the test is completed. */
747 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
748 netdev_err(netdev, "Could not disable MAC loopback\n");
750 if (ice_lbtest_disable_rings(test_vsi))
751 netdev_err(netdev, "Could not disable test rings\n");
753 test_vsi->netdev = NULL;
754 if (ice_vsi_release(test_vsi))
755 netdev_err(netdev, "Failed to remove the test VSI");
761 * ice_intr_test - perform an interrupt test on a given net_device
762 * @netdev: network interface device structure
764 * This function performs one of the self-tests required by ethtool.
765 * Returns 0 on success, non-zero on failure.
767 static u64 ice_intr_test(struct net_device *netdev)
769 struct ice_netdev_priv *np = netdev_priv(netdev);
770 struct ice_pf *pf = np->vsi->back;
771 u16 swic_old = pf->sw_int_count;
773 netdev_info(netdev, "interrupt test\n");
775 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
776 GLINT_DYN_CTL_SW_ITR_INDX_M |
777 GLINT_DYN_CTL_INTENA_MSK_M |
778 GLINT_DYN_CTL_SWINT_TRIG_M);
780 usleep_range(1000, 2000);
781 return (swic_old == pf->sw_int_count);
785 * ice_self_test - handler function for performing a self-test by ethtool
786 * @netdev: network interface device structure
787 * @eth_test: ethtool_test structure
788 * @data: required by ethtool.self_test
790 * This function is called after invoking 'ethtool -t devname' command where
791 * devname is the name of the network device on which ethtool should operate.
792 * It performs a set of self-tests to check if a device works properly.
795 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
798 struct ice_netdev_priv *np = netdev_priv(netdev);
799 bool if_running = netif_running(netdev);
800 struct ice_pf *pf = np->vsi->back;
802 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
803 netdev_info(netdev, "offline testing starting\n");
805 set_bit(__ICE_TESTING, pf->state);
807 if (ice_active_vfs(pf)) {
808 dev_warn(&pf->pdev->dev,
809 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
810 data[ICE_ETH_TEST_REG] = 1;
811 data[ICE_ETH_TEST_EEPROM] = 1;
812 data[ICE_ETH_TEST_INTR] = 1;
813 data[ICE_ETH_TEST_LOOP] = 1;
814 data[ICE_ETH_TEST_LINK] = 1;
815 eth_test->flags |= ETH_TEST_FL_FAILED;
816 clear_bit(__ICE_TESTING, pf->state);
819 /* If the device is online then take it offline */
821 /* indicate we're in test mode */
824 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
825 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
826 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
827 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
828 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
830 if (data[ICE_ETH_TEST_LINK] ||
831 data[ICE_ETH_TEST_EEPROM] ||
832 data[ICE_ETH_TEST_LOOP] ||
833 data[ICE_ETH_TEST_INTR] ||
834 data[ICE_ETH_TEST_REG])
835 eth_test->flags |= ETH_TEST_FL_FAILED;
837 clear_bit(__ICE_TESTING, pf->state);
840 int status = ice_open(netdev);
843 dev_err(&pf->pdev->dev,
844 "Could not open device %s, err %d",
845 pf->int_name, status);
850 netdev_info(netdev, "online testing starting\n");
852 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
853 if (data[ICE_ETH_TEST_LINK])
854 eth_test->flags |= ETH_TEST_FL_FAILED;
856 /* Offline only tests, not run in online; pass by default */
857 data[ICE_ETH_TEST_REG] = 0;
858 data[ICE_ETH_TEST_EEPROM] = 0;
859 data[ICE_ETH_TEST_INTR] = 0;
860 data[ICE_ETH_TEST_LOOP] = 0;
864 netdev_info(netdev, "testing finished\n");
867 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
869 struct ice_netdev_priv *np = netdev_priv(netdev);
870 struct ice_vsi *vsi = np->vsi;
871 char *p = (char *)data;
876 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
877 snprintf(p, ETH_GSTRING_LEN, "%s",
878 ice_gstrings_vsi_stats[i].stat_string);
879 p += ETH_GSTRING_LEN;
882 ice_for_each_alloc_txq(vsi, i) {
883 snprintf(p, ETH_GSTRING_LEN,
884 "tx_queue_%u_packets", i);
885 p += ETH_GSTRING_LEN;
886 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
887 p += ETH_GSTRING_LEN;
890 ice_for_each_alloc_rxq(vsi, i) {
891 snprintf(p, ETH_GSTRING_LEN,
892 "rx_queue_%u_packets", i);
893 p += ETH_GSTRING_LEN;
894 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
895 p += ETH_GSTRING_LEN;
898 if (vsi->type != ICE_VSI_PF)
901 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
902 snprintf(p, ETH_GSTRING_LEN, "%s",
903 ice_gstrings_pf_stats[i].stat_string);
904 p += ETH_GSTRING_LEN;
907 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
908 snprintf(p, ETH_GSTRING_LEN,
909 "tx_priority_%u_xon.nic", i);
910 p += ETH_GSTRING_LEN;
911 snprintf(p, ETH_GSTRING_LEN,
912 "tx_priority_%u_xoff.nic", i);
913 p += ETH_GSTRING_LEN;
915 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
916 snprintf(p, ETH_GSTRING_LEN,
917 "rx_priority_%u_xon.nic", i);
918 p += ETH_GSTRING_LEN;
919 snprintf(p, ETH_GSTRING_LEN,
920 "rx_priority_%u_xoff.nic", i);
921 p += ETH_GSTRING_LEN;
925 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
927 case ETH_SS_PRIV_FLAGS:
928 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
929 snprintf(p, ETH_GSTRING_LEN, "%s",
930 ice_gstrings_priv_flags[i].name);
931 p += ETH_GSTRING_LEN;
940 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
942 struct ice_netdev_priv *np = netdev_priv(netdev);
946 case ETHTOOL_ID_ACTIVE:
949 case ETHTOOL_ID_INACTIVE:
956 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
963 * ice_set_fec_cfg - Set link FEC options
964 * @netdev: network interface device structure
965 * @req_fec: FEC mode to configure
967 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
969 struct ice_netdev_priv *np = netdev_priv(netdev);
970 struct ice_aqc_set_phy_cfg_data config = { 0 };
971 struct ice_aqc_get_phy_caps_data *caps;
972 struct ice_vsi *vsi = np->vsi;
973 u8 sw_cfg_caps, sw_cfg_fec;
974 struct ice_port_info *pi;
975 enum ice_status status;
982 /* Changing the FEC parameters is not supported if not the PF VSI */
983 if (vsi->type != ICE_VSI_PF) {
984 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
988 /* Get last SW configuration */
989 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
993 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
1000 /* Copy SW configuration returned from PHY caps to PHY config */
1001 ice_copy_phy_caps_to_cfg(caps, &config);
1002 sw_cfg_caps = caps->caps;
1003 sw_cfg_fec = caps->link_fec_options;
1005 /* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
1006 memset(caps, 0, sizeof(*caps));
1008 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1015 config.caps |= (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
1016 config.link_fec_opt = caps->link_fec_options;
1018 ice_cfg_phy_fec(&config, req_fec);
1020 /* If FEC mode has changed, then set PHY configuration and enable AN. */
1021 if ((config.caps & ICE_AQ_PHY_ENA_AUTO_FEC) !=
1022 (sw_cfg_caps & ICE_AQC_PHY_EN_AUTO_FEC) ||
1023 config.link_fec_opt != sw_cfg_fec) {
1024 if (caps->caps & ICE_AQC_PHY_AN_MODE)
1025 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1027 status = ice_aq_set_phy_cfg(pi->hw, pi->lport, &config, NULL);
1034 devm_kfree(&vsi->back->pdev->dev, caps);
1039 * ice_set_fecparam - Set FEC link options
1040 * @netdev: network interface device structure
1041 * @fecparam: Ethtool structure to retrieve FEC parameters
1044 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1046 struct ice_netdev_priv *np = netdev_priv(netdev);
1047 struct ice_vsi *vsi = np->vsi;
1048 enum ice_fec_mode fec;
1050 switch (fecparam->fec) {
1051 case ETHTOOL_FEC_AUTO:
1054 case ETHTOOL_FEC_RS:
1057 case ETHTOOL_FEC_BASER:
1058 fec = ICE_FEC_BASER;
1060 case ETHTOOL_FEC_OFF:
1061 case ETHTOOL_FEC_NONE:
1065 dev_warn(&vsi->back->pdev->dev, "Unsupported FEC mode: %d\n",
1070 return ice_set_fec_cfg(netdev, fec);
1074 * ice_get_fecparam - Get link FEC options
1075 * @netdev: network interface device structure
1076 * @fecparam: Ethtool structure to retrieve FEC parameters
1079 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1081 struct ice_netdev_priv *np = netdev_priv(netdev);
1082 struct ice_aqc_get_phy_caps_data *caps;
1083 struct ice_link_status *link_info;
1084 struct ice_vsi *vsi = np->vsi;
1085 struct ice_port_info *pi;
1086 enum ice_status status;
1089 pi = vsi->port_info;
1093 link_info = &pi->phy.link_info;
1095 /* Set FEC mode based on negotiated link info */
1096 switch (link_info->fec_info) {
1097 case ICE_AQ_LINK_25G_KR_FEC_EN:
1098 fecparam->active_fec = ETHTOOL_FEC_BASER;
1100 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1102 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1103 fecparam->active_fec = ETHTOOL_FEC_RS;
1106 fecparam->active_fec = ETHTOOL_FEC_OFF;
1110 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
1114 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1121 /* Set supported/configured FEC modes based on PHY capability */
1122 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1123 fecparam->fec |= ETHTOOL_FEC_AUTO;
1124 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1125 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1126 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1127 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1128 fecparam->fec |= ETHTOOL_FEC_BASER;
1129 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1130 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1131 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1132 fecparam->fec |= ETHTOOL_FEC_RS;
1133 if (caps->link_fec_options == 0)
1134 fecparam->fec |= ETHTOOL_FEC_OFF;
1137 devm_kfree(&vsi->back->pdev->dev, caps);
1142 * ice_get_priv_flags - report device private flags
1143 * @netdev: network interface device structure
1145 * The get string set count and the string set should be matched for each
1146 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1149 * Returns a u32 bitmap of flags.
1151 static u32 ice_get_priv_flags(struct net_device *netdev)
1153 struct ice_netdev_priv *np = netdev_priv(netdev);
1154 struct ice_vsi *vsi = np->vsi;
1155 struct ice_pf *pf = vsi->back;
1156 u32 i, ret_flags = 0;
1158 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1159 const struct ice_priv_flag *priv_flag;
1161 priv_flag = &ice_gstrings_priv_flags[i];
1163 if (test_bit(priv_flag->bitno, pf->flags))
1164 ret_flags |= BIT(i);
1171 * ice_set_priv_flags - set private flags
1172 * @netdev: network interface device structure
1173 * @flags: bit flags to be set
1175 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1177 struct ice_netdev_priv *np = netdev_priv(netdev);
1178 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1179 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1180 struct ice_vsi *vsi = np->vsi;
1181 struct ice_pf *pf = vsi->back;
1185 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1188 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1190 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1191 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1192 const struct ice_priv_flag *priv_flag;
1194 priv_flag = &ice_gstrings_priv_flags[i];
1197 set_bit(priv_flag->bitno, pf->flags);
1199 clear_bit(priv_flag->bitno, pf->flags);
1202 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1204 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1205 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1206 enum ice_status status;
1208 /* Disable FW LLDP engine */
1209 status = ice_aq_cfg_lldp_mib_change(&pf->hw, false,
1211 /* If unregistering for LLDP events fails, this is
1212 * not an error state, as there shouldn't be any
1213 * events to respond to.
1216 dev_info(&pf->pdev->dev,
1217 "Failed to unreg for LLDP events\n");
1219 /* The AQ call to stop the FW LLDP agent will generate
1220 * an error if the agent is already stopped.
1222 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1224 dev_warn(&pf->pdev->dev,
1225 "Fail to stop LLDP agent\n");
1226 /* Use case for having the FW LLDP agent stopped
1227 * will likely not need DCB, so failure to init is
1228 * not a concern of ethtool
1230 status = ice_init_pf_dcb(pf, true);
1232 dev_warn(&pf->pdev->dev, "Fail to init DCB\n");
1234 /* Forward LLDP packets to default VSI so that they
1235 * are passed up the stack
1237 ice_cfg_sw_lldp(vsi, false, true);
1239 enum ice_status status;
1240 bool dcbx_agent_status;
1242 /* AQ command to start FW LLDP agent will return an
1243 * error if the agent is already started
1245 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1247 dev_warn(&pf->pdev->dev,
1248 "Fail to start LLDP Agent\n");
1250 /* AQ command to start FW DCBX agent will fail if
1251 * the agent is already started
1253 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1257 dev_dbg(&pf->pdev->dev,
1258 "Failed to start FW DCBX\n");
1260 dev_info(&pf->pdev->dev, "FW DCBX agent is %s\n",
1261 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1263 /* Failure to configure MIB change or init DCB is not
1264 * relevant to ethtool. Print notification that
1265 * registration/init failed but do not return error
1268 status = ice_init_pf_dcb(pf, true);
1270 dev_dbg(&pf->pdev->dev, "Fail to init DCB\n");
1272 /* Remove rule to direct LLDP packets to default VSI.
1273 * The FW LLDP engine will now be consuming them.
1275 ice_cfg_sw_lldp(vsi, false, false);
1278 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1282 static int ice_get_sset_count(struct net_device *netdev, int sset)
1286 /* The number (and order) of strings reported *must* remain
1287 * constant for a given netdevice. This function must not
1288 * report a different number based on run time parameters
1289 * (such as the number of queues in use, or the setting of
1290 * a private ethtool flag). This is due to the nature of the
1291 * ethtool stats API.
1293 * Userspace programs such as ethtool must make 3 separate
1294 * ioctl requests, one for size, one for the strings, and
1295 * finally one for the stats. Since these cross into
1296 * userspace, changes to the number or size could result in
1297 * undefined memory access or incorrect string<->value
1298 * correlations for statistics.
1300 * Even if it appears to be safe, changes to the size or
1301 * order of strings will suffer from race conditions and are
1304 return ICE_ALL_STATS_LEN(netdev);
1306 return ICE_TEST_LEN;
1307 case ETH_SS_PRIV_FLAGS:
1308 return ICE_PRIV_FLAG_ARRAY_SIZE;
1315 ice_get_ethtool_stats(struct net_device *netdev,
1316 struct ethtool_stats __always_unused *stats, u64 *data)
1318 struct ice_netdev_priv *np = netdev_priv(netdev);
1319 struct ice_vsi *vsi = np->vsi;
1320 struct ice_pf *pf = vsi->back;
1321 struct ice_ring *ring;
1326 ice_update_pf_stats(pf);
1327 ice_update_vsi_stats(vsi);
1329 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1330 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1331 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1332 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1335 /* populate per queue stats */
1338 ice_for_each_alloc_txq(vsi, j) {
1339 ring = READ_ONCE(vsi->tx_rings[j]);
1341 data[i++] = ring->stats.pkts;
1342 data[i++] = ring->stats.bytes;
1349 ice_for_each_alloc_rxq(vsi, j) {
1350 ring = READ_ONCE(vsi->rx_rings[j]);
1352 data[i++] = ring->stats.pkts;
1353 data[i++] = ring->stats.bytes;
1362 if (vsi->type != ICE_VSI_PF)
1365 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1366 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1367 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1368 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1371 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1372 data[i++] = pf->stats.priority_xon_tx[j];
1373 data[i++] = pf->stats.priority_xoff_tx[j];
1376 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1377 data[i++] = pf->stats.priority_xon_rx[j];
1378 data[i++] = pf->stats.priority_xoff_rx[j];
1383 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1384 * @netdev: network interface device structure
1385 * @ks: ethtool link ksettings struct to fill out
1388 ice_phy_type_to_ethtool(struct net_device *netdev,
1389 struct ethtool_link_ksettings *ks)
1391 struct ice_netdev_priv *np = netdev_priv(netdev);
1392 struct ice_link_status *hw_link_info;
1393 bool need_add_adv_mode = false;
1394 struct ice_vsi *vsi = np->vsi;
1398 hw_link_info = &vsi->port_info->phy.link_info;
1399 phy_types_low = vsi->port_info->phy.phy_type_low;
1400 phy_types_high = vsi->port_info->phy.phy_type_high;
1402 ethtool_link_ksettings_zero_link_mode(ks, supported);
1403 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1405 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1406 phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
1407 ethtool_link_ksettings_add_link_mode(ks, supported,
1409 if (!hw_link_info->req_speeds ||
1410 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
1411 ethtool_link_ksettings_add_link_mode(ks, advertising,
1414 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1415 phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
1416 ethtool_link_ksettings_add_link_mode(ks, supported,
1418 if (!hw_link_info->req_speeds ||
1419 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1420 ethtool_link_ksettings_add_link_mode(ks, advertising,
1423 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
1424 ethtool_link_ksettings_add_link_mode(ks, supported,
1426 if (!hw_link_info->req_speeds ||
1427 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1428 ethtool_link_ksettings_add_link_mode(ks, advertising,
1431 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
1432 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
1433 ethtool_link_ksettings_add_link_mode(ks, supported,
1435 if (!hw_link_info->req_speeds ||
1436 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1437 ethtool_link_ksettings_add_link_mode(ks, advertising,
1440 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
1441 ethtool_link_ksettings_add_link_mode(ks, supported,
1443 if (!hw_link_info->req_speeds ||
1444 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1445 ethtool_link_ksettings_add_link_mode(ks, advertising,
1448 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
1449 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
1450 ethtool_link_ksettings_add_link_mode(ks, supported,
1452 if (!hw_link_info->req_speeds ||
1453 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1454 ethtool_link_ksettings_add_link_mode(ks, advertising,
1457 if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1458 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
1459 ethtool_link_ksettings_add_link_mode(ks, supported,
1461 if (!hw_link_info->req_speeds ||
1462 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
1463 ethtool_link_ksettings_add_link_mode(ks, advertising,
1466 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1467 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
1468 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
1469 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
1470 ethtool_link_ksettings_add_link_mode(ks, supported,
1472 if (!hw_link_info->req_speeds ||
1473 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1474 ethtool_link_ksettings_add_link_mode(ks, advertising,
1477 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
1478 ethtool_link_ksettings_add_link_mode(ks, supported,
1480 if (!hw_link_info->req_speeds ||
1481 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1482 ethtool_link_ksettings_add_link_mode(ks, advertising,
1485 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
1486 ethtool_link_ksettings_add_link_mode(ks, supported,
1488 if (!hw_link_info->req_speeds ||
1489 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1490 ethtool_link_ksettings_add_link_mode(ks, advertising,
1493 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
1494 ethtool_link_ksettings_add_link_mode(ks, supported,
1496 if (!hw_link_info->req_speeds ||
1497 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1498 ethtool_link_ksettings_add_link_mode(ks, advertising,
1501 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1502 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1503 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1504 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1505 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
1506 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
1507 ethtool_link_ksettings_add_link_mode(ks, supported,
1509 if (!hw_link_info->req_speeds ||
1510 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1511 ethtool_link_ksettings_add_link_mode(ks, advertising,
1514 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
1515 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
1516 ethtool_link_ksettings_add_link_mode(ks, supported,
1518 if (!hw_link_info->req_speeds ||
1519 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1520 ethtool_link_ksettings_add_link_mode(ks, advertising,
1523 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1524 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1525 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
1526 ethtool_link_ksettings_add_link_mode(ks, supported,
1528 if (!hw_link_info->req_speeds ||
1529 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1530 ethtool_link_ksettings_add_link_mode(ks, advertising,
1533 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1534 ethtool_link_ksettings_add_link_mode(ks, supported,
1536 if (!hw_link_info->req_speeds ||
1537 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1538 ethtool_link_ksettings_add_link_mode(ks, advertising,
1541 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1542 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
1543 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
1544 ethtool_link_ksettings_add_link_mode(ks, supported,
1546 if (!hw_link_info->req_speeds ||
1547 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1548 ethtool_link_ksettings_add_link_mode(ks, advertising,
1551 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
1552 ethtool_link_ksettings_add_link_mode(ks, supported,
1554 if (!hw_link_info->req_speeds ||
1555 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1556 ethtool_link_ksettings_add_link_mode(ks, advertising,
1559 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
1560 ethtool_link_ksettings_add_link_mode(ks, supported,
1562 if (!hw_link_info->req_speeds ||
1563 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1564 ethtool_link_ksettings_add_link_mode(ks, advertising,
1567 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1568 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC ||
1569 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 ||
1570 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC ||
1571 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 ||
1572 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1573 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR ||
1574 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC ||
1575 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) {
1576 ethtool_link_ksettings_add_link_mode(ks, supported,
1578 if (!hw_link_info->req_speeds ||
1579 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1580 ethtool_link_ksettings_add_link_mode(ks, advertising,
1583 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1584 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1585 ethtool_link_ksettings_add_link_mode(ks, supported,
1587 if (!hw_link_info->req_speeds ||
1588 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1589 ethtool_link_ksettings_add_link_mode(ks, advertising,
1592 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 ||
1593 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 ||
1594 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR ||
1595 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) {
1596 ethtool_link_ksettings_add_link_mode(ks, supported,
1598 if (!hw_link_info->req_speeds ||
1599 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1600 ethtool_link_ksettings_add_link_mode(ks, advertising,
1603 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1604 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC ||
1605 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 ||
1606 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC ||
1607 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 ||
1608 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 ||
1609 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2 ||
1610 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC ||
1611 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 ||
1612 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC ||
1613 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) {
1614 ethtool_link_ksettings_add_link_mode(ks, supported,
1615 100000baseCR4_Full);
1616 if (!hw_link_info->req_speeds ||
1617 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1618 need_add_adv_mode = true;
1620 if (need_add_adv_mode) {
1621 need_add_adv_mode = false;
1622 ethtool_link_ksettings_add_link_mode(ks, advertising,
1623 100000baseCR4_Full);
1625 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 ||
1626 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) {
1627 ethtool_link_ksettings_add_link_mode(ks, supported,
1628 100000baseSR4_Full);
1629 if (!hw_link_info->req_speeds ||
1630 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1631 need_add_adv_mode = true;
1633 if (need_add_adv_mode) {
1634 need_add_adv_mode = false;
1635 ethtool_link_ksettings_add_link_mode(ks, advertising,
1636 100000baseSR4_Full);
1638 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 ||
1639 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) {
1640 ethtool_link_ksettings_add_link_mode(ks, supported,
1641 100000baseLR4_ER4_Full);
1642 if (!hw_link_info->req_speeds ||
1643 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1644 need_add_adv_mode = true;
1646 if (need_add_adv_mode) {
1647 need_add_adv_mode = false;
1648 ethtool_link_ksettings_add_link_mode(ks, advertising,
1649 100000baseLR4_ER4_Full);
1651 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1652 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1653 phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) {
1654 ethtool_link_ksettings_add_link_mode(ks, supported,
1655 100000baseKR4_Full);
1656 if (!hw_link_info->req_speeds ||
1657 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1658 need_add_adv_mode = true;
1660 if (need_add_adv_mode)
1661 ethtool_link_ksettings_add_link_mode(ks, advertising,
1662 100000baseKR4_Full);
1664 /* Autoneg PHY types */
1665 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1666 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1667 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
1668 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
1669 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
1670 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1671 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
1672 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1673 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
1674 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1675 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1676 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1677 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1678 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1679 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1680 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
1681 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1682 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1683 ethtool_link_ksettings_add_link_mode(ks, supported,
1685 ethtool_link_ksettings_add_link_mode(ks, advertising,
1688 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1689 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1690 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1691 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1692 ethtool_link_ksettings_add_link_mode(ks, supported,
1694 ethtool_link_ksettings_add_link_mode(ks, advertising,
1697 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1698 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1699 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1700 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) {
1701 ethtool_link_ksettings_add_link_mode(ks, supported,
1703 ethtool_link_ksettings_add_link_mode(ks, advertising,
1708 #define TEST_SET_BITS_TIMEOUT 50
1709 #define TEST_SET_BITS_SLEEP_MAX 2000
1710 #define TEST_SET_BITS_SLEEP_MIN 1000
1713 * ice_get_settings_link_up - Get Link settings for when link is up
1714 * @ks: ethtool ksettings to fill in
1715 * @netdev: network interface device structure
1718 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1719 struct net_device *netdev)
1721 struct ice_netdev_priv *np = netdev_priv(netdev);
1722 struct ice_port_info *pi = np->vsi->port_info;
1723 struct ethtool_link_ksettings cap_ksettings;
1724 struct ice_link_status *link_info;
1725 struct ice_vsi *vsi = np->vsi;
1726 bool unrecog_phy_high = false;
1727 bool unrecog_phy_low = false;
1729 link_info = &vsi->port_info->phy.link_info;
1731 /* Initialize supported and advertised settings based on PHY settings */
1732 switch (link_info->phy_type_low) {
1733 case ICE_PHY_TYPE_LOW_100BASE_TX:
1734 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1735 ethtool_link_ksettings_add_link_mode(ks, supported,
1737 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1738 ethtool_link_ksettings_add_link_mode(ks, advertising,
1741 case ICE_PHY_TYPE_LOW_100M_SGMII:
1742 ethtool_link_ksettings_add_link_mode(ks, supported,
1745 case ICE_PHY_TYPE_LOW_1000BASE_T:
1746 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1747 ethtool_link_ksettings_add_link_mode(ks, supported,
1749 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1750 ethtool_link_ksettings_add_link_mode(ks, advertising,
1753 case ICE_PHY_TYPE_LOW_1G_SGMII:
1754 ethtool_link_ksettings_add_link_mode(ks, supported,
1757 case ICE_PHY_TYPE_LOW_1000BASE_SX:
1758 case ICE_PHY_TYPE_LOW_1000BASE_LX:
1759 ethtool_link_ksettings_add_link_mode(ks, supported,
1762 case ICE_PHY_TYPE_LOW_1000BASE_KX:
1763 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1764 ethtool_link_ksettings_add_link_mode(ks, supported,
1766 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1767 ethtool_link_ksettings_add_link_mode(ks, advertising,
1770 case ICE_PHY_TYPE_LOW_2500BASE_T:
1771 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1772 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1773 ethtool_link_ksettings_add_link_mode(ks, supported,
1775 ethtool_link_ksettings_add_link_mode(ks, advertising,
1778 case ICE_PHY_TYPE_LOW_2500BASE_X:
1779 ethtool_link_ksettings_add_link_mode(ks, supported,
1782 case ICE_PHY_TYPE_LOW_2500BASE_KX:
1783 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1784 ethtool_link_ksettings_add_link_mode(ks, supported,
1786 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1787 ethtool_link_ksettings_add_link_mode(ks, advertising,
1790 case ICE_PHY_TYPE_LOW_5GBASE_T:
1791 case ICE_PHY_TYPE_LOW_5GBASE_KR:
1792 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1793 ethtool_link_ksettings_add_link_mode(ks, supported,
1795 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1796 ethtool_link_ksettings_add_link_mode(ks, advertising,
1799 case ICE_PHY_TYPE_LOW_10GBASE_T:
1800 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1801 ethtool_link_ksettings_add_link_mode(ks, supported,
1803 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1804 ethtool_link_ksettings_add_link_mode(ks, advertising,
1807 case ICE_PHY_TYPE_LOW_10G_SFI_DA:
1808 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
1809 case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
1810 ethtool_link_ksettings_add_link_mode(ks, supported,
1813 case ICE_PHY_TYPE_LOW_10GBASE_SR:
1814 ethtool_link_ksettings_add_link_mode(ks, supported,
1817 case ICE_PHY_TYPE_LOW_10GBASE_LR:
1818 ethtool_link_ksettings_add_link_mode(ks, supported,
1821 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
1822 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1823 ethtool_link_ksettings_add_link_mode(ks, supported,
1825 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1826 ethtool_link_ksettings_add_link_mode(ks, advertising,
1829 case ICE_PHY_TYPE_LOW_25GBASE_T:
1830 case ICE_PHY_TYPE_LOW_25GBASE_CR:
1831 case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
1832 case ICE_PHY_TYPE_LOW_25GBASE_CR1:
1833 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1834 ethtool_link_ksettings_add_link_mode(ks, supported,
1836 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1837 ethtool_link_ksettings_add_link_mode(ks, advertising,
1840 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
1841 case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
1842 ethtool_link_ksettings_add_link_mode(ks, supported,
1845 case ICE_PHY_TYPE_LOW_25GBASE_SR:
1846 case ICE_PHY_TYPE_LOW_25GBASE_LR:
1847 ethtool_link_ksettings_add_link_mode(ks, supported,
1850 case ICE_PHY_TYPE_LOW_25GBASE_KR:
1851 case ICE_PHY_TYPE_LOW_25GBASE_KR1:
1852 case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
1853 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1854 ethtool_link_ksettings_add_link_mode(ks, supported,
1856 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1857 ethtool_link_ksettings_add_link_mode(ks, advertising,
1860 case ICE_PHY_TYPE_LOW_40GBASE_CR4:
1861 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1862 ethtool_link_ksettings_add_link_mode(ks, supported,
1864 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1865 ethtool_link_ksettings_add_link_mode(ks, advertising,
1868 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
1869 case ICE_PHY_TYPE_LOW_40G_XLAUI:
1870 ethtool_link_ksettings_add_link_mode(ks, supported,
1873 case ICE_PHY_TYPE_LOW_40GBASE_SR4:
1874 ethtool_link_ksettings_add_link_mode(ks, supported,
1877 case ICE_PHY_TYPE_LOW_40GBASE_LR4:
1878 ethtool_link_ksettings_add_link_mode(ks, supported,
1881 case ICE_PHY_TYPE_LOW_40GBASE_KR4:
1882 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1883 ethtool_link_ksettings_add_link_mode(ks, supported,
1885 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1886 ethtool_link_ksettings_add_link_mode(ks, advertising,
1889 case ICE_PHY_TYPE_LOW_50GBASE_CR2:
1890 case ICE_PHY_TYPE_LOW_50GBASE_CP:
1891 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1892 ethtool_link_ksettings_add_link_mode(ks, supported,
1894 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1895 ethtool_link_ksettings_add_link_mode(ks, advertising,
1898 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
1899 case ICE_PHY_TYPE_LOW_50G_LAUI2:
1900 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
1901 case ICE_PHY_TYPE_LOW_50G_AUI2:
1902 case ICE_PHY_TYPE_LOW_50GBASE_SR:
1903 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
1904 case ICE_PHY_TYPE_LOW_50G_AUI1:
1905 ethtool_link_ksettings_add_link_mode(ks, supported,
1908 case ICE_PHY_TYPE_LOW_50GBASE_KR2:
1909 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
1910 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1911 ethtool_link_ksettings_add_link_mode(ks, supported,
1913 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1914 ethtool_link_ksettings_add_link_mode(ks, advertising,
1917 case ICE_PHY_TYPE_LOW_50GBASE_SR2:
1918 case ICE_PHY_TYPE_LOW_50GBASE_LR2:
1919 case ICE_PHY_TYPE_LOW_50GBASE_FR:
1920 case ICE_PHY_TYPE_LOW_50GBASE_LR:
1921 ethtool_link_ksettings_add_link_mode(ks, supported,
1924 case ICE_PHY_TYPE_LOW_100GBASE_CR4:
1925 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1926 ethtool_link_ksettings_add_link_mode(ks, supported,
1927 100000baseCR4_Full);
1928 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1929 ethtool_link_ksettings_add_link_mode(ks, advertising,
1930 100000baseCR4_Full);
1932 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
1933 case ICE_PHY_TYPE_LOW_100G_CAUI4:
1934 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
1935 case ICE_PHY_TYPE_LOW_100G_AUI4:
1936 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
1937 ethtool_link_ksettings_add_link_mode(ks, supported,
1938 100000baseCR4_Full);
1940 case ICE_PHY_TYPE_LOW_100GBASE_CP2:
1941 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1942 ethtool_link_ksettings_add_link_mode(ks, supported,
1943 100000baseCR4_Full);
1944 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1945 ethtool_link_ksettings_add_link_mode(ks, advertising,
1946 100000baseCR4_Full);
1948 case ICE_PHY_TYPE_LOW_100GBASE_SR4:
1949 case ICE_PHY_TYPE_LOW_100GBASE_SR2:
1950 ethtool_link_ksettings_add_link_mode(ks, supported,
1951 100000baseSR4_Full);
1953 case ICE_PHY_TYPE_LOW_100GBASE_LR4:
1954 case ICE_PHY_TYPE_LOW_100GBASE_DR:
1955 ethtool_link_ksettings_add_link_mode(ks, supported,
1956 100000baseLR4_ER4_Full);
1958 case ICE_PHY_TYPE_LOW_100GBASE_KR4:
1959 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
1960 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1961 ethtool_link_ksettings_add_link_mode(ks, supported,
1962 100000baseKR4_Full);
1963 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1964 ethtool_link_ksettings_add_link_mode(ks, advertising,
1965 100000baseKR4_Full);
1968 unrecog_phy_low = true;
1971 switch (link_info->phy_type_high) {
1972 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
1973 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1974 ethtool_link_ksettings_add_link_mode(ks, supported,
1975 100000baseKR4_Full);
1976 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1977 ethtool_link_ksettings_add_link_mode(ks, advertising,
1978 100000baseKR4_Full);
1980 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
1981 case ICE_PHY_TYPE_HIGH_100G_CAUI2:
1982 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
1983 case ICE_PHY_TYPE_HIGH_100G_AUI2:
1984 ethtool_link_ksettings_add_link_mode(ks, supported,
1985 100000baseCR4_Full);
1988 unrecog_phy_high = true;
1991 if (unrecog_phy_low && unrecog_phy_high) {
1992 /* if we got here and link is up something bad is afoot */
1994 "WARNING: Unrecognized PHY_Low (0x%llx).\n",
1995 (u64)link_info->phy_type_low);
1997 "WARNING: Unrecognized PHY_High (0x%llx).\n",
1998 (u64)link_info->phy_type_high);
2001 /* Now that we've worked out everything that could be supported by the
2002 * current PHY type, get what is supported by the NVM and intersect
2003 * them to get what is truly supported
2005 memset(&cap_ksettings, 0, sizeof(cap_ksettings));
2006 ice_phy_type_to_ethtool(netdev, &cap_ksettings);
2007 ethtool_intersect_link_masks(ks, &cap_ksettings);
2009 switch (link_info->link_speed) {
2010 case ICE_AQ_LINK_SPEED_100GB:
2011 ks->base.speed = SPEED_100000;
2013 case ICE_AQ_LINK_SPEED_50GB:
2014 ks->base.speed = SPEED_50000;
2016 case ICE_AQ_LINK_SPEED_40GB:
2017 ks->base.speed = SPEED_40000;
2019 case ICE_AQ_LINK_SPEED_25GB:
2020 ks->base.speed = SPEED_25000;
2022 case ICE_AQ_LINK_SPEED_20GB:
2023 ks->base.speed = SPEED_20000;
2025 case ICE_AQ_LINK_SPEED_10GB:
2026 ks->base.speed = SPEED_10000;
2028 case ICE_AQ_LINK_SPEED_5GB:
2029 ks->base.speed = SPEED_5000;
2031 case ICE_AQ_LINK_SPEED_2500MB:
2032 ks->base.speed = SPEED_2500;
2034 case ICE_AQ_LINK_SPEED_1000MB:
2035 ks->base.speed = SPEED_1000;
2037 case ICE_AQ_LINK_SPEED_100MB:
2038 ks->base.speed = SPEED_100;
2042 "WARNING: Unrecognized link_speed (0x%x).\n",
2043 link_info->link_speed);
2046 ks->base.duplex = DUPLEX_FULL;
2048 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
2049 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2052 /* Set flow control negotiated Rx/Tx pause */
2053 switch (pi->fc.current_mode) {
2055 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2057 case ICE_FC_TX_PAUSE:
2058 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2059 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2062 case ICE_FC_RX_PAUSE:
2063 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2069 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
2070 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
2077 * ice_get_settings_link_down - Get the Link settings when link is down
2078 * @ks: ethtool ksettings to fill in
2079 * @netdev: network interface device structure
2081 * Reports link settings that can be determined when link is down
2084 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
2085 struct net_device *netdev)
2087 /* link is down and the driver needs to fall back on
2088 * supported PHY types to figure out what info to display
2090 ice_phy_type_to_ethtool(netdev, ks);
2092 /* With no link, speed and duplex are unknown */
2093 ks->base.speed = SPEED_UNKNOWN;
2094 ks->base.duplex = DUPLEX_UNKNOWN;
2098 * ice_get_link_ksettings - Get Link Speed and Duplex settings
2099 * @netdev: network interface device structure
2100 * @ks: ethtool ksettings
2102 * Reports speed/duplex settings based on media_type
2105 ice_get_link_ksettings(struct net_device *netdev,
2106 struct ethtool_link_ksettings *ks)
2108 struct ice_netdev_priv *np = netdev_priv(netdev);
2109 struct ice_aqc_get_phy_caps_data *caps;
2110 struct ice_link_status *hw_link_info;
2111 struct ice_vsi *vsi = np->vsi;
2112 enum ice_status status;
2115 ethtool_link_ksettings_zero_link_mode(ks, supported);
2116 ethtool_link_ksettings_zero_link_mode(ks, advertising);
2117 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
2118 hw_link_info = &vsi->port_info->phy.link_info;
2120 /* set speed and duplex */
2121 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
2122 ice_get_settings_link_up(ks, netdev);
2124 ice_get_settings_link_down(ks, netdev);
2126 /* set autoneg settings */
2127 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
2128 AUTONEG_ENABLE : AUTONEG_DISABLE;
2130 /* set media type settings */
2131 switch (vsi->port_info->phy.media_type) {
2132 case ICE_MEDIA_FIBER:
2133 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2134 ks->base.port = PORT_FIBRE;
2136 case ICE_MEDIA_BASET:
2137 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
2138 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
2139 ks->base.port = PORT_TP;
2141 case ICE_MEDIA_BACKPLANE:
2142 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2143 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
2144 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2145 ethtool_link_ksettings_add_link_mode(ks, advertising,
2147 ks->base.port = PORT_NONE;
2150 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2151 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
2152 ks->base.port = PORT_DA;
2155 ks->base.port = PORT_OTHER;
2159 /* flow control is symmetric and always supported */
2160 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
2162 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
2166 status = ice_aq_get_phy_caps(vsi->port_info, false,
2167 ICE_AQC_REPORT_SW_CFG, caps, NULL);
2173 /* Set the advertised flow control based on the PHY capability */
2174 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
2175 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
2176 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2177 ethtool_link_ksettings_add_link_mode(ks, advertising,
2179 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
2180 ethtool_link_ksettings_add_link_mode(ks, advertising,
2182 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
2183 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2184 ethtool_link_ksettings_add_link_mode(ks, advertising,
2187 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2188 ethtool_link_ksettings_del_link_mode(ks, advertising,
2192 /* Set advertised FEC modes based on PHY capability */
2193 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2195 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2196 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2197 ethtool_link_ksettings_add_link_mode(ks, advertising,
2199 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2200 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2201 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2203 status = ice_aq_get_phy_caps(vsi->port_info, false,
2204 ICE_AQC_REPORT_TOPO_CAP, caps, NULL);
2210 /* Set supported FEC modes based on PHY capability */
2211 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2213 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2214 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2215 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2216 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2217 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2220 devm_kfree(&vsi->back->pdev->dev, caps);
2225 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2226 * @ks: ethtool ksettings
2229 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2231 u16 adv_link_speed = 0;
2233 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2235 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2236 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2238 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2239 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2241 ethtool_link_ksettings_test_link_mode(ks, advertising,
2243 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2244 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2246 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2247 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2249 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2250 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2252 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2253 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2255 ethtool_link_ksettings_test_link_mode(ks, advertising,
2257 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2258 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2259 10000baseSR_Full) ||
2260 ethtool_link_ksettings_test_link_mode(ks, advertising,
2262 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2263 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2264 25000baseCR_Full) ||
2265 ethtool_link_ksettings_test_link_mode(ks, advertising,
2266 25000baseSR_Full) ||
2267 ethtool_link_ksettings_test_link_mode(ks, advertising,
2269 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2270 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2271 40000baseCR4_Full) ||
2272 ethtool_link_ksettings_test_link_mode(ks, advertising,
2273 40000baseSR4_Full) ||
2274 ethtool_link_ksettings_test_link_mode(ks, advertising,
2275 40000baseLR4_Full) ||
2276 ethtool_link_ksettings_test_link_mode(ks, advertising,
2278 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2279 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2280 50000baseCR2_Full) ||
2281 ethtool_link_ksettings_test_link_mode(ks, advertising,
2283 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2284 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2286 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2287 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2288 100000baseCR4_Full) ||
2289 ethtool_link_ksettings_test_link_mode(ks, advertising,
2290 100000baseSR4_Full) ||
2291 ethtool_link_ksettings_test_link_mode(ks, advertising,
2292 100000baseLR4_ER4_Full) ||
2293 ethtool_link_ksettings_test_link_mode(ks, advertising,
2294 100000baseKR4_Full))
2295 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2297 return adv_link_speed;
2303 * @ks: ethtool_link_ksettings
2304 * @config: configuration that will be sent down to FW
2305 * @autoneg_enabled: autonegotiation is enabled or not
2306 * @autoneg_changed: will there a change in autonegotiation
2307 * @netdev: network interface device structure
2309 * Setup PHY autonegotiation feature
2312 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2313 struct ice_aqc_set_phy_cfg_data *config,
2314 u8 autoneg_enabled, u8 *autoneg_changed,
2315 struct net_device *netdev)
2319 *autoneg_changed = 0;
2322 if (autoneg_enabled == AUTONEG_ENABLE) {
2323 /* If autoneg was not already enabled */
2324 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2325 /* If autoneg is not supported, return error */
2326 if (!ethtool_link_ksettings_test_link_mode(ks,
2329 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2332 /* Autoneg is allowed to change */
2333 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2334 *autoneg_changed = 1;
2338 /* If autoneg is currently enabled */
2339 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2340 /* If autoneg is supported 10GBASE_T is the only PHY
2341 * that can disable it, so otherwise return error
2343 if (ethtool_link_ksettings_test_link_mode(ks,
2346 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2349 /* Autoneg is allowed to change */
2350 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2351 *autoneg_changed = 1;
2360 * ice_set_link_ksettings - Set Speed and Duplex
2361 * @netdev: network interface device structure
2362 * @ks: ethtool ksettings
2364 * Set speed/duplex per media_types advertised/forced
2367 ice_set_link_ksettings(struct net_device *netdev,
2368 const struct ethtool_link_ksettings *ks)
2370 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
2371 struct ice_netdev_priv *np = netdev_priv(netdev);
2372 struct ethtool_link_ksettings safe_ks, copy_ks;
2373 struct ice_aqc_get_phy_caps_data *abilities;
2374 u16 adv_link_speed, curr_link_speed, idx;
2375 struct ice_aqc_set_phy_cfg_data config;
2376 struct ice_pf *pf = np->vsi->back;
2377 struct ice_port_info *p;
2378 u8 autoneg_changed = 0;
2379 enum ice_status status;
2385 p = np->vsi->port_info;
2390 /* Check if this is LAN VSI */
2391 ice_for_each_vsi(pf, idx)
2392 if (pf->vsi[idx]->type == ICE_VSI_PF) {
2393 if (np->vsi != pf->vsi[idx])
2398 if (p->phy.media_type != ICE_MEDIA_BASET &&
2399 p->phy.media_type != ICE_MEDIA_FIBER &&
2400 p->phy.media_type != ICE_MEDIA_BACKPLANE &&
2401 p->phy.media_type != ICE_MEDIA_DA &&
2402 p->phy.link_info.link_info & ICE_AQ_LINK_UP)
2405 /* copy the ksettings to copy_ks to avoid modifying the original */
2406 memcpy(©_ks, ks, sizeof(copy_ks));
2408 /* save autoneg out of ksettings */
2409 autoneg = copy_ks.base.autoneg;
2411 memset(&safe_ks, 0, sizeof(safe_ks));
2413 /* Get link modes supported by hardware.*/
2414 ice_phy_type_to_ethtool(netdev, &safe_ks);
2416 /* and check against modes requested by user.
2417 * Return an error if unsupported mode was set.
2419 if (!bitmap_subset(copy_ks.link_modes.advertising,
2420 safe_ks.link_modes.supported,
2421 __ETHTOOL_LINK_MODE_MASK_NBITS))
2424 /* get our own copy of the bits to check against */
2425 memset(&safe_ks, 0, sizeof(safe_ks));
2426 safe_ks.base.cmd = copy_ks.base.cmd;
2427 safe_ks.base.link_mode_masks_nwords =
2428 copy_ks.base.link_mode_masks_nwords;
2429 ice_get_link_ksettings(netdev, &safe_ks);
2431 /* set autoneg back to what it currently is */
2432 copy_ks.base.autoneg = safe_ks.base.autoneg;
2433 /* we don't compare the speed */
2434 copy_ks.base.speed = safe_ks.base.speed;
2436 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2437 * trying to set something that we do not support.
2439 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base)))
2442 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2446 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2449 abilities = devm_kzalloc(&pf->pdev->dev, sizeof(*abilities),
2454 /* Get the current PHY config */
2455 status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
2462 /* Copy abilities to config in case autoneg is not set below */
2463 memset(&config, 0, sizeof(config));
2464 config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
2465 if (abilities->caps & ICE_AQC_PHY_AN_MODE)
2466 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2469 err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
2475 /* Call to get the current link speed */
2476 p->phy.get_link_info = true;
2477 status = ice_get_link_status(p, &linkup);
2483 curr_link_speed = p->phy.link_info.link_speed;
2484 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2486 /* If speed didn't get set, set it to what it currently is.
2487 * This is needed because if advertise is 0 (as it is when autoneg
2488 * is disabled) then speed won't get set.
2490 if (!adv_link_speed)
2491 adv_link_speed = curr_link_speed;
2493 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2494 ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed);
2496 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2497 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2501 /* copy over the rest of the abilities */
2502 config.low_power_ctrl = abilities->low_power_ctrl;
2503 config.eee_cap = abilities->eee_cap;
2504 config.eeer_value = abilities->eeer_value;
2505 config.link_fec_opt = abilities->link_fec_options;
2507 /* save the requested speeds */
2508 p->phy.link_info.req_speeds = adv_link_speed;
2510 /* set link and auto negotiation so changes take effect */
2511 config.caps |= ICE_AQ_PHY_ENA_LINK;
2513 if (phy_type_low || phy_type_high) {
2514 config.phy_type_high = cpu_to_le64(phy_type_high) &
2515 abilities->phy_type_high;
2516 config.phy_type_low = cpu_to_le64(phy_type_low) &
2517 abilities->phy_type_low;
2520 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2524 /* If link is up put link down */
2525 if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2526 /* Tell the OS link is going down, the link will go
2527 * back up when fw says it is ready asynchronously
2529 ice_print_link_msg(np->vsi, false);
2530 netif_carrier_off(netdev);
2531 netif_tx_stop_all_queues(netdev);
2534 /* make the aq call */
2535 status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
2537 netdev_info(netdev, "Set phy config failed,\n");
2542 devm_kfree(&pf->pdev->dev, abilities);
2543 clear_bit(__ICE_CFG_BUSY, pf->state);
2549 * ice_get_rxnfc - command to get Rx flow classification rules
2550 * @netdev: network interface device structure
2551 * @cmd: ethtool rxnfc command
2552 * @rule_locs: buffer to rturn Rx flow classification rules
2554 * Returns Success if the command is supported.
2557 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2558 u32 __always_unused *rule_locs)
2560 struct ice_netdev_priv *np = netdev_priv(netdev);
2561 struct ice_vsi *vsi = np->vsi;
2562 int ret = -EOPNOTSUPP;
2565 case ETHTOOL_GRXRINGS:
2566 cmd->data = vsi->rss_size;
2577 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2579 struct ice_netdev_priv *np = netdev_priv(netdev);
2580 struct ice_vsi *vsi = np->vsi;
2582 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2583 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2584 ring->rx_pending = vsi->rx_rings[0]->count;
2585 ring->tx_pending = vsi->tx_rings[0]->count;
2587 /* Rx mini and jumbo rings are not supported */
2588 ring->rx_mini_max_pending = 0;
2589 ring->rx_jumbo_max_pending = 0;
2590 ring->rx_mini_pending = 0;
2591 ring->rx_jumbo_pending = 0;
2595 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2597 struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2598 struct ice_netdev_priv *np = netdev_priv(netdev);
2599 struct ice_vsi *vsi = np->vsi;
2600 struct ice_pf *pf = vsi->back;
2601 int i, timeout = 50, err = 0;
2602 u32 new_rx_cnt, new_tx_cnt;
2604 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2605 ring->tx_pending < ICE_MIN_NUM_DESC ||
2606 ring->rx_pending > ICE_MAX_NUM_DESC ||
2607 ring->rx_pending < ICE_MIN_NUM_DESC) {
2608 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2609 ring->tx_pending, ring->rx_pending,
2610 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2611 ICE_REQ_DESC_MULTIPLE);
2615 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2616 if (new_tx_cnt != ring->tx_pending)
2618 "Requested Tx descriptor count rounded up to %d\n",
2620 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2621 if (new_rx_cnt != ring->rx_pending)
2623 "Requested Rx descriptor count rounded up to %d\n",
2626 /* if nothing to do return success */
2627 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2628 new_rx_cnt == vsi->rx_rings[0]->count) {
2629 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2633 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2637 usleep_range(1000, 2000);
2640 /* set for the next time the netdev is started */
2641 if (!netif_running(vsi->netdev)) {
2642 for (i = 0; i < vsi->alloc_txq; i++)
2643 vsi->tx_rings[i]->count = new_tx_cnt;
2644 for (i = 0; i < vsi->alloc_rxq; i++)
2645 vsi->rx_rings[i]->count = new_rx_cnt;
2646 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2650 if (new_tx_cnt == vsi->tx_rings[0]->count)
2653 /* alloc updated Tx resources */
2654 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2655 vsi->tx_rings[0]->count, new_tx_cnt);
2657 tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_txq,
2658 sizeof(*tx_rings), GFP_KERNEL);
2664 for (i = 0; i < vsi->alloc_txq; i++) {
2665 /* clone ring and setup updated count */
2666 tx_rings[i] = *vsi->tx_rings[i];
2667 tx_rings[i].count = new_tx_cnt;
2668 tx_rings[i].desc = NULL;
2669 tx_rings[i].tx_buf = NULL;
2670 err = ice_setup_tx_ring(&tx_rings[i]);
2674 ice_clean_tx_ring(&tx_rings[i]);
2676 devm_kfree(&pf->pdev->dev, tx_rings);
2682 if (new_rx_cnt == vsi->rx_rings[0]->count)
2685 /* alloc updated Rx resources */
2686 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2687 vsi->rx_rings[0]->count, new_rx_cnt);
2689 rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->alloc_rxq,
2690 sizeof(*rx_rings), GFP_KERNEL);
2696 for (i = 0; i < vsi->alloc_rxq; i++) {
2697 /* clone ring and setup updated count */
2698 rx_rings[i] = *vsi->rx_rings[i];
2699 rx_rings[i].count = new_rx_cnt;
2700 rx_rings[i].desc = NULL;
2701 rx_rings[i].rx_buf = NULL;
2702 /* this is to allow wr32 to have something to write to
2703 * during early allocation of Rx buffers
2705 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2707 err = ice_setup_rx_ring(&rx_rings[i]);
2711 /* allocate Rx buffers */
2712 err = ice_alloc_rx_bufs(&rx_rings[i],
2713 ICE_DESC_UNUSED(&rx_rings[i]));
2718 ice_free_rx_ring(&rx_rings[i]);
2720 devm_kfree(&pf->pdev->dev, rx_rings);
2727 /* Bring interface down, copy in the new ring info, then restore the
2728 * interface. if VSI is up, bring it down and then back up
2730 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2734 for (i = 0; i < vsi->alloc_txq; i++) {
2735 ice_free_tx_ring(vsi->tx_rings[i]);
2736 *vsi->tx_rings[i] = tx_rings[i];
2738 devm_kfree(&pf->pdev->dev, tx_rings);
2742 for (i = 0; i < vsi->alloc_rxq; i++) {
2743 ice_free_rx_ring(vsi->rx_rings[i]);
2744 /* copy the real tail offset */
2745 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2746 /* this is to fake out the allocation routine
2747 * into thinking it has to realloc everything
2748 * but the recycling logic will let us re-use
2749 * the buffers allocated above
2751 rx_rings[i].next_to_use = 0;
2752 rx_rings[i].next_to_clean = 0;
2753 rx_rings[i].next_to_alloc = 0;
2754 *vsi->rx_rings[i] = rx_rings[i];
2756 devm_kfree(&pf->pdev->dev, rx_rings);
2764 /* error cleanup if the Rx allocations failed after getting Tx */
2766 for (i = 0; i < vsi->alloc_txq; i++)
2767 ice_free_tx_ring(&tx_rings[i]);
2768 devm_kfree(&pf->pdev->dev, tx_rings);
2772 clear_bit(__ICE_CFG_BUSY, pf->state);
2776 static int ice_nway_reset(struct net_device *netdev)
2778 /* restart autonegotiation */
2779 struct ice_netdev_priv *np = netdev_priv(netdev);
2780 struct ice_vsi *vsi = np->vsi;
2781 struct ice_port_info *pi;
2782 enum ice_status status;
2784 pi = vsi->port_info;
2785 /* If VSI state is up, then restart autoneg with link up */
2786 if (!test_bit(__ICE_DOWN, vsi->back->state))
2787 status = ice_aq_set_link_restart_an(pi, true, NULL);
2789 status = ice_aq_set_link_restart_an(pi, false, NULL);
2792 netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
2793 status, pi->hw->adminq.sq_last_status);
2801 * ice_get_pauseparam - Get Flow Control status
2802 * @netdev: network interface device structure
2803 * @pause: ethernet pause (flow control) parameters
2805 * Get requested flow control status from PHY capability.
2806 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2807 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2808 * the negotiated Rx/Tx pause via lp_advertising.
2811 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2813 struct ice_netdev_priv *np = netdev_priv(netdev);
2814 struct ice_port_info *pi = np->vsi->port_info;
2815 struct ice_aqc_get_phy_caps_data *pcaps;
2816 struct ice_vsi *vsi = np->vsi;
2817 struct ice_dcbx_cfg *dcbx_cfg;
2818 enum ice_status status;
2820 /* Initialize pause params */
2821 pause->rx_pause = 0;
2822 pause->tx_pause = 0;
2824 dcbx_cfg = &pi->local_dcbx_cfg;
2826 pcaps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*pcaps),
2831 /* Get current PHY config */
2832 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2837 pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2838 AUTONEG_ENABLE : AUTONEG_DISABLE);
2840 if (dcbx_cfg->pfc.pfcena)
2841 /* PFC enabled so report LFC as off */
2844 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2845 pause->tx_pause = 1;
2846 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2847 pause->rx_pause = 1;
2850 devm_kfree(&vsi->back->pdev->dev, pcaps);
2854 * ice_set_pauseparam - Set Flow Control parameter
2855 * @netdev: network interface device structure
2856 * @pause: return Tx/Rx flow control status
2859 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2861 struct ice_netdev_priv *np = netdev_priv(netdev);
2862 struct ice_aqc_get_phy_caps_data *pcaps;
2863 struct ice_link_status *hw_link_info;
2864 struct ice_pf *pf = np->vsi->back;
2865 struct ice_dcbx_cfg *dcbx_cfg;
2866 struct ice_vsi *vsi = np->vsi;
2867 struct ice_hw *hw = &pf->hw;
2868 struct ice_port_info *pi;
2869 enum ice_status status;
2875 pi = vsi->port_info;
2876 hw_link_info = &pi->phy.link_info;
2877 dcbx_cfg = &pi->local_dcbx_cfg;
2878 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
2880 /* Changing the port's flow control is not supported if this isn't the
2883 if (vsi->type != ICE_VSI_PF) {
2884 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
2888 /* Get pause param reports configured and negotiated flow control pause
2889 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2890 * defined get pause param pause->autoneg reports SW configured setting,
2891 * so compare pause->autoneg with SW configured to prevent the user from
2892 * using set pause param to chance autoneg.
2894 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2898 /* Get current PHY config */
2899 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2906 is_an = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2907 AUTONEG_ENABLE : AUTONEG_DISABLE);
2911 if (pause->autoneg != is_an) {
2912 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2916 /* If we have link and don't have autoneg */
2917 if (!test_bit(__ICE_DOWN, pf->state) &&
2918 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
2919 /* Send message that it might not necessarily work*/
2920 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2923 if (dcbx_cfg->pfc.pfcena) {
2924 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
2927 if (pause->rx_pause && pause->tx_pause)
2928 pi->fc.req_mode = ICE_FC_FULL;
2929 else if (pause->rx_pause && !pause->tx_pause)
2930 pi->fc.req_mode = ICE_FC_RX_PAUSE;
2931 else if (!pause->rx_pause && pause->tx_pause)
2932 pi->fc.req_mode = ICE_FC_TX_PAUSE;
2933 else if (!pause->rx_pause && !pause->tx_pause)
2934 pi->fc.req_mode = ICE_FC_NONE;
2938 /* Tell the OS link is going down, the link will go back up when fw
2939 * says it is ready asynchronously
2941 ice_print_link_msg(vsi, false);
2942 netif_carrier_off(netdev);
2943 netif_tx_stop_all_queues(netdev);
2945 /* Set the FC mode and only restart AN if link is up */
2946 status = ice_set_fc(pi, &aq_failures, link_up);
2948 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
2949 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2950 status, hw->adminq.sq_last_status);
2952 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
2953 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2954 status, hw->adminq.sq_last_status);
2956 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
2957 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2958 status, hw->adminq.sq_last_status);
2962 if (!test_bit(__ICE_DOWN, pf->state)) {
2963 /* Give it a little more time to try to come back. If still
2964 * down, restart autoneg link or reinitialize the interface.
2967 if (!test_bit(__ICE_DOWN, pf->state))
2968 return ice_nway_reset(netdev);
2978 * ice_get_rxfh_key_size - get the RSS hash key size
2979 * @netdev: network interface device structure
2981 * Returns the table size.
2983 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
2985 return ICE_VSIQF_HKEY_ARRAY_SIZE;
2989 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
2990 * @netdev: network interface device structure
2992 * Returns the table size.
2994 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
2996 struct ice_netdev_priv *np = netdev_priv(netdev);
2998 return np->vsi->rss_table_size;
3002 * ice_get_rxfh - get the Rx flow hash indirection table
3003 * @netdev: network interface device structure
3004 * @indir: indirection table
3006 * @hfunc: hash function
3008 * Reads the indirection table directly from the hardware.
3011 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3013 struct ice_netdev_priv *np = netdev_priv(netdev);
3014 struct ice_vsi *vsi = np->vsi;
3015 struct ice_pf *pf = vsi->back;
3020 *hfunc = ETH_RSS_HASH_TOP;
3025 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3026 /* RSS not supported return error here */
3027 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3031 lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
3035 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3040 for (i = 0; i < vsi->rss_table_size; i++)
3041 indir[i] = (u32)(lut[i]);
3044 devm_kfree(&pf->pdev->dev, lut);
3049 * ice_set_rxfh - set the Rx flow hash indirection table
3050 * @netdev: network interface device structure
3051 * @indir: indirection table
3053 * @hfunc: hash function
3055 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3056 * returns 0 after programming the table.
3059 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3062 struct ice_netdev_priv *np = netdev_priv(netdev);
3063 struct ice_vsi *vsi = np->vsi;
3064 struct ice_pf *pf = vsi->back;
3067 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3070 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3071 /* RSS not supported return error here */
3072 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3077 if (!vsi->rss_hkey_user) {
3078 vsi->rss_hkey_user =
3079 devm_kzalloc(&pf->pdev->dev,
3080 ICE_VSIQF_HKEY_ARRAY_SIZE,
3082 if (!vsi->rss_hkey_user)
3085 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3086 seed = vsi->rss_hkey_user;
3089 if (!vsi->rss_lut_user) {
3090 vsi->rss_lut_user = devm_kzalloc(&pf->pdev->dev,
3091 vsi->rss_table_size,
3093 if (!vsi->rss_lut_user)
3097 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3101 for (i = 0; i < vsi->rss_table_size; i++)
3102 vsi->rss_lut_user[i] = (u8)(indir[i]);
3104 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3108 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3114 enum ice_container_type {
3120 * ice_get_rc_coalesce - get ITR values for specific ring container
3121 * @ec: ethtool structure to fill with driver's coalesce settings
3122 * @c_type: container type, Rx or Tx
3123 * @rc: ring container that the ITR values will come from
3125 * Query the device for ice_ring_container specific ITR values. This is
3126 * done per ice_ring_container because each q_vector can have 1 or more rings
3127 * and all of said ring(s) will have the same ITR values.
3129 * Returns 0 on success, negative otherwise.
3132 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3133 struct ice_ring_container *rc)
3140 pf = rc->ring->vsi->back;
3143 case ICE_RX_CONTAINER:
3144 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3145 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3146 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3148 case ICE_TX_CONTAINER:
3149 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3150 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3153 dev_dbg(&pf->pdev->dev, "Invalid c_type %d\n", c_type);
3161 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3162 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3163 * @ec: coalesce settings to program the device with
3164 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3166 * Return 0 on success, and negative under the following conditions:
3167 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3168 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3171 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3173 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3174 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3175 &vsi->rx_rings[q_num]->q_vector->rx))
3177 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3178 &vsi->tx_rings[q_num]->q_vector->tx))
3180 } else if (q_num < vsi->num_rxq) {
3181 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3182 &vsi->rx_rings[q_num]->q_vector->rx))
3184 } else if (q_num < vsi->num_txq) {
3185 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3186 &vsi->tx_rings[q_num]->q_vector->tx))
3196 * __ice_get_coalesce - get ITR/INTRL values for the device
3197 * @netdev: pointer to the netdev associated with this query
3198 * @ec: ethtool structure to fill with driver's coalesce settings
3199 * @q_num: queue number to get the coalesce settings for
3201 * If the caller passes in a negative q_num then we return coalesce settings
3202 * based on queue number 0, else use the actual q_num passed in.
3205 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3208 struct ice_netdev_priv *np = netdev_priv(netdev);
3209 struct ice_vsi *vsi = np->vsi;
3214 if (ice_get_q_coalesce(vsi, ec, q_num))
3217 if (q_num < vsi->num_txq)
3218 ec->tx_max_coalesced_frames_irq = vsi->work_lmt;
3220 if (q_num < vsi->num_rxq)
3221 ec->rx_max_coalesced_frames_irq = vsi->work_lmt;
3227 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3229 return __ice_get_coalesce(netdev, ec, -1);
3233 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3234 struct ethtool_coalesce *ec)
3236 return __ice_get_coalesce(netdev, ec, q_num);
3240 * ice_set_rc_coalesce - set ITR values for specific ring container
3241 * @c_type: container type, Rx or Tx
3242 * @ec: ethtool structure from user to update ITR settings
3243 * @rc: ring container that the ITR values will come from
3244 * @vsi: VSI associated to the ring container
3246 * Set specific ITR values. This is done per ice_ring_container because each
3247 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3250 * Returns 0 on success, negative otherwise.
3253 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3254 struct ice_ring_container *rc, struct ice_vsi *vsi)
3256 const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3257 u32 use_adaptive_coalesce, coalesce_usecs;
3258 struct ice_pf *pf = vsi->back;
3265 case ICE_RX_CONTAINER:
3266 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3267 (ec->rx_coalesce_usecs_high &&
3268 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3269 netdev_info(vsi->netdev,
3270 "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3271 c_type_str, pf->hw.intrl_gran,
3275 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3276 rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3277 wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3278 ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3279 pf->hw.intrl_gran));
3282 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3283 coalesce_usecs = ec->rx_coalesce_usecs;
3286 case ICE_TX_CONTAINER:
3287 if (ec->tx_coalesce_usecs_high) {
3288 netdev_info(vsi->netdev,
3289 "setting %s-usecs-high is not supported\n",
3294 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3295 coalesce_usecs = ec->tx_coalesce_usecs;
3299 dev_dbg(&pf->pdev->dev, "Invalid container type %d\n", c_type);
3303 itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3304 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3305 netdev_info(vsi->netdev,
3306 "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3307 c_type_str, c_type_str);
3311 if (coalesce_usecs > ICE_ITR_MAX) {
3312 netdev_info(vsi->netdev,
3313 "Invalid value, %s-usecs range is 0-%d\n",
3314 c_type_str, ICE_ITR_MAX);
3318 /* hardware only supports an ITR granularity of 2us */
3319 if (coalesce_usecs % 2 != 0) {
3320 netdev_info(vsi->netdev,
3321 "Invalid value, %s-usecs must be even\n",
3326 if (use_adaptive_coalesce) {
3327 rc->itr_setting |= ICE_ITR_DYNAMIC;
3329 /* store user facing value how it was set */
3330 rc->itr_setting = coalesce_usecs;
3331 /* set to static and convert to value HW understands */
3333 ITR_TO_REG(ITR_REG_ALIGN(rc->itr_setting));
3340 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3341 * @vsi: VSI associated to the queue that need updating
3342 * @ec: coalesce settings to program the device with
3343 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3345 * Return 0 on success, and negative under the following conditions:
3346 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3347 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3350 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3352 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3353 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3354 &vsi->rx_rings[q_num]->q_vector->rx,
3358 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3359 &vsi->tx_rings[q_num]->q_vector->tx,
3362 } else if (q_num < vsi->num_rxq) {
3363 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3364 &vsi->rx_rings[q_num]->q_vector->rx,
3367 } else if (q_num < vsi->num_txq) {
3368 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3369 &vsi->tx_rings[q_num]->q_vector->tx,
3380 * __ice_set_coalesce - set ITR/INTRL values for the device
3381 * @netdev: pointer to the netdev associated with this query
3382 * @ec: ethtool structure to fill with driver's coalesce settings
3383 * @q_num: queue number to get the coalesce settings for
3385 * If the caller passes in a negative q_num then we set the coalesce settings
3386 * for all Tx/Rx queues, else use the actual q_num passed in.
3389 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3392 struct ice_netdev_priv *np = netdev_priv(netdev);
3393 struct ice_vsi *vsi = np->vsi;
3398 ice_for_each_q_vector(vsi, i) {
3399 if (ice_set_q_coalesce(vsi, ec, i))
3405 if (ice_set_q_coalesce(vsi, ec, q_num))
3410 if (ec->tx_max_coalesced_frames_irq || ec->rx_max_coalesced_frames_irq)
3411 vsi->work_lmt = max(ec->tx_max_coalesced_frames_irq,
3412 ec->rx_max_coalesced_frames_irq);
3418 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3420 return __ice_set_coalesce(netdev, ec, -1);
3424 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3425 struct ethtool_coalesce *ec)
3427 return __ice_set_coalesce(netdev, ec, q_num);
3430 static const struct ethtool_ops ice_ethtool_ops = {
3431 .get_link_ksettings = ice_get_link_ksettings,
3432 .set_link_ksettings = ice_set_link_ksettings,
3433 .get_drvinfo = ice_get_drvinfo,
3434 .get_regs_len = ice_get_regs_len,
3435 .get_regs = ice_get_regs,
3436 .get_msglevel = ice_get_msglevel,
3437 .set_msglevel = ice_set_msglevel,
3438 .self_test = ice_self_test,
3439 .get_link = ethtool_op_get_link,
3440 .get_eeprom_len = ice_get_eeprom_len,
3441 .get_eeprom = ice_get_eeprom,
3442 .get_coalesce = ice_get_coalesce,
3443 .set_coalesce = ice_set_coalesce,
3444 .get_strings = ice_get_strings,
3445 .set_phys_id = ice_set_phys_id,
3446 .get_ethtool_stats = ice_get_ethtool_stats,
3447 .get_priv_flags = ice_get_priv_flags,
3448 .set_priv_flags = ice_set_priv_flags,
3449 .get_sset_count = ice_get_sset_count,
3450 .get_rxnfc = ice_get_rxnfc,
3451 .get_ringparam = ice_get_ringparam,
3452 .set_ringparam = ice_set_ringparam,
3453 .nway_reset = ice_nway_reset,
3454 .get_pauseparam = ice_get_pauseparam,
3455 .set_pauseparam = ice_set_pauseparam,
3456 .get_rxfh_key_size = ice_get_rxfh_key_size,
3457 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
3458 .get_rxfh = ice_get_rxfh,
3459 .set_rxfh = ice_set_rxfh,
3460 .get_ts_info = ethtool_op_get_ts_info,
3461 .get_per_queue_coalesce = ice_get_per_q_coalesce,
3462 .set_per_queue_coalesce = ice_set_per_q_coalesce,
3463 .get_fecparam = ice_get_fecparam,
3464 .set_fecparam = ice_set_fecparam,
3468 * ice_set_ethtool_ops - setup netdev ethtool ops
3469 * @netdev: network interface device structure
3471 * setup netdev ethtool ops with ice specific ops
3473 void ice_set_ethtool_ops(struct net_device *netdev)
3475 netdev->ethtool_ops = &ice_ethtool_ops;