1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
8 #include "ice_dcb_lib.h"
11 char stat_string
[ETH_GSTRING_LEN
];
16 #define ICE_STAT(_type, _name, _stat) { \
17 .stat_string = _name, \
18 .sizeof_stat = FIELD_SIZEOF(_type, _stat), \
19 .stat_offset = offsetof(_type, _stat) \
22 #define ICE_VSI_STAT(_name, _stat) \
23 ICE_STAT(struct ice_vsi, _name, _stat)
24 #define ICE_PF_STAT(_name, _stat) \
25 ICE_STAT(struct ice_pf, _name, _stat)
27 static int ice_q_stats_len(struct net_device
*netdev
)
29 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
31 return ((np
->vsi
->alloc_txq
+ np
->vsi
->alloc_rxq
) *
32 (sizeof(struct ice_q_stats
) / sizeof(u64
)));
35 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
36 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
38 #define ICE_PFC_STATS_LEN ( \
39 (FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_rx) + \
40 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_rx) + \
41 FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_tx) + \
42 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_tx)) \
44 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
45 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
47 static const struct ice_stats ice_gstrings_vsi_stats
[] = {
48 ICE_VSI_STAT("rx_unicast", eth_stats
.rx_unicast
),
49 ICE_VSI_STAT("tx_unicast", eth_stats
.tx_unicast
),
50 ICE_VSI_STAT("rx_multicast", eth_stats
.rx_multicast
),
51 ICE_VSI_STAT("tx_multicast", eth_stats
.tx_multicast
),
52 ICE_VSI_STAT("rx_broadcast", eth_stats
.rx_broadcast
),
53 ICE_VSI_STAT("tx_broadcast", eth_stats
.tx_broadcast
),
54 ICE_VSI_STAT("rx_bytes", eth_stats
.rx_bytes
),
55 ICE_VSI_STAT("tx_bytes", eth_stats
.tx_bytes
),
56 ICE_VSI_STAT("rx_dropped", eth_stats
.rx_discards
),
57 ICE_VSI_STAT("rx_unknown_protocol", eth_stats
.rx_unknown_protocol
),
58 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed
),
59 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed
),
60 ICE_VSI_STAT("tx_errors", eth_stats
.tx_errors
),
61 ICE_VSI_STAT("tx_linearize", tx_linearize
),
64 enum ice_ethtool_test_id
{
72 static const char ice_gstrings_test
[][ETH_GSTRING_LEN
] = {
73 "Register test (offline)",
74 "EEPROM test (offline)",
75 "Interrupt test (offline)",
76 "Loopback test (offline)",
77 "Link test (on/offline)",
80 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
82 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
83 * but they aren't. This device is capable of supporting multiple
84 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
85 * netdevs whereas the PF_STATs are for the physical function that's
86 * hosting these netdevs.
88 * The PF_STATs are appended to the netdev stats only when ethtool -S
89 * is queried on the base PF netdev.
91 static const struct ice_stats ice_gstrings_pf_stats
[] = {
92 ICE_PF_STAT("rx_bytes.nic", stats
.eth
.rx_bytes
),
93 ICE_PF_STAT("tx_bytes.nic", stats
.eth
.tx_bytes
),
94 ICE_PF_STAT("rx_unicast.nic", stats
.eth
.rx_unicast
),
95 ICE_PF_STAT("tx_unicast.nic", stats
.eth
.tx_unicast
),
96 ICE_PF_STAT("rx_multicast.nic", stats
.eth
.rx_multicast
),
97 ICE_PF_STAT("tx_multicast.nic", stats
.eth
.tx_multicast
),
98 ICE_PF_STAT("rx_broadcast.nic", stats
.eth
.rx_broadcast
),
99 ICE_PF_STAT("tx_broadcast.nic", stats
.eth
.tx_broadcast
),
100 ICE_PF_STAT("tx_errors.nic", stats
.eth
.tx_errors
),
101 ICE_PF_STAT("rx_size_64.nic", stats
.rx_size_64
),
102 ICE_PF_STAT("tx_size_64.nic", stats
.tx_size_64
),
103 ICE_PF_STAT("rx_size_127.nic", stats
.rx_size_127
),
104 ICE_PF_STAT("tx_size_127.nic", stats
.tx_size_127
),
105 ICE_PF_STAT("rx_size_255.nic", stats
.rx_size_255
),
106 ICE_PF_STAT("tx_size_255.nic", stats
.tx_size_255
),
107 ICE_PF_STAT("rx_size_511.nic", stats
.rx_size_511
),
108 ICE_PF_STAT("tx_size_511.nic", stats
.tx_size_511
),
109 ICE_PF_STAT("rx_size_1023.nic", stats
.rx_size_1023
),
110 ICE_PF_STAT("tx_size_1023.nic", stats
.tx_size_1023
),
111 ICE_PF_STAT("rx_size_1522.nic", stats
.rx_size_1522
),
112 ICE_PF_STAT("tx_size_1522.nic", stats
.tx_size_1522
),
113 ICE_PF_STAT("rx_size_big.nic", stats
.rx_size_big
),
114 ICE_PF_STAT("tx_size_big.nic", stats
.tx_size_big
),
115 ICE_PF_STAT("link_xon_rx.nic", stats
.link_xon_rx
),
116 ICE_PF_STAT("link_xon_tx.nic", stats
.link_xon_tx
),
117 ICE_PF_STAT("link_xoff_rx.nic", stats
.link_xoff_rx
),
118 ICE_PF_STAT("link_xoff_tx.nic", stats
.link_xoff_tx
),
119 ICE_PF_STAT("tx_dropped_link_down.nic", stats
.tx_dropped_link_down
),
120 ICE_PF_STAT("rx_undersize.nic", stats
.rx_undersize
),
121 ICE_PF_STAT("rx_fragments.nic", stats
.rx_fragments
),
122 ICE_PF_STAT("rx_oversize.nic", stats
.rx_oversize
),
123 ICE_PF_STAT("rx_jabber.nic", stats
.rx_jabber
),
124 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error
),
125 ICE_PF_STAT("rx_length_errors.nic", stats
.rx_len_errors
),
126 ICE_PF_STAT("rx_dropped.nic", stats
.eth
.rx_discards
),
127 ICE_PF_STAT("rx_crc_errors.nic", stats
.crc_errors
),
128 ICE_PF_STAT("illegal_bytes.nic", stats
.illegal_bytes
),
129 ICE_PF_STAT("mac_local_faults.nic", stats
.mac_local_faults
),
130 ICE_PF_STAT("mac_remote_faults.nic", stats
.mac_remote_faults
),
133 static const u32 ice_regs_dump_list
[] = {
146 struct ice_priv_flag
{
147 char name
[ETH_GSTRING_LEN
];
148 u32 bitno
; /* bit position in pf->flags */
151 #define ICE_PRIV_FLAG(_name, _bitno) { \
156 static const struct ice_priv_flag ice_gstrings_priv_flags
[] = {
157 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA
),
158 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT
),
161 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
164 ice_get_drvinfo(struct net_device
*netdev
, struct ethtool_drvinfo
*drvinfo
)
166 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
167 struct ice_vsi
*vsi
= np
->vsi
;
168 struct ice_pf
*pf
= vsi
->back
;
170 strlcpy(drvinfo
->driver
, KBUILD_MODNAME
, sizeof(drvinfo
->driver
));
171 strlcpy(drvinfo
->version
, ice_drv_ver
, sizeof(drvinfo
->version
));
172 strlcpy(drvinfo
->fw_version
, ice_nvm_version_str(&pf
->hw
),
173 sizeof(drvinfo
->fw_version
));
174 strlcpy(drvinfo
->bus_info
, pci_name(pf
->pdev
),
175 sizeof(drvinfo
->bus_info
));
176 drvinfo
->n_priv_flags
= ICE_PRIV_FLAG_ARRAY_SIZE
;
179 static int ice_get_regs_len(struct net_device __always_unused
*netdev
)
181 return sizeof(ice_regs_dump_list
);
185 ice_get_regs(struct net_device
*netdev
, struct ethtool_regs
*regs
, void *p
)
187 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
188 struct ice_pf
*pf
= np
->vsi
->back
;
189 struct ice_hw
*hw
= &pf
->hw
;
190 u32
*regs_buf
= (u32
*)p
;
195 for (i
= 0; i
< ARRAY_SIZE(ice_regs_dump_list
); ++i
)
196 regs_buf
[i
] = rd32(hw
, ice_regs_dump_list
[i
]);
199 static u32
ice_get_msglevel(struct net_device
*netdev
)
201 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
202 struct ice_pf
*pf
= np
->vsi
->back
;
204 #ifndef CONFIG_DYNAMIC_DEBUG
205 if (pf
->hw
.debug_mask
)
206 netdev_info(netdev
, "hw debug_mask: 0x%llX\n",
208 #endif /* !CONFIG_DYNAMIC_DEBUG */
210 return pf
->msg_enable
;
213 static void ice_set_msglevel(struct net_device
*netdev
, u32 data
)
215 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
216 struct ice_pf
*pf
= np
->vsi
->back
;
218 #ifndef CONFIG_DYNAMIC_DEBUG
219 if (ICE_DBG_USER
& data
)
220 pf
->hw
.debug_mask
= data
;
222 pf
->msg_enable
= data
;
224 pf
->msg_enable
= data
;
225 #endif /* !CONFIG_DYNAMIC_DEBUG */
228 static int ice_get_eeprom_len(struct net_device
*netdev
)
230 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
231 struct ice_pf
*pf
= np
->vsi
->back
;
233 return (int)(pf
->hw
.nvm
.sr_words
* sizeof(u16
));
237 ice_get_eeprom(struct net_device
*netdev
, struct ethtool_eeprom
*eeprom
,
240 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
241 u16 first_word
, last_word
, nwords
;
242 struct ice_vsi
*vsi
= np
->vsi
;
243 struct ice_pf
*pf
= vsi
->back
;
244 struct ice_hw
*hw
= &pf
->hw
;
245 enum ice_status status
;
250 dev
= &pf
->pdev
->dev
;
252 eeprom
->magic
= hw
->vendor_id
| (hw
->device_id
<< 16);
254 first_word
= eeprom
->offset
>> 1;
255 last_word
= (eeprom
->offset
+ eeprom
->len
- 1) >> 1;
256 nwords
= last_word
- first_word
+ 1;
258 buf
= devm_kcalloc(dev
, nwords
, sizeof(u16
), GFP_KERNEL
);
262 status
= ice_read_sr_buf(hw
, first_word
, &nwords
, buf
);
264 dev_err(dev
, "ice_read_sr_buf failed, err %d aq_err %d\n",
265 status
, hw
->adminq
.sq_last_status
);
266 eeprom
->len
= sizeof(u16
) * nwords
;
271 memcpy(bytes
, (u8
*)buf
+ (eeprom
->offset
& 1), eeprom
->len
);
273 devm_kfree(dev
, buf
);
278 * ice_active_vfs - check if there are any active VFs
279 * @pf: board private structure
281 * Returns true if an active VF is found, otherwise returns false
283 static bool ice_active_vfs(struct ice_pf
*pf
)
285 struct ice_vf
*vf
= pf
->vf
;
288 for (i
= 0; i
< pf
->num_alloc_vfs
; i
++, vf
++)
289 if (test_bit(ICE_VF_STATE_ACTIVE
, vf
->vf_states
))
295 * ice_link_test - perform a link test on a given net_device
296 * @netdev: network interface device structure
298 * This function performs one of the self-tests required by ethtool.
299 * Returns 0 on success, non-zero on failure.
301 static u64
ice_link_test(struct net_device
*netdev
)
303 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
304 enum ice_status status
;
305 bool link_up
= false;
307 netdev_info(netdev
, "link test\n");
308 status
= ice_get_link_status(np
->vsi
->port_info
, &link_up
);
310 netdev_err(netdev
, "link query error, status = %d\n", status
);
321 * ice_eeprom_test - perform an EEPROM test on a given net_device
322 * @netdev: network interface device structure
324 * This function performs one of the self-tests required by ethtool.
325 * Returns 0 on success, non-zero on failure.
327 static u64
ice_eeprom_test(struct net_device
*netdev
)
329 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
330 struct ice_pf
*pf
= np
->vsi
->back
;
332 netdev_info(netdev
, "EEPROM test\n");
333 return !!(ice_nvm_validate_checksum(&pf
->hw
));
337 * ice_reg_pattern_test
338 * @hw: pointer to the HW struct
339 * @reg: reg to be tested
340 * @mask: bits to be touched
342 static int ice_reg_pattern_test(struct ice_hw
*hw
, u32 reg
, u32 mask
)
344 struct ice_pf
*pf
= (struct ice_pf
*)hw
->back
;
345 static const u32 patterns
[] = {
346 0x5A5A5A5A, 0xA5A5A5A5,
347 0x00000000, 0xFFFFFFFF
352 orig_val
= rd32(hw
, reg
);
353 for (i
= 0; i
< ARRAY_SIZE(patterns
); ++i
) {
354 u32 pattern
= patterns
[i
] & mask
;
356 wr32(hw
, reg
, pattern
);
360 dev_err(&pf
->pdev
->dev
,
361 "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
362 , __func__
, reg
, pattern
, val
);
366 wr32(hw
, reg
, orig_val
);
368 if (val
!= orig_val
) {
369 dev_err(&pf
->pdev
->dev
,
370 "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
371 , __func__
, reg
, orig_val
, val
);
379 * ice_reg_test - perform a register test on a given net_device
380 * @netdev: network interface device structure
382 * This function performs one of the self-tests required by ethtool.
383 * Returns 0 on success, non-zero on failure.
385 static u64
ice_reg_test(struct net_device
*netdev
)
387 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
388 struct ice_hw
*hw
= np
->vsi
->port_info
->hw
;
389 u32 int_elements
= hw
->func_caps
.common_cap
.num_msix_vectors
?
390 hw
->func_caps
.common_cap
.num_msix_vectors
- 1 : 1;
391 struct ice_diag_reg_test_info
{
397 {GLINT_ITR(0, 0), 0x00000fff, int_elements
,
398 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
399 {GLINT_ITR(1, 0), 0x00000fff, int_elements
,
400 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
401 {GLINT_ITR(0, 0), 0x00000fff, int_elements
,
402 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
403 {GLINT_CTL
, 0xffff0001, 1, 0}
407 netdev_dbg(netdev
, "Register test\n");
408 for (i
= 0; i
< ARRAY_SIZE(ice_reg_list
); ++i
) {
411 for (j
= 0; j
< ice_reg_list
[i
].elem_num
; ++j
) {
412 u32 mask
= ice_reg_list
[i
].mask
;
413 u32 reg
= ice_reg_list
[i
].address
+
414 (j
* ice_reg_list
[i
].elem_size
);
416 /* bail on failure (non-zero return) */
417 if (ice_reg_pattern_test(hw
, reg
, mask
))
426 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
427 * @vsi: pointer to the VSI structure
429 * Function configures rings of a VSI for loopback test without
430 * enabling interrupts or informing the kernel about new queues.
432 * Returns 0 on success, negative on failure.
434 static int ice_lbtest_prepare_rings(struct ice_vsi
*vsi
)
438 status
= ice_vsi_setup_tx_rings(vsi
);
440 goto err_setup_tx_ring
;
442 status
= ice_vsi_setup_rx_rings(vsi
);
444 goto err_setup_rx_ring
;
446 status
= ice_vsi_cfg(vsi
);
448 goto err_setup_rx_ring
;
450 status
= ice_vsi_start_rx_rings(vsi
);
452 goto err_start_rx_ring
;
457 ice_vsi_free_rx_rings(vsi
);
459 ice_vsi_stop_lan_tx_rings(vsi
, ICE_NO_RESET
, 0);
461 ice_vsi_free_tx_rings(vsi
);
467 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
468 * @vsi: pointer to the VSI structure
470 * Function stops and frees VSI rings after a loopback test.
471 * Returns 0 on success, negative on failure.
473 static int ice_lbtest_disable_rings(struct ice_vsi
*vsi
)
477 status
= ice_vsi_stop_lan_tx_rings(vsi
, ICE_NO_RESET
, 0);
479 netdev_err(vsi
->netdev
, "Failed to stop Tx rings, VSI %d error %d\n",
480 vsi
->vsi_num
, status
);
482 status
= ice_vsi_stop_rx_rings(vsi
);
484 netdev_err(vsi
->netdev
, "Failed to stop Rx rings, VSI %d error %d\n",
485 vsi
->vsi_num
, status
);
487 ice_vsi_free_tx_rings(vsi
);
488 ice_vsi_free_rx_rings(vsi
);
494 * ice_lbtest_create_frame - create test packet
495 * @pf: pointer to the PF structure
496 * @ret_data: allocated frame buffer
497 * @size: size of the packet data
499 * Function allocates a frame with a test pattern on specific offsets.
500 * Returns 0 on success, non-zero on failure.
502 static int ice_lbtest_create_frame(struct ice_pf
*pf
, u8
**ret_data
, u16 size
)
509 data
= devm_kzalloc(&pf
->pdev
->dev
, size
, GFP_KERNEL
);
513 /* Since the ethernet test frame should always be at least
514 * 64 bytes long, fill some octets in the payload with test data.
516 memset(data
, 0xFF, size
);
528 * ice_lbtest_check_frame - verify received loopback frame
529 * @frame: pointer to the raw packet data
531 * Function verifies received test frame with a pattern.
532 * Returns true if frame matches the pattern, false otherwise.
534 static bool ice_lbtest_check_frame(u8
*frame
)
536 /* Validate bytes of a frame under offsets chosen earlier */
537 if (frame
[32] == 0xDE &&
548 * ice_diag_send - send test frames to the test ring
549 * @tx_ring: pointer to the transmit ring
550 * @data: pointer to the raw packet data
551 * @size: size of the packet to send
553 * Function sends loopback packets on a test Tx ring.
555 static int ice_diag_send(struct ice_ring
*tx_ring
, u8
*data
, u16 size
)
557 struct ice_tx_desc
*tx_desc
;
558 struct ice_tx_buf
*tx_buf
;
562 tx_desc
= ICE_TX_DESC(tx_ring
, tx_ring
->next_to_use
);
563 tx_buf
= &tx_ring
->tx_buf
[tx_ring
->next_to_use
];
565 dma
= dma_map_single(tx_ring
->dev
, data
, size
, DMA_TO_DEVICE
);
566 if (dma_mapping_error(tx_ring
->dev
, dma
))
569 tx_desc
->buf_addr
= cpu_to_le64(dma
);
571 /* These flags are required for a descriptor to be pushed out */
572 td_cmd
= (u64
)(ICE_TX_DESC_CMD_EOP
| ICE_TX_DESC_CMD_RS
);
573 tx_desc
->cmd_type_offset_bsz
=
574 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA
|
575 (td_cmd
<< ICE_TXD_QW1_CMD_S
) |
576 ((u64
)0 << ICE_TXD_QW1_OFFSET_S
) |
577 ((u64
)size
<< ICE_TXD_QW1_TX_BUF_SZ_S
) |
578 ((u64
)0 << ICE_TXD_QW1_L2TAG1_S
));
580 tx_buf
->next_to_watch
= tx_desc
;
582 /* Force memory write to complete before letting h/w know
583 * there are new descriptors to fetch.
587 tx_ring
->next_to_use
++;
588 if (tx_ring
->next_to_use
>= tx_ring
->count
)
589 tx_ring
->next_to_use
= 0;
591 writel_relaxed(tx_ring
->next_to_use
, tx_ring
->tail
);
593 /* Wait until the packets get transmitted to the receive queue. */
594 usleep_range(1000, 2000);
595 dma_unmap_single(tx_ring
->dev
, dma
, size
, DMA_TO_DEVICE
);
600 #define ICE_LB_FRAME_SIZE 64
602 * ice_lbtest_receive_frames - receive and verify test frames
603 * @rx_ring: pointer to the receive ring
605 * Function receives loopback packets and verify their correctness.
606 * Returns number of received valid frames.
608 static int ice_lbtest_receive_frames(struct ice_ring
*rx_ring
)
610 struct ice_rx_buf
*rx_buf
;
616 for (i
= 0; i
< rx_ring
->count
; i
++) {
617 union ice_32b_rx_flex_desc
*rx_desc
;
619 rx_desc
= ICE_RX_DESC(rx_ring
, i
);
621 if (!(rx_desc
->wb
.status_error0
&
622 cpu_to_le16(ICE_TX_DESC_CMD_EOP
| ICE_TX_DESC_CMD_RS
)))
625 rx_buf
= &rx_ring
->rx_buf
[i
];
626 received_buf
= page_address(rx_buf
->page
);
628 if (ice_lbtest_check_frame(received_buf
))
636 * ice_loopback_test - perform a loopback test on a given net_device
637 * @netdev: network interface device structure
639 * This function performs one of the self-tests required by ethtool.
640 * Returns 0 on success, non-zero on failure.
642 static u64
ice_loopback_test(struct net_device
*netdev
)
644 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
645 struct ice_vsi
*orig_vsi
= np
->vsi
, *test_vsi
;
646 struct ice_pf
*pf
= orig_vsi
->back
;
647 struct ice_ring
*tx_ring
, *rx_ring
;
648 u8 broadcast
[ETH_ALEN
], ret
= 0;
649 int num_frames
, valid_frames
;
654 netdev_info(netdev
, "loopback test\n");
656 test_vsi
= ice_lb_vsi_setup(pf
, pf
->hw
.port_info
);
658 netdev_err(netdev
, "Failed to create a VSI for the loopback test");
662 test_vsi
->netdev
= netdev
;
663 tx_ring
= test_vsi
->tx_rings
[0];
664 rx_ring
= test_vsi
->rx_rings
[0];
666 if (ice_lbtest_prepare_rings(test_vsi
)) {
668 goto lbtest_vsi_close
;
671 if (ice_alloc_rx_bufs(rx_ring
, rx_ring
->count
)) {
673 goto lbtest_rings_dis
;
676 /* Enable MAC loopback in firmware */
677 if (ice_aq_set_mac_loopback(&pf
->hw
, true, NULL
)) {
682 /* Test VSI needs to receive broadcast packets */
683 eth_broadcast_addr(broadcast
);
684 if (ice_add_mac_to_list(test_vsi
, &tmp_list
, broadcast
)) {
689 if (ice_add_mac(&pf
->hw
, &tmp_list
)) {
694 if (ice_lbtest_create_frame(pf
, &tx_frame
, ICE_LB_FRAME_SIZE
)) {
696 goto remove_mac_filters
;
699 num_frames
= min_t(int, tx_ring
->count
, 32);
700 for (i
= 0; i
< num_frames
; i
++) {
701 if (ice_diag_send(tx_ring
, tx_frame
, ICE_LB_FRAME_SIZE
)) {
703 goto lbtest_free_frame
;
707 valid_frames
= ice_lbtest_receive_frames(rx_ring
);
710 else if (valid_frames
!= num_frames
)
714 devm_kfree(&pf
->pdev
->dev
, tx_frame
);
716 if (ice_remove_mac(&pf
->hw
, &tmp_list
))
717 netdev_err(netdev
, "Could not remove MAC filter for the test VSI");
719 ice_free_fltr_list(&pf
->pdev
->dev
, &tmp_list
);
721 /* Disable MAC loopback after the test is completed. */
722 if (ice_aq_set_mac_loopback(&pf
->hw
, false, NULL
))
723 netdev_err(netdev
, "Could not disable MAC loopback\n");
725 if (ice_lbtest_disable_rings(test_vsi
))
726 netdev_err(netdev
, "Could not disable test rings\n");
728 test_vsi
->netdev
= NULL
;
729 if (ice_vsi_release(test_vsi
))
730 netdev_err(netdev
, "Failed to remove the test VSI");
736 * ice_intr_test - perform an interrupt test on a given net_device
737 * @netdev: network interface device structure
739 * This function performs one of the self-tests required by ethtool.
740 * Returns 0 on success, non-zero on failure.
742 static u64
ice_intr_test(struct net_device
*netdev
)
744 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
745 struct ice_pf
*pf
= np
->vsi
->back
;
746 u16 swic_old
= pf
->sw_int_count
;
748 netdev_info(netdev
, "interrupt test\n");
750 wr32(&pf
->hw
, GLINT_DYN_CTL(pf
->oicr_idx
),
751 GLINT_DYN_CTL_SW_ITR_INDX_M
|
752 GLINT_DYN_CTL_INTENA_MSK_M
|
753 GLINT_DYN_CTL_SWINT_TRIG_M
);
755 usleep_range(1000, 2000);
756 return (swic_old
== pf
->sw_int_count
);
760 * ice_self_test - handler function for performing a self-test by ethtool
761 * @netdev: network interface device structure
762 * @eth_test: ethtool_test structure
763 * @data: required by ethtool.self_test
765 * This function is called after invoking 'ethtool -t devname' command where
766 * devname is the name of the network device on which ethtool should operate.
767 * It performs a set of self-tests to check if a device works properly.
770 ice_self_test(struct net_device
*netdev
, struct ethtool_test
*eth_test
,
773 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
774 bool if_running
= netif_running(netdev
);
775 struct ice_pf
*pf
= np
->vsi
->back
;
777 if (eth_test
->flags
== ETH_TEST_FL_OFFLINE
) {
778 netdev_info(netdev
, "offline testing starting\n");
780 set_bit(__ICE_TESTING
, pf
->state
);
782 if (ice_active_vfs(pf
)) {
783 dev_warn(&pf
->pdev
->dev
,
784 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
785 data
[ICE_ETH_TEST_REG
] = 1;
786 data
[ICE_ETH_TEST_EEPROM
] = 1;
787 data
[ICE_ETH_TEST_INTR
] = 1;
788 data
[ICE_ETH_TEST_LOOP
] = 1;
789 data
[ICE_ETH_TEST_LINK
] = 1;
790 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
791 clear_bit(__ICE_TESTING
, pf
->state
);
794 /* If the device is online then take it offline */
796 /* indicate we're in test mode */
799 data
[ICE_ETH_TEST_LINK
] = ice_link_test(netdev
);
800 data
[ICE_ETH_TEST_EEPROM
] = ice_eeprom_test(netdev
);
801 data
[ICE_ETH_TEST_INTR
] = ice_intr_test(netdev
);
802 data
[ICE_ETH_TEST_LOOP
] = ice_loopback_test(netdev
);
803 data
[ICE_ETH_TEST_REG
] = ice_reg_test(netdev
);
805 if (data
[ICE_ETH_TEST_LINK
] ||
806 data
[ICE_ETH_TEST_EEPROM
] ||
807 data
[ICE_ETH_TEST_LOOP
] ||
808 data
[ICE_ETH_TEST_INTR
] ||
809 data
[ICE_ETH_TEST_REG
])
810 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
812 clear_bit(__ICE_TESTING
, pf
->state
);
815 int status
= ice_open(netdev
);
818 dev_err(&pf
->pdev
->dev
,
819 "Could not open device %s, err %d",
820 pf
->int_name
, status
);
825 netdev_info(netdev
, "online testing starting\n");
827 data
[ICE_ETH_TEST_LINK
] = ice_link_test(netdev
);
828 if (data
[ICE_ETH_TEST_LINK
])
829 eth_test
->flags
|= ETH_TEST_FL_FAILED
;
831 /* Offline only tests, not run in online; pass by default */
832 data
[ICE_ETH_TEST_REG
] = 0;
833 data
[ICE_ETH_TEST_EEPROM
] = 0;
834 data
[ICE_ETH_TEST_INTR
] = 0;
835 data
[ICE_ETH_TEST_LOOP
] = 0;
839 netdev_info(netdev
, "testing finished\n");
842 static void ice_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
844 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
845 struct ice_vsi
*vsi
= np
->vsi
;
846 char *p
= (char *)data
;
851 for (i
= 0; i
< ICE_VSI_STATS_LEN
; i
++) {
852 snprintf(p
, ETH_GSTRING_LEN
, "%s",
853 ice_gstrings_vsi_stats
[i
].stat_string
);
854 p
+= ETH_GSTRING_LEN
;
857 ice_for_each_alloc_txq(vsi
, i
) {
858 snprintf(p
, ETH_GSTRING_LEN
,
859 "tx_queue_%u_packets", i
);
860 p
+= ETH_GSTRING_LEN
;
861 snprintf(p
, ETH_GSTRING_LEN
, "tx_queue_%u_bytes", i
);
862 p
+= ETH_GSTRING_LEN
;
865 ice_for_each_alloc_rxq(vsi
, i
) {
866 snprintf(p
, ETH_GSTRING_LEN
,
867 "rx_queue_%u_packets", i
);
868 p
+= ETH_GSTRING_LEN
;
869 snprintf(p
, ETH_GSTRING_LEN
, "rx_queue_%u_bytes", i
);
870 p
+= ETH_GSTRING_LEN
;
873 if (vsi
->type
!= ICE_VSI_PF
)
876 for (i
= 0; i
< ICE_PF_STATS_LEN
; i
++) {
877 snprintf(p
, ETH_GSTRING_LEN
, "%s",
878 ice_gstrings_pf_stats
[i
].stat_string
);
879 p
+= ETH_GSTRING_LEN
;
882 for (i
= 0; i
< ICE_MAX_USER_PRIORITY
; i
++) {
883 snprintf(p
, ETH_GSTRING_LEN
,
884 "tx_priority_%u_xon.nic", i
);
885 p
+= ETH_GSTRING_LEN
;
886 snprintf(p
, ETH_GSTRING_LEN
,
887 "tx_priority_%u_xoff.nic", i
);
888 p
+= ETH_GSTRING_LEN
;
890 for (i
= 0; i
< ICE_MAX_USER_PRIORITY
; i
++) {
891 snprintf(p
, ETH_GSTRING_LEN
,
892 "rx_priority_%u_xon.nic", i
);
893 p
+= ETH_GSTRING_LEN
;
894 snprintf(p
, ETH_GSTRING_LEN
,
895 "rx_priority_%u_xoff.nic", i
);
896 p
+= ETH_GSTRING_LEN
;
900 memcpy(data
, ice_gstrings_test
, ICE_TEST_LEN
* ETH_GSTRING_LEN
);
902 case ETH_SS_PRIV_FLAGS
:
903 for (i
= 0; i
< ICE_PRIV_FLAG_ARRAY_SIZE
; i
++) {
904 snprintf(p
, ETH_GSTRING_LEN
, "%s",
905 ice_gstrings_priv_flags
[i
].name
);
906 p
+= ETH_GSTRING_LEN
;
915 ice_set_phys_id(struct net_device
*netdev
, enum ethtool_phys_id_state state
)
917 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
921 case ETHTOOL_ID_ACTIVE
:
924 case ETHTOOL_ID_INACTIVE
:
931 if (ice_aq_set_port_id_led(np
->vsi
->port_info
, !led_active
, NULL
))
938 * ice_set_fec_cfg - Set link FEC options
939 * @netdev: network interface device structure
940 * @req_fec: FEC mode to configure
942 static int ice_set_fec_cfg(struct net_device
*netdev
, enum ice_fec_mode req_fec
)
944 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
945 struct ice_aqc_set_phy_cfg_data config
= { 0 };
946 struct ice_aqc_get_phy_caps_data
*caps
;
947 struct ice_vsi
*vsi
= np
->vsi
;
948 u8 sw_cfg_caps
, sw_cfg_fec
;
949 struct ice_port_info
*pi
;
950 enum ice_status status
;
957 /* Changing the FEC parameters is not supported if not the PF VSI */
958 if (vsi
->type
!= ICE_VSI_PF
) {
959 netdev_info(netdev
, "Changing FEC parameters only supported for PF VSI\n");
963 /* Get last SW configuration */
964 caps
= devm_kzalloc(&vsi
->back
->pdev
->dev
, sizeof(*caps
), GFP_KERNEL
);
968 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
,
975 /* Copy SW configuration returned from PHY caps to PHY config */
976 ice_copy_phy_caps_to_cfg(caps
, &config
);
977 sw_cfg_caps
= caps
->caps
;
978 sw_cfg_fec
= caps
->link_fec_options
;
980 /* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
981 memset(caps
, 0, sizeof(*caps
));
983 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_TOPO_CAP
,
990 config
.caps
|= (caps
->caps
& ICE_AQC_PHY_EN_AUTO_FEC
);
991 config
.link_fec_opt
= caps
->link_fec_options
;
993 ice_cfg_phy_fec(&config
, req_fec
);
995 /* If FEC mode has changed, then set PHY configuration and enable AN. */
996 if ((config
.caps
& ICE_AQ_PHY_ENA_AUTO_FEC
) !=
997 (sw_cfg_caps
& ICE_AQC_PHY_EN_AUTO_FEC
) ||
998 config
.link_fec_opt
!= sw_cfg_fec
) {
999 if (caps
->caps
& ICE_AQC_PHY_AN_MODE
)
1000 config
.caps
|= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT
;
1002 status
= ice_aq_set_phy_cfg(pi
->hw
, pi
->lport
, &config
, NULL
);
1009 devm_kfree(&vsi
->back
->pdev
->dev
, caps
);
1014 * ice_set_fecparam - Set FEC link options
1015 * @netdev: network interface device structure
1016 * @fecparam: Ethtool structure to retrieve FEC parameters
1019 ice_set_fecparam(struct net_device
*netdev
, struct ethtool_fecparam
*fecparam
)
1021 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1022 struct ice_vsi
*vsi
= np
->vsi
;
1023 enum ice_fec_mode fec
;
1025 switch (fecparam
->fec
) {
1026 case ETHTOOL_FEC_AUTO
:
1029 case ETHTOOL_FEC_RS
:
1032 case ETHTOOL_FEC_BASER
:
1033 fec
= ICE_FEC_BASER
;
1035 case ETHTOOL_FEC_OFF
:
1036 case ETHTOOL_FEC_NONE
:
1040 dev_warn(&vsi
->back
->pdev
->dev
, "Unsupported FEC mode: %d\n",
1045 return ice_set_fec_cfg(netdev
, fec
);
1049 * ice_get_fecparam - Get link FEC options
1050 * @netdev: network interface device structure
1051 * @fecparam: Ethtool structure to retrieve FEC parameters
1054 ice_get_fecparam(struct net_device
*netdev
, struct ethtool_fecparam
*fecparam
)
1056 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1057 struct ice_aqc_get_phy_caps_data
*caps
;
1058 struct ice_link_status
*link_info
;
1059 struct ice_vsi
*vsi
= np
->vsi
;
1060 struct ice_port_info
*pi
;
1061 enum ice_status status
;
1064 pi
= vsi
->port_info
;
1068 link_info
= &pi
->phy
.link_info
;
1070 /* Set FEC mode based on negotiated link info */
1071 switch (link_info
->fec_info
) {
1072 case ICE_AQ_LINK_25G_KR_FEC_EN
:
1073 fecparam
->active_fec
= ETHTOOL_FEC_BASER
;
1075 case ICE_AQ_LINK_25G_RS_528_FEC_EN
:
1077 case ICE_AQ_LINK_25G_RS_544_FEC_EN
:
1078 fecparam
->active_fec
= ETHTOOL_FEC_RS
;
1081 fecparam
->active_fec
= ETHTOOL_FEC_OFF
;
1085 caps
= devm_kzalloc(&vsi
->back
->pdev
->dev
, sizeof(*caps
), GFP_KERNEL
);
1089 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_TOPO_CAP
,
1096 /* Set supported/configured FEC modes based on PHY capability */
1097 if (caps
->caps
& ICE_AQC_PHY_EN_AUTO_FEC
)
1098 fecparam
->fec
|= ETHTOOL_FEC_AUTO
;
1099 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN
||
1100 caps
->link_fec_options
& ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ
||
1101 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN
||
1102 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_KR_REQ
)
1103 fecparam
->fec
|= ETHTOOL_FEC_BASER
;
1104 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_528_REQ
||
1105 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_544_REQ
||
1106 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN
)
1107 fecparam
->fec
|= ETHTOOL_FEC_RS
;
1108 if (caps
->link_fec_options
== 0)
1109 fecparam
->fec
|= ETHTOOL_FEC_OFF
;
1112 devm_kfree(&vsi
->back
->pdev
->dev
, caps
);
1117 * ice_get_priv_flags - report device private flags
1118 * @netdev: network interface device structure
1120 * The get string set count and the string set should be matched for each
1121 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1124 * Returns a u32 bitmap of flags.
1126 static u32
ice_get_priv_flags(struct net_device
*netdev
)
1128 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1129 struct ice_vsi
*vsi
= np
->vsi
;
1130 struct ice_pf
*pf
= vsi
->back
;
1131 u32 i
, ret_flags
= 0;
1133 for (i
= 0; i
< ICE_PRIV_FLAG_ARRAY_SIZE
; i
++) {
1134 const struct ice_priv_flag
*priv_flag
;
1136 priv_flag
= &ice_gstrings_priv_flags
[i
];
1138 if (test_bit(priv_flag
->bitno
, pf
->flags
))
1139 ret_flags
|= BIT(i
);
1146 * ice_set_priv_flags - set private flags
1147 * @netdev: network interface device structure
1148 * @flags: bit flags to be set
1150 static int ice_set_priv_flags(struct net_device
*netdev
, u32 flags
)
1152 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1153 DECLARE_BITMAP(change_flags
, ICE_PF_FLAGS_NBITS
);
1154 DECLARE_BITMAP(orig_flags
, ICE_PF_FLAGS_NBITS
);
1155 struct ice_vsi
*vsi
= np
->vsi
;
1156 struct ice_pf
*pf
= vsi
->back
;
1160 if (flags
> BIT(ICE_PRIV_FLAG_ARRAY_SIZE
))
1163 set_bit(ICE_FLAG_ETHTOOL_CTXT
, pf
->flags
);
1165 bitmap_copy(orig_flags
, pf
->flags
, ICE_PF_FLAGS_NBITS
);
1166 for (i
= 0; i
< ICE_PRIV_FLAG_ARRAY_SIZE
; i
++) {
1167 const struct ice_priv_flag
*priv_flag
;
1169 priv_flag
= &ice_gstrings_priv_flags
[i
];
1172 set_bit(priv_flag
->bitno
, pf
->flags
);
1174 clear_bit(priv_flag
->bitno
, pf
->flags
);
1177 bitmap_xor(change_flags
, pf
->flags
, orig_flags
, ICE_PF_FLAGS_NBITS
);
1179 if (test_bit(ICE_FLAG_FW_LLDP_AGENT
, change_flags
)) {
1180 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT
, pf
->flags
)) {
1181 enum ice_status status
;
1183 /* Disable FW LLDP engine */
1184 status
= ice_cfg_lldp_mib_change(&pf
->hw
, false);
1186 /* If unregistering for LLDP events fails, this is
1187 * not an error state, as there shouldn't be any
1188 * events to respond to.
1191 dev_info(&pf
->pdev
->dev
,
1192 "Failed to unreg for LLDP events\n");
1194 /* The AQ call to stop the FW LLDP agent will generate
1195 * an error if the agent is already stopped.
1197 status
= ice_aq_stop_lldp(&pf
->hw
, true, true, NULL
);
1199 dev_warn(&pf
->pdev
->dev
,
1200 "Fail to stop LLDP agent\n");
1201 /* Use case for having the FW LLDP agent stopped
1202 * will likely not need DCB, so failure to init is
1203 * not a concern of ethtool
1205 status
= ice_init_pf_dcb(pf
, true);
1207 dev_warn(&pf
->pdev
->dev
, "Fail to init DCB\n");
1209 /* Forward LLDP packets to default VSI so that they
1210 * are passed up the stack
1212 ice_cfg_sw_lldp(vsi
, false, true);
1214 enum ice_status status
;
1215 bool dcbx_agent_status
;
1217 /* AQ command to start FW LLDP agent will return an
1218 * error if the agent is already started
1220 status
= ice_aq_start_lldp(&pf
->hw
, true, NULL
);
1222 dev_warn(&pf
->pdev
->dev
,
1223 "Fail to start LLDP Agent\n");
1225 /* AQ command to start FW DCBX agent will fail if
1226 * the agent is already started
1228 status
= ice_aq_start_stop_dcbx(&pf
->hw
, true,
1232 dev_dbg(&pf
->pdev
->dev
,
1233 "Failed to start FW DCBX\n");
1235 dev_info(&pf
->pdev
->dev
, "FW DCBX agent is %s\n",
1236 dcbx_agent_status
? "ACTIVE" : "DISABLED");
1238 /* Failure to configure MIB change or init DCB is not
1239 * relevant to ethtool. Print notification that
1240 * registration/init failed but do not return error
1243 status
= ice_init_pf_dcb(pf
, true);
1245 dev_dbg(&pf
->pdev
->dev
, "Fail to init DCB\n");
1247 /* Remove rule to direct LLDP packets to default VSI.
1248 * The FW LLDP engine will now be consuming them.
1250 ice_cfg_sw_lldp(vsi
, false, false);
1252 /* Register for MIB change events */
1253 status
= ice_cfg_lldp_mib_change(&pf
->hw
, true);
1255 dev_dbg(&pf
->pdev
->dev
,
1256 "Fail to enable MIB change events\n");
1259 clear_bit(ICE_FLAG_ETHTOOL_CTXT
, pf
->flags
);
1263 static int ice_get_sset_count(struct net_device
*netdev
, int sset
)
1267 /* The number (and order) of strings reported *must* remain
1268 * constant for a given netdevice. This function must not
1269 * report a different number based on run time parameters
1270 * (such as the number of queues in use, or the setting of
1271 * a private ethtool flag). This is due to the nature of the
1272 * ethtool stats API.
1274 * Userspace programs such as ethtool must make 3 separate
1275 * ioctl requests, one for size, one for the strings, and
1276 * finally one for the stats. Since these cross into
1277 * userspace, changes to the number or size could result in
1278 * undefined memory access or incorrect string<->value
1279 * correlations for statistics.
1281 * Even if it appears to be safe, changes to the size or
1282 * order of strings will suffer from race conditions and are
1285 return ICE_ALL_STATS_LEN(netdev
);
1287 return ICE_TEST_LEN
;
1288 case ETH_SS_PRIV_FLAGS
:
1289 return ICE_PRIV_FLAG_ARRAY_SIZE
;
1296 ice_get_ethtool_stats(struct net_device
*netdev
,
1297 struct ethtool_stats __always_unused
*stats
, u64
*data
)
1299 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1300 struct ice_vsi
*vsi
= np
->vsi
;
1301 struct ice_pf
*pf
= vsi
->back
;
1302 struct ice_ring
*ring
;
1307 ice_update_pf_stats(pf
);
1308 ice_update_vsi_stats(vsi
);
1310 for (j
= 0; j
< ICE_VSI_STATS_LEN
; j
++) {
1311 p
= (char *)vsi
+ ice_gstrings_vsi_stats
[j
].stat_offset
;
1312 data
[i
++] = (ice_gstrings_vsi_stats
[j
].sizeof_stat
==
1313 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1316 /* populate per queue stats */
1319 ice_for_each_alloc_txq(vsi
, j
) {
1320 ring
= READ_ONCE(vsi
->tx_rings
[j
]);
1322 data
[i
++] = ring
->stats
.pkts
;
1323 data
[i
++] = ring
->stats
.bytes
;
1330 ice_for_each_alloc_rxq(vsi
, j
) {
1331 ring
= READ_ONCE(vsi
->rx_rings
[j
]);
1333 data
[i
++] = ring
->stats
.pkts
;
1334 data
[i
++] = ring
->stats
.bytes
;
1343 if (vsi
->type
!= ICE_VSI_PF
)
1346 for (j
= 0; j
< ICE_PF_STATS_LEN
; j
++) {
1347 p
= (char *)pf
+ ice_gstrings_pf_stats
[j
].stat_offset
;
1348 data
[i
++] = (ice_gstrings_pf_stats
[j
].sizeof_stat
==
1349 sizeof(u64
)) ? *(u64
*)p
: *(u32
*)p
;
1352 for (j
= 0; j
< ICE_MAX_USER_PRIORITY
; j
++) {
1353 data
[i
++] = pf
->stats
.priority_xon_tx
[j
];
1354 data
[i
++] = pf
->stats
.priority_xoff_tx
[j
];
1357 for (j
= 0; j
< ICE_MAX_USER_PRIORITY
; j
++) {
1358 data
[i
++] = pf
->stats
.priority_xon_rx
[j
];
1359 data
[i
++] = pf
->stats
.priority_xoff_rx
[j
];
1364 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1365 * @netdev: network interface device structure
1366 * @ks: ethtool link ksettings struct to fill out
1369 ice_phy_type_to_ethtool(struct net_device
*netdev
,
1370 struct ethtool_link_ksettings
*ks
)
1372 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1373 struct ice_link_status
*hw_link_info
;
1374 bool need_add_adv_mode
= false;
1375 struct ice_vsi
*vsi
= np
->vsi
;
1379 hw_link_info
= &vsi
->port_info
->phy
.link_info
;
1380 phy_types_low
= vsi
->port_info
->phy
.phy_type_low
;
1381 phy_types_high
= vsi
->port_info
->phy
.phy_type_high
;
1383 ethtool_link_ksettings_zero_link_mode(ks
, supported
);
1384 ethtool_link_ksettings_zero_link_mode(ks
, advertising
);
1386 if (phy_types_low
& ICE_PHY_TYPE_LOW_100BASE_TX
||
1387 phy_types_low
& ICE_PHY_TYPE_LOW_100M_SGMII
) {
1388 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1390 if (!hw_link_info
->req_speeds
||
1391 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_100MB
)
1392 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1395 if (phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_T
||
1396 phy_types_low
& ICE_PHY_TYPE_LOW_1G_SGMII
) {
1397 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1399 if (!hw_link_info
->req_speeds
||
1400 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_1000MB
)
1401 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1404 if (phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_KX
) {
1405 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1407 if (!hw_link_info
->req_speeds
||
1408 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_1000MB
)
1409 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1412 if (phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_SX
||
1413 phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_LX
) {
1414 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1416 if (!hw_link_info
->req_speeds
||
1417 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_1000MB
)
1418 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1421 if (phy_types_low
& ICE_PHY_TYPE_LOW_2500BASE_T
) {
1422 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1424 if (!hw_link_info
->req_speeds
||
1425 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_2500MB
)
1426 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1429 if (phy_types_low
& ICE_PHY_TYPE_LOW_2500BASE_X
||
1430 phy_types_low
& ICE_PHY_TYPE_LOW_2500BASE_KX
) {
1431 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1433 if (!hw_link_info
->req_speeds
||
1434 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_2500MB
)
1435 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1438 if (phy_types_low
& ICE_PHY_TYPE_LOW_5GBASE_T
||
1439 phy_types_low
& ICE_PHY_TYPE_LOW_5GBASE_KR
) {
1440 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1442 if (!hw_link_info
->req_speeds
||
1443 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_5GB
)
1444 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1447 if (phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_T
||
1448 phy_types_low
& ICE_PHY_TYPE_LOW_10G_SFI_DA
||
1449 phy_types_low
& ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC
||
1450 phy_types_low
& ICE_PHY_TYPE_LOW_10G_SFI_C2C
) {
1451 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1453 if (!hw_link_info
->req_speeds
||
1454 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_10GB
)
1455 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1458 if (phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_KR_CR1
) {
1459 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1461 if (!hw_link_info
->req_speeds
||
1462 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_10GB
)
1463 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1466 if (phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_SR
) {
1467 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1469 if (!hw_link_info
->req_speeds
||
1470 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_10GB
)
1471 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1474 if (phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_LR
) {
1475 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1477 if (!hw_link_info
->req_speeds
||
1478 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_10GB
)
1479 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1482 if (phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_T
||
1483 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR
||
1484 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR_S
||
1485 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR1
||
1486 phy_types_low
& ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC
||
1487 phy_types_low
& ICE_PHY_TYPE_LOW_25G_AUI_C2C
) {
1488 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1490 if (!hw_link_info
->req_speeds
||
1491 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_25GB
)
1492 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1495 if (phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_SR
||
1496 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_LR
) {
1497 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1499 if (!hw_link_info
->req_speeds
||
1500 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_25GB
)
1501 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1504 if (phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR
||
1505 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR_S
||
1506 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR1
) {
1507 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1509 if (!hw_link_info
->req_speeds
||
1510 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_25GB
)
1511 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1514 if (phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_KR4
) {
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_40GB
)
1519 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1522 if (phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_CR4
||
1523 phy_types_low
& ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC
||
1524 phy_types_low
& ICE_PHY_TYPE_LOW_40G_XLAUI
) {
1525 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1527 if (!hw_link_info
->req_speeds
||
1528 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_40GB
)
1529 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1532 if (phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_SR4
) {
1533 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1535 if (!hw_link_info
->req_speeds
||
1536 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_40GB
)
1537 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1540 if (phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_LR4
) {
1541 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1543 if (!hw_link_info
->req_speeds
||
1544 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_40GB
)
1545 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1548 if (phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_CR2
||
1549 phy_types_low
& ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC
||
1550 phy_types_low
& ICE_PHY_TYPE_LOW_50G_LAUI2
||
1551 phy_types_low
& ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC
||
1552 phy_types_low
& ICE_PHY_TYPE_LOW_50G_AUI2
||
1553 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_CP
||
1554 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_SR
||
1555 phy_types_low
& ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC
||
1556 phy_types_low
& ICE_PHY_TYPE_LOW_50G_AUI1
) {
1557 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1559 if (!hw_link_info
->req_speeds
||
1560 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_50GB
)
1561 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1564 if (phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_KR2
||
1565 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4
) {
1566 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1568 if (!hw_link_info
->req_speeds
||
1569 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_50GB
)
1570 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1573 if (phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_SR2
||
1574 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_LR2
||
1575 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_FR
||
1576 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_LR
) {
1577 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1579 if (!hw_link_info
->req_speeds
||
1580 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_50GB
)
1581 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1584 if (phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_CR4
||
1585 phy_types_low
& ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC
||
1586 phy_types_low
& ICE_PHY_TYPE_LOW_100G_CAUI4
||
1587 phy_types_low
& ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC
||
1588 phy_types_low
& ICE_PHY_TYPE_LOW_100G_AUI4
||
1589 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4
||
1590 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_CP2
||
1591 phy_types_high
& ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC
||
1592 phy_types_high
& ICE_PHY_TYPE_HIGH_100G_CAUI2
||
1593 phy_types_high
& ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC
||
1594 phy_types_high
& ICE_PHY_TYPE_HIGH_100G_AUI2
) {
1595 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1596 100000baseCR4_Full
);
1597 if (!hw_link_info
->req_speeds
||
1598 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_100GB
)
1599 need_add_adv_mode
= true;
1601 if (need_add_adv_mode
) {
1602 need_add_adv_mode
= false;
1603 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1604 100000baseCR4_Full
);
1606 if (phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_SR4
||
1607 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_SR2
) {
1608 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1609 100000baseSR4_Full
);
1610 if (!hw_link_info
->req_speeds
||
1611 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_100GB
)
1612 need_add_adv_mode
= true;
1614 if (need_add_adv_mode
) {
1615 need_add_adv_mode
= false;
1616 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1617 100000baseSR4_Full
);
1619 if (phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_LR4
||
1620 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_DR
) {
1621 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1622 100000baseLR4_ER4_Full
);
1623 if (!hw_link_info
->req_speeds
||
1624 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_100GB
)
1625 need_add_adv_mode
= true;
1627 if (need_add_adv_mode
) {
1628 need_add_adv_mode
= false;
1629 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1630 100000baseLR4_ER4_Full
);
1632 if (phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_KR4
||
1633 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4
||
1634 phy_types_high
& ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4
) {
1635 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1636 100000baseKR4_Full
);
1637 if (!hw_link_info
->req_speeds
||
1638 hw_link_info
->req_speeds
& ICE_AQ_LINK_SPEED_100GB
)
1639 need_add_adv_mode
= true;
1641 if (need_add_adv_mode
)
1642 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1643 100000baseKR4_Full
);
1645 /* Autoneg PHY types */
1646 if (phy_types_low
& ICE_PHY_TYPE_LOW_100BASE_TX
||
1647 phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_T
||
1648 phy_types_low
& ICE_PHY_TYPE_LOW_1000BASE_KX
||
1649 phy_types_low
& ICE_PHY_TYPE_LOW_2500BASE_T
||
1650 phy_types_low
& ICE_PHY_TYPE_LOW_2500BASE_KX
||
1651 phy_types_low
& ICE_PHY_TYPE_LOW_5GBASE_T
||
1652 phy_types_low
& ICE_PHY_TYPE_LOW_5GBASE_KR
||
1653 phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_T
||
1654 phy_types_low
& ICE_PHY_TYPE_LOW_10GBASE_KR_CR1
||
1655 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_T
||
1656 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR
||
1657 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR_S
||
1658 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_CR1
||
1659 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR
||
1660 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR_S
||
1661 phy_types_low
& ICE_PHY_TYPE_LOW_25GBASE_KR1
||
1662 phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_CR4
||
1663 phy_types_low
& ICE_PHY_TYPE_LOW_40GBASE_KR4
) {
1664 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1666 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1669 if (phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_CR2
||
1670 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_KR2
||
1671 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_CP
||
1672 phy_types_low
& ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4
) {
1673 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1675 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1678 if (phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_CR4
||
1679 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_KR4
||
1680 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4
||
1681 phy_types_low
& ICE_PHY_TYPE_LOW_100GBASE_CP2
) {
1682 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1684 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1689 #define TEST_SET_BITS_TIMEOUT 50
1690 #define TEST_SET_BITS_SLEEP_MAX 2000
1691 #define TEST_SET_BITS_SLEEP_MIN 1000
1694 * ice_get_settings_link_up - Get Link settings for when link is up
1695 * @ks: ethtool ksettings to fill in
1696 * @netdev: network interface device structure
1699 ice_get_settings_link_up(struct ethtool_link_ksettings
*ks
,
1700 struct net_device
*netdev
)
1702 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
1703 struct ice_port_info
*pi
= np
->vsi
->port_info
;
1704 struct ethtool_link_ksettings cap_ksettings
;
1705 struct ice_link_status
*link_info
;
1706 struct ice_vsi
*vsi
= np
->vsi
;
1707 bool unrecog_phy_high
= false;
1708 bool unrecog_phy_low
= false;
1710 link_info
= &vsi
->port_info
->phy
.link_info
;
1712 /* Initialize supported and advertised settings based on PHY settings */
1713 switch (link_info
->phy_type_low
) {
1714 case ICE_PHY_TYPE_LOW_100BASE_TX
:
1715 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1716 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1718 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1719 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1722 case ICE_PHY_TYPE_LOW_100M_SGMII
:
1723 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1726 case ICE_PHY_TYPE_LOW_1000BASE_T
:
1727 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1728 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1730 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1731 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1734 case ICE_PHY_TYPE_LOW_1G_SGMII
:
1735 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1738 case ICE_PHY_TYPE_LOW_1000BASE_SX
:
1739 case ICE_PHY_TYPE_LOW_1000BASE_LX
:
1740 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1743 case ICE_PHY_TYPE_LOW_1000BASE_KX
:
1744 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1745 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1747 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1748 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1751 case ICE_PHY_TYPE_LOW_2500BASE_T
:
1752 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1753 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1754 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1756 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1759 case ICE_PHY_TYPE_LOW_2500BASE_X
:
1760 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1763 case ICE_PHY_TYPE_LOW_2500BASE_KX
:
1764 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1765 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1767 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1768 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1771 case ICE_PHY_TYPE_LOW_5GBASE_T
:
1772 case ICE_PHY_TYPE_LOW_5GBASE_KR
:
1773 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1774 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1776 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1777 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1780 case ICE_PHY_TYPE_LOW_10GBASE_T
:
1781 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1782 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1784 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1785 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1788 case ICE_PHY_TYPE_LOW_10G_SFI_DA
:
1789 case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC
:
1790 case ICE_PHY_TYPE_LOW_10G_SFI_C2C
:
1791 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1794 case ICE_PHY_TYPE_LOW_10GBASE_SR
:
1795 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1798 case ICE_PHY_TYPE_LOW_10GBASE_LR
:
1799 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1802 case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1
:
1803 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1804 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1806 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1807 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1810 case ICE_PHY_TYPE_LOW_25GBASE_T
:
1811 case ICE_PHY_TYPE_LOW_25GBASE_CR
:
1812 case ICE_PHY_TYPE_LOW_25GBASE_CR_S
:
1813 case ICE_PHY_TYPE_LOW_25GBASE_CR1
:
1814 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1815 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1817 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1818 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1821 case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC
:
1822 case ICE_PHY_TYPE_LOW_25G_AUI_C2C
:
1823 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1826 case ICE_PHY_TYPE_LOW_25GBASE_SR
:
1827 case ICE_PHY_TYPE_LOW_25GBASE_LR
:
1828 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1831 case ICE_PHY_TYPE_LOW_25GBASE_KR
:
1832 case ICE_PHY_TYPE_LOW_25GBASE_KR1
:
1833 case ICE_PHY_TYPE_LOW_25GBASE_KR_S
:
1834 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1835 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1837 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1838 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1841 case ICE_PHY_TYPE_LOW_40GBASE_CR4
:
1842 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1843 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1845 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1846 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1849 case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC
:
1850 case ICE_PHY_TYPE_LOW_40G_XLAUI
:
1851 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1854 case ICE_PHY_TYPE_LOW_40GBASE_SR4
:
1855 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1858 case ICE_PHY_TYPE_LOW_40GBASE_LR4
:
1859 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1862 case ICE_PHY_TYPE_LOW_40GBASE_KR4
:
1863 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1864 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1866 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1867 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1870 case ICE_PHY_TYPE_LOW_50GBASE_CR2
:
1871 case ICE_PHY_TYPE_LOW_50GBASE_CP
:
1872 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1873 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1875 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1876 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1879 case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC
:
1880 case ICE_PHY_TYPE_LOW_50G_LAUI2
:
1881 case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC
:
1882 case ICE_PHY_TYPE_LOW_50G_AUI2
:
1883 case ICE_PHY_TYPE_LOW_50GBASE_SR
:
1884 case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC
:
1885 case ICE_PHY_TYPE_LOW_50G_AUI1
:
1886 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1889 case ICE_PHY_TYPE_LOW_50GBASE_KR2
:
1890 case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4
:
1891 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1892 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1894 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1895 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1898 case ICE_PHY_TYPE_LOW_50GBASE_SR2
:
1899 case ICE_PHY_TYPE_LOW_50GBASE_LR2
:
1900 case ICE_PHY_TYPE_LOW_50GBASE_FR
:
1901 case ICE_PHY_TYPE_LOW_50GBASE_LR
:
1902 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1905 case ICE_PHY_TYPE_LOW_100GBASE_CR4
:
1906 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1907 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1908 100000baseCR4_Full
);
1909 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1910 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1911 100000baseCR4_Full
);
1913 case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC
:
1914 case ICE_PHY_TYPE_LOW_100G_CAUI4
:
1915 case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC
:
1916 case ICE_PHY_TYPE_LOW_100G_AUI4
:
1917 case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4
:
1918 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1919 100000baseCR4_Full
);
1921 case ICE_PHY_TYPE_LOW_100GBASE_CP2
:
1922 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1923 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1924 100000baseCR4_Full
);
1925 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1926 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1927 100000baseCR4_Full
);
1929 case ICE_PHY_TYPE_LOW_100GBASE_SR4
:
1930 case ICE_PHY_TYPE_LOW_100GBASE_SR2
:
1931 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1932 100000baseSR4_Full
);
1934 case ICE_PHY_TYPE_LOW_100GBASE_LR4
:
1935 case ICE_PHY_TYPE_LOW_100GBASE_DR
:
1936 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1937 100000baseLR4_ER4_Full
);
1939 case ICE_PHY_TYPE_LOW_100GBASE_KR4
:
1940 case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4
:
1941 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1942 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1943 100000baseKR4_Full
);
1944 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1945 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1946 100000baseKR4_Full
);
1949 unrecog_phy_low
= true;
1952 switch (link_info
->phy_type_high
) {
1953 case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4
:
1954 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
1955 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1956 100000baseKR4_Full
);
1957 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
1958 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
1959 100000baseKR4_Full
);
1961 case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC
:
1962 case ICE_PHY_TYPE_HIGH_100G_CAUI2
:
1963 case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC
:
1964 case ICE_PHY_TYPE_HIGH_100G_AUI2
:
1965 ethtool_link_ksettings_add_link_mode(ks
, supported
,
1966 100000baseCR4_Full
);
1969 unrecog_phy_high
= true;
1972 if (unrecog_phy_low
&& unrecog_phy_high
) {
1973 /* if we got here and link is up something bad is afoot */
1975 "WARNING: Unrecognized PHY_Low (0x%llx).\n",
1976 (u64
)link_info
->phy_type_low
);
1978 "WARNING: Unrecognized PHY_High (0x%llx).\n",
1979 (u64
)link_info
->phy_type_high
);
1982 /* Now that we've worked out everything that could be supported by the
1983 * current PHY type, get what is supported by the NVM and intersect
1984 * them to get what is truly supported
1986 memset(&cap_ksettings
, 0, sizeof(cap_ksettings
));
1987 ice_phy_type_to_ethtool(netdev
, &cap_ksettings
);
1988 ethtool_intersect_link_masks(ks
, &cap_ksettings
);
1990 switch (link_info
->link_speed
) {
1991 case ICE_AQ_LINK_SPEED_100GB
:
1992 ks
->base
.speed
= SPEED_100000
;
1994 case ICE_AQ_LINK_SPEED_50GB
:
1995 ks
->base
.speed
= SPEED_50000
;
1997 case ICE_AQ_LINK_SPEED_40GB
:
1998 ks
->base
.speed
= SPEED_40000
;
2000 case ICE_AQ_LINK_SPEED_25GB
:
2001 ks
->base
.speed
= SPEED_25000
;
2003 case ICE_AQ_LINK_SPEED_20GB
:
2004 ks
->base
.speed
= SPEED_20000
;
2006 case ICE_AQ_LINK_SPEED_10GB
:
2007 ks
->base
.speed
= SPEED_10000
;
2009 case ICE_AQ_LINK_SPEED_5GB
:
2010 ks
->base
.speed
= SPEED_5000
;
2012 case ICE_AQ_LINK_SPEED_2500MB
:
2013 ks
->base
.speed
= SPEED_2500
;
2015 case ICE_AQ_LINK_SPEED_1000MB
:
2016 ks
->base
.speed
= SPEED_1000
;
2018 case ICE_AQ_LINK_SPEED_100MB
:
2019 ks
->base
.speed
= SPEED_100
;
2023 "WARNING: Unrecognized link_speed (0x%x).\n",
2024 link_info
->link_speed
);
2027 ks
->base
.duplex
= DUPLEX_FULL
;
2029 if (link_info
->an_info
& ICE_AQ_AN_COMPLETED
)
2030 ethtool_link_ksettings_add_link_mode(ks
, lp_advertising
,
2033 /* Set flow control negotiated Rx/Tx pause */
2034 switch (pi
->fc
.current_mode
) {
2036 ethtool_link_ksettings_add_link_mode(ks
, lp_advertising
, Pause
);
2038 case ICE_FC_TX_PAUSE
:
2039 ethtool_link_ksettings_add_link_mode(ks
, lp_advertising
, Pause
);
2040 ethtool_link_ksettings_add_link_mode(ks
, lp_advertising
,
2043 case ICE_FC_RX_PAUSE
:
2044 ethtool_link_ksettings_add_link_mode(ks
, lp_advertising
,
2050 ethtool_link_ksettings_del_link_mode(ks
, lp_advertising
, Pause
);
2051 ethtool_link_ksettings_del_link_mode(ks
, lp_advertising
,
2058 * ice_get_settings_link_down - Get the Link settings when link is down
2059 * @ks: ethtool ksettings to fill in
2060 * @netdev: network interface device structure
2062 * Reports link settings that can be determined when link is down
2065 ice_get_settings_link_down(struct ethtool_link_ksettings
*ks
,
2066 struct net_device
*netdev
)
2068 /* link is down and the driver needs to fall back on
2069 * supported PHY types to figure out what info to display
2071 ice_phy_type_to_ethtool(netdev
, ks
);
2073 /* With no link, speed and duplex are unknown */
2074 ks
->base
.speed
= SPEED_UNKNOWN
;
2075 ks
->base
.duplex
= DUPLEX_UNKNOWN
;
2079 * ice_get_link_ksettings - Get Link Speed and Duplex settings
2080 * @netdev: network interface device structure
2081 * @ks: ethtool ksettings
2083 * Reports speed/duplex settings based on media_type
2086 ice_get_link_ksettings(struct net_device
*netdev
,
2087 struct ethtool_link_ksettings
*ks
)
2089 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2090 struct ice_aqc_get_phy_caps_data
*caps
;
2091 struct ice_link_status
*hw_link_info
;
2092 struct ice_vsi
*vsi
= np
->vsi
;
2093 enum ice_status status
;
2096 ethtool_link_ksettings_zero_link_mode(ks
, supported
);
2097 ethtool_link_ksettings_zero_link_mode(ks
, advertising
);
2098 ethtool_link_ksettings_zero_link_mode(ks
, lp_advertising
);
2099 hw_link_info
= &vsi
->port_info
->phy
.link_info
;
2101 /* set speed and duplex */
2102 if (hw_link_info
->link_info
& ICE_AQ_LINK_UP
)
2103 ice_get_settings_link_up(ks
, netdev
);
2105 ice_get_settings_link_down(ks
, netdev
);
2107 /* set autoneg settings */
2108 ks
->base
.autoneg
= (hw_link_info
->an_info
& ICE_AQ_AN_COMPLETED
) ?
2109 AUTONEG_ENABLE
: AUTONEG_DISABLE
;
2111 /* set media type settings */
2112 switch (vsi
->port_info
->phy
.media_type
) {
2113 case ICE_MEDIA_FIBER
:
2114 ethtool_link_ksettings_add_link_mode(ks
, supported
, FIBRE
);
2115 ks
->base
.port
= PORT_FIBRE
;
2117 case ICE_MEDIA_BASET
:
2118 ethtool_link_ksettings_add_link_mode(ks
, supported
, TP
);
2119 ethtool_link_ksettings_add_link_mode(ks
, advertising
, TP
);
2120 ks
->base
.port
= PORT_TP
;
2122 case ICE_MEDIA_BACKPLANE
:
2123 ethtool_link_ksettings_add_link_mode(ks
, supported
, Autoneg
);
2124 ethtool_link_ksettings_add_link_mode(ks
, supported
, Backplane
);
2125 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Autoneg
);
2126 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
2128 ks
->base
.port
= PORT_NONE
;
2131 ethtool_link_ksettings_add_link_mode(ks
, supported
, FIBRE
);
2132 ethtool_link_ksettings_add_link_mode(ks
, advertising
, FIBRE
);
2133 ks
->base
.port
= PORT_DA
;
2136 ks
->base
.port
= PORT_OTHER
;
2140 /* flow control is symmetric and always supported */
2141 ethtool_link_ksettings_add_link_mode(ks
, supported
, Pause
);
2143 caps
= devm_kzalloc(&vsi
->back
->pdev
->dev
, sizeof(*caps
), GFP_KERNEL
);
2147 status
= ice_aq_get_phy_caps(vsi
->port_info
, false,
2148 ICE_AQC_REPORT_SW_CFG
, caps
, NULL
);
2154 /* Set the advertised flow control based on the PHY capability */
2155 if ((caps
->caps
& ICE_AQC_PHY_EN_TX_LINK_PAUSE
) &&
2156 (caps
->caps
& ICE_AQC_PHY_EN_RX_LINK_PAUSE
)) {
2157 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Pause
);
2158 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
2160 } else if (caps
->caps
& ICE_AQC_PHY_EN_TX_LINK_PAUSE
) {
2161 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
2163 } else if (caps
->caps
& ICE_AQC_PHY_EN_RX_LINK_PAUSE
) {
2164 ethtool_link_ksettings_add_link_mode(ks
, advertising
, Pause
);
2165 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
2168 ethtool_link_ksettings_del_link_mode(ks
, advertising
, Pause
);
2169 ethtool_link_ksettings_del_link_mode(ks
, advertising
,
2173 /* Set advertised FEC modes based on PHY capability */
2174 ethtool_link_ksettings_add_link_mode(ks
, advertising
, FEC_NONE
);
2176 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ
||
2177 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_KR_REQ
)
2178 ethtool_link_ksettings_add_link_mode(ks
, advertising
,
2180 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_528_REQ
||
2181 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_544_REQ
)
2182 ethtool_link_ksettings_add_link_mode(ks
, advertising
, FEC_RS
);
2184 status
= ice_aq_get_phy_caps(vsi
->port_info
, false,
2185 ICE_AQC_REPORT_TOPO_CAP
, caps
, NULL
);
2191 /* Set supported FEC modes based on PHY capability */
2192 ethtool_link_ksettings_add_link_mode(ks
, supported
, FEC_NONE
);
2194 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN
||
2195 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN
)
2196 ethtool_link_ksettings_add_link_mode(ks
, supported
, FEC_BASER
);
2197 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN
)
2198 ethtool_link_ksettings_add_link_mode(ks
, supported
, FEC_RS
);
2201 devm_kfree(&vsi
->back
->pdev
->dev
, caps
);
2206 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2207 * @ks: ethtool ksettings
2210 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings
*ks
)
2212 u16 adv_link_speed
= 0;
2214 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2216 adv_link_speed
|= ICE_AQ_LINK_SPEED_100MB
;
2217 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2219 adv_link_speed
|= ICE_AQ_LINK_SPEED_1000MB
;
2220 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2222 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2224 adv_link_speed
|= ICE_AQ_LINK_SPEED_1000MB
;
2225 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2227 adv_link_speed
|= ICE_AQ_LINK_SPEED_2500MB
;
2228 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2230 adv_link_speed
|= ICE_AQ_LINK_SPEED_2500MB
;
2231 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2233 adv_link_speed
|= ICE_AQ_LINK_SPEED_5GB
;
2234 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2236 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2238 adv_link_speed
|= ICE_AQ_LINK_SPEED_10GB
;
2239 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2240 10000baseSR_Full
) ||
2241 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2243 adv_link_speed
|= ICE_AQ_LINK_SPEED_10GB
;
2244 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2245 25000baseCR_Full
) ||
2246 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2247 25000baseSR_Full
) ||
2248 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2250 adv_link_speed
|= ICE_AQ_LINK_SPEED_25GB
;
2251 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2252 40000baseCR4_Full
) ||
2253 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2254 40000baseSR4_Full
) ||
2255 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2256 40000baseLR4_Full
) ||
2257 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2259 adv_link_speed
|= ICE_AQ_LINK_SPEED_40GB
;
2260 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2261 50000baseCR2_Full
) ||
2262 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2264 adv_link_speed
|= ICE_AQ_LINK_SPEED_50GB
;
2265 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2267 adv_link_speed
|= ICE_AQ_LINK_SPEED_50GB
;
2268 if (ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2269 100000baseCR4_Full
) ||
2270 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2271 100000baseSR4_Full
) ||
2272 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2273 100000baseLR4_ER4_Full
) ||
2274 ethtool_link_ksettings_test_link_mode(ks
, advertising
,
2275 100000baseKR4_Full
))
2276 adv_link_speed
|= ICE_AQ_LINK_SPEED_100GB
;
2278 return adv_link_speed
;
2284 * @ks: ethtool_link_ksettings
2285 * @config: configuration that will be sent down to FW
2286 * @autoneg_enabled: autonegotiation is enabled or not
2287 * @autoneg_changed: will there a change in autonegotiation
2288 * @netdev: network interface device structure
2290 * Setup PHY autonegotiation feature
2293 ice_setup_autoneg(struct ice_port_info
*p
, struct ethtool_link_ksettings
*ks
,
2294 struct ice_aqc_set_phy_cfg_data
*config
,
2295 u8 autoneg_enabled
, u8
*autoneg_changed
,
2296 struct net_device
*netdev
)
2300 *autoneg_changed
= 0;
2303 if (autoneg_enabled
== AUTONEG_ENABLE
) {
2304 /* If autoneg was not already enabled */
2305 if (!(p
->phy
.link_info
.an_info
& ICE_AQ_AN_COMPLETED
)) {
2306 /* If autoneg is not supported, return error */
2307 if (!ethtool_link_ksettings_test_link_mode(ks
,
2310 netdev_info(netdev
, "Autoneg not supported on this phy.\n");
2313 /* Autoneg is allowed to change */
2314 config
->caps
|= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT
;
2315 *autoneg_changed
= 1;
2319 /* If autoneg is currently enabled */
2320 if (p
->phy
.link_info
.an_info
& ICE_AQ_AN_COMPLETED
) {
2321 /* If autoneg is supported 10GBASE_T is the only PHY
2322 * that can disable it, so otherwise return error
2324 if (ethtool_link_ksettings_test_link_mode(ks
,
2327 netdev_info(netdev
, "Autoneg cannot be disabled on this phy\n");
2330 /* Autoneg is allowed to change */
2331 config
->caps
&= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT
;
2332 *autoneg_changed
= 1;
2341 * ice_set_link_ksettings - Set Speed and Duplex
2342 * @netdev: network interface device structure
2343 * @ks: ethtool ksettings
2345 * Set speed/duplex per media_types advertised/forced
2348 ice_set_link_ksettings(struct net_device
*netdev
,
2349 const struct ethtool_link_ksettings
*ks
)
2351 u8 autoneg
, timeout
= TEST_SET_BITS_TIMEOUT
, lport
= 0;
2352 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2353 struct ethtool_link_ksettings safe_ks
, copy_ks
;
2354 struct ice_aqc_get_phy_caps_data
*abilities
;
2355 u16 adv_link_speed
, curr_link_speed
, idx
;
2356 struct ice_aqc_set_phy_cfg_data config
;
2357 struct ice_pf
*pf
= np
->vsi
->back
;
2358 struct ice_port_info
*p
;
2359 u8 autoneg_changed
= 0;
2360 enum ice_status status
;
2366 p
= np
->vsi
->port_info
;
2371 /* Check if this is LAN VSI */
2372 ice_for_each_vsi(pf
, idx
)
2373 if (pf
->vsi
[idx
]->type
== ICE_VSI_PF
) {
2374 if (np
->vsi
!= pf
->vsi
[idx
])
2379 if (p
->phy
.media_type
!= ICE_MEDIA_BASET
&&
2380 p
->phy
.media_type
!= ICE_MEDIA_FIBER
&&
2381 p
->phy
.media_type
!= ICE_MEDIA_BACKPLANE
&&
2382 p
->phy
.media_type
!= ICE_MEDIA_DA
&&
2383 p
->phy
.link_info
.link_info
& ICE_AQ_LINK_UP
)
2386 /* copy the ksettings to copy_ks to avoid modifying the original */
2387 memcpy(©_ks
, ks
, sizeof(copy_ks
));
2389 /* save autoneg out of ksettings */
2390 autoneg
= copy_ks
.base
.autoneg
;
2392 memset(&safe_ks
, 0, sizeof(safe_ks
));
2394 /* Get link modes supported by hardware.*/
2395 ice_phy_type_to_ethtool(netdev
, &safe_ks
);
2397 /* and check against modes requested by user.
2398 * Return an error if unsupported mode was set.
2400 if (!bitmap_subset(copy_ks
.link_modes
.advertising
,
2401 safe_ks
.link_modes
.supported
,
2402 __ETHTOOL_LINK_MODE_MASK_NBITS
))
2405 /* get our own copy of the bits to check against */
2406 memset(&safe_ks
, 0, sizeof(safe_ks
));
2407 safe_ks
.base
.cmd
= copy_ks
.base
.cmd
;
2408 safe_ks
.base
.link_mode_masks_nwords
=
2409 copy_ks
.base
.link_mode_masks_nwords
;
2410 ice_get_link_ksettings(netdev
, &safe_ks
);
2412 /* set autoneg back to what it currently is */
2413 copy_ks
.base
.autoneg
= safe_ks
.base
.autoneg
;
2414 /* we don't compare the speed */
2415 copy_ks
.base
.speed
= safe_ks
.base
.speed
;
2417 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2418 * trying to set something that we do not support.
2420 if (memcmp(©_ks
.base
, &safe_ks
.base
, sizeof(copy_ks
.base
)))
2423 while (test_and_set_bit(__ICE_CFG_BUSY
, pf
->state
)) {
2427 usleep_range(TEST_SET_BITS_SLEEP_MIN
, TEST_SET_BITS_SLEEP_MAX
);
2430 abilities
= devm_kzalloc(&pf
->pdev
->dev
, sizeof(*abilities
),
2435 /* Get the current PHY config */
2436 status
= ice_aq_get_phy_caps(p
, false, ICE_AQC_REPORT_SW_CFG
, abilities
,
2443 /* Copy abilities to config in case autoneg is not set below */
2444 memset(&config
, 0, sizeof(config
));
2445 config
.caps
= abilities
->caps
& ~ICE_AQC_PHY_AN_MODE
;
2446 if (abilities
->caps
& ICE_AQC_PHY_AN_MODE
)
2447 config
.caps
|= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT
;
2450 err
= ice_setup_autoneg(p
, &safe_ks
, &config
, autoneg
, &autoneg_changed
,
2456 /* Call to get the current link speed */
2457 p
->phy
.get_link_info
= true;
2458 status
= ice_get_link_status(p
, &linkup
);
2464 curr_link_speed
= p
->phy
.link_info
.link_speed
;
2465 adv_link_speed
= ice_ksettings_find_adv_link_speed(ks
);
2467 /* If speed didn't get set, set it to what it currently is.
2468 * This is needed because if advertise is 0 (as it is when autoneg
2469 * is disabled) then speed won't get set.
2471 if (!adv_link_speed
)
2472 adv_link_speed
= curr_link_speed
;
2474 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2475 ice_update_phy_type(&phy_type_low
, &phy_type_high
, adv_link_speed
);
2477 if (!autoneg_changed
&& adv_link_speed
== curr_link_speed
) {
2478 netdev_info(netdev
, "Nothing changed, exiting without setting anything.\n");
2482 /* copy over the rest of the abilities */
2483 config
.low_power_ctrl
= abilities
->low_power_ctrl
;
2484 config
.eee_cap
= abilities
->eee_cap
;
2485 config
.eeer_value
= abilities
->eeer_value
;
2486 config
.link_fec_opt
= abilities
->link_fec_options
;
2488 /* save the requested speeds */
2489 p
->phy
.link_info
.req_speeds
= adv_link_speed
;
2491 /* set link and auto negotiation so changes take effect */
2492 config
.caps
|= ICE_AQ_PHY_ENA_LINK
;
2494 if (phy_type_low
|| phy_type_high
) {
2495 config
.phy_type_high
= cpu_to_le64(phy_type_high
) &
2496 abilities
->phy_type_high
;
2497 config
.phy_type_low
= cpu_to_le64(phy_type_low
) &
2498 abilities
->phy_type_low
;
2501 netdev_info(netdev
, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2505 /* If link is up put link down */
2506 if (p
->phy
.link_info
.link_info
& ICE_AQ_LINK_UP
) {
2507 /* Tell the OS link is going down, the link will go
2508 * back up when fw says it is ready asynchronously
2510 ice_print_link_msg(np
->vsi
, false);
2511 netif_carrier_off(netdev
);
2512 netif_tx_stop_all_queues(netdev
);
2515 /* make the aq call */
2516 status
= ice_aq_set_phy_cfg(&pf
->hw
, lport
, &config
, NULL
);
2518 netdev_info(netdev
, "Set phy config failed,\n");
2523 devm_kfree(&pf
->pdev
->dev
, abilities
);
2524 clear_bit(__ICE_CFG_BUSY
, pf
->state
);
2530 * ice_get_rxnfc - command to get Rx flow classification rules
2531 * @netdev: network interface device structure
2532 * @cmd: ethtool rxnfc command
2533 * @rule_locs: buffer to rturn Rx flow classification rules
2535 * Returns Success if the command is supported.
2538 ice_get_rxnfc(struct net_device
*netdev
, struct ethtool_rxnfc
*cmd
,
2539 u32 __always_unused
*rule_locs
)
2541 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2542 struct ice_vsi
*vsi
= np
->vsi
;
2543 int ret
= -EOPNOTSUPP
;
2546 case ETHTOOL_GRXRINGS
:
2547 cmd
->data
= vsi
->rss_size
;
2558 ice_get_ringparam(struct net_device
*netdev
, struct ethtool_ringparam
*ring
)
2560 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2561 struct ice_vsi
*vsi
= np
->vsi
;
2563 ring
->rx_max_pending
= ICE_MAX_NUM_DESC
;
2564 ring
->tx_max_pending
= ICE_MAX_NUM_DESC
;
2565 ring
->rx_pending
= vsi
->rx_rings
[0]->count
;
2566 ring
->tx_pending
= vsi
->tx_rings
[0]->count
;
2568 /* Rx mini and jumbo rings are not supported */
2569 ring
->rx_mini_max_pending
= 0;
2570 ring
->rx_jumbo_max_pending
= 0;
2571 ring
->rx_mini_pending
= 0;
2572 ring
->rx_jumbo_pending
= 0;
2576 ice_set_ringparam(struct net_device
*netdev
, struct ethtool_ringparam
*ring
)
2578 struct ice_ring
*tx_rings
= NULL
, *rx_rings
= NULL
;
2579 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2580 struct ice_vsi
*vsi
= np
->vsi
;
2581 struct ice_pf
*pf
= vsi
->back
;
2582 int i
, timeout
= 50, err
= 0;
2583 u32 new_rx_cnt
, new_tx_cnt
;
2585 if (ring
->tx_pending
> ICE_MAX_NUM_DESC
||
2586 ring
->tx_pending
< ICE_MIN_NUM_DESC
||
2587 ring
->rx_pending
> ICE_MAX_NUM_DESC
||
2588 ring
->rx_pending
< ICE_MIN_NUM_DESC
) {
2589 netdev_err(netdev
, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2590 ring
->tx_pending
, ring
->rx_pending
,
2591 ICE_MIN_NUM_DESC
, ICE_MAX_NUM_DESC
,
2592 ICE_REQ_DESC_MULTIPLE
);
2596 new_tx_cnt
= ALIGN(ring
->tx_pending
, ICE_REQ_DESC_MULTIPLE
);
2597 if (new_tx_cnt
!= ring
->tx_pending
)
2599 "Requested Tx descriptor count rounded up to %d\n",
2601 new_rx_cnt
= ALIGN(ring
->rx_pending
, ICE_REQ_DESC_MULTIPLE
);
2602 if (new_rx_cnt
!= ring
->rx_pending
)
2604 "Requested Rx descriptor count rounded up to %d\n",
2607 /* if nothing to do return success */
2608 if (new_tx_cnt
== vsi
->tx_rings
[0]->count
&&
2609 new_rx_cnt
== vsi
->rx_rings
[0]->count
) {
2610 netdev_dbg(netdev
, "Nothing to change, descriptor count is same as requested\n");
2614 while (test_and_set_bit(__ICE_CFG_BUSY
, pf
->state
)) {
2618 usleep_range(1000, 2000);
2621 /* set for the next time the netdev is started */
2622 if (!netif_running(vsi
->netdev
)) {
2623 for (i
= 0; i
< vsi
->alloc_txq
; i
++)
2624 vsi
->tx_rings
[i
]->count
= new_tx_cnt
;
2625 for (i
= 0; i
< vsi
->alloc_rxq
; i
++)
2626 vsi
->rx_rings
[i
]->count
= new_rx_cnt
;
2627 netdev_dbg(netdev
, "Link is down, descriptor count change happens when link is brought up\n");
2631 if (new_tx_cnt
== vsi
->tx_rings
[0]->count
)
2634 /* alloc updated Tx resources */
2635 netdev_info(netdev
, "Changing Tx descriptor count from %d to %d\n",
2636 vsi
->tx_rings
[0]->count
, new_tx_cnt
);
2638 tx_rings
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->alloc_txq
,
2639 sizeof(*tx_rings
), GFP_KERNEL
);
2645 for (i
= 0; i
< vsi
->alloc_txq
; i
++) {
2646 /* clone ring and setup updated count */
2647 tx_rings
[i
] = *vsi
->tx_rings
[i
];
2648 tx_rings
[i
].count
= new_tx_cnt
;
2649 tx_rings
[i
].desc
= NULL
;
2650 tx_rings
[i
].tx_buf
= NULL
;
2651 err
= ice_setup_tx_ring(&tx_rings
[i
]);
2655 ice_clean_tx_ring(&tx_rings
[i
]);
2657 devm_kfree(&pf
->pdev
->dev
, tx_rings
);
2663 if (new_rx_cnt
== vsi
->rx_rings
[0]->count
)
2666 /* alloc updated Rx resources */
2667 netdev_info(netdev
, "Changing Rx descriptor count from %d to %d\n",
2668 vsi
->rx_rings
[0]->count
, new_rx_cnt
);
2670 rx_rings
= devm_kcalloc(&pf
->pdev
->dev
, vsi
->alloc_rxq
,
2671 sizeof(*rx_rings
), GFP_KERNEL
);
2677 for (i
= 0; i
< vsi
->alloc_rxq
; i
++) {
2678 /* clone ring and setup updated count */
2679 rx_rings
[i
] = *vsi
->rx_rings
[i
];
2680 rx_rings
[i
].count
= new_rx_cnt
;
2681 rx_rings
[i
].desc
= NULL
;
2682 rx_rings
[i
].rx_buf
= NULL
;
2683 /* this is to allow wr32 to have something to write to
2684 * during early allocation of Rx buffers
2686 rx_rings
[i
].tail
= vsi
->back
->hw
.hw_addr
+ PRTGEN_STATUS
;
2688 err
= ice_setup_rx_ring(&rx_rings
[i
]);
2692 /* allocate Rx buffers */
2693 err
= ice_alloc_rx_bufs(&rx_rings
[i
],
2694 ICE_DESC_UNUSED(&rx_rings
[i
]));
2699 ice_free_rx_ring(&rx_rings
[i
]);
2701 devm_kfree(&pf
->pdev
->dev
, rx_rings
);
2708 /* Bring interface down, copy in the new ring info, then restore the
2709 * interface. if VSI is up, bring it down and then back up
2711 if (!test_and_set_bit(__ICE_DOWN
, vsi
->state
)) {
2715 for (i
= 0; i
< vsi
->alloc_txq
; i
++) {
2716 ice_free_tx_ring(vsi
->tx_rings
[i
]);
2717 *vsi
->tx_rings
[i
] = tx_rings
[i
];
2719 devm_kfree(&pf
->pdev
->dev
, tx_rings
);
2723 for (i
= 0; i
< vsi
->alloc_rxq
; i
++) {
2724 ice_free_rx_ring(vsi
->rx_rings
[i
]);
2725 /* copy the real tail offset */
2726 rx_rings
[i
].tail
= vsi
->rx_rings
[i
]->tail
;
2727 /* this is to fake out the allocation routine
2728 * into thinking it has to realloc everything
2729 * but the recycling logic will let us re-use
2730 * the buffers allocated above
2732 rx_rings
[i
].next_to_use
= 0;
2733 rx_rings
[i
].next_to_clean
= 0;
2734 rx_rings
[i
].next_to_alloc
= 0;
2735 *vsi
->rx_rings
[i
] = rx_rings
[i
];
2737 devm_kfree(&pf
->pdev
->dev
, rx_rings
);
2745 /* error cleanup if the Rx allocations failed after getting Tx */
2747 for (i
= 0; i
< vsi
->alloc_txq
; i
++)
2748 ice_free_tx_ring(&tx_rings
[i
]);
2749 devm_kfree(&pf
->pdev
->dev
, tx_rings
);
2753 clear_bit(__ICE_CFG_BUSY
, pf
->state
);
2757 static int ice_nway_reset(struct net_device
*netdev
)
2759 /* restart autonegotiation */
2760 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2761 struct ice_vsi
*vsi
= np
->vsi
;
2762 struct ice_port_info
*pi
;
2763 enum ice_status status
;
2765 pi
= vsi
->port_info
;
2766 /* If VSI state is up, then restart autoneg with link up */
2767 if (!test_bit(__ICE_DOWN
, vsi
->back
->state
))
2768 status
= ice_aq_set_link_restart_an(pi
, true, NULL
);
2770 status
= ice_aq_set_link_restart_an(pi
, false, NULL
);
2773 netdev_info(netdev
, "link restart failed, err %d aq_err %d\n",
2774 status
, pi
->hw
->adminq
.sq_last_status
);
2782 * ice_get_pauseparam - Get Flow Control status
2783 * @netdev: network interface device structure
2784 * @pause: ethernet pause (flow control) parameters
2786 * Get requested flow control status from PHY capability.
2787 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2788 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2789 * the negotiated Rx/Tx pause via lp_advertising.
2792 ice_get_pauseparam(struct net_device
*netdev
, struct ethtool_pauseparam
*pause
)
2794 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2795 struct ice_port_info
*pi
= np
->vsi
->port_info
;
2796 struct ice_aqc_get_phy_caps_data
*pcaps
;
2797 struct ice_vsi
*vsi
= np
->vsi
;
2798 struct ice_dcbx_cfg
*dcbx_cfg
;
2799 enum ice_status status
;
2801 /* Initialize pause params */
2802 pause
->rx_pause
= 0;
2803 pause
->tx_pause
= 0;
2805 dcbx_cfg
= &pi
->local_dcbx_cfg
;
2807 pcaps
= devm_kzalloc(&vsi
->back
->pdev
->dev
, sizeof(*pcaps
),
2812 /* Get current PHY config */
2813 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
, pcaps
,
2818 pause
->autoneg
= ((pcaps
->caps
& ICE_AQC_PHY_AN_MODE
) ?
2819 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
2821 if (dcbx_cfg
->pfc
.pfcena
)
2822 /* PFC enabled so report LFC as off */
2825 if (pcaps
->caps
& ICE_AQC_PHY_EN_TX_LINK_PAUSE
)
2826 pause
->tx_pause
= 1;
2827 if (pcaps
->caps
& ICE_AQC_PHY_EN_RX_LINK_PAUSE
)
2828 pause
->rx_pause
= 1;
2831 devm_kfree(&vsi
->back
->pdev
->dev
, pcaps
);
2835 * ice_set_pauseparam - Set Flow Control parameter
2836 * @netdev: network interface device structure
2837 * @pause: return Tx/Rx flow control status
2840 ice_set_pauseparam(struct net_device
*netdev
, struct ethtool_pauseparam
*pause
)
2842 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2843 struct ice_aqc_get_phy_caps_data
*pcaps
;
2844 struct ice_link_status
*hw_link_info
;
2845 struct ice_pf
*pf
= np
->vsi
->back
;
2846 struct ice_dcbx_cfg
*dcbx_cfg
;
2847 struct ice_vsi
*vsi
= np
->vsi
;
2848 struct ice_hw
*hw
= &pf
->hw
;
2849 struct ice_port_info
*pi
;
2850 enum ice_status status
;
2856 pi
= vsi
->port_info
;
2857 hw_link_info
= &pi
->phy
.link_info
;
2858 dcbx_cfg
= &pi
->local_dcbx_cfg
;
2859 link_up
= hw_link_info
->link_info
& ICE_AQ_LINK_UP
;
2861 /* Changing the port's flow control is not supported if this isn't the
2864 if (vsi
->type
!= ICE_VSI_PF
) {
2865 netdev_info(netdev
, "Changing flow control parameters only supported for PF VSI\n");
2869 /* Get pause param reports configured and negotiated flow control pause
2870 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2871 * defined get pause param pause->autoneg reports SW configured setting,
2872 * so compare pause->autoneg with SW configured to prevent the user from
2873 * using set pause param to chance autoneg.
2875 pcaps
= kzalloc(sizeof(*pcaps
), GFP_KERNEL
);
2879 /* Get current PHY config */
2880 status
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
, pcaps
,
2887 is_an
= ((pcaps
->caps
& ICE_AQC_PHY_AN_MODE
) ?
2888 AUTONEG_ENABLE
: AUTONEG_DISABLE
);
2892 if (pause
->autoneg
!= is_an
) {
2893 netdev_info(netdev
, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2897 /* If we have link and don't have autoneg */
2898 if (!test_bit(__ICE_DOWN
, pf
->state
) &&
2899 !(hw_link_info
->an_info
& ICE_AQ_AN_COMPLETED
)) {
2900 /* Send message that it might not necessarily work*/
2901 netdev_info(netdev
, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2904 if (dcbx_cfg
->pfc
.pfcena
) {
2905 netdev_info(netdev
, "Priority flow control enabled. Cannot set link flow control.\n");
2908 if (pause
->rx_pause
&& pause
->tx_pause
)
2909 pi
->fc
.req_mode
= ICE_FC_FULL
;
2910 else if (pause
->rx_pause
&& !pause
->tx_pause
)
2911 pi
->fc
.req_mode
= ICE_FC_RX_PAUSE
;
2912 else if (!pause
->rx_pause
&& pause
->tx_pause
)
2913 pi
->fc
.req_mode
= ICE_FC_TX_PAUSE
;
2914 else if (!pause
->rx_pause
&& !pause
->tx_pause
)
2915 pi
->fc
.req_mode
= ICE_FC_NONE
;
2919 /* Tell the OS link is going down, the link will go back up when fw
2920 * says it is ready asynchronously
2922 ice_print_link_msg(vsi
, false);
2923 netif_carrier_off(netdev
);
2924 netif_tx_stop_all_queues(netdev
);
2926 /* Set the FC mode and only restart AN if link is up */
2927 status
= ice_set_fc(pi
, &aq_failures
, link_up
);
2929 if (aq_failures
& ICE_SET_FC_AQ_FAIL_GET
) {
2930 netdev_info(netdev
, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2931 status
, hw
->adminq
.sq_last_status
);
2933 } else if (aq_failures
& ICE_SET_FC_AQ_FAIL_SET
) {
2934 netdev_info(netdev
, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2935 status
, hw
->adminq
.sq_last_status
);
2937 } else if (aq_failures
& ICE_SET_FC_AQ_FAIL_UPDATE
) {
2938 netdev_info(netdev
, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2939 status
, hw
->adminq
.sq_last_status
);
2943 if (!test_bit(__ICE_DOWN
, pf
->state
)) {
2944 /* Give it a little more time to try to come back. If still
2945 * down, restart autoneg link or reinitialize the interface.
2948 if (!test_bit(__ICE_DOWN
, pf
->state
))
2949 return ice_nway_reset(netdev
);
2959 * ice_get_rxfh_key_size - get the RSS hash key size
2960 * @netdev: network interface device structure
2962 * Returns the table size.
2964 static u32
ice_get_rxfh_key_size(struct net_device __always_unused
*netdev
)
2966 return ICE_VSIQF_HKEY_ARRAY_SIZE
;
2970 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
2971 * @netdev: network interface device structure
2973 * Returns the table size.
2975 static u32
ice_get_rxfh_indir_size(struct net_device
*netdev
)
2977 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2979 return np
->vsi
->rss_table_size
;
2983 * ice_get_rxfh - get the Rx flow hash indirection table
2984 * @netdev: network interface device structure
2985 * @indir: indirection table
2987 * @hfunc: hash function
2989 * Reads the indirection table directly from the hardware.
2992 ice_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
, u8
*hfunc
)
2994 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2995 struct ice_vsi
*vsi
= np
->vsi
;
2996 struct ice_pf
*pf
= vsi
->back
;
3001 *hfunc
= ETH_RSS_HASH_TOP
;
3006 if (!test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
)) {
3007 /* RSS not supported return error here */
3008 netdev_warn(netdev
, "RSS is not configured on this VSI!\n");
3012 lut
= devm_kzalloc(&pf
->pdev
->dev
, vsi
->rss_table_size
, GFP_KERNEL
);
3016 if (ice_get_rss(vsi
, key
, lut
, vsi
->rss_table_size
)) {
3021 for (i
= 0; i
< vsi
->rss_table_size
; i
++)
3022 indir
[i
] = (u32
)(lut
[i
]);
3025 devm_kfree(&pf
->pdev
->dev
, lut
);
3030 * ice_set_rxfh - set the Rx flow hash indirection table
3031 * @netdev: network interface device structure
3032 * @indir: indirection table
3034 * @hfunc: hash function
3036 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3037 * returns 0 after programming the table.
3040 ice_set_rxfh(struct net_device
*netdev
, const u32
*indir
, const u8
*key
,
3043 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3044 struct ice_vsi
*vsi
= np
->vsi
;
3045 struct ice_pf
*pf
= vsi
->back
;
3048 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
)
3051 if (!test_bit(ICE_FLAG_RSS_ENA
, pf
->flags
)) {
3052 /* RSS not supported return error here */
3053 netdev_warn(netdev
, "RSS is not configured on this VSI!\n");
3058 if (!vsi
->rss_hkey_user
) {
3059 vsi
->rss_hkey_user
=
3060 devm_kzalloc(&pf
->pdev
->dev
,
3061 ICE_VSIQF_HKEY_ARRAY_SIZE
,
3063 if (!vsi
->rss_hkey_user
)
3066 memcpy(vsi
->rss_hkey_user
, key
, ICE_VSIQF_HKEY_ARRAY_SIZE
);
3067 seed
= vsi
->rss_hkey_user
;
3070 if (!vsi
->rss_lut_user
) {
3071 vsi
->rss_lut_user
= devm_kzalloc(&pf
->pdev
->dev
,
3072 vsi
->rss_table_size
,
3074 if (!vsi
->rss_lut_user
)
3078 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3082 for (i
= 0; i
< vsi
->rss_table_size
; i
++)
3083 vsi
->rss_lut_user
[i
] = (u8
)(indir
[i
]);
3085 ice_fill_rss_lut(vsi
->rss_lut_user
, vsi
->rss_table_size
,
3089 if (ice_set_rss(vsi
, seed
, vsi
->rss_lut_user
, vsi
->rss_table_size
))
3095 enum ice_container_type
{
3101 * ice_get_rc_coalesce - get ITR values for specific ring container
3102 * @ec: ethtool structure to fill with driver's coalesce settings
3103 * @c_type: container type, Rx or Tx
3104 * @rc: ring container that the ITR values will come from
3106 * Query the device for ice_ring_container specific ITR values. This is
3107 * done per ice_ring_container because each q_vector can have 1 or more rings
3108 * and all of said ring(s) will have the same ITR values.
3110 * Returns 0 on success, negative otherwise.
3113 ice_get_rc_coalesce(struct ethtool_coalesce
*ec
, enum ice_container_type c_type
,
3114 struct ice_ring_container
*rc
)
3121 pf
= rc
->ring
->vsi
->back
;
3124 case ICE_RX_CONTAINER
:
3125 ec
->use_adaptive_rx_coalesce
= ITR_IS_DYNAMIC(rc
->itr_setting
);
3126 ec
->rx_coalesce_usecs
= rc
->itr_setting
& ~ICE_ITR_DYNAMIC
;
3127 ec
->rx_coalesce_usecs_high
= rc
->ring
->q_vector
->intrl
;
3129 case ICE_TX_CONTAINER
:
3130 ec
->use_adaptive_tx_coalesce
= ITR_IS_DYNAMIC(rc
->itr_setting
);
3131 ec
->tx_coalesce_usecs
= rc
->itr_setting
& ~ICE_ITR_DYNAMIC
;
3134 dev_dbg(&pf
->pdev
->dev
, "Invalid c_type %d\n", c_type
);
3142 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3143 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3144 * @ec: coalesce settings to program the device with
3145 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3147 * Return 0 on success, and negative under the following conditions:
3148 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3149 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3152 ice_get_q_coalesce(struct ice_vsi
*vsi
, struct ethtool_coalesce
*ec
, int q_num
)
3154 if (q_num
< vsi
->num_rxq
&& q_num
< vsi
->num_txq
) {
3155 if (ice_get_rc_coalesce(ec
, ICE_RX_CONTAINER
,
3156 &vsi
->rx_rings
[q_num
]->q_vector
->rx
))
3158 if (ice_get_rc_coalesce(ec
, ICE_TX_CONTAINER
,
3159 &vsi
->tx_rings
[q_num
]->q_vector
->tx
))
3161 } else if (q_num
< vsi
->num_rxq
) {
3162 if (ice_get_rc_coalesce(ec
, ICE_RX_CONTAINER
,
3163 &vsi
->rx_rings
[q_num
]->q_vector
->rx
))
3165 } else if (q_num
< vsi
->num_txq
) {
3166 if (ice_get_rc_coalesce(ec
, ICE_TX_CONTAINER
,
3167 &vsi
->tx_rings
[q_num
]->q_vector
->tx
))
3177 * __ice_get_coalesce - get ITR/INTRL values for the device
3178 * @netdev: pointer to the netdev associated with this query
3179 * @ec: ethtool structure to fill with driver's coalesce settings
3180 * @q_num: queue number to get the coalesce settings for
3182 * If the caller passes in a negative q_num then we return coalesce settings
3183 * based on queue number 0, else use the actual q_num passed in.
3186 __ice_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ec
,
3189 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3190 struct ice_vsi
*vsi
= np
->vsi
;
3195 if (ice_get_q_coalesce(vsi
, ec
, q_num
))
3202 ice_get_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ec
)
3204 return __ice_get_coalesce(netdev
, ec
, -1);
3208 ice_get_per_q_coalesce(struct net_device
*netdev
, u32 q_num
,
3209 struct ethtool_coalesce
*ec
)
3211 return __ice_get_coalesce(netdev
, ec
, q_num
);
3215 * ice_set_rc_coalesce - set ITR values for specific ring container
3216 * @c_type: container type, Rx or Tx
3217 * @ec: ethtool structure from user to update ITR settings
3218 * @rc: ring container that the ITR values will come from
3219 * @vsi: VSI associated to the ring container
3221 * Set specific ITR values. This is done per ice_ring_container because each
3222 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3225 * Returns 0 on success, negative otherwise.
3228 ice_set_rc_coalesce(enum ice_container_type c_type
, struct ethtool_coalesce
*ec
,
3229 struct ice_ring_container
*rc
, struct ice_vsi
*vsi
)
3231 const char *c_type_str
= (c_type
== ICE_RX_CONTAINER
) ? "rx" : "tx";
3232 u32 use_adaptive_coalesce
, coalesce_usecs
;
3233 struct ice_pf
*pf
= vsi
->back
;
3240 case ICE_RX_CONTAINER
:
3241 if (ec
->rx_coalesce_usecs_high
> ICE_MAX_INTRL
||
3242 (ec
->rx_coalesce_usecs_high
&&
3243 ec
->rx_coalesce_usecs_high
< pf
->hw
.intrl_gran
)) {
3244 netdev_info(vsi
->netdev
,
3245 "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3246 c_type_str
, pf
->hw
.intrl_gran
,
3250 if (ec
->rx_coalesce_usecs_high
!= rc
->ring
->q_vector
->intrl
) {
3251 rc
->ring
->q_vector
->intrl
= ec
->rx_coalesce_usecs_high
;
3252 wr32(&pf
->hw
, GLINT_RATE(rc
->ring
->q_vector
->reg_idx
),
3253 ice_intrl_usec_to_reg(ec
->rx_coalesce_usecs_high
,
3254 pf
->hw
.intrl_gran
));
3257 use_adaptive_coalesce
= ec
->use_adaptive_rx_coalesce
;
3258 coalesce_usecs
= ec
->rx_coalesce_usecs
;
3261 case ICE_TX_CONTAINER
:
3262 if (ec
->tx_coalesce_usecs_high
) {
3263 netdev_info(vsi
->netdev
,
3264 "setting %s-usecs-high is not supported\n",
3269 use_adaptive_coalesce
= ec
->use_adaptive_tx_coalesce
;
3270 coalesce_usecs
= ec
->tx_coalesce_usecs
;
3274 dev_dbg(&pf
->pdev
->dev
, "Invalid container type %d\n", c_type
);
3278 itr_setting
= rc
->itr_setting
& ~ICE_ITR_DYNAMIC
;
3279 if (coalesce_usecs
!= itr_setting
&& use_adaptive_coalesce
) {
3280 netdev_info(vsi
->netdev
,
3281 "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3282 c_type_str
, c_type_str
);
3286 if (coalesce_usecs
> ICE_ITR_MAX
) {
3287 netdev_info(vsi
->netdev
,
3288 "Invalid value, %s-usecs range is 0-%d\n",
3289 c_type_str
, ICE_ITR_MAX
);
3293 /* hardware only supports an ITR granularity of 2us */
3294 if (coalesce_usecs
% 2 != 0) {
3295 netdev_info(vsi
->netdev
,
3296 "Invalid value, %s-usecs must be even\n",
3301 if (use_adaptive_coalesce
) {
3302 rc
->itr_setting
|= ICE_ITR_DYNAMIC
;
3304 /* store user facing value how it was set */
3305 rc
->itr_setting
= coalesce_usecs
;
3306 /* set to static and convert to value HW understands */
3308 ITR_TO_REG(ITR_REG_ALIGN(rc
->itr_setting
));
3315 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3316 * @vsi: VSI associated to the queue that need updating
3317 * @ec: coalesce settings to program the device with
3318 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3320 * Return 0 on success, and negative under the following conditions:
3321 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3322 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3325 ice_set_q_coalesce(struct ice_vsi
*vsi
, struct ethtool_coalesce
*ec
, int q_num
)
3327 if (q_num
< vsi
->num_rxq
&& q_num
< vsi
->num_txq
) {
3328 if (ice_set_rc_coalesce(ICE_RX_CONTAINER
, ec
,
3329 &vsi
->rx_rings
[q_num
]->q_vector
->rx
,
3333 if (ice_set_rc_coalesce(ICE_TX_CONTAINER
, ec
,
3334 &vsi
->tx_rings
[q_num
]->q_vector
->tx
,
3337 } else if (q_num
< vsi
->num_rxq
) {
3338 if (ice_set_rc_coalesce(ICE_RX_CONTAINER
, ec
,
3339 &vsi
->rx_rings
[q_num
]->q_vector
->rx
,
3342 } else if (q_num
< vsi
->num_txq
) {
3343 if (ice_set_rc_coalesce(ICE_TX_CONTAINER
, ec
,
3344 &vsi
->tx_rings
[q_num
]->q_vector
->tx
,
3355 * __ice_set_coalesce - set ITR/INTRL values for the device
3356 * @netdev: pointer to the netdev associated with this query
3357 * @ec: ethtool structure to fill with driver's coalesce settings
3358 * @q_num: queue number to get the coalesce settings for
3360 * If the caller passes in a negative q_num then we set the coalesce settings
3361 * for all Tx/Rx queues, else use the actual q_num passed in.
3364 __ice_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ec
,
3367 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3368 struct ice_vsi
*vsi
= np
->vsi
;
3373 ice_for_each_q_vector(vsi
, i
) {
3374 if (ice_set_q_coalesce(vsi
, ec
, i
))
3380 if (ice_set_q_coalesce(vsi
, ec
, q_num
))
3389 ice_set_coalesce(struct net_device
*netdev
, struct ethtool_coalesce
*ec
)
3391 return __ice_set_coalesce(netdev
, ec
, -1);
3395 ice_set_per_q_coalesce(struct net_device
*netdev
, u32 q_num
,
3396 struct ethtool_coalesce
*ec
)
3398 return __ice_set_coalesce(netdev
, ec
, q_num
);
3401 static const struct ethtool_ops ice_ethtool_ops
= {
3402 .get_link_ksettings
= ice_get_link_ksettings
,
3403 .set_link_ksettings
= ice_set_link_ksettings
,
3404 .get_drvinfo
= ice_get_drvinfo
,
3405 .get_regs_len
= ice_get_regs_len
,
3406 .get_regs
= ice_get_regs
,
3407 .get_msglevel
= ice_get_msglevel
,
3408 .set_msglevel
= ice_set_msglevel
,
3409 .self_test
= ice_self_test
,
3410 .get_link
= ethtool_op_get_link
,
3411 .get_eeprom_len
= ice_get_eeprom_len
,
3412 .get_eeprom
= ice_get_eeprom
,
3413 .get_coalesce
= ice_get_coalesce
,
3414 .set_coalesce
= ice_set_coalesce
,
3415 .get_strings
= ice_get_strings
,
3416 .set_phys_id
= ice_set_phys_id
,
3417 .get_ethtool_stats
= ice_get_ethtool_stats
,
3418 .get_priv_flags
= ice_get_priv_flags
,
3419 .set_priv_flags
= ice_set_priv_flags
,
3420 .get_sset_count
= ice_get_sset_count
,
3421 .get_rxnfc
= ice_get_rxnfc
,
3422 .get_ringparam
= ice_get_ringparam
,
3423 .set_ringparam
= ice_set_ringparam
,
3424 .nway_reset
= ice_nway_reset
,
3425 .get_pauseparam
= ice_get_pauseparam
,
3426 .set_pauseparam
= ice_set_pauseparam
,
3427 .get_rxfh_key_size
= ice_get_rxfh_key_size
,
3428 .get_rxfh_indir_size
= ice_get_rxfh_indir_size
,
3429 .get_rxfh
= ice_get_rxfh
,
3430 .set_rxfh
= ice_set_rxfh
,
3431 .get_ts_info
= ethtool_op_get_ts_info
,
3432 .get_per_queue_coalesce
= ice_get_per_q_coalesce
,
3433 .set_per_queue_coalesce
= ice_set_per_q_coalesce
,
3434 .get_fecparam
= ice_get_fecparam
,
3435 .set_fecparam
= ice_set_fecparam
,
3438 static const struct ethtool_ops ice_ethtool_safe_mode_ops
= {
3439 .get_link_ksettings
= ice_get_link_ksettings
,
3440 .set_link_ksettings
= ice_set_link_ksettings
,
3441 .get_drvinfo
= ice_get_drvinfo
,
3442 .get_regs_len
= ice_get_regs_len
,
3443 .get_regs
= ice_get_regs
,
3444 .get_msglevel
= ice_get_msglevel
,
3445 .set_msglevel
= ice_set_msglevel
,
3446 .get_eeprom_len
= ice_get_eeprom_len
,
3447 .get_eeprom
= ice_get_eeprom
,
3448 .get_strings
= ice_get_strings
,
3449 .get_ethtool_stats
= ice_get_ethtool_stats
,
3450 .get_sset_count
= ice_get_sset_count
,
3451 .get_ringparam
= ice_get_ringparam
,
3452 .set_ringparam
= ice_set_ringparam
,
3453 .nway_reset
= ice_nway_reset
,
3457 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
3458 * @netdev: network interface device structure
3460 void ice_set_ethtool_safe_mode_ops(struct net_device
*netdev
)
3462 netdev
->ethtool_ops
= &ice_ethtool_safe_mode_ops
;
3466 * ice_set_ethtool_ops - setup netdev ethtool ops
3467 * @netdev: network interface device structure
3469 * setup netdev ethtool ops with ice specific ops
3471 void ice_set_ethtool_ops(struct net_device
*netdev
)
3473 netdev
->ethtool_ops
= &ice_ethtool_ops
;