1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
9 #include "ice_dcb_lib.h"
12 char stat_string[ETH_GSTRING_LEN];
17 #define ICE_STAT(_type, _name, _stat) { \
18 .stat_string = _name, \
19 .sizeof_stat = sizeof_field(_type, _stat), \
20 .stat_offset = offsetof(_type, _stat) \
23 #define ICE_VSI_STAT(_name, _stat) \
24 ICE_STAT(struct ice_vsi, _name, _stat)
25 #define ICE_PF_STAT(_name, _stat) \
26 ICE_STAT(struct ice_pf, _name, _stat)
28 static int ice_q_stats_len(struct net_device *netdev)
30 struct ice_netdev_priv *np = netdev_priv(netdev);
32 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
33 (sizeof(struct ice_q_stats) / sizeof(u64)));
36 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
37 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
39 #define ICE_PFC_STATS_LEN ( \
40 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
41 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
42 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
43 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
45 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
46 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
48 static const struct ice_stats ice_gstrings_vsi_stats[] = {
49 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
50 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
51 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
52 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
53 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
54 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
55 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
56 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
57 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
58 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
59 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
60 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
61 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
62 ICE_VSI_STAT("tx_linearize", tx_linearize),
65 enum ice_ethtool_test_id {
73 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
74 "Register test (offline)",
75 "EEPROM test (offline)",
76 "Interrupt test (offline)",
77 "Loopback test (offline)",
78 "Link test (on/offline)",
81 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
83 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
84 * but they aren't. This device is capable of supporting multiple
85 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
86 * netdevs whereas the PF_STATs are for the physical function that's
87 * hosting these netdevs.
89 * The PF_STATs are appended to the netdev stats only when ethtool -S
90 * is queried on the base PF netdev.
92 static const struct ice_stats ice_gstrings_pf_stats[] = {
93 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
94 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
95 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
96 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
97 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
98 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
99 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
100 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
101 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
102 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
103 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
104 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
105 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
106 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
107 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
108 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
109 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
110 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
111 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
112 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
113 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
114 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
115 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
116 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
117 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
118 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
119 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
120 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
121 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
122 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
123 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
124 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
125 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
126 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
127 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
128 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
129 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
130 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
131 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
134 static const u32 ice_regs_dump_list[] = {
147 struct ice_priv_flag {
148 char name[ETH_GSTRING_LEN];
149 u32 bitno; /* bit position in pf->flags */
152 #define ICE_PRIV_FLAG(_name, _bitno) { \
157 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
158 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
159 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
160 ICE_PRIV_FLAG("vf-true-promisc-support",
161 ICE_FLAG_VF_TRUE_PROMISC_ENA),
162 ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
163 ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
166 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
169 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
171 struct ice_netdev_priv *np = netdev_priv(netdev);
172 struct ice_vsi *vsi = np->vsi;
173 struct ice_pf *pf = vsi->back;
174 struct ice_hw *hw = &pf->hw;
175 struct ice_orom_info *orom;
176 struct ice_nvm_info *nvm;
181 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
182 strscpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
184 /* Display NVM version (from which the firmware version can be
185 * determined) which contains more pertinent information.
187 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
188 "%x.%02x 0x%x %d.%d.%d", nvm->major_ver, nvm->minor_ver,
189 nvm->eetrack, orom->major, orom->build, orom->patch);
191 strscpy(drvinfo->bus_info, pci_name(pf->pdev),
192 sizeof(drvinfo->bus_info));
193 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
196 static int ice_get_regs_len(struct net_device __always_unused *netdev)
198 return sizeof(ice_regs_dump_list);
202 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
204 struct ice_netdev_priv *np = netdev_priv(netdev);
205 struct ice_pf *pf = np->vsi->back;
206 struct ice_hw *hw = &pf->hw;
207 u32 *regs_buf = (u32 *)p;
212 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
213 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
216 static u32 ice_get_msglevel(struct net_device *netdev)
218 struct ice_netdev_priv *np = netdev_priv(netdev);
219 struct ice_pf *pf = np->vsi->back;
221 #ifndef CONFIG_DYNAMIC_DEBUG
222 if (pf->hw.debug_mask)
223 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
225 #endif /* !CONFIG_DYNAMIC_DEBUG */
227 return pf->msg_enable;
230 static void ice_set_msglevel(struct net_device *netdev, u32 data)
232 struct ice_netdev_priv *np = netdev_priv(netdev);
233 struct ice_pf *pf = np->vsi->back;
235 #ifndef CONFIG_DYNAMIC_DEBUG
236 if (ICE_DBG_USER & data)
237 pf->hw.debug_mask = data;
239 pf->msg_enable = data;
241 pf->msg_enable = data;
242 #endif /* !CONFIG_DYNAMIC_DEBUG */
245 static int ice_get_eeprom_len(struct net_device *netdev)
247 struct ice_netdev_priv *np = netdev_priv(netdev);
248 struct ice_pf *pf = np->vsi->back;
250 return (int)pf->hw.nvm.flash_size;
254 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
257 struct ice_netdev_priv *np = netdev_priv(netdev);
258 struct ice_vsi *vsi = np->vsi;
259 struct ice_pf *pf = vsi->back;
260 struct ice_hw *hw = &pf->hw;
261 enum ice_status status;
266 dev = ice_pf_to_dev(pf);
268 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
269 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
270 eeprom->cmd, eeprom->offset, eeprom->len);
272 buf = kzalloc(eeprom->len, GFP_KERNEL);
276 status = ice_acquire_nvm(hw, ICE_RES_READ);
278 dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %d\n",
279 status, hw->adminq.sq_last_status);
284 status = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
287 dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %d\n",
288 status, hw->adminq.sq_last_status);
293 memcpy(bytes, buf, eeprom->len);
302 * ice_active_vfs - check if there are any active VFs
303 * @pf: board private structure
305 * Returns true if an active VF is found, otherwise returns false
307 static bool ice_active_vfs(struct ice_pf *pf)
311 ice_for_each_vf(pf, i) {
312 struct ice_vf *vf = &pf->vf[i];
314 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
322 * ice_link_test - perform a link test on a given net_device
323 * @netdev: network interface device structure
325 * This function performs one of the self-tests required by ethtool.
326 * Returns 0 on success, non-zero on failure.
328 static u64 ice_link_test(struct net_device *netdev)
330 struct ice_netdev_priv *np = netdev_priv(netdev);
331 enum ice_status status;
332 bool link_up = false;
334 netdev_info(netdev, "link test\n");
335 status = ice_get_link_status(np->vsi->port_info, &link_up);
337 netdev_err(netdev, "link query error, status = %d\n", status);
348 * ice_eeprom_test - perform an EEPROM test on a given net_device
349 * @netdev: network interface device structure
351 * This function performs one of the self-tests required by ethtool.
352 * Returns 0 on success, non-zero on failure.
354 static u64 ice_eeprom_test(struct net_device *netdev)
356 struct ice_netdev_priv *np = netdev_priv(netdev);
357 struct ice_pf *pf = np->vsi->back;
359 netdev_info(netdev, "EEPROM test\n");
360 return !!(ice_nvm_validate_checksum(&pf->hw));
364 * ice_reg_pattern_test
365 * @hw: pointer to the HW struct
366 * @reg: reg to be tested
367 * @mask: bits to be touched
369 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
371 struct ice_pf *pf = (struct ice_pf *)hw->back;
372 struct device *dev = ice_pf_to_dev(pf);
373 static const u32 patterns[] = {
374 0x5A5A5A5A, 0xA5A5A5A5,
375 0x00000000, 0xFFFFFFFF
380 orig_val = rd32(hw, reg);
381 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
382 u32 pattern = patterns[i] & mask;
384 wr32(hw, reg, pattern);
388 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
389 , __func__, reg, pattern, val);
393 wr32(hw, reg, orig_val);
395 if (val != orig_val) {
396 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
397 , __func__, reg, orig_val, val);
405 * ice_reg_test - perform a register test on a given net_device
406 * @netdev: network interface device structure
408 * This function performs one of the self-tests required by ethtool.
409 * Returns 0 on success, non-zero on failure.
411 static u64 ice_reg_test(struct net_device *netdev)
413 struct ice_netdev_priv *np = netdev_priv(netdev);
414 struct ice_hw *hw = np->vsi->port_info->hw;
415 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
416 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
417 struct ice_diag_reg_test_info {
423 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
424 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
425 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
426 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
427 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
428 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
429 {GLINT_CTL, 0xffff0001, 1, 0}
433 netdev_dbg(netdev, "Register test\n");
434 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
437 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
438 u32 mask = ice_reg_list[i].mask;
439 u32 reg = ice_reg_list[i].address +
440 (j * ice_reg_list[i].elem_size);
442 /* bail on failure (non-zero return) */
443 if (ice_reg_pattern_test(hw, reg, mask))
452 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
453 * @vsi: pointer to the VSI structure
455 * Function configures rings of a VSI for loopback test without
456 * enabling interrupts or informing the kernel about new queues.
458 * Returns 0 on success, negative on failure.
460 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
464 status = ice_vsi_setup_tx_rings(vsi);
466 goto err_setup_tx_ring;
468 status = ice_vsi_setup_rx_rings(vsi);
470 goto err_setup_rx_ring;
472 status = ice_vsi_cfg(vsi);
474 goto err_setup_rx_ring;
476 status = ice_vsi_start_all_rx_rings(vsi);
478 goto err_start_rx_ring;
483 ice_vsi_free_rx_rings(vsi);
485 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
487 ice_vsi_free_tx_rings(vsi);
493 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
494 * @vsi: pointer to the VSI structure
496 * Function stops and frees VSI rings after a loopback test.
497 * Returns 0 on success, negative on failure.
499 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
503 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
505 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
506 vsi->vsi_num, status);
508 status = ice_vsi_stop_all_rx_rings(vsi);
510 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
511 vsi->vsi_num, status);
513 ice_vsi_free_tx_rings(vsi);
514 ice_vsi_free_rx_rings(vsi);
520 * ice_lbtest_create_frame - create test packet
521 * @pf: pointer to the PF structure
522 * @ret_data: allocated frame buffer
523 * @size: size of the packet data
525 * Function allocates a frame with a test pattern on specific offsets.
526 * Returns 0 on success, non-zero on failure.
528 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
535 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
539 /* Since the ethernet test frame should always be at least
540 * 64 bytes long, fill some octets in the payload with test data.
542 memset(data, 0xFF, size);
554 * ice_lbtest_check_frame - verify received loopback frame
555 * @frame: pointer to the raw packet data
557 * Function verifies received test frame with a pattern.
558 * Returns true if frame matches the pattern, false otherwise.
560 static bool ice_lbtest_check_frame(u8 *frame)
562 /* Validate bytes of a frame under offsets chosen earlier */
563 if (frame[32] == 0xDE &&
574 * ice_diag_send - send test frames to the test ring
575 * @tx_ring: pointer to the transmit ring
576 * @data: pointer to the raw packet data
577 * @size: size of the packet to send
579 * Function sends loopback packets on a test Tx ring.
581 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
583 struct ice_tx_desc *tx_desc;
584 struct ice_tx_buf *tx_buf;
588 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
589 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
591 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
592 if (dma_mapping_error(tx_ring->dev, dma))
595 tx_desc->buf_addr = cpu_to_le64(dma);
597 /* These flags are required for a descriptor to be pushed out */
598 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
599 tx_desc->cmd_type_offset_bsz =
600 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
601 (td_cmd << ICE_TXD_QW1_CMD_S) |
602 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
603 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
604 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
606 tx_buf->next_to_watch = tx_desc;
608 /* Force memory write to complete before letting h/w know
609 * there are new descriptors to fetch.
613 tx_ring->next_to_use++;
614 if (tx_ring->next_to_use >= tx_ring->count)
615 tx_ring->next_to_use = 0;
617 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
619 /* Wait until the packets get transmitted to the receive queue. */
620 usleep_range(1000, 2000);
621 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
626 #define ICE_LB_FRAME_SIZE 64
628 * ice_lbtest_receive_frames - receive and verify test frames
629 * @rx_ring: pointer to the receive ring
631 * Function receives loopback packets and verify their correctness.
632 * Returns number of received valid frames.
634 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
636 struct ice_rx_buf *rx_buf;
642 for (i = 0; i < rx_ring->count; i++) {
643 union ice_32b_rx_flex_desc *rx_desc;
645 rx_desc = ICE_RX_DESC(rx_ring, i);
647 if (!(rx_desc->wb.status_error0 &
648 cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)))
651 rx_buf = &rx_ring->rx_buf[i];
652 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
654 if (ice_lbtest_check_frame(received_buf))
662 * ice_loopback_test - perform a loopback test on a given net_device
663 * @netdev: network interface device structure
665 * This function performs one of the self-tests required by ethtool.
666 * Returns 0 on success, non-zero on failure.
668 static u64 ice_loopback_test(struct net_device *netdev)
670 struct ice_netdev_priv *np = netdev_priv(netdev);
671 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
672 struct ice_pf *pf = orig_vsi->back;
673 struct ice_ring *tx_ring, *rx_ring;
674 u8 broadcast[ETH_ALEN], ret = 0;
675 int num_frames, valid_frames;
681 dev = ice_pf_to_dev(pf);
682 netdev_info(netdev, "loopback test\n");
684 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
686 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
690 test_vsi->netdev = netdev;
691 tx_ring = test_vsi->tx_rings[0];
692 rx_ring = test_vsi->rx_rings[0];
694 if (ice_lbtest_prepare_rings(test_vsi)) {
696 goto lbtest_vsi_close;
699 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
701 goto lbtest_rings_dis;
704 /* Enable MAC loopback in firmware */
705 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
710 /* Test VSI needs to receive broadcast packets */
711 eth_broadcast_addr(broadcast);
712 if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) {
717 if (ice_add_mac(&pf->hw, &tmp_list)) {
722 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
724 goto remove_mac_filters;
727 num_frames = min_t(int, tx_ring->count, 32);
728 for (i = 0; i < num_frames; i++) {
729 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
731 goto lbtest_free_frame;
735 valid_frames = ice_lbtest_receive_frames(rx_ring);
738 else if (valid_frames != num_frames)
742 devm_kfree(dev, tx_frame);
744 if (ice_remove_mac(&pf->hw, &tmp_list))
745 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
747 ice_free_fltr_list(dev, &tmp_list);
749 /* Disable MAC loopback after the test is completed. */
750 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
751 netdev_err(netdev, "Could not disable MAC loopback\n");
753 if (ice_lbtest_disable_rings(test_vsi))
754 netdev_err(netdev, "Could not disable test rings\n");
756 test_vsi->netdev = NULL;
757 if (ice_vsi_release(test_vsi))
758 netdev_err(netdev, "Failed to remove the test VSI\n");
764 * ice_intr_test - perform an interrupt test on a given net_device
765 * @netdev: network interface device structure
767 * This function performs one of the self-tests required by ethtool.
768 * Returns 0 on success, non-zero on failure.
770 static u64 ice_intr_test(struct net_device *netdev)
772 struct ice_netdev_priv *np = netdev_priv(netdev);
773 struct ice_pf *pf = np->vsi->back;
774 u16 swic_old = pf->sw_int_count;
776 netdev_info(netdev, "interrupt test\n");
778 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
779 GLINT_DYN_CTL_SW_ITR_INDX_M |
780 GLINT_DYN_CTL_INTENA_MSK_M |
781 GLINT_DYN_CTL_SWINT_TRIG_M);
783 usleep_range(1000, 2000);
784 return (swic_old == pf->sw_int_count);
788 * ice_self_test - handler function for performing a self-test by ethtool
789 * @netdev: network interface device structure
790 * @eth_test: ethtool_test structure
791 * @data: required by ethtool.self_test
793 * This function is called after invoking 'ethtool -t devname' command where
794 * devname is the name of the network device on which ethtool should operate.
795 * It performs a set of self-tests to check if a device works properly.
798 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
801 struct ice_netdev_priv *np = netdev_priv(netdev);
802 bool if_running = netif_running(netdev);
803 struct ice_pf *pf = np->vsi->back;
806 dev = ice_pf_to_dev(pf);
808 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
809 netdev_info(netdev, "offline testing starting\n");
811 set_bit(__ICE_TESTING, pf->state);
813 if (ice_active_vfs(pf)) {
814 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
815 data[ICE_ETH_TEST_REG] = 1;
816 data[ICE_ETH_TEST_EEPROM] = 1;
817 data[ICE_ETH_TEST_INTR] = 1;
818 data[ICE_ETH_TEST_LOOP] = 1;
819 data[ICE_ETH_TEST_LINK] = 1;
820 eth_test->flags |= ETH_TEST_FL_FAILED;
821 clear_bit(__ICE_TESTING, pf->state);
824 /* If the device is online then take it offline */
826 /* indicate we're in test mode */
829 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
830 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
831 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
832 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
833 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
835 if (data[ICE_ETH_TEST_LINK] ||
836 data[ICE_ETH_TEST_EEPROM] ||
837 data[ICE_ETH_TEST_LOOP] ||
838 data[ICE_ETH_TEST_INTR] ||
839 data[ICE_ETH_TEST_REG])
840 eth_test->flags |= ETH_TEST_FL_FAILED;
842 clear_bit(__ICE_TESTING, pf->state);
845 int status = ice_open(netdev);
848 dev_err(dev, "Could not open device %s, err %d\n",
849 pf->int_name, status);
854 netdev_info(netdev, "online testing starting\n");
856 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
857 if (data[ICE_ETH_TEST_LINK])
858 eth_test->flags |= ETH_TEST_FL_FAILED;
860 /* Offline only tests, not run in online; pass by default */
861 data[ICE_ETH_TEST_REG] = 0;
862 data[ICE_ETH_TEST_EEPROM] = 0;
863 data[ICE_ETH_TEST_INTR] = 0;
864 data[ICE_ETH_TEST_LOOP] = 0;
868 netdev_info(netdev, "testing finished\n");
871 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
873 struct ice_netdev_priv *np = netdev_priv(netdev);
874 struct ice_vsi *vsi = np->vsi;
875 char *p = (char *)data;
880 for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
881 snprintf(p, ETH_GSTRING_LEN, "%s",
882 ice_gstrings_vsi_stats[i].stat_string);
883 p += ETH_GSTRING_LEN;
886 ice_for_each_alloc_txq(vsi, i) {
887 snprintf(p, ETH_GSTRING_LEN,
888 "tx_queue_%u_packets", i);
889 p += ETH_GSTRING_LEN;
890 snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
891 p += ETH_GSTRING_LEN;
894 ice_for_each_alloc_rxq(vsi, i) {
895 snprintf(p, ETH_GSTRING_LEN,
896 "rx_queue_%u_packets", i);
897 p += ETH_GSTRING_LEN;
898 snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
899 p += ETH_GSTRING_LEN;
902 if (vsi->type != ICE_VSI_PF)
905 for (i = 0; i < ICE_PF_STATS_LEN; i++) {
906 snprintf(p, ETH_GSTRING_LEN, "%s",
907 ice_gstrings_pf_stats[i].stat_string);
908 p += ETH_GSTRING_LEN;
911 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
912 snprintf(p, ETH_GSTRING_LEN,
913 "tx_priority_%u_xon.nic", i);
914 p += ETH_GSTRING_LEN;
915 snprintf(p, ETH_GSTRING_LEN,
916 "tx_priority_%u_xoff.nic", i);
917 p += ETH_GSTRING_LEN;
919 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
920 snprintf(p, ETH_GSTRING_LEN,
921 "rx_priority_%u_xon.nic", i);
922 p += ETH_GSTRING_LEN;
923 snprintf(p, ETH_GSTRING_LEN,
924 "rx_priority_%u_xoff.nic", i);
925 p += ETH_GSTRING_LEN;
929 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
931 case ETH_SS_PRIV_FLAGS:
932 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
933 snprintf(p, ETH_GSTRING_LEN, "%s",
934 ice_gstrings_priv_flags[i].name);
935 p += ETH_GSTRING_LEN;
944 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
946 struct ice_netdev_priv *np = netdev_priv(netdev);
950 case ETHTOOL_ID_ACTIVE:
953 case ETHTOOL_ID_INACTIVE:
960 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
967 * ice_set_fec_cfg - Set link FEC options
968 * @netdev: network interface device structure
969 * @req_fec: FEC mode to configure
971 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
973 struct ice_netdev_priv *np = netdev_priv(netdev);
974 struct ice_aqc_set_phy_cfg_data config = { 0 };
975 struct ice_aqc_get_phy_caps_data *caps;
976 struct ice_vsi *vsi = np->vsi;
977 u8 sw_cfg_caps, sw_cfg_fec;
978 struct ice_port_info *pi;
979 enum ice_status status;
986 /* Changing the FEC parameters is not supported if not the PF VSI */
987 if (vsi->type != ICE_VSI_PF) {
988 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
992 /* Get last SW configuration */
993 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
997 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
1004 /* Copy SW configuration returned from PHY caps to PHY config */
1005 ice_copy_phy_caps_to_cfg(caps, &config);
1006 sw_cfg_caps = caps->caps;
1007 sw_cfg_fec = caps->link_fec_options;
1009 /* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
1010 memset(caps, 0, sizeof(*caps));
1012 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1019 config.caps |= (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
1020 config.link_fec_opt = caps->link_fec_options;
1022 ice_cfg_phy_fec(&config, req_fec);
1024 /* If FEC mode has changed, then set PHY configuration and enable AN. */
1025 if ((config.caps & ICE_AQ_PHY_ENA_AUTO_FEC) !=
1026 (sw_cfg_caps & ICE_AQC_PHY_EN_AUTO_FEC) ||
1027 config.link_fec_opt != sw_cfg_fec) {
1028 if (caps->caps & ICE_AQC_PHY_AN_MODE)
1029 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1031 status = ice_aq_set_phy_cfg(pi->hw, pi->lport, &config, NULL);
1043 * ice_set_fecparam - Set FEC link options
1044 * @netdev: network interface device structure
1045 * @fecparam: Ethtool structure to retrieve FEC parameters
1048 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1050 struct ice_netdev_priv *np = netdev_priv(netdev);
1051 struct ice_vsi *vsi = np->vsi;
1052 enum ice_fec_mode fec;
1054 switch (fecparam->fec) {
1055 case ETHTOOL_FEC_AUTO:
1058 case ETHTOOL_FEC_RS:
1061 case ETHTOOL_FEC_BASER:
1062 fec = ICE_FEC_BASER;
1064 case ETHTOOL_FEC_OFF:
1065 case ETHTOOL_FEC_NONE:
1069 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1074 return ice_set_fec_cfg(netdev, fec);
1078 * ice_get_fecparam - Get link FEC options
1079 * @netdev: network interface device structure
1080 * @fecparam: Ethtool structure to retrieve FEC parameters
1083 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1085 struct ice_netdev_priv *np = netdev_priv(netdev);
1086 struct ice_aqc_get_phy_caps_data *caps;
1087 struct ice_link_status *link_info;
1088 struct ice_vsi *vsi = np->vsi;
1089 struct ice_port_info *pi;
1090 enum ice_status status;
1093 pi = vsi->port_info;
1097 link_info = &pi->phy.link_info;
1099 /* Set FEC mode based on negotiated link info */
1100 switch (link_info->fec_info) {
1101 case ICE_AQ_LINK_25G_KR_FEC_EN:
1102 fecparam->active_fec = ETHTOOL_FEC_BASER;
1104 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1105 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1106 fecparam->active_fec = ETHTOOL_FEC_RS;
1109 fecparam->active_fec = ETHTOOL_FEC_OFF;
1113 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1117 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1124 /* Set supported/configured FEC modes based on PHY capability */
1125 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1126 fecparam->fec |= ETHTOOL_FEC_AUTO;
1127 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1128 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1129 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1130 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1131 fecparam->fec |= ETHTOOL_FEC_BASER;
1132 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1133 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1134 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1135 fecparam->fec |= ETHTOOL_FEC_RS;
1136 if (caps->link_fec_options == 0)
1137 fecparam->fec |= ETHTOOL_FEC_OFF;
1145 * ice_nway_reset - restart autonegotiation
1146 * @netdev: network interface device structure
1148 static int ice_nway_reset(struct net_device *netdev)
1150 struct ice_netdev_priv *np = netdev_priv(netdev);
1151 struct ice_vsi *vsi = np->vsi;
1152 struct ice_port_info *pi;
1153 enum ice_status status;
1155 pi = vsi->port_info;
1156 /* If VSI state is up, then restart autoneg with link up */
1157 if (!test_bit(__ICE_DOWN, vsi->back->state))
1158 status = ice_aq_set_link_restart_an(pi, true, NULL);
1160 status = ice_aq_set_link_restart_an(pi, false, NULL);
1163 netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
1164 status, pi->hw->adminq.sq_last_status);
1172 * ice_get_priv_flags - report device private flags
1173 * @netdev: network interface device structure
1175 * The get string set count and the string set should be matched for each
1176 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1179 * Returns a u32 bitmap of flags.
1181 static u32 ice_get_priv_flags(struct net_device *netdev)
1183 struct ice_netdev_priv *np = netdev_priv(netdev);
1184 struct ice_vsi *vsi = np->vsi;
1185 struct ice_pf *pf = vsi->back;
1186 u32 i, ret_flags = 0;
1188 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1189 const struct ice_priv_flag *priv_flag;
1191 priv_flag = &ice_gstrings_priv_flags[i];
1193 if (test_bit(priv_flag->bitno, pf->flags))
1194 ret_flags |= BIT(i);
1201 * ice_set_priv_flags - set private flags
1202 * @netdev: network interface device structure
1203 * @flags: bit flags to be set
1205 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1207 struct ice_netdev_priv *np = netdev_priv(netdev);
1208 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1209 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1210 struct ice_vsi *vsi = np->vsi;
1211 struct ice_pf *pf = vsi->back;
1216 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1219 dev = ice_pf_to_dev(pf);
1220 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1222 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1223 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1224 const struct ice_priv_flag *priv_flag;
1226 priv_flag = &ice_gstrings_priv_flags[i];
1229 set_bit(priv_flag->bitno, pf->flags);
1231 clear_bit(priv_flag->bitno, pf->flags);
1234 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1236 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1237 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1238 enum ice_status status;
1240 /* Disable FW LLDP engine */
1241 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1243 /* If unregistering for LLDP events fails, this is
1244 * not an error state, as there shouldn't be any
1245 * events to respond to.
1248 dev_info(dev, "Failed to unreg for LLDP events\n");
1250 /* The AQ call to stop the FW LLDP agent will generate
1251 * an error if the agent is already stopped.
1253 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1255 dev_warn(dev, "Fail to stop LLDP agent\n");
1256 /* Use case for having the FW LLDP agent stopped
1257 * will likely not need DCB, so failure to init is
1258 * not a concern of ethtool
1260 status = ice_init_pf_dcb(pf, true);
1262 dev_warn(dev, "Fail to init DCB\n");
1264 enum ice_status status;
1265 bool dcbx_agent_status;
1267 /* AQ command to start FW LLDP agent will return an
1268 * error if the agent is already started
1270 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1272 dev_warn(dev, "Fail to start LLDP Agent\n");
1274 /* AQ command to start FW DCBX agent will fail if
1275 * the agent is already started
1277 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1281 dev_dbg(dev, "Failed to start FW DCBX\n");
1283 dev_info(dev, "FW DCBX agent is %s\n",
1284 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1286 /* Failure to configure MIB change or init DCB is not
1287 * relevant to ethtool. Print notification that
1288 * registration/init failed but do not return error
1291 status = ice_init_pf_dcb(pf, true);
1293 dev_dbg(dev, "Fail to init DCB\n");
1295 /* Remove rule to direct LLDP packets to default VSI.
1296 * The FW LLDP engine will now be consuming them.
1298 ice_cfg_sw_lldp(vsi, false, false);
1300 /* Register for MIB change events */
1301 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1303 dev_dbg(dev, "Fail to enable MIB change events\n");
1305 ice_nway_reset(netdev);
1308 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1309 /* down and up VSI so that changes of Rx cfg are reflected. */
1313 /* don't allow modification of this flag when a single VF is in
1314 * promiscuous mode because it's not supported
1316 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1317 ice_is_any_vf_in_promisc(pf)) {
1318 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1319 /* toggle bit back to previous state */
1320 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1323 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1327 static int ice_get_sset_count(struct net_device *netdev, int sset)
1331 /* The number (and order) of strings reported *must* remain
1332 * constant for a given netdevice. This function must not
1333 * report a different number based on run time parameters
1334 * (such as the number of queues in use, or the setting of
1335 * a private ethtool flag). This is due to the nature of the
1336 * ethtool stats API.
1338 * Userspace programs such as ethtool must make 3 separate
1339 * ioctl requests, one for size, one for the strings, and
1340 * finally one for the stats. Since these cross into
1341 * userspace, changes to the number or size could result in
1342 * undefined memory access or incorrect string<->value
1343 * correlations for statistics.
1345 * Even if it appears to be safe, changes to the size or
1346 * order of strings will suffer from race conditions and are
1349 return ICE_ALL_STATS_LEN(netdev);
1351 return ICE_TEST_LEN;
1352 case ETH_SS_PRIV_FLAGS:
1353 return ICE_PRIV_FLAG_ARRAY_SIZE;
1360 ice_get_ethtool_stats(struct net_device *netdev,
1361 struct ethtool_stats __always_unused *stats, u64 *data)
1363 struct ice_netdev_priv *np = netdev_priv(netdev);
1364 struct ice_vsi *vsi = np->vsi;
1365 struct ice_pf *pf = vsi->back;
1366 struct ice_ring *ring;
1371 ice_update_pf_stats(pf);
1372 ice_update_vsi_stats(vsi);
1374 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1375 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1376 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1377 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1380 /* populate per queue stats */
1383 ice_for_each_alloc_txq(vsi, j) {
1384 ring = READ_ONCE(vsi->tx_rings[j]);
1386 data[i++] = ring->stats.pkts;
1387 data[i++] = ring->stats.bytes;
1394 ice_for_each_alloc_rxq(vsi, j) {
1395 ring = READ_ONCE(vsi->rx_rings[j]);
1397 data[i++] = ring->stats.pkts;
1398 data[i++] = ring->stats.bytes;
1407 if (vsi->type != ICE_VSI_PF)
1410 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1411 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1412 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1413 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1416 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1417 data[i++] = pf->stats.priority_xon_tx[j];
1418 data[i++] = pf->stats.priority_xoff_tx[j];
1421 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1422 data[i++] = pf->stats.priority_xon_rx[j];
1423 data[i++] = pf->stats.priority_xoff_rx[j];
1428 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1429 * @netdev: network interface device structure
1430 * @ks: ethtool link ksettings struct to fill out
1433 ice_phy_type_to_ethtool(struct net_device *netdev,
1434 struct ethtool_link_ksettings *ks)
1436 struct ice_netdev_priv *np = netdev_priv(netdev);
1437 struct ice_link_status *hw_link_info;
1438 bool need_add_adv_mode = false;
1439 struct ice_vsi *vsi = np->vsi;
1443 hw_link_info = &vsi->port_info->phy.link_info;
1444 phy_types_low = vsi->port_info->phy.phy_type_low;
1445 phy_types_high = vsi->port_info->phy.phy_type_high;
1447 ethtool_link_ksettings_zero_link_mode(ks, supported);
1448 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1450 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1451 phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
1452 ethtool_link_ksettings_add_link_mode(ks, supported,
1454 if (!hw_link_info->req_speeds ||
1455 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
1456 ethtool_link_ksettings_add_link_mode(ks, advertising,
1459 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1460 phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
1461 ethtool_link_ksettings_add_link_mode(ks, supported,
1463 if (!hw_link_info->req_speeds ||
1464 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1465 ethtool_link_ksettings_add_link_mode(ks, advertising,
1468 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
1469 ethtool_link_ksettings_add_link_mode(ks, supported,
1471 if (!hw_link_info->req_speeds ||
1472 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1473 ethtool_link_ksettings_add_link_mode(ks, advertising,
1476 if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
1477 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
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_1000MB)
1482 ethtool_link_ksettings_add_link_mode(ks, advertising,
1485 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
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_2500MB)
1490 ethtool_link_ksettings_add_link_mode(ks, advertising,
1493 if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
1494 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
1495 ethtool_link_ksettings_add_link_mode(ks, supported,
1497 if (!hw_link_info->req_speeds ||
1498 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1499 ethtool_link_ksettings_add_link_mode(ks, advertising,
1502 if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1503 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
1504 ethtool_link_ksettings_add_link_mode(ks, supported,
1506 if (!hw_link_info->req_speeds ||
1507 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
1508 ethtool_link_ksettings_add_link_mode(ks, advertising,
1511 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1512 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
1513 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
1514 phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
1515 ethtool_link_ksettings_add_link_mode(ks, supported,
1517 if (!hw_link_info->req_speeds ||
1518 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1519 ethtool_link_ksettings_add_link_mode(ks, advertising,
1522 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
1523 ethtool_link_ksettings_add_link_mode(ks, supported,
1525 if (!hw_link_info->req_speeds ||
1526 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1527 ethtool_link_ksettings_add_link_mode(ks, advertising,
1530 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
1531 ethtool_link_ksettings_add_link_mode(ks, supported,
1533 if (!hw_link_info->req_speeds ||
1534 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1535 ethtool_link_ksettings_add_link_mode(ks, advertising,
1538 if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
1539 ethtool_link_ksettings_add_link_mode(ks, supported,
1541 if (!hw_link_info->req_speeds ||
1542 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1543 ethtool_link_ksettings_add_link_mode(ks, advertising,
1546 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1547 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1548 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1549 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1550 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
1551 phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
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_25GB)
1556 ethtool_link_ksettings_add_link_mode(ks, advertising,
1559 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
1560 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
1561 ethtool_link_ksettings_add_link_mode(ks, supported,
1563 if (!hw_link_info->req_speeds ||
1564 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1565 ethtool_link_ksettings_add_link_mode(ks, advertising,
1568 if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1569 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1570 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
1571 ethtool_link_ksettings_add_link_mode(ks, supported,
1573 if (!hw_link_info->req_speeds ||
1574 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1575 ethtool_link_ksettings_add_link_mode(ks, advertising,
1578 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1579 ethtool_link_ksettings_add_link_mode(ks, supported,
1581 if (!hw_link_info->req_speeds ||
1582 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1583 ethtool_link_ksettings_add_link_mode(ks, advertising,
1586 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1587 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
1588 phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
1589 ethtool_link_ksettings_add_link_mode(ks, supported,
1591 if (!hw_link_info->req_speeds ||
1592 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1593 ethtool_link_ksettings_add_link_mode(ks, advertising,
1596 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
1597 ethtool_link_ksettings_add_link_mode(ks, supported,
1599 if (!hw_link_info->req_speeds ||
1600 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1601 ethtool_link_ksettings_add_link_mode(ks, advertising,
1604 if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
1605 ethtool_link_ksettings_add_link_mode(ks, supported,
1607 if (!hw_link_info->req_speeds ||
1608 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1609 ethtool_link_ksettings_add_link_mode(ks, advertising,
1612 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1613 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC ||
1614 phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 ||
1615 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC ||
1616 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 ||
1617 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1618 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR ||
1619 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC ||
1620 phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) {
1621 ethtool_link_ksettings_add_link_mode(ks, supported,
1623 if (!hw_link_info->req_speeds ||
1624 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1625 ethtool_link_ksettings_add_link_mode(ks, advertising,
1628 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1629 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1630 ethtool_link_ksettings_add_link_mode(ks, supported,
1632 if (!hw_link_info->req_speeds ||
1633 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1634 ethtool_link_ksettings_add_link_mode(ks, advertising,
1637 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 ||
1638 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 ||
1639 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR ||
1640 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) {
1641 ethtool_link_ksettings_add_link_mode(ks, supported,
1643 if (!hw_link_info->req_speeds ||
1644 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1645 ethtool_link_ksettings_add_link_mode(ks, advertising,
1648 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1649 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC ||
1650 phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 ||
1651 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC ||
1652 phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 ||
1653 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 ||
1654 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2 ||
1655 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC ||
1656 phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 ||
1657 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC ||
1658 phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) {
1659 ethtool_link_ksettings_add_link_mode(ks, supported,
1660 100000baseCR4_Full);
1661 if (!hw_link_info->req_speeds ||
1662 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1663 need_add_adv_mode = true;
1665 if (need_add_adv_mode) {
1666 need_add_adv_mode = false;
1667 ethtool_link_ksettings_add_link_mode(ks, advertising,
1668 100000baseCR4_Full);
1670 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 ||
1671 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) {
1672 ethtool_link_ksettings_add_link_mode(ks, supported,
1673 100000baseSR4_Full);
1674 if (!hw_link_info->req_speeds ||
1675 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1676 need_add_adv_mode = true;
1678 if (need_add_adv_mode) {
1679 need_add_adv_mode = false;
1680 ethtool_link_ksettings_add_link_mode(ks, advertising,
1681 100000baseSR4_Full);
1683 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 ||
1684 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) {
1685 ethtool_link_ksettings_add_link_mode(ks, supported,
1686 100000baseLR4_ER4_Full);
1687 if (!hw_link_info->req_speeds ||
1688 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1689 need_add_adv_mode = true;
1691 if (need_add_adv_mode) {
1692 need_add_adv_mode = false;
1693 ethtool_link_ksettings_add_link_mode(ks, advertising,
1694 100000baseLR4_ER4_Full);
1696 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1697 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1698 phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) {
1699 ethtool_link_ksettings_add_link_mode(ks, supported,
1700 100000baseKR4_Full);
1701 if (!hw_link_info->req_speeds ||
1702 hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1703 need_add_adv_mode = true;
1705 if (need_add_adv_mode)
1706 ethtool_link_ksettings_add_link_mode(ks, advertising,
1707 100000baseKR4_Full);
1709 /* Autoneg PHY types */
1710 if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1711 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1712 phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
1713 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
1714 phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
1715 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1716 phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
1717 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1718 phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
1719 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1720 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1721 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1722 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1723 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1724 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1725 phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
1726 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1727 phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1728 ethtool_link_ksettings_add_link_mode(ks, supported,
1730 ethtool_link_ksettings_add_link_mode(ks, advertising,
1733 if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1734 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1735 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1736 phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1737 ethtool_link_ksettings_add_link_mode(ks, supported,
1739 ethtool_link_ksettings_add_link_mode(ks, advertising,
1742 if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1743 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1744 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1745 phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) {
1746 ethtool_link_ksettings_add_link_mode(ks, supported,
1748 ethtool_link_ksettings_add_link_mode(ks, advertising,
1753 #define TEST_SET_BITS_TIMEOUT 50
1754 #define TEST_SET_BITS_SLEEP_MAX 2000
1755 #define TEST_SET_BITS_SLEEP_MIN 1000
1758 * ice_get_settings_link_up - Get Link settings for when link is up
1759 * @ks: ethtool ksettings to fill in
1760 * @netdev: network interface device structure
1763 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1764 struct net_device *netdev)
1766 struct ice_netdev_priv *np = netdev_priv(netdev);
1767 struct ice_port_info *pi = np->vsi->port_info;
1768 struct ice_link_status *link_info;
1769 struct ice_vsi *vsi = np->vsi;
1771 link_info = &vsi->port_info->phy.link_info;
1773 /* Get supported and advertised settings from PHY ability with media */
1774 ice_phy_type_to_ethtool(netdev, ks);
1776 switch (link_info->link_speed) {
1777 case ICE_AQ_LINK_SPEED_100GB:
1778 ks->base.speed = SPEED_100000;
1780 case ICE_AQ_LINK_SPEED_50GB:
1781 ks->base.speed = SPEED_50000;
1783 case ICE_AQ_LINK_SPEED_40GB:
1784 ks->base.speed = SPEED_40000;
1786 case ICE_AQ_LINK_SPEED_25GB:
1787 ks->base.speed = SPEED_25000;
1789 case ICE_AQ_LINK_SPEED_20GB:
1790 ks->base.speed = SPEED_20000;
1792 case ICE_AQ_LINK_SPEED_10GB:
1793 ks->base.speed = SPEED_10000;
1795 case ICE_AQ_LINK_SPEED_5GB:
1796 ks->base.speed = SPEED_5000;
1798 case ICE_AQ_LINK_SPEED_2500MB:
1799 ks->base.speed = SPEED_2500;
1801 case ICE_AQ_LINK_SPEED_1000MB:
1802 ks->base.speed = SPEED_1000;
1804 case ICE_AQ_LINK_SPEED_100MB:
1805 ks->base.speed = SPEED_100;
1808 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1809 link_info->link_speed);
1812 ks->base.duplex = DUPLEX_FULL;
1814 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1815 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1818 /* Set flow control negotiated Rx/Tx pause */
1819 switch (pi->fc.current_mode) {
1821 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1823 case ICE_FC_TX_PAUSE:
1824 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1825 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1828 case ICE_FC_RX_PAUSE:
1829 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1834 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1835 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1842 * ice_get_settings_link_down - Get the Link settings when link is down
1843 * @ks: ethtool ksettings to fill in
1844 * @netdev: network interface device structure
1846 * Reports link settings that can be determined when link is down
1849 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1850 struct net_device *netdev)
1852 /* link is down and the driver needs to fall back on
1853 * supported PHY types to figure out what info to display
1855 ice_phy_type_to_ethtool(netdev, ks);
1857 /* With no link, speed and duplex are unknown */
1858 ks->base.speed = SPEED_UNKNOWN;
1859 ks->base.duplex = DUPLEX_UNKNOWN;
1863 * ice_get_link_ksettings - Get Link Speed and Duplex settings
1864 * @netdev: network interface device structure
1865 * @ks: ethtool ksettings
1867 * Reports speed/duplex settings based on media_type
1870 ice_get_link_ksettings(struct net_device *netdev,
1871 struct ethtool_link_ksettings *ks)
1873 struct ice_netdev_priv *np = netdev_priv(netdev);
1874 struct ice_aqc_get_phy_caps_data *caps;
1875 struct ice_link_status *hw_link_info;
1876 struct ice_vsi *vsi = np->vsi;
1877 enum ice_status status;
1880 ethtool_link_ksettings_zero_link_mode(ks, supported);
1881 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1882 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1883 hw_link_info = &vsi->port_info->phy.link_info;
1885 /* set speed and duplex */
1886 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1887 ice_get_settings_link_up(ks, netdev);
1889 ice_get_settings_link_down(ks, netdev);
1891 /* set autoneg settings */
1892 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1893 AUTONEG_ENABLE : AUTONEG_DISABLE;
1895 /* set media type settings */
1896 switch (vsi->port_info->phy.media_type) {
1897 case ICE_MEDIA_FIBER:
1898 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1899 ks->base.port = PORT_FIBRE;
1901 case ICE_MEDIA_BASET:
1902 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1903 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1904 ks->base.port = PORT_TP;
1906 case ICE_MEDIA_BACKPLANE:
1907 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1908 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1909 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1910 ethtool_link_ksettings_add_link_mode(ks, advertising,
1912 ks->base.port = PORT_NONE;
1915 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1916 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1917 ks->base.port = PORT_DA;
1920 ks->base.port = PORT_OTHER;
1924 /* flow control is symmetric and always supported */
1925 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1927 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1931 status = ice_aq_get_phy_caps(vsi->port_info, false,
1932 ICE_AQC_REPORT_SW_CFG, caps, NULL);
1938 /* Set the advertised flow control based on the PHY capability */
1939 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
1940 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
1941 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1942 ethtool_link_ksettings_add_link_mode(ks, advertising,
1944 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
1945 ethtool_link_ksettings_add_link_mode(ks, advertising,
1947 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
1948 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1949 ethtool_link_ksettings_add_link_mode(ks, advertising,
1952 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
1953 ethtool_link_ksettings_del_link_mode(ks, advertising,
1957 /* Set advertised FEC modes based on PHY capability */
1958 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
1960 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1961 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1962 ethtool_link_ksettings_add_link_mode(ks, advertising,
1964 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1965 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
1966 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
1968 status = ice_aq_get_phy_caps(vsi->port_info, false,
1969 ICE_AQC_REPORT_TOPO_CAP, caps, NULL);
1975 /* Set supported FEC modes based on PHY capability */
1976 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
1978 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1979 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
1980 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
1981 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1982 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
1990 * ice_ksettings_find_adv_link_speed - Find advertising link speed
1991 * @ks: ethtool ksettings
1994 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
1996 u16 adv_link_speed = 0;
1998 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2000 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2001 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2003 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2004 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2006 ethtool_link_ksettings_test_link_mode(ks, advertising,
2008 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2009 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2011 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2012 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2014 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2015 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2017 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2018 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2020 ethtool_link_ksettings_test_link_mode(ks, advertising,
2022 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2023 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2024 10000baseSR_Full) ||
2025 ethtool_link_ksettings_test_link_mode(ks, advertising,
2027 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2028 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2029 25000baseCR_Full) ||
2030 ethtool_link_ksettings_test_link_mode(ks, advertising,
2031 25000baseSR_Full) ||
2032 ethtool_link_ksettings_test_link_mode(ks, advertising,
2034 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2035 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2036 40000baseCR4_Full) ||
2037 ethtool_link_ksettings_test_link_mode(ks, advertising,
2038 40000baseSR4_Full) ||
2039 ethtool_link_ksettings_test_link_mode(ks, advertising,
2040 40000baseLR4_Full) ||
2041 ethtool_link_ksettings_test_link_mode(ks, advertising,
2043 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2044 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2045 50000baseCR2_Full) ||
2046 ethtool_link_ksettings_test_link_mode(ks, advertising,
2048 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2049 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2051 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2052 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2053 100000baseCR4_Full) ||
2054 ethtool_link_ksettings_test_link_mode(ks, advertising,
2055 100000baseSR4_Full) ||
2056 ethtool_link_ksettings_test_link_mode(ks, advertising,
2057 100000baseLR4_ER4_Full) ||
2058 ethtool_link_ksettings_test_link_mode(ks, advertising,
2059 100000baseKR4_Full))
2060 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2062 return adv_link_speed;
2068 * @ks: ethtool_link_ksettings
2069 * @config: configuration that will be sent down to FW
2070 * @autoneg_enabled: autonegotiation is enabled or not
2071 * @autoneg_changed: will there a change in autonegotiation
2072 * @netdev: network interface device structure
2074 * Setup PHY autonegotiation feature
2077 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2078 struct ice_aqc_set_phy_cfg_data *config,
2079 u8 autoneg_enabled, u8 *autoneg_changed,
2080 struct net_device *netdev)
2084 *autoneg_changed = 0;
2087 if (autoneg_enabled == AUTONEG_ENABLE) {
2088 /* If autoneg was not already enabled */
2089 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2090 /* If autoneg is not supported, return error */
2091 if (!ethtool_link_ksettings_test_link_mode(ks,
2094 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2097 /* Autoneg is allowed to change */
2098 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2099 *autoneg_changed = 1;
2103 /* If autoneg is currently enabled */
2104 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2105 /* If autoneg is supported 10GBASE_T is the only PHY
2106 * that can disable it, so otherwise return error
2108 if (ethtool_link_ksettings_test_link_mode(ks,
2111 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2114 /* Autoneg is allowed to change */
2115 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2116 *autoneg_changed = 1;
2125 * ice_set_link_ksettings - Set Speed and Duplex
2126 * @netdev: network interface device structure
2127 * @ks: ethtool ksettings
2129 * Set speed/duplex per media_types advertised/forced
2132 ice_set_link_ksettings(struct net_device *netdev,
2133 const struct ethtool_link_ksettings *ks)
2135 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
2136 struct ice_netdev_priv *np = netdev_priv(netdev);
2137 struct ethtool_link_ksettings safe_ks, copy_ks;
2138 struct ice_aqc_get_phy_caps_data *abilities;
2139 u16 adv_link_speed, curr_link_speed, idx;
2140 struct ice_aqc_set_phy_cfg_data config;
2141 struct ice_pf *pf = np->vsi->back;
2142 struct ice_port_info *p;
2143 u8 autoneg_changed = 0;
2144 enum ice_status status;
2150 p = np->vsi->port_info;
2155 /* Check if this is LAN VSI */
2156 ice_for_each_vsi(pf, idx)
2157 if (pf->vsi[idx]->type == ICE_VSI_PF) {
2158 if (np->vsi != pf->vsi[idx])
2163 if (p->phy.media_type != ICE_MEDIA_BASET &&
2164 p->phy.media_type != ICE_MEDIA_FIBER &&
2165 p->phy.media_type != ICE_MEDIA_BACKPLANE &&
2166 p->phy.media_type != ICE_MEDIA_DA &&
2167 p->phy.link_info.link_info & ICE_AQ_LINK_UP)
2170 /* copy the ksettings to copy_ks to avoid modifying the original */
2171 memcpy(©_ks, ks, sizeof(copy_ks));
2173 /* save autoneg out of ksettings */
2174 autoneg = copy_ks.base.autoneg;
2176 memset(&safe_ks, 0, sizeof(safe_ks));
2178 /* Get link modes supported by hardware.*/
2179 ice_phy_type_to_ethtool(netdev, &safe_ks);
2181 /* and check against modes requested by user.
2182 * Return an error if unsupported mode was set.
2184 if (!bitmap_subset(copy_ks.link_modes.advertising,
2185 safe_ks.link_modes.supported,
2186 __ETHTOOL_LINK_MODE_MASK_NBITS))
2189 /* get our own copy of the bits to check against */
2190 memset(&safe_ks, 0, sizeof(safe_ks));
2191 safe_ks.base.cmd = copy_ks.base.cmd;
2192 safe_ks.base.link_mode_masks_nwords =
2193 copy_ks.base.link_mode_masks_nwords;
2194 ice_get_link_ksettings(netdev, &safe_ks);
2196 /* set autoneg back to what it currently is */
2197 copy_ks.base.autoneg = safe_ks.base.autoneg;
2198 /* we don't compare the speed */
2199 copy_ks.base.speed = safe_ks.base.speed;
2201 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2202 * trying to set something that we do not support.
2204 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base)))
2207 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2211 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2214 abilities = kzalloc(sizeof(*abilities), GFP_KERNEL);
2218 /* Get the current PHY config */
2219 status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
2226 /* Copy abilities to config in case autoneg is not set below */
2227 memset(&config, 0, sizeof(config));
2228 config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
2229 if (abilities->caps & ICE_AQC_PHY_AN_MODE)
2230 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2233 err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
2239 /* Call to get the current link speed */
2240 p->phy.get_link_info = true;
2241 status = ice_get_link_status(p, &linkup);
2247 curr_link_speed = p->phy.link_info.link_speed;
2248 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2250 /* If speed didn't get set, set it to what it currently is.
2251 * This is needed because if advertise is 0 (as it is when autoneg
2252 * is disabled) then speed won't get set.
2254 if (!adv_link_speed)
2255 adv_link_speed = curr_link_speed;
2257 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2258 ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed);
2260 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2261 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2265 /* copy over the rest of the abilities */
2266 config.low_power_ctrl = abilities->low_power_ctrl;
2267 config.eee_cap = abilities->eee_cap;
2268 config.eeer_value = abilities->eeer_value;
2269 config.link_fec_opt = abilities->link_fec_options;
2271 /* save the requested speeds */
2272 p->phy.link_info.req_speeds = adv_link_speed;
2274 /* set link and auto negotiation so changes take effect */
2275 config.caps |= ICE_AQ_PHY_ENA_LINK;
2277 if (phy_type_low || phy_type_high) {
2278 config.phy_type_high = cpu_to_le64(phy_type_high) &
2279 abilities->phy_type_high;
2280 config.phy_type_low = cpu_to_le64(phy_type_low) &
2281 abilities->phy_type_low;
2284 netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2288 /* If link is up put link down */
2289 if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2290 /* Tell the OS link is going down, the link will go
2291 * back up when fw says it is ready asynchronously
2293 ice_print_link_msg(np->vsi, false);
2294 netif_carrier_off(netdev);
2295 netif_tx_stop_all_queues(netdev);
2298 /* make the aq call */
2299 status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
2301 netdev_info(netdev, "Set phy config failed,\n");
2307 clear_bit(__ICE_CFG_BUSY, pf->state);
2313 * ice_parse_hdrs - parses headers from RSS hash input
2314 * @nfc: ethtool rxnfc command
2316 * This function parses the rxnfc command and returns intended
2317 * header types for RSS configuration
2319 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2321 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2323 switch (nfc->flow_type) {
2325 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2328 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2331 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2334 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2337 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2340 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2348 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2349 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2350 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2351 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2352 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2353 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2354 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2355 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2356 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2357 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2358 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2359 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2362 * ice_parse_hash_flds - parses hash fields from RSS hash input
2363 * @nfc: ethtool rxnfc command
2365 * This function parses the rxnfc command and returns intended
2366 * hash fields for RSS configuration
2368 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2370 u64 hfld = ICE_HASH_INVALID;
2372 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2373 switch (nfc->flow_type) {
2377 if (nfc->data & RXH_IP_SRC)
2378 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2379 if (nfc->data & RXH_IP_DST)
2380 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2385 if (nfc->data & RXH_IP_SRC)
2386 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2387 if (nfc->data & RXH_IP_DST)
2388 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2395 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2396 switch (nfc->flow_type) {
2399 if (nfc->data & RXH_L4_B_0_1)
2400 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2401 if (nfc->data & RXH_L4_B_2_3)
2402 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2406 if (nfc->data & RXH_L4_B_0_1)
2407 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2408 if (nfc->data & RXH_L4_B_2_3)
2409 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2413 if (nfc->data & RXH_L4_B_0_1)
2414 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2415 if (nfc->data & RXH_L4_B_2_3)
2416 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2427 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2428 * @vsi: the VSI being configured
2429 * @nfc: ethtool rxnfc command
2431 * Returns Success if the flow input set is supported.
2434 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2436 struct ice_pf *pf = vsi->back;
2437 enum ice_status status;
2442 dev = ice_pf_to_dev(pf);
2443 if (ice_is_safe_mode(pf)) {
2444 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2449 hashed_flds = ice_parse_hash_flds(nfc);
2450 if (hashed_flds == ICE_HASH_INVALID) {
2451 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2456 hdrs = ice_parse_hdrs(nfc);
2457 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2458 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2463 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2465 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
2466 vsi->vsi_num, status);
2474 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2475 * @vsi: the VSI being configured
2476 * @nfc: ethtool rxnfc command
2479 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2481 struct ice_pf *pf = vsi->back;
2486 dev = ice_pf_to_dev(pf);
2489 if (ice_is_safe_mode(pf)) {
2490 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2495 hdrs = ice_parse_hdrs(nfc);
2496 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2497 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2502 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2503 if (hash_flds == ICE_HASH_INVALID) {
2504 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2509 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2510 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2511 nfc->data |= (u64)RXH_IP_SRC;
2513 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2514 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2515 nfc->data |= (u64)RXH_IP_DST;
2517 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2518 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2519 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2520 nfc->data |= (u64)RXH_L4_B_0_1;
2522 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2523 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2524 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2525 nfc->data |= (u64)RXH_L4_B_2_3;
2529 * ice_set_rxnfc - command to set Rx flow rules.
2530 * @netdev: network interface device structure
2531 * @cmd: ethtool rxnfc command
2533 * Returns 0 for success and negative values for errors
2535 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2537 struct ice_netdev_priv *np = netdev_priv(netdev);
2538 struct ice_vsi *vsi = np->vsi;
2542 return ice_set_rss_hash_opt(vsi, cmd);
2550 * ice_get_rxnfc - command to get Rx flow classification rules
2551 * @netdev: network interface device structure
2552 * @cmd: ethtool rxnfc command
2553 * @rule_locs: buffer to rturn Rx flow classification rules
2555 * Returns Success if the command is supported.
2558 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2559 u32 __always_unused *rule_locs)
2561 struct ice_netdev_priv *np = netdev_priv(netdev);
2562 struct ice_vsi *vsi = np->vsi;
2563 int ret = -EOPNOTSUPP;
2566 case ETHTOOL_GRXRINGS:
2567 cmd->data = vsi->rss_size;
2571 ice_get_rss_hash_opt(vsi, cmd);
2582 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2584 struct ice_netdev_priv *np = netdev_priv(netdev);
2585 struct ice_vsi *vsi = np->vsi;
2587 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2588 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2589 ring->rx_pending = vsi->rx_rings[0]->count;
2590 ring->tx_pending = vsi->tx_rings[0]->count;
2592 /* Rx mini and jumbo rings are not supported */
2593 ring->rx_mini_max_pending = 0;
2594 ring->rx_jumbo_max_pending = 0;
2595 ring->rx_mini_pending = 0;
2596 ring->rx_jumbo_pending = 0;
2600 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2602 struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2603 struct ice_netdev_priv *np = netdev_priv(netdev);
2604 struct ice_ring *xdp_rings = NULL;
2605 struct ice_vsi *vsi = np->vsi;
2606 struct ice_pf *pf = vsi->back;
2607 int i, timeout = 50, err = 0;
2608 u32 new_rx_cnt, new_tx_cnt;
2610 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2611 ring->tx_pending < ICE_MIN_NUM_DESC ||
2612 ring->rx_pending > ICE_MAX_NUM_DESC ||
2613 ring->rx_pending < ICE_MIN_NUM_DESC) {
2614 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2615 ring->tx_pending, ring->rx_pending,
2616 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2617 ICE_REQ_DESC_MULTIPLE);
2621 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2622 if (new_tx_cnt != ring->tx_pending)
2623 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2625 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2626 if (new_rx_cnt != ring->rx_pending)
2627 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2630 /* if nothing to do return success */
2631 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2632 new_rx_cnt == vsi->rx_rings[0]->count) {
2633 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2637 /* If there is a AF_XDP UMEM attached to any of Rx rings,
2638 * disallow changing the number of descriptors -- regardless
2639 * if the netdev is running or not.
2641 if (ice_xsk_any_rx_ring_ena(vsi))
2644 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2648 usleep_range(1000, 2000);
2651 /* set for the next time the netdev is started */
2652 if (!netif_running(vsi->netdev)) {
2653 for (i = 0; i < vsi->alloc_txq; i++)
2654 vsi->tx_rings[i]->count = new_tx_cnt;
2655 for (i = 0; i < vsi->alloc_rxq; i++)
2656 vsi->rx_rings[i]->count = new_rx_cnt;
2657 if (ice_is_xdp_ena_vsi(vsi))
2658 for (i = 0; i < vsi->num_xdp_txq; i++)
2659 vsi->xdp_rings[i]->count = new_tx_cnt;
2660 vsi->num_tx_desc = new_tx_cnt;
2661 vsi->num_rx_desc = new_rx_cnt;
2662 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2666 if (new_tx_cnt == vsi->tx_rings[0]->count)
2669 /* alloc updated Tx resources */
2670 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2671 vsi->tx_rings[0]->count, new_tx_cnt);
2673 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2679 ice_for_each_txq(vsi, i) {
2680 /* clone ring and setup updated count */
2681 tx_rings[i] = *vsi->tx_rings[i];
2682 tx_rings[i].count = new_tx_cnt;
2683 tx_rings[i].desc = NULL;
2684 tx_rings[i].tx_buf = NULL;
2685 err = ice_setup_tx_ring(&tx_rings[i]);
2688 ice_clean_tx_ring(&tx_rings[i]);
2694 if (!ice_is_xdp_ena_vsi(vsi))
2697 /* alloc updated XDP resources */
2698 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2699 vsi->xdp_rings[0]->count, new_tx_cnt);
2701 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2707 for (i = 0; i < vsi->num_xdp_txq; i++) {
2708 /* clone ring and setup updated count */
2709 xdp_rings[i] = *vsi->xdp_rings[i];
2710 xdp_rings[i].count = new_tx_cnt;
2711 xdp_rings[i].desc = NULL;
2712 xdp_rings[i].tx_buf = NULL;
2713 err = ice_setup_tx_ring(&xdp_rings[i]);
2716 ice_clean_tx_ring(&xdp_rings[i]);
2720 ice_set_ring_xdp(&xdp_rings[i]);
2724 if (new_rx_cnt == vsi->rx_rings[0]->count)
2727 /* alloc updated Rx resources */
2728 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2729 vsi->rx_rings[0]->count, new_rx_cnt);
2731 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2737 ice_for_each_rxq(vsi, i) {
2738 /* clone ring and setup updated count */
2739 rx_rings[i] = *vsi->rx_rings[i];
2740 rx_rings[i].count = new_rx_cnt;
2741 rx_rings[i].desc = NULL;
2742 rx_rings[i].rx_buf = NULL;
2743 /* this is to allow wr32 to have something to write to
2744 * during early allocation of Rx buffers
2746 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2748 err = ice_setup_rx_ring(&rx_rings[i]);
2752 /* allocate Rx buffers */
2753 err = ice_alloc_rx_bufs(&rx_rings[i],
2754 ICE_DESC_UNUSED(&rx_rings[i]));
2759 ice_free_rx_ring(&rx_rings[i]);
2768 /* Bring interface down, copy in the new ring info, then restore the
2769 * interface. if VSI is up, bring it down and then back up
2771 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2775 ice_for_each_txq(vsi, i) {
2776 ice_free_tx_ring(vsi->tx_rings[i]);
2777 *vsi->tx_rings[i] = tx_rings[i];
2783 ice_for_each_rxq(vsi, i) {
2784 ice_free_rx_ring(vsi->rx_rings[i]);
2785 /* copy the real tail offset */
2786 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2787 /* this is to fake out the allocation routine
2788 * into thinking it has to realloc everything
2789 * but the recycling logic will let us re-use
2790 * the buffers allocated above
2792 rx_rings[i].next_to_use = 0;
2793 rx_rings[i].next_to_clean = 0;
2794 rx_rings[i].next_to_alloc = 0;
2795 *vsi->rx_rings[i] = rx_rings[i];
2801 for (i = 0; i < vsi->num_xdp_txq; i++) {
2802 ice_free_tx_ring(vsi->xdp_rings[i]);
2803 *vsi->xdp_rings[i] = xdp_rings[i];
2808 vsi->num_tx_desc = new_tx_cnt;
2809 vsi->num_rx_desc = new_rx_cnt;
2815 /* error cleanup if the Rx allocations failed after getting Tx */
2817 ice_for_each_txq(vsi, i)
2818 ice_free_tx_ring(&tx_rings[i]);
2823 clear_bit(__ICE_CFG_BUSY, pf->state);
2828 * ice_get_pauseparam - Get Flow Control status
2829 * @netdev: network interface device structure
2830 * @pause: ethernet pause (flow control) parameters
2832 * Get requested flow control status from PHY capability.
2833 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2834 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2835 * the negotiated Rx/Tx pause via lp_advertising.
2838 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2840 struct ice_netdev_priv *np = netdev_priv(netdev);
2841 struct ice_port_info *pi = np->vsi->port_info;
2842 struct ice_aqc_get_phy_caps_data *pcaps;
2843 struct ice_dcbx_cfg *dcbx_cfg;
2844 enum ice_status status;
2846 /* Initialize pause params */
2847 pause->rx_pause = 0;
2848 pause->tx_pause = 0;
2850 dcbx_cfg = &pi->local_dcbx_cfg;
2852 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2856 /* Get current PHY config */
2857 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2862 pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2863 AUTONEG_ENABLE : AUTONEG_DISABLE);
2865 if (dcbx_cfg->pfc.pfcena)
2866 /* PFC enabled so report LFC as off */
2869 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2870 pause->tx_pause = 1;
2871 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2872 pause->rx_pause = 1;
2879 * ice_set_pauseparam - Set Flow Control parameter
2880 * @netdev: network interface device structure
2881 * @pause: return Tx/Rx flow control status
2884 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2886 struct ice_netdev_priv *np = netdev_priv(netdev);
2887 struct ice_aqc_get_phy_caps_data *pcaps;
2888 struct ice_link_status *hw_link_info;
2889 struct ice_pf *pf = np->vsi->back;
2890 struct ice_dcbx_cfg *dcbx_cfg;
2891 struct ice_vsi *vsi = np->vsi;
2892 struct ice_hw *hw = &pf->hw;
2893 struct ice_port_info *pi;
2894 enum ice_status status;
2900 pi = vsi->port_info;
2901 hw_link_info = &pi->phy.link_info;
2902 dcbx_cfg = &pi->local_dcbx_cfg;
2903 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
2905 /* Changing the port's flow control is not supported if this isn't the
2908 if (vsi->type != ICE_VSI_PF) {
2909 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
2913 /* Get pause param reports configured and negotiated flow control pause
2914 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2915 * defined get pause param pause->autoneg reports SW configured setting,
2916 * so compare pause->autoneg with SW configured to prevent the user from
2917 * using set pause param to chance autoneg.
2919 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2923 /* Get current PHY config */
2924 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2931 is_an = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2932 AUTONEG_ENABLE : AUTONEG_DISABLE);
2936 if (pause->autoneg != is_an) {
2937 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2941 /* If we have link and don't have autoneg */
2942 if (!test_bit(__ICE_DOWN, pf->state) &&
2943 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
2944 /* Send message that it might not necessarily work*/
2945 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2948 if (dcbx_cfg->pfc.pfcena) {
2949 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
2952 if (pause->rx_pause && pause->tx_pause)
2953 pi->fc.req_mode = ICE_FC_FULL;
2954 else if (pause->rx_pause && !pause->tx_pause)
2955 pi->fc.req_mode = ICE_FC_RX_PAUSE;
2956 else if (!pause->rx_pause && pause->tx_pause)
2957 pi->fc.req_mode = ICE_FC_TX_PAUSE;
2958 else if (!pause->rx_pause && !pause->tx_pause)
2959 pi->fc.req_mode = ICE_FC_NONE;
2963 /* Set the FC mode and only restart AN if link is up */
2964 status = ice_set_fc(pi, &aq_failures, link_up);
2966 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
2967 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2968 status, hw->adminq.sq_last_status);
2970 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
2971 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2972 status, hw->adminq.sq_last_status);
2974 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
2975 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2976 status, hw->adminq.sq_last_status);
2980 if (!test_bit(__ICE_DOWN, pf->state)) {
2981 /* Give it a little more time to try to come back. If still
2982 * down, restart autoneg link or reinitialize the interface.
2985 if (!test_bit(__ICE_DOWN, pf->state))
2986 return ice_nway_reset(netdev);
2996 * ice_get_rxfh_key_size - get the RSS hash key size
2997 * @netdev: network interface device structure
2999 * Returns the table size.
3001 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3003 return ICE_VSIQF_HKEY_ARRAY_SIZE;
3007 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3008 * @netdev: network interface device structure
3010 * Returns the table size.
3012 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3014 struct ice_netdev_priv *np = netdev_priv(netdev);
3016 return np->vsi->rss_table_size;
3020 * ice_get_rxfh - get the Rx flow hash indirection table
3021 * @netdev: network interface device structure
3022 * @indir: indirection table
3024 * @hfunc: hash function
3026 * Reads the indirection table directly from the hardware.
3029 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3031 struct ice_netdev_priv *np = netdev_priv(netdev);
3032 struct ice_vsi *vsi = np->vsi;
3033 struct ice_pf *pf = vsi->back;
3038 *hfunc = ETH_RSS_HASH_TOP;
3043 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3044 /* RSS not supported return error here */
3045 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3049 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3053 if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3058 for (i = 0; i < vsi->rss_table_size; i++)
3059 indir[i] = (u32)(lut[i]);
3067 * ice_set_rxfh - set the Rx flow hash indirection table
3068 * @netdev: network interface device structure
3069 * @indir: indirection table
3071 * @hfunc: hash function
3073 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3074 * returns 0 after programming the table.
3077 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3080 struct ice_netdev_priv *np = netdev_priv(netdev);
3081 struct ice_vsi *vsi = np->vsi;
3082 struct ice_pf *pf = vsi->back;
3086 dev = ice_pf_to_dev(pf);
3087 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3090 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3091 /* RSS not supported return error here */
3092 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3097 if (!vsi->rss_hkey_user) {
3098 vsi->rss_hkey_user =
3099 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3101 if (!vsi->rss_hkey_user)
3104 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3105 seed = vsi->rss_hkey_user;
3108 if (!vsi->rss_lut_user) {
3109 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3111 if (!vsi->rss_lut_user)
3115 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3119 for (i = 0; i < vsi->rss_table_size; i++)
3120 vsi->rss_lut_user[i] = (u8)(indir[i]);
3122 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3126 if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3133 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3136 static int ice_get_max_txq(struct ice_pf *pf)
3138 return min_t(int, num_online_cpus(),
3139 pf->hw.func_caps.common_cap.num_txq);
3143 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3146 static int ice_get_max_rxq(struct ice_pf *pf)
3148 return min_t(int, num_online_cpus(),
3149 pf->hw.func_caps.common_cap.num_rxq);
3153 * ice_get_combined_cnt - return the current number of combined channels
3154 * @vsi: PF VSI pointer
3156 * Go through all queue vectors and count ones that have both Rx and Tx ring
3159 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3164 ice_for_each_q_vector(vsi, q_idx) {
3165 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3167 if (q_vector->rx.ring && q_vector->tx.ring)
3175 * ice_get_channels - get the current and max supported channels
3176 * @dev: network interface device structure
3177 * @ch: ethtool channel data structure
3180 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3182 struct ice_netdev_priv *np = netdev_priv(dev);
3183 struct ice_vsi *vsi = np->vsi;
3184 struct ice_pf *pf = vsi->back;
3186 /* check to see if VSI is active */
3187 if (test_bit(__ICE_DOWN, vsi->state))
3190 /* report maximum channels */
3191 ch->max_rx = ice_get_max_rxq(pf);
3192 ch->max_tx = ice_get_max_txq(pf);
3193 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3195 /* report current channels */
3196 ch->combined_count = ice_get_combined_cnt(vsi);
3197 ch->rx_count = vsi->num_rxq - ch->combined_count;
3198 ch->tx_count = vsi->num_txq - ch->combined_count;
3202 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3203 * @vsi: VSI to reconfigure RSS LUT on
3204 * @req_rss_size: requested range of queue numbers for hashing
3206 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3208 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3210 struct ice_pf *pf = vsi->back;
3211 enum ice_status status;
3217 dev = ice_pf_to_dev(pf);
3223 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3227 /* set RSS LUT parameters */
3228 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3231 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3233 vsi->rss_size = min_t(int, req_rss_size,
3234 BIT(caps->rss_table_entry_width));
3237 /* create/set RSS LUT */
3238 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3239 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type, lut,
3240 vsi->rss_table_size);
3242 dev_err(dev, "Cannot set RSS lut, err %d aq_err %d\n",
3243 status, hw->adminq.rq_last_status);
3252 * ice_set_channels - set the number channels
3253 * @dev: network interface device structure
3254 * @ch: ethtool channel data structure
3256 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3258 struct ice_netdev_priv *np = netdev_priv(dev);
3259 struct ice_vsi *vsi = np->vsi;
3260 struct ice_pf *pf = vsi->back;
3261 int new_rx = 0, new_tx = 0;
3264 /* do not support changing channels in Safe Mode */
3265 if (ice_is_safe_mode(pf)) {
3266 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3269 /* do not support changing other_count */
3270 if (ch->other_count)
3273 curr_combined = ice_get_combined_cnt(vsi);
3275 /* these checks are for cases where user didn't specify a particular
3276 * value on cmd line but we get non-zero value anyway via
3277 * get_channels(); look at ethtool.c in ethtool repository (the user
3278 * space part), particularly, do_schannels() routine
3280 if (ch->rx_count == vsi->num_rxq - curr_combined)
3282 if (ch->tx_count == vsi->num_txq - curr_combined)
3284 if (ch->combined_count == curr_combined)
3285 ch->combined_count = 0;
3287 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3288 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3292 new_rx = ch->combined_count + ch->rx_count;
3293 new_tx = ch->combined_count + ch->tx_count;
3295 if (new_rx > ice_get_max_rxq(pf)) {
3296 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3297 ice_get_max_rxq(pf));
3300 if (new_tx > ice_get_max_txq(pf)) {
3301 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3302 ice_get_max_txq(pf));
3306 ice_vsi_recfg_qs(vsi, new_rx, new_tx);
3308 if (new_rx && !netif_is_rxfh_configured(dev))
3309 return ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3314 enum ice_container_type {
3320 * ice_get_rc_coalesce - get ITR values for specific ring container
3321 * @ec: ethtool structure to fill with driver's coalesce settings
3322 * @c_type: container type, Rx or Tx
3323 * @rc: ring container that the ITR values will come from
3325 * Query the device for ice_ring_container specific ITR values. This is
3326 * done per ice_ring_container because each q_vector can have 1 or more rings
3327 * and all of said ring(s) will have the same ITR values.
3329 * Returns 0 on success, negative otherwise.
3332 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3333 struct ice_ring_container *rc)
3340 pf = rc->ring->vsi->back;
3343 case ICE_RX_CONTAINER:
3344 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3345 ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3346 ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3348 case ICE_TX_CONTAINER:
3349 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3350 ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3353 dev_dbg(ice_pf_to_dev(pf), "Invalid c_type %d\n", c_type);
3361 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3362 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3363 * @ec: coalesce settings to program the device with
3364 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3366 * Return 0 on success, and negative under the following conditions:
3367 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3368 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3371 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3373 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3374 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3375 &vsi->rx_rings[q_num]->q_vector->rx))
3377 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3378 &vsi->tx_rings[q_num]->q_vector->tx))
3380 } else if (q_num < vsi->num_rxq) {
3381 if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3382 &vsi->rx_rings[q_num]->q_vector->rx))
3384 } else if (q_num < vsi->num_txq) {
3385 if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3386 &vsi->tx_rings[q_num]->q_vector->tx))
3396 * __ice_get_coalesce - get ITR/INTRL values for the device
3397 * @netdev: pointer to the netdev associated with this query
3398 * @ec: ethtool structure to fill with driver's coalesce settings
3399 * @q_num: queue number to get the coalesce settings for
3401 * If the caller passes in a negative q_num then we return coalesce settings
3402 * based on queue number 0, else use the actual q_num passed in.
3405 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3408 struct ice_netdev_priv *np = netdev_priv(netdev);
3409 struct ice_vsi *vsi = np->vsi;
3414 if (ice_get_q_coalesce(vsi, ec, q_num))
3421 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3423 return __ice_get_coalesce(netdev, ec, -1);
3427 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3428 struct ethtool_coalesce *ec)
3430 return __ice_get_coalesce(netdev, ec, q_num);
3434 * ice_set_rc_coalesce - set ITR values for specific ring container
3435 * @c_type: container type, Rx or Tx
3436 * @ec: ethtool structure from user to update ITR settings
3437 * @rc: ring container that the ITR values will come from
3438 * @vsi: VSI associated to the ring container
3440 * Set specific ITR values. This is done per ice_ring_container because each
3441 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3444 * Returns 0 on success, negative otherwise.
3447 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3448 struct ice_ring_container *rc, struct ice_vsi *vsi)
3450 const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3451 u32 use_adaptive_coalesce, coalesce_usecs;
3452 struct ice_pf *pf = vsi->back;
3459 case ICE_RX_CONTAINER:
3460 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3461 (ec->rx_coalesce_usecs_high &&
3462 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3463 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3464 c_type_str, pf->hw.intrl_gran,
3468 if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3469 rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3470 wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3471 ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3472 pf->hw.intrl_gran));
3475 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3476 coalesce_usecs = ec->rx_coalesce_usecs;
3479 case ICE_TX_CONTAINER:
3480 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3481 coalesce_usecs = ec->tx_coalesce_usecs;
3485 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3490 itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3491 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3492 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3493 c_type_str, c_type_str);
3497 if (coalesce_usecs > ICE_ITR_MAX) {
3498 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3499 c_type_str, ICE_ITR_MAX);
3503 if (use_adaptive_coalesce) {
3504 rc->itr_setting |= ICE_ITR_DYNAMIC;
3506 /* save the user set usecs */
3507 rc->itr_setting = coalesce_usecs;
3508 /* device ITR granularity is in 2 usec increments */
3509 rc->target_itr = ITR_REG_ALIGN(rc->itr_setting);
3516 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3517 * @vsi: VSI associated to the queue that need updating
3518 * @ec: coalesce settings to program the device with
3519 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3521 * Return 0 on success, and negative under the following conditions:
3522 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3523 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3526 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3528 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3529 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3530 &vsi->rx_rings[q_num]->q_vector->rx,
3534 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3535 &vsi->tx_rings[q_num]->q_vector->tx,
3538 } else if (q_num < vsi->num_rxq) {
3539 if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3540 &vsi->rx_rings[q_num]->q_vector->rx,
3543 } else if (q_num < vsi->num_txq) {
3544 if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3545 &vsi->tx_rings[q_num]->q_vector->tx,
3556 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3557 * @netdev: netdev used for print
3558 * @itr_setting: previous user setting
3559 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3560 * @coalesce_usecs: requested value of [tx|rx]-usecs
3561 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3564 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3565 u32 use_adaptive_coalesce, u32 coalesce_usecs,
3566 const char *c_type_str)
3568 if (use_adaptive_coalesce)
3571 itr_setting = ITR_TO_REG(itr_setting);
3573 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3574 netdev_info(netdev, "User set %s-usecs to %d, device only supports even values. Rounding down and attempting to set %s-usecs to %d\n",
3575 c_type_str, coalesce_usecs, c_type_str,
3576 ITR_REG_ALIGN(coalesce_usecs));
3580 * __ice_set_coalesce - set ITR/INTRL values for the device
3581 * @netdev: pointer to the netdev associated with this query
3582 * @ec: ethtool structure to fill with driver's coalesce settings
3583 * @q_num: queue number to get the coalesce settings for
3585 * If the caller passes in a negative q_num then we set the coalesce settings
3586 * for all Tx/Rx queues, else use the actual q_num passed in.
3589 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3592 struct ice_netdev_priv *np = netdev_priv(netdev);
3593 struct ice_vsi *vsi = np->vsi;
3596 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3600 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3601 ec->use_adaptive_rx_coalesce,
3602 ec->rx_coalesce_usecs, "rx");
3604 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3605 ec->use_adaptive_tx_coalesce,
3606 ec->tx_coalesce_usecs, "tx");
3609 ice_for_each_q_vector(vsi, v_idx) {
3610 /* In some cases if DCB is configured the num_[rx|tx]q
3611 * can be less than vsi->num_q_vectors. This check
3612 * accounts for that so we don't report a false failure
3614 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3617 if (ice_set_q_coalesce(vsi, ec, v_idx))
3623 if (ice_set_q_coalesce(vsi, ec, q_num))
3632 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3634 return __ice_set_coalesce(netdev, ec, -1);
3638 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3639 struct ethtool_coalesce *ec)
3641 return __ice_set_coalesce(netdev, ec, q_num);
3644 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
3645 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
3646 #define ICE_MODULE_TYPE_SFP 0x03
3647 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
3648 #define ICE_MODULE_TYPE_QSFP28 0x11
3649 #define ICE_MODULE_SFF_ADDR_MODE 0x04
3650 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
3651 #define ICE_MODULE_REVISION_ADDR 0x01
3652 #define ICE_MODULE_SFF_8472_COMP 0x5E
3653 #define ICE_MODULE_SFF_8472_SWAP 0x5C
3654 #define ICE_MODULE_QSFP_MAX_LEN 640
3657 * ice_get_module_info - get SFF module type and revision information
3658 * @netdev: network interface device structure
3659 * @modinfo: module EEPROM size and layout information structure
3662 ice_get_module_info(struct net_device *netdev,
3663 struct ethtool_modinfo *modinfo)
3665 struct ice_netdev_priv *np = netdev_priv(netdev);
3666 struct ice_vsi *vsi = np->vsi;
3667 struct ice_pf *pf = vsi->back;
3668 struct ice_hw *hw = &pf->hw;
3669 enum ice_status status;
3670 u8 sff8472_comp = 0;
3671 u8 sff8472_swap = 0;
3675 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3676 0, &value, 1, 0, NULL);
3681 case ICE_MODULE_TYPE_SFP:
3682 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3683 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3684 &sff8472_comp, 1, 0, NULL);
3687 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3688 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3689 &sff8472_swap, 1, 0, NULL);
3693 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
3694 modinfo->type = ETH_MODULE_SFF_8079;
3695 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3696 } else if (sff8472_comp &&
3697 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
3698 modinfo->type = ETH_MODULE_SFF_8472;
3699 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3701 modinfo->type = ETH_MODULE_SFF_8079;
3702 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3705 case ICE_MODULE_TYPE_QSFP_PLUS:
3706 case ICE_MODULE_TYPE_QSFP28:
3707 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3708 ICE_MODULE_REVISION_ADDR, 0x00, 0,
3709 &sff8636_rev, 1, 0, NULL);
3712 /* Check revision compliance */
3713 if (sff8636_rev > 0x02) {
3714 /* Module is SFF-8636 compliant */
3715 modinfo->type = ETH_MODULE_SFF_8636;
3716 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3718 modinfo->type = ETH_MODULE_SFF_8436;
3719 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3723 netdev_warn(netdev, "SFF Module Type not recognized.\n");
3730 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
3731 * @netdev: network interface device structure
3732 * @ee: EEPROM dump request structure
3733 * @data: buffer to be filled with EEPROM contents
3736 ice_get_module_eeprom(struct net_device *netdev,
3737 struct ethtool_eeprom *ee, u8 *data)
3739 struct ice_netdev_priv *np = netdev_priv(netdev);
3740 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
3741 struct ice_vsi *vsi = np->vsi;
3742 struct ice_pf *pf = vsi->back;
3743 struct ice_hw *hw = &pf->hw;
3744 enum ice_status status;
3745 bool is_sfp = false;
3751 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0,
3752 &value, 1, 0, NULL);
3756 if (!ee || !ee->len || !data)
3759 if (value == ICE_MODULE_TYPE_SFP)
3762 for (i = 0; i < ee->len; i++) {
3763 offset = i + ee->offset;
3765 /* Check if we need to access the other memory page */
3767 if (offset >= ETH_MODULE_SFF_8079_LEN) {
3768 offset -= ETH_MODULE_SFF_8079_LEN;
3769 addr = ICE_I2C_EEPROM_DEV_ADDR2;
3772 while (offset >= ETH_MODULE_SFF_8436_LEN) {
3773 /* Compute memory page number and offset. */
3774 offset -= ETH_MODULE_SFF_8436_LEN / 2;
3779 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, !is_sfp,
3780 &value, 1, 0, NULL);
3788 static const struct ethtool_ops ice_ethtool_ops = {
3789 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
3790 ETHTOOL_COALESCE_USE_ADAPTIVE |
3791 ETHTOOL_COALESCE_RX_USECS_HIGH,
3792 .get_link_ksettings = ice_get_link_ksettings,
3793 .set_link_ksettings = ice_set_link_ksettings,
3794 .get_drvinfo = ice_get_drvinfo,
3795 .get_regs_len = ice_get_regs_len,
3796 .get_regs = ice_get_regs,
3797 .get_msglevel = ice_get_msglevel,
3798 .set_msglevel = ice_set_msglevel,
3799 .self_test = ice_self_test,
3800 .get_link = ethtool_op_get_link,
3801 .get_eeprom_len = ice_get_eeprom_len,
3802 .get_eeprom = ice_get_eeprom,
3803 .get_coalesce = ice_get_coalesce,
3804 .set_coalesce = ice_set_coalesce,
3805 .get_strings = ice_get_strings,
3806 .set_phys_id = ice_set_phys_id,
3807 .get_ethtool_stats = ice_get_ethtool_stats,
3808 .get_priv_flags = ice_get_priv_flags,
3809 .set_priv_flags = ice_set_priv_flags,
3810 .get_sset_count = ice_get_sset_count,
3811 .get_rxnfc = ice_get_rxnfc,
3812 .set_rxnfc = ice_set_rxnfc,
3813 .get_ringparam = ice_get_ringparam,
3814 .set_ringparam = ice_set_ringparam,
3815 .nway_reset = ice_nway_reset,
3816 .get_pauseparam = ice_get_pauseparam,
3817 .set_pauseparam = ice_set_pauseparam,
3818 .get_rxfh_key_size = ice_get_rxfh_key_size,
3819 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
3820 .get_rxfh = ice_get_rxfh,
3821 .set_rxfh = ice_set_rxfh,
3822 .get_channels = ice_get_channels,
3823 .set_channels = ice_set_channels,
3824 .get_ts_info = ethtool_op_get_ts_info,
3825 .get_per_queue_coalesce = ice_get_per_q_coalesce,
3826 .set_per_queue_coalesce = ice_set_per_q_coalesce,
3827 .get_fecparam = ice_get_fecparam,
3828 .set_fecparam = ice_set_fecparam,
3829 .get_module_info = ice_get_module_info,
3830 .get_module_eeprom = ice_get_module_eeprom,
3833 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
3834 .get_link_ksettings = ice_get_link_ksettings,
3835 .set_link_ksettings = ice_set_link_ksettings,
3836 .get_drvinfo = ice_get_drvinfo,
3837 .get_regs_len = ice_get_regs_len,
3838 .get_regs = ice_get_regs,
3839 .get_msglevel = ice_get_msglevel,
3840 .set_msglevel = ice_set_msglevel,
3841 .get_link = ethtool_op_get_link,
3842 .get_eeprom_len = ice_get_eeprom_len,
3843 .get_eeprom = ice_get_eeprom,
3844 .get_strings = ice_get_strings,
3845 .get_ethtool_stats = ice_get_ethtool_stats,
3846 .get_sset_count = ice_get_sset_count,
3847 .get_ringparam = ice_get_ringparam,
3848 .set_ringparam = ice_set_ringparam,
3849 .nway_reset = ice_nway_reset,
3850 .get_channels = ice_get_channels,
3854 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
3855 * @netdev: network interface device structure
3857 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
3859 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
3863 * ice_set_ethtool_ops - setup netdev ethtool ops
3864 * @netdev: network interface device structure
3866 * setup netdev ethtool ops with ice specific ops
3868 void ice_set_ethtool_ops(struct net_device *netdev)
3870 netdev->ethtool_ops = &ice_ethtool_ops;