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_eipe_error.nic", hw_rx_eipe_error),
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)
348 static const u32 ice_adv_lnk_speed_100[] __initconst = {
349 ETHTOOL_LINK_MODE_100baseT_Full_BIT,
352 static const u32 ice_adv_lnk_speed_1000[] __initconst = {
353 ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
354 ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
355 ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
358 static const u32 ice_adv_lnk_speed_2500[] __initconst = {
359 ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
360 ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
363 static const u32 ice_adv_lnk_speed_5000[] __initconst = {
364 ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
367 static const u32 ice_adv_lnk_speed_10000[] __initconst = {
368 ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
369 ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
370 ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
371 ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
374 static const u32 ice_adv_lnk_speed_25000[] __initconst = {
375 ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
376 ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
377 ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
380 static const u32 ice_adv_lnk_speed_40000[] __initconst = {
381 ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
382 ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
383 ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
384 ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
387 static const u32 ice_adv_lnk_speed_50000[] __initconst = {
388 ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
389 ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
390 ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
393 static const u32 ice_adv_lnk_speed_100000[] __initconst = {
394 ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
395 ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
396 ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
397 ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
398 ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
399 ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
400 ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
403 static const u32 ice_adv_lnk_speed_200000[] __initconst = {
404 ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
405 ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
406 ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
407 ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
408 ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
411 static struct ethtool_forced_speed_map ice_adv_lnk_speed_maps[] __ro_after_init = {
412 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 100),
413 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 1000),
414 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 2500),
415 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 5000),
416 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 10000),
417 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 25000),
418 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 40000),
419 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 50000),
420 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 100000),
421 ETHTOOL_FORCED_SPEED_MAP(ice_adv_lnk_speed, 200000),
424 void __init ice_adv_lnk_speed_maps_init(void)
426 ethtool_forced_speed_maps_init(ice_adv_lnk_speed_maps,
427 ARRAY_SIZE(ice_adv_lnk_speed_maps));
431 __ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo,
434 struct ice_pf *pf = vsi->back;
435 struct ice_hw *hw = &pf->hw;
436 struct ice_orom_info *orom;
437 struct ice_nvm_info *nvm;
439 nvm = &hw->flash.nvm;
440 orom = &hw->flash.orom;
442 strscpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
444 /* Display NVM version (from which the firmware version can be
445 * determined) which contains more pertinent information.
447 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
448 "%x.%02x 0x%x %d.%d.%d", nvm->major, nvm->minor,
449 nvm->eetrack, orom->major, orom->build, orom->patch);
451 strscpy(drvinfo->bus_info, pci_name(pf->pdev),
452 sizeof(drvinfo->bus_info));
456 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
458 struct ice_netdev_priv *np = netdev_priv(netdev);
460 __ice_get_drvinfo(netdev, drvinfo, np->vsi);
461 drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
464 static int ice_get_regs_len(struct net_device __always_unused *netdev)
466 return (sizeof(ice_regs_dump_list) +
467 sizeof(struct ice_regdump_to_ethtool));
471 * ice_ethtool_get_maxspeed - Get the max speed for given lport
472 * @hw: pointer to the HW struct
473 * @lport: logical port for which max speed is requested
474 * @max_speed: return max speed for input lport
476 * Return: 0 on success, negative on failure.
478 static int ice_ethtool_get_maxspeed(struct ice_hw *hw, u8 lport, u8 *max_speed)
480 struct ice_aqc_get_port_options_elem options[ICE_AQC_PORT_OPT_MAX] = {};
481 bool active_valid = false, pending_valid = true;
482 u8 option_count = ICE_AQC_PORT_OPT_MAX;
483 u8 active_idx = 0, pending_idx = 0;
486 status = ice_aq_get_port_options(hw, options, &option_count, lport,
487 true, &active_idx, &active_valid,
488 &pending_idx, &pending_valid);
494 *max_speed = options[active_idx].max_lane_speed & ICE_AQC_PORT_OPT_MAX_LANE_M;
499 * ice_is_serdes_muxed - returns whether serdes is muxed in hardware
500 * @hw: pointer to the HW struct
502 * Return: true when serdes is muxed, false when serdes is not muxed.
504 static bool ice_is_serdes_muxed(struct ice_hw *hw)
506 u32 reg_value = rd32(hw, GLGEN_SWITCH_MODE_CONFIG);
508 return FIELD_GET(GLGEN_SWITCH_MODE_CONFIG_25X4_QUAD_M, reg_value);
511 static int ice_map_port_topology_for_sfp(struct ice_port_topology *port_topology,
512 u8 lport, bool is_muxed)
516 port_topology->pcs_quad_select = 0;
517 port_topology->pcs_port = 0;
518 port_topology->primary_serdes_lane = 0;
521 port_topology->pcs_quad_select = 1;
522 port_topology->pcs_port = 0;
524 port_topology->primary_serdes_lane = 2;
526 port_topology->primary_serdes_lane = 4;
529 port_topology->pcs_quad_select = 0;
530 port_topology->pcs_port = 1;
531 port_topology->primary_serdes_lane = 1;
534 port_topology->pcs_quad_select = 1;
535 port_topology->pcs_port = 1;
537 port_topology->primary_serdes_lane = 3;
539 port_topology->primary_serdes_lane = 5;
542 port_topology->pcs_quad_select = 0;
543 port_topology->pcs_port = 2;
544 port_topology->primary_serdes_lane = 2;
547 port_topology->pcs_quad_select = 1;
548 port_topology->pcs_port = 2;
549 port_topology->primary_serdes_lane = 6;
552 port_topology->pcs_quad_select = 0;
553 port_topology->pcs_port = 3;
554 port_topology->primary_serdes_lane = 3;
557 port_topology->pcs_quad_select = 1;
558 port_topology->pcs_port = 3;
559 port_topology->primary_serdes_lane = 7;
568 static int ice_map_port_topology_for_qsfp(struct ice_port_topology *port_topology,
569 u8 lport, bool is_muxed)
573 port_topology->pcs_quad_select = 0;
574 port_topology->pcs_port = 0;
575 port_topology->primary_serdes_lane = 0;
578 port_topology->pcs_quad_select = 1;
579 port_topology->pcs_port = 0;
581 port_topology->primary_serdes_lane = 2;
583 port_topology->primary_serdes_lane = 4;
586 port_topology->pcs_quad_select = 0;
587 port_topology->pcs_port = 1;
588 port_topology->primary_serdes_lane = 1;
591 port_topology->pcs_quad_select = 1;
592 port_topology->pcs_port = 1;
594 port_topology->primary_serdes_lane = 3;
596 port_topology->primary_serdes_lane = 5;
599 port_topology->pcs_quad_select = 0;
600 port_topology->pcs_port = 2;
601 port_topology->primary_serdes_lane = 2;
604 port_topology->pcs_quad_select = 1;
605 port_topology->pcs_port = 2;
606 port_topology->primary_serdes_lane = 6;
609 port_topology->pcs_quad_select = 0;
610 port_topology->pcs_port = 3;
611 port_topology->primary_serdes_lane = 3;
614 port_topology->pcs_quad_select = 1;
615 port_topology->pcs_port = 3;
616 port_topology->primary_serdes_lane = 7;
626 * ice_get_port_topology - returns physical topology like pcsquad, pcsport,
628 * @hw: pointer to the HW struct
629 * @lport: logical port for which physical info requested
630 * @port_topology: buffer to hold port topology
632 * Return: 0 on success, negative on failure.
634 static int ice_get_port_topology(struct ice_hw *hw, u8 lport,
635 struct ice_port_topology *port_topology)
637 struct ice_aqc_get_link_topo cmd = {};
644 ctx = ICE_AQC_LINK_TOPO_NODE_TYPE_CAGE << ICE_AQC_LINK_TOPO_NODE_TYPE_S;
645 ctx |= ICE_AQC_LINK_TOPO_NODE_CTX_PORT << ICE_AQC_LINK_TOPO_NODE_CTX_S;
646 cmd.addr.topo_params.node_type_ctx = ctx;
648 err = ice_aq_get_netlist_node(hw, &cmd, &cage_type, &node_handle);
652 is_muxed = ice_is_serdes_muxed(hw);
654 if (cage_type == 0x11 || /* SFP+ */
655 cage_type == 0x12) { /* SFP28 */
656 port_topology->serdes_lane_count = 1;
657 err = ice_map_port_topology_for_sfp(port_topology, lport, is_muxed);
660 } else if (cage_type == 0x13 || /* QSFP */
661 cage_type == 0x14) { /* QSFP28 */
664 err = ice_ethtool_get_maxspeed(hw, lport, &max_speed);
668 if (max_speed == ICE_AQC_PORT_OPT_MAX_LANE_100G)
669 port_topology->serdes_lane_count = 4;
670 else if (max_speed == ICE_AQC_PORT_OPT_MAX_LANE_50G)
671 port_topology->serdes_lane_count = 2;
673 port_topology->serdes_lane_count = 1;
675 err = ice_map_port_topology_for_qsfp(port_topology, lport, is_muxed);
686 * ice_get_tx_rx_equa - read serdes tx rx equaliser param
687 * @hw: pointer to the HW struct
688 * @serdes_num: represents the serdes number
689 * @ptr: structure to read all serdes parameter for given serdes
691 * Return: all serdes equalization parameter supported per serdes number
693 static int ice_get_tx_rx_equa(struct ice_hw *hw, u8 serdes_num,
694 struct ice_serdes_equalization_to_ethtool *ptr)
698 err = ice_aq_get_phy_equalization(hw, ICE_AQC_TX_EQU_PRE1,
699 ICE_AQC_OP_CODE_TX_EQU, serdes_num,
700 &ptr->tx_equalization_pre1);
704 err = ice_aq_get_phy_equalization(hw, ICE_AQC_TX_EQU_PRE3,
705 ICE_AQC_OP_CODE_TX_EQU, serdes_num,
706 &ptr->tx_equalization_pre3);
710 err = ice_aq_get_phy_equalization(hw, ICE_AQC_TX_EQU_ATTEN,
711 ICE_AQC_OP_CODE_TX_EQU, serdes_num,
712 &ptr->tx_equalization_atten);
716 err = ice_aq_get_phy_equalization(hw, ICE_AQC_TX_EQU_POST1,
717 ICE_AQC_OP_CODE_TX_EQU, serdes_num,
718 &ptr->tx_equalization_post1);
722 err = ice_aq_get_phy_equalization(hw, ICE_AQC_TX_EQU_PRE2,
723 ICE_AQC_OP_CODE_TX_EQU, serdes_num,
724 &ptr->tx_equalization_pre2);
728 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_PRE2,
729 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
730 &ptr->rx_equalization_pre2);
734 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_PRE1,
735 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
736 &ptr->rx_equalization_pre1);
740 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_POST1,
741 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
742 &ptr->rx_equalization_post1);
746 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_BFLF,
747 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
748 &ptr->rx_equalization_bflf);
752 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_BFHF,
753 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
754 &ptr->rx_equalization_bfhf);
758 err = ice_aq_get_phy_equalization(hw, ICE_AQC_RX_EQU_DRATE,
759 ICE_AQC_OP_CODE_RX_EQU, serdes_num,
760 &ptr->rx_equalization_drate);
768 * ice_get_extended_regs - returns FEC correctable, uncorrectable stats per
770 * @netdev: pointer to net device structure
771 * @p: output buffer to fill requested register dump
773 * Return: 0 on success, negative on failure.
775 static int ice_get_extended_regs(struct net_device *netdev, void *p)
777 struct ice_netdev_priv *np = netdev_priv(netdev);
778 struct ice_regdump_to_ethtool *ice_prv_regs_buf;
779 struct ice_port_topology port_topology = {};
780 struct ice_port_info *pi;
788 pi = np->vsi->port_info;
790 /* Serdes parameters are not supported if not the PF VSI */
791 if (np->vsi->type != ICE_VSI_PF || !pi)
794 err = ice_get_port_topology(hw, pi->lport, &port_topology);
797 if (port_topology.serdes_lane_count > 4)
800 ice_prv_regs_buf = p;
802 /* Get serdes equalization parameter for available serdes */
803 for (i = 0; i < port_topology.serdes_lane_count; i++) {
806 serdes_num = port_topology.primary_serdes_lane + i;
807 err = ice_get_tx_rx_equa(hw, serdes_num,
808 &ice_prv_regs_buf->equalization[i]);
817 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
819 struct ice_netdev_priv *np = netdev_priv(netdev);
820 struct ice_pf *pf = np->vsi->back;
821 struct ice_hw *hw = &pf->hw;
822 u32 *regs_buf = (u32 *)p;
827 for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
828 regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
830 ice_get_extended_regs(netdev, (void *)®s_buf[i]);
833 static u32 ice_get_msglevel(struct net_device *netdev)
835 struct ice_netdev_priv *np = netdev_priv(netdev);
836 struct ice_pf *pf = np->vsi->back;
838 #ifndef CONFIG_DYNAMIC_DEBUG
839 if (pf->hw.debug_mask)
840 netdev_info(netdev, "hw debug_mask: 0x%llX\n",
842 #endif /* !CONFIG_DYNAMIC_DEBUG */
844 return pf->msg_enable;
847 static void ice_set_msglevel(struct net_device *netdev, u32 data)
849 struct ice_netdev_priv *np = netdev_priv(netdev);
850 struct ice_pf *pf = np->vsi->back;
852 #ifndef CONFIG_DYNAMIC_DEBUG
853 if (ICE_DBG_USER & data)
854 pf->hw.debug_mask = data;
856 pf->msg_enable = data;
858 pf->msg_enable = data;
859 #endif /* !CONFIG_DYNAMIC_DEBUG */
862 static int ice_get_eeprom_len(struct net_device *netdev)
864 struct ice_netdev_priv *np = netdev_priv(netdev);
865 struct ice_pf *pf = np->vsi->back;
867 return (int)pf->hw.flash.flash_size;
871 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
874 struct ice_netdev_priv *np = netdev_priv(netdev);
875 struct ice_vsi *vsi = np->vsi;
876 struct ice_pf *pf = vsi->back;
877 struct ice_hw *hw = &pf->hw;
882 dev = ice_pf_to_dev(pf);
884 eeprom->magic = hw->vendor_id | (hw->device_id << 16);
885 netdev_dbg(netdev, "GEEPROM cmd 0x%08x, offset 0x%08x, len 0x%08x\n",
886 eeprom->cmd, eeprom->offset, eeprom->len);
888 buf = kzalloc(eeprom->len, GFP_KERNEL);
892 ret = ice_acquire_nvm(hw, ICE_RES_READ);
894 dev_err(dev, "ice_acquire_nvm failed, err %d aq_err %s\n",
895 ret, ice_aq_str(hw->adminq.sq_last_status));
899 ret = ice_read_flat_nvm(hw, eeprom->offset, &eeprom->len, buf,
902 dev_err(dev, "ice_read_flat_nvm failed, err %d aq_err %s\n",
903 ret, ice_aq_str(hw->adminq.sq_last_status));
907 memcpy(bytes, buf, eeprom->len);
916 * ice_active_vfs - check if there are any active VFs
917 * @pf: board private structure
919 * Returns true if an active VF is found, otherwise returns false
921 static bool ice_active_vfs(struct ice_pf *pf)
928 ice_for_each_vf_rcu(pf, bkt, vf) {
929 if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
940 * ice_link_test - perform a link test on a given net_device
941 * @netdev: network interface device structure
943 * This function performs one of the self-tests required by ethtool.
944 * Returns 0 on success, non-zero on failure.
946 static u64 ice_link_test(struct net_device *netdev)
948 struct ice_netdev_priv *np = netdev_priv(netdev);
949 bool link_up = false;
952 netdev_info(netdev, "link test\n");
953 status = ice_get_link_status(np->vsi->port_info, &link_up);
955 netdev_err(netdev, "link query error, status = %d\n",
967 * ice_eeprom_test - perform an EEPROM test on a given net_device
968 * @netdev: network interface device structure
970 * This function performs one of the self-tests required by ethtool.
971 * Returns 0 on success, non-zero on failure.
973 static u64 ice_eeprom_test(struct net_device *netdev)
975 struct ice_netdev_priv *np = netdev_priv(netdev);
976 struct ice_pf *pf = np->vsi->back;
978 netdev_info(netdev, "EEPROM test\n");
979 return !!(ice_nvm_validate_checksum(&pf->hw));
983 * ice_reg_pattern_test
984 * @hw: pointer to the HW struct
985 * @reg: reg to be tested
986 * @mask: bits to be touched
988 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
990 struct ice_pf *pf = (struct ice_pf *)hw->back;
991 struct device *dev = ice_pf_to_dev(pf);
992 static const u32 patterns[] = {
993 0x5A5A5A5A, 0xA5A5A5A5,
994 0x00000000, 0xFFFFFFFF
999 orig_val = rd32(hw, reg);
1000 for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
1001 u32 pattern = patterns[i] & mask;
1003 wr32(hw, reg, pattern);
1004 val = rd32(hw, reg);
1007 dev_err(dev, "%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
1008 , __func__, reg, pattern, val);
1012 wr32(hw, reg, orig_val);
1013 val = rd32(hw, reg);
1014 if (val != orig_val) {
1015 dev_err(dev, "%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
1016 , __func__, reg, orig_val, val);
1024 * ice_reg_test - perform a register test on a given net_device
1025 * @netdev: network interface device structure
1027 * This function performs one of the self-tests required by ethtool.
1028 * Returns 0 on success, non-zero on failure.
1030 static u64 ice_reg_test(struct net_device *netdev)
1032 struct ice_netdev_priv *np = netdev_priv(netdev);
1033 struct ice_hw *hw = np->vsi->port_info->hw;
1034 u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
1035 hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
1036 struct ice_diag_reg_test_info {
1041 } ice_reg_list[] = {
1042 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
1043 GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
1044 {GLINT_ITR(1, 0), 0x00000fff, int_elements,
1045 GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
1046 {GLINT_ITR(0, 0), 0x00000fff, int_elements,
1047 GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
1048 {GLINT_CTL, 0xffff0001, 1, 0}
1052 netdev_dbg(netdev, "Register test\n");
1053 for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
1056 for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
1057 u32 mask = ice_reg_list[i].mask;
1058 u32 reg = ice_reg_list[i].address +
1059 (j * ice_reg_list[i].elem_size);
1061 /* bail on failure (non-zero return) */
1062 if (ice_reg_pattern_test(hw, reg, mask))
1071 * ice_lbtest_prepare_rings - configure Tx/Rx test rings
1072 * @vsi: pointer to the VSI structure
1074 * Function configures rings of a VSI for loopback test without
1075 * enabling interrupts or informing the kernel about new queues.
1077 * Returns 0 on success, negative on failure.
1079 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
1083 status = ice_vsi_setup_tx_rings(vsi);
1085 goto err_setup_tx_ring;
1087 status = ice_vsi_setup_rx_rings(vsi);
1089 goto err_setup_rx_ring;
1091 status = ice_vsi_cfg_lan(vsi);
1093 goto err_setup_rx_ring;
1095 status = ice_vsi_start_all_rx_rings(vsi);
1097 goto err_start_rx_ring;
1102 ice_vsi_free_rx_rings(vsi);
1104 ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
1106 ice_vsi_free_tx_rings(vsi);
1112 * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
1113 * @vsi: pointer to the VSI structure
1115 * Function stops and frees VSI rings after a loopback test.
1116 * Returns 0 on success, negative on failure.
1118 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
1122 status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
1124 netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
1125 vsi->vsi_num, status);
1127 status = ice_vsi_stop_all_rx_rings(vsi);
1129 netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
1130 vsi->vsi_num, status);
1132 ice_vsi_free_tx_rings(vsi);
1133 ice_vsi_free_rx_rings(vsi);
1139 * ice_lbtest_create_frame - create test packet
1140 * @pf: pointer to the PF structure
1141 * @ret_data: allocated frame buffer
1142 * @size: size of the packet data
1144 * Function allocates a frame with a test pattern on specific offsets.
1145 * Returns 0 on success, non-zero on failure.
1147 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
1154 data = kzalloc(size, GFP_KERNEL);
1158 /* Since the ethernet test frame should always be at least
1159 * 64 bytes long, fill some octets in the payload with test data.
1161 memset(data, 0xFF, size);
1173 * ice_lbtest_check_frame - verify received loopback frame
1174 * @frame: pointer to the raw packet data
1176 * Function verifies received test frame with a pattern.
1177 * Returns true if frame matches the pattern, false otherwise.
1179 static bool ice_lbtest_check_frame(u8 *frame)
1181 /* Validate bytes of a frame under offsets chosen earlier */
1182 if (frame[32] == 0xDE &&
1183 frame[42] == 0xAD &&
1184 frame[44] == 0xBE &&
1185 frame[46] == 0xEF &&
1193 * ice_diag_send - send test frames to the test ring
1194 * @tx_ring: pointer to the transmit ring
1195 * @data: pointer to the raw packet data
1196 * @size: size of the packet to send
1198 * Function sends loopback packets on a test Tx ring.
1200 static int ice_diag_send(struct ice_tx_ring *tx_ring, u8 *data, u16 size)
1202 struct ice_tx_desc *tx_desc;
1203 struct ice_tx_buf *tx_buf;
1207 tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
1208 tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
1210 dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
1211 if (dma_mapping_error(tx_ring->dev, dma))
1214 tx_desc->buf_addr = cpu_to_le64(dma);
1216 /* These flags are required for a descriptor to be pushed out */
1217 td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
1218 tx_desc->cmd_type_offset_bsz =
1219 cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
1220 (td_cmd << ICE_TXD_QW1_CMD_S) |
1221 ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
1222 ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
1223 ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
1225 tx_buf->next_to_watch = tx_desc;
1227 /* Force memory write to complete before letting h/w know
1228 * there are new descriptors to fetch.
1232 tx_ring->next_to_use++;
1233 if (tx_ring->next_to_use >= tx_ring->count)
1234 tx_ring->next_to_use = 0;
1236 writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
1238 /* Wait until the packets get transmitted to the receive queue. */
1239 usleep_range(1000, 2000);
1240 dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
1245 #define ICE_LB_FRAME_SIZE 64
1247 * ice_lbtest_receive_frames - receive and verify test frames
1248 * @rx_ring: pointer to the receive ring
1250 * Function receives loopback packets and verify their correctness.
1251 * Returns number of received valid frames.
1253 static int ice_lbtest_receive_frames(struct ice_rx_ring *rx_ring)
1255 struct ice_rx_buf *rx_buf;
1256 int valid_frames, i;
1261 for (i = 0; i < rx_ring->count; i++) {
1262 union ice_32b_rx_flex_desc *rx_desc;
1264 rx_desc = ICE_RX_DESC(rx_ring, i);
1266 if (!(rx_desc->wb.status_error0 &
1267 (cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_DD_S)) |
1268 cpu_to_le16(BIT(ICE_RX_FLEX_DESC_STATUS0_EOF_S)))))
1271 rx_buf = &rx_ring->rx_buf[i];
1272 received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
1274 if (ice_lbtest_check_frame(received_buf))
1278 return valid_frames;
1282 * ice_loopback_test - perform a loopback test on a given net_device
1283 * @netdev: network interface device structure
1285 * This function performs one of the self-tests required by ethtool.
1286 * Returns 0 on success, non-zero on failure.
1288 static u64 ice_loopback_test(struct net_device *netdev)
1290 struct ice_netdev_priv *np = netdev_priv(netdev);
1291 struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
1292 struct ice_pf *pf = orig_vsi->back;
1293 u8 *tx_frame __free(kfree) = NULL;
1294 u8 broadcast[ETH_ALEN], ret = 0;
1295 int num_frames, valid_frames;
1296 struct ice_tx_ring *tx_ring;
1297 struct ice_rx_ring *rx_ring;
1300 netdev_info(netdev, "loopback test\n");
1302 test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
1304 netdev_err(netdev, "Failed to create a VSI for the loopback test\n");
1308 test_vsi->netdev = netdev;
1309 tx_ring = test_vsi->tx_rings[0];
1310 rx_ring = test_vsi->rx_rings[0];
1312 if (ice_lbtest_prepare_rings(test_vsi)) {
1314 goto lbtest_vsi_close;
1317 if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
1319 goto lbtest_rings_dis;
1322 /* Enable MAC loopback in firmware */
1323 if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
1325 goto lbtest_mac_dis;
1328 /* Test VSI needs to receive broadcast packets */
1329 eth_broadcast_addr(broadcast);
1330 if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
1332 goto lbtest_mac_dis;
1335 if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
1337 goto remove_mac_filters;
1340 num_frames = min_t(int, tx_ring->count, 32);
1341 for (i = 0; i < num_frames; i++) {
1342 if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
1344 goto remove_mac_filters;
1348 valid_frames = ice_lbtest_receive_frames(rx_ring);
1351 else if (valid_frames != num_frames)
1355 if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
1356 netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
1358 /* Disable MAC loopback after the test is completed. */
1359 if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
1360 netdev_err(netdev, "Could not disable MAC loopback\n");
1362 if (ice_lbtest_disable_rings(test_vsi))
1363 netdev_err(netdev, "Could not disable test rings\n");
1365 test_vsi->netdev = NULL;
1366 if (ice_vsi_release(test_vsi))
1367 netdev_err(netdev, "Failed to remove the test VSI\n");
1373 * ice_intr_test - perform an interrupt test on a given net_device
1374 * @netdev: network interface device structure
1376 * This function performs one of the self-tests required by ethtool.
1377 * Returns 0 on success, non-zero on failure.
1379 static u64 ice_intr_test(struct net_device *netdev)
1381 struct ice_netdev_priv *np = netdev_priv(netdev);
1382 struct ice_pf *pf = np->vsi->back;
1383 u16 swic_old = pf->sw_int_count;
1385 netdev_info(netdev, "interrupt test\n");
1387 wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_irq.index),
1388 GLINT_DYN_CTL_SW_ITR_INDX_M |
1389 GLINT_DYN_CTL_INTENA_MSK_M |
1390 GLINT_DYN_CTL_SWINT_TRIG_M);
1392 usleep_range(1000, 2000);
1393 return (swic_old == pf->sw_int_count);
1397 * ice_self_test - handler function for performing a self-test by ethtool
1398 * @netdev: network interface device structure
1399 * @eth_test: ethtool_test structure
1400 * @data: required by ethtool.self_test
1402 * This function is called after invoking 'ethtool -t devname' command where
1403 * devname is the name of the network device on which ethtool should operate.
1404 * It performs a set of self-tests to check if a device works properly.
1407 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
1410 struct ice_netdev_priv *np = netdev_priv(netdev);
1411 bool if_running = netif_running(netdev);
1412 struct ice_pf *pf = np->vsi->back;
1415 dev = ice_pf_to_dev(pf);
1417 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
1418 netdev_info(netdev, "offline testing starting\n");
1420 set_bit(ICE_TESTING, pf->state);
1422 if (ice_active_vfs(pf)) {
1423 dev_warn(dev, "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
1424 data[ICE_ETH_TEST_REG] = 1;
1425 data[ICE_ETH_TEST_EEPROM] = 1;
1426 data[ICE_ETH_TEST_INTR] = 1;
1427 data[ICE_ETH_TEST_LOOP] = 1;
1428 data[ICE_ETH_TEST_LINK] = 1;
1429 eth_test->flags |= ETH_TEST_FL_FAILED;
1430 clear_bit(ICE_TESTING, pf->state);
1433 /* If the device is online then take it offline */
1435 /* indicate we're in test mode */
1438 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1439 data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
1440 data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
1441 data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
1442 data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
1444 if (data[ICE_ETH_TEST_LINK] ||
1445 data[ICE_ETH_TEST_EEPROM] ||
1446 data[ICE_ETH_TEST_LOOP] ||
1447 data[ICE_ETH_TEST_INTR] ||
1448 data[ICE_ETH_TEST_REG])
1449 eth_test->flags |= ETH_TEST_FL_FAILED;
1451 clear_bit(ICE_TESTING, pf->state);
1454 int status = ice_open(netdev);
1457 dev_err(dev, "Could not open device %s, err %d\n",
1458 pf->int_name, status);
1463 netdev_info(netdev, "online testing starting\n");
1465 data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
1466 if (data[ICE_ETH_TEST_LINK])
1467 eth_test->flags |= ETH_TEST_FL_FAILED;
1469 /* Offline only tests, not run in online; pass by default */
1470 data[ICE_ETH_TEST_REG] = 0;
1471 data[ICE_ETH_TEST_EEPROM] = 0;
1472 data[ICE_ETH_TEST_INTR] = 0;
1473 data[ICE_ETH_TEST_LOOP] = 0;
1477 netdev_info(netdev, "testing finished\n");
1481 __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
1482 struct ice_vsi *vsi)
1487 switch (stringset) {
1489 for (i = 0; i < ICE_VSI_STATS_LEN; i++)
1490 ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
1492 if (ice_is_port_repr_netdev(netdev))
1495 ice_for_each_alloc_txq(vsi, i) {
1496 ethtool_sprintf(&p, "tx_queue_%u_packets", i);
1497 ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
1500 ice_for_each_alloc_rxq(vsi, i) {
1501 ethtool_sprintf(&p, "rx_queue_%u_packets", i);
1502 ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
1505 if (vsi->type != ICE_VSI_PF)
1508 for (i = 0; i < ICE_PF_STATS_LEN; i++)
1509 ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
1511 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1512 ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
1513 ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
1515 for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
1516 ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
1517 ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
1521 memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
1523 case ETH_SS_PRIV_FLAGS:
1524 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
1525 ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
1532 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1534 struct ice_netdev_priv *np = netdev_priv(netdev);
1536 __ice_get_strings(netdev, stringset, data, np->vsi);
1540 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
1542 struct ice_netdev_priv *np = netdev_priv(netdev);
1546 case ETHTOOL_ID_ACTIVE:
1549 case ETHTOOL_ID_INACTIVE:
1556 if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
1563 * ice_set_fec_cfg - Set link FEC options
1564 * @netdev: network interface device structure
1565 * @req_fec: FEC mode to configure
1567 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
1569 struct ice_netdev_priv *np = netdev_priv(netdev);
1570 struct ice_aqc_set_phy_cfg_data config = { 0 };
1571 struct ice_vsi *vsi = np->vsi;
1572 struct ice_port_info *pi;
1574 pi = vsi->port_info;
1578 /* Changing the FEC parameters is not supported if not the PF VSI */
1579 if (vsi->type != ICE_VSI_PF) {
1580 netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
1584 /* Proceed only if requesting different FEC mode */
1585 if (pi->phy.curr_user_fec_req == req_fec)
1588 /* Copy the current user PHY configuration. The current user PHY
1589 * configuration is initialized during probe from PHY capabilities
1590 * software mode, and updated on set PHY configuration.
1592 memcpy(&config, &pi->phy.curr_user_phy_cfg, sizeof(config));
1594 ice_cfg_phy_fec(pi, &config, req_fec);
1595 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1597 if (ice_aq_set_phy_cfg(pi->hw, pi, &config, NULL))
1600 /* Save requested FEC config */
1601 pi->phy.curr_user_fec_req = req_fec;
1607 * ice_set_fecparam - Set FEC link options
1608 * @netdev: network interface device structure
1609 * @fecparam: Ethtool structure to retrieve FEC parameters
1612 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1614 struct ice_netdev_priv *np = netdev_priv(netdev);
1615 struct ice_vsi *vsi = np->vsi;
1616 enum ice_fec_mode fec;
1618 switch (fecparam->fec) {
1619 case ETHTOOL_FEC_AUTO:
1622 case ETHTOOL_FEC_RS:
1625 case ETHTOOL_FEC_BASER:
1626 fec = ICE_FEC_BASER;
1628 case ETHTOOL_FEC_OFF:
1629 case ETHTOOL_FEC_NONE:
1633 dev_warn(ice_pf_to_dev(vsi->back), "Unsupported FEC mode: %d\n",
1638 return ice_set_fec_cfg(netdev, fec);
1642 * ice_get_fecparam - Get link FEC options
1643 * @netdev: network interface device structure
1644 * @fecparam: Ethtool structure to retrieve FEC parameters
1647 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1649 struct ice_netdev_priv *np = netdev_priv(netdev);
1650 struct ice_aqc_get_phy_caps_data *caps;
1651 struct ice_link_status *link_info;
1652 struct ice_vsi *vsi = np->vsi;
1653 struct ice_port_info *pi;
1656 pi = vsi->port_info;
1660 link_info = &pi->phy.link_info;
1662 /* Set FEC mode based on negotiated link info */
1663 switch (link_info->fec_info) {
1664 case ICE_AQ_LINK_25G_KR_FEC_EN:
1665 fecparam->active_fec = ETHTOOL_FEC_BASER;
1667 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1668 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1669 fecparam->active_fec = ETHTOOL_FEC_RS;
1672 fecparam->active_fec = ETHTOOL_FEC_OFF;
1676 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
1680 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1685 /* Set supported/configured FEC modes based on PHY capability */
1686 if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1687 fecparam->fec |= ETHTOOL_FEC_AUTO;
1688 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1689 caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1690 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1691 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1692 fecparam->fec |= ETHTOOL_FEC_BASER;
1693 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1694 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1695 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1696 fecparam->fec |= ETHTOOL_FEC_RS;
1697 if (caps->link_fec_options == 0)
1698 fecparam->fec |= ETHTOOL_FEC_OFF;
1706 * ice_nway_reset - restart autonegotiation
1707 * @netdev: network interface device structure
1709 static int ice_nway_reset(struct net_device *netdev)
1711 struct ice_netdev_priv *np = netdev_priv(netdev);
1712 struct ice_vsi *vsi = np->vsi;
1715 /* If VSI state is up, then restart autoneg with link up */
1716 if (!test_bit(ICE_DOWN, vsi->back->state))
1717 err = ice_set_link(vsi, true);
1719 err = ice_set_link(vsi, false);
1725 * ice_get_priv_flags - report device private flags
1726 * @netdev: network interface device structure
1728 * The get string set count and the string set should be matched for each
1729 * flag returned. Add new strings for each flag to the ice_gstrings_priv_flags
1732 * Returns a u32 bitmap of flags.
1734 static u32 ice_get_priv_flags(struct net_device *netdev)
1736 struct ice_netdev_priv *np = netdev_priv(netdev);
1737 struct ice_vsi *vsi = np->vsi;
1738 struct ice_pf *pf = vsi->back;
1739 u32 i, ret_flags = 0;
1741 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1742 const struct ice_priv_flag *priv_flag;
1744 priv_flag = &ice_gstrings_priv_flags[i];
1746 if (test_bit(priv_flag->bitno, pf->flags))
1747 ret_flags |= BIT(i);
1754 * ice_set_priv_flags - set private flags
1755 * @netdev: network interface device structure
1756 * @flags: bit flags to be set
1758 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1760 struct ice_netdev_priv *np = netdev_priv(netdev);
1761 DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1762 DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1763 struct ice_vsi *vsi = np->vsi;
1764 struct ice_pf *pf = vsi->back;
1769 if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1772 dev = ice_pf_to_dev(pf);
1773 set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1775 bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1776 for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1777 const struct ice_priv_flag *priv_flag;
1779 priv_flag = &ice_gstrings_priv_flags[i];
1782 set_bit(priv_flag->bitno, pf->flags);
1784 clear_bit(priv_flag->bitno, pf->flags);
1787 bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1789 /* Do not allow change to link-down-on-close when Total Port Shutdown
1792 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, change_flags) &&
1793 test_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags)) {
1794 dev_err(dev, "Setting link-down-on-close not supported on this port\n");
1795 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1800 if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1801 if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1804 /* Disable FW LLDP engine */
1805 status = ice_cfg_lldp_mib_change(&pf->hw, false);
1807 /* If unregistering for LLDP events fails, this is
1808 * not an error state, as there shouldn't be any
1809 * events to respond to.
1812 dev_info(dev, "Failed to unreg for LLDP events\n");
1814 /* The AQ call to stop the FW LLDP agent will generate
1815 * an error if the agent is already stopped.
1817 status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1819 dev_warn(dev, "Fail to stop LLDP agent\n");
1820 /* Use case for having the FW LLDP agent stopped
1821 * will likely not need DCB, so failure to init is
1822 * not a concern of ethtool
1824 status = ice_init_pf_dcb(pf, true);
1826 dev_warn(dev, "Fail to init DCB\n");
1828 pf->dcbx_cap &= ~DCB_CAP_DCBX_LLD_MANAGED;
1829 pf->dcbx_cap |= DCB_CAP_DCBX_HOST;
1831 bool dcbx_agent_status;
1834 if (ice_get_pfc_mode(pf) == ICE_QOS_MODE_DSCP) {
1835 clear_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags);
1836 dev_err(dev, "QoS in L3 DSCP mode, FW Agent not allowed to start\n");
1841 /* Remove rule to direct LLDP packets to default VSI.
1842 * The FW LLDP engine will now be consuming them.
1844 ice_cfg_sw_lldp(vsi, false, false);
1846 /* AQ command to start FW LLDP agent will return an
1847 * error if the agent is already started
1849 status = ice_aq_start_lldp(&pf->hw, true, NULL);
1851 dev_warn(dev, "Fail to start LLDP Agent\n");
1853 /* AQ command to start FW DCBX agent will fail if
1854 * the agent is already started
1856 status = ice_aq_start_stop_dcbx(&pf->hw, true,
1860 dev_dbg(dev, "Failed to start FW DCBX\n");
1862 dev_info(dev, "FW DCBX agent is %s\n",
1863 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1865 /* Failure to configure MIB change or init DCB is not
1866 * relevant to ethtool. Print notification that
1867 * registration/init failed but do not return error
1870 status = ice_init_pf_dcb(pf, true);
1872 dev_dbg(dev, "Fail to init DCB\n");
1874 /* Register for MIB change events */
1875 status = ice_cfg_lldp_mib_change(&pf->hw, true);
1877 dev_dbg(dev, "Fail to enable MIB change events\n");
1879 pf->dcbx_cap &= ~DCB_CAP_DCBX_HOST;
1880 pf->dcbx_cap |= DCB_CAP_DCBX_LLD_MANAGED;
1882 ice_nway_reset(netdev);
1885 if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1886 /* down and up VSI so that changes of Rx cfg are reflected. */
1889 /* don't allow modification of this flag when a single VF is in
1890 * promiscuous mode because it's not supported
1892 if (test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, change_flags) &&
1893 ice_is_any_vf_in_unicast_promisc(pf)) {
1894 dev_err(dev, "Changing vf-true-promisc-support flag while VF(s) are in promiscuous mode not supported\n");
1895 /* toggle bit back to previous state */
1896 change_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags);
1900 if (test_bit(ICE_FLAG_VF_VLAN_PRUNING, change_flags) &&
1902 dev_err(dev, "vf-vlan-pruning: VLAN pruning cannot be changed while VFs are active.\n");
1903 /* toggle bit back to previous state */
1904 change_bit(ICE_FLAG_VF_VLAN_PRUNING, pf->flags);
1908 clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1912 static int ice_get_sset_count(struct net_device *netdev, int sset)
1916 /* The number (and order) of strings reported *must* remain
1917 * constant for a given netdevice. This function must not
1918 * report a different number based on run time parameters
1919 * (such as the number of queues in use, or the setting of
1920 * a private ethtool flag). This is due to the nature of the
1921 * ethtool stats API.
1923 * Userspace programs such as ethtool must make 3 separate
1924 * ioctl requests, one for size, one for the strings, and
1925 * finally one for the stats. Since these cross into
1926 * userspace, changes to the number or size could result in
1927 * undefined memory access or incorrect string<->value
1928 * correlations for statistics.
1930 * Even if it appears to be safe, changes to the size or
1931 * order of strings will suffer from race conditions and are
1934 return ICE_ALL_STATS_LEN(netdev);
1936 return ICE_TEST_LEN;
1937 case ETH_SS_PRIV_FLAGS:
1938 return ICE_PRIV_FLAG_ARRAY_SIZE;
1945 __ice_get_ethtool_stats(struct net_device *netdev,
1946 struct ethtool_stats __always_unused *stats, u64 *data,
1947 struct ice_vsi *vsi)
1949 struct ice_pf *pf = vsi->back;
1950 struct ice_tx_ring *tx_ring;
1951 struct ice_rx_ring *rx_ring;
1956 ice_update_pf_stats(pf);
1957 ice_update_vsi_stats(vsi);
1959 for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1960 p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1961 data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1962 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1965 if (ice_is_port_repr_netdev(netdev))
1968 /* populate per queue stats */
1971 ice_for_each_alloc_txq(vsi, j) {
1972 tx_ring = READ_ONCE(vsi->tx_rings[j]);
1973 if (tx_ring && tx_ring->ring_stats) {
1974 data[i++] = tx_ring->ring_stats->stats.pkts;
1975 data[i++] = tx_ring->ring_stats->stats.bytes;
1982 ice_for_each_alloc_rxq(vsi, j) {
1983 rx_ring = READ_ONCE(vsi->rx_rings[j]);
1984 if (rx_ring && rx_ring->ring_stats) {
1985 data[i++] = rx_ring->ring_stats->stats.pkts;
1986 data[i++] = rx_ring->ring_stats->stats.bytes;
1995 if (vsi->type != ICE_VSI_PF)
1998 for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1999 p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
2000 data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
2001 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
2004 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
2005 data[i++] = pf->stats.priority_xon_tx[j];
2006 data[i++] = pf->stats.priority_xoff_tx[j];
2009 for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
2010 data[i++] = pf->stats.priority_xon_rx[j];
2011 data[i++] = pf->stats.priority_xoff_rx[j];
2016 ice_get_ethtool_stats(struct net_device *netdev,
2017 struct ethtool_stats __always_unused *stats, u64 *data)
2019 struct ice_netdev_priv *np = netdev_priv(netdev);
2021 __ice_get_ethtool_stats(netdev, stats, data, np->vsi);
2024 #define ICE_PHY_TYPE_LOW_MASK_MIN_1G (ICE_PHY_TYPE_LOW_100BASE_TX | \
2025 ICE_PHY_TYPE_LOW_100M_SGMII)
2027 #define ICE_PHY_TYPE_LOW_MASK_MIN_25G (ICE_PHY_TYPE_LOW_MASK_MIN_1G | \
2028 ICE_PHY_TYPE_LOW_1000BASE_T | \
2029 ICE_PHY_TYPE_LOW_1000BASE_SX | \
2030 ICE_PHY_TYPE_LOW_1000BASE_LX | \
2031 ICE_PHY_TYPE_LOW_1000BASE_KX | \
2032 ICE_PHY_TYPE_LOW_1G_SGMII | \
2033 ICE_PHY_TYPE_LOW_2500BASE_T | \
2034 ICE_PHY_TYPE_LOW_2500BASE_X | \
2035 ICE_PHY_TYPE_LOW_2500BASE_KX | \
2036 ICE_PHY_TYPE_LOW_5GBASE_T | \
2037 ICE_PHY_TYPE_LOW_5GBASE_KR | \
2038 ICE_PHY_TYPE_LOW_10GBASE_T | \
2039 ICE_PHY_TYPE_LOW_10G_SFI_DA | \
2040 ICE_PHY_TYPE_LOW_10GBASE_SR | \
2041 ICE_PHY_TYPE_LOW_10GBASE_LR | \
2042 ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 | \
2043 ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC | \
2044 ICE_PHY_TYPE_LOW_10G_SFI_C2C)
2046 #define ICE_PHY_TYPE_LOW_MASK_100G (ICE_PHY_TYPE_LOW_100GBASE_CR4 | \
2047 ICE_PHY_TYPE_LOW_100GBASE_SR4 | \
2048 ICE_PHY_TYPE_LOW_100GBASE_LR4 | \
2049 ICE_PHY_TYPE_LOW_100GBASE_KR4 | \
2050 ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC | \
2051 ICE_PHY_TYPE_LOW_100G_CAUI4 | \
2052 ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC | \
2053 ICE_PHY_TYPE_LOW_100G_AUI4 | \
2054 ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 | \
2055 ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 | \
2056 ICE_PHY_TYPE_LOW_100GBASE_CP2 | \
2057 ICE_PHY_TYPE_LOW_100GBASE_SR2 | \
2058 ICE_PHY_TYPE_LOW_100GBASE_DR)
2060 #define ICE_PHY_TYPE_HIGH_MASK_100G (ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4 | \
2061 ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC |\
2062 ICE_PHY_TYPE_HIGH_100G_CAUI2 | \
2063 ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC | \
2064 ICE_PHY_TYPE_HIGH_100G_AUI2)
2066 #define ICE_PHY_TYPE_HIGH_MASK_200G (ICE_PHY_TYPE_HIGH_200G_CR4_PAM4 | \
2067 ICE_PHY_TYPE_HIGH_200G_SR4 | \
2068 ICE_PHY_TYPE_HIGH_200G_FR4 | \
2069 ICE_PHY_TYPE_HIGH_200G_LR4 | \
2070 ICE_PHY_TYPE_HIGH_200G_DR4 | \
2071 ICE_PHY_TYPE_HIGH_200G_KR4_PAM4 | \
2072 ICE_PHY_TYPE_HIGH_200G_AUI4_AOC_ACC | \
2073 ICE_PHY_TYPE_HIGH_200G_AUI4)
2076 * ice_mask_min_supported_speeds
2077 * @hw: pointer to the HW structure
2078 * @phy_types_high: PHY type high
2079 * @phy_types_low: PHY type low to apply minimum supported speeds mask
2081 * Apply minimum supported speeds mask to PHY type low. These are the speeds
2082 * for ethtool supported link mode.
2085 ice_mask_min_supported_speeds(struct ice_hw *hw,
2086 u64 phy_types_high, u64 *phy_types_low)
2088 /* if QSFP connection with 100G speed, minimum supported speed is 25G */
2089 if ((*phy_types_low & ICE_PHY_TYPE_LOW_MASK_100G) ||
2090 (phy_types_high & ICE_PHY_TYPE_HIGH_MASK_100G) ||
2091 (phy_types_high & ICE_PHY_TYPE_HIGH_MASK_200G))
2092 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_25G;
2093 else if (!ice_is_100m_speed_supported(hw))
2094 *phy_types_low &= ~ICE_PHY_TYPE_LOW_MASK_MIN_1G;
2098 * ice_linkmode_set_bit - set link mode bit
2099 * @phy_to_ethtool: PHY type to ethtool link mode struct to set
2100 * @ks: ethtool link ksettings struct to fill out
2101 * @req_speeds: speed requested by user
2102 * @advert_phy_type: advertised PHY type
2103 * @phy_type: PHY type
2106 ice_linkmode_set_bit(const struct ice_phy_type_to_ethtool *phy_to_ethtool,
2107 struct ethtool_link_ksettings *ks, u32 req_speeds,
2108 u64 advert_phy_type, u32 phy_type)
2110 linkmode_set_bit(phy_to_ethtool->link_mode, ks->link_modes.supported);
2112 if (req_speeds & phy_to_ethtool->aq_link_speed ||
2113 (!req_speeds && advert_phy_type & BIT(phy_type)))
2114 linkmode_set_bit(phy_to_ethtool->link_mode,
2115 ks->link_modes.advertising);
2119 * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
2120 * @netdev: network interface device structure
2121 * @ks: ethtool link ksettings struct to fill out
2124 ice_phy_type_to_ethtool(struct net_device *netdev,
2125 struct ethtool_link_ksettings *ks)
2127 struct ice_netdev_priv *np = netdev_priv(netdev);
2128 struct ice_vsi *vsi = np->vsi;
2129 struct ice_pf *pf = vsi->back;
2130 u64 advert_phy_type_lo = 0;
2131 u64 advert_phy_type_hi = 0;
2132 u64 phy_types_high = 0;
2133 u64 phy_types_low = 0;
2137 req_speeds = vsi->port_info->phy.link_info.req_speeds;
2139 /* Check if lenient mode is supported and enabled, or in strict mode.
2141 * In lenient mode the Supported link modes are the PHY types without
2142 * media. The Advertising link mode is either 1. the user requested
2143 * speed, 2. the override PHY mask, or 3. the PHY types with media.
2145 * In strict mode Supported link mode are the PHY type with media,
2146 * and Advertising link modes are the media PHY type or the speed
2147 * requested by user.
2149 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2150 phy_types_low = le64_to_cpu(pf->nvm_phy_type_lo);
2151 phy_types_high = le64_to_cpu(pf->nvm_phy_type_hi);
2153 ice_mask_min_supported_speeds(&pf->hw, phy_types_high,
2155 /* determine advertised modes based on link override only
2156 * if it's supported and if the FW doesn't abstract the
2157 * driver from having to account for link overrides
2159 if (ice_fw_supports_link_override(&pf->hw) &&
2160 !ice_fw_supports_report_dflt_cfg(&pf->hw)) {
2161 struct ice_link_default_override_tlv *ldo;
2163 ldo = &pf->link_dflt_override;
2164 /* If override enabled and PHY mask set, then
2165 * Advertising link mode is the intersection of the PHY
2166 * types without media and the override PHY mask.
2168 if (ldo->options & ICE_LINK_OVERRIDE_EN &&
2169 (ldo->phy_type_low || ldo->phy_type_high)) {
2170 advert_phy_type_lo =
2171 le64_to_cpu(pf->nvm_phy_type_lo) &
2173 advert_phy_type_hi =
2174 le64_to_cpu(pf->nvm_phy_type_hi) &
2180 phy_types_low = vsi->port_info->phy.phy_type_low;
2181 phy_types_high = vsi->port_info->phy.phy_type_high;
2184 /* If Advertising link mode PHY type is not using override PHY type,
2185 * then use PHY type with media.
2187 if (!advert_phy_type_lo && !advert_phy_type_hi) {
2188 advert_phy_type_lo = vsi->port_info->phy.phy_type_low;
2189 advert_phy_type_hi = vsi->port_info->phy.phy_type_high;
2192 linkmode_zero(ks->link_modes.supported);
2193 linkmode_zero(ks->link_modes.advertising);
2195 for (i = 0; i < ARRAY_SIZE(phy_type_low_lkup); i++) {
2196 if (phy_types_low & BIT_ULL(i))
2197 ice_linkmode_set_bit(&phy_type_low_lkup[i], ks,
2198 req_speeds, advert_phy_type_lo,
2202 for (i = 0; i < ARRAY_SIZE(phy_type_high_lkup); i++) {
2203 if (phy_types_high & BIT_ULL(i))
2204 ice_linkmode_set_bit(&phy_type_high_lkup[i], ks,
2205 req_speeds, advert_phy_type_hi,
2210 #define TEST_SET_BITS_TIMEOUT 50
2211 #define TEST_SET_BITS_SLEEP_MAX 2000
2212 #define TEST_SET_BITS_SLEEP_MIN 1000
2215 * ice_get_settings_link_up - Get Link settings for when link is up
2216 * @ks: ethtool ksettings to fill in
2217 * @netdev: network interface device structure
2220 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
2221 struct net_device *netdev)
2223 struct ice_netdev_priv *np = netdev_priv(netdev);
2224 struct ice_port_info *pi = np->vsi->port_info;
2225 struct ice_link_status *link_info;
2226 struct ice_vsi *vsi = np->vsi;
2228 link_info = &vsi->port_info->phy.link_info;
2230 /* Get supported and advertised settings from PHY ability with media */
2231 ice_phy_type_to_ethtool(netdev, ks);
2233 switch (link_info->link_speed) {
2234 case ICE_AQ_LINK_SPEED_200GB:
2235 ks->base.speed = SPEED_200000;
2237 case ICE_AQ_LINK_SPEED_100GB:
2238 ks->base.speed = SPEED_100000;
2240 case ICE_AQ_LINK_SPEED_50GB:
2241 ks->base.speed = SPEED_50000;
2243 case ICE_AQ_LINK_SPEED_40GB:
2244 ks->base.speed = SPEED_40000;
2246 case ICE_AQ_LINK_SPEED_25GB:
2247 ks->base.speed = SPEED_25000;
2249 case ICE_AQ_LINK_SPEED_20GB:
2250 ks->base.speed = SPEED_20000;
2252 case ICE_AQ_LINK_SPEED_10GB:
2253 ks->base.speed = SPEED_10000;
2255 case ICE_AQ_LINK_SPEED_5GB:
2256 ks->base.speed = SPEED_5000;
2258 case ICE_AQ_LINK_SPEED_2500MB:
2259 ks->base.speed = SPEED_2500;
2261 case ICE_AQ_LINK_SPEED_1000MB:
2262 ks->base.speed = SPEED_1000;
2264 case ICE_AQ_LINK_SPEED_100MB:
2265 ks->base.speed = SPEED_100;
2268 netdev_info(netdev, "WARNING: Unrecognized link_speed (0x%x).\n",
2269 link_info->link_speed);
2272 ks->base.duplex = DUPLEX_FULL;
2274 if (link_info->an_info & ICE_AQ_AN_COMPLETED)
2275 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2278 /* Set flow control negotiated Rx/Tx pause */
2279 switch (pi->fc.current_mode) {
2281 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2283 case ICE_FC_TX_PAUSE:
2284 ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2285 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2288 case ICE_FC_RX_PAUSE:
2289 ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2294 ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
2295 ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
2302 * ice_get_settings_link_down - Get the Link settings when link is down
2303 * @ks: ethtool ksettings to fill in
2304 * @netdev: network interface device structure
2306 * Reports link settings that can be determined when link is down
2309 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
2310 struct net_device *netdev)
2312 /* link is down and the driver needs to fall back on
2313 * supported PHY types to figure out what info to display
2315 ice_phy_type_to_ethtool(netdev, ks);
2317 /* With no link, speed and duplex are unknown */
2318 ks->base.speed = SPEED_UNKNOWN;
2319 ks->base.duplex = DUPLEX_UNKNOWN;
2323 * ice_get_link_ksettings - Get Link Speed and Duplex settings
2324 * @netdev: network interface device structure
2325 * @ks: ethtool ksettings
2327 * Reports speed/duplex settings based on media_type
2330 ice_get_link_ksettings(struct net_device *netdev,
2331 struct ethtool_link_ksettings *ks)
2333 struct ice_netdev_priv *np = netdev_priv(netdev);
2334 struct ice_aqc_get_phy_caps_data *caps;
2335 struct ice_link_status *hw_link_info;
2336 struct ice_vsi *vsi = np->vsi;
2339 ethtool_link_ksettings_zero_link_mode(ks, supported);
2340 ethtool_link_ksettings_zero_link_mode(ks, advertising);
2341 ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
2342 hw_link_info = &vsi->port_info->phy.link_info;
2344 /* set speed and duplex */
2345 if (hw_link_info->link_info & ICE_AQ_LINK_UP)
2346 ice_get_settings_link_up(ks, netdev);
2348 ice_get_settings_link_down(ks, netdev);
2350 /* set autoneg settings */
2351 ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
2352 AUTONEG_ENABLE : AUTONEG_DISABLE;
2354 /* set media type settings */
2355 switch (vsi->port_info->phy.media_type) {
2356 case ICE_MEDIA_FIBER:
2357 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2358 ks->base.port = PORT_FIBRE;
2360 case ICE_MEDIA_BASET:
2361 ethtool_link_ksettings_add_link_mode(ks, supported, TP);
2362 ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
2363 ks->base.port = PORT_TP;
2365 case ICE_MEDIA_BACKPLANE:
2366 ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
2367 ethtool_link_ksettings_add_link_mode(ks, advertising,
2369 ks->base.port = PORT_NONE;
2372 ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2373 ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
2374 ks->base.port = PORT_DA;
2377 ks->base.port = PORT_OTHER;
2381 /* flow control is symmetric and always supported */
2382 ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
2384 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
2388 err = ice_aq_get_phy_caps(vsi->port_info, false,
2389 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
2393 /* Set the advertised flow control based on the PHY capability */
2394 if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
2395 (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
2396 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2397 ethtool_link_ksettings_add_link_mode(ks, advertising,
2399 } else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
2400 ethtool_link_ksettings_add_link_mode(ks, advertising,
2402 } else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
2403 ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2404 ethtool_link_ksettings_add_link_mode(ks, advertising,
2407 ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2408 ethtool_link_ksettings_del_link_mode(ks, advertising,
2412 /* Set advertised FEC modes based on PHY capability */
2413 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2415 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2416 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2417 ethtool_link_ksettings_add_link_mode(ks, advertising,
2419 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2420 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2421 ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2423 err = ice_aq_get_phy_caps(vsi->port_info, false,
2424 ICE_AQC_REPORT_TOPO_CAP_MEDIA, caps, NULL);
2428 /* Set supported FEC modes based on PHY capability */
2429 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2431 if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2432 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2433 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2434 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2435 ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2437 /* Set supported and advertised autoneg */
2438 if (ice_is_phy_caps_an_enabled(caps)) {
2439 ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2440 ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2449 * ice_speed_to_aq_link - Get AQ link speed by Ethtool forced speed
2450 * @speed: ethtool forced speed
2452 static u16 ice_speed_to_aq_link(int speed)
2458 aq_speed = ICE_AQ_LINK_SPEED_10MB;
2461 aq_speed = ICE_AQ_LINK_SPEED_100MB;
2464 aq_speed = ICE_AQ_LINK_SPEED_1000MB;
2467 aq_speed = ICE_AQ_LINK_SPEED_2500MB;
2470 aq_speed = ICE_AQ_LINK_SPEED_5GB;
2473 aq_speed = ICE_AQ_LINK_SPEED_10GB;
2476 aq_speed = ICE_AQ_LINK_SPEED_20GB;
2479 aq_speed = ICE_AQ_LINK_SPEED_25GB;
2482 aq_speed = ICE_AQ_LINK_SPEED_40GB;
2485 aq_speed = ICE_AQ_LINK_SPEED_50GB;
2488 aq_speed = ICE_AQ_LINK_SPEED_100GB;
2491 aq_speed = ICE_AQ_LINK_SPEED_UNKNOWN;
2498 * ice_ksettings_find_adv_link_speed - Find advertising link speed
2499 * @ks: ethtool ksettings
2502 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2504 const struct ethtool_forced_speed_map *map;
2505 u16 adv_link_speed = 0;
2507 for (u32 i = 0; i < ARRAY_SIZE(ice_adv_lnk_speed_maps); i++) {
2508 map = ice_adv_lnk_speed_maps + i;
2509 if (linkmode_intersects(ks->link_modes.advertising, map->caps))
2510 adv_link_speed |= ice_speed_to_aq_link(map->speed);
2513 return adv_link_speed;
2519 * @ks: ethtool_link_ksettings
2520 * @config: configuration that will be sent down to FW
2521 * @autoneg_enabled: autonegotiation is enabled or not
2522 * @autoneg_changed: will there a change in autonegotiation
2523 * @netdev: network interface device structure
2525 * Setup PHY autonegotiation feature
2528 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2529 struct ice_aqc_set_phy_cfg_data *config,
2530 u8 autoneg_enabled, u8 *autoneg_changed,
2531 struct net_device *netdev)
2535 *autoneg_changed = 0;
2538 if (autoneg_enabled == AUTONEG_ENABLE) {
2539 /* If autoneg was not already enabled */
2540 if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2541 /* If autoneg is not supported, return error */
2542 if (!ethtool_link_ksettings_test_link_mode(ks,
2545 netdev_info(netdev, "Autoneg not supported on this phy.\n");
2548 /* Autoneg is allowed to change */
2549 config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2550 *autoneg_changed = 1;
2554 /* If autoneg is currently enabled */
2555 if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2556 /* If autoneg is supported 10GBASE_T is the only PHY
2557 * that can disable it, so otherwise return error
2559 if (ethtool_link_ksettings_test_link_mode(ks,
2562 netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2565 /* Autoneg is allowed to change */
2566 config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2567 *autoneg_changed = 1;
2576 * ice_set_phy_type_from_speed - set phy_types based on speeds
2577 * and advertised modes
2578 * @ks: ethtool link ksettings struct
2579 * @phy_type_low: pointer to the lower part of phy_type
2580 * @phy_type_high: pointer to the higher part of phy_type
2581 * @adv_link_speed: targeted link speeds bitmap
2584 ice_set_phy_type_from_speed(const struct ethtool_link_ksettings *ks,
2585 u64 *phy_type_low, u64 *phy_type_high,
2588 /* Handle 1000M speed in a special way because ice_update_phy_type
2589 * enables all link modes, but having mixed copper and optical
2590 * standards is not supported.
2592 adv_link_speed &= ~ICE_AQ_LINK_SPEED_1000MB;
2594 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2596 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_T |
2597 ICE_PHY_TYPE_LOW_1G_SGMII;
2599 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2601 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_KX;
2603 if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2605 *phy_type_low |= ICE_PHY_TYPE_LOW_1000BASE_SX |
2606 ICE_PHY_TYPE_LOW_1000BASE_LX;
2608 ice_update_phy_type(phy_type_low, phy_type_high, adv_link_speed);
2612 * ice_set_link_ksettings - Set Speed and Duplex
2613 * @netdev: network interface device structure
2614 * @ks: ethtool ksettings
2616 * Set speed/duplex per media_types advertised/forced
2619 ice_set_link_ksettings(struct net_device *netdev,
2620 const struct ethtool_link_ksettings *ks)
2622 struct ice_netdev_priv *np = netdev_priv(netdev);
2623 u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT;
2624 struct ethtool_link_ksettings copy_ks = *ks;
2625 struct ethtool_link_ksettings safe_ks = {};
2626 struct ice_aqc_get_phy_caps_data *phy_caps;
2627 struct ice_aqc_set_phy_cfg_data config;
2628 u16 adv_link_speed, curr_link_speed;
2629 struct ice_pf *pf = np->vsi->back;
2630 struct ice_port_info *pi;
2631 u8 autoneg_changed = 0;
2632 u64 phy_type_high = 0;
2633 u64 phy_type_low = 0;
2637 pi = np->vsi->port_info;
2642 if (pi->phy.media_type != ICE_MEDIA_BASET &&
2643 pi->phy.media_type != ICE_MEDIA_FIBER &&
2644 pi->phy.media_type != ICE_MEDIA_BACKPLANE &&
2645 pi->phy.media_type != ICE_MEDIA_DA &&
2646 pi->phy.link_info.link_info & ICE_AQ_LINK_UP)
2649 phy_caps = kzalloc(sizeof(*phy_caps), GFP_KERNEL);
2653 /* Get the PHY capabilities based on media */
2654 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2655 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2658 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2663 /* save autoneg out of ksettings */
2664 autoneg = copy_ks.base.autoneg;
2666 /* Get link modes supported by hardware.*/
2667 ice_phy_type_to_ethtool(netdev, &safe_ks);
2669 /* and check against modes requested by user.
2670 * Return an error if unsupported mode was set.
2672 if (!bitmap_subset(copy_ks.link_modes.advertising,
2673 safe_ks.link_modes.supported,
2674 __ETHTOOL_LINK_MODE_MASK_NBITS)) {
2675 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags))
2676 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");
2681 /* get our own copy of the bits to check against */
2682 memset(&safe_ks, 0, sizeof(safe_ks));
2683 safe_ks.base.cmd = copy_ks.base.cmd;
2684 safe_ks.base.link_mode_masks_nwords =
2685 copy_ks.base.link_mode_masks_nwords;
2686 ice_get_link_ksettings(netdev, &safe_ks);
2688 /* set autoneg back to what it currently is */
2689 copy_ks.base.autoneg = safe_ks.base.autoneg;
2690 /* we don't compare the speed */
2691 copy_ks.base.speed = safe_ks.base.speed;
2693 /* If copy_ks.base and safe_ks.base are not the same now, then they are
2694 * trying to set something that we do not support.
2696 if (memcmp(©_ks.base, &safe_ks.base, sizeof(copy_ks.base))) {
2701 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
2707 usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2710 /* Copy the current user PHY configuration. The current user PHY
2711 * configuration is initialized during probe from PHY capabilities
2712 * software mode, and updated on set PHY configuration.
2714 config = pi->phy.curr_user_phy_cfg;
2716 config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2719 err = ice_setup_autoneg(pi, &safe_ks, &config, autoneg, &autoneg_changed,
2725 /* Call to get the current link speed */
2726 pi->phy.get_link_info = true;
2727 err = ice_get_link_status(pi, &linkup);
2731 curr_link_speed = pi->phy.curr_user_speed_req;
2732 adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2734 /* If speed didn't get set, set it to what it currently is.
2735 * This is needed because if advertise is 0 (as it is when autoneg
2736 * is disabled) then speed won't get set.
2738 if (!adv_link_speed)
2739 adv_link_speed = curr_link_speed;
2741 /* Convert the advertise link speeds to their corresponded PHY_TYPE */
2742 ice_set_phy_type_from_speed(ks, &phy_type_low, &phy_type_high,
2745 if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2746 netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2750 /* save the requested speeds */
2751 pi->phy.link_info.req_speeds = adv_link_speed;
2753 /* set link and auto negotiation so changes take effect */
2754 config.caps |= ICE_AQ_PHY_ENA_LINK;
2756 /* check if there is a PHY type for the requested advertised speed */
2757 if (!(phy_type_low || phy_type_high)) {
2758 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");
2763 /* intersect requested advertised speed PHY types with media PHY types
2764 * for set PHY configuration
2766 config.phy_type_high = cpu_to_le64(phy_type_high) &
2767 phy_caps->phy_type_high;
2768 config.phy_type_low = cpu_to_le64(phy_type_low) &
2769 phy_caps->phy_type_low;
2771 if (!(config.phy_type_high || config.phy_type_low)) {
2772 /* If there is no intersection and lenient mode is enabled, then
2773 * intersect the requested advertised speed with NVM media type
2776 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags)) {
2777 config.phy_type_high = cpu_to_le64(phy_type_high) &
2778 pf->nvm_phy_type_hi;
2779 config.phy_type_low = cpu_to_le64(phy_type_low) &
2780 pf->nvm_phy_type_lo;
2782 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");
2788 /* If link is up put link down */
2789 if (pi->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2790 /* Tell the OS link is going down, the link will go
2791 * back up when fw says it is ready asynchronously
2793 ice_print_link_msg(np->vsi, false);
2794 netif_carrier_off(netdev);
2795 netif_tx_stop_all_queues(netdev);
2798 /* make the aq call */
2799 err = ice_aq_set_phy_cfg(&pf->hw, pi, &config, NULL);
2801 netdev_info(netdev, "Set phy config failed,\n");
2805 /* Save speed request */
2806 pi->phy.curr_user_speed_req = adv_link_speed;
2809 clear_bit(ICE_CFG_BUSY, pf->state);
2815 * ice_parse_hdrs - parses headers from RSS hash input
2816 * @nfc: ethtool rxnfc command
2818 * This function parses the rxnfc command and returns intended
2819 * header types for RSS configuration
2821 static u32 ice_parse_hdrs(struct ethtool_rxnfc *nfc)
2823 u32 hdrs = ICE_FLOW_SEG_HDR_NONE;
2825 switch (nfc->flow_type) {
2827 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV4;
2830 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV4;
2833 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV4;
2836 hdrs |= ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV4;
2839 hdrs |= ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV4;
2841 case GTPC_TEID_V4_FLOW:
2842 hdrs |= ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV4;
2844 case GTPU_EH_V4_FLOW:
2845 hdrs |= ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4;
2847 case GTPU_UL_V4_FLOW:
2848 hdrs |= ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV4;
2850 case GTPU_DL_V4_FLOW:
2851 hdrs |= ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV4;
2854 hdrs |= ICE_FLOW_SEG_HDR_TCP | ICE_FLOW_SEG_HDR_IPV6;
2857 hdrs |= ICE_FLOW_SEG_HDR_UDP | ICE_FLOW_SEG_HDR_IPV6;
2860 hdrs |= ICE_FLOW_SEG_HDR_SCTP | ICE_FLOW_SEG_HDR_IPV6;
2863 hdrs |= ICE_FLOW_SEG_HDR_GTPU_IP | ICE_FLOW_SEG_HDR_IPV6;
2866 hdrs |= ICE_FLOW_SEG_HDR_GTPC | ICE_FLOW_SEG_HDR_IPV6;
2868 case GTPC_TEID_V6_FLOW:
2869 hdrs |= ICE_FLOW_SEG_HDR_GTPC_TEID | ICE_FLOW_SEG_HDR_IPV6;
2871 case GTPU_EH_V6_FLOW:
2872 hdrs |= ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV6;
2874 case GTPU_UL_V6_FLOW:
2875 hdrs |= ICE_FLOW_SEG_HDR_GTPU_UP | ICE_FLOW_SEG_HDR_IPV6;
2877 case GTPU_DL_V6_FLOW:
2878 hdrs |= ICE_FLOW_SEG_HDR_GTPU_DWN | ICE_FLOW_SEG_HDR_IPV6;
2887 * ice_parse_hash_flds - parses hash fields from RSS hash input
2888 * @nfc: ethtool rxnfc command
2889 * @symm: true if Symmetric Topelitz is set
2891 * This function parses the rxnfc command and returns intended
2892 * hash fields for RSS configuration
2894 static u64 ice_parse_hash_flds(struct ethtool_rxnfc *nfc, bool symm)
2896 u64 hfld = ICE_HASH_INVALID;
2898 if (nfc->data & RXH_IP_SRC || nfc->data & RXH_IP_DST) {
2899 switch (nfc->flow_type) {
2905 case GTPC_TEID_V4_FLOW:
2906 case GTPU_EH_V4_FLOW:
2907 case GTPU_UL_V4_FLOW:
2908 case GTPU_DL_V4_FLOW:
2909 if (nfc->data & RXH_IP_SRC)
2910 hfld |= ICE_FLOW_HASH_FLD_IPV4_SA;
2911 if (nfc->data & RXH_IP_DST)
2912 hfld |= ICE_FLOW_HASH_FLD_IPV4_DA;
2919 case GTPC_TEID_V6_FLOW:
2920 case GTPU_EH_V6_FLOW:
2921 case GTPU_UL_V6_FLOW:
2922 case GTPU_DL_V6_FLOW:
2923 if (nfc->data & RXH_IP_SRC)
2924 hfld |= ICE_FLOW_HASH_FLD_IPV6_SA;
2925 if (nfc->data & RXH_IP_DST)
2926 hfld |= ICE_FLOW_HASH_FLD_IPV6_DA;
2933 if (nfc->data & RXH_L4_B_0_1 || nfc->data & RXH_L4_B_2_3) {
2934 switch (nfc->flow_type) {
2937 if (nfc->data & RXH_L4_B_0_1)
2938 hfld |= ICE_FLOW_HASH_FLD_TCP_SRC_PORT;
2939 if (nfc->data & RXH_L4_B_2_3)
2940 hfld |= ICE_FLOW_HASH_FLD_TCP_DST_PORT;
2944 if (nfc->data & RXH_L4_B_0_1)
2945 hfld |= ICE_FLOW_HASH_FLD_UDP_SRC_PORT;
2946 if (nfc->data & RXH_L4_B_2_3)
2947 hfld |= ICE_FLOW_HASH_FLD_UDP_DST_PORT;
2951 if (nfc->data & RXH_L4_B_0_1)
2952 hfld |= ICE_FLOW_HASH_FLD_SCTP_SRC_PORT;
2953 if (nfc->data & RXH_L4_B_2_3)
2954 hfld |= ICE_FLOW_HASH_FLD_SCTP_DST_PORT;
2961 if (nfc->data & RXH_GTP_TEID) {
2962 switch (nfc->flow_type) {
2963 case GTPC_TEID_V4_FLOW:
2964 case GTPC_TEID_V6_FLOW:
2965 hfld |= ICE_FLOW_HASH_FLD_GTPC_TEID;
2969 hfld |= ICE_FLOW_HASH_FLD_GTPU_IP_TEID;
2971 case GTPU_EH_V4_FLOW:
2972 case GTPU_EH_V6_FLOW:
2973 hfld |= ICE_FLOW_HASH_FLD_GTPU_EH_TEID;
2975 case GTPU_UL_V4_FLOW:
2976 case GTPU_UL_V6_FLOW:
2977 hfld |= ICE_FLOW_HASH_FLD_GTPU_UP_TEID;
2979 case GTPU_DL_V4_FLOW:
2980 case GTPU_DL_V6_FLOW:
2981 hfld |= ICE_FLOW_HASH_FLD_GTPU_DWN_TEID;
2992 * ice_set_rss_hash_opt - Enable/Disable flow types for RSS hash
2993 * @vsi: the VSI being configured
2994 * @nfc: ethtool rxnfc command
2996 * Returns Success if the flow input set is supported.
2999 ice_set_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
3001 struct ice_pf *pf = vsi->back;
3002 struct ice_rss_hash_cfg cfg;
3009 dev = ice_pf_to_dev(pf);
3010 if (ice_is_safe_mode(pf)) {
3011 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
3016 symm = !!(vsi->rss_hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ);
3017 hashed_flds = ice_parse_hash_flds(nfc, symm);
3018 if (hashed_flds == ICE_HASH_INVALID) {
3019 dev_dbg(dev, "Invalid hash fields, vsi num = %d\n",
3024 hdrs = ice_parse_hdrs(nfc);
3025 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
3026 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
3031 cfg.hash_flds = hashed_flds;
3032 cfg.addl_hdrs = hdrs;
3033 cfg.hdr_type = ICE_RSS_ANY_HEADERS;
3036 status = ice_add_rss_cfg(&pf->hw, vsi, &cfg);
3038 dev_dbg(dev, "ice_add_rss_cfg failed, vsi num = %d, error = %d\n",
3039 vsi->vsi_num, status);
3047 * ice_get_rss_hash_opt - Retrieve hash fields for a given flow-type
3048 * @vsi: the VSI being configured
3049 * @nfc: ethtool rxnfc command
3052 ice_get_rss_hash_opt(struct ice_vsi *vsi, struct ethtool_rxnfc *nfc)
3054 struct ice_pf *pf = vsi->back;
3060 dev = ice_pf_to_dev(pf);
3063 if (ice_is_safe_mode(pf)) {
3064 dev_dbg(dev, "Advanced RSS disabled. Package download failed, vsi num = %d\n",
3069 hdrs = ice_parse_hdrs(nfc);
3070 if (hdrs == ICE_FLOW_SEG_HDR_NONE) {
3071 dev_dbg(dev, "Header type is not valid, vsi num = %d\n",
3076 hash_flds = ice_get_rss_cfg(&pf->hw, vsi->idx, hdrs, &symm);
3077 if (hash_flds == ICE_HASH_INVALID) {
3078 dev_dbg(dev, "No hash fields found for the given header type, vsi num = %d\n",
3083 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_SA ||
3084 hash_flds & ICE_FLOW_HASH_FLD_IPV6_SA)
3085 nfc->data |= (u64)RXH_IP_SRC;
3087 if (hash_flds & ICE_FLOW_HASH_FLD_IPV4_DA ||
3088 hash_flds & ICE_FLOW_HASH_FLD_IPV6_DA)
3089 nfc->data |= (u64)RXH_IP_DST;
3091 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_SRC_PORT ||
3092 hash_flds & ICE_FLOW_HASH_FLD_UDP_SRC_PORT ||
3093 hash_flds & ICE_FLOW_HASH_FLD_SCTP_SRC_PORT)
3094 nfc->data |= (u64)RXH_L4_B_0_1;
3096 if (hash_flds & ICE_FLOW_HASH_FLD_TCP_DST_PORT ||
3097 hash_flds & ICE_FLOW_HASH_FLD_UDP_DST_PORT ||
3098 hash_flds & ICE_FLOW_HASH_FLD_SCTP_DST_PORT)
3099 nfc->data |= (u64)RXH_L4_B_2_3;
3101 if (hash_flds & ICE_FLOW_HASH_FLD_GTPC_TEID ||
3102 hash_flds & ICE_FLOW_HASH_FLD_GTPU_IP_TEID ||
3103 hash_flds & ICE_FLOW_HASH_FLD_GTPU_EH_TEID ||
3104 hash_flds & ICE_FLOW_HASH_FLD_GTPU_UP_TEID ||
3105 hash_flds & ICE_FLOW_HASH_FLD_GTPU_DWN_TEID)
3106 nfc->data |= (u64)RXH_GTP_TEID;
3110 * ice_set_rxnfc - command to set Rx flow rules.
3111 * @netdev: network interface device structure
3112 * @cmd: ethtool rxnfc command
3114 * Returns 0 for success and negative values for errors
3116 static int ice_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
3118 struct ice_netdev_priv *np = netdev_priv(netdev);
3119 struct ice_vsi *vsi = np->vsi;
3122 case ETHTOOL_SRXCLSRLINS:
3123 return ice_add_fdir_ethtool(vsi, cmd);
3124 case ETHTOOL_SRXCLSRLDEL:
3125 return ice_del_fdir_ethtool(vsi, cmd);
3127 return ice_set_rss_hash_opt(vsi, cmd);
3135 * ice_get_rxnfc - command to get Rx flow classification rules
3136 * @netdev: network interface device structure
3137 * @cmd: ethtool rxnfc command
3138 * @rule_locs: buffer to rturn Rx flow classification rules
3140 * Returns Success if the command is supported.
3143 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
3144 u32 __always_unused *rule_locs)
3146 struct ice_netdev_priv *np = netdev_priv(netdev);
3147 struct ice_vsi *vsi = np->vsi;
3148 int ret = -EOPNOTSUPP;
3151 hw = &vsi->back->hw;
3154 case ETHTOOL_GRXRINGS:
3155 cmd->data = vsi->rss_size;
3158 case ETHTOOL_GRXCLSRLCNT:
3159 cmd->rule_cnt = hw->fdir_active_fltr;
3160 /* report total rule count */
3161 cmd->data = ice_get_fdir_cnt_all(hw);
3164 case ETHTOOL_GRXCLSRULE:
3165 ret = ice_get_ethtool_fdir_entry(hw, cmd);
3167 case ETHTOOL_GRXCLSRLALL:
3168 ret = ice_get_fdir_fltr_ids(hw, cmd, (u32 *)rule_locs);
3171 ice_get_rss_hash_opt(vsi, cmd);
3182 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
3183 struct kernel_ethtool_ringparam *kernel_ring,
3184 struct netlink_ext_ack *extack)
3186 struct ice_netdev_priv *np = netdev_priv(netdev);
3187 struct ice_vsi *vsi = np->vsi;
3189 ring->rx_max_pending = ICE_MAX_NUM_DESC;
3190 ring->tx_max_pending = ICE_MAX_NUM_DESC;
3191 if (vsi->tx_rings && vsi->rx_rings) {
3192 ring->rx_pending = vsi->rx_rings[0]->count;
3193 ring->tx_pending = vsi->tx_rings[0]->count;
3195 ring->rx_pending = 0;
3196 ring->tx_pending = 0;
3199 /* Rx mini and jumbo rings are not supported */
3200 ring->rx_mini_max_pending = 0;
3201 ring->rx_jumbo_max_pending = 0;
3202 ring->rx_mini_pending = 0;
3203 ring->rx_jumbo_pending = 0;
3207 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring,
3208 struct kernel_ethtool_ringparam *kernel_ring,
3209 struct netlink_ext_ack *extack)
3211 struct ice_netdev_priv *np = netdev_priv(netdev);
3212 struct ice_tx_ring *xdp_rings = NULL;
3213 struct ice_tx_ring *tx_rings = NULL;
3214 struct ice_rx_ring *rx_rings = NULL;
3215 struct ice_vsi *vsi = np->vsi;
3216 struct ice_pf *pf = vsi->back;
3217 int i, timeout = 50, err = 0;
3218 u16 new_rx_cnt, new_tx_cnt;
3220 if (ring->tx_pending > ICE_MAX_NUM_DESC ||
3221 ring->tx_pending < ICE_MIN_NUM_DESC ||
3222 ring->rx_pending > ICE_MAX_NUM_DESC ||
3223 ring->rx_pending < ICE_MIN_NUM_DESC) {
3224 netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
3225 ring->tx_pending, ring->rx_pending,
3226 ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
3227 ICE_REQ_DESC_MULTIPLE);
3231 /* Return if there is no rings (device is reloading) */
3232 if (!vsi->tx_rings || !vsi->rx_rings)
3235 new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
3236 if (new_tx_cnt != ring->tx_pending)
3237 netdev_info(netdev, "Requested Tx descriptor count rounded up to %d\n",
3239 new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
3240 if (new_rx_cnt != ring->rx_pending)
3241 netdev_info(netdev, "Requested Rx descriptor count rounded up to %d\n",
3244 /* if nothing to do return success */
3245 if (new_tx_cnt == vsi->tx_rings[0]->count &&
3246 new_rx_cnt == vsi->rx_rings[0]->count) {
3247 netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
3251 /* If there is a AF_XDP UMEM attached to any of Rx rings,
3252 * disallow changing the number of descriptors -- regardless
3253 * if the netdev is running or not.
3255 if (ice_xsk_any_rx_ring_ena(vsi))
3258 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
3262 usleep_range(1000, 2000);
3265 /* set for the next time the netdev is started */
3266 if (!netif_running(vsi->netdev)) {
3267 ice_for_each_alloc_txq(vsi, i)
3268 vsi->tx_rings[i]->count = new_tx_cnt;
3269 ice_for_each_alloc_rxq(vsi, i)
3270 vsi->rx_rings[i]->count = new_rx_cnt;
3271 if (ice_is_xdp_ena_vsi(vsi))
3272 ice_for_each_xdp_txq(vsi, i)
3273 vsi->xdp_rings[i]->count = new_tx_cnt;
3274 vsi->num_tx_desc = (u16)new_tx_cnt;
3275 vsi->num_rx_desc = (u16)new_rx_cnt;
3276 netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
3280 if (new_tx_cnt == vsi->tx_rings[0]->count)
3283 /* alloc updated Tx resources */
3284 netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
3285 vsi->tx_rings[0]->count, new_tx_cnt);
3287 tx_rings = kcalloc(vsi->num_txq, sizeof(*tx_rings), GFP_KERNEL);
3293 ice_for_each_txq(vsi, i) {
3294 /* clone ring and setup updated count */
3295 tx_rings[i] = *vsi->tx_rings[i];
3296 tx_rings[i].count = new_tx_cnt;
3297 tx_rings[i].desc = NULL;
3298 tx_rings[i].tx_buf = NULL;
3299 tx_rings[i].tx_tstamps = &pf->ptp.port.tx;
3300 err = ice_setup_tx_ring(&tx_rings[i]);
3303 ice_clean_tx_ring(&tx_rings[i]);
3309 if (!ice_is_xdp_ena_vsi(vsi))
3312 /* alloc updated XDP resources */
3313 netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
3314 vsi->xdp_rings[0]->count, new_tx_cnt);
3316 xdp_rings = kcalloc(vsi->num_xdp_txq, sizeof(*xdp_rings), GFP_KERNEL);
3322 ice_for_each_xdp_txq(vsi, i) {
3323 /* clone ring and setup updated count */
3324 xdp_rings[i] = *vsi->xdp_rings[i];
3325 xdp_rings[i].count = new_tx_cnt;
3326 xdp_rings[i].desc = NULL;
3327 xdp_rings[i].tx_buf = NULL;
3328 err = ice_setup_tx_ring(&xdp_rings[i]);
3331 ice_clean_tx_ring(&xdp_rings[i]);
3335 ice_set_ring_xdp(&xdp_rings[i]);
3339 if (new_rx_cnt == vsi->rx_rings[0]->count)
3342 /* alloc updated Rx resources */
3343 netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
3344 vsi->rx_rings[0]->count, new_rx_cnt);
3346 rx_rings = kcalloc(vsi->num_rxq, sizeof(*rx_rings), GFP_KERNEL);
3352 ice_for_each_rxq(vsi, i) {
3353 /* clone ring and setup updated count */
3354 rx_rings[i] = *vsi->rx_rings[i];
3355 rx_rings[i].count = new_rx_cnt;
3356 rx_rings[i].cached_phctime = pf->ptp.cached_phc_time;
3357 rx_rings[i].desc = NULL;
3358 rx_rings[i].rx_buf = NULL;
3359 /* this is to allow wr32 to have something to write to
3360 * during early allocation of Rx buffers
3362 rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
3364 err = ice_setup_rx_ring(&rx_rings[i]);
3368 /* allocate Rx buffers */
3369 err = ice_alloc_rx_bufs(&rx_rings[i],
3370 ICE_RX_DESC_UNUSED(&rx_rings[i]));
3375 ice_free_rx_ring(&rx_rings[i]);
3384 /* Bring interface down, copy in the new ring info, then restore the
3385 * interface. if VSI is up, bring it down and then back up
3387 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
3391 ice_for_each_txq(vsi, i) {
3392 ice_free_tx_ring(vsi->tx_rings[i]);
3393 *vsi->tx_rings[i] = tx_rings[i];
3399 ice_for_each_rxq(vsi, i) {
3400 ice_free_rx_ring(vsi->rx_rings[i]);
3401 /* copy the real tail offset */
3402 rx_rings[i].tail = vsi->rx_rings[i]->tail;
3403 /* this is to fake out the allocation routine
3404 * into thinking it has to realloc everything
3405 * but the recycling logic will let us re-use
3406 * the buffers allocated above
3408 rx_rings[i].next_to_use = 0;
3409 rx_rings[i].next_to_clean = 0;
3410 rx_rings[i].next_to_alloc = 0;
3411 *vsi->rx_rings[i] = rx_rings[i];
3417 ice_for_each_xdp_txq(vsi, i) {
3418 ice_free_tx_ring(vsi->xdp_rings[i]);
3419 *vsi->xdp_rings[i] = xdp_rings[i];
3424 vsi->num_tx_desc = new_tx_cnt;
3425 vsi->num_rx_desc = new_rx_cnt;
3431 /* error cleanup if the Rx allocations failed after getting Tx */
3433 ice_for_each_txq(vsi, i)
3434 ice_free_tx_ring(&tx_rings[i]);
3439 clear_bit(ICE_CFG_BUSY, pf->state);
3444 * ice_get_pauseparam - Get Flow Control status
3445 * @netdev: network interface device structure
3446 * @pause: ethernet pause (flow control) parameters
3448 * Get requested flow control status from PHY capability.
3449 * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
3450 * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
3451 * the negotiated Rx/Tx pause via lp_advertising.
3454 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3456 struct ice_netdev_priv *np = netdev_priv(netdev);
3457 struct ice_port_info *pi = np->vsi->port_info;
3458 struct ice_aqc_get_phy_caps_data *pcaps;
3459 struct ice_dcbx_cfg *dcbx_cfg;
3462 /* Initialize pause params */
3463 pause->rx_pause = 0;
3464 pause->tx_pause = 0;
3466 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3468 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3472 /* Get current PHY config */
3473 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3478 pause->autoneg = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3481 if (dcbx_cfg->pfc.pfcena)
3482 /* PFC enabled so report LFC as off */
3485 if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
3486 pause->tx_pause = 1;
3487 if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
3488 pause->rx_pause = 1;
3495 * ice_set_pauseparam - Set Flow Control parameter
3496 * @netdev: network interface device structure
3497 * @pause: return Tx/Rx flow control status
3500 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
3502 struct ice_netdev_priv *np = netdev_priv(netdev);
3503 struct ice_aqc_get_phy_caps_data *pcaps;
3504 struct ice_link_status *hw_link_info;
3505 struct ice_pf *pf = np->vsi->back;
3506 struct ice_dcbx_cfg *dcbx_cfg;
3507 struct ice_vsi *vsi = np->vsi;
3508 struct ice_hw *hw = &pf->hw;
3509 struct ice_port_info *pi;
3515 pi = vsi->port_info;
3516 hw_link_info = &pi->phy.link_info;
3517 dcbx_cfg = &pi->qos_cfg.local_dcbx_cfg;
3518 link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
3520 /* Changing the port's flow control is not supported if this isn't the
3523 if (vsi->type != ICE_VSI_PF) {
3524 netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
3528 /* Get pause param reports configured and negotiated flow control pause
3529 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
3530 * defined get pause param pause->autoneg reports SW configured setting,
3531 * so compare pause->autoneg with SW configured to prevent the user from
3532 * using set pause param to chance autoneg.
3534 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
3538 /* Get current PHY config */
3539 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
3546 is_an = ice_is_phy_caps_an_enabled(pcaps) ? AUTONEG_ENABLE :
3551 if (pause->autoneg != is_an) {
3552 netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
3556 /* If we have link and don't have autoneg */
3557 if (!test_bit(ICE_DOWN, pf->state) &&
3558 !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
3559 /* Send message that it might not necessarily work*/
3560 netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
3563 if (dcbx_cfg->pfc.pfcena) {
3564 netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
3567 if (pause->rx_pause && pause->tx_pause)
3568 pi->fc.req_mode = ICE_FC_FULL;
3569 else if (pause->rx_pause && !pause->tx_pause)
3570 pi->fc.req_mode = ICE_FC_RX_PAUSE;
3571 else if (!pause->rx_pause && pause->tx_pause)
3572 pi->fc.req_mode = ICE_FC_TX_PAUSE;
3573 else if (!pause->rx_pause && !pause->tx_pause)
3574 pi->fc.req_mode = ICE_FC_NONE;
3578 /* Set the FC mode and only restart AN if link is up */
3579 err = ice_set_fc(pi, &aq_failures, link_up);
3581 if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
3582 netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %s\n",
3583 err, ice_aq_str(hw->adminq.sq_last_status));
3585 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
3586 netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %s\n",
3587 err, ice_aq_str(hw->adminq.sq_last_status));
3589 } else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
3590 netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %s\n",
3591 err, ice_aq_str(hw->adminq.sq_last_status));
3599 * ice_get_rxfh_key_size - get the RSS hash key size
3600 * @netdev: network interface device structure
3602 * Returns the table size.
3604 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3606 return ICE_VSIQF_HKEY_ARRAY_SIZE;
3610 * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3611 * @netdev: network interface device structure
3613 * Returns the table size.
3615 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3617 struct ice_netdev_priv *np = netdev_priv(netdev);
3619 return np->vsi->rss_table_size;
3623 * ice_get_rxfh - get the Rx flow hash indirection table
3624 * @netdev: network interface device structure
3625 * @rxfh: pointer to param struct (indir, key, hfunc)
3627 * Reads the indirection table directly from the hardware.
3630 ice_get_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh)
3632 struct ice_netdev_priv *np = netdev_priv(netdev);
3633 u32 rss_context = rxfh->rss_context;
3634 struct ice_vsi *vsi = np->vsi;
3635 struct ice_pf *pf = vsi->back;
3640 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3641 netdev_warn(netdev, "RSS is not supported on this VSI!\n");
3645 if (rss_context && !ice_is_adq_active(pf)) {
3646 netdev_err(netdev, "RSS context cannot be non-zero when ADQ is not configured.\n");
3650 qcount = vsi->mqprio_qopt.qopt.count[rss_context];
3651 offset = vsi->mqprio_qopt.qopt.offset[rss_context];
3653 if (rss_context && ice_is_adq_active(pf)) {
3654 num_tc = vsi->mqprio_qopt.qopt.num_tc;
3655 if (rss_context >= num_tc) {
3656 netdev_err(netdev, "RSS context:%d > num_tc:%d\n",
3657 rss_context, num_tc);
3660 /* Use channel VSI of given TC */
3661 vsi = vsi->tc_map_vsi[rss_context];
3664 rxfh->hfunc = ETH_RSS_HASH_TOP;
3665 if (vsi->rss_hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ)
3666 rxfh->input_xfrm |= RXH_XFRM_SYM_XOR;
3671 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3675 err = ice_get_rss_key(vsi, rxfh->key);
3679 err = ice_get_rss_lut(vsi, lut, vsi->rss_table_size);
3683 if (ice_is_adq_active(pf)) {
3684 for (i = 0; i < vsi->rss_table_size; i++)
3685 rxfh->indir[i] = offset + lut[i] % qcount;
3689 for (i = 0; i < vsi->rss_table_size; i++)
3690 rxfh->indir[i] = lut[i];
3698 * ice_set_rxfh - set the Rx flow hash indirection table
3699 * @netdev: network interface device structure
3700 * @rxfh: pointer to param struct (indir, key, hfunc)
3701 * @extack: extended ACK from the Netlink message
3703 * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3704 * returns 0 after programming the table.
3707 ice_set_rxfh(struct net_device *netdev, struct ethtool_rxfh_param *rxfh,
3708 struct netlink_ext_ack *extack)
3710 struct ice_netdev_priv *np = netdev_priv(netdev);
3711 u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
3712 struct ice_vsi *vsi = np->vsi;
3713 struct ice_pf *pf = vsi->back;
3717 dev = ice_pf_to_dev(pf);
3718 if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
3719 rxfh->hfunc != ETH_RSS_HASH_TOP)
3722 if (rxfh->rss_context)
3725 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3726 /* RSS not supported return error here */
3727 netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3731 if (ice_is_adq_active(pf)) {
3732 netdev_err(netdev, "Cannot change RSS params with ADQ configured.\n");
3736 /* Update the VSI's hash function */
3737 if (rxfh->input_xfrm & RXH_XFRM_SYM_XOR)
3738 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
3740 err = ice_set_rss_hfunc(vsi, hfunc);
3745 if (!vsi->rss_hkey_user) {
3746 vsi->rss_hkey_user =
3747 devm_kzalloc(dev, ICE_VSIQF_HKEY_ARRAY_SIZE,
3749 if (!vsi->rss_hkey_user)
3752 memcpy(vsi->rss_hkey_user, rxfh->key,
3753 ICE_VSIQF_HKEY_ARRAY_SIZE);
3755 err = ice_set_rss_key(vsi, vsi->rss_hkey_user);
3760 if (!vsi->rss_lut_user) {
3761 vsi->rss_lut_user = devm_kzalloc(dev, vsi->rss_table_size,
3763 if (!vsi->rss_lut_user)
3767 /* Each 32 bits pointed by 'indir' is stored with a lut entry */
3771 for (i = 0; i < vsi->rss_table_size; i++)
3772 vsi->rss_lut_user[i] = (u8)(rxfh->indir[i]);
3774 ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3778 err = ice_set_rss_lut(vsi, vsi->rss_lut_user, vsi->rss_table_size);
3786 ice_get_ts_info(struct net_device *dev, struct kernel_ethtool_ts_info *info)
3788 struct ice_pf *pf = ice_netdev_to_pf(dev);
3790 /* only report timestamping if PTP is enabled */
3791 if (pf->ptp.state != ICE_PTP_READY)
3792 return ethtool_op_get_ts_info(dev, info);
3794 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
3795 SOF_TIMESTAMPING_TX_HARDWARE |
3796 SOF_TIMESTAMPING_RX_HARDWARE |
3797 SOF_TIMESTAMPING_RAW_HARDWARE;
3799 info->phc_index = ice_ptp_clock_index(pf);
3801 info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
3803 info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) | BIT(HWTSTAMP_FILTER_ALL);
3809 * ice_get_max_txq - return the maximum number of Tx queues for in a PF
3812 static int ice_get_max_txq(struct ice_pf *pf)
3814 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3815 (u16)pf->hw.func_caps.common_cap.num_txq);
3819 * ice_get_max_rxq - return the maximum number of Rx queues for in a PF
3822 static int ice_get_max_rxq(struct ice_pf *pf)
3824 return min3(pf->num_lan_msix, (u16)num_online_cpus(),
3825 (u16)pf->hw.func_caps.common_cap.num_rxq);
3829 * ice_get_combined_cnt - return the current number of combined channels
3830 * @vsi: PF VSI pointer
3832 * Go through all queue vectors and count ones that have both Rx and Tx ring
3835 static u32 ice_get_combined_cnt(struct ice_vsi *vsi)
3840 ice_for_each_q_vector(vsi, q_idx) {
3841 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3843 if (q_vector->rx.rx_ring && q_vector->tx.tx_ring)
3851 * ice_get_channels - get the current and max supported channels
3852 * @dev: network interface device structure
3853 * @ch: ethtool channel data structure
3856 ice_get_channels(struct net_device *dev, struct ethtool_channels *ch)
3858 struct ice_netdev_priv *np = netdev_priv(dev);
3859 struct ice_vsi *vsi = np->vsi;
3860 struct ice_pf *pf = vsi->back;
3862 /* report maximum channels */
3863 ch->max_rx = ice_get_max_rxq(pf);
3864 ch->max_tx = ice_get_max_txq(pf);
3865 ch->max_combined = min_t(int, ch->max_rx, ch->max_tx);
3867 /* report current channels */
3868 ch->combined_count = ice_get_combined_cnt(vsi);
3869 ch->rx_count = vsi->num_rxq - ch->combined_count;
3870 ch->tx_count = vsi->num_txq - ch->combined_count;
3872 /* report other queues */
3873 ch->other_count = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
3874 ch->max_other = ch->other_count;
3878 * ice_get_valid_rss_size - return valid number of RSS queues
3879 * @hw: pointer to the HW structure
3880 * @new_size: requested RSS queues
3882 static int ice_get_valid_rss_size(struct ice_hw *hw, int new_size)
3884 struct ice_hw_common_caps *caps = &hw->func_caps.common_cap;
3886 return min_t(int, new_size, BIT(caps->rss_table_entry_width));
3890 * ice_vsi_set_dflt_rss_lut - set default RSS LUT with requested RSS size
3891 * @vsi: VSI to reconfigure RSS LUT on
3892 * @req_rss_size: requested range of queue numbers for hashing
3894 * Set the VSI's RSS parameters, configure the RSS LUT based on these.
3896 static int ice_vsi_set_dflt_rss_lut(struct ice_vsi *vsi, int req_rss_size)
3898 struct ice_pf *pf = vsi->back;
3904 dev = ice_pf_to_dev(pf);
3910 lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
3914 /* set RSS LUT parameters */
3915 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
3918 vsi->rss_size = ice_get_valid_rss_size(hw, req_rss_size);
3920 /* create/set RSS LUT */
3921 ice_fill_rss_lut(lut, vsi->rss_table_size, vsi->rss_size);
3922 err = ice_set_rss_lut(vsi, lut, vsi->rss_table_size);
3924 dev_err(dev, "Cannot set RSS lut, err %d aq_err %s\n", err,
3925 ice_aq_str(hw->adminq.sq_last_status));
3932 * ice_set_channels - set the number channels
3933 * @dev: network interface device structure
3934 * @ch: ethtool channel data structure
3936 static int ice_set_channels(struct net_device *dev, struct ethtool_channels *ch)
3938 struct ice_netdev_priv *np = netdev_priv(dev);
3939 struct ice_vsi *vsi = np->vsi;
3940 struct ice_pf *pf = vsi->back;
3941 int new_rx = 0, new_tx = 0;
3942 bool locked = false;
3945 /* do not support changing channels in Safe Mode */
3946 if (ice_is_safe_mode(pf)) {
3947 netdev_err(dev, "Changing channel in Safe Mode is not supported\n");
3950 /* do not support changing other_count */
3951 if (ch->other_count != (test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1U : 0U))
3954 if (ice_is_adq_active(pf)) {
3955 netdev_err(dev, "Cannot set channels with ADQ configured.\n");
3959 if (test_bit(ICE_FLAG_FD_ENA, pf->flags) && pf->hw.fdir_active_fltr) {
3960 netdev_err(dev, "Cannot set channels when Flow Director filters are active\n");
3964 if (ch->rx_count && ch->tx_count) {
3965 netdev_err(dev, "Dedicated RX or TX channels cannot be used simultaneously\n");
3969 new_rx = ch->combined_count + ch->rx_count;
3970 new_tx = ch->combined_count + ch->tx_count;
3972 if (new_rx < vsi->tc_cfg.numtc) {
3973 netdev_err(dev, "Cannot set less Rx channels, than Traffic Classes you have (%u)\n",
3977 if (new_tx < vsi->tc_cfg.numtc) {
3978 netdev_err(dev, "Cannot set less Tx channels, than Traffic Classes you have (%u)\n",
3982 if (new_rx > ice_get_max_rxq(pf)) {
3983 netdev_err(dev, "Maximum allowed Rx channels is %d\n",
3984 ice_get_max_rxq(pf));
3987 if (new_tx > ice_get_max_txq(pf)) {
3988 netdev_err(dev, "Maximum allowed Tx channels is %d\n",
3989 ice_get_max_txq(pf));
3994 mutex_lock(&pf->adev_mutex);
3995 device_lock(&pf->adev->dev);
3997 if (pf->adev->dev.driver) {
3998 netdev_err(dev, "Cannot change channels when RDMA is active\n");
4004 ice_vsi_recfg_qs(vsi, new_rx, new_tx, locked);
4006 if (!netif_is_rxfh_configured(dev)) {
4007 ret = ice_vsi_set_dflt_rss_lut(vsi, new_rx);
4011 /* Update rss_size due to change in Rx queues */
4012 vsi->rss_size = ice_get_valid_rss_size(&pf->hw, new_rx);
4016 device_unlock(&pf->adev->dev);
4017 mutex_unlock(&pf->adev_mutex);
4023 * ice_get_wol - get current Wake on LAN configuration
4024 * @netdev: network interface device structure
4025 * @wol: Ethtool structure to retrieve WoL settings
4027 static void ice_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
4029 struct ice_netdev_priv *np = netdev_priv(netdev);
4030 struct ice_pf *pf = np->vsi->back;
4032 if (np->vsi->type != ICE_VSI_PF)
4033 netdev_warn(netdev, "Wake on LAN is not supported on this interface!\n");
4035 /* Get WoL settings based on the HW capability */
4036 if (ice_is_wol_supported(&pf->hw)) {
4037 wol->supported = WAKE_MAGIC;
4038 wol->wolopts = pf->wol_ena ? WAKE_MAGIC : 0;
4046 * ice_set_wol - set Wake on LAN on supported device
4047 * @netdev: network interface device structure
4048 * @wol: Ethtool structure to set WoL
4050 static int ice_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
4052 struct ice_netdev_priv *np = netdev_priv(netdev);
4053 struct ice_vsi *vsi = np->vsi;
4054 struct ice_pf *pf = vsi->back;
4056 if (vsi->type != ICE_VSI_PF || !ice_is_wol_supported(&pf->hw))
4059 /* only magic packet is supported */
4060 if (wol->wolopts && wol->wolopts != WAKE_MAGIC)
4063 /* Set WoL only if there is a new value */
4064 if (pf->wol_ena != !!wol->wolopts) {
4065 pf->wol_ena = !!wol->wolopts;
4066 device_set_wakeup_enable(ice_pf_to_dev(pf), pf->wol_ena);
4067 netdev_dbg(netdev, "WoL magic packet %sabled\n",
4068 pf->wol_ena ? "en" : "dis");
4075 * ice_get_rc_coalesce - get ITR values for specific ring container
4076 * @ec: ethtool structure to fill with driver's coalesce settings
4077 * @rc: ring container that the ITR values will come from
4079 * Query the device for ice_ring_container specific ITR values. This is
4080 * done per ice_ring_container because each q_vector can have 1 or more rings
4081 * and all of said ring(s) will have the same ITR values.
4083 * Returns 0 on success, negative otherwise.
4086 ice_get_rc_coalesce(struct ethtool_coalesce *ec, struct ice_ring_container *rc)
4092 case ICE_RX_CONTAINER:
4093 ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc);
4094 ec->rx_coalesce_usecs = rc->itr_setting;
4095 ec->rx_coalesce_usecs_high = rc->rx_ring->q_vector->intrl;
4097 case ICE_TX_CONTAINER:
4098 ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc);
4099 ec->tx_coalesce_usecs = rc->itr_setting;
4102 dev_dbg(ice_pf_to_dev(rc->rx_ring->vsi->back), "Invalid c_type %d\n", rc->type);
4110 * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
4111 * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
4112 * @ec: coalesce settings to program the device with
4113 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
4115 * Return 0 on success, and negative under the following conditions:
4116 * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
4117 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
4120 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
4122 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
4123 if (ice_get_rc_coalesce(ec,
4124 &vsi->rx_rings[q_num]->q_vector->rx))
4126 if (ice_get_rc_coalesce(ec,
4127 &vsi->tx_rings[q_num]->q_vector->tx))
4129 } else if (q_num < vsi->num_rxq) {
4130 if (ice_get_rc_coalesce(ec,
4131 &vsi->rx_rings[q_num]->q_vector->rx))
4133 } else if (q_num < vsi->num_txq) {
4134 if (ice_get_rc_coalesce(ec,
4135 &vsi->tx_rings[q_num]->q_vector->tx))
4145 * __ice_get_coalesce - get ITR/INTRL values for the device
4146 * @netdev: pointer to the netdev associated with this query
4147 * @ec: ethtool structure to fill with driver's coalesce settings
4148 * @q_num: queue number to get the coalesce settings for
4150 * If the caller passes in a negative q_num then we return coalesce settings
4151 * based on queue number 0, else use the actual q_num passed in.
4154 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
4157 struct ice_netdev_priv *np = netdev_priv(netdev);
4158 struct ice_vsi *vsi = np->vsi;
4163 if (ice_get_q_coalesce(vsi, ec, q_num))
4169 static int ice_get_coalesce(struct net_device *netdev,
4170 struct ethtool_coalesce *ec,
4171 struct kernel_ethtool_coalesce *kernel_coal,
4172 struct netlink_ext_ack *extack)
4174 return __ice_get_coalesce(netdev, ec, -1);
4178 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
4179 struct ethtool_coalesce *ec)
4181 return __ice_get_coalesce(netdev, ec, q_num);
4185 * ice_set_rc_coalesce - set ITR values for specific ring container
4186 * @ec: ethtool structure from user to update ITR settings
4187 * @rc: ring container that the ITR values will come from
4188 * @vsi: VSI associated to the ring container
4190 * Set specific ITR values. This is done per ice_ring_container because each
4191 * q_vector can have 1 or more rings and all of said ring(s) will have the same
4194 * Returns 0 on success, negative otherwise.
4197 ice_set_rc_coalesce(struct ethtool_coalesce *ec,
4198 struct ice_ring_container *rc, struct ice_vsi *vsi)
4200 const char *c_type_str = (rc->type == ICE_RX_CONTAINER) ? "rx" : "tx";
4201 u32 use_adaptive_coalesce, coalesce_usecs;
4202 struct ice_pf *pf = vsi->back;
4209 case ICE_RX_CONTAINER:
4211 struct ice_q_vector *q_vector = rc->rx_ring->q_vector;
4213 if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
4214 (ec->rx_coalesce_usecs_high &&
4215 ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
4216 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
4217 c_type_str, pf->hw.intrl_gran,
4221 if (ec->rx_coalesce_usecs_high != q_vector->intrl &&
4222 (ec->use_adaptive_rx_coalesce || ec->use_adaptive_tx_coalesce)) {
4223 netdev_info(vsi->netdev, "Invalid value, %s-usecs-high cannot be changed if adaptive-tx or adaptive-rx is enabled\n",
4227 if (ec->rx_coalesce_usecs_high != q_vector->intrl)
4228 q_vector->intrl = ec->rx_coalesce_usecs_high;
4230 use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
4231 coalesce_usecs = ec->rx_coalesce_usecs;
4235 case ICE_TX_CONTAINER:
4236 use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
4237 coalesce_usecs = ec->tx_coalesce_usecs;
4241 dev_dbg(ice_pf_to_dev(pf), "Invalid container type %d\n",
4246 itr_setting = rc->itr_setting;
4247 if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
4248 netdev_info(vsi->netdev, "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
4249 c_type_str, c_type_str);
4253 if (coalesce_usecs > ICE_ITR_MAX) {
4254 netdev_info(vsi->netdev, "Invalid value, %s-usecs range is 0-%d\n",
4255 c_type_str, ICE_ITR_MAX);
4259 if (use_adaptive_coalesce) {
4260 rc->itr_mode = ITR_DYNAMIC;
4262 rc->itr_mode = ITR_STATIC;
4263 /* store user facing value how it was set */
4264 rc->itr_setting = coalesce_usecs;
4265 /* write the change to the register */
4266 ice_write_itr(rc, coalesce_usecs);
4267 /* force writes to take effect immediately, the flush shouldn't
4268 * be done in the functions above because the intent is for
4269 * them to do lazy writes.
4278 * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
4279 * @vsi: VSI associated to the queue that need updating
4280 * @ec: coalesce settings to program the device with
4281 * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
4283 * Return 0 on success, and negative under the following conditions:
4284 * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
4285 * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
4288 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
4290 if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
4291 if (ice_set_rc_coalesce(ec,
4292 &vsi->rx_rings[q_num]->q_vector->rx,
4296 if (ice_set_rc_coalesce(ec,
4297 &vsi->tx_rings[q_num]->q_vector->tx,
4300 } else if (q_num < vsi->num_rxq) {
4301 if (ice_set_rc_coalesce(ec,
4302 &vsi->rx_rings[q_num]->q_vector->rx,
4305 } else if (q_num < vsi->num_txq) {
4306 if (ice_set_rc_coalesce(ec,
4307 &vsi->tx_rings[q_num]->q_vector->tx,
4318 * ice_print_if_odd_usecs - print message if user tries to set odd [tx|rx]-usecs
4319 * @netdev: netdev used for print
4320 * @itr_setting: previous user setting
4321 * @use_adaptive_coalesce: if adaptive coalesce is enabled or being enabled
4322 * @coalesce_usecs: requested value of [tx|rx]-usecs
4323 * @c_type_str: either "rx" or "tx" to match user set field of [tx|rx]-usecs
4326 ice_print_if_odd_usecs(struct net_device *netdev, u16 itr_setting,
4327 u32 use_adaptive_coalesce, u32 coalesce_usecs,
4328 const char *c_type_str)
4330 if (use_adaptive_coalesce)
4333 if (itr_setting != coalesce_usecs && (coalesce_usecs % 2))
4334 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",
4335 c_type_str, coalesce_usecs, c_type_str,
4336 ITR_REG_ALIGN(coalesce_usecs));
4340 * __ice_set_coalesce - set ITR/INTRL values for the device
4341 * @netdev: pointer to the netdev associated with this query
4342 * @ec: ethtool structure to fill with driver's coalesce settings
4343 * @q_num: queue number to get the coalesce settings for
4345 * If the caller passes in a negative q_num then we set the coalesce settings
4346 * for all Tx/Rx queues, else use the actual q_num passed in.
4349 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
4352 struct ice_netdev_priv *np = netdev_priv(netdev);
4353 struct ice_vsi *vsi = np->vsi;
4356 struct ice_q_vector *q_vector = vsi->q_vectors[0];
4360 ice_print_if_odd_usecs(netdev, q_vector->rx.itr_setting,
4361 ec->use_adaptive_rx_coalesce,
4362 ec->rx_coalesce_usecs, "rx");
4364 ice_print_if_odd_usecs(netdev, q_vector->tx.itr_setting,
4365 ec->use_adaptive_tx_coalesce,
4366 ec->tx_coalesce_usecs, "tx");
4369 ice_for_each_q_vector(vsi, v_idx) {
4370 /* In some cases if DCB is configured the num_[rx|tx]q
4371 * can be less than vsi->num_q_vectors. This check
4372 * accounts for that so we don't report a false failure
4374 if (v_idx >= vsi->num_rxq && v_idx >= vsi->num_txq)
4377 if (ice_set_q_coalesce(vsi, ec, v_idx))
4380 ice_set_q_vector_intrl(vsi->q_vectors[v_idx]);
4385 if (ice_set_q_coalesce(vsi, ec, q_num))
4388 ice_set_q_vector_intrl(vsi->q_vectors[q_num]);
4394 static int ice_set_coalesce(struct net_device *netdev,
4395 struct ethtool_coalesce *ec,
4396 struct kernel_ethtool_coalesce *kernel_coal,
4397 struct netlink_ext_ack *extack)
4399 return __ice_set_coalesce(netdev, ec, -1);
4403 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
4404 struct ethtool_coalesce *ec)
4406 return __ice_set_coalesce(netdev, ec, q_num);
4410 ice_repr_get_drvinfo(struct net_device *netdev,
4411 struct ethtool_drvinfo *drvinfo)
4413 struct ice_repr *repr = ice_netdev_to_repr(netdev);
4415 if (repr->ops.ready(repr))
4418 __ice_get_drvinfo(netdev, drvinfo, repr->src_vsi);
4422 ice_repr_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
4424 struct ice_repr *repr = ice_netdev_to_repr(netdev);
4426 /* for port representors only ETH_SS_STATS is supported */
4427 if (repr->ops.ready(repr) || stringset != ETH_SS_STATS)
4430 __ice_get_strings(netdev, stringset, data, repr->src_vsi);
4434 ice_repr_get_ethtool_stats(struct net_device *netdev,
4435 struct ethtool_stats __always_unused *stats,
4438 struct ice_repr *repr = ice_netdev_to_repr(netdev);
4440 if (repr->ops.ready(repr))
4443 __ice_get_ethtool_stats(netdev, stats, data, repr->src_vsi);
4446 static int ice_repr_get_sset_count(struct net_device *netdev, int sset)
4450 return ICE_VSI_STATS_LEN;
4456 #define ICE_I2C_EEPROM_DEV_ADDR 0xA0
4457 #define ICE_I2C_EEPROM_DEV_ADDR2 0xA2
4458 #define ICE_MODULE_TYPE_SFP 0x03
4459 #define ICE_MODULE_TYPE_QSFP_PLUS 0x0D
4460 #define ICE_MODULE_TYPE_QSFP28 0x11
4461 #define ICE_MODULE_SFF_ADDR_MODE 0x04
4462 #define ICE_MODULE_SFF_DIAG_CAPAB 0x40
4463 #define ICE_MODULE_REVISION_ADDR 0x01
4464 #define ICE_MODULE_SFF_8472_COMP 0x5E
4465 #define ICE_MODULE_SFF_8472_SWAP 0x5C
4466 #define ICE_MODULE_QSFP_MAX_LEN 640
4469 * ice_get_module_info - get SFF module type and revision information
4470 * @netdev: network interface device structure
4471 * @modinfo: module EEPROM size and layout information structure
4474 ice_get_module_info(struct net_device *netdev,
4475 struct ethtool_modinfo *modinfo)
4477 struct ice_netdev_priv *np = netdev_priv(netdev);
4478 struct ice_vsi *vsi = np->vsi;
4479 struct ice_pf *pf = vsi->back;
4480 struct ice_hw *hw = &pf->hw;
4481 u8 sff8472_comp = 0;
4482 u8 sff8472_swap = 0;
4487 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
4488 0, &value, 1, 0, NULL);
4493 case ICE_MODULE_TYPE_SFP:
4494 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4495 ICE_MODULE_SFF_8472_COMP, 0x00, 0,
4496 &sff8472_comp, 1, 0, NULL);
4499 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4500 ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
4501 &sff8472_swap, 1, 0, NULL);
4505 if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
4506 modinfo->type = ETH_MODULE_SFF_8079;
4507 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4508 } else if (sff8472_comp &&
4509 (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
4510 modinfo->type = ETH_MODULE_SFF_8472;
4511 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
4513 modinfo->type = ETH_MODULE_SFF_8079;
4514 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
4517 case ICE_MODULE_TYPE_QSFP_PLUS:
4518 case ICE_MODULE_TYPE_QSFP28:
4519 status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
4520 ICE_MODULE_REVISION_ADDR, 0x00, 0,
4521 &sff8636_rev, 1, 0, NULL);
4524 /* Check revision compliance */
4525 if (sff8636_rev > 0x02) {
4526 /* Module is SFF-8636 compliant */
4527 modinfo->type = ETH_MODULE_SFF_8636;
4528 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4530 modinfo->type = ETH_MODULE_SFF_8436;
4531 modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
4535 netdev_warn(netdev, "SFF Module Type not recognized.\n");
4542 * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
4543 * @netdev: network interface device structure
4544 * @ee: EEPROM dump request structure
4545 * @data: buffer to be filled with EEPROM contents
4548 ice_get_module_eeprom(struct net_device *netdev,
4549 struct ethtool_eeprom *ee, u8 *data)
4551 struct ice_netdev_priv *np = netdev_priv(netdev);
4552 #define SFF_READ_BLOCK_SIZE 8
4553 u8 value[SFF_READ_BLOCK_SIZE] = { 0 };
4554 u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
4555 struct ice_vsi *vsi = np->vsi;
4556 struct ice_pf *pf = vsi->back;
4557 struct ice_hw *hw = &pf->hw;
4558 bool is_sfp = false;
4564 if (!ee || !ee->len || !data)
4567 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0, value, 1, 0,
4572 if (value[0] == ICE_MODULE_TYPE_SFP)
4575 memset(data, 0, ee->len);
4576 for (i = 0; i < ee->len; i += SFF_READ_BLOCK_SIZE) {
4577 offset = i + ee->offset;
4580 /* Check if we need to access the other memory page */
4582 if (offset >= ETH_MODULE_SFF_8079_LEN) {
4583 offset -= ETH_MODULE_SFF_8079_LEN;
4584 addr = ICE_I2C_EEPROM_DEV_ADDR2;
4587 while (offset >= ETH_MODULE_SFF_8436_LEN) {
4588 /* Compute memory page number and offset. */
4589 offset -= ETH_MODULE_SFF_8436_LEN / 2;
4594 /* Bit 2 of EEPROM address 0x02 declares upper
4595 * pages are disabled on QSFP modules.
4596 * SFP modules only ever use page 0.
4598 if (page == 0 || !(data[0x2] & 0x4)) {
4601 /* If i2c bus is busy due to slow page change or
4602 * link management access, call can fail. This is normal.
4603 * So we retry this a few times.
4605 for (j = 0; j < 4; j++) {
4606 status = ice_aq_sff_eeprom(hw, 0, addr, offset, page,
4608 SFF_READ_BLOCK_SIZE,
4610 netdev_dbg(netdev, "SFF %02X %02X %02X %X = %02X%02X%02X%02X.%02X%02X%02X%02X (%X)\n",
4611 addr, offset, page, is_sfp,
4612 value[0], value[1], value[2], value[3],
4613 value[4], value[5], value[6], value[7],
4616 usleep_range(1500, 2500);
4617 memset(value, 0, SFF_READ_BLOCK_SIZE);
4623 /* Make sure we have enough room for the new block */
4624 copy_len = min_t(u32, SFF_READ_BLOCK_SIZE, ee->len - i);
4625 memcpy(data + i, value, copy_len);
4632 * ice_get_port_fec_stats - returns FEC correctable, uncorrectable stats per
4634 * @hw: pointer to the HW struct
4635 * @pcs_quad: pcsquad for input port
4636 * @pcs_port: pcsport for input port
4637 * @fec_stats: buffer to hold FEC statistics for given port
4639 * Return: 0 on success, negative on failure.
4641 static int ice_get_port_fec_stats(struct ice_hw *hw, u16 pcs_quad, u16 pcs_port,
4642 struct ethtool_fec_stats *fec_stats)
4644 u32 fec_uncorr_low_val = 0, fec_uncorr_high_val = 0;
4645 u32 fec_corr_low_val = 0, fec_corr_high_val = 0;
4648 if (pcs_quad > 1 || pcs_port > 3)
4651 err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port, ICE_FEC_CORR_LOW,
4656 err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port, ICE_FEC_CORR_HIGH,
4657 &fec_corr_high_val);
4661 err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port,
4663 &fec_uncorr_low_val);
4667 err = ice_aq_get_fec_stats(hw, pcs_quad, pcs_port,
4668 ICE_FEC_UNCORR_HIGH,
4669 &fec_uncorr_high_val);
4673 fec_stats->corrected_blocks.total = (fec_corr_high_val << 16) +
4675 fec_stats->uncorrectable_blocks.total = (fec_uncorr_high_val << 16) +
4681 * ice_get_fec_stats - returns FEC correctable, uncorrectable stats per netdev
4682 * @netdev: network interface device structure
4683 * @fec_stats: buffer to hold FEC statistics for given port
4686 static void ice_get_fec_stats(struct net_device *netdev,
4687 struct ethtool_fec_stats *fec_stats)
4689 struct ice_netdev_priv *np = netdev_priv(netdev);
4690 struct ice_port_topology port_topology;
4691 struct ice_port_info *pi;
4698 pi = np->vsi->port_info;
4700 /* Serdes parameters are not supported if not the PF VSI */
4701 if (np->vsi->type != ICE_VSI_PF || !pi)
4704 err = ice_get_port_topology(hw, pi->lport, &port_topology);
4706 netdev_info(netdev, "Extended register dump failed Lport %d\n",
4711 /* Get FEC correctable, uncorrectable counter */
4712 err = ice_get_port_fec_stats(hw, port_topology.pcs_quad_select,
4713 port_topology.pcs_port, fec_stats);
4715 netdev_info(netdev, "FEC stats get failed Lport %d Err %d\n",
4719 static const struct ethtool_ops ice_ethtool_ops = {
4720 .cap_rss_ctx_supported = true,
4721 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
4722 ETHTOOL_COALESCE_USE_ADAPTIVE |
4723 ETHTOOL_COALESCE_RX_USECS_HIGH,
4724 .cap_rss_sym_xor_supported = true,
4725 .rxfh_per_ctx_key = true,
4726 .get_link_ksettings = ice_get_link_ksettings,
4727 .set_link_ksettings = ice_set_link_ksettings,
4728 .get_fec_stats = ice_get_fec_stats,
4729 .get_drvinfo = ice_get_drvinfo,
4730 .get_regs_len = ice_get_regs_len,
4731 .get_regs = ice_get_regs,
4732 .get_wol = ice_get_wol,
4733 .set_wol = ice_set_wol,
4734 .get_msglevel = ice_get_msglevel,
4735 .set_msglevel = ice_set_msglevel,
4736 .self_test = ice_self_test,
4737 .get_link = ethtool_op_get_link,
4738 .get_eeprom_len = ice_get_eeprom_len,
4739 .get_eeprom = ice_get_eeprom,
4740 .get_coalesce = ice_get_coalesce,
4741 .set_coalesce = ice_set_coalesce,
4742 .get_strings = ice_get_strings,
4743 .set_phys_id = ice_set_phys_id,
4744 .get_ethtool_stats = ice_get_ethtool_stats,
4745 .get_priv_flags = ice_get_priv_flags,
4746 .set_priv_flags = ice_set_priv_flags,
4747 .get_sset_count = ice_get_sset_count,
4748 .get_rxnfc = ice_get_rxnfc,
4749 .set_rxnfc = ice_set_rxnfc,
4750 .get_ringparam = ice_get_ringparam,
4751 .set_ringparam = ice_set_ringparam,
4752 .nway_reset = ice_nway_reset,
4753 .get_pauseparam = ice_get_pauseparam,
4754 .set_pauseparam = ice_set_pauseparam,
4755 .get_rxfh_key_size = ice_get_rxfh_key_size,
4756 .get_rxfh_indir_size = ice_get_rxfh_indir_size,
4757 .get_rxfh = ice_get_rxfh,
4758 .set_rxfh = ice_set_rxfh,
4759 .get_channels = ice_get_channels,
4760 .set_channels = ice_set_channels,
4761 .get_ts_info = ice_get_ts_info,
4762 .get_per_queue_coalesce = ice_get_per_q_coalesce,
4763 .set_per_queue_coalesce = ice_set_per_q_coalesce,
4764 .get_fecparam = ice_get_fecparam,
4765 .set_fecparam = ice_set_fecparam,
4766 .get_module_info = ice_get_module_info,
4767 .get_module_eeprom = ice_get_module_eeprom,
4770 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
4771 .get_link_ksettings = ice_get_link_ksettings,
4772 .set_link_ksettings = ice_set_link_ksettings,
4773 .get_drvinfo = ice_get_drvinfo,
4774 .get_regs_len = ice_get_regs_len,
4775 .get_regs = ice_get_regs,
4776 .get_wol = ice_get_wol,
4777 .set_wol = ice_set_wol,
4778 .get_msglevel = ice_get_msglevel,
4779 .set_msglevel = ice_set_msglevel,
4780 .get_link = ethtool_op_get_link,
4781 .get_eeprom_len = ice_get_eeprom_len,
4782 .get_eeprom = ice_get_eeprom,
4783 .get_strings = ice_get_strings,
4784 .get_ethtool_stats = ice_get_ethtool_stats,
4785 .get_sset_count = ice_get_sset_count,
4786 .get_ringparam = ice_get_ringparam,
4787 .set_ringparam = ice_set_ringparam,
4788 .nway_reset = ice_nway_reset,
4789 .get_channels = ice_get_channels,
4793 * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
4794 * @netdev: network interface device structure
4796 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
4798 netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
4801 static const struct ethtool_ops ice_ethtool_repr_ops = {
4802 .get_drvinfo = ice_repr_get_drvinfo,
4803 .get_link = ethtool_op_get_link,
4804 .get_strings = ice_repr_get_strings,
4805 .get_ethtool_stats = ice_repr_get_ethtool_stats,
4806 .get_sset_count = ice_repr_get_sset_count,
4810 * ice_set_ethtool_repr_ops - setup VF's port representor ethtool ops
4811 * @netdev: network interface device structure
4813 void ice_set_ethtool_repr_ops(struct net_device *netdev)
4815 netdev->ethtool_ops = &ice_ethtool_repr_ops;
4819 * ice_set_ethtool_ops - setup netdev ethtool ops
4820 * @netdev: network interface device structure
4822 * setup netdev ethtool ops with ice specific ops
4824 void ice_set_ethtool_ops(struct net_device *netdev)
4826 netdev->ethtool_ops = &ice_ethtool_ops;