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.";
18 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
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_40GB:
651 case ICE_AQ_LINK_SPEED_25GB:
654 case ICE_AQ_LINK_SPEED_20GB:
657 case ICE_AQ_LINK_SPEED_10GB:
660 case ICE_AQ_LINK_SPEED_5GB:
663 case ICE_AQ_LINK_SPEED_2500MB:
666 case ICE_AQ_LINK_SPEED_1000MB:
669 case ICE_AQ_LINK_SPEED_100MB:
677 switch (vsi->port_info->fc.current_mode) {
681 case ICE_FC_TX_PAUSE:
684 case ICE_FC_RX_PAUSE:
695 /* Get FEC mode based on negotiated link info */
696 switch (vsi->port_info->phy.link_info.fec_info) {
697 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
699 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
702 case ICE_AQ_LINK_25G_KR_FEC_EN:
703 fec = "FC-FEC/BASE-R";
710 /* Get FEC mode requested based on PHY caps last SW configuration */
711 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
717 status = ice_aq_get_phy_caps(vsi->port_info, false,
718 ICE_AQC_REPORT_SW_CFG, caps, NULL);
720 netdev_info(vsi->netdev, "Get phy capability failed.\n");
722 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
723 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
725 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
726 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
727 fec_req = "FC-FEC/BASE-R";
731 devm_kfree(&vsi->back->pdev->dev, caps);
734 netdev_info(vsi->netdev, "NIC Link is up %sbps, Requested FEC: %s, FEC: %s, Flow Control: %s\n",
735 speed, fec_req, fec, fc);
739 * ice_vsi_link_event - update the VSI's netdev
740 * @vsi: the VSI on which the link event occurred
741 * @link_up: whether or not the VSI needs to be set up or down
743 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
748 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
751 if (vsi->type == ICE_VSI_PF) {
752 if (link_up == netif_carrier_ok(vsi->netdev))
756 netif_carrier_on(vsi->netdev);
757 netif_tx_wake_all_queues(vsi->netdev);
759 netif_carrier_off(vsi->netdev);
760 netif_tx_stop_all_queues(vsi->netdev);
766 * ice_link_event - process the link event
767 * @pf: pf that the link event is associated with
768 * @pi: port_info for the port that the link event is associated with
769 * @link_up: true if the physical link is up and false if it is down
770 * @link_speed: current link speed received from the link event
772 * Returns 0 on success and negative on failure
775 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
778 struct ice_phy_info *phy_info;
785 phy_info->link_info_old = phy_info->link_info;
787 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
788 old_link_speed = phy_info->link_info_old.link_speed;
790 /* update the link info structures and re-enable link events,
791 * don't bail on failure due to other book keeping needed
793 result = ice_update_link_info(pi);
795 dev_dbg(&pf->pdev->dev,
796 "Failed to update link status and re-enable link events for port %d\n",
799 /* if the old link up/down and speed is the same as the new */
800 if (link_up == old_link && link_speed == old_link_speed)
803 vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF);
804 if (!vsi || !vsi->port_info)
807 ice_vsi_link_event(vsi, link_up);
808 ice_print_link_msg(vsi, link_up);
810 if (pf->num_alloc_vfs)
811 ice_vc_notify_link_state(pf);
817 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
818 * @pf: board private structure
820 static void ice_watchdog_subtask(struct ice_pf *pf)
824 /* if interface is down do nothing */
825 if (test_bit(__ICE_DOWN, pf->state) ||
826 test_bit(__ICE_CFG_BUSY, pf->state))
829 /* make sure we don't do these things too often */
830 if (time_before(jiffies,
831 pf->serv_tmr_prev + pf->serv_tmr_period))
834 pf->serv_tmr_prev = jiffies;
836 /* Update the stats for active netdevs so the network stack
837 * can look at updated numbers whenever it cares to
839 ice_update_pf_stats(pf);
840 ice_for_each_vsi(pf, i)
841 if (pf->vsi[i] && pf->vsi[i]->netdev)
842 ice_update_vsi_stats(pf->vsi[i]);
846 * ice_init_link_events - enable/initialize link events
847 * @pi: pointer to the port_info instance
849 * Returns -EIO on failure, 0 on success
851 static int ice_init_link_events(struct ice_port_info *pi)
855 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
856 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
858 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
859 dev_dbg(ice_hw_to_dev(pi->hw),
860 "Failed to set link event mask for port %d\n",
865 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
866 dev_dbg(ice_hw_to_dev(pi->hw),
867 "Failed to enable link events for port %d\n",
876 * ice_handle_link_event - handle link event via ARQ
877 * @pf: pf that the link event is associated with
878 * @event: event structure containing link status info
881 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
883 struct ice_aqc_get_link_status_data *link_data;
884 struct ice_port_info *port_info;
887 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
888 port_info = pf->hw.port_info;
892 status = ice_link_event(pf, port_info,
893 !!(link_data->link_info & ICE_AQ_LINK_UP),
894 le16_to_cpu(link_data->link_speed));
896 dev_dbg(&pf->pdev->dev,
897 "Could not process link event, error %d\n", status);
903 * __ice_clean_ctrlq - helper function to clean controlq rings
904 * @pf: ptr to struct ice_pf
905 * @q_type: specific Control queue type
907 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
909 struct ice_rq_event_info event;
910 struct ice_hw *hw = &pf->hw;
911 struct ice_ctl_q_info *cq;
916 /* Do not clean control queue if/when PF reset fails */
917 if (test_bit(__ICE_RESET_FAILED, pf->state))
921 case ICE_CTL_Q_ADMIN:
925 case ICE_CTL_Q_MAILBOX:
930 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
935 /* check for error indications - PF_xx_AxQLEN register layout for
936 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
938 val = rd32(hw, cq->rq.len);
939 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
940 PF_FW_ARQLEN_ARQCRIT_M)) {
942 if (val & PF_FW_ARQLEN_ARQVFE_M)
943 dev_dbg(&pf->pdev->dev,
944 "%s Receive Queue VF Error detected\n", qtype);
945 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
946 dev_dbg(&pf->pdev->dev,
947 "%s Receive Queue Overflow Error detected\n",
950 if (val & PF_FW_ARQLEN_ARQCRIT_M)
951 dev_dbg(&pf->pdev->dev,
952 "%s Receive Queue Critical Error detected\n",
954 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
955 PF_FW_ARQLEN_ARQCRIT_M);
957 wr32(hw, cq->rq.len, val);
960 val = rd32(hw, cq->sq.len);
961 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
962 PF_FW_ATQLEN_ATQCRIT_M)) {
964 if (val & PF_FW_ATQLEN_ATQVFE_M)
965 dev_dbg(&pf->pdev->dev,
966 "%s Send Queue VF Error detected\n", qtype);
967 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
968 dev_dbg(&pf->pdev->dev,
969 "%s Send Queue Overflow Error detected\n",
972 if (val & PF_FW_ATQLEN_ATQCRIT_M)
973 dev_dbg(&pf->pdev->dev,
974 "%s Send Queue Critical Error detected\n",
976 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
977 PF_FW_ATQLEN_ATQCRIT_M);
979 wr32(hw, cq->sq.len, val);
982 event.buf_len = cq->rq_buf_size;
983 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
992 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
993 if (ret == ICE_ERR_AQ_NO_WORK)
996 dev_err(&pf->pdev->dev,
997 "%s Receive Queue event error %d\n", qtype,
1002 opcode = le16_to_cpu(event.desc.opcode);
1005 case ice_aqc_opc_get_link_status:
1006 if (ice_handle_link_event(pf, &event))
1007 dev_err(&pf->pdev->dev,
1008 "Could not handle link event\n");
1010 case ice_mbx_opc_send_msg_to_pf:
1011 ice_vc_process_vf_msg(pf, &event);
1013 case ice_aqc_opc_fw_logging:
1014 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1016 case ice_aqc_opc_lldp_set_mib_change:
1017 ice_dcb_process_lldp_set_mib_change(pf, &event);
1020 dev_dbg(&pf->pdev->dev,
1021 "%s Receive Queue unknown event 0x%04x ignored\n",
1025 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1027 devm_kfree(&pf->pdev->dev, event.msg_buf);
1029 return pending && (i == ICE_DFLT_IRQ_WORK);
1033 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1034 * @hw: pointer to hardware info
1035 * @cq: control queue information
1037 * returns true if there are pending messages in a queue, false if there aren't
1039 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1043 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1044 return cq->rq.next_to_clean != ntu;
1048 * ice_clean_adminq_subtask - clean the AdminQ rings
1049 * @pf: board private structure
1051 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1053 struct ice_hw *hw = &pf->hw;
1055 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1058 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1061 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1063 /* There might be a situation where new messages arrive to a control
1064 * queue between processing the last message and clearing the
1065 * EVENT_PENDING bit. So before exiting, check queue head again (using
1066 * ice_ctrlq_pending) and process new messages if any.
1068 if (ice_ctrlq_pending(hw, &hw->adminq))
1069 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1075 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1076 * @pf: board private structure
1078 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1080 struct ice_hw *hw = &pf->hw;
1082 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1085 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1088 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1090 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1091 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1097 * ice_service_task_schedule - schedule the service task to wake up
1098 * @pf: board private structure
1100 * If not already scheduled, this puts the task into the work queue.
1102 static void ice_service_task_schedule(struct ice_pf *pf)
1104 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1105 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1106 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1107 queue_work(ice_wq, &pf->serv_task);
1111 * ice_service_task_complete - finish up the service task
1112 * @pf: board private structure
1114 static void ice_service_task_complete(struct ice_pf *pf)
1116 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1118 /* force memory (pf->state) to sync before next service task */
1119 smp_mb__before_atomic();
1120 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1124 * ice_service_task_stop - stop service task and cancel works
1125 * @pf: board private structure
1127 static void ice_service_task_stop(struct ice_pf *pf)
1129 set_bit(__ICE_SERVICE_DIS, pf->state);
1131 if (pf->serv_tmr.function)
1132 del_timer_sync(&pf->serv_tmr);
1133 if (pf->serv_task.func)
1134 cancel_work_sync(&pf->serv_task);
1136 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1140 * ice_service_task_restart - restart service task and schedule works
1141 * @pf: board private structure
1143 * This function is needed for suspend and resume works (e.g WoL scenario)
1145 static void ice_service_task_restart(struct ice_pf *pf)
1147 clear_bit(__ICE_SERVICE_DIS, pf->state);
1148 ice_service_task_schedule(pf);
1152 * ice_service_timer - timer callback to schedule service task
1153 * @t: pointer to timer_list
1155 static void ice_service_timer(struct timer_list *t)
1157 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1159 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1160 ice_service_task_schedule(pf);
1164 * ice_handle_mdd_event - handle malicious driver detect event
1165 * @pf: pointer to the PF structure
1167 * Called from service task. OICR interrupt handler indicates MDD event
1169 static void ice_handle_mdd_event(struct ice_pf *pf)
1171 struct ice_hw *hw = &pf->hw;
1172 bool mdd_detected = false;
1176 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1179 /* find what triggered the MDD event */
1180 reg = rd32(hw, GL_MDET_TX_PQM);
1181 if (reg & GL_MDET_TX_PQM_VALID_M) {
1182 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1183 GL_MDET_TX_PQM_PF_NUM_S;
1184 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1185 GL_MDET_TX_PQM_VF_NUM_S;
1186 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1187 GL_MDET_TX_PQM_MAL_TYPE_S;
1188 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1189 GL_MDET_TX_PQM_QNUM_S);
1191 if (netif_msg_tx_err(pf))
1192 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1193 event, queue, pf_num, vf_num);
1194 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1195 mdd_detected = true;
1198 reg = rd32(hw, GL_MDET_TX_TCLAN);
1199 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1200 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1201 GL_MDET_TX_TCLAN_PF_NUM_S;
1202 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1203 GL_MDET_TX_TCLAN_VF_NUM_S;
1204 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1205 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1206 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1207 GL_MDET_TX_TCLAN_QNUM_S);
1209 if (netif_msg_rx_err(pf))
1210 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1211 event, queue, pf_num, vf_num);
1212 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1213 mdd_detected = true;
1216 reg = rd32(hw, GL_MDET_RX);
1217 if (reg & GL_MDET_RX_VALID_M) {
1218 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1219 GL_MDET_RX_PF_NUM_S;
1220 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1221 GL_MDET_RX_VF_NUM_S;
1222 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1223 GL_MDET_RX_MAL_TYPE_S;
1224 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1227 if (netif_msg_rx_err(pf))
1228 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1229 event, queue, pf_num, vf_num);
1230 wr32(hw, GL_MDET_RX, 0xffffffff);
1231 mdd_detected = true;
1235 bool pf_mdd_detected = false;
1237 reg = rd32(hw, PF_MDET_TX_PQM);
1238 if (reg & PF_MDET_TX_PQM_VALID_M) {
1239 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1240 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1241 pf_mdd_detected = true;
1244 reg = rd32(hw, PF_MDET_TX_TCLAN);
1245 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1246 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1247 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1248 pf_mdd_detected = true;
1251 reg = rd32(hw, PF_MDET_RX);
1252 if (reg & PF_MDET_RX_VALID_M) {
1253 wr32(hw, PF_MDET_RX, 0xFFFF);
1254 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
1255 pf_mdd_detected = true;
1257 /* Queue belongs to the PF initiate a reset */
1258 if (pf_mdd_detected) {
1259 set_bit(__ICE_NEEDS_RESTART, pf->state);
1260 ice_service_task_schedule(pf);
1264 /* check to see if one of the VFs caused the MDD */
1265 for (i = 0; i < pf->num_alloc_vfs; i++) {
1266 struct ice_vf *vf = &pf->vf[i];
1268 bool vf_mdd_detected = false;
1270 reg = rd32(hw, VP_MDET_TX_PQM(i));
1271 if (reg & VP_MDET_TX_PQM_VALID_M) {
1272 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1273 vf_mdd_detected = true;
1274 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1278 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1279 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1280 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1281 vf_mdd_detected = true;
1282 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1286 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1287 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1288 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1289 vf_mdd_detected = true;
1290 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1294 reg = rd32(hw, VP_MDET_RX(i));
1295 if (reg & VP_MDET_RX_VALID_M) {
1296 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1297 vf_mdd_detected = true;
1298 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1302 if (vf_mdd_detected) {
1303 vf->num_mdd_events++;
1304 if (vf->num_mdd_events > 1)
1305 dev_info(&pf->pdev->dev, "VF %d has had %llu MDD events since last boot\n",
1306 i, vf->num_mdd_events);
1312 * ice_service_task - manage and run subtasks
1313 * @work: pointer to work_struct contained by the PF struct
1315 static void ice_service_task(struct work_struct *work)
1317 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1318 unsigned long start_time = jiffies;
1322 /* process reset requests first */
1323 ice_reset_subtask(pf);
1325 /* bail if a reset/recovery cycle is pending or rebuild failed */
1326 if (ice_is_reset_in_progress(pf->state) ||
1327 test_bit(__ICE_SUSPENDED, pf->state) ||
1328 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1329 ice_service_task_complete(pf);
1333 ice_check_for_hang_subtask(pf);
1334 ice_sync_fltr_subtask(pf);
1335 ice_handle_mdd_event(pf);
1336 ice_process_vflr_event(pf);
1337 ice_watchdog_subtask(pf);
1338 ice_clean_adminq_subtask(pf);
1339 ice_clean_mailboxq_subtask(pf);
1341 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1342 ice_service_task_complete(pf);
1344 /* If the tasks have taken longer than one service timer period
1345 * or there is more work to be done, reset the service timer to
1346 * schedule the service task now.
1348 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1349 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1350 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1351 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1352 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1353 mod_timer(&pf->serv_tmr, jiffies);
1357 * ice_set_ctrlq_len - helper function to set controlq length
1358 * @hw: pointer to the HW instance
1360 static void ice_set_ctrlq_len(struct ice_hw *hw)
1362 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1363 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1364 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1365 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1366 hw->mailboxq.num_rq_entries = ICE_MBXQ_LEN;
1367 hw->mailboxq.num_sq_entries = ICE_MBXQ_LEN;
1368 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1369 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1373 * ice_irq_affinity_notify - Callback for affinity changes
1374 * @notify: context as to what irq was changed
1375 * @mask: the new affinity mask
1377 * This is a callback function used by the irq_set_affinity_notifier function
1378 * so that we may register to receive changes to the irq affinity masks.
1381 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1382 const cpumask_t *mask)
1384 struct ice_q_vector *q_vector =
1385 container_of(notify, struct ice_q_vector, affinity_notify);
1387 cpumask_copy(&q_vector->affinity_mask, mask);
1391 * ice_irq_affinity_release - Callback for affinity notifier release
1392 * @ref: internal core kernel usage
1394 * This is a callback function used by the irq_set_affinity_notifier function
1395 * to inform the current notification subscriber that they will no longer
1396 * receive notifications.
1398 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1401 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1402 * @vsi: the VSI being configured
1404 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1406 struct ice_pf *pf = vsi->back;
1407 struct ice_hw *hw = &pf->hw;
1409 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
1412 ice_for_each_q_vector(vsi, i)
1413 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1421 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1422 * @vsi: the VSI being configured
1423 * @basename: name for the vector
1425 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1427 int q_vectors = vsi->num_q_vectors;
1428 struct ice_pf *pf = vsi->back;
1429 int base = vsi->base_vector;
1435 for (vector = 0; vector < q_vectors; vector++) {
1436 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1438 irq_num = pf->msix_entries[base + vector].vector;
1440 if (q_vector->tx.ring && q_vector->rx.ring) {
1441 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1442 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1444 } else if (q_vector->rx.ring) {
1445 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1446 "%s-%s-%d", basename, "rx", rx_int_idx++);
1447 } else if (q_vector->tx.ring) {
1448 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1449 "%s-%s-%d", basename, "tx", tx_int_idx++);
1451 /* skip this unused q_vector */
1454 err = devm_request_irq(&pf->pdev->dev, irq_num,
1455 vsi->irq_handler, 0,
1456 q_vector->name, q_vector);
1458 netdev_err(vsi->netdev,
1459 "MSIX request_irq failed, error: %d\n", err);
1463 /* register for affinity change notifications */
1464 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1465 q_vector->affinity_notify.release = ice_irq_affinity_release;
1466 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1468 /* assign the mask for this irq */
1469 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1472 vsi->irqs_ready = true;
1478 irq_num = pf->msix_entries[base + vector].vector,
1479 irq_set_affinity_notifier(irq_num, NULL);
1480 irq_set_affinity_hint(irq_num, NULL);
1481 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1487 * ice_ena_misc_vector - enable the non-queue interrupts
1488 * @pf: board private structure
1490 static void ice_ena_misc_vector(struct ice_pf *pf)
1492 struct ice_hw *hw = &pf->hw;
1495 /* clear things first */
1496 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1497 rd32(hw, PFINT_OICR); /* read to clear */
1499 val = (PFINT_OICR_ECC_ERR_M |
1500 PFINT_OICR_MAL_DETECT_M |
1502 PFINT_OICR_PCI_EXCEPTION_M |
1504 PFINT_OICR_HMC_ERR_M |
1505 PFINT_OICR_PE_CRITERR_M);
1507 wr32(hw, PFINT_OICR_ENA, val);
1509 /* SW_ITR_IDX = 0, but don't change INTENA */
1510 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
1511 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1515 * ice_misc_intr - misc interrupt handler
1516 * @irq: interrupt number
1517 * @data: pointer to a q_vector
1519 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1521 struct ice_pf *pf = (struct ice_pf *)data;
1522 struct ice_hw *hw = &pf->hw;
1523 irqreturn_t ret = IRQ_NONE;
1526 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1527 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1529 oicr = rd32(hw, PFINT_OICR);
1530 ena_mask = rd32(hw, PFINT_OICR_ENA);
1532 if (oicr & PFINT_OICR_SWINT_M) {
1533 ena_mask &= ~PFINT_OICR_SWINT_M;
1537 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1538 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1539 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1541 if (oicr & PFINT_OICR_VFLR_M) {
1542 ena_mask &= ~PFINT_OICR_VFLR_M;
1543 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1546 if (oicr & PFINT_OICR_GRST_M) {
1549 /* we have a reset warning */
1550 ena_mask &= ~PFINT_OICR_GRST_M;
1551 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1552 GLGEN_RSTAT_RESET_TYPE_S;
1554 if (reset == ICE_RESET_CORER)
1556 else if (reset == ICE_RESET_GLOBR)
1558 else if (reset == ICE_RESET_EMPR)
1561 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1564 /* If a reset cycle isn't already in progress, we set a bit in
1565 * pf->state so that the service task can start a reset/rebuild.
1566 * We also make note of which reset happened so that peer
1567 * devices/drivers can be informed.
1569 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1570 if (reset == ICE_RESET_CORER)
1571 set_bit(__ICE_CORER_RECV, pf->state);
1572 else if (reset == ICE_RESET_GLOBR)
1573 set_bit(__ICE_GLOBR_RECV, pf->state);
1575 set_bit(__ICE_EMPR_RECV, pf->state);
1577 /* There are couple of different bits at play here.
1578 * hw->reset_ongoing indicates whether the hardware is
1579 * in reset. This is set to true when a reset interrupt
1580 * is received and set back to false after the driver
1581 * has determined that the hardware is out of reset.
1583 * __ICE_RESET_OICR_RECV in pf->state indicates
1584 * that a post reset rebuild is required before the
1585 * driver is operational again. This is set above.
1587 * As this is the start of the reset/rebuild cycle, set
1588 * both to indicate that.
1590 hw->reset_ongoing = true;
1594 if (oicr & PFINT_OICR_HMC_ERR_M) {
1595 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1596 dev_dbg(&pf->pdev->dev,
1597 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1598 rd32(hw, PFHMC_ERRORINFO),
1599 rd32(hw, PFHMC_ERRORDATA));
1602 /* Report any remaining unexpected interrupts */
1605 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1607 /* If a critical error is pending there is no choice but to
1610 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1611 PFINT_OICR_PCI_EXCEPTION_M |
1612 PFINT_OICR_ECC_ERR_M)) {
1613 set_bit(__ICE_PFR_REQ, pf->state);
1614 ice_service_task_schedule(pf);
1619 if (!test_bit(__ICE_DOWN, pf->state)) {
1620 ice_service_task_schedule(pf);
1621 ice_irq_dynamic_ena(hw, NULL, NULL);
1628 * ice_dis_ctrlq_interrupts - disable control queue interrupts
1629 * @hw: pointer to HW structure
1631 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
1633 /* disable Admin queue Interrupt causes */
1634 wr32(hw, PFINT_FW_CTL,
1635 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
1637 /* disable Mailbox queue Interrupt causes */
1638 wr32(hw, PFINT_MBX_CTL,
1639 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
1641 /* disable Control queue Interrupt causes */
1642 wr32(hw, PFINT_OICR_CTL,
1643 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
1649 * ice_free_irq_msix_misc - Unroll misc vector setup
1650 * @pf: board private structure
1652 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1654 struct ice_hw *hw = &pf->hw;
1656 ice_dis_ctrlq_interrupts(hw);
1658 /* disable OICR interrupt */
1659 wr32(hw, PFINT_OICR_ENA, 0);
1662 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags) && pf->msix_entries) {
1663 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
1664 devm_free_irq(&pf->pdev->dev,
1665 pf->msix_entries[pf->oicr_idx].vector, pf);
1668 pf->num_avail_sw_msix += 1;
1669 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
1673 * ice_ena_ctrlq_interrupts - enable control queue interrupts
1674 * @hw: pointer to HW structure
1675 * @reg_idx: HW vector index to associate the control queue interrupts with
1677 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
1681 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1682 PFINT_OICR_CTL_CAUSE_ENA_M);
1683 wr32(hw, PFINT_OICR_CTL, val);
1685 /* enable Admin queue Interrupt causes */
1686 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1687 PFINT_FW_CTL_CAUSE_ENA_M);
1688 wr32(hw, PFINT_FW_CTL, val);
1690 /* enable Mailbox queue Interrupt causes */
1691 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1692 PFINT_MBX_CTL_CAUSE_ENA_M);
1693 wr32(hw, PFINT_MBX_CTL, val);
1699 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1700 * @pf: board private structure
1702 * This sets up the handler for MSIX 0, which is used to manage the
1703 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1704 * when in MSI or Legacy interrupt mode.
1706 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1708 struct ice_hw *hw = &pf->hw;
1709 int oicr_idx, err = 0;
1711 if (!pf->int_name[0])
1712 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1713 dev_driver_string(&pf->pdev->dev),
1714 dev_name(&pf->pdev->dev));
1716 /* Do not request IRQ but do enable OICR interrupt since settings are
1717 * lost during reset. Note that this function is called only during
1718 * rebuild path and not while reset is in progress.
1720 if (ice_is_reset_in_progress(pf->state))
1723 /* reserve one vector in irq_tracker for misc interrupts */
1724 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1728 pf->num_avail_sw_msix -= 1;
1729 pf->oicr_idx = oicr_idx;
1731 err = devm_request_irq(&pf->pdev->dev,
1732 pf->msix_entries[pf->oicr_idx].vector,
1733 ice_misc_intr, 0, pf->int_name, pf);
1735 dev_err(&pf->pdev->dev,
1736 "devm_request_irq for %s failed: %d\n",
1738 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1739 pf->num_avail_sw_msix += 1;
1744 ice_ena_misc_vector(pf);
1746 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
1747 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
1748 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
1751 ice_irq_dynamic_ena(hw, NULL, NULL);
1757 * ice_napi_add - register NAPI handler for the VSI
1758 * @vsi: VSI for which NAPI handler is to be registered
1760 * This function is only called in the driver's load path. Registering the NAPI
1761 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1762 * reset/rebuild, etc.)
1764 static void ice_napi_add(struct ice_vsi *vsi)
1771 ice_for_each_q_vector(vsi, v_idx)
1772 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1773 ice_napi_poll, NAPI_POLL_WEIGHT);
1777 * ice_cfg_netdev - Allocate, configure and register a netdev
1778 * @vsi: the VSI associated with the new netdev
1780 * Returns 0 on success, negative value on failure
1782 static int ice_cfg_netdev(struct ice_vsi *vsi)
1784 netdev_features_t csumo_features;
1785 netdev_features_t vlano_features;
1786 netdev_features_t dflt_features;
1787 netdev_features_t tso_features;
1788 struct ice_netdev_priv *np;
1789 struct net_device *netdev;
1790 u8 mac_addr[ETH_ALEN];
1793 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
1798 vsi->netdev = netdev;
1799 np = netdev_priv(netdev);
1802 dflt_features = NETIF_F_SG |
1806 csumo_features = NETIF_F_RXCSUM |
1811 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1812 NETIF_F_HW_VLAN_CTAG_TX |
1813 NETIF_F_HW_VLAN_CTAG_RX;
1815 tso_features = NETIF_F_TSO;
1817 /* set features that user can change */
1818 netdev->hw_features = dflt_features | csumo_features |
1819 vlano_features | tso_features;
1821 /* enable features */
1822 netdev->features |= netdev->hw_features;
1823 /* encap and VLAN devices inherit default, csumo and tso features */
1824 netdev->hw_enc_features |= dflt_features | csumo_features |
1826 netdev->vlan_features |= dflt_features | csumo_features |
1829 if (vsi->type == ICE_VSI_PF) {
1830 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1831 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1833 ether_addr_copy(netdev->dev_addr, mac_addr);
1834 ether_addr_copy(netdev->perm_addr, mac_addr);
1837 netdev->priv_flags |= IFF_UNICAST_FLT;
1839 /* assign netdev_ops */
1840 netdev->netdev_ops = &ice_netdev_ops;
1842 /* setup watchdog timeout value to be 5 second */
1843 netdev->watchdog_timeo = 5 * HZ;
1845 ice_set_ethtool_ops(netdev);
1847 netdev->min_mtu = ETH_MIN_MTU;
1848 netdev->max_mtu = ICE_MAX_MTU;
1850 err = register_netdev(vsi->netdev);
1854 netif_carrier_off(vsi->netdev);
1856 /* make sure transmit queues start off as stopped */
1857 netif_tx_stop_all_queues(vsi->netdev);
1863 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1864 * @lut: Lookup table
1865 * @rss_table_size: Lookup table size
1866 * @rss_size: Range of queue number for hashing
1868 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
1872 for (i = 0; i < rss_table_size; i++)
1873 lut[i] = i % rss_size;
1877 * ice_pf_vsi_setup - Set up a PF VSI
1878 * @pf: board private structure
1879 * @pi: pointer to the port_info instance
1881 * Returns pointer to the successfully allocated VSI software struct
1882 * on success, otherwise returns NULL on failure.
1884 static struct ice_vsi *
1885 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1887 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
1891 * ice_lb_vsi_setup - Set up a loopback VSI
1892 * @pf: board private structure
1893 * @pi: pointer to the port_info instance
1895 * Returns pointer to the successfully allocated VSI software struct
1896 * on success, otherwise returns NULL on failure.
1899 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
1901 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
1905 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
1906 * @netdev: network interface to be adjusted
1907 * @proto: unused protocol
1908 * @vid: VLAN ID to be added
1910 * net_device_ops implementation for adding VLAN IDs
1913 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
1916 struct ice_netdev_priv *np = netdev_priv(netdev);
1917 struct ice_vsi *vsi = np->vsi;
1920 if (vid >= VLAN_N_VID) {
1921 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
1929 /* Enable VLAN pruning when VLAN 0 is added */
1930 if (unlikely(!vid)) {
1931 ret = ice_cfg_vlan_pruning(vsi, true, false);
1936 /* Add all VLAN IDs including 0 to the switch filter. VLAN ID 0 is
1937 * needed to continue allowing all untagged packets since VLAN prune
1938 * list is applied to all packets by the switch
1940 ret = ice_vsi_add_vlan(vsi, vid);
1942 vsi->vlan_ena = true;
1943 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
1950 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
1951 * @netdev: network interface to be adjusted
1952 * @proto: unused protocol
1953 * @vid: VLAN ID to be removed
1955 * net_device_ops implementation for removing VLAN IDs
1958 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
1961 struct ice_netdev_priv *np = netdev_priv(netdev);
1962 struct ice_vsi *vsi = np->vsi;
1968 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
1971 ret = ice_vsi_kill_vlan(vsi, vid);
1975 /* Disable VLAN pruning when VLAN 0 is removed */
1977 ret = ice_cfg_vlan_pruning(vsi, false, false);
1979 vsi->vlan_ena = false;
1980 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
1985 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
1986 * @pf: board private structure
1988 * Returns 0 on success, negative value on failure
1990 static int ice_setup_pf_sw(struct ice_pf *pf)
1992 struct ice_vsi *vsi;
1995 if (ice_is_reset_in_progress(pf->state))
1998 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2001 goto unroll_vsi_setup;
2004 status = ice_cfg_netdev(vsi);
2007 goto unroll_vsi_setup;
2010 /* registering the NAPI handler requires both the queues and
2011 * netdev to be created, which are done in ice_pf_vsi_setup()
2012 * and ice_cfg_netdev() respectively
2016 status = ice_init_mac_fltr(pf);
2018 goto unroll_napi_add;
2026 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2027 unregister_netdev(vsi->netdev);
2028 free_netdev(vsi->netdev);
2035 ice_vsi_free_q_vectors(vsi);
2036 ice_vsi_delete(vsi);
2037 ice_vsi_put_qs(vsi);
2038 pf->q_left_tx += vsi->alloc_txq;
2039 pf->q_left_rx += vsi->alloc_rxq;
2046 * ice_determine_q_usage - Calculate queue distribution
2047 * @pf: board private structure
2049 * Return -ENOMEM if we don't get enough queues for all ports
2051 static void ice_determine_q_usage(struct ice_pf *pf)
2053 u16 q_left_tx, q_left_rx;
2055 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
2056 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
2058 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
2060 /* only 1 Rx queue unless RSS is enabled */
2061 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2064 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
2066 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
2067 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
2071 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2072 * @pf: board private structure to initialize
2074 static void ice_deinit_pf(struct ice_pf *pf)
2076 ice_service_task_stop(pf);
2077 mutex_destroy(&pf->sw_mutex);
2078 mutex_destroy(&pf->avail_q_mutex);
2082 * ice_init_pf - Initialize general software structures (struct ice_pf)
2083 * @pf: board private structure to initialize
2085 static void ice_init_pf(struct ice_pf *pf)
2087 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
2088 set_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2089 #ifdef CONFIG_PCI_IOV
2090 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
2091 struct ice_hw *hw = &pf->hw;
2093 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2094 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
2097 #endif /* CONFIG_PCI_IOV */
2099 mutex_init(&pf->sw_mutex);
2100 mutex_init(&pf->avail_q_mutex);
2102 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
2103 mutex_lock(&pf->avail_q_mutex);
2104 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
2105 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
2106 mutex_unlock(&pf->avail_q_mutex);
2108 if (pf->hw.func_caps.common_cap.rss_table_size)
2109 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2111 /* setup service timer and periodic service task */
2112 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2113 pf->serv_tmr_period = HZ;
2114 INIT_WORK(&pf->serv_task, ice_service_task);
2115 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2119 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2120 * @pf: board private structure
2122 * compute the number of MSIX vectors required (v_budget) and request from
2123 * the OS. Return the number of vectors reserved or negative on failure
2125 static int ice_ena_msix_range(struct ice_pf *pf)
2127 int v_left, v_actual, v_budget = 0;
2130 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2132 /* reserve one vector for miscellaneous handler */
2137 /* reserve vectors for LAN traffic */
2138 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
2139 v_budget += pf->num_lan_msix;
2140 v_left -= pf->num_lan_msix;
2142 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
2143 sizeof(*pf->msix_entries), GFP_KERNEL);
2145 if (!pf->msix_entries) {
2150 for (i = 0; i < v_budget; i++)
2151 pf->msix_entries[i].entry = i;
2153 /* actually reserve the vectors */
2154 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2155 ICE_MIN_MSIX, v_budget);
2158 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
2163 if (v_actual < v_budget) {
2164 dev_warn(&pf->pdev->dev,
2165 "not enough vectors. requested = %d, obtained = %d\n",
2166 v_budget, v_actual);
2167 if (v_actual >= (pf->num_lan_msix + 1)) {
2168 pf->num_avail_sw_msix = v_actual -
2169 (pf->num_lan_msix + 1);
2170 } else if (v_actual >= 2) {
2171 pf->num_lan_msix = 1;
2172 pf->num_avail_sw_msix = v_actual - 2;
2174 pci_disable_msix(pf->pdev);
2183 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2187 pf->num_lan_msix = 0;
2188 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2193 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2194 * @pf: board private structure
2196 static void ice_dis_msix(struct ice_pf *pf)
2198 pci_disable_msix(pf->pdev);
2199 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2200 pf->msix_entries = NULL;
2201 clear_bit(ICE_FLAG_MSIX_ENA, pf->flags);
2205 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2206 * @pf: board private structure
2208 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2210 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2213 if (pf->irq_tracker) {
2214 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
2215 pf->irq_tracker = NULL;
2220 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2221 * @pf: board private structure to initialize
2223 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2227 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
2228 vectors = ice_ena_msix_range(pf);
2235 /* set up vector assignment tracking */
2237 devm_kzalloc(&pf->pdev->dev, sizeof(*pf->irq_tracker) +
2238 (sizeof(u16) * vectors), GFP_KERNEL);
2239 if (!pf->irq_tracker) {
2244 /* populate SW interrupts pool with number of OS granted IRQs. */
2245 pf->num_avail_sw_msix = vectors;
2246 pf->irq_tracker->num_entries = vectors;
2247 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2253 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
2254 * @pf: pointer to the PF structure
2256 * There is no error returned here because the driver should be able to handle
2257 * 128 Byte cache lines, so we only print a warning in case issues are seen,
2258 * specifically with Tx.
2260 static void ice_verify_cacheline_size(struct ice_pf *pf)
2262 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
2263 dev_warn(&pf->pdev->dev,
2264 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
2265 ICE_CACHE_LINE_BYTES);
2269 * ice_probe - Device initialization routine
2270 * @pdev: PCI device information struct
2271 * @ent: entry in ice_pci_tbl
2273 * Returns 0 on success, negative on failure
2276 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
2278 struct device *dev = &pdev->dev;
2283 /* this driver uses devres, see Documentation/driver-model/devres.txt */
2284 err = pcim_enable_device(pdev);
2288 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2290 dev_err(dev, "BAR0 I/O map error %d\n", err);
2294 pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
2298 /* set up for high or low dma */
2299 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2301 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
2303 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
2307 pci_enable_pcie_error_reporting(pdev);
2308 pci_set_master(pdev);
2311 pci_set_drvdata(pdev, pf);
2312 set_bit(__ICE_DOWN, pf->state);
2313 /* Disable service task until DOWN bit is cleared */
2314 set_bit(__ICE_SERVICE_DIS, pf->state);
2317 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2319 hw->vendor_id = pdev->vendor;
2320 hw->device_id = pdev->device;
2321 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2322 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2323 hw->subsystem_device_id = pdev->subsystem_device;
2324 hw->bus.device = PCI_SLOT(pdev->devfn);
2325 hw->bus.func = PCI_FUNC(pdev->devfn);
2326 ice_set_ctrlq_len(hw);
2328 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2330 #ifndef CONFIG_DYNAMIC_DEBUG
2332 hw->debug_mask = debug;
2335 err = ice_init_hw(hw);
2337 dev_err(dev, "ice_init_hw failed: %d\n", err);
2339 goto err_exit_unroll;
2342 dev_info(dev, "firmware %d.%d.%05d api %d.%d\n",
2343 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2344 hw->api_maj_ver, hw->api_min_ver);
2348 err = ice_init_pf_dcb(pf, false);
2350 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2351 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
2353 /* do not fail overall init if DCB init fails */
2357 ice_determine_q_usage(pf);
2359 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
2360 if (!pf->num_alloc_vsi) {
2362 goto err_init_pf_unroll;
2365 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
2369 goto err_init_pf_unroll;
2372 err = ice_init_interrupt_scheme(pf);
2374 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
2376 goto err_init_interrupt_unroll;
2379 /* Driver is mostly up */
2380 clear_bit(__ICE_DOWN, pf->state);
2382 /* In case of MSIX we are going to setup the misc vector right here
2383 * to handle admin queue events etc. In case of legacy and MSI
2384 * the misc functionality and queue processing is combined in
2385 * the same vector and that gets setup at open.
2387 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
2388 err = ice_req_irq_msix_misc(pf);
2390 dev_err(dev, "setup of misc vector failed: %d\n", err);
2391 goto err_init_interrupt_unroll;
2395 /* create switch struct for the switch element created by FW on boot */
2396 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
2397 if (!pf->first_sw) {
2399 goto err_msix_misc_unroll;
2403 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2405 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2407 pf->first_sw->pf = pf;
2409 /* record the sw_id available for later use */
2410 pf->first_sw->sw_id = hw->port_info->sw_id;
2412 err = ice_setup_pf_sw(pf);
2414 dev_err(dev, "probe failed due to setup pf switch:%d\n", err);
2415 goto err_alloc_sw_unroll;
2418 clear_bit(__ICE_SERVICE_DIS, pf->state);
2420 /* since everything is good, start the service timer */
2421 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2423 err = ice_init_link_events(pf->hw.port_info);
2425 dev_err(dev, "ice_init_link_events failed: %d\n", err);
2426 goto err_alloc_sw_unroll;
2429 ice_verify_cacheline_size(pf);
2433 err_alloc_sw_unroll:
2434 set_bit(__ICE_SERVICE_DIS, pf->state);
2435 set_bit(__ICE_DOWN, pf->state);
2436 devm_kfree(&pf->pdev->dev, pf->first_sw);
2437 err_msix_misc_unroll:
2438 ice_free_irq_msix_misc(pf);
2439 err_init_interrupt_unroll:
2440 ice_clear_interrupt_scheme(pf);
2441 devm_kfree(dev, pf->vsi);
2446 pci_disable_pcie_error_reporting(pdev);
2451 * ice_remove - Device removal routine
2452 * @pdev: PCI device information struct
2454 static void ice_remove(struct pci_dev *pdev)
2456 struct ice_pf *pf = pci_get_drvdata(pdev);
2462 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
2463 if (!ice_is_reset_in_progress(pf->state))
2468 set_bit(__ICE_DOWN, pf->state);
2469 ice_service_task_stop(pf);
2471 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2473 ice_vsi_release_all(pf);
2474 ice_free_irq_msix_misc(pf);
2475 ice_for_each_vsi(pf, i) {
2478 ice_vsi_free_q_vectors(pf->vsi[i]);
2480 ice_clear_interrupt_scheme(pf);
2482 ice_deinit_hw(&pf->hw);
2483 pci_disable_pcie_error_reporting(pdev);
2487 * ice_pci_err_detected - warning that PCI error has been detected
2488 * @pdev: PCI device information struct
2489 * @err: the type of PCI error
2491 * Called to warn that something happened on the PCI bus and the error handling
2492 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
2494 static pci_ers_result_t
2495 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
2497 struct ice_pf *pf = pci_get_drvdata(pdev);
2500 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
2502 return PCI_ERS_RESULT_DISCONNECT;
2505 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2506 ice_service_task_stop(pf);
2508 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2509 set_bit(__ICE_PFR_REQ, pf->state);
2510 ice_prepare_for_reset(pf);
2514 return PCI_ERS_RESULT_NEED_RESET;
2518 * ice_pci_err_slot_reset - a PCI slot reset has just happened
2519 * @pdev: PCI device information struct
2521 * Called to determine if the driver can recover from the PCI slot reset by
2522 * using a register read to determine if the device is recoverable.
2524 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
2526 struct ice_pf *pf = pci_get_drvdata(pdev);
2527 pci_ers_result_t result;
2531 err = pci_enable_device_mem(pdev);
2534 "Cannot re-enable PCI device after reset, error %d\n",
2536 result = PCI_ERS_RESULT_DISCONNECT;
2538 pci_set_master(pdev);
2539 pci_restore_state(pdev);
2540 pci_save_state(pdev);
2541 pci_wake_from_d3(pdev, false);
2543 /* Check for life */
2544 reg = rd32(&pf->hw, GLGEN_RTRIG);
2546 result = PCI_ERS_RESULT_RECOVERED;
2548 result = PCI_ERS_RESULT_DISCONNECT;
2551 err = pci_cleanup_aer_uncorrect_error_status(pdev);
2554 "pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
2556 /* non-fatal, continue */
2562 * ice_pci_err_resume - restart operations after PCI error recovery
2563 * @pdev: PCI device information struct
2565 * Called to allow the driver to bring things back up after PCI error and/or
2566 * reset recovery have finished
2568 static void ice_pci_err_resume(struct pci_dev *pdev)
2570 struct ice_pf *pf = pci_get_drvdata(pdev);
2574 "%s failed, device is unrecoverable\n", __func__);
2578 if (test_bit(__ICE_SUSPENDED, pf->state)) {
2579 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
2584 ice_do_reset(pf, ICE_RESET_PFR);
2585 ice_service_task_restart(pf);
2586 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2590 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
2591 * @pdev: PCI device information struct
2593 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
2595 struct ice_pf *pf = pci_get_drvdata(pdev);
2597 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2598 ice_service_task_stop(pf);
2600 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2601 set_bit(__ICE_PFR_REQ, pf->state);
2602 ice_prepare_for_reset(pf);
2608 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
2609 * @pdev: PCI device information struct
2611 static void ice_pci_err_reset_done(struct pci_dev *pdev)
2613 ice_pci_err_resume(pdev);
2616 /* ice_pci_tbl - PCI Device ID Table
2618 * Wildcard entries (PCI_ANY_ID) should come last
2619 * Last entry must be all 0s
2621 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2622 * Class, Class Mask, private data (not used) }
2624 static const struct pci_device_id ice_pci_tbl[] = {
2625 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
2626 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
2627 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
2628 /* required last entry */
2631 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2633 static const struct pci_error_handlers ice_pci_err_handler = {
2634 .error_detected = ice_pci_err_detected,
2635 .slot_reset = ice_pci_err_slot_reset,
2636 .reset_prepare = ice_pci_err_reset_prepare,
2637 .reset_done = ice_pci_err_reset_done,
2638 .resume = ice_pci_err_resume
2641 static struct pci_driver ice_driver = {
2642 .name = KBUILD_MODNAME,
2643 .id_table = ice_pci_tbl,
2645 .remove = ice_remove,
2646 .sriov_configure = ice_sriov_configure,
2647 .err_handler = &ice_pci_err_handler
2651 * ice_module_init - Driver registration routine
2653 * ice_module_init is the first routine called when the driver is
2654 * loaded. All it does is register with the PCI subsystem.
2656 static int __init ice_module_init(void)
2660 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2661 pr_info("%s\n", ice_copyright);
2663 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2665 pr_err("Failed to create workqueue\n");
2669 status = pci_register_driver(&ice_driver);
2671 pr_err("failed to register pci driver, err %d\n", status);
2672 destroy_workqueue(ice_wq);
2677 module_init(ice_module_init);
2680 * ice_module_exit - Driver exit cleanup routine
2682 * ice_module_exit is called just before the driver is removed
2685 static void __exit ice_module_exit(void)
2687 pci_unregister_driver(&ice_driver);
2688 destroy_workqueue(ice_wq);
2689 pr_info("module unloaded\n");
2691 module_exit(ice_module_exit);
2694 * ice_set_mac_address - NDO callback to set MAC address
2695 * @netdev: network interface device structure
2696 * @pi: pointer to an address structure
2698 * Returns 0 on success, negative on failure
2700 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2702 struct ice_netdev_priv *np = netdev_priv(netdev);
2703 struct ice_vsi *vsi = np->vsi;
2704 struct ice_pf *pf = vsi->back;
2705 struct ice_hw *hw = &pf->hw;
2706 struct sockaddr *addr = pi;
2707 enum ice_status status;
2708 LIST_HEAD(a_mac_list);
2709 LIST_HEAD(r_mac_list);
2714 mac = (u8 *)addr->sa_data;
2716 if (!is_valid_ether_addr(mac))
2717 return -EADDRNOTAVAIL;
2719 if (ether_addr_equal(netdev->dev_addr, mac)) {
2720 netdev_warn(netdev, "already using mac %pM\n", mac);
2724 if (test_bit(__ICE_DOWN, pf->state) ||
2725 ice_is_reset_in_progress(pf->state)) {
2726 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2731 /* When we change the MAC address we also have to change the MAC address
2732 * based filter rules that were created previously for the old MAC
2733 * address. So first, we remove the old filter rule using ice_remove_mac
2734 * and then create a new filter rule using ice_add_mac. Note that for
2735 * both these operations, we first need to form a "list" of MAC
2736 * addresses (even though in this case, we have only 1 MAC address to be
2737 * added/removed) and this done using ice_add_mac_to_list. Depending on
2738 * the ensuing operation this "list" of MAC addresses is either to be
2739 * added or removed from the filter.
2741 err = ice_add_mac_to_list(vsi, &r_mac_list, netdev->dev_addr);
2743 err = -EADDRNOTAVAIL;
2747 status = ice_remove_mac(hw, &r_mac_list);
2749 err = -EADDRNOTAVAIL;
2753 err = ice_add_mac_to_list(vsi, &a_mac_list, mac);
2755 err = -EADDRNOTAVAIL;
2759 status = ice_add_mac(hw, &a_mac_list);
2761 err = -EADDRNOTAVAIL;
2766 /* free list entries */
2767 ice_free_fltr_list(&pf->pdev->dev, &r_mac_list);
2768 ice_free_fltr_list(&pf->pdev->dev, &a_mac_list);
2771 netdev_err(netdev, "can't set mac %pM. filter update failed\n",
2776 /* change the netdev's MAC address */
2777 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2778 netdev_dbg(vsi->netdev, "updated mac address to %pM\n",
2781 /* write new MAC address to the firmware */
2782 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2783 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2785 netdev_err(netdev, "can't set mac %pM. write to firmware failed.\n",
2792 * ice_set_rx_mode - NDO callback to set the netdev filters
2793 * @netdev: network interface device structure
2795 static void ice_set_rx_mode(struct net_device *netdev)
2797 struct ice_netdev_priv *np = netdev_priv(netdev);
2798 struct ice_vsi *vsi = np->vsi;
2803 /* Set the flags to synchronize filters
2804 * ndo_set_rx_mode may be triggered even without a change in netdev
2807 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2808 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2809 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2811 /* schedule our worker thread which will take care of
2812 * applying the new filter changes
2814 ice_service_task_schedule(vsi->back);
2818 * ice_fdb_add - add an entry to the hardware database
2819 * @ndm: the input from the stack
2820 * @tb: pointer to array of nladdr (unused)
2821 * @dev: the net device pointer
2822 * @addr: the MAC address entry being added
2824 * @flags: instructions from stack about fdb operation
2825 * @extack: netlink extended ack
2828 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2829 struct net_device *dev, const unsigned char *addr, u16 vid,
2830 u16 flags, struct netlink_ext_ack __always_unused *extack)
2835 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2838 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2839 netdev_err(dev, "FDB only supports static addresses\n");
2843 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2844 err = dev_uc_add_excl(dev, addr);
2845 else if (is_multicast_ether_addr(addr))
2846 err = dev_mc_add_excl(dev, addr);
2850 /* Only return duplicate errors if NLM_F_EXCL is set */
2851 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2858 * ice_fdb_del - delete an entry from the hardware database
2859 * @ndm: the input from the stack
2860 * @tb: pointer to array of nladdr (unused)
2861 * @dev: the net device pointer
2862 * @addr: the MAC address entry being added
2866 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2867 struct net_device *dev, const unsigned char *addr,
2868 __always_unused u16 vid)
2872 if (ndm->ndm_state & NUD_PERMANENT) {
2873 netdev_err(dev, "FDB only supports static addresses\n");
2877 if (is_unicast_ether_addr(addr))
2878 err = dev_uc_del(dev, addr);
2879 else if (is_multicast_ether_addr(addr))
2880 err = dev_mc_del(dev, addr);
2888 * ice_set_features - set the netdev feature flags
2889 * @netdev: ptr to the netdev being adjusted
2890 * @features: the feature set that the stack is suggesting
2893 ice_set_features(struct net_device *netdev, netdev_features_t features)
2895 struct ice_netdev_priv *np = netdev_priv(netdev);
2896 struct ice_vsi *vsi = np->vsi;
2899 /* Multiple features can be changed in one call so keep features in
2900 * separate if/else statements to guarantee each feature is checked
2902 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
2903 ret = ice_vsi_manage_rss_lut(vsi, true);
2904 else if (!(features & NETIF_F_RXHASH) &&
2905 netdev->features & NETIF_F_RXHASH)
2906 ret = ice_vsi_manage_rss_lut(vsi, false);
2908 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
2909 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2910 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2911 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
2912 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
2913 ret = ice_vsi_manage_vlan_stripping(vsi, false);
2915 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
2916 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2917 ret = ice_vsi_manage_vlan_insertion(vsi);
2918 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
2919 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
2920 ret = ice_vsi_manage_vlan_insertion(vsi);
2922 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
2923 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
2924 ret = ice_cfg_vlan_pruning(vsi, true, false);
2925 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
2926 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
2927 ret = ice_cfg_vlan_pruning(vsi, false, false);
2933 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
2934 * @vsi: VSI to setup VLAN properties for
2936 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
2940 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
2941 ret = ice_vsi_manage_vlan_stripping(vsi, true);
2942 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
2943 ret = ice_vsi_manage_vlan_insertion(vsi);
2949 * ice_vsi_cfg - Setup the VSI
2950 * @vsi: the VSI being configured
2952 * Return 0 on success and negative value on error
2954 int ice_vsi_cfg(struct ice_vsi *vsi)
2959 ice_set_rx_mode(vsi->netdev);
2961 err = ice_vsi_vlan_setup(vsi);
2966 ice_vsi_cfg_dcb_rings(vsi);
2968 err = ice_vsi_cfg_lan_txqs(vsi);
2970 err = ice_vsi_cfg_rxqs(vsi);
2976 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
2977 * @vsi: the VSI being configured
2979 static void ice_napi_enable_all(struct ice_vsi *vsi)
2986 ice_for_each_q_vector(vsi, q_idx) {
2987 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
2989 if (q_vector->rx.ring || q_vector->tx.ring)
2990 napi_enable(&q_vector->napi);
2995 * ice_up_complete - Finish the last steps of bringing up a connection
2996 * @vsi: The VSI being configured
2998 * Return 0 on success and negative value on error
3000 static int ice_up_complete(struct ice_vsi *vsi)
3002 struct ice_pf *pf = vsi->back;
3005 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3006 ice_vsi_cfg_msix(vsi);
3010 /* Enable only Rx rings, Tx rings were enabled by the FW when the
3011 * Tx queue group list was configured and the context bits were
3012 * programmed using ice_vsi_cfg_txqs
3014 err = ice_vsi_start_rx_rings(vsi);
3018 clear_bit(__ICE_DOWN, vsi->state);
3019 ice_napi_enable_all(vsi);
3020 ice_vsi_ena_irq(vsi);
3022 if (vsi->port_info &&
3023 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
3025 ice_print_link_msg(vsi, true);
3026 netif_tx_start_all_queues(vsi->netdev);
3027 netif_carrier_on(vsi->netdev);
3030 ice_service_task_schedule(pf);
3036 * ice_up - Bring the connection back up after being down
3037 * @vsi: VSI being configured
3039 int ice_up(struct ice_vsi *vsi)
3043 err = ice_vsi_cfg(vsi);
3045 err = ice_up_complete(vsi);
3051 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
3052 * @ring: Tx or Rx ring to read stats from
3053 * @pkts: packets stats counter
3054 * @bytes: bytes stats counter
3056 * This function fetches stats from the ring considering the atomic operations
3057 * that needs to be performed to read u64 values in 32 bit machine.
3060 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
3069 start = u64_stats_fetch_begin_irq(&ring->syncp);
3070 *pkts = ring->stats.pkts;
3071 *bytes = ring->stats.bytes;
3072 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
3076 * ice_update_vsi_ring_stats - Update VSI stats counters
3077 * @vsi: the VSI to be updated
3079 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
3081 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
3082 struct ice_ring *ring;
3086 /* reset netdev stats */
3087 vsi_stats->tx_packets = 0;
3088 vsi_stats->tx_bytes = 0;
3089 vsi_stats->rx_packets = 0;
3090 vsi_stats->rx_bytes = 0;
3092 /* reset non-netdev (extended) stats */
3093 vsi->tx_restart = 0;
3095 vsi->tx_linearize = 0;
3096 vsi->rx_buf_failed = 0;
3097 vsi->rx_page_failed = 0;
3101 /* update Tx rings counters */
3102 ice_for_each_txq(vsi, i) {
3103 ring = READ_ONCE(vsi->tx_rings[i]);
3104 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3105 vsi_stats->tx_packets += pkts;
3106 vsi_stats->tx_bytes += bytes;
3107 vsi->tx_restart += ring->tx_stats.restart_q;
3108 vsi->tx_busy += ring->tx_stats.tx_busy;
3109 vsi->tx_linearize += ring->tx_stats.tx_linearize;
3112 /* update Rx rings counters */
3113 ice_for_each_rxq(vsi, i) {
3114 ring = READ_ONCE(vsi->rx_rings[i]);
3115 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3116 vsi_stats->rx_packets += pkts;
3117 vsi_stats->rx_bytes += bytes;
3118 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
3119 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
3126 * ice_update_vsi_stats - Update VSI stats counters
3127 * @vsi: the VSI to be updated
3129 static void ice_update_vsi_stats(struct ice_vsi *vsi)
3131 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
3132 struct ice_eth_stats *cur_es = &vsi->eth_stats;
3133 struct ice_pf *pf = vsi->back;
3135 if (test_bit(__ICE_DOWN, vsi->state) ||
3136 test_bit(__ICE_CFG_BUSY, pf->state))
3139 /* get stats as recorded by Tx/Rx rings */
3140 ice_update_vsi_ring_stats(vsi);
3142 /* get VSI stats as recorded by the hardware */
3143 ice_update_eth_stats(vsi);
3145 cur_ns->tx_errors = cur_es->tx_errors;
3146 cur_ns->rx_dropped = cur_es->rx_discards;
3147 cur_ns->tx_dropped = cur_es->tx_discards;
3148 cur_ns->multicast = cur_es->rx_multicast;
3150 /* update some more netdev stats if this is main VSI */
3151 if (vsi->type == ICE_VSI_PF) {
3152 cur_ns->rx_crc_errors = pf->stats.crc_errors;
3153 cur_ns->rx_errors = pf->stats.crc_errors +
3154 pf->stats.illegal_bytes;
3155 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
3160 * ice_update_pf_stats - Update PF port stats counters
3161 * @pf: PF whose stats needs to be updated
3163 static void ice_update_pf_stats(struct ice_pf *pf)
3165 struct ice_hw_port_stats *prev_ps, *cur_ps;
3166 struct ice_hw *hw = &pf->hw;
3169 prev_ps = &pf->stats_prev;
3170 cur_ps = &pf->stats;
3173 ice_stat_update40(hw, GLPRT_GORCH(pf_id), GLPRT_GORCL(pf_id),
3174 pf->stat_prev_loaded, &prev_ps->eth.rx_bytes,
3175 &cur_ps->eth.rx_bytes);
3177 ice_stat_update40(hw, GLPRT_UPRCH(pf_id), GLPRT_UPRCL(pf_id),
3178 pf->stat_prev_loaded, &prev_ps->eth.rx_unicast,
3179 &cur_ps->eth.rx_unicast);
3181 ice_stat_update40(hw, GLPRT_MPRCH(pf_id), GLPRT_MPRCL(pf_id),
3182 pf->stat_prev_loaded, &prev_ps->eth.rx_multicast,
3183 &cur_ps->eth.rx_multicast);
3185 ice_stat_update40(hw, GLPRT_BPRCH(pf_id), GLPRT_BPRCL(pf_id),
3186 pf->stat_prev_loaded, &prev_ps->eth.rx_broadcast,
3187 &cur_ps->eth.rx_broadcast);
3189 ice_stat_update40(hw, GLPRT_GOTCH(pf_id), GLPRT_GOTCL(pf_id),
3190 pf->stat_prev_loaded, &prev_ps->eth.tx_bytes,
3191 &cur_ps->eth.tx_bytes);
3193 ice_stat_update40(hw, GLPRT_UPTCH(pf_id), GLPRT_UPTCL(pf_id),
3194 pf->stat_prev_loaded, &prev_ps->eth.tx_unicast,
3195 &cur_ps->eth.tx_unicast);
3197 ice_stat_update40(hw, GLPRT_MPTCH(pf_id), GLPRT_MPTCL(pf_id),
3198 pf->stat_prev_loaded, &prev_ps->eth.tx_multicast,
3199 &cur_ps->eth.tx_multicast);
3201 ice_stat_update40(hw, GLPRT_BPTCH(pf_id), GLPRT_BPTCL(pf_id),
3202 pf->stat_prev_loaded, &prev_ps->eth.tx_broadcast,
3203 &cur_ps->eth.tx_broadcast);
3205 ice_stat_update32(hw, GLPRT_TDOLD(pf_id), pf->stat_prev_loaded,
3206 &prev_ps->tx_dropped_link_down,
3207 &cur_ps->tx_dropped_link_down);
3209 ice_stat_update40(hw, GLPRT_PRC64H(pf_id), GLPRT_PRC64L(pf_id),
3210 pf->stat_prev_loaded, &prev_ps->rx_size_64,
3211 &cur_ps->rx_size_64);
3213 ice_stat_update40(hw, GLPRT_PRC127H(pf_id), GLPRT_PRC127L(pf_id),
3214 pf->stat_prev_loaded, &prev_ps->rx_size_127,
3215 &cur_ps->rx_size_127);
3217 ice_stat_update40(hw, GLPRT_PRC255H(pf_id), GLPRT_PRC255L(pf_id),
3218 pf->stat_prev_loaded, &prev_ps->rx_size_255,
3219 &cur_ps->rx_size_255);
3221 ice_stat_update40(hw, GLPRT_PRC511H(pf_id), GLPRT_PRC511L(pf_id),
3222 pf->stat_prev_loaded, &prev_ps->rx_size_511,
3223 &cur_ps->rx_size_511);
3225 ice_stat_update40(hw, GLPRT_PRC1023H(pf_id),
3226 GLPRT_PRC1023L(pf_id), pf->stat_prev_loaded,
3227 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
3229 ice_stat_update40(hw, GLPRT_PRC1522H(pf_id),
3230 GLPRT_PRC1522L(pf_id), pf->stat_prev_loaded,
3231 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
3233 ice_stat_update40(hw, GLPRT_PRC9522H(pf_id),
3234 GLPRT_PRC9522L(pf_id), pf->stat_prev_loaded,
3235 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
3237 ice_stat_update40(hw, GLPRT_PTC64H(pf_id), GLPRT_PTC64L(pf_id),
3238 pf->stat_prev_loaded, &prev_ps->tx_size_64,
3239 &cur_ps->tx_size_64);
3241 ice_stat_update40(hw, GLPRT_PTC127H(pf_id), GLPRT_PTC127L(pf_id),
3242 pf->stat_prev_loaded, &prev_ps->tx_size_127,
3243 &cur_ps->tx_size_127);
3245 ice_stat_update40(hw, GLPRT_PTC255H(pf_id), GLPRT_PTC255L(pf_id),
3246 pf->stat_prev_loaded, &prev_ps->tx_size_255,
3247 &cur_ps->tx_size_255);
3249 ice_stat_update40(hw, GLPRT_PTC511H(pf_id), GLPRT_PTC511L(pf_id),
3250 pf->stat_prev_loaded, &prev_ps->tx_size_511,
3251 &cur_ps->tx_size_511);
3253 ice_stat_update40(hw, GLPRT_PTC1023H(pf_id),
3254 GLPRT_PTC1023L(pf_id), pf->stat_prev_loaded,
3255 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
3257 ice_stat_update40(hw, GLPRT_PTC1522H(pf_id),
3258 GLPRT_PTC1522L(pf_id), pf->stat_prev_loaded,
3259 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
3261 ice_stat_update40(hw, GLPRT_PTC9522H(pf_id),
3262 GLPRT_PTC9522L(pf_id), pf->stat_prev_loaded,
3263 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
3265 ice_stat_update32(hw, GLPRT_LXONRXC(pf_id), pf->stat_prev_loaded,
3266 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
3268 ice_stat_update32(hw, GLPRT_LXOFFRXC(pf_id), pf->stat_prev_loaded,
3269 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
3271 ice_stat_update32(hw, GLPRT_LXONTXC(pf_id), pf->stat_prev_loaded,
3272 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
3274 ice_stat_update32(hw, GLPRT_LXOFFTXC(pf_id), pf->stat_prev_loaded,
3275 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
3277 ice_update_dcb_stats(pf);
3279 ice_stat_update32(hw, GLPRT_CRCERRS(pf_id), pf->stat_prev_loaded,
3280 &prev_ps->crc_errors, &cur_ps->crc_errors);
3282 ice_stat_update32(hw, GLPRT_ILLERRC(pf_id), pf->stat_prev_loaded,
3283 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
3285 ice_stat_update32(hw, GLPRT_MLFC(pf_id), pf->stat_prev_loaded,
3286 &prev_ps->mac_local_faults,
3287 &cur_ps->mac_local_faults);
3289 ice_stat_update32(hw, GLPRT_MRFC(pf_id), pf->stat_prev_loaded,
3290 &prev_ps->mac_remote_faults,
3291 &cur_ps->mac_remote_faults);
3293 ice_stat_update32(hw, GLPRT_RLEC(pf_id), pf->stat_prev_loaded,
3294 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
3296 ice_stat_update32(hw, GLPRT_RUC(pf_id), pf->stat_prev_loaded,
3297 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
3299 ice_stat_update32(hw, GLPRT_RFC(pf_id), pf->stat_prev_loaded,
3300 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
3302 ice_stat_update32(hw, GLPRT_ROC(pf_id), pf->stat_prev_loaded,
3303 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
3305 ice_stat_update32(hw, GLPRT_RJC(pf_id), pf->stat_prev_loaded,
3306 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
3308 pf->stat_prev_loaded = true;
3312 * ice_get_stats64 - get statistics for network device structure
3313 * @netdev: network interface device structure
3314 * @stats: main device statistics structure
3317 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
3319 struct ice_netdev_priv *np = netdev_priv(netdev);
3320 struct rtnl_link_stats64 *vsi_stats;
3321 struct ice_vsi *vsi = np->vsi;
3323 vsi_stats = &vsi->net_stats;
3325 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
3327 /* netdev packet/byte stats come from ring counter. These are obtained
3328 * by summing up ring counters (done by ice_update_vsi_ring_stats).
3330 ice_update_vsi_ring_stats(vsi);
3331 stats->tx_packets = vsi_stats->tx_packets;
3332 stats->tx_bytes = vsi_stats->tx_bytes;
3333 stats->rx_packets = vsi_stats->rx_packets;
3334 stats->rx_bytes = vsi_stats->rx_bytes;
3336 /* The rest of the stats can be read from the hardware but instead we
3337 * just return values that the watchdog task has already obtained from
3340 stats->multicast = vsi_stats->multicast;
3341 stats->tx_errors = vsi_stats->tx_errors;
3342 stats->tx_dropped = vsi_stats->tx_dropped;
3343 stats->rx_errors = vsi_stats->rx_errors;
3344 stats->rx_dropped = vsi_stats->rx_dropped;
3345 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
3346 stats->rx_length_errors = vsi_stats->rx_length_errors;
3350 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3351 * @vsi: VSI having NAPI disabled
3353 static void ice_napi_disable_all(struct ice_vsi *vsi)
3360 ice_for_each_q_vector(vsi, q_idx) {
3361 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3363 if (q_vector->rx.ring || q_vector->tx.ring)
3364 napi_disable(&q_vector->napi);
3369 * ice_force_phys_link_state - Force the physical link state
3370 * @vsi: VSI to force the physical link state to up/down
3371 * @link_up: true/false indicates to set the physical link to up/down
3373 * Force the physical link state by getting the current PHY capabilities from
3374 * hardware and setting the PHY config based on the determined capabilities. If
3375 * link changes a link event will be triggered because both the Enable Automatic
3376 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
3378 * Returns 0 on success, negative on failure
3380 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
3382 struct ice_aqc_get_phy_caps_data *pcaps;
3383 struct ice_aqc_set_phy_cfg_data *cfg;
3384 struct ice_port_info *pi;
3388 if (!vsi || !vsi->port_info || !vsi->back)
3390 if (vsi->type != ICE_VSI_PF)
3393 dev = &vsi->back->pdev->dev;
3395 pi = vsi->port_info;
3397 pcaps = devm_kzalloc(dev, sizeof(*pcaps), GFP_KERNEL);
3401 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
3405 "Failed to get phy capabilities, VSI %d error %d\n",
3406 vsi->vsi_num, retcode);
3411 /* No change in link */
3412 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
3413 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
3416 cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL);
3422 cfg->phy_type_low = pcaps->phy_type_low;
3423 cfg->phy_type_high = pcaps->phy_type_high;
3424 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
3425 cfg->low_power_ctrl = pcaps->low_power_ctrl;
3426 cfg->eee_cap = pcaps->eee_cap;
3427 cfg->eeer_value = pcaps->eeer_value;
3428 cfg->link_fec_opt = pcaps->link_fec_options;
3430 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
3432 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
3434 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
3436 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
3437 vsi->vsi_num, retcode);
3441 devm_kfree(dev, cfg);
3443 devm_kfree(dev, pcaps);
3448 * ice_down - Shutdown the connection
3449 * @vsi: The VSI being stopped
3451 int ice_down(struct ice_vsi *vsi)
3453 int i, tx_err, rx_err, link_err = 0;
3455 /* Caller of this function is expected to set the
3456 * vsi->state __ICE_DOWN bit
3459 netif_carrier_off(vsi->netdev);
3460 netif_tx_disable(vsi->netdev);
3463 ice_vsi_dis_irq(vsi);
3465 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
3467 netdev_err(vsi->netdev,
3468 "Failed stop Tx rings, VSI %d error %d\n",
3469 vsi->vsi_num, tx_err);
3471 rx_err = ice_vsi_stop_rx_rings(vsi);
3473 netdev_err(vsi->netdev,
3474 "Failed stop Rx rings, VSI %d error %d\n",
3475 vsi->vsi_num, rx_err);
3477 ice_napi_disable_all(vsi);
3479 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
3480 link_err = ice_force_phys_link_state(vsi, false);
3482 netdev_err(vsi->netdev,
3483 "Failed to set physical link down, VSI %d error %d\n",
3484 vsi->vsi_num, link_err);
3487 ice_for_each_txq(vsi, i)
3488 ice_clean_tx_ring(vsi->tx_rings[i]);
3490 ice_for_each_rxq(vsi, i)
3491 ice_clean_rx_ring(vsi->rx_rings[i]);
3493 if (tx_err || rx_err || link_err) {
3494 netdev_err(vsi->netdev,
3495 "Failed to close VSI 0x%04X on switch 0x%04X\n",
3496 vsi->vsi_num, vsi->vsw->sw_id);
3504 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
3505 * @vsi: VSI having resources allocated
3507 * Return 0 on success, negative on failure
3509 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3513 if (!vsi->num_txq) {
3514 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3519 ice_for_each_txq(vsi, i) {
3520 vsi->tx_rings[i]->netdev = vsi->netdev;
3521 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3530 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3531 * @vsi: VSI having resources allocated
3533 * Return 0 on success, negative on failure
3535 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3539 if (!vsi->num_rxq) {
3540 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3545 ice_for_each_rxq(vsi, i) {
3546 vsi->rx_rings[i]->netdev = vsi->netdev;
3547 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3556 * ice_vsi_req_irq - Request IRQ from the OS
3557 * @vsi: The VSI IRQ is being requested for
3558 * @basename: name for the vector
3560 * Return 0 on success and a negative value on error
3562 static int ice_vsi_req_irq(struct ice_vsi *vsi, char *basename)
3564 struct ice_pf *pf = vsi->back;
3567 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
3568 err = ice_vsi_req_irq_msix(vsi, basename);
3574 * ice_vsi_open - Called when a network interface is made active
3575 * @vsi: the VSI to open
3577 * Initialization of the VSI
3579 * Returns 0 on success, negative value on error
3581 static int ice_vsi_open(struct ice_vsi *vsi)
3583 char int_name[ICE_INT_NAME_STR_LEN];
3584 struct ice_pf *pf = vsi->back;
3587 /* allocate descriptors */
3588 err = ice_vsi_setup_tx_rings(vsi);
3592 err = ice_vsi_setup_rx_rings(vsi);
3596 err = ice_vsi_cfg(vsi);
3600 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3601 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3602 err = ice_vsi_req_irq(vsi, int_name);
3606 /* Notify the stack of the actual queue counts. */
3607 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3611 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3615 err = ice_up_complete(vsi);
3617 goto err_up_complete;
3624 ice_vsi_free_irq(vsi);
3626 ice_vsi_free_rx_rings(vsi);
3628 ice_vsi_free_tx_rings(vsi);
3634 * ice_vsi_release_all - Delete all VSIs
3635 * @pf: PF from which all VSIs are being removed
3637 static void ice_vsi_release_all(struct ice_pf *pf)
3644 ice_for_each_vsi(pf, i) {
3648 err = ice_vsi_release(pf->vsi[i]);
3650 dev_dbg(&pf->pdev->dev,
3651 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3652 i, err, pf->vsi[i]->vsi_num);
3657 * ice_ena_vsi - resume a VSI
3658 * @vsi: the VSI being resume
3659 * @locked: is the rtnl_lock already held
3661 static int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
3665 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
3668 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
3670 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
3671 struct net_device *netd = vsi->netdev;
3673 if (netif_running(vsi->netdev)) {
3675 err = netd->netdev_ops->ndo_open(netd);
3678 err = netd->netdev_ops->ndo_open(netd);
3682 err = ice_vsi_open(vsi);
3690 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3692 * @locked: is the rtnl_lock already held
3695 int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3697 static int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3698 #endif /* CONFIG_DCB */
3702 ice_for_each_vsi(pf, v)
3704 if (ice_ena_vsi(pf->vsi[v], locked))
3711 * ice_vsi_rebuild_all - rebuild all VSIs in pf
3714 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3718 /* loop through pf->vsi array and reinit the VSI if found */
3719 ice_for_each_vsi(pf, i) {
3725 err = ice_vsi_rebuild(pf->vsi[i]);
3727 dev_err(&pf->pdev->dev,
3728 "VSI at index %d rebuild failed\n",
3733 dev_info(&pf->pdev->dev,
3734 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3735 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3742 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3745 static int ice_vsi_replay_all(struct ice_pf *pf)
3747 struct ice_hw *hw = &pf->hw;
3748 enum ice_status ret;
3751 /* loop through pf->vsi array and replay the VSI if found */
3752 ice_for_each_vsi(pf, i) {
3756 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3758 dev_err(&pf->pdev->dev,
3759 "VSI at index %d replay failed %d\n",
3760 pf->vsi[i]->idx, ret);
3764 /* Re-map HW VSI number, using VSI handle that has been
3765 * previously validated in ice_replay_vsi() call above
3767 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3769 dev_info(&pf->pdev->dev,
3770 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3771 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3774 /* Clean up replay filter after successful re-configuration */
3775 ice_replay_post(hw);
3780 * ice_rebuild - rebuild after reset
3781 * @pf: pf to rebuild
3783 static void ice_rebuild(struct ice_pf *pf)
3785 struct device *dev = &pf->pdev->dev;
3786 struct ice_hw *hw = &pf->hw;
3787 enum ice_status ret;
3790 if (test_bit(__ICE_DOWN, pf->state))
3791 goto clear_recovery;
3793 dev_dbg(dev, "rebuilding pf\n");
3795 ret = ice_init_all_ctrlq(hw);
3797 dev_err(dev, "control queues init failed %d\n", ret);
3798 goto err_init_ctrlq;
3801 ret = ice_clear_pf_cfg(hw);
3803 dev_err(dev, "clear PF configuration failed %d\n", ret);
3804 goto err_init_ctrlq;
3807 ice_clear_pxe_mode(hw);
3809 ret = ice_get_caps(hw);
3811 dev_err(dev, "ice_get_caps failed %d\n", ret);
3812 goto err_init_ctrlq;
3815 err = ice_sched_init_port(hw->port_info);
3817 goto err_sched_init_port;
3819 ice_dcb_rebuild(pf);
3821 err = ice_vsi_rebuild_all(pf);
3823 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3824 goto err_vsi_rebuild;
3827 err = ice_update_link_info(hw->port_info);
3829 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3831 /* Replay all VSIs Configuration, including filters after reset */
3832 if (ice_vsi_replay_all(pf)) {
3833 dev_err(&pf->pdev->dev,
3834 "error replaying VSI configurations with switch filter rules\n");
3835 goto err_vsi_rebuild;
3838 /* start misc vector */
3839 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags)) {
3840 err = ice_req_irq_msix_misc(pf);
3842 dev_err(dev, "misc vector setup failed: %d\n", err);
3843 goto err_vsi_rebuild;
3847 /* restart the VSIs that were rebuilt and running before the reset */
3848 err = ice_pf_ena_all_vsi(pf, false);
3850 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3851 /* no need to disable VSIs in tear down path in ice_rebuild()
3852 * since its already taken care in ice_vsi_open()
3854 goto err_vsi_rebuild;
3857 ice_for_each_vsi(pf, i) {
3860 if (!pf->vsi[i] || pf->vsi[i]->type != ICE_VSI_PF)
3862 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
3864 netif_carrier_on(pf->vsi[i]->netdev);
3865 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
3867 netif_carrier_off(pf->vsi[i]->netdev);
3868 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
3872 /* if we get here, reset flow is successful */
3873 clear_bit(__ICE_RESET_FAILED, pf->state);
3877 ice_vsi_release_all(pf);
3878 err_sched_init_port:
3879 ice_sched_cleanup_all(hw);
3881 ice_shutdown_all_ctrlq(hw);
3882 set_bit(__ICE_RESET_FAILED, pf->state);
3884 /* set this bit in PF state to control service task scheduling */
3885 set_bit(__ICE_NEEDS_RESTART, pf->state);
3886 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3890 * ice_change_mtu - NDO callback to change the MTU
3891 * @netdev: network interface device structure
3892 * @new_mtu: new value for maximum frame size
3894 * Returns 0 on success, negative on failure
3896 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3898 struct ice_netdev_priv *np = netdev_priv(netdev);
3899 struct ice_vsi *vsi = np->vsi;
3900 struct ice_pf *pf = vsi->back;
3903 if (new_mtu == netdev->mtu) {
3904 netdev_warn(netdev, "mtu is already %u\n", netdev->mtu);
3908 if (new_mtu < netdev->min_mtu) {
3909 netdev_err(netdev, "new mtu invalid. min_mtu is %d\n",
3912 } else if (new_mtu > netdev->max_mtu) {
3913 netdev_err(netdev, "new mtu invalid. max_mtu is %d\n",
3917 /* if a reset is in progress, wait for some time for it to complete */
3919 if (ice_is_reset_in_progress(pf->state)) {
3921 usleep_range(1000, 2000);
3926 } while (count < 100);
3929 netdev_err(netdev, "can't change mtu. Device is busy\n");
3933 netdev->mtu = new_mtu;
3935 /* if VSI is up, bring it down and then back up */
3936 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3939 err = ice_down(vsi);
3941 netdev_err(netdev, "change mtu if_up err %d\n", err);
3947 netdev_err(netdev, "change mtu if_up err %d\n", err);
3952 netdev_info(netdev, "changed MTU to %d\n", new_mtu);
3957 * ice_set_rss - Set RSS keys and lut
3958 * @vsi: Pointer to VSI structure
3959 * @seed: RSS hash seed
3960 * @lut: Lookup table
3961 * @lut_size: Lookup table size
3963 * Returns 0 on success, negative on failure
3965 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3967 struct ice_pf *pf = vsi->back;
3968 struct ice_hw *hw = &pf->hw;
3969 enum ice_status status;
3972 struct ice_aqc_get_set_rss_keys *buf =
3973 (struct ice_aqc_get_set_rss_keys *)seed;
3975 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3978 dev_err(&pf->pdev->dev,
3979 "Cannot set RSS key, err %d aq_err %d\n",
3980 status, hw->adminq.rq_last_status);
3986 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3989 dev_err(&pf->pdev->dev,
3990 "Cannot set RSS lut, err %d aq_err %d\n",
3991 status, hw->adminq.rq_last_status);
4000 * ice_get_rss - Get RSS keys and lut
4001 * @vsi: Pointer to VSI structure
4002 * @seed: Buffer to store the keys
4003 * @lut: Buffer to store the lookup table entries
4004 * @lut_size: Size of buffer to store the lookup table entries
4006 * Returns 0 on success, negative on failure
4008 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4010 struct ice_pf *pf = vsi->back;
4011 struct ice_hw *hw = &pf->hw;
4012 enum ice_status status;
4015 struct ice_aqc_get_set_rss_keys *buf =
4016 (struct ice_aqc_get_set_rss_keys *)seed;
4018 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4020 dev_err(&pf->pdev->dev,
4021 "Cannot get RSS key, err %d aq_err %d\n",
4022 status, hw->adminq.rq_last_status);
4028 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4031 dev_err(&pf->pdev->dev,
4032 "Cannot get RSS lut, err %d aq_err %d\n",
4033 status, hw->adminq.rq_last_status);
4042 * ice_bridge_getlink - Get the hardware bridge mode
4045 * @seq: RTNL message seq
4046 * @dev: the netdev being configured
4047 * @filter_mask: filter mask passed in
4048 * @nlflags: netlink flags passed in
4050 * Return the bridge mode (VEB/VEPA)
4053 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4054 struct net_device *dev, u32 filter_mask, int nlflags)
4056 struct ice_netdev_priv *np = netdev_priv(dev);
4057 struct ice_vsi *vsi = np->vsi;
4058 struct ice_pf *pf = vsi->back;
4061 bmode = pf->first_sw->bridge_mode;
4063 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4068 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4069 * @vsi: Pointer to VSI structure
4070 * @bmode: Hardware bridge mode (VEB/VEPA)
4072 * Returns 0 on success, negative on failure
4074 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4076 struct device *dev = &vsi->back->pdev->dev;
4077 struct ice_aqc_vsi_props *vsi_props;
4078 struct ice_hw *hw = &vsi->back->hw;
4079 struct ice_vsi_ctx *ctxt;
4080 enum ice_status status;
4083 vsi_props = &vsi->info;
4085 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
4089 ctxt->info = vsi->info;
4091 if (bmode == BRIDGE_MODE_VEB)
4092 /* change from VEPA to VEB mode */
4093 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4095 /* change from VEB to VEPA mode */
4096 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4097 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4099 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4101 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4102 bmode, status, hw->adminq.sq_last_status);
4106 /* Update sw flags for book keeping */
4107 vsi_props->sw_flags = ctxt->info.sw_flags;
4110 devm_kfree(dev, ctxt);
4115 * ice_bridge_setlink - Set the hardware bridge mode
4116 * @dev: the netdev being configured
4117 * @nlh: RTNL message
4118 * @flags: bridge setlink flags
4119 * @extack: netlink extended ack
4121 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4122 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4123 * not already set for all VSIs connected to this switch. And also update the
4124 * unicast switch filter rules for the corresponding switch of the netdev.
4127 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4128 u16 __always_unused flags,
4129 struct netlink_ext_ack __always_unused *extack)
4131 struct ice_netdev_priv *np = netdev_priv(dev);
4132 struct ice_pf *pf = np->vsi->back;
4133 struct nlattr *attr, *br_spec;
4134 struct ice_hw *hw = &pf->hw;
4135 enum ice_status status;
4136 struct ice_sw *pf_sw;
4137 int rem, v, err = 0;
4139 pf_sw = pf->first_sw;
4140 /* find the attribute in the netlink message */
4141 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4143 nla_for_each_nested(attr, br_spec, rem) {
4146 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4148 mode = nla_get_u16(attr);
4149 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4151 /* Continue if bridge mode is not being flipped */
4152 if (mode == pf_sw->bridge_mode)
4154 /* Iterates through the PF VSI list and update the loopback
4157 ice_for_each_vsi(pf, v) {
4160 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
4165 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
4166 /* Update the unicast switch filter rules for the corresponding
4167 * switch of the netdev
4169 status = ice_update_sw_rule_bridge_mode(hw);
4171 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
4172 mode, status, hw->adminq.sq_last_status);
4173 /* revert hw->evb_veb */
4174 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
4178 pf_sw->bridge_mode = mode;
4185 * ice_tx_timeout - Respond to a Tx Hang
4186 * @netdev: network interface device structure
4188 static void ice_tx_timeout(struct net_device *netdev)
4190 struct ice_netdev_priv *np = netdev_priv(netdev);
4191 struct ice_ring *tx_ring = NULL;
4192 struct ice_vsi *vsi = np->vsi;
4193 struct ice_pf *pf = vsi->back;
4194 int hung_queue = -1;
4197 pf->tx_timeout_count++;
4199 /* find the stopped queue the same way dev_watchdog() does */
4200 for (i = 0; i < netdev->num_tx_queues; i++) {
4201 unsigned long trans_start;
4202 struct netdev_queue *q;
4204 q = netdev_get_tx_queue(netdev, i);
4205 trans_start = q->trans_start;
4206 if (netif_xmit_stopped(q) &&
4208 trans_start + netdev->watchdog_timeo)) {
4214 if (i == netdev->num_tx_queues)
4215 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
4217 /* now that we have an index, find the tx_ring struct */
4218 for (i = 0; i < vsi->num_txq; i++)
4219 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
4220 if (hung_queue == vsi->tx_rings[i]->q_index) {
4221 tx_ring = vsi->tx_rings[i];
4225 /* Reset recovery level if enough time has elapsed after last timeout.
4226 * Also ensure no new reset action happens before next timeout period.
4228 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
4229 pf->tx_timeout_recovery_level = 1;
4230 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
4231 netdev->watchdog_timeo)))
4235 struct ice_hw *hw = &pf->hw;
4238 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
4239 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
4240 /* Read interrupt register */
4241 if (test_bit(ICE_FLAG_MSIX_ENA, pf->flags))
4243 GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
4245 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
4246 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
4247 head, tx_ring->next_to_use, val);
4250 pf->tx_timeout_last_recovery = jiffies;
4251 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
4252 pf->tx_timeout_recovery_level, hung_queue);
4254 switch (pf->tx_timeout_recovery_level) {
4256 set_bit(__ICE_PFR_REQ, pf->state);
4259 set_bit(__ICE_CORER_REQ, pf->state);
4262 set_bit(__ICE_GLOBR_REQ, pf->state);
4265 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
4266 set_bit(__ICE_DOWN, pf->state);
4267 set_bit(__ICE_NEEDS_RESTART, vsi->state);
4268 set_bit(__ICE_SERVICE_DIS, pf->state);
4272 ice_service_task_schedule(pf);
4273 pf->tx_timeout_recovery_level++;
4277 * ice_open - Called when a network interface becomes active
4278 * @netdev: network interface device structure
4280 * The open entry point is called when a network interface is made
4281 * active by the system (IFF_UP). At this point all resources needed
4282 * for transmit and receive operations are allocated, the interrupt
4283 * handler is registered with the OS, the netdev watchdog is enabled,
4284 * and the stack is notified that the interface is ready.
4286 * Returns 0 on success, negative value on failure
4288 int ice_open(struct net_device *netdev)
4290 struct ice_netdev_priv *np = netdev_priv(netdev);
4291 struct ice_vsi *vsi = np->vsi;
4294 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
4295 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
4299 netif_carrier_off(netdev);
4301 err = ice_force_phys_link_state(vsi, true);
4304 "Failed to set physical link up, error %d\n", err);
4308 err = ice_vsi_open(vsi);
4310 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
4311 vsi->vsi_num, vsi->vsw->sw_id);
4316 * ice_stop - Disables a network interface
4317 * @netdev: network interface device structure
4319 * The stop entry point is called when an interface is de-activated by the OS,
4320 * and the netdevice enters the DOWN state. The hardware is still under the
4321 * driver's control, but the netdev interface is disabled.
4323 * Returns success only - not allowed to fail
4325 int ice_stop(struct net_device *netdev)
4327 struct ice_netdev_priv *np = netdev_priv(netdev);
4328 struct ice_vsi *vsi = np->vsi;
4336 * ice_features_check - Validate encapsulated packet conforms to limits
4338 * @netdev: This port's netdev
4339 * @features: Offload features that the stack believes apply
4341 static netdev_features_t
4342 ice_features_check(struct sk_buff *skb,
4343 struct net_device __always_unused *netdev,
4344 netdev_features_t features)
4348 /* No point in doing any of this if neither checksum nor GSO are
4349 * being requested for this frame. We can rule out both by just
4350 * checking for CHECKSUM_PARTIAL
4352 if (skb->ip_summed != CHECKSUM_PARTIAL)
4355 /* We cannot support GSO if the MSS is going to be less than
4356 * 64 bytes. If it is then we need to drop support for GSO.
4358 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
4359 features &= ~NETIF_F_GSO_MASK;
4361 len = skb_network_header(skb) - skb->data;
4362 if (len & ~(ICE_TXD_MACLEN_MAX))
4363 goto out_rm_features;
4365 len = skb_transport_header(skb) - skb_network_header(skb);
4366 if (len & ~(ICE_TXD_IPLEN_MAX))
4367 goto out_rm_features;
4369 if (skb->encapsulation) {
4370 len = skb_inner_network_header(skb) - skb_transport_header(skb);
4371 if (len & ~(ICE_TXD_L4LEN_MAX))
4372 goto out_rm_features;
4374 len = skb_inner_transport_header(skb) -
4375 skb_inner_network_header(skb);
4376 if (len & ~(ICE_TXD_IPLEN_MAX))
4377 goto out_rm_features;
4382 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
4385 static const struct net_device_ops ice_netdev_ops = {
4386 .ndo_open = ice_open,
4387 .ndo_stop = ice_stop,
4388 .ndo_start_xmit = ice_start_xmit,
4389 .ndo_features_check = ice_features_check,
4390 .ndo_set_rx_mode = ice_set_rx_mode,
4391 .ndo_set_mac_address = ice_set_mac_address,
4392 .ndo_validate_addr = eth_validate_addr,
4393 .ndo_change_mtu = ice_change_mtu,
4394 .ndo_get_stats64 = ice_get_stats64,
4395 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
4396 .ndo_set_vf_mac = ice_set_vf_mac,
4397 .ndo_get_vf_config = ice_get_vf_cfg,
4398 .ndo_set_vf_trust = ice_set_vf_trust,
4399 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
4400 .ndo_set_vf_link_state = ice_set_vf_link_state,
4401 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
4402 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
4403 .ndo_set_features = ice_set_features,
4404 .ndo_bridge_getlink = ice_bridge_getlink,
4405 .ndo_bridge_setlink = ice_bridge_setlink,
4406 .ndo_fdb_add = ice_fdb_add,
4407 .ndo_fdb_del = ice_fdb_del,
4408 .ndo_tx_timeout = ice_tx_timeout,