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
12 #include "ice_dcb_lib.h"
13 #include "ice_dcb_nl.h"
14 #include "ice_devlink.h"
16 #define DRV_VERSION_MAJOR 0
17 #define DRV_VERSION_MINOR 8
18 #define DRV_VERSION_BUILD 2
20 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
21 __stringify(DRV_VERSION_MINOR) "." \
22 __stringify(DRV_VERSION_BUILD) "-k"
23 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
24 const char ice_drv_ver[] = DRV_VERSION;
25 static const char ice_driver_string[] = DRV_SUMMARY;
26 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
28 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
29 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
30 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
32 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
33 MODULE_DESCRIPTION(DRV_SUMMARY);
34 MODULE_LICENSE("GPL v2");
35 MODULE_VERSION(DRV_VERSION);
36 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
38 static int debug = -1;
39 module_param(debug, int, 0644);
40 #ifndef CONFIG_DYNAMIC_DEBUG
41 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
43 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
44 #endif /* !CONFIG_DYNAMIC_DEBUG */
46 static struct workqueue_struct *ice_wq;
47 static const struct net_device_ops ice_netdev_safe_mode_ops;
48 static const struct net_device_ops ice_netdev_ops;
49 static int ice_vsi_open(struct ice_vsi *vsi);
51 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
53 static void ice_vsi_release_all(struct ice_pf *pf);
56 * ice_get_tx_pending - returns number of Tx descriptors not processed
57 * @ring: the ring of descriptors
59 static u16 ice_get_tx_pending(struct ice_ring *ring)
63 head = ring->next_to_clean;
64 tail = ring->next_to_use;
67 return (head < tail) ?
68 tail - head : (tail + ring->count - head);
73 * ice_check_for_hang_subtask - check for and recover hung queues
74 * @pf: pointer to PF struct
76 static void ice_check_for_hang_subtask(struct ice_pf *pf)
78 struct ice_vsi *vsi = NULL;
84 ice_for_each_vsi(pf, v)
85 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
90 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
93 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
98 for (i = 0; i < vsi->num_txq; i++) {
99 struct ice_ring *tx_ring = vsi->tx_rings[i];
101 if (tx_ring && tx_ring->desc) {
102 /* If packet counter has not changed the queue is
103 * likely stalled, so force an interrupt for this
106 * prev_pkt would be negative if there was no
109 packets = tx_ring->stats.pkts & INT_MAX;
110 if (tx_ring->tx_stats.prev_pkt == packets) {
111 /* Trigger sw interrupt to revive the queue */
112 ice_trigger_sw_intr(hw, tx_ring->q_vector);
116 /* Memory barrier between read of packet count and call
117 * to ice_get_tx_pending()
120 tx_ring->tx_stats.prev_pkt =
121 ice_get_tx_pending(tx_ring) ? packets : -1;
127 * ice_init_mac_fltr - Set initial MAC filters
128 * @pf: board private structure
130 * Set initial set of MAC filters for PF VSI; configure filters for permanent
131 * address and broadcast address. If an error is encountered, netdevice will be
134 static int ice_init_mac_fltr(struct ice_pf *pf)
136 enum ice_status status;
140 vsi = ice_get_main_vsi(pf);
144 perm_addr = vsi->port_info->mac.perm_addr;
145 status = ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
149 /* We aren't useful with no MAC filters, so unregister if we
152 if (vsi->netdev->reg_state == NETREG_REGISTERED) {
153 dev_err(ice_pf_to_dev(pf), "Could not add MAC filters error %s. Unregistering device\n",
154 ice_stat_str(status));
155 unregister_netdev(vsi->netdev);
156 free_netdev(vsi->netdev);
164 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
165 * @netdev: the net device on which the sync is happening
166 * @addr: MAC address to sync
168 * This is a callback function which is called by the in kernel device sync
169 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
170 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
171 * MAC filters from the hardware.
173 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
175 struct ice_netdev_priv *np = netdev_priv(netdev);
176 struct ice_vsi *vsi = np->vsi;
178 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
186 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
187 * @netdev: the net device on which the unsync is happening
188 * @addr: MAC address to unsync
190 * This is a callback function which is called by the in kernel device unsync
191 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
192 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
193 * delete the MAC filters from the hardware.
195 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
197 struct ice_netdev_priv *np = netdev_priv(netdev);
198 struct ice_vsi *vsi = np->vsi;
200 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
208 * ice_vsi_fltr_changed - check if filter state changed
209 * @vsi: VSI to be checked
211 * returns true if filter state has changed, false otherwise.
213 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
215 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
216 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
217 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
221 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
222 * @vsi: the VSI being configured
223 * @promisc_m: mask of promiscuous config bits
224 * @set_promisc: enable or disable promisc flag request
227 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
229 struct ice_hw *hw = &vsi->back->hw;
230 enum ice_status status = 0;
232 if (vsi->type != ICE_VSI_PF)
236 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
240 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
243 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
254 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
255 * @vsi: ptr to the VSI
257 * Push any outstanding VSI filter changes through the AdminQ.
259 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
261 struct device *dev = ice_pf_to_dev(vsi->back);
262 struct net_device *netdev = vsi->netdev;
263 bool promisc_forced_on = false;
264 struct ice_pf *pf = vsi->back;
265 struct ice_hw *hw = &pf->hw;
266 enum ice_status status = 0;
267 u32 changed_flags = 0;
274 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
275 usleep_range(1000, 2000);
277 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
278 vsi->current_netdev_flags = vsi->netdev->flags;
280 INIT_LIST_HEAD(&vsi->tmp_sync_list);
281 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
283 if (ice_vsi_fltr_changed(vsi)) {
284 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
285 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
286 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
288 /* grab the netdev's addr_list_lock */
289 netif_addr_lock_bh(netdev);
290 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
291 ice_add_mac_to_unsync_list);
292 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
293 ice_add_mac_to_unsync_list);
294 /* our temp lists are populated. release lock */
295 netif_addr_unlock_bh(netdev);
298 /* Remove MAC addresses in the unsync list */
299 status = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
300 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
302 netdev_err(netdev, "Failed to delete MAC filters\n");
303 /* if we failed because of alloc failures, just bail */
304 if (status == ICE_ERR_NO_MEMORY) {
310 /* Add MAC addresses in the sync list */
311 status = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
312 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
313 /* If filter is added successfully or already exists, do not go into
314 * 'if' condition and report it as error. Instead continue processing
315 * rest of the function.
317 if (status && status != ICE_ERR_ALREADY_EXISTS) {
318 netdev_err(netdev, "Failed to add MAC filters\n");
319 /* If there is no more space for new umac filters, VSI
320 * should go into promiscuous mode. There should be some
321 * space reserved for promiscuous filters.
323 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
324 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
326 promisc_forced_on = true;
327 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
334 /* check for changes in promiscuous modes */
335 if (changed_flags & IFF_ALLMULTI) {
336 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
338 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
340 promisc_m = ICE_MCAST_PROMISC_BITS;
342 err = ice_cfg_promisc(vsi, promisc_m, true);
344 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
346 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
350 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
352 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
354 promisc_m = ICE_MCAST_PROMISC_BITS;
356 err = ice_cfg_promisc(vsi, promisc_m, false);
358 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
360 vsi->current_netdev_flags |= IFF_ALLMULTI;
366 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
367 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
368 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
369 if (vsi->current_netdev_flags & IFF_PROMISC) {
370 /* Apply Rx filter rule to get traffic from wire */
371 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) {
372 err = ice_set_dflt_vsi(pf->first_sw, vsi);
373 if (err && err != -EEXIST) {
374 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
376 vsi->current_netdev_flags &=
382 /* Clear Rx filter to remove traffic from wire */
383 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) {
384 err = ice_clear_dflt_vsi(pf->first_sw);
386 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
388 vsi->current_netdev_flags |=
398 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
401 /* if something went wrong then set the changed flag so we try again */
402 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
403 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
405 clear_bit(__ICE_CFG_BUSY, vsi->state);
410 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
411 * @pf: board private structure
413 static void ice_sync_fltr_subtask(struct ice_pf *pf)
417 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
420 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
422 ice_for_each_vsi(pf, v)
423 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
424 ice_vsi_sync_fltr(pf->vsi[v])) {
425 /* come back and try again later */
426 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
432 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
434 * @locked: is the rtnl_lock already held
436 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
440 ice_for_each_vsi(pf, v)
442 ice_dis_vsi(pf->vsi[v], locked);
446 * ice_prepare_for_reset - prep for the core to reset
447 * @pf: board private structure
449 * Inform or close all dependent features in prep for reset.
452 ice_prepare_for_reset(struct ice_pf *pf)
454 struct ice_hw *hw = &pf->hw;
457 /* already prepared for reset */
458 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
461 /* Notify VFs of impending reset */
462 if (ice_check_sq_alive(hw, &hw->mailboxq))
463 ice_vc_notify_reset(pf);
465 /* Disable VFs until reset is completed */
466 ice_for_each_vf(pf, i)
467 ice_set_vf_state_qs_dis(&pf->vf[i]);
469 /* clear SW filtering DB */
470 ice_clear_hw_tbls(hw);
471 /* disable the VSIs and their queues that are not already DOWN */
472 ice_pf_dis_all_vsi(pf, false);
475 ice_sched_clear_port(hw->port_info);
477 ice_shutdown_all_ctrlq(hw);
479 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
483 * ice_do_reset - Initiate one of many types of resets
484 * @pf: board private structure
485 * @reset_type: reset type requested
486 * before this function was called.
488 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
490 struct device *dev = ice_pf_to_dev(pf);
491 struct ice_hw *hw = &pf->hw;
493 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
494 WARN_ON(in_interrupt());
496 ice_prepare_for_reset(pf);
498 /* trigger the reset */
499 if (ice_reset(hw, reset_type)) {
500 dev_err(dev, "reset %d failed\n", reset_type);
501 set_bit(__ICE_RESET_FAILED, pf->state);
502 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
503 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
504 clear_bit(__ICE_PFR_REQ, pf->state);
505 clear_bit(__ICE_CORER_REQ, pf->state);
506 clear_bit(__ICE_GLOBR_REQ, pf->state);
510 /* PFR is a bit of a special case because it doesn't result in an OICR
511 * interrupt. So for PFR, rebuild after the reset and clear the reset-
512 * associated state bits.
514 if (reset_type == ICE_RESET_PFR) {
516 ice_rebuild(pf, reset_type);
517 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
518 clear_bit(__ICE_PFR_REQ, pf->state);
519 ice_reset_all_vfs(pf, true);
524 * ice_reset_subtask - Set up for resetting the device and driver
525 * @pf: board private structure
527 static void ice_reset_subtask(struct ice_pf *pf)
529 enum ice_reset_req reset_type = ICE_RESET_INVAL;
531 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
532 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
533 * of reset is pending and sets bits in pf->state indicating the reset
534 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
535 * prepare for pending reset if not already (for PF software-initiated
536 * global resets the software should already be prepared for it as
537 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
538 * by firmware or software on other PFs, that bit is not set so prepare
539 * for the reset now), poll for reset done, rebuild and return.
541 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
542 /* Perform the largest reset requested */
543 if (test_and_clear_bit(__ICE_CORER_RECV, pf->state))
544 reset_type = ICE_RESET_CORER;
545 if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state))
546 reset_type = ICE_RESET_GLOBR;
547 if (test_and_clear_bit(__ICE_EMPR_RECV, pf->state))
548 reset_type = ICE_RESET_EMPR;
549 /* return if no valid reset type requested */
550 if (reset_type == ICE_RESET_INVAL)
552 ice_prepare_for_reset(pf);
554 /* make sure we are ready to rebuild */
555 if (ice_check_reset(&pf->hw)) {
556 set_bit(__ICE_RESET_FAILED, pf->state);
558 /* done with reset. start rebuild */
559 pf->hw.reset_ongoing = false;
560 ice_rebuild(pf, reset_type);
561 /* clear bit to resume normal operations, but
562 * ICE_NEEDS_RESTART bit is set in case rebuild failed
564 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
565 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
566 clear_bit(__ICE_PFR_REQ, pf->state);
567 clear_bit(__ICE_CORER_REQ, pf->state);
568 clear_bit(__ICE_GLOBR_REQ, pf->state);
569 ice_reset_all_vfs(pf, true);
575 /* No pending resets to finish processing. Check for new resets */
576 if (test_bit(__ICE_PFR_REQ, pf->state))
577 reset_type = ICE_RESET_PFR;
578 if (test_bit(__ICE_CORER_REQ, pf->state))
579 reset_type = ICE_RESET_CORER;
580 if (test_bit(__ICE_GLOBR_REQ, pf->state))
581 reset_type = ICE_RESET_GLOBR;
582 /* If no valid reset type requested just return */
583 if (reset_type == ICE_RESET_INVAL)
586 /* reset if not already down or busy */
587 if (!test_bit(__ICE_DOWN, pf->state) &&
588 !test_bit(__ICE_CFG_BUSY, pf->state)) {
589 ice_do_reset(pf, reset_type);
594 * ice_print_topo_conflict - print topology conflict message
595 * @vsi: the VSI whose topology status is being checked
597 static void ice_print_topo_conflict(struct ice_vsi *vsi)
599 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
600 case ICE_AQ_LINK_TOPO_CONFLICT:
601 case ICE_AQ_LINK_MEDIA_CONFLICT:
602 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
603 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
604 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
605 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");
607 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
608 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");
616 * ice_print_link_msg - print link up or down message
617 * @vsi: the VSI whose link status is being queried
618 * @isup: boolean for if the link is now up or down
620 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
622 struct ice_aqc_get_phy_caps_data *caps;
623 enum ice_status status;
633 if (vsi->current_isup == isup)
636 vsi->current_isup = isup;
639 netdev_info(vsi->netdev, "NIC Link is Down\n");
643 switch (vsi->port_info->phy.link_info.link_speed) {
644 case ICE_AQ_LINK_SPEED_100GB:
647 case ICE_AQ_LINK_SPEED_50GB:
650 case ICE_AQ_LINK_SPEED_40GB:
653 case ICE_AQ_LINK_SPEED_25GB:
656 case ICE_AQ_LINK_SPEED_20GB:
659 case ICE_AQ_LINK_SPEED_10GB:
662 case ICE_AQ_LINK_SPEED_5GB:
665 case ICE_AQ_LINK_SPEED_2500MB:
668 case ICE_AQ_LINK_SPEED_1000MB:
671 case ICE_AQ_LINK_SPEED_100MB:
679 switch (vsi->port_info->fc.current_mode) {
683 case ICE_FC_TX_PAUSE:
686 case ICE_FC_RX_PAUSE:
697 /* Get FEC mode based on negotiated link info */
698 switch (vsi->port_info->phy.link_info.fec_info) {
699 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
700 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
703 case ICE_AQ_LINK_25G_KR_FEC_EN:
704 fec = "FC-FEC/BASE-R";
711 /* check if autoneg completed, might be false due to not supported */
712 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
717 /* Get FEC mode requested based on PHY caps last SW configuration */
718 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
724 status = ice_aq_get_phy_caps(vsi->port_info, false,
725 ICE_AQC_REPORT_SW_CFG, caps, NULL);
727 netdev_info(vsi->netdev, "Get phy capability failed.\n");
729 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
730 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
732 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
733 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
734 fec_req = "FC-FEC/BASE-R";
741 netdev_info(vsi->netdev, "NIC Link is up %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
742 speed, fec_req, fec, an, fc);
743 ice_print_topo_conflict(vsi);
747 * ice_vsi_link_event - update the VSI's netdev
748 * @vsi: the VSI on which the link event occurred
749 * @link_up: whether or not the VSI needs to be set up or down
751 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
756 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
759 if (vsi->type == ICE_VSI_PF) {
760 if (link_up == netif_carrier_ok(vsi->netdev))
764 netif_carrier_on(vsi->netdev);
765 netif_tx_wake_all_queues(vsi->netdev);
767 netif_carrier_off(vsi->netdev);
768 netif_tx_stop_all_queues(vsi->netdev);
774 * ice_link_event - process the link event
775 * @pf: PF that the link event is associated with
776 * @pi: port_info for the port that the link event is associated with
777 * @link_up: true if the physical link is up and false if it is down
778 * @link_speed: current link speed received from the link event
780 * Returns 0 on success and negative on failure
783 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
786 struct device *dev = ice_pf_to_dev(pf);
787 struct ice_phy_info *phy_info;
794 phy_info->link_info_old = phy_info->link_info;
796 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
797 old_link_speed = phy_info->link_info_old.link_speed;
799 /* update the link info structures and re-enable link events,
800 * don't bail on failure due to other book keeping needed
802 result = ice_update_link_info(pi);
804 dev_dbg(dev, "Failed to update link status and re-enable link events for port %d\n",
807 /* if the old link up/down and speed is the same as the new */
808 if (link_up == old_link && link_speed == old_link_speed)
811 vsi = ice_get_main_vsi(pf);
812 if (!vsi || !vsi->port_info)
815 /* turn off PHY if media was removed */
816 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
817 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
818 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
820 result = ice_aq_set_link_restart_an(pi, false, NULL);
822 dev_dbg(dev, "Failed to set link down, VSI %d error %d\n",
823 vsi->vsi_num, result);
829 ice_vsi_link_event(vsi, link_up);
830 ice_print_link_msg(vsi, link_up);
832 ice_vc_notify_link_state(pf);
838 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
839 * @pf: board private structure
841 static void ice_watchdog_subtask(struct ice_pf *pf)
845 /* if interface is down do nothing */
846 if (test_bit(__ICE_DOWN, pf->state) ||
847 test_bit(__ICE_CFG_BUSY, pf->state))
850 /* make sure we don't do these things too often */
851 if (time_before(jiffies,
852 pf->serv_tmr_prev + pf->serv_tmr_period))
855 pf->serv_tmr_prev = jiffies;
857 /* Update the stats for active netdevs so the network stack
858 * can look at updated numbers whenever it cares to
860 ice_update_pf_stats(pf);
861 ice_for_each_vsi(pf, i)
862 if (pf->vsi[i] && pf->vsi[i]->netdev)
863 ice_update_vsi_stats(pf->vsi[i]);
867 * ice_init_link_events - enable/initialize link events
868 * @pi: pointer to the port_info instance
870 * Returns -EIO on failure, 0 on success
872 static int ice_init_link_events(struct ice_port_info *pi)
876 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
877 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
879 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
880 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
885 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
886 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
895 * ice_handle_link_event - handle link event via ARQ
896 * @pf: PF that the link event is associated with
897 * @event: event structure containing link status info
900 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
902 struct ice_aqc_get_link_status_data *link_data;
903 struct ice_port_info *port_info;
906 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
907 port_info = pf->hw.port_info;
911 status = ice_link_event(pf, port_info,
912 !!(link_data->link_info & ICE_AQ_LINK_UP),
913 le16_to_cpu(link_data->link_speed));
915 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
922 * __ice_clean_ctrlq - helper function to clean controlq rings
923 * @pf: ptr to struct ice_pf
924 * @q_type: specific Control queue type
926 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
928 struct device *dev = ice_pf_to_dev(pf);
929 struct ice_rq_event_info event;
930 struct ice_hw *hw = &pf->hw;
931 struct ice_ctl_q_info *cq;
936 /* Do not clean control queue if/when PF reset fails */
937 if (test_bit(__ICE_RESET_FAILED, pf->state))
941 case ICE_CTL_Q_ADMIN:
945 case ICE_CTL_Q_MAILBOX:
950 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
954 /* check for error indications - PF_xx_AxQLEN register layout for
955 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
957 val = rd32(hw, cq->rq.len);
958 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
959 PF_FW_ARQLEN_ARQCRIT_M)) {
961 if (val & PF_FW_ARQLEN_ARQVFE_M)
962 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
964 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
965 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
968 if (val & PF_FW_ARQLEN_ARQCRIT_M)
969 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
971 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
972 PF_FW_ARQLEN_ARQCRIT_M);
974 wr32(hw, cq->rq.len, val);
977 val = rd32(hw, cq->sq.len);
978 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
979 PF_FW_ATQLEN_ATQCRIT_M)) {
981 if (val & PF_FW_ATQLEN_ATQVFE_M)
982 dev_dbg(dev, "%s Send Queue VF Error detected\n",
984 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
985 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
988 if (val & PF_FW_ATQLEN_ATQCRIT_M)
989 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
991 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
992 PF_FW_ATQLEN_ATQCRIT_M);
994 wr32(hw, cq->sq.len, val);
997 event.buf_len = cq->rq_buf_size;
998 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1003 enum ice_status ret;
1006 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1007 if (ret == ICE_ERR_AQ_NO_WORK)
1010 dev_err(dev, "%s Receive Queue event error %s\n", qtype,
1015 opcode = le16_to_cpu(event.desc.opcode);
1018 case ice_aqc_opc_get_link_status:
1019 if (ice_handle_link_event(pf, &event))
1020 dev_err(dev, "Could not handle link event\n");
1022 case ice_aqc_opc_event_lan_overflow:
1023 ice_vf_lan_overflow_event(pf, &event);
1025 case ice_mbx_opc_send_msg_to_pf:
1026 ice_vc_process_vf_msg(pf, &event);
1028 case ice_aqc_opc_fw_logging:
1029 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1031 case ice_aqc_opc_lldp_set_mib_change:
1032 ice_dcb_process_lldp_set_mib_change(pf, &event);
1035 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1039 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1041 kfree(event.msg_buf);
1043 return pending && (i == ICE_DFLT_IRQ_WORK);
1047 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1048 * @hw: pointer to hardware info
1049 * @cq: control queue information
1051 * returns true if there are pending messages in a queue, false if there aren't
1053 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1057 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1058 return cq->rq.next_to_clean != ntu;
1062 * ice_clean_adminq_subtask - clean the AdminQ rings
1063 * @pf: board private structure
1065 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1067 struct ice_hw *hw = &pf->hw;
1069 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1072 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1075 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1077 /* There might be a situation where new messages arrive to a control
1078 * queue between processing the last message and clearing the
1079 * EVENT_PENDING bit. So before exiting, check queue head again (using
1080 * ice_ctrlq_pending) and process new messages if any.
1082 if (ice_ctrlq_pending(hw, &hw->adminq))
1083 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1089 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1090 * @pf: board private structure
1092 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1094 struct ice_hw *hw = &pf->hw;
1096 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1099 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1102 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1104 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1105 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1111 * ice_service_task_schedule - schedule the service task to wake up
1112 * @pf: board private structure
1114 * If not already scheduled, this puts the task into the work queue.
1116 void ice_service_task_schedule(struct ice_pf *pf)
1118 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1119 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1120 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1121 queue_work(ice_wq, &pf->serv_task);
1125 * ice_service_task_complete - finish up the service task
1126 * @pf: board private structure
1128 static void ice_service_task_complete(struct ice_pf *pf)
1130 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1132 /* force memory (pf->state) to sync before next service task */
1133 smp_mb__before_atomic();
1134 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1138 * ice_service_task_stop - stop service task and cancel works
1139 * @pf: board private structure
1141 static void ice_service_task_stop(struct ice_pf *pf)
1143 set_bit(__ICE_SERVICE_DIS, pf->state);
1145 if (pf->serv_tmr.function)
1146 del_timer_sync(&pf->serv_tmr);
1147 if (pf->serv_task.func)
1148 cancel_work_sync(&pf->serv_task);
1150 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1154 * ice_service_task_restart - restart service task and schedule works
1155 * @pf: board private structure
1157 * This function is needed for suspend and resume works (e.g WoL scenario)
1159 static void ice_service_task_restart(struct ice_pf *pf)
1161 clear_bit(__ICE_SERVICE_DIS, pf->state);
1162 ice_service_task_schedule(pf);
1166 * ice_service_timer - timer callback to schedule service task
1167 * @t: pointer to timer_list
1169 static void ice_service_timer(struct timer_list *t)
1171 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1173 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1174 ice_service_task_schedule(pf);
1178 * ice_handle_mdd_event - handle malicious driver detect event
1179 * @pf: pointer to the PF structure
1181 * Called from service task. OICR interrupt handler indicates MDD event.
1182 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1183 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1184 * disable the queue, the PF can be configured to reset the VF using ethtool
1185 * private flag mdd-auto-reset-vf.
1187 static void ice_handle_mdd_event(struct ice_pf *pf)
1189 struct device *dev = ice_pf_to_dev(pf);
1190 struct ice_hw *hw = &pf->hw;
1194 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state)) {
1195 /* Since the VF MDD event logging is rate limited, check if
1196 * there are pending MDD events.
1198 ice_print_vfs_mdd_events(pf);
1202 /* find what triggered an MDD event */
1203 reg = rd32(hw, GL_MDET_TX_PQM);
1204 if (reg & GL_MDET_TX_PQM_VALID_M) {
1205 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1206 GL_MDET_TX_PQM_PF_NUM_S;
1207 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1208 GL_MDET_TX_PQM_VF_NUM_S;
1209 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1210 GL_MDET_TX_PQM_MAL_TYPE_S;
1211 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1212 GL_MDET_TX_PQM_QNUM_S);
1214 if (netif_msg_tx_err(pf))
1215 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1216 event, queue, pf_num, vf_num);
1217 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
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);
1237 reg = rd32(hw, GL_MDET_RX);
1238 if (reg & GL_MDET_RX_VALID_M) {
1239 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1240 GL_MDET_RX_PF_NUM_S;
1241 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1242 GL_MDET_RX_VF_NUM_S;
1243 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1244 GL_MDET_RX_MAL_TYPE_S;
1245 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1248 if (netif_msg_rx_err(pf))
1249 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1250 event, queue, pf_num, vf_num);
1251 wr32(hw, GL_MDET_RX, 0xffffffff);
1254 /* check to see if this PF caused an MDD event */
1255 reg = rd32(hw, PF_MDET_TX_PQM);
1256 if (reg & PF_MDET_TX_PQM_VALID_M) {
1257 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1258 if (netif_msg_tx_err(pf))
1259 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1262 reg = rd32(hw, PF_MDET_TX_TCLAN);
1263 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1264 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1265 if (netif_msg_tx_err(pf))
1266 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1269 reg = rd32(hw, PF_MDET_RX);
1270 if (reg & PF_MDET_RX_VALID_M) {
1271 wr32(hw, PF_MDET_RX, 0xFFFF);
1272 if (netif_msg_rx_err(pf))
1273 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1276 /* Check to see if one of the VFs caused an MDD event, and then
1277 * increment counters and set print pending
1279 ice_for_each_vf(pf, i) {
1280 struct ice_vf *vf = &pf->vf[i];
1282 reg = rd32(hw, VP_MDET_TX_PQM(i));
1283 if (reg & VP_MDET_TX_PQM_VALID_M) {
1284 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1285 vf->mdd_tx_events.count++;
1286 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state);
1287 if (netif_msg_tx_err(pf))
1288 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1292 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1293 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1294 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1295 vf->mdd_tx_events.count++;
1296 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state);
1297 if (netif_msg_tx_err(pf))
1298 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1302 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1303 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1304 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1305 vf->mdd_tx_events.count++;
1306 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state);
1307 if (netif_msg_tx_err(pf))
1308 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1312 reg = rd32(hw, VP_MDET_RX(i));
1313 if (reg & VP_MDET_RX_VALID_M) {
1314 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1315 vf->mdd_rx_events.count++;
1316 set_bit(__ICE_MDD_VF_PRINT_PENDING, pf->state);
1317 if (netif_msg_rx_err(pf))
1318 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1321 /* Since the queue is disabled on VF Rx MDD events, the
1322 * PF can be configured to reset the VF through ethtool
1323 * private flag mdd-auto-reset-vf.
1325 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) {
1326 /* VF MDD event counters will be cleared by
1327 * reset, so print the event prior to reset.
1329 ice_print_vf_rx_mdd_event(vf);
1330 ice_reset_vf(&pf->vf[i], false);
1335 ice_print_vfs_mdd_events(pf);
1339 * ice_force_phys_link_state - Force the physical link state
1340 * @vsi: VSI to force the physical link state to up/down
1341 * @link_up: true/false indicates to set the physical link to up/down
1343 * Force the physical link state by getting the current PHY capabilities from
1344 * hardware and setting the PHY config based on the determined capabilities. If
1345 * link changes a link event will be triggered because both the Enable Automatic
1346 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1348 * Returns 0 on success, negative on failure
1350 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1352 struct ice_aqc_get_phy_caps_data *pcaps;
1353 struct ice_aqc_set_phy_cfg_data *cfg;
1354 struct ice_port_info *pi;
1358 if (!vsi || !vsi->port_info || !vsi->back)
1360 if (vsi->type != ICE_VSI_PF)
1363 dev = ice_pf_to_dev(vsi->back);
1365 pi = vsi->port_info;
1367 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1371 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1374 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1375 vsi->vsi_num, retcode);
1380 /* No change in link */
1381 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1382 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1385 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
1391 cfg->phy_type_low = pcaps->phy_type_low;
1392 cfg->phy_type_high = pcaps->phy_type_high;
1393 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1394 cfg->low_power_ctrl = pcaps->low_power_ctrl;
1395 cfg->eee_cap = pcaps->eee_cap;
1396 cfg->eeer_value = pcaps->eeer_value;
1397 cfg->link_fec_opt = pcaps->link_fec_options;
1399 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1401 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1403 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
1405 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1406 vsi->vsi_num, retcode);
1417 * ice_check_media_subtask - Check for media; bring link up if detected.
1418 * @pf: pointer to PF struct
1420 static void ice_check_media_subtask(struct ice_pf *pf)
1422 struct ice_port_info *pi;
1423 struct ice_vsi *vsi;
1426 vsi = ice_get_main_vsi(pf);
1430 /* No need to check for media if it's already present or the interface
1433 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) ||
1434 test_bit(__ICE_DOWN, vsi->state))
1437 /* Refresh link info and check if media is present */
1438 pi = vsi->port_info;
1439 err = ice_update_link_info(pi);
1443 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1444 err = ice_force_phys_link_state(vsi, true);
1447 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1449 /* A Link Status Event will be generated; the event handler
1450 * will complete bringing the interface up
1456 * ice_service_task - manage and run subtasks
1457 * @work: pointer to work_struct contained by the PF struct
1459 static void ice_service_task(struct work_struct *work)
1461 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1462 unsigned long start_time = jiffies;
1466 /* process reset requests first */
1467 ice_reset_subtask(pf);
1469 /* bail if a reset/recovery cycle is pending or rebuild failed */
1470 if (ice_is_reset_in_progress(pf->state) ||
1471 test_bit(__ICE_SUSPENDED, pf->state) ||
1472 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1473 ice_service_task_complete(pf);
1477 ice_clean_adminq_subtask(pf);
1478 ice_check_media_subtask(pf);
1479 ice_check_for_hang_subtask(pf);
1480 ice_sync_fltr_subtask(pf);
1481 ice_handle_mdd_event(pf);
1482 ice_watchdog_subtask(pf);
1484 if (ice_is_safe_mode(pf)) {
1485 ice_service_task_complete(pf);
1489 ice_process_vflr_event(pf);
1490 ice_clean_mailboxq_subtask(pf);
1491 ice_sync_arfs_fltrs(pf);
1492 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1493 ice_service_task_complete(pf);
1495 /* If the tasks have taken longer than one service timer period
1496 * or there is more work to be done, reset the service timer to
1497 * schedule the service task now.
1499 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1500 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1501 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1502 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1503 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1504 mod_timer(&pf->serv_tmr, jiffies);
1508 * ice_set_ctrlq_len - helper function to set controlq length
1509 * @hw: pointer to the HW instance
1511 static void ice_set_ctrlq_len(struct ice_hw *hw)
1513 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1514 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1515 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1516 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1517 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
1518 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
1519 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1520 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1524 * ice_schedule_reset - schedule a reset
1525 * @pf: board private structure
1526 * @reset: reset being requested
1528 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
1530 struct device *dev = ice_pf_to_dev(pf);
1532 /* bail out if earlier reset has failed */
1533 if (test_bit(__ICE_RESET_FAILED, pf->state)) {
1534 dev_dbg(dev, "earlier reset has failed\n");
1537 /* bail if reset/recovery already in progress */
1538 if (ice_is_reset_in_progress(pf->state)) {
1539 dev_dbg(dev, "Reset already in progress\n");
1545 set_bit(__ICE_PFR_REQ, pf->state);
1547 case ICE_RESET_CORER:
1548 set_bit(__ICE_CORER_REQ, pf->state);
1550 case ICE_RESET_GLOBR:
1551 set_bit(__ICE_GLOBR_REQ, pf->state);
1557 ice_service_task_schedule(pf);
1562 * ice_irq_affinity_notify - Callback for affinity changes
1563 * @notify: context as to what irq was changed
1564 * @mask: the new affinity mask
1566 * This is a callback function used by the irq_set_affinity_notifier function
1567 * so that we may register to receive changes to the irq affinity masks.
1570 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1571 const cpumask_t *mask)
1573 struct ice_q_vector *q_vector =
1574 container_of(notify, struct ice_q_vector, affinity_notify);
1576 cpumask_copy(&q_vector->affinity_mask, mask);
1580 * ice_irq_affinity_release - Callback for affinity notifier release
1581 * @ref: internal core kernel usage
1583 * This is a callback function used by the irq_set_affinity_notifier function
1584 * to inform the current notification subscriber that they will no longer
1585 * receive notifications.
1587 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1590 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1591 * @vsi: the VSI being configured
1593 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1595 struct ice_hw *hw = &vsi->back->hw;
1598 ice_for_each_q_vector(vsi, i)
1599 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1606 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1607 * @vsi: the VSI being configured
1608 * @basename: name for the vector
1610 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1612 int q_vectors = vsi->num_q_vectors;
1613 struct ice_pf *pf = vsi->back;
1614 int base = vsi->base_vector;
1621 dev = ice_pf_to_dev(pf);
1622 for (vector = 0; vector < q_vectors; vector++) {
1623 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1625 irq_num = pf->msix_entries[base + vector].vector;
1627 if (q_vector->tx.ring && q_vector->rx.ring) {
1628 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1629 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1631 } else if (q_vector->rx.ring) {
1632 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1633 "%s-%s-%d", basename, "rx", rx_int_idx++);
1634 } else if (q_vector->tx.ring) {
1635 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1636 "%s-%s-%d", basename, "tx", tx_int_idx++);
1638 /* skip this unused q_vector */
1641 err = devm_request_irq(dev, irq_num, vsi->irq_handler, 0,
1642 q_vector->name, q_vector);
1644 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
1649 /* register for affinity change notifications */
1650 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
1651 struct irq_affinity_notify *affinity_notify;
1653 affinity_notify = &q_vector->affinity_notify;
1654 affinity_notify->notify = ice_irq_affinity_notify;
1655 affinity_notify->release = ice_irq_affinity_release;
1656 irq_set_affinity_notifier(irq_num, affinity_notify);
1659 /* assign the mask for this irq */
1660 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1663 vsi->irqs_ready = true;
1669 irq_num = pf->msix_entries[base + vector].vector;
1670 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
1671 irq_set_affinity_notifier(irq_num, NULL);
1672 irq_set_affinity_hint(irq_num, NULL);
1673 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
1679 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
1680 * @vsi: VSI to setup Tx rings used by XDP
1682 * Return 0 on success and negative value on error
1684 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
1686 struct device *dev = ice_pf_to_dev(vsi->back);
1689 for (i = 0; i < vsi->num_xdp_txq; i++) {
1690 u16 xdp_q_idx = vsi->alloc_txq + i;
1691 struct ice_ring *xdp_ring;
1693 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
1696 goto free_xdp_rings;
1698 xdp_ring->q_index = xdp_q_idx;
1699 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
1700 xdp_ring->ring_active = false;
1701 xdp_ring->vsi = vsi;
1702 xdp_ring->netdev = NULL;
1703 xdp_ring->dev = dev;
1704 xdp_ring->count = vsi->num_tx_desc;
1705 vsi->xdp_rings[i] = xdp_ring;
1706 if (ice_setup_tx_ring(xdp_ring))
1707 goto free_xdp_rings;
1708 ice_set_ring_xdp(xdp_ring);
1709 xdp_ring->xsk_umem = ice_xsk_umem(xdp_ring);
1716 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
1717 ice_free_tx_ring(vsi->xdp_rings[i]);
1722 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
1723 * @vsi: VSI to set the bpf prog on
1724 * @prog: the bpf prog pointer
1726 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
1728 struct bpf_prog *old_prog;
1731 old_prog = xchg(&vsi->xdp_prog, prog);
1733 bpf_prog_put(old_prog);
1735 ice_for_each_rxq(vsi, i)
1736 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
1740 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
1741 * @vsi: VSI to bring up Tx rings used by XDP
1742 * @prog: bpf program that will be assigned to VSI
1744 * Return 0 on success and negative value on error
1746 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
1748 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1749 int xdp_rings_rem = vsi->num_xdp_txq;
1750 struct ice_pf *pf = vsi->back;
1751 struct ice_qs_cfg xdp_qs_cfg = {
1752 .qs_mutex = &pf->avail_q_mutex,
1753 .pf_map = pf->avail_txqs,
1754 .pf_map_size = pf->max_pf_txqs,
1755 .q_count = vsi->num_xdp_txq,
1756 .scatter_count = ICE_MAX_SCATTER_TXQS,
1757 .vsi_map = vsi->txq_map,
1758 .vsi_map_offset = vsi->alloc_txq,
1759 .mapping_mode = ICE_VSI_MAP_CONTIG
1761 enum ice_status status;
1765 dev = ice_pf_to_dev(pf);
1766 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
1767 sizeof(*vsi->xdp_rings), GFP_KERNEL);
1768 if (!vsi->xdp_rings)
1771 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
1772 if (__ice_vsi_get_qs(&xdp_qs_cfg))
1775 if (ice_xdp_alloc_setup_rings(vsi))
1776 goto clear_xdp_rings;
1778 /* follow the logic from ice_vsi_map_rings_to_vectors */
1779 ice_for_each_q_vector(vsi, v_idx) {
1780 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1781 int xdp_rings_per_v, q_id, q_base;
1783 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
1784 vsi->num_q_vectors - v_idx);
1785 q_base = vsi->num_xdp_txq - xdp_rings_rem;
1787 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
1788 struct ice_ring *xdp_ring = vsi->xdp_rings[q_id];
1790 xdp_ring->q_vector = q_vector;
1791 xdp_ring->next = q_vector->tx.ring;
1792 q_vector->tx.ring = xdp_ring;
1794 xdp_rings_rem -= xdp_rings_per_v;
1797 /* omit the scheduler update if in reset path; XDP queues will be
1798 * taken into account at the end of ice_vsi_rebuild, where
1799 * ice_cfg_vsi_lan is being called
1801 if (ice_is_reset_in_progress(pf->state))
1804 /* tell the Tx scheduler that right now we have
1807 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1808 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
1810 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1813 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %s\n",
1814 ice_stat_str(status));
1815 goto clear_xdp_rings;
1817 ice_vsi_assign_bpf_prog(vsi, prog);
1821 for (i = 0; i < vsi->num_xdp_txq; i++)
1822 if (vsi->xdp_rings[i]) {
1823 kfree_rcu(vsi->xdp_rings[i], rcu);
1824 vsi->xdp_rings[i] = NULL;
1828 mutex_lock(&pf->avail_q_mutex);
1829 for (i = 0; i < vsi->num_xdp_txq; i++) {
1830 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1831 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1833 mutex_unlock(&pf->avail_q_mutex);
1835 devm_kfree(dev, vsi->xdp_rings);
1840 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
1841 * @vsi: VSI to remove XDP rings
1843 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
1846 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
1848 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
1849 struct ice_pf *pf = vsi->back;
1852 /* q_vectors are freed in reset path so there's no point in detaching
1853 * rings; in case of rebuild being triggered not from reset reset bits
1854 * in pf->state won't be set, so additionally check first q_vector
1857 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1860 ice_for_each_q_vector(vsi, v_idx) {
1861 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
1862 struct ice_ring *ring;
1864 ice_for_each_ring(ring, q_vector->tx)
1865 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
1868 /* restore the value of last node prior to XDP setup */
1869 q_vector->tx.ring = ring;
1873 mutex_lock(&pf->avail_q_mutex);
1874 for (i = 0; i < vsi->num_xdp_txq; i++) {
1875 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
1876 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
1878 mutex_unlock(&pf->avail_q_mutex);
1880 for (i = 0; i < vsi->num_xdp_txq; i++)
1881 if (vsi->xdp_rings[i]) {
1882 if (vsi->xdp_rings[i]->desc)
1883 ice_free_tx_ring(vsi->xdp_rings[i]);
1884 kfree_rcu(vsi->xdp_rings[i], rcu);
1885 vsi->xdp_rings[i] = NULL;
1888 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
1889 vsi->xdp_rings = NULL;
1891 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
1894 ice_vsi_assign_bpf_prog(vsi, NULL);
1896 /* notify Tx scheduler that we destroyed XDP queues and bring
1897 * back the old number of child nodes
1899 for (i = 0; i < vsi->tc_cfg.numtc; i++)
1900 max_txqs[i] = vsi->num_txq;
1902 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
1907 * ice_xdp_setup_prog - Add or remove XDP eBPF program
1908 * @vsi: VSI to setup XDP for
1909 * @prog: XDP program
1910 * @extack: netlink extended ack
1913 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
1914 struct netlink_ext_ack *extack)
1916 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
1917 bool if_running = netif_running(vsi->netdev);
1918 int ret = 0, xdp_ring_err = 0;
1920 if (frame_size > vsi->rx_buf_len) {
1921 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
1925 /* need to stop netdev while setting up the program for Rx rings */
1926 if (if_running && !test_and_set_bit(__ICE_DOWN, vsi->state)) {
1927 ret = ice_down(vsi);
1929 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
1934 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
1935 vsi->num_xdp_txq = vsi->alloc_txq;
1936 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
1938 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
1939 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
1940 xdp_ring_err = ice_destroy_xdp_rings(vsi);
1942 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
1944 ice_vsi_assign_bpf_prog(vsi, prog);
1950 if (!ret && prog && vsi->xsk_umems) {
1953 ice_for_each_rxq(vsi, i) {
1954 struct ice_ring *rx_ring = vsi->rx_rings[i];
1956 if (rx_ring->xsk_umem)
1957 napi_schedule(&rx_ring->q_vector->napi);
1961 return (ret || xdp_ring_err) ? -ENOMEM : 0;
1965 * ice_xdp - implements XDP handler
1969 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
1971 struct ice_netdev_priv *np = netdev_priv(dev);
1972 struct ice_vsi *vsi = np->vsi;
1974 if (vsi->type != ICE_VSI_PF) {
1975 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI");
1979 switch (xdp->command) {
1980 case XDP_SETUP_PROG:
1981 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
1982 case XDP_QUERY_PROG:
1983 xdp->prog_id = vsi->xdp_prog ? vsi->xdp_prog->aux->id : 0;
1985 case XDP_SETUP_XSK_UMEM:
1986 return ice_xsk_umem_setup(vsi, xdp->xsk.umem,
1994 * ice_ena_misc_vector - enable the non-queue interrupts
1995 * @pf: board private structure
1997 static void ice_ena_misc_vector(struct ice_pf *pf)
1999 struct ice_hw *hw = &pf->hw;
2002 /* Disable anti-spoof detection interrupt to prevent spurious event
2003 * interrupts during a function reset. Anti-spoof functionally is
2006 val = rd32(hw, GL_MDCK_TX_TDPU);
2007 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
2008 wr32(hw, GL_MDCK_TX_TDPU, val);
2010 /* clear things first */
2011 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
2012 rd32(hw, PFINT_OICR); /* read to clear */
2014 val = (PFINT_OICR_ECC_ERR_M |
2015 PFINT_OICR_MAL_DETECT_M |
2017 PFINT_OICR_PCI_EXCEPTION_M |
2019 PFINT_OICR_HMC_ERR_M |
2020 PFINT_OICR_PE_CRITERR_M);
2022 wr32(hw, PFINT_OICR_ENA, val);
2024 /* SW_ITR_IDX = 0, but don't change INTENA */
2025 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2026 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2030 * ice_misc_intr - misc interrupt handler
2031 * @irq: interrupt number
2032 * @data: pointer to a q_vector
2034 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2036 struct ice_pf *pf = (struct ice_pf *)data;
2037 struct ice_hw *hw = &pf->hw;
2038 irqreturn_t ret = IRQ_NONE;
2042 dev = ice_pf_to_dev(pf);
2043 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
2044 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2046 oicr = rd32(hw, PFINT_OICR);
2047 ena_mask = rd32(hw, PFINT_OICR_ENA);
2049 if (oicr & PFINT_OICR_SWINT_M) {
2050 ena_mask &= ~PFINT_OICR_SWINT_M;
2054 if (oicr & PFINT_OICR_MAL_DETECT_M) {
2055 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2056 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
2058 if (oicr & PFINT_OICR_VFLR_M) {
2059 /* disable any further VFLR event notifications */
2060 if (test_bit(__ICE_VF_RESETS_DISABLED, pf->state)) {
2061 u32 reg = rd32(hw, PFINT_OICR_ENA);
2063 reg &= ~PFINT_OICR_VFLR_M;
2064 wr32(hw, PFINT_OICR_ENA, reg);
2066 ena_mask &= ~PFINT_OICR_VFLR_M;
2067 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
2071 if (oicr & PFINT_OICR_GRST_M) {
2074 /* we have a reset warning */
2075 ena_mask &= ~PFINT_OICR_GRST_M;
2076 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
2077 GLGEN_RSTAT_RESET_TYPE_S;
2079 if (reset == ICE_RESET_CORER)
2081 else if (reset == ICE_RESET_GLOBR)
2083 else if (reset == ICE_RESET_EMPR)
2086 dev_dbg(dev, "Invalid reset type %d\n", reset);
2088 /* If a reset cycle isn't already in progress, we set a bit in
2089 * pf->state so that the service task can start a reset/rebuild.
2090 * We also make note of which reset happened so that peer
2091 * devices/drivers can be informed.
2093 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
2094 if (reset == ICE_RESET_CORER)
2095 set_bit(__ICE_CORER_RECV, pf->state);
2096 else if (reset == ICE_RESET_GLOBR)
2097 set_bit(__ICE_GLOBR_RECV, pf->state);
2099 set_bit(__ICE_EMPR_RECV, pf->state);
2101 /* There are couple of different bits at play here.
2102 * hw->reset_ongoing indicates whether the hardware is
2103 * in reset. This is set to true when a reset interrupt
2104 * is received and set back to false after the driver
2105 * has determined that the hardware is out of reset.
2107 * __ICE_RESET_OICR_RECV in pf->state indicates
2108 * that a post reset rebuild is required before the
2109 * driver is operational again. This is set above.
2111 * As this is the start of the reset/rebuild cycle, set
2112 * both to indicate that.
2114 hw->reset_ongoing = true;
2118 if (oicr & PFINT_OICR_HMC_ERR_M) {
2119 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
2120 dev_dbg(dev, "HMC Error interrupt - info 0x%x, data 0x%x\n",
2121 rd32(hw, PFHMC_ERRORINFO),
2122 rd32(hw, PFHMC_ERRORDATA));
2125 /* Report any remaining unexpected interrupts */
2128 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
2129 /* If a critical error is pending there is no choice but to
2132 if (oicr & (PFINT_OICR_PE_CRITERR_M |
2133 PFINT_OICR_PCI_EXCEPTION_M |
2134 PFINT_OICR_ECC_ERR_M)) {
2135 set_bit(__ICE_PFR_REQ, pf->state);
2136 ice_service_task_schedule(pf);
2141 ice_service_task_schedule(pf);
2142 ice_irq_dynamic_ena(hw, NULL, NULL);
2148 * ice_dis_ctrlq_interrupts - disable control queue interrupts
2149 * @hw: pointer to HW structure
2151 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
2153 /* disable Admin queue Interrupt causes */
2154 wr32(hw, PFINT_FW_CTL,
2155 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
2157 /* disable Mailbox queue Interrupt causes */
2158 wr32(hw, PFINT_MBX_CTL,
2159 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
2161 /* disable Control queue Interrupt causes */
2162 wr32(hw, PFINT_OICR_CTL,
2163 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
2169 * ice_free_irq_msix_misc - Unroll misc vector setup
2170 * @pf: board private structure
2172 static void ice_free_irq_msix_misc(struct ice_pf *pf)
2174 struct ice_hw *hw = &pf->hw;
2176 ice_dis_ctrlq_interrupts(hw);
2178 /* disable OICR interrupt */
2179 wr32(hw, PFINT_OICR_ENA, 0);
2182 if (pf->msix_entries) {
2183 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
2184 devm_free_irq(ice_pf_to_dev(pf),
2185 pf->msix_entries[pf->oicr_idx].vector, pf);
2188 pf->num_avail_sw_msix += 1;
2189 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
2193 * ice_ena_ctrlq_interrupts - enable control queue interrupts
2194 * @hw: pointer to HW structure
2195 * @reg_idx: HW vector index to associate the control queue interrupts with
2197 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
2201 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2202 PFINT_OICR_CTL_CAUSE_ENA_M);
2203 wr32(hw, PFINT_OICR_CTL, val);
2205 /* enable Admin queue Interrupt causes */
2206 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2207 PFINT_FW_CTL_CAUSE_ENA_M);
2208 wr32(hw, PFINT_FW_CTL, val);
2210 /* enable Mailbox queue Interrupt causes */
2211 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
2212 PFINT_MBX_CTL_CAUSE_ENA_M);
2213 wr32(hw, PFINT_MBX_CTL, val);
2219 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2220 * @pf: board private structure
2222 * This sets up the handler for MSIX 0, which is used to manage the
2223 * non-queue interrupts, e.g. AdminQ and errors. This is not used
2224 * when in MSI or Legacy interrupt mode.
2226 static int ice_req_irq_msix_misc(struct ice_pf *pf)
2228 struct device *dev = ice_pf_to_dev(pf);
2229 struct ice_hw *hw = &pf->hw;
2230 int oicr_idx, err = 0;
2232 if (!pf->int_name[0])
2233 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
2234 dev_driver_string(dev), dev_name(dev));
2236 /* Do not request IRQ but do enable OICR interrupt since settings are
2237 * lost during reset. Note that this function is called only during
2238 * rebuild path and not while reset is in progress.
2240 if (ice_is_reset_in_progress(pf->state))
2243 /* reserve one vector in irq_tracker for misc interrupts */
2244 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2248 pf->num_avail_sw_msix -= 1;
2249 pf->oicr_idx = (u16)oicr_idx;
2251 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
2252 ice_misc_intr, 0, pf->int_name, pf);
2254 dev_err(dev, "devm_request_irq for %s failed: %d\n",
2256 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2257 pf->num_avail_sw_msix += 1;
2262 ice_ena_misc_vector(pf);
2264 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
2265 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
2266 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
2269 ice_irq_dynamic_ena(hw, NULL, NULL);
2275 * ice_napi_add - register NAPI handler for the VSI
2276 * @vsi: VSI for which NAPI handler is to be registered
2278 * This function is only called in the driver's load path. Registering the NAPI
2279 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
2280 * reset/rebuild, etc.)
2282 static void ice_napi_add(struct ice_vsi *vsi)
2289 ice_for_each_q_vector(vsi, v_idx)
2290 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
2291 ice_napi_poll, NAPI_POLL_WEIGHT);
2295 * ice_set_ops - set netdev and ethtools ops for the given netdev
2296 * @netdev: netdev instance
2298 static void ice_set_ops(struct net_device *netdev)
2300 struct ice_pf *pf = ice_netdev_to_pf(netdev);
2302 if (ice_is_safe_mode(pf)) {
2303 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
2304 ice_set_ethtool_safe_mode_ops(netdev);
2308 netdev->netdev_ops = &ice_netdev_ops;
2309 ice_set_ethtool_ops(netdev);
2313 * ice_set_netdev_features - set features for the given netdev
2314 * @netdev: netdev instance
2316 static void ice_set_netdev_features(struct net_device *netdev)
2318 struct ice_pf *pf = ice_netdev_to_pf(netdev);
2319 netdev_features_t csumo_features;
2320 netdev_features_t vlano_features;
2321 netdev_features_t dflt_features;
2322 netdev_features_t tso_features;
2324 if (ice_is_safe_mode(pf)) {
2326 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
2327 netdev->hw_features = netdev->features;
2331 dflt_features = NETIF_F_SG |
2336 csumo_features = NETIF_F_RXCSUM |
2341 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
2342 NETIF_F_HW_VLAN_CTAG_TX |
2343 NETIF_F_HW_VLAN_CTAG_RX;
2345 tso_features = NETIF_F_TSO |
2349 NETIF_F_GSO_UDP_TUNNEL |
2350 NETIF_F_GSO_GRE_CSUM |
2351 NETIF_F_GSO_UDP_TUNNEL_CSUM |
2352 NETIF_F_GSO_PARTIAL |
2353 NETIF_F_GSO_IPXIP4 |
2354 NETIF_F_GSO_IPXIP6 |
2357 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
2358 NETIF_F_GSO_GRE_CSUM;
2359 /* set features that user can change */
2360 netdev->hw_features = dflt_features | csumo_features |
2361 vlano_features | tso_features;
2363 /* add support for HW_CSUM on packets with MPLS header */
2364 netdev->mpls_features = NETIF_F_HW_CSUM;
2366 /* enable features */
2367 netdev->features |= netdev->hw_features;
2368 /* encap and VLAN devices inherit default, csumo and tso features */
2369 netdev->hw_enc_features |= dflt_features | csumo_features |
2371 netdev->vlan_features |= dflt_features | csumo_features |
2376 * ice_cfg_netdev - Allocate, configure and register a netdev
2377 * @vsi: the VSI associated with the new netdev
2379 * Returns 0 on success, negative value on failure
2381 static int ice_cfg_netdev(struct ice_vsi *vsi)
2383 struct ice_pf *pf = vsi->back;
2384 struct ice_netdev_priv *np;
2385 struct net_device *netdev;
2386 u8 mac_addr[ETH_ALEN];
2389 err = ice_devlink_create_port(pf);
2393 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
2397 goto err_destroy_devlink_port;
2400 vsi->netdev = netdev;
2401 np = netdev_priv(netdev);
2404 ice_set_netdev_features(netdev);
2406 ice_set_ops(netdev);
2408 if (vsi->type == ICE_VSI_PF) {
2409 SET_NETDEV_DEV(netdev, ice_pf_to_dev(pf));
2410 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
2411 ether_addr_copy(netdev->dev_addr, mac_addr);
2412 ether_addr_copy(netdev->perm_addr, mac_addr);
2415 netdev->priv_flags |= IFF_UNICAST_FLT;
2417 /* Setup netdev TC information */
2418 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
2420 /* setup watchdog timeout value to be 5 second */
2421 netdev->watchdog_timeo = 5 * HZ;
2423 netdev->min_mtu = ETH_MIN_MTU;
2424 netdev->max_mtu = ICE_MAX_MTU;
2426 err = register_netdev(vsi->netdev);
2428 goto err_destroy_devlink_port;
2430 devlink_port_type_eth_set(&pf->devlink_port, vsi->netdev);
2432 netif_carrier_off(vsi->netdev);
2434 /* make sure transmit queues start off as stopped */
2435 netif_tx_stop_all_queues(vsi->netdev);
2439 err_destroy_devlink_port:
2440 ice_devlink_destroy_port(pf);
2446 * ice_fill_rss_lut - Fill the RSS lookup table with default values
2447 * @lut: Lookup table
2448 * @rss_table_size: Lookup table size
2449 * @rss_size: Range of queue number for hashing
2451 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2455 for (i = 0; i < rss_table_size; i++)
2456 lut[i] = i % rss_size;
2460 * ice_pf_vsi_setup - Set up a PF VSI
2461 * @pf: board private structure
2462 * @pi: pointer to the port_info instance
2464 * Returns pointer to the successfully allocated VSI software struct
2465 * on success, otherwise returns NULL on failure.
2467 static struct ice_vsi *
2468 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2470 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
2474 * ice_ctrl_vsi_setup - Set up a control VSI
2475 * @pf: board private structure
2476 * @pi: pointer to the port_info instance
2478 * Returns pointer to the successfully allocated VSI software struct
2479 * on success, otherwise returns NULL on failure.
2481 static struct ice_vsi *
2482 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2484 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, ICE_INVAL_VFID);
2488 * ice_lb_vsi_setup - Set up a loopback VSI
2489 * @pf: board private structure
2490 * @pi: pointer to the port_info instance
2492 * Returns pointer to the successfully allocated VSI software struct
2493 * on success, otherwise returns NULL on failure.
2496 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2498 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
2502 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2503 * @netdev: network interface to be adjusted
2504 * @proto: unused protocol
2505 * @vid: VLAN ID to be added
2507 * net_device_ops implementation for adding VLAN IDs
2510 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
2513 struct ice_netdev_priv *np = netdev_priv(netdev);
2514 struct ice_vsi *vsi = np->vsi;
2517 if (vid >= VLAN_N_VID) {
2518 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2526 /* VLAN 0 is added by default during load/reset */
2530 /* Enable VLAN pruning when a VLAN other than 0 is added */
2531 if (!ice_vsi_is_vlan_pruning_ena(vsi)) {
2532 ret = ice_cfg_vlan_pruning(vsi, true, false);
2537 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
2538 * packets aren't pruned by the device's internal switch on Rx
2540 ret = ice_vsi_add_vlan(vsi, vid, ICE_FWD_TO_VSI);
2542 vsi->vlan_ena = true;
2543 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2550 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2551 * @netdev: network interface to be adjusted
2552 * @proto: unused protocol
2553 * @vid: VLAN ID to be removed
2555 * net_device_ops implementation for removing VLAN IDs
2558 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
2561 struct ice_netdev_priv *np = netdev_priv(netdev);
2562 struct ice_vsi *vsi = np->vsi;
2568 /* don't allow removal of VLAN 0 */
2572 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2575 ret = ice_vsi_kill_vlan(vsi, vid);
2579 /* Disable pruning when VLAN 0 is the only VLAN rule */
2580 if (vsi->num_vlan == 1 && ice_vsi_is_vlan_pruning_ena(vsi))
2581 ret = ice_cfg_vlan_pruning(vsi, false, false);
2583 vsi->vlan_ena = false;
2584 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2589 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2590 * @pf: board private structure
2592 * Returns 0 on success, negative value on failure
2594 static int ice_setup_pf_sw(struct ice_pf *pf)
2596 struct ice_vsi *vsi;
2599 if (ice_is_reset_in_progress(pf->state))
2602 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2605 goto unroll_vsi_setup;
2608 status = ice_cfg_netdev(vsi);
2611 goto unroll_vsi_setup;
2613 /* netdev has to be configured before setting frame size */
2614 ice_vsi_cfg_frame_size(vsi);
2616 /* Setup DCB netlink interface */
2617 ice_dcbnl_setup(vsi);
2619 /* registering the NAPI handler requires both the queues and
2620 * netdev to be created, which are done in ice_pf_vsi_setup()
2621 * and ice_cfg_netdev() respectively
2625 status = ice_set_cpu_rx_rmap(vsi);
2627 dev_err(ice_pf_to_dev(pf), "Failed to set CPU Rx map VSI %d error %d\n",
2628 vsi->vsi_num, status);
2630 goto unroll_napi_add;
2632 status = ice_init_mac_fltr(pf);
2634 goto free_cpu_rx_map;
2639 ice_free_cpu_rx_rmap(vsi);
2645 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2646 unregister_netdev(vsi->netdev);
2647 free_netdev(vsi->netdev);
2654 ice_vsi_free_q_vectors(vsi);
2655 ice_vsi_delete(vsi);
2656 ice_vsi_put_qs(vsi);
2663 * ice_get_avail_q_count - Get count of queues in use
2664 * @pf_qmap: bitmap to get queue use count from
2665 * @lock: pointer to a mutex that protects access to pf_qmap
2666 * @size: size of the bitmap
2669 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
2675 for_each_clear_bit(bit, pf_qmap, size)
2683 * ice_get_avail_txq_count - Get count of Tx queues in use
2684 * @pf: pointer to an ice_pf instance
2686 u16 ice_get_avail_txq_count(struct ice_pf *pf)
2688 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
2693 * ice_get_avail_rxq_count - Get count of Rx queues in use
2694 * @pf: pointer to an ice_pf instance
2696 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
2698 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
2703 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2704 * @pf: board private structure to initialize
2706 static void ice_deinit_pf(struct ice_pf *pf)
2708 ice_service_task_stop(pf);
2709 mutex_destroy(&pf->sw_mutex);
2710 mutex_destroy(&pf->tc_mutex);
2711 mutex_destroy(&pf->avail_q_mutex);
2713 if (pf->avail_txqs) {
2714 bitmap_free(pf->avail_txqs);
2715 pf->avail_txqs = NULL;
2718 if (pf->avail_rxqs) {
2719 bitmap_free(pf->avail_rxqs);
2720 pf->avail_rxqs = NULL;
2725 * ice_set_pf_caps - set PFs capability flags
2726 * @pf: pointer to the PF instance
2728 static void ice_set_pf_caps(struct ice_pf *pf)
2730 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
2732 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2733 if (func_caps->common_cap.dcb)
2734 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2735 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2736 if (func_caps->common_cap.sr_iov_1_1) {
2737 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2738 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
2741 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
2742 if (func_caps->common_cap.rss_table_size)
2743 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2745 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
2746 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
2749 /* ctrl_vsi_idx will be set to a valid value when flow director
2750 * is setup by ice_init_fdir
2752 pf->ctrl_vsi_idx = ICE_NO_VSI;
2753 set_bit(ICE_FLAG_FD_ENA, pf->flags);
2754 /* force guaranteed filter pool for PF */
2755 ice_alloc_fd_guar_item(&pf->hw, &unused,
2756 func_caps->fd_fltr_guar);
2757 /* force shared filter pool for PF */
2758 ice_alloc_fd_shrd_item(&pf->hw, &unused,
2759 func_caps->fd_fltr_best_effort);
2762 pf->max_pf_txqs = func_caps->common_cap.num_txq;
2763 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
2767 * ice_init_pf - Initialize general software structures (struct ice_pf)
2768 * @pf: board private structure to initialize
2770 static int ice_init_pf(struct ice_pf *pf)
2772 ice_set_pf_caps(pf);
2774 mutex_init(&pf->sw_mutex);
2775 mutex_init(&pf->tc_mutex);
2777 /* setup service timer and periodic service task */
2778 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2779 pf->serv_tmr_period = HZ;
2780 INIT_WORK(&pf->serv_task, ice_service_task);
2781 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2783 mutex_init(&pf->avail_q_mutex);
2784 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
2785 if (!pf->avail_txqs)
2788 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
2789 if (!pf->avail_rxqs) {
2790 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
2791 pf->avail_txqs = NULL;
2799 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2800 * @pf: board private structure
2802 * compute the number of MSIX vectors required (v_budget) and request from
2803 * the OS. Return the number of vectors reserved or negative on failure
2805 static int ice_ena_msix_range(struct ice_pf *pf)
2807 struct device *dev = ice_pf_to_dev(pf);
2808 int v_left, v_actual, v_budget = 0;
2811 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2813 /* reserve one vector for miscellaneous handler */
2815 if (v_left < needed)
2816 goto no_hw_vecs_left_err;
2820 /* reserve vectors for LAN traffic */
2821 needed = min_t(int, num_online_cpus(), v_left);
2822 if (v_left < needed)
2823 goto no_hw_vecs_left_err;
2824 pf->num_lan_msix = needed;
2828 /* reserve one vector for flow director */
2829 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
2830 needed = ICE_FDIR_MSIX;
2831 if (v_left < needed)
2832 goto no_hw_vecs_left_err;
2837 pf->msix_entries = devm_kcalloc(dev, v_budget,
2838 sizeof(*pf->msix_entries), GFP_KERNEL);
2840 if (!pf->msix_entries) {
2845 for (i = 0; i < v_budget; i++)
2846 pf->msix_entries[i].entry = i;
2848 /* actually reserve the vectors */
2849 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2850 ICE_MIN_MSIX, v_budget);
2853 dev_err(dev, "unable to reserve MSI-X vectors\n");
2858 if (v_actual < v_budget) {
2859 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
2860 v_budget, v_actual);
2861 /* 2 vectors each for LAN and RDMA (traffic + OICR), one for flow director */
2862 #define ICE_MIN_LAN_VECS 2
2863 #define ICE_MIN_RDMA_VECS 2
2864 #define ICE_MIN_VECS (ICE_MIN_LAN_VECS + ICE_MIN_RDMA_VECS + 1)
2866 if (v_actual < ICE_MIN_LAN_VECS) {
2867 /* error if we can't get minimum vectors */
2868 pci_disable_msix(pf->pdev);
2872 pf->num_lan_msix = ICE_MIN_LAN_VECS;
2879 devm_kfree(dev, pf->msix_entries);
2882 no_hw_vecs_left_err:
2883 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
2887 pf->num_lan_msix = 0;
2892 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2893 * @pf: board private structure
2895 static void ice_dis_msix(struct ice_pf *pf)
2897 pci_disable_msix(pf->pdev);
2898 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
2899 pf->msix_entries = NULL;
2903 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2904 * @pf: board private structure
2906 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2910 if (pf->irq_tracker) {
2911 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
2912 pf->irq_tracker = NULL;
2917 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2918 * @pf: board private structure to initialize
2920 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2924 vectors = ice_ena_msix_range(pf);
2929 /* set up vector assignment tracking */
2931 devm_kzalloc(ice_pf_to_dev(pf), sizeof(*pf->irq_tracker) +
2932 (sizeof(u16) * vectors), GFP_KERNEL);
2933 if (!pf->irq_tracker) {
2938 /* populate SW interrupts pool with number of OS granted IRQs. */
2939 pf->num_avail_sw_msix = (u16)vectors;
2940 pf->irq_tracker->num_entries = (u16)vectors;
2941 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2947 * ice_vsi_recfg_qs - Change the number of queues on a VSI
2948 * @vsi: VSI being changed
2949 * @new_rx: new number of Rx queues
2950 * @new_tx: new number of Tx queues
2952 * Only change the number of queues if new_tx, or new_rx is non-0.
2954 * Returns 0 on success.
2956 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
2958 struct ice_pf *pf = vsi->back;
2959 int err = 0, timeout = 50;
2961 if (!new_rx && !new_tx)
2964 while (test_and_set_bit(__ICE_CFG_BUSY, pf->state)) {
2968 usleep_range(1000, 2000);
2972 vsi->req_txq = (u16)new_tx;
2974 vsi->req_rxq = (u16)new_rx;
2976 /* set for the next time the netdev is started */
2977 if (!netif_running(vsi->netdev)) {
2978 ice_vsi_rebuild(vsi, false);
2979 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
2984 ice_vsi_rebuild(vsi, false);
2985 ice_pf_dcb_recfg(pf);
2988 clear_bit(__ICE_CFG_BUSY, pf->state);
2993 * ice_log_pkg_init - log result of DDP package load
2994 * @hw: pointer to hardware info
2995 * @status: status of package load
2998 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status)
3000 struct ice_pf *pf = (struct ice_pf *)hw->back;
3001 struct device *dev = ice_pf_to_dev(pf);
3005 /* The package download AdminQ command returned success because
3006 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
3007 * already a package loaded on the device.
3009 if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
3010 hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
3011 hw->pkg_ver.update == hw->active_pkg_ver.update &&
3012 hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
3013 !memcmp(hw->pkg_name, hw->active_pkg_name,
3014 sizeof(hw->pkg_name))) {
3015 if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST)
3016 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
3017 hw->active_pkg_name,
3018 hw->active_pkg_ver.major,
3019 hw->active_pkg_ver.minor,
3020 hw->active_pkg_ver.update,
3021 hw->active_pkg_ver.draft);
3023 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
3024 hw->active_pkg_name,
3025 hw->active_pkg_ver.major,
3026 hw->active_pkg_ver.minor,
3027 hw->active_pkg_ver.update,
3028 hw->active_pkg_ver.draft);
3029 } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
3030 hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
3031 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",
3032 hw->active_pkg_name,
3033 hw->active_pkg_ver.major,
3034 hw->active_pkg_ver.minor,
3035 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
3036 *status = ICE_ERR_NOT_SUPPORTED;
3037 } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3038 hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
3039 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",
3040 hw->active_pkg_name,
3041 hw->active_pkg_ver.major,
3042 hw->active_pkg_ver.minor,
3043 hw->active_pkg_ver.update,
3044 hw->active_pkg_ver.draft,
3051 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");
3052 *status = ICE_ERR_NOT_SUPPORTED;
3055 case ICE_ERR_FW_DDP_MISMATCH:
3056 dev_err(dev, "The firmware loaded on the device is not compatible with the DDP package. Please update the device's NVM. Entering safe mode.\n");
3058 case ICE_ERR_BUF_TOO_SHORT:
3060 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
3062 case ICE_ERR_NOT_SUPPORTED:
3063 /* Package File version not supported */
3064 if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ ||
3065 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3066 hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR))
3067 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
3068 else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ ||
3069 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3070 hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR))
3071 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",
3072 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
3074 case ICE_ERR_AQ_ERROR:
3075 switch (hw->pkg_dwnld_status) {
3076 case ICE_AQ_RC_ENOSEC:
3077 case ICE_AQ_RC_EBADSIG:
3078 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");
3080 case ICE_AQ_RC_ESVN:
3081 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");
3083 case ICE_AQ_RC_EBADMAN:
3084 case ICE_AQ_RC_EBADBUF:
3085 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
3092 dev_err(dev, "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n",
3099 * ice_load_pkg - load/reload the DDP Package file
3100 * @firmware: firmware structure when firmware requested or NULL for reload
3101 * @pf: pointer to the PF instance
3103 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
3104 * initialize HW tables.
3107 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
3109 enum ice_status status = ICE_ERR_PARAM;
3110 struct device *dev = ice_pf_to_dev(pf);
3111 struct ice_hw *hw = &pf->hw;
3113 /* Load DDP Package */
3114 if (firmware && !hw->pkg_copy) {
3115 status = ice_copy_and_init_pkg(hw, firmware->data,
3117 ice_log_pkg_init(hw, &status);
3118 } else if (!firmware && hw->pkg_copy) {
3119 /* Reload package during rebuild after CORER/GLOBR reset */
3120 status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
3121 ice_log_pkg_init(hw, &status);
3123 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
3128 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3132 /* Successful download package is the precondition for advanced
3133 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
3135 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3139 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
3140 * @pf: pointer to the PF structure
3142 * There is no error returned here because the driver should be able to handle
3143 * 128 Byte cache lines, so we only print a warning in case issues are seen,
3144 * specifically with Tx.
3146 static void ice_verify_cacheline_size(struct ice_pf *pf)
3148 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
3149 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
3150 ICE_CACHE_LINE_BYTES);
3154 * ice_send_version - update firmware with driver version
3157 * Returns ICE_SUCCESS on success, else error code
3159 static enum ice_status ice_send_version(struct ice_pf *pf)
3161 struct ice_driver_ver dv;
3163 dv.major_ver = DRV_VERSION_MAJOR;
3164 dv.minor_ver = DRV_VERSION_MINOR;
3165 dv.build_ver = DRV_VERSION_BUILD;
3166 dv.subbuild_ver = 0;
3167 strscpy((char *)dv.driver_string, DRV_VERSION,
3168 sizeof(dv.driver_string));
3169 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
3173 * ice_init_fdir - Initialize flow director VSI and configuration
3174 * @pf: pointer to the PF instance
3176 * returns 0 on success, negative on error
3178 static int ice_init_fdir(struct ice_pf *pf)
3180 struct device *dev = ice_pf_to_dev(pf);
3181 struct ice_vsi *ctrl_vsi;
3184 /* Side Band Flow Director needs to have a control VSI.
3185 * Allocate it and store it in the PF.
3187 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
3189 dev_dbg(dev, "could not create control VSI\n");
3193 err = ice_vsi_open_ctrl(ctrl_vsi);
3195 dev_dbg(dev, "could not open control VSI\n");
3199 mutex_init(&pf->hw.fdir_fltr_lock);
3201 err = ice_fdir_create_dflt_rules(pf);
3208 ice_fdir_release_flows(&pf->hw);
3209 ice_vsi_close(ctrl_vsi);
3211 ice_vsi_release(ctrl_vsi);
3212 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
3213 pf->vsi[pf->ctrl_vsi_idx] = NULL;
3214 pf->ctrl_vsi_idx = ICE_NO_VSI;
3220 * ice_get_opt_fw_name - return optional firmware file name or NULL
3221 * @pf: pointer to the PF instance
3223 static char *ice_get_opt_fw_name(struct ice_pf *pf)
3225 /* Optional firmware name same as default with additional dash
3226 * followed by a EUI-64 identifier (PCIe Device Serial Number)
3228 struct pci_dev *pdev = pf->pdev;
3229 char *opt_fw_filename;
3232 /* Determine the name of the optional file using the DSN (two
3233 * dwords following the start of the DSN Capability).
3235 dsn = pci_get_dsn(pdev);
3239 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
3240 if (!opt_fw_filename)
3243 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llX.pkg",
3244 ICE_DDP_PKG_PATH, dsn);
3246 return opt_fw_filename;
3250 * ice_request_fw - Device initialization routine
3251 * @pf: pointer to the PF instance
3253 static void ice_request_fw(struct ice_pf *pf)
3255 char *opt_fw_filename = ice_get_opt_fw_name(pf);
3256 const struct firmware *firmware = NULL;
3257 struct device *dev = ice_pf_to_dev(pf);
3260 /* optional device-specific DDP (if present) overrides the default DDP
3261 * package file. kernel logs a debug message if the file doesn't exist,
3262 * and warning messages for other errors.
3264 if (opt_fw_filename) {
3265 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
3267 kfree(opt_fw_filename);
3271 /* request for firmware was successful. Download to device */
3272 ice_load_pkg(firmware, pf);
3273 kfree(opt_fw_filename);
3274 release_firmware(firmware);
3279 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
3281 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
3285 /* request for firmware was successful. Download to device */
3286 ice_load_pkg(firmware, pf);
3287 release_firmware(firmware);
3291 * ice_probe - Device initialization routine
3292 * @pdev: PCI device information struct
3293 * @ent: entry in ice_pci_tbl
3295 * Returns 0 on success, negative on failure
3298 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
3300 struct device *dev = &pdev->dev;
3305 /* this driver uses devres, see
3306 * Documentation/driver-api/driver-model/devres.rst
3308 err = pcim_enable_device(pdev);
3312 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
3314 dev_err(dev, "BAR0 I/O map error %d\n", err);
3318 pf = ice_allocate_pf(dev);
3322 /* set up for high or low DMA */
3323 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
3325 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
3327 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
3331 pci_enable_pcie_error_reporting(pdev);
3332 pci_set_master(pdev);
3335 pci_set_drvdata(pdev, pf);
3336 set_bit(__ICE_DOWN, pf->state);
3337 /* Disable service task until DOWN bit is cleared */
3338 set_bit(__ICE_SERVICE_DIS, pf->state);
3341 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
3342 pci_save_state(pdev);
3345 hw->vendor_id = pdev->vendor;
3346 hw->device_id = pdev->device;
3347 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
3348 hw->subsystem_vendor_id = pdev->subsystem_vendor;
3349 hw->subsystem_device_id = pdev->subsystem_device;
3350 hw->bus.device = PCI_SLOT(pdev->devfn);
3351 hw->bus.func = PCI_FUNC(pdev->devfn);
3352 ice_set_ctrlq_len(hw);
3354 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
3356 err = ice_devlink_register(pf);
3358 dev_err(dev, "ice_devlink_register failed: %d\n", err);
3359 goto err_exit_unroll;
3362 #ifndef CONFIG_DYNAMIC_DEBUG
3364 hw->debug_mask = debug;
3367 err = ice_init_hw(hw);
3369 dev_err(dev, "ice_init_hw failed: %d\n", err);
3371 goto err_exit_unroll;
3376 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
3377 * set in pf->state, which will cause ice_is_safe_mode to return
3380 if (ice_is_safe_mode(pf)) {
3381 dev_err(dev, "Package download failed. Advanced features disabled - Device now in Safe Mode\n");
3382 /* we already got function/device capabilities but these don't
3383 * reflect what the driver needs to do in safe mode. Instead of
3384 * adding conditional logic everywhere to ignore these
3385 * device/function capabilities, override them.
3387 ice_set_safe_mode_caps(hw);
3390 err = ice_init_pf(pf);
3392 dev_err(dev, "ice_init_pf failed: %d\n", err);
3393 goto err_init_pf_unroll;
3396 ice_devlink_init_regions(pf);
3398 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
3399 if (!pf->num_alloc_vsi) {
3401 goto err_init_pf_unroll;
3404 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
3408 goto err_init_pf_unroll;
3411 err = ice_init_interrupt_scheme(pf);
3413 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
3415 goto err_init_interrupt_unroll;
3418 /* In case of MSIX we are going to setup the misc vector right here
3419 * to handle admin queue events etc. In case of legacy and MSI
3420 * the misc functionality and queue processing is combined in
3421 * the same vector and that gets setup at open.
3423 err = ice_req_irq_msix_misc(pf);
3425 dev_err(dev, "setup of misc vector failed: %d\n", err);
3426 goto err_init_interrupt_unroll;
3429 /* create switch struct for the switch element created by FW on boot */
3430 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
3431 if (!pf->first_sw) {
3433 goto err_msix_misc_unroll;
3437 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
3439 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
3441 pf->first_sw->pf = pf;
3443 /* record the sw_id available for later use */
3444 pf->first_sw->sw_id = hw->port_info->sw_id;
3446 err = ice_setup_pf_sw(pf);
3448 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
3449 goto err_alloc_sw_unroll;
3452 clear_bit(__ICE_SERVICE_DIS, pf->state);
3454 /* tell the firmware we are up */
3455 err = ice_send_version(pf);
3457 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
3459 goto err_alloc_sw_unroll;
3462 /* since everything is good, start the service timer */
3463 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3465 err = ice_init_link_events(pf->hw.port_info);
3467 dev_err(dev, "ice_init_link_events failed: %d\n", err);
3468 goto err_alloc_sw_unroll;
3471 ice_verify_cacheline_size(pf);
3473 /* If no DDP driven features have to be setup, we are done with probe */
3474 if (ice_is_safe_mode(pf))
3477 /* initialize DDP driven features */
3479 /* Note: Flow director init failure is non-fatal to load */
3480 if (ice_init_fdir(pf))
3481 dev_err(dev, "could not initialize flow director\n");
3483 /* Note: DCB init failure is non-fatal to load */
3484 if (ice_init_pf_dcb(pf, false)) {
3485 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3486 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
3488 ice_cfg_lldp_mib_change(&pf->hw, true);
3491 /* print PCI link speed and width */
3492 pcie_print_link_status(pf->pdev);
3495 /* ready to go, so clear down state bit */
3496 clear_bit(__ICE_DOWN, pf->state);
3499 err_alloc_sw_unroll:
3500 ice_devlink_destroy_port(pf);
3501 set_bit(__ICE_SERVICE_DIS, pf->state);
3502 set_bit(__ICE_DOWN, pf->state);
3503 devm_kfree(dev, pf->first_sw);
3504 err_msix_misc_unroll:
3505 ice_free_irq_msix_misc(pf);
3506 err_init_interrupt_unroll:
3507 ice_clear_interrupt_scheme(pf);
3508 devm_kfree(dev, pf->vsi);
3511 ice_devlink_destroy_regions(pf);
3514 ice_devlink_unregister(pf);
3515 pci_disable_pcie_error_reporting(pdev);
3520 * ice_remove - Device removal routine
3521 * @pdev: PCI device information struct
3523 static void ice_remove(struct pci_dev *pdev)
3525 struct ice_pf *pf = pci_get_drvdata(pdev);
3531 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
3532 if (!ice_is_reset_in_progress(pf->state))
3537 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
3538 set_bit(__ICE_VF_RESETS_DISABLED, pf->state);
3542 set_bit(__ICE_DOWN, pf->state);
3543 ice_service_task_stop(pf);
3545 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
3546 if (!ice_is_safe_mode(pf))
3547 ice_remove_arfs(pf);
3548 ice_devlink_destroy_port(pf);
3549 ice_vsi_release_all(pf);
3550 ice_free_irq_msix_misc(pf);
3551 ice_for_each_vsi(pf, i) {
3554 ice_vsi_free_q_vectors(pf->vsi[i]);
3557 ice_devlink_destroy_regions(pf);
3558 ice_deinit_hw(&pf->hw);
3559 ice_devlink_unregister(pf);
3561 /* Issue a PFR as part of the prescribed driver unload flow. Do not
3562 * do it via ice_schedule_reset() since there is no need to rebuild
3563 * and the service task is already stopped.
3565 ice_reset(&pf->hw, ICE_RESET_PFR);
3566 pci_wait_for_pending_transaction(pdev);
3567 ice_clear_interrupt_scheme(pf);
3568 pci_disable_pcie_error_reporting(pdev);
3572 * ice_pci_err_detected - warning that PCI error has been detected
3573 * @pdev: PCI device information struct
3574 * @err: the type of PCI error
3576 * Called to warn that something happened on the PCI bus and the error handling
3577 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
3579 static pci_ers_result_t
3580 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
3582 struct ice_pf *pf = pci_get_drvdata(pdev);
3585 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
3587 return PCI_ERS_RESULT_DISCONNECT;
3590 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3591 ice_service_task_stop(pf);
3593 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3594 set_bit(__ICE_PFR_REQ, pf->state);
3595 ice_prepare_for_reset(pf);
3599 return PCI_ERS_RESULT_NEED_RESET;
3603 * ice_pci_err_slot_reset - a PCI slot reset has just happened
3604 * @pdev: PCI device information struct
3606 * Called to determine if the driver can recover from the PCI slot reset by
3607 * using a register read to determine if the device is recoverable.
3609 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
3611 struct ice_pf *pf = pci_get_drvdata(pdev);
3612 pci_ers_result_t result;
3616 err = pci_enable_device_mem(pdev);
3618 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
3620 result = PCI_ERS_RESULT_DISCONNECT;
3622 pci_set_master(pdev);
3623 pci_restore_state(pdev);
3624 pci_save_state(pdev);
3625 pci_wake_from_d3(pdev, false);
3627 /* Check for life */
3628 reg = rd32(&pf->hw, GLGEN_RTRIG);
3630 result = PCI_ERS_RESULT_RECOVERED;
3632 result = PCI_ERS_RESULT_DISCONNECT;
3635 err = pci_aer_clear_nonfatal_status(pdev);
3637 dev_dbg(&pdev->dev, "pci_aer_clear_nonfatal_status() failed, error %d\n",
3639 /* non-fatal, continue */
3645 * ice_pci_err_resume - restart operations after PCI error recovery
3646 * @pdev: PCI device information struct
3648 * Called to allow the driver to bring things back up after PCI error and/or
3649 * reset recovery have finished
3651 static void ice_pci_err_resume(struct pci_dev *pdev)
3653 struct ice_pf *pf = pci_get_drvdata(pdev);
3656 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
3661 if (test_bit(__ICE_SUSPENDED, pf->state)) {
3662 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
3667 ice_do_reset(pf, ICE_RESET_PFR);
3668 ice_service_task_restart(pf);
3669 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3673 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
3674 * @pdev: PCI device information struct
3676 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
3678 struct ice_pf *pf = pci_get_drvdata(pdev);
3680 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3681 ice_service_task_stop(pf);
3683 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3684 set_bit(__ICE_PFR_REQ, pf->state);
3685 ice_prepare_for_reset(pf);
3691 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
3692 * @pdev: PCI device information struct
3694 static void ice_pci_err_reset_done(struct pci_dev *pdev)
3696 ice_pci_err_resume(pdev);
3699 /* ice_pci_tbl - PCI Device ID Table
3701 * Wildcard entries (PCI_ANY_ID) should come last
3702 * Last entry must be all 0s
3704 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3705 * Class, Class Mask, private data (not used) }
3707 static const struct pci_device_id ice_pci_tbl[] = {
3708 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
3709 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
3710 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
3711 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 },
3712 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 },
3713 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 },
3714 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 },
3715 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 },
3716 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 },
3717 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
3718 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
3719 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
3720 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
3721 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
3722 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 },
3723 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
3724 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
3725 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
3726 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 },
3727 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 },
3728 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 },
3729 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 },
3730 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 },
3731 /* required last entry */
3734 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
3736 static const struct pci_error_handlers ice_pci_err_handler = {
3737 .error_detected = ice_pci_err_detected,
3738 .slot_reset = ice_pci_err_slot_reset,
3739 .reset_prepare = ice_pci_err_reset_prepare,
3740 .reset_done = ice_pci_err_reset_done,
3741 .resume = ice_pci_err_resume
3744 static struct pci_driver ice_driver = {
3745 .name = KBUILD_MODNAME,
3746 .id_table = ice_pci_tbl,
3748 .remove = ice_remove,
3749 .sriov_configure = ice_sriov_configure,
3750 .err_handler = &ice_pci_err_handler
3754 * ice_module_init - Driver registration routine
3756 * ice_module_init is the first routine called when the driver is
3757 * loaded. All it does is register with the PCI subsystem.
3759 static int __init ice_module_init(void)
3763 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
3764 pr_info("%s\n", ice_copyright);
3766 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
3768 pr_err("Failed to create workqueue\n");
3772 status = pci_register_driver(&ice_driver);
3774 pr_err("failed to register PCI driver, err %d\n", status);
3775 destroy_workqueue(ice_wq);
3780 module_init(ice_module_init);
3783 * ice_module_exit - Driver exit cleanup routine
3785 * ice_module_exit is called just before the driver is removed
3788 static void __exit ice_module_exit(void)
3790 pci_unregister_driver(&ice_driver);
3791 destroy_workqueue(ice_wq);
3792 pr_info("module unloaded\n");
3794 module_exit(ice_module_exit);
3797 * ice_set_mac_address - NDO callback to set MAC address
3798 * @netdev: network interface device structure
3799 * @pi: pointer to an address structure
3801 * Returns 0 on success, negative on failure
3803 static int ice_set_mac_address(struct net_device *netdev, void *pi)
3805 struct ice_netdev_priv *np = netdev_priv(netdev);
3806 struct ice_vsi *vsi = np->vsi;
3807 struct ice_pf *pf = vsi->back;
3808 struct ice_hw *hw = &pf->hw;
3809 struct sockaddr *addr = pi;
3810 enum ice_status status;
3815 mac = (u8 *)addr->sa_data;
3817 if (!is_valid_ether_addr(mac))
3818 return -EADDRNOTAVAIL;
3820 if (ether_addr_equal(netdev->dev_addr, mac)) {
3821 netdev_warn(netdev, "already using mac %pM\n", mac);
3825 if (test_bit(__ICE_DOWN, pf->state) ||
3826 ice_is_reset_in_progress(pf->state)) {
3827 netdev_err(netdev, "can't set mac %pM. device not ready\n",
3832 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
3833 status = ice_fltr_remove_mac(vsi, netdev->dev_addr, ICE_FWD_TO_VSI);
3834 if (status && status != ICE_ERR_DOES_NOT_EXIST) {
3835 err = -EADDRNOTAVAIL;
3836 goto err_update_filters;
3839 /* Add filter for new MAC. If filter exists, just return success */
3840 status = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
3841 if (status == ICE_ERR_ALREADY_EXISTS) {
3842 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
3846 /* error if the new filter addition failed */
3848 err = -EADDRNOTAVAIL;
3852 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
3857 /* change the netdev's MAC address */
3858 memcpy(netdev->dev_addr, mac, netdev->addr_len);
3859 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
3862 /* write new MAC address to the firmware */
3863 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3864 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
3866 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %s\n",
3867 mac, ice_stat_str(status));
3873 * ice_set_rx_mode - NDO callback to set the netdev filters
3874 * @netdev: network interface device structure
3876 static void ice_set_rx_mode(struct net_device *netdev)
3878 struct ice_netdev_priv *np = netdev_priv(netdev);
3879 struct ice_vsi *vsi = np->vsi;
3884 /* Set the flags to synchronize filters
3885 * ndo_set_rx_mode may be triggered even without a change in netdev
3888 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
3889 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
3890 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
3892 /* schedule our worker thread which will take care of
3893 * applying the new filter changes
3895 ice_service_task_schedule(vsi->back);
3899 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
3900 * @netdev: network interface device structure
3901 * @queue_index: Queue ID
3902 * @maxrate: maximum bandwidth in Mbps
3905 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
3907 struct ice_netdev_priv *np = netdev_priv(netdev);
3908 struct ice_vsi *vsi = np->vsi;
3909 enum ice_status status;
3913 /* Validate maxrate requested is within permitted range */
3914 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
3915 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
3916 maxrate, queue_index);
3920 q_handle = vsi->tx_rings[queue_index]->q_handle;
3921 tc = ice_dcb_get_tc(vsi, queue_index);
3923 /* Set BW back to default, when user set maxrate to 0 */
3925 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
3926 q_handle, ICE_MAX_BW);
3928 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
3929 q_handle, ICE_MAX_BW, maxrate * 1000);
3931 netdev_err(netdev, "Unable to set Tx max rate, error %s\n",
3932 ice_stat_str(status));
3940 * ice_fdb_add - add an entry to the hardware database
3941 * @ndm: the input from the stack
3942 * @tb: pointer to array of nladdr (unused)
3943 * @dev: the net device pointer
3944 * @addr: the MAC address entry being added
3946 * @flags: instructions from stack about fdb operation
3947 * @extack: netlink extended ack
3950 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
3951 struct net_device *dev, const unsigned char *addr, u16 vid,
3952 u16 flags, struct netlink_ext_ack __always_unused *extack)
3957 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3960 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
3961 netdev_err(dev, "FDB only supports static addresses\n");
3965 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
3966 err = dev_uc_add_excl(dev, addr);
3967 else if (is_multicast_ether_addr(addr))
3968 err = dev_mc_add_excl(dev, addr);
3972 /* Only return duplicate errors if NLM_F_EXCL is set */
3973 if (err == -EEXIST && !(flags & NLM_F_EXCL))
3980 * ice_fdb_del - delete an entry from the hardware database
3981 * @ndm: the input from the stack
3982 * @tb: pointer to array of nladdr (unused)
3983 * @dev: the net device pointer
3984 * @addr: the MAC address entry being added
3988 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
3989 struct net_device *dev, const unsigned char *addr,
3990 __always_unused u16 vid)
3994 if (ndm->ndm_state & NUD_PERMANENT) {
3995 netdev_err(dev, "FDB only supports static addresses\n");
3999 if (is_unicast_ether_addr(addr))
4000 err = dev_uc_del(dev, addr);
4001 else if (is_multicast_ether_addr(addr))
4002 err = dev_mc_del(dev, addr);
4010 * ice_set_features - set the netdev feature flags
4011 * @netdev: ptr to the netdev being adjusted
4012 * @features: the feature set that the stack is suggesting
4015 ice_set_features(struct net_device *netdev, netdev_features_t features)
4017 struct ice_netdev_priv *np = netdev_priv(netdev);
4018 struct ice_vsi *vsi = np->vsi;
4019 struct ice_pf *pf = vsi->back;
4022 /* Don't set any netdev advanced features with device in Safe Mode */
4023 if (ice_is_safe_mode(vsi->back)) {
4024 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
4028 /* Do not change setting during reset */
4029 if (ice_is_reset_in_progress(pf->state)) {
4030 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
4034 /* Multiple features can be changed in one call so keep features in
4035 * separate if/else statements to guarantee each feature is checked
4037 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
4038 ret = ice_vsi_manage_rss_lut(vsi, true);
4039 else if (!(features & NETIF_F_RXHASH) &&
4040 netdev->features & NETIF_F_RXHASH)
4041 ret = ice_vsi_manage_rss_lut(vsi, false);
4043 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
4044 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
4045 ret = ice_vsi_manage_vlan_stripping(vsi, true);
4046 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
4047 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
4048 ret = ice_vsi_manage_vlan_stripping(vsi, false);
4050 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
4051 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
4052 ret = ice_vsi_manage_vlan_insertion(vsi);
4053 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
4054 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
4055 ret = ice_vsi_manage_vlan_insertion(vsi);
4057 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4058 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
4059 ret = ice_cfg_vlan_pruning(vsi, true, false);
4060 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
4061 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
4062 ret = ice_cfg_vlan_pruning(vsi, false, false);
4064 if ((features & NETIF_F_NTUPLE) &&
4065 !(netdev->features & NETIF_F_NTUPLE)) {
4066 ice_vsi_manage_fdir(vsi, true);
4068 } else if (!(features & NETIF_F_NTUPLE) &&
4069 (netdev->features & NETIF_F_NTUPLE)) {
4070 ice_vsi_manage_fdir(vsi, false);
4071 ice_clear_arfs(vsi);
4078 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
4079 * @vsi: VSI to setup VLAN properties for
4081 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
4085 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
4086 ret = ice_vsi_manage_vlan_stripping(vsi, true);
4087 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
4088 ret = ice_vsi_manage_vlan_insertion(vsi);
4094 * ice_vsi_cfg - Setup the VSI
4095 * @vsi: the VSI being configured
4097 * Return 0 on success and negative value on error
4099 int ice_vsi_cfg(struct ice_vsi *vsi)
4104 ice_set_rx_mode(vsi->netdev);
4106 err = ice_vsi_vlan_setup(vsi);
4111 ice_vsi_cfg_dcb_rings(vsi);
4113 err = ice_vsi_cfg_lan_txqs(vsi);
4114 if (!err && ice_is_xdp_ena_vsi(vsi))
4115 err = ice_vsi_cfg_xdp_txqs(vsi);
4117 err = ice_vsi_cfg_rxqs(vsi);
4123 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
4124 * @vsi: the VSI being configured
4126 static void ice_napi_enable_all(struct ice_vsi *vsi)
4133 ice_for_each_q_vector(vsi, q_idx) {
4134 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
4136 if (q_vector->rx.ring || q_vector->tx.ring)
4137 napi_enable(&q_vector->napi);
4142 * ice_up_complete - Finish the last steps of bringing up a connection
4143 * @vsi: The VSI being configured
4145 * Return 0 on success and negative value on error
4147 static int ice_up_complete(struct ice_vsi *vsi)
4149 struct ice_pf *pf = vsi->back;
4152 ice_vsi_cfg_msix(vsi);
4154 /* Enable only Rx rings, Tx rings were enabled by the FW when the
4155 * Tx queue group list was configured and the context bits were
4156 * programmed using ice_vsi_cfg_txqs
4158 err = ice_vsi_start_all_rx_rings(vsi);
4162 clear_bit(__ICE_DOWN, vsi->state);
4163 ice_napi_enable_all(vsi);
4164 ice_vsi_ena_irq(vsi);
4166 if (vsi->port_info &&
4167 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
4169 ice_print_link_msg(vsi, true);
4170 netif_tx_start_all_queues(vsi->netdev);
4171 netif_carrier_on(vsi->netdev);
4174 ice_service_task_schedule(pf);
4180 * ice_up - Bring the connection back up after being down
4181 * @vsi: VSI being configured
4183 int ice_up(struct ice_vsi *vsi)
4187 err = ice_vsi_cfg(vsi);
4189 err = ice_up_complete(vsi);
4195 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
4196 * @ring: Tx or Rx ring to read stats from
4197 * @pkts: packets stats counter
4198 * @bytes: bytes stats counter
4200 * This function fetches stats from the ring considering the atomic operations
4201 * that needs to be performed to read u64 values in 32 bit machine.
4204 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
4213 start = u64_stats_fetch_begin_irq(&ring->syncp);
4214 *pkts = ring->stats.pkts;
4215 *bytes = ring->stats.bytes;
4216 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
4220 * ice_update_vsi_ring_stats - Update VSI stats counters
4221 * @vsi: the VSI to be updated
4223 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
4225 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
4226 struct ice_ring *ring;
4230 /* reset netdev stats */
4231 vsi_stats->tx_packets = 0;
4232 vsi_stats->tx_bytes = 0;
4233 vsi_stats->rx_packets = 0;
4234 vsi_stats->rx_bytes = 0;
4236 /* reset non-netdev (extended) stats */
4237 vsi->tx_restart = 0;
4239 vsi->tx_linearize = 0;
4240 vsi->rx_buf_failed = 0;
4241 vsi->rx_page_failed = 0;
4245 /* update Tx rings counters */
4246 ice_for_each_txq(vsi, i) {
4247 ring = READ_ONCE(vsi->tx_rings[i]);
4248 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4249 vsi_stats->tx_packets += pkts;
4250 vsi_stats->tx_bytes += bytes;
4251 vsi->tx_restart += ring->tx_stats.restart_q;
4252 vsi->tx_busy += ring->tx_stats.tx_busy;
4253 vsi->tx_linearize += ring->tx_stats.tx_linearize;
4256 /* update Rx rings counters */
4257 ice_for_each_rxq(vsi, i) {
4258 ring = READ_ONCE(vsi->rx_rings[i]);
4259 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
4260 vsi_stats->rx_packets += pkts;
4261 vsi_stats->rx_bytes += bytes;
4262 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
4263 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
4270 * ice_update_vsi_stats - Update VSI stats counters
4271 * @vsi: the VSI to be updated
4273 void ice_update_vsi_stats(struct ice_vsi *vsi)
4275 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
4276 struct ice_eth_stats *cur_es = &vsi->eth_stats;
4277 struct ice_pf *pf = vsi->back;
4279 if (test_bit(__ICE_DOWN, vsi->state) ||
4280 test_bit(__ICE_CFG_BUSY, pf->state))
4283 /* get stats as recorded by Tx/Rx rings */
4284 ice_update_vsi_ring_stats(vsi);
4286 /* get VSI stats as recorded by the hardware */
4287 ice_update_eth_stats(vsi);
4289 cur_ns->tx_errors = cur_es->tx_errors;
4290 cur_ns->rx_dropped = cur_es->rx_discards;
4291 cur_ns->tx_dropped = cur_es->tx_discards;
4292 cur_ns->multicast = cur_es->rx_multicast;
4294 /* update some more netdev stats if this is main VSI */
4295 if (vsi->type == ICE_VSI_PF) {
4296 cur_ns->rx_crc_errors = pf->stats.crc_errors;
4297 cur_ns->rx_errors = pf->stats.crc_errors +
4298 pf->stats.illegal_bytes;
4299 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
4300 /* record drops from the port level */
4301 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
4306 * ice_update_pf_stats - Update PF port stats counters
4307 * @pf: PF whose stats needs to be updated
4309 void ice_update_pf_stats(struct ice_pf *pf)
4311 struct ice_hw_port_stats *prev_ps, *cur_ps;
4312 struct ice_hw *hw = &pf->hw;
4316 port = hw->port_info->lport;
4317 prev_ps = &pf->stats_prev;
4318 cur_ps = &pf->stats;
4320 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
4321 &prev_ps->eth.rx_bytes,
4322 &cur_ps->eth.rx_bytes);
4324 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
4325 &prev_ps->eth.rx_unicast,
4326 &cur_ps->eth.rx_unicast);
4328 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
4329 &prev_ps->eth.rx_multicast,
4330 &cur_ps->eth.rx_multicast);
4332 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
4333 &prev_ps->eth.rx_broadcast,
4334 &cur_ps->eth.rx_broadcast);
4336 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
4337 &prev_ps->eth.rx_discards,
4338 &cur_ps->eth.rx_discards);
4340 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
4341 &prev_ps->eth.tx_bytes,
4342 &cur_ps->eth.tx_bytes);
4344 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
4345 &prev_ps->eth.tx_unicast,
4346 &cur_ps->eth.tx_unicast);
4348 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
4349 &prev_ps->eth.tx_multicast,
4350 &cur_ps->eth.tx_multicast);
4352 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
4353 &prev_ps->eth.tx_broadcast,
4354 &cur_ps->eth.tx_broadcast);
4356 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
4357 &prev_ps->tx_dropped_link_down,
4358 &cur_ps->tx_dropped_link_down);
4360 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
4361 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
4363 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
4364 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
4366 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
4367 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
4369 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
4370 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
4372 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
4373 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
4375 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
4376 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
4378 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
4379 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
4381 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
4382 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
4384 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
4385 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
4387 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
4388 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
4390 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
4391 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
4393 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
4394 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
4396 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
4397 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
4399 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
4400 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
4402 fd_ctr_base = hw->fd_ctr_base;
4404 ice_stat_update40(hw,
4405 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
4406 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
4407 &cur_ps->fd_sb_match);
4408 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
4409 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
4411 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
4412 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
4414 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
4415 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
4417 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
4418 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
4420 ice_update_dcb_stats(pf);
4422 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
4423 &prev_ps->crc_errors, &cur_ps->crc_errors);
4425 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
4426 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
4428 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
4429 &prev_ps->mac_local_faults,
4430 &cur_ps->mac_local_faults);
4432 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
4433 &prev_ps->mac_remote_faults,
4434 &cur_ps->mac_remote_faults);
4436 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
4437 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
4439 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
4440 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
4442 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
4443 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
4445 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
4446 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
4448 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
4449 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
4451 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
4453 pf->stat_prev_loaded = true;
4457 * ice_get_stats64 - get statistics for network device structure
4458 * @netdev: network interface device structure
4459 * @stats: main device statistics structure
4462 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
4464 struct ice_netdev_priv *np = netdev_priv(netdev);
4465 struct rtnl_link_stats64 *vsi_stats;
4466 struct ice_vsi *vsi = np->vsi;
4468 vsi_stats = &vsi->net_stats;
4470 if (!vsi->num_txq || !vsi->num_rxq)
4473 /* netdev packet/byte stats come from ring counter. These are obtained
4474 * by summing up ring counters (done by ice_update_vsi_ring_stats).
4475 * But, only call the update routine and read the registers if VSI is
4478 if (!test_bit(__ICE_DOWN, vsi->state))
4479 ice_update_vsi_ring_stats(vsi);
4480 stats->tx_packets = vsi_stats->tx_packets;
4481 stats->tx_bytes = vsi_stats->tx_bytes;
4482 stats->rx_packets = vsi_stats->rx_packets;
4483 stats->rx_bytes = vsi_stats->rx_bytes;
4485 /* The rest of the stats can be read from the hardware but instead we
4486 * just return values that the watchdog task has already obtained from
4489 stats->multicast = vsi_stats->multicast;
4490 stats->tx_errors = vsi_stats->tx_errors;
4491 stats->tx_dropped = vsi_stats->tx_dropped;
4492 stats->rx_errors = vsi_stats->rx_errors;
4493 stats->rx_dropped = vsi_stats->rx_dropped;
4494 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
4495 stats->rx_length_errors = vsi_stats->rx_length_errors;
4499 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4500 * @vsi: VSI having NAPI disabled
4502 static void ice_napi_disable_all(struct ice_vsi *vsi)
4509 ice_for_each_q_vector(vsi, q_idx) {
4510 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
4512 if (q_vector->rx.ring || q_vector->tx.ring)
4513 napi_disable(&q_vector->napi);
4518 * ice_down - Shutdown the connection
4519 * @vsi: The VSI being stopped
4521 int ice_down(struct ice_vsi *vsi)
4523 int i, tx_err, rx_err, link_err = 0;
4525 /* Caller of this function is expected to set the
4526 * vsi->state __ICE_DOWN bit
4529 netif_carrier_off(vsi->netdev);
4530 netif_tx_disable(vsi->netdev);
4533 ice_vsi_dis_irq(vsi);
4535 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
4537 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
4538 vsi->vsi_num, tx_err);
4539 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
4540 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
4542 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
4543 vsi->vsi_num, tx_err);
4546 rx_err = ice_vsi_stop_all_rx_rings(vsi);
4548 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
4549 vsi->vsi_num, rx_err);
4551 ice_napi_disable_all(vsi);
4553 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
4554 link_err = ice_force_phys_link_state(vsi, false);
4556 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
4557 vsi->vsi_num, link_err);
4560 ice_for_each_txq(vsi, i)
4561 ice_clean_tx_ring(vsi->tx_rings[i]);
4563 ice_for_each_rxq(vsi, i)
4564 ice_clean_rx_ring(vsi->rx_rings[i]);
4566 if (tx_err || rx_err || link_err) {
4567 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
4568 vsi->vsi_num, vsi->vsw->sw_id);
4576 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
4577 * @vsi: VSI having resources allocated
4579 * Return 0 on success, negative on failure
4581 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
4585 if (!vsi->num_txq) {
4586 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
4591 ice_for_each_txq(vsi, i) {
4592 struct ice_ring *ring = vsi->tx_rings[i];
4597 ring->netdev = vsi->netdev;
4598 err = ice_setup_tx_ring(ring);
4607 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
4608 * @vsi: VSI having resources allocated
4610 * Return 0 on success, negative on failure
4612 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
4616 if (!vsi->num_rxq) {
4617 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
4622 ice_for_each_rxq(vsi, i) {
4623 struct ice_ring *ring = vsi->rx_rings[i];
4628 ring->netdev = vsi->netdev;
4629 err = ice_setup_rx_ring(ring);
4638 * ice_vsi_open_ctrl - open control VSI for use
4639 * @vsi: the VSI to open
4641 * Initialization of the Control VSI
4643 * Returns 0 on success, negative value on error
4645 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
4647 char int_name[ICE_INT_NAME_STR_LEN];
4648 struct ice_pf *pf = vsi->back;
4652 dev = ice_pf_to_dev(pf);
4653 /* allocate descriptors */
4654 err = ice_vsi_setup_tx_rings(vsi);
4658 err = ice_vsi_setup_rx_rings(vsi);
4662 err = ice_vsi_cfg(vsi);
4666 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
4667 dev_driver_string(dev), dev_name(dev));
4668 err = ice_vsi_req_irq_msix(vsi, int_name);
4672 ice_vsi_cfg_msix(vsi);
4674 err = ice_vsi_start_all_rx_rings(vsi);
4676 goto err_up_complete;
4678 clear_bit(__ICE_DOWN, vsi->state);
4679 ice_vsi_ena_irq(vsi);
4686 ice_vsi_free_rx_rings(vsi);
4688 ice_vsi_free_tx_rings(vsi);
4694 * ice_vsi_open - Called when a network interface is made active
4695 * @vsi: the VSI to open
4697 * Initialization of the VSI
4699 * Returns 0 on success, negative value on error
4701 static int ice_vsi_open(struct ice_vsi *vsi)
4703 char int_name[ICE_INT_NAME_STR_LEN];
4704 struct ice_pf *pf = vsi->back;
4707 /* allocate descriptors */
4708 err = ice_vsi_setup_tx_rings(vsi);
4712 err = ice_vsi_setup_rx_rings(vsi);
4716 err = ice_vsi_cfg(vsi);
4720 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4721 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
4722 err = ice_vsi_req_irq_msix(vsi, int_name);
4726 /* Notify the stack of the actual queue counts. */
4727 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
4731 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
4735 err = ice_up_complete(vsi);
4737 goto err_up_complete;
4744 ice_vsi_free_irq(vsi);
4746 ice_vsi_free_rx_rings(vsi);
4748 ice_vsi_free_tx_rings(vsi);
4754 * ice_vsi_release_all - Delete all VSIs
4755 * @pf: PF from which all VSIs are being removed
4757 static void ice_vsi_release_all(struct ice_pf *pf)
4764 ice_for_each_vsi(pf, i) {
4768 err = ice_vsi_release(pf->vsi[i]);
4770 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
4771 i, err, pf->vsi[i]->vsi_num);
4776 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
4777 * @pf: pointer to the PF instance
4778 * @type: VSI type to rebuild
4780 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
4782 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
4784 struct device *dev = ice_pf_to_dev(pf);
4785 enum ice_status status;
4788 ice_for_each_vsi(pf, i) {
4789 struct ice_vsi *vsi = pf->vsi[i];
4791 if (!vsi || vsi->type != type)
4794 /* rebuild the VSI */
4795 err = ice_vsi_rebuild(vsi, true);
4797 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
4798 err, vsi->idx, ice_vsi_type_str(type));
4802 /* replay filters for the VSI */
4803 status = ice_replay_vsi(&pf->hw, vsi->idx);
4805 dev_err(dev, "replay VSI failed, status %s, VSI index %d, type %s\n",
4806 ice_stat_str(status), vsi->idx,
4807 ice_vsi_type_str(type));
4811 /* Re-map HW VSI number, using VSI handle that has been
4812 * previously validated in ice_replay_vsi() call above
4814 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
4816 /* enable the VSI */
4817 err = ice_ena_vsi(vsi, false);
4819 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
4820 err, vsi->idx, ice_vsi_type_str(type));
4824 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
4825 ice_vsi_type_str(type));
4832 * ice_update_pf_netdev_link - Update PF netdev link status
4833 * @pf: pointer to the PF instance
4835 static void ice_update_pf_netdev_link(struct ice_pf *pf)
4840 ice_for_each_vsi(pf, i) {
4841 struct ice_vsi *vsi = pf->vsi[i];
4843 if (!vsi || vsi->type != ICE_VSI_PF)
4846 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
4848 netif_carrier_on(pf->vsi[i]->netdev);
4849 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
4851 netif_carrier_off(pf->vsi[i]->netdev);
4852 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
4858 * ice_rebuild - rebuild after reset
4859 * @pf: PF to rebuild
4860 * @reset_type: type of reset
4862 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
4864 struct device *dev = ice_pf_to_dev(pf);
4865 struct ice_hw *hw = &pf->hw;
4866 enum ice_status ret;
4869 if (test_bit(__ICE_DOWN, pf->state))
4870 goto clear_recovery;
4872 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
4874 ret = ice_init_all_ctrlq(hw);
4876 dev_err(dev, "control queues init failed %s\n",
4878 goto err_init_ctrlq;
4881 /* if DDP was previously loaded successfully */
4882 if (!ice_is_safe_mode(pf)) {
4883 /* reload the SW DB of filter tables */
4884 if (reset_type == ICE_RESET_PFR)
4885 ice_fill_blk_tbls(hw);
4887 /* Reload DDP Package after CORER/GLOBR reset */
4888 ice_load_pkg(NULL, pf);
4891 ret = ice_clear_pf_cfg(hw);
4893 dev_err(dev, "clear PF configuration failed %s\n",
4895 goto err_init_ctrlq;
4898 if (pf->first_sw->dflt_vsi_ena)
4899 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n");
4900 /* clear the default VSI configuration if it exists */
4901 pf->first_sw->dflt_vsi = NULL;
4902 pf->first_sw->dflt_vsi_ena = false;
4904 ice_clear_pxe_mode(hw);
4906 ret = ice_get_caps(hw);
4908 dev_err(dev, "ice_get_caps failed %s\n", ice_stat_str(ret));
4909 goto err_init_ctrlq;
4912 ret = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
4914 dev_err(dev, "set_mac_cfg failed %s\n", ice_stat_str(ret));
4915 goto err_init_ctrlq;
4918 err = ice_sched_init_port(hw->port_info);
4920 goto err_sched_init_port;
4922 err = ice_update_link_info(hw->port_info);
4924 dev_err(dev, "Get link status error %d\n", err);
4926 /* start misc vector */
4927 err = ice_req_irq_msix_misc(pf);
4929 dev_err(dev, "misc vector setup failed: %d\n", err);
4930 goto err_sched_init_port;
4933 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
4934 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
4935 if (!rd32(hw, PFQF_FD_SIZE)) {
4936 u16 unused, guar, b_effort;
4938 guar = hw->func_caps.fd_fltr_guar;
4939 b_effort = hw->func_caps.fd_fltr_best_effort;
4941 /* force guaranteed filter pool for PF */
4942 ice_alloc_fd_guar_item(hw, &unused, guar);
4943 /* force shared filter pool for PF */
4944 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
4948 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
4949 ice_dcb_rebuild(pf);
4951 /* rebuild PF VSI */
4952 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
4954 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
4955 goto err_vsi_rebuild;
4958 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4959 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_VF);
4961 dev_err(dev, "VF VSI rebuild failed: %d\n", err);
4962 goto err_vsi_rebuild;
4966 /* If Flow Director is active */
4967 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
4968 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
4970 dev_err(dev, "control VSI rebuild failed: %d\n", err);
4971 goto err_vsi_rebuild;
4974 /* replay HW Flow Director recipes */
4976 ice_fdir_replay_flows(hw);
4978 /* replay Flow Director filters */
4979 ice_fdir_replay_fltrs(pf);
4981 ice_rebuild_arfs(pf);
4984 ice_update_pf_netdev_link(pf);
4986 /* tell the firmware we are up */
4987 ret = ice_send_version(pf);
4989 dev_err(dev, "Rebuild failed due to error sending driver version: %s\n",
4991 goto err_vsi_rebuild;
4994 ice_replay_post(hw);
4996 /* if we get here, reset flow is successful */
4997 clear_bit(__ICE_RESET_FAILED, pf->state);
5001 err_sched_init_port:
5002 ice_sched_cleanup_all(hw);
5004 ice_shutdown_all_ctrlq(hw);
5005 set_bit(__ICE_RESET_FAILED, pf->state);
5007 /* set this bit in PF state to control service task scheduling */
5008 set_bit(__ICE_NEEDS_RESTART, pf->state);
5009 dev_err(dev, "Rebuild failed, unload and reload driver\n");
5013 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
5014 * @vsi: Pointer to VSI structure
5016 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
5018 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
5019 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
5021 return ICE_RXBUF_3072;
5025 * ice_change_mtu - NDO callback to change the MTU
5026 * @netdev: network interface device structure
5027 * @new_mtu: new value for maximum frame size
5029 * Returns 0 on success, negative on failure
5031 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
5033 struct ice_netdev_priv *np = netdev_priv(netdev);
5034 struct ice_vsi *vsi = np->vsi;
5035 struct ice_pf *pf = vsi->back;
5038 if (new_mtu == (int)netdev->mtu) {
5039 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
5043 if (ice_is_xdp_ena_vsi(vsi)) {
5044 int frame_size = ice_max_xdp_frame_size(vsi);
5046 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
5047 netdev_err(netdev, "max MTU for XDP usage is %d\n",
5048 frame_size - ICE_ETH_PKT_HDR_PAD);
5053 if (new_mtu < (int)netdev->min_mtu) {
5054 netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
5057 } else if (new_mtu > (int)netdev->max_mtu) {
5058 netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
5062 /* if a reset is in progress, wait for some time for it to complete */
5064 if (ice_is_reset_in_progress(pf->state)) {
5066 usleep_range(1000, 2000);
5071 } while (count < 100);
5074 netdev_err(netdev, "can't change MTU. Device is busy\n");
5078 netdev->mtu = (unsigned int)new_mtu;
5080 /* if VSI is up, bring it down and then back up */
5081 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
5084 err = ice_down(vsi);
5086 netdev_err(netdev, "change MTU if_up err %d\n", err);
5092 netdev_err(netdev, "change MTU if_up err %d\n", err);
5097 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
5102 * ice_aq_str - convert AQ err code to a string
5103 * @aq_err: the AQ error code to convert
5105 const char *ice_aq_str(enum ice_aq_err aq_err)
5110 case ICE_AQ_RC_EPERM:
5111 return "ICE_AQ_RC_EPERM";
5112 case ICE_AQ_RC_ENOENT:
5113 return "ICE_AQ_RC_ENOENT";
5114 case ICE_AQ_RC_ENOMEM:
5115 return "ICE_AQ_RC_ENOMEM";
5116 case ICE_AQ_RC_EBUSY:
5117 return "ICE_AQ_RC_EBUSY";
5118 case ICE_AQ_RC_EEXIST:
5119 return "ICE_AQ_RC_EEXIST";
5120 case ICE_AQ_RC_EINVAL:
5121 return "ICE_AQ_RC_EINVAL";
5122 case ICE_AQ_RC_ENOSPC:
5123 return "ICE_AQ_RC_ENOSPC";
5124 case ICE_AQ_RC_ENOSYS:
5125 return "ICE_AQ_RC_ENOSYS";
5126 case ICE_AQ_RC_ENOSEC:
5127 return "ICE_AQ_RC_ENOSEC";
5128 case ICE_AQ_RC_EBADSIG:
5129 return "ICE_AQ_RC_EBADSIG";
5130 case ICE_AQ_RC_ESVN:
5131 return "ICE_AQ_RC_ESVN";
5132 case ICE_AQ_RC_EBADMAN:
5133 return "ICE_AQ_RC_EBADMAN";
5134 case ICE_AQ_RC_EBADBUF:
5135 return "ICE_AQ_RC_EBADBUF";
5138 return "ICE_AQ_RC_UNKNOWN";
5142 * ice_stat_str - convert status err code to a string
5143 * @stat_err: the status error code to convert
5145 const char *ice_stat_str(enum ice_status stat_err)
5151 return "ICE_ERR_PARAM";
5152 case ICE_ERR_NOT_IMPL:
5153 return "ICE_ERR_NOT_IMPL";
5154 case ICE_ERR_NOT_READY:
5155 return "ICE_ERR_NOT_READY";
5156 case ICE_ERR_NOT_SUPPORTED:
5157 return "ICE_ERR_NOT_SUPPORTED";
5158 case ICE_ERR_BAD_PTR:
5159 return "ICE_ERR_BAD_PTR";
5160 case ICE_ERR_INVAL_SIZE:
5161 return "ICE_ERR_INVAL_SIZE";
5162 case ICE_ERR_DEVICE_NOT_SUPPORTED:
5163 return "ICE_ERR_DEVICE_NOT_SUPPORTED";
5164 case ICE_ERR_RESET_FAILED:
5165 return "ICE_ERR_RESET_FAILED";
5166 case ICE_ERR_FW_API_VER:
5167 return "ICE_ERR_FW_API_VER";
5168 case ICE_ERR_NO_MEMORY:
5169 return "ICE_ERR_NO_MEMORY";
5171 return "ICE_ERR_CFG";
5172 case ICE_ERR_OUT_OF_RANGE:
5173 return "ICE_ERR_OUT_OF_RANGE";
5174 case ICE_ERR_ALREADY_EXISTS:
5175 return "ICE_ERR_ALREADY_EXISTS";
5176 case ICE_ERR_NVM_CHECKSUM:
5177 return "ICE_ERR_NVM_CHECKSUM";
5178 case ICE_ERR_BUF_TOO_SHORT:
5179 return "ICE_ERR_BUF_TOO_SHORT";
5180 case ICE_ERR_NVM_BLANK_MODE:
5181 return "ICE_ERR_NVM_BLANK_MODE";
5182 case ICE_ERR_IN_USE:
5183 return "ICE_ERR_IN_USE";
5184 case ICE_ERR_MAX_LIMIT:
5185 return "ICE_ERR_MAX_LIMIT";
5186 case ICE_ERR_RESET_ONGOING:
5187 return "ICE_ERR_RESET_ONGOING";
5188 case ICE_ERR_HW_TABLE:
5189 return "ICE_ERR_HW_TABLE";
5190 case ICE_ERR_DOES_NOT_EXIST:
5191 return "ICE_ERR_DOES_NOT_EXIST";
5192 case ICE_ERR_FW_DDP_MISMATCH:
5193 return "ICE_ERR_FW_DDP_MISMATCH";
5194 case ICE_ERR_AQ_ERROR:
5195 return "ICE_ERR_AQ_ERROR";
5196 case ICE_ERR_AQ_TIMEOUT:
5197 return "ICE_ERR_AQ_TIMEOUT";
5198 case ICE_ERR_AQ_FULL:
5199 return "ICE_ERR_AQ_FULL";
5200 case ICE_ERR_AQ_NO_WORK:
5201 return "ICE_ERR_AQ_NO_WORK";
5202 case ICE_ERR_AQ_EMPTY:
5203 return "ICE_ERR_AQ_EMPTY";
5206 return "ICE_ERR_UNKNOWN";
5210 * ice_set_rss - Set RSS keys and lut
5211 * @vsi: Pointer to VSI structure
5212 * @seed: RSS hash seed
5213 * @lut: Lookup table
5214 * @lut_size: Lookup table size
5216 * Returns 0 on success, negative on failure
5218 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
5220 struct ice_pf *pf = vsi->back;
5221 struct ice_hw *hw = &pf->hw;
5222 enum ice_status status;
5225 dev = ice_pf_to_dev(pf);
5227 struct ice_aqc_get_set_rss_keys *buf =
5228 (struct ice_aqc_get_set_rss_keys *)seed;
5230 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
5233 dev_err(dev, "Cannot set RSS key, err %s aq_err %s\n",
5234 ice_stat_str(status),
5235 ice_aq_str(hw->adminq.sq_last_status));
5241 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
5244 dev_err(dev, "Cannot set RSS lut, err %s aq_err %s\n",
5245 ice_stat_str(status),
5246 ice_aq_str(hw->adminq.sq_last_status));
5255 * ice_get_rss - Get RSS keys and lut
5256 * @vsi: Pointer to VSI structure
5257 * @seed: Buffer to store the keys
5258 * @lut: Buffer to store the lookup table entries
5259 * @lut_size: Size of buffer to store the lookup table entries
5261 * Returns 0 on success, negative on failure
5263 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
5265 struct ice_pf *pf = vsi->back;
5266 struct ice_hw *hw = &pf->hw;
5267 enum ice_status status;
5270 dev = ice_pf_to_dev(pf);
5272 struct ice_aqc_get_set_rss_keys *buf =
5273 (struct ice_aqc_get_set_rss_keys *)seed;
5275 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
5277 dev_err(dev, "Cannot get RSS key, err %s aq_err %s\n",
5278 ice_stat_str(status),
5279 ice_aq_str(hw->adminq.sq_last_status));
5285 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
5288 dev_err(dev, "Cannot get RSS lut, err %s aq_err %s\n",
5289 ice_stat_str(status),
5290 ice_aq_str(hw->adminq.sq_last_status));
5299 * ice_bridge_getlink - Get the hardware bridge mode
5302 * @seq: RTNL message seq
5303 * @dev: the netdev being configured
5304 * @filter_mask: filter mask passed in
5305 * @nlflags: netlink flags passed in
5307 * Return the bridge mode (VEB/VEPA)
5310 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
5311 struct net_device *dev, u32 filter_mask, int nlflags)
5313 struct ice_netdev_priv *np = netdev_priv(dev);
5314 struct ice_vsi *vsi = np->vsi;
5315 struct ice_pf *pf = vsi->back;
5318 bmode = pf->first_sw->bridge_mode;
5320 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
5325 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
5326 * @vsi: Pointer to VSI structure
5327 * @bmode: Hardware bridge mode (VEB/VEPA)
5329 * Returns 0 on success, negative on failure
5331 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
5333 struct ice_aqc_vsi_props *vsi_props;
5334 struct ice_hw *hw = &vsi->back->hw;
5335 struct ice_vsi_ctx *ctxt;
5336 enum ice_status status;
5339 vsi_props = &vsi->info;
5341 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
5345 ctxt->info = vsi->info;
5347 if (bmode == BRIDGE_MODE_VEB)
5348 /* change from VEPA to VEB mode */
5349 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
5351 /* change from VEB to VEPA mode */
5352 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
5353 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
5355 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
5357 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %s aq_err %s\n",
5358 bmode, ice_stat_str(status),
5359 ice_aq_str(hw->adminq.sq_last_status));
5363 /* Update sw flags for book keeping */
5364 vsi_props->sw_flags = ctxt->info.sw_flags;
5372 * ice_bridge_setlink - Set the hardware bridge mode
5373 * @dev: the netdev being configured
5374 * @nlh: RTNL message
5375 * @flags: bridge setlink flags
5376 * @extack: netlink extended ack
5378 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
5379 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
5380 * not already set for all VSIs connected to this switch. And also update the
5381 * unicast switch filter rules for the corresponding switch of the netdev.
5384 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
5385 u16 __always_unused flags,
5386 struct netlink_ext_ack __always_unused *extack)
5388 struct ice_netdev_priv *np = netdev_priv(dev);
5389 struct ice_pf *pf = np->vsi->back;
5390 struct nlattr *attr, *br_spec;
5391 struct ice_hw *hw = &pf->hw;
5392 enum ice_status status;
5393 struct ice_sw *pf_sw;
5394 int rem, v, err = 0;
5396 pf_sw = pf->first_sw;
5397 /* find the attribute in the netlink message */
5398 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
5400 nla_for_each_nested(attr, br_spec, rem) {
5403 if (nla_type(attr) != IFLA_BRIDGE_MODE)
5405 mode = nla_get_u16(attr);
5406 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
5408 /* Continue if bridge mode is not being flipped */
5409 if (mode == pf_sw->bridge_mode)
5411 /* Iterates through the PF VSI list and update the loopback
5414 ice_for_each_vsi(pf, v) {
5417 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
5422 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
5423 /* Update the unicast switch filter rules for the corresponding
5424 * switch of the netdev
5426 status = ice_update_sw_rule_bridge_mode(hw);
5428 netdev_err(dev, "switch rule update failed, mode = %d err %s aq_err %s\n",
5429 mode, ice_stat_str(status),
5430 ice_aq_str(hw->adminq.sq_last_status));
5431 /* revert hw->evb_veb */
5432 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
5436 pf_sw->bridge_mode = mode;
5443 * ice_tx_timeout - Respond to a Tx Hang
5444 * @netdev: network interface device structure
5445 * @txqueue: Tx queue
5447 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
5449 struct ice_netdev_priv *np = netdev_priv(netdev);
5450 struct ice_ring *tx_ring = NULL;
5451 struct ice_vsi *vsi = np->vsi;
5452 struct ice_pf *pf = vsi->back;
5455 pf->tx_timeout_count++;
5457 /* Check if PFC is enabled for the TC to which the queue belongs
5458 * to. If yes then Tx timeout is not caused by a hung queue, no
5459 * need to reset and rebuild
5461 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
5462 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
5467 /* now that we have an index, find the tx_ring struct */
5468 for (i = 0; i < vsi->num_txq; i++)
5469 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
5470 if (txqueue == vsi->tx_rings[i]->q_index) {
5471 tx_ring = vsi->tx_rings[i];
5475 /* Reset recovery level if enough time has elapsed after last timeout.
5476 * Also ensure no new reset action happens before next timeout period.
5478 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
5479 pf->tx_timeout_recovery_level = 1;
5480 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
5481 netdev->watchdog_timeo)))
5485 struct ice_hw *hw = &pf->hw;
5488 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
5489 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
5490 /* Read interrupt register */
5491 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
5493 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
5494 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
5495 head, tx_ring->next_to_use, val);
5498 pf->tx_timeout_last_recovery = jiffies;
5499 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
5500 pf->tx_timeout_recovery_level, txqueue);
5502 switch (pf->tx_timeout_recovery_level) {
5504 set_bit(__ICE_PFR_REQ, pf->state);
5507 set_bit(__ICE_CORER_REQ, pf->state);
5510 set_bit(__ICE_GLOBR_REQ, pf->state);
5513 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
5514 set_bit(__ICE_DOWN, pf->state);
5515 set_bit(__ICE_NEEDS_RESTART, vsi->state);
5516 set_bit(__ICE_SERVICE_DIS, pf->state);
5520 ice_service_task_schedule(pf);
5521 pf->tx_timeout_recovery_level++;
5525 * ice_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
5526 * @netdev: This physical port's netdev
5527 * @ti: Tunnel endpoint information
5530 ice_udp_tunnel_add(struct net_device *netdev, struct udp_tunnel_info *ti)
5532 struct ice_netdev_priv *np = netdev_priv(netdev);
5533 struct ice_vsi *vsi = np->vsi;
5534 struct ice_pf *pf = vsi->back;
5535 enum ice_tunnel_type tnl_type;
5536 u16 port = ntohs(ti->port);
5537 enum ice_status status;
5540 case UDP_TUNNEL_TYPE_VXLAN:
5541 tnl_type = TNL_VXLAN;
5543 case UDP_TUNNEL_TYPE_GENEVE:
5544 tnl_type = TNL_GENEVE;
5547 netdev_err(netdev, "Unknown tunnel type\n");
5551 status = ice_create_tunnel(&pf->hw, tnl_type, port);
5552 if (status == ICE_ERR_OUT_OF_RANGE)
5553 netdev_info(netdev, "Max tunneled UDP ports reached, port %d not added\n",
5556 netdev_err(netdev, "Error adding UDP tunnel - %s\n",
5557 ice_stat_str(status));
5561 * ice_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
5562 * @netdev: This physical port's netdev
5563 * @ti: Tunnel endpoint information
5566 ice_udp_tunnel_del(struct net_device *netdev, struct udp_tunnel_info *ti)
5568 struct ice_netdev_priv *np = netdev_priv(netdev);
5569 struct ice_vsi *vsi = np->vsi;
5570 struct ice_pf *pf = vsi->back;
5571 u16 port = ntohs(ti->port);
5572 enum ice_status status;
5575 retval = ice_tunnel_port_in_use(&pf->hw, port, NULL);
5577 netdev_info(netdev, "port %d not found in UDP tunnels list\n",
5582 status = ice_destroy_tunnel(&pf->hw, port, false);
5584 netdev_err(netdev, "error deleting port %d from UDP tunnels list\n",
5589 * ice_open - Called when a network interface becomes active
5590 * @netdev: network interface device structure
5592 * The open entry point is called when a network interface is made
5593 * active by the system (IFF_UP). At this point all resources needed
5594 * for transmit and receive operations are allocated, the interrupt
5595 * handler is registered with the OS, the netdev watchdog is enabled,
5596 * and the stack is notified that the interface is ready.
5598 * Returns 0 on success, negative value on failure
5600 int ice_open(struct net_device *netdev)
5602 struct ice_netdev_priv *np = netdev_priv(netdev);
5603 struct ice_vsi *vsi = np->vsi;
5604 struct ice_pf *pf = vsi->back;
5605 struct ice_port_info *pi;
5608 if (test_bit(__ICE_NEEDS_RESTART, pf->state)) {
5609 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
5613 if (test_bit(__ICE_DOWN, pf->state)) {
5614 netdev_err(netdev, "device is not ready yet\n");
5618 netif_carrier_off(netdev);
5620 pi = vsi->port_info;
5621 err = ice_update_link_info(pi);
5623 netdev_err(netdev, "Failed to get link info, error %d\n",
5628 /* Set PHY if there is media, otherwise, turn off PHY */
5629 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
5630 err = ice_force_phys_link_state(vsi, true);
5632 netdev_err(netdev, "Failed to set physical link up, error %d\n",
5637 err = ice_aq_set_link_restart_an(pi, false, NULL);
5639 netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n",
5643 set_bit(ICE_FLAG_NO_MEDIA, vsi->back->flags);
5646 err = ice_vsi_open(vsi);
5648 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
5649 vsi->vsi_num, vsi->vsw->sw_id);
5651 /* Update existing tunnels information */
5652 udp_tunnel_get_rx_info(netdev);
5658 * ice_stop - Disables a network interface
5659 * @netdev: network interface device structure
5661 * The stop entry point is called when an interface is de-activated by the OS,
5662 * and the netdevice enters the DOWN state. The hardware is still under the
5663 * driver's control, but the netdev interface is disabled.
5665 * Returns success only - not allowed to fail
5667 int ice_stop(struct net_device *netdev)
5669 struct ice_netdev_priv *np = netdev_priv(netdev);
5670 struct ice_vsi *vsi = np->vsi;
5678 * ice_features_check - Validate encapsulated packet conforms to limits
5680 * @netdev: This port's netdev
5681 * @features: Offload features that the stack believes apply
5683 static netdev_features_t
5684 ice_features_check(struct sk_buff *skb,
5685 struct net_device __always_unused *netdev,
5686 netdev_features_t features)
5690 /* No point in doing any of this if neither checksum nor GSO are
5691 * being requested for this frame. We can rule out both by just
5692 * checking for CHECKSUM_PARTIAL
5694 if (skb->ip_summed != CHECKSUM_PARTIAL)
5697 /* We cannot support GSO if the MSS is going to be less than
5698 * 64 bytes. If it is then we need to drop support for GSO.
5700 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
5701 features &= ~NETIF_F_GSO_MASK;
5703 len = skb_network_header(skb) - skb->data;
5704 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
5705 goto out_rm_features;
5707 len = skb_transport_header(skb) - skb_network_header(skb);
5708 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
5709 goto out_rm_features;
5711 if (skb->encapsulation) {
5712 len = skb_inner_network_header(skb) - skb_transport_header(skb);
5713 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
5714 goto out_rm_features;
5716 len = skb_inner_transport_header(skb) -
5717 skb_inner_network_header(skb);
5718 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
5719 goto out_rm_features;
5724 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
5727 static const struct net_device_ops ice_netdev_safe_mode_ops = {
5728 .ndo_open = ice_open,
5729 .ndo_stop = ice_stop,
5730 .ndo_start_xmit = ice_start_xmit,
5731 .ndo_set_mac_address = ice_set_mac_address,
5732 .ndo_validate_addr = eth_validate_addr,
5733 .ndo_change_mtu = ice_change_mtu,
5734 .ndo_get_stats64 = ice_get_stats64,
5735 .ndo_tx_timeout = ice_tx_timeout,
5738 static const struct net_device_ops ice_netdev_ops = {
5739 .ndo_open = ice_open,
5740 .ndo_stop = ice_stop,
5741 .ndo_start_xmit = ice_start_xmit,
5742 .ndo_features_check = ice_features_check,
5743 .ndo_set_rx_mode = ice_set_rx_mode,
5744 .ndo_set_mac_address = ice_set_mac_address,
5745 .ndo_validate_addr = eth_validate_addr,
5746 .ndo_change_mtu = ice_change_mtu,
5747 .ndo_get_stats64 = ice_get_stats64,
5748 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
5749 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
5750 .ndo_set_vf_mac = ice_set_vf_mac,
5751 .ndo_get_vf_config = ice_get_vf_cfg,
5752 .ndo_set_vf_trust = ice_set_vf_trust,
5753 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
5754 .ndo_set_vf_link_state = ice_set_vf_link_state,
5755 .ndo_get_vf_stats = ice_get_vf_stats,
5756 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
5757 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
5758 .ndo_set_features = ice_set_features,
5759 .ndo_bridge_getlink = ice_bridge_getlink,
5760 .ndo_bridge_setlink = ice_bridge_setlink,
5761 .ndo_fdb_add = ice_fdb_add,
5762 .ndo_fdb_del = ice_fdb_del,
5763 #ifdef CONFIG_RFS_ACCEL
5764 .ndo_rx_flow_steer = ice_rx_flow_steer,
5766 .ndo_tx_timeout = ice_tx_timeout,
5768 .ndo_xdp_xmit = ice_xdp_xmit,
5769 .ndo_xsk_wakeup = ice_xsk_wakeup,
5770 .ndo_udp_tunnel_add = ice_udp_tunnel_add,
5771 .ndo_udp_tunnel_del = ice_udp_tunnel_del,