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
10 #include "ice_dcb_lib.h"
12 #define DRV_VERSION "0.7.4-k"
13 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
14 const char ice_drv_ver[] = DRV_VERSION;
15 static const char ice_driver_string[] = DRV_SUMMARY;
16 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
19 MODULE_DESCRIPTION(DRV_SUMMARY);
20 MODULE_LICENSE("GPL v2");
21 MODULE_VERSION(DRV_VERSION);
23 static int debug = -1;
24 module_param(debug, int, 0644);
25 #ifndef CONFIG_DYNAMIC_DEBUG
26 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
28 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
29 #endif /* !CONFIG_DYNAMIC_DEBUG */
31 static struct workqueue_struct *ice_wq;
32 static const struct net_device_ops ice_netdev_ops;
34 static void ice_rebuild(struct ice_pf *pf);
36 static void ice_vsi_release_all(struct ice_pf *pf);
37 static void ice_update_vsi_stats(struct ice_vsi *vsi);
38 static void ice_update_pf_stats(struct ice_pf *pf);
41 * ice_get_tx_pending - returns number of Tx descriptors not processed
42 * @ring: the ring of descriptors
44 static u32 ice_get_tx_pending(struct ice_ring *ring)
48 head = ring->next_to_clean;
49 tail = readl(ring->tail);
52 return (head < tail) ?
53 tail - head : (tail + ring->count - head);
58 * ice_check_for_hang_subtask - check for and recover hung queues
59 * @pf: pointer to PF struct
61 static void ice_check_for_hang_subtask(struct ice_pf *pf)
63 struct ice_vsi *vsi = NULL;
69 ice_for_each_vsi(pf, v)
70 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
75 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
78 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
83 for (i = 0; i < vsi->num_txq; i++) {
84 struct ice_ring *tx_ring = vsi->tx_rings[i];
86 if (tx_ring && tx_ring->desc) {
87 /* If packet counter has not changed the queue is
88 * likely stalled, so force an interrupt for this
91 * prev_pkt would be negative if there was no
94 packets = tx_ring->stats.pkts & INT_MAX;
95 if (tx_ring->tx_stats.prev_pkt == packets) {
96 /* Trigger sw interrupt to revive the queue */
97 ice_trigger_sw_intr(hw, tx_ring->q_vector);
101 /* Memory barrier between read of packet count and call
102 * to ice_get_tx_pending()
105 tx_ring->tx_stats.prev_pkt =
106 ice_get_tx_pending(tx_ring) ? packets : -1;
112 * ice_init_mac_fltr - Set initial MAC filters
113 * @pf: board private structure
115 * Set initial set of MAC filters for PF VSI; configure filters for permanent
116 * address and broadcast address. If an error is encountered, netdevice will be
119 static int ice_init_mac_fltr(struct ice_pf *pf)
121 LIST_HEAD(tmp_add_list);
122 u8 broadcast[ETH_ALEN];
126 vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF);
130 /* To add a MAC filter, first add the MAC to a list and then
131 * pass the list to ice_add_mac.
134 /* Add a unicast MAC filter so the VSI can get its packets */
135 status = ice_add_mac_to_list(vsi, &tmp_add_list,
136 vsi->port_info->mac.perm_addr);
140 /* VSI needs to receive broadcast traffic, so add the broadcast
141 * MAC address to the list as well.
143 eth_broadcast_addr(broadcast);
144 status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
148 /* Program MAC filters for entries in tmp_add_list */
149 status = ice_add_mac(&pf->hw, &tmp_add_list);
154 ice_free_fltr_list(&pf->pdev->dev, &tmp_add_list);
157 /* We aren't useful with no MAC filters, so unregister if we
160 if (status && vsi->netdev->reg_state == NETREG_REGISTERED) {
161 dev_err(&pf->pdev->dev,
162 "Could not add MAC filters error %d. Unregistering device\n",
164 unregister_netdev(vsi->netdev);
165 free_netdev(vsi->netdev);
173 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
174 * @netdev: the net device on which the sync is happening
175 * @addr: MAC address to sync
177 * This is a callback function which is called by the in kernel device sync
178 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
179 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
180 * MAC filters from the hardware.
182 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
184 struct ice_netdev_priv *np = netdev_priv(netdev);
185 struct ice_vsi *vsi = np->vsi;
187 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
194 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
195 * @netdev: the net device on which the unsync is happening
196 * @addr: MAC address to unsync
198 * This is a callback function which is called by the in kernel device unsync
199 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
200 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
201 * delete the MAC filters from the hardware.
203 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
205 struct ice_netdev_priv *np = netdev_priv(netdev);
206 struct ice_vsi *vsi = np->vsi;
208 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
215 * ice_vsi_fltr_changed - check if filter state changed
216 * @vsi: VSI to be checked
218 * returns true if filter state has changed, false otherwise.
220 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
222 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
223 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
224 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
228 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
229 * @vsi: the VSI being configured
230 * @promisc_m: mask of promiscuous config bits
231 * @set_promisc: enable or disable promisc flag request
234 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
236 struct ice_hw *hw = &vsi->back->hw;
237 enum ice_status status = 0;
239 if (vsi->type != ICE_VSI_PF)
243 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
247 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
250 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
261 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
262 * @vsi: ptr to the VSI
264 * Push any outstanding VSI filter changes through the AdminQ.
266 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
268 struct device *dev = &vsi->back->pdev->dev;
269 struct net_device *netdev = vsi->netdev;
270 bool promisc_forced_on = false;
271 struct ice_pf *pf = vsi->back;
272 struct ice_hw *hw = &pf->hw;
273 enum ice_status status = 0;
274 u32 changed_flags = 0;
281 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
282 usleep_range(1000, 2000);
284 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
285 vsi->current_netdev_flags = vsi->netdev->flags;
287 INIT_LIST_HEAD(&vsi->tmp_sync_list);
288 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
290 if (ice_vsi_fltr_changed(vsi)) {
291 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
292 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
293 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
295 /* grab the netdev's addr_list_lock */
296 netif_addr_lock_bh(netdev);
297 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
298 ice_add_mac_to_unsync_list);
299 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
300 ice_add_mac_to_unsync_list);
301 /* our temp lists are populated. release lock */
302 netif_addr_unlock_bh(netdev);
305 /* Remove MAC addresses in the unsync list */
306 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
307 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
309 netdev_err(netdev, "Failed to delete MAC filters\n");
310 /* if we failed because of alloc failures, just bail */
311 if (status == ICE_ERR_NO_MEMORY) {
317 /* Add MAC addresses in the sync list */
318 status = ice_add_mac(hw, &vsi->tmp_sync_list);
319 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
320 /* If filter is added successfully or already exists, do not go into
321 * 'if' condition and report it as error. Instead continue processing
322 * rest of the function.
324 if (status && status != ICE_ERR_ALREADY_EXISTS) {
325 netdev_err(netdev, "Failed to add MAC filters\n");
326 /* If there is no more space for new umac filters, VSI
327 * should go into promiscuous mode. There should be some
328 * space reserved for promiscuous filters.
330 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
331 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
333 promisc_forced_on = true;
335 "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
342 /* check for changes in promiscuous modes */
343 if (changed_flags & IFF_ALLMULTI) {
344 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
346 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
348 promisc_m = ICE_MCAST_PROMISC_BITS;
350 err = ice_cfg_promisc(vsi, promisc_m, true);
352 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
354 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
357 } else if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
359 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
361 promisc_m = ICE_MCAST_PROMISC_BITS;
363 err = ice_cfg_promisc(vsi, promisc_m, false);
365 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
367 vsi->current_netdev_flags |= IFF_ALLMULTI;
373 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
374 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
375 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
376 if (vsi->current_netdev_flags & IFF_PROMISC) {
377 /* Apply Rx filter rule to get traffic from wire */
378 status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
381 netdev_err(netdev, "Error setting default VSI %i Rx rule\n",
383 vsi->current_netdev_flags &= ~IFF_PROMISC;
388 /* Clear Rx filter to remove traffic from wire */
389 status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
392 netdev_err(netdev, "Error clearing default VSI %i Rx rule\n",
394 vsi->current_netdev_flags |= IFF_PROMISC;
403 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
406 /* if something went wrong then set the changed flag so we try again */
407 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
408 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
410 clear_bit(__ICE_CFG_BUSY, vsi->state);
415 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
416 * @pf: board private structure
418 static void ice_sync_fltr_subtask(struct ice_pf *pf)
422 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
425 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
427 ice_for_each_vsi(pf, v)
428 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
429 ice_vsi_sync_fltr(pf->vsi[v])) {
430 /* come back and try again later */
431 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
437 * ice_dis_vsi - pause a VSI
438 * @vsi: the VSI being paused
439 * @locked: is the rtnl_lock already held
441 static void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
443 if (test_bit(__ICE_DOWN, vsi->state))
446 set_bit(__ICE_NEEDS_RESTART, vsi->state);
448 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
449 if (netif_running(vsi->netdev)) {
452 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
455 vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
464 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
466 * @locked: is the rtnl_lock already held
469 void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
471 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
472 #endif /* CONFIG_DCB */
476 ice_for_each_vsi(pf, v)
478 ice_dis_vsi(pf->vsi[v], locked);
482 * ice_prepare_for_reset - prep for the core to reset
483 * @pf: board private structure
485 * Inform or close all dependent features in prep for reset.
488 ice_prepare_for_reset(struct ice_pf *pf)
490 struct ice_hw *hw = &pf->hw;
492 /* already prepared for reset */
493 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
496 /* Notify VFs of impending reset */
497 if (ice_check_sq_alive(hw, &hw->mailboxq))
498 ice_vc_notify_reset(pf);
500 /* disable the VSIs and their queues that are not already DOWN */
501 ice_pf_dis_all_vsi(pf, false);
504 ice_sched_clear_port(hw->port_info);
506 ice_shutdown_all_ctrlq(hw);
508 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
512 * ice_do_reset - Initiate one of many types of resets
513 * @pf: board private structure
514 * @reset_type: reset type requested
515 * before this function was called.
517 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
519 struct device *dev = &pf->pdev->dev;
520 struct ice_hw *hw = &pf->hw;
522 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
523 WARN_ON(in_interrupt());
525 ice_prepare_for_reset(pf);
527 /* trigger the reset */
528 if (ice_reset(hw, reset_type)) {
529 dev_err(dev, "reset %d failed\n", reset_type);
530 set_bit(__ICE_RESET_FAILED, pf->state);
531 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
532 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
533 clear_bit(__ICE_PFR_REQ, pf->state);
534 clear_bit(__ICE_CORER_REQ, pf->state);
535 clear_bit(__ICE_GLOBR_REQ, pf->state);
539 /* PFR is a bit of a special case because it doesn't result in an OICR
540 * interrupt. So for PFR, rebuild after the reset and clear the reset-
541 * associated state bits.
543 if (reset_type == ICE_RESET_PFR) {
546 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
547 clear_bit(__ICE_PFR_REQ, pf->state);
548 ice_reset_all_vfs(pf, true);
553 * ice_reset_subtask - Set up for resetting the device and driver
554 * @pf: board private structure
556 static void ice_reset_subtask(struct ice_pf *pf)
558 enum ice_reset_req reset_type = ICE_RESET_INVAL;
560 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
561 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
562 * of reset is pending and sets bits in pf->state indicating the reset
563 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
564 * prepare for pending reset if not already (for PF software-initiated
565 * global resets the software should already be prepared for it as
566 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
567 * by firmware or software on other PFs, that bit is not set so prepare
568 * for the reset now), poll for reset done, rebuild and return.
570 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
571 /* Perform the largest reset requested */
572 if (test_and_clear_bit(__ICE_CORER_RECV, pf->state))
573 reset_type = ICE_RESET_CORER;
574 if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state))
575 reset_type = ICE_RESET_GLOBR;
576 /* return if no valid reset type requested */
577 if (reset_type == ICE_RESET_INVAL)
579 ice_prepare_for_reset(pf);
581 /* make sure we are ready to rebuild */
582 if (ice_check_reset(&pf->hw)) {
583 set_bit(__ICE_RESET_FAILED, pf->state);
585 /* done with reset. start rebuild */
586 pf->hw.reset_ongoing = false;
588 /* clear bit to resume normal operations, but
589 * ICE_NEEDS_RESTART bit is set in case rebuild failed
591 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
592 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
593 clear_bit(__ICE_PFR_REQ, pf->state);
594 clear_bit(__ICE_CORER_REQ, pf->state);
595 clear_bit(__ICE_GLOBR_REQ, pf->state);
596 ice_reset_all_vfs(pf, true);
602 /* No pending resets to finish processing. Check for new resets */
603 if (test_bit(__ICE_PFR_REQ, pf->state))
604 reset_type = ICE_RESET_PFR;
605 if (test_bit(__ICE_CORER_REQ, pf->state))
606 reset_type = ICE_RESET_CORER;
607 if (test_bit(__ICE_GLOBR_REQ, pf->state))
608 reset_type = ICE_RESET_GLOBR;
609 /* If no valid reset type requested just return */
610 if (reset_type == ICE_RESET_INVAL)
613 /* reset if not already down or busy */
614 if (!test_bit(__ICE_DOWN, pf->state) &&
615 !test_bit(__ICE_CFG_BUSY, pf->state)) {
616 ice_do_reset(pf, reset_type);
621 * ice_print_link_msg - print link up or down message
622 * @vsi: the VSI whose link status is being queried
623 * @isup: boolean for if the link is now up or down
625 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
627 struct ice_aqc_get_phy_caps_data *caps;
628 enum ice_status status;
637 if (vsi->current_isup == isup)
640 vsi->current_isup = isup;
643 netdev_info(vsi->netdev, "NIC Link is Down\n");
647 switch (vsi->port_info->phy.link_info.link_speed) {
648 case ICE_AQ_LINK_SPEED_100GB:
651 case ICE_AQ_LINK_SPEED_50GB:
654 case ICE_AQ_LINK_SPEED_40GB:
657 case ICE_AQ_LINK_SPEED_25GB:
660 case ICE_AQ_LINK_SPEED_20GB:
663 case ICE_AQ_LINK_SPEED_10GB:
666 case ICE_AQ_LINK_SPEED_5GB:
669 case ICE_AQ_LINK_SPEED_2500MB:
672 case ICE_AQ_LINK_SPEED_1000MB:
675 case ICE_AQ_LINK_SPEED_100MB:
683 switch (vsi->port_info->fc.current_mode) {
687 case ICE_FC_TX_PAUSE:
690 case ICE_FC_RX_PAUSE:
701 /* Get FEC mode based on negotiated link info */
702 switch (vsi->port_info->phy.link_info.fec_info) {
703 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
705 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
708 case ICE_AQ_LINK_25G_KR_FEC_EN:
709 fec = "FC-FEC/BASE-R";
716 /* Get FEC mode requested based on PHY caps last SW configuration */
717 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
723 status = ice_aq_get_phy_caps(vsi->port_info, false,
724 ICE_AQC_REPORT_SW_CFG, caps, NULL);
726 netdev_info(vsi->netdev, "Get phy capability failed.\n");
728 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
729 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
731 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
732 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
733 fec_req = "FC-FEC/BASE-R";
737 devm_kfree(&vsi->back->pdev->dev, caps);
740 netdev_info(vsi->netdev, "NIC Link is up %sbps, Requested FEC: %s, FEC: %s, Flow Control: %s\n",
741 speed, fec_req, fec, fc);
745 * ice_vsi_link_event - update the VSI's netdev
746 * @vsi: the VSI on which the link event occurred
747 * @link_up: whether or not the VSI needs to be set up or down
749 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
754 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
757 if (vsi->type == ICE_VSI_PF) {
758 if (link_up == netif_carrier_ok(vsi->netdev))
762 netif_carrier_on(vsi->netdev);
763 netif_tx_wake_all_queues(vsi->netdev);
765 netif_carrier_off(vsi->netdev);
766 netif_tx_stop_all_queues(vsi->netdev);
772 * ice_link_event - process the link event
773 * @pf: PF that the link event is associated with
774 * @pi: port_info for the port that the link event is associated with
775 * @link_up: true if the physical link is up and false if it is down
776 * @link_speed: current link speed received from the link event
778 * Returns 0 on success and negative on failure
781 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
784 struct ice_phy_info *phy_info;
791 phy_info->link_info_old = phy_info->link_info;
793 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
794 old_link_speed = phy_info->link_info_old.link_speed;
796 /* update the link info structures and re-enable link events,
797 * don't bail on failure due to other book keeping needed
799 result = ice_update_link_info(pi);
801 dev_dbg(&pf->pdev->dev,
802 "Failed to update link status and re-enable link events for port %d\n",
805 /* if the old link up/down and speed is the same as the new */
806 if (link_up == old_link && link_speed == old_link_speed)
809 vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF);
810 if (!vsi || !vsi->port_info)
813 ice_vsi_link_event(vsi, link_up);
814 ice_print_link_msg(vsi, link_up);
816 if (pf->num_alloc_vfs)
817 ice_vc_notify_link_state(pf);
823 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
824 * @pf: board private structure
826 static void ice_watchdog_subtask(struct ice_pf *pf)
830 /* if interface is down do nothing */
831 if (test_bit(__ICE_DOWN, pf->state) ||
832 test_bit(__ICE_CFG_BUSY, pf->state))
835 /* make sure we don't do these things too often */
836 if (time_before(jiffies,
837 pf->serv_tmr_prev + pf->serv_tmr_period))
840 pf->serv_tmr_prev = jiffies;
842 /* Update the stats for active netdevs so the network stack
843 * can look at updated numbers whenever it cares to
845 ice_update_pf_stats(pf);
846 ice_for_each_vsi(pf, i)
847 if (pf->vsi[i] && pf->vsi[i]->netdev)
848 ice_update_vsi_stats(pf->vsi[i]);
852 * ice_init_link_events - enable/initialize link events
853 * @pi: pointer to the port_info instance
855 * Returns -EIO on failure, 0 on success
857 static int ice_init_link_events(struct ice_port_info *pi)
861 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
862 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
864 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
865 dev_dbg(ice_hw_to_dev(pi->hw),
866 "Failed to set link event mask for port %d\n",
871 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
872 dev_dbg(ice_hw_to_dev(pi->hw),
873 "Failed to enable link events for port %d\n",
882 * ice_handle_link_event - handle link event via ARQ
883 * @pf: PF that the link event is associated with
884 * @event: event structure containing link status info
887 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
889 struct ice_aqc_get_link_status_data *link_data;
890 struct ice_port_info *port_info;
893 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
894 port_info = pf->hw.port_info;
898 status = ice_link_event(pf, port_info,
899 !!(link_data->link_info & ICE_AQ_LINK_UP),
900 le16_to_cpu(link_data->link_speed));
902 dev_dbg(&pf->pdev->dev,
903 "Could not process link event, error %d\n", status);
909 * __ice_clean_ctrlq - helper function to clean controlq rings
910 * @pf: ptr to struct ice_pf
911 * @q_type: specific Control queue type
913 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
915 struct ice_rq_event_info event;
916 struct ice_hw *hw = &pf->hw;
917 struct ice_ctl_q_info *cq;
922 /* Do not clean control queue if/when PF reset fails */
923 if (test_bit(__ICE_RESET_FAILED, pf->state))
927 case ICE_CTL_Q_ADMIN:
931 case ICE_CTL_Q_MAILBOX:
936 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
941 /* check for error indications - PF_xx_AxQLEN register layout for
942 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
944 val = rd32(hw, cq->rq.len);
945 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
946 PF_FW_ARQLEN_ARQCRIT_M)) {
948 if (val & PF_FW_ARQLEN_ARQVFE_M)
949 dev_dbg(&pf->pdev->dev,
950 "%s Receive Queue VF Error detected\n", qtype);
951 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
952 dev_dbg(&pf->pdev->dev,
953 "%s Receive Queue Overflow Error detected\n",
956 if (val & PF_FW_ARQLEN_ARQCRIT_M)
957 dev_dbg(&pf->pdev->dev,
958 "%s Receive Queue Critical Error detected\n",
960 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
961 PF_FW_ARQLEN_ARQCRIT_M);
963 wr32(hw, cq->rq.len, val);
966 val = rd32(hw, cq->sq.len);
967 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
968 PF_FW_ATQLEN_ATQCRIT_M)) {
970 if (val & PF_FW_ATQLEN_ATQVFE_M)
971 dev_dbg(&pf->pdev->dev,
972 "%s Send Queue VF Error detected\n", qtype);
973 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
974 dev_dbg(&pf->pdev->dev,
975 "%s Send Queue Overflow Error detected\n",
978 if (val & PF_FW_ATQLEN_ATQCRIT_M)
979 dev_dbg(&pf->pdev->dev,
980 "%s Send Queue Critical Error detected\n",
982 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
983 PF_FW_ATQLEN_ATQCRIT_M);
985 wr32(hw, cq->sq.len, val);
988 event.buf_len = cq->rq_buf_size;
989 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
998 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
999 if (ret == ICE_ERR_AQ_NO_WORK)
1002 dev_err(&pf->pdev->dev,
1003 "%s Receive Queue event error %d\n", qtype,
1008 opcode = le16_to_cpu(event.desc.opcode);
1011 case ice_aqc_opc_get_link_status:
1012 if (ice_handle_link_event(pf, &event))
1013 dev_err(&pf->pdev->dev,
1014 "Could not handle link event\n");
1016 case ice_mbx_opc_send_msg_to_pf:
1017 ice_vc_process_vf_msg(pf, &event);
1019 case ice_aqc_opc_fw_logging:
1020 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1022 case ice_aqc_opc_lldp_set_mib_change:
1023 ice_dcb_process_lldp_set_mib_change(pf, &event);
1026 dev_dbg(&pf->pdev->dev,
1027 "%s Receive Queue unknown event 0x%04x ignored\n",
1031 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1033 devm_kfree(&pf->pdev->dev, event.msg_buf);
1035 return pending && (i == ICE_DFLT_IRQ_WORK);
1039 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1040 * @hw: pointer to hardware info
1041 * @cq: control queue information
1043 * returns true if there are pending messages in a queue, false if there aren't
1045 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1049 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1050 return cq->rq.next_to_clean != ntu;
1054 * ice_clean_adminq_subtask - clean the AdminQ rings
1055 * @pf: board private structure
1057 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1059 struct ice_hw *hw = &pf->hw;
1061 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1064 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1067 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1069 /* There might be a situation where new messages arrive to a control
1070 * queue between processing the last message and clearing the
1071 * EVENT_PENDING bit. So before exiting, check queue head again (using
1072 * ice_ctrlq_pending) and process new messages if any.
1074 if (ice_ctrlq_pending(hw, &hw->adminq))
1075 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1081 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1082 * @pf: board private structure
1084 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1086 struct ice_hw *hw = &pf->hw;
1088 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1091 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1094 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1096 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1097 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1103 * ice_service_task_schedule - schedule the service task to wake up
1104 * @pf: board private structure
1106 * If not already scheduled, this puts the task into the work queue.
1108 static void ice_service_task_schedule(struct ice_pf *pf)
1110 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1111 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1112 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1113 queue_work(ice_wq, &pf->serv_task);
1117 * ice_service_task_complete - finish up the service task
1118 * @pf: board private structure
1120 static void ice_service_task_complete(struct ice_pf *pf)
1122 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1124 /* force memory (pf->state) to sync before next service task */
1125 smp_mb__before_atomic();
1126 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1130 * ice_service_task_stop - stop service task and cancel works
1131 * @pf: board private structure
1133 static void ice_service_task_stop(struct ice_pf *pf)
1135 set_bit(__ICE_SERVICE_DIS, pf->state);
1137 if (pf->serv_tmr.function)
1138 del_timer_sync(&pf->serv_tmr);
1139 if (pf->serv_task.func)
1140 cancel_work_sync(&pf->serv_task);
1142 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1146 * ice_service_task_restart - restart service task and schedule works
1147 * @pf: board private structure
1149 * This function is needed for suspend and resume works (e.g WoL scenario)
1151 static void ice_service_task_restart(struct ice_pf *pf)
1153 clear_bit(__ICE_SERVICE_DIS, pf->state);
1154 ice_service_task_schedule(pf);
1158 * ice_service_timer - timer callback to schedule service task
1159 * @t: pointer to timer_list
1161 static void ice_service_timer(struct timer_list *t)
1163 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1165 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1166 ice_service_task_schedule(pf);
1170 * ice_handle_mdd_event - handle malicious driver detect event
1171 * @pf: pointer to the PF structure
1173 * Called from service task. OICR interrupt handler indicates MDD event
1175 static void ice_handle_mdd_event(struct ice_pf *pf)
1177 struct ice_hw *hw = &pf->hw;
1178 bool mdd_detected = false;
1182 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1185 /* find what triggered the MDD event */
1186 reg = rd32(hw, GL_MDET_TX_PQM);
1187 if (reg & GL_MDET_TX_PQM_VALID_M) {
1188 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1189 GL_MDET_TX_PQM_PF_NUM_S;
1190 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1191 GL_MDET_TX_PQM_VF_NUM_S;
1192 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1193 GL_MDET_TX_PQM_MAL_TYPE_S;
1194 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1195 GL_MDET_TX_PQM_QNUM_S);
1197 if (netif_msg_tx_err(pf))
1198 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1199 event, queue, pf_num, vf_num);
1200 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1201 mdd_detected = true;
1204 reg = rd32(hw, GL_MDET_TX_TCLAN);
1205 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1206 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1207 GL_MDET_TX_TCLAN_PF_NUM_S;
1208 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1209 GL_MDET_TX_TCLAN_VF_NUM_S;
1210 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1211 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1212 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1213 GL_MDET_TX_TCLAN_QNUM_S);
1215 if (netif_msg_rx_err(pf))
1216 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1217 event, queue, pf_num, vf_num);
1218 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1219 mdd_detected = true;
1222 reg = rd32(hw, GL_MDET_RX);
1223 if (reg & GL_MDET_RX_VALID_M) {
1224 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1225 GL_MDET_RX_PF_NUM_S;
1226 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1227 GL_MDET_RX_VF_NUM_S;
1228 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1229 GL_MDET_RX_MAL_TYPE_S;
1230 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1233 if (netif_msg_rx_err(pf))
1234 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1235 event, queue, pf_num, vf_num);
1236 wr32(hw, GL_MDET_RX, 0xffffffff);
1237 mdd_detected = true;
1241 bool pf_mdd_detected = false;
1243 reg = rd32(hw, PF_MDET_TX_PQM);
1244 if (reg & PF_MDET_TX_PQM_VALID_M) {
1245 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1246 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1247 pf_mdd_detected = true;
1250 reg = rd32(hw, PF_MDET_TX_TCLAN);
1251 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1252 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1253 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1254 pf_mdd_detected = true;
1257 reg = rd32(hw, PF_MDET_RX);
1258 if (reg & PF_MDET_RX_VALID_M) {
1259 wr32(hw, PF_MDET_RX, 0xFFFF);
1260 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
1261 pf_mdd_detected = true;
1263 /* Queue belongs to the PF initiate a reset */
1264 if (pf_mdd_detected) {
1265 set_bit(__ICE_NEEDS_RESTART, pf->state);
1266 ice_service_task_schedule(pf);
1270 /* check to see if one of the VFs caused the MDD */
1271 for (i = 0; i < pf->num_alloc_vfs; i++) {
1272 struct ice_vf *vf = &pf->vf[i];
1274 bool vf_mdd_detected = false;
1276 reg = rd32(hw, VP_MDET_TX_PQM(i));
1277 if (reg & VP_MDET_TX_PQM_VALID_M) {
1278 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1279 vf_mdd_detected = true;
1280 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1284 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1285 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1286 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1287 vf_mdd_detected = true;
1288 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1292 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1293 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1294 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1295 vf_mdd_detected = true;
1296 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1300 reg = rd32(hw, VP_MDET_RX(i));
1301 if (reg & VP_MDET_RX_VALID_M) {
1302 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1303 vf_mdd_detected = true;
1304 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1308 if (vf_mdd_detected) {
1309 vf->num_mdd_events++;
1310 if (vf->num_mdd_events > 1)
1311 dev_info(&pf->pdev->dev, "VF %d has had %llu MDD events since last boot\n",
1312 i, vf->num_mdd_events);
1318 * ice_service_task - manage and run subtasks
1319 * @work: pointer to work_struct contained by the PF struct
1321 static void ice_service_task(struct work_struct *work)
1323 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1324 unsigned long start_time = jiffies;
1328 /* process reset requests first */
1329 ice_reset_subtask(pf);
1331 /* bail if a reset/recovery cycle is pending or rebuild failed */
1332 if (ice_is_reset_in_progress(pf->state) ||
1333 test_bit(__ICE_SUSPENDED, pf->state) ||
1334 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1335 ice_service_task_complete(pf);
1339 ice_check_for_hang_subtask(pf);
1340 ice_sync_fltr_subtask(pf);
1341 ice_handle_mdd_event(pf);
1342 ice_process_vflr_event(pf);
1343 ice_watchdog_subtask(pf);
1344 ice_clean_adminq_subtask(pf);
1345 ice_clean_mailboxq_subtask(pf);
1347 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1348 ice_service_task_complete(pf);
1350 /* If the tasks have taken longer than one service timer period
1351 * or there is more work to be done, reset the service timer to
1352 * schedule the service task now.
1354 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1355 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1356 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1357 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1358 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1359 mod_timer(&pf->serv_tmr, jiffies);
1363 * ice_set_ctrlq_len - helper function to set controlq length
1364 * @hw: pointer to the HW instance
1366 static void ice_set_ctrlq_len(struct ice_hw *hw)
1368 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1369 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1370 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1371 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1372 hw->mailboxq.num_rq_entries = ICE_MBXQ_LEN;
1373 hw->mailboxq.num_sq_entries = ICE_MBXQ_LEN;
1374 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1375 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1379 * ice_irq_affinity_notify - Callback for affinity changes
1380 * @notify: context as to what irq was changed
1381 * @mask: the new affinity mask
1383 * This is a callback function used by the irq_set_affinity_notifier function
1384 * so that we may register to receive changes to the irq affinity masks.
1387 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1388 const cpumask_t *mask)
1390 struct ice_q_vector *q_vector =
1391 container_of(notify, struct ice_q_vector, affinity_notify);
1393 cpumask_copy(&q_vector->affinity_mask, mask);
1397 * ice_irq_affinity_release - Callback for affinity notifier release
1398 * @ref: internal core kernel usage
1400 * This is a callback function used by the irq_set_affinity_notifier function
1401 * to inform the current notification subscriber that they will no longer
1402 * receive notifications.
1404 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1407 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1408 * @vsi: the VSI being configured
1410 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1412 struct ice_pf *pf = vsi->back;
1413 struct ice_hw *hw = &pf->hw;
1415 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1418 ice_for_each_q_vector(vsi, i)
1419 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1427 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1428 * @vsi: the VSI being configured
1429 * @basename: name for the vector
1431 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1433 int q_vectors = vsi->num_q_vectors;
1434 struct ice_pf *pf = vsi->back;
1435 int base = vsi->base_vector;
1441 for (vector = 0; vector < q_vectors; vector++) {
1442 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1444 irq_num = pf->msix_entries[base + vector].vector;
1446 if (q_vector->tx.ring && q_vector->rx.ring) {
1447 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1448 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1450 } else if (q_vector->rx.ring) {
1451 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1452 "%s-%s-%d", basename, "rx", rx_int_idx++);
1453 } else if (q_vector->tx.ring) {
1454 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1455 "%s-%s-%d", basename, "tx", tx_int_idx++);
1457 /* skip this unused q_vector */
1460 err = devm_request_irq(&pf->pdev->dev, irq_num,
1461 vsi->irq_handler, 0,
1462 q_vector->name, q_vector);
1464 netdev_err(vsi->netdev,
1465 "MSIX request_irq failed, error: %d\n", err);
1469 /* register for affinity change notifications */
1470 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1471 q_vector->affinity_notify.release = ice_irq_affinity_release;
1472 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1474 /* assign the mask for this irq */
1475 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1478 vsi->irqs_ready = true;
1484 irq_num = pf->msix_entries[base + vector].vector,
1485 irq_set_affinity_notifier(irq_num, NULL);
1486 irq_set_affinity_hint(irq_num, NULL);
1487 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1493 * ice_ena_misc_vector - enable the non-queue interrupts
1494 * @pf: board private structure
1496 static void ice_ena_misc_vector(struct ice_pf *pf)
1498 struct ice_hw *hw = &pf->hw;
1501 /* clear things first */
1502 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1503 rd32(hw, PFINT_OICR); /* read to clear */
1505 val = (PFINT_OICR_ECC_ERR_M |
1506 PFINT_OICR_MAL_DETECT_M |
1508 PFINT_OICR_PCI_EXCEPTION_M |
1510 PFINT_OICR_HMC_ERR_M |
1511 PFINT_OICR_PE_CRITERR_M);
1513 wr32(hw, PFINT_OICR_ENA, val);
1515 /* SW_ITR_IDX = 0, but don't change INTENA */
1516 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
1517 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1521 * ice_misc_intr - misc interrupt handler
1522 * @irq: interrupt number
1523 * @data: pointer to a q_vector
1525 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1527 struct ice_pf *pf = (struct ice_pf *)data;
1528 struct ice_hw *hw = &pf->hw;
1529 irqreturn_t ret = IRQ_NONE;
1532 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1533 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1535 oicr = rd32(hw, PFINT_OICR);
1536 ena_mask = rd32(hw, PFINT_OICR_ENA);
1538 if (oicr & PFINT_OICR_SWINT_M) {
1539 ena_mask &= ~PFINT_OICR_SWINT_M;
1543 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1544 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1545 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1547 if (oicr & PFINT_OICR_VFLR_M) {
1548 ena_mask &= ~PFINT_OICR_VFLR_M;
1549 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1552 if (oicr & PFINT_OICR_GRST_M) {
1555 /* we have a reset warning */
1556 ena_mask &= ~PFINT_OICR_GRST_M;
1557 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1558 GLGEN_RSTAT_RESET_TYPE_S;
1560 if (reset == ICE_RESET_CORER)
1562 else if (reset == ICE_RESET_GLOBR)
1564 else if (reset == ICE_RESET_EMPR)
1567 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1570 /* If a reset cycle isn't already in progress, we set a bit in
1571 * pf->state so that the service task can start a reset/rebuild.
1572 * We also make note of which reset happened so that peer
1573 * devices/drivers can be informed.
1575 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1576 if (reset == ICE_RESET_CORER)
1577 set_bit(__ICE_CORER_RECV, pf->state);
1578 else if (reset == ICE_RESET_GLOBR)
1579 set_bit(__ICE_GLOBR_RECV, pf->state);
1581 set_bit(__ICE_EMPR_RECV, pf->state);
1583 /* There are couple of different bits at play here.
1584 * hw->reset_ongoing indicates whether the hardware is
1585 * in reset. This is set to true when a reset interrupt
1586 * is received and set back to false after the driver
1587 * has determined that the hardware is out of reset.
1589 * __ICE_RESET_OICR_RECV in pf->state indicates
1590 * that a post reset rebuild is required before the
1591 * driver is operational again. This is set above.
1593 * As this is the start of the reset/rebuild cycle, set
1594 * both to indicate that.
1596 hw->reset_ongoing = true;
1600 if (oicr & PFINT_OICR_HMC_ERR_M) {
1601 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1602 dev_dbg(&pf->pdev->dev,
1603 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1604 rd32(hw, PFHMC_ERRORINFO),
1605 rd32(hw, PFHMC_ERRORDATA));
1608 /* Report any remaining unexpected interrupts */
1611 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1613 /* If a critical error is pending there is no choice but to
1616 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1617 PFINT_OICR_PCI_EXCEPTION_M |
1618 PFINT_OICR_ECC_ERR_M)) {
1619 set_bit(__ICE_PFR_REQ, pf->state);
1620 ice_service_task_schedule(pf);
1625 if (!test_bit(__ICE_DOWN, pf->state)) {
1626 ice_service_task_schedule(pf);
1627 ice_irq_dynamic_ena(hw, NULL, NULL);
1634 * ice_dis_ctrlq_interrupts - disable control queue interrupts
1635 * @hw: pointer to HW structure
1637 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
1639 /* disable Admin queue Interrupt causes */
1640 wr32(hw, PFINT_FW_CTL,
1641 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
1643 /* disable Mailbox queue Interrupt causes */
1644 wr32(hw, PFINT_MBX_CTL,
1645 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
1647 /* disable Control queue Interrupt causes */
1648 wr32(hw, PFINT_OICR_CTL,
1649 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
1655 * ice_free_irq_msix_misc - Unroll misc vector setup
1656 * @pf: board private structure
1658 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1660 struct ice_hw *hw = &pf->hw;
1662 ice_dis_ctrlq_interrupts(hw);
1664 /* disable OICR interrupt */
1665 wr32(hw, PFINT_OICR_ENA, 0);
1668 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
1669 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
1670 devm_free_irq(&pf->pdev->dev,
1671 pf->msix_entries[pf->oicr_idx].vector, pf);
1674 pf->num_avail_sw_msix += 1;
1675 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
1679 * ice_ena_ctrlq_interrupts - enable control queue interrupts
1680 * @hw: pointer to HW structure
1681 * @reg_idx: HW vector index to associate the control queue interrupts with
1683 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
1687 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1688 PFINT_OICR_CTL_CAUSE_ENA_M);
1689 wr32(hw, PFINT_OICR_CTL, val);
1691 /* enable Admin queue Interrupt causes */
1692 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1693 PFINT_FW_CTL_CAUSE_ENA_M);
1694 wr32(hw, PFINT_FW_CTL, val);
1696 /* enable Mailbox queue Interrupt causes */
1697 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1698 PFINT_MBX_CTL_CAUSE_ENA_M);
1699 wr32(hw, PFINT_MBX_CTL, val);
1705 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1706 * @pf: board private structure
1708 * This sets up the handler for MSIX 0, which is used to manage the
1709 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1710 * when in MSI or Legacy interrupt mode.
1712 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1714 struct ice_hw *hw = &pf->hw;
1715 int oicr_idx, err = 0;
1717 if (!pf->int_name[0])
1718 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1719 dev_driver_string(&pf->pdev->dev),
1720 dev_name(&pf->pdev->dev));
1722 /* Do not request IRQ but do enable OICR interrupt since settings are
1723 * lost during reset. Note that this function is called only during
1724 * rebuild path and not while reset is in progress.
1726 if (ice_is_reset_in_progress(pf->state))
1729 /* reserve one vector in irq_tracker for misc interrupts */
1730 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1734 pf->num_avail_sw_msix -= 1;
1735 pf->oicr_idx = oicr_idx;
1737 err = devm_request_irq(&pf->pdev->dev,
1738 pf->msix_entries[pf->oicr_idx].vector,
1739 ice_misc_intr, 0, pf->int_name, pf);
1741 dev_err(&pf->pdev->dev,
1742 "devm_request_irq for %s failed: %d\n",
1744 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1745 pf->num_avail_sw_msix += 1;
1750 ice_ena_misc_vector(pf);
1752 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
1753 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
1754 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
1757 ice_irq_dynamic_ena(hw, NULL, NULL);
1763 * ice_napi_add - register NAPI handler for the VSI
1764 * @vsi: VSI for which NAPI handler is to be registered
1766 * This function is only called in the driver's load path. Registering the NAPI
1767 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1768 * reset/rebuild, etc.)
1770 static void ice_napi_add(struct ice_vsi *vsi)
1777 ice_for_each_q_vector(vsi, v_idx)
1778 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1779 ice_napi_poll, NAPI_POLL_WEIGHT);
1783 * ice_cfg_netdev - Allocate, configure and register a netdev
1784 * @vsi: the VSI associated with the new netdev
1786 * Returns 0 on success, negative value on failure
1788 static int ice_cfg_netdev(struct ice_vsi *vsi)
1790 netdev_features_t csumo_features;
1791 netdev_features_t vlano_features;
1792 netdev_features_t dflt_features;
1793 netdev_features_t tso_features;
1794 struct ice_netdev_priv *np;
1795 struct net_device *netdev;
1796 u8 mac_addr[ETH_ALEN];
1799 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
1804 vsi->netdev = netdev;
1805 np = netdev_priv(netdev);
1808 dflt_features = NETIF_F_SG |
1812 csumo_features = NETIF_F_RXCSUM |
1817 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1818 NETIF_F_HW_VLAN_CTAG_TX |
1819 NETIF_F_HW_VLAN_CTAG_RX;
1821 tso_features = NETIF_F_TSO;
1823 /* set features that user can change */
1824 netdev->hw_features = dflt_features | csumo_features |
1825 vlano_features | tso_features;
1827 /* enable features */
1828 netdev->features |= netdev->hw_features;
1829 /* encap and VLAN devices inherit default, csumo and tso features */
1830 netdev->hw_enc_features |= dflt_features | csumo_features |
1832 netdev->vlan_features |= dflt_features | csumo_features |
1835 if (vsi->type == ICE_VSI_PF) {
1836 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1837 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1839 ether_addr_copy(netdev->dev_addr, mac_addr);
1840 ether_addr_copy(netdev->perm_addr, mac_addr);
1843 netdev->priv_flags |= IFF_UNICAST_FLT;
1845 /* assign netdev_ops */
1846 netdev->netdev_ops = &ice_netdev_ops;
1848 /* setup watchdog timeout value to be 5 second */
1849 netdev->watchdog_timeo = 5 * HZ;
1851 ice_set_ethtool_ops(netdev);
1853 netdev->min_mtu = ETH_MIN_MTU;
1854 netdev->max_mtu = ICE_MAX_MTU;
1856 err = register_netdev(vsi->netdev);
1860 netif_carrier_off(vsi->netdev);
1862 /* make sure transmit queues start off as stopped */
1863 netif_tx_stop_all_queues(vsi->netdev);
1869 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1870 * @lut: Lookup table
1871 * @rss_table_size: Lookup table size
1872 * @rss_size: Range of queue number for hashing
1874 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1878 for (i = 0; i < rss_table_size; i++)
1879 lut[i] = i % rss_size;
1883 * ice_pf_vsi_setup - Set up a PF VSI
1884 * @pf: board private structure
1885 * @pi: pointer to the port_info instance
1887 * Returns pointer to the successfully allocated VSI software struct
1888 * on success, otherwise returns NULL on failure.
1890 static struct ice_vsi *
1891 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1893 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
1897 * ice_lb_vsi_setup - Set up a loopback VSI
1898 * @pf: board private structure
1899 * @pi: pointer to the port_info instance
1901 * Returns pointer to the successfully allocated VSI software struct
1902 * on success, otherwise returns NULL on failure.
1905 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1907 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
1911 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
1912 * @netdev: network interface to be adjusted
1913 * @proto: unused protocol
1914 * @vid: VLAN ID to be added
1916 * net_device_ops implementation for adding VLAN IDs
1919 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
1922 struct ice_netdev_priv *np = netdev_priv(netdev);
1923 struct ice_vsi *vsi = np->vsi;
1926 if (vid >= VLAN_N_VID) {
1927 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
1935 /* Enable VLAN pruning when VLAN 0 is added */
1936 if (unlikely(!vid)) {
1937 ret = ice_cfg_vlan_pruning(vsi, true, false);
1942 /* Add all VLAN IDs including 0 to the switch filter. VLAN ID 0 is
1943 * needed to continue allowing all untagged packets since VLAN prune
1944 * list is applied to all packets by the switch
1946 ret = ice_vsi_add_vlan(vsi, vid);
1948 vsi->vlan_ena = true;
1949 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
1956 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
1957 * @netdev: network interface to be adjusted
1958 * @proto: unused protocol
1959 * @vid: VLAN ID to be removed
1961 * net_device_ops implementation for removing VLAN IDs
1964 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
1967 struct ice_netdev_priv *np = netdev_priv(netdev);
1968 struct ice_vsi *vsi = np->vsi;
1974 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
1977 ret = ice_vsi_kill_vlan(vsi, vid);
1981 /* Disable VLAN pruning when VLAN 0 is removed */
1983 ret = ice_cfg_vlan_pruning(vsi, false, false);
1985 vsi->vlan_ena = false;
1986 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
1991 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
1992 * @pf: board private structure
1994 * Returns 0 on success, negative value on failure
1996 static int ice_setup_pf_sw(struct ice_pf *pf)
1998 struct ice_vsi *vsi;
2001 if (ice_is_reset_in_progress(pf->state))
2004 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2007 goto unroll_vsi_setup;
2010 status = ice_cfg_netdev(vsi);
2013 goto unroll_vsi_setup;
2016 /* registering the NAPI handler requires both the queues and
2017 * netdev to be created, which are done in ice_pf_vsi_setup()
2018 * and ice_cfg_netdev() respectively
2022 status = ice_init_mac_fltr(pf);
2024 goto unroll_napi_add;
2032 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2033 unregister_netdev(vsi->netdev);
2034 free_netdev(vsi->netdev);
2041 ice_vsi_free_q_vectors(vsi);
2042 ice_vsi_delete(vsi);
2043 ice_vsi_put_qs(vsi);
2044 pf->q_left_tx += vsi->alloc_txq;
2045 pf->q_left_rx += vsi->alloc_rxq;
2052 * ice_determine_q_usage - Calculate queue distribution
2053 * @pf: board private structure
2055 * Return -ENOMEM if we don't get enough queues for all ports
2057 static void ice_determine_q_usage(struct ice_pf *pf)
2059 u16 q_left_tx, q_left_rx;
2061 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
2062 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
2064 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
2066 /* only 1 Rx queue unless RSS is enabled */
2067 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2070 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
2072 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
2073 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
2077 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2078 * @pf: board private structure to initialize
2080 static void ice_deinit_pf(struct ice_pf *pf)
2082 ice_service_task_stop(pf);
2083 mutex_destroy(&pf->sw_mutex);
2084 mutex_destroy(&pf->avail_q_mutex);
2088 * ice_init_pf - Initialize general software structures (struct ice_pf)
2089 * @pf: board private structure to initialize
2091 static void ice_init_pf(struct ice_pf *pf)
2093 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
2094 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2095 #ifdef CONFIG_PCI_IOV
2096 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
2097 struct ice_hw *hw = &pf->hw;
2099 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2100 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
2103 #endif /* CONFIG_PCI_IOV */
2105 mutex_init(&pf->sw_mutex);
2106 mutex_init(&pf->avail_q_mutex);
2108 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
2109 mutex_lock(&pf->avail_q_mutex);
2110 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
2111 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
2112 mutex_unlock(&pf->avail_q_mutex);
2114 if (pf->hw.func_caps.common_cap.rss_table_size)
2115 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2117 /* setup service timer and periodic service task */
2118 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2119 pf->serv_tmr_period = HZ;
2120 INIT_WORK(&pf->serv_task, ice_service_task);
2121 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2125 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2126 * @pf: board private structure
2128 * compute the number of MSIX vectors required (v_budget) and request from
2129 * the OS. Return the number of vectors reserved or negative on failure
2131 static int ice_ena_msix_range(struct ice_pf *pf)
2133 int v_left, v_actual, v_budget = 0;
2136 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2138 /* reserve one vector for miscellaneous handler */
2143 /* reserve vectors for LAN traffic */
2144 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
2145 v_budget += pf->num_lan_msix;
2146 v_left -= pf->num_lan_msix;
2148 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
2149 sizeof(*pf->msix_entries), GFP_KERNEL);
2151 if (!pf->msix_entries) {
2156 for (i = 0; i < v_budget; i++)
2157 pf->msix_entries[i].entry = i;
2159 /* actually reserve the vectors */
2160 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2161 ICE_MIN_MSIX, v_budget);
2164 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
2169 if (v_actual < v_budget) {
2170 dev_warn(&pf->pdev->dev,
2171 "not enough vectors. requested = %d, obtained = %d\n",
2172 v_budget, v_actual);
2173 if (v_actual >= (pf->num_lan_msix + 1)) {
2174 pf->num_avail_sw_msix = v_actual -
2175 (pf->num_lan_msix + 1);
2176 } else if (v_actual >= 2) {
2177 pf->num_lan_msix = 1;
2178 pf->num_avail_sw_msix = v_actual - 2;
2180 pci_disable_msix(pf->pdev);
2189 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2193 pf->num_lan_msix = 0;
2194 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2199 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2200 * @pf: board private structure
2202 static void ice_dis_msix(struct ice_pf *pf)
2204 pci_disable_msix(pf->pdev);
2205 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2206 pf->msix_entries = NULL;
2207 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2211 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2212 * @pf: board private structure
2214 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2216 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2219 if (pf->irq_tracker) {
2220 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
2221 pf->irq_tracker = NULL;
2226 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2227 * @pf: board private structure to initialize
2229 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2233 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2234 vectors = ice_ena_msix_range(pf);
2241 /* set up vector assignment tracking */
2243 devm_kzalloc(&pf->pdev->dev, sizeof(*pf->irq_tracker) +
2244 (sizeof(u16) * vectors), GFP_KERNEL);
2245 if (!pf->irq_tracker) {
2250 /* populate SW interrupts pool with number of OS granted IRQs. */
2251 pf->num_avail_sw_msix = vectors;
2252 pf->irq_tracker->num_entries = vectors;
2253 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2259 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
2260 * @pf: pointer to the PF structure
2262 * There is no error returned here because the driver should be able to handle
2263 * 128 Byte cache lines, so we only print a warning in case issues are seen,
2264 * specifically with Tx.
2266 static void ice_verify_cacheline_size(struct ice_pf *pf)
2268 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
2269 dev_warn(&pf->pdev->dev,
2270 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
2271 ICE_CACHE_LINE_BYTES);
2275 * ice_probe - Device initialization routine
2276 * @pdev: PCI device information struct
2277 * @ent: entry in ice_pci_tbl
2279 * Returns 0 on success, negative on failure
2282 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
2284 struct device *dev = &pdev->dev;
2289 /* this driver uses devres, see Documentation/driver-model/devres.rst */
2290 err = pcim_enable_device(pdev);
2294 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2296 dev_err(dev, "BAR0 I/O map error %d\n", err);
2300 pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
2304 /* set up for high or low DMA */
2305 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2307 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
2309 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
2313 pci_enable_pcie_error_reporting(pdev);
2314 pci_set_master(pdev);
2317 pci_set_drvdata(pdev, pf);
2318 set_bit(__ICE_DOWN, pf->state);
2319 /* Disable service task until DOWN bit is cleared */
2320 set_bit(__ICE_SERVICE_DIS, pf->state);
2323 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2325 hw->vendor_id = pdev->vendor;
2326 hw->device_id = pdev->device;
2327 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2328 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2329 hw->subsystem_device_id = pdev->subsystem_device;
2330 hw->bus.device = PCI_SLOT(pdev->devfn);
2331 hw->bus.func = PCI_FUNC(pdev->devfn);
2332 ice_set_ctrlq_len(hw);
2334 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2336 #ifndef CONFIG_DYNAMIC_DEBUG
2338 hw->debug_mask = debug;
2341 err = ice_init_hw(hw);
2343 dev_err(dev, "ice_init_hw failed: %d\n", err);
2345 goto err_exit_unroll;
2348 dev_info(dev, "firmware %d.%d.%05d api %d.%d\n",
2349 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2350 hw->api_maj_ver, hw->api_min_ver);
2354 err = ice_init_pf_dcb(pf, false);
2356 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2357 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
2359 /* do not fail overall init if DCB init fails */
2363 ice_determine_q_usage(pf);
2365 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
2366 if (!pf->num_alloc_vsi) {
2368 goto err_init_pf_unroll;
2371 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
2375 goto err_init_pf_unroll;
2378 err = ice_init_interrupt_scheme(pf);
2380 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
2382 goto err_init_interrupt_unroll;
2385 /* Driver is mostly up */
2386 clear_bit(__ICE_DOWN, pf->state);
2388 /* In case of MSIX we are going to setup the misc vector right here
2389 * to handle admin queue events etc. In case of legacy and MSI
2390 * the misc functionality and queue processing is combined in
2391 * the same vector and that gets setup at open.
2393 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2394 err = ice_req_irq_msix_misc(pf);
2396 dev_err(dev, "setup of misc vector failed: %d\n", err);
2397 goto err_init_interrupt_unroll;
2401 /* create switch struct for the switch element created by FW on boot */
2402 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
2403 if (!pf->first_sw) {
2405 goto err_msix_misc_unroll;
2409 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2411 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2413 pf->first_sw->pf = pf;
2415 /* record the sw_id available for later use */
2416 pf->first_sw->sw_id = hw->port_info->sw_id;
2418 err = ice_setup_pf_sw(pf);
2420 dev_err(dev, "probe failed due to setup PF switch:%d\n", err);
2421 goto err_alloc_sw_unroll;
2424 clear_bit(__ICE_SERVICE_DIS, pf->state);
2426 /* since everything is good, start the service timer */
2427 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2429 err = ice_init_link_events(pf->hw.port_info);
2431 dev_err(dev, "ice_init_link_events failed: %d\n", err);
2432 goto err_alloc_sw_unroll;
2435 ice_verify_cacheline_size(pf);
2439 err_alloc_sw_unroll:
2440 set_bit(__ICE_SERVICE_DIS, pf->state);
2441 set_bit(__ICE_DOWN, pf->state);
2442 devm_kfree(&pf->pdev->dev, pf->first_sw);
2443 err_msix_misc_unroll:
2444 ice_free_irq_msix_misc(pf);
2445 err_init_interrupt_unroll:
2446 ice_clear_interrupt_scheme(pf);
2447 devm_kfree(dev, pf->vsi);
2452 pci_disable_pcie_error_reporting(pdev);
2457 * ice_remove - Device removal routine
2458 * @pdev: PCI device information struct
2460 static void ice_remove(struct pci_dev *pdev)
2462 struct ice_pf *pf = pci_get_drvdata(pdev);
2468 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
2469 if (!ice_is_reset_in_progress(pf->state))
2474 set_bit(__ICE_DOWN, pf->state);
2475 ice_service_task_stop(pf);
2477 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2479 ice_vsi_release_all(pf);
2480 ice_free_irq_msix_misc(pf);
2481 ice_for_each_vsi(pf, i) {
2484 ice_vsi_free_q_vectors(pf->vsi[i]);
2486 ice_clear_interrupt_scheme(pf);
2488 ice_deinit_hw(&pf->hw);
2489 pci_disable_pcie_error_reporting(pdev);
2493 * ice_pci_err_detected - warning that PCI error has been detected
2494 * @pdev: PCI device information struct
2495 * @err: the type of PCI error
2497 * Called to warn that something happened on the PCI bus and the error handling
2498 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
2500 static pci_ers_result_t
2501 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
2503 struct ice_pf *pf = pci_get_drvdata(pdev);
2506 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
2508 return PCI_ERS_RESULT_DISCONNECT;
2511 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2512 ice_service_task_stop(pf);
2514 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2515 set_bit(__ICE_PFR_REQ, pf->state);
2516 ice_prepare_for_reset(pf);
2520 return PCI_ERS_RESULT_NEED_RESET;
2524 * ice_pci_err_slot_reset - a PCI slot reset has just happened
2525 * @pdev: PCI device information struct
2527 * Called to determine if the driver can recover from the PCI slot reset by
2528 * using a register read to determine if the device is recoverable.
2530 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
2532 struct ice_pf *pf = pci_get_drvdata(pdev);
2533 pci_ers_result_t result;
2537 err = pci_enable_device_mem(pdev);
2540 "Cannot re-enable PCI device after reset, error %d\n",
2542 result = PCI_ERS_RESULT_DISCONNECT;
2544 pci_set_master(pdev);
2545 pci_restore_state(pdev);
2546 pci_save_state(pdev);
2547 pci_wake_from_d3(pdev, false);
2549 /* Check for life */
2550 reg = rd32(&pf->hw, GLGEN_RTRIG);
2552 result = PCI_ERS_RESULT_RECOVERED;
2554 result = PCI_ERS_RESULT_DISCONNECT;
2557 err = pci_cleanup_aer_uncorrect_error_status(pdev);
2560 "pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
2562 /* non-fatal, continue */
2568 * ice_pci_err_resume - restart operations after PCI error recovery
2569 * @pdev: PCI device information struct
2571 * Called to allow the driver to bring things back up after PCI error and/or
2572 * reset recovery have finished
2574 static void ice_pci_err_resume(struct pci_dev *pdev)
2576 struct ice_pf *pf = pci_get_drvdata(pdev);
2580 "%s failed, device is unrecoverable\n", __func__);
2584 if (test_bit(__ICE_SUSPENDED, pf->state)) {
2585 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
2590 ice_do_reset(pf, ICE_RESET_PFR);
2591 ice_service_task_restart(pf);
2592 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2596 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
2597 * @pdev: PCI device information struct
2599 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
2601 struct ice_pf *pf = pci_get_drvdata(pdev);
2603 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2604 ice_service_task_stop(pf);
2606 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2607 set_bit(__ICE_PFR_REQ, pf->state);
2608 ice_prepare_for_reset(pf);
2614 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
2615 * @pdev: PCI device information struct
2617 static void ice_pci_err_reset_done(struct pci_dev *pdev)
2619 ice_pci_err_resume(pdev);
2622 /* ice_pci_tbl - PCI Device ID Table
2624 * Wildcard entries (PCI_ANY_ID) should come last
2625 * Last entry must be all 0s
2627 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2628 * Class, Class Mask, private data (not used) }
2630 static const struct pci_device_id ice_pci_tbl[] = {
2631 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
2632 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
2633 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
2634 /* required last entry */
2637 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2639 static const struct pci_error_handlers ice_pci_err_handler = {
2640 .error_detected = ice_pci_err_detected,
2641 .slot_reset = ice_pci_err_slot_reset,
2642 .reset_prepare = ice_pci_err_reset_prepare,
2643 .reset_done = ice_pci_err_reset_done,
2644 .resume = ice_pci_err_resume
2647 static struct pci_driver ice_driver = {
2648 .name = KBUILD_MODNAME,
2649 .id_table = ice_pci_tbl,
2651 .remove = ice_remove,
2652 .sriov_configure = ice_sriov_configure,
2653 .err_handler = &ice_pci_err_handler
2657 * ice_module_init - Driver registration routine
2659 * ice_module_init is the first routine called when the driver is
2660 * loaded. All it does is register with the PCI subsystem.
2662 static int __init ice_module_init(void)
2666 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2667 pr_info("%s\n", ice_copyright);
2669 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2671 pr_err("Failed to create workqueue\n");
2675 status = pci_register_driver(&ice_driver);
2677 pr_err("failed to register PCI driver, err %d\n", status);
2678 destroy_workqueue(ice_wq);
2683 module_init(ice_module_init);
2686 * ice_module_exit - Driver exit cleanup routine
2688 * ice_module_exit is called just before the driver is removed
2691 static void __exit ice_module_exit(void)
2693 pci_unregister_driver(&ice_driver);
2694 destroy_workqueue(ice_wq);
2695 pr_info("module unloaded\n");
2697 module_exit(ice_module_exit);
2700 * ice_set_mac_address - NDO callback to set MAC address
2701 * @netdev: network interface device structure
2702 * @pi: pointer to an address structure
2704 * Returns 0 on success, negative on failure
2706 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2708 struct ice_netdev_priv *np = netdev_priv(netdev);
2709 struct ice_vsi *vsi = np->vsi;
2710 struct ice_pf *pf = vsi->back;
2711 struct ice_hw *hw = &pf->hw;
2712 struct sockaddr *addr = pi;
2713 enum ice_status status;
2714 LIST_HEAD(a_mac_list);
2715 LIST_HEAD(r_mac_list);
2720 mac = (u8 *)addr->sa_data;
2722 if (!is_valid_ether_addr(mac))
2723 return -EADDRNOTAVAIL;
2725 if (ether_addr_equal(netdev->dev_addr, mac)) {
2726 netdev_warn(netdev, "already using mac %pM\n", mac);
2730 if (test_bit(__ICE_DOWN, pf->state) ||
2731 ice_is_reset_in_progress(pf->state)) {
2732 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2737 /* When we change the MAC address we also have to change the MAC address
2738 * based filter rules that were created previously for the old MAC
2739 * address. So first, we remove the old filter rule using ice_remove_mac
2740 * and then create a new filter rule using ice_add_mac. Note that for
2741 * both these operations, we first need to form a "list" of MAC
2742 * addresses (even though in this case, we have only 1 MAC address to be
2743 * added/removed) and this done using ice_add_mac_to_list. Depending on
2744 * the ensuing operation this "list" of MAC addresses is either to be
2745 * added or removed from the filter.
2747 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
2749 err = -EADDRNOTAVAIL;
2753 status = ice_remove_mac(hw, &r_mac_list);
2755 err = -EADDRNOTAVAIL;
2759 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
2761 err = -EADDRNOTAVAIL;
2765 status = ice_add_mac(hw, &a_mac_list);
2767 err = -EADDRNOTAVAIL;
2772 /* free list entries */
2773 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
2774 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
2777 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
2782 /* change the netdev's MAC address */
2783 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2784 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
2787 /* write new MAC address to the firmware */
2788 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2789 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2791 netdev_err(netdev, "can't set MAC %pM. write to firmware failed.\n",
2798 * ice_set_rx_mode - NDO callback to set the netdev filters
2799 * @netdev: network interface device structure
2801 static void ice_set_rx_mode(struct net_device *netdev)
2803 struct ice_netdev_priv *np = netdev_priv(netdev);
2804 struct ice_vsi *vsi = np->vsi;
2809 /* Set the flags to synchronize filters
2810 * ndo_set_rx_mode may be triggered even without a change in netdev
2813 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2814 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2815 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2817 /* schedule our worker thread which will take care of
2818 * applying the new filter changes
2820 ice_service_task_schedule(vsi->back);
2824 * ice_fdb_add - add an entry to the hardware database
2825 * @ndm: the input from the stack
2826 * @tb: pointer to array of nladdr (unused)
2827 * @dev: the net device pointer
2828 * @addr: the MAC address entry being added
2830 * @flags: instructions from stack about fdb operation
2831 * @extack: netlink extended ack
2834 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2835 struct net_device *dev, const unsigned char *addr, u16 vid,
2836 u16 flags, struct netlink_ext_ack __always_unused *extack)
2841 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2844 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2845 netdev_err(dev, "FDB only supports static addresses\n");
2849 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2850 err = dev_uc_add_excl(dev, addr);
2851 else if (is_multicast_ether_addr(addr))
2852 err = dev_mc_add_excl(dev, addr);
2856 /* Only return duplicate errors if NLM_F_EXCL is set */
2857 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2864 * ice_fdb_del - delete an entry from the hardware database
2865 * @ndm: the input from the stack
2866 * @tb: pointer to array of nladdr (unused)
2867 * @dev: the net device pointer
2868 * @addr: the MAC address entry being added
2872 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2873 struct net_device *dev, const unsigned char *addr,
2874 __always_unused u16 vid)
2878 if (ndm->ndm_state & NUD_PERMANENT) {
2879 netdev_err(dev, "FDB only supports static addresses\n");
2883 if (is_unicast_ether_addr(addr))
2884 err = dev_uc_del(dev, addr);
2885 else if (is_multicast_ether_addr(addr))
2886 err = dev_mc_del(dev, addr);
2894 * ice_set_features - set the netdev feature flags
2895 * @netdev: ptr to the netdev being adjusted
2896 * @features: the feature set that the stack is suggesting
2899 ice_set_features(struct net_device *netdev, netdev_features_t features)
2901 struct ice_netdev_priv *np = netdev_priv(netdev);
2902 struct ice_vsi *vsi = np->vsi;
2905 /* Multiple features can be changed in one call so keep features in
2906 * separate if/else statements to guarantee each feature is checked
2908 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
2909 ret = ice_vsi_manage_rss_lut(vsi, true);
2910 else if (!(features & NETIF_F_RXHASH) &&
2911 netdev->features & NETIF_F_RXHASH)
2912 ret = ice_vsi_manage_rss_lut(vsi, false);
2914 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
2915 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2916 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2917 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
2918 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2919 ret = ice_vsi_manage_vlan_stripping(vsi, false);
2921 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
2922 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2923 ret = ice_vsi_manage_vlan_insertion(vsi);
2924 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
2925 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2926 ret = ice_vsi_manage_vlan_insertion(vsi);
2928 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
2929 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
2930 ret = ice_cfg_vlan_pruning(vsi, true, false);
2931 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
2932 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
2933 ret = ice_cfg_vlan_pruning(vsi, false, false);
2939 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
2940 * @vsi: VSI to setup VLAN properties for
2942 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
2946 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2947 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2948 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
2949 ret = ice_vsi_manage_vlan_insertion(vsi);
2955 * ice_vsi_cfg - Setup the VSI
2956 * @vsi: the VSI being configured
2958 * Return 0 on success and negative value on error
2960 int ice_vsi_cfg(struct ice_vsi *vsi)
2965 ice_set_rx_mode(vsi->netdev);
2967 err = ice_vsi_vlan_setup(vsi);
2972 ice_vsi_cfg_dcb_rings(vsi);
2974 err = ice_vsi_cfg_lan_txqs(vsi);
2976 err = ice_vsi_cfg_rxqs(vsi);
2982 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
2983 * @vsi: the VSI being configured
2985 static void ice_napi_enable_all(struct ice_vsi *vsi)
2992 ice_for_each_q_vector(vsi, q_idx) {
2993 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
2995 if (q_vector->rx.ring || q_vector->tx.ring)
2996 napi_enable(&q_vector->napi);
3001 * ice_up_complete - Finish the last steps of bringing up a connection
3002 * @vsi: The VSI being configured
3004 * Return 0 on success and negative value on error
3006 static int ice_up_complete(struct ice_vsi *vsi)
3008 struct ice_pf *pf = vsi->back;
3011 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3012 ice_vsi_cfg_msix(vsi);
3016 /* Enable only Rx rings, Tx rings were enabled by the FW when the
3017 * Tx queue group list was configured and the context bits were
3018 * programmed using ice_vsi_cfg_txqs
3020 err = ice_vsi_start_rx_rings(vsi);
3024 clear_bit(__ICE_DOWN, vsi->state);
3025 ice_napi_enable_all(vsi);
3026 ice_vsi_ena_irq(vsi);
3028 if (vsi->port_info &&
3029 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
3031 ice_print_link_msg(vsi, true);
3032 netif_tx_start_all_queues(vsi->netdev);
3033 netif_carrier_on(vsi->netdev);
3036 ice_service_task_schedule(pf);
3042 * ice_up - Bring the connection back up after being down
3043 * @vsi: VSI being configured
3045 int ice_up(struct ice_vsi *vsi)
3049 err = ice_vsi_cfg(vsi);
3051 err = ice_up_complete(vsi);
3057 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
3058 * @ring: Tx or Rx ring to read stats from
3059 * @pkts: packets stats counter
3060 * @bytes: bytes stats counter
3062 * This function fetches stats from the ring considering the atomic operations
3063 * that needs to be performed to read u64 values in 32 bit machine.
3066 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
3075 start = u64_stats_fetch_begin_irq(&ring->syncp);
3076 *pkts = ring->stats.pkts;
3077 *bytes = ring->stats.bytes;
3078 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
3082 * ice_update_vsi_ring_stats - Update VSI stats counters
3083 * @vsi: the VSI to be updated
3085 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
3087 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
3088 struct ice_ring *ring;
3092 /* reset netdev stats */
3093 vsi_stats->tx_packets = 0;
3094 vsi_stats->tx_bytes = 0;
3095 vsi_stats->rx_packets = 0;
3096 vsi_stats->rx_bytes = 0;
3098 /* reset non-netdev (extended) stats */
3099 vsi->tx_restart = 0;
3101 vsi->tx_linearize = 0;
3102 vsi->rx_buf_failed = 0;
3103 vsi->rx_page_failed = 0;
3107 /* update Tx rings counters */
3108 ice_for_each_txq(vsi, i) {
3109 ring = READ_ONCE(vsi->tx_rings[i]);
3110 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3111 vsi_stats->tx_packets += pkts;
3112 vsi_stats->tx_bytes += bytes;
3113 vsi->tx_restart += ring->tx_stats.restart_q;
3114 vsi->tx_busy += ring->tx_stats.tx_busy;
3115 vsi->tx_linearize += ring->tx_stats.tx_linearize;
3118 /* update Rx rings counters */
3119 ice_for_each_rxq(vsi, i) {
3120 ring = READ_ONCE(vsi->rx_rings[i]);
3121 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3122 vsi_stats->rx_packets += pkts;
3123 vsi_stats->rx_bytes += bytes;
3124 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
3125 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
3132 * ice_update_vsi_stats - Update VSI stats counters
3133 * @vsi: the VSI to be updated
3135 static void ice_update_vsi_stats(struct ice_vsi *vsi)
3137 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
3138 struct ice_eth_stats *cur_es = &vsi->eth_stats;
3139 struct ice_pf *pf = vsi->back;
3141 if (test_bit(__ICE_DOWN, vsi->state) ||
3142 test_bit(__ICE_CFG_BUSY, pf->state))
3145 /* get stats as recorded by Tx/Rx rings */
3146 ice_update_vsi_ring_stats(vsi);
3148 /* get VSI stats as recorded by the hardware */
3149 ice_update_eth_stats(vsi);
3151 cur_ns->tx_errors = cur_es->tx_errors;
3152 cur_ns->rx_dropped = cur_es->rx_discards;
3153 cur_ns->tx_dropped = cur_es->tx_discards;
3154 cur_ns->multicast = cur_es->rx_multicast;
3156 /* update some more netdev stats if this is main VSI */
3157 if (vsi->type == ICE_VSI_PF) {
3158 cur_ns->rx_crc_errors = pf->stats.crc_errors;
3159 cur_ns->rx_errors = pf->stats.crc_errors +
3160 pf->stats.illegal_bytes;
3161 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
3166 * ice_update_pf_stats - Update PF port stats counters
3167 * @pf: PF whose stats needs to be updated
3169 static void ice_update_pf_stats(struct ice_pf *pf)
3171 struct ice_hw_port_stats *prev_ps, *cur_ps;
3172 struct ice_hw *hw = &pf->hw;
3175 prev_ps = &pf->stats_prev;
3176 cur_ps = &pf->stats;
3179 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
3180 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
3181 &cur_ps->eth.rx_bytes);
3183 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
3184 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
3185 &cur_ps->eth.rx_unicast);
3187 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
3188 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
3189 &cur_ps->eth.rx_multicast);
3191 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
3192 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
3193 &cur_ps->eth.rx_broadcast);
3195 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
3196 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
3197 &cur_ps->eth.tx_bytes);
3199 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
3200 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
3201 &cur_ps->eth.tx_unicast);
3203 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
3204 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
3205 &cur_ps->eth.tx_multicast);
3207 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
3208 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
3209 &cur_ps->eth.tx_broadcast);
3211 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
3212 &prev_ps->tx_dropped_link_down,
3213 &cur_ps->tx_dropped_link_down);
3215 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
3216 pf->stat_prev_loaded, &prev_ps->rx_size_64,
3217 &cur_ps->rx_size_64);
3219 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
3220 pf->stat_prev_loaded, &prev_ps->rx_size_127,
3221 &cur_ps->rx_size_127);
3223 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
3224 pf->stat_prev_loaded, &prev_ps->rx_size_255,
3225 &cur_ps->rx_size_255);
3227 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
3228 pf->stat_prev_loaded, &prev_ps->rx_size_511,
3229 &cur_ps->rx_size_511);
3231 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
3232 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
3233 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
3235 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
3236 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
3237 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
3239 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
3240 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
3241 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
3243 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
3244 pf->stat_prev_loaded, &prev_ps->tx_size_64,
3245 &cur_ps->tx_size_64);
3247 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
3248 pf->stat_prev_loaded, &prev_ps->tx_size_127,
3249 &cur_ps->tx_size_127);
3251 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
3252 pf->stat_prev_loaded, &prev_ps->tx_size_255,
3253 &cur_ps->tx_size_255);
3255 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
3256 pf->stat_prev_loaded, &prev_ps->tx_size_511,
3257 &cur_ps->tx_size_511);
3259 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
3260 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
3261 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
3263 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
3264 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
3265 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
3267 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
3268 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
3269 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
3271 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
3272 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
3274 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
3275 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
3277 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
3278 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
3280 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
3281 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
3283 ice_update_dcb_stats(pf);
3285 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
3286 &prev_ps->crc_errors, &cur_ps->crc_errors);
3288 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
3289 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
3291 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
3292 &prev_ps->mac_local_faults,
3293 &cur_ps->mac_local_faults);
3295 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
3296 &prev_ps->mac_remote_faults,
3297 &cur_ps->mac_remote_faults);
3299 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
3300 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
3302 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
3303 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
3305 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
3306 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
3308 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
3309 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
3311 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
3312 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
3314 pf->stat_prev_loaded = true;
3318 * ice_get_stats64 - get statistics for network device structure
3319 * @netdev: network interface device structure
3320 * @stats: main device statistics structure
3323 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
3325 struct ice_netdev_priv *np = netdev_priv(netdev);
3326 struct rtnl_link_stats64 *vsi_stats;
3327 struct ice_vsi *vsi = np->vsi;
3329 vsi_stats = &vsi->net_stats;
3331 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
3333 /* netdev packet/byte stats come from ring counter. These are obtained
3334 * by summing up ring counters (done by ice_update_vsi_ring_stats).
3336 ice_update_vsi_ring_stats(vsi);
3337 stats->tx_packets = vsi_stats->tx_packets;
3338 stats->tx_bytes = vsi_stats->tx_bytes;
3339 stats->rx_packets = vsi_stats->rx_packets;
3340 stats->rx_bytes = vsi_stats->rx_bytes;
3342 /* The rest of the stats can be read from the hardware but instead we
3343 * just return values that the watchdog task has already obtained from
3346 stats->multicast = vsi_stats->multicast;
3347 stats->tx_errors = vsi_stats->tx_errors;
3348 stats->tx_dropped = vsi_stats->tx_dropped;
3349 stats->rx_errors = vsi_stats->rx_errors;
3350 stats->rx_dropped = vsi_stats->rx_dropped;
3351 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
3352 stats->rx_length_errors = vsi_stats->rx_length_errors;
3356 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3357 * @vsi: VSI having NAPI disabled
3359 static void ice_napi_disable_all(struct ice_vsi *vsi)
3366 ice_for_each_q_vector(vsi, q_idx) {
3367 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3369 if (q_vector->rx.ring || q_vector->tx.ring)
3370 napi_disable(&q_vector->napi);
3375 * ice_force_phys_link_state - Force the physical link state
3376 * @vsi: VSI to force the physical link state to up/down
3377 * @link_up: true/false indicates to set the physical link to up/down
3379 * Force the physical link state by getting the current PHY capabilities from
3380 * hardware and setting the PHY config based on the determined capabilities. If
3381 * link changes a link event will be triggered because both the Enable Automatic
3382 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
3384 * Returns 0 on success, negative on failure
3386 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
3388 struct ice_aqc_get_phy_caps_data *pcaps;
3389 struct ice_aqc_set_phy_cfg_data *cfg;
3390 struct ice_port_info *pi;
3394 if (!vsi || !vsi->port_info || !vsi->back)
3396 if (vsi->type != ICE_VSI_PF)
3399 dev = &vsi->back->pdev->dev;
3401 pi = vsi->port_info;
3403 pcaps = devm_kzalloc(dev, sizeof(*pcaps), GFP_KERNEL);
3407 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
3411 "Failed to get phy capabilities, VSI %d error %d\n",
3412 vsi->vsi_num, retcode);
3417 /* No change in link */
3418 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
3419 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
3422 cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL);
3428 cfg->phy_type_low = pcaps->phy_type_low;
3429 cfg->phy_type_high = pcaps->phy_type_high;
3430 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3431 cfg->low_power_ctrl = pcaps->low_power_ctrl;
3432 cfg->eee_cap = pcaps->eee_cap;
3433 cfg->eeer_value = pcaps->eeer_value;
3434 cfg->link_fec_opt = pcaps->link_fec_options;
3436 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
3438 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
3440 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
3442 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
3443 vsi->vsi_num, retcode);
3447 devm_kfree(dev, cfg);
3449 devm_kfree(dev, pcaps);
3454 * ice_down - Shutdown the connection
3455 * @vsi: The VSI being stopped
3457 int ice_down(struct ice_vsi *vsi)
3459 int i, tx_err, rx_err, link_err = 0;
3461 /* Caller of this function is expected to set the
3462 * vsi->state __ICE_DOWN bit
3465 netif_carrier_off(vsi->netdev);
3466 netif_tx_disable(vsi->netdev);
3469 ice_vsi_dis_irq(vsi);
3471 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
3473 netdev_err(vsi->netdev,
3474 "Failed stop Tx rings, VSI %d error %d\n",
3475 vsi->vsi_num, tx_err);
3477 rx_err = ice_vsi_stop_rx_rings(vsi);
3479 netdev_err(vsi->netdev,
3480 "Failed stop Rx rings, VSI %d error %d\n",
3481 vsi->vsi_num, rx_err);
3483 ice_napi_disable_all(vsi);
3485 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
3486 link_err = ice_force_phys_link_state(vsi, false);
3488 netdev_err(vsi->netdev,
3489 "Failed to set physical link down, VSI %d error %d\n",
3490 vsi->vsi_num, link_err);
3493 ice_for_each_txq(vsi, i)
3494 ice_clean_tx_ring(vsi->tx_rings[i]);
3496 ice_for_each_rxq(vsi, i)
3497 ice_clean_rx_ring(vsi->rx_rings[i]);
3499 if (tx_err || rx_err || link_err) {
3500 netdev_err(vsi->netdev,
3501 "Failed to close VSI 0x%04X on switch 0x%04X\n",
3502 vsi->vsi_num, vsi->vsw->sw_id);
3510 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
3511 * @vsi: VSI having resources allocated
3513 * Return 0 on success, negative on failure
3515 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3519 if (!vsi->num_txq) {
3520 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3525 ice_for_each_txq(vsi, i) {
3526 vsi->tx_rings[i]->netdev = vsi->netdev;
3527 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3536 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3537 * @vsi: VSI having resources allocated
3539 * Return 0 on success, negative on failure
3541 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3545 if (!vsi->num_rxq) {
3546 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3551 ice_for_each_rxq(vsi, i) {
3552 vsi->rx_rings[i]->netdev = vsi->netdev;
3553 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3562 * ice_vsi_req_irq - Request IRQ from the OS
3563 * @vsi: The VSI IRQ is being requested for
3564 * @basename: name for the vector
3566 * Return 0 on success and a negative value on error
3568 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
3570 struct ice_pf *pf = vsi->back;
3573 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3574 err = ice_vsi_req_irq_msix(vsi, basename);
3580 * ice_vsi_open - Called when a network interface is made active
3581 * @vsi: the VSI to open
3583 * Initialization of the VSI
3585 * Returns 0 on success, negative value on error
3587 static int ice_vsi_open(struct ice_vsi *vsi)
3589 char int_name[ICE_INT_NAME_STR_LEN];
3590 struct ice_pf *pf = vsi->back;
3593 /* allocate descriptors */
3594 err = ice_vsi_setup_tx_rings(vsi);
3598 err = ice_vsi_setup_rx_rings(vsi);
3602 err = ice_vsi_cfg(vsi);
3606 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3607 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3608 err = ice_vsi_req_irq(vsi, int_name);
3612 /* Notify the stack of the actual queue counts. */
3613 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3617 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3621 err = ice_up_complete(vsi);
3623 goto err_up_complete;
3630 ice_vsi_free_irq(vsi);
3632 ice_vsi_free_rx_rings(vsi);
3634 ice_vsi_free_tx_rings(vsi);
3640 * ice_vsi_release_all - Delete all VSIs
3641 * @pf: PF from which all VSIs are being removed
3643 static void ice_vsi_release_all(struct ice_pf *pf)
3650 ice_for_each_vsi(pf, i) {
3654 err = ice_vsi_release(pf->vsi[i]);
3656 dev_dbg(&pf->pdev->dev,
3657 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3658 i, err, pf->vsi[i]->vsi_num);
3663 * ice_ena_vsi - resume a VSI
3664 * @vsi: the VSI being resume
3665 * @locked: is the rtnl_lock already held
3667 static int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
3671 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
3674 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
3676 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
3677 struct net_device *netd = vsi->netdev;
3679 if (netif_running(vsi->netdev)) {
3681 err = netd->netdev_ops->ndo_open(netd);
3684 err = netd->netdev_ops->ndo_open(netd);
3688 err = ice_vsi_open(vsi);
3696 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3698 * @locked: is the rtnl_lock already held
3701 int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3703 static int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3704 #endif /* CONFIG_DCB */
3708 ice_for_each_vsi(pf, v)
3710 if (ice_ena_vsi(pf->vsi[v], locked))
3717 * ice_vsi_rebuild_all - rebuild all VSIs in PF
3720 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3724 /* loop through pf->vsi array and reinit the VSI if found */
3725 ice_for_each_vsi(pf, i) {
3731 err = ice_vsi_rebuild(pf->vsi[i]);
3733 dev_err(&pf->pdev->dev,
3734 "VSI at index %d rebuild failed\n",
3739 dev_info(&pf->pdev->dev,
3740 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3741 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3748 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3751 static int ice_vsi_replay_all(struct ice_pf *pf)
3753 struct ice_hw *hw = &pf->hw;
3754 enum ice_status ret;
3757 /* loop through pf->vsi array and replay the VSI if found */
3758 ice_for_each_vsi(pf, i) {
3762 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3764 dev_err(&pf->pdev->dev,
3765 "VSI at index %d replay failed %d\n",
3766 pf->vsi[i]->idx, ret);
3770 /* Re-map HW VSI number, using VSI handle that has been
3771 * previously validated in ice_replay_vsi() call above
3773 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3775 dev_info(&pf->pdev->dev,
3776 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3777 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3780 /* Clean up replay filter after successful re-configuration */
3781 ice_replay_post(hw);
3786 * ice_rebuild - rebuild after reset
3787 * @pf: PF to rebuild
3789 static void ice_rebuild(struct ice_pf *pf)
3791 struct device *dev = &pf->pdev->dev;
3792 struct ice_hw *hw = &pf->hw;
3793 enum ice_status ret;
3796 if (test_bit(__ICE_DOWN, pf->state))
3797 goto clear_recovery;
3799 dev_dbg(dev, "rebuilding PF\n");
3801 ret = ice_init_all_ctrlq(hw);
3803 dev_err(dev, "control queues init failed %d\n", ret);
3804 goto err_init_ctrlq;
3807 ret = ice_clear_pf_cfg(hw);
3809 dev_err(dev, "clear PF configuration failed %d\n", ret);
3810 goto err_init_ctrlq;
3813 ice_clear_pxe_mode(hw);
3815 ret = ice_get_caps(hw);
3817 dev_err(dev, "ice_get_caps failed %d\n", ret);
3818 goto err_init_ctrlq;
3821 err = ice_sched_init_port(hw->port_info);
3823 goto err_sched_init_port;
3825 ice_dcb_rebuild(pf);
3827 err = ice_vsi_rebuild_all(pf);
3829 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3830 goto err_vsi_rebuild;
3833 err = ice_update_link_info(hw->port_info);
3835 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3837 /* Replay all VSIs Configuration, including filters after reset */
3838 if (ice_vsi_replay_all(pf)) {
3839 dev_err(&pf->pdev->dev,
3840 "error replaying VSI configurations with switch filter rules\n");
3841 goto err_vsi_rebuild;
3844 /* start misc vector */
3845 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3846 err = ice_req_irq_msix_misc(pf);
3848 dev_err(dev, "misc vector setup failed: %d\n", err);
3849 goto err_vsi_rebuild;
3853 /* restart the VSIs that were rebuilt and running before the reset */
3854 err = ice_pf_ena_all_vsi(pf, false);
3856 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3857 /* no need to disable VSIs in tear down path in ice_rebuild()
3858 * since its already taken care in ice_vsi_open()
3860 goto err_vsi_rebuild;
3863 ice_for_each_vsi(pf, i) {
3866 if (!pf->vsi[i] || pf->vsi[i]->type != ICE_VSI_PF)
3868 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
3870 netif_carrier_on(pf->vsi[i]->netdev);
3871 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
3873 netif_carrier_off(pf->vsi[i]->netdev);
3874 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
3878 /* if we get here, reset flow is successful */
3879 clear_bit(__ICE_RESET_FAILED, pf->state);
3883 ice_vsi_release_all(pf);
3884 err_sched_init_port:
3885 ice_sched_cleanup_all(hw);
3887 ice_shutdown_all_ctrlq(hw);
3888 set_bit(__ICE_RESET_FAILED, pf->state);
3890 /* set this bit in PF state to control service task scheduling */
3891 set_bit(__ICE_NEEDS_RESTART, pf->state);
3892 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3896 * ice_change_mtu - NDO callback to change the MTU
3897 * @netdev: network interface device structure
3898 * @new_mtu: new value for maximum frame size
3900 * Returns 0 on success, negative on failure
3902 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3904 struct ice_netdev_priv *np = netdev_priv(netdev);
3905 struct ice_vsi *vsi = np->vsi;
3906 struct ice_pf *pf = vsi->back;
3909 if (new_mtu == netdev->mtu) {
3910 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
3914 if (new_mtu < netdev->min_mtu) {
3915 netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
3918 } else if (new_mtu > netdev->max_mtu) {
3919 netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
3923 /* if a reset is in progress, wait for some time for it to complete */
3925 if (ice_is_reset_in_progress(pf->state)) {
3927 usleep_range(1000, 2000);
3932 } while (count < 100);
3935 netdev_err(netdev, "can't change MTU. Device is busy\n");
3939 netdev->mtu = new_mtu;
3941 /* if VSI is up, bring it down and then back up */
3942 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3945 err = ice_down(vsi);
3947 netdev_err(netdev, "change MTU if_up err %d\n", err);
3953 netdev_err(netdev, "change MTU if_up err %d\n", err);
3958 netdev_info(netdev, "changed MTU to %d\n", new_mtu);
3963 * ice_set_rss - Set RSS keys and lut
3964 * @vsi: Pointer to VSI structure
3965 * @seed: RSS hash seed
3966 * @lut: Lookup table
3967 * @lut_size: Lookup table size
3969 * Returns 0 on success, negative on failure
3971 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3973 struct ice_pf *pf = vsi->back;
3974 struct ice_hw *hw = &pf->hw;
3975 enum ice_status status;
3978 struct ice_aqc_get_set_rss_keys *buf =
3979 (struct ice_aqc_get_set_rss_keys *)seed;
3981 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3984 dev_err(&pf->pdev->dev,
3985 "Cannot set RSS key, err %d aq_err %d\n",
3986 status, hw->adminq.rq_last_status);
3992 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3995 dev_err(&pf->pdev->dev,
3996 "Cannot set RSS lut, err %d aq_err %d\n",
3997 status, hw->adminq.rq_last_status);
4006 * ice_get_rss - Get RSS keys and lut
4007 * @vsi: Pointer to VSI structure
4008 * @seed: Buffer to store the keys
4009 * @lut: Buffer to store the lookup table entries
4010 * @lut_size: Size of buffer to store the lookup table entries
4012 * Returns 0 on success, negative on failure
4014 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4016 struct ice_pf *pf = vsi->back;
4017 struct ice_hw *hw = &pf->hw;
4018 enum ice_status status;
4021 struct ice_aqc_get_set_rss_keys *buf =
4022 (struct ice_aqc_get_set_rss_keys *)seed;
4024 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4026 dev_err(&pf->pdev->dev,
4027 "Cannot get RSS key, err %d aq_err %d\n",
4028 status, hw->adminq.rq_last_status);
4034 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4037 dev_err(&pf->pdev->dev,
4038 "Cannot get RSS lut, err %d aq_err %d\n",
4039 status, hw->adminq.rq_last_status);
4048 * ice_bridge_getlink - Get the hardware bridge mode
4051 * @seq: RTNL message seq
4052 * @dev: the netdev being configured
4053 * @filter_mask: filter mask passed in
4054 * @nlflags: netlink flags passed in
4056 * Return the bridge mode (VEB/VEPA)
4059 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4060 struct net_device *dev, u32 filter_mask, int nlflags)
4062 struct ice_netdev_priv *np = netdev_priv(dev);
4063 struct ice_vsi *vsi = np->vsi;
4064 struct ice_pf *pf = vsi->back;
4067 bmode = pf->first_sw->bridge_mode;
4069 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4074 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4075 * @vsi: Pointer to VSI structure
4076 * @bmode: Hardware bridge mode (VEB/VEPA)
4078 * Returns 0 on success, negative on failure
4080 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4082 struct device *dev = &vsi->back->pdev->dev;
4083 struct ice_aqc_vsi_props *vsi_props;
4084 struct ice_hw *hw = &vsi->back->hw;
4085 struct ice_vsi_ctx *ctxt;
4086 enum ice_status status;
4089 vsi_props = &vsi->info;
4091 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
4095 ctxt->info = vsi->info;
4097 if (bmode == BRIDGE_MODE_VEB)
4098 /* change from VEPA to VEB mode */
4099 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4101 /* change from VEB to VEPA mode */
4102 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4103 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4105 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4107 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4108 bmode, status, hw->adminq.sq_last_status);
4112 /* Update sw flags for book keeping */
4113 vsi_props->sw_flags = ctxt->info.sw_flags;
4116 devm_kfree(dev, ctxt);
4121 * ice_bridge_setlink - Set the hardware bridge mode
4122 * @dev: the netdev being configured
4123 * @nlh: RTNL message
4124 * @flags: bridge setlink flags
4125 * @extack: netlink extended ack
4127 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4128 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4129 * not already set for all VSIs connected to this switch. And also update the
4130 * unicast switch filter rules for the corresponding switch of the netdev.
4133 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4134 u16 __always_unused flags,
4135 struct netlink_ext_ack __always_unused *extack)
4137 struct ice_netdev_priv *np = netdev_priv(dev);
4138 struct ice_pf *pf = np->vsi->back;
4139 struct nlattr *attr, *br_spec;
4140 struct ice_hw *hw = &pf->hw;
4141 enum ice_status status;
4142 struct ice_sw *pf_sw;
4143 int rem, v, err = 0;
4145 pf_sw = pf->first_sw;
4146 /* find the attribute in the netlink message */
4147 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4149 nla_for_each_nested(attr, br_spec, rem) {
4152 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4154 mode = nla_get_u16(attr);
4155 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4157 /* Continue if bridge mode is not being flipped */
4158 if (mode == pf_sw->bridge_mode)
4160 /* Iterates through the PF VSI list and update the loopback
4163 ice_for_each_vsi(pf, v) {
4166 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
4171 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
4172 /* Update the unicast switch filter rules for the corresponding
4173 * switch of the netdev
4175 status = ice_update_sw_rule_bridge_mode(hw);
4177 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
4178 mode, status, hw->adminq.sq_last_status);
4179 /* revert hw->evb_veb */
4180 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
4184 pf_sw->bridge_mode = mode;
4191 * ice_tx_timeout - Respond to a Tx Hang
4192 * @netdev: network interface device structure
4194 static void ice_tx_timeout(struct net_device *netdev)
4196 struct ice_netdev_priv *np = netdev_priv(netdev);
4197 struct ice_ring *tx_ring = NULL;
4198 struct ice_vsi *vsi = np->vsi;
4199 struct ice_pf *pf = vsi->back;
4200 int hung_queue = -1;
4203 pf->tx_timeout_count++;
4205 /* find the stopped queue the same way dev_watchdog() does */
4206 for (i = 0; i < netdev->num_tx_queues; i++) {
4207 unsigned long trans_start;
4208 struct netdev_queue *q;
4210 q = netdev_get_tx_queue(netdev, i);
4211 trans_start = q->trans_start;
4212 if (netif_xmit_stopped(q) &&
4214 trans_start + netdev->watchdog_timeo)) {
4220 if (i == netdev->num_tx_queues)
4221 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
4223 /* now that we have an index, find the tx_ring struct */
4224 for (i = 0; i < vsi->num_txq; i++)
4225 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
4226 if (hung_queue == vsi->tx_rings[i]->q_index) {
4227 tx_ring = vsi->tx_rings[i];
4231 /* Reset recovery level if enough time has elapsed after last timeout.
4232 * Also ensure no new reset action happens before next timeout period.
4234 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
4235 pf->tx_timeout_recovery_level = 1;
4236 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
4237 netdev->watchdog_timeo)))
4241 struct ice_hw *hw = &pf->hw;
4244 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
4245 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
4246 /* Read interrupt register */
4247 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
4249 GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
4251 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
4252 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
4253 head, tx_ring->next_to_use, val);
4256 pf->tx_timeout_last_recovery = jiffies;
4257 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
4258 pf->tx_timeout_recovery_level, hung_queue);
4260 switch (pf->tx_timeout_recovery_level) {
4262 set_bit(__ICE_PFR_REQ, pf->state);
4265 set_bit(__ICE_CORER_REQ, pf->state);
4268 set_bit(__ICE_GLOBR_REQ, pf->state);
4271 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
4272 set_bit(__ICE_DOWN, pf->state);
4273 set_bit(__ICE_NEEDS_RESTART, vsi->state);
4274 set_bit(__ICE_SERVICE_DIS, pf->state);
4278 ice_service_task_schedule(pf);
4279 pf->tx_timeout_recovery_level++;
4283 * ice_open - Called when a network interface becomes active
4284 * @netdev: network interface device structure
4286 * The open entry point is called when a network interface is made
4287 * active by the system (IFF_UP). At this point all resources needed
4288 * for transmit and receive operations are allocated, the interrupt
4289 * handler is registered with the OS, the netdev watchdog is enabled,
4290 * and the stack is notified that the interface is ready.
4292 * Returns 0 on success, negative value on failure
4294 int ice_open(struct net_device *netdev)
4296 struct ice_netdev_priv *np = netdev_priv(netdev);
4297 struct ice_vsi *vsi = np->vsi;
4300 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
4301 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
4305 netif_carrier_off(netdev);
4307 err = ice_force_phys_link_state(vsi, true);
4310 "Failed to set physical link up, error %d\n", err);
4314 err = ice_vsi_open(vsi);
4316 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
4317 vsi->vsi_num, vsi->vsw->sw_id);
4322 * ice_stop - Disables a network interface
4323 * @netdev: network interface device structure
4325 * The stop entry point is called when an interface is de-activated by the OS,
4326 * and the netdevice enters the DOWN state. The hardware is still under the
4327 * driver's control, but the netdev interface is disabled.
4329 * Returns success only - not allowed to fail
4331 int ice_stop(struct net_device *netdev)
4333 struct ice_netdev_priv *np = netdev_priv(netdev);
4334 struct ice_vsi *vsi = np->vsi;
4342 * ice_features_check - Validate encapsulated packet conforms to limits
4344 * @netdev: This port's netdev
4345 * @features: Offload features that the stack believes apply
4347 static netdev_features_t
4348 ice_features_check(struct sk_buff *skb,
4349 struct net_device __always_unused *netdev,
4350 netdev_features_t features)
4354 /* No point in doing any of this if neither checksum nor GSO are
4355 * being requested for this frame. We can rule out both by just
4356 * checking for CHECKSUM_PARTIAL
4358 if (skb->ip_summed != CHECKSUM_PARTIAL)
4361 /* We cannot support GSO if the MSS is going to be less than
4362 * 64 bytes. If it is then we need to drop support for GSO.
4364 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
4365 features &= ~NETIF_F_GSO_MASK;
4367 len = skb_network_header(skb) - skb->data;
4368 if (len & ~(ICE_TXD_MACLEN_MAX))
4369 goto out_rm_features;
4371 len = skb_transport_header(skb) - skb_network_header(skb);
4372 if (len & ~(ICE_TXD_IPLEN_MAX))
4373 goto out_rm_features;
4375 if (skb->encapsulation) {
4376 len = skb_inner_network_header(skb) - skb_transport_header(skb);
4377 if (len & ~(ICE_TXD_L4LEN_MAX))
4378 goto out_rm_features;
4380 len = skb_inner_transport_header(skb) -
4381 skb_inner_network_header(skb);
4382 if (len & ~(ICE_TXD_IPLEN_MAX))
4383 goto out_rm_features;
4388 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
4391 static const struct net_device_ops ice_netdev_ops = {
4392 .ndo_open = ice_open,
4393 .ndo_stop = ice_stop,
4394 .ndo_start_xmit = ice_start_xmit,
4395 .ndo_features_check = ice_features_check,
4396 .ndo_set_rx_mode = ice_set_rx_mode,
4397 .ndo_set_mac_address = ice_set_mac_address,
4398 .ndo_validate_addr = eth_validate_addr,
4399 .ndo_change_mtu = ice_change_mtu,
4400 .ndo_get_stats64 = ice_get_stats64,
4401 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
4402 .ndo_set_vf_mac = ice_set_vf_mac,
4403 .ndo_get_vf_config = ice_get_vf_cfg,
4404 .ndo_set_vf_trust = ice_set_vf_trust,
4405 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
4406 .ndo_set_vf_link_state = ice_set_vf_link_state,
4407 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
4408 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
4409 .ndo_set_features = ice_set_features,
4410 .ndo_bridge_getlink = ice_bridge_getlink,
4411 .ndo_bridge_setlink = ice_bridge_setlink,
4412 .ndo_fdb_add = ice_fdb_add,
4413 .ndo_fdb_del = ice_fdb_del,
4414 .ndo_tx_timeout = ice_tx_timeout,