1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
3 
4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */
5 
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 
8 #include "ice.h"
9 #include "ice_base.h"
10 #include "ice_lib.h"
11 #include "ice_dcb_lib.h"
12 #include "ice_dcb_nl.h"
13 
14 #define DRV_VERSION_MAJOR 0
15 #define DRV_VERSION_MINOR 8
16 #define DRV_VERSION_BUILD 1
17 
18 #define DRV_VERSION	__stringify(DRV_VERSION_MAJOR) "." \
19 			__stringify(DRV_VERSION_MINOR) "." \
20 			__stringify(DRV_VERSION_BUILD) "-k"
21 #define DRV_SUMMARY	"Intel(R) Ethernet Connection E800 Series Linux Driver"
22 const char ice_drv_ver[] = DRV_VERSION;
23 static const char ice_driver_string[] = DRV_SUMMARY;
24 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
25 
26 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
27 #define ICE_DDP_PKG_PATH	"intel/ice/ddp/"
28 #define ICE_DDP_PKG_FILE	ICE_DDP_PKG_PATH "ice.pkg"
29 
30 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
31 MODULE_DESCRIPTION(DRV_SUMMARY);
32 MODULE_LICENSE("GPL v2");
33 MODULE_VERSION(DRV_VERSION);
34 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
35 
36 static int debug = -1;
37 module_param(debug, int, 0644);
38 #ifndef CONFIG_DYNAMIC_DEBUG
39 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
40 #else
41 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
42 #endif /* !CONFIG_DYNAMIC_DEBUG */
43 
44 static struct workqueue_struct *ice_wq;
45 static const struct net_device_ops ice_netdev_safe_mode_ops;
46 static const struct net_device_ops ice_netdev_ops;
47 static int ice_vsi_open(struct ice_vsi *vsi);
48 
49 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
50 
51 static void ice_vsi_release_all(struct ice_pf *pf);
52 
53 /**
54  * ice_get_tx_pending - returns number of Tx descriptors not processed
55  * @ring: the ring of descriptors
56  */
57 static u16 ice_get_tx_pending(struct ice_ring *ring)
58 {
59 	u16 head, tail;
60 
61 	head = ring->next_to_clean;
62 	tail = ring->next_to_use;
63 
64 	if (head != tail)
65 		return (head < tail) ?
66 			tail - head : (tail + ring->count - head);
67 	return 0;
68 }
69 
70 /**
71  * ice_check_for_hang_subtask - check for and recover hung queues
72  * @pf: pointer to PF struct
73  */
74 static void ice_check_for_hang_subtask(struct ice_pf *pf)
75 {
76 	struct ice_vsi *vsi = NULL;
77 	struct ice_hw *hw;
78 	unsigned int i;
79 	int packets;
80 	u32 v;
81 
82 	ice_for_each_vsi(pf, v)
83 		if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
84 			vsi = pf->vsi[v];
85 			break;
86 		}
87 
88 	if (!vsi || test_bit(__ICE_DOWN, vsi->state))
89 		return;
90 
91 	if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
92 		return;
93 
94 	hw = &vsi->back->hw;
95 
96 	for (i = 0; i < vsi->num_txq; i++) {
97 		struct ice_ring *tx_ring = vsi->tx_rings[i];
98 
99 		if (tx_ring && tx_ring->desc) {
100 			/* If packet counter has not changed the queue is
101 			 * likely stalled, so force an interrupt for this
102 			 * queue.
103 			 *
104 			 * prev_pkt would be negative if there was no
105 			 * pending work.
106 			 */
107 			packets = tx_ring->stats.pkts & INT_MAX;
108 			if (tx_ring->tx_stats.prev_pkt == packets) {
109 				/* Trigger sw interrupt to revive the queue */
110 				ice_trigger_sw_intr(hw, tx_ring->q_vector);
111 				continue;
112 			}
113 
114 			/* Memory barrier between read of packet count and call
115 			 * to ice_get_tx_pending()
116 			 */
117 			smp_rmb();
118 			tx_ring->tx_stats.prev_pkt =
119 			    ice_get_tx_pending(tx_ring) ? packets : -1;
120 		}
121 	}
122 }
123 
124 /**
125  * ice_init_mac_fltr - Set initial MAC filters
126  * @pf: board private structure
127  *
128  * Set initial set of MAC filters for PF VSI; configure filters for permanent
129  * address and broadcast address. If an error is encountered, netdevice will be
130  * unregistered.
131  */
132 static int ice_init_mac_fltr(struct ice_pf *pf)
133 {
134 	enum ice_status status;
135 	u8 broadcast[ETH_ALEN];
136 	struct ice_vsi *vsi;
137 
138 	vsi = ice_get_main_vsi(pf);
139 	if (!vsi)
140 		return -EINVAL;
141 
142 	/* To add a MAC filter, first add the MAC to a list and then
143 	 * pass the list to ice_add_mac.
144 	 */
145 
146 	 /* Add a unicast MAC filter so the VSI can get its packets */
147 	status = ice_vsi_cfg_mac_fltr(vsi, vsi->port_info->mac.perm_addr, true);
148 	if (status)
149 		goto unregister;
150 
151 	/* VSI needs to receive broadcast traffic, so add the broadcast
152 	 * MAC address to the list as well.
153 	 */
154 	eth_broadcast_addr(broadcast);
155 	status = ice_vsi_cfg_mac_fltr(vsi, broadcast, true);
156 	if (status)
157 		goto unregister;
158 
159 	return 0;
160 unregister:
161 	/* We aren't useful with no MAC filters, so unregister if we
162 	 * had an error
163 	 */
164 	if (status && vsi->netdev->reg_state == NETREG_REGISTERED) {
165 		dev_err(ice_pf_to_dev(pf),
166 			"Could not add MAC filters error %d. Unregistering device\n",
167 			status);
168 		unregister_netdev(vsi->netdev);
169 		free_netdev(vsi->netdev);
170 		vsi->netdev = NULL;
171 	}
172 
173 	return -EIO;
174 }
175 
176 /**
177  * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
178  * @netdev: the net device on which the sync is happening
179  * @addr: MAC address to sync
180  *
181  * This is a callback function which is called by the in kernel device sync
182  * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
183  * populates the tmp_sync_list, which is later used by ice_add_mac to add the
184  * MAC filters from the hardware.
185  */
186 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
187 {
188 	struct ice_netdev_priv *np = netdev_priv(netdev);
189 	struct ice_vsi *vsi = np->vsi;
190 
191 	if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
192 		return -EINVAL;
193 
194 	return 0;
195 }
196 
197 /**
198  * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
199  * @netdev: the net device on which the unsync is happening
200  * @addr: MAC address to unsync
201  *
202  * This is a callback function which is called by the in kernel device unsync
203  * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
204  * populates the tmp_unsync_list, which is later used by ice_remove_mac to
205  * delete the MAC filters from the hardware.
206  */
207 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
208 {
209 	struct ice_netdev_priv *np = netdev_priv(netdev);
210 	struct ice_vsi *vsi = np->vsi;
211 
212 	if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
213 		return -EINVAL;
214 
215 	return 0;
216 }
217 
218 /**
219  * ice_vsi_fltr_changed - check if filter state changed
220  * @vsi: VSI to be checked
221  *
222  * returns true if filter state has changed, false otherwise.
223  */
224 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
225 {
226 	return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
227 	       test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
228 	       test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
229 }
230 
231 /**
232  * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
233  * @vsi: the VSI being configured
234  * @promisc_m: mask of promiscuous config bits
235  * @set_promisc: enable or disable promisc flag request
236  *
237  */
238 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
239 {
240 	struct ice_hw *hw = &vsi->back->hw;
241 	enum ice_status status = 0;
242 
243 	if (vsi->type != ICE_VSI_PF)
244 		return 0;
245 
246 	if (vsi->vlan_ena) {
247 		status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
248 						  set_promisc);
249 	} else {
250 		if (set_promisc)
251 			status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
252 						     0);
253 		else
254 			status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
255 						       0);
256 	}
257 
258 	if (status)
259 		return -EIO;
260 
261 	return 0;
262 }
263 
264 /**
265  * ice_vsi_sync_fltr - Update the VSI filter list to the HW
266  * @vsi: ptr to the VSI
267  *
268  * Push any outstanding VSI filter changes through the AdminQ.
269  */
270 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
271 {
272 	struct device *dev = &vsi->back->pdev->dev;
273 	struct net_device *netdev = vsi->netdev;
274 	bool promisc_forced_on = false;
275 	struct ice_pf *pf = vsi->back;
276 	struct ice_hw *hw = &pf->hw;
277 	enum ice_status status = 0;
278 	u32 changed_flags = 0;
279 	u8 promisc_m;
280 	int err = 0;
281 
282 	if (!vsi->netdev)
283 		return -EINVAL;
284 
285 	while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
286 		usleep_range(1000, 2000);
287 
288 	changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
289 	vsi->current_netdev_flags = vsi->netdev->flags;
290 
291 	INIT_LIST_HEAD(&vsi->tmp_sync_list);
292 	INIT_LIST_HEAD(&vsi->tmp_unsync_list);
293 
294 	if (ice_vsi_fltr_changed(vsi)) {
295 		clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
296 		clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
297 		clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
298 
299 		/* grab the netdev's addr_list_lock */
300 		netif_addr_lock_bh(netdev);
301 		__dev_uc_sync(netdev, ice_add_mac_to_sync_list,
302 			      ice_add_mac_to_unsync_list);
303 		__dev_mc_sync(netdev, ice_add_mac_to_sync_list,
304 			      ice_add_mac_to_unsync_list);
305 		/* our temp lists are populated. release lock */
306 		netif_addr_unlock_bh(netdev);
307 	}
308 
309 	/* Remove MAC addresses in the unsync list */
310 	status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
311 	ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
312 	if (status) {
313 		netdev_err(netdev, "Failed to delete MAC filters\n");
314 		/* if we failed because of alloc failures, just bail */
315 		if (status == ICE_ERR_NO_MEMORY) {
316 			err = -ENOMEM;
317 			goto out;
318 		}
319 	}
320 
321 	/* Add MAC addresses in the sync list */
322 	status = ice_add_mac(hw, &vsi->tmp_sync_list);
323 	ice_free_fltr_list(dev, &vsi->tmp_sync_list);
324 	/* If filter is added successfully or already exists, do not go into
325 	 * 'if' condition and report it as error. Instead continue processing
326 	 * rest of the function.
327 	 */
328 	if (status && status != ICE_ERR_ALREADY_EXISTS) {
329 		netdev_err(netdev, "Failed to add MAC filters\n");
330 		/* If there is no more space for new umac filters, VSI
331 		 * should go into promiscuous mode. There should be some
332 		 * space reserved for promiscuous filters.
333 		 */
334 		if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
335 		    !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
336 				      vsi->state)) {
337 			promisc_forced_on = true;
338 			netdev_warn(netdev,
339 				    "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
340 				    vsi->vsi_num);
341 		} else {
342 			err = -EIO;
343 			goto out;
344 		}
345 	}
346 	/* check for changes in promiscuous modes */
347 	if (changed_flags & IFF_ALLMULTI) {
348 		if (vsi->current_netdev_flags & IFF_ALLMULTI) {
349 			if (vsi->vlan_ena)
350 				promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
351 			else
352 				promisc_m = ICE_MCAST_PROMISC_BITS;
353 
354 			err = ice_cfg_promisc(vsi, promisc_m, true);
355 			if (err) {
356 				netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
357 					   vsi->vsi_num);
358 				vsi->current_netdev_flags &= ~IFF_ALLMULTI;
359 				goto out_promisc;
360 			}
361 		} else if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
362 			if (vsi->vlan_ena)
363 				promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
364 			else
365 				promisc_m = ICE_MCAST_PROMISC_BITS;
366 
367 			err = ice_cfg_promisc(vsi, promisc_m, false);
368 			if (err) {
369 				netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
370 					   vsi->vsi_num);
371 				vsi->current_netdev_flags |= IFF_ALLMULTI;
372 				goto out_promisc;
373 			}
374 		}
375 	}
376 
377 	if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
378 	    test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
379 		clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
380 		if (vsi->current_netdev_flags & IFF_PROMISC) {
381 			/* Apply Rx filter rule to get traffic from wire */
382 			status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
383 						  ICE_FLTR_RX);
384 			if (status) {
385 				netdev_err(netdev, "Error setting default VSI %i Rx rule\n",
386 					   vsi->vsi_num);
387 				vsi->current_netdev_flags &= ~IFF_PROMISC;
388 				err = -EIO;
389 				goto out_promisc;
390 			}
391 		} else {
392 			/* Clear Rx filter to remove traffic from wire */
393 			status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
394 						  ICE_FLTR_RX);
395 			if (status) {
396 				netdev_err(netdev, "Error clearing default VSI %i Rx rule\n",
397 					   vsi->vsi_num);
398 				vsi->current_netdev_flags |= IFF_PROMISC;
399 				err = -EIO;
400 				goto out_promisc;
401 			}
402 		}
403 	}
404 	goto exit;
405 
406 out_promisc:
407 	set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
408 	goto exit;
409 out:
410 	/* if something went wrong then set the changed flag so we try again */
411 	set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
412 	set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
413 exit:
414 	clear_bit(__ICE_CFG_BUSY, vsi->state);
415 	return err;
416 }
417 
418 /**
419  * ice_sync_fltr_subtask - Sync the VSI filter list with HW
420  * @pf: board private structure
421  */
422 static void ice_sync_fltr_subtask(struct ice_pf *pf)
423 {
424 	int v;
425 
426 	if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
427 		return;
428 
429 	clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
430 
431 	ice_for_each_vsi(pf, v)
432 		if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
433 		    ice_vsi_sync_fltr(pf->vsi[v])) {
434 			/* come back and try again later */
435 			set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
436 			break;
437 		}
438 }
439 
440 /**
441  * ice_pf_dis_all_vsi - Pause all VSIs on a PF
442  * @pf: the PF
443  * @locked: is the rtnl_lock already held
444  */
445 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
446 {
447 	int v;
448 
449 	ice_for_each_vsi(pf, v)
450 		if (pf->vsi[v])
451 			ice_dis_vsi(pf->vsi[v], locked);
452 }
453 
454 /**
455  * ice_prepare_for_reset - prep for the core to reset
456  * @pf: board private structure
457  *
458  * Inform or close all dependent features in prep for reset.
459  */
460 static void
461 ice_prepare_for_reset(struct ice_pf *pf)
462 {
463 	struct ice_hw *hw = &pf->hw;
464 	int i;
465 
466 	/* already prepared for reset */
467 	if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
468 		return;
469 
470 	/* Notify VFs of impending reset */
471 	if (ice_check_sq_alive(hw, &hw->mailboxq))
472 		ice_vc_notify_reset(pf);
473 
474 	/* Disable VFs until reset is completed */
475 	for (i = 0; i < pf->num_alloc_vfs; i++)
476 		ice_set_vf_state_qs_dis(&pf->vf[i]);
477 
478 	/* clear SW filtering DB */
479 	ice_clear_hw_tbls(hw);
480 	/* disable the VSIs and their queues that are not already DOWN */
481 	ice_pf_dis_all_vsi(pf, false);
482 
483 	if (hw->port_info)
484 		ice_sched_clear_port(hw->port_info);
485 
486 	ice_shutdown_all_ctrlq(hw);
487 
488 	set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
489 }
490 
491 /**
492  * ice_do_reset - Initiate one of many types of resets
493  * @pf: board private structure
494  * @reset_type: reset type requested
495  * before this function was called.
496  */
497 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
498 {
499 	struct device *dev = ice_pf_to_dev(pf);
500 	struct ice_hw *hw = &pf->hw;
501 
502 	dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
503 	WARN_ON(in_interrupt());
504 
505 	ice_prepare_for_reset(pf);
506 
507 	/* trigger the reset */
508 	if (ice_reset(hw, reset_type)) {
509 		dev_err(dev, "reset %d failed\n", reset_type);
510 		set_bit(__ICE_RESET_FAILED, pf->state);
511 		clear_bit(__ICE_RESET_OICR_RECV, pf->state);
512 		clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
513 		clear_bit(__ICE_PFR_REQ, pf->state);
514 		clear_bit(__ICE_CORER_REQ, pf->state);
515 		clear_bit(__ICE_GLOBR_REQ, pf->state);
516 		return;
517 	}
518 
519 	/* PFR is a bit of a special case because it doesn't result in an OICR
520 	 * interrupt. So for PFR, rebuild after the reset and clear the reset-
521 	 * associated state bits.
522 	 */
523 	if (reset_type == ICE_RESET_PFR) {
524 		pf->pfr_count++;
525 		ice_rebuild(pf, reset_type);
526 		clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
527 		clear_bit(__ICE_PFR_REQ, pf->state);
528 		ice_reset_all_vfs(pf, true);
529 	}
530 }
531 
532 /**
533  * ice_reset_subtask - Set up for resetting the device and driver
534  * @pf: board private structure
535  */
536 static void ice_reset_subtask(struct ice_pf *pf)
537 {
538 	enum ice_reset_req reset_type = ICE_RESET_INVAL;
539 
540 	/* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
541 	 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
542 	 * of reset is pending and sets bits in pf->state indicating the reset
543 	 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
544 	 * prepare for pending reset if not already (for PF software-initiated
545 	 * global resets the software should already be prepared for it as
546 	 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
547 	 * by firmware or software on other PFs, that bit is not set so prepare
548 	 * for the reset now), poll for reset done, rebuild and return.
549 	 */
550 	if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
551 		/* Perform the largest reset requested */
552 		if (test_and_clear_bit(__ICE_CORER_RECV, pf->state))
553 			reset_type = ICE_RESET_CORER;
554 		if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state))
555 			reset_type = ICE_RESET_GLOBR;
556 		if (test_and_clear_bit(__ICE_EMPR_RECV, pf->state))
557 			reset_type = ICE_RESET_EMPR;
558 		/* return if no valid reset type requested */
559 		if (reset_type == ICE_RESET_INVAL)
560 			return;
561 		ice_prepare_for_reset(pf);
562 
563 		/* make sure we are ready to rebuild */
564 		if (ice_check_reset(&pf->hw)) {
565 			set_bit(__ICE_RESET_FAILED, pf->state);
566 		} else {
567 			/* done with reset. start rebuild */
568 			pf->hw.reset_ongoing = false;
569 			ice_rebuild(pf, reset_type);
570 			/* clear bit to resume normal operations, but
571 			 * ICE_NEEDS_RESTART bit is set in case rebuild failed
572 			 */
573 			clear_bit(__ICE_RESET_OICR_RECV, pf->state);
574 			clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
575 			clear_bit(__ICE_PFR_REQ, pf->state);
576 			clear_bit(__ICE_CORER_REQ, pf->state);
577 			clear_bit(__ICE_GLOBR_REQ, pf->state);
578 			ice_reset_all_vfs(pf, true);
579 		}
580 
581 		return;
582 	}
583 
584 	/* No pending resets to finish processing. Check for new resets */
585 	if (test_bit(__ICE_PFR_REQ, pf->state))
586 		reset_type = ICE_RESET_PFR;
587 	if (test_bit(__ICE_CORER_REQ, pf->state))
588 		reset_type = ICE_RESET_CORER;
589 	if (test_bit(__ICE_GLOBR_REQ, pf->state))
590 		reset_type = ICE_RESET_GLOBR;
591 	/* If no valid reset type requested just return */
592 	if (reset_type == ICE_RESET_INVAL)
593 		return;
594 
595 	/* reset if not already down or busy */
596 	if (!test_bit(__ICE_DOWN, pf->state) &&
597 	    !test_bit(__ICE_CFG_BUSY, pf->state)) {
598 		ice_do_reset(pf, reset_type);
599 	}
600 }
601 
602 /**
603  * ice_print_topo_conflict - print topology conflict message
604  * @vsi: the VSI whose topology status is being checked
605  */
606 static void ice_print_topo_conflict(struct ice_vsi *vsi)
607 {
608 	switch (vsi->port_info->phy.link_info.topo_media_conflict) {
609 	case ICE_AQ_LINK_TOPO_CONFLICT:
610 	case ICE_AQ_LINK_MEDIA_CONFLICT:
611 	case ICE_AQ_LINK_TOPO_UNREACH_PRT:
612 	case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
613 	case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
614 		netdev_info(vsi->netdev, "Possible mis-configuration of the Ethernet port detected, please use the Intel(R) Ethernet Port Configuration Tool application to address the issue.\n");
615 		break;
616 	case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
617 		netdev_info(vsi->netdev, "Rx/Tx is disabled on this device because an unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
618 		break;
619 	default:
620 		break;
621 	}
622 }
623 
624 /**
625  * ice_print_link_msg - print link up or down message
626  * @vsi: the VSI whose link status is being queried
627  * @isup: boolean for if the link is now up or down
628  */
629 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
630 {
631 	struct ice_aqc_get_phy_caps_data *caps;
632 	enum ice_status status;
633 	const char *fec_req;
634 	const char *speed;
635 	const char *fec;
636 	const char *fc;
637 	const char *an;
638 
639 	if (!vsi)
640 		return;
641 
642 	if (vsi->current_isup == isup)
643 		return;
644 
645 	vsi->current_isup = isup;
646 
647 	if (!isup) {
648 		netdev_info(vsi->netdev, "NIC Link is Down\n");
649 		return;
650 	}
651 
652 	switch (vsi->port_info->phy.link_info.link_speed) {
653 	case ICE_AQ_LINK_SPEED_100GB:
654 		speed = "100 G";
655 		break;
656 	case ICE_AQ_LINK_SPEED_50GB:
657 		speed = "50 G";
658 		break;
659 	case ICE_AQ_LINK_SPEED_40GB:
660 		speed = "40 G";
661 		break;
662 	case ICE_AQ_LINK_SPEED_25GB:
663 		speed = "25 G";
664 		break;
665 	case ICE_AQ_LINK_SPEED_20GB:
666 		speed = "20 G";
667 		break;
668 	case ICE_AQ_LINK_SPEED_10GB:
669 		speed = "10 G";
670 		break;
671 	case ICE_AQ_LINK_SPEED_5GB:
672 		speed = "5 G";
673 		break;
674 	case ICE_AQ_LINK_SPEED_2500MB:
675 		speed = "2.5 G";
676 		break;
677 	case ICE_AQ_LINK_SPEED_1000MB:
678 		speed = "1 G";
679 		break;
680 	case ICE_AQ_LINK_SPEED_100MB:
681 		speed = "100 M";
682 		break;
683 	default:
684 		speed = "Unknown";
685 		break;
686 	}
687 
688 	switch (vsi->port_info->fc.current_mode) {
689 	case ICE_FC_FULL:
690 		fc = "Rx/Tx";
691 		break;
692 	case ICE_FC_TX_PAUSE:
693 		fc = "Tx";
694 		break;
695 	case ICE_FC_RX_PAUSE:
696 		fc = "Rx";
697 		break;
698 	case ICE_FC_NONE:
699 		fc = "None";
700 		break;
701 	default:
702 		fc = "Unknown";
703 		break;
704 	}
705 
706 	/* Get FEC mode based on negotiated link info */
707 	switch (vsi->port_info->phy.link_info.fec_info) {
708 	case ICE_AQ_LINK_25G_RS_528_FEC_EN:
709 		/* fall through */
710 	case ICE_AQ_LINK_25G_RS_544_FEC_EN:
711 		fec = "RS-FEC";
712 		break;
713 	case ICE_AQ_LINK_25G_KR_FEC_EN:
714 		fec = "FC-FEC/BASE-R";
715 		break;
716 	default:
717 		fec = "NONE";
718 		break;
719 	}
720 
721 	/* check if autoneg completed, might be false due to not supported */
722 	if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
723 		an = "True";
724 	else
725 		an = "False";
726 
727 	/* Get FEC mode requested based on PHY caps last SW configuration */
728 	caps = kzalloc(sizeof(*caps), GFP_KERNEL);
729 	if (!caps) {
730 		fec_req = "Unknown";
731 		goto done;
732 	}
733 
734 	status = ice_aq_get_phy_caps(vsi->port_info, false,
735 				     ICE_AQC_REPORT_SW_CFG, caps, NULL);
736 	if (status)
737 		netdev_info(vsi->netdev, "Get phy capability failed.\n");
738 
739 	if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
740 	    caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
741 		fec_req = "RS-FEC";
742 	else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
743 		 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
744 		fec_req = "FC-FEC/BASE-R";
745 	else
746 		fec_req = "NONE";
747 
748 	kfree(caps);
749 
750 done:
751 	netdev_info(vsi->netdev, "NIC Link is up %sbps, Requested FEC: %s, FEC: %s, Autoneg: %s, Flow Control: %s\n",
752 		    speed, fec_req, fec, an, fc);
753 	ice_print_topo_conflict(vsi);
754 }
755 
756 /**
757  * ice_vsi_link_event - update the VSI's netdev
758  * @vsi: the VSI on which the link event occurred
759  * @link_up: whether or not the VSI needs to be set up or down
760  */
761 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
762 {
763 	if (!vsi)
764 		return;
765 
766 	if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
767 		return;
768 
769 	if (vsi->type == ICE_VSI_PF) {
770 		if (link_up == netif_carrier_ok(vsi->netdev))
771 			return;
772 
773 		if (link_up) {
774 			netif_carrier_on(vsi->netdev);
775 			netif_tx_wake_all_queues(vsi->netdev);
776 		} else {
777 			netif_carrier_off(vsi->netdev);
778 			netif_tx_stop_all_queues(vsi->netdev);
779 		}
780 	}
781 }
782 
783 /**
784  * ice_link_event - process the link event
785  * @pf: PF that the link event is associated with
786  * @pi: port_info for the port that the link event is associated with
787  * @link_up: true if the physical link is up and false if it is down
788  * @link_speed: current link speed received from the link event
789  *
790  * Returns 0 on success and negative on failure
791  */
792 static int
793 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
794 	       u16 link_speed)
795 {
796 	struct device *dev = ice_pf_to_dev(pf);
797 	struct ice_phy_info *phy_info;
798 	struct ice_vsi *vsi;
799 	u16 old_link_speed;
800 	bool old_link;
801 	int result;
802 
803 	phy_info = &pi->phy;
804 	phy_info->link_info_old = phy_info->link_info;
805 
806 	old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
807 	old_link_speed = phy_info->link_info_old.link_speed;
808 
809 	/* update the link info structures and re-enable link events,
810 	 * don't bail on failure due to other book keeping needed
811 	 */
812 	result = ice_update_link_info(pi);
813 	if (result)
814 		dev_dbg(dev,
815 			"Failed to update link status and re-enable link events for port %d\n",
816 			pi->lport);
817 
818 	/* if the old link up/down and speed is the same as the new */
819 	if (link_up == old_link && link_speed == old_link_speed)
820 		return result;
821 
822 	vsi = ice_get_main_vsi(pf);
823 	if (!vsi || !vsi->port_info)
824 		return -EINVAL;
825 
826 	/* turn off PHY if media was removed */
827 	if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
828 	    !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
829 		set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
830 
831 		result = ice_aq_set_link_restart_an(pi, false, NULL);
832 		if (result) {
833 			dev_dbg(dev,
834 				"Failed to set link down, VSI %d error %d\n",
835 				vsi->vsi_num, result);
836 			return result;
837 		}
838 	}
839 
840 	ice_vsi_link_event(vsi, link_up);
841 	ice_print_link_msg(vsi, link_up);
842 
843 	if (pf->num_alloc_vfs)
844 		ice_vc_notify_link_state(pf);
845 
846 	return result;
847 }
848 
849 /**
850  * ice_watchdog_subtask - periodic tasks not using event driven scheduling
851  * @pf: board private structure
852  */
853 static void ice_watchdog_subtask(struct ice_pf *pf)
854 {
855 	int i;
856 
857 	/* if interface is down do nothing */
858 	if (test_bit(__ICE_DOWN, pf->state) ||
859 	    test_bit(__ICE_CFG_BUSY, pf->state))
860 		return;
861 
862 	/* make sure we don't do these things too often */
863 	if (time_before(jiffies,
864 			pf->serv_tmr_prev + pf->serv_tmr_period))
865 		return;
866 
867 	pf->serv_tmr_prev = jiffies;
868 
869 	/* Update the stats for active netdevs so the network stack
870 	 * can look at updated numbers whenever it cares to
871 	 */
872 	ice_update_pf_stats(pf);
873 	ice_for_each_vsi(pf, i)
874 		if (pf->vsi[i] && pf->vsi[i]->netdev)
875 			ice_update_vsi_stats(pf->vsi[i]);
876 }
877 
878 /**
879  * ice_init_link_events - enable/initialize link events
880  * @pi: pointer to the port_info instance
881  *
882  * Returns -EIO on failure, 0 on success
883  */
884 static int ice_init_link_events(struct ice_port_info *pi)
885 {
886 	u16 mask;
887 
888 	mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
889 		       ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
890 
891 	if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
892 		dev_dbg(ice_hw_to_dev(pi->hw),
893 			"Failed to set link event mask for port %d\n",
894 			pi->lport);
895 		return -EIO;
896 	}
897 
898 	if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
899 		dev_dbg(ice_hw_to_dev(pi->hw),
900 			"Failed to enable link events for port %d\n",
901 			pi->lport);
902 		return -EIO;
903 	}
904 
905 	return 0;
906 }
907 
908 /**
909  * ice_handle_link_event - handle link event via ARQ
910  * @pf: PF that the link event is associated with
911  * @event: event structure containing link status info
912  */
913 static int
914 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
915 {
916 	struct ice_aqc_get_link_status_data *link_data;
917 	struct ice_port_info *port_info;
918 	int status;
919 
920 	link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
921 	port_info = pf->hw.port_info;
922 	if (!port_info)
923 		return -EINVAL;
924 
925 	status = ice_link_event(pf, port_info,
926 				!!(link_data->link_info & ICE_AQ_LINK_UP),
927 				le16_to_cpu(link_data->link_speed));
928 	if (status)
929 		dev_dbg(ice_pf_to_dev(pf),
930 			"Could not process link event, error %d\n", status);
931 
932 	return status;
933 }
934 
935 /**
936  * __ice_clean_ctrlq - helper function to clean controlq rings
937  * @pf: ptr to struct ice_pf
938  * @q_type: specific Control queue type
939  */
940 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
941 {
942 	struct device *dev = ice_pf_to_dev(pf);
943 	struct ice_rq_event_info event;
944 	struct ice_hw *hw = &pf->hw;
945 	struct ice_ctl_q_info *cq;
946 	u16 pending, i = 0;
947 	const char *qtype;
948 	u32 oldval, val;
949 
950 	/* Do not clean control queue if/when PF reset fails */
951 	if (test_bit(__ICE_RESET_FAILED, pf->state))
952 		return 0;
953 
954 	switch (q_type) {
955 	case ICE_CTL_Q_ADMIN:
956 		cq = &hw->adminq;
957 		qtype = "Admin";
958 		break;
959 	case ICE_CTL_Q_MAILBOX:
960 		cq = &hw->mailboxq;
961 		qtype = "Mailbox";
962 		break;
963 	default:
964 		dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
965 		return 0;
966 	}
967 
968 	/* check for error indications - PF_xx_AxQLEN register layout for
969 	 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
970 	 */
971 	val = rd32(hw, cq->rq.len);
972 	if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
973 		   PF_FW_ARQLEN_ARQCRIT_M)) {
974 		oldval = val;
975 		if (val & PF_FW_ARQLEN_ARQVFE_M)
976 			dev_dbg(dev, "%s Receive Queue VF Error detected\n",
977 				qtype);
978 		if (val & PF_FW_ARQLEN_ARQOVFL_M) {
979 			dev_dbg(dev,
980 				"%s Receive Queue Overflow Error detected\n",
981 				qtype);
982 		}
983 		if (val & PF_FW_ARQLEN_ARQCRIT_M)
984 			dev_dbg(dev,
985 				"%s Receive Queue Critical Error detected\n",
986 				qtype);
987 		val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
988 			 PF_FW_ARQLEN_ARQCRIT_M);
989 		if (oldval != val)
990 			wr32(hw, cq->rq.len, val);
991 	}
992 
993 	val = rd32(hw, cq->sq.len);
994 	if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
995 		   PF_FW_ATQLEN_ATQCRIT_M)) {
996 		oldval = val;
997 		if (val & PF_FW_ATQLEN_ATQVFE_M)
998 			dev_dbg(dev,
999 				"%s Send Queue VF Error detected\n", qtype);
1000 		if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1001 			dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1002 				qtype);
1003 		}
1004 		if (val & PF_FW_ATQLEN_ATQCRIT_M)
1005 			dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1006 				qtype);
1007 		val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1008 			 PF_FW_ATQLEN_ATQCRIT_M);
1009 		if (oldval != val)
1010 			wr32(hw, cq->sq.len, val);
1011 	}
1012 
1013 	event.buf_len = cq->rq_buf_size;
1014 	event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1015 	if (!event.msg_buf)
1016 		return 0;
1017 
1018 	do {
1019 		enum ice_status ret;
1020 		u16 opcode;
1021 
1022 		ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1023 		if (ret == ICE_ERR_AQ_NO_WORK)
1024 			break;
1025 		if (ret) {
1026 			dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1027 				ret);
1028 			break;
1029 		}
1030 
1031 		opcode = le16_to_cpu(event.desc.opcode);
1032 
1033 		switch (opcode) {
1034 		case ice_aqc_opc_get_link_status:
1035 			if (ice_handle_link_event(pf, &event))
1036 				dev_err(dev, "Could not handle link event\n");
1037 			break;
1038 		case ice_mbx_opc_send_msg_to_pf:
1039 			ice_vc_process_vf_msg(pf, &event);
1040 			break;
1041 		case ice_aqc_opc_fw_logging:
1042 			ice_output_fw_log(hw, &event.desc, event.msg_buf);
1043 			break;
1044 		case ice_aqc_opc_lldp_set_mib_change:
1045 			ice_dcb_process_lldp_set_mib_change(pf, &event);
1046 			break;
1047 		default:
1048 			dev_dbg(dev,
1049 				"%s Receive Queue unknown event 0x%04x ignored\n",
1050 				qtype, opcode);
1051 			break;
1052 		}
1053 	} while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1054 
1055 	kfree(event.msg_buf);
1056 
1057 	return pending && (i == ICE_DFLT_IRQ_WORK);
1058 }
1059 
1060 /**
1061  * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1062  * @hw: pointer to hardware info
1063  * @cq: control queue information
1064  *
1065  * returns true if there are pending messages in a queue, false if there aren't
1066  */
1067 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1068 {
1069 	u16 ntu;
1070 
1071 	ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1072 	return cq->rq.next_to_clean != ntu;
1073 }
1074 
1075 /**
1076  * ice_clean_adminq_subtask - clean the AdminQ rings
1077  * @pf: board private structure
1078  */
1079 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1080 {
1081 	struct ice_hw *hw = &pf->hw;
1082 
1083 	if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1084 		return;
1085 
1086 	if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1087 		return;
1088 
1089 	clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1090 
1091 	/* There might be a situation where new messages arrive to a control
1092 	 * queue between processing the last message and clearing the
1093 	 * EVENT_PENDING bit. So before exiting, check queue head again (using
1094 	 * ice_ctrlq_pending) and process new messages if any.
1095 	 */
1096 	if (ice_ctrlq_pending(hw, &hw->adminq))
1097 		__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1098 
1099 	ice_flush(hw);
1100 }
1101 
1102 /**
1103  * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1104  * @pf: board private structure
1105  */
1106 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1107 {
1108 	struct ice_hw *hw = &pf->hw;
1109 
1110 	if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1111 		return;
1112 
1113 	if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1114 		return;
1115 
1116 	clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1117 
1118 	if (ice_ctrlq_pending(hw, &hw->mailboxq))
1119 		__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1120 
1121 	ice_flush(hw);
1122 }
1123 
1124 /**
1125  * ice_service_task_schedule - schedule the service task to wake up
1126  * @pf: board private structure
1127  *
1128  * If not already scheduled, this puts the task into the work queue.
1129  */
1130 static void ice_service_task_schedule(struct ice_pf *pf)
1131 {
1132 	if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1133 	    !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1134 	    !test_bit(__ICE_NEEDS_RESTART, pf->state))
1135 		queue_work(ice_wq, &pf->serv_task);
1136 }
1137 
1138 /**
1139  * ice_service_task_complete - finish up the service task
1140  * @pf: board private structure
1141  */
1142 static void ice_service_task_complete(struct ice_pf *pf)
1143 {
1144 	WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1145 
1146 	/* force memory (pf->state) to sync before next service task */
1147 	smp_mb__before_atomic();
1148 	clear_bit(__ICE_SERVICE_SCHED, pf->state);
1149 }
1150 
1151 /**
1152  * ice_service_task_stop - stop service task and cancel works
1153  * @pf: board private structure
1154  */
1155 static void ice_service_task_stop(struct ice_pf *pf)
1156 {
1157 	set_bit(__ICE_SERVICE_DIS, pf->state);
1158 
1159 	if (pf->serv_tmr.function)
1160 		del_timer_sync(&pf->serv_tmr);
1161 	if (pf->serv_task.func)
1162 		cancel_work_sync(&pf->serv_task);
1163 
1164 	clear_bit(__ICE_SERVICE_SCHED, pf->state);
1165 }
1166 
1167 /**
1168  * ice_service_task_restart - restart service task and schedule works
1169  * @pf: board private structure
1170  *
1171  * This function is needed for suspend and resume works (e.g WoL scenario)
1172  */
1173 static void ice_service_task_restart(struct ice_pf *pf)
1174 {
1175 	clear_bit(__ICE_SERVICE_DIS, pf->state);
1176 	ice_service_task_schedule(pf);
1177 }
1178 
1179 /**
1180  * ice_service_timer - timer callback to schedule service task
1181  * @t: pointer to timer_list
1182  */
1183 static void ice_service_timer(struct timer_list *t)
1184 {
1185 	struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1186 
1187 	mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1188 	ice_service_task_schedule(pf);
1189 }
1190 
1191 /**
1192  * ice_handle_mdd_event - handle malicious driver detect event
1193  * @pf: pointer to the PF structure
1194  *
1195  * Called from service task. OICR interrupt handler indicates MDD event
1196  */
1197 static void ice_handle_mdd_event(struct ice_pf *pf)
1198 {
1199 	struct device *dev = ice_pf_to_dev(pf);
1200 	struct ice_hw *hw = &pf->hw;
1201 	bool mdd_detected = false;
1202 	u32 reg;
1203 	int i;
1204 
1205 	if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1206 		return;
1207 
1208 	/* find what triggered the MDD event */
1209 	reg = rd32(hw, GL_MDET_TX_PQM);
1210 	if (reg & GL_MDET_TX_PQM_VALID_M) {
1211 		u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1212 				GL_MDET_TX_PQM_PF_NUM_S;
1213 		u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1214 				GL_MDET_TX_PQM_VF_NUM_S;
1215 		u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1216 				GL_MDET_TX_PQM_MAL_TYPE_S;
1217 		u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1218 				GL_MDET_TX_PQM_QNUM_S);
1219 
1220 		if (netif_msg_tx_err(pf))
1221 			dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1222 				 event, queue, pf_num, vf_num);
1223 		wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1224 		mdd_detected = true;
1225 	}
1226 
1227 	reg = rd32(hw, GL_MDET_TX_TCLAN);
1228 	if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1229 		u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1230 				GL_MDET_TX_TCLAN_PF_NUM_S;
1231 		u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1232 				GL_MDET_TX_TCLAN_VF_NUM_S;
1233 		u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1234 				GL_MDET_TX_TCLAN_MAL_TYPE_S;
1235 		u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1236 				GL_MDET_TX_TCLAN_QNUM_S);
1237 
1238 		if (netif_msg_rx_err(pf))
1239 			dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1240 				 event, queue, pf_num, vf_num);
1241 		wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1242 		mdd_detected = true;
1243 	}
1244 
1245 	reg = rd32(hw, GL_MDET_RX);
1246 	if (reg & GL_MDET_RX_VALID_M) {
1247 		u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1248 				GL_MDET_RX_PF_NUM_S;
1249 		u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1250 				GL_MDET_RX_VF_NUM_S;
1251 		u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1252 				GL_MDET_RX_MAL_TYPE_S;
1253 		u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1254 				GL_MDET_RX_QNUM_S);
1255 
1256 		if (netif_msg_rx_err(pf))
1257 			dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1258 				 event, queue, pf_num, vf_num);
1259 		wr32(hw, GL_MDET_RX, 0xffffffff);
1260 		mdd_detected = true;
1261 	}
1262 
1263 	if (mdd_detected) {
1264 		bool pf_mdd_detected = false;
1265 
1266 		reg = rd32(hw, PF_MDET_TX_PQM);
1267 		if (reg & PF_MDET_TX_PQM_VALID_M) {
1268 			wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1269 			dev_info(dev, "TX driver issue detected, PF reset issued\n");
1270 			pf_mdd_detected = true;
1271 		}
1272 
1273 		reg = rd32(hw, PF_MDET_TX_TCLAN);
1274 		if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1275 			wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1276 			dev_info(dev, "TX driver issue detected, PF reset issued\n");
1277 			pf_mdd_detected = true;
1278 		}
1279 
1280 		reg = rd32(hw, PF_MDET_RX);
1281 		if (reg & PF_MDET_RX_VALID_M) {
1282 			wr32(hw, PF_MDET_RX, 0xFFFF);
1283 			dev_info(dev, "RX driver issue detected, PF reset issued\n");
1284 			pf_mdd_detected = true;
1285 		}
1286 		/* Queue belongs to the PF initiate a reset */
1287 		if (pf_mdd_detected) {
1288 			set_bit(__ICE_NEEDS_RESTART, pf->state);
1289 			ice_service_task_schedule(pf);
1290 		}
1291 	}
1292 
1293 	/* check to see if one of the VFs caused the MDD */
1294 	for (i = 0; i < pf->num_alloc_vfs; i++) {
1295 		struct ice_vf *vf = &pf->vf[i];
1296 
1297 		bool vf_mdd_detected = false;
1298 
1299 		reg = rd32(hw, VP_MDET_TX_PQM(i));
1300 		if (reg & VP_MDET_TX_PQM_VALID_M) {
1301 			wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1302 			vf_mdd_detected = true;
1303 			dev_info(dev, "TX driver issue detected on VF %d\n",
1304 				 i);
1305 		}
1306 
1307 		reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1308 		if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1309 			wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1310 			vf_mdd_detected = true;
1311 			dev_info(dev, "TX driver issue detected on VF %d\n",
1312 				 i);
1313 		}
1314 
1315 		reg = rd32(hw, VP_MDET_TX_TDPU(i));
1316 		if (reg & VP_MDET_TX_TDPU_VALID_M) {
1317 			wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1318 			vf_mdd_detected = true;
1319 			dev_info(dev, "TX driver issue detected on VF %d\n",
1320 				 i);
1321 		}
1322 
1323 		reg = rd32(hw, VP_MDET_RX(i));
1324 		if (reg & VP_MDET_RX_VALID_M) {
1325 			wr32(hw, VP_MDET_RX(i), 0xFFFF);
1326 			vf_mdd_detected = true;
1327 			dev_info(dev, "RX driver issue detected on VF %d\n",
1328 				 i);
1329 		}
1330 
1331 		if (vf_mdd_detected) {
1332 			vf->num_mdd_events++;
1333 			if (vf->num_mdd_events &&
1334 			    vf->num_mdd_events <= ICE_MDD_EVENTS_THRESHOLD)
1335 				dev_info(dev,
1336 					 "VF %d has had %llu MDD events since last boot, Admin might need to reload AVF driver with this number of events\n",
1337 					 i, vf->num_mdd_events);
1338 		}
1339 	}
1340 }
1341 
1342 /**
1343  * ice_force_phys_link_state - Force the physical link state
1344  * @vsi: VSI to force the physical link state to up/down
1345  * @link_up: true/false indicates to set the physical link to up/down
1346  *
1347  * Force the physical link state by getting the current PHY capabilities from
1348  * hardware and setting the PHY config based on the determined capabilities. If
1349  * link changes a link event will be triggered because both the Enable Automatic
1350  * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1351  *
1352  * Returns 0 on success, negative on failure
1353  */
1354 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1355 {
1356 	struct ice_aqc_get_phy_caps_data *pcaps;
1357 	struct ice_aqc_set_phy_cfg_data *cfg;
1358 	struct ice_port_info *pi;
1359 	struct device *dev;
1360 	int retcode;
1361 
1362 	if (!vsi || !vsi->port_info || !vsi->back)
1363 		return -EINVAL;
1364 	if (vsi->type != ICE_VSI_PF)
1365 		return 0;
1366 
1367 	dev = &vsi->back->pdev->dev;
1368 
1369 	pi = vsi->port_info;
1370 
1371 	pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1372 	if (!pcaps)
1373 		return -ENOMEM;
1374 
1375 	retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1376 				      NULL);
1377 	if (retcode) {
1378 		dev_err(dev,
1379 			"Failed to get phy capabilities, VSI %d error %d\n",
1380 			vsi->vsi_num, retcode);
1381 		retcode = -EIO;
1382 		goto out;
1383 	}
1384 
1385 	/* No change in link */
1386 	if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1387 	    link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1388 		goto out;
1389 
1390 	cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
1391 	if (!cfg) {
1392 		retcode = -ENOMEM;
1393 		goto out;
1394 	}
1395 
1396 	cfg->phy_type_low = pcaps->phy_type_low;
1397 	cfg->phy_type_high = pcaps->phy_type_high;
1398 	cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1399 	cfg->low_power_ctrl = pcaps->low_power_ctrl;
1400 	cfg->eee_cap = pcaps->eee_cap;
1401 	cfg->eeer_value = pcaps->eeer_value;
1402 	cfg->link_fec_opt = pcaps->link_fec_options;
1403 	if (link_up)
1404 		cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1405 	else
1406 		cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1407 
1408 	retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
1409 	if (retcode) {
1410 		dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1411 			vsi->vsi_num, retcode);
1412 		retcode = -EIO;
1413 	}
1414 
1415 	kfree(cfg);
1416 out:
1417 	kfree(pcaps);
1418 	return retcode;
1419 }
1420 
1421 /**
1422  * ice_check_media_subtask - Check for media; bring link up if detected.
1423  * @pf: pointer to PF struct
1424  */
1425 static void ice_check_media_subtask(struct ice_pf *pf)
1426 {
1427 	struct ice_port_info *pi;
1428 	struct ice_vsi *vsi;
1429 	int err;
1430 
1431 	vsi = ice_get_main_vsi(pf);
1432 	if (!vsi)
1433 		return;
1434 
1435 	/* No need to check for media if it's already present or the interface
1436 	 * is down
1437 	 */
1438 	if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) ||
1439 	    test_bit(__ICE_DOWN, vsi->state))
1440 		return;
1441 
1442 	/* Refresh link info and check if media is present */
1443 	pi = vsi->port_info;
1444 	err = ice_update_link_info(pi);
1445 	if (err)
1446 		return;
1447 
1448 	if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1449 		err = ice_force_phys_link_state(vsi, true);
1450 		if (err)
1451 			return;
1452 		clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1453 
1454 		/* A Link Status Event will be generated; the event handler
1455 		 * will complete bringing the interface up
1456 		 */
1457 	}
1458 }
1459 
1460 /**
1461  * ice_service_task - manage and run subtasks
1462  * @work: pointer to work_struct contained by the PF struct
1463  */
1464 static void ice_service_task(struct work_struct *work)
1465 {
1466 	struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1467 	unsigned long start_time = jiffies;
1468 
1469 	/* subtasks */
1470 
1471 	/* process reset requests first */
1472 	ice_reset_subtask(pf);
1473 
1474 	/* bail if a reset/recovery cycle is pending or rebuild failed */
1475 	if (ice_is_reset_in_progress(pf->state) ||
1476 	    test_bit(__ICE_SUSPENDED, pf->state) ||
1477 	    test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1478 		ice_service_task_complete(pf);
1479 		return;
1480 	}
1481 
1482 	ice_clean_adminq_subtask(pf);
1483 	ice_check_media_subtask(pf);
1484 	ice_check_for_hang_subtask(pf);
1485 	ice_sync_fltr_subtask(pf);
1486 	ice_handle_mdd_event(pf);
1487 	ice_watchdog_subtask(pf);
1488 
1489 	if (ice_is_safe_mode(pf)) {
1490 		ice_service_task_complete(pf);
1491 		return;
1492 	}
1493 
1494 	ice_process_vflr_event(pf);
1495 	ice_clean_mailboxq_subtask(pf);
1496 
1497 	/* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1498 	ice_service_task_complete(pf);
1499 
1500 	/* If the tasks have taken longer than one service timer period
1501 	 * or there is more work to be done, reset the service timer to
1502 	 * schedule the service task now.
1503 	 */
1504 	if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1505 	    test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1506 	    test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1507 	    test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1508 	    test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1509 		mod_timer(&pf->serv_tmr, jiffies);
1510 }
1511 
1512 /**
1513  * ice_set_ctrlq_len - helper function to set controlq length
1514  * @hw: pointer to the HW instance
1515  */
1516 static void ice_set_ctrlq_len(struct ice_hw *hw)
1517 {
1518 	hw->adminq.num_rq_entries = ICE_AQ_LEN;
1519 	hw->adminq.num_sq_entries = ICE_AQ_LEN;
1520 	hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1521 	hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1522 	hw->mailboxq.num_rq_entries = ICE_MBXRQ_LEN;
1523 	hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
1524 	hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1525 	hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1526 }
1527 
1528 /**
1529  * ice_schedule_reset - schedule a reset
1530  * @pf: board private structure
1531  * @reset: reset being requested
1532  */
1533 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
1534 {
1535 	struct device *dev = ice_pf_to_dev(pf);
1536 
1537 	/* bail out if earlier reset has failed */
1538 	if (test_bit(__ICE_RESET_FAILED, pf->state)) {
1539 		dev_dbg(dev, "earlier reset has failed\n");
1540 		return -EIO;
1541 	}
1542 	/* bail if reset/recovery already in progress */
1543 	if (ice_is_reset_in_progress(pf->state)) {
1544 		dev_dbg(dev, "Reset already in progress\n");
1545 		return -EBUSY;
1546 	}
1547 
1548 	switch (reset) {
1549 	case ICE_RESET_PFR:
1550 		set_bit(__ICE_PFR_REQ, pf->state);
1551 		break;
1552 	case ICE_RESET_CORER:
1553 		set_bit(__ICE_CORER_REQ, pf->state);
1554 		break;
1555 	case ICE_RESET_GLOBR:
1556 		set_bit(__ICE_GLOBR_REQ, pf->state);
1557 		break;
1558 	default:
1559 		return -EINVAL;
1560 	}
1561 
1562 	ice_service_task_schedule(pf);
1563 	return 0;
1564 }
1565 
1566 /**
1567  * ice_irq_affinity_notify - Callback for affinity changes
1568  * @notify: context as to what irq was changed
1569  * @mask: the new affinity mask
1570  *
1571  * This is a callback function used by the irq_set_affinity_notifier function
1572  * so that we may register to receive changes to the irq affinity masks.
1573  */
1574 static void
1575 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1576 			const cpumask_t *mask)
1577 {
1578 	struct ice_q_vector *q_vector =
1579 		container_of(notify, struct ice_q_vector, affinity_notify);
1580 
1581 	cpumask_copy(&q_vector->affinity_mask, mask);
1582 }
1583 
1584 /**
1585  * ice_irq_affinity_release - Callback for affinity notifier release
1586  * @ref: internal core kernel usage
1587  *
1588  * This is a callback function used by the irq_set_affinity_notifier function
1589  * to inform the current notification subscriber that they will no longer
1590  * receive notifications.
1591  */
1592 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1593 
1594 /**
1595  * ice_vsi_ena_irq - Enable IRQ for the given VSI
1596  * @vsi: the VSI being configured
1597  */
1598 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1599 {
1600 	struct ice_hw *hw = &vsi->back->hw;
1601 	int i;
1602 
1603 	ice_for_each_q_vector(vsi, i)
1604 		ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1605 
1606 	ice_flush(hw);
1607 	return 0;
1608 }
1609 
1610 /**
1611  * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1612  * @vsi: the VSI being configured
1613  * @basename: name for the vector
1614  */
1615 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1616 {
1617 	int q_vectors = vsi->num_q_vectors;
1618 	struct ice_pf *pf = vsi->back;
1619 	int base = vsi->base_vector;
1620 	struct device *dev;
1621 	int rx_int_idx = 0;
1622 	int tx_int_idx = 0;
1623 	int vector, err;
1624 	int irq_num;
1625 
1626 	dev = ice_pf_to_dev(pf);
1627 	for (vector = 0; vector < q_vectors; vector++) {
1628 		struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1629 
1630 		irq_num = pf->msix_entries[base + vector].vector;
1631 
1632 		if (q_vector->tx.ring && q_vector->rx.ring) {
1633 			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1634 				 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1635 			tx_int_idx++;
1636 		} else if (q_vector->rx.ring) {
1637 			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1638 				 "%s-%s-%d", basename, "rx", rx_int_idx++);
1639 		} else if (q_vector->tx.ring) {
1640 			snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1641 				 "%s-%s-%d", basename, "tx", tx_int_idx++);
1642 		} else {
1643 			/* skip this unused q_vector */
1644 			continue;
1645 		}
1646 		err = devm_request_irq(dev, irq_num, vsi->irq_handler, 0,
1647 				       q_vector->name, q_vector);
1648 		if (err) {
1649 			netdev_err(vsi->netdev,
1650 				   "MSIX request_irq failed, error: %d\n", err);
1651 			goto free_q_irqs;
1652 		}
1653 
1654 		/* register for affinity change notifications */
1655 		q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1656 		q_vector->affinity_notify.release = ice_irq_affinity_release;
1657 		irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1658 
1659 		/* assign the mask for this irq */
1660 		irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1661 	}
1662 
1663 	vsi->irqs_ready = true;
1664 	return 0;
1665 
1666 free_q_irqs:
1667 	while (vector) {
1668 		vector--;
1669 		irq_num = pf->msix_entries[base + vector].vector,
1670 		irq_set_affinity_notifier(irq_num, NULL);
1671 		irq_set_affinity_hint(irq_num, NULL);
1672 		devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
1673 	}
1674 	return err;
1675 }
1676 
1677 /**
1678  * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
1679  * @vsi: VSI to setup Tx rings used by XDP
1680  *
1681  * Return 0 on success and negative value on error
1682  */
1683 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
1684 {
1685 	struct device *dev = &vsi->back->pdev->dev;
1686 	int i;
1687 
1688 	for (i = 0; i < vsi->num_xdp_txq; i++) {
1689 		u16 xdp_q_idx = vsi->alloc_txq + i;
1690 		struct ice_ring *xdp_ring;
1691 
1692 		xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
1693 
1694 		if (!xdp_ring)
1695 			goto free_xdp_rings;
1696 
1697 		xdp_ring->q_index = xdp_q_idx;
1698 		xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
1699 		xdp_ring->ring_active = false;
1700 		xdp_ring->vsi = vsi;
1701 		xdp_ring->netdev = NULL;
1702 		xdp_ring->dev = dev;
1703 		xdp_ring->count = vsi->num_tx_desc;
1704 		vsi->xdp_rings[i] = xdp_ring;
1705 		if (ice_setup_tx_ring(xdp_ring))
1706 			goto free_xdp_rings;
1707 		ice_set_ring_xdp(xdp_ring);
1708 		xdp_ring->xsk_umem = ice_xsk_umem(xdp_ring);
1709 	}
1710 
1711 	return 0;
1712 
1713 free_xdp_rings:
1714 	for (; i >= 0; i--)
1715 		if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
1716 			ice_free_tx_ring(vsi->xdp_rings[i]);
1717 	return -ENOMEM;
1718 }
1719 
1720 /**
1721  * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
1722  * @vsi: VSI to set the bpf prog on
1723  * @prog: the bpf prog pointer
1724  */
1725 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
1726 {
1727 	struct bpf_prog *old_prog;
1728 	int i;
1729 
1730 	old_prog = xchg(&vsi->xdp_prog, prog);
1731 	if (old_prog)
1732 		bpf_prog_put(old_prog);
1733 
1734 	ice_for_each_rxq(vsi, i)
1735 		WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
1736 }
1737 
1738 /**
1739  * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
1740  * @vsi: VSI to bring up Tx rings used by XDP
1741  * @prog: bpf program that will be assigned to VSI
1742  *
1743  * Return 0 on success and negative value on error
1744  */
1745 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
1746 {
1747 	u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1748 	int xdp_rings_rem = vsi->num_xdp_txq;
1749 	struct ice_pf *pf = vsi->back;
1750 	struct ice_qs_cfg xdp_qs_cfg = {
1751 		.qs_mutex = &pf->avail_q_mutex,
1752 		.pf_map = pf->avail_txqs,
1753 		.pf_map_size = pf->max_pf_txqs,
1754 		.q_count = vsi->num_xdp_txq,
1755 		.scatter_count = ICE_MAX_SCATTER_TXQS,
1756 		.vsi_map = vsi->txq_map,
1757 		.vsi_map_offset = vsi->alloc_txq,
1758 		.mapping_mode = ICE_VSI_MAP_CONTIG
1759 	};
1760 	enum ice_status status;
1761 	struct device *dev;
1762 	int i, v_idx;
1763 
1764 	dev = ice_pf_to_dev(pf);
1765 	vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
1766 				      sizeof(*vsi->xdp_rings), GFP_KERNEL);
1767 	if (!vsi->xdp_rings)
1768 		return -ENOMEM;
1769 
1770 	vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
1771 	if (__ice_vsi_get_qs(&xdp_qs_cfg))
1772 		goto err_map_xdp;
1773 
1774 	if (ice_xdp_alloc_setup_rings(vsi))
1775 		goto clear_xdp_rings;
1776 
1777 	/* follow the logic from ice_vsi_map_rings_to_vectors */
1778 	ice_for_each_q_vector(vsi, v_idx) {
1779 		struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1780 		int xdp_rings_per_v, q_id, q_base;
1781 
1782 		xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
1783 					       vsi->num_q_vectors - v_idx);
1784 		q_base = vsi->num_xdp_txq - xdp_rings_rem;
1785 
1786 		for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
1787 			struct ice_ring *xdp_ring = vsi->xdp_rings[q_id];
1788 
1789 			xdp_ring->q_vector = q_vector;
1790 			xdp_ring->next = q_vector->tx.ring;
1791 			q_vector->tx.ring = xdp_ring;
1792 		}
1793 		xdp_rings_rem -= xdp_rings_per_v;
1794 	}
1795 
1796 	/* omit the scheduler update if in reset path; XDP queues will be
1797 	 * taken into account at the end of ice_vsi_rebuild, where
1798 	 * ice_cfg_vsi_lan is being called
1799 	 */
1800 	if (ice_is_reset_in_progress(pf->state))
1801 		return 0;
1802 
1803 	/* tell the Tx scheduler that right now we have
1804 	 * additional queues
1805 	 */
1806 	for (i = 0; i < vsi->tc_cfg.numtc; i++)
1807 		max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
1808 
1809 	status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1810 				 max_txqs);
1811 	if (status) {
1812 		dev_err(dev, "Failed VSI LAN queue config for XDP, error:%d\n",
1813 			status);
1814 		goto clear_xdp_rings;
1815 	}
1816 	ice_vsi_assign_bpf_prog(vsi, prog);
1817 
1818 	return 0;
1819 clear_xdp_rings:
1820 	for (i = 0; i < vsi->num_xdp_txq; i++)
1821 		if (vsi->xdp_rings[i]) {
1822 			kfree_rcu(vsi->xdp_rings[i], rcu);
1823 			vsi->xdp_rings[i] = NULL;
1824 		}
1825 
1826 err_map_xdp:
1827 	mutex_lock(&pf->avail_q_mutex);
1828 	for (i = 0; i < vsi->num_xdp_txq; i++) {
1829 		clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1830 		vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1831 	}
1832 	mutex_unlock(&pf->avail_q_mutex);
1833 
1834 	devm_kfree(dev, vsi->xdp_rings);
1835 	return -ENOMEM;
1836 }
1837 
1838 /**
1839  * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
1840  * @vsi: VSI to remove XDP rings
1841  *
1842  * Detach XDP rings from irq vectors, clean up the PF bitmap and free
1843  * resources
1844  */
1845 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
1846 {
1847 	u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1848 	struct ice_pf *pf = vsi->back;
1849 	int i, v_idx;
1850 
1851 	/* q_vectors are freed in reset path so there's no point in detaching
1852 	 * rings; in case of rebuild being triggered not from reset reset bits
1853 	 * in pf->state won't be set, so additionally check first q_vector
1854 	 * against NULL
1855 	 */
1856 	if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1857 		goto free_qmap;
1858 
1859 	ice_for_each_q_vector(vsi, v_idx) {
1860 		struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1861 		struct ice_ring *ring;
1862 
1863 		ice_for_each_ring(ring, q_vector->tx)
1864 			if (!ring->tx_buf || !ice_ring_is_xdp(ring))
1865 				break;
1866 
1867 		/* restore the value of last node prior to XDP setup */
1868 		q_vector->tx.ring = ring;
1869 	}
1870 
1871 free_qmap:
1872 	mutex_lock(&pf->avail_q_mutex);
1873 	for (i = 0; i < vsi->num_xdp_txq; i++) {
1874 		clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1875 		vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1876 	}
1877 	mutex_unlock(&pf->avail_q_mutex);
1878 
1879 	for (i = 0; i < vsi->num_xdp_txq; i++)
1880 		if (vsi->xdp_rings[i]) {
1881 			if (vsi->xdp_rings[i]->desc)
1882 				ice_free_tx_ring(vsi->xdp_rings[i]);
1883 			kfree_rcu(vsi->xdp_rings[i], rcu);
1884 			vsi->xdp_rings[i] = NULL;
1885 		}
1886 
1887 	devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
1888 	vsi->xdp_rings = NULL;
1889 
1890 	if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1891 		return 0;
1892 
1893 	ice_vsi_assign_bpf_prog(vsi, NULL);
1894 
1895 	/* notify Tx scheduler that we destroyed XDP queues and bring
1896 	 * back the old number of child nodes
1897 	 */
1898 	for (i = 0; i < vsi->tc_cfg.numtc; i++)
1899 		max_txqs[i] = vsi->num_txq;
1900 
1901 	return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1902 			       max_txqs);
1903 }
1904 
1905 /**
1906  * ice_xdp_setup_prog - Add or remove XDP eBPF program
1907  * @vsi: VSI to setup XDP for
1908  * @prog: XDP program
1909  * @extack: netlink extended ack
1910  */
1911 static int
1912 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
1913 		   struct netlink_ext_ack *extack)
1914 {
1915 	int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
1916 	bool if_running = netif_running(vsi->netdev);
1917 	int ret = 0, xdp_ring_err = 0;
1918 
1919 	if (frame_size > vsi->rx_buf_len) {
1920 		NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
1921 		return -EOPNOTSUPP;
1922 	}
1923 
1924 	/* need to stop netdev while setting up the program for Rx rings */
1925 	if (if_running && !test_and_set_bit(__ICE_DOWN, vsi->state)) {
1926 		ret = ice_down(vsi);
1927 		if (ret) {
1928 			NL_SET_ERR_MSG_MOD(extack,
1929 					   "Preparing device for XDP attach failed");
1930 			return ret;
1931 		}
1932 	}
1933 
1934 	if (!ice_is_xdp_ena_vsi(vsi) && prog) {
1935 		vsi->num_xdp_txq = vsi->alloc_txq;
1936 		xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
1937 		if (xdp_ring_err)
1938 			NL_SET_ERR_MSG_MOD(extack,
1939 					   "Setting up XDP Tx resources failed");
1940 	} else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
1941 		xdp_ring_err = ice_destroy_xdp_rings(vsi);
1942 		if (xdp_ring_err)
1943 			NL_SET_ERR_MSG_MOD(extack,
1944 					   "Freeing XDP Tx resources failed");
1945 	} else {
1946 		ice_vsi_assign_bpf_prog(vsi, prog);
1947 	}
1948 
1949 	if (if_running)
1950 		ret = ice_up(vsi);
1951 
1952 	if (!ret && prog && vsi->xsk_umems) {
1953 		int i;
1954 
1955 		ice_for_each_rxq(vsi, i) {
1956 			struct ice_ring *rx_ring = vsi->rx_rings[i];
1957 
1958 			if (rx_ring->xsk_umem)
1959 				napi_schedule(&rx_ring->q_vector->napi);
1960 		}
1961 	}
1962 
1963 	return (ret || xdp_ring_err) ? -ENOMEM : 0;
1964 }
1965 
1966 /**
1967  * ice_xdp - implements XDP handler
1968  * @dev: netdevice
1969  * @xdp: XDP command
1970  */
1971 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
1972 {
1973 	struct ice_netdev_priv *np = netdev_priv(dev);
1974 	struct ice_vsi *vsi = np->vsi;
1975 
1976 	if (vsi->type != ICE_VSI_PF) {
1977 		NL_SET_ERR_MSG_MOD(xdp->extack,
1978 				   "XDP can be loaded only on PF VSI");
1979 		return -EINVAL;
1980 	}
1981 
1982 	switch (xdp->command) {
1983 	case XDP_SETUP_PROG:
1984 		return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
1985 	case XDP_QUERY_PROG:
1986 		xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
1987 		return 0;
1988 	case XDP_SETUP_XSK_UMEM:
1989 		return ice_xsk_umem_setup(vsi, xdp->xsk.umem,
1990 					  xdp->xsk.queue_id);
1991 	default:
1992 		return -EINVAL;
1993 	}
1994 }
1995 
1996 /**
1997  * ice_ena_misc_vector - enable the non-queue interrupts
1998  * @pf: board private structure
1999  */
2000 static void ice_ena_misc_vector(struct ice_pf *pf)
2001 {
2002 	struct ice_hw *hw = &pf->hw;
2003 	u32 val;
2004 
2005 	/* clear things first */
2006 	wr32(hw, PFINT_OICR_ENA, 0);	/* disable all */
2007 	rd32(hw, PFINT_OICR);		/* read to clear */
2008 
2009 	val = (PFINT_OICR_ECC_ERR_M |
2010 	       PFINT_OICR_MAL_DETECT_M |
2011 	       PFINT_OICR_GRST_M |
2012 	       PFINT_OICR_PCI_EXCEPTION_M |
2013 	       PFINT_OICR_VFLR_M |
2014 	       PFINT_OICR_HMC_ERR_M |
2015 	       PFINT_OICR_PE_CRITERR_M);
2016 
2017 	wr32(hw, PFINT_OICR_ENA, val);
2018 
2019 	/* SW_ITR_IDX = 0, but don't change INTENA */
2020 	wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2021 	     GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2022 }
2023 
2024 /**
2025  * ice_misc_intr - misc interrupt handler
2026  * @irq: interrupt number
2027  * @data: pointer to a q_vector
2028  */
2029 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2030 {
2031 	struct ice_pf *pf = (struct ice_pf *)data;
2032 	struct ice_hw *hw = &pf->hw;
2033 	irqreturn_t ret = IRQ_NONE;
2034 	struct device *dev;
2035 	u32 oicr, ena_mask;
2036 
2037 	dev = ice_pf_to_dev(pf);
2038 	set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
2039 	set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2040 
2041 	oicr = rd32(hw, PFINT_OICR);
2042 	ena_mask = rd32(hw, PFINT_OICR_ENA);
2043 
2044 	if (oicr & PFINT_OICR_SWINT_M) {
2045 		ena_mask &= ~PFINT_OICR_SWINT_M;
2046 		pf->sw_int_count++;
2047 	}
2048 
2049 	if (oicr & PFINT_OICR_MAL_DETECT_M) {
2050 		ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2051 		set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
2052 	}
2053 	if (oicr & PFINT_OICR_VFLR_M) {
2054 		ena_mask &= ~PFINT_OICR_VFLR_M;
2055 		set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
2056 	}
2057 
2058 	if (oicr & PFINT_OICR_GRST_M) {
2059 		u32 reset;
2060 
2061 		/* we have a reset warning */
2062 		ena_mask &= ~PFINT_OICR_GRST_M;
2063 		reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
2064 			GLGEN_RSTAT_RESET_TYPE_S;
2065 
2066 		if (reset == ICE_RESET_CORER)
2067 			pf->corer_count++;
2068 		else if (reset == ICE_RESET_GLOBR)
2069 			pf->globr_count++;
2070 		else if (reset == ICE_RESET_EMPR)
2071 			pf->empr_count++;
2072 		else
2073 			dev_dbg(dev, "Invalid reset type %d\n", reset);
2074 
2075 		/* If a reset cycle isn't already in progress, we set a bit in
2076 		 * pf->state so that the service task can start a reset/rebuild.
2077 		 * We also make note of which reset happened so that peer
2078 		 * devices/drivers can be informed.
2079 		 */
2080 		if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
2081 			if (reset == ICE_RESET_CORER)
2082 				set_bit(__ICE_CORER_RECV, pf->state);
2083 			else if (reset == ICE_RESET_GLOBR)
2084 				set_bit(__ICE_GLOBR_RECV, pf->state);
2085 			else
2086 				set_bit(__ICE_EMPR_RECV, pf->state);
2087 
2088 			/* There are couple of different bits at play here.
2089 			 * hw->reset_ongoing indicates whether the hardware is
2090 			 * in reset. This is set to true when a reset interrupt
2091 			 * is received and set back to false after the driver
2092 			 * has determined that the hardware is out of reset.
2093 			 *
2094 			 * __ICE_RESET_OICR_RECV in pf->state indicates
2095 			 * that a post reset rebuild is required before the
2096 			 * driver is operational again. This is set above.
2097 			 *
2098 			 * As this is the start of the reset/rebuild cycle, set
2099 			 * both to indicate that.
2100 			 */
2101 			hw->reset_ongoing = true;
2102 		}
2103 	}
2104 
2105 	if (oicr & PFINT_OICR_HMC_ERR_M) {
2106 		ena_mask &= ~PFINT_OICR_HMC_ERR_M;
2107 		dev_dbg(dev, "HMC Error interrupt - info 0x%x, data 0x%x\n",
2108 			rd32(hw, PFHMC_ERRORINFO),
2109 			rd32(hw, PFHMC_ERRORDATA));
2110 	}
2111 
2112 	/* Report any remaining unexpected interrupts */
2113 	oicr &= ena_mask;
2114 	if (oicr) {
2115 		dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
2116 		/* If a critical error is pending there is no choice but to
2117 		 * reset the device.
2118 		 */
2119 		if (oicr & (PFINT_OICR_PE_CRITERR_M |
2120 			    PFINT_OICR_PCI_EXCEPTION_M |
2121 			    PFINT_OICR_ECC_ERR_M)) {
2122 			set_bit(__ICE_PFR_REQ, pf->state);
2123 			ice_service_task_schedule(pf);
2124 		}
2125 	}
2126 	ret = IRQ_HANDLED;
2127 
2128 	if (!test_bit(__ICE_DOWN, pf->state)) {
2129 		ice_service_task_schedule(pf);
2130 		ice_irq_dynamic_ena(hw, NULL, NULL);
2131 	}
2132 
2133 	return ret;
2134 }
2135 
2136 /**
2137  * ice_dis_ctrlq_interrupts - disable control queue interrupts
2138  * @hw: pointer to HW structure
2139  */
2140 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
2141 {
2142 	/* disable Admin queue Interrupt causes */
2143 	wr32(hw, PFINT_FW_CTL,
2144 	     rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
2145 
2146 	/* disable Mailbox queue Interrupt causes */
2147 	wr32(hw, PFINT_MBX_CTL,
2148 	     rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
2149 
2150 	/* disable Control queue Interrupt causes */
2151 	wr32(hw, PFINT_OICR_CTL,
2152 	     rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
2153 
2154 	ice_flush(hw);
2155 }
2156 
2157 /**
2158  * ice_free_irq_msix_misc - Unroll misc vector setup
2159  * @pf: board private structure
2160  */
2161 static void ice_free_irq_msix_misc(struct ice_pf *pf)
2162 {
2163 	struct ice_hw *hw = &pf->hw;
2164 
2165 	ice_dis_ctrlq_interrupts(hw);
2166 
2167 	/* disable OICR interrupt */
2168 	wr32(hw, PFINT_OICR_ENA, 0);
2169 	ice_flush(hw);
2170 
2171 	if (pf->msix_entries) {
2172 		synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
2173 		devm_free_irq(ice_pf_to_dev(pf),
2174 			      pf->msix_entries[pf->oicr_idx].vector, pf);
2175 	}
2176 
2177 	pf->num_avail_sw_msix += 1;
2178 	ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
2179 }
2180 
2181 /**
2182  * ice_ena_ctrlq_interrupts - enable control queue interrupts
2183  * @hw: pointer to HW structure
2184  * @reg_idx: HW vector index to associate the control queue interrupts with
2185  */
2186 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
2187 {
2188 	u32 val;
2189 
2190 	val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2191 	       PFINT_OICR_CTL_CAUSE_ENA_M);
2192 	wr32(hw, PFINT_OICR_CTL, val);
2193 
2194 	/* enable Admin queue Interrupt causes */
2195 	val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2196 	       PFINT_FW_CTL_CAUSE_ENA_M);
2197 	wr32(hw, PFINT_FW_CTL, val);
2198 
2199 	/* enable Mailbox queue Interrupt causes */
2200 	val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
2201 	       PFINT_MBX_CTL_CAUSE_ENA_M);
2202 	wr32(hw, PFINT_MBX_CTL, val);
2203 
2204 	ice_flush(hw);
2205 }
2206 
2207 /**
2208  * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2209  * @pf: board private structure
2210  *
2211  * This sets up the handler for MSIX 0, which is used to manage the
2212  * non-queue interrupts, e.g. AdminQ and errors. This is not used
2213  * when in MSI or Legacy interrupt mode.
2214  */
2215 static int ice_req_irq_msix_misc(struct ice_pf *pf)
2216 {
2217 	struct device *dev = ice_pf_to_dev(pf);
2218 	struct ice_hw *hw = &pf->hw;
2219 	int oicr_idx, err = 0;
2220 
2221 	if (!pf->int_name[0])
2222 		snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
2223 			 dev_driver_string(dev), dev_name(dev));
2224 
2225 	/* Do not request IRQ but do enable OICR interrupt since settings are
2226 	 * lost during reset. Note that this function is called only during
2227 	 * rebuild path and not while reset is in progress.
2228 	 */
2229 	if (ice_is_reset_in_progress(pf->state))
2230 		goto skip_req_irq;
2231 
2232 	/* reserve one vector in irq_tracker for misc interrupts */
2233 	oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2234 	if (oicr_idx < 0)
2235 		return oicr_idx;
2236 
2237 	pf->num_avail_sw_msix -= 1;
2238 	pf->oicr_idx = oicr_idx;
2239 
2240 	err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
2241 			       ice_misc_intr, 0, pf->int_name, pf);
2242 	if (err) {
2243 		dev_err(dev, "devm_request_irq for %s failed: %d\n",
2244 			pf->int_name, err);
2245 		ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2246 		pf->num_avail_sw_msix += 1;
2247 		return err;
2248 	}
2249 
2250 skip_req_irq:
2251 	ice_ena_misc_vector(pf);
2252 
2253 	ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
2254 	wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
2255 	     ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
2256 
2257 	ice_flush(hw);
2258 	ice_irq_dynamic_ena(hw, NULL, NULL);
2259 
2260 	return 0;
2261 }
2262 
2263 /**
2264  * ice_napi_add - register NAPI handler for the VSI
2265  * @vsi: VSI for which NAPI handler is to be registered
2266  *
2267  * This function is only called in the driver's load path. Registering the NAPI
2268  * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
2269  * reset/rebuild, etc.)
2270  */
2271 static void ice_napi_add(struct ice_vsi *vsi)
2272 {
2273 	int v_idx;
2274 
2275 	if (!vsi->netdev)
2276 		return;
2277 
2278 	ice_for_each_q_vector(vsi, v_idx)
2279 		netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
2280 			       ice_napi_poll, NAPI_POLL_WEIGHT);
2281 }
2282 
2283 /**
2284  * ice_set_ops - set netdev and ethtools ops for the given netdev
2285  * @netdev: netdev instance
2286  */
2287 static void ice_set_ops(struct net_device *netdev)
2288 {
2289 	struct ice_pf *pf = ice_netdev_to_pf(netdev);
2290 
2291 	if (ice_is_safe_mode(pf)) {
2292 		netdev->netdev_ops = &ice_netdev_safe_mode_ops;
2293 		ice_set_ethtool_safe_mode_ops(netdev);
2294 		return;
2295 	}
2296 
2297 	netdev->netdev_ops = &ice_netdev_ops;
2298 	ice_set_ethtool_ops(netdev);
2299 }
2300 
2301 /**
2302  * ice_set_netdev_features - set features for the given netdev
2303  * @netdev: netdev instance
2304  */
2305 static void ice_set_netdev_features(struct net_device *netdev)
2306 {
2307 	struct ice_pf *pf = ice_netdev_to_pf(netdev);
2308 	netdev_features_t csumo_features;
2309 	netdev_features_t vlano_features;
2310 	netdev_features_t dflt_features;
2311 	netdev_features_t tso_features;
2312 
2313 	if (ice_is_safe_mode(pf)) {
2314 		/* safe mode */
2315 		netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
2316 		netdev->hw_features = netdev->features;
2317 		return;
2318 	}
2319 
2320 	dflt_features = NETIF_F_SG	|
2321 			NETIF_F_HIGHDMA	|
2322 			NETIF_F_RXHASH;
2323 
2324 	csumo_features = NETIF_F_RXCSUM	  |
2325 			 NETIF_F_IP_CSUM  |
2326 			 NETIF_F_SCTP_CRC |
2327 			 NETIF_F_IPV6_CSUM;
2328 
2329 	vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
2330 			 NETIF_F_HW_VLAN_CTAG_TX     |
2331 			 NETIF_F_HW_VLAN_CTAG_RX;
2332 
2333 	tso_features = NETIF_F_TSO;
2334 
2335 	/* set features that user can change */
2336 	netdev->hw_features = dflt_features | csumo_features |
2337 			      vlano_features | tso_features;
2338 
2339 	/* enable features */
2340 	netdev->features |= netdev->hw_features;
2341 	/* encap and VLAN devices inherit default, csumo and tso features */
2342 	netdev->hw_enc_features |= dflt_features | csumo_features |
2343 				   tso_features;
2344 	netdev->vlan_features |= dflt_features | csumo_features |
2345 				 tso_features;
2346 }
2347 
2348 /**
2349  * ice_cfg_netdev - Allocate, configure and register a netdev
2350  * @vsi: the VSI associated with the new netdev
2351  *
2352  * Returns 0 on success, negative value on failure
2353  */
2354 static int ice_cfg_netdev(struct ice_vsi *vsi)
2355 {
2356 	struct ice_pf *pf = vsi->back;
2357 	struct ice_netdev_priv *np;
2358 	struct net_device *netdev;
2359 	u8 mac_addr[ETH_ALEN];
2360 	int err;
2361 
2362 	netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
2363 				    vsi->alloc_rxq);
2364 	if (!netdev)
2365 		return -ENOMEM;
2366 
2367 	vsi->netdev = netdev;
2368 	np = netdev_priv(netdev);
2369 	np->vsi = vsi;
2370 
2371 	ice_set_netdev_features(netdev);
2372 
2373 	ice_set_ops(netdev);
2374 
2375 	if (vsi->type == ICE_VSI_PF) {
2376 		SET_NETDEV_DEV(netdev, ice_pf_to_dev(pf));
2377 		ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
2378 		ether_addr_copy(netdev->dev_addr, mac_addr);
2379 		ether_addr_copy(netdev->perm_addr, mac_addr);
2380 	}
2381 
2382 	netdev->priv_flags |= IFF_UNICAST_FLT;
2383 
2384 	/* Setup netdev TC information */
2385 	ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
2386 
2387 	/* setup watchdog timeout value to be 5 second */
2388 	netdev->watchdog_timeo = 5 * HZ;
2389 
2390 	netdev->min_mtu = ETH_MIN_MTU;
2391 	netdev->max_mtu = ICE_MAX_MTU;
2392 
2393 	err = register_netdev(vsi->netdev);
2394 	if (err)
2395 		return err;
2396 
2397 	netif_carrier_off(vsi->netdev);
2398 
2399 	/* make sure transmit queues start off as stopped */
2400 	netif_tx_stop_all_queues(vsi->netdev);
2401 
2402 	return 0;
2403 }
2404 
2405 /**
2406  * ice_fill_rss_lut - Fill the RSS lookup table with default values
2407  * @lut: Lookup table
2408  * @rss_table_size: Lookup table size
2409  * @rss_size: Range of queue number for hashing
2410  */
2411 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2412 {
2413 	u16 i;
2414 
2415 	for (i = 0; i < rss_table_size; i++)
2416 		lut[i] = i % rss_size;
2417 }
2418 
2419 /**
2420  * ice_pf_vsi_setup - Set up a PF VSI
2421  * @pf: board private structure
2422  * @pi: pointer to the port_info instance
2423  *
2424  * Returns pointer to the successfully allocated VSI software struct
2425  * on success, otherwise returns NULL on failure.
2426  */
2427 static struct ice_vsi *
2428 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2429 {
2430 	return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
2431 }
2432 
2433 /**
2434  * ice_lb_vsi_setup - Set up a loopback VSI
2435  * @pf: board private structure
2436  * @pi: pointer to the port_info instance
2437  *
2438  * Returns pointer to the successfully allocated VSI software struct
2439  * on success, otherwise returns NULL on failure.
2440  */
2441 struct ice_vsi *
2442 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2443 {
2444 	return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
2445 }
2446 
2447 /**
2448  * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2449  * @netdev: network interface to be adjusted
2450  * @proto: unused protocol
2451  * @vid: VLAN ID to be added
2452  *
2453  * net_device_ops implementation for adding VLAN IDs
2454  */
2455 static int
2456 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
2457 		    u16 vid)
2458 {
2459 	struct ice_netdev_priv *np = netdev_priv(netdev);
2460 	struct ice_vsi *vsi = np->vsi;
2461 	int ret;
2462 
2463 	if (vid >= VLAN_N_VID) {
2464 		netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2465 			   vid, VLAN_N_VID);
2466 		return -EINVAL;
2467 	}
2468 
2469 	if (vsi->info.pvid)
2470 		return -EINVAL;
2471 
2472 	/* Enable VLAN pruning when VLAN 0 is added */
2473 	if (unlikely(!vid)) {
2474 		ret = ice_cfg_vlan_pruning(vsi, true, false);
2475 		if (ret)
2476 			return ret;
2477 	}
2478 
2479 	/* Add all VLAN IDs including 0 to the switch filter. VLAN ID 0 is
2480 	 * needed to continue allowing all untagged packets since VLAN prune
2481 	 * list is applied to all packets by the switch
2482 	 */
2483 	ret = ice_vsi_add_vlan(vsi, vid);
2484 	if (!ret) {
2485 		vsi->vlan_ena = true;
2486 		set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2487 	}
2488 
2489 	return ret;
2490 }
2491 
2492 /**
2493  * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2494  * @netdev: network interface to be adjusted
2495  * @proto: unused protocol
2496  * @vid: VLAN ID to be removed
2497  *
2498  * net_device_ops implementation for removing VLAN IDs
2499  */
2500 static int
2501 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
2502 		     u16 vid)
2503 {
2504 	struct ice_netdev_priv *np = netdev_priv(netdev);
2505 	struct ice_vsi *vsi = np->vsi;
2506 	int ret;
2507 
2508 	if (vsi->info.pvid)
2509 		return -EINVAL;
2510 
2511 	/* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2512 	 * information
2513 	 */
2514 	ret = ice_vsi_kill_vlan(vsi, vid);
2515 	if (ret)
2516 		return ret;
2517 
2518 	/* Disable VLAN pruning when VLAN 0 is removed */
2519 	if (unlikely(!vid))
2520 		ret = ice_cfg_vlan_pruning(vsi, false, false);
2521 
2522 	vsi->vlan_ena = false;
2523 	set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2524 	return ret;
2525 }
2526 
2527 /**
2528  * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2529  * @pf: board private structure
2530  *
2531  * Returns 0 on success, negative value on failure
2532  */
2533 static int ice_setup_pf_sw(struct ice_pf *pf)
2534 {
2535 	struct ice_vsi *vsi;
2536 	int status = 0;
2537 
2538 	if (ice_is_reset_in_progress(pf->state))
2539 		return -EBUSY;
2540 
2541 	vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2542 	if (!vsi) {
2543 		status = -ENOMEM;
2544 		goto unroll_vsi_setup;
2545 	}
2546 
2547 	status = ice_cfg_netdev(vsi);
2548 	if (status) {
2549 		status = -ENODEV;
2550 		goto unroll_vsi_setup;
2551 	}
2552 	/* netdev has to be configured before setting frame size */
2553 	ice_vsi_cfg_frame_size(vsi);
2554 
2555 	/* Setup DCB netlink interface */
2556 	ice_dcbnl_setup(vsi);
2557 
2558 	/* registering the NAPI handler requires both the queues and
2559 	 * netdev to be created, which are done in ice_pf_vsi_setup()
2560 	 * and ice_cfg_netdev() respectively
2561 	 */
2562 	ice_napi_add(vsi);
2563 
2564 	status = ice_init_mac_fltr(pf);
2565 	if (status)
2566 		goto unroll_napi_add;
2567 
2568 	return status;
2569 
2570 unroll_napi_add:
2571 	if (vsi) {
2572 		ice_napi_del(vsi);
2573 		if (vsi->netdev) {
2574 			if (vsi->netdev->reg_state == NETREG_REGISTERED)
2575 				unregister_netdev(vsi->netdev);
2576 			free_netdev(vsi->netdev);
2577 			vsi->netdev = NULL;
2578 		}
2579 	}
2580 
2581 unroll_vsi_setup:
2582 	if (vsi) {
2583 		ice_vsi_free_q_vectors(vsi);
2584 		ice_vsi_delete(vsi);
2585 		ice_vsi_put_qs(vsi);
2586 		ice_vsi_clear(vsi);
2587 	}
2588 	return status;
2589 }
2590 
2591 /**
2592  * ice_get_avail_q_count - Get count of queues in use
2593  * @pf_qmap: bitmap to get queue use count from
2594  * @lock: pointer to a mutex that protects access to pf_qmap
2595  * @size: size of the bitmap
2596  */
2597 static u16
2598 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
2599 {
2600 	u16 count = 0, bit;
2601 
2602 	mutex_lock(lock);
2603 	for_each_clear_bit(bit, pf_qmap, size)
2604 		count++;
2605 	mutex_unlock(lock);
2606 
2607 	return count;
2608 }
2609 
2610 /**
2611  * ice_get_avail_txq_count - Get count of Tx queues in use
2612  * @pf: pointer to an ice_pf instance
2613  */
2614 u16 ice_get_avail_txq_count(struct ice_pf *pf)
2615 {
2616 	return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
2617 				     pf->max_pf_txqs);
2618 }
2619 
2620 /**
2621  * ice_get_avail_rxq_count - Get count of Rx queues in use
2622  * @pf: pointer to an ice_pf instance
2623  */
2624 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
2625 {
2626 	return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
2627 				     pf->max_pf_rxqs);
2628 }
2629 
2630 /**
2631  * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2632  * @pf: board private structure to initialize
2633  */
2634 static void ice_deinit_pf(struct ice_pf *pf)
2635 {
2636 	ice_service_task_stop(pf);
2637 	mutex_destroy(&pf->sw_mutex);
2638 	mutex_destroy(&pf->tc_mutex);
2639 	mutex_destroy(&pf->avail_q_mutex);
2640 
2641 	if (pf->avail_txqs) {
2642 		bitmap_free(pf->avail_txqs);
2643 		pf->avail_txqs = NULL;
2644 	}
2645 
2646 	if (pf->avail_rxqs) {
2647 		bitmap_free(pf->avail_rxqs);
2648 		pf->avail_rxqs = NULL;
2649 	}
2650 }
2651 
2652 /**
2653  * ice_set_pf_caps - set PFs capability flags
2654  * @pf: pointer to the PF instance
2655  */
2656 static void ice_set_pf_caps(struct ice_pf *pf)
2657 {
2658 	struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
2659 
2660 	clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2661 	if (func_caps->common_cap.dcb)
2662 		set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2663 #ifdef CONFIG_PCI_IOV
2664 	clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2665 	if (func_caps->common_cap.sr_iov_1_1) {
2666 		set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2667 		pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
2668 					      ICE_MAX_VF_COUNT);
2669 	}
2670 #endif /* CONFIG_PCI_IOV */
2671 	clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
2672 	if (func_caps->common_cap.rss_table_size)
2673 		set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2674 
2675 	pf->max_pf_txqs = func_caps->common_cap.num_txq;
2676 	pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
2677 }
2678 
2679 /**
2680  * ice_init_pf - Initialize general software structures (struct ice_pf)
2681  * @pf: board private structure to initialize
2682  */
2683 static int ice_init_pf(struct ice_pf *pf)
2684 {
2685 	ice_set_pf_caps(pf);
2686 
2687 	mutex_init(&pf->sw_mutex);
2688 	mutex_init(&pf->tc_mutex);
2689 
2690 	/* setup service timer and periodic service task */
2691 	timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2692 	pf->serv_tmr_period = HZ;
2693 	INIT_WORK(&pf->serv_task, ice_service_task);
2694 	clear_bit(__ICE_SERVICE_SCHED, pf->state);
2695 
2696 	mutex_init(&pf->avail_q_mutex);
2697 	pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
2698 	if (!pf->avail_txqs)
2699 		return -ENOMEM;
2700 
2701 	pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
2702 	if (!pf->avail_rxqs) {
2703 		devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
2704 		pf->avail_txqs = NULL;
2705 		return -ENOMEM;
2706 	}
2707 
2708 	return 0;
2709 }
2710 
2711 /**
2712  * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2713  * @pf: board private structure
2714  *
2715  * compute the number of MSIX vectors required (v_budget) and request from
2716  * the OS. Return the number of vectors reserved or negative on failure
2717  */
2718 static int ice_ena_msix_range(struct ice_pf *pf)
2719 {
2720 	struct device *dev = ice_pf_to_dev(pf);
2721 	int v_left, v_actual, v_budget = 0;
2722 	int needed, err, i;
2723 
2724 	v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2725 
2726 	/* reserve one vector for miscellaneous handler */
2727 	needed = 1;
2728 	if (v_left < needed)
2729 		goto no_hw_vecs_left_err;
2730 	v_budget += needed;
2731 	v_left -= needed;
2732 
2733 	/* reserve vectors for LAN traffic */
2734 	needed = min_t(int, num_online_cpus(), v_left);
2735 	if (v_left < needed)
2736 		goto no_hw_vecs_left_err;
2737 	pf->num_lan_msix = needed;
2738 	v_budget += needed;
2739 	v_left -= needed;
2740 
2741 	pf->msix_entries = devm_kcalloc(dev, v_budget,
2742 					sizeof(*pf->msix_entries), GFP_KERNEL);
2743 
2744 	if (!pf->msix_entries) {
2745 		err = -ENOMEM;
2746 		goto exit_err;
2747 	}
2748 
2749 	for (i = 0; i < v_budget; i++)
2750 		pf->msix_entries[i].entry = i;
2751 
2752 	/* actually reserve the vectors */
2753 	v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2754 					 ICE_MIN_MSIX, v_budget);
2755 
2756 	if (v_actual < 0) {
2757 		dev_err(dev, "unable to reserve MSI-X vectors\n");
2758 		err = v_actual;
2759 		goto msix_err;
2760 	}
2761 
2762 	if (v_actual < v_budget) {
2763 		dev_warn(dev,
2764 			 "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
2765 			 v_budget, v_actual);
2766 /* 2 vectors for LAN (traffic + OICR) */
2767 #define ICE_MIN_LAN_VECS 2
2768 
2769 		if (v_actual < ICE_MIN_LAN_VECS) {
2770 			/* error if we can't get minimum vectors */
2771 			pci_disable_msix(pf->pdev);
2772 			err = -ERANGE;
2773 			goto msix_err;
2774 		} else {
2775 			pf->num_lan_msix = ICE_MIN_LAN_VECS;
2776 		}
2777 	}
2778 
2779 	return v_actual;
2780 
2781 msix_err:
2782 	devm_kfree(dev, pf->msix_entries);
2783 	goto exit_err;
2784 
2785 no_hw_vecs_left_err:
2786 	dev_err(dev,
2787 		"not enough device MSI-X vectors. requested = %d, available = %d\n",
2788 		needed, v_left);
2789 	err = -ERANGE;
2790 exit_err:
2791 	pf->num_lan_msix = 0;
2792 	return err;
2793 }
2794 
2795 /**
2796  * ice_dis_msix - Disable MSI-X interrupt setup in OS
2797  * @pf: board private structure
2798  */
2799 static void ice_dis_msix(struct ice_pf *pf)
2800 {
2801 	pci_disable_msix(pf->pdev);
2802 	devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
2803 	pf->msix_entries = NULL;
2804 }
2805 
2806 /**
2807  * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2808  * @pf: board private structure
2809  */
2810 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2811 {
2812 	ice_dis_msix(pf);
2813 
2814 	if (pf->irq_tracker) {
2815 		devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
2816 		pf->irq_tracker = NULL;
2817 	}
2818 }
2819 
2820 /**
2821  * ice_init_interrupt_scheme - Determine proper interrupt scheme
2822  * @pf: board private structure to initialize
2823  */
2824 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2825 {
2826 	int vectors;
2827 
2828 	vectors = ice_ena_msix_range(pf);
2829 
2830 	if (vectors < 0)
2831 		return vectors;
2832 
2833 	/* set up vector assignment tracking */
2834 	pf->irq_tracker =
2835 		devm_kzalloc(ice_pf_to_dev(pf), sizeof(*pf->irq_tracker) +
2836 			     (sizeof(u16) * vectors), GFP_KERNEL);
2837 	if (!pf->irq_tracker) {
2838 		ice_dis_msix(pf);
2839 		return -ENOMEM;
2840 	}
2841 
2842 	/* populate SW interrupts pool with number of OS granted IRQs. */
2843 	pf->num_avail_sw_msix = vectors;
2844 	pf->irq_tracker->num_entries = vectors;
2845 	pf->irq_tracker->end = pf->irq_tracker->num_entries;
2846 
2847 	return 0;
2848 }
2849 
2850 /**
2851  * ice_vsi_recfg_qs - Change the number of queues on a VSI
2852  * @vsi: VSI being changed
2853  * @new_rx: new number of Rx queues
2854  * @new_tx: new number of Tx queues
2855  *
2856  * Only change the number of queues if new_tx, or new_rx is non-0.
2857  *
2858  * Returns 0 on success.
2859  */
2860 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
2861 {
2862 	struct ice_pf *pf = vsi->back;
2863 	int err = 0, timeout = 50;
2864 
2865 	if (!new_rx && !new_tx)
2866 		return -EINVAL;
2867 
2868 	while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2869 		timeout--;
2870 		if (!timeout)
2871 			return -EBUSY;
2872 		usleep_range(1000, 2000);
2873 	}
2874 
2875 	if (new_tx)
2876 		vsi->req_txq = new_tx;
2877 	if (new_rx)
2878 		vsi->req_rxq = new_rx;
2879 
2880 	/* set for the next time the netdev is started */
2881 	if (!netif_running(vsi->netdev)) {
2882 		ice_vsi_rebuild(vsi, false);
2883 		dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
2884 		goto done;
2885 	}
2886 
2887 	ice_vsi_close(vsi);
2888 	ice_vsi_rebuild(vsi, false);
2889 	ice_pf_dcb_recfg(pf);
2890 	ice_vsi_open(vsi);
2891 done:
2892 	clear_bit(__ICE_CFG_BUSY, pf->state);
2893 	return err;
2894 }
2895 
2896 /**
2897  * ice_log_pkg_init - log result of DDP package load
2898  * @hw: pointer to hardware info
2899  * @status: status of package load
2900  */
2901 static void
2902 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status)
2903 {
2904 	struct ice_pf *pf = (struct ice_pf *)hw->back;
2905 	struct device *dev = ice_pf_to_dev(pf);
2906 
2907 	switch (*status) {
2908 	case ICE_SUCCESS:
2909 		/* The package download AdminQ command returned success because
2910 		 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
2911 		 * already a package loaded on the device.
2912 		 */
2913 		if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
2914 		    hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
2915 		    hw->pkg_ver.update == hw->active_pkg_ver.update &&
2916 		    hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
2917 		    !memcmp(hw->pkg_name, hw->active_pkg_name,
2918 			    sizeof(hw->pkg_name))) {
2919 			if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST)
2920 				dev_info(dev,
2921 					 "DDP package already present on device: %s version %d.%d.%d.%d\n",
2922 					 hw->active_pkg_name,
2923 					 hw->active_pkg_ver.major,
2924 					 hw->active_pkg_ver.minor,
2925 					 hw->active_pkg_ver.update,
2926 					 hw->active_pkg_ver.draft);
2927 			else
2928 				dev_info(dev,
2929 					 "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
2930 					 hw->active_pkg_name,
2931 					 hw->active_pkg_ver.major,
2932 					 hw->active_pkg_ver.minor,
2933 					 hw->active_pkg_ver.update,
2934 					 hw->active_pkg_ver.draft);
2935 		} else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
2936 			   hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
2937 			dev_err(dev,
2938 				"The device has a DDP package that is not supported by the driver.  The device has package '%s' version %d.%d.x.x.  The driver requires version %d.%d.x.x.  Entering Safe Mode.\n",
2939 				hw->active_pkg_name,
2940 				hw->active_pkg_ver.major,
2941 				hw->active_pkg_ver.minor,
2942 				ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2943 			*status = ICE_ERR_NOT_SUPPORTED;
2944 		} else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2945 			   hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
2946 			dev_info(dev,
2947 				 "The driver could not load the DDP package file because a compatible DDP package is already present on the device.  The device has package '%s' version %d.%d.%d.%d.  The package file found by the driver: '%s' version %d.%d.%d.%d.\n",
2948 				 hw->active_pkg_name,
2949 				 hw->active_pkg_ver.major,
2950 				 hw->active_pkg_ver.minor,
2951 				 hw->active_pkg_ver.update,
2952 				 hw->active_pkg_ver.draft,
2953 				 hw->pkg_name,
2954 				 hw->pkg_ver.major,
2955 				 hw->pkg_ver.minor,
2956 				 hw->pkg_ver.update,
2957 				 hw->pkg_ver.draft);
2958 		} else {
2959 			dev_err(dev,
2960 				"An unknown error occurred when loading the DDP package, please reboot the system.  If the problem persists, update the NVM.  Entering Safe Mode.\n");
2961 			*status = ICE_ERR_NOT_SUPPORTED;
2962 		}
2963 		break;
2964 	case ICE_ERR_BUF_TOO_SHORT:
2965 		/* fall-through */
2966 	case ICE_ERR_CFG:
2967 		dev_err(dev,
2968 			"The DDP package file is invalid. Entering Safe Mode.\n");
2969 		break;
2970 	case ICE_ERR_NOT_SUPPORTED:
2971 		/* Package File version not supported */
2972 		if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ ||
2973 		    (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2974 		     hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR))
2975 			dev_err(dev,
2976 				"The DDP package file version is higher than the driver supports.  Please use an updated driver.  Entering Safe Mode.\n");
2977 		else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ ||
2978 			 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2979 			  hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR))
2980 			dev_err(dev,
2981 				"The DDP package file version is lower than the driver supports.  The driver requires version %d.%d.x.x.  Please use an updated DDP Package file.  Entering Safe Mode.\n",
2982 				ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2983 		break;
2984 	case ICE_ERR_AQ_ERROR:
2985 		switch (hw->pkg_dwnld_status) {
2986 		case ICE_AQ_RC_ENOSEC:
2987 		case ICE_AQ_RC_EBADSIG:
2988 			dev_err(dev,
2989 				"The DDP package could not be loaded because its signature is not valid.  Please use a valid DDP Package.  Entering Safe Mode.\n");
2990 			return;
2991 		case ICE_AQ_RC_ESVN:
2992 			dev_err(dev,
2993 				"The DDP Package could not be loaded because its security revision is too low.  Please use an updated DDP Package.  Entering Safe Mode.\n");
2994 			return;
2995 		case ICE_AQ_RC_EBADMAN:
2996 		case ICE_AQ_RC_EBADBUF:
2997 			dev_err(dev,
2998 				"An error occurred on the device while loading the DDP package.  The device will be reset.\n");
2999 			return;
3000 		default:
3001 			break;
3002 		}
3003 		/* fall-through */
3004 	default:
3005 		dev_err(dev,
3006 			"An unknown error (%d) occurred when loading the DDP package.  Entering Safe Mode.\n",
3007 			*status);
3008 		break;
3009 	}
3010 }
3011 
3012 /**
3013  * ice_load_pkg - load/reload the DDP Package file
3014  * @firmware: firmware structure when firmware requested or NULL for reload
3015  * @pf: pointer to the PF instance
3016  *
3017  * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
3018  * initialize HW tables.
3019  */
3020 static void
3021 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
3022 {
3023 	enum ice_status status = ICE_ERR_PARAM;
3024 	struct device *dev = ice_pf_to_dev(pf);
3025 	struct ice_hw *hw = &pf->hw;
3026 
3027 	/* Load DDP Package */
3028 	if (firmware && !hw->pkg_copy) {
3029 		status = ice_copy_and_init_pkg(hw, firmware->data,
3030 					       firmware->size);
3031 		ice_log_pkg_init(hw, &status);
3032 	} else if (!firmware && hw->pkg_copy) {
3033 		/* Reload package during rebuild after CORER/GLOBR reset */
3034 		status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
3035 		ice_log_pkg_init(hw, &status);
3036 	} else {
3037 		dev_err(dev,
3038 			"The DDP package file failed to load. Entering Safe Mode.\n");
3039 	}
3040 
3041 	if (status) {
3042 		/* Safe Mode */
3043 		clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3044 		return;
3045 	}
3046 
3047 	/* Successful download package is the precondition for advanced
3048 	 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
3049 	 */
3050 	set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3051 }
3052 
3053 /**
3054  * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
3055  * @pf: pointer to the PF structure
3056  *
3057  * There is no error returned here because the driver should be able to handle
3058  * 128 Byte cache lines, so we only print a warning in case issues are seen,
3059  * specifically with Tx.
3060  */
3061 static void ice_verify_cacheline_size(struct ice_pf *pf)
3062 {
3063 	if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
3064 		dev_warn(ice_pf_to_dev(pf),
3065 			 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
3066 			 ICE_CACHE_LINE_BYTES);
3067 }
3068 
3069 /**
3070  * ice_send_version - update firmware with driver version
3071  * @pf: PF struct
3072  *
3073  * Returns ICE_SUCCESS on success, else error code
3074  */
3075 static enum ice_status ice_send_version(struct ice_pf *pf)
3076 {
3077 	struct ice_driver_ver dv;
3078 
3079 	dv.major_ver = DRV_VERSION_MAJOR;
3080 	dv.minor_ver = DRV_VERSION_MINOR;
3081 	dv.build_ver = DRV_VERSION_BUILD;
3082 	dv.subbuild_ver = 0;
3083 	strscpy((char *)dv.driver_string, DRV_VERSION,
3084 		sizeof(dv.driver_string));
3085 	return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
3086 }
3087 
3088 /**
3089  * ice_get_opt_fw_name - return optional firmware file name or NULL
3090  * @pf: pointer to the PF instance
3091  */
3092 static char *ice_get_opt_fw_name(struct ice_pf *pf)
3093 {
3094 	/* Optional firmware name same as default with additional dash
3095 	 * followed by a EUI-64 identifier (PCIe Device Serial Number)
3096 	 */
3097 	struct pci_dev *pdev = pf->pdev;
3098 	char *opt_fw_filename = NULL;
3099 	u32 dword;
3100 	u8 dsn[8];
3101 	int pos;
3102 
3103 	/* Determine the name of the optional file using the DSN (two
3104 	 * dwords following the start of the DSN Capability).
3105 	 */
3106 	pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
3107 	if (pos) {
3108 		opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
3109 		if (!opt_fw_filename)
3110 			return NULL;
3111 
3112 		pci_read_config_dword(pdev, pos + 4, &dword);
3113 		put_unaligned_le32(dword, &dsn[0]);
3114 		pci_read_config_dword(pdev, pos + 8, &dword);
3115 		put_unaligned_le32(dword, &dsn[4]);
3116 		snprintf(opt_fw_filename, NAME_MAX,
3117 			 "%sice-%02x%02x%02x%02x%02x%02x%02x%02x.pkg",
3118 			 ICE_DDP_PKG_PATH,
3119 			 dsn[7], dsn[6], dsn[5], dsn[4],
3120 			 dsn[3], dsn[2], dsn[1], dsn[0]);
3121 	}
3122 
3123 	return opt_fw_filename;
3124 }
3125 
3126 /**
3127  * ice_request_fw - Device initialization routine
3128  * @pf: pointer to the PF instance
3129  */
3130 static void ice_request_fw(struct ice_pf *pf)
3131 {
3132 	char *opt_fw_filename = ice_get_opt_fw_name(pf);
3133 	const struct firmware *firmware = NULL;
3134 	struct device *dev = ice_pf_to_dev(pf);
3135 	int err = 0;
3136 
3137 	/* optional device-specific DDP (if present) overrides the default DDP
3138 	 * package file. kernel logs a debug message if the file doesn't exist,
3139 	 * and warning messages for other errors.
3140 	 */
3141 	if (opt_fw_filename) {
3142 		err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
3143 		if (err) {
3144 			kfree(opt_fw_filename);
3145 			goto dflt_pkg_load;
3146 		}
3147 
3148 		/* request for firmware was successful. Download to device */
3149 		ice_load_pkg(firmware, pf);
3150 		kfree(opt_fw_filename);
3151 		release_firmware(firmware);
3152 		return;
3153 	}
3154 
3155 dflt_pkg_load:
3156 	err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
3157 	if (err) {
3158 		dev_err(dev,
3159 			"The DDP package file was not found or could not be read. Entering Safe Mode\n");
3160 		return;
3161 	}
3162 
3163 	/* request for firmware was successful. Download to device */
3164 	ice_load_pkg(firmware, pf);
3165 	release_firmware(firmware);
3166 }
3167 
3168 /**
3169  * ice_probe - Device initialization routine
3170  * @pdev: PCI device information struct
3171  * @ent: entry in ice_pci_tbl
3172  *
3173  * Returns 0 on success, negative on failure
3174  */
3175 static int
3176 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
3177 {
3178 	struct device *dev = &pdev->dev;
3179 	struct ice_pf *pf;
3180 	struct ice_hw *hw;
3181 	int err;
3182 
3183 	/* this driver uses devres, see Documentation/driver-api/driver-model/devres.rst */
3184 	err = pcim_enable_device(pdev);
3185 	if (err)
3186 		return err;
3187 
3188 	err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
3189 	if (err) {
3190 		dev_err(dev, "BAR0 I/O map error %d\n", err);
3191 		return err;
3192 	}
3193 
3194 	pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
3195 	if (!pf)
3196 		return -ENOMEM;
3197 
3198 	/* set up for high or low DMA */
3199 	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
3200 	if (err)
3201 		err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
3202 	if (err) {
3203 		dev_err(dev, "DMA configuration failed: 0x%x\n", err);
3204 		return err;
3205 	}
3206 
3207 	pci_enable_pcie_error_reporting(pdev);
3208 	pci_set_master(pdev);
3209 
3210 	pf->pdev = pdev;
3211 	pci_set_drvdata(pdev, pf);
3212 	set_bit(__ICE_DOWN, pf->state);
3213 	/* Disable service task until DOWN bit is cleared */
3214 	set_bit(__ICE_SERVICE_DIS, pf->state);
3215 
3216 	hw = &pf->hw;
3217 	hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
3218 	pci_save_state(pdev);
3219 
3220 	hw->back = pf;
3221 	hw->vendor_id = pdev->vendor;
3222 	hw->device_id = pdev->device;
3223 	pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3224 	hw->subsystem_vendor_id = pdev->subsystem_vendor;
3225 	hw->subsystem_device_id = pdev->subsystem_device;
3226 	hw->bus.device = PCI_SLOT(pdev->devfn);
3227 	hw->bus.func = PCI_FUNC(pdev->devfn);
3228 	ice_set_ctrlq_len(hw);
3229 
3230 	pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
3231 
3232 #ifndef CONFIG_DYNAMIC_DEBUG
3233 	if (debug < -1)
3234 		hw->debug_mask = debug;
3235 #endif
3236 
3237 	err = ice_init_hw(hw);
3238 	if (err) {
3239 		dev_err(dev, "ice_init_hw failed: %d\n", err);
3240 		err = -EIO;
3241 		goto err_exit_unroll;
3242 	}
3243 
3244 	dev_info(dev, "firmware %d.%d.%d api %d.%d.%d nvm %s build 0x%08x\n",
3245 		 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_patch,
3246 		 hw->api_maj_ver, hw->api_min_ver, hw->api_patch,
3247 		 ice_nvm_version_str(hw), hw->fw_build);
3248 
3249 	ice_request_fw(pf);
3250 
3251 	/* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
3252 	 * set in pf->state, which will cause ice_is_safe_mode to return
3253 	 * true
3254 	 */
3255 	if (ice_is_safe_mode(pf)) {
3256 		dev_err(dev,
3257 			"Package download failed. Advanced features disabled - Device now in Safe Mode\n");
3258 		/* we already got function/device capabilities but these don't
3259 		 * reflect what the driver needs to do in safe mode. Instead of
3260 		 * adding conditional logic everywhere to ignore these
3261 		 * device/function capabilities, override them.
3262 		 */
3263 		ice_set_safe_mode_caps(hw);
3264 	}
3265 
3266 	err = ice_init_pf(pf);
3267 	if (err) {
3268 		dev_err(dev, "ice_init_pf failed: %d\n", err);
3269 		goto err_init_pf_unroll;
3270 	}
3271 
3272 	pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
3273 	if (!pf->num_alloc_vsi) {
3274 		err = -EIO;
3275 		goto err_init_pf_unroll;
3276 	}
3277 
3278 	pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
3279 			       GFP_KERNEL);
3280 	if (!pf->vsi) {
3281 		err = -ENOMEM;
3282 		goto err_init_pf_unroll;
3283 	}
3284 
3285 	err = ice_init_interrupt_scheme(pf);
3286 	if (err) {
3287 		dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
3288 		err = -EIO;
3289 		goto err_init_interrupt_unroll;
3290 	}
3291 
3292 	/* Driver is mostly up */
3293 	clear_bit(__ICE_DOWN, pf->state);
3294 
3295 	/* In case of MSIX we are going to setup the misc vector right here
3296 	 * to handle admin queue events etc. In case of legacy and MSI
3297 	 * the misc functionality and queue processing is combined in
3298 	 * the same vector and that gets setup at open.
3299 	 */
3300 	err = ice_req_irq_msix_misc(pf);
3301 	if (err) {
3302 		dev_err(dev, "setup of misc vector failed: %d\n", err);
3303 		goto err_init_interrupt_unroll;
3304 	}
3305 
3306 	/* create switch struct for the switch element created by FW on boot */
3307 	pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
3308 	if (!pf->first_sw) {
3309 		err = -ENOMEM;
3310 		goto err_msix_misc_unroll;
3311 	}
3312 
3313 	if (hw->evb_veb)
3314 		pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
3315 	else
3316 		pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
3317 
3318 	pf->first_sw->pf = pf;
3319 
3320 	/* record the sw_id available for later use */
3321 	pf->first_sw->sw_id = hw->port_info->sw_id;
3322 
3323 	err = ice_setup_pf_sw(pf);
3324 	if (err) {
3325 		dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
3326 		goto err_alloc_sw_unroll;
3327 	}
3328 
3329 	clear_bit(__ICE_SERVICE_DIS, pf->state);
3330 
3331 	/* tell the firmware we are up */
3332 	err = ice_send_version(pf);
3333 	if (err) {
3334 		dev_err(dev,
3335 			"probe failed sending driver version %s. error: %d\n",
3336 			ice_drv_ver, err);
3337 		goto err_alloc_sw_unroll;
3338 	}
3339 
3340 	/* since everything is good, start the service timer */
3341 	mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3342 
3343 	err = ice_init_link_events(pf->hw.port_info);
3344 	if (err) {
3345 		dev_err(dev, "ice_init_link_events failed: %d\n", err);
3346 		goto err_alloc_sw_unroll;
3347 	}
3348 
3349 	ice_verify_cacheline_size(pf);
3350 
3351 	/* If no DDP driven features have to be setup, return here */
3352 	if (ice_is_safe_mode(pf))
3353 		return 0;
3354 
3355 	/* initialize DDP driven features */
3356 
3357 	/* Note: DCB init failure is non-fatal to load */
3358 	if (ice_init_pf_dcb(pf, false)) {
3359 		clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3360 		clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
3361 	} else {
3362 		ice_cfg_lldp_mib_change(&pf->hw, true);
3363 	}
3364 
3365 	/* print PCI link speed and width */
3366 	pcie_print_link_status(pf->pdev);
3367 
3368 	return 0;
3369 
3370 err_alloc_sw_unroll:
3371 	set_bit(__ICE_SERVICE_DIS, pf->state);
3372 	set_bit(__ICE_DOWN, pf->state);
3373 	devm_kfree(dev, pf->first_sw);
3374 err_msix_misc_unroll:
3375 	ice_free_irq_msix_misc(pf);
3376 err_init_interrupt_unroll:
3377 	ice_clear_interrupt_scheme(pf);
3378 	devm_kfree(dev, pf->vsi);
3379 err_init_pf_unroll:
3380 	ice_deinit_pf(pf);
3381 	ice_deinit_hw(hw);
3382 err_exit_unroll:
3383 	pci_disable_pcie_error_reporting(pdev);
3384 	return err;
3385 }
3386 
3387 /**
3388  * ice_remove - Device removal routine
3389  * @pdev: PCI device information struct
3390  */
3391 static void ice_remove(struct pci_dev *pdev)
3392 {
3393 	struct ice_pf *pf = pci_get_drvdata(pdev);
3394 	int i;
3395 
3396 	if (!pf)
3397 		return;
3398 
3399 	for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
3400 		if (!ice_is_reset_in_progress(pf->state))
3401 			break;
3402 		msleep(100);
3403 	}
3404 
3405 	set_bit(__ICE_DOWN, pf->state);
3406 	ice_service_task_stop(pf);
3407 
3408 	if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
3409 		ice_free_vfs(pf);
3410 	ice_vsi_release_all(pf);
3411 	ice_free_irq_msix_misc(pf);
3412 	ice_for_each_vsi(pf, i) {
3413 		if (!pf->vsi[i])
3414 			continue;
3415 		ice_vsi_free_q_vectors(pf->vsi[i]);
3416 	}
3417 	ice_deinit_pf(pf);
3418 	ice_deinit_hw(&pf->hw);
3419 	/* Issue a PFR as part of the prescribed driver unload flow.  Do not
3420 	 * do it via ice_schedule_reset() since there is no need to rebuild
3421 	 * and the service task is already stopped.
3422 	 */
3423 	ice_reset(&pf->hw, ICE_RESET_PFR);
3424 	pci_wait_for_pending_transaction(pdev);
3425 	ice_clear_interrupt_scheme(pf);
3426 	pci_disable_pcie_error_reporting(pdev);
3427 }
3428 
3429 /**
3430  * ice_pci_err_detected - warning that PCI error has been detected
3431  * @pdev: PCI device information struct
3432  * @err: the type of PCI error
3433  *
3434  * Called to warn that something happened on the PCI bus and the error handling
3435  * is in progress.  Allows the driver to gracefully prepare/handle PCI errors.
3436  */
3437 static pci_ers_result_t
3438 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
3439 {
3440 	struct ice_pf *pf = pci_get_drvdata(pdev);
3441 
3442 	if (!pf) {
3443 		dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
3444 			__func__, err);
3445 		return PCI_ERS_RESULT_DISCONNECT;
3446 	}
3447 
3448 	if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3449 		ice_service_task_stop(pf);
3450 
3451 		if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3452 			set_bit(__ICE_PFR_REQ, pf->state);
3453 			ice_prepare_for_reset(pf);
3454 		}
3455 	}
3456 
3457 	return PCI_ERS_RESULT_NEED_RESET;
3458 }
3459 
3460 /**
3461  * ice_pci_err_slot_reset - a PCI slot reset has just happened
3462  * @pdev: PCI device information struct
3463  *
3464  * Called to determine if the driver can recover from the PCI slot reset by
3465  * using a register read to determine if the device is recoverable.
3466  */
3467 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
3468 {
3469 	struct ice_pf *pf = pci_get_drvdata(pdev);
3470 	pci_ers_result_t result;
3471 	int err;
3472 	u32 reg;
3473 
3474 	err = pci_enable_device_mem(pdev);
3475 	if (err) {
3476 		dev_err(&pdev->dev,
3477 			"Cannot re-enable PCI device after reset, error %d\n",
3478 			err);
3479 		result = PCI_ERS_RESULT_DISCONNECT;
3480 	} else {
3481 		pci_set_master(pdev);
3482 		pci_restore_state(pdev);
3483 		pci_save_state(pdev);
3484 		pci_wake_from_d3(pdev, false);
3485 
3486 		/* Check for life */
3487 		reg = rd32(&pf->hw, GLGEN_RTRIG);
3488 		if (!reg)
3489 			result = PCI_ERS_RESULT_RECOVERED;
3490 		else
3491 			result = PCI_ERS_RESULT_DISCONNECT;
3492 	}
3493 
3494 	err = pci_cleanup_aer_uncorrect_error_status(pdev);
3495 	if (err)
3496 		dev_dbg(&pdev->dev,
3497 			"pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
3498 			err);
3499 		/* non-fatal, continue */
3500 
3501 	return result;
3502 }
3503 
3504 /**
3505  * ice_pci_err_resume - restart operations after PCI error recovery
3506  * @pdev: PCI device information struct
3507  *
3508  * Called to allow the driver to bring things back up after PCI error and/or
3509  * reset recovery have finished
3510  */
3511 static void ice_pci_err_resume(struct pci_dev *pdev)
3512 {
3513 	struct ice_pf *pf = pci_get_drvdata(pdev);
3514 
3515 	if (!pf) {
3516 		dev_err(&pdev->dev,
3517 			"%s failed, device is unrecoverable\n", __func__);
3518 		return;
3519 	}
3520 
3521 	if (test_bit(__ICE_SUSPENDED, pf->state)) {
3522 		dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
3523 			__func__);
3524 		return;
3525 	}
3526 
3527 	ice_do_reset(pf, ICE_RESET_PFR);
3528 	ice_service_task_restart(pf);
3529 	mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3530 }
3531 
3532 /**
3533  * ice_pci_err_reset_prepare - prepare device driver for PCI reset
3534  * @pdev: PCI device information struct
3535  */
3536 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
3537 {
3538 	struct ice_pf *pf = pci_get_drvdata(pdev);
3539 
3540 	if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3541 		ice_service_task_stop(pf);
3542 
3543 		if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3544 			set_bit(__ICE_PFR_REQ, pf->state);
3545 			ice_prepare_for_reset(pf);
3546 		}
3547 	}
3548 }
3549 
3550 /**
3551  * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
3552  * @pdev: PCI device information struct
3553  */
3554 static void ice_pci_err_reset_done(struct pci_dev *pdev)
3555 {
3556 	ice_pci_err_resume(pdev);
3557 }
3558 
3559 /* ice_pci_tbl - PCI Device ID Table
3560  *
3561  * Wildcard entries (PCI_ANY_ID) should come last
3562  * Last entry must be all 0s
3563  *
3564  * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3565  *   Class, Class Mask, private data (not used) }
3566  */
3567 static const struct pci_device_id ice_pci_tbl[] = {
3568 	{ PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
3569 	{ PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
3570 	{ PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
3571 	/* required last entry */
3572 	{ 0, }
3573 };
3574 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
3575 
3576 static const struct pci_error_handlers ice_pci_err_handler = {
3577 	.error_detected = ice_pci_err_detected,
3578 	.slot_reset = ice_pci_err_slot_reset,
3579 	.reset_prepare = ice_pci_err_reset_prepare,
3580 	.reset_done = ice_pci_err_reset_done,
3581 	.resume = ice_pci_err_resume
3582 };
3583 
3584 static struct pci_driver ice_driver = {
3585 	.name = KBUILD_MODNAME,
3586 	.id_table = ice_pci_tbl,
3587 	.probe = ice_probe,
3588 	.remove = ice_remove,
3589 	.sriov_configure = ice_sriov_configure,
3590 	.err_handler = &ice_pci_err_handler
3591 };
3592 
3593 /**
3594  * ice_module_init - Driver registration routine
3595  *
3596  * ice_module_init is the first routine called when the driver is
3597  * loaded. All it does is register with the PCI subsystem.
3598  */
3599 static int __init ice_module_init(void)
3600 {
3601 	int status;
3602 
3603 	pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
3604 	pr_info("%s\n", ice_copyright);
3605 
3606 	ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
3607 	if (!ice_wq) {
3608 		pr_err("Failed to create workqueue\n");
3609 		return -ENOMEM;
3610 	}
3611 
3612 	status = pci_register_driver(&ice_driver);
3613 	if (status) {
3614 		pr_err("failed to register PCI driver, err %d\n", status);
3615 		destroy_workqueue(ice_wq);
3616 	}
3617 
3618 	return status;
3619 }
3620 module_init(ice_module_init);
3621 
3622 /**
3623  * ice_module_exit - Driver exit cleanup routine
3624  *
3625  * ice_module_exit is called just before the driver is removed
3626  * from memory.
3627  */
3628 static void __exit ice_module_exit(void)
3629 {
3630 	pci_unregister_driver(&ice_driver);
3631 	destroy_workqueue(ice_wq);
3632 	pr_info("module unloaded\n");
3633 }
3634 module_exit(ice_module_exit);
3635 
3636 /**
3637  * ice_set_mac_address - NDO callback to set MAC address
3638  * @netdev: network interface device structure
3639  * @pi: pointer to an address structure
3640  *
3641  * Returns 0 on success, negative on failure
3642  */
3643 static int ice_set_mac_address(struct net_device *netdev, void *pi)
3644 {
3645 	struct ice_netdev_priv *np = netdev_priv(netdev);
3646 	struct ice_vsi *vsi = np->vsi;
3647 	struct ice_pf *pf = vsi->back;
3648 	struct ice_hw *hw = &pf->hw;
3649 	struct sockaddr *addr = pi;
3650 	enum ice_status status;
3651 	u8 flags = 0;
3652 	int err = 0;
3653 	u8 *mac;
3654 
3655 	mac = (u8 *)addr->sa_data;
3656 
3657 	if (!is_valid_ether_addr(mac))
3658 		return -EADDRNOTAVAIL;
3659 
3660 	if (ether_addr_equal(netdev->dev_addr, mac)) {
3661 		netdev_warn(netdev, "already using mac %pM\n", mac);
3662 		return 0;
3663 	}
3664 
3665 	if (test_bit(__ICE_DOWN, pf->state) ||
3666 	    ice_is_reset_in_progress(pf->state)) {
3667 		netdev_err(netdev, "can't set mac %pM. device not ready\n",
3668 			   mac);
3669 		return -EBUSY;
3670 	}
3671 
3672 	/* When we change the MAC address we also have to change the MAC address
3673 	 * based filter rules that were created previously for the old MAC
3674 	 * address. So first, we remove the old filter rule using ice_remove_mac
3675 	 * and then create a new filter rule using ice_add_mac via
3676 	 * ice_vsi_cfg_mac_fltr function call for both add and/or remove
3677 	 * filters.
3678 	 */
3679 	status = ice_vsi_cfg_mac_fltr(vsi, netdev->dev_addr, false);
3680 	if (status) {
3681 		err = -EADDRNOTAVAIL;
3682 		goto err_update_filters;
3683 	}
3684 
3685 	status = ice_vsi_cfg_mac_fltr(vsi, mac, true);
3686 	if (status) {
3687 		err = -EADDRNOTAVAIL;
3688 		goto err_update_filters;
3689 	}
3690 
3691 err_update_filters:
3692 	if (err) {
3693 		netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
3694 			   mac);
3695 		return err;
3696 	}
3697 
3698 	/* change the netdev's MAC address */
3699 	memcpy(netdev->dev_addr, mac, netdev->addr_len);
3700 	netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
3701 		   netdev->dev_addr);
3702 
3703 	/* write new MAC address to the firmware */
3704 	flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3705 	status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
3706 	if (status) {
3707 		netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
3708 			   mac, status);
3709 	}
3710 	return 0;
3711 }
3712 
3713 /**
3714  * ice_set_rx_mode - NDO callback to set the netdev filters
3715  * @netdev: network interface device structure
3716  */
3717 static void ice_set_rx_mode(struct net_device *netdev)
3718 {
3719 	struct ice_netdev_priv *np = netdev_priv(netdev);
3720 	struct ice_vsi *vsi = np->vsi;
3721 
3722 	if (!vsi)
3723 		return;
3724 
3725 	/* Set the flags to synchronize filters
3726 	 * ndo_set_rx_mode may be triggered even without a change in netdev
3727 	 * flags
3728 	 */
3729 	set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
3730 	set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
3731 	set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
3732 
3733 	/* schedule our worker thread which will take care of
3734 	 * applying the new filter changes
3735 	 */
3736 	ice_service_task_schedule(vsi->back);
3737 }
3738 
3739 /**
3740  * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
3741  * @netdev: network interface device structure
3742  * @queue_index: Queue ID
3743  * @maxrate: maximum bandwidth in Mbps
3744  */
3745 static int
3746 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
3747 {
3748 	struct ice_netdev_priv *np = netdev_priv(netdev);
3749 	struct ice_vsi *vsi = np->vsi;
3750 	enum ice_status status;
3751 	u16 q_handle;
3752 	u8 tc;
3753 
3754 	/* Validate maxrate requested is within permitted range */
3755 	if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
3756 		netdev_err(netdev,
3757 			   "Invalid max rate %d specified for the queue %d\n",
3758 			   maxrate, queue_index);
3759 		return -EINVAL;
3760 	}
3761 
3762 	q_handle = vsi->tx_rings[queue_index]->q_handle;
3763 	tc = ice_dcb_get_tc(vsi, queue_index);
3764 
3765 	/* Set BW back to default, when user set maxrate to 0 */
3766 	if (!maxrate)
3767 		status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
3768 					       q_handle, ICE_MAX_BW);
3769 	else
3770 		status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
3771 					  q_handle, ICE_MAX_BW, maxrate * 1000);
3772 	if (status) {
3773 		netdev_err(netdev,
3774 			   "Unable to set Tx max rate, error %d\n", status);
3775 		return -EIO;
3776 	}
3777 
3778 	return 0;
3779 }
3780 
3781 /**
3782  * ice_fdb_add - add an entry to the hardware database
3783  * @ndm: the input from the stack
3784  * @tb: pointer to array of nladdr (unused)
3785  * @dev: the net device pointer
3786  * @addr: the MAC address entry being added
3787  * @vid: VLAN ID
3788  * @flags: instructions from stack about fdb operation
3789  * @extack: netlink extended ack
3790  */
3791 static int
3792 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
3793 	    struct net_device *dev, const unsigned char *addr, u16 vid,
3794 	    u16 flags, struct netlink_ext_ack __always_unused *extack)
3795 {
3796 	int err;
3797 
3798 	if (vid) {
3799 		netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3800 		return -EINVAL;
3801 	}
3802 	if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
3803 		netdev_err(dev, "FDB only supports static addresses\n");
3804 		return -EINVAL;
3805 	}
3806 
3807 	if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
3808 		err = dev_uc_add_excl(dev, addr);
3809 	else if (is_multicast_ether_addr(addr))
3810 		err = dev_mc_add_excl(dev, addr);
3811 	else
3812 		err = -EINVAL;
3813 
3814 	/* Only return duplicate errors if NLM_F_EXCL is set */
3815 	if (err == -EEXIST && !(flags & NLM_F_EXCL))
3816 		err = 0;
3817 
3818 	return err;
3819 }
3820 
3821 /**
3822  * ice_fdb_del - delete an entry from the hardware database
3823  * @ndm: the input from the stack
3824  * @tb: pointer to array of nladdr (unused)
3825  * @dev: the net device pointer
3826  * @addr: the MAC address entry being added
3827  * @vid: VLAN ID
3828  */
3829 static int
3830 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
3831 	    struct net_device *dev, const unsigned char *addr,
3832 	    __always_unused u16 vid)
3833 {
3834 	int err;
3835 
3836 	if (ndm->ndm_state & NUD_PERMANENT) {
3837 		netdev_err(dev, "FDB only supports static addresses\n");
3838 		return -EINVAL;
3839 	}
3840 
3841 	if (is_unicast_ether_addr(addr))
3842 		err = dev_uc_del(dev, addr);
3843 	else if (is_multicast_ether_addr(addr))
3844 		err = dev_mc_del(dev, addr);
3845 	else
3846 		err = -EINVAL;
3847 
3848 	return err;
3849 }
3850 
3851 /**
3852  * ice_set_features - set the netdev feature flags
3853  * @netdev: ptr to the netdev being adjusted
3854  * @features: the feature set that the stack is suggesting
3855  */
3856 static int
3857 ice_set_features(struct net_device *netdev, netdev_features_t features)
3858 {
3859 	struct ice_netdev_priv *np = netdev_priv(netdev);
3860 	struct ice_vsi *vsi = np->vsi;
3861 	struct ice_pf *pf = vsi->back;
3862 	int ret = 0;
3863 
3864 	/* Don't set any netdev advanced features with device in Safe Mode */
3865 	if (ice_is_safe_mode(vsi->back)) {
3866 		dev_err(&vsi->back->pdev->dev,
3867 			"Device is in Safe Mode - not enabling advanced netdev features\n");
3868 		return ret;
3869 	}
3870 
3871 	/* Do not change setting during reset */
3872 	if (ice_is_reset_in_progress(pf->state)) {
3873 		dev_err(&vsi->back->pdev->dev,
3874 			"Device is resetting, changing advanced netdev features temporarily unavailable.\n");
3875 		return -EBUSY;
3876 	}
3877 
3878 	/* Multiple features can be changed in one call so keep features in
3879 	 * separate if/else statements to guarantee each feature is checked
3880 	 */
3881 	if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
3882 		ret = ice_vsi_manage_rss_lut(vsi, true);
3883 	else if (!(features & NETIF_F_RXHASH) &&
3884 		 netdev->features & NETIF_F_RXHASH)
3885 		ret = ice_vsi_manage_rss_lut(vsi, false);
3886 
3887 	if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
3888 	    !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3889 		ret = ice_vsi_manage_vlan_stripping(vsi, true);
3890 	else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
3891 		 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3892 		ret = ice_vsi_manage_vlan_stripping(vsi, false);
3893 
3894 	if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
3895 	    !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3896 		ret = ice_vsi_manage_vlan_insertion(vsi);
3897 	else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
3898 		 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3899 		ret = ice_vsi_manage_vlan_insertion(vsi);
3900 
3901 	if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3902 	    !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3903 		ret = ice_cfg_vlan_pruning(vsi, true, false);
3904 	else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3905 		 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3906 		ret = ice_cfg_vlan_pruning(vsi, false, false);
3907 
3908 	return ret;
3909 }
3910 
3911 /**
3912  * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
3913  * @vsi: VSI to setup VLAN properties for
3914  */
3915 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
3916 {
3917 	int ret = 0;
3918 
3919 	if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3920 		ret = ice_vsi_manage_vlan_stripping(vsi, true);
3921 	if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
3922 		ret = ice_vsi_manage_vlan_insertion(vsi);
3923 
3924 	return ret;
3925 }
3926 
3927 /**
3928  * ice_vsi_cfg - Setup the VSI
3929  * @vsi: the VSI being configured
3930  *
3931  * Return 0 on success and negative value on error
3932  */
3933 int ice_vsi_cfg(struct ice_vsi *vsi)
3934 {
3935 	int err;
3936 
3937 	if (vsi->netdev) {
3938 		ice_set_rx_mode(vsi->netdev);
3939 
3940 		err = ice_vsi_vlan_setup(vsi);
3941 
3942 		if (err)
3943 			return err;
3944 	}
3945 	ice_vsi_cfg_dcb_rings(vsi);
3946 
3947 	err = ice_vsi_cfg_lan_txqs(vsi);
3948 	if (!err && ice_is_xdp_ena_vsi(vsi))
3949 		err = ice_vsi_cfg_xdp_txqs(vsi);
3950 	if (!err)
3951 		err = ice_vsi_cfg_rxqs(vsi);
3952 
3953 	return err;
3954 }
3955 
3956 /**
3957  * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3958  * @vsi: the VSI being configured
3959  */
3960 static void ice_napi_enable_all(struct ice_vsi *vsi)
3961 {
3962 	int q_idx;
3963 
3964 	if (!vsi->netdev)
3965 		return;
3966 
3967 	ice_for_each_q_vector(vsi, q_idx) {
3968 		struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3969 
3970 		if (q_vector->rx.ring || q_vector->tx.ring)
3971 			napi_enable(&q_vector->napi);
3972 	}
3973 }
3974 
3975 /**
3976  * ice_up_complete - Finish the last steps of bringing up a connection
3977  * @vsi: The VSI being configured
3978  *
3979  * Return 0 on success and negative value on error
3980  */
3981 static int ice_up_complete(struct ice_vsi *vsi)
3982 {
3983 	struct ice_pf *pf = vsi->back;
3984 	int err;
3985 
3986 	ice_vsi_cfg_msix(vsi);
3987 
3988 	/* Enable only Rx rings, Tx rings were enabled by the FW when the
3989 	 * Tx queue group list was configured and the context bits were
3990 	 * programmed using ice_vsi_cfg_txqs
3991 	 */
3992 	err = ice_vsi_start_rx_rings(vsi);
3993 	if (err)
3994 		return err;
3995 
3996 	clear_bit(__ICE_DOWN, vsi->state);
3997 	ice_napi_enable_all(vsi);
3998 	ice_vsi_ena_irq(vsi);
3999 
4000 	if (vsi->port_info &&
4001 	    (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
4002 	    vsi->netdev) {
4003 		ice_print_link_msg(vsi, true);
4004 		netif_tx_start_all_queues(vsi->netdev);
4005 		netif_carrier_on(vsi->netdev);
4006 	}
4007 
4008 	ice_service_task_schedule(pf);
4009 
4010 	return 0;
4011 }
4012 
4013 /**
4014  * ice_up - Bring the connection back up after being down
4015  * @vsi: VSI being configured
4016  */
4017 int ice_up(struct ice_vsi *vsi)
4018 {
4019 	int err;
4020 
4021 	err = ice_vsi_cfg(vsi);
4022 	if (!err)
4023 		err = ice_up_complete(vsi);
4024 
4025 	return err;
4026 }
4027 
4028 /**
4029  * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
4030  * @ring: Tx or Rx ring to read stats from
4031  * @pkts: packets stats counter
4032  * @bytes: bytes stats counter
4033  *
4034  * This function fetches stats from the ring considering the atomic operations
4035  * that needs to be performed to read u64 values in 32 bit machine.
4036  */
4037 static void
4038 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
4039 {
4040 	unsigned int start;
4041 	*pkts = 0;
4042 	*bytes = 0;
4043 
4044 	if (!ring)
4045 		return;
4046 	do {
4047 		start = u64_stats_fetch_begin_irq(&ring->syncp);
4048 		*pkts = ring->stats.pkts;
4049 		*bytes = ring->stats.bytes;
4050 	} while (u64_stats_fetch_retry_irq(&ring->syncp, start));
4051 }
4052 
4053 /**
4054  * ice_update_vsi_ring_stats - Update VSI stats counters
4055  * @vsi: the VSI to be updated
4056  */
4057 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
4058 {
4059 	struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
4060 	struct ice_ring *ring;
4061 	u64 pkts, bytes;
4062 	int i;
4063 
4064 	/* reset netdev stats */
4065 	vsi_stats->tx_packets = 0;
4066 	vsi_stats->tx_bytes = 0;
4067 	vsi_stats->rx_packets = 0;
4068 	vsi_stats->rx_bytes = 0;
4069 
4070 	/* reset non-netdev (extended) stats */
4071 	vsi->tx_restart = 0;
4072 	vsi->tx_busy = 0;
4073 	vsi->tx_linearize = 0;
4074 	vsi->rx_buf_failed = 0;
4075 	vsi->rx_page_failed = 0;
4076 
4077 	rcu_read_lock();
4078 
4079 	/* update Tx rings counters */
4080 	ice_for_each_txq(vsi, i) {
4081 		ring = READ_ONCE(vsi->tx_rings[i]);
4082 		ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4083 		vsi_stats->tx_packets += pkts;
4084 		vsi_stats->tx_bytes += bytes;
4085 		vsi->tx_restart += ring->tx_stats.restart_q;
4086 		vsi->tx_busy += ring->tx_stats.tx_busy;
4087 		vsi->tx_linearize += ring->tx_stats.tx_linearize;
4088 	}
4089 
4090 	/* update Rx rings counters */
4091 	ice_for_each_rxq(vsi, i) {
4092 		ring = READ_ONCE(vsi->rx_rings[i]);
4093 		ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4094 		vsi_stats->rx_packets += pkts;
4095 		vsi_stats->rx_bytes += bytes;
4096 		vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
4097 		vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
4098 	}
4099 
4100 	rcu_read_unlock();
4101 }
4102 
4103 /**
4104  * ice_update_vsi_stats - Update VSI stats counters
4105  * @vsi: the VSI to be updated
4106  */
4107 void ice_update_vsi_stats(struct ice_vsi *vsi)
4108 {
4109 	struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
4110 	struct ice_eth_stats *cur_es = &vsi->eth_stats;
4111 	struct ice_pf *pf = vsi->back;
4112 
4113 	if (test_bit(__ICE_DOWN, vsi->state) ||
4114 	    test_bit(__ICE_CFG_BUSY, pf->state))
4115 		return;
4116 
4117 	/* get stats as recorded by Tx/Rx rings */
4118 	ice_update_vsi_ring_stats(vsi);
4119 
4120 	/* get VSI stats as recorded by the hardware */
4121 	ice_update_eth_stats(vsi);
4122 
4123 	cur_ns->tx_errors = cur_es->tx_errors;
4124 	cur_ns->rx_dropped = cur_es->rx_discards;
4125 	cur_ns->tx_dropped = cur_es->tx_discards;
4126 	cur_ns->multicast = cur_es->rx_multicast;
4127 
4128 	/* update some more netdev stats if this is main VSI */
4129 	if (vsi->type == ICE_VSI_PF) {
4130 		cur_ns->rx_crc_errors = pf->stats.crc_errors;
4131 		cur_ns->rx_errors = pf->stats.crc_errors +
4132 				    pf->stats.illegal_bytes;
4133 		cur_ns->rx_length_errors = pf->stats.rx_len_errors;
4134 		/* record drops from the port level */
4135 		cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
4136 	}
4137 }
4138 
4139 /**
4140  * ice_update_pf_stats - Update PF port stats counters
4141  * @pf: PF whose stats needs to be updated
4142  */
4143 void ice_update_pf_stats(struct ice_pf *pf)
4144 {
4145 	struct ice_hw_port_stats *prev_ps, *cur_ps;
4146 	struct ice_hw *hw = &pf->hw;
4147 	u8 port;
4148 
4149 	port = hw->port_info->lport;
4150 	prev_ps = &pf->stats_prev;
4151 	cur_ps = &pf->stats;
4152 
4153 	ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
4154 			  &prev_ps->eth.rx_bytes,
4155 			  &cur_ps->eth.rx_bytes);
4156 
4157 	ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
4158 			  &prev_ps->eth.rx_unicast,
4159 			  &cur_ps->eth.rx_unicast);
4160 
4161 	ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
4162 			  &prev_ps->eth.rx_multicast,
4163 			  &cur_ps->eth.rx_multicast);
4164 
4165 	ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
4166 			  &prev_ps->eth.rx_broadcast,
4167 			  &cur_ps->eth.rx_broadcast);
4168 
4169 	ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
4170 			  &prev_ps->eth.rx_discards,
4171 			  &cur_ps->eth.rx_discards);
4172 
4173 	ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
4174 			  &prev_ps->eth.tx_bytes,
4175 			  &cur_ps->eth.tx_bytes);
4176 
4177 	ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
4178 			  &prev_ps->eth.tx_unicast,
4179 			  &cur_ps->eth.tx_unicast);
4180 
4181 	ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
4182 			  &prev_ps->eth.tx_multicast,
4183 			  &cur_ps->eth.tx_multicast);
4184 
4185 	ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
4186 			  &prev_ps->eth.tx_broadcast,
4187 			  &cur_ps->eth.tx_broadcast);
4188 
4189 	ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
4190 			  &prev_ps->tx_dropped_link_down,
4191 			  &cur_ps->tx_dropped_link_down);
4192 
4193 	ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
4194 			  &prev_ps->rx_size_64, &cur_ps->rx_size_64);
4195 
4196 	ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
4197 			  &prev_ps->rx_size_127, &cur_ps->rx_size_127);
4198 
4199 	ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
4200 			  &prev_ps->rx_size_255, &cur_ps->rx_size_255);
4201 
4202 	ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
4203 			  &prev_ps->rx_size_511, &cur_ps->rx_size_511);
4204 
4205 	ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
4206 			  &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
4207 
4208 	ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
4209 			  &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
4210 
4211 	ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
4212 			  &prev_ps->rx_size_big, &cur_ps->rx_size_big);
4213 
4214 	ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
4215 			  &prev_ps->tx_size_64, &cur_ps->tx_size_64);
4216 
4217 	ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
4218 			  &prev_ps->tx_size_127, &cur_ps->tx_size_127);
4219 
4220 	ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
4221 			  &prev_ps->tx_size_255, &cur_ps->tx_size_255);
4222 
4223 	ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
4224 			  &prev_ps->tx_size_511, &cur_ps->tx_size_511);
4225 
4226 	ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
4227 			  &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
4228 
4229 	ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
4230 			  &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
4231 
4232 	ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
4233 			  &prev_ps->tx_size_big, &cur_ps->tx_size_big);
4234 
4235 	ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
4236 			  &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
4237 
4238 	ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
4239 			  &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
4240 
4241 	ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
4242 			  &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
4243 
4244 	ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
4245 			  &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
4246 
4247 	ice_update_dcb_stats(pf);
4248 
4249 	ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
4250 			  &prev_ps->crc_errors, &cur_ps->crc_errors);
4251 
4252 	ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
4253 			  &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
4254 
4255 	ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
4256 			  &prev_ps->mac_local_faults,
4257 			  &cur_ps->mac_local_faults);
4258 
4259 	ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
4260 			  &prev_ps->mac_remote_faults,
4261 			  &cur_ps->mac_remote_faults);
4262 
4263 	ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
4264 			  &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
4265 
4266 	ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
4267 			  &prev_ps->rx_undersize, &cur_ps->rx_undersize);
4268 
4269 	ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
4270 			  &prev_ps->rx_fragments, &cur_ps->rx_fragments);
4271 
4272 	ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
4273 			  &prev_ps->rx_oversize, &cur_ps->rx_oversize);
4274 
4275 	ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
4276 			  &prev_ps->rx_jabber, &cur_ps->rx_jabber);
4277 
4278 	pf->stat_prev_loaded = true;
4279 }
4280 
4281 /**
4282  * ice_get_stats64 - get statistics for network device structure
4283  * @netdev: network interface device structure
4284  * @stats: main device statistics structure
4285  */
4286 static
4287 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
4288 {
4289 	struct ice_netdev_priv *np = netdev_priv(netdev);
4290 	struct rtnl_link_stats64 *vsi_stats;
4291 	struct ice_vsi *vsi = np->vsi;
4292 
4293 	vsi_stats = &vsi->net_stats;
4294 
4295 	if (!vsi->num_txq || !vsi->num_rxq)
4296 		return;
4297 
4298 	/* netdev packet/byte stats come from ring counter. These are obtained
4299 	 * by summing up ring counters (done by ice_update_vsi_ring_stats).
4300 	 * But, only call the update routine and read the registers if VSI is
4301 	 * not down.
4302 	 */
4303 	if (!test_bit(__ICE_DOWN, vsi->state))
4304 		ice_update_vsi_ring_stats(vsi);
4305 	stats->tx_packets = vsi_stats->tx_packets;
4306 	stats->tx_bytes = vsi_stats->tx_bytes;
4307 	stats->rx_packets = vsi_stats->rx_packets;
4308 	stats->rx_bytes = vsi_stats->rx_bytes;
4309 
4310 	/* The rest of the stats can be read from the hardware but instead we
4311 	 * just return values that the watchdog task has already obtained from
4312 	 * the hardware.
4313 	 */
4314 	stats->multicast = vsi_stats->multicast;
4315 	stats->tx_errors = vsi_stats->tx_errors;
4316 	stats->tx_dropped = vsi_stats->tx_dropped;
4317 	stats->rx_errors = vsi_stats->rx_errors;
4318 	stats->rx_dropped = vsi_stats->rx_dropped;
4319 	stats->rx_crc_errors = vsi_stats->rx_crc_errors;
4320 	stats->rx_length_errors = vsi_stats->rx_length_errors;
4321 }
4322 
4323 /**
4324  * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4325  * @vsi: VSI having NAPI disabled
4326  */
4327 static void ice_napi_disable_all(struct ice_vsi *vsi)
4328 {
4329 	int q_idx;
4330 
4331 	if (!vsi->netdev)
4332 		return;
4333 
4334 	ice_for_each_q_vector(vsi, q_idx) {
4335 		struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
4336 
4337 		if (q_vector->rx.ring || q_vector->tx.ring)
4338 			napi_disable(&q_vector->napi);
4339 	}
4340 }
4341 
4342 /**
4343  * ice_down - Shutdown the connection
4344  * @vsi: The VSI being stopped
4345  */
4346 int ice_down(struct ice_vsi *vsi)
4347 {
4348 	int i, tx_err, rx_err, link_err = 0;
4349 
4350 	/* Caller of this function is expected to set the
4351 	 * vsi->state __ICE_DOWN bit
4352 	 */
4353 	if (vsi->netdev) {
4354 		netif_carrier_off(vsi->netdev);
4355 		netif_tx_disable(vsi->netdev);
4356 	}
4357 
4358 	ice_vsi_dis_irq(vsi);
4359 
4360 	tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
4361 	if (tx_err)
4362 		netdev_err(vsi->netdev,
4363 			   "Failed stop Tx rings, VSI %d error %d\n",
4364 			   vsi->vsi_num, tx_err);
4365 	if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
4366 		tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
4367 		if (tx_err)
4368 			netdev_err(vsi->netdev,
4369 				   "Failed stop XDP rings, VSI %d error %d\n",
4370 				   vsi->vsi_num, tx_err);
4371 	}
4372 
4373 	rx_err = ice_vsi_stop_rx_rings(vsi);
4374 	if (rx_err)
4375 		netdev_err(vsi->netdev,
4376 			   "Failed stop Rx rings, VSI %d error %d\n",
4377 			   vsi->vsi_num, rx_err);
4378 
4379 	ice_napi_disable_all(vsi);
4380 
4381 	if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
4382 		link_err = ice_force_phys_link_state(vsi, false);
4383 		if (link_err)
4384 			netdev_err(vsi->netdev,
4385 				   "Failed to set physical link down, VSI %d error %d\n",
4386 				   vsi->vsi_num, link_err);
4387 	}
4388 
4389 	ice_for_each_txq(vsi, i)
4390 		ice_clean_tx_ring(vsi->tx_rings[i]);
4391 
4392 	ice_for_each_rxq(vsi, i)
4393 		ice_clean_rx_ring(vsi->rx_rings[i]);
4394 
4395 	if (tx_err || rx_err || link_err) {
4396 		netdev_err(vsi->netdev,
4397 			   "Failed to close VSI 0x%04X on switch 0x%04X\n",
4398 			   vsi->vsi_num, vsi->vsw->sw_id);
4399 		return -EIO;
4400 	}
4401 
4402 	return 0;
4403 }
4404 
4405 /**
4406  * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
4407  * @vsi: VSI having resources allocated
4408  *
4409  * Return 0 on success, negative on failure
4410  */
4411 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4412 {
4413 	int i, err = 0;
4414 
4415 	if (!vsi->num_txq) {
4416 		dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
4417 			vsi->vsi_num);
4418 		return -EINVAL;
4419 	}
4420 
4421 	ice_for_each_txq(vsi, i) {
4422 		struct ice_ring *ring = vsi->tx_rings[i];
4423 
4424 		if (!ring)
4425 			return -EINVAL;
4426 
4427 		ring->netdev = vsi->netdev;
4428 		err = ice_setup_tx_ring(ring);
4429 		if (err)
4430 			break;
4431 	}
4432 
4433 	return err;
4434 }
4435 
4436 /**
4437  * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
4438  * @vsi: VSI having resources allocated
4439  *
4440  * Return 0 on success, negative on failure
4441  */
4442 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
4443 {
4444 	int i, err = 0;
4445 
4446 	if (!vsi->num_rxq) {
4447 		dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
4448 			vsi->vsi_num);
4449 		return -EINVAL;
4450 	}
4451 
4452 	ice_for_each_rxq(vsi, i) {
4453 		struct ice_ring *ring = vsi->rx_rings[i];
4454 
4455 		if (!ring)
4456 			return -EINVAL;
4457 
4458 		ring->netdev = vsi->netdev;
4459 		err = ice_setup_rx_ring(ring);
4460 		if (err)
4461 			break;
4462 	}
4463 
4464 	return err;
4465 }
4466 
4467 /**
4468  * ice_vsi_open - Called when a network interface is made active
4469  * @vsi: the VSI to open
4470  *
4471  * Initialization of the VSI
4472  *
4473  * Returns 0 on success, negative value on error
4474  */
4475 static int ice_vsi_open(struct ice_vsi *vsi)
4476 {
4477 	char int_name[ICE_INT_NAME_STR_LEN];
4478 	struct ice_pf *pf = vsi->back;
4479 	int err;
4480 
4481 	/* allocate descriptors */
4482 	err = ice_vsi_setup_tx_rings(vsi);
4483 	if (err)
4484 		goto err_setup_tx;
4485 
4486 	err = ice_vsi_setup_rx_rings(vsi);
4487 	if (err)
4488 		goto err_setup_rx;
4489 
4490 	err = ice_vsi_cfg(vsi);
4491 	if (err)
4492 		goto err_setup_rx;
4493 
4494 	snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4495 		 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
4496 	err = ice_vsi_req_irq_msix(vsi, int_name);
4497 	if (err)
4498 		goto err_setup_rx;
4499 
4500 	/* Notify the stack of the actual queue counts. */
4501 	err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
4502 	if (err)
4503 		goto err_set_qs;
4504 
4505 	err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
4506 	if (err)
4507 		goto err_set_qs;
4508 
4509 	err = ice_up_complete(vsi);
4510 	if (err)
4511 		goto err_up_complete;
4512 
4513 	return 0;
4514 
4515 err_up_complete:
4516 	ice_down(vsi);
4517 err_set_qs:
4518 	ice_vsi_free_irq(vsi);
4519 err_setup_rx:
4520 	ice_vsi_free_rx_rings(vsi);
4521 err_setup_tx:
4522 	ice_vsi_free_tx_rings(vsi);
4523 
4524 	return err;
4525 }
4526 
4527 /**
4528  * ice_vsi_release_all - Delete all VSIs
4529  * @pf: PF from which all VSIs are being removed
4530  */
4531 static void ice_vsi_release_all(struct ice_pf *pf)
4532 {
4533 	int err, i;
4534 
4535 	if (!pf->vsi)
4536 		return;
4537 
4538 	ice_for_each_vsi(pf, i) {
4539 		if (!pf->vsi[i])
4540 			continue;
4541 
4542 		err = ice_vsi_release(pf->vsi[i]);
4543 		if (err)
4544 			dev_dbg(ice_pf_to_dev(pf),
4545 				"Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
4546 				i, err, pf->vsi[i]->vsi_num);
4547 	}
4548 }
4549 
4550 /**
4551  * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
4552  * @pf: pointer to the PF instance
4553  * @type: VSI type to rebuild
4554  *
4555  * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
4556  */
4557 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
4558 {
4559 	struct device *dev = ice_pf_to_dev(pf);
4560 	enum ice_status status;
4561 	int i, err;
4562 
4563 	ice_for_each_vsi(pf, i) {
4564 		struct ice_vsi *vsi = pf->vsi[i];
4565 
4566 		if (!vsi || vsi->type != type)
4567 			continue;
4568 
4569 		/* rebuild the VSI */
4570 		err = ice_vsi_rebuild(vsi, true);
4571 		if (err) {
4572 			dev_err(dev,
4573 				"rebuild VSI failed, err %d, VSI index %d, type %s\n",
4574 				err, vsi->idx, ice_vsi_type_str(type));
4575 			return err;
4576 		}
4577 
4578 		/* replay filters for the VSI */
4579 		status = ice_replay_vsi(&pf->hw, vsi->idx);
4580 		if (status) {
4581 			dev_err(dev,
4582 				"replay VSI failed, status %d, VSI index %d, type %s\n",
4583 				status, vsi->idx, ice_vsi_type_str(type));
4584 			return -EIO;
4585 		}
4586 
4587 		/* Re-map HW VSI number, using VSI handle that has been
4588 		 * previously validated in ice_replay_vsi() call above
4589 		 */
4590 		vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
4591 
4592 		/* enable the VSI */
4593 		err = ice_ena_vsi(vsi, false);
4594 		if (err) {
4595 			dev_err(dev,
4596 				"enable VSI failed, err %d, VSI index %d, type %s\n",
4597 				err, vsi->idx, ice_vsi_type_str(type));
4598 			return err;
4599 		}
4600 
4601 		dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
4602 			 ice_vsi_type_str(type));
4603 	}
4604 
4605 	return 0;
4606 }
4607 
4608 /**
4609  * ice_update_pf_netdev_link - Update PF netdev link status
4610  * @pf: pointer to the PF instance
4611  */
4612 static void ice_update_pf_netdev_link(struct ice_pf *pf)
4613 {
4614 	bool link_up;
4615 	int i;
4616 
4617 	ice_for_each_vsi(pf, i) {
4618 		struct ice_vsi *vsi = pf->vsi[i];
4619 
4620 		if (!vsi || vsi->type != ICE_VSI_PF)
4621 			return;
4622 
4623 		ice_get_link_status(pf->vsi[i]->port_info, &link_up);
4624 		if (link_up) {
4625 			netif_carrier_on(pf->vsi[i]->netdev);
4626 			netif_tx_wake_all_queues(pf->vsi[i]->netdev);
4627 		} else {
4628 			netif_carrier_off(pf->vsi[i]->netdev);
4629 			netif_tx_stop_all_queues(pf->vsi[i]->netdev);
4630 		}
4631 	}
4632 }
4633 
4634 /**
4635  * ice_rebuild - rebuild after reset
4636  * @pf: PF to rebuild
4637  * @reset_type: type of reset
4638  */
4639 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
4640 {
4641 	struct device *dev = ice_pf_to_dev(pf);
4642 	struct ice_hw *hw = &pf->hw;
4643 	enum ice_status ret;
4644 	int err;
4645 
4646 	if (test_bit(__ICE_DOWN, pf->state))
4647 		goto clear_recovery;
4648 
4649 	dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
4650 
4651 	ret = ice_init_all_ctrlq(hw);
4652 	if (ret) {
4653 		dev_err(dev, "control queues init failed %d\n", ret);
4654 		goto err_init_ctrlq;
4655 	}
4656 
4657 	/* if DDP was previously loaded successfully */
4658 	if (!ice_is_safe_mode(pf)) {
4659 		/* reload the SW DB of filter tables */
4660 		if (reset_type == ICE_RESET_PFR)
4661 			ice_fill_blk_tbls(hw);
4662 		else
4663 			/* Reload DDP Package after CORER/GLOBR reset */
4664 			ice_load_pkg(NULL, pf);
4665 	}
4666 
4667 	ret = ice_clear_pf_cfg(hw);
4668 	if (ret) {
4669 		dev_err(dev, "clear PF configuration failed %d\n", ret);
4670 		goto err_init_ctrlq;
4671 	}
4672 
4673 	ice_clear_pxe_mode(hw);
4674 
4675 	ret = ice_get_caps(hw);
4676 	if (ret) {
4677 		dev_err(dev, "ice_get_caps failed %d\n", ret);
4678 		goto err_init_ctrlq;
4679 	}
4680 
4681 	err = ice_sched_init_port(hw->port_info);
4682 	if (err)
4683 		goto err_sched_init_port;
4684 
4685 	err = ice_update_link_info(hw->port_info);
4686 	if (err)
4687 		dev_err(dev, "Get link status error %d\n", err);
4688 
4689 	/* start misc vector */
4690 	err = ice_req_irq_msix_misc(pf);
4691 	if (err) {
4692 		dev_err(dev, "misc vector setup failed: %d\n", err);
4693 		goto err_sched_init_port;
4694 	}
4695 
4696 	if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
4697 		ice_dcb_rebuild(pf);
4698 
4699 	/* rebuild PF VSI */
4700 	err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
4701 	if (err) {
4702 		dev_err(dev, "PF VSI rebuild failed: %d\n", err);
4703 		goto err_vsi_rebuild;
4704 	}
4705 
4706 	if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4707 		err = ice_vsi_rebuild_by_type(pf, ICE_VSI_VF);
4708 		if (err) {
4709 			dev_err(dev, "VF VSI rebuild failed: %d\n", err);
4710 			goto err_vsi_rebuild;
4711 		}
4712 	}
4713 
4714 	ice_update_pf_netdev_link(pf);
4715 
4716 	/* tell the firmware we are up */
4717 	ret = ice_send_version(pf);
4718 	if (ret) {
4719 		dev_err(dev,
4720 			"Rebuild failed due to error sending driver version: %d\n",
4721 			ret);
4722 		goto err_vsi_rebuild;
4723 	}
4724 
4725 	ice_replay_post(hw);
4726 
4727 	/* if we get here, reset flow is successful */
4728 	clear_bit(__ICE_RESET_FAILED, pf->state);
4729 	return;
4730 
4731 err_vsi_rebuild:
4732 err_sched_init_port:
4733 	ice_sched_cleanup_all(hw);
4734 err_init_ctrlq:
4735 	ice_shutdown_all_ctrlq(hw);
4736 	set_bit(__ICE_RESET_FAILED, pf->state);
4737 clear_recovery:
4738 	/* set this bit in PF state to control service task scheduling */
4739 	set_bit(__ICE_NEEDS_RESTART, pf->state);
4740 	dev_err(dev, "Rebuild failed, unload and reload driver\n");
4741 }
4742 
4743 /**
4744  * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
4745  * @vsi: Pointer to VSI structure
4746  */
4747 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
4748 {
4749 	if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
4750 		return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
4751 	else
4752 		return ICE_RXBUF_3072;
4753 }
4754 
4755 /**
4756  * ice_change_mtu - NDO callback to change the MTU
4757  * @netdev: network interface device structure
4758  * @new_mtu: new value for maximum frame size
4759  *
4760  * Returns 0 on success, negative on failure
4761  */
4762 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
4763 {
4764 	struct ice_netdev_priv *np = netdev_priv(netdev);
4765 	struct ice_vsi *vsi = np->vsi;
4766 	struct ice_pf *pf = vsi->back;
4767 	u8 count = 0;
4768 
4769 	if (new_mtu == netdev->mtu) {
4770 		netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
4771 		return 0;
4772 	}
4773 
4774 	if (ice_is_xdp_ena_vsi(vsi)) {
4775 		int frame_size = ice_max_xdp_frame_size(vsi);
4776 
4777 		if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
4778 			netdev_err(netdev, "max MTU for XDP usage is %d\n",
4779 				   frame_size - ICE_ETH_PKT_HDR_PAD);
4780 			return -EINVAL;
4781 		}
4782 	}
4783 
4784 	if (new_mtu < netdev->min_mtu) {
4785 		netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
4786 			   netdev->min_mtu);
4787 		return -EINVAL;
4788 	} else if (new_mtu > netdev->max_mtu) {
4789 		netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
4790 			   netdev->min_mtu);
4791 		return -EINVAL;
4792 	}
4793 	/* if a reset is in progress, wait for some time for it to complete */
4794 	do {
4795 		if (ice_is_reset_in_progress(pf->state)) {
4796 			count++;
4797 			usleep_range(1000, 2000);
4798 		} else {
4799 			break;
4800 		}
4801 
4802 	} while (count < 100);
4803 
4804 	if (count == 100) {
4805 		netdev_err(netdev, "can't change MTU. Device is busy\n");
4806 		return -EBUSY;
4807 	}
4808 
4809 	netdev->mtu = new_mtu;
4810 
4811 	/* if VSI is up, bring it down and then back up */
4812 	if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
4813 		int err;
4814 
4815 		err = ice_down(vsi);
4816 		if (err) {
4817 			netdev_err(netdev, "change MTU if_up err %d\n", err);
4818 			return err;
4819 		}
4820 
4821 		err = ice_up(vsi);
4822 		if (err) {
4823 			netdev_err(netdev, "change MTU if_up err %d\n", err);
4824 			return err;
4825 		}
4826 	}
4827 
4828 	netdev_info(netdev, "changed MTU to %d\n", new_mtu);
4829 	return 0;
4830 }
4831 
4832 /**
4833  * ice_set_rss - Set RSS keys and lut
4834  * @vsi: Pointer to VSI structure
4835  * @seed: RSS hash seed
4836  * @lut: Lookup table
4837  * @lut_size: Lookup table size
4838  *
4839  * Returns 0 on success, negative on failure
4840  */
4841 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4842 {
4843 	struct ice_pf *pf = vsi->back;
4844 	struct ice_hw *hw = &pf->hw;
4845 	enum ice_status status;
4846 	struct device *dev;
4847 
4848 	dev = ice_pf_to_dev(pf);
4849 	if (seed) {
4850 		struct ice_aqc_get_set_rss_keys *buf =
4851 				  (struct ice_aqc_get_set_rss_keys *)seed;
4852 
4853 		status = ice_aq_set_rss_key(hw, vsi->idx, buf);
4854 
4855 		if (status) {
4856 			dev_err(dev, "Cannot set RSS key, err %d aq_err %d\n",
4857 				status, hw->adminq.rq_last_status);
4858 			return -EIO;
4859 		}
4860 	}
4861 
4862 	if (lut) {
4863 		status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4864 					    lut, lut_size);
4865 		if (status) {
4866 			dev_err(dev, "Cannot set RSS lut, err %d aq_err %d\n",
4867 				status, hw->adminq.rq_last_status);
4868 			return -EIO;
4869 		}
4870 	}
4871 
4872 	return 0;
4873 }
4874 
4875 /**
4876  * ice_get_rss - Get RSS keys and lut
4877  * @vsi: Pointer to VSI structure
4878  * @seed: Buffer to store the keys
4879  * @lut: Buffer to store the lookup table entries
4880  * @lut_size: Size of buffer to store the lookup table entries
4881  *
4882  * Returns 0 on success, negative on failure
4883  */
4884 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4885 {
4886 	struct ice_pf *pf = vsi->back;
4887 	struct ice_hw *hw = &pf->hw;
4888 	enum ice_status status;
4889 	struct device *dev;
4890 
4891 	dev = ice_pf_to_dev(pf);
4892 	if (seed) {
4893 		struct ice_aqc_get_set_rss_keys *buf =
4894 				  (struct ice_aqc_get_set_rss_keys *)seed;
4895 
4896 		status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4897 		if (status) {
4898 			dev_err(dev, "Cannot get RSS key, err %d aq_err %d\n",
4899 				status, hw->adminq.rq_last_status);
4900 			return -EIO;
4901 		}
4902 	}
4903 
4904 	if (lut) {
4905 		status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4906 					    lut, lut_size);
4907 		if (status) {
4908 			dev_err(dev, "Cannot get RSS lut, err %d aq_err %d\n",
4909 				status, hw->adminq.rq_last_status);
4910 			return -EIO;
4911 		}
4912 	}
4913 
4914 	return 0;
4915 }
4916 
4917 /**
4918  * ice_bridge_getlink - Get the hardware bridge mode
4919  * @skb: skb buff
4920  * @pid: process ID
4921  * @seq: RTNL message seq
4922  * @dev: the netdev being configured
4923  * @filter_mask: filter mask passed in
4924  * @nlflags: netlink flags passed in
4925  *
4926  * Return the bridge mode (VEB/VEPA)
4927  */
4928 static int
4929 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4930 		   struct net_device *dev, u32 filter_mask, int nlflags)
4931 {
4932 	struct ice_netdev_priv *np = netdev_priv(dev);
4933 	struct ice_vsi *vsi = np->vsi;
4934 	struct ice_pf *pf = vsi->back;
4935 	u16 bmode;
4936 
4937 	bmode = pf->first_sw->bridge_mode;
4938 
4939 	return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4940 				       filter_mask, NULL);
4941 }
4942 
4943 /**
4944  * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4945  * @vsi: Pointer to VSI structure
4946  * @bmode: Hardware bridge mode (VEB/VEPA)
4947  *
4948  * Returns 0 on success, negative on failure
4949  */
4950 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4951 {
4952 	struct ice_aqc_vsi_props *vsi_props;
4953 	struct ice_hw *hw = &vsi->back->hw;
4954 	struct ice_vsi_ctx *ctxt;
4955 	enum ice_status status;
4956 	int ret = 0;
4957 
4958 	vsi_props = &vsi->info;
4959 
4960 	ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4961 	if (!ctxt)
4962 		return -ENOMEM;
4963 
4964 	ctxt->info = vsi->info;
4965 
4966 	if (bmode == BRIDGE_MODE_VEB)
4967 		/* change from VEPA to VEB mode */
4968 		ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4969 	else
4970 		/* change from VEB to VEPA mode */
4971 		ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4972 	ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4973 
4974 	status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4975 	if (status) {
4976 		dev_err(&vsi->back->pdev->dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4977 			bmode, status, hw->adminq.sq_last_status);
4978 		ret = -EIO;
4979 		goto out;
4980 	}
4981 	/* Update sw flags for book keeping */
4982 	vsi_props->sw_flags = ctxt->info.sw_flags;
4983 
4984 out:
4985 	kfree(ctxt);
4986 	return ret;
4987 }
4988 
4989 /**
4990  * ice_bridge_setlink - Set the hardware bridge mode
4991  * @dev: the netdev being configured
4992  * @nlh: RTNL message
4993  * @flags: bridge setlink flags
4994  * @extack: netlink extended ack
4995  *
4996  * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4997  * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4998  * not already set for all VSIs connected to this switch. And also update the
4999  * unicast switch filter rules for the corresponding switch of the netdev.
5000  */
5001 static int
5002 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
5003 		   u16 __always_unused flags,
5004 		   struct netlink_ext_ack __always_unused *extack)
5005 {
5006 	struct ice_netdev_priv *np = netdev_priv(dev);
5007 	struct ice_pf *pf = np->vsi->back;
5008 	struct nlattr *attr, *br_spec;
5009 	struct ice_hw *hw = &pf->hw;
5010 	enum ice_status status;
5011 	struct ice_sw *pf_sw;
5012 	int rem, v, err = 0;
5013 
5014 	pf_sw = pf->first_sw;
5015 	/* find the attribute in the netlink message */
5016 	br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
5017 
5018 	nla_for_each_nested(attr, br_spec, rem) {
5019 		__u16 mode;
5020 
5021 		if (nla_type(attr) != IFLA_BRIDGE_MODE)
5022 			continue;
5023 		mode = nla_get_u16(attr);
5024 		if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
5025 			return -EINVAL;
5026 		/* Continue  if bridge mode is not being flipped */
5027 		if (mode == pf_sw->bridge_mode)
5028 			continue;
5029 		/* Iterates through the PF VSI list and update the loopback
5030 		 * mode of the VSI
5031 		 */
5032 		ice_for_each_vsi(pf, v) {
5033 			if (!pf->vsi[v])
5034 				continue;
5035 			err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
5036 			if (err)
5037 				return err;
5038 		}
5039 
5040 		hw->evb_veb = (mode == BRIDGE_MODE_VEB);
5041 		/* Update the unicast switch filter rules for the corresponding
5042 		 * switch of the netdev
5043 		 */
5044 		status = ice_update_sw_rule_bridge_mode(hw);
5045 		if (status) {
5046 			netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
5047 				   mode, status, hw->adminq.sq_last_status);
5048 			/* revert hw->evb_veb */
5049 			hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
5050 			return -EIO;
5051 		}
5052 
5053 		pf_sw->bridge_mode = mode;
5054 	}
5055 
5056 	return 0;
5057 }
5058 
5059 /**
5060  * ice_tx_timeout - Respond to a Tx Hang
5061  * @netdev: network interface device structure
5062  */
5063 static void ice_tx_timeout(struct net_device *netdev)
5064 {
5065 	struct ice_netdev_priv *np = netdev_priv(netdev);
5066 	struct ice_ring *tx_ring = NULL;
5067 	struct ice_vsi *vsi = np->vsi;
5068 	struct ice_pf *pf = vsi->back;
5069 	int hung_queue = -1;
5070 	u32 i;
5071 
5072 	pf->tx_timeout_count++;
5073 
5074 	/* find the stopped queue the same way dev_watchdog() does */
5075 	for (i = 0; i < netdev->num_tx_queues; i++) {
5076 		unsigned long trans_start;
5077 		struct netdev_queue *q;
5078 
5079 		q = netdev_get_tx_queue(netdev, i);
5080 		trans_start = q->trans_start;
5081 		if (netif_xmit_stopped(q) &&
5082 		    time_after(jiffies,
5083 			       trans_start + netdev->watchdog_timeo)) {
5084 			hung_queue = i;
5085 			break;
5086 		}
5087 	}
5088 
5089 	if (i == netdev->num_tx_queues)
5090 		netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
5091 	else
5092 		/* now that we have an index, find the tx_ring struct */
5093 		for (i = 0; i < vsi->num_txq; i++)
5094 			if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
5095 				if (hung_queue == vsi->tx_rings[i]->q_index) {
5096 					tx_ring = vsi->tx_rings[i];
5097 					break;
5098 				}
5099 
5100 	/* Reset recovery level if enough time has elapsed after last timeout.
5101 	 * Also ensure no new reset action happens before next timeout period.
5102 	 */
5103 	if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
5104 		pf->tx_timeout_recovery_level = 1;
5105 	else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
5106 				       netdev->watchdog_timeo)))
5107 		return;
5108 
5109 	if (tx_ring) {
5110 		struct ice_hw *hw = &pf->hw;
5111 		u32 head, val = 0;
5112 
5113 		head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
5114 			QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
5115 		/* Read interrupt register */
5116 		val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
5117 
5118 		netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
5119 			    vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
5120 			    head, tx_ring->next_to_use, val);
5121 	}
5122 
5123 	pf->tx_timeout_last_recovery = jiffies;
5124 	netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
5125 		    pf->tx_timeout_recovery_level, hung_queue);
5126 
5127 	switch (pf->tx_timeout_recovery_level) {
5128 	case 1:
5129 		set_bit(__ICE_PFR_REQ, pf->state);
5130 		break;
5131 	case 2:
5132 		set_bit(__ICE_CORER_REQ, pf->state);
5133 		break;
5134 	case 3:
5135 		set_bit(__ICE_GLOBR_REQ, pf->state);
5136 		break;
5137 	default:
5138 		netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
5139 		set_bit(__ICE_DOWN, pf->state);
5140 		set_bit(__ICE_NEEDS_RESTART, vsi->state);
5141 		set_bit(__ICE_SERVICE_DIS, pf->state);
5142 		break;
5143 	}
5144 
5145 	ice_service_task_schedule(pf);
5146 	pf->tx_timeout_recovery_level++;
5147 }
5148 
5149 /**
5150  * ice_open - Called when a network interface becomes active
5151  * @netdev: network interface device structure
5152  *
5153  * The open entry point is called when a network interface is made
5154  * active by the system (IFF_UP). At this point all resources needed
5155  * for transmit and receive operations are allocated, the interrupt
5156  * handler is registered with the OS, the netdev watchdog is enabled,
5157  * and the stack is notified that the interface is ready.
5158  *
5159  * Returns 0 on success, negative value on failure
5160  */
5161 int ice_open(struct net_device *netdev)
5162 {
5163 	struct ice_netdev_priv *np = netdev_priv(netdev);
5164 	struct ice_vsi *vsi = np->vsi;
5165 	struct ice_port_info *pi;
5166 	int err;
5167 
5168 	if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
5169 		netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
5170 		return -EIO;
5171 	}
5172 
5173 	netif_carrier_off(netdev);
5174 
5175 	pi = vsi->port_info;
5176 	err = ice_update_link_info(pi);
5177 	if (err) {
5178 		netdev_err(netdev, "Failed to get link info, error %d\n",
5179 			   err);
5180 		return err;
5181 	}
5182 
5183 	/* Set PHY if there is media, otherwise, turn off PHY */
5184 	if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
5185 		err = ice_force_phys_link_state(vsi, true);
5186 		if (err) {
5187 			netdev_err(netdev,
5188 				   "Failed to set physical link up, error %d\n",
5189 				   err);
5190 			return err;
5191 		}
5192 	} else {
5193 		err = ice_aq_set_link_restart_an(pi, false, NULL);
5194 		if (err) {
5195 			netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n",
5196 				   vsi->vsi_num, err);
5197 			return err;
5198 		}
5199 		set_bit(ICE_FLAG_NO_MEDIA, vsi->back->flags);
5200 	}
5201 
5202 	err = ice_vsi_open(vsi);
5203 	if (err)
5204 		netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
5205 			   vsi->vsi_num, vsi->vsw->sw_id);
5206 	return err;
5207 }
5208 
5209 /**
5210  * ice_stop - Disables a network interface
5211  * @netdev: network interface device structure
5212  *
5213  * The stop entry point is called when an interface is de-activated by the OS,
5214  * and the netdevice enters the DOWN state. The hardware is still under the
5215  * driver's control, but the netdev interface is disabled.
5216  *
5217  * Returns success only - not allowed to fail
5218  */
5219 int ice_stop(struct net_device *netdev)
5220 {
5221 	struct ice_netdev_priv *np = netdev_priv(netdev);
5222 	struct ice_vsi *vsi = np->vsi;
5223 
5224 	ice_vsi_close(vsi);
5225 
5226 	return 0;
5227 }
5228 
5229 /**
5230  * ice_features_check - Validate encapsulated packet conforms to limits
5231  * @skb: skb buffer
5232  * @netdev: This port's netdev
5233  * @features: Offload features that the stack believes apply
5234  */
5235 static netdev_features_t
5236 ice_features_check(struct sk_buff *skb,
5237 		   struct net_device __always_unused *netdev,
5238 		   netdev_features_t features)
5239 {
5240 	size_t len;
5241 
5242 	/* No point in doing any of this if neither checksum nor GSO are
5243 	 * being requested for this frame. We can rule out both by just
5244 	 * checking for CHECKSUM_PARTIAL
5245 	 */
5246 	if (skb->ip_summed != CHECKSUM_PARTIAL)
5247 		return features;
5248 
5249 	/* We cannot support GSO if the MSS is going to be less than
5250 	 * 64 bytes. If it is then we need to drop support for GSO.
5251 	 */
5252 	if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
5253 		features &= ~NETIF_F_GSO_MASK;
5254 
5255 	len = skb_network_header(skb) - skb->data;
5256 	if (len & ~(ICE_TXD_MACLEN_MAX))
5257 		goto out_rm_features;
5258 
5259 	len = skb_transport_header(skb) - skb_network_header(skb);
5260 	if (len & ~(ICE_TXD_IPLEN_MAX))
5261 		goto out_rm_features;
5262 
5263 	if (skb->encapsulation) {
5264 		len = skb_inner_network_header(skb) - skb_transport_header(skb);
5265 		if (len & ~(ICE_TXD_L4LEN_MAX))
5266 			goto out_rm_features;
5267 
5268 		len = skb_inner_transport_header(skb) -
5269 		      skb_inner_network_header(skb);
5270 		if (len & ~(ICE_TXD_IPLEN_MAX))
5271 			goto out_rm_features;
5272 	}
5273 
5274 	return features;
5275 out_rm_features:
5276 	return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
5277 }
5278 
5279 static const struct net_device_ops ice_netdev_safe_mode_ops = {
5280 	.ndo_open = ice_open,
5281 	.ndo_stop = ice_stop,
5282 	.ndo_start_xmit = ice_start_xmit,
5283 	.ndo_set_mac_address = ice_set_mac_address,
5284 	.ndo_validate_addr = eth_validate_addr,
5285 	.ndo_change_mtu = ice_change_mtu,
5286 	.ndo_get_stats64 = ice_get_stats64,
5287 	.ndo_tx_timeout = ice_tx_timeout,
5288 };
5289 
5290 static const struct net_device_ops ice_netdev_ops = {
5291 	.ndo_open = ice_open,
5292 	.ndo_stop = ice_stop,
5293 	.ndo_start_xmit = ice_start_xmit,
5294 	.ndo_features_check = ice_features_check,
5295 	.ndo_set_rx_mode = ice_set_rx_mode,
5296 	.ndo_set_mac_address = ice_set_mac_address,
5297 	.ndo_validate_addr = eth_validate_addr,
5298 	.ndo_change_mtu = ice_change_mtu,
5299 	.ndo_get_stats64 = ice_get_stats64,
5300 	.ndo_set_tx_maxrate = ice_set_tx_maxrate,
5301 	.ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
5302 	.ndo_set_vf_mac = ice_set_vf_mac,
5303 	.ndo_get_vf_config = ice_get_vf_cfg,
5304 	.ndo_set_vf_trust = ice_set_vf_trust,
5305 	.ndo_set_vf_vlan = ice_set_vf_port_vlan,
5306 	.ndo_set_vf_link_state = ice_set_vf_link_state,
5307 	.ndo_get_vf_stats = ice_get_vf_stats,
5308 	.ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
5309 	.ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
5310 	.ndo_set_features = ice_set_features,
5311 	.ndo_bridge_getlink = ice_bridge_getlink,
5312 	.ndo_bridge_setlink = ice_bridge_setlink,
5313 	.ndo_fdb_add = ice_fdb_add,
5314 	.ndo_fdb_del = ice_fdb_del,
5315 	.ndo_tx_timeout = ice_tx_timeout,
5316 	.ndo_bpf = ice_xdp,
5317 	.ndo_xdp_xmit = ice_xdp_xmit,
5318 	.ndo_xsk_wakeup = ice_xsk_wakeup,
5319 };
5320