1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* ethtool support for ice */
7 #include "ice_ethtool.h"
11 #include "ice_dcb_lib.h"
12 #include <net/dcbnl.h>
15 char stat_string[ETH_GSTRING_LEN];
20 #define ICE_STAT(_type, _name, _stat) { \
21 .stat_string = _name, \
22 .sizeof_stat = sizeof_field(_type, _stat), \
23 .stat_offset = offsetof(_type, _stat) \
26 #define ICE_VSI_STAT(_name, _stat) \
27 ICE_STAT(struct ice_vsi, _name, _stat)
28 #define ICE_PF_STAT(_name, _stat) \
29 ICE_STAT(struct ice_pf, _name, _stat)
31 static int ice_q_stats_len(struct net_device *netdev)
33 struct ice_netdev_priv *np = netdev_priv(netdev);
35 return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
36 (sizeof(struct ice_q_stats) / sizeof(u64)));
39 #define ICE_PF_STATS_LEN ARRAY_SIZE(ice_gstrings_pf_stats)
40 #define ICE_VSI_STATS_LEN ARRAY_SIZE(ice_gstrings_vsi_stats)
42 #define ICE_PFC_STATS_LEN ( \
43 (sizeof_field(struct ice_pf, stats.priority_xoff_rx) + \
44 sizeof_field(struct ice_pf, stats.priority_xon_rx) + \
45 sizeof_field(struct ice_pf, stats.priority_xoff_tx) + \
46 sizeof_field(struct ice_pf, stats.priority_xon_tx)) \
48 #define ICE_ALL_STATS_LEN(n) (ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
49 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
51 static const struct ice_stats ice_gstrings_vsi_stats[] = {
52 ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
53 ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
54 ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
55 ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
56 ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
57 ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
58 ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
59 ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
60 ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
61 ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
62 ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
63 ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
64 ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
65 ICE_VSI_STAT("tx_linearize", tx_linearize),
66 ICE_VSI_STAT("tx_busy", tx_busy),
67 ICE_VSI_STAT("tx_restart", tx_restart),
70 enum ice_ethtool_test_id {
78 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
79 "Register test (offline)",
80 "EEPROM test (offline)",
81 "Interrupt test (offline)",
82 "Loopback test (offline)",
83 "Link test (on/offline)",
86 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
88 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
89 * but they aren't. This device is capable of supporting multiple
90 * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
91 * netdevs whereas the PF_STATs are for the physical function that's
92 * hosting these netdevs.
94 * The PF_STATs are appended to the netdev stats only when ethtool -S
95 * is queried on the base PF netdev.
97 static const struct ice_stats ice_gstrings_pf_stats[] = {
98 ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
99 ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
100 ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
101 ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
102 ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
103 ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
104 ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
105 ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
106 ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
107 ICE_PF_STAT("tx_timeout.nic", tx_timeout_count),
108 ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
109 ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
110 ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
111 ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
112 ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
113 ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
114 ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
115 ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
116 ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
117 ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
118 ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
119 ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
120 ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
121 ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
122 ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
123 ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
124 ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
125 ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
126 ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
127 ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
128 ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
129 ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
130 ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
131 ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
132 ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
133 ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
134 ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
135 ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
136 ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
137 ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
138 ICE_PF_STAT("fdir_sb_match.nic", stats.fd_sb_match),
139 ICE_PF_STAT("fdir_sb_status.nic", stats.fd_sb_status),
140 ICE_PF_STAT("tx_hwtstamp_skipped", ptp.tx_hwtstamp_skipped),
141 ICE_PF_STAT("tx_hwtstamp_timeouts", ptp.tx_hwtstamp_timeouts),
142 ICE_PF_STAT("tx_hwtstamp_flushed", ptp.tx_hwtstamp_flushed),
143 ICE_PF_STAT("tx_hwtstamp_discarded", ptp.tx_hwtstamp_discarded),
144 ICE_PF_STAT("late_cached_phc_updates", ptp.late_cached_phc_updates),
147 static const u32 ice_regs_dump_list[] = {
155 #define GLDCB_TLPM_PCI_DM 0x000A0180
157 #define GLDCB_TLPM_TC2PFC 0x000A0194
159 #define TCDCB_TLPM_WAIT_DM(_i) (0x000A0080 + ((_i) * 4))
160 TCDCB_TLPM_WAIT_DM(0),
161 TCDCB_TLPM_WAIT_DM(1),
162 TCDCB_TLPM_WAIT_DM(2),
163 TCDCB_TLPM_WAIT_DM(3),
164 TCDCB_TLPM_WAIT_DM(4),
165 TCDCB_TLPM_WAIT_DM(5),
166 TCDCB_TLPM_WAIT_DM(6),
167 TCDCB_TLPM_WAIT_DM(7),
168 TCDCB_TLPM_WAIT_DM(8),
169 TCDCB_TLPM_WAIT_DM(9),
170 TCDCB_TLPM_WAIT_DM(10),
171 TCDCB_TLPM_WAIT_DM(11),
172 TCDCB_TLPM_WAIT_DM(12),
173 TCDCB_TLPM_WAIT_DM(13),
174 TCDCB_TLPM_WAIT_DM(14),
175 TCDCB_TLPM_WAIT_DM(15),
176 TCDCB_TLPM_WAIT_DM(16),
177 TCDCB_TLPM_WAIT_DM(17),
178 TCDCB_TLPM_WAIT_DM(18),
179 TCDCB_TLPM_WAIT_DM(19),
180 TCDCB_TLPM_WAIT_DM(20),
181 TCDCB_TLPM_WAIT_DM(21),
182 TCDCB_TLPM_WAIT_DM(22),
183 TCDCB_TLPM_WAIT_DM(23),
184 TCDCB_TLPM_WAIT_DM(24),
185 TCDCB_TLPM_WAIT_DM(25),
186 TCDCB_TLPM_WAIT_DM(26),
187 TCDCB_TLPM_WAIT_DM(27),
188 TCDCB_TLPM_WAIT_DM(28),
189 TCDCB_TLPM_WAIT_DM(29),
190 TCDCB_TLPM_WAIT_DM(30),
191 TCDCB_TLPM_WAIT_DM(31),
192 #define GLPCI_WATMK_CLNT_PIPEMON 0x000BFD90
193 GLPCI_WATMK_CLNT_PIPEMON,
194 #define GLPCI_CUR_CLNT_COMMON 0x000BFD84
195 GLPCI_CUR_CLNT_COMMON,
196 #define GLPCI_CUR_CLNT_PIPEMON 0x000BFD88
197 GLPCI_CUR_CLNT_PIPEMON,
198 #define GLPCI_PCIERR 0x0009DEB0
200 #define GLPSM_DEBUG_CTL_STATUS 0x000B0600
201 GLPSM_DEBUG_CTL_STATUS,
202 #define GLPSM0_DEBUG_FIFO_OVERFLOW_DETECT 0x000B0680
203 GLPSM0_DEBUG_FIFO_OVERFLOW_DETECT,
204 #define GLPSM0_DEBUG_FIFO_UNDERFLOW_DETECT 0x000B0684
205 GLPSM0_DEBUG_FIFO_UNDERFLOW_DETECT,
206 #define GLPSM0_DEBUG_DT_OUT_OF_WINDOW 0x000B0688
207 GLPSM0_DEBUG_DT_OUT_OF_WINDOW,
208 #define GLPSM0_DEBUG_INTF_HW_ERROR_DETECT 0x000B069C
209 GLPSM0_DEBUG_INTF_HW_ERROR_DETECT,
210 #define GLPSM0_DEBUG_MISC_HW_ERROR_DETECT 0x000B06A0
211 GLPSM0_DEBUG_MISC_HW_ERROR_DETECT,
212 #define GLPSM1_DEBUG_FIFO_OVERFLOW_DETECT 0x000B0E80
213 GLPSM1_DEBUG_FIFO_OVERFLOW_DETECT,
214 #define GLPSM1_DEBUG_FIFO_UNDERFLOW_DETECT 0x000B0E84
215 GLPSM1_DEBUG_FIFO_UNDERFLOW_DETECT,
216 #define GLPSM1_DEBUG_SRL_FIFO_OVERFLOW_DETECT 0x000B0E88
217 GLPSM1_DEBUG_SRL_FIFO_OVERFLOW_DETECT,
218 #define GLPSM1_DEBUG_SRL_FIFO_UNDERFLOW_DETECT 0x000B0E8C
219 GLPSM1_DEBUG_SRL_FIFO_UNDERFLOW_DETECT,
220 #define GLPSM1_DEBUG_MISC_HW_ERROR_DETECT 0x000B0E90
221 GLPSM1_DEBUG_MISC_HW_ERROR_DETECT,
222 #define GLPSM2_DEBUG_FIFO_OVERFLOW_DETECT 0x000B1680
223 GLPSM2_DEBUG_FIFO_OVERFLOW_DETECT,
224 #define GLPSM2_DEBUG_FIFO_UNDERFLOW_DETECT 0x000B1684
225 GLPSM2_DEBUG_FIFO_UNDERFLOW_DETECT,
226 #define GLPSM2_DEBUG_MISC_HW_ERROR_DETECT 0x000B1688
227 GLPSM2_DEBUG_MISC_HW_ERROR_DETECT,
228 #define GLTDPU_TCLAN_COMP_BOB(_i) (0x00049ADC + ((_i) * 4))
229 GLTDPU_TCLAN_COMP_BOB(1),
230 GLTDPU_TCLAN_COMP_BOB(2),
231 GLTDPU_TCLAN_COMP_BOB(3),
232 GLTDPU_TCLAN_COMP_BOB(4),
233 GLTDPU_TCLAN_COMP_BOB(5),
234 GLTDPU_TCLAN_COMP_BOB(6),
235 GLTDPU_TCLAN_COMP_BOB(7),
236 GLTDPU_TCLAN_COMP_BOB(8),
237 #define GLTDPU_TCB_CMD_BOB(_i) (0x0004975C + ((_i) * 4))
238 GLTDPU_TCB_CMD_BOB(1),
239 GLTDPU_TCB_CMD_BOB(2),
240 GLTDPU_TCB_CMD_BOB(3),
241 GLTDPU_TCB_CMD_BOB(4),
242 GLTDPU_TCB_CMD_BOB(5),
243 GLTDPU_TCB_CMD_BOB(6),
244 GLTDPU_TCB_CMD_BOB(7),
245 GLTDPU_TCB_CMD_BOB(8),
246 #define GLTDPU_PSM_UPDATE_BOB(_i) (0x00049B5C + ((_i) * 4))
247 GLTDPU_PSM_UPDATE_BOB(1),
248 GLTDPU_PSM_UPDATE_BOB(2),
249 GLTDPU_PSM_UPDATE_BOB(3),
250 GLTDPU_PSM_UPDATE_BOB(4),
251 GLTDPU_PSM_UPDATE_BOB(5),
252 GLTDPU_PSM_UPDATE_BOB(6),
253 GLTDPU_PSM_UPDATE_BOB(7),
254 GLTDPU_PSM_UPDATE_BOB(8),
255 #define GLTCB_CMD_IN_BOB(_i) (0x000AE288 + ((_i) * 4))
264 #define GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(_i) (0x000FC148 + ((_i) * 4))
265 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(1),
266 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(2),
267 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(3),
268 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(4),
269 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(5),
270 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(6),
271 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(7),
272 GLLAN_TCLAN_FETCH_CTL_FBK_BOB_CTL(8),
273 #define GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(_i) (0x000FC248 + ((_i) * 4))
274 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(1),
275 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(2),
276 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(3),
277 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(4),
278 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(5),
279 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(6),
280 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(7),
281 GLLAN_TCLAN_FETCH_CTL_SCHED_BOB_CTL(8),
282 #define GLLAN_TCLAN_CACHE_CTL_BOB_CTL(_i) (0x000FC1C8 + ((_i) * 4))
283 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(1),
284 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(2),
285 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(3),
286 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(4),
287 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(5),
288 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(6),
289 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(7),
290 GLLAN_TCLAN_CACHE_CTL_BOB_CTL(8),
291 #define GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(_i) (0x000FC188 + ((_i) * 4))
292 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(1),
293 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(2),
294 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(3),
295 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(4),
296 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(5),
297 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(6),
298 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(7),
299 GLLAN_TCLAN_FETCH_CTL_PROC_BOB_CTL(8),
300 #define GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(_i) (0x000FC288 + ((_i) * 4))
301 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(1),
302 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(2),
303 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(3),
304 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(4),
305 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(5),
306 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(6),
307 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(7),
308 GLLAN_TCLAN_FETCH_CTL_PCIE_RD_BOB_CTL(8),
309 #define PRTDCB_TCUPM_REG_CM(_i) (0x000BC360 + ((_i) * 4))
310 PRTDCB_TCUPM_REG_CM(0),
311 PRTDCB_TCUPM_REG_CM(1),
312 PRTDCB_TCUPM_REG_CM(2),
313 PRTDCB_TCUPM_REG_CM(3),
314 #define PRTDCB_TCUPM_REG_DM(_i) (0x000BC3A0 + ((_i) * 4))
315 PRTDCB_TCUPM_REG_DM(0),
316 PRTDCB_TCUPM_REG_DM(1),
317 PRTDCB_TCUPM_REG_DM(2),
318 PRTDCB_TCUPM_REG_DM(3),
319 #define PRTDCB_TLPM_REG_DM(_i) (0x000A0000 + ((_i) * 4))
320 PRTDCB_TLPM_REG_DM(0),
321 PRTDCB_TLPM_REG_DM(1),
322 PRTDCB_TLPM_REG_DM(2),
323 PRTDCB_TLPM_REG_DM(3),
326 struct ice_priv_flag {
327 char name[ETH_GSTRING_LEN];
328 u32 bitno; /* bit position in pf->flags */
331 #define ICE_PRIV_FLAG(_name, _bitno) { \
336 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
337 ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
338 ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
339 ICE_PRIV_FLAG("vf-true-promisc-support",
340 ICE_FLAG_VF_TRUE_PROMISC_ENA),
341 ICE_PRIV_FLAG("mdd-auto-reset-vf", ICE_FLAG_MDD_AUTO_RESET_VF),
342 ICE_PRIV_FLAG("vf-vlan-pruning", ICE_FLAG_VF_VLAN_PRUNING),
343 ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
346 #define ICE_PRIV_FLAG_ARRAY_SIZE ARRAY_SIZE(ice_gstrings_priv_flags)
349 __ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo,
352 struct ice_pf *pf = vsi->back;
353 struct ice_hw *hw = &pf->hw;
354 struct ice_orom_info *orom;
355 struct ice_nvm_info *nvm;
357 nvm = &hw->flash.nvm;
358 orom = &hw->flash.orom;
360 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
362 /* Display NVM version (from which the firmware version can be
363 * determined) which contains more pertinent information.
365 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
366 "%x.%02x 0x%x %d.%d.%d", nvm->major, nvm->minor,
367 nvm->eetrack, orom->major, orom->build, orom->patch);
369 strscpy(drvinfo->bus_info, pci_name(pf->pdev),
370 sizeof(drvinfo->bus_info));
374 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
376 struct ice_netdev_priv *np = netdev_priv(netdev);
378 __ice_get_drvinfo(netdev, drvinfo, np->vsi);
379 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
382 static int ice_get_regs_len(struct net_device __always_unused *netdev)
384 return sizeof(ice_regs_dump_list);
388 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
390 struct ice_netdev_priv *np = netdev_priv(netdev);
391 struct ice_pf *pf = np->vsi->back;
392 struct ice_hw *hw = &pf->hw;
393 u32 *regs_buf = (u32 *)p;
398 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
399 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
402 static u32 ice_get_msglevel(struct net_device *netdev)
404 struct ice_netdev_priv *np = netdev_priv(netdev);
405 struct ice_pf *pf = np->vsi->back;
407 #ifndef CONFIG_DYNAMIC_DEBUG
408 if (pf->hw.debug_mask)
409 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
411 #endif /* !CONFIG_DYNAMIC_DEBUG */
413 return pf->msg_enable;
416 static void ice_set_msglevel(struct net_device *netdev, u32 data)
418 struct ice_netdev_priv *np = netdev_priv(netdev);
419 struct ice_pf *pf = np->vsi->back;
421 #ifndef CONFIG_DYNAMIC_DEBUG
422 if (ICE_DBG_USER & data)
423 pf->hw.debug_mask = data;
425 pf->msg_enable = data;
427 pf->msg_enable = data;
428 #endif /* !CONFIG_DYNAMIC_DEBUG */
431 static int ice_get_eeprom_len(struct net_device *netdev)
433 struct ice_netdev_priv *np = netdev_priv(netdev);
434 struct ice_pf *pf = np->vsi->back;
436 return (int)pf->hw.flash.flash_size;
440 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
443 struct ice_netdev_priv *np = netdev_priv(netdev);
444 struct ice_vsi *vsi = np->vsi;
445 struct ice_pf *pf = vsi->back;
446 struct ice_hw *hw = &pf->hw;
451 dev = ice_pf_to_dev(pf);
453 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
454 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
455 eeprom->cmd, eeprom->offset, eeprom->len);
457 buf = kzalloc(eeprom->len, GFP_KERNEL);
461 ret = ice_acquire_nvm(hw, ICE_RES_READ);
463 dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %s\n",
464 ret, ice_aq_str(hw->adminq.sq_last_status));
468 ret = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
471 dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %s\n",
472 ret, ice_aq_str(hw->adminq.sq_last_status));
476 memcpy(bytes, buf, eeprom->len);
485 * ice_active_vfs - check if there are any active VFs
486 * @pf: board private structure
488 * Returns true if an active VF is found, otherwise returns false
490 static bool ice_active_vfs(struct ice_pf *pf)
497 ice_for_each_vf_rcu(pf, bkt, vf) {
498 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
509 * ice_link_test - perform a link test on a given net_device
510 * @netdev: network interface device structure
512 * This function performs one of the self-tests required by ethtool.
513 * Returns 0 on success, non-zero on failure.
515 static u64 ice_link_test(struct net_device *netdev)
517 struct ice_netdev_priv *np = netdev_priv(netdev);
518 bool link_up = false;
521 netdev_info(netdev, "link test\n");
522 status = ice_get_link_status(np->vsi->port_info, &link_up);
524 netdev_err(netdev, "link query error, status = %d\n",
536 * ice_eeprom_test - perform an EEPROM test on a given net_device
537 * @netdev: network interface device structure
539 * This function performs one of the self-tests required by ethtool.
540 * Returns 0 on success, non-zero on failure.
542 static u64 ice_eeprom_test(struct net_device *netdev)
544 struct ice_netdev_priv *np = netdev_priv(netdev);
545 struct ice_pf *pf = np->vsi->back;
547 netdev_info(netdev, "EEPROM test\n");
548 return !!(ice_nvm_validate_checksum(&pf->hw));
552 * ice_reg_pattern_test
553 * @hw: pointer to the HW struct
554 * @reg: reg to be tested
555 * @mask: bits to be touched
557 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
559 struct ice_pf *pf = (struct ice_pf *)hw->back;
560 struct device *dev = ice_pf_to_dev(pf);
561 static const u32 patterns[] = {
562 0x5A5A5A5A, 0xA5A5A5A5,
563 0x00000000, 0xFFFFFFFF
568 orig_val = rd32(hw, reg);
569 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
570 u32 pattern = patterns[i] & mask;
572 wr32(hw, reg, pattern);
576 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
577 , __func__, reg, pattern, val);
581 wr32(hw, reg, orig_val);
583 if (val != orig_val) {
584 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
585 , __func__, reg, orig_val, val);
593 * ice_reg_test - perform a register test on a given net_device
594 * @netdev: network interface device structure
596 * This function performs one of the self-tests required by ethtool.
597 * Returns 0 on success, non-zero on failure.
599 static u64 ice_reg_test(struct net_device *netdev)
601 struct ice_netdev_priv *np = netdev_priv(netdev);
602 struct ice_hw *hw = np->vsi->port_info->hw;
603 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
604 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
605 struct ice_diag_reg_test_info {
611 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
612 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
613 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
614 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
615 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
616 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
617 {GLINT_CTL, 0xffff0001, 1, 0}
621 netdev_dbg(netdev, "Register test\n");
622 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
625 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
626 u32 mask = ice_reg_list[i].mask;
627 u32 reg = ice_reg_list[i].address +
628 (j * ice_reg_list[i].elem_size);
630 /* bail on failure (non-zero return) */
631 if (ice_reg_pattern_test(hw, reg, mask))
640 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
641 * @vsi: pointer to the VSI structure
643 * Function configures rings of a VSI for loopback test without
644 * enabling interrupts or informing the kernel about new queues.
646 * Returns 0 on success, negative on failure.
648 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
652 status = ice_vsi_setup_tx_rings(vsi);
654 goto err_setup_tx_ring;
656 status = ice_vsi_setup_rx_rings(vsi);
658 goto err_setup_rx_ring;
660 status = ice_vsi_cfg_lan(vsi);
662 goto err_setup_rx_ring;
664 status = ice_vsi_start_all_rx_rings(vsi);
666 goto err_start_rx_ring;
671 ice_vsi_free_rx_rings(vsi);
673 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
675 ice_vsi_free_tx_rings(vsi);
681 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
682 * @vsi: pointer to the VSI structure
684 * Function stops and frees VSI rings after a loopback test.
685 * Returns 0 on success, negative on failure.
687 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
691 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
693 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
694 vsi->vsi_num, status);
696 status = ice_vsi_stop_all_rx_rings(vsi);
698 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
699 vsi->vsi_num, status);
701 ice_vsi_free_tx_rings(vsi);
702 ice_vsi_free_rx_rings(vsi);
708 * ice_lbtest_create_frame - create test packet
709 * @pf: pointer to the PF structure
710 * @ret_data: allocated frame buffer
711 * @size: size of the packet data
713 * Function allocates a frame with a test pattern on specific offsets.
714 * Returns 0 on success, non-zero on failure.
716 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
723 data = devm_kzalloc(ice_pf_to_dev(pf), size, GFP_KERNEL);
727 /* Since the ethernet test frame should always be at least
728 * 64 bytes long, fill some octets in the payload with test data.
730 memset(data, 0xFF, size);
742 * ice_lbtest_check_frame - verify received loopback frame
743 * @frame: pointer to the raw packet data
745 * Function verifies received test frame with a pattern.
746 * Returns true if frame matches the pattern, false otherwise.
748 static bool ice_lbtest_check_frame(u8 *frame)
750 /* Validate bytes of a frame under offsets chosen earlier */
751 if (frame[32] == 0xDE &&
762 * ice_diag_send - send test frames to the test ring
763 * @tx_ring: pointer to the transmit ring
764 * @data: pointer to the raw packet data
765 * @size: size of the packet to send
767 * Function sends loopback packets on a test Tx ring.
769 static int ice_diag_send(struct ice_tx_ring *tx_ring, u8 *data, u16 size)
771 struct ice_tx_desc *tx_desc;
772 struct ice_tx_buf *tx_buf;
776 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
777 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
779 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
780 if (dma_mapping_error(tx_ring->dev, dma))
783 tx_desc->buf_addr = cpu_to_le64(dma);
785 /* These flags are required for a descriptor to be pushed out */
786 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
787 tx_desc->cmd_type_offset_bsz =
788 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
789 (td_cmd << ICE_TXD_QW1_CMD_S) |
790 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
791 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
792 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
794 tx_buf->next_to_watch = tx_desc;
796 /* Force memory write to complete before letting h/w know
797 * there are new descriptors to fetch.
801 tx_ring->next_to_use++;
802 if (tx_ring->next_to_use >= tx_ring->count)
803 tx_ring->next_to_use = 0;
805 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
807 /* Wait until the packets get transmitted to the receive queue. */
808 usleep_range(1000, 2000);
809 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
814 #define ICE_LB_FRAME_SIZE 64
816 * ice_lbtest_receive_frames - receive and verify test frames
817 * @rx_ring: pointer to the receive ring
819 * Function receives loopback packets and verify their correctness.
820 * Returns number of received valid frames.
822 static int ice_lbtest_receive_frames(struct ice_rx_ring *rx_ring)
824 struct ice_rx_buf *rx_buf;
830 for (i = 0; i < rx_ring->count; i++) {
831 union ice_32b_rx_flex_desc *rx_desc;
833 rx_desc = ICE_RX_DESC(rx_ring, i);
835 if (!(rx_desc->wb.status_error0 &
836 (cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S)) |
837 cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)))))
840 rx_buf = &rx_ring->rx_buf[i];
841 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
843 if (ice_lbtest_check_frame(received_buf))
851 * ice_loopback_test - perform a loopback test on a given net_device
852 * @netdev: network interface device structure
854 * This function performs one of the self-tests required by ethtool.
855 * Returns 0 on success, non-zero on failure.
857 static u64 ice_loopback_test(struct net_device *netdev)
859 struct ice_netdev_priv *np = netdev_priv(netdev);
860 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
861 struct ice_pf *pf = orig_vsi->back;
862 u8 broadcast[ETH_ALEN], ret = 0;
863 int num_frames, valid_frames;
864 struct ice_tx_ring *tx_ring;
865 struct ice_rx_ring *rx_ring;
870 dev = ice_pf_to_dev(pf);
871 netdev_info(netdev, "loopback test\n");
873 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
875 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
879 test_vsi->netdev = netdev;
880 tx_ring = test_vsi->tx_rings[0];
881 rx_ring = test_vsi->rx_rings[0];
883 if (ice_lbtest_prepare_rings(test_vsi)) {
885 goto lbtest_vsi_close;
888 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
890 goto lbtest_rings_dis;
893 /* Enable MAC loopback in firmware */
894 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
899 /* Test VSI needs to receive broadcast packets */
900 eth_broadcast_addr(broadcast);
901 if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
906 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
908 goto remove_mac_filters;
911 num_frames = min_t(int, tx_ring->count, 32);
912 for (i = 0; i < num_frames; i++) {
913 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
915 goto lbtest_free_frame;
919 valid_frames = ice_lbtest_receive_frames(rx_ring);
922 else if (valid_frames != num_frames)
926 devm_kfree(dev, tx_frame);
928 if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
929 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
931 /* Disable MAC loopback after the test is completed. */
932 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
933 netdev_err(netdev, "Could not disable MAC loopback\n");
935 if (ice_lbtest_disable_rings(test_vsi))
936 netdev_err(netdev, "Could not disable test rings\n");
938 test_vsi->netdev = NULL;
939 if (ice_vsi_release(test_vsi))
940 netdev_err(netdev, "Failed to remove the test VSI\n");
946 * ice_intr_test - perform an interrupt test on a given net_device
947 * @netdev: network interface device structure
949 * This function performs one of the self-tests required by ethtool.
950 * Returns 0 on success, non-zero on failure.
952 static u64 ice_intr_test(struct net_device *netdev)
954 struct ice_netdev_priv *np = netdev_priv(netdev);
955 struct ice_pf *pf = np->vsi->back;
956 u16 swic_old = pf->sw_int_count;
958 netdev_info(netdev, "interrupt test\n");
960 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_irq.index),
961 GLINT_DYN_CTL_SW_ITR_INDX_M |
962 GLINT_DYN_CTL_INTENA_MSK_M |
963 GLINT_DYN_CTL_SWINT_TRIG_M);
965 usleep_range(1000, 2000);
966 return (swic_old == pf->sw_int_count);
970 * ice_self_test - handler function for performing a self-test by ethtool
971 * @netdev: network interface device structure
972 * @eth_test: ethtool_test structure
973 * @data: required by ethtool.self_test
975 * This function is called after invoking 'ethtool -t devname' command where
976 * devname is the name of the network device on which ethtool should operate.
977 * It performs a set of self-tests to check if a device works properly.
980 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
983 struct ice_netdev_priv *np = netdev_priv(netdev);
984 bool if_running = netif_running(netdev);
985 struct ice_pf *pf = np->vsi->back;
988 dev = ice_pf_to_dev(pf);
990 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
991 netdev_info(netdev, "offline testing starting\n");
993 set_bit(ICE_TESTING, pf->state);
995 if (ice_active_vfs(pf)) {
996 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
997 data[ICE_ETH_TEST_REG] = 1;
998 data[ICE_ETH_TEST_EEPROM] = 1;
999 data[ICE_ETH_TEST_INTR] = 1;
1000 data[ICE_ETH_TEST_LOOP] = 1;
1001 data[ICE_ETH_TEST_LINK] = 1;
1002 eth_test->flags |= ETH_TEST_FL_FAILED;
1003 clear_bit(ICE_TESTING, pf->state);
1006 /* If the device is online then take it offline */
1008 /* indicate we're in test mode */
1011 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1012 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
1013 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
1014 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
1015 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
1017 if (data[ICE_ETH_TEST_LINK] ||
1018 data[ICE_ETH_TEST_EEPROM] ||
1019 data[ICE_ETH_TEST_LOOP] ||
1020 data[ICE_ETH_TEST_INTR] ||
1021 data[ICE_ETH_TEST_REG])
1022 eth_test->flags |= ETH_TEST_FL_FAILED;
1024 clear_bit(ICE_TESTING, pf->state);
1027 int status = ice_open(netdev);
1030 dev_err(dev, "Could not open device %s, err %d\n",
1031 pf->int_name, status);
1036 netdev_info(netdev, "online testing starting\n");
1038 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1039 if (data[ICE_ETH_TEST_LINK])
1040 eth_test->flags |= ETH_TEST_FL_FAILED;
1042 /* Offline only tests, not run in online; pass by default */
1043 data[ICE_ETH_TEST_REG] = 0;
1044 data[ICE_ETH_TEST_EEPROM] = 0;
1045 data[ICE_ETH_TEST_INTR] = 0;
1046 data[ICE_ETH_TEST_LOOP] = 0;
1050 netdev_info(netdev, "testing finished\n");
1054 __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
1055 struct ice_vsi *vsi)
1060 switch (stringset) {
1062 for (i = 0; i < ICE_VSI_STATS_LEN; i++)
1064 ice_gstrings_vsi_stats[i].stat_string);
1066 if (ice_is_port_repr_netdev(netdev))
1069 ice_for_each_alloc_txq(vsi, i) {
1070 ethtool_sprintf(&p, "tx_queue_%u_packets", i);
1071 ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
1074 ice_for_each_alloc_rxq(vsi, i) {
1075 ethtool_sprintf(&p, "rx_queue_%u_packets", i);
1076 ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
1079 if (vsi->type != ICE_VSI_PF)
1082 for (i = 0; i < ICE_PF_STATS_LEN; i++)
1084 ice_gstrings_pf_stats[i].stat_string);
1086 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1087 ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
1088 ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
1090 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1091 ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
1092 ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
1096 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
1098 case ETH_SS_PRIV_FLAGS:
1099 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
1100 ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
1107 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1109 struct ice_netdev_priv *np = netdev_priv(netdev);
1111 __ice_get_strings(netdev, stringset, data, np->vsi);
1115 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
1117 struct ice_netdev_priv *np = netdev_priv(netdev);
1121 case ETHTOOL_ID_ACTIVE:
1124 case ETHTOOL_ID_INACTIVE:
1131 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
1138 * ice_set_fec_cfg - Set link FEC options
1139 * @netdev: network interface device structure
1140 * @req_fec: FEC mode to configure
1142 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
1144 struct ice_netdev_priv *np = netdev_priv(netdev);
1145 struct ice_aqc_set_phy_cfg_data config = { 0 };
1146 struct ice_vsi *vsi = np->vsi;
1147 struct ice_port_info *pi;
1149 pi = vsi->port_info;
1153 /* Changing the FEC parameters is not supported if not the PF VSI */
1154 if (vsi->type != ICE_VSI_PF) {
1155 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
1159 /* Proceed only if requesting different FEC mode */
1160 if (pi->phy.curr_user_fec_req == req_fec)
1163 /* Copy the current user PHY configuration. The current user PHY
1164 * configuration is initialized during probe from PHY capabilities
1165 * software mode, and updated on set PHY configuration.
1167 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
1169 ice_cfg_phy_fec(pi, &config, req_fec);
1170 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1172 if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL))
1175 /* Save requested FEC config */
1176 pi->phy.curr_user_fec_req = req_fec;
1182 * ice_set_fecparam - Set FEC link options
1183 * @netdev: network interface device structure
1184 * @fecparam: Ethtool structure to retrieve FEC parameters
1187 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1189 struct ice_netdev_priv *np = netdev_priv(netdev);
1190 struct ice_vsi *vsi = np->vsi;
1191 enum ice_fec_mode fec;
1193 switch (fecparam->fec) {
1194 case ETHTOOL_FEC_AUTO:
1197 case ETHTOOL_FEC_RS:
1200 case ETHTOOL_FEC_BASER:
1201 fec = ICE_FEC_BASER;
1203 case ETHTOOL_FEC_OFF:
1204 case ETHTOOL_FEC_NONE:
1208 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1213 return ice_set_fec_cfg(netdev, fec);
1217 * ice_get_fecparam - Get link FEC options
1218 * @netdev: network interface device structure
1219 * @fecparam: Ethtool structure to retrieve FEC parameters
1222 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1224 struct ice_netdev_priv *np = netdev_priv(netdev);
1225 struct ice_aqc_get_phy_caps_data *caps;
1226 struct ice_link_status *link_info;
1227 struct ice_vsi *vsi = np->vsi;
1228 struct ice_port_info *pi;
1231 pi = vsi->port_info;
1235 link_info = &pi->phy.link_info;
1237 /* Set FEC mode based on negotiated link info */
1238 switch (link_info->fec_info) {
1239 case ICE_AQ_LINK_25G_KR_FEC_EN:
1240 fecparam->active_fec = ETHTOOL_FEC_BASER;
1242 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1243 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1244 fecparam->active_fec = ETHTOOL_FEC_RS;
1247 fecparam->active_fec = ETHTOOL_FEC_OFF;
1251 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1255 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1260 /* Set supported/configured FEC modes based on PHY capability */
1261 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1262 fecparam->fec |= ETHTOOL_FEC_AUTO;
1263 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1264 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1265 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1266 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1267 fecparam->fec |= ETHTOOL_FEC_BASER;
1268 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1269 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1270 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1271 fecparam->fec |= ETHTOOL_FEC_RS;
1272 if (caps->link_fec_options == 0)
1273 fecparam->fec |= ETHTOOL_FEC_OFF;
1281 * ice_nway_reset - restart autonegotiation
1282 * @netdev: network interface device structure
1284 static int ice_nway_reset(struct net_device *netdev)
1286 struct ice_netdev_priv *np = netdev_priv(netdev);
1287 struct ice_vsi *vsi = np->vsi;
1290 /* If VSI state is up, then restart autoneg with link up */
1291 if (!test_bit(ICE_DOWN, vsi->back->state))
1292 err = ice_set_link(vsi, true);
1294 err = ice_set_link(vsi, false);
1300 * ice_get_priv_flags - report device private flags
1301 * @netdev: network interface device structure
1303 * The get string set count and the string set should be matched for each
1304 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1307 * Returns a u32 bitmap of flags.
1309 static u32 ice_get_priv_flags(struct net_device *netdev)
1311 struct ice_netdev_priv *np = netdev_priv(netdev);
1312 struct ice_vsi *vsi = np->vsi;
1313 struct ice_pf *pf = vsi->back;
1314 u32 i, ret_flags = 0;
1316 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1317 const struct ice_priv_flag *priv_flag;
1319 priv_flag = &ice_gstrings_priv_flags[i];
1321 if (test_bit(priv_flag->bitno, pf->flags))
1322 ret_flags |= BIT(i);
1329 * ice_set_priv_flags - set private flags
1330 * @netdev: network interface device structure
1331 * @flags: bit flags to be set
1333 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1335 struct ice_netdev_priv *np = netdev_priv(netdev);
1336 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1337 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1338 struct ice_vsi *vsi = np->vsi;
1339 struct ice_pf *pf = vsi->back;
1344 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1347 dev = ice_pf_to_dev(pf);
1348 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1350 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1351 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1352 const struct ice_priv_flag *priv_flag;
1354 priv_flag = &ice_gstrings_priv_flags[i];
1357 set_bit(priv_flag->bitno, pf->flags);
1359 clear_bit(priv_flag->bitno, pf->flags);
1362 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1364 /* Do not allow change to link-down-on-close when Total Port Shutdown
1367 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) &&
1368 test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) {
1369 dev_err(dev, "Setting link-down-on-close not supported on this port\n");
1370 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1375 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1376 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1379 /* Disable FW LLDP engine */
1380 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1382 /* If unregistering for LLDP events fails, this is
1383 * not an error state, as there shouldn't be any
1384 * events to respond to.
1387 dev_info(dev, "Failed to unreg for LLDP events\n");
1389 /* The AQ call to stop the FW LLDP agent will generate
1390 * an error if the agent is already stopped.
1392 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1394 dev_warn(dev, "Fail to stop LLDP agent\n");
1395 /* Use case for having the FW LLDP agent stopped
1396 * will likely not need DCB, so failure to init is
1397 * not a concern of ethtool
1399 status = ice_init_pf_dcb(pf, true);
1401 dev_warn(dev, "Fail to init DCB\n");
1403 pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED;
1404 pf->dcbx_cap |= DCB_CAP_DCBX_HOST;
1406 bool dcbx_agent_status;
1409 if (ice_get_pfc_mode(pf) == ICE_QOS_MODE_DSCP) {
1410 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
1411 dev_err(dev, "QoS in L3 DSCP mode, FW Agent not allowed to start\n");
1416 /* Remove rule to direct LLDP packets to default VSI.
1417 * The FW LLDP engine will now be consuming them.
1419 ice_cfg_sw_lldp(vsi, false, false);
1421 /* AQ command to start FW LLDP agent will return an
1422 * error if the agent is already started
1424 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1426 dev_warn(dev, "Fail to start LLDP Agent\n");
1428 /* AQ command to start FW DCBX agent will fail if
1429 * the agent is already started
1431 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1435 dev_dbg(dev, "Failed to start FW DCBX\n");
1437 dev_info(dev, "FW DCBX agent is %s\n",
1438 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1440 /* Failure to configure MIB change or init DCB is not
1441 * relevant to ethtool. Print notification that
1442 * registration/init failed but do not return error
1445 status = ice_init_pf_dcb(pf, true);
1447 dev_dbg(dev, "Fail to init DCB\n");
1449 /* Register for MIB change events */
1450 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1452 dev_dbg(dev, "Fail to enable MIB change events\n");
1454 pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST;
1455 pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
1457 ice_nway_reset(netdev);
1460 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1461 /* down and up VSI so that changes of Rx cfg are reflected. */
1464 /* don't allow modification of this flag when a single VF is in
1465 * promiscuous mode because it's not supported
1467 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1468 ice_is_any_vf_in_unicast_promisc(pf)) {
1469 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1470 /* toggle bit back to previous state */
1471 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1475 if (test_bit(ICE_FLAG_VF_VLAN_PRUNING, change_flags) &&
1477 dev_err(dev, "vf-vlan-pruning: VLAN pruning cannot be changed while VFs are active.\n");
1478 /* toggle bit back to previous state */
1479 change_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags);
1483 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1487 static int ice_get_sset_count(struct net_device *netdev, int sset)
1491 /* The number (and order) of strings reported *must* remain
1492 * constant for a given netdevice. This function must not
1493 * report a different number based on run time parameters
1494 * (such as the number of queues in use, or the setting of
1495 * a private ethtool flag). This is due to the nature of the
1496 * ethtool stats API.
1498 * Userspace programs such as ethtool must make 3 separate
1499 * ioctl requests, one for size, one for the strings, and
1500 * finally one for the stats. Since these cross into
1501 * userspace, changes to the number or size could result in
1502 * undefined memory access or incorrect string<->value
1503 * correlations for statistics.
1505 * Even if it appears to be safe, changes to the size or
1506 * order of strings will suffer from race conditions and are
1509 return ICE_ALL_STATS_LEN(netdev);
1511 return ICE_TEST_LEN;
1512 case ETH_SS_PRIV_FLAGS:
1513 return ICE_PRIV_FLAG_ARRAY_SIZE;
1520 __ice_get_ethtool_stats(struct net_device *netdev,
1521 struct ethtool_stats __always_unused *stats, u64 *data,
1522 struct ice_vsi *vsi)
1524 struct ice_pf *pf = vsi->back;
1525 struct ice_tx_ring *tx_ring;
1526 struct ice_rx_ring *rx_ring;
1531 ice_update_pf_stats(pf);
1532 ice_update_vsi_stats(vsi);
1534 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1535 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1536 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1537 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1540 if (ice_is_port_repr_netdev(netdev))
1543 /* populate per queue stats */
1546 ice_for_each_alloc_txq(vsi, j) {
1547 tx_ring = READ_ONCE(vsi->tx_rings[j]);
1548 if (tx_ring && tx_ring->ring_stats) {
1549 data[i++] = tx_ring->ring_stats->stats.pkts;
1550 data[i++] = tx_ring->ring_stats->stats.bytes;
1557 ice_for_each_alloc_rxq(vsi, j) {
1558 rx_ring = READ_ONCE(vsi->rx_rings[j]);
1559 if (rx_ring && rx_ring->ring_stats) {
1560 data[i++] = rx_ring->ring_stats->stats.pkts;
1561 data[i++] = rx_ring->ring_stats->stats.bytes;
1570 if (vsi->type != ICE_VSI_PF)
1573 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1574 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1575 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1576 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1579 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1580 data[i++] = pf->stats.priority_xon_tx[j];
1581 data[i++] = pf->stats.priority_xoff_tx[j];
1584 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1585 data[i++] = pf->stats.priority_xon_rx[j];
1586 data[i++] = pf->stats.priority_xoff_rx[j];
1591 ice_get_ethtool_stats(struct net_device *netdev,
1592 struct ethtool_stats __always_unused *stats, u64 *data)
1594 struct ice_netdev_priv *np = netdev_priv(netdev);
1596 __ice_get_ethtool_stats(netdev, stats, data, np->vsi);
1599 #define ICE_PHY_TYPE_LOW_MASK_MIN_1G (ICE_PHY_TYPE_LOW_100BASE_TX | \
1600 ICE_PHY_TYPE_LOW_100M_SGMII)
1602 #define ICE_PHY_TYPE_LOW_MASK_MIN_25G (ICE_PHY_TYPE_LOW_MASK_MIN_1G | \
1603 ICE_PHY_TYPE_LOW_1000BASE_T | \
1604 ICE_PHY_TYPE_LOW_1000BASE_SX | \
1605 ICE_PHY_TYPE_LOW_1000BASE_LX | \
1606 ICE_PHY_TYPE_LOW_1000BASE_KX | \
1607 ICE_PHY_TYPE_LOW_1G_SGMII | \
1608 ICE_PHY_TYPE_LOW_2500BASE_T | \
1609 ICE_PHY_TYPE_LOW_2500BASE_X | \
1610 ICE_PHY_TYPE_LOW_2500BASE_KX | \
1611 ICE_PHY_TYPE_LOW_5GBASE_T | \
1612 ICE_PHY_TYPE_LOW_5GBASE_KR | \
1613 ICE_PHY_TYPE_LOW_10GBASE_T | \
1614 ICE_PHY_TYPE_LOW_10G_SFI_DA | \
1615 ICE_PHY_TYPE_LOW_10GBASE_SR | \
1616 ICE_PHY_TYPE_LOW_10GBASE_LR | \
1617 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \
1618 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \
1619 ICE_PHY_TYPE_LOW_10G_SFI_C2C)
1621 #define ICE_PHY_TYPE_LOW_MASK_100G (ICE_PHY_TYPE_LOW_100GBASE_CR4 | \
1622 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \
1623 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \
1624 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \
1625 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \
1626 ICE_PHY_TYPE_LOW_100G_CAUI4 | \
1627 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \
1628 ICE_PHY_TYPE_LOW_100G_AUI4 | \
1629 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \
1630 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \
1631 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \
1632 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \
1633 ICE_PHY_TYPE_LOW_100GBASE_DR)
1635 #define ICE_PHY_TYPE_HIGH_MASK_100G (ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \
1636 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\
1637 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \
1638 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \
1639 ICE_PHY_TYPE_HIGH_100G_AUI2)
1642 * ice_mask_min_supported_speeds
1643 * @hw: pointer to the HW structure
1644 * @phy_types_high: PHY type high
1645 * @phy_types_low: PHY type low to apply minimum supported speeds mask
1647 * Apply minimum supported speeds mask to PHY type low. These are the speeds
1648 * for ethtool supported link mode.
1651 ice_mask_min_supported_speeds(struct ice_hw *hw,
1652 u64 phy_types_high, u64 *phy_types_low)
1654 /* if QSFP connection with 100G speed, minimum supported speed is 25G */
1655 if (*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G ||
1656 phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G)
1657 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G;
1658 else if (!ice_is_100m_speed_supported(hw))
1659 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G;
1663 * ice_linkmode_set_bit - set link mode bit
1664 * @phy_to_ethtool: PHY type to ethtool link mode struct to set
1665 * @ks: ethtool link ksettings struct to fill out
1666 * @req_speeds: speed requested by user
1667 * @advert_phy_type: advertised PHY type
1668 * @phy_type: PHY type
1671 ice_linkmode_set_bit(const struct ice_phy_type_to_ethtool *phy_to_ethtool,
1672 struct ethtool_link_ksettings *ks, u32 req_speeds,
1673 u64 advert_phy_type, u32 phy_type)
1675 linkmode_set_bit(phy_to_ethtool->link_mode, ks->link_modes.supported);
1677 if (req_speeds & phy_to_ethtool->aq_link_speed ||
1678 (!req_speeds && advert_phy_type & BIT(phy_type)))
1679 linkmode_set_bit(phy_to_ethtool->link_mode,
1680 ks->link_modes.advertising);
1684 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1685 * @netdev: network interface device structure
1686 * @ks: ethtool link ksettings struct to fill out
1689 ice_phy_type_to_ethtool(struct net_device *netdev,
1690 struct ethtool_link_ksettings *ks)
1692 struct ice_netdev_priv *np = netdev_priv(netdev);
1693 struct ice_vsi *vsi = np->vsi;
1694 struct ice_pf *pf = vsi->back;
1695 u64 advert_phy_type_lo = 0;
1696 u64 advert_phy_type_hi = 0;
1697 u64 phy_types_high = 0;
1698 u64 phy_types_low = 0;
1702 req_speeds = vsi->port_info->phy.link_info.req_speeds;
1704 /* Check if lenient mode is supported and enabled, or in strict mode.
1706 * In lenient mode the Supported link modes are the PHY types without
1707 * media. The Advertising link mode is either 1. the user requested
1708 * speed, 2. the override PHY mask, or 3. the PHY types with media.
1710 * In strict mode Supported link mode are the PHY type with media,
1711 * and Advertising link modes are the media PHY type or the speed
1712 * requested by user.
1714 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
1715 phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo);
1716 phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi);
1718 ice_mask_min_supported_speeds(&pf->hw, phy_types_high,
1720 /* determine advertised modes based on link override only
1721 * if it's supported and if the FW doesn't abstract the
1722 * driver from having to account for link overrides
1724 if (ice_fw_supports_link_override(&pf->hw) &&
1725 !ice_fw_supports_report_dflt_cfg(&pf->hw)) {
1726 struct ice_link_default_override_tlv *ldo;
1728 ldo = &pf->link_dflt_override;
1729 /* If override enabled and PHY mask set, then
1730 * Advertising link mode is the intersection of the PHY
1731 * types without media and the override PHY mask.
1733 if (ldo->options & ICE_LINK_OVERRIDE_EN &&
1734 (ldo->phy_type_low || ldo->phy_type_high)) {
1735 advert_phy_type_lo =
1736 le64_to_cpu(pf->nvm_phy_type_lo) &
1738 advert_phy_type_hi =
1739 le64_to_cpu(pf->nvm_phy_type_hi) &
1745 phy_types_low = vsi->port_info->phy.phy_type_low;
1746 phy_types_high = vsi->port_info->phy.phy_type_high;
1749 /* If Advertising link mode PHY type is not using override PHY type,
1750 * then use PHY type with media.
1752 if (!advert_phy_type_lo && !advert_phy_type_hi) {
1753 advert_phy_type_lo = vsi->port_info->phy.phy_type_low;
1754 advert_phy_type_hi = vsi->port_info->phy.phy_type_high;
1757 linkmode_zero(ks->link_modes.supported);
1758 linkmode_zero(ks->link_modes.advertising);
1760 for (i = 0; i < BITS_PER_TYPE(u64); i++) {
1761 if (phy_types_low & BIT_ULL(i))
1762 ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
1763 req_speeds, advert_phy_type_lo,
1767 for (i = 0; i < BITS_PER_TYPE(u64); i++) {
1768 if (phy_types_high & BIT_ULL(i))
1769 ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
1770 req_speeds, advert_phy_type_hi,
1775 #define TEST_SET_BITS_TIMEOUT 50
1776 #define TEST_SET_BITS_SLEEP_MAX 2000
1777 #define TEST_SET_BITS_SLEEP_MIN 1000
1780 * ice_get_settings_link_up - Get Link settings for when link is up
1781 * @ks: ethtool ksettings to fill in
1782 * @netdev: network interface device structure
1785 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1786 struct net_device *netdev)
1788 struct ice_netdev_priv *np = netdev_priv(netdev);
1789 struct ice_port_info *pi = np->vsi->port_info;
1790 struct ice_link_status *link_info;
1791 struct ice_vsi *vsi = np->vsi;
1793 link_info = &vsi->port_info->phy.link_info;
1795 /* Get supported and advertised settings from PHY ability with media */
1796 ice_phy_type_to_ethtool(netdev, ks);
1798 switch (link_info->link_speed) {
1799 case ICE_AQ_LINK_SPEED_100GB:
1800 ks->base.speed = SPEED_100000;
1802 case ICE_AQ_LINK_SPEED_50GB:
1803 ks->base.speed = SPEED_50000;
1805 case ICE_AQ_LINK_SPEED_40GB:
1806 ks->base.speed = SPEED_40000;
1808 case ICE_AQ_LINK_SPEED_25GB:
1809 ks->base.speed = SPEED_25000;
1811 case ICE_AQ_LINK_SPEED_20GB:
1812 ks->base.speed = SPEED_20000;
1814 case ICE_AQ_LINK_SPEED_10GB:
1815 ks->base.speed = SPEED_10000;
1817 case ICE_AQ_LINK_SPEED_5GB:
1818 ks->base.speed = SPEED_5000;
1820 case ICE_AQ_LINK_SPEED_2500MB:
1821 ks->base.speed = SPEED_2500;
1823 case ICE_AQ_LINK_SPEED_1000MB:
1824 ks->base.speed = SPEED_1000;
1826 case ICE_AQ_LINK_SPEED_100MB:
1827 ks->base.speed = SPEED_100;
1830 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
1831 link_info->link_speed);
1834 ks->base.duplex = DUPLEX_FULL;
1836 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
1837 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1840 /* Set flow control negotiated Rx/Tx pause */
1841 switch (pi->fc.current_mode) {
1843 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1845 case ICE_FC_TX_PAUSE:
1846 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
1847 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1850 case ICE_FC_RX_PAUSE:
1851 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
1856 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
1857 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
1864 * ice_get_settings_link_down - Get the Link settings when link is down
1865 * @ks: ethtool ksettings to fill in
1866 * @netdev: network interface device structure
1868 * Reports link settings that can be determined when link is down
1871 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
1872 struct net_device *netdev)
1874 /* link is down and the driver needs to fall back on
1875 * supported PHY types to figure out what info to display
1877 ice_phy_type_to_ethtool(netdev, ks);
1879 /* With no link, speed and duplex are unknown */
1880 ks->base.speed = SPEED_UNKNOWN;
1881 ks->base.duplex = DUPLEX_UNKNOWN;
1885 * ice_get_link_ksettings - Get Link Speed and Duplex settings
1886 * @netdev: network interface device structure
1887 * @ks: ethtool ksettings
1889 * Reports speed/duplex settings based on media_type
1892 ice_get_link_ksettings(struct net_device *netdev,
1893 struct ethtool_link_ksettings *ks)
1895 struct ice_netdev_priv *np = netdev_priv(netdev);
1896 struct ice_aqc_get_phy_caps_data *caps;
1897 struct ice_link_status *hw_link_info;
1898 struct ice_vsi *vsi = np->vsi;
1901 ethtool_link_ksettings_zero_link_mode(ks, supported);
1902 ethtool_link_ksettings_zero_link_mode(ks, advertising);
1903 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
1904 hw_link_info = &vsi->port_info->phy.link_info;
1906 /* set speed and duplex */
1907 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
1908 ice_get_settings_link_up(ks, netdev);
1910 ice_get_settings_link_down(ks, netdev);
1912 /* set autoneg settings */
1913 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
1914 AUTONEG_ENABLE : AUTONEG_DISABLE;
1916 /* set media type settings */
1917 switch (vsi->port_info->phy.media_type) {
1918 case ICE_MEDIA_FIBER:
1919 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1920 ks->base.port = PORT_FIBRE;
1922 case ICE_MEDIA_BASET:
1923 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
1924 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
1925 ks->base.port = PORT_TP;
1927 case ICE_MEDIA_BACKPLANE:
1928 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
1929 ethtool_link_ksettings_add_link_mode(ks, advertising,
1931 ks->base.port = PORT_NONE;
1934 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
1935 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
1936 ks->base.port = PORT_DA;
1939 ks->base.port = PORT_OTHER;
1943 /* flow control is symmetric and always supported */
1944 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
1946 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1950 err = ice_aq_get_phy_caps(vsi->port_info, false,
1951 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
1955 /* Set the advertised flow control based on the PHY capability */
1956 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
1957 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
1958 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1959 ethtool_link_ksettings_add_link_mode(ks, advertising,
1961 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
1962 ethtool_link_ksettings_add_link_mode(ks, advertising,
1964 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
1965 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
1966 ethtool_link_ksettings_add_link_mode(ks, advertising,
1969 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
1970 ethtool_link_ksettings_del_link_mode(ks, advertising,
1974 /* Set advertised FEC modes based on PHY capability */
1975 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
1977 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1978 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1979 ethtool_link_ksettings_add_link_mode(ks, advertising,
1981 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1982 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
1983 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
1985 err = ice_aq_get_phy_caps(vsi->port_info, false,
1986 ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL);
1990 /* Set supported FEC modes based on PHY capability */
1991 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
1993 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1994 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
1995 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
1996 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1997 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
1999 /* Set supported and advertised autoneg */
2000 if (ice_is_phy_caps_an_enabled(caps)) {
2001 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2002 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2011 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2012 * @ks: ethtool ksettings
2015 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2017 u16 adv_link_speed = 0;
2019 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2021 adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2022 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2024 ethtool_link_ksettings_test_link_mode(ks, advertising,
2026 ethtool_link_ksettings_test_link_mode(ks, advertising,
2028 adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2029 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2031 ethtool_link_ksettings_test_link_mode(ks, advertising,
2033 adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2034 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2036 adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2037 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2039 ethtool_link_ksettings_test_link_mode(ks, advertising,
2040 10000baseKR_Full) ||
2041 ethtool_link_ksettings_test_link_mode(ks, advertising,
2042 10000baseSR_Full) ||
2043 ethtool_link_ksettings_test_link_mode(ks, advertising,
2045 adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2046 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2047 25000baseCR_Full) ||
2048 ethtool_link_ksettings_test_link_mode(ks, advertising,
2049 25000baseSR_Full) ||
2050 ethtool_link_ksettings_test_link_mode(ks, advertising,
2052 adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2053 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2054 40000baseCR4_Full) ||
2055 ethtool_link_ksettings_test_link_mode(ks, advertising,
2056 40000baseSR4_Full) ||
2057 ethtool_link_ksettings_test_link_mode(ks, advertising,
2058 40000baseLR4_Full) ||
2059 ethtool_link_ksettings_test_link_mode(ks, advertising,
2061 adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2062 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2063 50000baseCR2_Full) ||
2064 ethtool_link_ksettings_test_link_mode(ks, advertising,
2065 50000baseKR2_Full) ||
2066 ethtool_link_ksettings_test_link_mode(ks, advertising,
2068 adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2069 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2070 100000baseCR4_Full) ||
2071 ethtool_link_ksettings_test_link_mode(ks, advertising,
2072 100000baseSR4_Full) ||
2073 ethtool_link_ksettings_test_link_mode(ks, advertising,
2074 100000baseLR4_ER4_Full) ||
2075 ethtool_link_ksettings_test_link_mode(ks, advertising,
2076 100000baseKR4_Full) ||
2077 ethtool_link_ksettings_test_link_mode(ks, advertising,
2078 100000baseCR2_Full) ||
2079 ethtool_link_ksettings_test_link_mode(ks, advertising,
2080 100000baseSR2_Full) ||
2081 ethtool_link_ksettings_test_link_mode(ks, advertising,
2082 100000baseKR2_Full))
2083 adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2085 return adv_link_speed;
2091 * @ks: ethtool_link_ksettings
2092 * @config: configuration that will be sent down to FW
2093 * @autoneg_enabled: autonegotiation is enabled or not
2094 * @autoneg_changed: will there a change in autonegotiation
2095 * @netdev: network interface device structure
2097 * Setup PHY autonegotiation feature
2100 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2101 struct ice_aqc_set_phy_cfg_data *config,
2102 u8 autoneg_enabled, u8 *autoneg_changed,
2103 struct net_device *netdev)
2107 *autoneg_changed = 0;
2110 if (autoneg_enabled == AUTONEG_ENABLE) {
2111 /* If autoneg was not already enabled */
2112 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2113 /* If autoneg is not supported, return error */
2114 if (!ethtool_link_ksettings_test_link_mode(ks,
2117 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2120 /* Autoneg is allowed to change */
2121 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2122 *autoneg_changed = 1;
2126 /* If autoneg is currently enabled */
2127 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2128 /* If autoneg is supported 10GBASE_T is the only PHY
2129 * that can disable it, so otherwise return error
2131 if (ethtool_link_ksettings_test_link_mode(ks,
2134 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2137 /* Autoneg is allowed to change */
2138 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2139 *autoneg_changed = 1;
2148 * ice_set_phy_type_from_speed - set phy_types based on speeds
2149 * and advertised modes
2150 * @ks: ethtool link ksettings struct
2151 * @phy_type_low: pointer to the lower part of phy_type
2152 * @phy_type_high: pointer to the higher part of phy_type
2153 * @adv_link_speed: targeted link speeds bitmap
2156 ice_set_phy_type_from_speed(const struct ethtool_link_ksettings *ks,
2157 u64 *phy_type_low, u64 *phy_type_high,
2160 /* Handle 1000M speed in a special way because ice_update_phy_type
2161 * enables all link modes, but having mixed copper and optical
2162 * standards is not supported.
2164 adv_link_speed &= ~ICE_AQ_LINK_SPEED_1000MB;
2166 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2168 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_T |
2169 ICE_PHY_TYPE_LOW_1G_SGMII;
2171 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2173 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_KX;
2175 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2177 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_SX |
2178 ICE_PHY_TYPE_LOW_1000BASE_LX;
2180 ice_update_phy_type(phy_type_low, phy_type_high, adv_link_speed);
2184 * ice_set_link_ksettings - Set Speed and Duplex
2185 * @netdev: network interface device structure
2186 * @ks: ethtool ksettings
2188 * Set speed/duplex per media_types advertised/forced
2191 ice_set_link_ksettings(struct net_device *netdev,
2192 const struct ethtool_link_ksettings *ks)
2194 struct ice_netdev_priv *np = netdev_priv(netdev);
2195 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT;
2196 struct ethtool_link_ksettings copy_ks = *ks;
2197 struct ethtool_link_ksettings safe_ks = {};
2198 struct ice_aqc_get_phy_caps_data *phy_caps;
2199 struct ice_aqc_set_phy_cfg_data config;
2200 u16 adv_link_speed, curr_link_speed;
2201 struct ice_pf *pf = np->vsi->back;
2202 struct ice_port_info *pi;
2203 u8 autoneg_changed = 0;
2204 u64 phy_type_high = 0;
2205 u64 phy_type_low = 0;
2209 pi = np->vsi->port_info;
2214 if (pi->phy.media_type != ICE_MEDIA_BASET &&
2215 pi->phy.media_type != ICE_MEDIA_FIBER &&
2216 pi->phy.media_type != ICE_MEDIA_BACKPLANE &&
2217 pi->phy.media_type != ICE_MEDIA_DA &&
2218 pi->phy.link_info.link_info & ICE_AQ_LINK_UP)
2221 phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL);
2225 /* Get the PHY capabilities based on media */
2226 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2227 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2230 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2235 /* save autoneg out of ksettings */
2236 autoneg = copy_ks.base.autoneg;
2238 /* Get link modes supported by hardware.*/
2239 ice_phy_type_to_ethtool(netdev, &safe_ks);
2241 /* and check against modes requested by user.
2242 * Return an error if unsupported mode was set.
2244 if (!bitmap_subset(copy_ks.link_modes.advertising,
2245 safe_ks.link_modes.supported,
2246 __ETHTOOL_LINK_MODE_MASK_NBITS)) {
2247 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags))
2248 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2253 /* get our own copy of the bits to check against */
2254 memset(&safe_ks, 0, sizeof(safe_ks));
2255 safe_ks.base.cmd = copy_ks.base.cmd;
2256 safe_ks.base.link_mode_masks_nwords =
2257 copy_ks.base.link_mode_masks_nwords;
2258 ice_get_link_ksettings(netdev, &safe_ks);
2260 /* set autoneg back to what it currently is */
2261 copy_ks.base.autoneg = safe_ks.base.autoneg;
2262 /* we don't compare the speed */
2263 copy_ks.base.speed = safe_ks.base.speed;
2265 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2266 * trying to set something that we do not support.
2268 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) {
2273 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2279 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2282 /* Copy the current user PHY configuration. The current user PHY
2283 * configuration is initialized during probe from PHY capabilities
2284 * software mode, and updated on set PHY configuration.
2286 config = pi->phy.curr_user_phy_cfg;
2288 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2291 err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed,
2297 /* Call to get the current link speed */
2298 pi->phy.get_link_info = true;
2299 err = ice_get_link_status(pi, &linkup);
2303 curr_link_speed = pi->phy.curr_user_speed_req;
2304 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2306 /* If speed didn't get set, set it to what it currently is.
2307 * This is needed because if advertise is 0 (as it is when autoneg
2308 * is disabled) then speed won't get set.
2310 if (!adv_link_speed)
2311 adv_link_speed = curr_link_speed;
2313 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2314 ice_set_phy_type_from_speed(ks, &phy_type_low, &phy_type_high,
2317 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2318 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2322 /* save the requested speeds */
2323 pi->phy.link_info.req_speeds = adv_link_speed;
2325 /* set link and auto negotiation so changes take effect */
2326 config.caps |= ICE_AQ_PHY_ENA_LINK;
2328 /* check if there is a PHY type for the requested advertised speed */
2329 if (!(phy_type_low || phy_type_high)) {
2330 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2335 /* intersect requested advertised speed PHY types with media PHY types
2336 * for set PHY configuration
2338 config.phy_type_high = cpu_to_le64(phy_type_high) &
2339 phy_caps->phy_type_high;
2340 config.phy_type_low = cpu_to_le64(phy_type_low) &
2341 phy_caps->phy_type_low;
2343 if (!(config.phy_type_high || config.phy_type_low)) {
2344 /* If there is no intersection and lenient mode is enabled, then
2345 * intersect the requested advertised speed with NVM media type
2348 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2349 config.phy_type_high = cpu_to_le64(phy_type_high) &
2350 pf->nvm_phy_type_hi;
2351 config.phy_type_low = cpu_to_le64(phy_type_low) &
2352 pf->nvm_phy_type_lo;
2354 netdev_info(netdev, "The selected speed is not supported by the current media. Please select a link speed that is supported by the current media.\n");
2360 /* If link is up put link down */
2361 if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2362 /* Tell the OS link is going down, the link will go
2363 * back up when fw says it is ready asynchronously
2365 ice_print_link_msg(np->vsi, false);
2366 netif_carrier_off(netdev);
2367 netif_tx_stop_all_queues(netdev);
2370 /* make the aq call */
2371 err = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL);
2373 netdev_info(netdev, "Set phy config failed,\n");
2377 /* Save speed request */
2378 pi->phy.curr_user_speed_req = adv_link_speed;
2381 clear_bit(ICE_CFG_BUSY, pf->state);
2387 * ice_parse_hdrs - parses headers from RSS hash input
2388 * @nfc: ethtool rxnfc command
2390 * This function parses the rxnfc command and returns intended
2391 * header types for RSS configuration
2393 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2395 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2397 switch (nfc->flow_type) {
2399 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2402 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2405 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2408 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2411 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2414 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2422 #define ICE_FLOW_HASH_FLD_IPV4_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)
2423 #define ICE_FLOW_HASH_FLD_IPV6_SA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)
2424 #define ICE_FLOW_HASH_FLD_IPV4_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)
2425 #define ICE_FLOW_HASH_FLD_IPV6_DA BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)
2426 #define ICE_FLOW_HASH_FLD_TCP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)
2427 #define ICE_FLOW_HASH_FLD_TCP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)
2428 #define ICE_FLOW_HASH_FLD_UDP_SRC_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)
2429 #define ICE_FLOW_HASH_FLD_UDP_DST_PORT BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)
2430 #define ICE_FLOW_HASH_FLD_SCTP_SRC_PORT \
2431 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)
2432 #define ICE_FLOW_HASH_FLD_SCTP_DST_PORT \
2433 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)
2436 * ice_parse_hash_flds - parses hash fields from RSS hash input
2437 * @nfc: ethtool rxnfc command
2439 * This function parses the rxnfc command and returns intended
2440 * hash fields for RSS configuration
2442 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc)
2444 u64 hfld = ICE_HASH_INVALID;
2446 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2447 switch (nfc->flow_type) {
2451 if (nfc->data & RXH_IP_SRC)
2452 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2453 if (nfc->data & RXH_IP_DST)
2454 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2459 if (nfc->data & RXH_IP_SRC)
2460 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2461 if (nfc->data & RXH_IP_DST)
2462 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2469 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2470 switch (nfc->flow_type) {
2473 if (nfc->data & RXH_L4_B_0_1)
2474 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2475 if (nfc->data & RXH_L4_B_2_3)
2476 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2480 if (nfc->data & RXH_L4_B_0_1)
2481 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2482 if (nfc->data & RXH_L4_B_2_3)
2483 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2487 if (nfc->data & RXH_L4_B_0_1)
2488 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2489 if (nfc->data & RXH_L4_B_2_3)
2490 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2501 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2502 * @vsi: the VSI being configured
2503 * @nfc: ethtool rxnfc command
2505 * Returns Success if the flow input set is supported.
2508 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2510 struct ice_pf *pf = vsi->back;
2516 dev = ice_pf_to_dev(pf);
2517 if (ice_is_safe_mode(pf)) {
2518 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2523 hashed_flds = ice_parse_hash_flds(nfc);
2524 if (hashed_flds == ICE_HASH_INVALID) {
2525 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
2530 hdrs = ice_parse_hdrs(nfc);
2531 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2532 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2537 status = ice_add_rss_cfg(&pf->hw, vsi->idx, hashed_flds, hdrs);
2539 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
2540 vsi->vsi_num, status);
2548 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
2549 * @vsi: the VSI being configured
2550 * @nfc: ethtool rxnfc command
2553 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
2555 struct ice_pf *pf = vsi->back;
2560 dev = ice_pf_to_dev(pf);
2563 if (ice_is_safe_mode(pf)) {
2564 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
2569 hdrs = ice_parse_hdrs(nfc);
2570 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
2571 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
2576 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs);
2577 if (hash_flds == ICE_HASH_INVALID) {
2578 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
2583 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
2584 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
2585 nfc->data |= (u64)RXH_IP_SRC;
2587 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
2588 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
2589 nfc->data |= (u64)RXH_IP_DST;
2591 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
2592 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
2593 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
2594 nfc->data |= (u64)RXH_L4_B_0_1;
2596 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
2597 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
2598 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
2599 nfc->data |= (u64)RXH_L4_B_2_3;
2603 * ice_set_rxnfc - command to set Rx flow rules.
2604 * @netdev: network interface device structure
2605 * @cmd: ethtool rxnfc command
2607 * Returns 0 for success and negative values for errors
2609 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
2611 struct ice_netdev_priv *np = netdev_priv(netdev);
2612 struct ice_vsi *vsi = np->vsi;
2615 case ETHTOOL_SRXCLSRLINS:
2616 return ice_add_fdir_ethtool(vsi, cmd);
2617 case ETHTOOL_SRXCLSRLDEL:
2618 return ice_del_fdir_ethtool(vsi, cmd);
2620 return ice_set_rss_hash_opt(vsi, cmd);
2628 * ice_get_rxnfc - command to get Rx flow classification rules
2629 * @netdev: network interface device structure
2630 * @cmd: ethtool rxnfc command
2631 * @rule_locs: buffer to rturn Rx flow classification rules
2633 * Returns Success if the command is supported.
2636 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2637 u32 __always_unused *rule_locs)
2639 struct ice_netdev_priv *np = netdev_priv(netdev);
2640 struct ice_vsi *vsi = np->vsi;
2641 int ret = -EOPNOTSUPP;
2644 hw = &vsi->back->hw;
2647 case ETHTOOL_GRXRINGS:
2648 cmd->data = vsi->rss_size;
2651 case ETHTOOL_GRXCLSRLCNT:
2652 cmd->rule_cnt = hw->fdir_active_fltr;
2653 /* report total rule count */
2654 cmd->data = ice_get_fdir_cnt_all(hw);
2657 case ETHTOOL_GRXCLSRULE:
2658 ret = ice_get_ethtool_fdir_entry(hw, cmd);
2660 case ETHTOOL_GRXCLSRLALL:
2661 ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs);
2664 ice_get_rss_hash_opt(vsi, cmd);
2675 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
2676 struct kernel_ethtool_ringparam *kernel_ring,
2677 struct netlink_ext_ack *extack)
2679 struct ice_netdev_priv *np = netdev_priv(netdev);
2680 struct ice_vsi *vsi = np->vsi;
2682 ring->rx_max_pending = ICE_MAX_NUM_DESC;
2683 ring->tx_max_pending = ICE_MAX_NUM_DESC;
2684 ring->rx_pending = vsi->rx_rings[0]->count;
2685 ring->tx_pending = vsi->tx_rings[0]->count;
2687 /* Rx mini and jumbo rings are not supported */
2688 ring->rx_mini_max_pending = 0;
2689 ring->rx_jumbo_max_pending = 0;
2690 ring->rx_mini_pending = 0;
2691 ring->rx_jumbo_pending = 0;
2695 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
2696 struct kernel_ethtool_ringparam *kernel_ring,
2697 struct netlink_ext_ack *extack)
2699 struct ice_netdev_priv *np = netdev_priv(netdev);
2700 struct ice_tx_ring *xdp_rings = NULL;
2701 struct ice_tx_ring *tx_rings = NULL;
2702 struct ice_rx_ring *rx_rings = NULL;
2703 struct ice_vsi *vsi = np->vsi;
2704 struct ice_pf *pf = vsi->back;
2705 int i, timeout = 50, err = 0;
2706 u16 new_rx_cnt, new_tx_cnt;
2708 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2709 ring->tx_pending < ICE_MIN_NUM_DESC ||
2710 ring->rx_pending > ICE_MAX_NUM_DESC ||
2711 ring->rx_pending < ICE_MIN_NUM_DESC) {
2712 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2713 ring->tx_pending, ring->rx_pending,
2714 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2715 ICE_REQ_DESC_MULTIPLE);
2719 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2720 if (new_tx_cnt != ring->tx_pending)
2721 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
2723 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2724 if (new_rx_cnt != ring->rx_pending)
2725 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
2728 /* if nothing to do return success */
2729 if (new_tx_cnt == vsi->tx_rings[0]->count &&
2730 new_rx_cnt == vsi->rx_rings[0]->count) {
2731 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2735 /* If there is a AF_XDP UMEM attached to any of Rx rings,
2736 * disallow changing the number of descriptors -- regardless
2737 * if the netdev is running or not.
2739 if (ice_xsk_any_rx_ring_ena(vsi))
2742 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2746 usleep_range(1000, 2000);
2749 /* set for the next time the netdev is started */
2750 if (!netif_running(vsi->netdev)) {
2751 ice_for_each_alloc_txq(vsi, i)
2752 vsi->tx_rings[i]->count = new_tx_cnt;
2753 ice_for_each_alloc_rxq(vsi, i)
2754 vsi->rx_rings[i]->count = new_rx_cnt;
2755 if (ice_is_xdp_ena_vsi(vsi))
2756 ice_for_each_xdp_txq(vsi, i)
2757 vsi->xdp_rings[i]->count = new_tx_cnt;
2758 vsi->num_tx_desc = (u16)new_tx_cnt;
2759 vsi->num_rx_desc = (u16)new_rx_cnt;
2760 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2764 if (new_tx_cnt == vsi->tx_rings[0]->count)
2767 /* alloc updated Tx resources */
2768 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2769 vsi->tx_rings[0]->count, new_tx_cnt);
2771 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
2777 ice_for_each_txq(vsi, i) {
2778 /* clone ring and setup updated count */
2779 tx_rings[i] = *vsi->tx_rings[i];
2780 tx_rings[i].count = new_tx_cnt;
2781 tx_rings[i].desc = NULL;
2782 tx_rings[i].tx_buf = NULL;
2783 tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
2784 err = ice_setup_tx_ring(&tx_rings[i]);
2787 ice_clean_tx_ring(&tx_rings[i]);
2793 if (!ice_is_xdp_ena_vsi(vsi))
2796 /* alloc updated XDP resources */
2797 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2798 vsi->xdp_rings[0]->count, new_tx_cnt);
2800 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
2806 ice_for_each_xdp_txq(vsi, i) {
2807 /* clone ring and setup updated count */
2808 xdp_rings[i] = *vsi->xdp_rings[i];
2809 xdp_rings[i].count = new_tx_cnt;
2810 xdp_rings[i].desc = NULL;
2811 xdp_rings[i].tx_buf = NULL;
2812 err = ice_setup_tx_ring(&xdp_rings[i]);
2815 ice_clean_tx_ring(&xdp_rings[i]);
2819 ice_set_ring_xdp(&xdp_rings[i]);
2823 if (new_rx_cnt == vsi->rx_rings[0]->count)
2826 /* alloc updated Rx resources */
2827 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2828 vsi->rx_rings[0]->count, new_rx_cnt);
2830 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
2836 ice_for_each_rxq(vsi, i) {
2837 /* clone ring and setup updated count */
2838 rx_rings[i] = *vsi->rx_rings[i];
2839 rx_rings[i].count = new_rx_cnt;
2840 rx_rings[i].cached_phctime = pf->ptp.cached_phc_time;
2841 rx_rings[i].desc = NULL;
2842 rx_rings[i].rx_buf = NULL;
2843 /* this is to allow wr32 to have something to write to
2844 * during early allocation of Rx buffers
2846 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2848 err = ice_setup_rx_ring(&rx_rings[i]);
2852 /* allocate Rx buffers */
2853 err = ice_alloc_rx_bufs(&rx_rings[i],
2854 ICE_RX_DESC_UNUSED(&rx_rings[i]));
2859 ice_free_rx_ring(&rx_rings[i]);
2868 /* Bring interface down, copy in the new ring info, then restore the
2869 * interface. if VSI is up, bring it down and then back up
2871 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2875 ice_for_each_txq(vsi, i) {
2876 ice_free_tx_ring(vsi->tx_rings[i]);
2877 *vsi->tx_rings[i] = tx_rings[i];
2883 ice_for_each_rxq(vsi, i) {
2884 ice_free_rx_ring(vsi->rx_rings[i]);
2885 /* copy the real tail offset */
2886 rx_rings[i].tail = vsi->rx_rings[i]->tail;
2887 /* this is to fake out the allocation routine
2888 * into thinking it has to realloc everything
2889 * but the recycling logic will let us re-use
2890 * the buffers allocated above
2892 rx_rings[i].next_to_use = 0;
2893 rx_rings[i].next_to_clean = 0;
2894 rx_rings[i].next_to_alloc = 0;
2895 *vsi->rx_rings[i] = rx_rings[i];
2901 ice_for_each_xdp_txq(vsi, i) {
2902 ice_free_tx_ring(vsi->xdp_rings[i]);
2903 *vsi->xdp_rings[i] = xdp_rings[i];
2908 vsi->num_tx_desc = new_tx_cnt;
2909 vsi->num_rx_desc = new_rx_cnt;
2915 /* error cleanup if the Rx allocations failed after getting Tx */
2917 ice_for_each_txq(vsi, i)
2918 ice_free_tx_ring(&tx_rings[i]);
2923 clear_bit(ICE_CFG_BUSY, pf->state);
2928 * ice_get_pauseparam - Get Flow Control status
2929 * @netdev: network interface device structure
2930 * @pause: ethernet pause (flow control) parameters
2932 * Get requested flow control status from PHY capability.
2933 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2934 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2935 * the negotiated Rx/Tx pause via lp_advertising.
2938 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2940 struct ice_netdev_priv *np = netdev_priv(netdev);
2941 struct ice_port_info *pi = np->vsi->port_info;
2942 struct ice_aqc_get_phy_caps_data *pcaps;
2943 struct ice_dcbx_cfg *dcbx_cfg;
2946 /* Initialize pause params */
2947 pause->rx_pause = 0;
2948 pause->tx_pause = 0;
2950 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
2952 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2956 /* Get current PHY config */
2957 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2962 pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
2965 if (dcbx_cfg->pfc.pfcena)
2966 /* PFC enabled so report LFC as off */
2969 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2970 pause->tx_pause = 1;
2971 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2972 pause->rx_pause = 1;
2979 * ice_set_pauseparam - Set Flow Control parameter
2980 * @netdev: network interface device structure
2981 * @pause: return Tx/Rx flow control status
2984 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2986 struct ice_netdev_priv *np = netdev_priv(netdev);
2987 struct ice_aqc_get_phy_caps_data *pcaps;
2988 struct ice_link_status *hw_link_info;
2989 struct ice_pf *pf = np->vsi->back;
2990 struct ice_dcbx_cfg *dcbx_cfg;
2991 struct ice_vsi *vsi = np->vsi;
2992 struct ice_hw *hw = &pf->hw;
2993 struct ice_port_info *pi;
2999 pi = vsi->port_info;
3000 hw_link_info = &pi->phy.link_info;
3001 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3002 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
3004 /* Changing the port's flow control is not supported if this isn't the
3007 if (vsi->type != ICE_VSI_PF) {
3008 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
3012 /* Get pause param reports configured and negotiated flow control pause
3013 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
3014 * defined get pause param pause->autoneg reports SW configured setting,
3015 * so compare pause->autoneg with SW configured to prevent the user from
3016 * using set pause param to chance autoneg.
3018 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3022 /* Get current PHY config */
3023 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3030 is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3035 if (pause->autoneg != is_an) {
3036 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
3040 /* If we have link and don't have autoneg */
3041 if (!test_bit(ICE_DOWN, pf->state) &&
3042 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
3043 /* Send message that it might not necessarily work*/
3044 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
3047 if (dcbx_cfg->pfc.pfcena) {
3048 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
3051 if (pause->rx_pause && pause->tx_pause)
3052 pi->fc.req_mode = ICE_FC_FULL;
3053 else if (pause->rx_pause && !pause->tx_pause)
3054 pi->fc.req_mode = ICE_FC_RX_PAUSE;
3055 else if (!pause->rx_pause && pause->tx_pause)
3056 pi->fc.req_mode = ICE_FC_TX_PAUSE;
3057 else if (!pause->rx_pause && !pause->tx_pause)
3058 pi->fc.req_mode = ICE_FC_NONE;
3062 /* Set the FC mode and only restart AN if link is up */
3063 err = ice_set_fc(pi, &aq_failures, link_up);
3065 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
3066 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n",
3067 err, ice_aq_str(hw->adminq.sq_last_status));
3069 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
3070 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %s\n",
3071 err, ice_aq_str(hw->adminq.sq_last_status));
3073 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
3074 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %s\n",
3075 err, ice_aq_str(hw->adminq.sq_last_status));
3083 * ice_get_rxfh_key_size - get the RSS hash key size
3084 * @netdev: network interface device structure
3086 * Returns the table size.
3088 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3090 return ICE_VSIQF_HKEY_ARRAY_SIZE;
3094 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3095 * @netdev: network interface device structure
3097 * Returns the table size.
3099 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3101 struct ice_netdev_priv *np = netdev_priv(netdev);
3103 return np->vsi->rss_table_size;
3107 ice_get_rxfh_context(struct net_device *netdev, u32 *indir,
3108 u8 *key, u8 *hfunc, u32 rss_context)
3110 struct ice_netdev_priv *np = netdev_priv(netdev);
3111 struct ice_vsi *vsi = np->vsi;
3112 struct ice_pf *pf = vsi->back;
3117 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3118 netdev_warn(netdev, "RSS is not supported on this VSI!\n");
3122 if (rss_context && !ice_is_adq_active(pf)) {
3123 netdev_err(netdev, "RSS context cannot be non-zero when ADQ is not configured.\n");
3127 qcount = vsi->mqprio_qopt.qopt.count[rss_context];
3128 offset = vsi->mqprio_qopt.qopt.offset[rss_context];
3130 if (rss_context && ice_is_adq_active(pf)) {
3131 num_tc = vsi->mqprio_qopt.qopt.num_tc;
3132 if (rss_context >= num_tc) {
3133 netdev_err(netdev, "RSS context:%d > num_tc:%d\n",
3134 rss_context, num_tc);
3137 /* Use channel VSI of given TC */
3138 vsi = vsi->tc_map_vsi[rss_context];
3142 *hfunc = ETH_RSS_HASH_TOP;
3147 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3151 err = ice_get_rss_key(vsi, key);
3155 err = ice_get_rss_lut(vsi, lut, vsi->rss_table_size);
3159 if (ice_is_adq_active(pf)) {
3160 for (i = 0; i < vsi->rss_table_size; i++)
3161 indir[i] = offset + lut[i] % qcount;
3165 for (i = 0; i < vsi->rss_table_size; i++)
3174 * ice_get_rxfh - get the Rx flow hash indirection table
3175 * @netdev: network interface device structure
3176 * @indir: indirection table
3178 * @hfunc: hash function
3180 * Reads the indirection table directly from the hardware.
3183 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3185 return ice_get_rxfh_context(netdev, indir, key, hfunc, 0);
3189 * ice_set_rxfh - set the Rx flow hash indirection table
3190 * @netdev: network interface device structure
3191 * @indir: indirection table
3193 * @hfunc: hash function
3195 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3196 * returns 0 after programming the table.
3199 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3202 struct ice_netdev_priv *np = netdev_priv(netdev);
3203 struct ice_vsi *vsi = np->vsi;
3204 struct ice_pf *pf = vsi->back;
3208 dev = ice_pf_to_dev(pf);
3209 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3212 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3213 /* RSS not supported return error here */
3214 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3218 if (ice_is_adq_active(pf)) {
3219 netdev_err(netdev, "Cannot change RSS params with ADQ configured.\n");
3224 if (!vsi->rss_hkey_user) {
3225 vsi->rss_hkey_user =
3226 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3228 if (!vsi->rss_hkey_user)
3231 memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3233 err = ice_set_rss_key(vsi, vsi->rss_hkey_user);
3238 if (!vsi->rss_lut_user) {
3239 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3241 if (!vsi->rss_lut_user)
3245 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3249 for (i = 0; i < vsi->rss_table_size; i++)
3250 vsi->rss_lut_user[i] = (u8)(indir[i]);
3252 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3256 err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size);
3264 ice_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
3266 struct ice_pf *pf = ice_netdev_to_pf(dev);
3268 /* only report timestamping if PTP is enabled */
3269 if (!test_bit(ICE_FLAG_PTP, pf->flags))
3270 return ethtool_op_get_ts_info(dev, info);
3272 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
3273 SOF_TIMESTAMPING_RX_SOFTWARE |
3274 SOF_TIMESTAMPING_SOFTWARE |
3275 SOF_TIMESTAMPING_TX_HARDWARE |
3276 SOF_TIMESTAMPING_RX_HARDWARE |
3277 SOF_TIMESTAMPING_RAW_HARDWARE;
3279 info->phc_index = ice_get_ptp_clock_index(pf);
3281 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
3283 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
3289 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3292 static int ice_get_max_txq(struct ice_pf *pf)
3294 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3295 (u16)pf->hw.func_caps.common_cap.num_txq);
3299 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3302 static int ice_get_max_rxq(struct ice_pf *pf)
3304 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3305 (u16)pf->hw.func_caps.common_cap.num_rxq);
3309 * ice_get_combined_cnt - return the current number of combined channels
3310 * @vsi: PF VSI pointer
3312 * Go through all queue vectors and count ones that have both Rx and Tx ring
3315 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3320 ice_for_each_q_vector(vsi, q_idx) {
3321 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3323 if (q_vector->rx.rx_ring && q_vector->tx.tx_ring)
3331 * ice_get_channels - get the current and max supported channels
3332 * @dev: network interface device structure
3333 * @ch: ethtool channel data structure
3336 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3338 struct ice_netdev_priv *np = netdev_priv(dev);
3339 struct ice_vsi *vsi = np->vsi;
3340 struct ice_pf *pf = vsi->back;
3342 /* report maximum channels */
3343 ch->max_rx = ice_get_max_rxq(pf);
3344 ch->max_tx = ice_get_max_txq(pf);
3345 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3347 /* report current channels */
3348 ch->combined_count = ice_get_combined_cnt(vsi);
3349 ch->rx_count = vsi->num_rxq - ch->combined_count;
3350 ch->tx_count = vsi->num_txq - ch->combined_count;
3352 /* report other queues */
3353 ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
3354 ch->max_other = ch->other_count;
3358 * ice_get_valid_rss_size - return valid number of RSS queues
3359 * @hw: pointer to the HW structure
3360 * @new_size: requested RSS queues
3362 static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size)
3364 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3366 return min_t(int, new_size, BIT(caps->rss_table_entry_width));
3370 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3371 * @vsi: VSI to reconfigure RSS LUT on
3372 * @req_rss_size: requested range of queue numbers for hashing
3374 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3376 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3378 struct ice_pf *pf = vsi->back;
3384 dev = ice_pf_to_dev(pf);
3390 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3394 /* set RSS LUT parameters */
3395 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3398 vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size);
3400 /* create/set RSS LUT */
3401 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3402 err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
3404 dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err,
3405 ice_aq_str(hw->adminq.sq_last_status));
3412 * ice_set_channels - set the number channels
3413 * @dev: network interface device structure
3414 * @ch: ethtool channel data structure
3416 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3418 struct ice_netdev_priv *np = netdev_priv(dev);
3419 struct ice_vsi *vsi = np->vsi;
3420 struct ice_pf *pf = vsi->back;
3421 int new_rx = 0, new_tx = 0;
3422 bool locked = false;
3426 /* do not support changing channels in Safe Mode */
3427 if (ice_is_safe_mode(pf)) {
3428 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3431 /* do not support changing other_count */
3432 if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U))
3435 if (ice_is_adq_active(pf)) {
3436 netdev_err(dev, "Cannot set channels with ADQ configured.\n");
3440 if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) {
3441 netdev_err(dev, "Cannot set channels when Flow Director filters are active\n");
3445 curr_combined = ice_get_combined_cnt(vsi);
3447 /* these checks are for cases where user didn't specify a particular
3448 * value on cmd line but we get non-zero value anyway via
3449 * get_channels(); look at ethtool.c in ethtool repository (the user
3450 * space part), particularly, do_schannels() routine
3452 if (ch->rx_count == vsi->num_rxq - curr_combined)
3454 if (ch->tx_count == vsi->num_txq - curr_combined)
3456 if (ch->combined_count == curr_combined)
3457 ch->combined_count = 0;
3459 if (!(ch->combined_count || (ch->rx_count && ch->tx_count))) {
3460 netdev_err(dev, "Please specify at least 1 Rx and 1 Tx channel\n");
3464 new_rx = ch->combined_count + ch->rx_count;
3465 new_tx = ch->combined_count + ch->tx_count;
3467 if (new_rx < vsi->tc_cfg.numtc) {
3468 netdev_err(dev, "Cannot set less Rx channels, than Traffic Classes you have (%u)\n",
3472 if (new_tx < vsi->tc_cfg.numtc) {
3473 netdev_err(dev, "Cannot set less Tx channels, than Traffic Classes you have (%u)\n",
3477 if (new_rx > ice_get_max_rxq(pf)) {
3478 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3479 ice_get_max_rxq(pf));
3482 if (new_tx > ice_get_max_txq(pf)) {
3483 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3484 ice_get_max_txq(pf));
3489 mutex_lock(&pf->adev_mutex);
3490 device_lock(&pf->adev->dev);
3492 if (pf->adev->dev.driver) {
3493 netdev_err(dev, "Cannot change channels when RDMA is active\n");
3499 ice_vsi_recfg_qs(vsi, new_rx, new_tx, locked);
3501 if (!netif_is_rxfh_configured(dev)) {
3502 ret = ice_vsi_set_dflt_rss_lut(vsi, new_rx);
3506 /* Update rss_size due to change in Rx queues */
3507 vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx);
3511 device_unlock(&pf->adev->dev);
3512 mutex_unlock(&pf->adev_mutex);
3518 * ice_get_wol - get current Wake on LAN configuration
3519 * @netdev: network interface device structure
3520 * @wol: Ethtool structure to retrieve WoL settings
3522 static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3524 struct ice_netdev_priv *np = netdev_priv(netdev);
3525 struct ice_pf *pf = np->vsi->back;
3527 if (np->vsi->type != ICE_VSI_PF)
3528 netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
3530 /* Get WoL settings based on the HW capability */
3531 if (ice_is_wol_supported(&pf->hw)) {
3532 wol->supported = WAKE_MAGIC;
3533 wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
3541 * ice_set_wol - set Wake on LAN on supported device
3542 * @netdev: network interface device structure
3543 * @wol: Ethtool structure to set WoL
3545 static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
3547 struct ice_netdev_priv *np = netdev_priv(netdev);
3548 struct ice_vsi *vsi = np->vsi;
3549 struct ice_pf *pf = vsi->back;
3551 if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw))
3554 /* only magic packet is supported */
3555 if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
3558 /* Set WoL only if there is a new value */
3559 if (pf->wol_ena != !!wol->wolopts) {
3560 pf->wol_ena = !!wol->wolopts;
3561 device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
3562 netdev_dbg(netdev, "WoL magic packet %sabled\n",
3563 pf->wol_ena ? "en" : "dis");
3570 * ice_get_rc_coalesce - get ITR values for specific ring container
3571 * @ec: ethtool structure to fill with driver's coalesce settings
3572 * @rc: ring container that the ITR values will come from
3574 * Query the device for ice_ring_container specific ITR values. This is
3575 * done per ice_ring_container because each q_vector can have 1 or more rings
3576 * and all of said ring(s) will have the same ITR values.
3578 * Returns 0 on success, negative otherwise.
3581 ice_get_rc_coalesce(struct ethtool_coalesce *ec, struct ice_ring_container *rc)
3587 case ICE_RX_CONTAINER:
3588 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc);
3589 ec->rx_coalesce_usecs = rc->itr_setting;
3590 ec->rx_coalesce_usecs_high = rc->rx_ring->q_vector->intrl;
3592 case ICE_TX_CONTAINER:
3593 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc);
3594 ec->tx_coalesce_usecs = rc->itr_setting;
3597 dev_dbg(ice_pf_to_dev(rc->rx_ring->vsi->back), "Invalid c_type %d\n", rc->type);
3605 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3606 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3607 * @ec: coalesce settings to program the device with
3608 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3610 * Return 0 on success, and negative under the following conditions:
3611 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3612 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3615 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3617 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3618 if (ice_get_rc_coalesce(ec,
3619 &vsi->rx_rings[q_num]->q_vector->rx))
3621 if (ice_get_rc_coalesce(ec,
3622 &vsi->tx_rings[q_num]->q_vector->tx))
3624 } else if (q_num < vsi->num_rxq) {
3625 if (ice_get_rc_coalesce(ec,
3626 &vsi->rx_rings[q_num]->q_vector->rx))
3628 } else if (q_num < vsi->num_txq) {
3629 if (ice_get_rc_coalesce(ec,
3630 &vsi->tx_rings[q_num]->q_vector->tx))
3640 * __ice_get_coalesce - get ITR/INTRL values for the device
3641 * @netdev: pointer to the netdev associated with this query
3642 * @ec: ethtool structure to fill with driver's coalesce settings
3643 * @q_num: queue number to get the coalesce settings for
3645 * If the caller passes in a negative q_num then we return coalesce settings
3646 * based on queue number 0, else use the actual q_num passed in.
3649 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3652 struct ice_netdev_priv *np = netdev_priv(netdev);
3653 struct ice_vsi *vsi = np->vsi;
3658 if (ice_get_q_coalesce(vsi, ec, q_num))
3664 static int ice_get_coalesce(struct net_device *netdev,
3665 struct ethtool_coalesce *ec,
3666 struct kernel_ethtool_coalesce *kernel_coal,
3667 struct netlink_ext_ack *extack)
3669 return __ice_get_coalesce(netdev, ec, -1);
3673 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3674 struct ethtool_coalesce *ec)
3676 return __ice_get_coalesce(netdev, ec, q_num);
3680 * ice_set_rc_coalesce - set ITR values for specific ring container
3681 * @ec: ethtool structure from user to update ITR settings
3682 * @rc: ring container that the ITR values will come from
3683 * @vsi: VSI associated to the ring container
3685 * Set specific ITR values. This is done per ice_ring_container because each
3686 * q_vector can have 1 or more rings and all of said ring(s) will have the same
3689 * Returns 0 on success, negative otherwise.
3692 ice_set_rc_coalesce(struct ethtool_coalesce *ec,
3693 struct ice_ring_container *rc, struct ice_vsi *vsi)
3695 const char *c_type_str = (rc->type == ICE_RX_CONTAINER) ? "rx" : "tx";
3696 u32 use_adaptive_coalesce, coalesce_usecs;
3697 struct ice_pf *pf = vsi->back;
3704 case ICE_RX_CONTAINER:
3706 struct ice_q_vector *q_vector = rc->rx_ring->q_vector;
3708 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3709 (ec->rx_coalesce_usecs_high &&
3710 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3711 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3712 c_type_str, pf->hw.intrl_gran,
3716 if (ec->rx_coalesce_usecs_high != q_vector->intrl &&
3717 (ec->use_adaptive_rx_coalesce || ec->use_adaptive_tx_coalesce)) {
3718 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high cannot be changed if adaptive-tx or adaptive-rx is enabled\n",
3722 if (ec->rx_coalesce_usecs_high != q_vector->intrl)
3723 q_vector->intrl = ec->rx_coalesce_usecs_high;
3725 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3726 coalesce_usecs = ec->rx_coalesce_usecs;
3730 case ICE_TX_CONTAINER:
3731 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3732 coalesce_usecs = ec->tx_coalesce_usecs;
3736 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
3741 itr_setting = rc->itr_setting;
3742 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3743 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3744 c_type_str, c_type_str);
3748 if (coalesce_usecs > ICE_ITR_MAX) {
3749 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
3750 c_type_str, ICE_ITR_MAX);
3754 if (use_adaptive_coalesce) {
3755 rc->itr_mode = ITR_DYNAMIC;
3757 rc->itr_mode = ITR_STATIC;
3758 /* store user facing value how it was set */
3759 rc->itr_setting = coalesce_usecs;
3760 /* write the change to the register */
3761 ice_write_itr(rc, coalesce_usecs);
3762 /* force writes to take effect immediately, the flush shouldn't
3763 * be done in the functions above because the intent is for
3764 * them to do lazy writes.
3773 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3774 * @vsi: VSI associated to the queue that need updating
3775 * @ec: coalesce settings to program the device with
3776 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3778 * Return 0 on success, and negative under the following conditions:
3779 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3780 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3783 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3785 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3786 if (ice_set_rc_coalesce(ec,
3787 &vsi->rx_rings[q_num]->q_vector->rx,
3791 if (ice_set_rc_coalesce(ec,
3792 &vsi->tx_rings[q_num]->q_vector->tx,
3795 } else if (q_num < vsi->num_rxq) {
3796 if (ice_set_rc_coalesce(ec,
3797 &vsi->rx_rings[q_num]->q_vector->rx,
3800 } else if (q_num < vsi->num_txq) {
3801 if (ice_set_rc_coalesce(ec,
3802 &vsi->tx_rings[q_num]->q_vector->tx,
3813 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
3814 * @netdev: netdev used for print
3815 * @itr_setting: previous user setting
3816 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
3817 * @coalesce_usecs: requested value of [tx|rx]-usecs
3818 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
3821 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
3822 u32 use_adaptive_coalesce, u32 coalesce_usecs,
3823 const char *c_type_str)
3825 if (use_adaptive_coalesce)
3828 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
3829 netdev_info(netdev, "User set %s-usecs to %d, device only supports even values. Rounding down and attempting to set %s-usecs to %d\n",
3830 c_type_str, coalesce_usecs, c_type_str,
3831 ITR_REG_ALIGN(coalesce_usecs));
3835 * __ice_set_coalesce - set ITR/INTRL values for the device
3836 * @netdev: pointer to the netdev associated with this query
3837 * @ec: ethtool structure to fill with driver's coalesce settings
3838 * @q_num: queue number to get the coalesce settings for
3840 * If the caller passes in a negative q_num then we set the coalesce settings
3841 * for all Tx/Rx queues, else use the actual q_num passed in.
3844 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3847 struct ice_netdev_priv *np = netdev_priv(netdev);
3848 struct ice_vsi *vsi = np->vsi;
3851 struct ice_q_vector *q_vector = vsi->q_vectors[0];
3855 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
3856 ec->use_adaptive_rx_coalesce,
3857 ec->rx_coalesce_usecs, "rx");
3859 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
3860 ec->use_adaptive_tx_coalesce,
3861 ec->tx_coalesce_usecs, "tx");
3864 ice_for_each_q_vector(vsi, v_idx) {
3865 /* In some cases if DCB is configured the num_[rx|tx]q
3866 * can be less than vsi->num_q_vectors. This check
3867 * accounts for that so we don't report a false failure
3869 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
3872 if (ice_set_q_coalesce(vsi, ec, v_idx))
3875 ice_set_q_vector_intrl(vsi->q_vectors[v_idx]);
3880 if (ice_set_q_coalesce(vsi, ec, q_num))
3883 ice_set_q_vector_intrl(vsi->q_vectors[q_num]);
3889 static int ice_set_coalesce(struct net_device *netdev,
3890 struct ethtool_coalesce *ec,
3891 struct kernel_ethtool_coalesce *kernel_coal,
3892 struct netlink_ext_ack *extack)
3894 return __ice_set_coalesce(netdev, ec, -1);
3898 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3899 struct ethtool_coalesce *ec)
3901 return __ice_set_coalesce(netdev, ec, q_num);
3905 ice_repr_get_drvinfo(struct net_device *netdev,
3906 struct ethtool_drvinfo *drvinfo)
3908 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3910 if (ice_check_vf_ready_for_cfg(repr->vf))
3913 __ice_get_drvinfo(netdev, drvinfo, repr->src_vsi);
3917 ice_repr_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
3919 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3921 /* for port representors only ETH_SS_STATS is supported */
3922 if (ice_check_vf_ready_for_cfg(repr->vf) ||
3923 stringset != ETH_SS_STATS)
3926 __ice_get_strings(netdev, stringset, data, repr->src_vsi);
3930 ice_repr_get_ethtool_stats(struct net_device *netdev,
3931 struct ethtool_stats __always_unused *stats,
3934 struct ice_repr *repr = ice_netdev_to_repr(netdev);
3936 if (ice_check_vf_ready_for_cfg(repr->vf))
3939 __ice_get_ethtool_stats(netdev, stats, data, repr->src_vsi);
3942 static int ice_repr_get_sset_count(struct net_device *netdev, int sset)
3946 return ICE_VSI_STATS_LEN;
3952 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
3953 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
3954 #define ICE_MODULE_TYPE_SFP 0x03
3955 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
3956 #define ICE_MODULE_TYPE_QSFP28 0x11
3957 #define ICE_MODULE_SFF_ADDR_MODE 0x04
3958 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
3959 #define ICE_MODULE_REVISION_ADDR 0x01
3960 #define ICE_MODULE_SFF_8472_COMP 0x5E
3961 #define ICE_MODULE_SFF_8472_SWAP 0x5C
3962 #define ICE_MODULE_QSFP_MAX_LEN 640
3965 * ice_get_module_info - get SFF module type and revision information
3966 * @netdev: network interface device structure
3967 * @modinfo: module EEPROM size and layout information structure
3970 ice_get_module_info(struct net_device *netdev,
3971 struct ethtool_modinfo *modinfo)
3973 struct ice_netdev_priv *np = netdev_priv(netdev);
3974 struct ice_vsi *vsi = np->vsi;
3975 struct ice_pf *pf = vsi->back;
3976 struct ice_hw *hw = &pf->hw;
3977 u8 sff8472_comp = 0;
3978 u8 sff8472_swap = 0;
3983 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3984 0, &value, 1, 0, NULL);
3989 case ICE_MODULE_TYPE_SFP:
3990 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3991 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3992 &sff8472_comp, 1, 0, NULL);
3995 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3996 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3997 &sff8472_swap, 1, 0, NULL);
4001 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
4002 modinfo->type = ETH_MODULE_SFF_8079;
4003 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4004 } else if (sff8472_comp &&
4005 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
4006 modinfo->type = ETH_MODULE_SFF_8472;
4007 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4009 modinfo->type = ETH_MODULE_SFF_8079;
4010 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4013 case ICE_MODULE_TYPE_QSFP_PLUS:
4014 case ICE_MODULE_TYPE_QSFP28:
4015 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4016 ICE_MODULE_REVISION_ADDR, 0x00, 0,
4017 &sff8636_rev, 1, 0, NULL);
4020 /* Check revision compliance */
4021 if (sff8636_rev > 0x02) {
4022 /* Module is SFF-8636 compliant */
4023 modinfo->type = ETH_MODULE_SFF_8636;
4024 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4026 modinfo->type = ETH_MODULE_SFF_8436;
4027 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4031 netdev_warn(netdev, "SFF Module Type not recognized.\n");
4038 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
4039 * @netdev: network interface device structure
4040 * @ee: EEPROM dump request structure
4041 * @data: buffer to be filled with EEPROM contents
4044 ice_get_module_eeprom(struct net_device *netdev,
4045 struct ethtool_eeprom *ee, u8 *data)
4047 struct ice_netdev_priv *np = netdev_priv(netdev);
4048 #define SFF_READ_BLOCK_SIZE 8
4049 u8 value[SFF_READ_BLOCK_SIZE] = { 0 };
4050 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
4051 struct ice_vsi *vsi = np->vsi;
4052 struct ice_pf *pf = vsi->back;
4053 struct ice_hw *hw = &pf->hw;
4054 bool is_sfp = false;
4060 if (!ee || !ee->len || !data)
4063 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
4068 if (value[0] == ICE_MODULE_TYPE_SFP)
4071 memset(data, 0, ee->len);
4072 for (i = 0; i < ee->len; i += SFF_READ_BLOCK_SIZE) {
4073 offset = i + ee->offset;
4076 /* Check if we need to access the other memory page */
4078 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4079 offset -= ETH_MODULE_SFF_8079_LEN;
4080 addr = ICE_I2C_EEPROM_DEV_ADDR2;
4083 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4084 /* Compute memory page number and offset. */
4085 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4090 /* Bit 2 of EEPROM address 0x02 declares upper
4091 * pages are disabled on QSFP modules.
4092 * SFP modules only ever use page 0.
4094 if (page == 0 || !(data[0x2] & 0x4)) {
4097 /* If i2c bus is busy due to slow page change or
4098 * link management access, call can fail. This is normal.
4099 * So we retry this a few times.
4101 for (j = 0; j < 4; j++) {
4102 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page,
4104 SFF_READ_BLOCK_SIZE,
4106 netdev_dbg(netdev, "SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%X)\n",
4107 addr, offset, page, is_sfp,
4108 value[0], value[1], value[2], value[3],
4109 value[4], value[5], value[6], value[7],
4112 usleep_range(1500, 2500);
4113 memset(value, 0, SFF_READ_BLOCK_SIZE);
4119 /* Make sure we have enough room for the new block */
4120 copy_len = min_t(u32, SFF_READ_BLOCK_SIZE, ee->len - i);
4121 memcpy(data + i, value, copy_len);
4127 static const struct ethtool_ops ice_ethtool_ops = {
4128 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
4129 ETHTOOL_COALESCE_USE_ADAPTIVE |
4130 ETHTOOL_COALESCE_RX_USECS_HIGH,
4131 .get_link_ksettings = ice_get_link_ksettings,
4132 .set_link_ksettings = ice_set_link_ksettings,
4133 .get_drvinfo = ice_get_drvinfo,
4134 .get_regs_len = ice_get_regs_len,
4135 .get_regs = ice_get_regs,
4136 .get_wol = ice_get_wol,
4137 .set_wol = ice_set_wol,
4138 .get_msglevel = ice_get_msglevel,
4139 .set_msglevel = ice_set_msglevel,
4140 .self_test = ice_self_test,
4141 .get_link = ethtool_op_get_link,
4142 .get_eeprom_len = ice_get_eeprom_len,
4143 .get_eeprom = ice_get_eeprom,
4144 .get_coalesce = ice_get_coalesce,
4145 .set_coalesce = ice_set_coalesce,
4146 .get_strings = ice_get_strings,
4147 .set_phys_id = ice_set_phys_id,
4148 .get_ethtool_stats = ice_get_ethtool_stats,
4149 .get_priv_flags = ice_get_priv_flags,
4150 .set_priv_flags = ice_set_priv_flags,
4151 .get_sset_count = ice_get_sset_count,
4152 .get_rxnfc = ice_get_rxnfc,
4153 .set_rxnfc = ice_set_rxnfc,
4154 .get_ringparam = ice_get_ringparam,
4155 .set_ringparam = ice_set_ringparam,
4156 .nway_reset = ice_nway_reset,
4157 .get_pauseparam = ice_get_pauseparam,
4158 .set_pauseparam = ice_set_pauseparam,
4159 .get_rxfh_key_size = ice_get_rxfh_key_size,
4160 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
4161 .get_rxfh_context = ice_get_rxfh_context,
4162 .get_rxfh = ice_get_rxfh,
4163 .set_rxfh = ice_set_rxfh,
4164 .get_channels = ice_get_channels,
4165 .set_channels = ice_set_channels,
4166 .get_ts_info = ice_get_ts_info,
4167 .get_per_queue_coalesce = ice_get_per_q_coalesce,
4168 .set_per_queue_coalesce = ice_set_per_q_coalesce,
4169 .get_fecparam = ice_get_fecparam,
4170 .set_fecparam = ice_set_fecparam,
4171 .get_module_info = ice_get_module_info,
4172 .get_module_eeprom = ice_get_module_eeprom,
4175 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
4176 .get_link_ksettings = ice_get_link_ksettings,
4177 .set_link_ksettings = ice_set_link_ksettings,
4178 .get_drvinfo = ice_get_drvinfo,
4179 .get_regs_len = ice_get_regs_len,
4180 .get_regs = ice_get_regs,
4181 .get_wol = ice_get_wol,
4182 .set_wol = ice_set_wol,
4183 .get_msglevel = ice_get_msglevel,
4184 .set_msglevel = ice_set_msglevel,
4185 .get_link = ethtool_op_get_link,
4186 .get_eeprom_len = ice_get_eeprom_len,
4187 .get_eeprom = ice_get_eeprom,
4188 .get_strings = ice_get_strings,
4189 .get_ethtool_stats = ice_get_ethtool_stats,
4190 .get_sset_count = ice_get_sset_count,
4191 .get_ringparam = ice_get_ringparam,
4192 .set_ringparam = ice_set_ringparam,
4193 .nway_reset = ice_nway_reset,
4194 .get_channels = ice_get_channels,
4198 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
4199 * @netdev: network interface device structure
4201 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
4203 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
4206 static const struct ethtool_ops ice_ethtool_repr_ops = {
4207 .get_drvinfo = ice_repr_get_drvinfo,
4208 .get_link = ethtool_op_get_link,
4209 .get_strings = ice_repr_get_strings,
4210 .get_ethtool_stats = ice_repr_get_ethtool_stats,
4211 .get_sset_count = ice_repr_get_sset_count,
4215 * ice_set_ethtool_repr_ops - setup VF's port representor ethtool ops
4216 * @netdev: network interface device structure
4218 void ice_set_ethtool_repr_ops(struct net_device *netdev)
4220 netdev->ethtool_ops = &ice_ethtool_repr_ops;
4224 * ice_set_ethtool_ops - setup netdev ethtool ops
4225 * @netdev: network interface device structure
4227 * setup netdev ethtool ops with ice specific ops
4229 void ice_set_ethtool_ops(struct net_device *netdev)
4231 netdev->ethtool_ops = &ice_ethtool_ops;