1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include "ice_dcb_lib.h"
12 #include "ice_dcb_nl.h"
14 #define DRV_VERSION_MAJOR 0
15 #define DRV_VERSION_MINOR 8
16 #define DRV_VERSION_BUILD 2
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.";
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"
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);
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)");
41 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
42 #endif /* !CONFIG_DYNAMIC_DEBUG */
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);
49 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
51 static void ice_vsi_release_all(struct ice_pf *pf);
54 * ice_get_tx_pending - returns number of Tx descriptors not processed
55 * @ring: the ring of descriptors
57 static u16 ice_get_tx_pending(struct ice_ring *ring)
61 head = ring->next_to_clean;
62 tail = ring->next_to_use;
65 return (head < tail) ?
66 tail - head : (tail + ring->count - head);
71 * ice_check_for_hang_subtask - check for and recover hung queues
72 * @pf: pointer to PF struct
74 static void ice_check_for_hang_subtask(struct ice_pf *pf)
76 struct ice_vsi *vsi = NULL;
82 ice_for_each_vsi(pf, v)
83 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
88 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
91 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
96 for (i = 0; i < vsi->num_txq; i++) {
97 struct ice_ring *tx_ring = vsi->tx_rings[i];
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
104 * prev_pkt would be negative if there was no
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);
114 /* Memory barrier between read of packet count and call
115 * to ice_get_tx_pending()
118 tx_ring->tx_stats.prev_pkt =
119 ice_get_tx_pending(tx_ring) ? packets : -1;
125 * ice_init_mac_fltr - Set initial MAC filters
126 * @pf: board private structure
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
132 static int ice_init_mac_fltr(struct ice_pf *pf)
134 enum ice_status status;
135 u8 broadcast[ETH_ALEN];
138 vsi = ice_get_main_vsi(pf);
142 /* To add a MAC filter, first add the MAC to a list and then
143 * pass the list to ice_add_mac.
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);
151 /* VSI needs to receive broadcast traffic, so add the broadcast
152 * MAC address to the list as well.
154 eth_broadcast_addr(broadcast);
155 status = ice_vsi_cfg_mac_fltr(vsi, broadcast, true);
161 /* We aren't useful with no MAC filters, so unregister if we
164 if (status && vsi->netdev->reg_state == NETREG_REGISTERED) {
165 dev_err(ice_pf_to_dev(pf), "Could not add MAC filters error %d. Unregistering device\n",
167 unregister_netdev(vsi->netdev);
168 free_netdev(vsi->netdev);
176 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
177 * @netdev: the net device on which the sync is happening
178 * @addr: MAC address to sync
180 * This is a callback function which is called by the in kernel device sync
181 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
182 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
183 * MAC filters from the hardware.
185 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
187 struct ice_netdev_priv *np = netdev_priv(netdev);
188 struct ice_vsi *vsi = np->vsi;
190 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
197 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
198 * @netdev: the net device on which the unsync is happening
199 * @addr: MAC address to unsync
201 * This is a callback function which is called by the in kernel device unsync
202 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
203 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
204 * delete the MAC filters from the hardware.
206 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
208 struct ice_netdev_priv *np = netdev_priv(netdev);
209 struct ice_vsi *vsi = np->vsi;
211 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
218 * ice_vsi_fltr_changed - check if filter state changed
219 * @vsi: VSI to be checked
221 * returns true if filter state has changed, false otherwise.
223 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
225 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
226 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
227 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
231 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
232 * @vsi: the VSI being configured
233 * @promisc_m: mask of promiscuous config bits
234 * @set_promisc: enable or disable promisc flag request
237 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
239 struct ice_hw *hw = &vsi->back->hw;
240 enum ice_status status = 0;
242 if (vsi->type != ICE_VSI_PF)
246 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
250 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
253 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
264 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
265 * @vsi: ptr to the VSI
267 * Push any outstanding VSI filter changes through the AdminQ.
269 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
271 struct device *dev = ice_pf_to_dev(vsi->back);
272 struct net_device *netdev = vsi->netdev;
273 bool promisc_forced_on = false;
274 struct ice_pf *pf = vsi->back;
275 struct ice_hw *hw = &pf->hw;
276 enum ice_status status = 0;
277 u32 changed_flags = 0;
284 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
285 usleep_range(1000, 2000);
287 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
288 vsi->current_netdev_flags = vsi->netdev->flags;
290 INIT_LIST_HEAD(&vsi->tmp_sync_list);
291 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
293 if (ice_vsi_fltr_changed(vsi)) {
294 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
295 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
296 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
298 /* grab the netdev's addr_list_lock */
299 netif_addr_lock_bh(netdev);
300 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
301 ice_add_mac_to_unsync_list);
302 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
303 ice_add_mac_to_unsync_list);
304 /* our temp lists are populated. release lock */
305 netif_addr_unlock_bh(netdev);
308 /* Remove MAC addresses in the unsync list */
309 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
310 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
312 netdev_err(netdev, "Failed to delete MAC filters\n");
313 /* if we failed because of alloc failures, just bail */
314 if (status == ICE_ERR_NO_MEMORY) {
320 /* Add MAC addresses in the sync list */
321 status = ice_add_mac(hw, &vsi->tmp_sync_list);
322 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
323 /* If filter is added successfully or already exists, do not go into
324 * 'if' condition and report it as error. Instead continue processing
325 * rest of the function.
327 if (status && status != ICE_ERR_ALREADY_EXISTS) {
328 netdev_err(netdev, "Failed to add MAC filters\n");
329 /* If there is no more space for new umac filters, VSI
330 * should go into promiscuous mode. There should be some
331 * space reserved for promiscuous filters.
333 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
334 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
336 promisc_forced_on = true;
337 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
344 /* check for changes in promiscuous modes */
345 if (changed_flags & IFF_ALLMULTI) {
346 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
348 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
350 promisc_m = ICE_MCAST_PROMISC_BITS;
352 err = ice_cfg_promisc(vsi, promisc_m, true);
354 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
356 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
359 } else if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
361 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
363 promisc_m = ICE_MCAST_PROMISC_BITS;
365 err = ice_cfg_promisc(vsi, promisc_m, false);
367 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
369 vsi->current_netdev_flags |= IFF_ALLMULTI;
375 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
376 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
377 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
378 if (vsi->current_netdev_flags & IFF_PROMISC) {
379 /* Apply Rx filter rule to get traffic from wire */
380 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) {
381 err = ice_set_dflt_vsi(pf->first_sw, vsi);
382 if (err && err != -EEXIST) {
383 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
385 vsi->current_netdev_flags &=
391 /* Clear Rx filter to remove traffic from wire */
392 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) {
393 err = ice_clear_dflt_vsi(pf->first_sw);
395 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
397 vsi->current_netdev_flags |=
407 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
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);
414 clear_bit(__ICE_CFG_BUSY, vsi->state);
419 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
420 * @pf: board private structure
422 static void ice_sync_fltr_subtask(struct ice_pf *pf)
426 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
429 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
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);
441 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
443 * @locked: is the rtnl_lock already held
445 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
449 ice_for_each_vsi(pf, v)
451 ice_dis_vsi(pf->vsi[v], locked);
455 * ice_prepare_for_reset - prep for the core to reset
456 * @pf: board private structure
458 * Inform or close all dependent features in prep for reset.
461 ice_prepare_for_reset(struct ice_pf *pf)
463 struct ice_hw *hw = &pf->hw;
466 /* already prepared for reset */
467 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
470 /* Notify VFs of impending reset */
471 if (ice_check_sq_alive(hw, &hw->mailboxq))
472 ice_vc_notify_reset(pf);
474 /* Disable VFs until reset is completed */
475 ice_for_each_vf(pf, i)
476 ice_set_vf_state_qs_dis(&pf->vf[i]);
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);
484 ice_sched_clear_port(hw->port_info);
486 ice_shutdown_all_ctrlq(hw);
488 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
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.
497 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
499 struct device *dev = ice_pf_to_dev(pf);
500 struct ice_hw *hw = &pf->hw;
502 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
503 WARN_ON(in_interrupt());
505 ice_prepare_for_reset(pf);
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);
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.
523 if (reset_type == ICE_RESET_PFR) {
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);
533 * ice_reset_subtask - Set up for resetting the device and driver
534 * @pf: board private structure
536 static void ice_reset_subtask(struct ice_pf *pf)
538 enum ice_reset_req reset_type = ICE_RESET_INVAL;
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.
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)
561 ice_prepare_for_reset(pf);
563 /* make sure we are ready to rebuild */
564 if (ice_check_reset(&pf->hw)) {
565 set_bit(__ICE_RESET_FAILED, pf->state);
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
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);
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)
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);
603 * ice_print_topo_conflict - print topology conflict message
604 * @vsi: the VSI whose topology status is being checked
606 static void ice_print_topo_conflict(struct ice_vsi *vsi)
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");
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");
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
629 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
631 struct ice_aqc_get_phy_caps_data *caps;
632 enum ice_status status;
642 if (vsi->current_isup == isup)
645 vsi->current_isup = isup;
648 netdev_info(vsi->netdev, "NIC Link is Down\n");
652 switch (vsi->port_info->phy.link_info.link_speed) {
653 case ICE_AQ_LINK_SPEED_100GB:
656 case ICE_AQ_LINK_SPEED_50GB:
659 case ICE_AQ_LINK_SPEED_40GB:
662 case ICE_AQ_LINK_SPEED_25GB:
665 case ICE_AQ_LINK_SPEED_20GB:
668 case ICE_AQ_LINK_SPEED_10GB:
671 case ICE_AQ_LINK_SPEED_5GB:
674 case ICE_AQ_LINK_SPEED_2500MB:
677 case ICE_AQ_LINK_SPEED_1000MB:
680 case ICE_AQ_LINK_SPEED_100MB:
688 switch (vsi->port_info->fc.current_mode) {
692 case ICE_FC_TX_PAUSE:
695 case ICE_FC_RX_PAUSE:
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:
710 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
713 case ICE_AQ_LINK_25G_KR_FEC_EN:
714 fec = "FC-FEC/BASE-R";
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)
727 /* Get FEC mode requested based on PHY caps last SW configuration */
728 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
734 status = ice_aq_get_phy_caps(vsi->port_info, false,
735 ICE_AQC_REPORT_SW_CFG, caps, NULL);
737 netdev_info(vsi->netdev, "Get phy capability failed.\n");
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)
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";
751 netdev_info(vsi->netdev, "NIC Link is up %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
752 speed, fec_req, fec, an, fc);
753 ice_print_topo_conflict(vsi);
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
761 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
766 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
769 if (vsi->type == ICE_VSI_PF) {
770 if (link_up == netif_carrier_ok(vsi->netdev))
774 netif_carrier_on(vsi->netdev);
775 netif_tx_wake_all_queues(vsi->netdev);
777 netif_carrier_off(vsi->netdev);
778 netif_tx_stop_all_queues(vsi->netdev);
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
790 * Returns 0 on success and negative on failure
793 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
796 struct device *dev = ice_pf_to_dev(pf);
797 struct ice_phy_info *phy_info;
804 phy_info->link_info_old = phy_info->link_info;
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;
809 /* update the link info structures and re-enable link events,
810 * don't bail on failure due to other book keeping needed
812 result = ice_update_link_info(pi);
814 dev_dbg(dev, "Failed to update link status and re-enable link events for port %d\n",
817 /* if the old link up/down and speed is the same as the new */
818 if (link_up == old_link && link_speed == old_link_speed)
821 vsi = ice_get_main_vsi(pf);
822 if (!vsi || !vsi->port_info)
825 /* turn off PHY if media was removed */
826 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
827 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
828 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
830 result = ice_aq_set_link_restart_an(pi, false, NULL);
832 dev_dbg(dev, "Failed to set link down, VSI %d error %d\n",
833 vsi->vsi_num, result);
839 ice_vsi_link_event(vsi, link_up);
840 ice_print_link_msg(vsi, link_up);
842 ice_vc_notify_link_state(pf);
848 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
849 * @pf: board private structure
851 static void ice_watchdog_subtask(struct ice_pf *pf)
855 /* if interface is down do nothing */
856 if (test_bit(__ICE_DOWN, pf->state) ||
857 test_bit(__ICE_CFG_BUSY, pf->state))
860 /* make sure we don't do these things too often */
861 if (time_before(jiffies,
862 pf->serv_tmr_prev + pf->serv_tmr_period))
865 pf->serv_tmr_prev = jiffies;
867 /* Update the stats for active netdevs so the network stack
868 * can look at updated numbers whenever it cares to
870 ice_update_pf_stats(pf);
871 ice_for_each_vsi(pf, i)
872 if (pf->vsi[i] && pf->vsi[i]->netdev)
873 ice_update_vsi_stats(pf->vsi[i]);
877 * ice_init_link_events - enable/initialize link events
878 * @pi: pointer to the port_info instance
880 * Returns -EIO on failure, 0 on success
882 static int ice_init_link_events(struct ice_port_info *pi)
886 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
887 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
889 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
890 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
895 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
896 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
905 * ice_handle_link_event - handle link event via ARQ
906 * @pf: PF that the link event is associated with
907 * @event: event structure containing link status info
910 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
912 struct ice_aqc_get_link_status_data *link_data;
913 struct ice_port_info *port_info;
916 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
917 port_info = pf->hw.port_info;
921 status = ice_link_event(pf, port_info,
922 !!(link_data->link_info & ICE_AQ_LINK_UP),
923 le16_to_cpu(link_data->link_speed));
925 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
932 * __ice_clean_ctrlq - helper function to clean controlq rings
933 * @pf: ptr to struct ice_pf
934 * @q_type: specific Control queue type
936 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
938 struct device *dev = ice_pf_to_dev(pf);
939 struct ice_rq_event_info event;
940 struct ice_hw *hw = &pf->hw;
941 struct ice_ctl_q_info *cq;
946 /* Do not clean control queue if/when PF reset fails */
947 if (test_bit(__ICE_RESET_FAILED, pf->state))
951 case ICE_CTL_Q_ADMIN:
955 case ICE_CTL_Q_MAILBOX:
960 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
964 /* check for error indications - PF_xx_AxQLEN register layout for
965 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
967 val = rd32(hw, cq->rq.len);
968 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
969 PF_FW_ARQLEN_ARQCRIT_M)) {
971 if (val & PF_FW_ARQLEN_ARQVFE_M)
972 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
974 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
975 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
978 if (val & PF_FW_ARQLEN_ARQCRIT_M)
979 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
981 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
982 PF_FW_ARQLEN_ARQCRIT_M);
984 wr32(hw, cq->rq.len, val);
987 val = rd32(hw, cq->sq.len);
988 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
989 PF_FW_ATQLEN_ATQCRIT_M)) {
991 if (val & PF_FW_ATQLEN_ATQVFE_M)
992 dev_dbg(dev, "%s Send Queue VF Error detected\n",
994 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
995 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
998 if (val & PF_FW_ATQLEN_ATQCRIT_M)
999 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1001 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1002 PF_FW_ATQLEN_ATQCRIT_M);
1004 wr32(hw, cq->sq.len, val);
1007 event.buf_len = cq->rq_buf_size;
1008 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1013 enum ice_status ret;
1016 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1017 if (ret == ICE_ERR_AQ_NO_WORK)
1020 dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1025 opcode = le16_to_cpu(event.desc.opcode);
1028 case ice_aqc_opc_get_link_status:
1029 if (ice_handle_link_event(pf, &event))
1030 dev_err(dev, "Could not handle link event\n");
1032 case ice_mbx_opc_send_msg_to_pf:
1033 ice_vc_process_vf_msg(pf, &event);
1035 case ice_aqc_opc_fw_logging:
1036 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1038 case ice_aqc_opc_lldp_set_mib_change:
1039 ice_dcb_process_lldp_set_mib_change(pf, &event);
1042 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1046 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1048 kfree(event.msg_buf);
1050 return pending && (i == ICE_DFLT_IRQ_WORK);
1054 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1055 * @hw: pointer to hardware info
1056 * @cq: control queue information
1058 * returns true if there are pending messages in a queue, false if there aren't
1060 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1064 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1065 return cq->rq.next_to_clean != ntu;
1069 * ice_clean_adminq_subtask - clean the AdminQ rings
1070 * @pf: board private structure
1072 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1074 struct ice_hw *hw = &pf->hw;
1076 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1079 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1082 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1084 /* There might be a situation where new messages arrive to a control
1085 * queue between processing the last message and clearing the
1086 * EVENT_PENDING bit. So before exiting, check queue head again (using
1087 * ice_ctrlq_pending) and process new messages if any.
1089 if (ice_ctrlq_pending(hw, &hw->adminq))
1090 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1096 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1097 * @pf: board private structure
1099 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1101 struct ice_hw *hw = &pf->hw;
1103 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1106 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1109 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1111 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1112 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1118 * ice_service_task_schedule - schedule the service task to wake up
1119 * @pf: board private structure
1121 * If not already scheduled, this puts the task into the work queue.
1123 static void ice_service_task_schedule(struct ice_pf *pf)
1125 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1126 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1127 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1128 queue_work(ice_wq, &pf->serv_task);
1132 * ice_service_task_complete - finish up the service task
1133 * @pf: board private structure
1135 static void ice_service_task_complete(struct ice_pf *pf)
1137 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1139 /* force memory (pf->state) to sync before next service task */
1140 smp_mb__before_atomic();
1141 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1145 * ice_service_task_stop - stop service task and cancel works
1146 * @pf: board private structure
1148 static void ice_service_task_stop(struct ice_pf *pf)
1150 set_bit(__ICE_SERVICE_DIS, pf->state);
1152 if (pf->serv_tmr.function)
1153 del_timer_sync(&pf->serv_tmr);
1154 if (pf->serv_task.func)
1155 cancel_work_sync(&pf->serv_task);
1157 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1161 * ice_service_task_restart - restart service task and schedule works
1162 * @pf: board private structure
1164 * This function is needed for suspend and resume works (e.g WoL scenario)
1166 static void ice_service_task_restart(struct ice_pf *pf)
1168 clear_bit(__ICE_SERVICE_DIS, pf->state);
1169 ice_service_task_schedule(pf);
1173 * ice_service_timer - timer callback to schedule service task
1174 * @t: pointer to timer_list
1176 static void ice_service_timer(struct timer_list *t)
1178 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1180 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1181 ice_service_task_schedule(pf);
1185 * ice_handle_mdd_event - handle malicious driver detect event
1186 * @pf: pointer to the PF structure
1188 * Called from service task. OICR interrupt handler indicates MDD event
1190 static void ice_handle_mdd_event(struct ice_pf *pf)
1192 struct device *dev = ice_pf_to_dev(pf);
1193 struct ice_hw *hw = &pf->hw;
1194 bool mdd_detected = false;
1198 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1201 /* find what triggered the MDD event */
1202 reg = rd32(hw, GL_MDET_TX_PQM);
1203 if (reg & GL_MDET_TX_PQM_VALID_M) {
1204 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1205 GL_MDET_TX_PQM_PF_NUM_S;
1206 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1207 GL_MDET_TX_PQM_VF_NUM_S;
1208 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1209 GL_MDET_TX_PQM_MAL_TYPE_S;
1210 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1211 GL_MDET_TX_PQM_QNUM_S);
1213 if (netif_msg_tx_err(pf))
1214 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1215 event, queue, pf_num, vf_num);
1216 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1217 mdd_detected = true;
1220 reg = rd32(hw, GL_MDET_TX_TCLAN);
1221 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1222 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1223 GL_MDET_TX_TCLAN_PF_NUM_S;
1224 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1225 GL_MDET_TX_TCLAN_VF_NUM_S;
1226 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1227 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1228 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1229 GL_MDET_TX_TCLAN_QNUM_S);
1231 if (netif_msg_tx_err(pf))
1232 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1233 event, queue, pf_num, vf_num);
1234 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1235 mdd_detected = true;
1238 reg = rd32(hw, GL_MDET_RX);
1239 if (reg & GL_MDET_RX_VALID_M) {
1240 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1241 GL_MDET_RX_PF_NUM_S;
1242 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1243 GL_MDET_RX_VF_NUM_S;
1244 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1245 GL_MDET_RX_MAL_TYPE_S;
1246 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1249 if (netif_msg_rx_err(pf))
1250 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1251 event, queue, pf_num, vf_num);
1252 wr32(hw, GL_MDET_RX, 0xffffffff);
1253 mdd_detected = true;
1257 bool pf_mdd_detected = false;
1259 reg = rd32(hw, PF_MDET_TX_PQM);
1260 if (reg & PF_MDET_TX_PQM_VALID_M) {
1261 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1262 dev_info(dev, "TX driver issue detected, PF reset issued\n");
1263 pf_mdd_detected = true;
1266 reg = rd32(hw, PF_MDET_TX_TCLAN);
1267 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1268 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1269 dev_info(dev, "TX driver issue detected, PF reset issued\n");
1270 pf_mdd_detected = true;
1273 reg = rd32(hw, PF_MDET_RX);
1274 if (reg & PF_MDET_RX_VALID_M) {
1275 wr32(hw, PF_MDET_RX, 0xFFFF);
1276 dev_info(dev, "RX driver issue detected, PF reset issued\n");
1277 pf_mdd_detected = true;
1279 /* Queue belongs to the PF initiate a reset */
1280 if (pf_mdd_detected) {
1281 set_bit(__ICE_NEEDS_RESTART, pf->state);
1282 ice_service_task_schedule(pf);
1286 /* check to see if one of the VFs caused the MDD */
1287 ice_for_each_vf(pf, i) {
1288 struct ice_vf *vf = &pf->vf[i];
1290 bool vf_mdd_detected = false;
1292 reg = rd32(hw, VP_MDET_TX_PQM(i));
1293 if (reg & VP_MDET_TX_PQM_VALID_M) {
1294 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1295 vf_mdd_detected = true;
1296 dev_info(dev, "TX driver issue detected on VF %d\n",
1300 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1301 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1302 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1303 vf_mdd_detected = true;
1304 dev_info(dev, "TX driver issue detected on VF %d\n",
1308 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1309 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1310 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1311 vf_mdd_detected = true;
1312 dev_info(dev, "TX driver issue detected on VF %d\n",
1316 reg = rd32(hw, VP_MDET_RX(i));
1317 if (reg & VP_MDET_RX_VALID_M) {
1318 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1319 vf_mdd_detected = true;
1320 dev_info(dev, "RX driver issue detected on VF %d\n",
1324 if (vf_mdd_detected) {
1325 vf->num_mdd_events++;
1326 if (vf->num_mdd_events &&
1327 vf->num_mdd_events <= ICE_MDD_EVENTS_THRESHOLD)
1328 dev_info(dev, "VF %d has had %llu MDD events since last boot, Admin might need to reload AVF driver with this number of events\n",
1329 i, vf->num_mdd_events);
1335 * ice_force_phys_link_state - Force the physical link state
1336 * @vsi: VSI to force the physical link state to up/down
1337 * @link_up: true/false indicates to set the physical link to up/down
1339 * Force the physical link state by getting the current PHY capabilities from
1340 * hardware and setting the PHY config based on the determined capabilities. If
1341 * link changes a link event will be triggered because both the Enable Automatic
1342 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1344 * Returns 0 on success, negative on failure
1346 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1348 struct ice_aqc_get_phy_caps_data *pcaps;
1349 struct ice_aqc_set_phy_cfg_data *cfg;
1350 struct ice_port_info *pi;
1354 if (!vsi || !vsi->port_info || !vsi->back)
1356 if (vsi->type != ICE_VSI_PF)
1359 dev = ice_pf_to_dev(vsi->back);
1361 pi = vsi->port_info;
1363 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1367 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1370 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1371 vsi->vsi_num, retcode);
1376 /* No change in link */
1377 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1378 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1381 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
1387 cfg->phy_type_low = pcaps->phy_type_low;
1388 cfg->phy_type_high = pcaps->phy_type_high;
1389 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1390 cfg->low_power_ctrl = pcaps->low_power_ctrl;
1391 cfg->eee_cap = pcaps->eee_cap;
1392 cfg->eeer_value = pcaps->eeer_value;
1393 cfg->link_fec_opt = pcaps->link_fec_options;
1395 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1397 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1399 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
1401 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1402 vsi->vsi_num, retcode);
1413 * ice_check_media_subtask - Check for media; bring link up if detected.
1414 * @pf: pointer to PF struct
1416 static void ice_check_media_subtask(struct ice_pf *pf)
1418 struct ice_port_info *pi;
1419 struct ice_vsi *vsi;
1422 vsi = ice_get_main_vsi(pf);
1426 /* No need to check for media if it's already present or the interface
1429 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) ||
1430 test_bit(__ICE_DOWN, vsi->state))
1433 /* Refresh link info and check if media is present */
1434 pi = vsi->port_info;
1435 err = ice_update_link_info(pi);
1439 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1440 err = ice_force_phys_link_state(vsi, true);
1443 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1445 /* A Link Status Event will be generated; the event handler
1446 * will complete bringing the interface up
1452 * ice_service_task - manage and run subtasks
1453 * @work: pointer to work_struct contained by the PF struct
1455 static void ice_service_task(struct work_struct *work)
1457 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1458 unsigned long start_time = jiffies;
1462 /* process reset requests first */
1463 ice_reset_subtask(pf);
1465 /* bail if a reset/recovery cycle is pending or rebuild failed */
1466 if (ice_is_reset_in_progress(pf->state) ||
1467 test_bit(__ICE_SUSPENDED, pf->state) ||
1468 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1469 ice_service_task_complete(pf);
1473 ice_clean_adminq_subtask(pf);
1474 ice_check_media_subtask(pf);
1475 ice_check_for_hang_subtask(pf);
1476 ice_sync_fltr_subtask(pf);
1477 ice_handle_mdd_event(pf);
1478 ice_watchdog_subtask(pf);
1480 if (ice_is_safe_mode(pf)) {
1481 ice_service_task_complete(pf);
1485 ice_process_vflr_event(pf);
1486 ice_clean_mailboxq_subtask(pf);
1488 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1489 ice_service_task_complete(pf);
1491 /* If the tasks have taken longer than one service timer period
1492 * or there is more work to be done, reset the service timer to
1493 * schedule the service task now.
1495 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1496 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1497 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1498 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1499 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1500 mod_timer(&pf->serv_tmr, jiffies);
1504 * ice_set_ctrlq_len - helper function to set controlq length
1505 * @hw: pointer to the HW instance
1507 static void ice_set_ctrlq_len(struct ice_hw *hw)
1509 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1510 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1511 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1512 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1513 hw->mailboxq.num_rq_entries = ICE_MBXRQ_LEN;
1514 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
1515 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1516 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1520 * ice_schedule_reset - schedule a reset
1521 * @pf: board private structure
1522 * @reset: reset being requested
1524 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
1526 struct device *dev = ice_pf_to_dev(pf);
1528 /* bail out if earlier reset has failed */
1529 if (test_bit(__ICE_RESET_FAILED, pf->state)) {
1530 dev_dbg(dev, "earlier reset has failed\n");
1533 /* bail if reset/recovery already in progress */
1534 if (ice_is_reset_in_progress(pf->state)) {
1535 dev_dbg(dev, "Reset already in progress\n");
1541 set_bit(__ICE_PFR_REQ, pf->state);
1543 case ICE_RESET_CORER:
1544 set_bit(__ICE_CORER_REQ, pf->state);
1546 case ICE_RESET_GLOBR:
1547 set_bit(__ICE_GLOBR_REQ, pf->state);
1553 ice_service_task_schedule(pf);
1558 * ice_irq_affinity_notify - Callback for affinity changes
1559 * @notify: context as to what irq was changed
1560 * @mask: the new affinity mask
1562 * This is a callback function used by the irq_set_affinity_notifier function
1563 * so that we may register to receive changes to the irq affinity masks.
1566 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1567 const cpumask_t *mask)
1569 struct ice_q_vector *q_vector =
1570 container_of(notify, struct ice_q_vector, affinity_notify);
1572 cpumask_copy(&q_vector->affinity_mask, mask);
1576 * ice_irq_affinity_release - Callback for affinity notifier release
1577 * @ref: internal core kernel usage
1579 * This is a callback function used by the irq_set_affinity_notifier function
1580 * to inform the current notification subscriber that they will no longer
1581 * receive notifications.
1583 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1586 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1587 * @vsi: the VSI being configured
1589 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1591 struct ice_hw *hw = &vsi->back->hw;
1594 ice_for_each_q_vector(vsi, i)
1595 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1602 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1603 * @vsi: the VSI being configured
1604 * @basename: name for the vector
1606 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1608 int q_vectors = vsi->num_q_vectors;
1609 struct ice_pf *pf = vsi->back;
1610 int base = vsi->base_vector;
1617 dev = ice_pf_to_dev(pf);
1618 for (vector = 0; vector < q_vectors; vector++) {
1619 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1621 irq_num = pf->msix_entries[base + vector].vector;
1623 if (q_vector->tx.ring && q_vector->rx.ring) {
1624 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1625 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1627 } else if (q_vector->rx.ring) {
1628 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1629 "%s-%s-%d", basename, "rx", rx_int_idx++);
1630 } else if (q_vector->tx.ring) {
1631 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1632 "%s-%s-%d", basename, "tx", tx_int_idx++);
1634 /* skip this unused q_vector */
1637 err = devm_request_irq(dev, irq_num, vsi->irq_handler, 0,
1638 q_vector->name, q_vector);
1640 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
1645 /* register for affinity change notifications */
1646 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1647 q_vector->affinity_notify.release = ice_irq_affinity_release;
1648 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1650 /* assign the mask for this irq */
1651 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1654 vsi->irqs_ready = true;
1660 irq_num = pf->msix_entries[base + vector].vector,
1661 irq_set_affinity_notifier(irq_num, NULL);
1662 irq_set_affinity_hint(irq_num, NULL);
1663 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
1669 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
1670 * @vsi: VSI to setup Tx rings used by XDP
1672 * Return 0 on success and negative value on error
1674 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
1676 struct device *dev = ice_pf_to_dev(vsi->back);
1679 for (i = 0; i < vsi->num_xdp_txq; i++) {
1680 u16 xdp_q_idx = vsi->alloc_txq + i;
1681 struct ice_ring *xdp_ring;
1683 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
1686 goto free_xdp_rings;
1688 xdp_ring->q_index = xdp_q_idx;
1689 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
1690 xdp_ring->ring_active = false;
1691 xdp_ring->vsi = vsi;
1692 xdp_ring->netdev = NULL;
1693 xdp_ring->dev = dev;
1694 xdp_ring->count = vsi->num_tx_desc;
1695 vsi->xdp_rings[i] = xdp_ring;
1696 if (ice_setup_tx_ring(xdp_ring))
1697 goto free_xdp_rings;
1698 ice_set_ring_xdp(xdp_ring);
1699 xdp_ring->xsk_umem = ice_xsk_umem(xdp_ring);
1706 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
1707 ice_free_tx_ring(vsi->xdp_rings[i]);
1712 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
1713 * @vsi: VSI to set the bpf prog on
1714 * @prog: the bpf prog pointer
1716 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
1718 struct bpf_prog *old_prog;
1721 old_prog = xchg(&vsi->xdp_prog, prog);
1723 bpf_prog_put(old_prog);
1725 ice_for_each_rxq(vsi, i)
1726 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
1730 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
1731 * @vsi: VSI to bring up Tx rings used by XDP
1732 * @prog: bpf program that will be assigned to VSI
1734 * Return 0 on success and negative value on error
1736 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
1738 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1739 int xdp_rings_rem = vsi->num_xdp_txq;
1740 struct ice_pf *pf = vsi->back;
1741 struct ice_qs_cfg xdp_qs_cfg = {
1742 .qs_mutex = &pf->avail_q_mutex,
1743 .pf_map = pf->avail_txqs,
1744 .pf_map_size = pf->max_pf_txqs,
1745 .q_count = vsi->num_xdp_txq,
1746 .scatter_count = ICE_MAX_SCATTER_TXQS,
1747 .vsi_map = vsi->txq_map,
1748 .vsi_map_offset = vsi->alloc_txq,
1749 .mapping_mode = ICE_VSI_MAP_CONTIG
1751 enum ice_status status;
1755 dev = ice_pf_to_dev(pf);
1756 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
1757 sizeof(*vsi->xdp_rings), GFP_KERNEL);
1758 if (!vsi->xdp_rings)
1761 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
1762 if (__ice_vsi_get_qs(&xdp_qs_cfg))
1765 if (ice_xdp_alloc_setup_rings(vsi))
1766 goto clear_xdp_rings;
1768 /* follow the logic from ice_vsi_map_rings_to_vectors */
1769 ice_for_each_q_vector(vsi, v_idx) {
1770 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1771 int xdp_rings_per_v, q_id, q_base;
1773 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
1774 vsi->num_q_vectors - v_idx);
1775 q_base = vsi->num_xdp_txq - xdp_rings_rem;
1777 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
1778 struct ice_ring *xdp_ring = vsi->xdp_rings[q_id];
1780 xdp_ring->q_vector = q_vector;
1781 xdp_ring->next = q_vector->tx.ring;
1782 q_vector->tx.ring = xdp_ring;
1784 xdp_rings_rem -= xdp_rings_per_v;
1787 /* omit the scheduler update if in reset path; XDP queues will be
1788 * taken into account at the end of ice_vsi_rebuild, where
1789 * ice_cfg_vsi_lan is being called
1791 if (ice_is_reset_in_progress(pf->state))
1794 /* tell the Tx scheduler that right now we have
1797 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1798 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
1800 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1803 dev_err(dev, "Failed VSI LAN queue config for XDP, error:%d\n",
1805 goto clear_xdp_rings;
1807 ice_vsi_assign_bpf_prog(vsi, prog);
1811 for (i = 0; i < vsi->num_xdp_txq; i++)
1812 if (vsi->xdp_rings[i]) {
1813 kfree_rcu(vsi->xdp_rings[i], rcu);
1814 vsi->xdp_rings[i] = NULL;
1818 mutex_lock(&pf->avail_q_mutex);
1819 for (i = 0; i < vsi->num_xdp_txq; i++) {
1820 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1821 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1823 mutex_unlock(&pf->avail_q_mutex);
1825 devm_kfree(dev, vsi->xdp_rings);
1830 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
1831 * @vsi: VSI to remove XDP rings
1833 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
1836 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
1838 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1839 struct ice_pf *pf = vsi->back;
1842 /* q_vectors are freed in reset path so there's no point in detaching
1843 * rings; in case of rebuild being triggered not from reset reset bits
1844 * in pf->state won't be set, so additionally check first q_vector
1847 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1850 ice_for_each_q_vector(vsi, v_idx) {
1851 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1852 struct ice_ring *ring;
1854 ice_for_each_ring(ring, q_vector->tx)
1855 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
1858 /* restore the value of last node prior to XDP setup */
1859 q_vector->tx.ring = ring;
1863 mutex_lock(&pf->avail_q_mutex);
1864 for (i = 0; i < vsi->num_xdp_txq; i++) {
1865 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1866 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1868 mutex_unlock(&pf->avail_q_mutex);
1870 for (i = 0; i < vsi->num_xdp_txq; i++)
1871 if (vsi->xdp_rings[i]) {
1872 if (vsi->xdp_rings[i]->desc)
1873 ice_free_tx_ring(vsi->xdp_rings[i]);
1874 kfree_rcu(vsi->xdp_rings[i], rcu);
1875 vsi->xdp_rings[i] = NULL;
1878 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
1879 vsi->xdp_rings = NULL;
1881 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1884 ice_vsi_assign_bpf_prog(vsi, NULL);
1886 /* notify Tx scheduler that we destroyed XDP queues and bring
1887 * back the old number of child nodes
1889 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1890 max_txqs[i] = vsi->num_txq;
1892 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1897 * ice_xdp_setup_prog - Add or remove XDP eBPF program
1898 * @vsi: VSI to setup XDP for
1899 * @prog: XDP program
1900 * @extack: netlink extended ack
1903 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
1904 struct netlink_ext_ack *extack)
1906 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
1907 bool if_running = netif_running(vsi->netdev);
1908 int ret = 0, xdp_ring_err = 0;
1910 if (frame_size > vsi->rx_buf_len) {
1911 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
1915 /* need to stop netdev while setting up the program for Rx rings */
1916 if (if_running && !test_and_set_bit(__ICE_DOWN, vsi->state)) {
1917 ret = ice_down(vsi);
1919 NL_SET_ERR_MSG_MOD(extack,
1920 "Preparing device for XDP attach failed");
1925 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
1926 vsi->num_xdp_txq = vsi->alloc_txq;
1927 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
1929 NL_SET_ERR_MSG_MOD(extack,
1930 "Setting up XDP Tx resources failed");
1931 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
1932 xdp_ring_err = ice_destroy_xdp_rings(vsi);
1934 NL_SET_ERR_MSG_MOD(extack,
1935 "Freeing XDP Tx resources failed");
1937 ice_vsi_assign_bpf_prog(vsi, prog);
1943 if (!ret && prog && vsi->xsk_umems) {
1946 ice_for_each_rxq(vsi, i) {
1947 struct ice_ring *rx_ring = vsi->rx_rings[i];
1949 if (rx_ring->xsk_umem)
1950 napi_schedule(&rx_ring->q_vector->napi);
1954 return (ret || xdp_ring_err) ? -ENOMEM : 0;
1958 * ice_xdp - implements XDP handler
1962 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
1964 struct ice_netdev_priv *np = netdev_priv(dev);
1965 struct ice_vsi *vsi = np->vsi;
1967 if (vsi->type != ICE_VSI_PF) {
1968 NL_SET_ERR_MSG_MOD(xdp->extack,
1969 "XDP can be loaded only on PF VSI");
1973 switch (xdp->command) {
1974 case XDP_SETUP_PROG:
1975 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
1976 case XDP_QUERY_PROG:
1977 xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
1979 case XDP_SETUP_XSK_UMEM:
1980 return ice_xsk_umem_setup(vsi, xdp->xsk.umem,
1988 * ice_ena_misc_vector - enable the non-queue interrupts
1989 * @pf: board private structure
1991 static void ice_ena_misc_vector(struct ice_pf *pf)
1993 struct ice_hw *hw = &pf->hw;
1996 /* clear things first */
1997 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1998 rd32(hw, PFINT_OICR); /* read to clear */
2000 val = (PFINT_OICR_ECC_ERR_M |
2001 PFINT_OICR_MAL_DETECT_M |
2003 PFINT_OICR_PCI_EXCEPTION_M |
2005 PFINT_OICR_HMC_ERR_M |
2006 PFINT_OICR_PE_CRITERR_M);
2008 wr32(hw, PFINT_OICR_ENA, val);
2010 /* SW_ITR_IDX = 0, but don't change INTENA */
2011 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2012 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2016 * ice_misc_intr - misc interrupt handler
2017 * @irq: interrupt number
2018 * @data: pointer to a q_vector
2020 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2022 struct ice_pf *pf = (struct ice_pf *)data;
2023 struct ice_hw *hw = &pf->hw;
2024 irqreturn_t ret = IRQ_NONE;
2028 dev = ice_pf_to_dev(pf);
2029 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
2030 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2032 oicr = rd32(hw, PFINT_OICR);
2033 ena_mask = rd32(hw, PFINT_OICR_ENA);
2035 if (oicr & PFINT_OICR_SWINT_M) {
2036 ena_mask &= ~PFINT_OICR_SWINT_M;
2040 if (oicr & PFINT_OICR_MAL_DETECT_M) {
2041 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2042 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
2044 if (oicr & PFINT_OICR_VFLR_M) {
2045 ena_mask &= ~PFINT_OICR_VFLR_M;
2046 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
2049 if (oicr & PFINT_OICR_GRST_M) {
2052 /* we have a reset warning */
2053 ena_mask &= ~PFINT_OICR_GRST_M;
2054 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
2055 GLGEN_RSTAT_RESET_TYPE_S;
2057 if (reset == ICE_RESET_CORER)
2059 else if (reset == ICE_RESET_GLOBR)
2061 else if (reset == ICE_RESET_EMPR)
2064 dev_dbg(dev, "Invalid reset type %d\n", reset);
2066 /* If a reset cycle isn't already in progress, we set a bit in
2067 * pf->state so that the service task can start a reset/rebuild.
2068 * We also make note of which reset happened so that peer
2069 * devices/drivers can be informed.
2071 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
2072 if (reset == ICE_RESET_CORER)
2073 set_bit(__ICE_CORER_RECV, pf->state);
2074 else if (reset == ICE_RESET_GLOBR)
2075 set_bit(__ICE_GLOBR_RECV, pf->state);
2077 set_bit(__ICE_EMPR_RECV, pf->state);
2079 /* There are couple of different bits at play here.
2080 * hw->reset_ongoing indicates whether the hardware is
2081 * in reset. This is set to true when a reset interrupt
2082 * is received and set back to false after the driver
2083 * has determined that the hardware is out of reset.
2085 * __ICE_RESET_OICR_RECV in pf->state indicates
2086 * that a post reset rebuild is required before the
2087 * driver is operational again. This is set above.
2089 * As this is the start of the reset/rebuild cycle, set
2090 * both to indicate that.
2092 hw->reset_ongoing = true;
2096 if (oicr & PFINT_OICR_HMC_ERR_M) {
2097 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
2098 dev_dbg(dev, "HMC Error interrupt - info 0x%x, data 0x%x\n",
2099 rd32(hw, PFHMC_ERRORINFO),
2100 rd32(hw, PFHMC_ERRORDATA));
2103 /* Report any remaining unexpected interrupts */
2106 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
2107 /* If a critical error is pending there is no choice but to
2110 if (oicr & (PFINT_OICR_PE_CRITERR_M |
2111 PFINT_OICR_PCI_EXCEPTION_M |
2112 PFINT_OICR_ECC_ERR_M)) {
2113 set_bit(__ICE_PFR_REQ, pf->state);
2114 ice_service_task_schedule(pf);
2119 if (!test_bit(__ICE_DOWN, pf->state)) {
2120 ice_service_task_schedule(pf);
2121 ice_irq_dynamic_ena(hw, NULL, NULL);
2128 * ice_dis_ctrlq_interrupts - disable control queue interrupts
2129 * @hw: pointer to HW structure
2131 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
2133 /* disable Admin queue Interrupt causes */
2134 wr32(hw, PFINT_FW_CTL,
2135 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
2137 /* disable Mailbox queue Interrupt causes */
2138 wr32(hw, PFINT_MBX_CTL,
2139 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
2141 /* disable Control queue Interrupt causes */
2142 wr32(hw, PFINT_OICR_CTL,
2143 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
2149 * ice_free_irq_msix_misc - Unroll misc vector setup
2150 * @pf: board private structure
2152 static void ice_free_irq_msix_misc(struct ice_pf *pf)
2154 struct ice_hw *hw = &pf->hw;
2156 ice_dis_ctrlq_interrupts(hw);
2158 /* disable OICR interrupt */
2159 wr32(hw, PFINT_OICR_ENA, 0);
2162 if (pf->msix_entries) {
2163 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
2164 devm_free_irq(ice_pf_to_dev(pf),
2165 pf->msix_entries[pf->oicr_idx].vector, pf);
2168 pf->num_avail_sw_msix += 1;
2169 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
2173 * ice_ena_ctrlq_interrupts - enable control queue interrupts
2174 * @hw: pointer to HW structure
2175 * @reg_idx: HW vector index to associate the control queue interrupts with
2177 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
2181 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2182 PFINT_OICR_CTL_CAUSE_ENA_M);
2183 wr32(hw, PFINT_OICR_CTL, val);
2185 /* enable Admin queue Interrupt causes */
2186 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2187 PFINT_FW_CTL_CAUSE_ENA_M);
2188 wr32(hw, PFINT_FW_CTL, val);
2190 /* enable Mailbox queue Interrupt causes */
2191 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
2192 PFINT_MBX_CTL_CAUSE_ENA_M);
2193 wr32(hw, PFINT_MBX_CTL, val);
2199 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2200 * @pf: board private structure
2202 * This sets up the handler for MSIX 0, which is used to manage the
2203 * non-queue interrupts, e.g. AdminQ and errors. This is not used
2204 * when in MSI or Legacy interrupt mode.
2206 static int ice_req_irq_msix_misc(struct ice_pf *pf)
2208 struct device *dev = ice_pf_to_dev(pf);
2209 struct ice_hw *hw = &pf->hw;
2210 int oicr_idx, err = 0;
2212 if (!pf->int_name[0])
2213 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
2214 dev_driver_string(dev), dev_name(dev));
2216 /* Do not request IRQ but do enable OICR interrupt since settings are
2217 * lost during reset. Note that this function is called only during
2218 * rebuild path and not while reset is in progress.
2220 if (ice_is_reset_in_progress(pf->state))
2223 /* reserve one vector in irq_tracker for misc interrupts */
2224 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2228 pf->num_avail_sw_msix -= 1;
2229 pf->oicr_idx = oicr_idx;
2231 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
2232 ice_misc_intr, 0, pf->int_name, pf);
2234 dev_err(dev, "devm_request_irq for %s failed: %d\n",
2236 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2237 pf->num_avail_sw_msix += 1;
2242 ice_ena_misc_vector(pf);
2244 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
2245 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
2246 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
2249 ice_irq_dynamic_ena(hw, NULL, NULL);
2255 * ice_napi_add - register NAPI handler for the VSI
2256 * @vsi: VSI for which NAPI handler is to be registered
2258 * This function is only called in the driver's load path. Registering the NAPI
2259 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
2260 * reset/rebuild, etc.)
2262 static void ice_napi_add(struct ice_vsi *vsi)
2269 ice_for_each_q_vector(vsi, v_idx)
2270 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
2271 ice_napi_poll, NAPI_POLL_WEIGHT);
2275 * ice_set_ops - set netdev and ethtools ops for the given netdev
2276 * @netdev: netdev instance
2278 static void ice_set_ops(struct net_device *netdev)
2280 struct ice_pf *pf = ice_netdev_to_pf(netdev);
2282 if (ice_is_safe_mode(pf)) {
2283 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
2284 ice_set_ethtool_safe_mode_ops(netdev);
2288 netdev->netdev_ops = &ice_netdev_ops;
2289 ice_set_ethtool_ops(netdev);
2293 * ice_set_netdev_features - set features for the given netdev
2294 * @netdev: netdev instance
2296 static void ice_set_netdev_features(struct net_device *netdev)
2298 struct ice_pf *pf = ice_netdev_to_pf(netdev);
2299 netdev_features_t csumo_features;
2300 netdev_features_t vlano_features;
2301 netdev_features_t dflt_features;
2302 netdev_features_t tso_features;
2304 if (ice_is_safe_mode(pf)) {
2306 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
2307 netdev->hw_features = netdev->features;
2311 dflt_features = NETIF_F_SG |
2315 csumo_features = NETIF_F_RXCSUM |
2320 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
2321 NETIF_F_HW_VLAN_CTAG_TX |
2322 NETIF_F_HW_VLAN_CTAG_RX;
2324 tso_features = NETIF_F_TSO |
2327 /* set features that user can change */
2328 netdev->hw_features = dflt_features | csumo_features |
2329 vlano_features | tso_features;
2331 /* enable features */
2332 netdev->features |= netdev->hw_features;
2333 /* encap and VLAN devices inherit default, csumo and tso features */
2334 netdev->hw_enc_features |= dflt_features | csumo_features |
2336 netdev->vlan_features |= dflt_features | csumo_features |
2341 * ice_cfg_netdev - Allocate, configure and register a netdev
2342 * @vsi: the VSI associated with the new netdev
2344 * Returns 0 on success, negative value on failure
2346 static int ice_cfg_netdev(struct ice_vsi *vsi)
2348 struct ice_pf *pf = vsi->back;
2349 struct ice_netdev_priv *np;
2350 struct net_device *netdev;
2351 u8 mac_addr[ETH_ALEN];
2354 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
2359 vsi->netdev = netdev;
2360 np = netdev_priv(netdev);
2363 ice_set_netdev_features(netdev);
2365 ice_set_ops(netdev);
2367 if (vsi->type == ICE_VSI_PF) {
2368 SET_NETDEV_DEV(netdev, ice_pf_to_dev(pf));
2369 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
2370 ether_addr_copy(netdev->dev_addr, mac_addr);
2371 ether_addr_copy(netdev->perm_addr, mac_addr);
2374 netdev->priv_flags |= IFF_UNICAST_FLT;
2376 /* Setup netdev TC information */
2377 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
2379 /* setup watchdog timeout value to be 5 second */
2380 netdev->watchdog_timeo = 5 * HZ;
2382 netdev->min_mtu = ETH_MIN_MTU;
2383 netdev->max_mtu = ICE_MAX_MTU;
2385 err = register_netdev(vsi->netdev);
2389 netif_carrier_off(vsi->netdev);
2391 /* make sure transmit queues start off as stopped */
2392 netif_tx_stop_all_queues(vsi->netdev);
2398 * ice_fill_rss_lut - Fill the RSS lookup table with default values
2399 * @lut: Lookup table
2400 * @rss_table_size: Lookup table size
2401 * @rss_size: Range of queue number for hashing
2403 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2407 for (i = 0; i < rss_table_size; i++)
2408 lut[i] = i % rss_size;
2412 * ice_pf_vsi_setup - Set up a PF VSI
2413 * @pf: board private structure
2414 * @pi: pointer to the port_info instance
2416 * Returns pointer to the successfully allocated VSI software struct
2417 * on success, otherwise returns NULL on failure.
2419 static struct ice_vsi *
2420 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2422 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
2426 * ice_lb_vsi_setup - Set up a loopback VSI
2427 * @pf: board private structure
2428 * @pi: pointer to the port_info instance
2430 * Returns pointer to the successfully allocated VSI software struct
2431 * on success, otherwise returns NULL on failure.
2434 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2436 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
2440 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2441 * @netdev: network interface to be adjusted
2442 * @proto: unused protocol
2443 * @vid: VLAN ID to be added
2445 * net_device_ops implementation for adding VLAN IDs
2448 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
2451 struct ice_netdev_priv *np = netdev_priv(netdev);
2452 struct ice_vsi *vsi = np->vsi;
2455 if (vid >= VLAN_N_VID) {
2456 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2464 /* VLAN 0 is added by default during load/reset */
2468 /* Enable VLAN pruning when a VLAN other than 0 is added */
2469 if (!ice_vsi_is_vlan_pruning_ena(vsi)) {
2470 ret = ice_cfg_vlan_pruning(vsi, true, false);
2475 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
2476 * packets aren't pruned by the device's internal switch on Rx
2478 ret = ice_vsi_add_vlan(vsi, vid);
2480 vsi->vlan_ena = true;
2481 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2488 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2489 * @netdev: network interface to be adjusted
2490 * @proto: unused protocol
2491 * @vid: VLAN ID to be removed
2493 * net_device_ops implementation for removing VLAN IDs
2496 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
2499 struct ice_netdev_priv *np = netdev_priv(netdev);
2500 struct ice_vsi *vsi = np->vsi;
2506 /* don't allow removal of VLAN 0 */
2510 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2513 ret = ice_vsi_kill_vlan(vsi, vid);
2517 /* Disable pruning when VLAN 0 is the only VLAN rule */
2518 if (vsi->num_vlan == 1 && ice_vsi_is_vlan_pruning_ena(vsi))
2519 ret = ice_cfg_vlan_pruning(vsi, false, false);
2521 vsi->vlan_ena = false;
2522 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2527 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2528 * @pf: board private structure
2530 * Returns 0 on success, negative value on failure
2532 static int ice_setup_pf_sw(struct ice_pf *pf)
2534 struct ice_vsi *vsi;
2537 if (ice_is_reset_in_progress(pf->state))
2540 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2543 goto unroll_vsi_setup;
2546 status = ice_cfg_netdev(vsi);
2549 goto unroll_vsi_setup;
2551 /* netdev has to be configured before setting frame size */
2552 ice_vsi_cfg_frame_size(vsi);
2554 /* Setup DCB netlink interface */
2555 ice_dcbnl_setup(vsi);
2557 /* registering the NAPI handler requires both the queues and
2558 * netdev to be created, which are done in ice_pf_vsi_setup()
2559 * and ice_cfg_netdev() respectively
2563 status = ice_init_mac_fltr(pf);
2565 goto unroll_napi_add;
2573 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2574 unregister_netdev(vsi->netdev);
2575 free_netdev(vsi->netdev);
2582 ice_vsi_free_q_vectors(vsi);
2583 ice_vsi_delete(vsi);
2584 ice_vsi_put_qs(vsi);
2591 * ice_get_avail_q_count - Get count of queues in use
2592 * @pf_qmap: bitmap to get queue use count from
2593 * @lock: pointer to a mutex that protects access to pf_qmap
2594 * @size: size of the bitmap
2597 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
2602 for_each_clear_bit(bit, pf_qmap, size)
2610 * ice_get_avail_txq_count - Get count of Tx queues in use
2611 * @pf: pointer to an ice_pf instance
2613 u16 ice_get_avail_txq_count(struct ice_pf *pf)
2615 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
2620 * ice_get_avail_rxq_count - Get count of Rx queues in use
2621 * @pf: pointer to an ice_pf instance
2623 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
2625 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
2630 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2631 * @pf: board private structure to initialize
2633 static void ice_deinit_pf(struct ice_pf *pf)
2635 ice_service_task_stop(pf);
2636 mutex_destroy(&pf->sw_mutex);
2637 mutex_destroy(&pf->tc_mutex);
2638 mutex_destroy(&pf->avail_q_mutex);
2640 if (pf->avail_txqs) {
2641 bitmap_free(pf->avail_txqs);
2642 pf->avail_txqs = NULL;
2645 if (pf->avail_rxqs) {
2646 bitmap_free(pf->avail_rxqs);
2647 pf->avail_rxqs = NULL;
2652 * ice_set_pf_caps - set PFs capability flags
2653 * @pf: pointer to the PF instance
2655 static void ice_set_pf_caps(struct ice_pf *pf)
2657 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
2659 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2660 if (func_caps->common_cap.dcb)
2661 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2662 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2663 if (func_caps->common_cap.sr_iov_1_1) {
2664 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2665 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
2668 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
2669 if (func_caps->common_cap.rss_table_size)
2670 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2672 pf->max_pf_txqs = func_caps->common_cap.num_txq;
2673 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
2677 * ice_init_pf - Initialize general software structures (struct ice_pf)
2678 * @pf: board private structure to initialize
2680 static int ice_init_pf(struct ice_pf *pf)
2682 ice_set_pf_caps(pf);
2684 mutex_init(&pf->sw_mutex);
2685 mutex_init(&pf->tc_mutex);
2687 /* setup service timer and periodic service task */
2688 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2689 pf->serv_tmr_period = HZ;
2690 INIT_WORK(&pf->serv_task, ice_service_task);
2691 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2693 mutex_init(&pf->avail_q_mutex);
2694 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
2695 if (!pf->avail_txqs)
2698 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
2699 if (!pf->avail_rxqs) {
2700 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
2701 pf->avail_txqs = NULL;
2709 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2710 * @pf: board private structure
2712 * compute the number of MSIX vectors required (v_budget) and request from
2713 * the OS. Return the number of vectors reserved or negative on failure
2715 static int ice_ena_msix_range(struct ice_pf *pf)
2717 struct device *dev = ice_pf_to_dev(pf);
2718 int v_left, v_actual, v_budget = 0;
2721 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2723 /* reserve one vector for miscellaneous handler */
2725 if (v_left < needed)
2726 goto no_hw_vecs_left_err;
2730 /* reserve vectors for LAN traffic */
2731 needed = min_t(int, num_online_cpus(), v_left);
2732 if (v_left < needed)
2733 goto no_hw_vecs_left_err;
2734 pf->num_lan_msix = needed;
2738 pf->msix_entries = devm_kcalloc(dev, v_budget,
2739 sizeof(*pf->msix_entries), GFP_KERNEL);
2741 if (!pf->msix_entries) {
2746 for (i = 0; i < v_budget; i++)
2747 pf->msix_entries[i].entry = i;
2749 /* actually reserve the vectors */
2750 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2751 ICE_MIN_MSIX, v_budget);
2754 dev_err(dev, "unable to reserve MSI-X vectors\n");
2759 if (v_actual < v_budget) {
2760 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
2761 v_budget, v_actual);
2762 /* 2 vectors for LAN (traffic + OICR) */
2763 #define ICE_MIN_LAN_VECS 2
2765 if (v_actual < ICE_MIN_LAN_VECS) {
2766 /* error if we can't get minimum vectors */
2767 pci_disable_msix(pf->pdev);
2771 pf->num_lan_msix = ICE_MIN_LAN_VECS;
2778 devm_kfree(dev, pf->msix_entries);
2781 no_hw_vecs_left_err:
2782 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
2786 pf->num_lan_msix = 0;
2791 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2792 * @pf: board private structure
2794 static void ice_dis_msix(struct ice_pf *pf)
2796 pci_disable_msix(pf->pdev);
2797 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
2798 pf->msix_entries = NULL;
2802 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2803 * @pf: board private structure
2805 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2809 if (pf->irq_tracker) {
2810 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
2811 pf->irq_tracker = NULL;
2816 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2817 * @pf: board private structure to initialize
2819 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2823 vectors = ice_ena_msix_range(pf);
2828 /* set up vector assignment tracking */
2830 devm_kzalloc(ice_pf_to_dev(pf), sizeof(*pf->irq_tracker) +
2831 (sizeof(u16) * vectors), GFP_KERNEL);
2832 if (!pf->irq_tracker) {
2837 /* populate SW interrupts pool with number of OS granted IRQs. */
2838 pf->num_avail_sw_msix = vectors;
2839 pf->irq_tracker->num_entries = vectors;
2840 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2846 * ice_vsi_recfg_qs - Change the number of queues on a VSI
2847 * @vsi: VSI being changed
2848 * @new_rx: new number of Rx queues
2849 * @new_tx: new number of Tx queues
2851 * Only change the number of queues if new_tx, or new_rx is non-0.
2853 * Returns 0 on success.
2855 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
2857 struct ice_pf *pf = vsi->back;
2858 int err = 0, timeout = 50;
2860 if (!new_rx && !new_tx)
2863 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2867 usleep_range(1000, 2000);
2871 vsi->req_txq = new_tx;
2873 vsi->req_rxq = new_rx;
2875 /* set for the next time the netdev is started */
2876 if (!netif_running(vsi->netdev)) {
2877 ice_vsi_rebuild(vsi, false);
2878 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
2883 ice_vsi_rebuild(vsi, false);
2884 ice_pf_dcb_recfg(pf);
2887 clear_bit(__ICE_CFG_BUSY, pf->state);
2892 * ice_log_pkg_init - log result of DDP package load
2893 * @hw: pointer to hardware info
2894 * @status: status of package load
2897 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status)
2899 struct ice_pf *pf = (struct ice_pf *)hw->back;
2900 struct device *dev = ice_pf_to_dev(pf);
2904 /* The package download AdminQ command returned success because
2905 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
2906 * already a package loaded on the device.
2908 if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
2909 hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
2910 hw->pkg_ver.update == hw->active_pkg_ver.update &&
2911 hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
2912 !memcmp(hw->pkg_name, hw->active_pkg_name,
2913 sizeof(hw->pkg_name))) {
2914 if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST)
2915 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
2916 hw->active_pkg_name,
2917 hw->active_pkg_ver.major,
2918 hw->active_pkg_ver.minor,
2919 hw->active_pkg_ver.update,
2920 hw->active_pkg_ver.draft);
2922 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
2923 hw->active_pkg_name,
2924 hw->active_pkg_ver.major,
2925 hw->active_pkg_ver.minor,
2926 hw->active_pkg_ver.update,
2927 hw->active_pkg_ver.draft);
2928 } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
2929 hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
2930 dev_err(dev, "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",
2931 hw->active_pkg_name,
2932 hw->active_pkg_ver.major,
2933 hw->active_pkg_ver.minor,
2934 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2935 *status = ICE_ERR_NOT_SUPPORTED;
2936 } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2937 hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
2938 dev_info(dev, "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",
2939 hw->active_pkg_name,
2940 hw->active_pkg_ver.major,
2941 hw->active_pkg_ver.minor,
2942 hw->active_pkg_ver.update,
2943 hw->active_pkg_ver.draft,
2950 dev_err(dev, "An unknown error occurred when loading the DDP package, please reboot the system. If the problem persists, update the NVM. Entering Safe Mode.\n");
2951 *status = ICE_ERR_NOT_SUPPORTED;
2954 case ICE_ERR_BUF_TOO_SHORT:
2957 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
2959 case ICE_ERR_NOT_SUPPORTED:
2960 /* Package File version not supported */
2961 if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ ||
2962 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2963 hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR))
2964 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
2965 else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ ||
2966 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2967 hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR))
2968 dev_err(dev, "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",
2969 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2971 case ICE_ERR_AQ_ERROR:
2972 switch (hw->pkg_dwnld_status) {
2973 case ICE_AQ_RC_ENOSEC:
2974 case ICE_AQ_RC_EBADSIG:
2975 dev_err(dev, "The DDP package could not be loaded because its signature is not valid. Please use a valid DDP Package. Entering Safe Mode.\n");
2977 case ICE_AQ_RC_ESVN:
2978 dev_err(dev, "The DDP Package could not be loaded because its security revision is too low. Please use an updated DDP Package. Entering Safe Mode.\n");
2980 case ICE_AQ_RC_EBADMAN:
2981 case ICE_AQ_RC_EBADBUF:
2982 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
2989 dev_err(dev, "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n",
2996 * ice_load_pkg - load/reload the DDP Package file
2997 * @firmware: firmware structure when firmware requested or NULL for reload
2998 * @pf: pointer to the PF instance
3000 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
3001 * initialize HW tables.
3004 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
3006 enum ice_status status = ICE_ERR_PARAM;
3007 struct device *dev = ice_pf_to_dev(pf);
3008 struct ice_hw *hw = &pf->hw;
3010 /* Load DDP Package */
3011 if (firmware && !hw->pkg_copy) {
3012 status = ice_copy_and_init_pkg(hw, firmware->data,
3014 ice_log_pkg_init(hw, &status);
3015 } else if (!firmware && hw->pkg_copy) {
3016 /* Reload package during rebuild after CORER/GLOBR reset */
3017 status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
3018 ice_log_pkg_init(hw, &status);
3020 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
3025 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3029 /* Successful download package is the precondition for advanced
3030 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
3032 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3036 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
3037 * @pf: pointer to the PF structure
3039 * There is no error returned here because the driver should be able to handle
3040 * 128 Byte cache lines, so we only print a warning in case issues are seen,
3041 * specifically with Tx.
3043 static void ice_verify_cacheline_size(struct ice_pf *pf)
3045 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
3046 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
3047 ICE_CACHE_LINE_BYTES);
3051 * ice_send_version - update firmware with driver version
3054 * Returns ICE_SUCCESS on success, else error code
3056 static enum ice_status ice_send_version(struct ice_pf *pf)
3058 struct ice_driver_ver dv;
3060 dv.major_ver = DRV_VERSION_MAJOR;
3061 dv.minor_ver = DRV_VERSION_MINOR;
3062 dv.build_ver = DRV_VERSION_BUILD;
3063 dv.subbuild_ver = 0;
3064 strscpy((char *)dv.driver_string, DRV_VERSION,
3065 sizeof(dv.driver_string));
3066 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
3070 * ice_get_opt_fw_name - return optional firmware file name or NULL
3071 * @pf: pointer to the PF instance
3073 static char *ice_get_opt_fw_name(struct ice_pf *pf)
3075 /* Optional firmware name same as default with additional dash
3076 * followed by a EUI-64 identifier (PCIe Device Serial Number)
3078 struct pci_dev *pdev = pf->pdev;
3079 char *opt_fw_filename = NULL;
3084 /* Determine the name of the optional file using the DSN (two
3085 * dwords following the start of the DSN Capability).
3087 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
3089 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
3090 if (!opt_fw_filename)
3093 pci_read_config_dword(pdev, pos + 4, &dword);
3094 put_unaligned_le32(dword, &dsn[0]);
3095 pci_read_config_dword(pdev, pos + 8, &dword);
3096 put_unaligned_le32(dword, &dsn[4]);
3097 snprintf(opt_fw_filename, NAME_MAX,
3098 "%sice-%02x%02x%02x%02x%02x%02x%02x%02x.pkg",
3100 dsn[7], dsn[6], dsn[5], dsn[4],
3101 dsn[3], dsn[2], dsn[1], dsn[0]);
3104 return opt_fw_filename;
3108 * ice_request_fw - Device initialization routine
3109 * @pf: pointer to the PF instance
3111 static void ice_request_fw(struct ice_pf *pf)
3113 char *opt_fw_filename = ice_get_opt_fw_name(pf);
3114 const struct firmware *firmware = NULL;
3115 struct device *dev = ice_pf_to_dev(pf);
3118 /* optional device-specific DDP (if present) overrides the default DDP
3119 * package file. kernel logs a debug message if the file doesn't exist,
3120 * and warning messages for other errors.
3122 if (opt_fw_filename) {
3123 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
3125 kfree(opt_fw_filename);
3129 /* request for firmware was successful. Download to device */
3130 ice_load_pkg(firmware, pf);
3131 kfree(opt_fw_filename);
3132 release_firmware(firmware);
3137 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
3139 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
3143 /* request for firmware was successful. Download to device */
3144 ice_load_pkg(firmware, pf);
3145 release_firmware(firmware);
3149 * ice_probe - Device initialization routine
3150 * @pdev: PCI device information struct
3151 * @ent: entry in ice_pci_tbl
3153 * Returns 0 on success, negative on failure
3156 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
3158 struct device *dev = &pdev->dev;
3163 /* this driver uses devres, see
3164 * Documentation/driver-api/driver-model/devres.rst
3166 err = pcim_enable_device(pdev);
3170 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
3172 dev_err(dev, "BAR0 I/O map error %d\n", err);
3176 pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
3180 /* set up for high or low DMA */
3181 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
3183 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
3185 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
3189 pci_enable_pcie_error_reporting(pdev);
3190 pci_set_master(pdev);
3193 pci_set_drvdata(pdev, pf);
3194 set_bit(__ICE_DOWN, pf->state);
3195 /* Disable service task until DOWN bit is cleared */
3196 set_bit(__ICE_SERVICE_DIS, pf->state);
3199 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
3200 pci_save_state(pdev);
3203 hw->vendor_id = pdev->vendor;
3204 hw->device_id = pdev->device;
3205 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3206 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3207 hw->subsystem_device_id = pdev->subsystem_device;
3208 hw->bus.device = PCI_SLOT(pdev->devfn);
3209 hw->bus.func = PCI_FUNC(pdev->devfn);
3210 ice_set_ctrlq_len(hw);
3212 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
3214 #ifndef CONFIG_DYNAMIC_DEBUG
3216 hw->debug_mask = debug;
3219 err = ice_init_hw(hw);
3221 dev_err(dev, "ice_init_hw failed: %d\n", err);
3223 goto err_exit_unroll;
3228 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
3229 * set in pf->state, which will cause ice_is_safe_mode to return
3232 if (ice_is_safe_mode(pf)) {
3233 dev_err(dev, "Package download failed. Advanced features disabled - Device now in Safe Mode\n");
3234 /* we already got function/device capabilities but these don't
3235 * reflect what the driver needs to do in safe mode. Instead of
3236 * adding conditional logic everywhere to ignore these
3237 * device/function capabilities, override them.
3239 ice_set_safe_mode_caps(hw);
3242 err = ice_init_pf(pf);
3244 dev_err(dev, "ice_init_pf failed: %d\n", err);
3245 goto err_init_pf_unroll;
3248 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
3249 if (!pf->num_alloc_vsi) {
3251 goto err_init_pf_unroll;
3254 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
3258 goto err_init_pf_unroll;
3261 err = ice_init_interrupt_scheme(pf);
3263 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
3265 goto err_init_interrupt_unroll;
3268 /* Driver is mostly up */
3269 clear_bit(__ICE_DOWN, pf->state);
3271 /* In case of MSIX we are going to setup the misc vector right here
3272 * to handle admin queue events etc. In case of legacy and MSI
3273 * the misc functionality and queue processing is combined in
3274 * the same vector and that gets setup at open.
3276 err = ice_req_irq_msix_misc(pf);
3278 dev_err(dev, "setup of misc vector failed: %d\n", err);
3279 goto err_init_interrupt_unroll;
3282 /* create switch struct for the switch element created by FW on boot */
3283 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
3284 if (!pf->first_sw) {
3286 goto err_msix_misc_unroll;
3290 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
3292 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
3294 pf->first_sw->pf = pf;
3296 /* record the sw_id available for later use */
3297 pf->first_sw->sw_id = hw->port_info->sw_id;
3299 err = ice_setup_pf_sw(pf);
3301 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
3302 goto err_alloc_sw_unroll;
3305 clear_bit(__ICE_SERVICE_DIS, pf->state);
3307 /* tell the firmware we are up */
3308 err = ice_send_version(pf);
3310 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
3312 goto err_alloc_sw_unroll;
3315 /* since everything is good, start the service timer */
3316 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3318 err = ice_init_link_events(pf->hw.port_info);
3320 dev_err(dev, "ice_init_link_events failed: %d\n", err);
3321 goto err_alloc_sw_unroll;
3324 ice_verify_cacheline_size(pf);
3326 /* If no DDP driven features have to be setup, return here */
3327 if (ice_is_safe_mode(pf))
3330 /* initialize DDP driven features */
3332 /* Note: DCB init failure is non-fatal to load */
3333 if (ice_init_pf_dcb(pf, false)) {
3334 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3335 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
3337 ice_cfg_lldp_mib_change(&pf->hw, true);
3340 /* print PCI link speed and width */
3341 pcie_print_link_status(pf->pdev);
3345 err_alloc_sw_unroll:
3346 set_bit(__ICE_SERVICE_DIS, pf->state);
3347 set_bit(__ICE_DOWN, pf->state);
3348 devm_kfree(dev, pf->first_sw);
3349 err_msix_misc_unroll:
3350 ice_free_irq_msix_misc(pf);
3351 err_init_interrupt_unroll:
3352 ice_clear_interrupt_scheme(pf);
3353 devm_kfree(dev, pf->vsi);
3358 pci_disable_pcie_error_reporting(pdev);
3363 * ice_remove - Device removal routine
3364 * @pdev: PCI device information struct
3366 static void ice_remove(struct pci_dev *pdev)
3368 struct ice_pf *pf = pci_get_drvdata(pdev);
3374 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
3375 if (!ice_is_reset_in_progress(pf->state))
3380 set_bit(__ICE_DOWN, pf->state);
3381 ice_service_task_stop(pf);
3383 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
3385 ice_vsi_release_all(pf);
3386 ice_free_irq_msix_misc(pf);
3387 ice_for_each_vsi(pf, i) {
3390 ice_vsi_free_q_vectors(pf->vsi[i]);
3393 ice_deinit_hw(&pf->hw);
3394 /* Issue a PFR as part of the prescribed driver unload flow. Do not
3395 * do it via ice_schedule_reset() since there is no need to rebuild
3396 * and the service task is already stopped.
3398 ice_reset(&pf->hw, ICE_RESET_PFR);
3399 pci_wait_for_pending_transaction(pdev);
3400 ice_clear_interrupt_scheme(pf);
3401 pci_disable_pcie_error_reporting(pdev);
3405 * ice_pci_err_detected - warning that PCI error has been detected
3406 * @pdev: PCI device information struct
3407 * @err: the type of PCI error
3409 * Called to warn that something happened on the PCI bus and the error handling
3410 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
3412 static pci_ers_result_t
3413 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
3415 struct ice_pf *pf = pci_get_drvdata(pdev);
3418 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
3420 return PCI_ERS_RESULT_DISCONNECT;
3423 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3424 ice_service_task_stop(pf);
3426 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3427 set_bit(__ICE_PFR_REQ, pf->state);
3428 ice_prepare_for_reset(pf);
3432 return PCI_ERS_RESULT_NEED_RESET;
3436 * ice_pci_err_slot_reset - a PCI slot reset has just happened
3437 * @pdev: PCI device information struct
3439 * Called to determine if the driver can recover from the PCI slot reset by
3440 * using a register read to determine if the device is recoverable.
3442 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
3444 struct ice_pf *pf = pci_get_drvdata(pdev);
3445 pci_ers_result_t result;
3449 err = pci_enable_device_mem(pdev);
3451 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
3453 result = PCI_ERS_RESULT_DISCONNECT;
3455 pci_set_master(pdev);
3456 pci_restore_state(pdev);
3457 pci_save_state(pdev);
3458 pci_wake_from_d3(pdev, false);
3460 /* Check for life */
3461 reg = rd32(&pf->hw, GLGEN_RTRIG);
3463 result = PCI_ERS_RESULT_RECOVERED;
3465 result = PCI_ERS_RESULT_DISCONNECT;
3468 err = pci_cleanup_aer_uncorrect_error_status(pdev);
3470 dev_dbg(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
3472 /* non-fatal, continue */
3478 * ice_pci_err_resume - restart operations after PCI error recovery
3479 * @pdev: PCI device information struct
3481 * Called to allow the driver to bring things back up after PCI error and/or
3482 * reset recovery have finished
3484 static void ice_pci_err_resume(struct pci_dev *pdev)
3486 struct ice_pf *pf = pci_get_drvdata(pdev);
3489 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
3494 if (test_bit(__ICE_SUSPENDED, pf->state)) {
3495 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
3500 ice_do_reset(pf, ICE_RESET_PFR);
3501 ice_service_task_restart(pf);
3502 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3506 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
3507 * @pdev: PCI device information struct
3509 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
3511 struct ice_pf *pf = pci_get_drvdata(pdev);
3513 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3514 ice_service_task_stop(pf);
3516 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3517 set_bit(__ICE_PFR_REQ, pf->state);
3518 ice_prepare_for_reset(pf);
3524 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
3525 * @pdev: PCI device information struct
3527 static void ice_pci_err_reset_done(struct pci_dev *pdev)
3529 ice_pci_err_resume(pdev);
3532 /* ice_pci_tbl - PCI Device ID Table
3534 * Wildcard entries (PCI_ANY_ID) should come last
3535 * Last entry must be all 0s
3537 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3538 * Class, Class Mask, private data (not used) }
3540 static const struct pci_device_id ice_pci_tbl[] = {
3541 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
3542 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
3543 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
3544 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
3545 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
3546 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
3547 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
3548 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
3549 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822X_BACKPLANE), 0 },
3550 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
3551 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
3552 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
3553 /* required last entry */
3556 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
3558 static const struct pci_error_handlers ice_pci_err_handler = {
3559 .error_detected = ice_pci_err_detected,
3560 .slot_reset = ice_pci_err_slot_reset,
3561 .reset_prepare = ice_pci_err_reset_prepare,
3562 .reset_done = ice_pci_err_reset_done,
3563 .resume = ice_pci_err_resume
3566 static struct pci_driver ice_driver = {
3567 .name = KBUILD_MODNAME,
3568 .id_table = ice_pci_tbl,
3570 .remove = ice_remove,
3571 .sriov_configure = ice_sriov_configure,
3572 .err_handler = &ice_pci_err_handler
3576 * ice_module_init - Driver registration routine
3578 * ice_module_init is the first routine called when the driver is
3579 * loaded. All it does is register with the PCI subsystem.
3581 static int __init ice_module_init(void)
3585 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
3586 pr_info("%s\n", ice_copyright);
3588 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
3590 pr_err("Failed to create workqueue\n");
3594 status = pci_register_driver(&ice_driver);
3596 pr_err("failed to register PCI driver, err %d\n", status);
3597 destroy_workqueue(ice_wq);
3602 module_init(ice_module_init);
3605 * ice_module_exit - Driver exit cleanup routine
3607 * ice_module_exit is called just before the driver is removed
3610 static void __exit ice_module_exit(void)
3612 pci_unregister_driver(&ice_driver);
3613 destroy_workqueue(ice_wq);
3614 pr_info("module unloaded\n");
3616 module_exit(ice_module_exit);
3619 * ice_set_mac_address - NDO callback to set MAC address
3620 * @netdev: network interface device structure
3621 * @pi: pointer to an address structure
3623 * Returns 0 on success, negative on failure
3625 static int ice_set_mac_address(struct net_device *netdev, void *pi)
3627 struct ice_netdev_priv *np = netdev_priv(netdev);
3628 struct ice_vsi *vsi = np->vsi;
3629 struct ice_pf *pf = vsi->back;
3630 struct ice_hw *hw = &pf->hw;
3631 struct sockaddr *addr = pi;
3632 enum ice_status status;
3637 mac = (u8 *)addr->sa_data;
3639 if (!is_valid_ether_addr(mac))
3640 return -EADDRNOTAVAIL;
3642 if (ether_addr_equal(netdev->dev_addr, mac)) {
3643 netdev_warn(netdev, "already using mac %pM\n", mac);
3647 if (test_bit(__ICE_DOWN, pf->state) ||
3648 ice_is_reset_in_progress(pf->state)) {
3649 netdev_err(netdev, "can't set mac %pM. device not ready\n",
3654 /* When we change the MAC address we also have to change the MAC address
3655 * based filter rules that were created previously for the old MAC
3656 * address. So first, we remove the old filter rule using ice_remove_mac
3657 * and then create a new filter rule using ice_add_mac via
3658 * ice_vsi_cfg_mac_fltr function call for both add and/or remove
3661 status = ice_vsi_cfg_mac_fltr(vsi, netdev->dev_addr, false);
3663 err = -EADDRNOTAVAIL;
3664 goto err_update_filters;
3667 status = ice_vsi_cfg_mac_fltr(vsi, mac, true);
3669 err = -EADDRNOTAVAIL;
3670 goto err_update_filters;
3675 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
3680 /* change the netdev's MAC address */
3681 memcpy(netdev->dev_addr, mac, netdev->addr_len);
3682 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
3685 /* write new MAC address to the firmware */
3686 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3687 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
3689 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
3696 * ice_set_rx_mode - NDO callback to set the netdev filters
3697 * @netdev: network interface device structure
3699 static void ice_set_rx_mode(struct net_device *netdev)
3701 struct ice_netdev_priv *np = netdev_priv(netdev);
3702 struct ice_vsi *vsi = np->vsi;
3707 /* Set the flags to synchronize filters
3708 * ndo_set_rx_mode may be triggered even without a change in netdev
3711 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
3712 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
3713 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
3715 /* schedule our worker thread which will take care of
3716 * applying the new filter changes
3718 ice_service_task_schedule(vsi->back);
3722 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
3723 * @netdev: network interface device structure
3724 * @queue_index: Queue ID
3725 * @maxrate: maximum bandwidth in Mbps
3728 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
3730 struct ice_netdev_priv *np = netdev_priv(netdev);
3731 struct ice_vsi *vsi = np->vsi;
3732 enum ice_status status;
3736 /* Validate maxrate requested is within permitted range */
3737 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
3738 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
3739 maxrate, queue_index);
3743 q_handle = vsi->tx_rings[queue_index]->q_handle;
3744 tc = ice_dcb_get_tc(vsi, queue_index);
3746 /* Set BW back to default, when user set maxrate to 0 */
3748 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
3749 q_handle, ICE_MAX_BW);
3751 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
3752 q_handle, ICE_MAX_BW, maxrate * 1000);
3754 netdev_err(netdev, "Unable to set Tx max rate, error %d\n",
3763 * ice_fdb_add - add an entry to the hardware database
3764 * @ndm: the input from the stack
3765 * @tb: pointer to array of nladdr (unused)
3766 * @dev: the net device pointer
3767 * @addr: the MAC address entry being added
3769 * @flags: instructions from stack about fdb operation
3770 * @extack: netlink extended ack
3773 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
3774 struct net_device *dev, const unsigned char *addr, u16 vid,
3775 u16 flags, struct netlink_ext_ack __always_unused *extack)
3780 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3783 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
3784 netdev_err(dev, "FDB only supports static addresses\n");
3788 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
3789 err = dev_uc_add_excl(dev, addr);
3790 else if (is_multicast_ether_addr(addr))
3791 err = dev_mc_add_excl(dev, addr);
3795 /* Only return duplicate errors if NLM_F_EXCL is set */
3796 if (err == -EEXIST && !(flags & NLM_F_EXCL))
3803 * ice_fdb_del - delete an entry from the hardware database
3804 * @ndm: the input from the stack
3805 * @tb: pointer to array of nladdr (unused)
3806 * @dev: the net device pointer
3807 * @addr: the MAC address entry being added
3811 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
3812 struct net_device *dev, const unsigned char *addr,
3813 __always_unused u16 vid)
3817 if (ndm->ndm_state & NUD_PERMANENT) {
3818 netdev_err(dev, "FDB only supports static addresses\n");
3822 if (is_unicast_ether_addr(addr))
3823 err = dev_uc_del(dev, addr);
3824 else if (is_multicast_ether_addr(addr))
3825 err = dev_mc_del(dev, addr);
3833 * ice_set_features - set the netdev feature flags
3834 * @netdev: ptr to the netdev being adjusted
3835 * @features: the feature set that the stack is suggesting
3838 ice_set_features(struct net_device *netdev, netdev_features_t features)
3840 struct ice_netdev_priv *np = netdev_priv(netdev);
3841 struct ice_vsi *vsi = np->vsi;
3842 struct ice_pf *pf = vsi->back;
3845 /* Don't set any netdev advanced features with device in Safe Mode */
3846 if (ice_is_safe_mode(vsi->back)) {
3847 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
3851 /* Do not change setting during reset */
3852 if (ice_is_reset_in_progress(pf->state)) {
3853 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
3857 /* Multiple features can be changed in one call so keep features in
3858 * separate if/else statements to guarantee each feature is checked
3860 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
3861 ret = ice_vsi_manage_rss_lut(vsi, true);
3862 else if (!(features & NETIF_F_RXHASH) &&
3863 netdev->features & NETIF_F_RXHASH)
3864 ret = ice_vsi_manage_rss_lut(vsi, false);
3866 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
3867 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3868 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3869 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
3870 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3871 ret = ice_vsi_manage_vlan_stripping(vsi, false);
3873 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
3874 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3875 ret = ice_vsi_manage_vlan_insertion(vsi);
3876 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
3877 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3878 ret = ice_vsi_manage_vlan_insertion(vsi);
3880 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3881 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3882 ret = ice_cfg_vlan_pruning(vsi, true, false);
3883 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3884 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3885 ret = ice_cfg_vlan_pruning(vsi, false, false);
3891 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
3892 * @vsi: VSI to setup VLAN properties for
3894 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
3898 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3899 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3900 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
3901 ret = ice_vsi_manage_vlan_insertion(vsi);
3907 * ice_vsi_cfg - Setup the VSI
3908 * @vsi: the VSI being configured
3910 * Return 0 on success and negative value on error
3912 int ice_vsi_cfg(struct ice_vsi *vsi)
3917 ice_set_rx_mode(vsi->netdev);
3919 err = ice_vsi_vlan_setup(vsi);
3924 ice_vsi_cfg_dcb_rings(vsi);
3926 err = ice_vsi_cfg_lan_txqs(vsi);
3927 if (!err && ice_is_xdp_ena_vsi(vsi))
3928 err = ice_vsi_cfg_xdp_txqs(vsi);
3930 err = ice_vsi_cfg_rxqs(vsi);
3936 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3937 * @vsi: the VSI being configured
3939 static void ice_napi_enable_all(struct ice_vsi *vsi)
3946 ice_for_each_q_vector(vsi, q_idx) {
3947 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3949 if (q_vector->rx.ring || q_vector->tx.ring)
3950 napi_enable(&q_vector->napi);
3955 * ice_up_complete - Finish the last steps of bringing up a connection
3956 * @vsi: The VSI being configured
3958 * Return 0 on success and negative value on error
3960 static int ice_up_complete(struct ice_vsi *vsi)
3962 struct ice_pf *pf = vsi->back;
3965 ice_vsi_cfg_msix(vsi);
3967 /* Enable only Rx rings, Tx rings were enabled by the FW when the
3968 * Tx queue group list was configured and the context bits were
3969 * programmed using ice_vsi_cfg_txqs
3971 err = ice_vsi_start_all_rx_rings(vsi);
3975 clear_bit(__ICE_DOWN, vsi->state);
3976 ice_napi_enable_all(vsi);
3977 ice_vsi_ena_irq(vsi);
3979 if (vsi->port_info &&
3980 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
3982 ice_print_link_msg(vsi, true);
3983 netif_tx_start_all_queues(vsi->netdev);
3984 netif_carrier_on(vsi->netdev);
3987 ice_service_task_schedule(pf);
3993 * ice_up - Bring the connection back up after being down
3994 * @vsi: VSI being configured
3996 int ice_up(struct ice_vsi *vsi)
4000 err = ice_vsi_cfg(vsi);
4002 err = ice_up_complete(vsi);
4008 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
4009 * @ring: Tx or Rx ring to read stats from
4010 * @pkts: packets stats counter
4011 * @bytes: bytes stats counter
4013 * This function fetches stats from the ring considering the atomic operations
4014 * that needs to be performed to read u64 values in 32 bit machine.
4017 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
4026 start = u64_stats_fetch_begin_irq(&ring->syncp);
4027 *pkts = ring->stats.pkts;
4028 *bytes = ring->stats.bytes;
4029 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
4033 * ice_update_vsi_ring_stats - Update VSI stats counters
4034 * @vsi: the VSI to be updated
4036 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
4038 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
4039 struct ice_ring *ring;
4043 /* reset netdev stats */
4044 vsi_stats->tx_packets = 0;
4045 vsi_stats->tx_bytes = 0;
4046 vsi_stats->rx_packets = 0;
4047 vsi_stats->rx_bytes = 0;
4049 /* reset non-netdev (extended) stats */
4050 vsi->tx_restart = 0;
4052 vsi->tx_linearize = 0;
4053 vsi->rx_buf_failed = 0;
4054 vsi->rx_page_failed = 0;
4058 /* update Tx rings counters */
4059 ice_for_each_txq(vsi, i) {
4060 ring = READ_ONCE(vsi->tx_rings[i]);
4061 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4062 vsi_stats->tx_packets += pkts;
4063 vsi_stats->tx_bytes += bytes;
4064 vsi->tx_restart += ring->tx_stats.restart_q;
4065 vsi->tx_busy += ring->tx_stats.tx_busy;
4066 vsi->tx_linearize += ring->tx_stats.tx_linearize;
4069 /* update Rx rings counters */
4070 ice_for_each_rxq(vsi, i) {
4071 ring = READ_ONCE(vsi->rx_rings[i]);
4072 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4073 vsi_stats->rx_packets += pkts;
4074 vsi_stats->rx_bytes += bytes;
4075 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
4076 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
4083 * ice_update_vsi_stats - Update VSI stats counters
4084 * @vsi: the VSI to be updated
4086 void ice_update_vsi_stats(struct ice_vsi *vsi)
4088 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
4089 struct ice_eth_stats *cur_es = &vsi->eth_stats;
4090 struct ice_pf *pf = vsi->back;
4092 if (test_bit(__ICE_DOWN, vsi->state) ||
4093 test_bit(__ICE_CFG_BUSY, pf->state))
4096 /* get stats as recorded by Tx/Rx rings */
4097 ice_update_vsi_ring_stats(vsi);
4099 /* get VSI stats as recorded by the hardware */
4100 ice_update_eth_stats(vsi);
4102 cur_ns->tx_errors = cur_es->tx_errors;
4103 cur_ns->rx_dropped = cur_es->rx_discards;
4104 cur_ns->tx_dropped = cur_es->tx_discards;
4105 cur_ns->multicast = cur_es->rx_multicast;
4107 /* update some more netdev stats if this is main VSI */
4108 if (vsi->type == ICE_VSI_PF) {
4109 cur_ns->rx_crc_errors = pf->stats.crc_errors;
4110 cur_ns->rx_errors = pf->stats.crc_errors +
4111 pf->stats.illegal_bytes;
4112 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
4113 /* record drops from the port level */
4114 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
4119 * ice_update_pf_stats - Update PF port stats counters
4120 * @pf: PF whose stats needs to be updated
4122 void ice_update_pf_stats(struct ice_pf *pf)
4124 struct ice_hw_port_stats *prev_ps, *cur_ps;
4125 struct ice_hw *hw = &pf->hw;
4128 port = hw->port_info->lport;
4129 prev_ps = &pf->stats_prev;
4130 cur_ps = &pf->stats;
4132 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
4133 &prev_ps->eth.rx_bytes,
4134 &cur_ps->eth.rx_bytes);
4136 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
4137 &prev_ps->eth.rx_unicast,
4138 &cur_ps->eth.rx_unicast);
4140 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
4141 &prev_ps->eth.rx_multicast,
4142 &cur_ps->eth.rx_multicast);
4144 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
4145 &prev_ps->eth.rx_broadcast,
4146 &cur_ps->eth.rx_broadcast);
4148 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
4149 &prev_ps->eth.rx_discards,
4150 &cur_ps->eth.rx_discards);
4152 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
4153 &prev_ps->eth.tx_bytes,
4154 &cur_ps->eth.tx_bytes);
4156 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
4157 &prev_ps->eth.tx_unicast,
4158 &cur_ps->eth.tx_unicast);
4160 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
4161 &prev_ps->eth.tx_multicast,
4162 &cur_ps->eth.tx_multicast);
4164 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
4165 &prev_ps->eth.tx_broadcast,
4166 &cur_ps->eth.tx_broadcast);
4168 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
4169 &prev_ps->tx_dropped_link_down,
4170 &cur_ps->tx_dropped_link_down);
4172 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
4173 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
4175 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
4176 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
4178 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
4179 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
4181 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
4182 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
4184 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
4185 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
4187 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
4188 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
4190 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
4191 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
4193 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
4194 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
4196 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
4197 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
4199 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
4200 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
4202 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
4203 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
4205 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
4206 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
4208 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
4209 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
4211 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
4212 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
4214 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
4215 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
4217 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
4218 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
4220 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
4221 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
4223 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
4224 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
4226 ice_update_dcb_stats(pf);
4228 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
4229 &prev_ps->crc_errors, &cur_ps->crc_errors);
4231 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
4232 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
4234 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
4235 &prev_ps->mac_local_faults,
4236 &cur_ps->mac_local_faults);
4238 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
4239 &prev_ps->mac_remote_faults,
4240 &cur_ps->mac_remote_faults);
4242 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
4243 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
4245 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
4246 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
4248 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
4249 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
4251 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
4252 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
4254 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
4255 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
4257 pf->stat_prev_loaded = true;
4261 * ice_get_stats64 - get statistics for network device structure
4262 * @netdev: network interface device structure
4263 * @stats: main device statistics structure
4266 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
4268 struct ice_netdev_priv *np = netdev_priv(netdev);
4269 struct rtnl_link_stats64 *vsi_stats;
4270 struct ice_vsi *vsi = np->vsi;
4272 vsi_stats = &vsi->net_stats;
4274 if (!vsi->num_txq || !vsi->num_rxq)
4277 /* netdev packet/byte stats come from ring counter. These are obtained
4278 * by summing up ring counters (done by ice_update_vsi_ring_stats).
4279 * But, only call the update routine and read the registers if VSI is
4282 if (!test_bit(__ICE_DOWN, vsi->state))
4283 ice_update_vsi_ring_stats(vsi);
4284 stats->tx_packets = vsi_stats->tx_packets;
4285 stats->tx_bytes = vsi_stats->tx_bytes;
4286 stats->rx_packets = vsi_stats->rx_packets;
4287 stats->rx_bytes = vsi_stats->rx_bytes;
4289 /* The rest of the stats can be read from the hardware but instead we
4290 * just return values that the watchdog task has already obtained from
4293 stats->multicast = vsi_stats->multicast;
4294 stats->tx_errors = vsi_stats->tx_errors;
4295 stats->tx_dropped = vsi_stats->tx_dropped;
4296 stats->rx_errors = vsi_stats->rx_errors;
4297 stats->rx_dropped = vsi_stats->rx_dropped;
4298 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
4299 stats->rx_length_errors = vsi_stats->rx_length_errors;
4303 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4304 * @vsi: VSI having NAPI disabled
4306 static void ice_napi_disable_all(struct ice_vsi *vsi)
4313 ice_for_each_q_vector(vsi, q_idx) {
4314 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
4316 if (q_vector->rx.ring || q_vector->tx.ring)
4317 napi_disable(&q_vector->napi);
4322 * ice_down - Shutdown the connection
4323 * @vsi: The VSI being stopped
4325 int ice_down(struct ice_vsi *vsi)
4327 int i, tx_err, rx_err, link_err = 0;
4329 /* Caller of this function is expected to set the
4330 * vsi->state __ICE_DOWN bit
4333 netif_carrier_off(vsi->netdev);
4334 netif_tx_disable(vsi->netdev);
4337 ice_vsi_dis_irq(vsi);
4339 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
4341 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
4342 vsi->vsi_num, tx_err);
4343 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
4344 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
4346 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
4347 vsi->vsi_num, tx_err);
4350 rx_err = ice_vsi_stop_all_rx_rings(vsi);
4352 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
4353 vsi->vsi_num, rx_err);
4355 ice_napi_disable_all(vsi);
4357 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
4358 link_err = ice_force_phys_link_state(vsi, false);
4360 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
4361 vsi->vsi_num, link_err);
4364 ice_for_each_txq(vsi, i)
4365 ice_clean_tx_ring(vsi->tx_rings[i]);
4367 ice_for_each_rxq(vsi, i)
4368 ice_clean_rx_ring(vsi->rx_rings[i]);
4370 if (tx_err || rx_err || link_err) {
4371 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
4372 vsi->vsi_num, vsi->vsw->sw_id);
4380 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
4381 * @vsi: VSI having resources allocated
4383 * Return 0 on success, negative on failure
4385 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4389 if (!vsi->num_txq) {
4390 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
4395 ice_for_each_txq(vsi, i) {
4396 struct ice_ring *ring = vsi->tx_rings[i];
4401 ring->netdev = vsi->netdev;
4402 err = ice_setup_tx_ring(ring);
4411 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
4412 * @vsi: VSI having resources allocated
4414 * Return 0 on success, negative on failure
4416 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
4420 if (!vsi->num_rxq) {
4421 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
4426 ice_for_each_rxq(vsi, i) {
4427 struct ice_ring *ring = vsi->rx_rings[i];
4432 ring->netdev = vsi->netdev;
4433 err = ice_setup_rx_ring(ring);
4442 * ice_vsi_open - Called when a network interface is made active
4443 * @vsi: the VSI to open
4445 * Initialization of the VSI
4447 * Returns 0 on success, negative value on error
4449 static int ice_vsi_open(struct ice_vsi *vsi)
4451 char int_name[ICE_INT_NAME_STR_LEN];
4452 struct ice_pf *pf = vsi->back;
4455 /* allocate descriptors */
4456 err = ice_vsi_setup_tx_rings(vsi);
4460 err = ice_vsi_setup_rx_rings(vsi);
4464 err = ice_vsi_cfg(vsi);
4468 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4469 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
4470 err = ice_vsi_req_irq_msix(vsi, int_name);
4474 /* Notify the stack of the actual queue counts. */
4475 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
4479 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
4483 err = ice_up_complete(vsi);
4485 goto err_up_complete;
4492 ice_vsi_free_irq(vsi);
4494 ice_vsi_free_rx_rings(vsi);
4496 ice_vsi_free_tx_rings(vsi);
4502 * ice_vsi_release_all - Delete all VSIs
4503 * @pf: PF from which all VSIs are being removed
4505 static void ice_vsi_release_all(struct ice_pf *pf)
4512 ice_for_each_vsi(pf, i) {
4516 err = ice_vsi_release(pf->vsi[i]);
4518 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
4519 i, err, pf->vsi[i]->vsi_num);
4524 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
4525 * @pf: pointer to the PF instance
4526 * @type: VSI type to rebuild
4528 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
4530 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
4532 struct device *dev = ice_pf_to_dev(pf);
4533 enum ice_status status;
4536 ice_for_each_vsi(pf, i) {
4537 struct ice_vsi *vsi = pf->vsi[i];
4539 if (!vsi || vsi->type != type)
4542 /* rebuild the VSI */
4543 err = ice_vsi_rebuild(vsi, true);
4545 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
4546 err, vsi->idx, ice_vsi_type_str(type));
4550 /* replay filters for the VSI */
4551 status = ice_replay_vsi(&pf->hw, vsi->idx);
4553 dev_err(dev, "replay VSI failed, status %d, VSI index %d, type %s\n",
4554 status, vsi->idx, ice_vsi_type_str(type));
4558 /* Re-map HW VSI number, using VSI handle that has been
4559 * previously validated in ice_replay_vsi() call above
4561 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
4563 /* enable the VSI */
4564 err = ice_ena_vsi(vsi, false);
4566 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
4567 err, vsi->idx, ice_vsi_type_str(type));
4571 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
4572 ice_vsi_type_str(type));
4579 * ice_update_pf_netdev_link - Update PF netdev link status
4580 * @pf: pointer to the PF instance
4582 static void ice_update_pf_netdev_link(struct ice_pf *pf)
4587 ice_for_each_vsi(pf, i) {
4588 struct ice_vsi *vsi = pf->vsi[i];
4590 if (!vsi || vsi->type != ICE_VSI_PF)
4593 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
4595 netif_carrier_on(pf->vsi[i]->netdev);
4596 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
4598 netif_carrier_off(pf->vsi[i]->netdev);
4599 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
4605 * ice_rebuild - rebuild after reset
4606 * @pf: PF to rebuild
4607 * @reset_type: type of reset
4609 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
4611 struct device *dev = ice_pf_to_dev(pf);
4612 struct ice_hw *hw = &pf->hw;
4613 enum ice_status ret;
4616 if (test_bit(__ICE_DOWN, pf->state))
4617 goto clear_recovery;
4619 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
4621 ret = ice_init_all_ctrlq(hw);
4623 dev_err(dev, "control queues init failed %d\n", ret);
4624 goto err_init_ctrlq;
4627 /* if DDP was previously loaded successfully */
4628 if (!ice_is_safe_mode(pf)) {
4629 /* reload the SW DB of filter tables */
4630 if (reset_type == ICE_RESET_PFR)
4631 ice_fill_blk_tbls(hw);
4633 /* Reload DDP Package after CORER/GLOBR reset */
4634 ice_load_pkg(NULL, pf);
4637 ret = ice_clear_pf_cfg(hw);
4639 dev_err(dev, "clear PF configuration failed %d\n", ret);
4640 goto err_init_ctrlq;
4643 if (pf->first_sw->dflt_vsi_ena)
4644 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n");
4645 /* clear the default VSI configuration if it exists */
4646 pf->first_sw->dflt_vsi = NULL;
4647 pf->first_sw->dflt_vsi_ena = false;
4649 ice_clear_pxe_mode(hw);
4651 ret = ice_get_caps(hw);
4653 dev_err(dev, "ice_get_caps failed %d\n", ret);
4654 goto err_init_ctrlq;
4657 err = ice_sched_init_port(hw->port_info);
4659 goto err_sched_init_port;
4661 err = ice_update_link_info(hw->port_info);
4663 dev_err(dev, "Get link status error %d\n", err);
4665 /* start misc vector */
4666 err = ice_req_irq_msix_misc(pf);
4668 dev_err(dev, "misc vector setup failed: %d\n", err);
4669 goto err_sched_init_port;
4672 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
4673 ice_dcb_rebuild(pf);
4675 /* rebuild PF VSI */
4676 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
4678 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
4679 goto err_vsi_rebuild;
4682 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4683 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_VF);
4685 dev_err(dev, "VF VSI rebuild failed: %d\n", err);
4686 goto err_vsi_rebuild;
4690 ice_update_pf_netdev_link(pf);
4692 /* tell the firmware we are up */
4693 ret = ice_send_version(pf);
4695 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n",
4697 goto err_vsi_rebuild;
4700 ice_replay_post(hw);
4702 /* if we get here, reset flow is successful */
4703 clear_bit(__ICE_RESET_FAILED, pf->state);
4707 err_sched_init_port:
4708 ice_sched_cleanup_all(hw);
4710 ice_shutdown_all_ctrlq(hw);
4711 set_bit(__ICE_RESET_FAILED, pf->state);
4713 /* set this bit in PF state to control service task scheduling */
4714 set_bit(__ICE_NEEDS_RESTART, pf->state);
4715 dev_err(dev, "Rebuild failed, unload and reload driver\n");
4719 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
4720 * @vsi: Pointer to VSI structure
4722 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
4724 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
4725 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
4727 return ICE_RXBUF_3072;
4731 * ice_change_mtu - NDO callback to change the MTU
4732 * @netdev: network interface device structure
4733 * @new_mtu: new value for maximum frame size
4735 * Returns 0 on success, negative on failure
4737 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
4739 struct ice_netdev_priv *np = netdev_priv(netdev);
4740 struct ice_vsi *vsi = np->vsi;
4741 struct ice_pf *pf = vsi->back;
4744 if (new_mtu == netdev->mtu) {
4745 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
4749 if (ice_is_xdp_ena_vsi(vsi)) {
4750 int frame_size = ice_max_xdp_frame_size(vsi);
4752 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
4753 netdev_err(netdev, "max MTU for XDP usage is %d\n",
4754 frame_size - ICE_ETH_PKT_HDR_PAD);
4759 if (new_mtu < netdev->min_mtu) {
4760 netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
4763 } else if (new_mtu > netdev->max_mtu) {
4764 netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
4768 /* if a reset is in progress, wait for some time for it to complete */
4770 if (ice_is_reset_in_progress(pf->state)) {
4772 usleep_range(1000, 2000);
4777 } while (count < 100);
4780 netdev_err(netdev, "can't change MTU. Device is busy\n");
4784 netdev->mtu = new_mtu;
4786 /* if VSI is up, bring it down and then back up */
4787 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
4790 err = ice_down(vsi);
4792 netdev_err(netdev, "change MTU if_up err %d\n", err);
4798 netdev_err(netdev, "change MTU if_up err %d\n", err);
4803 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
4808 * ice_set_rss - Set RSS keys and lut
4809 * @vsi: Pointer to VSI structure
4810 * @seed: RSS hash seed
4811 * @lut: Lookup table
4812 * @lut_size: Lookup table size
4814 * Returns 0 on success, negative on failure
4816 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4818 struct ice_pf *pf = vsi->back;
4819 struct ice_hw *hw = &pf->hw;
4820 enum ice_status status;
4823 dev = ice_pf_to_dev(pf);
4825 struct ice_aqc_get_set_rss_keys *buf =
4826 (struct ice_aqc_get_set_rss_keys *)seed;
4828 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
4831 dev_err(dev, "Cannot set RSS key, err %d aq_err %d\n",
4832 status, hw->adminq.rq_last_status);
4838 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4841 dev_err(dev, "Cannot set RSS lut, err %d aq_err %d\n",
4842 status, hw->adminq.rq_last_status);
4851 * ice_get_rss - Get RSS keys and lut
4852 * @vsi: Pointer to VSI structure
4853 * @seed: Buffer to store the keys
4854 * @lut: Buffer to store the lookup table entries
4855 * @lut_size: Size of buffer to store the lookup table entries
4857 * Returns 0 on success, negative on failure
4859 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4861 struct ice_pf *pf = vsi->back;
4862 struct ice_hw *hw = &pf->hw;
4863 enum ice_status status;
4866 dev = ice_pf_to_dev(pf);
4868 struct ice_aqc_get_set_rss_keys *buf =
4869 (struct ice_aqc_get_set_rss_keys *)seed;
4871 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4873 dev_err(dev, "Cannot get RSS key, err %d aq_err %d\n",
4874 status, hw->adminq.rq_last_status);
4880 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4883 dev_err(dev, "Cannot get RSS lut, err %d aq_err %d\n",
4884 status, hw->adminq.rq_last_status);
4893 * ice_bridge_getlink - Get the hardware bridge mode
4896 * @seq: RTNL message seq
4897 * @dev: the netdev being configured
4898 * @filter_mask: filter mask passed in
4899 * @nlflags: netlink flags passed in
4901 * Return the bridge mode (VEB/VEPA)
4904 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4905 struct net_device *dev, u32 filter_mask, int nlflags)
4907 struct ice_netdev_priv *np = netdev_priv(dev);
4908 struct ice_vsi *vsi = np->vsi;
4909 struct ice_pf *pf = vsi->back;
4912 bmode = pf->first_sw->bridge_mode;
4914 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4919 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4920 * @vsi: Pointer to VSI structure
4921 * @bmode: Hardware bridge mode (VEB/VEPA)
4923 * Returns 0 on success, negative on failure
4925 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4927 struct ice_aqc_vsi_props *vsi_props;
4928 struct ice_hw *hw = &vsi->back->hw;
4929 struct ice_vsi_ctx *ctxt;
4930 enum ice_status status;
4933 vsi_props = &vsi->info;
4935 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4939 ctxt->info = vsi->info;
4941 if (bmode == BRIDGE_MODE_VEB)
4942 /* change from VEPA to VEB mode */
4943 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4945 /* change from VEB to VEPA mode */
4946 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4947 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4949 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4951 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4952 bmode, status, hw->adminq.sq_last_status);
4956 /* Update sw flags for book keeping */
4957 vsi_props->sw_flags = ctxt->info.sw_flags;
4965 * ice_bridge_setlink - Set the hardware bridge mode
4966 * @dev: the netdev being configured
4967 * @nlh: RTNL message
4968 * @flags: bridge setlink flags
4969 * @extack: netlink extended ack
4971 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4972 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4973 * not already set for all VSIs connected to this switch. And also update the
4974 * unicast switch filter rules for the corresponding switch of the netdev.
4977 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4978 u16 __always_unused flags,
4979 struct netlink_ext_ack __always_unused *extack)
4981 struct ice_netdev_priv *np = netdev_priv(dev);
4982 struct ice_pf *pf = np->vsi->back;
4983 struct nlattr *attr, *br_spec;
4984 struct ice_hw *hw = &pf->hw;
4985 enum ice_status status;
4986 struct ice_sw *pf_sw;
4987 int rem, v, err = 0;
4989 pf_sw = pf->first_sw;
4990 /* find the attribute in the netlink message */
4991 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4993 nla_for_each_nested(attr, br_spec, rem) {
4996 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4998 mode = nla_get_u16(attr);
4999 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
5001 /* Continue if bridge mode is not being flipped */
5002 if (mode == pf_sw->bridge_mode)
5004 /* Iterates through the PF VSI list and update the loopback
5007 ice_for_each_vsi(pf, v) {
5010 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
5015 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
5016 /* Update the unicast switch filter rules for the corresponding
5017 * switch of the netdev
5019 status = ice_update_sw_rule_bridge_mode(hw);
5021 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
5022 mode, status, hw->adminq.sq_last_status);
5023 /* revert hw->evb_veb */
5024 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
5028 pf_sw->bridge_mode = mode;
5035 * ice_tx_timeout - Respond to a Tx Hang
5036 * @netdev: network interface device structure
5038 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
5040 struct ice_netdev_priv *np = netdev_priv(netdev);
5041 struct ice_ring *tx_ring = NULL;
5042 struct ice_vsi *vsi = np->vsi;
5043 struct ice_pf *pf = vsi->back;
5046 pf->tx_timeout_count++;
5048 /* now that we have an index, find the tx_ring struct */
5049 for (i = 0; i < vsi->num_txq; i++)
5050 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
5051 if (txqueue == vsi->tx_rings[i]->q_index) {
5052 tx_ring = vsi->tx_rings[i];
5056 /* Reset recovery level if enough time has elapsed after last timeout.
5057 * Also ensure no new reset action happens before next timeout period.
5059 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
5060 pf->tx_timeout_recovery_level = 1;
5061 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
5062 netdev->watchdog_timeo)))
5066 struct ice_hw *hw = &pf->hw;
5069 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
5070 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
5071 /* Read interrupt register */
5072 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
5074 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
5075 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
5076 head, tx_ring->next_to_use, val);
5079 pf->tx_timeout_last_recovery = jiffies;
5080 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %d\n",
5081 pf->tx_timeout_recovery_level, txqueue);
5083 switch (pf->tx_timeout_recovery_level) {
5085 set_bit(__ICE_PFR_REQ, pf->state);
5088 set_bit(__ICE_CORER_REQ, pf->state);
5091 set_bit(__ICE_GLOBR_REQ, pf->state);
5094 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
5095 set_bit(__ICE_DOWN, pf->state);
5096 set_bit(__ICE_NEEDS_RESTART, vsi->state);
5097 set_bit(__ICE_SERVICE_DIS, pf->state);
5101 ice_service_task_schedule(pf);
5102 pf->tx_timeout_recovery_level++;
5106 * ice_open - Called when a network interface becomes active
5107 * @netdev: network interface device structure
5109 * The open entry point is called when a network interface is made
5110 * active by the system (IFF_UP). At this point all resources needed
5111 * for transmit and receive operations are allocated, the interrupt
5112 * handler is registered with the OS, the netdev watchdog is enabled,
5113 * and the stack is notified that the interface is ready.
5115 * Returns 0 on success, negative value on failure
5117 int ice_open(struct net_device *netdev)
5119 struct ice_netdev_priv *np = netdev_priv(netdev);
5120 struct ice_vsi *vsi = np->vsi;
5121 struct ice_port_info *pi;
5124 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
5125 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
5129 netif_carrier_off(netdev);
5131 pi = vsi->port_info;
5132 err = ice_update_link_info(pi);
5134 netdev_err(netdev, "Failed to get link info, error %d\n",
5139 /* Set PHY if there is media, otherwise, turn off PHY */
5140 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
5141 err = ice_force_phys_link_state(vsi, true);
5143 netdev_err(netdev, "Failed to set physical link up, error %d\n",
5148 err = ice_aq_set_link_restart_an(pi, false, NULL);
5150 netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n",
5154 set_bit(ICE_FLAG_NO_MEDIA, vsi->back->flags);
5157 err = ice_vsi_open(vsi);
5159 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
5160 vsi->vsi_num, vsi->vsw->sw_id);
5165 * ice_stop - Disables a network interface
5166 * @netdev: network interface device structure
5168 * The stop entry point is called when an interface is de-activated by the OS,
5169 * and the netdevice enters the DOWN state. The hardware is still under the
5170 * driver's control, but the netdev interface is disabled.
5172 * Returns success only - not allowed to fail
5174 int ice_stop(struct net_device *netdev)
5176 struct ice_netdev_priv *np = netdev_priv(netdev);
5177 struct ice_vsi *vsi = np->vsi;
5185 * ice_features_check - Validate encapsulated packet conforms to limits
5187 * @netdev: This port's netdev
5188 * @features: Offload features that the stack believes apply
5190 static netdev_features_t
5191 ice_features_check(struct sk_buff *skb,
5192 struct net_device __always_unused *netdev,
5193 netdev_features_t features)
5197 /* No point in doing any of this if neither checksum nor GSO are
5198 * being requested for this frame. We can rule out both by just
5199 * checking for CHECKSUM_PARTIAL
5201 if (skb->ip_summed != CHECKSUM_PARTIAL)
5204 /* We cannot support GSO if the MSS is going to be less than
5205 * 64 bytes. If it is then we need to drop support for GSO.
5207 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
5208 features &= ~NETIF_F_GSO_MASK;
5210 len = skb_network_header(skb) - skb->data;
5211 if (len & ~(ICE_TXD_MACLEN_MAX))
5212 goto out_rm_features;
5214 len = skb_transport_header(skb) - skb_network_header(skb);
5215 if (len & ~(ICE_TXD_IPLEN_MAX))
5216 goto out_rm_features;
5218 if (skb->encapsulation) {
5219 len = skb_inner_network_header(skb) - skb_transport_header(skb);
5220 if (len & ~(ICE_TXD_L4LEN_MAX))
5221 goto out_rm_features;
5223 len = skb_inner_transport_header(skb) -
5224 skb_inner_network_header(skb);
5225 if (len & ~(ICE_TXD_IPLEN_MAX))
5226 goto out_rm_features;
5231 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
5234 static const struct net_device_ops ice_netdev_safe_mode_ops = {
5235 .ndo_open = ice_open,
5236 .ndo_stop = ice_stop,
5237 .ndo_start_xmit = ice_start_xmit,
5238 .ndo_set_mac_address = ice_set_mac_address,
5239 .ndo_validate_addr = eth_validate_addr,
5240 .ndo_change_mtu = ice_change_mtu,
5241 .ndo_get_stats64 = ice_get_stats64,
5242 .ndo_tx_timeout = ice_tx_timeout,
5245 static const struct net_device_ops ice_netdev_ops = {
5246 .ndo_open = ice_open,
5247 .ndo_stop = ice_stop,
5248 .ndo_start_xmit = ice_start_xmit,
5249 .ndo_features_check = ice_features_check,
5250 .ndo_set_rx_mode = ice_set_rx_mode,
5251 .ndo_set_mac_address = ice_set_mac_address,
5252 .ndo_validate_addr = eth_validate_addr,
5253 .ndo_change_mtu = ice_change_mtu,
5254 .ndo_get_stats64 = ice_get_stats64,
5255 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
5256 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
5257 .ndo_set_vf_mac = ice_set_vf_mac,
5258 .ndo_get_vf_config = ice_get_vf_cfg,
5259 .ndo_set_vf_trust = ice_set_vf_trust,
5260 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
5261 .ndo_set_vf_link_state = ice_set_vf_link_state,
5262 .ndo_get_vf_stats = ice_get_vf_stats,
5263 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
5264 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
5265 .ndo_set_features = ice_set_features,
5266 .ndo_bridge_getlink = ice_bridge_getlink,
5267 .ndo_bridge_setlink = ice_bridge_setlink,
5268 .ndo_fdb_add = ice_fdb_add,
5269 .ndo_fdb_del = ice_fdb_del,
5270 .ndo_tx_timeout = ice_tx_timeout,
5272 .ndo_xdp_xmit = ice_xdp_xmit,
5273 .ndo_xsk_wakeup = ice_xsk_wakeup,