xref: /linux/drivers/net/ethernet/intel/ice/ice_ethtool.c (revision 4d66c56f7efe122d09d06cd3ebfa52a43d51a9cb)
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 /* ethtool support for ice */
5 
6 #include "ice.h"
7 #include "ice_lib.h"
8 #include "ice_dcb_lib.h"
9 
10 struct ice_stats {
11 	char stat_string[ETH_GSTRING_LEN];
12 	int sizeof_stat;
13 	int stat_offset;
14 };
15 
16 #define ICE_STAT(_type, _name, _stat) { \
17 	.stat_string = _name, \
18 	.sizeof_stat = FIELD_SIZEOF(_type, _stat), \
19 	.stat_offset = offsetof(_type, _stat) \
20 }
21 
22 #define ICE_VSI_STAT(_name, _stat) \
23 		ICE_STAT(struct ice_vsi, _name, _stat)
24 #define ICE_PF_STAT(_name, _stat) \
25 		ICE_STAT(struct ice_pf, _name, _stat)
26 
27 static int ice_q_stats_len(struct net_device *netdev)
28 {
29 	struct ice_netdev_priv *np = netdev_priv(netdev);
30 
31 	return ((np->vsi->alloc_txq + np->vsi->alloc_rxq) *
32 		(sizeof(struct ice_q_stats) / sizeof(u64)));
33 }
34 
35 #define ICE_PF_STATS_LEN	ARRAY_SIZE(ice_gstrings_pf_stats)
36 #define ICE_VSI_STATS_LEN	ARRAY_SIZE(ice_gstrings_vsi_stats)
37 
38 #define ICE_PFC_STATS_LEN ( \
39 		(FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_rx) + \
40 		 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_rx) + \
41 		 FIELD_SIZEOF(struct ice_pf, stats.priority_xoff_tx) + \
42 		 FIELD_SIZEOF(struct ice_pf, stats.priority_xon_tx)) \
43 		 / sizeof(u64))
44 #define ICE_ALL_STATS_LEN(n)	(ICE_PF_STATS_LEN + ICE_PFC_STATS_LEN + \
45 				 ICE_VSI_STATS_LEN + ice_q_stats_len(n))
46 
47 static const struct ice_stats ice_gstrings_vsi_stats[] = {
48 	ICE_VSI_STAT("rx_unicast", eth_stats.rx_unicast),
49 	ICE_VSI_STAT("tx_unicast", eth_stats.tx_unicast),
50 	ICE_VSI_STAT("rx_multicast", eth_stats.rx_multicast),
51 	ICE_VSI_STAT("tx_multicast", eth_stats.tx_multicast),
52 	ICE_VSI_STAT("rx_broadcast", eth_stats.rx_broadcast),
53 	ICE_VSI_STAT("tx_broadcast", eth_stats.tx_broadcast),
54 	ICE_VSI_STAT("rx_bytes", eth_stats.rx_bytes),
55 	ICE_VSI_STAT("tx_bytes", eth_stats.tx_bytes),
56 	ICE_VSI_STAT("rx_dropped", eth_stats.rx_discards),
57 	ICE_VSI_STAT("rx_unknown_protocol", eth_stats.rx_unknown_protocol),
58 	ICE_VSI_STAT("rx_alloc_fail", rx_buf_failed),
59 	ICE_VSI_STAT("rx_pg_alloc_fail", rx_page_failed),
60 	ICE_VSI_STAT("tx_errors", eth_stats.tx_errors),
61 	ICE_VSI_STAT("tx_linearize", tx_linearize),
62 };
63 
64 enum ice_ethtool_test_id {
65 	ICE_ETH_TEST_REG = 0,
66 	ICE_ETH_TEST_EEPROM,
67 	ICE_ETH_TEST_INTR,
68 	ICE_ETH_TEST_LOOP,
69 	ICE_ETH_TEST_LINK,
70 };
71 
72 static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
73 	"Register test  (offline)",
74 	"EEPROM test    (offline)",
75 	"Interrupt test (offline)",
76 	"Loopback test  (offline)",
77 	"Link test   (on/offline)",
78 };
79 
80 #define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
81 
82 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
83  * but they aren't. This device is capable of supporting multiple
84  * VSIs/netdevs on a single PF. The NETDEV_STATs are for individual
85  * netdevs whereas the PF_STATs are for the physical function that's
86  * hosting these netdevs.
87  *
88  * The PF_STATs are appended to the netdev stats only when ethtool -S
89  * is queried on the base PF netdev.
90  */
91 static const struct ice_stats ice_gstrings_pf_stats[] = {
92 	ICE_PF_STAT("rx_bytes.nic", stats.eth.rx_bytes),
93 	ICE_PF_STAT("tx_bytes.nic", stats.eth.tx_bytes),
94 	ICE_PF_STAT("rx_unicast.nic", stats.eth.rx_unicast),
95 	ICE_PF_STAT("tx_unicast.nic", stats.eth.tx_unicast),
96 	ICE_PF_STAT("rx_multicast.nic", stats.eth.rx_multicast),
97 	ICE_PF_STAT("tx_multicast.nic", stats.eth.tx_multicast),
98 	ICE_PF_STAT("rx_broadcast.nic", stats.eth.rx_broadcast),
99 	ICE_PF_STAT("tx_broadcast.nic", stats.eth.tx_broadcast),
100 	ICE_PF_STAT("tx_errors.nic", stats.eth.tx_errors),
101 	ICE_PF_STAT("rx_size_64.nic", stats.rx_size_64),
102 	ICE_PF_STAT("tx_size_64.nic", stats.tx_size_64),
103 	ICE_PF_STAT("rx_size_127.nic", stats.rx_size_127),
104 	ICE_PF_STAT("tx_size_127.nic", stats.tx_size_127),
105 	ICE_PF_STAT("rx_size_255.nic", stats.rx_size_255),
106 	ICE_PF_STAT("tx_size_255.nic", stats.tx_size_255),
107 	ICE_PF_STAT("rx_size_511.nic", stats.rx_size_511),
108 	ICE_PF_STAT("tx_size_511.nic", stats.tx_size_511),
109 	ICE_PF_STAT("rx_size_1023.nic", stats.rx_size_1023),
110 	ICE_PF_STAT("tx_size_1023.nic", stats.tx_size_1023),
111 	ICE_PF_STAT("rx_size_1522.nic", stats.rx_size_1522),
112 	ICE_PF_STAT("tx_size_1522.nic", stats.tx_size_1522),
113 	ICE_PF_STAT("rx_size_big.nic", stats.rx_size_big),
114 	ICE_PF_STAT("tx_size_big.nic", stats.tx_size_big),
115 	ICE_PF_STAT("link_xon_rx.nic", stats.link_xon_rx),
116 	ICE_PF_STAT("link_xon_tx.nic", stats.link_xon_tx),
117 	ICE_PF_STAT("link_xoff_rx.nic", stats.link_xoff_rx),
118 	ICE_PF_STAT("link_xoff_tx.nic", stats.link_xoff_tx),
119 	ICE_PF_STAT("tx_dropped_link_down.nic", stats.tx_dropped_link_down),
120 	ICE_PF_STAT("rx_undersize.nic", stats.rx_undersize),
121 	ICE_PF_STAT("rx_fragments.nic", stats.rx_fragments),
122 	ICE_PF_STAT("rx_oversize.nic", stats.rx_oversize),
123 	ICE_PF_STAT("rx_jabber.nic", stats.rx_jabber),
124 	ICE_PF_STAT("rx_csum_bad.nic", hw_csum_rx_error),
125 	ICE_PF_STAT("rx_length_errors.nic", stats.rx_len_errors),
126 	ICE_PF_STAT("rx_dropped.nic", stats.eth.rx_discards),
127 	ICE_PF_STAT("rx_crc_errors.nic", stats.crc_errors),
128 	ICE_PF_STAT("illegal_bytes.nic", stats.illegal_bytes),
129 	ICE_PF_STAT("mac_local_faults.nic", stats.mac_local_faults),
130 	ICE_PF_STAT("mac_remote_faults.nic", stats.mac_remote_faults),
131 };
132 
133 static const u32 ice_regs_dump_list[] = {
134 	PFGEN_STATE,
135 	PRTGEN_STATUS,
136 	QRX_CTRL(0),
137 	QINT_TQCTL(0),
138 	QINT_RQCTL(0),
139 	PFINT_OICR_ENA,
140 	QRX_ITR(0),
141 	PF0INT_ITR_0(0),
142 	PF0INT_ITR_1(0),
143 	PF0INT_ITR_2(0),
144 };
145 
146 struct ice_priv_flag {
147 	char name[ETH_GSTRING_LEN];
148 	u32 bitno;			/* bit position in pf->flags */
149 };
150 
151 #define ICE_PRIV_FLAG(_name, _bitno) { \
152 	.name = _name, \
153 	.bitno = _bitno, \
154 }
155 
156 static const struct ice_priv_flag ice_gstrings_priv_flags[] = {
157 	ICE_PRIV_FLAG("link-down-on-close", ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA),
158 	ICE_PRIV_FLAG("fw-lldp-agent", ICE_FLAG_FW_LLDP_AGENT),
159 	ICE_PRIV_FLAG("legacy-rx", ICE_FLAG_LEGACY_RX),
160 };
161 
162 #define ICE_PRIV_FLAG_ARRAY_SIZE	ARRAY_SIZE(ice_gstrings_priv_flags)
163 
164 static void
165 ice_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
166 {
167 	struct ice_netdev_priv *np = netdev_priv(netdev);
168 	struct ice_vsi *vsi = np->vsi;
169 	struct ice_pf *pf = vsi->back;
170 
171 	strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver));
172 	strlcpy(drvinfo->version, ice_drv_ver, sizeof(drvinfo->version));
173 	strlcpy(drvinfo->fw_version, ice_nvm_version_str(&pf->hw),
174 		sizeof(drvinfo->fw_version));
175 	strlcpy(drvinfo->bus_info, pci_name(pf->pdev),
176 		sizeof(drvinfo->bus_info));
177 	drvinfo->n_priv_flags = ICE_PRIV_FLAG_ARRAY_SIZE;
178 }
179 
180 static int ice_get_regs_len(struct net_device __always_unused *netdev)
181 {
182 	return sizeof(ice_regs_dump_list);
183 }
184 
185 static void
186 ice_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p)
187 {
188 	struct ice_netdev_priv *np = netdev_priv(netdev);
189 	struct ice_pf *pf = np->vsi->back;
190 	struct ice_hw *hw = &pf->hw;
191 	u32 *regs_buf = (u32 *)p;
192 	int i;
193 
194 	regs->version = 1;
195 
196 	for (i = 0; i < ARRAY_SIZE(ice_regs_dump_list); ++i)
197 		regs_buf[i] = rd32(hw, ice_regs_dump_list[i]);
198 }
199 
200 static u32 ice_get_msglevel(struct net_device *netdev)
201 {
202 	struct ice_netdev_priv *np = netdev_priv(netdev);
203 	struct ice_pf *pf = np->vsi->back;
204 
205 #ifndef CONFIG_DYNAMIC_DEBUG
206 	if (pf->hw.debug_mask)
207 		netdev_info(netdev, "hw debug_mask: 0x%llX\n",
208 			    pf->hw.debug_mask);
209 #endif /* !CONFIG_DYNAMIC_DEBUG */
210 
211 	return pf->msg_enable;
212 }
213 
214 static void ice_set_msglevel(struct net_device *netdev, u32 data)
215 {
216 	struct ice_netdev_priv *np = netdev_priv(netdev);
217 	struct ice_pf *pf = np->vsi->back;
218 
219 #ifndef CONFIG_DYNAMIC_DEBUG
220 	if (ICE_DBG_USER & data)
221 		pf->hw.debug_mask = data;
222 	else
223 		pf->msg_enable = data;
224 #else
225 	pf->msg_enable = data;
226 #endif /* !CONFIG_DYNAMIC_DEBUG */
227 }
228 
229 static int ice_get_eeprom_len(struct net_device *netdev)
230 {
231 	struct ice_netdev_priv *np = netdev_priv(netdev);
232 	struct ice_pf *pf = np->vsi->back;
233 
234 	return (int)(pf->hw.nvm.sr_words * sizeof(u16));
235 }
236 
237 static int
238 ice_get_eeprom(struct net_device *netdev, struct ethtool_eeprom *eeprom,
239 	       u8 *bytes)
240 {
241 	struct ice_netdev_priv *np = netdev_priv(netdev);
242 	u16 first_word, last_word, nwords;
243 	struct ice_vsi *vsi = np->vsi;
244 	struct ice_pf *pf = vsi->back;
245 	struct ice_hw *hw = &pf->hw;
246 	enum ice_status status;
247 	struct device *dev;
248 	int ret = 0;
249 	u16 *buf;
250 
251 	dev = &pf->pdev->dev;
252 
253 	eeprom->magic = hw->vendor_id | (hw->device_id << 16);
254 
255 	first_word = eeprom->offset >> 1;
256 	last_word = (eeprom->offset + eeprom->len - 1) >> 1;
257 	nwords = last_word - first_word + 1;
258 
259 	buf = devm_kcalloc(dev, nwords, sizeof(u16), GFP_KERNEL);
260 	if (!buf)
261 		return -ENOMEM;
262 
263 	status = ice_read_sr_buf(hw, first_word, &nwords, buf);
264 	if (status) {
265 		dev_err(dev, "ice_read_sr_buf failed, err %d aq_err %d\n",
266 			status, hw->adminq.sq_last_status);
267 		eeprom->len = sizeof(u16) * nwords;
268 		ret = -EIO;
269 		goto out;
270 	}
271 
272 	memcpy(bytes, (u8 *)buf + (eeprom->offset & 1), eeprom->len);
273 out:
274 	devm_kfree(dev, buf);
275 	return ret;
276 }
277 
278 /**
279  * ice_active_vfs - check if there are any active VFs
280  * @pf: board private structure
281  *
282  * Returns true if an active VF is found, otherwise returns false
283  */
284 static bool ice_active_vfs(struct ice_pf *pf)
285 {
286 	struct ice_vf *vf = pf->vf;
287 	int i;
288 
289 	for (i = 0; i < pf->num_alloc_vfs; i++, vf++)
290 		if (test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
291 			return true;
292 	return false;
293 }
294 
295 /**
296  * ice_link_test - perform a link test on a given net_device
297  * @netdev: network interface device structure
298  *
299  * This function performs one of the self-tests required by ethtool.
300  * Returns 0 on success, non-zero on failure.
301  */
302 static u64 ice_link_test(struct net_device *netdev)
303 {
304 	struct ice_netdev_priv *np = netdev_priv(netdev);
305 	enum ice_status status;
306 	bool link_up = false;
307 
308 	netdev_info(netdev, "link test\n");
309 	status = ice_get_link_status(np->vsi->port_info, &link_up);
310 	if (status) {
311 		netdev_err(netdev, "link query error, status = %d\n", status);
312 		return 1;
313 	}
314 
315 	if (!link_up)
316 		return 2;
317 
318 	return 0;
319 }
320 
321 /**
322  * ice_eeprom_test - perform an EEPROM test on a given net_device
323  * @netdev: network interface device structure
324  *
325  * This function performs one of the self-tests required by ethtool.
326  * Returns 0 on success, non-zero on failure.
327  */
328 static u64 ice_eeprom_test(struct net_device *netdev)
329 {
330 	struct ice_netdev_priv *np = netdev_priv(netdev);
331 	struct ice_pf *pf = np->vsi->back;
332 
333 	netdev_info(netdev, "EEPROM test\n");
334 	return !!(ice_nvm_validate_checksum(&pf->hw));
335 }
336 
337 /**
338  * ice_reg_pattern_test
339  * @hw: pointer to the HW struct
340  * @reg: reg to be tested
341  * @mask: bits to be touched
342  */
343 static int ice_reg_pattern_test(struct ice_hw *hw, u32 reg, u32 mask)
344 {
345 	struct ice_pf *pf = (struct ice_pf *)hw->back;
346 	static const u32 patterns[] = {
347 		0x5A5A5A5A, 0xA5A5A5A5,
348 		0x00000000, 0xFFFFFFFF
349 	};
350 	u32 val, orig_val;
351 	int i;
352 
353 	orig_val = rd32(hw, reg);
354 	for (i = 0; i < ARRAY_SIZE(patterns); ++i) {
355 		u32 pattern = patterns[i] & mask;
356 
357 		wr32(hw, reg, pattern);
358 		val = rd32(hw, reg);
359 		if (val == pattern)
360 			continue;
361 		dev_err(&pf->pdev->dev,
362 			"%s: reg pattern test failed - reg 0x%08x pat 0x%08x val 0x%08x\n"
363 			, __func__, reg, pattern, val);
364 		return 1;
365 	}
366 
367 	wr32(hw, reg, orig_val);
368 	val = rd32(hw, reg);
369 	if (val != orig_val) {
370 		dev_err(&pf->pdev->dev,
371 			"%s: reg restore test failed - reg 0x%08x orig 0x%08x val 0x%08x\n"
372 			, __func__, reg, orig_val, val);
373 		return 1;
374 	}
375 
376 	return 0;
377 }
378 
379 /**
380  * ice_reg_test - perform a register test on a given net_device
381  * @netdev: network interface device structure
382  *
383  * This function performs one of the self-tests required by ethtool.
384  * Returns 0 on success, non-zero on failure.
385  */
386 static u64 ice_reg_test(struct net_device *netdev)
387 {
388 	struct ice_netdev_priv *np = netdev_priv(netdev);
389 	struct ice_hw *hw = np->vsi->port_info->hw;
390 	u32 int_elements = hw->func_caps.common_cap.num_msix_vectors ?
391 		hw->func_caps.common_cap.num_msix_vectors - 1 : 1;
392 	struct ice_diag_reg_test_info {
393 		u32 address;
394 		u32 mask;
395 		u32 elem_num;
396 		u32 elem_size;
397 	} ice_reg_list[] = {
398 		{GLINT_ITR(0, 0), 0x00000fff, int_elements,
399 			GLINT_ITR(0, 1) - GLINT_ITR(0, 0)},
400 		{GLINT_ITR(1, 0), 0x00000fff, int_elements,
401 			GLINT_ITR(1, 1) - GLINT_ITR(1, 0)},
402 		{GLINT_ITR(0, 0), 0x00000fff, int_elements,
403 			GLINT_ITR(2, 1) - GLINT_ITR(2, 0)},
404 		{GLINT_CTL, 0xffff0001, 1, 0}
405 	};
406 	int i;
407 
408 	netdev_dbg(netdev, "Register test\n");
409 	for (i = 0; i < ARRAY_SIZE(ice_reg_list); ++i) {
410 		u32 j;
411 
412 		for (j = 0; j < ice_reg_list[i].elem_num; ++j) {
413 			u32 mask = ice_reg_list[i].mask;
414 			u32 reg = ice_reg_list[i].address +
415 				(j * ice_reg_list[i].elem_size);
416 
417 			/* bail on failure (non-zero return) */
418 			if (ice_reg_pattern_test(hw, reg, mask))
419 				return 1;
420 		}
421 	}
422 
423 	return 0;
424 }
425 
426 /**
427  * ice_lbtest_prepare_rings - configure Tx/Rx test rings
428  * @vsi: pointer to the VSI structure
429  *
430  * Function configures rings of a VSI for loopback test without
431  * enabling interrupts or informing the kernel about new queues.
432  *
433  * Returns 0 on success, negative on failure.
434  */
435 static int ice_lbtest_prepare_rings(struct ice_vsi *vsi)
436 {
437 	int status;
438 
439 	status = ice_vsi_setup_tx_rings(vsi);
440 	if (status)
441 		goto err_setup_tx_ring;
442 
443 	status = ice_vsi_setup_rx_rings(vsi);
444 	if (status)
445 		goto err_setup_rx_ring;
446 
447 	status = ice_vsi_cfg(vsi);
448 	if (status)
449 		goto err_setup_rx_ring;
450 
451 	status = ice_vsi_start_rx_rings(vsi);
452 	if (status)
453 		goto err_start_rx_ring;
454 
455 	return status;
456 
457 err_start_rx_ring:
458 	ice_vsi_free_rx_rings(vsi);
459 err_setup_rx_ring:
460 	ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
461 err_setup_tx_ring:
462 	ice_vsi_free_tx_rings(vsi);
463 
464 	return status;
465 }
466 
467 /**
468  * ice_lbtest_disable_rings - disable Tx/Rx test rings after loopback test
469  * @vsi: pointer to the VSI structure
470  *
471  * Function stops and frees VSI rings after a loopback test.
472  * Returns 0 on success, negative on failure.
473  */
474 static int ice_lbtest_disable_rings(struct ice_vsi *vsi)
475 {
476 	int status;
477 
478 	status = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
479 	if (status)
480 		netdev_err(vsi->netdev, "Failed to stop Tx rings, VSI %d error %d\n",
481 			   vsi->vsi_num, status);
482 
483 	status = ice_vsi_stop_rx_rings(vsi);
484 	if (status)
485 		netdev_err(vsi->netdev, "Failed to stop Rx rings, VSI %d error %d\n",
486 			   vsi->vsi_num, status);
487 
488 	ice_vsi_free_tx_rings(vsi);
489 	ice_vsi_free_rx_rings(vsi);
490 
491 	return status;
492 }
493 
494 /**
495  * ice_lbtest_create_frame - create test packet
496  * @pf: pointer to the PF structure
497  * @ret_data: allocated frame buffer
498  * @size: size of the packet data
499  *
500  * Function allocates a frame with a test pattern on specific offsets.
501  * Returns 0 on success, non-zero on failure.
502  */
503 static int ice_lbtest_create_frame(struct ice_pf *pf, u8 **ret_data, u16 size)
504 {
505 	u8 *data;
506 
507 	if (!pf)
508 		return -EINVAL;
509 
510 	data = devm_kzalloc(&pf->pdev->dev, size, GFP_KERNEL);
511 	if (!data)
512 		return -ENOMEM;
513 
514 	/* Since the ethernet test frame should always be at least
515 	 * 64 bytes long, fill some octets in the payload with test data.
516 	 */
517 	memset(data, 0xFF, size);
518 	data[32] = 0xDE;
519 	data[42] = 0xAD;
520 	data[44] = 0xBE;
521 	data[46] = 0xEF;
522 
523 	*ret_data = data;
524 
525 	return 0;
526 }
527 
528 /**
529  * ice_lbtest_check_frame - verify received loopback frame
530  * @frame: pointer to the raw packet data
531  *
532  * Function verifies received test frame with a pattern.
533  * Returns true if frame matches the pattern, false otherwise.
534  */
535 static bool ice_lbtest_check_frame(u8 *frame)
536 {
537 	/* Validate bytes of a frame under offsets chosen earlier */
538 	if (frame[32] == 0xDE &&
539 	    frame[42] == 0xAD &&
540 	    frame[44] == 0xBE &&
541 	    frame[46] == 0xEF &&
542 	    frame[48] == 0xFF)
543 		return true;
544 
545 	return false;
546 }
547 
548 /**
549  * ice_diag_send - send test frames to the test ring
550  * @tx_ring: pointer to the transmit ring
551  * @data: pointer to the raw packet data
552  * @size: size of the packet to send
553  *
554  * Function sends loopback packets on a test Tx ring.
555  */
556 static int ice_diag_send(struct ice_ring *tx_ring, u8 *data, u16 size)
557 {
558 	struct ice_tx_desc *tx_desc;
559 	struct ice_tx_buf *tx_buf;
560 	dma_addr_t dma;
561 	u64 td_cmd;
562 
563 	tx_desc = ICE_TX_DESC(tx_ring, tx_ring->next_to_use);
564 	tx_buf = &tx_ring->tx_buf[tx_ring->next_to_use];
565 
566 	dma = dma_map_single(tx_ring->dev, data, size, DMA_TO_DEVICE);
567 	if (dma_mapping_error(tx_ring->dev, dma))
568 		return -EINVAL;
569 
570 	tx_desc->buf_addr = cpu_to_le64(dma);
571 
572 	/* These flags are required for a descriptor to be pushed out */
573 	td_cmd = (u64)(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS);
574 	tx_desc->cmd_type_offset_bsz =
575 		cpu_to_le64(ICE_TX_DESC_DTYPE_DATA |
576 			    (td_cmd << ICE_TXD_QW1_CMD_S) |
577 			    ((u64)0 << ICE_TXD_QW1_OFFSET_S) |
578 			    ((u64)size << ICE_TXD_QW1_TX_BUF_SZ_S) |
579 			    ((u64)0 << ICE_TXD_QW1_L2TAG1_S));
580 
581 	tx_buf->next_to_watch = tx_desc;
582 
583 	/* Force memory write to complete before letting h/w know
584 	 * there are new descriptors to fetch.
585 	 */
586 	wmb();
587 
588 	tx_ring->next_to_use++;
589 	if (tx_ring->next_to_use >= tx_ring->count)
590 		tx_ring->next_to_use = 0;
591 
592 	writel_relaxed(tx_ring->next_to_use, tx_ring->tail);
593 
594 	/* Wait until the packets get transmitted to the receive queue. */
595 	usleep_range(1000, 2000);
596 	dma_unmap_single(tx_ring->dev, dma, size, DMA_TO_DEVICE);
597 
598 	return 0;
599 }
600 
601 #define ICE_LB_FRAME_SIZE 64
602 /**
603  * ice_lbtest_receive_frames - receive and verify test frames
604  * @rx_ring: pointer to the receive ring
605  *
606  * Function receives loopback packets and verify their correctness.
607  * Returns number of received valid frames.
608  */
609 static int ice_lbtest_receive_frames(struct ice_ring *rx_ring)
610 {
611 	struct ice_rx_buf *rx_buf;
612 	int valid_frames, i;
613 	u8 *received_buf;
614 
615 	valid_frames = 0;
616 
617 	for (i = 0; i < rx_ring->count; i++) {
618 		union ice_32b_rx_flex_desc *rx_desc;
619 
620 		rx_desc = ICE_RX_DESC(rx_ring, i);
621 
622 		if (!(rx_desc->wb.status_error0 &
623 		    cpu_to_le16(ICE_TX_DESC_CMD_EOP | ICE_TX_DESC_CMD_RS)))
624 			continue;
625 
626 		rx_buf = &rx_ring->rx_buf[i];
627 		received_buf = page_address(rx_buf->page) + rx_buf->page_offset;
628 
629 		if (ice_lbtest_check_frame(received_buf))
630 			valid_frames++;
631 	}
632 
633 	return valid_frames;
634 }
635 
636 /**
637  * ice_loopback_test - perform a loopback test on a given net_device
638  * @netdev: network interface device structure
639  *
640  * This function performs one of the self-tests required by ethtool.
641  * Returns 0 on success, non-zero on failure.
642  */
643 static u64 ice_loopback_test(struct net_device *netdev)
644 {
645 	struct ice_netdev_priv *np = netdev_priv(netdev);
646 	struct ice_vsi *orig_vsi = np->vsi, *test_vsi;
647 	struct ice_pf *pf = orig_vsi->back;
648 	struct ice_ring *tx_ring, *rx_ring;
649 	u8 broadcast[ETH_ALEN], ret = 0;
650 	int num_frames, valid_frames;
651 	LIST_HEAD(tmp_list);
652 	u8 *tx_frame;
653 	int i;
654 
655 	netdev_info(netdev, "loopback test\n");
656 
657 	test_vsi = ice_lb_vsi_setup(pf, pf->hw.port_info);
658 	if (!test_vsi) {
659 		netdev_err(netdev, "Failed to create a VSI for the loopback test");
660 		return 1;
661 	}
662 
663 	test_vsi->netdev = netdev;
664 	tx_ring = test_vsi->tx_rings[0];
665 	rx_ring = test_vsi->rx_rings[0];
666 
667 	if (ice_lbtest_prepare_rings(test_vsi)) {
668 		ret = 2;
669 		goto lbtest_vsi_close;
670 	}
671 
672 	if (ice_alloc_rx_bufs(rx_ring, rx_ring->count)) {
673 		ret = 3;
674 		goto lbtest_rings_dis;
675 	}
676 
677 	/* Enable MAC loopback in firmware */
678 	if (ice_aq_set_mac_loopback(&pf->hw, true, NULL)) {
679 		ret = 4;
680 		goto lbtest_mac_dis;
681 	}
682 
683 	/* Test VSI needs to receive broadcast packets */
684 	eth_broadcast_addr(broadcast);
685 	if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) {
686 		ret = 5;
687 		goto lbtest_mac_dis;
688 	}
689 
690 	if (ice_add_mac(&pf->hw, &tmp_list)) {
691 		ret = 6;
692 		goto free_mac_list;
693 	}
694 
695 	if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
696 		ret = 7;
697 		goto remove_mac_filters;
698 	}
699 
700 	num_frames = min_t(int, tx_ring->count, 32);
701 	for (i = 0; i < num_frames; i++) {
702 		if (ice_diag_send(tx_ring, tx_frame, ICE_LB_FRAME_SIZE)) {
703 			ret = 8;
704 			goto lbtest_free_frame;
705 		}
706 	}
707 
708 	valid_frames = ice_lbtest_receive_frames(rx_ring);
709 	if (!valid_frames)
710 		ret = 9;
711 	else if (valid_frames != num_frames)
712 		ret = 10;
713 
714 lbtest_free_frame:
715 	devm_kfree(&pf->pdev->dev, tx_frame);
716 remove_mac_filters:
717 	if (ice_remove_mac(&pf->hw, &tmp_list))
718 		netdev_err(netdev, "Could not remove MAC filter for the test VSI");
719 free_mac_list:
720 	ice_free_fltr_list(&pf->pdev->dev, &tmp_list);
721 lbtest_mac_dis:
722 	/* Disable MAC loopback after the test is completed. */
723 	if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
724 		netdev_err(netdev, "Could not disable MAC loopback\n");
725 lbtest_rings_dis:
726 	if (ice_lbtest_disable_rings(test_vsi))
727 		netdev_err(netdev, "Could not disable test rings\n");
728 lbtest_vsi_close:
729 	test_vsi->netdev = NULL;
730 	if (ice_vsi_release(test_vsi))
731 		netdev_err(netdev, "Failed to remove the test VSI");
732 
733 	return ret;
734 }
735 
736 /**
737  * ice_intr_test - perform an interrupt test on a given net_device
738  * @netdev: network interface device structure
739  *
740  * This function performs one of the self-tests required by ethtool.
741  * Returns 0 on success, non-zero on failure.
742  */
743 static u64 ice_intr_test(struct net_device *netdev)
744 {
745 	struct ice_netdev_priv *np = netdev_priv(netdev);
746 	struct ice_pf *pf = np->vsi->back;
747 	u16 swic_old = pf->sw_int_count;
748 
749 	netdev_info(netdev, "interrupt test\n");
750 
751 	wr32(&pf->hw, GLINT_DYN_CTL(pf->oicr_idx),
752 	     GLINT_DYN_CTL_SW_ITR_INDX_M |
753 	     GLINT_DYN_CTL_INTENA_MSK_M |
754 	     GLINT_DYN_CTL_SWINT_TRIG_M);
755 
756 	usleep_range(1000, 2000);
757 	return (swic_old == pf->sw_int_count);
758 }
759 
760 /**
761  * ice_self_test - handler function for performing a self-test by ethtool
762  * @netdev: network interface device structure
763  * @eth_test: ethtool_test structure
764  * @data: required by ethtool.self_test
765  *
766  * This function is called after invoking 'ethtool -t devname' command where
767  * devname is the name of the network device on which ethtool should operate.
768  * It performs a set of self-tests to check if a device works properly.
769  */
770 static void
771 ice_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
772 	      u64 *data)
773 {
774 	struct ice_netdev_priv *np = netdev_priv(netdev);
775 	bool if_running = netif_running(netdev);
776 	struct ice_pf *pf = np->vsi->back;
777 
778 	if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
779 		netdev_info(netdev, "offline testing starting\n");
780 
781 		set_bit(__ICE_TESTING, pf->state);
782 
783 		if (ice_active_vfs(pf)) {
784 			dev_warn(&pf->pdev->dev,
785 				 "Please take active VFs and Netqueues offline and restart the adapter before running NIC diagnostics\n");
786 			data[ICE_ETH_TEST_REG] = 1;
787 			data[ICE_ETH_TEST_EEPROM] = 1;
788 			data[ICE_ETH_TEST_INTR] = 1;
789 			data[ICE_ETH_TEST_LOOP] = 1;
790 			data[ICE_ETH_TEST_LINK] = 1;
791 			eth_test->flags |= ETH_TEST_FL_FAILED;
792 			clear_bit(__ICE_TESTING, pf->state);
793 			goto skip_ol_tests;
794 		}
795 		/* If the device is online then take it offline */
796 		if (if_running)
797 			/* indicate we're in test mode */
798 			ice_stop(netdev);
799 
800 		data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
801 		data[ICE_ETH_TEST_EEPROM] = ice_eeprom_test(netdev);
802 		data[ICE_ETH_TEST_INTR] = ice_intr_test(netdev);
803 		data[ICE_ETH_TEST_LOOP] = ice_loopback_test(netdev);
804 		data[ICE_ETH_TEST_REG] = ice_reg_test(netdev);
805 
806 		if (data[ICE_ETH_TEST_LINK] ||
807 		    data[ICE_ETH_TEST_EEPROM] ||
808 		    data[ICE_ETH_TEST_LOOP] ||
809 		    data[ICE_ETH_TEST_INTR] ||
810 		    data[ICE_ETH_TEST_REG])
811 			eth_test->flags |= ETH_TEST_FL_FAILED;
812 
813 		clear_bit(__ICE_TESTING, pf->state);
814 
815 		if (if_running) {
816 			int status = ice_open(netdev);
817 
818 			if (status) {
819 				dev_err(&pf->pdev->dev,
820 					"Could not open device %s, err %d",
821 					pf->int_name, status);
822 			}
823 		}
824 	} else {
825 		/* Online tests */
826 		netdev_info(netdev, "online testing starting\n");
827 
828 		data[ICE_ETH_TEST_LINK] = ice_link_test(netdev);
829 		if (data[ICE_ETH_TEST_LINK])
830 			eth_test->flags |= ETH_TEST_FL_FAILED;
831 
832 		/* Offline only tests, not run in online; pass by default */
833 		data[ICE_ETH_TEST_REG] = 0;
834 		data[ICE_ETH_TEST_EEPROM] = 0;
835 		data[ICE_ETH_TEST_INTR] = 0;
836 		data[ICE_ETH_TEST_LOOP] = 0;
837 	}
838 
839 skip_ol_tests:
840 	netdev_info(netdev, "testing finished\n");
841 }
842 
843 static void ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
844 {
845 	struct ice_netdev_priv *np = netdev_priv(netdev);
846 	struct ice_vsi *vsi = np->vsi;
847 	char *p = (char *)data;
848 	unsigned int i;
849 
850 	switch (stringset) {
851 	case ETH_SS_STATS:
852 		for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
853 			snprintf(p, ETH_GSTRING_LEN, "%s",
854 				 ice_gstrings_vsi_stats[i].stat_string);
855 			p += ETH_GSTRING_LEN;
856 		}
857 
858 		ice_for_each_alloc_txq(vsi, i) {
859 			snprintf(p, ETH_GSTRING_LEN,
860 				 "tx_queue_%u_packets", i);
861 			p += ETH_GSTRING_LEN;
862 			snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_bytes", i);
863 			p += ETH_GSTRING_LEN;
864 		}
865 
866 		ice_for_each_alloc_rxq(vsi, i) {
867 			snprintf(p, ETH_GSTRING_LEN,
868 				 "rx_queue_%u_packets", i);
869 			p += ETH_GSTRING_LEN;
870 			snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_bytes", i);
871 			p += ETH_GSTRING_LEN;
872 		}
873 
874 		if (vsi->type != ICE_VSI_PF)
875 			return;
876 
877 		for (i = 0; i < ICE_PF_STATS_LEN; i++) {
878 			snprintf(p, ETH_GSTRING_LEN, "%s",
879 				 ice_gstrings_pf_stats[i].stat_string);
880 			p += ETH_GSTRING_LEN;
881 		}
882 
883 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
884 			snprintf(p, ETH_GSTRING_LEN,
885 				 "tx_priority_%u_xon.nic", i);
886 			p += ETH_GSTRING_LEN;
887 			snprintf(p, ETH_GSTRING_LEN,
888 				 "tx_priority_%u_xoff.nic", i);
889 			p += ETH_GSTRING_LEN;
890 		}
891 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
892 			snprintf(p, ETH_GSTRING_LEN,
893 				 "rx_priority_%u_xon.nic", i);
894 			p += ETH_GSTRING_LEN;
895 			snprintf(p, ETH_GSTRING_LEN,
896 				 "rx_priority_%u_xoff.nic", i);
897 			p += ETH_GSTRING_LEN;
898 		}
899 		break;
900 	case ETH_SS_TEST:
901 		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
902 		break;
903 	case ETH_SS_PRIV_FLAGS:
904 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
905 			snprintf(p, ETH_GSTRING_LEN, "%s",
906 				 ice_gstrings_priv_flags[i].name);
907 			p += ETH_GSTRING_LEN;
908 		}
909 		break;
910 	default:
911 		break;
912 	}
913 }
914 
915 static int
916 ice_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
917 {
918 	struct ice_netdev_priv *np = netdev_priv(netdev);
919 	bool led_active;
920 
921 	switch (state) {
922 	case ETHTOOL_ID_ACTIVE:
923 		led_active = true;
924 		break;
925 	case ETHTOOL_ID_INACTIVE:
926 		led_active = false;
927 		break;
928 	default:
929 		return -EINVAL;
930 	}
931 
932 	if (ice_aq_set_port_id_led(np->vsi->port_info, !led_active, NULL))
933 		return -EIO;
934 
935 	return 0;
936 }
937 
938 /**
939  * ice_set_fec_cfg - Set link FEC options
940  * @netdev: network interface device structure
941  * @req_fec: FEC mode to configure
942  */
943 static int ice_set_fec_cfg(struct net_device *netdev, enum ice_fec_mode req_fec)
944 {
945 	struct ice_netdev_priv *np = netdev_priv(netdev);
946 	struct ice_aqc_set_phy_cfg_data config = { 0 };
947 	struct ice_aqc_get_phy_caps_data *caps;
948 	struct ice_vsi *vsi = np->vsi;
949 	u8 sw_cfg_caps, sw_cfg_fec;
950 	struct ice_port_info *pi;
951 	enum ice_status status;
952 	int err = 0;
953 
954 	pi = vsi->port_info;
955 	if (!pi)
956 		return -EOPNOTSUPP;
957 
958 	/* Changing the FEC parameters is not supported if not the PF VSI */
959 	if (vsi->type != ICE_VSI_PF) {
960 		netdev_info(netdev, "Changing FEC parameters only supported for PF VSI\n");
961 		return -EOPNOTSUPP;
962 	}
963 
964 	/* Get last SW configuration */
965 	caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
966 	if (!caps)
967 		return -ENOMEM;
968 
969 	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
970 				     caps, NULL);
971 	if (status) {
972 		err = -EAGAIN;
973 		goto done;
974 	}
975 
976 	/* Copy SW configuration returned from PHY caps to PHY config */
977 	ice_copy_phy_caps_to_cfg(caps, &config);
978 	sw_cfg_caps = caps->caps;
979 	sw_cfg_fec = caps->link_fec_options;
980 
981 	/* Get toloplogy caps, then copy PHY FEC topoloy caps to PHY config */
982 	memset(caps, 0, sizeof(*caps));
983 
984 	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
985 				     caps, NULL);
986 	if (status) {
987 		err = -EAGAIN;
988 		goto done;
989 	}
990 
991 	config.caps |= (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC);
992 	config.link_fec_opt = caps->link_fec_options;
993 
994 	ice_cfg_phy_fec(&config, req_fec);
995 
996 	/* If FEC mode has changed, then set PHY configuration and enable AN. */
997 	if ((config.caps & ICE_AQ_PHY_ENA_AUTO_FEC) !=
998 	    (sw_cfg_caps & ICE_AQC_PHY_EN_AUTO_FEC) ||
999 	    config.link_fec_opt != sw_cfg_fec) {
1000 		if (caps->caps & ICE_AQC_PHY_AN_MODE)
1001 			config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1002 
1003 		status = ice_aq_set_phy_cfg(pi->hw, pi->lport, &config, NULL);
1004 
1005 		if (status)
1006 			err = -EAGAIN;
1007 	}
1008 
1009 done:
1010 	devm_kfree(&vsi->back->pdev->dev, caps);
1011 	return err;
1012 }
1013 
1014 /**
1015  * ice_set_fecparam - Set FEC link options
1016  * @netdev: network interface device structure
1017  * @fecparam: Ethtool structure to retrieve FEC parameters
1018  */
1019 static int
1020 ice_set_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1021 {
1022 	struct ice_netdev_priv *np = netdev_priv(netdev);
1023 	struct ice_vsi *vsi = np->vsi;
1024 	enum ice_fec_mode fec;
1025 
1026 	switch (fecparam->fec) {
1027 	case ETHTOOL_FEC_AUTO:
1028 		fec = ICE_FEC_AUTO;
1029 		break;
1030 	case ETHTOOL_FEC_RS:
1031 		fec = ICE_FEC_RS;
1032 		break;
1033 	case ETHTOOL_FEC_BASER:
1034 		fec = ICE_FEC_BASER;
1035 		break;
1036 	case ETHTOOL_FEC_OFF:
1037 	case ETHTOOL_FEC_NONE:
1038 		fec = ICE_FEC_NONE;
1039 		break;
1040 	default:
1041 		dev_warn(&vsi->back->pdev->dev, "Unsupported FEC mode: %d\n",
1042 			 fecparam->fec);
1043 		return -EINVAL;
1044 	}
1045 
1046 	return ice_set_fec_cfg(netdev, fec);
1047 }
1048 
1049 /**
1050  * ice_get_fecparam - Get link FEC options
1051  * @netdev: network interface device structure
1052  * @fecparam: Ethtool structure to retrieve FEC parameters
1053  */
1054 static int
1055 ice_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam)
1056 {
1057 	struct ice_netdev_priv *np = netdev_priv(netdev);
1058 	struct ice_aqc_get_phy_caps_data *caps;
1059 	struct ice_link_status *link_info;
1060 	struct ice_vsi *vsi = np->vsi;
1061 	struct ice_port_info *pi;
1062 	enum ice_status status;
1063 	int err = 0;
1064 
1065 	pi = vsi->port_info;
1066 
1067 	if (!pi)
1068 		return -EOPNOTSUPP;
1069 	link_info = &pi->phy.link_info;
1070 
1071 	/* Set FEC mode based on negotiated link info */
1072 	switch (link_info->fec_info) {
1073 	case ICE_AQ_LINK_25G_KR_FEC_EN:
1074 		fecparam->active_fec = ETHTOOL_FEC_BASER;
1075 		break;
1076 	case ICE_AQ_LINK_25G_RS_528_FEC_EN:
1077 		/* fall through */
1078 	case ICE_AQ_LINK_25G_RS_544_FEC_EN:
1079 		fecparam->active_fec = ETHTOOL_FEC_RS;
1080 		break;
1081 	default:
1082 		fecparam->active_fec = ETHTOOL_FEC_OFF;
1083 		break;
1084 	}
1085 
1086 	caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
1087 	if (!caps)
1088 		return -ENOMEM;
1089 
1090 	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP,
1091 				     caps, NULL);
1092 	if (status) {
1093 		err = -EAGAIN;
1094 		goto done;
1095 	}
1096 
1097 	/* Set supported/configured FEC modes based on PHY capability */
1098 	if (caps->caps & ICE_AQC_PHY_EN_AUTO_FEC)
1099 		fecparam->fec |= ETHTOOL_FEC_AUTO;
1100 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
1101 	    caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
1102 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN ||
1103 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
1104 		fecparam->fec |= ETHTOOL_FEC_BASER;
1105 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
1106 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ ||
1107 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
1108 		fecparam->fec |= ETHTOOL_FEC_RS;
1109 	if (caps->link_fec_options == 0)
1110 		fecparam->fec |= ETHTOOL_FEC_OFF;
1111 
1112 done:
1113 	devm_kfree(&vsi->back->pdev->dev, caps);
1114 	return err;
1115 }
1116 
1117 /**
1118  * ice_get_priv_flags - report device private flags
1119  * @netdev: network interface device structure
1120  *
1121  * The get string set count and the string set should be matched for each
1122  * flag returned.  Add new strings for each flag to the ice_gstrings_priv_flags
1123  * array.
1124  *
1125  * Returns a u32 bitmap of flags.
1126  */
1127 static u32 ice_get_priv_flags(struct net_device *netdev)
1128 {
1129 	struct ice_netdev_priv *np = netdev_priv(netdev);
1130 	struct ice_vsi *vsi = np->vsi;
1131 	struct ice_pf *pf = vsi->back;
1132 	u32 i, ret_flags = 0;
1133 
1134 	for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1135 		const struct ice_priv_flag *priv_flag;
1136 
1137 		priv_flag = &ice_gstrings_priv_flags[i];
1138 
1139 		if (test_bit(priv_flag->bitno, pf->flags))
1140 			ret_flags |= BIT(i);
1141 	}
1142 
1143 	return ret_flags;
1144 }
1145 
1146 /**
1147  * ice_set_priv_flags - set private flags
1148  * @netdev: network interface device structure
1149  * @flags: bit flags to be set
1150  */
1151 static int ice_set_priv_flags(struct net_device *netdev, u32 flags)
1152 {
1153 	struct ice_netdev_priv *np = netdev_priv(netdev);
1154 	DECLARE_BITMAP(change_flags, ICE_PF_FLAGS_NBITS);
1155 	DECLARE_BITMAP(orig_flags, ICE_PF_FLAGS_NBITS);
1156 	struct ice_vsi *vsi = np->vsi;
1157 	struct ice_pf *pf = vsi->back;
1158 	int ret = 0;
1159 	u32 i;
1160 
1161 	if (flags > BIT(ICE_PRIV_FLAG_ARRAY_SIZE))
1162 		return -EINVAL;
1163 
1164 	set_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1165 
1166 	bitmap_copy(orig_flags, pf->flags, ICE_PF_FLAGS_NBITS);
1167 	for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++) {
1168 		const struct ice_priv_flag *priv_flag;
1169 
1170 		priv_flag = &ice_gstrings_priv_flags[i];
1171 
1172 		if (flags & BIT(i))
1173 			set_bit(priv_flag->bitno, pf->flags);
1174 		else
1175 			clear_bit(priv_flag->bitno, pf->flags);
1176 	}
1177 
1178 	bitmap_xor(change_flags, pf->flags, orig_flags, ICE_PF_FLAGS_NBITS);
1179 
1180 	if (test_bit(ICE_FLAG_FW_LLDP_AGENT, change_flags)) {
1181 		if (!test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags)) {
1182 			enum ice_status status;
1183 
1184 			/* Disable FW LLDP engine */
1185 			status = ice_cfg_lldp_mib_change(&pf->hw, false);
1186 
1187 			/* If unregistering for LLDP events fails, this is
1188 			 * not an error state, as there shouldn't be any
1189 			 * events to respond to.
1190 			 */
1191 			if (status)
1192 				dev_info(&pf->pdev->dev,
1193 					 "Failed to unreg for LLDP events\n");
1194 
1195 			/* The AQ call to stop the FW LLDP agent will generate
1196 			 * an error if the agent is already stopped.
1197 			 */
1198 			status = ice_aq_stop_lldp(&pf->hw, true, true, NULL);
1199 			if (status)
1200 				dev_warn(&pf->pdev->dev,
1201 					 "Fail to stop LLDP agent\n");
1202 			/* Use case for having the FW LLDP agent stopped
1203 			 * will likely not need DCB, so failure to init is
1204 			 * not a concern of ethtool
1205 			 */
1206 			status = ice_init_pf_dcb(pf, true);
1207 			if (status)
1208 				dev_warn(&pf->pdev->dev, "Fail to init DCB\n");
1209 		} else {
1210 			enum ice_status status;
1211 			bool dcbx_agent_status;
1212 
1213 			/* AQ command to start FW LLDP agent will return an
1214 			 * error if the agent is already started
1215 			 */
1216 			status = ice_aq_start_lldp(&pf->hw, true, NULL);
1217 			if (status)
1218 				dev_warn(&pf->pdev->dev,
1219 					 "Fail to start LLDP Agent\n");
1220 
1221 			/* AQ command to start FW DCBX agent will fail if
1222 			 * the agent is already started
1223 			 */
1224 			status = ice_aq_start_stop_dcbx(&pf->hw, true,
1225 							&dcbx_agent_status,
1226 							NULL);
1227 			if (status)
1228 				dev_dbg(&pf->pdev->dev,
1229 					"Failed to start FW DCBX\n");
1230 
1231 			dev_info(&pf->pdev->dev, "FW DCBX agent is %s\n",
1232 				 dcbx_agent_status ? "ACTIVE" : "DISABLED");
1233 
1234 			/* Failure to configure MIB change or init DCB is not
1235 			 * relevant to ethtool.  Print notification that
1236 			 * registration/init failed but do not return error
1237 			 * state to ethtool
1238 			 */
1239 			status = ice_init_pf_dcb(pf, true);
1240 			if (status)
1241 				dev_dbg(&pf->pdev->dev, "Fail to init DCB\n");
1242 
1243 			/* Remove rule to direct LLDP packets to default VSI.
1244 			 * The FW LLDP engine will now be consuming them.
1245 			 */
1246 			ice_cfg_sw_lldp(vsi, false, false);
1247 
1248 			/* Register for MIB change events */
1249 			status = ice_cfg_lldp_mib_change(&pf->hw, true);
1250 			if (status)
1251 				dev_dbg(&pf->pdev->dev,
1252 					"Fail to enable MIB change events\n");
1253 		}
1254 	}
1255 	if (test_bit(ICE_FLAG_LEGACY_RX, change_flags)) {
1256 		/* down and up VSI so that changes of Rx cfg are reflected. */
1257 		ice_down(vsi);
1258 		ice_up(vsi);
1259 	}
1260 	clear_bit(ICE_FLAG_ETHTOOL_CTXT, pf->flags);
1261 	return ret;
1262 }
1263 
1264 static int ice_get_sset_count(struct net_device *netdev, int sset)
1265 {
1266 	switch (sset) {
1267 	case ETH_SS_STATS:
1268 		/* The number (and order) of strings reported *must* remain
1269 		 * constant for a given netdevice. This function must not
1270 		 * report a different number based on run time parameters
1271 		 * (such as the number of queues in use, or the setting of
1272 		 * a private ethtool flag). This is due to the nature of the
1273 		 * ethtool stats API.
1274 		 *
1275 		 * Userspace programs such as ethtool must make 3 separate
1276 		 * ioctl requests, one for size, one for the strings, and
1277 		 * finally one for the stats. Since these cross into
1278 		 * userspace, changes to the number or size could result in
1279 		 * undefined memory access or incorrect string<->value
1280 		 * correlations for statistics.
1281 		 *
1282 		 * Even if it appears to be safe, changes to the size or
1283 		 * order of strings will suffer from race conditions and are
1284 		 * not safe.
1285 		 */
1286 		return ICE_ALL_STATS_LEN(netdev);
1287 	case ETH_SS_TEST:
1288 		return ICE_TEST_LEN;
1289 	case ETH_SS_PRIV_FLAGS:
1290 		return ICE_PRIV_FLAG_ARRAY_SIZE;
1291 	default:
1292 		return -EOPNOTSUPP;
1293 	}
1294 }
1295 
1296 static void
1297 ice_get_ethtool_stats(struct net_device *netdev,
1298 		      struct ethtool_stats __always_unused *stats, u64 *data)
1299 {
1300 	struct ice_netdev_priv *np = netdev_priv(netdev);
1301 	struct ice_vsi *vsi = np->vsi;
1302 	struct ice_pf *pf = vsi->back;
1303 	struct ice_ring *ring;
1304 	unsigned int j;
1305 	int i = 0;
1306 	char *p;
1307 
1308 	ice_update_pf_stats(pf);
1309 	ice_update_vsi_stats(vsi);
1310 
1311 	for (j = 0; j < ICE_VSI_STATS_LEN; j++) {
1312 		p = (char *)vsi + ice_gstrings_vsi_stats[j].stat_offset;
1313 		data[i++] = (ice_gstrings_vsi_stats[j].sizeof_stat ==
1314 			     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1315 	}
1316 
1317 	/* populate per queue stats */
1318 	rcu_read_lock();
1319 
1320 	ice_for_each_alloc_txq(vsi, j) {
1321 		ring = READ_ONCE(vsi->tx_rings[j]);
1322 		if (ring) {
1323 			data[i++] = ring->stats.pkts;
1324 			data[i++] = ring->stats.bytes;
1325 		} else {
1326 			data[i++] = 0;
1327 			data[i++] = 0;
1328 		}
1329 	}
1330 
1331 	ice_for_each_alloc_rxq(vsi, j) {
1332 		ring = READ_ONCE(vsi->rx_rings[j]);
1333 		if (ring) {
1334 			data[i++] = ring->stats.pkts;
1335 			data[i++] = ring->stats.bytes;
1336 		} else {
1337 			data[i++] = 0;
1338 			data[i++] = 0;
1339 		}
1340 	}
1341 
1342 	rcu_read_unlock();
1343 
1344 	if (vsi->type != ICE_VSI_PF)
1345 		return;
1346 
1347 	for (j = 0; j < ICE_PF_STATS_LEN; j++) {
1348 		p = (char *)pf + ice_gstrings_pf_stats[j].stat_offset;
1349 		data[i++] = (ice_gstrings_pf_stats[j].sizeof_stat ==
1350 			     sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
1351 	}
1352 
1353 	for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1354 		data[i++] = pf->stats.priority_xon_tx[j];
1355 		data[i++] = pf->stats.priority_xoff_tx[j];
1356 	}
1357 
1358 	for (j = 0; j < ICE_MAX_USER_PRIORITY; j++) {
1359 		data[i++] = pf->stats.priority_xon_rx[j];
1360 		data[i++] = pf->stats.priority_xoff_rx[j];
1361 	}
1362 }
1363 
1364 /**
1365  * ice_phy_type_to_ethtool - convert the phy_types to ethtool link modes
1366  * @netdev: network interface device structure
1367  * @ks: ethtool link ksettings struct to fill out
1368  */
1369 static void
1370 ice_phy_type_to_ethtool(struct net_device *netdev,
1371 			struct ethtool_link_ksettings *ks)
1372 {
1373 	struct ice_netdev_priv *np = netdev_priv(netdev);
1374 	struct ice_link_status *hw_link_info;
1375 	bool need_add_adv_mode = false;
1376 	struct ice_vsi *vsi = np->vsi;
1377 	u64 phy_types_high;
1378 	u64 phy_types_low;
1379 
1380 	hw_link_info = &vsi->port_info->phy.link_info;
1381 	phy_types_low = vsi->port_info->phy.phy_type_low;
1382 	phy_types_high = vsi->port_info->phy.phy_type_high;
1383 
1384 	ethtool_link_ksettings_zero_link_mode(ks, supported);
1385 	ethtool_link_ksettings_zero_link_mode(ks, advertising);
1386 
1387 	if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1388 	    phy_types_low & ICE_PHY_TYPE_LOW_100M_SGMII) {
1389 		ethtool_link_ksettings_add_link_mode(ks, supported,
1390 						     100baseT_Full);
1391 		if (!hw_link_info->req_speeds ||
1392 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100MB)
1393 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1394 							     100baseT_Full);
1395 	}
1396 	if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1397 	    phy_types_low & ICE_PHY_TYPE_LOW_1G_SGMII) {
1398 		ethtool_link_ksettings_add_link_mode(ks, supported,
1399 						     1000baseT_Full);
1400 		if (!hw_link_info->req_speeds ||
1401 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1402 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1403 							     1000baseT_Full);
1404 	}
1405 	if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX) {
1406 		ethtool_link_ksettings_add_link_mode(ks, supported,
1407 						     1000baseKX_Full);
1408 		if (!hw_link_info->req_speeds ||
1409 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1410 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1411 							     1000baseKX_Full);
1412 	}
1413 	if (phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_SX ||
1414 	    phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_LX) {
1415 		ethtool_link_ksettings_add_link_mode(ks, supported,
1416 						     1000baseX_Full);
1417 		if (!hw_link_info->req_speeds ||
1418 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_1000MB)
1419 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1420 							     1000baseX_Full);
1421 	}
1422 	if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T) {
1423 		ethtool_link_ksettings_add_link_mode(ks, supported,
1424 						     2500baseT_Full);
1425 		if (!hw_link_info->req_speeds ||
1426 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1427 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1428 							     2500baseT_Full);
1429 	}
1430 	if (phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_X ||
1431 	    phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX) {
1432 		ethtool_link_ksettings_add_link_mode(ks, supported,
1433 						     2500baseX_Full);
1434 		if (!hw_link_info->req_speeds ||
1435 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_2500MB)
1436 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1437 							     2500baseX_Full);
1438 	}
1439 	if (phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1440 	    phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR) {
1441 		ethtool_link_ksettings_add_link_mode(ks, supported,
1442 						     5000baseT_Full);
1443 		if (!hw_link_info->req_speeds ||
1444 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_5GB)
1445 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1446 							     5000baseT_Full);
1447 	}
1448 	if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1449 	    phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_DA ||
1450 	    phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC ||
1451 	    phy_types_low & ICE_PHY_TYPE_LOW_10G_SFI_C2C) {
1452 		ethtool_link_ksettings_add_link_mode(ks, supported,
1453 						     10000baseT_Full);
1454 		if (!hw_link_info->req_speeds ||
1455 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1456 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1457 							     10000baseT_Full);
1458 	}
1459 	if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1) {
1460 		ethtool_link_ksettings_add_link_mode(ks, supported,
1461 						     10000baseKR_Full);
1462 		if (!hw_link_info->req_speeds ||
1463 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1464 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1465 							     10000baseKR_Full);
1466 	}
1467 	if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_SR) {
1468 		ethtool_link_ksettings_add_link_mode(ks, supported,
1469 						     10000baseSR_Full);
1470 		if (!hw_link_info->req_speeds ||
1471 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1472 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1473 							     10000baseSR_Full);
1474 	}
1475 	if (phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_LR) {
1476 		ethtool_link_ksettings_add_link_mode(ks, supported,
1477 						     10000baseLR_Full);
1478 		if (!hw_link_info->req_speeds ||
1479 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_10GB)
1480 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1481 							     10000baseLR_Full);
1482 	}
1483 	if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1484 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1485 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1486 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1487 	    phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC ||
1488 	    phy_types_low & ICE_PHY_TYPE_LOW_25G_AUI_C2C) {
1489 		ethtool_link_ksettings_add_link_mode(ks, supported,
1490 						     25000baseCR_Full);
1491 		if (!hw_link_info->req_speeds ||
1492 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1493 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1494 							     25000baseCR_Full);
1495 	}
1496 	if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_SR ||
1497 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_LR) {
1498 		ethtool_link_ksettings_add_link_mode(ks, supported,
1499 						     25000baseSR_Full);
1500 		if (!hw_link_info->req_speeds ||
1501 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1502 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1503 							     25000baseSR_Full);
1504 	}
1505 	if (phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1506 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1507 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1) {
1508 		ethtool_link_ksettings_add_link_mode(ks, supported,
1509 						     25000baseKR_Full);
1510 		if (!hw_link_info->req_speeds ||
1511 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_25GB)
1512 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1513 							     25000baseKR_Full);
1514 	}
1515 	if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1516 		ethtool_link_ksettings_add_link_mode(ks, supported,
1517 						     40000baseKR4_Full);
1518 		if (!hw_link_info->req_speeds ||
1519 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1520 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1521 							     40000baseKR4_Full);
1522 	}
1523 	if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1524 	    phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC ||
1525 	    phy_types_low & ICE_PHY_TYPE_LOW_40G_XLAUI) {
1526 		ethtool_link_ksettings_add_link_mode(ks, supported,
1527 						     40000baseCR4_Full);
1528 		if (!hw_link_info->req_speeds ||
1529 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1530 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1531 							     40000baseCR4_Full);
1532 	}
1533 	if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_SR4) {
1534 		ethtool_link_ksettings_add_link_mode(ks, supported,
1535 						     40000baseSR4_Full);
1536 		if (!hw_link_info->req_speeds ||
1537 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1538 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1539 							     40000baseSR4_Full);
1540 	}
1541 	if (phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_LR4) {
1542 		ethtool_link_ksettings_add_link_mode(ks, supported,
1543 						     40000baseLR4_Full);
1544 		if (!hw_link_info->req_speeds ||
1545 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_40GB)
1546 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1547 							     40000baseLR4_Full);
1548 	}
1549 	if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1550 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC ||
1551 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_LAUI2 ||
1552 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC ||
1553 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI2 ||
1554 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1555 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR ||
1556 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC ||
1557 	    phy_types_low & ICE_PHY_TYPE_LOW_50G_AUI1) {
1558 		ethtool_link_ksettings_add_link_mode(ks, supported,
1559 						     50000baseCR2_Full);
1560 		if (!hw_link_info->req_speeds ||
1561 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1562 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1563 							     50000baseCR2_Full);
1564 	}
1565 	if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1566 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1567 		ethtool_link_ksettings_add_link_mode(ks, supported,
1568 						     50000baseKR2_Full);
1569 		if (!hw_link_info->req_speeds ||
1570 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1571 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1572 							     50000baseKR2_Full);
1573 	}
1574 	if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_SR2 ||
1575 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR2 ||
1576 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_FR ||
1577 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_LR) {
1578 		ethtool_link_ksettings_add_link_mode(ks, supported,
1579 						     50000baseSR2_Full);
1580 		if (!hw_link_info->req_speeds ||
1581 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_50GB)
1582 			ethtool_link_ksettings_add_link_mode(ks, advertising,
1583 							     50000baseSR2_Full);
1584 	}
1585 	if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1586 	    phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC ||
1587 	    phy_types_low & ICE_PHY_TYPE_LOW_100G_CAUI4 ||
1588 	    phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC ||
1589 	    phy_types_low & ICE_PHY_TYPE_LOW_100G_AUI4 ||
1590 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4 ||
1591 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2  ||
1592 	    phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC ||
1593 	    phy_types_high & ICE_PHY_TYPE_HIGH_100G_CAUI2 ||
1594 	    phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC ||
1595 	    phy_types_high & ICE_PHY_TYPE_HIGH_100G_AUI2) {
1596 		ethtool_link_ksettings_add_link_mode(ks, supported,
1597 						     100000baseCR4_Full);
1598 		if (!hw_link_info->req_speeds ||
1599 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1600 			need_add_adv_mode = true;
1601 	}
1602 	if (need_add_adv_mode) {
1603 		need_add_adv_mode = false;
1604 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1605 						     100000baseCR4_Full);
1606 	}
1607 	if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR4 ||
1608 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_SR2) {
1609 		ethtool_link_ksettings_add_link_mode(ks, supported,
1610 						     100000baseSR4_Full);
1611 		if (!hw_link_info->req_speeds ||
1612 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1613 			need_add_adv_mode = true;
1614 	}
1615 	if (need_add_adv_mode) {
1616 		need_add_adv_mode = false;
1617 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1618 						     100000baseSR4_Full);
1619 	}
1620 	if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_LR4 ||
1621 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_DR) {
1622 		ethtool_link_ksettings_add_link_mode(ks, supported,
1623 						     100000baseLR4_ER4_Full);
1624 		if (!hw_link_info->req_speeds ||
1625 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1626 			need_add_adv_mode = true;
1627 	}
1628 	if (need_add_adv_mode) {
1629 		need_add_adv_mode = false;
1630 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1631 						     100000baseLR4_ER4_Full);
1632 	}
1633 	if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1634 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1635 	    phy_types_high & ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4) {
1636 		ethtool_link_ksettings_add_link_mode(ks, supported,
1637 						     100000baseKR4_Full);
1638 		if (!hw_link_info->req_speeds ||
1639 		    hw_link_info->req_speeds & ICE_AQ_LINK_SPEED_100GB)
1640 			need_add_adv_mode = true;
1641 	}
1642 	if (need_add_adv_mode)
1643 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1644 						     100000baseKR4_Full);
1645 
1646 	/* Autoneg PHY types */
1647 	if (phy_types_low & ICE_PHY_TYPE_LOW_100BASE_TX ||
1648 	    phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_T ||
1649 	    phy_types_low & ICE_PHY_TYPE_LOW_1000BASE_KX ||
1650 	    phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_T ||
1651 	    phy_types_low & ICE_PHY_TYPE_LOW_2500BASE_KX ||
1652 	    phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_T ||
1653 	    phy_types_low & ICE_PHY_TYPE_LOW_5GBASE_KR ||
1654 	    phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_T ||
1655 	    phy_types_low & ICE_PHY_TYPE_LOW_10GBASE_KR_CR1 ||
1656 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_T ||
1657 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR ||
1658 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR_S ||
1659 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_CR1 ||
1660 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR ||
1661 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR_S ||
1662 	    phy_types_low & ICE_PHY_TYPE_LOW_25GBASE_KR1 ||
1663 	    phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_CR4 ||
1664 	    phy_types_low & ICE_PHY_TYPE_LOW_40GBASE_KR4) {
1665 		ethtool_link_ksettings_add_link_mode(ks, supported,
1666 						     Autoneg);
1667 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1668 						     Autoneg);
1669 	}
1670 	if (phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CR2 ||
1671 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR2 ||
1672 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_CP ||
1673 	    phy_types_low & ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4) {
1674 		ethtool_link_ksettings_add_link_mode(ks, supported,
1675 						     Autoneg);
1676 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1677 						     Autoneg);
1678 	}
1679 	if (phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CR4 ||
1680 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR4 ||
1681 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4 ||
1682 	    phy_types_low & ICE_PHY_TYPE_LOW_100GBASE_CP2) {
1683 		ethtool_link_ksettings_add_link_mode(ks, supported,
1684 						     Autoneg);
1685 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1686 						     Autoneg);
1687 	}
1688 }
1689 
1690 #define TEST_SET_BITS_TIMEOUT	50
1691 #define TEST_SET_BITS_SLEEP_MAX	2000
1692 #define TEST_SET_BITS_SLEEP_MIN	1000
1693 
1694 /**
1695  * ice_get_settings_link_up - Get Link settings for when link is up
1696  * @ks: ethtool ksettings to fill in
1697  * @netdev: network interface device structure
1698  */
1699 static void
1700 ice_get_settings_link_up(struct ethtool_link_ksettings *ks,
1701 			 struct net_device *netdev)
1702 {
1703 	struct ice_netdev_priv *np = netdev_priv(netdev);
1704 	struct ice_port_info *pi = np->vsi->port_info;
1705 	struct ethtool_link_ksettings cap_ksettings;
1706 	struct ice_link_status *link_info;
1707 	struct ice_vsi *vsi = np->vsi;
1708 	bool unrecog_phy_high = false;
1709 	bool unrecog_phy_low = false;
1710 
1711 	link_info = &vsi->port_info->phy.link_info;
1712 
1713 	/* Initialize supported and advertised settings based on PHY settings */
1714 	switch (link_info->phy_type_low) {
1715 	case ICE_PHY_TYPE_LOW_100BASE_TX:
1716 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1717 		ethtool_link_ksettings_add_link_mode(ks, supported,
1718 						     100baseT_Full);
1719 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1720 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1721 						     100baseT_Full);
1722 		break;
1723 	case ICE_PHY_TYPE_LOW_100M_SGMII:
1724 		ethtool_link_ksettings_add_link_mode(ks, supported,
1725 						     100baseT_Full);
1726 		break;
1727 	case ICE_PHY_TYPE_LOW_1000BASE_T:
1728 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1729 		ethtool_link_ksettings_add_link_mode(ks, supported,
1730 						     1000baseT_Full);
1731 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1732 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1733 						     1000baseT_Full);
1734 		break;
1735 	case ICE_PHY_TYPE_LOW_1G_SGMII:
1736 		ethtool_link_ksettings_add_link_mode(ks, supported,
1737 						     1000baseT_Full);
1738 		break;
1739 	case ICE_PHY_TYPE_LOW_1000BASE_SX:
1740 	case ICE_PHY_TYPE_LOW_1000BASE_LX:
1741 		ethtool_link_ksettings_add_link_mode(ks, supported,
1742 						     1000baseX_Full);
1743 		break;
1744 	case ICE_PHY_TYPE_LOW_1000BASE_KX:
1745 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1746 		ethtool_link_ksettings_add_link_mode(ks, supported,
1747 						     1000baseKX_Full);
1748 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1749 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1750 						     1000baseKX_Full);
1751 		break;
1752 	case ICE_PHY_TYPE_LOW_2500BASE_T:
1753 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1754 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1755 		ethtool_link_ksettings_add_link_mode(ks, supported,
1756 						     2500baseT_Full);
1757 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1758 						     2500baseT_Full);
1759 		break;
1760 	case ICE_PHY_TYPE_LOW_2500BASE_X:
1761 		ethtool_link_ksettings_add_link_mode(ks, supported,
1762 						     2500baseX_Full);
1763 		break;
1764 	case ICE_PHY_TYPE_LOW_2500BASE_KX:
1765 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1766 		ethtool_link_ksettings_add_link_mode(ks, supported,
1767 						     2500baseX_Full);
1768 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1769 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1770 						     2500baseX_Full);
1771 		break;
1772 	case ICE_PHY_TYPE_LOW_5GBASE_T:
1773 	case ICE_PHY_TYPE_LOW_5GBASE_KR:
1774 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1775 		ethtool_link_ksettings_add_link_mode(ks, supported,
1776 						     5000baseT_Full);
1777 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1778 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1779 						     5000baseT_Full);
1780 		break;
1781 	case ICE_PHY_TYPE_LOW_10GBASE_T:
1782 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1783 		ethtool_link_ksettings_add_link_mode(ks, supported,
1784 						     10000baseT_Full);
1785 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1786 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1787 						     10000baseT_Full);
1788 		break;
1789 	case ICE_PHY_TYPE_LOW_10G_SFI_DA:
1790 	case ICE_PHY_TYPE_LOW_10G_SFI_AOC_ACC:
1791 	case ICE_PHY_TYPE_LOW_10G_SFI_C2C:
1792 		ethtool_link_ksettings_add_link_mode(ks, supported,
1793 						     10000baseT_Full);
1794 		break;
1795 	case ICE_PHY_TYPE_LOW_10GBASE_SR:
1796 		ethtool_link_ksettings_add_link_mode(ks, supported,
1797 						     10000baseSR_Full);
1798 		break;
1799 	case ICE_PHY_TYPE_LOW_10GBASE_LR:
1800 		ethtool_link_ksettings_add_link_mode(ks, supported,
1801 						     10000baseLR_Full);
1802 		break;
1803 	case ICE_PHY_TYPE_LOW_10GBASE_KR_CR1:
1804 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1805 		ethtool_link_ksettings_add_link_mode(ks, supported,
1806 						     10000baseKR_Full);
1807 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1808 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1809 						     10000baseKR_Full);
1810 		break;
1811 	case ICE_PHY_TYPE_LOW_25GBASE_T:
1812 	case ICE_PHY_TYPE_LOW_25GBASE_CR:
1813 	case ICE_PHY_TYPE_LOW_25GBASE_CR_S:
1814 	case ICE_PHY_TYPE_LOW_25GBASE_CR1:
1815 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1816 		ethtool_link_ksettings_add_link_mode(ks, supported,
1817 						     25000baseCR_Full);
1818 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1819 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1820 						     25000baseCR_Full);
1821 		break;
1822 	case ICE_PHY_TYPE_LOW_25G_AUI_AOC_ACC:
1823 	case ICE_PHY_TYPE_LOW_25G_AUI_C2C:
1824 		ethtool_link_ksettings_add_link_mode(ks, supported,
1825 						     25000baseCR_Full);
1826 		break;
1827 	case ICE_PHY_TYPE_LOW_25GBASE_SR:
1828 	case ICE_PHY_TYPE_LOW_25GBASE_LR:
1829 		ethtool_link_ksettings_add_link_mode(ks, supported,
1830 						     25000baseSR_Full);
1831 		break;
1832 	case ICE_PHY_TYPE_LOW_25GBASE_KR:
1833 	case ICE_PHY_TYPE_LOW_25GBASE_KR1:
1834 	case ICE_PHY_TYPE_LOW_25GBASE_KR_S:
1835 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1836 		ethtool_link_ksettings_add_link_mode(ks, supported,
1837 						     25000baseKR_Full);
1838 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1839 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1840 						     25000baseKR_Full);
1841 		break;
1842 	case ICE_PHY_TYPE_LOW_40GBASE_CR4:
1843 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1844 		ethtool_link_ksettings_add_link_mode(ks, supported,
1845 						     40000baseCR4_Full);
1846 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1847 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1848 						     40000baseCR4_Full);
1849 		break;
1850 	case ICE_PHY_TYPE_LOW_40G_XLAUI_AOC_ACC:
1851 	case ICE_PHY_TYPE_LOW_40G_XLAUI:
1852 		ethtool_link_ksettings_add_link_mode(ks, supported,
1853 						     40000baseCR4_Full);
1854 		break;
1855 	case ICE_PHY_TYPE_LOW_40GBASE_SR4:
1856 		ethtool_link_ksettings_add_link_mode(ks, supported,
1857 						     40000baseSR4_Full);
1858 		break;
1859 	case ICE_PHY_TYPE_LOW_40GBASE_LR4:
1860 		ethtool_link_ksettings_add_link_mode(ks, supported,
1861 						     40000baseLR4_Full);
1862 		break;
1863 	case ICE_PHY_TYPE_LOW_40GBASE_KR4:
1864 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1865 		ethtool_link_ksettings_add_link_mode(ks, supported,
1866 						     40000baseKR4_Full);
1867 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1868 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1869 						     40000baseKR4_Full);
1870 		break;
1871 	case ICE_PHY_TYPE_LOW_50GBASE_CR2:
1872 	case ICE_PHY_TYPE_LOW_50GBASE_CP:
1873 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1874 		ethtool_link_ksettings_add_link_mode(ks, supported,
1875 						     50000baseCR2_Full);
1876 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1877 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1878 						     50000baseCR2_Full);
1879 		break;
1880 	case ICE_PHY_TYPE_LOW_50G_LAUI2_AOC_ACC:
1881 	case ICE_PHY_TYPE_LOW_50G_LAUI2:
1882 	case ICE_PHY_TYPE_LOW_50G_AUI2_AOC_ACC:
1883 	case ICE_PHY_TYPE_LOW_50G_AUI2:
1884 	case ICE_PHY_TYPE_LOW_50GBASE_SR:
1885 	case ICE_PHY_TYPE_LOW_50G_AUI1_AOC_ACC:
1886 	case ICE_PHY_TYPE_LOW_50G_AUI1:
1887 		ethtool_link_ksettings_add_link_mode(ks, supported,
1888 						     50000baseCR2_Full);
1889 		break;
1890 	case ICE_PHY_TYPE_LOW_50GBASE_KR2:
1891 	case ICE_PHY_TYPE_LOW_50GBASE_KR_PAM4:
1892 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1893 		ethtool_link_ksettings_add_link_mode(ks, supported,
1894 						     50000baseKR2_Full);
1895 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1896 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1897 						     50000baseKR2_Full);
1898 		break;
1899 	case ICE_PHY_TYPE_LOW_50GBASE_SR2:
1900 	case ICE_PHY_TYPE_LOW_50GBASE_LR2:
1901 	case ICE_PHY_TYPE_LOW_50GBASE_FR:
1902 	case ICE_PHY_TYPE_LOW_50GBASE_LR:
1903 		ethtool_link_ksettings_add_link_mode(ks, supported,
1904 						     50000baseSR2_Full);
1905 		break;
1906 	case ICE_PHY_TYPE_LOW_100GBASE_CR4:
1907 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1908 		ethtool_link_ksettings_add_link_mode(ks, supported,
1909 						     100000baseCR4_Full);
1910 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1911 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1912 						     100000baseCR4_Full);
1913 		break;
1914 	case ICE_PHY_TYPE_LOW_100G_CAUI4_AOC_ACC:
1915 	case ICE_PHY_TYPE_LOW_100G_CAUI4:
1916 	case ICE_PHY_TYPE_LOW_100G_AUI4_AOC_ACC:
1917 	case ICE_PHY_TYPE_LOW_100G_AUI4:
1918 	case ICE_PHY_TYPE_LOW_100GBASE_CR_PAM4:
1919 		ethtool_link_ksettings_add_link_mode(ks, supported,
1920 						     100000baseCR4_Full);
1921 		break;
1922 	case ICE_PHY_TYPE_LOW_100GBASE_CP2:
1923 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1924 		ethtool_link_ksettings_add_link_mode(ks, supported,
1925 						     100000baseCR4_Full);
1926 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1927 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1928 						     100000baseCR4_Full);
1929 		break;
1930 	case ICE_PHY_TYPE_LOW_100GBASE_SR4:
1931 	case ICE_PHY_TYPE_LOW_100GBASE_SR2:
1932 		ethtool_link_ksettings_add_link_mode(ks, supported,
1933 						     100000baseSR4_Full);
1934 		break;
1935 	case ICE_PHY_TYPE_LOW_100GBASE_LR4:
1936 	case ICE_PHY_TYPE_LOW_100GBASE_DR:
1937 		ethtool_link_ksettings_add_link_mode(ks, supported,
1938 						     100000baseLR4_ER4_Full);
1939 		break;
1940 	case ICE_PHY_TYPE_LOW_100GBASE_KR4:
1941 	case ICE_PHY_TYPE_LOW_100GBASE_KR_PAM4:
1942 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1943 		ethtool_link_ksettings_add_link_mode(ks, supported,
1944 						     100000baseKR4_Full);
1945 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1946 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1947 						     100000baseKR4_Full);
1948 		break;
1949 	default:
1950 		unrecog_phy_low = true;
1951 	}
1952 
1953 	switch (link_info->phy_type_high) {
1954 	case ICE_PHY_TYPE_HIGH_100GBASE_KR2_PAM4:
1955 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
1956 		ethtool_link_ksettings_add_link_mode(ks, supported,
1957 						     100000baseKR4_Full);
1958 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
1959 		ethtool_link_ksettings_add_link_mode(ks, advertising,
1960 						     100000baseKR4_Full);
1961 		break;
1962 	case ICE_PHY_TYPE_HIGH_100G_CAUI2_AOC_ACC:
1963 	case ICE_PHY_TYPE_HIGH_100G_CAUI2:
1964 	case ICE_PHY_TYPE_HIGH_100G_AUI2_AOC_ACC:
1965 	case ICE_PHY_TYPE_HIGH_100G_AUI2:
1966 		ethtool_link_ksettings_add_link_mode(ks, supported,
1967 						     100000baseCR4_Full);
1968 		break;
1969 	default:
1970 		unrecog_phy_high = true;
1971 	}
1972 
1973 	if (unrecog_phy_low && unrecog_phy_high) {
1974 		/* if we got here and link is up something bad is afoot */
1975 		netdev_info(netdev,
1976 			    "WARNING: Unrecognized PHY_Low (0x%llx).\n",
1977 			    (u64)link_info->phy_type_low);
1978 		netdev_info(netdev,
1979 			    "WARNING: Unrecognized PHY_High (0x%llx).\n",
1980 			    (u64)link_info->phy_type_high);
1981 	}
1982 
1983 	/* Now that we've worked out everything that could be supported by the
1984 	 * current PHY type, get what is supported by the NVM and intersect
1985 	 * them to get what is truly supported
1986 	 */
1987 	memset(&cap_ksettings, 0, sizeof(cap_ksettings));
1988 	ice_phy_type_to_ethtool(netdev, &cap_ksettings);
1989 	ethtool_intersect_link_masks(ks, &cap_ksettings);
1990 
1991 	switch (link_info->link_speed) {
1992 	case ICE_AQ_LINK_SPEED_100GB:
1993 		ks->base.speed = SPEED_100000;
1994 		break;
1995 	case ICE_AQ_LINK_SPEED_50GB:
1996 		ks->base.speed = SPEED_50000;
1997 		break;
1998 	case ICE_AQ_LINK_SPEED_40GB:
1999 		ks->base.speed = SPEED_40000;
2000 		break;
2001 	case ICE_AQ_LINK_SPEED_25GB:
2002 		ks->base.speed = SPEED_25000;
2003 		break;
2004 	case ICE_AQ_LINK_SPEED_20GB:
2005 		ks->base.speed = SPEED_20000;
2006 		break;
2007 	case ICE_AQ_LINK_SPEED_10GB:
2008 		ks->base.speed = SPEED_10000;
2009 		break;
2010 	case ICE_AQ_LINK_SPEED_5GB:
2011 		ks->base.speed = SPEED_5000;
2012 		break;
2013 	case ICE_AQ_LINK_SPEED_2500MB:
2014 		ks->base.speed = SPEED_2500;
2015 		break;
2016 	case ICE_AQ_LINK_SPEED_1000MB:
2017 		ks->base.speed = SPEED_1000;
2018 		break;
2019 	case ICE_AQ_LINK_SPEED_100MB:
2020 		ks->base.speed = SPEED_100;
2021 		break;
2022 	default:
2023 		netdev_info(netdev,
2024 			    "WARNING: Unrecognized link_speed (0x%x).\n",
2025 			    link_info->link_speed);
2026 		break;
2027 	}
2028 	ks->base.duplex = DUPLEX_FULL;
2029 
2030 	if (link_info->an_info & ICE_AQ_AN_COMPLETED)
2031 		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2032 						     Autoneg);
2033 
2034 	/* Set flow control negotiated Rx/Tx pause */
2035 	switch (pi->fc.current_mode) {
2036 	case ICE_FC_FULL:
2037 		ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2038 		break;
2039 	case ICE_FC_TX_PAUSE:
2040 		ethtool_link_ksettings_add_link_mode(ks, lp_advertising, Pause);
2041 		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2042 						     Asym_Pause);
2043 		break;
2044 	case ICE_FC_RX_PAUSE:
2045 		ethtool_link_ksettings_add_link_mode(ks, lp_advertising,
2046 						     Asym_Pause);
2047 		break;
2048 	case ICE_FC_PFC:
2049 		/* fall through */
2050 	default:
2051 		ethtool_link_ksettings_del_link_mode(ks, lp_advertising, Pause);
2052 		ethtool_link_ksettings_del_link_mode(ks, lp_advertising,
2053 						     Asym_Pause);
2054 		break;
2055 	}
2056 }
2057 
2058 /**
2059  * ice_get_settings_link_down - Get the Link settings when link is down
2060  * @ks: ethtool ksettings to fill in
2061  * @netdev: network interface device structure
2062  *
2063  * Reports link settings that can be determined when link is down
2064  */
2065 static void
2066 ice_get_settings_link_down(struct ethtool_link_ksettings *ks,
2067 			   struct net_device *netdev)
2068 {
2069 	/* link is down and the driver needs to fall back on
2070 	 * supported PHY types to figure out what info to display
2071 	 */
2072 	ice_phy_type_to_ethtool(netdev, ks);
2073 
2074 	/* With no link, speed and duplex are unknown */
2075 	ks->base.speed = SPEED_UNKNOWN;
2076 	ks->base.duplex = DUPLEX_UNKNOWN;
2077 }
2078 
2079 /**
2080  * ice_get_link_ksettings - Get Link Speed and Duplex settings
2081  * @netdev: network interface device structure
2082  * @ks: ethtool ksettings
2083  *
2084  * Reports speed/duplex settings based on media_type
2085  */
2086 static int
2087 ice_get_link_ksettings(struct net_device *netdev,
2088 		       struct ethtool_link_ksettings *ks)
2089 {
2090 	struct ice_netdev_priv *np = netdev_priv(netdev);
2091 	struct ice_aqc_get_phy_caps_data *caps;
2092 	struct ice_link_status *hw_link_info;
2093 	struct ice_vsi *vsi = np->vsi;
2094 	enum ice_status status;
2095 	int err = 0;
2096 
2097 	ethtool_link_ksettings_zero_link_mode(ks, supported);
2098 	ethtool_link_ksettings_zero_link_mode(ks, advertising);
2099 	ethtool_link_ksettings_zero_link_mode(ks, lp_advertising);
2100 	hw_link_info = &vsi->port_info->phy.link_info;
2101 
2102 	/* set speed and duplex */
2103 	if (hw_link_info->link_info & ICE_AQ_LINK_UP)
2104 		ice_get_settings_link_up(ks, netdev);
2105 	else
2106 		ice_get_settings_link_down(ks, netdev);
2107 
2108 	/* set autoneg settings */
2109 	ks->base.autoneg = (hw_link_info->an_info & ICE_AQ_AN_COMPLETED) ?
2110 		AUTONEG_ENABLE : AUTONEG_DISABLE;
2111 
2112 	/* set media type settings */
2113 	switch (vsi->port_info->phy.media_type) {
2114 	case ICE_MEDIA_FIBER:
2115 		ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2116 		ks->base.port = PORT_FIBRE;
2117 		break;
2118 	case ICE_MEDIA_BASET:
2119 		ethtool_link_ksettings_add_link_mode(ks, supported, TP);
2120 		ethtool_link_ksettings_add_link_mode(ks, advertising, TP);
2121 		ks->base.port = PORT_TP;
2122 		break;
2123 	case ICE_MEDIA_BACKPLANE:
2124 		ethtool_link_ksettings_add_link_mode(ks, supported, Autoneg);
2125 		ethtool_link_ksettings_add_link_mode(ks, supported, Backplane);
2126 		ethtool_link_ksettings_add_link_mode(ks, advertising, Autoneg);
2127 		ethtool_link_ksettings_add_link_mode(ks, advertising,
2128 						     Backplane);
2129 		ks->base.port = PORT_NONE;
2130 		break;
2131 	case ICE_MEDIA_DA:
2132 		ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);
2133 		ethtool_link_ksettings_add_link_mode(ks, advertising, FIBRE);
2134 		ks->base.port = PORT_DA;
2135 		break;
2136 	default:
2137 		ks->base.port = PORT_OTHER;
2138 		break;
2139 	}
2140 
2141 	/* flow control is symmetric and always supported */
2142 	ethtool_link_ksettings_add_link_mode(ks, supported, Pause);
2143 
2144 	caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
2145 	if (!caps)
2146 		return -ENOMEM;
2147 
2148 	status = ice_aq_get_phy_caps(vsi->port_info, false,
2149 				     ICE_AQC_REPORT_SW_CFG, caps, NULL);
2150 	if (status) {
2151 		err = -EIO;
2152 		goto done;
2153 	}
2154 
2155 	/* Set the advertised flow control based on the PHY capability */
2156 	if ((caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) &&
2157 	    (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)) {
2158 		ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2159 		ethtool_link_ksettings_add_link_mode(ks, advertising,
2160 						     Asym_Pause);
2161 	} else if (caps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE) {
2162 		ethtool_link_ksettings_add_link_mode(ks, advertising,
2163 						     Asym_Pause);
2164 	} else if (caps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE) {
2165 		ethtool_link_ksettings_add_link_mode(ks, advertising, Pause);
2166 		ethtool_link_ksettings_add_link_mode(ks, advertising,
2167 						     Asym_Pause);
2168 	} else {
2169 		ethtool_link_ksettings_del_link_mode(ks, advertising, Pause);
2170 		ethtool_link_ksettings_del_link_mode(ks, advertising,
2171 						     Asym_Pause);
2172 	}
2173 
2174 	/* Set advertised FEC modes based on PHY capability */
2175 	ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
2176 
2177 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
2178 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
2179 		ethtool_link_ksettings_add_link_mode(ks, advertising,
2180 						     FEC_BASER);
2181 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
2182 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
2183 		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
2184 
2185 	status = ice_aq_get_phy_caps(vsi->port_info, false,
2186 				     ICE_AQC_REPORT_TOPO_CAP, caps, NULL);
2187 	if (status) {
2188 		err = -EIO;
2189 		goto done;
2190 	}
2191 
2192 	/* Set supported FEC modes based on PHY capability */
2193 	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
2194 
2195 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_EN ||
2196 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_CLAUSE74_EN)
2197 		ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
2198 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_CLAUSE91_EN)
2199 		ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
2200 
2201 done:
2202 	devm_kfree(&vsi->back->pdev->dev, caps);
2203 	return err;
2204 }
2205 
2206 /**
2207  * ice_ksettings_find_adv_link_speed - Find advertising link speed
2208  * @ks: ethtool ksettings
2209  */
2210 static u16
2211 ice_ksettings_find_adv_link_speed(const struct ethtool_link_ksettings *ks)
2212 {
2213 	u16 adv_link_speed = 0;
2214 
2215 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2216 						  100baseT_Full))
2217 		adv_link_speed |= ICE_AQ_LINK_SPEED_100MB;
2218 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2219 						  1000baseX_Full))
2220 		adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2221 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2222 						  1000baseT_Full) ||
2223 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2224 						  1000baseKX_Full))
2225 		adv_link_speed |= ICE_AQ_LINK_SPEED_1000MB;
2226 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2227 						  2500baseT_Full))
2228 		adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2229 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2230 						  2500baseX_Full))
2231 		adv_link_speed |= ICE_AQ_LINK_SPEED_2500MB;
2232 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2233 						  5000baseT_Full))
2234 		adv_link_speed |= ICE_AQ_LINK_SPEED_5GB;
2235 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2236 						  10000baseT_Full) ||
2237 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2238 						  10000baseKR_Full))
2239 		adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2240 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2241 						  10000baseSR_Full) ||
2242 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2243 						  10000baseLR_Full))
2244 		adv_link_speed |= ICE_AQ_LINK_SPEED_10GB;
2245 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2246 						  25000baseCR_Full) ||
2247 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2248 						  25000baseSR_Full) ||
2249 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2250 						  25000baseKR_Full))
2251 		adv_link_speed |= ICE_AQ_LINK_SPEED_25GB;
2252 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2253 						  40000baseCR4_Full) ||
2254 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2255 						  40000baseSR4_Full) ||
2256 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2257 						  40000baseLR4_Full) ||
2258 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2259 						  40000baseKR4_Full))
2260 		adv_link_speed |= ICE_AQ_LINK_SPEED_40GB;
2261 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2262 						  50000baseCR2_Full) ||
2263 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2264 						  50000baseKR2_Full))
2265 		adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2266 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2267 						  50000baseSR2_Full))
2268 		adv_link_speed |= ICE_AQ_LINK_SPEED_50GB;
2269 	if (ethtool_link_ksettings_test_link_mode(ks, advertising,
2270 						  100000baseCR4_Full) ||
2271 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2272 						  100000baseSR4_Full) ||
2273 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2274 						  100000baseLR4_ER4_Full) ||
2275 	    ethtool_link_ksettings_test_link_mode(ks, advertising,
2276 						  100000baseKR4_Full))
2277 		adv_link_speed |= ICE_AQ_LINK_SPEED_100GB;
2278 
2279 	return adv_link_speed;
2280 }
2281 
2282 /**
2283  * ice_setup_autoneg
2284  * @p: port info
2285  * @ks: ethtool_link_ksettings
2286  * @config: configuration that will be sent down to FW
2287  * @autoneg_enabled: autonegotiation is enabled or not
2288  * @autoneg_changed: will there a change in autonegotiation
2289  * @netdev: network interface device structure
2290  *
2291  * Setup PHY autonegotiation feature
2292  */
2293 static int
2294 ice_setup_autoneg(struct ice_port_info *p, struct ethtool_link_ksettings *ks,
2295 		  struct ice_aqc_set_phy_cfg_data *config,
2296 		  u8 autoneg_enabled, u8 *autoneg_changed,
2297 		  struct net_device *netdev)
2298 {
2299 	int err = 0;
2300 
2301 	*autoneg_changed = 0;
2302 
2303 	/* Check autoneg */
2304 	if (autoneg_enabled == AUTONEG_ENABLE) {
2305 		/* If autoneg was not already enabled */
2306 		if (!(p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)) {
2307 			/* If autoneg is not supported, return error */
2308 			if (!ethtool_link_ksettings_test_link_mode(ks,
2309 								   supported,
2310 								   Autoneg)) {
2311 				netdev_info(netdev, "Autoneg not supported on this phy.\n");
2312 				err = -EINVAL;
2313 			} else {
2314 				/* Autoneg is allowed to change */
2315 				config->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2316 				*autoneg_changed = 1;
2317 			}
2318 		}
2319 	} else {
2320 		/* If autoneg is currently enabled */
2321 		if (p->phy.link_info.an_info & ICE_AQ_AN_COMPLETED) {
2322 			/* If autoneg is supported 10GBASE_T is the only PHY
2323 			 * that can disable it, so otherwise return error
2324 			 */
2325 			if (ethtool_link_ksettings_test_link_mode(ks,
2326 								  supported,
2327 								  Autoneg)) {
2328 				netdev_info(netdev, "Autoneg cannot be disabled on this phy\n");
2329 				err = -EINVAL;
2330 			} else {
2331 				/* Autoneg is allowed to change */
2332 				config->caps &= ~ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2333 				*autoneg_changed = 1;
2334 			}
2335 		}
2336 	}
2337 
2338 	return err;
2339 }
2340 
2341 /**
2342  * ice_set_link_ksettings - Set Speed and Duplex
2343  * @netdev: network interface device structure
2344  * @ks: ethtool ksettings
2345  *
2346  * Set speed/duplex per media_types advertised/forced
2347  */
2348 static int
2349 ice_set_link_ksettings(struct net_device *netdev,
2350 		       const struct ethtool_link_ksettings *ks)
2351 {
2352 	u8 autoneg, timeout = TEST_SET_BITS_TIMEOUT, lport = 0;
2353 	struct ice_netdev_priv *np = netdev_priv(netdev);
2354 	struct ethtool_link_ksettings safe_ks, copy_ks;
2355 	struct ice_aqc_get_phy_caps_data *abilities;
2356 	u16 adv_link_speed, curr_link_speed, idx;
2357 	struct ice_aqc_set_phy_cfg_data config;
2358 	struct ice_pf *pf = np->vsi->back;
2359 	struct ice_port_info *p;
2360 	u8 autoneg_changed = 0;
2361 	enum ice_status status;
2362 	u64 phy_type_high;
2363 	u64 phy_type_low;
2364 	int err = 0;
2365 	bool linkup;
2366 
2367 	p = np->vsi->port_info;
2368 
2369 	if (!p)
2370 		return -EOPNOTSUPP;
2371 
2372 	/* Check if this is LAN VSI */
2373 	ice_for_each_vsi(pf, idx)
2374 		if (pf->vsi[idx]->type == ICE_VSI_PF) {
2375 			if (np->vsi != pf->vsi[idx])
2376 				return -EOPNOTSUPP;
2377 			break;
2378 		}
2379 
2380 	if (p->phy.media_type != ICE_MEDIA_BASET &&
2381 	    p->phy.media_type != ICE_MEDIA_FIBER &&
2382 	    p->phy.media_type != ICE_MEDIA_BACKPLANE &&
2383 	    p->phy.media_type != ICE_MEDIA_DA &&
2384 	    p->phy.link_info.link_info & ICE_AQ_LINK_UP)
2385 		return -EOPNOTSUPP;
2386 
2387 	/* copy the ksettings to copy_ks to avoid modifying the original */
2388 	memcpy(&copy_ks, ks, sizeof(copy_ks));
2389 
2390 	/* save autoneg out of ksettings */
2391 	autoneg = copy_ks.base.autoneg;
2392 
2393 	memset(&safe_ks, 0, sizeof(safe_ks));
2394 
2395 	/* Get link modes supported by hardware.*/
2396 	ice_phy_type_to_ethtool(netdev, &safe_ks);
2397 
2398 	/* and check against modes requested by user.
2399 	 * Return an error if unsupported mode was set.
2400 	 */
2401 	if (!bitmap_subset(copy_ks.link_modes.advertising,
2402 			   safe_ks.link_modes.supported,
2403 			   __ETHTOOL_LINK_MODE_MASK_NBITS))
2404 		return -EINVAL;
2405 
2406 	/* get our own copy of the bits to check against */
2407 	memset(&safe_ks, 0, sizeof(safe_ks));
2408 	safe_ks.base.cmd = copy_ks.base.cmd;
2409 	safe_ks.base.link_mode_masks_nwords =
2410 		copy_ks.base.link_mode_masks_nwords;
2411 	ice_get_link_ksettings(netdev, &safe_ks);
2412 
2413 	/* set autoneg back to what it currently is */
2414 	copy_ks.base.autoneg = safe_ks.base.autoneg;
2415 	/* we don't compare the speed */
2416 	copy_ks.base.speed = safe_ks.base.speed;
2417 
2418 	/* If copy_ks.base and safe_ks.base are not the same now, then they are
2419 	 * trying to set something that we do not support.
2420 	 */
2421 	if (memcmp(&copy_ks.base, &safe_ks.base, sizeof(copy_ks.base)))
2422 		return -EOPNOTSUPP;
2423 
2424 	while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2425 		timeout--;
2426 		if (!timeout)
2427 			return -EBUSY;
2428 		usleep_range(TEST_SET_BITS_SLEEP_MIN, TEST_SET_BITS_SLEEP_MAX);
2429 	}
2430 
2431 	abilities = devm_kzalloc(&pf->pdev->dev, sizeof(*abilities),
2432 				 GFP_KERNEL);
2433 	if (!abilities)
2434 		return -ENOMEM;
2435 
2436 	/* Get the current PHY config */
2437 	status = ice_aq_get_phy_caps(p, false, ICE_AQC_REPORT_SW_CFG, abilities,
2438 				     NULL);
2439 	if (status) {
2440 		err = -EAGAIN;
2441 		goto done;
2442 	}
2443 
2444 	/* Copy abilities to config in case autoneg is not set below */
2445 	memset(&config, 0, sizeof(config));
2446 	config.caps = abilities->caps & ~ICE_AQC_PHY_AN_MODE;
2447 	if (abilities->caps & ICE_AQC_PHY_AN_MODE)
2448 		config.caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2449 
2450 	/* Check autoneg */
2451 	err = ice_setup_autoneg(p, &safe_ks, &config, autoneg, &autoneg_changed,
2452 				netdev);
2453 
2454 	if (err)
2455 		goto done;
2456 
2457 	/* Call to get the current link speed */
2458 	p->phy.get_link_info = true;
2459 	status = ice_get_link_status(p, &linkup);
2460 	if (status) {
2461 		err = -EAGAIN;
2462 		goto done;
2463 	}
2464 
2465 	curr_link_speed = p->phy.link_info.link_speed;
2466 	adv_link_speed = ice_ksettings_find_adv_link_speed(ks);
2467 
2468 	/* If speed didn't get set, set it to what it currently is.
2469 	 * This is needed because if advertise is 0 (as it is when autoneg
2470 	 * is disabled) then speed won't get set.
2471 	 */
2472 	if (!adv_link_speed)
2473 		adv_link_speed = curr_link_speed;
2474 
2475 	/* Convert the advertise link speeds to their corresponded PHY_TYPE */
2476 	ice_update_phy_type(&phy_type_low, &phy_type_high, adv_link_speed);
2477 
2478 	if (!autoneg_changed && adv_link_speed == curr_link_speed) {
2479 		netdev_info(netdev, "Nothing changed, exiting without setting anything.\n");
2480 		goto done;
2481 	}
2482 
2483 	/* copy over the rest of the abilities */
2484 	config.low_power_ctrl = abilities->low_power_ctrl;
2485 	config.eee_cap = abilities->eee_cap;
2486 	config.eeer_value = abilities->eeer_value;
2487 	config.link_fec_opt = abilities->link_fec_options;
2488 
2489 	/* save the requested speeds */
2490 	p->phy.link_info.req_speeds = adv_link_speed;
2491 
2492 	/* set link and auto negotiation so changes take effect */
2493 	config.caps |= ICE_AQ_PHY_ENA_LINK;
2494 
2495 	if (phy_type_low || phy_type_high) {
2496 		config.phy_type_high = cpu_to_le64(phy_type_high) &
2497 			abilities->phy_type_high;
2498 		config.phy_type_low = cpu_to_le64(phy_type_low) &
2499 			abilities->phy_type_low;
2500 	} else {
2501 		err = -EAGAIN;
2502 		netdev_info(netdev, "Nothing changed. No PHY_TYPE is corresponded to advertised link speed.\n");
2503 		goto done;
2504 	}
2505 
2506 	/* If link is up put link down */
2507 	if (p->phy.link_info.link_info & ICE_AQ_LINK_UP) {
2508 		/* Tell the OS link is going down, the link will go
2509 		 * back up when fw says it is ready asynchronously
2510 		 */
2511 		ice_print_link_msg(np->vsi, false);
2512 		netif_carrier_off(netdev);
2513 		netif_tx_stop_all_queues(netdev);
2514 	}
2515 
2516 	/* make the aq call */
2517 	status = ice_aq_set_phy_cfg(&pf->hw, lport, &config, NULL);
2518 	if (status) {
2519 		netdev_info(netdev, "Set phy config failed,\n");
2520 		err = -EAGAIN;
2521 	}
2522 
2523 done:
2524 	devm_kfree(&pf->pdev->dev, abilities);
2525 	clear_bit(__ICE_CFG_BUSY, pf->state);
2526 
2527 	return err;
2528 }
2529 
2530 /**
2531  * ice_get_rxnfc - command to get Rx flow classification rules
2532  * @netdev: network interface device structure
2533  * @cmd: ethtool rxnfc command
2534  * @rule_locs: buffer to rturn Rx flow classification rules
2535  *
2536  * Returns Success if the command is supported.
2537  */
2538 static int
2539 ice_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd,
2540 	      u32 __always_unused *rule_locs)
2541 {
2542 	struct ice_netdev_priv *np = netdev_priv(netdev);
2543 	struct ice_vsi *vsi = np->vsi;
2544 	int ret = -EOPNOTSUPP;
2545 
2546 	switch (cmd->cmd) {
2547 	case ETHTOOL_GRXRINGS:
2548 		cmd->data = vsi->rss_size;
2549 		ret = 0;
2550 		break;
2551 	default:
2552 		break;
2553 	}
2554 
2555 	return ret;
2556 }
2557 
2558 static void
2559 ice_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2560 {
2561 	struct ice_netdev_priv *np = netdev_priv(netdev);
2562 	struct ice_vsi *vsi = np->vsi;
2563 
2564 	ring->rx_max_pending = ICE_MAX_NUM_DESC;
2565 	ring->tx_max_pending = ICE_MAX_NUM_DESC;
2566 	ring->rx_pending = vsi->rx_rings[0]->count;
2567 	ring->tx_pending = vsi->tx_rings[0]->count;
2568 
2569 	/* Rx mini and jumbo rings are not supported */
2570 	ring->rx_mini_max_pending = 0;
2571 	ring->rx_jumbo_max_pending = 0;
2572 	ring->rx_mini_pending = 0;
2573 	ring->rx_jumbo_pending = 0;
2574 }
2575 
2576 static int
2577 ice_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring)
2578 {
2579 	struct ice_ring *tx_rings = NULL, *rx_rings = NULL;
2580 	struct ice_netdev_priv *np = netdev_priv(netdev);
2581 	struct ice_ring *xdp_rings = NULL;
2582 	struct ice_vsi *vsi = np->vsi;
2583 	struct ice_pf *pf = vsi->back;
2584 	int i, timeout = 50, err = 0;
2585 	u32 new_rx_cnt, new_tx_cnt;
2586 
2587 	if (ring->tx_pending > ICE_MAX_NUM_DESC ||
2588 	    ring->tx_pending < ICE_MIN_NUM_DESC ||
2589 	    ring->rx_pending > ICE_MAX_NUM_DESC ||
2590 	    ring->rx_pending < ICE_MIN_NUM_DESC) {
2591 		netdev_err(netdev, "Descriptors requested (Tx: %d / Rx: %d) out of range [%d-%d] (increment %d)\n",
2592 			   ring->tx_pending, ring->rx_pending,
2593 			   ICE_MIN_NUM_DESC, ICE_MAX_NUM_DESC,
2594 			   ICE_REQ_DESC_MULTIPLE);
2595 		return -EINVAL;
2596 	}
2597 
2598 	new_tx_cnt = ALIGN(ring->tx_pending, ICE_REQ_DESC_MULTIPLE);
2599 	if (new_tx_cnt != ring->tx_pending)
2600 		netdev_info(netdev,
2601 			    "Requested Tx descriptor count rounded up to %d\n",
2602 			    new_tx_cnt);
2603 	new_rx_cnt = ALIGN(ring->rx_pending, ICE_REQ_DESC_MULTIPLE);
2604 	if (new_rx_cnt != ring->rx_pending)
2605 		netdev_info(netdev,
2606 			    "Requested Rx descriptor count rounded up to %d\n",
2607 			    new_rx_cnt);
2608 
2609 	/* if nothing to do return success */
2610 	if (new_tx_cnt == vsi->tx_rings[0]->count &&
2611 	    new_rx_cnt == vsi->rx_rings[0]->count) {
2612 		netdev_dbg(netdev, "Nothing to change, descriptor count is same as requested\n");
2613 		return 0;
2614 	}
2615 
2616 	/* If there is a AF_XDP UMEM attached to any of Rx rings,
2617 	 * disallow changing the number of descriptors -- regardless
2618 	 * if the netdev is running or not.
2619 	 */
2620 	if (ice_xsk_any_rx_ring_ena(vsi))
2621 		return -EBUSY;
2622 
2623 	while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2624 		timeout--;
2625 		if (!timeout)
2626 			return -EBUSY;
2627 		usleep_range(1000, 2000);
2628 	}
2629 
2630 	/* set for the next time the netdev is started */
2631 	if (!netif_running(vsi->netdev)) {
2632 		for (i = 0; i < vsi->alloc_txq; i++)
2633 			vsi->tx_rings[i]->count = new_tx_cnt;
2634 		for (i = 0; i < vsi->alloc_rxq; i++)
2635 			vsi->rx_rings[i]->count = new_rx_cnt;
2636 		if (ice_is_xdp_ena_vsi(vsi))
2637 			for (i = 0; i < vsi->num_xdp_txq; i++)
2638 				vsi->xdp_rings[i]->count = new_tx_cnt;
2639 		vsi->num_tx_desc = new_tx_cnt;
2640 		vsi->num_rx_desc = new_rx_cnt;
2641 		netdev_dbg(netdev, "Link is down, descriptor count change happens when link is brought up\n");
2642 		goto done;
2643 	}
2644 
2645 	if (new_tx_cnt == vsi->tx_rings[0]->count)
2646 		goto process_rx;
2647 
2648 	/* alloc updated Tx resources */
2649 	netdev_info(netdev, "Changing Tx descriptor count from %d to %d\n",
2650 		    vsi->tx_rings[0]->count, new_tx_cnt);
2651 
2652 	tx_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_txq,
2653 				sizeof(*tx_rings), GFP_KERNEL);
2654 	if (!tx_rings) {
2655 		err = -ENOMEM;
2656 		goto done;
2657 	}
2658 
2659 	ice_for_each_txq(vsi, i) {
2660 		/* clone ring and setup updated count */
2661 		tx_rings[i] = *vsi->tx_rings[i];
2662 		tx_rings[i].count = new_tx_cnt;
2663 		tx_rings[i].desc = NULL;
2664 		tx_rings[i].tx_buf = NULL;
2665 		err = ice_setup_tx_ring(&tx_rings[i]);
2666 		if (err) {
2667 			while (i--)
2668 				ice_clean_tx_ring(&tx_rings[i]);
2669 			devm_kfree(&pf->pdev->dev, tx_rings);
2670 			goto done;
2671 		}
2672 	}
2673 
2674 	if (!ice_is_xdp_ena_vsi(vsi))
2675 		goto process_rx;
2676 
2677 	/* alloc updated XDP resources */
2678 	netdev_info(netdev, "Changing XDP descriptor count from %d to %d\n",
2679 		    vsi->xdp_rings[0]->count, new_tx_cnt);
2680 
2681 	xdp_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_xdp_txq,
2682 				 sizeof(*xdp_rings), GFP_KERNEL);
2683 	if (!xdp_rings) {
2684 		err = -ENOMEM;
2685 		goto free_tx;
2686 	}
2687 
2688 	for (i = 0; i < vsi->num_xdp_txq; i++) {
2689 		/* clone ring and setup updated count */
2690 		xdp_rings[i] = *vsi->xdp_rings[i];
2691 		xdp_rings[i].count = new_tx_cnt;
2692 		xdp_rings[i].desc = NULL;
2693 		xdp_rings[i].tx_buf = NULL;
2694 		err = ice_setup_tx_ring(&xdp_rings[i]);
2695 		if (err) {
2696 			while (i--)
2697 				ice_clean_tx_ring(&xdp_rings[i]);
2698 			devm_kfree(&pf->pdev->dev, xdp_rings);
2699 			goto free_tx;
2700 		}
2701 		ice_set_ring_xdp(&xdp_rings[i]);
2702 	}
2703 
2704 process_rx:
2705 	if (new_rx_cnt == vsi->rx_rings[0]->count)
2706 		goto process_link;
2707 
2708 	/* alloc updated Rx resources */
2709 	netdev_info(netdev, "Changing Rx descriptor count from %d to %d\n",
2710 		    vsi->rx_rings[0]->count, new_rx_cnt);
2711 
2712 	rx_rings = devm_kcalloc(&pf->pdev->dev, vsi->num_rxq,
2713 				sizeof(*rx_rings), GFP_KERNEL);
2714 	if (!rx_rings) {
2715 		err = -ENOMEM;
2716 		goto done;
2717 	}
2718 
2719 	ice_for_each_rxq(vsi, i) {
2720 		/* clone ring and setup updated count */
2721 		rx_rings[i] = *vsi->rx_rings[i];
2722 		rx_rings[i].count = new_rx_cnt;
2723 		rx_rings[i].desc = NULL;
2724 		rx_rings[i].rx_buf = NULL;
2725 		/* this is to allow wr32 to have something to write to
2726 		 * during early allocation of Rx buffers
2727 		 */
2728 		rx_rings[i].tail = vsi->back->hw.hw_addr + PRTGEN_STATUS;
2729 
2730 		err = ice_setup_rx_ring(&rx_rings[i]);
2731 		if (err)
2732 			goto rx_unwind;
2733 
2734 		/* allocate Rx buffers */
2735 		err = ice_alloc_rx_bufs(&rx_rings[i],
2736 					ICE_DESC_UNUSED(&rx_rings[i]));
2737 rx_unwind:
2738 		if (err) {
2739 			while (i) {
2740 				i--;
2741 				ice_free_rx_ring(&rx_rings[i]);
2742 			}
2743 			devm_kfree(&pf->pdev->dev, rx_rings);
2744 			err = -ENOMEM;
2745 			goto free_tx;
2746 		}
2747 	}
2748 
2749 process_link:
2750 	/* Bring interface down, copy in the new ring info, then restore the
2751 	 * interface. if VSI is up, bring it down and then back up
2752 	 */
2753 	if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
2754 		ice_down(vsi);
2755 
2756 		if (tx_rings) {
2757 			ice_for_each_txq(vsi, i) {
2758 				ice_free_tx_ring(vsi->tx_rings[i]);
2759 				*vsi->tx_rings[i] = tx_rings[i];
2760 			}
2761 			devm_kfree(&pf->pdev->dev, tx_rings);
2762 		}
2763 
2764 		if (rx_rings) {
2765 			ice_for_each_rxq(vsi, i) {
2766 				ice_free_rx_ring(vsi->rx_rings[i]);
2767 				/* copy the real tail offset */
2768 				rx_rings[i].tail = vsi->rx_rings[i]->tail;
2769 				/* this is to fake out the allocation routine
2770 				 * into thinking it has to realloc everything
2771 				 * but the recycling logic will let us re-use
2772 				 * the buffers allocated above
2773 				 */
2774 				rx_rings[i].next_to_use = 0;
2775 				rx_rings[i].next_to_clean = 0;
2776 				rx_rings[i].next_to_alloc = 0;
2777 				*vsi->rx_rings[i] = rx_rings[i];
2778 			}
2779 			devm_kfree(&pf->pdev->dev, rx_rings);
2780 		}
2781 
2782 		if (xdp_rings) {
2783 			for (i = 0; i < vsi->num_xdp_txq; i++) {
2784 				ice_free_tx_ring(vsi->xdp_rings[i]);
2785 				*vsi->xdp_rings[i] = xdp_rings[i];
2786 			}
2787 			devm_kfree(&pf->pdev->dev, xdp_rings);
2788 		}
2789 
2790 		vsi->num_tx_desc = new_tx_cnt;
2791 		vsi->num_rx_desc = new_rx_cnt;
2792 		ice_up(vsi);
2793 	}
2794 	goto done;
2795 
2796 free_tx:
2797 	/* error cleanup if the Rx allocations failed after getting Tx */
2798 	if (tx_rings) {
2799 		ice_for_each_txq(vsi, i)
2800 			ice_free_tx_ring(&tx_rings[i]);
2801 		devm_kfree(&pf->pdev->dev, tx_rings);
2802 	}
2803 
2804 done:
2805 	clear_bit(__ICE_CFG_BUSY, pf->state);
2806 	return err;
2807 }
2808 
2809 static int ice_nway_reset(struct net_device *netdev)
2810 {
2811 	/* restart autonegotiation */
2812 	struct ice_netdev_priv *np = netdev_priv(netdev);
2813 	struct ice_vsi *vsi = np->vsi;
2814 	struct ice_port_info *pi;
2815 	enum ice_status status;
2816 
2817 	pi = vsi->port_info;
2818 	/* If VSI state is up, then restart autoneg with link up */
2819 	if (!test_bit(__ICE_DOWN, vsi->back->state))
2820 		status = ice_aq_set_link_restart_an(pi, true, NULL);
2821 	else
2822 		status = ice_aq_set_link_restart_an(pi, false, NULL);
2823 
2824 	if (status) {
2825 		netdev_info(netdev, "link restart failed, err %d aq_err %d\n",
2826 			    status, pi->hw->adminq.sq_last_status);
2827 		return -EIO;
2828 	}
2829 
2830 	return 0;
2831 }
2832 
2833 /**
2834  * ice_get_pauseparam - Get Flow Control status
2835  * @netdev: network interface device structure
2836  * @pause: ethernet pause (flow control) parameters
2837  *
2838  * Get requested flow control status from PHY capability.
2839  * If autoneg is true, then ethtool will send the ETHTOOL_GSET ioctl which
2840  * is handled by ice_get_link_ksettings. ice_get_link_ksettings will report
2841  * the negotiated Rx/Tx pause via lp_advertising.
2842  */
2843 static void
2844 ice_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2845 {
2846 	struct ice_netdev_priv *np = netdev_priv(netdev);
2847 	struct ice_port_info *pi = np->vsi->port_info;
2848 	struct ice_aqc_get_phy_caps_data *pcaps;
2849 	struct ice_vsi *vsi = np->vsi;
2850 	struct ice_dcbx_cfg *dcbx_cfg;
2851 	enum ice_status status;
2852 
2853 	/* Initialize pause params */
2854 	pause->rx_pause = 0;
2855 	pause->tx_pause = 0;
2856 
2857 	dcbx_cfg = &pi->local_dcbx_cfg;
2858 
2859 	pcaps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*pcaps),
2860 			     GFP_KERNEL);
2861 	if (!pcaps)
2862 		return;
2863 
2864 	/* Get current PHY config */
2865 	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2866 				     NULL);
2867 	if (status)
2868 		goto out;
2869 
2870 	pause->autoneg = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2871 			AUTONEG_ENABLE : AUTONEG_DISABLE);
2872 
2873 	if (dcbx_cfg->pfc.pfcena)
2874 		/* PFC enabled so report LFC as off */
2875 		goto out;
2876 
2877 	if (pcaps->caps & ICE_AQC_PHY_EN_TX_LINK_PAUSE)
2878 		pause->tx_pause = 1;
2879 	if (pcaps->caps & ICE_AQC_PHY_EN_RX_LINK_PAUSE)
2880 		pause->rx_pause = 1;
2881 
2882 out:
2883 	devm_kfree(&vsi->back->pdev->dev, pcaps);
2884 }
2885 
2886 /**
2887  * ice_set_pauseparam - Set Flow Control parameter
2888  * @netdev: network interface device structure
2889  * @pause: return Tx/Rx flow control status
2890  */
2891 static int
2892 ice_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause)
2893 {
2894 	struct ice_netdev_priv *np = netdev_priv(netdev);
2895 	struct ice_aqc_get_phy_caps_data *pcaps;
2896 	struct ice_link_status *hw_link_info;
2897 	struct ice_pf *pf = np->vsi->back;
2898 	struct ice_dcbx_cfg *dcbx_cfg;
2899 	struct ice_vsi *vsi = np->vsi;
2900 	struct ice_hw *hw = &pf->hw;
2901 	struct ice_port_info *pi;
2902 	enum ice_status status;
2903 	u8 aq_failures;
2904 	bool link_up;
2905 	int err = 0;
2906 	u32 is_an;
2907 
2908 	pi = vsi->port_info;
2909 	hw_link_info = &pi->phy.link_info;
2910 	dcbx_cfg = &pi->local_dcbx_cfg;
2911 	link_up = hw_link_info->link_info & ICE_AQ_LINK_UP;
2912 
2913 	/* Changing the port's flow control is not supported if this isn't the
2914 	 * PF VSI
2915 	 */
2916 	if (vsi->type != ICE_VSI_PF) {
2917 		netdev_info(netdev, "Changing flow control parameters only supported for PF VSI\n");
2918 		return -EOPNOTSUPP;
2919 	}
2920 
2921 	/* Get pause param reports configured and negotiated flow control pause
2922 	 * when ETHTOOL_GLINKSETTINGS is defined. Since ETHTOOL_GLINKSETTINGS is
2923 	 * defined get pause param pause->autoneg reports SW configured setting,
2924 	 * so compare pause->autoneg with SW configured to prevent the user from
2925 	 * using set pause param to chance autoneg.
2926 	 */
2927 	pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2928 	if (!pcaps)
2929 		return -ENOMEM;
2930 
2931 	/* Get current PHY config */
2932 	status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
2933 				     NULL);
2934 	if (status) {
2935 		kfree(pcaps);
2936 		return -EIO;
2937 	}
2938 
2939 	is_an = ((pcaps->caps & ICE_AQC_PHY_AN_MODE) ?
2940 			AUTONEG_ENABLE : AUTONEG_DISABLE);
2941 
2942 	kfree(pcaps);
2943 
2944 	if (pause->autoneg != is_an) {
2945 		netdev_info(netdev, "To change autoneg please use: ethtool -s <dev> autoneg <on|off>\n");
2946 		return -EOPNOTSUPP;
2947 	}
2948 
2949 	/* If we have link and don't have autoneg */
2950 	if (!test_bit(__ICE_DOWN, pf->state) &&
2951 	    !(hw_link_info->an_info & ICE_AQ_AN_COMPLETED)) {
2952 		/* Send message that it might not necessarily work*/
2953 		netdev_info(netdev, "Autoneg did not complete so changing settings may not result in an actual change.\n");
2954 	}
2955 
2956 	if (dcbx_cfg->pfc.pfcena) {
2957 		netdev_info(netdev, "Priority flow control enabled. Cannot set link flow control.\n");
2958 		return -EOPNOTSUPP;
2959 	}
2960 	if (pause->rx_pause && pause->tx_pause)
2961 		pi->fc.req_mode = ICE_FC_FULL;
2962 	else if (pause->rx_pause && !pause->tx_pause)
2963 		pi->fc.req_mode = ICE_FC_RX_PAUSE;
2964 	else if (!pause->rx_pause && pause->tx_pause)
2965 		pi->fc.req_mode = ICE_FC_TX_PAUSE;
2966 	else if (!pause->rx_pause && !pause->tx_pause)
2967 		pi->fc.req_mode = ICE_FC_NONE;
2968 	else
2969 		return -EINVAL;
2970 
2971 	/* Tell the OS link is going down, the link will go back up when fw
2972 	 * says it is ready asynchronously
2973 	 */
2974 	ice_print_link_msg(vsi, false);
2975 	netif_carrier_off(netdev);
2976 	netif_tx_stop_all_queues(netdev);
2977 
2978 	/* Set the FC mode and only restart AN if link is up */
2979 	status = ice_set_fc(pi, &aq_failures, link_up);
2980 
2981 	if (aq_failures & ICE_SET_FC_AQ_FAIL_GET) {
2982 		netdev_info(netdev, "Set fc failed on the get_phy_capabilities call with err %d aq_err %d\n",
2983 			    status, hw->adminq.sq_last_status);
2984 		err = -EAGAIN;
2985 	} else if (aq_failures & ICE_SET_FC_AQ_FAIL_SET) {
2986 		netdev_info(netdev, "Set fc failed on the set_phy_config call with err %d aq_err %d\n",
2987 			    status, hw->adminq.sq_last_status);
2988 		err = -EAGAIN;
2989 	} else if (aq_failures & ICE_SET_FC_AQ_FAIL_UPDATE) {
2990 		netdev_info(netdev, "Set fc failed on the get_link_info call with err %d aq_err %d\n",
2991 			    status, hw->adminq.sq_last_status);
2992 		err = -EAGAIN;
2993 	}
2994 
2995 	if (!test_bit(__ICE_DOWN, pf->state)) {
2996 		/* Give it a little more time to try to come back. If still
2997 		 * down, restart autoneg link or reinitialize the interface.
2998 		 */
2999 		msleep(75);
3000 		if (!test_bit(__ICE_DOWN, pf->state))
3001 			return ice_nway_reset(netdev);
3002 
3003 		ice_down(vsi);
3004 		ice_up(vsi);
3005 	}
3006 
3007 	return err;
3008 }
3009 
3010 /**
3011  * ice_get_rxfh_key_size - get the RSS hash key size
3012  * @netdev: network interface device structure
3013  *
3014  * Returns the table size.
3015  */
3016 static u32 ice_get_rxfh_key_size(struct net_device __always_unused *netdev)
3017 {
3018 	return ICE_VSIQF_HKEY_ARRAY_SIZE;
3019 }
3020 
3021 /**
3022  * ice_get_rxfh_indir_size - get the Rx flow hash indirection table size
3023  * @netdev: network interface device structure
3024  *
3025  * Returns the table size.
3026  */
3027 static u32 ice_get_rxfh_indir_size(struct net_device *netdev)
3028 {
3029 	struct ice_netdev_priv *np = netdev_priv(netdev);
3030 
3031 	return np->vsi->rss_table_size;
3032 }
3033 
3034 /**
3035  * ice_get_rxfh - get the Rx flow hash indirection table
3036  * @netdev: network interface device structure
3037  * @indir: indirection table
3038  * @key: hash key
3039  * @hfunc: hash function
3040  *
3041  * Reads the indirection table directly from the hardware.
3042  */
3043 static int
3044 ice_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
3045 {
3046 	struct ice_netdev_priv *np = netdev_priv(netdev);
3047 	struct ice_vsi *vsi = np->vsi;
3048 	struct ice_pf *pf = vsi->back;
3049 	int ret = 0, i;
3050 	u8 *lut;
3051 
3052 	if (hfunc)
3053 		*hfunc = ETH_RSS_HASH_TOP;
3054 
3055 	if (!indir)
3056 		return 0;
3057 
3058 	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3059 		/* RSS not supported return error here */
3060 		netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3061 		return -EIO;
3062 	}
3063 
3064 	lut = devm_kzalloc(&pf->pdev->dev, vsi->rss_table_size, GFP_KERNEL);
3065 	if (!lut)
3066 		return -ENOMEM;
3067 
3068 	if (ice_get_rss(vsi, key, lut, vsi->rss_table_size)) {
3069 		ret = -EIO;
3070 		goto out;
3071 	}
3072 
3073 	for (i = 0; i < vsi->rss_table_size; i++)
3074 		indir[i] = (u32)(lut[i]);
3075 
3076 out:
3077 	devm_kfree(&pf->pdev->dev, lut);
3078 	return ret;
3079 }
3080 
3081 /**
3082  * ice_set_rxfh - set the Rx flow hash indirection table
3083  * @netdev: network interface device structure
3084  * @indir: indirection table
3085  * @key: hash key
3086  * @hfunc: hash function
3087  *
3088  * Returns -EINVAL if the table specifies an invalid queue ID, otherwise
3089  * returns 0 after programming the table.
3090  */
3091 static int
3092 ice_set_rxfh(struct net_device *netdev, const u32 *indir, const u8 *key,
3093 	     const u8 hfunc)
3094 {
3095 	struct ice_netdev_priv *np = netdev_priv(netdev);
3096 	struct ice_vsi *vsi = np->vsi;
3097 	struct ice_pf *pf = vsi->back;
3098 	u8 *seed = NULL;
3099 
3100 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
3101 		return -EOPNOTSUPP;
3102 
3103 	if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
3104 		/* RSS not supported return error here */
3105 		netdev_warn(netdev, "RSS is not configured on this VSI!\n");
3106 		return -EIO;
3107 	}
3108 
3109 	if (key) {
3110 		if (!vsi->rss_hkey_user) {
3111 			vsi->rss_hkey_user =
3112 				devm_kzalloc(&pf->pdev->dev,
3113 					     ICE_VSIQF_HKEY_ARRAY_SIZE,
3114 					     GFP_KERNEL);
3115 			if (!vsi->rss_hkey_user)
3116 				return -ENOMEM;
3117 		}
3118 		memcpy(vsi->rss_hkey_user, key, ICE_VSIQF_HKEY_ARRAY_SIZE);
3119 		seed = vsi->rss_hkey_user;
3120 	}
3121 
3122 	if (!vsi->rss_lut_user) {
3123 		vsi->rss_lut_user = devm_kzalloc(&pf->pdev->dev,
3124 						 vsi->rss_table_size,
3125 						 GFP_KERNEL);
3126 		if (!vsi->rss_lut_user)
3127 			return -ENOMEM;
3128 	}
3129 
3130 	/* Each 32 bits pointed by 'indir' is stored with a lut entry */
3131 	if (indir) {
3132 		int i;
3133 
3134 		for (i = 0; i < vsi->rss_table_size; i++)
3135 			vsi->rss_lut_user[i] = (u8)(indir[i]);
3136 	} else {
3137 		ice_fill_rss_lut(vsi->rss_lut_user, vsi->rss_table_size,
3138 				 vsi->rss_size);
3139 	}
3140 
3141 	if (ice_set_rss(vsi, seed, vsi->rss_lut_user, vsi->rss_table_size))
3142 		return -EIO;
3143 
3144 	return 0;
3145 }
3146 
3147 enum ice_container_type {
3148 	ICE_RX_CONTAINER,
3149 	ICE_TX_CONTAINER,
3150 };
3151 
3152 /**
3153  * ice_get_rc_coalesce - get ITR values for specific ring container
3154  * @ec: ethtool structure to fill with driver's coalesce settings
3155  * @c_type: container type, Rx or Tx
3156  * @rc: ring container that the ITR values will come from
3157  *
3158  * Query the device for ice_ring_container specific ITR values. This is
3159  * done per ice_ring_container because each q_vector can have 1 or more rings
3160  * and all of said ring(s) will have the same ITR values.
3161  *
3162  * Returns 0 on success, negative otherwise.
3163  */
3164 static int
3165 ice_get_rc_coalesce(struct ethtool_coalesce *ec, enum ice_container_type c_type,
3166 		    struct ice_ring_container *rc)
3167 {
3168 	struct ice_pf *pf;
3169 
3170 	if (!rc->ring)
3171 		return -EINVAL;
3172 
3173 	pf = rc->ring->vsi->back;
3174 
3175 	switch (c_type) {
3176 	case ICE_RX_CONTAINER:
3177 		ec->use_adaptive_rx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3178 		ec->rx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3179 		ec->rx_coalesce_usecs_high = rc->ring->q_vector->intrl;
3180 		break;
3181 	case ICE_TX_CONTAINER:
3182 		ec->use_adaptive_tx_coalesce = ITR_IS_DYNAMIC(rc->itr_setting);
3183 		ec->tx_coalesce_usecs = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3184 		break;
3185 	default:
3186 		dev_dbg(&pf->pdev->dev, "Invalid c_type %d\n", c_type);
3187 		return -EINVAL;
3188 	}
3189 
3190 	return 0;
3191 }
3192 
3193 /**
3194  * ice_get_q_coalesce - get a queue's ITR/INTRL (coalesce) settings
3195  * @vsi: VSI associated to the queue for getting ITR/INTRL (coalesce) settings
3196  * @ec: coalesce settings to program the device with
3197  * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3198  *
3199  * Return 0 on success, and negative under the following conditions:
3200  * 1. Getting Tx or Rx ITR/INTRL (coalesce) settings failed.
3201  * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3202  */
3203 static int
3204 ice_get_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3205 {
3206 	if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3207 		if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3208 					&vsi->rx_rings[q_num]->q_vector->rx))
3209 			return -EINVAL;
3210 		if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3211 					&vsi->tx_rings[q_num]->q_vector->tx))
3212 			return -EINVAL;
3213 	} else if (q_num < vsi->num_rxq) {
3214 		if (ice_get_rc_coalesce(ec, ICE_RX_CONTAINER,
3215 					&vsi->rx_rings[q_num]->q_vector->rx))
3216 			return -EINVAL;
3217 	} else if (q_num < vsi->num_txq) {
3218 		if (ice_get_rc_coalesce(ec, ICE_TX_CONTAINER,
3219 					&vsi->tx_rings[q_num]->q_vector->tx))
3220 			return -EINVAL;
3221 	} else {
3222 		return -EINVAL;
3223 	}
3224 
3225 	return 0;
3226 }
3227 
3228 /**
3229  * __ice_get_coalesce - get ITR/INTRL values for the device
3230  * @netdev: pointer to the netdev associated with this query
3231  * @ec: ethtool structure to fill with driver's coalesce settings
3232  * @q_num: queue number to get the coalesce settings for
3233  *
3234  * If the caller passes in a negative q_num then we return coalesce settings
3235  * based on queue number 0, else use the actual q_num passed in.
3236  */
3237 static int
3238 __ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3239 		   int q_num)
3240 {
3241 	struct ice_netdev_priv *np = netdev_priv(netdev);
3242 	struct ice_vsi *vsi = np->vsi;
3243 
3244 	if (q_num < 0)
3245 		q_num = 0;
3246 
3247 	if (ice_get_q_coalesce(vsi, ec, q_num))
3248 		return -EINVAL;
3249 
3250 	return 0;
3251 }
3252 
3253 static int
3254 ice_get_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3255 {
3256 	return __ice_get_coalesce(netdev, ec, -1);
3257 }
3258 
3259 static int
3260 ice_get_per_q_coalesce(struct net_device *netdev, u32 q_num,
3261 		       struct ethtool_coalesce *ec)
3262 {
3263 	return __ice_get_coalesce(netdev, ec, q_num);
3264 }
3265 
3266 /**
3267  * ice_set_rc_coalesce - set ITR values for specific ring container
3268  * @c_type: container type, Rx or Tx
3269  * @ec: ethtool structure from user to update ITR settings
3270  * @rc: ring container that the ITR values will come from
3271  * @vsi: VSI associated to the ring container
3272  *
3273  * Set specific ITR values. This is done per ice_ring_container because each
3274  * q_vector can have 1 or more rings and all of said ring(s) will have the same
3275  * ITR values.
3276  *
3277  * Returns 0 on success, negative otherwise.
3278  */
3279 static int
3280 ice_set_rc_coalesce(enum ice_container_type c_type, struct ethtool_coalesce *ec,
3281 		    struct ice_ring_container *rc, struct ice_vsi *vsi)
3282 {
3283 	const char *c_type_str = (c_type == ICE_RX_CONTAINER) ? "rx" : "tx";
3284 	u32 use_adaptive_coalesce, coalesce_usecs;
3285 	struct ice_pf *pf = vsi->back;
3286 	u16 itr_setting;
3287 
3288 	if (!rc->ring)
3289 		return -EINVAL;
3290 
3291 	switch (c_type) {
3292 	case ICE_RX_CONTAINER:
3293 		if (ec->rx_coalesce_usecs_high > ICE_MAX_INTRL ||
3294 		    (ec->rx_coalesce_usecs_high &&
3295 		     ec->rx_coalesce_usecs_high < pf->hw.intrl_gran)) {
3296 			netdev_info(vsi->netdev,
3297 				    "Invalid value, %s-usecs-high valid values are 0 (disabled), %d-%d\n",
3298 				    c_type_str, pf->hw.intrl_gran,
3299 				    ICE_MAX_INTRL);
3300 			return -EINVAL;
3301 		}
3302 		if (ec->rx_coalesce_usecs_high != rc->ring->q_vector->intrl) {
3303 			rc->ring->q_vector->intrl = ec->rx_coalesce_usecs_high;
3304 			wr32(&pf->hw, GLINT_RATE(rc->ring->q_vector->reg_idx),
3305 			     ice_intrl_usec_to_reg(ec->rx_coalesce_usecs_high,
3306 						   pf->hw.intrl_gran));
3307 		}
3308 
3309 		use_adaptive_coalesce = ec->use_adaptive_rx_coalesce;
3310 		coalesce_usecs = ec->rx_coalesce_usecs;
3311 
3312 		break;
3313 	case ICE_TX_CONTAINER:
3314 		if (ec->tx_coalesce_usecs_high) {
3315 			netdev_info(vsi->netdev,
3316 				    "setting %s-usecs-high is not supported\n",
3317 				    c_type_str);
3318 			return -EINVAL;
3319 		}
3320 
3321 		use_adaptive_coalesce = ec->use_adaptive_tx_coalesce;
3322 		coalesce_usecs = ec->tx_coalesce_usecs;
3323 
3324 		break;
3325 	default:
3326 		dev_dbg(&pf->pdev->dev, "Invalid container type %d\n", c_type);
3327 		return -EINVAL;
3328 	}
3329 
3330 	itr_setting = rc->itr_setting & ~ICE_ITR_DYNAMIC;
3331 	if (coalesce_usecs != itr_setting && use_adaptive_coalesce) {
3332 		netdev_info(vsi->netdev,
3333 			    "%s interrupt throttling cannot be changed if adaptive-%s is enabled\n",
3334 			    c_type_str, c_type_str);
3335 		return -EINVAL;
3336 	}
3337 
3338 	if (coalesce_usecs > ICE_ITR_MAX) {
3339 		netdev_info(vsi->netdev,
3340 			    "Invalid value, %s-usecs range is 0-%d\n",
3341 			    c_type_str, ICE_ITR_MAX);
3342 		return -EINVAL;
3343 	}
3344 
3345 	/* hardware only supports an ITR granularity of 2us */
3346 	if (coalesce_usecs % 2 != 0) {
3347 		netdev_info(vsi->netdev,
3348 			    "Invalid value, %s-usecs must be even\n",
3349 			    c_type_str);
3350 		return -EINVAL;
3351 	}
3352 
3353 	if (use_adaptive_coalesce) {
3354 		rc->itr_setting |= ICE_ITR_DYNAMIC;
3355 	} else {
3356 		/* store user facing value how it was set */
3357 		rc->itr_setting = coalesce_usecs;
3358 		/* set to static and convert to value HW understands */
3359 		rc->target_itr =
3360 			ITR_TO_REG(ITR_REG_ALIGN(rc->itr_setting));
3361 	}
3362 
3363 	return 0;
3364 }
3365 
3366 /**
3367  * ice_set_q_coalesce - set a queue's ITR/INTRL (coalesce) settings
3368  * @vsi: VSI associated to the queue that need updating
3369  * @ec: coalesce settings to program the device with
3370  * @q_num: update ITR/INTRL (coalesce) settings for this queue number/index
3371  *
3372  * Return 0 on success, and negative under the following conditions:
3373  * 1. Setting Tx or Rx ITR/INTRL (coalesce) settings failed.
3374  * 2. The q_num passed in is not a valid number/index for Tx and Rx rings.
3375  */
3376 static int
3377 ice_set_q_coalesce(struct ice_vsi *vsi, struct ethtool_coalesce *ec, int q_num)
3378 {
3379 	if (q_num < vsi->num_rxq && q_num < vsi->num_txq) {
3380 		if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3381 					&vsi->rx_rings[q_num]->q_vector->rx,
3382 					vsi))
3383 			return -EINVAL;
3384 
3385 		if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3386 					&vsi->tx_rings[q_num]->q_vector->tx,
3387 					vsi))
3388 			return -EINVAL;
3389 	} else if (q_num < vsi->num_rxq) {
3390 		if (ice_set_rc_coalesce(ICE_RX_CONTAINER, ec,
3391 					&vsi->rx_rings[q_num]->q_vector->rx,
3392 					vsi))
3393 			return -EINVAL;
3394 	} else if (q_num < vsi->num_txq) {
3395 		if (ice_set_rc_coalesce(ICE_TX_CONTAINER, ec,
3396 					&vsi->tx_rings[q_num]->q_vector->tx,
3397 					vsi))
3398 			return -EINVAL;
3399 	} else {
3400 		return -EINVAL;
3401 	}
3402 
3403 	return 0;
3404 }
3405 
3406 /**
3407  * __ice_set_coalesce - set ITR/INTRL values for the device
3408  * @netdev: pointer to the netdev associated with this query
3409  * @ec: ethtool structure to fill with driver's coalesce settings
3410  * @q_num: queue number to get the coalesce settings for
3411  *
3412  * If the caller passes in a negative q_num then we set the coalesce settings
3413  * for all Tx/Rx queues, else use the actual q_num passed in.
3414  */
3415 static int
3416 __ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec,
3417 		   int q_num)
3418 {
3419 	struct ice_netdev_priv *np = netdev_priv(netdev);
3420 	struct ice_vsi *vsi = np->vsi;
3421 
3422 	if (q_num < 0) {
3423 		int i;
3424 
3425 		ice_for_each_q_vector(vsi, i) {
3426 			if (ice_set_q_coalesce(vsi, ec, i))
3427 				return -EINVAL;
3428 		}
3429 		goto set_complete;
3430 	}
3431 
3432 	if (ice_set_q_coalesce(vsi, ec, q_num))
3433 		return -EINVAL;
3434 
3435 set_complete:
3436 
3437 	return 0;
3438 }
3439 
3440 static int
3441 ice_set_coalesce(struct net_device *netdev, struct ethtool_coalesce *ec)
3442 {
3443 	return __ice_set_coalesce(netdev, ec, -1);
3444 }
3445 
3446 static int
3447 ice_set_per_q_coalesce(struct net_device *netdev, u32 q_num,
3448 		       struct ethtool_coalesce *ec)
3449 {
3450 	return __ice_set_coalesce(netdev, ec, q_num);
3451 }
3452 
3453 #define ICE_I2C_EEPROM_DEV_ADDR		0xA0
3454 #define ICE_I2C_EEPROM_DEV_ADDR2	0xA2
3455 #define ICE_MODULE_TYPE_SFP		0x03
3456 #define ICE_MODULE_TYPE_QSFP_PLUS	0x0D
3457 #define ICE_MODULE_TYPE_QSFP28		0x11
3458 #define ICE_MODULE_SFF_ADDR_MODE	0x04
3459 #define ICE_MODULE_SFF_DIAG_CAPAB	0x40
3460 #define ICE_MODULE_REVISION_ADDR	0x01
3461 #define ICE_MODULE_SFF_8472_COMP	0x5E
3462 #define ICE_MODULE_SFF_8472_SWAP	0x5C
3463 #define ICE_MODULE_QSFP_MAX_LEN		640
3464 
3465 /**
3466  * ice_get_module_info - get SFF module type and revision information
3467  * @netdev: network interface device structure
3468  * @modinfo: module EEPROM size and layout information structure
3469  */
3470 static int
3471 ice_get_module_info(struct net_device *netdev,
3472 		    struct ethtool_modinfo *modinfo)
3473 {
3474 	struct ice_netdev_priv *np = netdev_priv(netdev);
3475 	struct ice_vsi *vsi = np->vsi;
3476 	struct ice_pf *pf = vsi->back;
3477 	struct ice_hw *hw = &pf->hw;
3478 	enum ice_status status;
3479 	u8 sff8472_comp = 0;
3480 	u8 sff8472_swap = 0;
3481 	u8 sff8636_rev = 0;
3482 	u8 value = 0;
3483 
3484 	status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR, 0x00, 0x00,
3485 				   0, &value, 1, 0, NULL);
3486 	if (status)
3487 		return -EIO;
3488 
3489 	switch (value) {
3490 	case ICE_MODULE_TYPE_SFP:
3491 		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3492 					   ICE_MODULE_SFF_8472_COMP, 0x00, 0,
3493 					   &sff8472_comp, 1, 0, NULL);
3494 		if (status)
3495 			return -EIO;
3496 		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3497 					   ICE_MODULE_SFF_8472_SWAP, 0x00, 0,
3498 					   &sff8472_swap, 1, 0, NULL);
3499 		if (status)
3500 			return -EIO;
3501 
3502 		if (sff8472_swap & ICE_MODULE_SFF_ADDR_MODE) {
3503 			modinfo->type = ETH_MODULE_SFF_8079;
3504 			modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3505 		} else if (sff8472_comp &&
3506 			   (sff8472_swap & ICE_MODULE_SFF_DIAG_CAPAB)) {
3507 			modinfo->type = ETH_MODULE_SFF_8472;
3508 			modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
3509 		} else {
3510 			modinfo->type = ETH_MODULE_SFF_8079;
3511 			modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
3512 		}
3513 		break;
3514 	case ICE_MODULE_TYPE_QSFP_PLUS:
3515 	case ICE_MODULE_TYPE_QSFP28:
3516 		status = ice_aq_sff_eeprom(hw, 0, ICE_I2C_EEPROM_DEV_ADDR,
3517 					   ICE_MODULE_REVISION_ADDR, 0x00, 0,
3518 					   &sff8636_rev, 1, 0, NULL);
3519 		if (status)
3520 			return -EIO;
3521 		/* Check revision compliance */
3522 		if (sff8636_rev > 0x02) {
3523 			/* Module is SFF-8636 compliant */
3524 			modinfo->type = ETH_MODULE_SFF_8636;
3525 			modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3526 		} else {
3527 			modinfo->type = ETH_MODULE_SFF_8436;
3528 			modinfo->eeprom_len = ICE_MODULE_QSFP_MAX_LEN;
3529 		}
3530 		break;
3531 	default:
3532 		netdev_warn(netdev,
3533 			    "SFF Module Type not recognized.\n");
3534 		return -EINVAL;
3535 	}
3536 	return 0;
3537 }
3538 
3539 /**
3540  * ice_get_module_eeprom - fill buffer with SFF EEPROM contents
3541  * @netdev: network interface device structure
3542  * @ee: EEPROM dump request structure
3543  * @data: buffer to be filled with EEPROM contents
3544  */
3545 static int
3546 ice_get_module_eeprom(struct net_device *netdev,
3547 		      struct ethtool_eeprom *ee, u8 *data)
3548 {
3549 	struct ice_netdev_priv *np = netdev_priv(netdev);
3550 	u8 addr = ICE_I2C_EEPROM_DEV_ADDR;
3551 	struct ice_vsi *vsi = np->vsi;
3552 	struct ice_pf *pf = vsi->back;
3553 	struct ice_hw *hw = &pf->hw;
3554 	enum ice_status status;
3555 	bool is_sfp = false;
3556 	u16 offset = 0;
3557 	u8 value = 0;
3558 	u8 page = 0;
3559 	int i;
3560 
3561 	status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, 0,
3562 				   &value, 1, 0, NULL);
3563 	if (status)
3564 		return -EIO;
3565 
3566 	if (!ee || !ee->len || !data)
3567 		return -EINVAL;
3568 
3569 	if (value == ICE_MODULE_TYPE_SFP)
3570 		is_sfp = true;
3571 
3572 	for (i = 0; i < ee->len; i++) {
3573 		offset = i + ee->offset;
3574 
3575 		/* Check if we need to access the other memory page */
3576 		if (is_sfp) {
3577 			if (offset >= ETH_MODULE_SFF_8079_LEN) {
3578 				offset -= ETH_MODULE_SFF_8079_LEN;
3579 				addr = ICE_I2C_EEPROM_DEV_ADDR2;
3580 			}
3581 		} else {
3582 			while (offset >= ETH_MODULE_SFF_8436_LEN) {
3583 				/* Compute memory page number and offset. */
3584 				offset -= ETH_MODULE_SFF_8436_LEN / 2;
3585 				page++;
3586 			}
3587 		}
3588 
3589 		status = ice_aq_sff_eeprom(hw, 0, addr, offset, page, !is_sfp,
3590 					   &value, 1, 0, NULL);
3591 		if (status)
3592 			value = 0;
3593 		data[i] = value;
3594 	}
3595 	return 0;
3596 }
3597 
3598 static const struct ethtool_ops ice_ethtool_ops = {
3599 	.get_link_ksettings	= ice_get_link_ksettings,
3600 	.set_link_ksettings	= ice_set_link_ksettings,
3601 	.get_drvinfo            = ice_get_drvinfo,
3602 	.get_regs_len           = ice_get_regs_len,
3603 	.get_regs               = ice_get_regs,
3604 	.get_msglevel           = ice_get_msglevel,
3605 	.set_msglevel           = ice_set_msglevel,
3606 	.self_test		= ice_self_test,
3607 	.get_link		= ethtool_op_get_link,
3608 	.get_eeprom_len		= ice_get_eeprom_len,
3609 	.get_eeprom		= ice_get_eeprom,
3610 	.get_coalesce		= ice_get_coalesce,
3611 	.set_coalesce		= ice_set_coalesce,
3612 	.get_strings		= ice_get_strings,
3613 	.set_phys_id		= ice_set_phys_id,
3614 	.get_ethtool_stats      = ice_get_ethtool_stats,
3615 	.get_priv_flags		= ice_get_priv_flags,
3616 	.set_priv_flags		= ice_set_priv_flags,
3617 	.get_sset_count		= ice_get_sset_count,
3618 	.get_rxnfc		= ice_get_rxnfc,
3619 	.get_ringparam		= ice_get_ringparam,
3620 	.set_ringparam		= ice_set_ringparam,
3621 	.nway_reset		= ice_nway_reset,
3622 	.get_pauseparam		= ice_get_pauseparam,
3623 	.set_pauseparam		= ice_set_pauseparam,
3624 	.get_rxfh_key_size	= ice_get_rxfh_key_size,
3625 	.get_rxfh_indir_size	= ice_get_rxfh_indir_size,
3626 	.get_rxfh		= ice_get_rxfh,
3627 	.set_rxfh		= ice_set_rxfh,
3628 	.get_ts_info		= ethtool_op_get_ts_info,
3629 	.get_per_queue_coalesce = ice_get_per_q_coalesce,
3630 	.set_per_queue_coalesce = ice_set_per_q_coalesce,
3631 	.get_fecparam		= ice_get_fecparam,
3632 	.set_fecparam		= ice_set_fecparam,
3633 	.get_module_info	= ice_get_module_info,
3634 	.get_module_eeprom	= ice_get_module_eeprom,
3635 };
3636 
3637 static const struct ethtool_ops ice_ethtool_safe_mode_ops = {
3638 	.get_link_ksettings	= ice_get_link_ksettings,
3639 	.set_link_ksettings	= ice_set_link_ksettings,
3640 	.get_drvinfo		= ice_get_drvinfo,
3641 	.get_regs_len		= ice_get_regs_len,
3642 	.get_regs		= ice_get_regs,
3643 	.get_msglevel		= ice_get_msglevel,
3644 	.set_msglevel		= ice_set_msglevel,
3645 	.get_eeprom_len		= ice_get_eeprom_len,
3646 	.get_eeprom		= ice_get_eeprom,
3647 	.get_strings		= ice_get_strings,
3648 	.get_ethtool_stats	= ice_get_ethtool_stats,
3649 	.get_sset_count		= ice_get_sset_count,
3650 	.get_ringparam		= ice_get_ringparam,
3651 	.set_ringparam		= ice_set_ringparam,
3652 	.nway_reset		= ice_nway_reset,
3653 };
3654 
3655 /**
3656  * ice_set_ethtool_safe_mode_ops - setup safe mode ethtool ops
3657  * @netdev: network interface device structure
3658  */
3659 void ice_set_ethtool_safe_mode_ops(struct net_device *netdev)
3660 {
3661 	netdev->ethtool_ops = &ice_ethtool_safe_mode_ops;
3662 }
3663 
3664 /**
3665  * ice_set_ethtool_ops - setup netdev ethtool ops
3666  * @netdev: network interface device structure
3667  *
3668  * setup netdev ethtool ops with ice specific ops
3669  */
3670 void ice_set_ethtool_ops(struct net_device *netdev)
3671 {
3672 	netdev->ethtool_ops = &ice_ethtool_ops;
3673 }
3674