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.5-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);
39 * ice_get_tx_pending - returns number of Tx descriptors not processed
40 * @ring: the ring of descriptors
42 static u16 ice_get_tx_pending(struct ice_ring *ring)
46 head = ring->next_to_clean;
47 tail = ring->next_to_use;
50 return (head < tail) ?
51 tail - head : (tail + ring->count - head);
56 * ice_check_for_hang_subtask - check for and recover hung queues
57 * @pf: pointer to PF struct
59 static void ice_check_for_hang_subtask(struct ice_pf *pf)
61 struct ice_vsi *vsi = NULL;
67 ice_for_each_vsi(pf, v)
68 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
73 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
76 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
81 for (i = 0; i < vsi->num_txq; i++) {
82 struct ice_ring *tx_ring = vsi->tx_rings[i];
84 if (tx_ring && tx_ring->desc) {
85 /* If packet counter has not changed the queue is
86 * likely stalled, so force an interrupt for this
89 * prev_pkt would be negative if there was no
92 packets = tx_ring->stats.pkts & INT_MAX;
93 if (tx_ring->tx_stats.prev_pkt == packets) {
94 /* Trigger sw interrupt to revive the queue */
95 ice_trigger_sw_intr(hw, tx_ring->q_vector);
99 /* Memory barrier between read of packet count and call
100 * to ice_get_tx_pending()
103 tx_ring->tx_stats.prev_pkt =
104 ice_get_tx_pending(tx_ring) ? packets : -1;
110 * ice_init_mac_fltr - Set initial MAC filters
111 * @pf: board private structure
113 * Set initial set of MAC filters for PF VSI; configure filters for permanent
114 * address and broadcast address. If an error is encountered, netdevice will be
117 static int ice_init_mac_fltr(struct ice_pf *pf)
119 enum ice_status status;
120 u8 broadcast[ETH_ALEN];
123 vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF);
127 /* To add a MAC filter, first add the MAC to a list and then
128 * pass the list to ice_add_mac.
131 /* Add a unicast MAC filter so the VSI can get its packets */
132 status = ice_vsi_cfg_mac_fltr(vsi, vsi->port_info->mac.perm_addr, true);
136 /* VSI needs to receive broadcast traffic, so add the broadcast
137 * MAC address to the list as well.
139 eth_broadcast_addr(broadcast);
140 status = ice_vsi_cfg_mac_fltr(vsi, broadcast, true);
146 /* We aren't useful with no MAC filters, so unregister if we
149 if (status && vsi->netdev->reg_state == NETREG_REGISTERED) {
150 dev_err(&pf->pdev->dev,
151 "Could not add MAC filters error %d. Unregistering device\n",
153 unregister_netdev(vsi->netdev);
154 free_netdev(vsi->netdev);
162 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
163 * @netdev: the net device on which the sync is happening
164 * @addr: MAC address to sync
166 * This is a callback function which is called by the in kernel device sync
167 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
168 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
169 * MAC filters from the hardware.
171 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
173 struct ice_netdev_priv *np = netdev_priv(netdev);
174 struct ice_vsi *vsi = np->vsi;
176 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
183 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
184 * @netdev: the net device on which the unsync is happening
185 * @addr: MAC address to unsync
187 * This is a callback function which is called by the in kernel device unsync
188 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
189 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
190 * delete the MAC filters from the hardware.
192 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
194 struct ice_netdev_priv *np = netdev_priv(netdev);
195 struct ice_vsi *vsi = np->vsi;
197 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
204 * ice_vsi_fltr_changed - check if filter state changed
205 * @vsi: VSI to be checked
207 * returns true if filter state has changed, false otherwise.
209 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
211 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
212 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
213 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
217 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
218 * @vsi: the VSI being configured
219 * @promisc_m: mask of promiscuous config bits
220 * @set_promisc: enable or disable promisc flag request
223 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
225 struct ice_hw *hw = &vsi->back->hw;
226 enum ice_status status = 0;
228 if (vsi->type != ICE_VSI_PF)
232 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
236 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
239 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
250 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
251 * @vsi: ptr to the VSI
253 * Push any outstanding VSI filter changes through the AdminQ.
255 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
257 struct device *dev = &vsi->back->pdev->dev;
258 struct net_device *netdev = vsi->netdev;
259 bool promisc_forced_on = false;
260 struct ice_pf *pf = vsi->back;
261 struct ice_hw *hw = &pf->hw;
262 enum ice_status status = 0;
263 u32 changed_flags = 0;
270 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
271 usleep_range(1000, 2000);
273 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
274 vsi->current_netdev_flags = vsi->netdev->flags;
276 INIT_LIST_HEAD(&vsi->tmp_sync_list);
277 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
279 if (ice_vsi_fltr_changed(vsi)) {
280 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
281 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
282 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
284 /* grab the netdev's addr_list_lock */
285 netif_addr_lock_bh(netdev);
286 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
287 ice_add_mac_to_unsync_list);
288 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
289 ice_add_mac_to_unsync_list);
290 /* our temp lists are populated. release lock */
291 netif_addr_unlock_bh(netdev);
294 /* Remove MAC addresses in the unsync list */
295 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
296 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
298 netdev_err(netdev, "Failed to delete MAC filters\n");
299 /* if we failed because of alloc failures, just bail */
300 if (status == ICE_ERR_NO_MEMORY) {
306 /* Add MAC addresses in the sync list */
307 status = ice_add_mac(hw, &vsi->tmp_sync_list);
308 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
309 /* If filter is added successfully or already exists, do not go into
310 * 'if' condition and report it as error. Instead continue processing
311 * rest of the function.
313 if (status && status != ICE_ERR_ALREADY_EXISTS) {
314 netdev_err(netdev, "Failed to add MAC filters\n");
315 /* If there is no more space for new umac filters, VSI
316 * should go into promiscuous mode. There should be some
317 * space reserved for promiscuous filters.
319 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
320 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
322 promisc_forced_on = true;
324 "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
331 /* check for changes in promiscuous modes */
332 if (changed_flags & IFF_ALLMULTI) {
333 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
335 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
337 promisc_m = ICE_MCAST_PROMISC_BITS;
339 err = ice_cfg_promisc(vsi, promisc_m, true);
341 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
343 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
346 } else if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
348 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
350 promisc_m = ICE_MCAST_PROMISC_BITS;
352 err = ice_cfg_promisc(vsi, promisc_m, false);
354 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
356 vsi->current_netdev_flags |= IFF_ALLMULTI;
362 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
363 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
364 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
365 if (vsi->current_netdev_flags & IFF_PROMISC) {
366 /* Apply Rx filter rule to get traffic from wire */
367 status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
370 netdev_err(netdev, "Error setting default VSI %i Rx rule\n",
372 vsi->current_netdev_flags &= ~IFF_PROMISC;
377 /* Clear Rx filter to remove traffic from wire */
378 status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
381 netdev_err(netdev, "Error clearing default VSI %i Rx rule\n",
383 vsi->current_netdev_flags |= IFF_PROMISC;
392 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
395 /* if something went wrong then set the changed flag so we try again */
396 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
397 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
399 clear_bit(__ICE_CFG_BUSY, vsi->state);
404 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
405 * @pf: board private structure
407 static void ice_sync_fltr_subtask(struct ice_pf *pf)
411 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
414 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
416 ice_for_each_vsi(pf, v)
417 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
418 ice_vsi_sync_fltr(pf->vsi[v])) {
419 /* come back and try again later */
420 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
426 * ice_dis_vsi - pause a VSI
427 * @vsi: the VSI being paused
428 * @locked: is the rtnl_lock already held
430 static void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
432 if (test_bit(__ICE_DOWN, vsi->state))
435 set_bit(__ICE_NEEDS_RESTART, vsi->state);
437 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
438 if (netif_running(vsi->netdev)) {
442 ice_stop(vsi->netdev);
453 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
455 * @locked: is the rtnl_lock already held
458 void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
460 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
461 #endif /* CONFIG_DCB */
465 ice_for_each_vsi(pf, v)
467 ice_dis_vsi(pf->vsi[v], locked);
471 * ice_prepare_for_reset - prep for the core to reset
472 * @pf: board private structure
474 * Inform or close all dependent features in prep for reset.
477 ice_prepare_for_reset(struct ice_pf *pf)
479 struct ice_hw *hw = &pf->hw;
482 /* already prepared for reset */
483 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
486 /* Notify VFs of impending reset */
487 if (ice_check_sq_alive(hw, &hw->mailboxq))
488 ice_vc_notify_reset(pf);
490 /* Disable VFs until reset is completed */
491 for (i = 0; i < pf->num_alloc_vfs; i++)
492 clear_bit(ICE_VF_STATE_ENA, pf->vf[i].vf_states);
494 /* disable the VSIs and their queues that are not already DOWN */
495 ice_pf_dis_all_vsi(pf, false);
498 ice_sched_clear_port(hw->port_info);
500 ice_shutdown_all_ctrlq(hw);
502 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
506 * ice_do_reset - Initiate one of many types of resets
507 * @pf: board private structure
508 * @reset_type: reset type requested
509 * before this function was called.
511 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
513 struct device *dev = &pf->pdev->dev;
514 struct ice_hw *hw = &pf->hw;
516 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
517 WARN_ON(in_interrupt());
519 ice_prepare_for_reset(pf);
521 /* trigger the reset */
522 if (ice_reset(hw, reset_type)) {
523 dev_err(dev, "reset %d failed\n", reset_type);
524 set_bit(__ICE_RESET_FAILED, pf->state);
525 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
526 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
527 clear_bit(__ICE_PFR_REQ, pf->state);
528 clear_bit(__ICE_CORER_REQ, pf->state);
529 clear_bit(__ICE_GLOBR_REQ, pf->state);
533 /* PFR is a bit of a special case because it doesn't result in an OICR
534 * interrupt. So for PFR, rebuild after the reset and clear the reset-
535 * associated state bits.
537 if (reset_type == ICE_RESET_PFR) {
540 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
541 clear_bit(__ICE_PFR_REQ, pf->state);
542 ice_reset_all_vfs(pf, true);
547 * ice_reset_subtask - Set up for resetting the device and driver
548 * @pf: board private structure
550 static void ice_reset_subtask(struct ice_pf *pf)
552 enum ice_reset_req reset_type = ICE_RESET_INVAL;
554 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
555 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
556 * of reset is pending and sets bits in pf->state indicating the reset
557 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
558 * prepare for pending reset if not already (for PF software-initiated
559 * global resets the software should already be prepared for it as
560 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
561 * by firmware or software on other PFs, that bit is not set so prepare
562 * for the reset now), poll for reset done, rebuild and return.
564 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
565 /* Perform the largest reset requested */
566 if (test_and_clear_bit(__ICE_CORER_RECV, pf->state))
567 reset_type = ICE_RESET_CORER;
568 if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state))
569 reset_type = ICE_RESET_GLOBR;
570 /* return if no valid reset type requested */
571 if (reset_type == ICE_RESET_INVAL)
573 ice_prepare_for_reset(pf);
575 /* make sure we are ready to rebuild */
576 if (ice_check_reset(&pf->hw)) {
577 set_bit(__ICE_RESET_FAILED, pf->state);
579 /* done with reset. start rebuild */
580 pf->hw.reset_ongoing = false;
582 /* clear bit to resume normal operations, but
583 * ICE_NEEDS_RESTART bit is set in case rebuild failed
585 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
586 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
587 clear_bit(__ICE_PFR_REQ, pf->state);
588 clear_bit(__ICE_CORER_REQ, pf->state);
589 clear_bit(__ICE_GLOBR_REQ, pf->state);
590 ice_reset_all_vfs(pf, true);
596 /* No pending resets to finish processing. Check for new resets */
597 if (test_bit(__ICE_PFR_REQ, pf->state))
598 reset_type = ICE_RESET_PFR;
599 if (test_bit(__ICE_CORER_REQ, pf->state))
600 reset_type = ICE_RESET_CORER;
601 if (test_bit(__ICE_GLOBR_REQ, pf->state))
602 reset_type = ICE_RESET_GLOBR;
603 /* If no valid reset type requested just return */
604 if (reset_type == ICE_RESET_INVAL)
607 /* reset if not already down or busy */
608 if (!test_bit(__ICE_DOWN, pf->state) &&
609 !test_bit(__ICE_CFG_BUSY, pf->state)) {
610 ice_do_reset(pf, reset_type);
615 * ice_print_link_msg - print link up or down message
616 * @vsi: the VSI whose link status is being queried
617 * @isup: boolean for if the link is now up or down
619 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
621 struct ice_aqc_get_phy_caps_data *caps;
622 enum ice_status status;
631 if (vsi->current_isup == isup)
634 vsi->current_isup = isup;
637 netdev_info(vsi->netdev, "NIC Link is Down\n");
641 switch (vsi->port_info->phy.link_info.link_speed) {
642 case ICE_AQ_LINK_SPEED_100GB:
645 case ICE_AQ_LINK_SPEED_50GB:
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 /* turn off PHY if media was removed */
808 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
809 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
810 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
812 result = ice_aq_set_link_restart_an(pi, false, NULL);
814 dev_dbg(&pf->pdev->dev,
815 "Failed to set link down, VSI %d error %d\n",
816 vsi->vsi_num, result);
821 ice_vsi_link_event(vsi, link_up);
822 ice_print_link_msg(vsi, link_up);
824 if (pf->num_alloc_vfs)
825 ice_vc_notify_link_state(pf);
831 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
832 * @pf: board private structure
834 static void ice_watchdog_subtask(struct ice_pf *pf)
838 /* if interface is down do nothing */
839 if (test_bit(__ICE_DOWN, pf->state) ||
840 test_bit(__ICE_CFG_BUSY, pf->state))
843 /* make sure we don't do these things too often */
844 if (time_before(jiffies,
845 pf->serv_tmr_prev + pf->serv_tmr_period))
848 pf->serv_tmr_prev = jiffies;
850 /* Update the stats for active netdevs so the network stack
851 * can look at updated numbers whenever it cares to
853 ice_update_pf_stats(pf);
854 ice_for_each_vsi(pf, i)
855 if (pf->vsi[i] && pf->vsi[i]->netdev)
856 ice_update_vsi_stats(pf->vsi[i]);
860 * ice_init_link_events - enable/initialize link events
861 * @pi: pointer to the port_info instance
863 * Returns -EIO on failure, 0 on success
865 static int ice_init_link_events(struct ice_port_info *pi)
869 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
870 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
872 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
873 dev_dbg(ice_hw_to_dev(pi->hw),
874 "Failed to set link event mask for port %d\n",
879 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
880 dev_dbg(ice_hw_to_dev(pi->hw),
881 "Failed to enable link events for port %d\n",
890 * ice_handle_link_event - handle link event via ARQ
891 * @pf: PF that the link event is associated with
892 * @event: event structure containing link status info
895 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
897 struct ice_aqc_get_link_status_data *link_data;
898 struct ice_port_info *port_info;
901 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
902 port_info = pf->hw.port_info;
906 status = ice_link_event(pf, port_info,
907 !!(link_data->link_info & ICE_AQ_LINK_UP),
908 le16_to_cpu(link_data->link_speed));
910 dev_dbg(&pf->pdev->dev,
911 "Could not process link event, error %d\n", status);
917 * __ice_clean_ctrlq - helper function to clean controlq rings
918 * @pf: ptr to struct ice_pf
919 * @q_type: specific Control queue type
921 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
923 struct ice_rq_event_info event;
924 struct ice_hw *hw = &pf->hw;
925 struct ice_ctl_q_info *cq;
930 /* Do not clean control queue if/when PF reset fails */
931 if (test_bit(__ICE_RESET_FAILED, pf->state))
935 case ICE_CTL_Q_ADMIN:
939 case ICE_CTL_Q_MAILBOX:
944 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
949 /* check for error indications - PF_xx_AxQLEN register layout for
950 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
952 val = rd32(hw, cq->rq.len);
953 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
954 PF_FW_ARQLEN_ARQCRIT_M)) {
956 if (val & PF_FW_ARQLEN_ARQVFE_M)
957 dev_dbg(&pf->pdev->dev,
958 "%s Receive Queue VF Error detected\n", qtype);
959 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
960 dev_dbg(&pf->pdev->dev,
961 "%s Receive Queue Overflow Error detected\n",
964 if (val & PF_FW_ARQLEN_ARQCRIT_M)
965 dev_dbg(&pf->pdev->dev,
966 "%s Receive Queue Critical Error detected\n",
968 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
969 PF_FW_ARQLEN_ARQCRIT_M);
971 wr32(hw, cq->rq.len, val);
974 val = rd32(hw, cq->sq.len);
975 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
976 PF_FW_ATQLEN_ATQCRIT_M)) {
978 if (val & PF_FW_ATQLEN_ATQVFE_M)
979 dev_dbg(&pf->pdev->dev,
980 "%s Send Queue VF Error detected\n", qtype);
981 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
982 dev_dbg(&pf->pdev->dev,
983 "%s Send Queue Overflow Error detected\n",
986 if (val & PF_FW_ATQLEN_ATQCRIT_M)
987 dev_dbg(&pf->pdev->dev,
988 "%s Send Queue Critical Error detected\n",
990 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
991 PF_FW_ATQLEN_ATQCRIT_M);
993 wr32(hw, cq->sq.len, val);
996 event.buf_len = cq->rq_buf_size;
997 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
1003 enum ice_status ret;
1006 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1007 if (ret == ICE_ERR_AQ_NO_WORK)
1010 dev_err(&pf->pdev->dev,
1011 "%s Receive Queue event error %d\n", qtype,
1016 opcode = le16_to_cpu(event.desc.opcode);
1019 case ice_aqc_opc_get_link_status:
1020 if (ice_handle_link_event(pf, &event))
1021 dev_err(&pf->pdev->dev,
1022 "Could not handle link event\n");
1024 case ice_mbx_opc_send_msg_to_pf:
1025 ice_vc_process_vf_msg(pf, &event);
1027 case ice_aqc_opc_fw_logging:
1028 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1030 case ice_aqc_opc_lldp_set_mib_change:
1031 ice_dcb_process_lldp_set_mib_change(pf, &event);
1034 dev_dbg(&pf->pdev->dev,
1035 "%s Receive Queue unknown event 0x%04x ignored\n",
1039 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1041 devm_kfree(&pf->pdev->dev, event.msg_buf);
1043 return pending && (i == ICE_DFLT_IRQ_WORK);
1047 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1048 * @hw: pointer to hardware info
1049 * @cq: control queue information
1051 * returns true if there are pending messages in a queue, false if there aren't
1053 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1057 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1058 return cq->rq.next_to_clean != ntu;
1062 * ice_clean_adminq_subtask - clean the AdminQ rings
1063 * @pf: board private structure
1065 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1067 struct ice_hw *hw = &pf->hw;
1069 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1072 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1075 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1077 /* There might be a situation where new messages arrive to a control
1078 * queue between processing the last message and clearing the
1079 * EVENT_PENDING bit. So before exiting, check queue head again (using
1080 * ice_ctrlq_pending) and process new messages if any.
1082 if (ice_ctrlq_pending(hw, &hw->adminq))
1083 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1089 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1090 * @pf: board private structure
1092 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1094 struct ice_hw *hw = &pf->hw;
1096 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1099 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1102 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1104 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1105 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1111 * ice_service_task_schedule - schedule the service task to wake up
1112 * @pf: board private structure
1114 * If not already scheduled, this puts the task into the work queue.
1116 static void ice_service_task_schedule(struct ice_pf *pf)
1118 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1119 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1120 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1121 queue_work(ice_wq, &pf->serv_task);
1125 * ice_service_task_complete - finish up the service task
1126 * @pf: board private structure
1128 static void ice_service_task_complete(struct ice_pf *pf)
1130 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1132 /* force memory (pf->state) to sync before next service task */
1133 smp_mb__before_atomic();
1134 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1138 * ice_service_task_stop - stop service task and cancel works
1139 * @pf: board private structure
1141 static void ice_service_task_stop(struct ice_pf *pf)
1143 set_bit(__ICE_SERVICE_DIS, pf->state);
1145 if (pf->serv_tmr.function)
1146 del_timer_sync(&pf->serv_tmr);
1147 if (pf->serv_task.func)
1148 cancel_work_sync(&pf->serv_task);
1150 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1154 * ice_service_task_restart - restart service task and schedule works
1155 * @pf: board private structure
1157 * This function is needed for suspend and resume works (e.g WoL scenario)
1159 static void ice_service_task_restart(struct ice_pf *pf)
1161 clear_bit(__ICE_SERVICE_DIS, pf->state);
1162 ice_service_task_schedule(pf);
1166 * ice_service_timer - timer callback to schedule service task
1167 * @t: pointer to timer_list
1169 static void ice_service_timer(struct timer_list *t)
1171 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1173 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1174 ice_service_task_schedule(pf);
1178 * ice_handle_mdd_event - handle malicious driver detect event
1179 * @pf: pointer to the PF structure
1181 * Called from service task. OICR interrupt handler indicates MDD event
1183 static void ice_handle_mdd_event(struct ice_pf *pf)
1185 struct ice_hw *hw = &pf->hw;
1186 bool mdd_detected = false;
1190 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1193 /* find what triggered the MDD event */
1194 reg = rd32(hw, GL_MDET_TX_PQM);
1195 if (reg & GL_MDET_TX_PQM_VALID_M) {
1196 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1197 GL_MDET_TX_PQM_PF_NUM_S;
1198 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1199 GL_MDET_TX_PQM_VF_NUM_S;
1200 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1201 GL_MDET_TX_PQM_MAL_TYPE_S;
1202 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1203 GL_MDET_TX_PQM_QNUM_S);
1205 if (netif_msg_tx_err(pf))
1206 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1207 event, queue, pf_num, vf_num);
1208 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1209 mdd_detected = true;
1212 reg = rd32(hw, GL_MDET_TX_TCLAN);
1213 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1214 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1215 GL_MDET_TX_TCLAN_PF_NUM_S;
1216 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1217 GL_MDET_TX_TCLAN_VF_NUM_S;
1218 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1219 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1220 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1221 GL_MDET_TX_TCLAN_QNUM_S);
1223 if (netif_msg_rx_err(pf))
1224 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1225 event, queue, pf_num, vf_num);
1226 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1227 mdd_detected = true;
1230 reg = rd32(hw, GL_MDET_RX);
1231 if (reg & GL_MDET_RX_VALID_M) {
1232 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1233 GL_MDET_RX_PF_NUM_S;
1234 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1235 GL_MDET_RX_VF_NUM_S;
1236 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1237 GL_MDET_RX_MAL_TYPE_S;
1238 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1241 if (netif_msg_rx_err(pf))
1242 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1243 event, queue, pf_num, vf_num);
1244 wr32(hw, GL_MDET_RX, 0xffffffff);
1245 mdd_detected = true;
1249 bool pf_mdd_detected = false;
1251 reg = rd32(hw, PF_MDET_TX_PQM);
1252 if (reg & PF_MDET_TX_PQM_VALID_M) {
1253 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1254 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1255 pf_mdd_detected = true;
1258 reg = rd32(hw, PF_MDET_TX_TCLAN);
1259 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1260 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1261 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1262 pf_mdd_detected = true;
1265 reg = rd32(hw, PF_MDET_RX);
1266 if (reg & PF_MDET_RX_VALID_M) {
1267 wr32(hw, PF_MDET_RX, 0xFFFF);
1268 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
1269 pf_mdd_detected = true;
1271 /* Queue belongs to the PF initiate a reset */
1272 if (pf_mdd_detected) {
1273 set_bit(__ICE_NEEDS_RESTART, pf->state);
1274 ice_service_task_schedule(pf);
1278 /* check to see if one of the VFs caused the MDD */
1279 for (i = 0; i < pf->num_alloc_vfs; i++) {
1280 struct ice_vf *vf = &pf->vf[i];
1282 bool vf_mdd_detected = false;
1284 reg = rd32(hw, VP_MDET_TX_PQM(i));
1285 if (reg & VP_MDET_TX_PQM_VALID_M) {
1286 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1287 vf_mdd_detected = true;
1288 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1292 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1293 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1294 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1295 vf_mdd_detected = true;
1296 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1300 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1301 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1302 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1303 vf_mdd_detected = true;
1304 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1308 reg = rd32(hw, VP_MDET_RX(i));
1309 if (reg & VP_MDET_RX_VALID_M) {
1310 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1311 vf_mdd_detected = true;
1312 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1316 if (vf_mdd_detected) {
1317 vf->num_mdd_events++;
1318 if (vf->num_mdd_events > 1)
1319 dev_info(&pf->pdev->dev, "VF %d has had %llu MDD events since last boot\n",
1320 i, vf->num_mdd_events);
1326 * ice_force_phys_link_state - Force the physical link state
1327 * @vsi: VSI to force the physical link state to up/down
1328 * @link_up: true/false indicates to set the physical link to up/down
1330 * Force the physical link state by getting the current PHY capabilities from
1331 * hardware and setting the PHY config based on the determined capabilities. If
1332 * link changes a link event will be triggered because both the Enable Automatic
1333 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1335 * Returns 0 on success, negative on failure
1337 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1339 struct ice_aqc_get_phy_caps_data *pcaps;
1340 struct ice_aqc_set_phy_cfg_data *cfg;
1341 struct ice_port_info *pi;
1345 if (!vsi || !vsi->port_info || !vsi->back)
1347 if (vsi->type != ICE_VSI_PF)
1350 dev = &vsi->back->pdev->dev;
1352 pi = vsi->port_info;
1354 pcaps = devm_kzalloc(dev, sizeof(*pcaps), GFP_KERNEL);
1358 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1362 "Failed to get phy capabilities, VSI %d error %d\n",
1363 vsi->vsi_num, retcode);
1368 /* No change in link */
1369 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1370 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1373 cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL);
1379 cfg->phy_type_low = pcaps->phy_type_low;
1380 cfg->phy_type_high = pcaps->phy_type_high;
1381 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1382 cfg->low_power_ctrl = pcaps->low_power_ctrl;
1383 cfg->eee_cap = pcaps->eee_cap;
1384 cfg->eeer_value = pcaps->eeer_value;
1385 cfg->link_fec_opt = pcaps->link_fec_options;
1387 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1389 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1391 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
1393 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1394 vsi->vsi_num, retcode);
1398 devm_kfree(dev, cfg);
1400 devm_kfree(dev, pcaps);
1405 * ice_check_media_subtask - Check for media; bring link up if detected.
1406 * @pf: pointer to PF struct
1408 static void ice_check_media_subtask(struct ice_pf *pf)
1410 struct ice_port_info *pi;
1411 struct ice_vsi *vsi;
1414 vsi = ice_find_vsi_by_type(pf, ICE_VSI_PF);
1418 /* No need to check for media if it's already present or the interface
1421 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) ||
1422 test_bit(__ICE_DOWN, vsi->state))
1425 /* Refresh link info and check if media is present */
1426 pi = vsi->port_info;
1427 err = ice_update_link_info(pi);
1431 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1432 err = ice_force_phys_link_state(vsi, true);
1435 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1437 /* A Link Status Event will be generated; the event handler
1438 * will complete bringing the interface up
1444 * ice_service_task - manage and run subtasks
1445 * @work: pointer to work_struct contained by the PF struct
1447 static void ice_service_task(struct work_struct *work)
1449 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1450 unsigned long start_time = jiffies;
1454 /* process reset requests first */
1455 ice_reset_subtask(pf);
1457 /* bail if a reset/recovery cycle is pending or rebuild failed */
1458 if (ice_is_reset_in_progress(pf->state) ||
1459 test_bit(__ICE_SUSPENDED, pf->state) ||
1460 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1461 ice_service_task_complete(pf);
1465 ice_check_media_subtask(pf);
1466 ice_check_for_hang_subtask(pf);
1467 ice_sync_fltr_subtask(pf);
1468 ice_handle_mdd_event(pf);
1469 ice_process_vflr_event(pf);
1470 ice_watchdog_subtask(pf);
1471 ice_clean_adminq_subtask(pf);
1472 ice_clean_mailboxq_subtask(pf);
1474 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1475 ice_service_task_complete(pf);
1477 /* If the tasks have taken longer than one service timer period
1478 * or there is more work to be done, reset the service timer to
1479 * schedule the service task now.
1481 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1482 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1483 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1484 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1485 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1486 mod_timer(&pf->serv_tmr, jiffies);
1490 * ice_set_ctrlq_len - helper function to set controlq length
1491 * @hw: pointer to the HW instance
1493 static void ice_set_ctrlq_len(struct ice_hw *hw)
1495 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1496 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1497 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1498 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1499 hw->mailboxq.num_rq_entries = ICE_MBXRQ_LEN;
1500 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
1501 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1502 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1506 * ice_irq_affinity_notify - Callback for affinity changes
1507 * @notify: context as to what irq was changed
1508 * @mask: the new affinity mask
1510 * This is a callback function used by the irq_set_affinity_notifier function
1511 * so that we may register to receive changes to the irq affinity masks.
1514 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1515 const cpumask_t *mask)
1517 struct ice_q_vector *q_vector =
1518 container_of(notify, struct ice_q_vector, affinity_notify);
1520 cpumask_copy(&q_vector->affinity_mask, mask);
1524 * ice_irq_affinity_release - Callback for affinity notifier release
1525 * @ref: internal core kernel usage
1527 * This is a callback function used by the irq_set_affinity_notifier function
1528 * to inform the current notification subscriber that they will no longer
1529 * receive notifications.
1531 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1534 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1535 * @vsi: the VSI being configured
1537 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1539 struct ice_hw *hw = &vsi->back->hw;
1542 ice_for_each_q_vector(vsi, i)
1543 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1550 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1551 * @vsi: the VSI being configured
1552 * @basename: name for the vector
1554 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1556 int q_vectors = vsi->num_q_vectors;
1557 struct ice_pf *pf = vsi->back;
1558 int base = vsi->base_vector;
1564 for (vector = 0; vector < q_vectors; vector++) {
1565 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1567 irq_num = pf->msix_entries[base + vector].vector;
1569 if (q_vector->tx.ring && q_vector->rx.ring) {
1570 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1571 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1573 } else if (q_vector->rx.ring) {
1574 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1575 "%s-%s-%d", basename, "rx", rx_int_idx++);
1576 } else if (q_vector->tx.ring) {
1577 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1578 "%s-%s-%d", basename, "tx", tx_int_idx++);
1580 /* skip this unused q_vector */
1583 err = devm_request_irq(&pf->pdev->dev, irq_num,
1584 vsi->irq_handler, 0,
1585 q_vector->name, q_vector);
1587 netdev_err(vsi->netdev,
1588 "MSIX request_irq failed, error: %d\n", err);
1592 /* register for affinity change notifications */
1593 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1594 q_vector->affinity_notify.release = ice_irq_affinity_release;
1595 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1597 /* assign the mask for this irq */
1598 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1601 vsi->irqs_ready = true;
1607 irq_num = pf->msix_entries[base + vector].vector,
1608 irq_set_affinity_notifier(irq_num, NULL);
1609 irq_set_affinity_hint(irq_num, NULL);
1610 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1616 * ice_ena_misc_vector - enable the non-queue interrupts
1617 * @pf: board private structure
1619 static void ice_ena_misc_vector(struct ice_pf *pf)
1621 struct ice_hw *hw = &pf->hw;
1624 /* clear things first */
1625 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1626 rd32(hw, PFINT_OICR); /* read to clear */
1628 val = (PFINT_OICR_ECC_ERR_M |
1629 PFINT_OICR_MAL_DETECT_M |
1631 PFINT_OICR_PCI_EXCEPTION_M |
1633 PFINT_OICR_HMC_ERR_M |
1634 PFINT_OICR_PE_CRITERR_M);
1636 wr32(hw, PFINT_OICR_ENA, val);
1638 /* SW_ITR_IDX = 0, but don't change INTENA */
1639 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
1640 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1644 * ice_misc_intr - misc interrupt handler
1645 * @irq: interrupt number
1646 * @data: pointer to a q_vector
1648 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1650 struct ice_pf *pf = (struct ice_pf *)data;
1651 struct ice_hw *hw = &pf->hw;
1652 irqreturn_t ret = IRQ_NONE;
1655 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1656 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1658 oicr = rd32(hw, PFINT_OICR);
1659 ena_mask = rd32(hw, PFINT_OICR_ENA);
1661 if (oicr & PFINT_OICR_SWINT_M) {
1662 ena_mask &= ~PFINT_OICR_SWINT_M;
1666 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1667 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1668 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1670 if (oicr & PFINT_OICR_VFLR_M) {
1671 ena_mask &= ~PFINT_OICR_VFLR_M;
1672 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1675 if (oicr & PFINT_OICR_GRST_M) {
1678 /* we have a reset warning */
1679 ena_mask &= ~PFINT_OICR_GRST_M;
1680 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1681 GLGEN_RSTAT_RESET_TYPE_S;
1683 if (reset == ICE_RESET_CORER)
1685 else if (reset == ICE_RESET_GLOBR)
1687 else if (reset == ICE_RESET_EMPR)
1690 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1693 /* If a reset cycle isn't already in progress, we set a bit in
1694 * pf->state so that the service task can start a reset/rebuild.
1695 * We also make note of which reset happened so that peer
1696 * devices/drivers can be informed.
1698 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1699 if (reset == ICE_RESET_CORER)
1700 set_bit(__ICE_CORER_RECV, pf->state);
1701 else if (reset == ICE_RESET_GLOBR)
1702 set_bit(__ICE_GLOBR_RECV, pf->state);
1704 set_bit(__ICE_EMPR_RECV, pf->state);
1706 /* There are couple of different bits at play here.
1707 * hw->reset_ongoing indicates whether the hardware is
1708 * in reset. This is set to true when a reset interrupt
1709 * is received and set back to false after the driver
1710 * has determined that the hardware is out of reset.
1712 * __ICE_RESET_OICR_RECV in pf->state indicates
1713 * that a post reset rebuild is required before the
1714 * driver is operational again. This is set above.
1716 * As this is the start of the reset/rebuild cycle, set
1717 * both to indicate that.
1719 hw->reset_ongoing = true;
1723 if (oicr & PFINT_OICR_HMC_ERR_M) {
1724 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1725 dev_dbg(&pf->pdev->dev,
1726 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1727 rd32(hw, PFHMC_ERRORINFO),
1728 rd32(hw, PFHMC_ERRORDATA));
1731 /* Report any remaining unexpected interrupts */
1734 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1736 /* If a critical error is pending there is no choice but to
1739 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1740 PFINT_OICR_PCI_EXCEPTION_M |
1741 PFINT_OICR_ECC_ERR_M)) {
1742 set_bit(__ICE_PFR_REQ, pf->state);
1743 ice_service_task_schedule(pf);
1748 if (!test_bit(__ICE_DOWN, pf->state)) {
1749 ice_service_task_schedule(pf);
1750 ice_irq_dynamic_ena(hw, NULL, NULL);
1757 * ice_dis_ctrlq_interrupts - disable control queue interrupts
1758 * @hw: pointer to HW structure
1760 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
1762 /* disable Admin queue Interrupt causes */
1763 wr32(hw, PFINT_FW_CTL,
1764 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
1766 /* disable Mailbox queue Interrupt causes */
1767 wr32(hw, PFINT_MBX_CTL,
1768 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
1770 /* disable Control queue Interrupt causes */
1771 wr32(hw, PFINT_OICR_CTL,
1772 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
1778 * ice_free_irq_msix_misc - Unroll misc vector setup
1779 * @pf: board private structure
1781 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1783 struct ice_hw *hw = &pf->hw;
1785 ice_dis_ctrlq_interrupts(hw);
1787 /* disable OICR interrupt */
1788 wr32(hw, PFINT_OICR_ENA, 0);
1791 if (pf->msix_entries) {
1792 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
1793 devm_free_irq(&pf->pdev->dev,
1794 pf->msix_entries[pf->oicr_idx].vector, pf);
1797 pf->num_avail_sw_msix += 1;
1798 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
1802 * ice_ena_ctrlq_interrupts - enable control queue interrupts
1803 * @hw: pointer to HW structure
1804 * @reg_idx: HW vector index to associate the control queue interrupts with
1806 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
1810 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1811 PFINT_OICR_CTL_CAUSE_ENA_M);
1812 wr32(hw, PFINT_OICR_CTL, val);
1814 /* enable Admin queue Interrupt causes */
1815 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1816 PFINT_FW_CTL_CAUSE_ENA_M);
1817 wr32(hw, PFINT_FW_CTL, val);
1819 /* enable Mailbox queue Interrupt causes */
1820 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1821 PFINT_MBX_CTL_CAUSE_ENA_M);
1822 wr32(hw, PFINT_MBX_CTL, val);
1828 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1829 * @pf: board private structure
1831 * This sets up the handler for MSIX 0, which is used to manage the
1832 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1833 * when in MSI or Legacy interrupt mode.
1835 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1837 struct ice_hw *hw = &pf->hw;
1838 int oicr_idx, err = 0;
1840 if (!pf->int_name[0])
1841 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1842 dev_driver_string(&pf->pdev->dev),
1843 dev_name(&pf->pdev->dev));
1845 /* Do not request IRQ but do enable OICR interrupt since settings are
1846 * lost during reset. Note that this function is called only during
1847 * rebuild path and not while reset is in progress.
1849 if (ice_is_reset_in_progress(pf->state))
1852 /* reserve one vector in irq_tracker for misc interrupts */
1853 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1857 pf->num_avail_sw_msix -= 1;
1858 pf->oicr_idx = oicr_idx;
1860 err = devm_request_irq(&pf->pdev->dev,
1861 pf->msix_entries[pf->oicr_idx].vector,
1862 ice_misc_intr, 0, pf->int_name, pf);
1864 dev_err(&pf->pdev->dev,
1865 "devm_request_irq for %s failed: %d\n",
1867 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1868 pf->num_avail_sw_msix += 1;
1873 ice_ena_misc_vector(pf);
1875 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
1876 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
1877 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
1880 ice_irq_dynamic_ena(hw, NULL, NULL);
1886 * ice_napi_add - register NAPI handler for the VSI
1887 * @vsi: VSI for which NAPI handler is to be registered
1889 * This function is only called in the driver's load path. Registering the NAPI
1890 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1891 * reset/rebuild, etc.)
1893 static void ice_napi_add(struct ice_vsi *vsi)
1900 ice_for_each_q_vector(vsi, v_idx)
1901 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1902 ice_napi_poll, NAPI_POLL_WEIGHT);
1906 * ice_cfg_netdev - Allocate, configure and register a netdev
1907 * @vsi: the VSI associated with the new netdev
1909 * Returns 0 on success, negative value on failure
1911 static int ice_cfg_netdev(struct ice_vsi *vsi)
1913 netdev_features_t csumo_features;
1914 netdev_features_t vlano_features;
1915 netdev_features_t dflt_features;
1916 netdev_features_t tso_features;
1917 struct ice_netdev_priv *np;
1918 struct net_device *netdev;
1919 u8 mac_addr[ETH_ALEN];
1922 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
1927 vsi->netdev = netdev;
1928 np = netdev_priv(netdev);
1931 dflt_features = NETIF_F_SG |
1935 csumo_features = NETIF_F_RXCSUM |
1940 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
1941 NETIF_F_HW_VLAN_CTAG_TX |
1942 NETIF_F_HW_VLAN_CTAG_RX;
1944 tso_features = NETIF_F_TSO;
1946 /* set features that user can change */
1947 netdev->hw_features = dflt_features | csumo_features |
1948 vlano_features | tso_features;
1950 /* enable features */
1951 netdev->features |= netdev->hw_features;
1952 /* encap and VLAN devices inherit default, csumo and tso features */
1953 netdev->hw_enc_features |= dflt_features | csumo_features |
1955 netdev->vlan_features |= dflt_features | csumo_features |
1958 if (vsi->type == ICE_VSI_PF) {
1959 SET_NETDEV_DEV(netdev, &vsi->back->pdev->dev);
1960 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
1962 ether_addr_copy(netdev->dev_addr, mac_addr);
1963 ether_addr_copy(netdev->perm_addr, mac_addr);
1966 netdev->priv_flags |= IFF_UNICAST_FLT;
1968 /* assign netdev_ops */
1969 netdev->netdev_ops = &ice_netdev_ops;
1971 /* setup watchdog timeout value to be 5 second */
1972 netdev->watchdog_timeo = 5 * HZ;
1974 ice_set_ethtool_ops(netdev);
1976 netdev->min_mtu = ETH_MIN_MTU;
1977 netdev->max_mtu = ICE_MAX_MTU;
1979 err = register_netdev(vsi->netdev);
1983 netif_carrier_off(vsi->netdev);
1985 /* make sure transmit queues start off as stopped */
1986 netif_tx_stop_all_queues(vsi->netdev);
1992 * ice_fill_rss_lut - Fill the RSS lookup table with default values
1993 * @lut: Lookup table
1994 * @rss_table_size: Lookup table size
1995 * @rss_size: Range of queue number for hashing
1997 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2001 for (i = 0; i < rss_table_size; i++)
2002 lut[i] = i % rss_size;
2006 * ice_pf_vsi_setup - Set up a PF VSI
2007 * @pf: board private structure
2008 * @pi: pointer to the port_info instance
2010 * Returns pointer to the successfully allocated VSI software struct
2011 * on success, otherwise returns NULL on failure.
2013 static struct ice_vsi *
2014 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2016 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
2020 * ice_lb_vsi_setup - Set up a loopback VSI
2021 * @pf: board private structure
2022 * @pi: pointer to the port_info instance
2024 * Returns pointer to the successfully allocated VSI software struct
2025 * on success, otherwise returns NULL on failure.
2028 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2030 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
2034 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2035 * @netdev: network interface to be adjusted
2036 * @proto: unused protocol
2037 * @vid: VLAN ID to be added
2039 * net_device_ops implementation for adding VLAN IDs
2042 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
2045 struct ice_netdev_priv *np = netdev_priv(netdev);
2046 struct ice_vsi *vsi = np->vsi;
2049 if (vid >= VLAN_N_VID) {
2050 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2058 /* Enable VLAN pruning when VLAN 0 is added */
2059 if (unlikely(!vid)) {
2060 ret = ice_cfg_vlan_pruning(vsi, true, false);
2065 /* Add all VLAN IDs including 0 to the switch filter. VLAN ID 0 is
2066 * needed to continue allowing all untagged packets since VLAN prune
2067 * list is applied to all packets by the switch
2069 ret = ice_vsi_add_vlan(vsi, vid);
2071 vsi->vlan_ena = true;
2072 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2079 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2080 * @netdev: network interface to be adjusted
2081 * @proto: unused protocol
2082 * @vid: VLAN ID to be removed
2084 * net_device_ops implementation for removing VLAN IDs
2087 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
2090 struct ice_netdev_priv *np = netdev_priv(netdev);
2091 struct ice_vsi *vsi = np->vsi;
2097 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2100 ret = ice_vsi_kill_vlan(vsi, vid);
2104 /* Disable VLAN pruning when VLAN 0 is removed */
2106 ret = ice_cfg_vlan_pruning(vsi, false, false);
2108 vsi->vlan_ena = false;
2109 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2114 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2115 * @pf: board private structure
2117 * Returns 0 on success, negative value on failure
2119 static int ice_setup_pf_sw(struct ice_pf *pf)
2121 struct ice_vsi *vsi;
2124 if (ice_is_reset_in_progress(pf->state))
2127 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2130 goto unroll_vsi_setup;
2133 status = ice_cfg_netdev(vsi);
2136 goto unroll_vsi_setup;
2139 /* registering the NAPI handler requires both the queues and
2140 * netdev to be created, which are done in ice_pf_vsi_setup()
2141 * and ice_cfg_netdev() respectively
2145 status = ice_init_mac_fltr(pf);
2147 goto unroll_napi_add;
2155 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2156 unregister_netdev(vsi->netdev);
2157 free_netdev(vsi->netdev);
2164 ice_vsi_free_q_vectors(vsi);
2165 ice_vsi_delete(vsi);
2166 ice_vsi_put_qs(vsi);
2167 pf->q_left_tx += vsi->alloc_txq;
2168 pf->q_left_rx += vsi->alloc_rxq;
2175 * ice_determine_q_usage - Calculate queue distribution
2176 * @pf: board private structure
2178 * Return -ENOMEM if we don't get enough queues for all ports
2180 static void ice_determine_q_usage(struct ice_pf *pf)
2182 u16 q_left_tx, q_left_rx;
2184 q_left_tx = pf->hw.func_caps.common_cap.num_txq;
2185 q_left_rx = pf->hw.func_caps.common_cap.num_rxq;
2187 pf->num_lan_tx = min_t(int, q_left_tx, num_online_cpus());
2189 /* only 1 Rx queue unless RSS is enabled */
2190 if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags))
2193 pf->num_lan_rx = min_t(int, q_left_rx, num_online_cpus());
2195 pf->q_left_tx = q_left_tx - pf->num_lan_tx;
2196 pf->q_left_rx = q_left_rx - pf->num_lan_rx;
2200 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2201 * @pf: board private structure to initialize
2203 static void ice_deinit_pf(struct ice_pf *pf)
2205 ice_service_task_stop(pf);
2206 mutex_destroy(&pf->sw_mutex);
2207 mutex_destroy(&pf->avail_q_mutex);
2211 * ice_init_pf - Initialize general software structures (struct ice_pf)
2212 * @pf: board private structure to initialize
2214 static void ice_init_pf(struct ice_pf *pf)
2216 bitmap_zero(pf->flags, ICE_PF_FLAGS_NBITS);
2217 #ifdef CONFIG_PCI_IOV
2218 if (pf->hw.func_caps.common_cap.sr_iov_1_1) {
2219 struct ice_hw *hw = &pf->hw;
2221 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2222 pf->num_vfs_supported = min_t(int, hw->func_caps.num_allocd_vfs,
2225 #endif /* CONFIG_PCI_IOV */
2227 mutex_init(&pf->sw_mutex);
2228 mutex_init(&pf->avail_q_mutex);
2230 /* Clear avail_[t|r]x_qs bitmaps (set all to avail) */
2231 mutex_lock(&pf->avail_q_mutex);
2232 bitmap_zero(pf->avail_txqs, ICE_MAX_TXQS);
2233 bitmap_zero(pf->avail_rxqs, ICE_MAX_RXQS);
2234 mutex_unlock(&pf->avail_q_mutex);
2236 if (pf->hw.func_caps.common_cap.rss_table_size)
2237 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2239 /* setup service timer and periodic service task */
2240 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2241 pf->serv_tmr_period = HZ;
2242 INIT_WORK(&pf->serv_task, ice_service_task);
2243 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2247 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2248 * @pf: board private structure
2250 * compute the number of MSIX vectors required (v_budget) and request from
2251 * the OS. Return the number of vectors reserved or negative on failure
2253 static int ice_ena_msix_range(struct ice_pf *pf)
2255 int v_left, v_actual, v_budget = 0;
2258 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2260 /* reserve one vector for miscellaneous handler */
2265 /* reserve vectors for LAN traffic */
2266 pf->num_lan_msix = min_t(int, num_online_cpus(), v_left);
2267 v_budget += pf->num_lan_msix;
2268 v_left -= pf->num_lan_msix;
2270 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
2271 sizeof(*pf->msix_entries), GFP_KERNEL);
2273 if (!pf->msix_entries) {
2278 for (i = 0; i < v_budget; i++)
2279 pf->msix_entries[i].entry = i;
2281 /* actually reserve the vectors */
2282 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2283 ICE_MIN_MSIX, v_budget);
2286 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
2291 if (v_actual < v_budget) {
2292 dev_warn(&pf->pdev->dev,
2293 "not enough vectors. requested = %d, obtained = %d\n",
2294 v_budget, v_actual);
2295 if (v_actual >= (pf->num_lan_msix + 1)) {
2296 pf->num_avail_sw_msix = v_actual -
2297 (pf->num_lan_msix + 1);
2298 } else if (v_actual >= 2) {
2299 pf->num_lan_msix = 1;
2300 pf->num_avail_sw_msix = v_actual - 2;
2302 pci_disable_msix(pf->pdev);
2311 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2315 pf->num_lan_msix = 0;
2320 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2321 * @pf: board private structure
2323 static void ice_dis_msix(struct ice_pf *pf)
2325 pci_disable_msix(pf->pdev);
2326 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2327 pf->msix_entries = NULL;
2331 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2332 * @pf: board private structure
2334 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2338 if (pf->irq_tracker) {
2339 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
2340 pf->irq_tracker = NULL;
2345 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2346 * @pf: board private structure to initialize
2348 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2352 vectors = ice_ena_msix_range(pf);
2357 /* set up vector assignment tracking */
2359 devm_kzalloc(&pf->pdev->dev, sizeof(*pf->irq_tracker) +
2360 (sizeof(u16) * vectors), GFP_KERNEL);
2361 if (!pf->irq_tracker) {
2366 /* populate SW interrupts pool with number of OS granted IRQs. */
2367 pf->num_avail_sw_msix = vectors;
2368 pf->irq_tracker->num_entries = vectors;
2369 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2375 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
2376 * @pf: pointer to the PF structure
2378 * There is no error returned here because the driver should be able to handle
2379 * 128 Byte cache lines, so we only print a warning in case issues are seen,
2380 * specifically with Tx.
2382 static void ice_verify_cacheline_size(struct ice_pf *pf)
2384 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
2385 dev_warn(&pf->pdev->dev,
2386 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
2387 ICE_CACHE_LINE_BYTES);
2391 * ice_probe - Device initialization routine
2392 * @pdev: PCI device information struct
2393 * @ent: entry in ice_pci_tbl
2395 * Returns 0 on success, negative on failure
2398 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
2400 struct device *dev = &pdev->dev;
2405 /* this driver uses devres, see Documentation/driver-api/driver-model/devres.rst */
2406 err = pcim_enable_device(pdev);
2410 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2412 dev_err(dev, "BAR0 I/O map error %d\n", err);
2416 pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
2420 /* set up for high or low DMA */
2421 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2423 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
2425 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
2429 pci_enable_pcie_error_reporting(pdev);
2430 pci_set_master(pdev);
2433 pci_set_drvdata(pdev, pf);
2434 set_bit(__ICE_DOWN, pf->state);
2435 /* Disable service task until DOWN bit is cleared */
2436 set_bit(__ICE_SERVICE_DIS, pf->state);
2439 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2441 hw->vendor_id = pdev->vendor;
2442 hw->device_id = pdev->device;
2443 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2444 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2445 hw->subsystem_device_id = pdev->subsystem_device;
2446 hw->bus.device = PCI_SLOT(pdev->devfn);
2447 hw->bus.func = PCI_FUNC(pdev->devfn);
2448 ice_set_ctrlq_len(hw);
2450 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2452 #ifndef CONFIG_DYNAMIC_DEBUG
2454 hw->debug_mask = debug;
2457 err = ice_init_hw(hw);
2459 dev_err(dev, "ice_init_hw failed: %d\n", err);
2461 goto err_exit_unroll;
2464 dev_info(dev, "firmware %d.%d.%05d api %d.%d\n",
2465 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_build,
2466 hw->api_maj_ver, hw->api_min_ver);
2470 err = ice_init_pf_dcb(pf, false);
2472 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2473 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
2475 /* do not fail overall init if DCB init fails */
2479 ice_determine_q_usage(pf);
2481 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
2482 if (!pf->num_alloc_vsi) {
2484 goto err_init_pf_unroll;
2487 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
2491 goto err_init_pf_unroll;
2494 err = ice_init_interrupt_scheme(pf);
2496 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
2498 goto err_init_interrupt_unroll;
2501 /* Driver is mostly up */
2502 clear_bit(__ICE_DOWN, pf->state);
2504 /* In case of MSIX we are going to setup the misc vector right here
2505 * to handle admin queue events etc. In case of legacy and MSI
2506 * the misc functionality and queue processing is combined in
2507 * the same vector and that gets setup at open.
2509 err = ice_req_irq_msix_misc(pf);
2511 dev_err(dev, "setup of misc vector failed: %d\n", err);
2512 goto err_init_interrupt_unroll;
2515 /* create switch struct for the switch element created by FW on boot */
2516 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
2517 if (!pf->first_sw) {
2519 goto err_msix_misc_unroll;
2523 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2525 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2527 pf->first_sw->pf = pf;
2529 /* record the sw_id available for later use */
2530 pf->first_sw->sw_id = hw->port_info->sw_id;
2532 err = ice_setup_pf_sw(pf);
2534 dev_err(dev, "probe failed due to setup PF switch:%d\n", err);
2535 goto err_alloc_sw_unroll;
2538 clear_bit(__ICE_SERVICE_DIS, pf->state);
2540 /* since everything is good, start the service timer */
2541 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2543 err = ice_init_link_events(pf->hw.port_info);
2545 dev_err(dev, "ice_init_link_events failed: %d\n", err);
2546 goto err_alloc_sw_unroll;
2549 ice_verify_cacheline_size(pf);
2553 err_alloc_sw_unroll:
2554 set_bit(__ICE_SERVICE_DIS, pf->state);
2555 set_bit(__ICE_DOWN, pf->state);
2556 devm_kfree(&pf->pdev->dev, pf->first_sw);
2557 err_msix_misc_unroll:
2558 ice_free_irq_msix_misc(pf);
2559 err_init_interrupt_unroll:
2560 ice_clear_interrupt_scheme(pf);
2561 devm_kfree(dev, pf->vsi);
2566 pci_disable_pcie_error_reporting(pdev);
2571 * ice_remove - Device removal routine
2572 * @pdev: PCI device information struct
2574 static void ice_remove(struct pci_dev *pdev)
2576 struct ice_pf *pf = pci_get_drvdata(pdev);
2582 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
2583 if (!ice_is_reset_in_progress(pf->state))
2588 set_bit(__ICE_DOWN, pf->state);
2589 ice_service_task_stop(pf);
2591 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
2593 ice_vsi_release_all(pf);
2594 ice_free_irq_msix_misc(pf);
2595 ice_for_each_vsi(pf, i) {
2598 ice_vsi_free_q_vectors(pf->vsi[i]);
2600 ice_clear_interrupt_scheme(pf);
2602 ice_deinit_hw(&pf->hw);
2603 pci_disable_pcie_error_reporting(pdev);
2607 * ice_pci_err_detected - warning that PCI error has been detected
2608 * @pdev: PCI device information struct
2609 * @err: the type of PCI error
2611 * Called to warn that something happened on the PCI bus and the error handling
2612 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
2614 static pci_ers_result_t
2615 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
2617 struct ice_pf *pf = pci_get_drvdata(pdev);
2620 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
2622 return PCI_ERS_RESULT_DISCONNECT;
2625 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2626 ice_service_task_stop(pf);
2628 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2629 set_bit(__ICE_PFR_REQ, pf->state);
2630 ice_prepare_for_reset(pf);
2634 return PCI_ERS_RESULT_NEED_RESET;
2638 * ice_pci_err_slot_reset - a PCI slot reset has just happened
2639 * @pdev: PCI device information struct
2641 * Called to determine if the driver can recover from the PCI slot reset by
2642 * using a register read to determine if the device is recoverable.
2644 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
2646 struct ice_pf *pf = pci_get_drvdata(pdev);
2647 pci_ers_result_t result;
2651 err = pci_enable_device_mem(pdev);
2654 "Cannot re-enable PCI device after reset, error %d\n",
2656 result = PCI_ERS_RESULT_DISCONNECT;
2658 pci_set_master(pdev);
2659 pci_restore_state(pdev);
2660 pci_save_state(pdev);
2661 pci_wake_from_d3(pdev, false);
2663 /* Check for life */
2664 reg = rd32(&pf->hw, GLGEN_RTRIG);
2666 result = PCI_ERS_RESULT_RECOVERED;
2668 result = PCI_ERS_RESULT_DISCONNECT;
2671 err = pci_cleanup_aer_uncorrect_error_status(pdev);
2674 "pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
2676 /* non-fatal, continue */
2682 * ice_pci_err_resume - restart operations after PCI error recovery
2683 * @pdev: PCI device information struct
2685 * Called to allow the driver to bring things back up after PCI error and/or
2686 * reset recovery have finished
2688 static void ice_pci_err_resume(struct pci_dev *pdev)
2690 struct ice_pf *pf = pci_get_drvdata(pdev);
2694 "%s failed, device is unrecoverable\n", __func__);
2698 if (test_bit(__ICE_SUSPENDED, pf->state)) {
2699 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
2704 ice_do_reset(pf, ICE_RESET_PFR);
2705 ice_service_task_restart(pf);
2706 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2710 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
2711 * @pdev: PCI device information struct
2713 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
2715 struct ice_pf *pf = pci_get_drvdata(pdev);
2717 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
2718 ice_service_task_stop(pf);
2720 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
2721 set_bit(__ICE_PFR_REQ, pf->state);
2722 ice_prepare_for_reset(pf);
2728 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
2729 * @pdev: PCI device information struct
2731 static void ice_pci_err_reset_done(struct pci_dev *pdev)
2733 ice_pci_err_resume(pdev);
2736 /* ice_pci_tbl - PCI Device ID Table
2738 * Wildcard entries (PCI_ANY_ID) should come last
2739 * Last entry must be all 0s
2741 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
2742 * Class, Class Mask, private data (not used) }
2744 static const struct pci_device_id ice_pci_tbl[] = {
2745 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
2746 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
2747 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
2748 /* required last entry */
2751 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
2753 static const struct pci_error_handlers ice_pci_err_handler = {
2754 .error_detected = ice_pci_err_detected,
2755 .slot_reset = ice_pci_err_slot_reset,
2756 .reset_prepare = ice_pci_err_reset_prepare,
2757 .reset_done = ice_pci_err_reset_done,
2758 .resume = ice_pci_err_resume
2761 static struct pci_driver ice_driver = {
2762 .name = KBUILD_MODNAME,
2763 .id_table = ice_pci_tbl,
2765 .remove = ice_remove,
2766 .sriov_configure = ice_sriov_configure,
2767 .err_handler = &ice_pci_err_handler
2771 * ice_module_init - Driver registration routine
2773 * ice_module_init is the first routine called when the driver is
2774 * loaded. All it does is register with the PCI subsystem.
2776 static int __init ice_module_init(void)
2780 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
2781 pr_info("%s\n", ice_copyright);
2783 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
2785 pr_err("Failed to create workqueue\n");
2789 status = pci_register_driver(&ice_driver);
2791 pr_err("failed to register PCI driver, err %d\n", status);
2792 destroy_workqueue(ice_wq);
2797 module_init(ice_module_init);
2800 * ice_module_exit - Driver exit cleanup routine
2802 * ice_module_exit is called just before the driver is removed
2805 static void __exit ice_module_exit(void)
2807 pci_unregister_driver(&ice_driver);
2808 destroy_workqueue(ice_wq);
2809 pr_info("module unloaded\n");
2811 module_exit(ice_module_exit);
2814 * ice_set_mac_address - NDO callback to set MAC address
2815 * @netdev: network interface device structure
2816 * @pi: pointer to an address structure
2818 * Returns 0 on success, negative on failure
2820 static int ice_set_mac_address(struct net_device *netdev, void *pi)
2822 struct ice_netdev_priv *np = netdev_priv(netdev);
2823 struct ice_vsi *vsi = np->vsi;
2824 struct ice_pf *pf = vsi->back;
2825 struct ice_hw *hw = &pf->hw;
2826 struct sockaddr *addr = pi;
2827 enum ice_status status;
2832 mac = (u8 *)addr->sa_data;
2834 if (!is_valid_ether_addr(mac))
2835 return -EADDRNOTAVAIL;
2837 if (ether_addr_equal(netdev->dev_addr, mac)) {
2838 netdev_warn(netdev, "already using mac %pM\n", mac);
2842 if (test_bit(__ICE_DOWN, pf->state) ||
2843 ice_is_reset_in_progress(pf->state)) {
2844 netdev_err(netdev, "can't set mac %pM. device not ready\n",
2849 /* When we change the MAC address we also have to change the MAC address
2850 * based filter rules that were created previously for the old MAC
2851 * address. So first, we remove the old filter rule using ice_remove_mac
2852 * and then create a new filter rule using ice_add_mac via
2853 * ice_vsi_cfg_mac_fltr function call for both add and/or remove
2856 status = ice_vsi_cfg_mac_fltr(vsi, netdev->dev_addr, false);
2858 err = -EADDRNOTAVAIL;
2859 goto err_update_filters;
2862 status = ice_vsi_cfg_mac_fltr(vsi, mac, true);
2864 err = -EADDRNOTAVAIL;
2865 goto err_update_filters;
2870 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
2875 /* change the netdev's MAC address */
2876 memcpy(netdev->dev_addr, mac, netdev->addr_len);
2877 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
2880 /* write new MAC address to the firmware */
2881 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
2882 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
2884 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
2891 * ice_set_rx_mode - NDO callback to set the netdev filters
2892 * @netdev: network interface device structure
2894 static void ice_set_rx_mode(struct net_device *netdev)
2896 struct ice_netdev_priv *np = netdev_priv(netdev);
2897 struct ice_vsi *vsi = np->vsi;
2902 /* Set the flags to synchronize filters
2903 * ndo_set_rx_mode may be triggered even without a change in netdev
2906 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
2907 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
2908 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
2910 /* schedule our worker thread which will take care of
2911 * applying the new filter changes
2913 ice_service_task_schedule(vsi->back);
2917 * ice_fdb_add - add an entry to the hardware database
2918 * @ndm: the input from the stack
2919 * @tb: pointer to array of nladdr (unused)
2920 * @dev: the net device pointer
2921 * @addr: the MAC address entry being added
2923 * @flags: instructions from stack about fdb operation
2924 * @extack: netlink extended ack
2927 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
2928 struct net_device *dev, const unsigned char *addr, u16 vid,
2929 u16 flags, struct netlink_ext_ack __always_unused *extack)
2934 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
2937 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
2938 netdev_err(dev, "FDB only supports static addresses\n");
2942 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
2943 err = dev_uc_add_excl(dev, addr);
2944 else if (is_multicast_ether_addr(addr))
2945 err = dev_mc_add_excl(dev, addr);
2949 /* Only return duplicate errors if NLM_F_EXCL is set */
2950 if (err == -EEXIST && !(flags & NLM_F_EXCL))
2957 * ice_fdb_del - delete an entry from the hardware database
2958 * @ndm: the input from the stack
2959 * @tb: pointer to array of nladdr (unused)
2960 * @dev: the net device pointer
2961 * @addr: the MAC address entry being added
2965 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
2966 struct net_device *dev, const unsigned char *addr,
2967 __always_unused u16 vid)
2971 if (ndm->ndm_state & NUD_PERMANENT) {
2972 netdev_err(dev, "FDB only supports static addresses\n");
2976 if (is_unicast_ether_addr(addr))
2977 err = dev_uc_del(dev, addr);
2978 else if (is_multicast_ether_addr(addr))
2979 err = dev_mc_del(dev, addr);
2987 * ice_set_features - set the netdev feature flags
2988 * @netdev: ptr to the netdev being adjusted
2989 * @features: the feature set that the stack is suggesting
2992 ice_set_features(struct net_device *netdev, netdev_features_t features)
2994 struct ice_netdev_priv *np = netdev_priv(netdev);
2995 struct ice_vsi *vsi = np->vsi;
2998 /* Multiple features can be changed in one call so keep features in
2999 * separate if/else statements to guarantee each feature is checked
3001 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
3002 ret = ice_vsi_manage_rss_lut(vsi, true);
3003 else if (!(features & NETIF_F_RXHASH) &&
3004 netdev->features & NETIF_F_RXHASH)
3005 ret = ice_vsi_manage_rss_lut(vsi, false);
3007 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
3008 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3009 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3010 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
3011 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3012 ret = ice_vsi_manage_vlan_stripping(vsi, false);
3014 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
3015 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3016 ret = ice_vsi_manage_vlan_insertion(vsi);
3017 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
3018 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3019 ret = ice_vsi_manage_vlan_insertion(vsi);
3021 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3022 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3023 ret = ice_cfg_vlan_pruning(vsi, true, false);
3024 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3025 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3026 ret = ice_cfg_vlan_pruning(vsi, false, false);
3032 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
3033 * @vsi: VSI to setup VLAN properties for
3035 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
3039 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3040 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3041 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
3042 ret = ice_vsi_manage_vlan_insertion(vsi);
3048 * ice_vsi_cfg - Setup the VSI
3049 * @vsi: the VSI being configured
3051 * Return 0 on success and negative value on error
3053 int ice_vsi_cfg(struct ice_vsi *vsi)
3058 ice_set_rx_mode(vsi->netdev);
3060 err = ice_vsi_vlan_setup(vsi);
3065 ice_vsi_cfg_dcb_rings(vsi);
3067 err = ice_vsi_cfg_lan_txqs(vsi);
3069 err = ice_vsi_cfg_rxqs(vsi);
3075 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3076 * @vsi: the VSI being configured
3078 static void ice_napi_enable_all(struct ice_vsi *vsi)
3085 ice_for_each_q_vector(vsi, q_idx) {
3086 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3088 if (q_vector->rx.ring || q_vector->tx.ring)
3089 napi_enable(&q_vector->napi);
3094 * ice_up_complete - Finish the last steps of bringing up a connection
3095 * @vsi: The VSI being configured
3097 * Return 0 on success and negative value on error
3099 static int ice_up_complete(struct ice_vsi *vsi)
3101 struct ice_pf *pf = vsi->back;
3104 ice_vsi_cfg_msix(vsi);
3106 /* Enable only Rx rings, Tx rings were enabled by the FW when the
3107 * Tx queue group list was configured and the context bits were
3108 * programmed using ice_vsi_cfg_txqs
3110 err = ice_vsi_start_rx_rings(vsi);
3114 clear_bit(__ICE_DOWN, vsi->state);
3115 ice_napi_enable_all(vsi);
3116 ice_vsi_ena_irq(vsi);
3118 if (vsi->port_info &&
3119 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
3121 ice_print_link_msg(vsi, true);
3122 netif_tx_start_all_queues(vsi->netdev);
3123 netif_carrier_on(vsi->netdev);
3126 ice_service_task_schedule(pf);
3132 * ice_up - Bring the connection back up after being down
3133 * @vsi: VSI being configured
3135 int ice_up(struct ice_vsi *vsi)
3139 err = ice_vsi_cfg(vsi);
3141 err = ice_up_complete(vsi);
3147 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
3148 * @ring: Tx or Rx ring to read stats from
3149 * @pkts: packets stats counter
3150 * @bytes: bytes stats counter
3152 * This function fetches stats from the ring considering the atomic operations
3153 * that needs to be performed to read u64 values in 32 bit machine.
3156 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
3165 start = u64_stats_fetch_begin_irq(&ring->syncp);
3166 *pkts = ring->stats.pkts;
3167 *bytes = ring->stats.bytes;
3168 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
3172 * ice_update_vsi_ring_stats - Update VSI stats counters
3173 * @vsi: the VSI to be updated
3175 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
3177 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
3178 struct ice_ring *ring;
3182 /* reset netdev stats */
3183 vsi_stats->tx_packets = 0;
3184 vsi_stats->tx_bytes = 0;
3185 vsi_stats->rx_packets = 0;
3186 vsi_stats->rx_bytes = 0;
3188 /* reset non-netdev (extended) stats */
3189 vsi->tx_restart = 0;
3191 vsi->tx_linearize = 0;
3192 vsi->rx_buf_failed = 0;
3193 vsi->rx_page_failed = 0;
3197 /* update Tx rings counters */
3198 ice_for_each_txq(vsi, i) {
3199 ring = READ_ONCE(vsi->tx_rings[i]);
3200 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3201 vsi_stats->tx_packets += pkts;
3202 vsi_stats->tx_bytes += bytes;
3203 vsi->tx_restart += ring->tx_stats.restart_q;
3204 vsi->tx_busy += ring->tx_stats.tx_busy;
3205 vsi->tx_linearize += ring->tx_stats.tx_linearize;
3208 /* update Rx rings counters */
3209 ice_for_each_rxq(vsi, i) {
3210 ring = READ_ONCE(vsi->rx_rings[i]);
3211 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3212 vsi_stats->rx_packets += pkts;
3213 vsi_stats->rx_bytes += bytes;
3214 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
3215 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
3222 * ice_update_vsi_stats - Update VSI stats counters
3223 * @vsi: the VSI to be updated
3225 void ice_update_vsi_stats(struct ice_vsi *vsi)
3227 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
3228 struct ice_eth_stats *cur_es = &vsi->eth_stats;
3229 struct ice_pf *pf = vsi->back;
3231 if (test_bit(__ICE_DOWN, vsi->state) ||
3232 test_bit(__ICE_CFG_BUSY, pf->state))
3235 /* get stats as recorded by Tx/Rx rings */
3236 ice_update_vsi_ring_stats(vsi);
3238 /* get VSI stats as recorded by the hardware */
3239 ice_update_eth_stats(vsi);
3241 cur_ns->tx_errors = cur_es->tx_errors;
3242 cur_ns->rx_dropped = cur_es->rx_discards;
3243 cur_ns->tx_dropped = cur_es->tx_discards;
3244 cur_ns->multicast = cur_es->rx_multicast;
3246 /* update some more netdev stats if this is main VSI */
3247 if (vsi->type == ICE_VSI_PF) {
3248 cur_ns->rx_crc_errors = pf->stats.crc_errors;
3249 cur_ns->rx_errors = pf->stats.crc_errors +
3250 pf->stats.illegal_bytes;
3251 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
3252 /* record drops from the port level */
3253 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
3258 * ice_update_pf_stats - Update PF port stats counters
3259 * @pf: PF whose stats needs to be updated
3261 void ice_update_pf_stats(struct ice_pf *pf)
3263 struct ice_hw_port_stats *prev_ps, *cur_ps;
3264 struct ice_hw *hw = &pf->hw;
3267 port = hw->port_info->lport;
3268 prev_ps = &pf->stats_prev;
3269 cur_ps = &pf->stats;
3271 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
3272 &prev_ps->eth.rx_bytes,
3273 &cur_ps->eth.rx_bytes);
3275 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
3276 &prev_ps->eth.rx_unicast,
3277 &cur_ps->eth.rx_unicast);
3279 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
3280 &prev_ps->eth.rx_multicast,
3281 &cur_ps->eth.rx_multicast);
3283 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
3284 &prev_ps->eth.rx_broadcast,
3285 &cur_ps->eth.rx_broadcast);
3287 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
3288 &prev_ps->eth.rx_discards,
3289 &cur_ps->eth.rx_discards);
3291 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
3292 &prev_ps->eth.tx_bytes,
3293 &cur_ps->eth.tx_bytes);
3295 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
3296 &prev_ps->eth.tx_unicast,
3297 &cur_ps->eth.tx_unicast);
3299 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
3300 &prev_ps->eth.tx_multicast,
3301 &cur_ps->eth.tx_multicast);
3303 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
3304 &prev_ps->eth.tx_broadcast,
3305 &cur_ps->eth.tx_broadcast);
3307 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
3308 &prev_ps->tx_dropped_link_down,
3309 &cur_ps->tx_dropped_link_down);
3311 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
3312 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
3314 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
3315 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
3317 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
3318 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
3320 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
3321 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
3323 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
3324 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
3326 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
3327 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
3329 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
3330 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
3332 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
3333 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
3335 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
3336 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
3338 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
3339 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
3341 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
3342 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
3344 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
3345 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
3347 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
3348 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
3350 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
3351 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
3353 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
3354 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
3356 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
3357 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
3359 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
3360 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
3362 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
3363 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
3365 ice_update_dcb_stats(pf);
3367 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
3368 &prev_ps->crc_errors, &cur_ps->crc_errors);
3370 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
3371 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
3373 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
3374 &prev_ps->mac_local_faults,
3375 &cur_ps->mac_local_faults);
3377 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
3378 &prev_ps->mac_remote_faults,
3379 &cur_ps->mac_remote_faults);
3381 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
3382 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
3384 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
3385 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
3387 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
3388 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
3390 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
3391 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
3393 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
3394 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
3396 pf->stat_prev_loaded = true;
3400 * ice_get_stats64 - get statistics for network device structure
3401 * @netdev: network interface device structure
3402 * @stats: main device statistics structure
3405 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
3407 struct ice_netdev_priv *np = netdev_priv(netdev);
3408 struct rtnl_link_stats64 *vsi_stats;
3409 struct ice_vsi *vsi = np->vsi;
3411 vsi_stats = &vsi->net_stats;
3413 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->num_txq || !vsi->num_rxq)
3415 /* netdev packet/byte stats come from ring counter. These are obtained
3416 * by summing up ring counters (done by ice_update_vsi_ring_stats).
3418 ice_update_vsi_ring_stats(vsi);
3419 stats->tx_packets = vsi_stats->tx_packets;
3420 stats->tx_bytes = vsi_stats->tx_bytes;
3421 stats->rx_packets = vsi_stats->rx_packets;
3422 stats->rx_bytes = vsi_stats->rx_bytes;
3424 /* The rest of the stats can be read from the hardware but instead we
3425 * just return values that the watchdog task has already obtained from
3428 stats->multicast = vsi_stats->multicast;
3429 stats->tx_errors = vsi_stats->tx_errors;
3430 stats->tx_dropped = vsi_stats->tx_dropped;
3431 stats->rx_errors = vsi_stats->rx_errors;
3432 stats->rx_dropped = vsi_stats->rx_dropped;
3433 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
3434 stats->rx_length_errors = vsi_stats->rx_length_errors;
3438 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3439 * @vsi: VSI having NAPI disabled
3441 static void ice_napi_disable_all(struct ice_vsi *vsi)
3448 ice_for_each_q_vector(vsi, q_idx) {
3449 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3451 if (q_vector->rx.ring || q_vector->tx.ring)
3452 napi_disable(&q_vector->napi);
3457 * ice_down - Shutdown the connection
3458 * @vsi: The VSI being stopped
3460 int ice_down(struct ice_vsi *vsi)
3462 int i, tx_err, rx_err, link_err = 0;
3464 /* Caller of this function is expected to set the
3465 * vsi->state __ICE_DOWN bit
3468 netif_carrier_off(vsi->netdev);
3469 netif_tx_disable(vsi->netdev);
3472 ice_vsi_dis_irq(vsi);
3474 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
3476 netdev_err(vsi->netdev,
3477 "Failed stop Tx rings, VSI %d error %d\n",
3478 vsi->vsi_num, tx_err);
3480 rx_err = ice_vsi_stop_rx_rings(vsi);
3482 netdev_err(vsi->netdev,
3483 "Failed stop Rx rings, VSI %d error %d\n",
3484 vsi->vsi_num, rx_err);
3486 ice_napi_disable_all(vsi);
3488 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
3489 link_err = ice_force_phys_link_state(vsi, false);
3491 netdev_err(vsi->netdev,
3492 "Failed to set physical link down, VSI %d error %d\n",
3493 vsi->vsi_num, link_err);
3496 ice_for_each_txq(vsi, i)
3497 ice_clean_tx_ring(vsi->tx_rings[i]);
3499 ice_for_each_rxq(vsi, i)
3500 ice_clean_rx_ring(vsi->rx_rings[i]);
3502 if (tx_err || rx_err || link_err) {
3503 netdev_err(vsi->netdev,
3504 "Failed to close VSI 0x%04X on switch 0x%04X\n",
3505 vsi->vsi_num, vsi->vsw->sw_id);
3513 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
3514 * @vsi: VSI having resources allocated
3516 * Return 0 on success, negative on failure
3518 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3522 if (!vsi->num_txq) {
3523 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3528 ice_for_each_txq(vsi, i) {
3529 vsi->tx_rings[i]->netdev = vsi->netdev;
3530 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3539 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3540 * @vsi: VSI having resources allocated
3542 * Return 0 on success, negative on failure
3544 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3548 if (!vsi->num_rxq) {
3549 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3554 ice_for_each_rxq(vsi, i) {
3555 vsi->rx_rings[i]->netdev = vsi->netdev;
3556 err = ice_setup_rx_ring(vsi->rx_rings[i]);
3565 * ice_vsi_open - Called when a network interface is made active
3566 * @vsi: the VSI to open
3568 * Initialization of the VSI
3570 * Returns 0 on success, negative value on error
3572 static int ice_vsi_open(struct ice_vsi *vsi)
3574 char int_name[ICE_INT_NAME_STR_LEN];
3575 struct ice_pf *pf = vsi->back;
3578 /* allocate descriptors */
3579 err = ice_vsi_setup_tx_rings(vsi);
3583 err = ice_vsi_setup_rx_rings(vsi);
3587 err = ice_vsi_cfg(vsi);
3591 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
3592 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
3593 err = ice_vsi_req_irq_msix(vsi, int_name);
3597 /* Notify the stack of the actual queue counts. */
3598 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
3602 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
3606 err = ice_up_complete(vsi);
3608 goto err_up_complete;
3615 ice_vsi_free_irq(vsi);
3617 ice_vsi_free_rx_rings(vsi);
3619 ice_vsi_free_tx_rings(vsi);
3625 * ice_vsi_release_all - Delete all VSIs
3626 * @pf: PF from which all VSIs are being removed
3628 static void ice_vsi_release_all(struct ice_pf *pf)
3635 ice_for_each_vsi(pf, i) {
3639 err = ice_vsi_release(pf->vsi[i]);
3641 dev_dbg(&pf->pdev->dev,
3642 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
3643 i, err, pf->vsi[i]->vsi_num);
3648 * ice_ena_vsi - resume a VSI
3649 * @vsi: the VSI being resume
3650 * @locked: is the rtnl_lock already held
3652 static int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
3656 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
3659 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
3661 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
3662 if (netif_running(vsi->netdev)) {
3666 err = ice_open(vsi->netdev);
3677 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
3679 * @locked: is the rtnl_lock already held
3682 int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3684 static int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
3685 #endif /* CONFIG_DCB */
3689 ice_for_each_vsi(pf, v)
3691 if (ice_ena_vsi(pf->vsi[v], locked))
3698 * ice_vsi_rebuild_all - rebuild all VSIs in PF
3701 static int ice_vsi_rebuild_all(struct ice_pf *pf)
3705 /* loop through pf->vsi array and reinit the VSI if found */
3706 ice_for_each_vsi(pf, i) {
3712 err = ice_vsi_rebuild(pf->vsi[i]);
3714 dev_err(&pf->pdev->dev,
3715 "VSI at index %d rebuild failed\n",
3720 dev_info(&pf->pdev->dev,
3721 "VSI at index %d rebuilt. vsi_num = 0x%x\n",
3722 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3729 * ice_vsi_replay_all - replay all VSIs configuration in the PF
3732 static int ice_vsi_replay_all(struct ice_pf *pf)
3734 struct ice_hw *hw = &pf->hw;
3735 enum ice_status ret;
3738 /* loop through pf->vsi array and replay the VSI if found */
3739 ice_for_each_vsi(pf, i) {
3743 ret = ice_replay_vsi(hw, pf->vsi[i]->idx);
3745 dev_err(&pf->pdev->dev,
3746 "VSI at index %d replay failed %d\n",
3747 pf->vsi[i]->idx, ret);
3751 /* Re-map HW VSI number, using VSI handle that has been
3752 * previously validated in ice_replay_vsi() call above
3754 pf->vsi[i]->vsi_num = ice_get_hw_vsi_num(hw, pf->vsi[i]->idx);
3756 dev_info(&pf->pdev->dev,
3757 "VSI at index %d filter replayed successfully - vsi_num %i\n",
3758 pf->vsi[i]->idx, pf->vsi[i]->vsi_num);
3761 /* Clean up replay filter after successful re-configuration */
3762 ice_replay_post(hw);
3767 * ice_rebuild - rebuild after reset
3768 * @pf: PF to rebuild
3770 static void ice_rebuild(struct ice_pf *pf)
3772 struct device *dev = &pf->pdev->dev;
3773 struct ice_hw *hw = &pf->hw;
3774 enum ice_status ret;
3777 if (test_bit(__ICE_DOWN, pf->state))
3778 goto clear_recovery;
3780 dev_dbg(dev, "rebuilding PF\n");
3782 ret = ice_init_all_ctrlq(hw);
3784 dev_err(dev, "control queues init failed %d\n", ret);
3785 goto err_init_ctrlq;
3788 ret = ice_clear_pf_cfg(hw);
3790 dev_err(dev, "clear PF configuration failed %d\n", ret);
3791 goto err_init_ctrlq;
3794 ice_clear_pxe_mode(hw);
3796 ret = ice_get_caps(hw);
3798 dev_err(dev, "ice_get_caps failed %d\n", ret);
3799 goto err_init_ctrlq;
3802 err = ice_sched_init_port(hw->port_info);
3804 goto err_sched_init_port;
3806 ice_dcb_rebuild(pf);
3808 err = ice_vsi_rebuild_all(pf);
3810 dev_err(dev, "ice_vsi_rebuild_all failed\n");
3811 goto err_vsi_rebuild;
3814 err = ice_update_link_info(hw->port_info);
3816 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
3818 /* Replay all VSIs Configuration, including filters after reset */
3819 if (ice_vsi_replay_all(pf)) {
3820 dev_err(&pf->pdev->dev,
3821 "error replaying VSI configurations with switch filter rules\n");
3822 goto err_vsi_rebuild;
3825 /* start misc vector */
3826 err = ice_req_irq_msix_misc(pf);
3828 dev_err(dev, "misc vector setup failed: %d\n", err);
3829 goto err_vsi_rebuild;
3832 /* restart the VSIs that were rebuilt and running before the reset */
3833 err = ice_pf_ena_all_vsi(pf, false);
3835 dev_err(&pf->pdev->dev, "error enabling VSIs\n");
3836 /* no need to disable VSIs in tear down path in ice_rebuild()
3837 * since its already taken care in ice_vsi_open()
3839 goto err_vsi_rebuild;
3842 ice_for_each_vsi(pf, i) {
3845 if (!pf->vsi[i] || pf->vsi[i]->type != ICE_VSI_PF)
3847 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
3849 netif_carrier_on(pf->vsi[i]->netdev);
3850 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
3852 netif_carrier_off(pf->vsi[i]->netdev);
3853 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
3857 /* if we get here, reset flow is successful */
3858 clear_bit(__ICE_RESET_FAILED, pf->state);
3862 ice_vsi_release_all(pf);
3863 err_sched_init_port:
3864 ice_sched_cleanup_all(hw);
3866 ice_shutdown_all_ctrlq(hw);
3867 set_bit(__ICE_RESET_FAILED, pf->state);
3869 /* set this bit in PF state to control service task scheduling */
3870 set_bit(__ICE_NEEDS_RESTART, pf->state);
3871 dev_err(dev, "Rebuild failed, unload and reload driver\n");
3875 * ice_change_mtu - NDO callback to change the MTU
3876 * @netdev: network interface device structure
3877 * @new_mtu: new value for maximum frame size
3879 * Returns 0 on success, negative on failure
3881 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
3883 struct ice_netdev_priv *np = netdev_priv(netdev);
3884 struct ice_vsi *vsi = np->vsi;
3885 struct ice_pf *pf = vsi->back;
3888 if (new_mtu == netdev->mtu) {
3889 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
3893 if (new_mtu < netdev->min_mtu) {
3894 netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
3897 } else if (new_mtu > netdev->max_mtu) {
3898 netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
3902 /* if a reset is in progress, wait for some time for it to complete */
3904 if (ice_is_reset_in_progress(pf->state)) {
3906 usleep_range(1000, 2000);
3911 } while (count < 100);
3914 netdev_err(netdev, "can't change MTU. Device is busy\n");
3918 netdev->mtu = new_mtu;
3920 /* if VSI is up, bring it down and then back up */
3921 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
3924 err = ice_down(vsi);
3926 netdev_err(netdev, "change MTU if_up err %d\n", err);
3932 netdev_err(netdev, "change MTU if_up err %d\n", err);
3937 netdev_info(netdev, "changed MTU to %d\n", new_mtu);
3942 * ice_set_rss - Set RSS keys and lut
3943 * @vsi: Pointer to VSI structure
3944 * @seed: RSS hash seed
3945 * @lut: Lookup table
3946 * @lut_size: Lookup table size
3948 * Returns 0 on success, negative on failure
3950 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3952 struct ice_pf *pf = vsi->back;
3953 struct ice_hw *hw = &pf->hw;
3954 enum ice_status status;
3957 struct ice_aqc_get_set_rss_keys *buf =
3958 (struct ice_aqc_get_set_rss_keys *)seed;
3960 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
3963 dev_err(&pf->pdev->dev,
3964 "Cannot set RSS key, err %d aq_err %d\n",
3965 status, hw->adminq.rq_last_status);
3971 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
3974 dev_err(&pf->pdev->dev,
3975 "Cannot set RSS lut, err %d aq_err %d\n",
3976 status, hw->adminq.rq_last_status);
3985 * ice_get_rss - Get RSS keys and lut
3986 * @vsi: Pointer to VSI structure
3987 * @seed: Buffer to store the keys
3988 * @lut: Buffer to store the lookup table entries
3989 * @lut_size: Size of buffer to store the lookup table entries
3991 * Returns 0 on success, negative on failure
3993 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
3995 struct ice_pf *pf = vsi->back;
3996 struct ice_hw *hw = &pf->hw;
3997 enum ice_status status;
4000 struct ice_aqc_get_set_rss_keys *buf =
4001 (struct ice_aqc_get_set_rss_keys *)seed;
4003 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4005 dev_err(&pf->pdev->dev,
4006 "Cannot get RSS key, err %d aq_err %d\n",
4007 status, hw->adminq.rq_last_status);
4013 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4016 dev_err(&pf->pdev->dev,
4017 "Cannot get RSS lut, err %d aq_err %d\n",
4018 status, hw->adminq.rq_last_status);
4027 * ice_bridge_getlink - Get the hardware bridge mode
4030 * @seq: RTNL message seq
4031 * @dev: the netdev being configured
4032 * @filter_mask: filter mask passed in
4033 * @nlflags: netlink flags passed in
4035 * Return the bridge mode (VEB/VEPA)
4038 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4039 struct net_device *dev, u32 filter_mask, int nlflags)
4041 struct ice_netdev_priv *np = netdev_priv(dev);
4042 struct ice_vsi *vsi = np->vsi;
4043 struct ice_pf *pf = vsi->back;
4046 bmode = pf->first_sw->bridge_mode;
4048 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4053 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4054 * @vsi: Pointer to VSI structure
4055 * @bmode: Hardware bridge mode (VEB/VEPA)
4057 * Returns 0 on success, negative on failure
4059 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4061 struct device *dev = &vsi->back->pdev->dev;
4062 struct ice_aqc_vsi_props *vsi_props;
4063 struct ice_hw *hw = &vsi->back->hw;
4064 struct ice_vsi_ctx *ctxt;
4065 enum ice_status status;
4068 vsi_props = &vsi->info;
4070 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
4074 ctxt->info = vsi->info;
4076 if (bmode == BRIDGE_MODE_VEB)
4077 /* change from VEPA to VEB mode */
4078 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4080 /* change from VEB to VEPA mode */
4081 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4082 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4084 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4086 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4087 bmode, status, hw->adminq.sq_last_status);
4091 /* Update sw flags for book keeping */
4092 vsi_props->sw_flags = ctxt->info.sw_flags;
4095 devm_kfree(dev, ctxt);
4100 * ice_bridge_setlink - Set the hardware bridge mode
4101 * @dev: the netdev being configured
4102 * @nlh: RTNL message
4103 * @flags: bridge setlink flags
4104 * @extack: netlink extended ack
4106 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4107 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4108 * not already set for all VSIs connected to this switch. And also update the
4109 * unicast switch filter rules for the corresponding switch of the netdev.
4112 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4113 u16 __always_unused flags,
4114 struct netlink_ext_ack __always_unused *extack)
4116 struct ice_netdev_priv *np = netdev_priv(dev);
4117 struct ice_pf *pf = np->vsi->back;
4118 struct nlattr *attr, *br_spec;
4119 struct ice_hw *hw = &pf->hw;
4120 enum ice_status status;
4121 struct ice_sw *pf_sw;
4122 int rem, v, err = 0;
4124 pf_sw = pf->first_sw;
4125 /* find the attribute in the netlink message */
4126 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4128 nla_for_each_nested(attr, br_spec, rem) {
4131 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4133 mode = nla_get_u16(attr);
4134 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4136 /* Continue if bridge mode is not being flipped */
4137 if (mode == pf_sw->bridge_mode)
4139 /* Iterates through the PF VSI list and update the loopback
4142 ice_for_each_vsi(pf, v) {
4145 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
4150 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
4151 /* Update the unicast switch filter rules for the corresponding
4152 * switch of the netdev
4154 status = ice_update_sw_rule_bridge_mode(hw);
4156 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
4157 mode, status, hw->adminq.sq_last_status);
4158 /* revert hw->evb_veb */
4159 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
4163 pf_sw->bridge_mode = mode;
4170 * ice_tx_timeout - Respond to a Tx Hang
4171 * @netdev: network interface device structure
4173 static void ice_tx_timeout(struct net_device *netdev)
4175 struct ice_netdev_priv *np = netdev_priv(netdev);
4176 struct ice_ring *tx_ring = NULL;
4177 struct ice_vsi *vsi = np->vsi;
4178 struct ice_pf *pf = vsi->back;
4179 int hung_queue = -1;
4182 pf->tx_timeout_count++;
4184 /* find the stopped queue the same way dev_watchdog() does */
4185 for (i = 0; i < netdev->num_tx_queues; i++) {
4186 unsigned long trans_start;
4187 struct netdev_queue *q;
4189 q = netdev_get_tx_queue(netdev, i);
4190 trans_start = q->trans_start;
4191 if (netif_xmit_stopped(q) &&
4193 trans_start + netdev->watchdog_timeo)) {
4199 if (i == netdev->num_tx_queues)
4200 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
4202 /* now that we have an index, find the tx_ring struct */
4203 for (i = 0; i < vsi->num_txq; i++)
4204 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
4205 if (hung_queue == vsi->tx_rings[i]->q_index) {
4206 tx_ring = vsi->tx_rings[i];
4210 /* Reset recovery level if enough time has elapsed after last timeout.
4211 * Also ensure no new reset action happens before next timeout period.
4213 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
4214 pf->tx_timeout_recovery_level = 1;
4215 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
4216 netdev->watchdog_timeo)))
4220 struct ice_hw *hw = &pf->hw;
4223 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
4224 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
4225 /* Read interrupt register */
4226 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
4228 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
4229 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
4230 head, tx_ring->next_to_use, val);
4233 pf->tx_timeout_last_recovery = jiffies;
4234 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
4235 pf->tx_timeout_recovery_level, hung_queue);
4237 switch (pf->tx_timeout_recovery_level) {
4239 set_bit(__ICE_PFR_REQ, pf->state);
4242 set_bit(__ICE_CORER_REQ, pf->state);
4245 set_bit(__ICE_GLOBR_REQ, pf->state);
4248 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
4249 set_bit(__ICE_DOWN, pf->state);
4250 set_bit(__ICE_NEEDS_RESTART, vsi->state);
4251 set_bit(__ICE_SERVICE_DIS, pf->state);
4255 ice_service_task_schedule(pf);
4256 pf->tx_timeout_recovery_level++;
4260 * ice_open - Called when a network interface becomes active
4261 * @netdev: network interface device structure
4263 * The open entry point is called when a network interface is made
4264 * active by the system (IFF_UP). At this point all resources needed
4265 * for transmit and receive operations are allocated, the interrupt
4266 * handler is registered with the OS, the netdev watchdog is enabled,
4267 * and the stack is notified that the interface is ready.
4269 * Returns 0 on success, negative value on failure
4271 int ice_open(struct net_device *netdev)
4273 struct ice_netdev_priv *np = netdev_priv(netdev);
4274 struct ice_vsi *vsi = np->vsi;
4275 struct ice_port_info *pi;
4278 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
4279 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
4283 netif_carrier_off(netdev);
4285 pi = vsi->port_info;
4286 err = ice_update_link_info(pi);
4288 netdev_err(netdev, "Failed to get link info, error %d\n",
4293 /* Set PHY if there is media, otherwise, turn off PHY */
4294 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
4295 err = ice_force_phys_link_state(vsi, true);
4298 "Failed to set physical link up, error %d\n",
4303 err = ice_aq_set_link_restart_an(pi, false, NULL);
4305 netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n",
4309 set_bit(ICE_FLAG_NO_MEDIA, vsi->back->flags);
4312 err = ice_vsi_open(vsi);
4314 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
4315 vsi->vsi_num, vsi->vsw->sw_id);
4320 * ice_stop - Disables a network interface
4321 * @netdev: network interface device structure
4323 * The stop entry point is called when an interface is de-activated by the OS,
4324 * and the netdevice enters the DOWN state. The hardware is still under the
4325 * driver's control, but the netdev interface is disabled.
4327 * Returns success only - not allowed to fail
4329 int ice_stop(struct net_device *netdev)
4331 struct ice_netdev_priv *np = netdev_priv(netdev);
4332 struct ice_vsi *vsi = np->vsi;
4340 * ice_features_check - Validate encapsulated packet conforms to limits
4342 * @netdev: This port's netdev
4343 * @features: Offload features that the stack believes apply
4345 static netdev_features_t
4346 ice_features_check(struct sk_buff *skb,
4347 struct net_device __always_unused *netdev,
4348 netdev_features_t features)
4352 /* No point in doing any of this if neither checksum nor GSO are
4353 * being requested for this frame. We can rule out both by just
4354 * checking for CHECKSUM_PARTIAL
4356 if (skb->ip_summed != CHECKSUM_PARTIAL)
4359 /* We cannot support GSO if the MSS is going to be less than
4360 * 64 bytes. If it is then we need to drop support for GSO.
4362 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
4363 features &= ~NETIF_F_GSO_MASK;
4365 len = skb_network_header(skb) - skb->data;
4366 if (len & ~(ICE_TXD_MACLEN_MAX))
4367 goto out_rm_features;
4369 len = skb_transport_header(skb) - skb_network_header(skb);
4370 if (len & ~(ICE_TXD_IPLEN_MAX))
4371 goto out_rm_features;
4373 if (skb->encapsulation) {
4374 len = skb_inner_network_header(skb) - skb_transport_header(skb);
4375 if (len & ~(ICE_TXD_L4LEN_MAX))
4376 goto out_rm_features;
4378 len = skb_inner_transport_header(skb) -
4379 skb_inner_network_header(skb);
4380 if (len & ~(ICE_TXD_IPLEN_MAX))
4381 goto out_rm_features;
4386 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
4389 static const struct net_device_ops ice_netdev_ops = {
4390 .ndo_open = ice_open,
4391 .ndo_stop = ice_stop,
4392 .ndo_start_xmit = ice_start_xmit,
4393 .ndo_features_check = ice_features_check,
4394 .ndo_set_rx_mode = ice_set_rx_mode,
4395 .ndo_set_mac_address = ice_set_mac_address,
4396 .ndo_validate_addr = eth_validate_addr,
4397 .ndo_change_mtu = ice_change_mtu,
4398 .ndo_get_stats64 = ice_get_stats64,
4399 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
4400 .ndo_set_vf_mac = ice_set_vf_mac,
4401 .ndo_get_vf_config = ice_get_vf_cfg,
4402 .ndo_set_vf_trust = ice_set_vf_trust,
4403 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
4404 .ndo_set_vf_link_state = ice_set_vf_link_state,
4405 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
4406 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
4407 .ndo_set_features = ice_set_features,
4408 .ndo_bridge_getlink = ice_bridge_getlink,
4409 .ndo_bridge_setlink = ice_bridge_setlink,
4410 .ndo_fdb_add = ice_fdb_add,
4411 .ndo_fdb_del = ice_fdb_del,
4412 .ndo_tx_timeout = ice_tx_timeout,