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_MAJOR 0
13 #define DRV_VERSION_MINOR 7
14 #define DRV_VERSION_BUILD 5
16 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
17 __stringify(DRV_VERSION_MINOR) "." \
18 __stringify(DRV_VERSION_BUILD) "-k"
19 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
20 const char ice_drv_ver[] = DRV_VERSION;
21 static const char ice_driver_string[] = DRV_SUMMARY;
22 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
24 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
25 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
26 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
28 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
29 MODULE_DESCRIPTION(DRV_SUMMARY);
30 MODULE_LICENSE("GPL v2");
31 MODULE_VERSION(DRV_VERSION);
32 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
34 static int debug = -1;
35 module_param(debug, int, 0644);
36 #ifndef CONFIG_DYNAMIC_DEBUG
37 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
39 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
40 #endif /* !CONFIG_DYNAMIC_DEBUG */
42 static struct workqueue_struct *ice_wq;
43 static const struct net_device_ops ice_netdev_safe_mode_ops;
44 static const struct net_device_ops ice_netdev_ops;
46 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
48 static void ice_vsi_release_all(struct ice_pf *pf);
51 * ice_get_tx_pending - returns number of Tx descriptors not processed
52 * @ring: the ring of descriptors
54 static u16 ice_get_tx_pending(struct ice_ring *ring)
58 head = ring->next_to_clean;
59 tail = ring->next_to_use;
62 return (head < tail) ?
63 tail - head : (tail + ring->count - head);
68 * ice_check_for_hang_subtask - check for and recover hung queues
69 * @pf: pointer to PF struct
71 static void ice_check_for_hang_subtask(struct ice_pf *pf)
73 struct ice_vsi *vsi = NULL;
79 ice_for_each_vsi(pf, v)
80 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
85 if (!vsi || test_bit(__ICE_DOWN, vsi->state))
88 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
93 for (i = 0; i < vsi->num_txq; i++) {
94 struct ice_ring *tx_ring = vsi->tx_rings[i];
96 if (tx_ring && tx_ring->desc) {
97 /* If packet counter has not changed the queue is
98 * likely stalled, so force an interrupt for this
101 * prev_pkt would be negative if there was no
104 packets = tx_ring->stats.pkts & INT_MAX;
105 if (tx_ring->tx_stats.prev_pkt == packets) {
106 /* Trigger sw interrupt to revive the queue */
107 ice_trigger_sw_intr(hw, tx_ring->q_vector);
111 /* Memory barrier between read of packet count and call
112 * to ice_get_tx_pending()
115 tx_ring->tx_stats.prev_pkt =
116 ice_get_tx_pending(tx_ring) ? packets : -1;
122 * ice_init_mac_fltr - Set initial MAC filters
123 * @pf: board private structure
125 * Set initial set of MAC filters for PF VSI; configure filters for permanent
126 * address and broadcast address. If an error is encountered, netdevice will be
129 static int ice_init_mac_fltr(struct ice_pf *pf)
131 enum ice_status status;
132 u8 broadcast[ETH_ALEN];
135 vsi = ice_get_main_vsi(pf);
139 /* To add a MAC filter, first add the MAC to a list and then
140 * pass the list to ice_add_mac.
143 /* Add a unicast MAC filter so the VSI can get its packets */
144 status = ice_vsi_cfg_mac_fltr(vsi, vsi->port_info->mac.perm_addr, true);
148 /* VSI needs to receive broadcast traffic, so add the broadcast
149 * MAC address to the list as well.
151 eth_broadcast_addr(broadcast);
152 status = ice_vsi_cfg_mac_fltr(vsi, broadcast, true);
158 /* We aren't useful with no MAC filters, so unregister if we
161 if (status && vsi->netdev->reg_state == NETREG_REGISTERED) {
162 dev_err(&pf->pdev->dev,
163 "Could not add MAC filters error %d. Unregistering device\n",
165 unregister_netdev(vsi->netdev);
166 free_netdev(vsi->netdev);
174 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
175 * @netdev: the net device on which the sync is happening
176 * @addr: MAC address to sync
178 * This is a callback function which is called by the in kernel device sync
179 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
180 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
181 * MAC filters from the hardware.
183 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
185 struct ice_netdev_priv *np = netdev_priv(netdev);
186 struct ice_vsi *vsi = np->vsi;
188 if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr))
195 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
196 * @netdev: the net device on which the unsync is happening
197 * @addr: MAC address to unsync
199 * This is a callback function which is called by the in kernel device unsync
200 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
201 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
202 * delete the MAC filters from the hardware.
204 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
206 struct ice_netdev_priv *np = netdev_priv(netdev);
207 struct ice_vsi *vsi = np->vsi;
209 if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr))
216 * ice_vsi_fltr_changed - check if filter state changed
217 * @vsi: VSI to be checked
219 * returns true if filter state has changed, false otherwise.
221 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
223 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags) ||
224 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags) ||
225 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
229 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
230 * @vsi: the VSI being configured
231 * @promisc_m: mask of promiscuous config bits
232 * @set_promisc: enable or disable promisc flag request
235 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
237 struct ice_hw *hw = &vsi->back->hw;
238 enum ice_status status = 0;
240 if (vsi->type != ICE_VSI_PF)
244 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
248 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
251 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
262 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
263 * @vsi: ptr to the VSI
265 * Push any outstanding VSI filter changes through the AdminQ.
267 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
269 struct device *dev = &vsi->back->pdev->dev;
270 struct net_device *netdev = vsi->netdev;
271 bool promisc_forced_on = false;
272 struct ice_pf *pf = vsi->back;
273 struct ice_hw *hw = &pf->hw;
274 enum ice_status status = 0;
275 u32 changed_flags = 0;
282 while (test_and_set_bit(__ICE_CFG_BUSY, vsi->state))
283 usleep_range(1000, 2000);
285 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
286 vsi->current_netdev_flags = vsi->netdev->flags;
288 INIT_LIST_HEAD(&vsi->tmp_sync_list);
289 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
291 if (ice_vsi_fltr_changed(vsi)) {
292 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
293 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
294 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
296 /* grab the netdev's addr_list_lock */
297 netif_addr_lock_bh(netdev);
298 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
299 ice_add_mac_to_unsync_list);
300 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
301 ice_add_mac_to_unsync_list);
302 /* our temp lists are populated. release lock */
303 netif_addr_unlock_bh(netdev);
306 /* Remove MAC addresses in the unsync list */
307 status = ice_remove_mac(hw, &vsi->tmp_unsync_list);
308 ice_free_fltr_list(dev, &vsi->tmp_unsync_list);
310 netdev_err(netdev, "Failed to delete MAC filters\n");
311 /* if we failed because of alloc failures, just bail */
312 if (status == ICE_ERR_NO_MEMORY) {
318 /* Add MAC addresses in the sync list */
319 status = ice_add_mac(hw, &vsi->tmp_sync_list);
320 ice_free_fltr_list(dev, &vsi->tmp_sync_list);
321 /* If filter is added successfully or already exists, do not go into
322 * 'if' condition and report it as error. Instead continue processing
323 * rest of the function.
325 if (status && status != ICE_ERR_ALREADY_EXISTS) {
326 netdev_err(netdev, "Failed to add MAC filters\n");
327 /* If there is no more space for new umac filters, VSI
328 * should go into promiscuous mode. There should be some
329 * space reserved for promiscuous filters.
331 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
332 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC,
334 promisc_forced_on = true;
336 "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
343 /* check for changes in promiscuous modes */
344 if (changed_flags & IFF_ALLMULTI) {
345 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
347 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
349 promisc_m = ICE_MCAST_PROMISC_BITS;
351 err = ice_cfg_promisc(vsi, promisc_m, true);
353 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
355 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
358 } else if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
360 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
362 promisc_m = ICE_MCAST_PROMISC_BITS;
364 err = ice_cfg_promisc(vsi, promisc_m, false);
366 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
368 vsi->current_netdev_flags |= IFF_ALLMULTI;
374 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
375 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags)) {
376 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
377 if (vsi->current_netdev_flags & IFF_PROMISC) {
378 /* Apply Rx filter rule to get traffic from wire */
379 status = ice_cfg_dflt_vsi(hw, vsi->idx, true,
382 netdev_err(netdev, "Error setting default VSI %i Rx rule\n",
384 vsi->current_netdev_flags &= ~IFF_PROMISC;
389 /* Clear Rx filter to remove traffic from wire */
390 status = ice_cfg_dflt_vsi(hw, vsi->idx, false,
393 netdev_err(netdev, "Error clearing default VSI %i Rx rule\n",
395 vsi->current_netdev_flags |= IFF_PROMISC;
404 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED, vsi->flags);
407 /* if something went wrong then set the changed flag so we try again */
408 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
409 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
411 clear_bit(__ICE_CFG_BUSY, vsi->state);
416 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
417 * @pf: board private structure
419 static void ice_sync_fltr_subtask(struct ice_pf *pf)
423 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
426 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
428 ice_for_each_vsi(pf, v)
429 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
430 ice_vsi_sync_fltr(pf->vsi[v])) {
431 /* come back and try again later */
432 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
438 * ice_dis_vsi - pause a VSI
439 * @vsi: the VSI being paused
440 * @locked: is the rtnl_lock already held
442 static void ice_dis_vsi(struct ice_vsi *vsi, bool locked)
444 if (test_bit(__ICE_DOWN, vsi->state))
447 set_bit(__ICE_NEEDS_RESTART, vsi->state);
449 if (vsi->type == ICE_VSI_PF && vsi->netdev) {
450 if (netif_running(vsi->netdev)) {
454 ice_stop(vsi->netdev);
465 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
467 * @locked: is the rtnl_lock already held
470 void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
472 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
473 #endif /* CONFIG_DCB */
477 ice_for_each_vsi(pf, v)
479 ice_dis_vsi(pf->vsi[v], locked);
483 * ice_prepare_for_reset - prep for the core to reset
484 * @pf: board private structure
486 * Inform or close all dependent features in prep for reset.
489 ice_prepare_for_reset(struct ice_pf *pf)
491 struct ice_hw *hw = &pf->hw;
494 /* already prepared for reset */
495 if (test_bit(__ICE_PREPARED_FOR_RESET, pf->state))
498 /* Notify VFs of impending reset */
499 if (ice_check_sq_alive(hw, &hw->mailboxq))
500 ice_vc_notify_reset(pf);
502 /* Disable VFs until reset is completed */
503 for (i = 0; i < pf->num_alloc_vfs; i++)
504 ice_set_vf_state_qs_dis(&pf->vf[i]);
506 /* clear SW filtering DB */
507 ice_clear_hw_tbls(hw);
508 /* disable the VSIs and their queues that are not already DOWN */
509 ice_pf_dis_all_vsi(pf, false);
512 ice_sched_clear_port(hw->port_info);
514 ice_shutdown_all_ctrlq(hw);
516 set_bit(__ICE_PREPARED_FOR_RESET, pf->state);
520 * ice_do_reset - Initiate one of many types of resets
521 * @pf: board private structure
522 * @reset_type: reset type requested
523 * before this function was called.
525 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
527 struct device *dev = &pf->pdev->dev;
528 struct ice_hw *hw = &pf->hw;
530 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
531 WARN_ON(in_interrupt());
533 ice_prepare_for_reset(pf);
535 /* trigger the reset */
536 if (ice_reset(hw, reset_type)) {
537 dev_err(dev, "reset %d failed\n", reset_type);
538 set_bit(__ICE_RESET_FAILED, pf->state);
539 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
540 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
541 clear_bit(__ICE_PFR_REQ, pf->state);
542 clear_bit(__ICE_CORER_REQ, pf->state);
543 clear_bit(__ICE_GLOBR_REQ, pf->state);
547 /* PFR is a bit of a special case because it doesn't result in an OICR
548 * interrupt. So for PFR, rebuild after the reset and clear the reset-
549 * associated state bits.
551 if (reset_type == ICE_RESET_PFR) {
553 ice_rebuild(pf, reset_type);
554 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
555 clear_bit(__ICE_PFR_REQ, pf->state);
556 ice_reset_all_vfs(pf, true);
561 * ice_reset_subtask - Set up for resetting the device and driver
562 * @pf: board private structure
564 static void ice_reset_subtask(struct ice_pf *pf)
566 enum ice_reset_req reset_type = ICE_RESET_INVAL;
568 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
569 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
570 * of reset is pending and sets bits in pf->state indicating the reset
571 * type and __ICE_RESET_OICR_RECV. So, if the latter bit is set
572 * prepare for pending reset if not already (for PF software-initiated
573 * global resets the software should already be prepared for it as
574 * indicated by __ICE_PREPARED_FOR_RESET; for global resets initiated
575 * by firmware or software on other PFs, that bit is not set so prepare
576 * for the reset now), poll for reset done, rebuild and return.
578 if (test_bit(__ICE_RESET_OICR_RECV, pf->state)) {
579 /* Perform the largest reset requested */
580 if (test_and_clear_bit(__ICE_CORER_RECV, pf->state))
581 reset_type = ICE_RESET_CORER;
582 if (test_and_clear_bit(__ICE_GLOBR_RECV, pf->state))
583 reset_type = ICE_RESET_GLOBR;
584 if (test_and_clear_bit(__ICE_EMPR_RECV, pf->state))
585 reset_type = ICE_RESET_EMPR;
586 /* return if no valid reset type requested */
587 if (reset_type == ICE_RESET_INVAL)
589 ice_prepare_for_reset(pf);
591 /* make sure we are ready to rebuild */
592 if (ice_check_reset(&pf->hw)) {
593 set_bit(__ICE_RESET_FAILED, pf->state);
595 /* done with reset. start rebuild */
596 pf->hw.reset_ongoing = false;
597 ice_rebuild(pf, reset_type);
598 /* clear bit to resume normal operations, but
599 * ICE_NEEDS_RESTART bit is set in case rebuild failed
601 clear_bit(__ICE_RESET_OICR_RECV, pf->state);
602 clear_bit(__ICE_PREPARED_FOR_RESET, pf->state);
603 clear_bit(__ICE_PFR_REQ, pf->state);
604 clear_bit(__ICE_CORER_REQ, pf->state);
605 clear_bit(__ICE_GLOBR_REQ, pf->state);
606 ice_reset_all_vfs(pf, true);
612 /* No pending resets to finish processing. Check for new resets */
613 if (test_bit(__ICE_PFR_REQ, pf->state))
614 reset_type = ICE_RESET_PFR;
615 if (test_bit(__ICE_CORER_REQ, pf->state))
616 reset_type = ICE_RESET_CORER;
617 if (test_bit(__ICE_GLOBR_REQ, pf->state))
618 reset_type = ICE_RESET_GLOBR;
619 /* If no valid reset type requested just return */
620 if (reset_type == ICE_RESET_INVAL)
623 /* reset if not already down or busy */
624 if (!test_bit(__ICE_DOWN, pf->state) &&
625 !test_bit(__ICE_CFG_BUSY, pf->state)) {
626 ice_do_reset(pf, reset_type);
631 * ice_print_topo_conflict - print topology conflict message
632 * @vsi: the VSI whose topology status is being checked
634 static void ice_print_topo_conflict(struct ice_vsi *vsi)
636 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
637 case ICE_AQ_LINK_TOPO_CONFLICT:
638 case ICE_AQ_LINK_MEDIA_CONFLICT:
639 netdev_info(vsi->netdev, "Possible mis-configuration of the Ethernet port detected, please use the Intel(R) Ethernet Port Configuration Tool application to address the issue.\n");
647 * ice_print_link_msg - print link up or down message
648 * @vsi: the VSI whose link status is being queried
649 * @isup: boolean for if the link is now up or down
651 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
653 struct ice_aqc_get_phy_caps_data *caps;
654 enum ice_status status;
664 if (vsi->current_isup == isup)
667 vsi->current_isup = isup;
670 netdev_info(vsi->netdev, "NIC Link is Down\n");
674 switch (vsi->port_info->phy.link_info.link_speed) {
675 case ICE_AQ_LINK_SPEED_100GB:
678 case ICE_AQ_LINK_SPEED_50GB:
681 case ICE_AQ_LINK_SPEED_40GB:
684 case ICE_AQ_LINK_SPEED_25GB:
687 case ICE_AQ_LINK_SPEED_20GB:
690 case ICE_AQ_LINK_SPEED_10GB:
693 case ICE_AQ_LINK_SPEED_5GB:
696 case ICE_AQ_LINK_SPEED_2500MB:
699 case ICE_AQ_LINK_SPEED_1000MB:
702 case ICE_AQ_LINK_SPEED_100MB:
710 switch (vsi->port_info->fc.current_mode) {
714 case ICE_FC_TX_PAUSE:
717 case ICE_FC_RX_PAUSE:
728 /* Get FEC mode based on negotiated link info */
729 switch (vsi->port_info->phy.link_info.fec_info) {
730 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
732 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
735 case ICE_AQ_LINK_25G_KR_FEC_EN:
736 fec = "FC-FEC/BASE-R";
743 /* check if autoneg completed, might be false due to not supported */
744 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
749 /* Get FEC mode requested based on PHY caps last SW configuration */
750 caps = devm_kzalloc(&vsi->back->pdev->dev, sizeof(*caps), GFP_KERNEL);
756 status = ice_aq_get_phy_caps(vsi->port_info, false,
757 ICE_AQC_REPORT_SW_CFG, caps, NULL);
759 netdev_info(vsi->netdev, "Get phy capability failed.\n");
761 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
762 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
764 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
765 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
766 fec_req = "FC-FEC/BASE-R";
770 devm_kfree(&vsi->back->pdev->dev, caps);
773 netdev_info(vsi->netdev, "NIC Link is up %sbps, Requested FEC: %s, FEC: %s, Autoneg: %s, Flow Control: %s\n",
774 speed, fec_req, fec, an, fc);
775 ice_print_topo_conflict(vsi);
779 * ice_vsi_link_event - update the VSI's netdev
780 * @vsi: the VSI on which the link event occurred
781 * @link_up: whether or not the VSI needs to be set up or down
783 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
788 if (test_bit(__ICE_DOWN, vsi->state) || !vsi->netdev)
791 if (vsi->type == ICE_VSI_PF) {
792 if (link_up == netif_carrier_ok(vsi->netdev))
796 netif_carrier_on(vsi->netdev);
797 netif_tx_wake_all_queues(vsi->netdev);
799 netif_carrier_off(vsi->netdev);
800 netif_tx_stop_all_queues(vsi->netdev);
806 * ice_link_event - process the link event
807 * @pf: PF that the link event is associated with
808 * @pi: port_info for the port that the link event is associated with
809 * @link_up: true if the physical link is up and false if it is down
810 * @link_speed: current link speed received from the link event
812 * Returns 0 on success and negative on failure
815 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
818 struct ice_phy_info *phy_info;
825 phy_info->link_info_old = phy_info->link_info;
827 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
828 old_link_speed = phy_info->link_info_old.link_speed;
830 /* update the link info structures and re-enable link events,
831 * don't bail on failure due to other book keeping needed
833 result = ice_update_link_info(pi);
835 dev_dbg(&pf->pdev->dev,
836 "Failed to update link status and re-enable link events for port %d\n",
839 /* if the old link up/down and speed is the same as the new */
840 if (link_up == old_link && link_speed == old_link_speed)
843 vsi = ice_get_main_vsi(pf);
844 if (!vsi || !vsi->port_info)
847 /* turn off PHY if media was removed */
848 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
849 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
850 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
852 result = ice_aq_set_link_restart_an(pi, false, NULL);
854 dev_dbg(&pf->pdev->dev,
855 "Failed to set link down, VSI %d error %d\n",
856 vsi->vsi_num, result);
861 ice_vsi_link_event(vsi, link_up);
862 ice_print_link_msg(vsi, link_up);
864 if (pf->num_alloc_vfs)
865 ice_vc_notify_link_state(pf);
871 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
872 * @pf: board private structure
874 static void ice_watchdog_subtask(struct ice_pf *pf)
878 /* if interface is down do nothing */
879 if (test_bit(__ICE_DOWN, pf->state) ||
880 test_bit(__ICE_CFG_BUSY, pf->state))
883 /* make sure we don't do these things too often */
884 if (time_before(jiffies,
885 pf->serv_tmr_prev + pf->serv_tmr_period))
888 pf->serv_tmr_prev = jiffies;
890 /* Update the stats for active netdevs so the network stack
891 * can look at updated numbers whenever it cares to
893 ice_update_pf_stats(pf);
894 ice_for_each_vsi(pf, i)
895 if (pf->vsi[i] && pf->vsi[i]->netdev)
896 ice_update_vsi_stats(pf->vsi[i]);
900 * ice_init_link_events - enable/initialize link events
901 * @pi: pointer to the port_info instance
903 * Returns -EIO on failure, 0 on success
905 static int ice_init_link_events(struct ice_port_info *pi)
909 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
910 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
912 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
913 dev_dbg(ice_hw_to_dev(pi->hw),
914 "Failed to set link event mask for port %d\n",
919 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
920 dev_dbg(ice_hw_to_dev(pi->hw),
921 "Failed to enable link events for port %d\n",
930 * ice_handle_link_event - handle link event via ARQ
931 * @pf: PF that the link event is associated with
932 * @event: event structure containing link status info
935 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
937 struct ice_aqc_get_link_status_data *link_data;
938 struct ice_port_info *port_info;
941 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
942 port_info = pf->hw.port_info;
946 status = ice_link_event(pf, port_info,
947 !!(link_data->link_info & ICE_AQ_LINK_UP),
948 le16_to_cpu(link_data->link_speed));
950 dev_dbg(&pf->pdev->dev,
951 "Could not process link event, error %d\n", status);
957 * __ice_clean_ctrlq - helper function to clean controlq rings
958 * @pf: ptr to struct ice_pf
959 * @q_type: specific Control queue type
961 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
963 struct ice_rq_event_info event;
964 struct ice_hw *hw = &pf->hw;
965 struct ice_ctl_q_info *cq;
970 /* Do not clean control queue if/when PF reset fails */
971 if (test_bit(__ICE_RESET_FAILED, pf->state))
975 case ICE_CTL_Q_ADMIN:
979 case ICE_CTL_Q_MAILBOX:
984 dev_warn(&pf->pdev->dev, "Unknown control queue type 0x%x\n",
989 /* check for error indications - PF_xx_AxQLEN register layout for
990 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
992 val = rd32(hw, cq->rq.len);
993 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
994 PF_FW_ARQLEN_ARQCRIT_M)) {
996 if (val & PF_FW_ARQLEN_ARQVFE_M)
997 dev_dbg(&pf->pdev->dev,
998 "%s Receive Queue VF Error detected\n", qtype);
999 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1000 dev_dbg(&pf->pdev->dev,
1001 "%s Receive Queue Overflow Error detected\n",
1004 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1005 dev_dbg(&pf->pdev->dev,
1006 "%s Receive Queue Critical Error detected\n",
1008 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1009 PF_FW_ARQLEN_ARQCRIT_M);
1011 wr32(hw, cq->rq.len, val);
1014 val = rd32(hw, cq->sq.len);
1015 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1016 PF_FW_ATQLEN_ATQCRIT_M)) {
1018 if (val & PF_FW_ATQLEN_ATQVFE_M)
1019 dev_dbg(&pf->pdev->dev,
1020 "%s Send Queue VF Error detected\n", qtype);
1021 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1022 dev_dbg(&pf->pdev->dev,
1023 "%s Send Queue Overflow Error detected\n",
1026 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1027 dev_dbg(&pf->pdev->dev,
1028 "%s Send Queue Critical Error detected\n",
1030 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1031 PF_FW_ATQLEN_ATQCRIT_M);
1033 wr32(hw, cq->sq.len, val);
1036 event.buf_len = cq->rq_buf_size;
1037 event.msg_buf = devm_kzalloc(&pf->pdev->dev, event.buf_len,
1043 enum ice_status ret;
1046 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1047 if (ret == ICE_ERR_AQ_NO_WORK)
1050 dev_err(&pf->pdev->dev,
1051 "%s Receive Queue event error %d\n", qtype,
1056 opcode = le16_to_cpu(event.desc.opcode);
1059 case ice_aqc_opc_get_link_status:
1060 if (ice_handle_link_event(pf, &event))
1061 dev_err(&pf->pdev->dev,
1062 "Could not handle link event\n");
1064 case ice_mbx_opc_send_msg_to_pf:
1065 ice_vc_process_vf_msg(pf, &event);
1067 case ice_aqc_opc_fw_logging:
1068 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1070 case ice_aqc_opc_lldp_set_mib_change:
1071 ice_dcb_process_lldp_set_mib_change(pf, &event);
1074 dev_dbg(&pf->pdev->dev,
1075 "%s Receive Queue unknown event 0x%04x ignored\n",
1079 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1081 devm_kfree(&pf->pdev->dev, event.msg_buf);
1083 return pending && (i == ICE_DFLT_IRQ_WORK);
1087 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1088 * @hw: pointer to hardware info
1089 * @cq: control queue information
1091 * returns true if there are pending messages in a queue, false if there aren't
1093 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1097 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1098 return cq->rq.next_to_clean != ntu;
1102 * ice_clean_adminq_subtask - clean the AdminQ rings
1103 * @pf: board private structure
1105 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1107 struct ice_hw *hw = &pf->hw;
1109 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1112 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1115 clear_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1117 /* There might be a situation where new messages arrive to a control
1118 * queue between processing the last message and clearing the
1119 * EVENT_PENDING bit. So before exiting, check queue head again (using
1120 * ice_ctrlq_pending) and process new messages if any.
1122 if (ice_ctrlq_pending(hw, &hw->adminq))
1123 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1129 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1130 * @pf: board private structure
1132 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1134 struct ice_hw *hw = &pf->hw;
1136 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1139 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1142 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1144 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1145 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1151 * ice_service_task_schedule - schedule the service task to wake up
1152 * @pf: board private structure
1154 * If not already scheduled, this puts the task into the work queue.
1156 static void ice_service_task_schedule(struct ice_pf *pf)
1158 if (!test_bit(__ICE_SERVICE_DIS, pf->state) &&
1159 !test_and_set_bit(__ICE_SERVICE_SCHED, pf->state) &&
1160 !test_bit(__ICE_NEEDS_RESTART, pf->state))
1161 queue_work(ice_wq, &pf->serv_task);
1165 * ice_service_task_complete - finish up the service task
1166 * @pf: board private structure
1168 static void ice_service_task_complete(struct ice_pf *pf)
1170 WARN_ON(!test_bit(__ICE_SERVICE_SCHED, pf->state));
1172 /* force memory (pf->state) to sync before next service task */
1173 smp_mb__before_atomic();
1174 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1178 * ice_service_task_stop - stop service task and cancel works
1179 * @pf: board private structure
1181 static void ice_service_task_stop(struct ice_pf *pf)
1183 set_bit(__ICE_SERVICE_DIS, pf->state);
1185 if (pf->serv_tmr.function)
1186 del_timer_sync(&pf->serv_tmr);
1187 if (pf->serv_task.func)
1188 cancel_work_sync(&pf->serv_task);
1190 clear_bit(__ICE_SERVICE_SCHED, pf->state);
1194 * ice_service_task_restart - restart service task and schedule works
1195 * @pf: board private structure
1197 * This function is needed for suspend and resume works (e.g WoL scenario)
1199 static void ice_service_task_restart(struct ice_pf *pf)
1201 clear_bit(__ICE_SERVICE_DIS, pf->state);
1202 ice_service_task_schedule(pf);
1206 * ice_service_timer - timer callback to schedule service task
1207 * @t: pointer to timer_list
1209 static void ice_service_timer(struct timer_list *t)
1211 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1213 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1214 ice_service_task_schedule(pf);
1218 * ice_handle_mdd_event - handle malicious driver detect event
1219 * @pf: pointer to the PF structure
1221 * Called from service task. OICR interrupt handler indicates MDD event
1223 static void ice_handle_mdd_event(struct ice_pf *pf)
1225 struct ice_hw *hw = &pf->hw;
1226 bool mdd_detected = false;
1230 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING, pf->state))
1233 /* find what triggered the MDD event */
1234 reg = rd32(hw, GL_MDET_TX_PQM);
1235 if (reg & GL_MDET_TX_PQM_VALID_M) {
1236 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1237 GL_MDET_TX_PQM_PF_NUM_S;
1238 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1239 GL_MDET_TX_PQM_VF_NUM_S;
1240 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1241 GL_MDET_TX_PQM_MAL_TYPE_S;
1242 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1243 GL_MDET_TX_PQM_QNUM_S);
1245 if (netif_msg_tx_err(pf))
1246 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1247 event, queue, pf_num, vf_num);
1248 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1249 mdd_detected = true;
1252 reg = rd32(hw, GL_MDET_TX_TCLAN);
1253 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1254 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1255 GL_MDET_TX_TCLAN_PF_NUM_S;
1256 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1257 GL_MDET_TX_TCLAN_VF_NUM_S;
1258 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1259 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1260 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1261 GL_MDET_TX_TCLAN_QNUM_S);
1263 if (netif_msg_rx_err(pf))
1264 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1265 event, queue, pf_num, vf_num);
1266 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1267 mdd_detected = true;
1270 reg = rd32(hw, GL_MDET_RX);
1271 if (reg & GL_MDET_RX_VALID_M) {
1272 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1273 GL_MDET_RX_PF_NUM_S;
1274 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1275 GL_MDET_RX_VF_NUM_S;
1276 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1277 GL_MDET_RX_MAL_TYPE_S;
1278 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1281 if (netif_msg_rx_err(pf))
1282 dev_info(&pf->pdev->dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1283 event, queue, pf_num, vf_num);
1284 wr32(hw, GL_MDET_RX, 0xffffffff);
1285 mdd_detected = true;
1289 bool pf_mdd_detected = false;
1291 reg = rd32(hw, PF_MDET_TX_PQM);
1292 if (reg & PF_MDET_TX_PQM_VALID_M) {
1293 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1294 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1295 pf_mdd_detected = true;
1298 reg = rd32(hw, PF_MDET_TX_TCLAN);
1299 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1300 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1301 dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
1302 pf_mdd_detected = true;
1305 reg = rd32(hw, PF_MDET_RX);
1306 if (reg & PF_MDET_RX_VALID_M) {
1307 wr32(hw, PF_MDET_RX, 0xFFFF);
1308 dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
1309 pf_mdd_detected = true;
1311 /* Queue belongs to the PF initiate a reset */
1312 if (pf_mdd_detected) {
1313 set_bit(__ICE_NEEDS_RESTART, pf->state);
1314 ice_service_task_schedule(pf);
1318 /* check to see if one of the VFs caused the MDD */
1319 for (i = 0; i < pf->num_alloc_vfs; i++) {
1320 struct ice_vf *vf = &pf->vf[i];
1322 bool vf_mdd_detected = false;
1324 reg = rd32(hw, VP_MDET_TX_PQM(i));
1325 if (reg & VP_MDET_TX_PQM_VALID_M) {
1326 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1327 vf_mdd_detected = true;
1328 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1332 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1333 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1334 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1335 vf_mdd_detected = true;
1336 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1340 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1341 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1342 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1343 vf_mdd_detected = true;
1344 dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
1348 reg = rd32(hw, VP_MDET_RX(i));
1349 if (reg & VP_MDET_RX_VALID_M) {
1350 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1351 vf_mdd_detected = true;
1352 dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
1356 if (vf_mdd_detected) {
1357 vf->num_mdd_events++;
1358 if (vf->num_mdd_events &&
1359 vf->num_mdd_events <= ICE_MDD_EVENTS_THRESHOLD)
1360 dev_info(&pf->pdev->dev,
1361 "VF %d has had %llu MDD events since last boot, Admin might need to reload AVF driver with this number of events\n",
1362 i, vf->num_mdd_events);
1368 * ice_force_phys_link_state - Force the physical link state
1369 * @vsi: VSI to force the physical link state to up/down
1370 * @link_up: true/false indicates to set the physical link to up/down
1372 * Force the physical link state by getting the current PHY capabilities from
1373 * hardware and setting the PHY config based on the determined capabilities. If
1374 * link changes a link event will be triggered because both the Enable Automatic
1375 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1377 * Returns 0 on success, negative on failure
1379 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1381 struct ice_aqc_get_phy_caps_data *pcaps;
1382 struct ice_aqc_set_phy_cfg_data *cfg;
1383 struct ice_port_info *pi;
1387 if (!vsi || !vsi->port_info || !vsi->back)
1389 if (vsi->type != ICE_VSI_PF)
1392 dev = &vsi->back->pdev->dev;
1394 pi = vsi->port_info;
1396 pcaps = devm_kzalloc(dev, sizeof(*pcaps), GFP_KERNEL);
1400 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1404 "Failed to get phy capabilities, VSI %d error %d\n",
1405 vsi->vsi_num, retcode);
1410 /* No change in link */
1411 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1412 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1415 cfg = devm_kzalloc(dev, sizeof(*cfg), GFP_KERNEL);
1421 cfg->phy_type_low = pcaps->phy_type_low;
1422 cfg->phy_type_high = pcaps->phy_type_high;
1423 cfg->caps = pcaps->caps | ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1424 cfg->low_power_ctrl = pcaps->low_power_ctrl;
1425 cfg->eee_cap = pcaps->eee_cap;
1426 cfg->eeer_value = pcaps->eeer_value;
1427 cfg->link_fec_opt = pcaps->link_fec_options;
1429 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1431 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1433 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi->lport, cfg, NULL);
1435 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1436 vsi->vsi_num, retcode);
1440 devm_kfree(dev, cfg);
1442 devm_kfree(dev, pcaps);
1447 * ice_check_media_subtask - Check for media; bring link up if detected.
1448 * @pf: pointer to PF struct
1450 static void ice_check_media_subtask(struct ice_pf *pf)
1452 struct ice_port_info *pi;
1453 struct ice_vsi *vsi;
1456 vsi = ice_get_main_vsi(pf);
1460 /* No need to check for media if it's already present or the interface
1463 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) ||
1464 test_bit(__ICE_DOWN, vsi->state))
1467 /* Refresh link info and check if media is present */
1468 pi = vsi->port_info;
1469 err = ice_update_link_info(pi);
1473 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1474 err = ice_force_phys_link_state(vsi, true);
1477 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1479 /* A Link Status Event will be generated; the event handler
1480 * will complete bringing the interface up
1486 * ice_service_task - manage and run subtasks
1487 * @work: pointer to work_struct contained by the PF struct
1489 static void ice_service_task(struct work_struct *work)
1491 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
1492 unsigned long start_time = jiffies;
1496 /* process reset requests first */
1497 ice_reset_subtask(pf);
1499 /* bail if a reset/recovery cycle is pending or rebuild failed */
1500 if (ice_is_reset_in_progress(pf->state) ||
1501 test_bit(__ICE_SUSPENDED, pf->state) ||
1502 test_bit(__ICE_NEEDS_RESTART, pf->state)) {
1503 ice_service_task_complete(pf);
1507 ice_clean_adminq_subtask(pf);
1508 ice_check_media_subtask(pf);
1509 ice_check_for_hang_subtask(pf);
1510 ice_sync_fltr_subtask(pf);
1511 ice_handle_mdd_event(pf);
1512 ice_watchdog_subtask(pf);
1514 if (ice_is_safe_mode(pf)) {
1515 ice_service_task_complete(pf);
1519 ice_process_vflr_event(pf);
1520 ice_clean_mailboxq_subtask(pf);
1522 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1523 ice_service_task_complete(pf);
1525 /* If the tasks have taken longer than one service timer period
1526 * or there is more work to be done, reset the service timer to
1527 * schedule the service task now.
1529 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
1530 test_bit(__ICE_MDD_EVENT_PENDING, pf->state) ||
1531 test_bit(__ICE_VFLR_EVENT_PENDING, pf->state) ||
1532 test_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
1533 test_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state))
1534 mod_timer(&pf->serv_tmr, jiffies);
1538 * ice_set_ctrlq_len - helper function to set controlq length
1539 * @hw: pointer to the HW instance
1541 static void ice_set_ctrlq_len(struct ice_hw *hw)
1543 hw->adminq.num_rq_entries = ICE_AQ_LEN;
1544 hw->adminq.num_sq_entries = ICE_AQ_LEN;
1545 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
1546 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
1547 hw->mailboxq.num_rq_entries = ICE_MBXRQ_LEN;
1548 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
1549 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1550 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
1554 * ice_irq_affinity_notify - Callback for affinity changes
1555 * @notify: context as to what irq was changed
1556 * @mask: the new affinity mask
1558 * This is a callback function used by the irq_set_affinity_notifier function
1559 * so that we may register to receive changes to the irq affinity masks.
1562 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
1563 const cpumask_t *mask)
1565 struct ice_q_vector *q_vector =
1566 container_of(notify, struct ice_q_vector, affinity_notify);
1568 cpumask_copy(&q_vector->affinity_mask, mask);
1572 * ice_irq_affinity_release - Callback for affinity notifier release
1573 * @ref: internal core kernel usage
1575 * This is a callback function used by the irq_set_affinity_notifier function
1576 * to inform the current notification subscriber that they will no longer
1577 * receive notifications.
1579 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
1582 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1583 * @vsi: the VSI being configured
1585 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
1587 struct ice_hw *hw = &vsi->back->hw;
1590 ice_for_each_q_vector(vsi, i)
1591 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
1598 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1599 * @vsi: the VSI being configured
1600 * @basename: name for the vector
1602 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
1604 int q_vectors = vsi->num_q_vectors;
1605 struct ice_pf *pf = vsi->back;
1606 int base = vsi->base_vector;
1612 for (vector = 0; vector < q_vectors; vector++) {
1613 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
1615 irq_num = pf->msix_entries[base + vector].vector;
1617 if (q_vector->tx.ring && q_vector->rx.ring) {
1618 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1619 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
1621 } else if (q_vector->rx.ring) {
1622 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1623 "%s-%s-%d", basename, "rx", rx_int_idx++);
1624 } else if (q_vector->tx.ring) {
1625 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
1626 "%s-%s-%d", basename, "tx", tx_int_idx++);
1628 /* skip this unused q_vector */
1631 err = devm_request_irq(&pf->pdev->dev, irq_num,
1632 vsi->irq_handler, 0,
1633 q_vector->name, q_vector);
1635 netdev_err(vsi->netdev,
1636 "MSIX request_irq failed, error: %d\n", err);
1640 /* register for affinity change notifications */
1641 q_vector->affinity_notify.notify = ice_irq_affinity_notify;
1642 q_vector->affinity_notify.release = ice_irq_affinity_release;
1643 irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
1645 /* assign the mask for this irq */
1646 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
1649 vsi->irqs_ready = true;
1655 irq_num = pf->msix_entries[base + vector].vector,
1656 irq_set_affinity_notifier(irq_num, NULL);
1657 irq_set_affinity_hint(irq_num, NULL);
1658 devm_free_irq(&pf->pdev->dev, irq_num, &vsi->q_vectors[vector]);
1664 * ice_ena_misc_vector - enable the non-queue interrupts
1665 * @pf: board private structure
1667 static void ice_ena_misc_vector(struct ice_pf *pf)
1669 struct ice_hw *hw = &pf->hw;
1672 /* clear things first */
1673 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
1674 rd32(hw, PFINT_OICR); /* read to clear */
1676 val = (PFINT_OICR_ECC_ERR_M |
1677 PFINT_OICR_MAL_DETECT_M |
1679 PFINT_OICR_PCI_EXCEPTION_M |
1681 PFINT_OICR_HMC_ERR_M |
1682 PFINT_OICR_PE_CRITERR_M);
1684 wr32(hw, PFINT_OICR_ENA, val);
1686 /* SW_ITR_IDX = 0, but don't change INTENA */
1687 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
1688 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
1692 * ice_misc_intr - misc interrupt handler
1693 * @irq: interrupt number
1694 * @data: pointer to a q_vector
1696 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
1698 struct ice_pf *pf = (struct ice_pf *)data;
1699 struct ice_hw *hw = &pf->hw;
1700 irqreturn_t ret = IRQ_NONE;
1703 set_bit(__ICE_ADMINQ_EVENT_PENDING, pf->state);
1704 set_bit(__ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1706 oicr = rd32(hw, PFINT_OICR);
1707 ena_mask = rd32(hw, PFINT_OICR_ENA);
1709 if (oicr & PFINT_OICR_SWINT_M) {
1710 ena_mask &= ~PFINT_OICR_SWINT_M;
1714 if (oicr & PFINT_OICR_MAL_DETECT_M) {
1715 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
1716 set_bit(__ICE_MDD_EVENT_PENDING, pf->state);
1718 if (oicr & PFINT_OICR_VFLR_M) {
1719 ena_mask &= ~PFINT_OICR_VFLR_M;
1720 set_bit(__ICE_VFLR_EVENT_PENDING, pf->state);
1723 if (oicr & PFINT_OICR_GRST_M) {
1726 /* we have a reset warning */
1727 ena_mask &= ~PFINT_OICR_GRST_M;
1728 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
1729 GLGEN_RSTAT_RESET_TYPE_S;
1731 if (reset == ICE_RESET_CORER)
1733 else if (reset == ICE_RESET_GLOBR)
1735 else if (reset == ICE_RESET_EMPR)
1738 dev_dbg(&pf->pdev->dev, "Invalid reset type %d\n",
1741 /* If a reset cycle isn't already in progress, we set a bit in
1742 * pf->state so that the service task can start a reset/rebuild.
1743 * We also make note of which reset happened so that peer
1744 * devices/drivers can be informed.
1746 if (!test_and_set_bit(__ICE_RESET_OICR_RECV, pf->state)) {
1747 if (reset == ICE_RESET_CORER)
1748 set_bit(__ICE_CORER_RECV, pf->state);
1749 else if (reset == ICE_RESET_GLOBR)
1750 set_bit(__ICE_GLOBR_RECV, pf->state);
1752 set_bit(__ICE_EMPR_RECV, pf->state);
1754 /* There are couple of different bits at play here.
1755 * hw->reset_ongoing indicates whether the hardware is
1756 * in reset. This is set to true when a reset interrupt
1757 * is received and set back to false after the driver
1758 * has determined that the hardware is out of reset.
1760 * __ICE_RESET_OICR_RECV in pf->state indicates
1761 * that a post reset rebuild is required before the
1762 * driver is operational again. This is set above.
1764 * As this is the start of the reset/rebuild cycle, set
1765 * both to indicate that.
1767 hw->reset_ongoing = true;
1771 if (oicr & PFINT_OICR_HMC_ERR_M) {
1772 ena_mask &= ~PFINT_OICR_HMC_ERR_M;
1773 dev_dbg(&pf->pdev->dev,
1774 "HMC Error interrupt - info 0x%x, data 0x%x\n",
1775 rd32(hw, PFHMC_ERRORINFO),
1776 rd32(hw, PFHMC_ERRORDATA));
1779 /* Report any remaining unexpected interrupts */
1782 dev_dbg(&pf->pdev->dev, "unhandled interrupt oicr=0x%08x\n",
1784 /* If a critical error is pending there is no choice but to
1787 if (oicr & (PFINT_OICR_PE_CRITERR_M |
1788 PFINT_OICR_PCI_EXCEPTION_M |
1789 PFINT_OICR_ECC_ERR_M)) {
1790 set_bit(__ICE_PFR_REQ, pf->state);
1791 ice_service_task_schedule(pf);
1796 if (!test_bit(__ICE_DOWN, pf->state)) {
1797 ice_service_task_schedule(pf);
1798 ice_irq_dynamic_ena(hw, NULL, NULL);
1805 * ice_dis_ctrlq_interrupts - disable control queue interrupts
1806 * @hw: pointer to HW structure
1808 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
1810 /* disable Admin queue Interrupt causes */
1811 wr32(hw, PFINT_FW_CTL,
1812 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
1814 /* disable Mailbox queue Interrupt causes */
1815 wr32(hw, PFINT_MBX_CTL,
1816 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
1818 /* disable Control queue Interrupt causes */
1819 wr32(hw, PFINT_OICR_CTL,
1820 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
1826 * ice_free_irq_msix_misc - Unroll misc vector setup
1827 * @pf: board private structure
1829 static void ice_free_irq_msix_misc(struct ice_pf *pf)
1831 struct ice_hw *hw = &pf->hw;
1833 ice_dis_ctrlq_interrupts(hw);
1835 /* disable OICR interrupt */
1836 wr32(hw, PFINT_OICR_ENA, 0);
1839 if (pf->msix_entries) {
1840 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
1841 devm_free_irq(&pf->pdev->dev,
1842 pf->msix_entries[pf->oicr_idx].vector, pf);
1845 pf->num_avail_sw_msix += 1;
1846 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
1850 * ice_ena_ctrlq_interrupts - enable control queue interrupts
1851 * @hw: pointer to HW structure
1852 * @reg_idx: HW vector index to associate the control queue interrupts with
1854 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
1858 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
1859 PFINT_OICR_CTL_CAUSE_ENA_M);
1860 wr32(hw, PFINT_OICR_CTL, val);
1862 /* enable Admin queue Interrupt causes */
1863 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
1864 PFINT_FW_CTL_CAUSE_ENA_M);
1865 wr32(hw, PFINT_FW_CTL, val);
1867 /* enable Mailbox queue Interrupt causes */
1868 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
1869 PFINT_MBX_CTL_CAUSE_ENA_M);
1870 wr32(hw, PFINT_MBX_CTL, val);
1876 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
1877 * @pf: board private structure
1879 * This sets up the handler for MSIX 0, which is used to manage the
1880 * non-queue interrupts, e.g. AdminQ and errors. This is not used
1881 * when in MSI or Legacy interrupt mode.
1883 static int ice_req_irq_msix_misc(struct ice_pf *pf)
1885 struct ice_hw *hw = &pf->hw;
1886 int oicr_idx, err = 0;
1888 if (!pf->int_name[0])
1889 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
1890 dev_driver_string(&pf->pdev->dev),
1891 dev_name(&pf->pdev->dev));
1893 /* Do not request IRQ but do enable OICR interrupt since settings are
1894 * lost during reset. Note that this function is called only during
1895 * rebuild path and not while reset is in progress.
1897 if (ice_is_reset_in_progress(pf->state))
1900 /* reserve one vector in irq_tracker for misc interrupts */
1901 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1905 pf->num_avail_sw_msix -= 1;
1906 pf->oicr_idx = oicr_idx;
1908 err = devm_request_irq(&pf->pdev->dev,
1909 pf->msix_entries[pf->oicr_idx].vector,
1910 ice_misc_intr, 0, pf->int_name, pf);
1912 dev_err(&pf->pdev->dev,
1913 "devm_request_irq for %s failed: %d\n",
1915 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
1916 pf->num_avail_sw_msix += 1;
1921 ice_ena_misc_vector(pf);
1923 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
1924 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
1925 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
1928 ice_irq_dynamic_ena(hw, NULL, NULL);
1934 * ice_napi_add - register NAPI handler for the VSI
1935 * @vsi: VSI for which NAPI handler is to be registered
1937 * This function is only called in the driver's load path. Registering the NAPI
1938 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
1939 * reset/rebuild, etc.)
1941 static void ice_napi_add(struct ice_vsi *vsi)
1948 ice_for_each_q_vector(vsi, v_idx)
1949 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
1950 ice_napi_poll, NAPI_POLL_WEIGHT);
1954 * ice_set_ops - set netdev and ethtools ops for the given netdev
1955 * @netdev: netdev instance
1957 static void ice_set_ops(struct net_device *netdev)
1959 struct ice_pf *pf = ice_netdev_to_pf(netdev);
1961 if (ice_is_safe_mode(pf)) {
1962 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
1963 ice_set_ethtool_safe_mode_ops(netdev);
1967 netdev->netdev_ops = &ice_netdev_ops;
1968 ice_set_ethtool_ops(netdev);
1972 * ice_set_netdev_features - set features for the given netdev
1973 * @netdev: netdev instance
1975 static void ice_set_netdev_features(struct net_device *netdev)
1977 struct ice_pf *pf = ice_netdev_to_pf(netdev);
1978 netdev_features_t csumo_features;
1979 netdev_features_t vlano_features;
1980 netdev_features_t dflt_features;
1981 netdev_features_t tso_features;
1983 if (ice_is_safe_mode(pf)) {
1985 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
1986 netdev->hw_features = netdev->features;
1990 dflt_features = NETIF_F_SG |
1994 csumo_features = NETIF_F_RXCSUM |
1999 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
2000 NETIF_F_HW_VLAN_CTAG_TX |
2001 NETIF_F_HW_VLAN_CTAG_RX;
2003 tso_features = NETIF_F_TSO;
2005 /* set features that user can change */
2006 netdev->hw_features = dflt_features | csumo_features |
2007 vlano_features | tso_features;
2009 /* enable features */
2010 netdev->features |= netdev->hw_features;
2011 /* encap and VLAN devices inherit default, csumo and tso features */
2012 netdev->hw_enc_features |= dflt_features | csumo_features |
2014 netdev->vlan_features |= dflt_features | csumo_features |
2019 * ice_cfg_netdev - Allocate, configure and register a netdev
2020 * @vsi: the VSI associated with the new netdev
2022 * Returns 0 on success, negative value on failure
2024 static int ice_cfg_netdev(struct ice_vsi *vsi)
2026 struct ice_pf *pf = vsi->back;
2027 struct ice_netdev_priv *np;
2028 struct net_device *netdev;
2029 u8 mac_addr[ETH_ALEN];
2032 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
2037 vsi->netdev = netdev;
2038 np = netdev_priv(netdev);
2041 ice_set_netdev_features(netdev);
2043 ice_set_ops(netdev);
2045 if (vsi->type == ICE_VSI_PF) {
2046 SET_NETDEV_DEV(netdev, &pf->pdev->dev);
2047 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
2048 ether_addr_copy(netdev->dev_addr, mac_addr);
2049 ether_addr_copy(netdev->perm_addr, mac_addr);
2052 netdev->priv_flags |= IFF_UNICAST_FLT;
2054 /* Setup netdev TC information */
2055 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
2057 /* setup watchdog timeout value to be 5 second */
2058 netdev->watchdog_timeo = 5 * HZ;
2060 netdev->min_mtu = ETH_MIN_MTU;
2061 netdev->max_mtu = ICE_MAX_MTU;
2063 err = register_netdev(vsi->netdev);
2067 netif_carrier_off(vsi->netdev);
2069 /* make sure transmit queues start off as stopped */
2070 netif_tx_stop_all_queues(vsi->netdev);
2076 * ice_fill_rss_lut - Fill the RSS lookup table with default values
2077 * @lut: Lookup table
2078 * @rss_table_size: Lookup table size
2079 * @rss_size: Range of queue number for hashing
2081 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
2085 for (i = 0; i < rss_table_size; i++)
2086 lut[i] = i % rss_size;
2090 * ice_pf_vsi_setup - Set up a PF VSI
2091 * @pf: board private structure
2092 * @pi: pointer to the port_info instance
2094 * Returns pointer to the successfully allocated VSI software struct
2095 * on success, otherwise returns NULL on failure.
2097 static struct ice_vsi *
2098 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2100 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
2104 * ice_lb_vsi_setup - Set up a loopback VSI
2105 * @pf: board private structure
2106 * @pi: pointer to the port_info instance
2108 * Returns pointer to the successfully allocated VSI software struct
2109 * on success, otherwise returns NULL on failure.
2112 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
2114 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
2118 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2119 * @netdev: network interface to be adjusted
2120 * @proto: unused protocol
2121 * @vid: VLAN ID to be added
2123 * net_device_ops implementation for adding VLAN IDs
2126 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
2129 struct ice_netdev_priv *np = netdev_priv(netdev);
2130 struct ice_vsi *vsi = np->vsi;
2133 if (vid >= VLAN_N_VID) {
2134 netdev_err(netdev, "VLAN id requested %d is out of range %d\n",
2142 /* Enable VLAN pruning when VLAN 0 is added */
2143 if (unlikely(!vid)) {
2144 ret = ice_cfg_vlan_pruning(vsi, true, false);
2149 /* Add all VLAN IDs including 0 to the switch filter. VLAN ID 0 is
2150 * needed to continue allowing all untagged packets since VLAN prune
2151 * list is applied to all packets by the switch
2153 ret = ice_vsi_add_vlan(vsi, vid);
2155 vsi->vlan_ena = true;
2156 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2163 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2164 * @netdev: network interface to be adjusted
2165 * @proto: unused protocol
2166 * @vid: VLAN ID to be removed
2168 * net_device_ops implementation for removing VLAN IDs
2171 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
2174 struct ice_netdev_priv *np = netdev_priv(netdev);
2175 struct ice_vsi *vsi = np->vsi;
2181 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2184 ret = ice_vsi_kill_vlan(vsi, vid);
2188 /* Disable VLAN pruning when VLAN 0 is removed */
2190 ret = ice_cfg_vlan_pruning(vsi, false, false);
2192 vsi->vlan_ena = false;
2193 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
2198 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2199 * @pf: board private structure
2201 * Returns 0 on success, negative value on failure
2203 static int ice_setup_pf_sw(struct ice_pf *pf)
2205 struct ice_vsi *vsi;
2208 if (ice_is_reset_in_progress(pf->state))
2211 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
2214 goto unroll_vsi_setup;
2217 status = ice_cfg_netdev(vsi);
2220 goto unroll_vsi_setup;
2223 /* registering the NAPI handler requires both the queues and
2224 * netdev to be created, which are done in ice_pf_vsi_setup()
2225 * and ice_cfg_netdev() respectively
2229 status = ice_init_mac_fltr(pf);
2231 goto unroll_napi_add;
2239 if (vsi->netdev->reg_state == NETREG_REGISTERED)
2240 unregister_netdev(vsi->netdev);
2241 free_netdev(vsi->netdev);
2248 ice_vsi_free_q_vectors(vsi);
2249 ice_vsi_delete(vsi);
2250 ice_vsi_put_qs(vsi);
2257 * ice_get_avail_q_count - Get count of queues in use
2258 * @pf_qmap: bitmap to get queue use count from
2259 * @lock: pointer to a mutex that protects access to pf_qmap
2260 * @size: size of the bitmap
2263 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
2268 for_each_clear_bit(bit, pf_qmap, size)
2276 * ice_get_avail_txq_count - Get count of Tx queues in use
2277 * @pf: pointer to an ice_pf instance
2279 u16 ice_get_avail_txq_count(struct ice_pf *pf)
2281 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
2286 * ice_get_avail_rxq_count - Get count of Rx queues in use
2287 * @pf: pointer to an ice_pf instance
2289 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
2291 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
2296 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2297 * @pf: board private structure to initialize
2299 static void ice_deinit_pf(struct ice_pf *pf)
2301 ice_service_task_stop(pf);
2302 mutex_destroy(&pf->sw_mutex);
2303 mutex_destroy(&pf->avail_q_mutex);
2305 if (pf->avail_txqs) {
2306 bitmap_free(pf->avail_txqs);
2307 pf->avail_txqs = NULL;
2310 if (pf->avail_rxqs) {
2311 bitmap_free(pf->avail_rxqs);
2312 pf->avail_rxqs = NULL;
2317 * ice_set_pf_caps - set PFs capability flags
2318 * @pf: pointer to the PF instance
2320 static void ice_set_pf_caps(struct ice_pf *pf)
2322 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
2324 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2325 if (func_caps->common_cap.dcb)
2326 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2327 #ifdef CONFIG_PCI_IOV
2328 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2329 if (func_caps->common_cap.sr_iov_1_1) {
2330 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
2331 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
2334 #endif /* CONFIG_PCI_IOV */
2335 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
2336 if (func_caps->common_cap.rss_table_size)
2337 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
2339 pf->max_pf_txqs = func_caps->common_cap.num_txq;
2340 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
2344 * ice_init_pf - Initialize general software structures (struct ice_pf)
2345 * @pf: board private structure to initialize
2347 static int ice_init_pf(struct ice_pf *pf)
2349 ice_set_pf_caps(pf);
2351 mutex_init(&pf->sw_mutex);
2353 /* setup service timer and periodic service task */
2354 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
2355 pf->serv_tmr_period = HZ;
2356 INIT_WORK(&pf->serv_task, ice_service_task);
2357 clear_bit(__ICE_SERVICE_SCHED, pf->state);
2359 mutex_init(&pf->avail_q_mutex);
2360 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
2361 if (!pf->avail_txqs)
2364 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
2365 if (!pf->avail_rxqs) {
2366 devm_kfree(&pf->pdev->dev, pf->avail_txqs);
2367 pf->avail_txqs = NULL;
2375 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2376 * @pf: board private structure
2378 * compute the number of MSIX vectors required (v_budget) and request from
2379 * the OS. Return the number of vectors reserved or negative on failure
2381 static int ice_ena_msix_range(struct ice_pf *pf)
2383 int v_left, v_actual, v_budget = 0;
2386 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
2388 /* reserve one vector for miscellaneous handler */
2390 if (v_left < needed)
2391 goto no_hw_vecs_left_err;
2395 /* reserve vectors for LAN traffic */
2396 needed = min_t(int, num_online_cpus(), v_left);
2397 if (v_left < needed)
2398 goto no_hw_vecs_left_err;
2399 pf->num_lan_msix = needed;
2403 pf->msix_entries = devm_kcalloc(&pf->pdev->dev, v_budget,
2404 sizeof(*pf->msix_entries), GFP_KERNEL);
2406 if (!pf->msix_entries) {
2411 for (i = 0; i < v_budget; i++)
2412 pf->msix_entries[i].entry = i;
2414 /* actually reserve the vectors */
2415 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
2416 ICE_MIN_MSIX, v_budget);
2419 dev_err(&pf->pdev->dev, "unable to reserve MSI-X vectors\n");
2424 if (v_actual < v_budget) {
2425 dev_warn(&pf->pdev->dev,
2426 "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
2427 v_budget, v_actual);
2428 /* 2 vectors for LAN (traffic + OICR) */
2429 #define ICE_MIN_LAN_VECS 2
2431 if (v_actual < ICE_MIN_LAN_VECS) {
2432 /* error if we can't get minimum vectors */
2433 pci_disable_msix(pf->pdev);
2437 pf->num_lan_msix = ICE_MIN_LAN_VECS;
2444 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2447 no_hw_vecs_left_err:
2448 dev_err(&pf->pdev->dev,
2449 "not enough device MSI-X vectors. requested = %d, available = %d\n",
2453 pf->num_lan_msix = 0;
2458 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2459 * @pf: board private structure
2461 static void ice_dis_msix(struct ice_pf *pf)
2463 pci_disable_msix(pf->pdev);
2464 devm_kfree(&pf->pdev->dev, pf->msix_entries);
2465 pf->msix_entries = NULL;
2469 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2470 * @pf: board private structure
2472 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
2476 if (pf->irq_tracker) {
2477 devm_kfree(&pf->pdev->dev, pf->irq_tracker);
2478 pf->irq_tracker = NULL;
2483 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2484 * @pf: board private structure to initialize
2486 static int ice_init_interrupt_scheme(struct ice_pf *pf)
2490 vectors = ice_ena_msix_range(pf);
2495 /* set up vector assignment tracking */
2497 devm_kzalloc(&pf->pdev->dev, sizeof(*pf->irq_tracker) +
2498 (sizeof(u16) * vectors), GFP_KERNEL);
2499 if (!pf->irq_tracker) {
2504 /* populate SW interrupts pool with number of OS granted IRQs. */
2505 pf->num_avail_sw_msix = vectors;
2506 pf->irq_tracker->num_entries = vectors;
2507 pf->irq_tracker->end = pf->irq_tracker->num_entries;
2513 * ice_log_pkg_init - log result of DDP package load
2514 * @hw: pointer to hardware info
2515 * @status: status of package load
2518 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status)
2520 struct ice_pf *pf = (struct ice_pf *)hw->back;
2521 struct device *dev = &pf->pdev->dev;
2525 /* The package download AdminQ command returned success because
2526 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
2527 * already a package loaded on the device.
2529 if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
2530 hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
2531 hw->pkg_ver.update == hw->active_pkg_ver.update &&
2532 hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
2533 !memcmp(hw->pkg_name, hw->active_pkg_name,
2534 sizeof(hw->pkg_name))) {
2535 if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST)
2537 "DDP package already present on device: %s version %d.%d.%d.%d\n",
2538 hw->active_pkg_name,
2539 hw->active_pkg_ver.major,
2540 hw->active_pkg_ver.minor,
2541 hw->active_pkg_ver.update,
2542 hw->active_pkg_ver.draft);
2545 "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
2546 hw->active_pkg_name,
2547 hw->active_pkg_ver.major,
2548 hw->active_pkg_ver.minor,
2549 hw->active_pkg_ver.update,
2550 hw->active_pkg_ver.draft);
2551 } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
2552 hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
2554 "The device has a DDP package that is not supported by the driver. The device has package '%s' version %d.%d.x.x. The driver requires version %d.%d.x.x. Entering Safe Mode.\n",
2555 hw->active_pkg_name,
2556 hw->active_pkg_ver.major,
2557 hw->active_pkg_ver.minor,
2558 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2559 *status = ICE_ERR_NOT_SUPPORTED;
2560 } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2561 hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
2563 "The driver could not load the DDP package file because a compatible DDP package is already present on the device. The device has package '%s' version %d.%d.%d.%d. The package file found by the driver: '%s' version %d.%d.%d.%d.\n",
2564 hw->active_pkg_name,
2565 hw->active_pkg_ver.major,
2566 hw->active_pkg_ver.minor,
2567 hw->active_pkg_ver.update,
2568 hw->active_pkg_ver.draft,
2576 "An unknown error occurred when loading the DDP package, please reboot the system. If the problem persists, update the NVM. Entering Safe Mode.\n");
2577 *status = ICE_ERR_NOT_SUPPORTED;
2580 case ICE_ERR_BUF_TOO_SHORT:
2584 "The DDP package file is invalid. Entering Safe Mode.\n");
2586 case ICE_ERR_NOT_SUPPORTED:
2587 /* Package File version not supported */
2588 if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ ||
2589 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2590 hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR))
2592 "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
2593 else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ ||
2594 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
2595 hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR))
2597 "The DDP package file version is lower than the driver supports. The driver requires version %d.%d.x.x. Please use an updated DDP Package file. Entering Safe Mode.\n",
2598 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
2600 case ICE_ERR_AQ_ERROR:
2601 switch (hw->adminq.sq_last_status) {
2602 case ICE_AQ_RC_ENOSEC:
2603 case ICE_AQ_RC_EBADSIG:
2605 "The DDP package could not be loaded because its signature is not valid. Please use a valid DDP Package. Entering Safe Mode.\n");
2607 case ICE_AQ_RC_ESVN:
2609 "The DDP Package could not be loaded because its security revision is too low. Please use an updated DDP Package. Entering Safe Mode.\n");
2611 case ICE_AQ_RC_EBADMAN:
2612 case ICE_AQ_RC_EBADBUF:
2614 "An error occurred on the device while loading the DDP package. The device will be reset.\n");
2622 "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n",
2629 * ice_load_pkg - load/reload the DDP Package file
2630 * @firmware: firmware structure when firmware requested or NULL for reload
2631 * @pf: pointer to the PF instance
2633 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
2634 * initialize HW tables.
2637 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
2639 enum ice_status status = ICE_ERR_PARAM;
2640 struct device *dev = &pf->pdev->dev;
2641 struct ice_hw *hw = &pf->hw;
2643 /* Load DDP Package */
2644 if (firmware && !hw->pkg_copy) {
2645 status = ice_copy_and_init_pkg(hw, firmware->data,
2647 ice_log_pkg_init(hw, &status);
2648 } else if (!firmware && hw->pkg_copy) {
2649 /* Reload package during rebuild after CORER/GLOBR reset */
2650 status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
2651 ice_log_pkg_init(hw, &status);
2654 "The DDP package file failed to load. Entering Safe Mode.\n");
2659 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
2663 /* Successful download package is the precondition for advanced
2664 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
2666 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
2670 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
2671 * @pf: pointer to the PF structure
2673 * There is no error returned here because the driver should be able to handle
2674 * 128 Byte cache lines, so we only print a warning in case issues are seen,
2675 * specifically with Tx.
2677 static void ice_verify_cacheline_size(struct ice_pf *pf)
2679 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
2680 dev_warn(&pf->pdev->dev,
2681 "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
2682 ICE_CACHE_LINE_BYTES);
2686 * ice_send_version - update firmware with driver version
2689 * Returns ICE_SUCCESS on success, else error code
2691 static enum ice_status ice_send_version(struct ice_pf *pf)
2693 struct ice_driver_ver dv;
2695 dv.major_ver = DRV_VERSION_MAJOR;
2696 dv.minor_ver = DRV_VERSION_MINOR;
2697 dv.build_ver = DRV_VERSION_BUILD;
2698 dv.subbuild_ver = 0;
2699 strscpy((char *)dv.driver_string, DRV_VERSION,
2700 sizeof(dv.driver_string));
2701 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
2705 * ice_get_opt_fw_name - return optional firmware file name or NULL
2706 * @pf: pointer to the PF instance
2708 static char *ice_get_opt_fw_name(struct ice_pf *pf)
2710 /* Optional firmware name same as default with additional dash
2711 * followed by a EUI-64 identifier (PCIe Device Serial Number)
2713 struct pci_dev *pdev = pf->pdev;
2714 char *opt_fw_filename = NULL;
2719 /* Determine the name of the optional file using the DSN (two
2720 * dwords following the start of the DSN Capability).
2722 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_DSN);
2724 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
2725 if (!opt_fw_filename)
2728 pci_read_config_dword(pdev, pos + 4, &dword);
2729 put_unaligned_le32(dword, &dsn[0]);
2730 pci_read_config_dword(pdev, pos + 8, &dword);
2731 put_unaligned_le32(dword, &dsn[4]);
2732 snprintf(opt_fw_filename, NAME_MAX,
2733 "%sice-%02x%02x%02x%02x%02x%02x%02x%02x.pkg",
2735 dsn[7], dsn[6], dsn[5], dsn[4],
2736 dsn[3], dsn[2], dsn[1], dsn[0]);
2739 return opt_fw_filename;
2743 * ice_request_fw - Device initialization routine
2744 * @pf: pointer to the PF instance
2746 static void ice_request_fw(struct ice_pf *pf)
2748 char *opt_fw_filename = ice_get_opt_fw_name(pf);
2749 const struct firmware *firmware = NULL;
2750 struct device *dev = &pf->pdev->dev;
2753 /* optional device-specific DDP (if present) overrides the default DDP
2754 * package file. kernel logs a debug message if the file doesn't exist,
2755 * and warning messages for other errors.
2757 if (opt_fw_filename) {
2758 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
2760 kfree(opt_fw_filename);
2764 /* request for firmware was successful. Download to device */
2765 ice_load_pkg(firmware, pf);
2766 kfree(opt_fw_filename);
2767 release_firmware(firmware);
2772 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
2775 "The DDP package file was not found or could not be read. Entering Safe Mode\n");
2779 /* request for firmware was successful. Download to device */
2780 ice_load_pkg(firmware, pf);
2781 release_firmware(firmware);
2785 * ice_probe - Device initialization routine
2786 * @pdev: PCI device information struct
2787 * @ent: entry in ice_pci_tbl
2789 * Returns 0 on success, negative on failure
2792 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
2794 struct device *dev = &pdev->dev;
2799 /* this driver uses devres, see Documentation/driver-api/driver-model/devres.rst */
2800 err = pcim_enable_device(pdev);
2804 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), pci_name(pdev));
2806 dev_err(dev, "BAR0 I/O map error %d\n", err);
2810 pf = devm_kzalloc(dev, sizeof(*pf), GFP_KERNEL);
2814 /* set up for high or low DMA */
2815 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
2817 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
2819 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
2823 pci_enable_pcie_error_reporting(pdev);
2824 pci_set_master(pdev);
2827 pci_set_drvdata(pdev, pf);
2828 set_bit(__ICE_DOWN, pf->state);
2829 /* Disable service task until DOWN bit is cleared */
2830 set_bit(__ICE_SERVICE_DIS, pf->state);
2833 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
2835 hw->vendor_id = pdev->vendor;
2836 hw->device_id = pdev->device;
2837 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
2838 hw->subsystem_vendor_id = pdev->subsystem_vendor;
2839 hw->subsystem_device_id = pdev->subsystem_device;
2840 hw->bus.device = PCI_SLOT(pdev->devfn);
2841 hw->bus.func = PCI_FUNC(pdev->devfn);
2842 ice_set_ctrlq_len(hw);
2844 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
2846 #ifndef CONFIG_DYNAMIC_DEBUG
2848 hw->debug_mask = debug;
2851 err = ice_init_hw(hw);
2853 dev_err(dev, "ice_init_hw failed: %d\n", err);
2855 goto err_exit_unroll;
2858 dev_info(dev, "firmware %d.%d.%d api %d.%d.%d nvm %s build 0x%08x\n",
2859 hw->fw_maj_ver, hw->fw_min_ver, hw->fw_patch,
2860 hw->api_maj_ver, hw->api_min_ver, hw->api_patch,
2861 ice_nvm_version_str(hw), hw->fw_build);
2865 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
2866 * set in pf->state, which will cause ice_is_safe_mode to return
2869 if (ice_is_safe_mode(pf)) {
2871 "Package download failed. Advanced features disabled - Device now in Safe Mode\n");
2872 /* we already got function/device capabilities but these don't
2873 * reflect what the driver needs to do in safe mode. Instead of
2874 * adding conditional logic everywhere to ignore these
2875 * device/function capabilities, override them.
2877 ice_set_safe_mode_caps(hw);
2880 err = ice_init_pf(pf);
2882 dev_err(dev, "ice_init_pf failed: %d\n", err);
2883 goto err_init_pf_unroll;
2886 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
2887 if (!pf->num_alloc_vsi) {
2889 goto err_init_pf_unroll;
2892 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
2896 goto err_init_pf_unroll;
2899 err = ice_init_interrupt_scheme(pf);
2901 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
2903 goto err_init_interrupt_unroll;
2906 /* Driver is mostly up */
2907 clear_bit(__ICE_DOWN, pf->state);
2909 /* In case of MSIX we are going to setup the misc vector right here
2910 * to handle admin queue events etc. In case of legacy and MSI
2911 * the misc functionality and queue processing is combined in
2912 * the same vector and that gets setup at open.
2914 err = ice_req_irq_msix_misc(pf);
2916 dev_err(dev, "setup of misc vector failed: %d\n", err);
2917 goto err_init_interrupt_unroll;
2920 /* create switch struct for the switch element created by FW on boot */
2921 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
2922 if (!pf->first_sw) {
2924 goto err_msix_misc_unroll;
2928 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
2930 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
2932 pf->first_sw->pf = pf;
2934 /* record the sw_id available for later use */
2935 pf->first_sw->sw_id = hw->port_info->sw_id;
2937 err = ice_setup_pf_sw(pf);
2939 dev_err(dev, "probe failed due to setup PF switch:%d\n", err);
2940 goto err_alloc_sw_unroll;
2943 clear_bit(__ICE_SERVICE_DIS, pf->state);
2945 /* tell the firmware we are up */
2946 err = ice_send_version(pf);
2949 "probe failed sending driver version %s. error: %d\n",
2951 goto err_alloc_sw_unroll;
2954 /* since everything is good, start the service timer */
2955 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
2957 err = ice_init_link_events(pf->hw.port_info);
2959 dev_err(dev, "ice_init_link_events failed: %d\n", err);
2960 goto err_alloc_sw_unroll;
2963 ice_verify_cacheline_size(pf);
2965 /* If no DDP driven features have to be setup, return here */
2966 if (ice_is_safe_mode(pf))
2969 /* initialize DDP driven features */
2971 /* Note: DCB init failure is non-fatal to load */
2972 if (ice_init_pf_dcb(pf, false)) {
2973 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
2974 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
2976 ice_cfg_lldp_mib_change(&pf->hw, true);
2981 err_alloc_sw_unroll:
2982 set_bit(__ICE_SERVICE_DIS, pf->state);
2983 set_bit(__ICE_DOWN, pf->state);
2984 devm_kfree(&pf->pdev->dev, pf->first_sw);
2985 err_msix_misc_unroll:
2986 ice_free_irq_msix_misc(pf);
2987 err_init_interrupt_unroll:
2988 ice_clear_interrupt_scheme(pf);
2989 devm_kfree(dev, pf->vsi);
2994 pci_disable_pcie_error_reporting(pdev);
2999 * ice_remove - Device removal routine
3000 * @pdev: PCI device information struct
3002 static void ice_remove(struct pci_dev *pdev)
3004 struct ice_pf *pf = pci_get_drvdata(pdev);
3010 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
3011 if (!ice_is_reset_in_progress(pf->state))
3016 set_bit(__ICE_DOWN, pf->state);
3017 ice_service_task_stop(pf);
3019 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags))
3021 ice_vsi_release_all(pf);
3022 ice_free_irq_msix_misc(pf);
3023 ice_for_each_vsi(pf, i) {
3026 ice_vsi_free_q_vectors(pf->vsi[i]);
3029 ice_deinit_hw(&pf->hw);
3030 ice_clear_interrupt_scheme(pf);
3031 /* Issue a PFR as part of the prescribed driver unload flow. Do not
3032 * do it via ice_schedule_reset() since there is no need to rebuild
3033 * and the service task is already stopped.
3035 ice_reset(&pf->hw, ICE_RESET_PFR);
3036 pci_disable_pcie_error_reporting(pdev);
3040 * ice_pci_err_detected - warning that PCI error has been detected
3041 * @pdev: PCI device information struct
3042 * @err: the type of PCI error
3044 * Called to warn that something happened on the PCI bus and the error handling
3045 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
3047 static pci_ers_result_t
3048 ice_pci_err_detected(struct pci_dev *pdev, enum pci_channel_state err)
3050 struct ice_pf *pf = pci_get_drvdata(pdev);
3053 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
3055 return PCI_ERS_RESULT_DISCONNECT;
3058 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3059 ice_service_task_stop(pf);
3061 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3062 set_bit(__ICE_PFR_REQ, pf->state);
3063 ice_prepare_for_reset(pf);
3067 return PCI_ERS_RESULT_NEED_RESET;
3071 * ice_pci_err_slot_reset - a PCI slot reset has just happened
3072 * @pdev: PCI device information struct
3074 * Called to determine if the driver can recover from the PCI slot reset by
3075 * using a register read to determine if the device is recoverable.
3077 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
3079 struct ice_pf *pf = pci_get_drvdata(pdev);
3080 pci_ers_result_t result;
3084 err = pci_enable_device_mem(pdev);
3087 "Cannot re-enable PCI device after reset, error %d\n",
3089 result = PCI_ERS_RESULT_DISCONNECT;
3091 pci_set_master(pdev);
3092 pci_restore_state(pdev);
3093 pci_save_state(pdev);
3094 pci_wake_from_d3(pdev, false);
3096 /* Check for life */
3097 reg = rd32(&pf->hw, GLGEN_RTRIG);
3099 result = PCI_ERS_RESULT_RECOVERED;
3101 result = PCI_ERS_RESULT_DISCONNECT;
3104 err = pci_cleanup_aer_uncorrect_error_status(pdev);
3107 "pci_cleanup_aer_uncorrect_error_status failed, error %d\n",
3109 /* non-fatal, continue */
3115 * ice_pci_err_resume - restart operations after PCI error recovery
3116 * @pdev: PCI device information struct
3118 * Called to allow the driver to bring things back up after PCI error and/or
3119 * reset recovery have finished
3121 static void ice_pci_err_resume(struct pci_dev *pdev)
3123 struct ice_pf *pf = pci_get_drvdata(pdev);
3127 "%s failed, device is unrecoverable\n", __func__);
3131 if (test_bit(__ICE_SUSPENDED, pf->state)) {
3132 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
3137 ice_do_reset(pf, ICE_RESET_PFR);
3138 ice_service_task_restart(pf);
3139 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
3143 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
3144 * @pdev: PCI device information struct
3146 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
3148 struct ice_pf *pf = pci_get_drvdata(pdev);
3150 if (!test_bit(__ICE_SUSPENDED, pf->state)) {
3151 ice_service_task_stop(pf);
3153 if (!test_bit(__ICE_PREPARED_FOR_RESET, pf->state)) {
3154 set_bit(__ICE_PFR_REQ, pf->state);
3155 ice_prepare_for_reset(pf);
3161 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
3162 * @pdev: PCI device information struct
3164 static void ice_pci_err_reset_done(struct pci_dev *pdev)
3166 ice_pci_err_resume(pdev);
3169 /* ice_pci_tbl - PCI Device ID Table
3171 * Wildcard entries (PCI_ANY_ID) should come last
3172 * Last entry must be all 0s
3174 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3175 * Class, Class Mask, private data (not used) }
3177 static const struct pci_device_id ice_pci_tbl[] = {
3178 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
3179 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
3180 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
3181 /* required last entry */
3184 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
3186 static const struct pci_error_handlers ice_pci_err_handler = {
3187 .error_detected = ice_pci_err_detected,
3188 .slot_reset = ice_pci_err_slot_reset,
3189 .reset_prepare = ice_pci_err_reset_prepare,
3190 .reset_done = ice_pci_err_reset_done,
3191 .resume = ice_pci_err_resume
3194 static struct pci_driver ice_driver = {
3195 .name = KBUILD_MODNAME,
3196 .id_table = ice_pci_tbl,
3198 .remove = ice_remove,
3199 .sriov_configure = ice_sriov_configure,
3200 .err_handler = &ice_pci_err_handler
3204 * ice_module_init - Driver registration routine
3206 * ice_module_init is the first routine called when the driver is
3207 * loaded. All it does is register with the PCI subsystem.
3209 static int __init ice_module_init(void)
3213 pr_info("%s - version %s\n", ice_driver_string, ice_drv_ver);
3214 pr_info("%s\n", ice_copyright);
3216 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
3218 pr_err("Failed to create workqueue\n");
3222 status = pci_register_driver(&ice_driver);
3224 pr_err("failed to register PCI driver, err %d\n", status);
3225 destroy_workqueue(ice_wq);
3230 module_init(ice_module_init);
3233 * ice_module_exit - Driver exit cleanup routine
3235 * ice_module_exit is called just before the driver is removed
3238 static void __exit ice_module_exit(void)
3240 pci_unregister_driver(&ice_driver);
3241 destroy_workqueue(ice_wq);
3242 pr_info("module unloaded\n");
3244 module_exit(ice_module_exit);
3247 * ice_set_mac_address - NDO callback to set MAC address
3248 * @netdev: network interface device structure
3249 * @pi: pointer to an address structure
3251 * Returns 0 on success, negative on failure
3253 static int ice_set_mac_address(struct net_device *netdev, void *pi)
3255 struct ice_netdev_priv *np = netdev_priv(netdev);
3256 struct ice_vsi *vsi = np->vsi;
3257 struct ice_pf *pf = vsi->back;
3258 struct ice_hw *hw = &pf->hw;
3259 struct sockaddr *addr = pi;
3260 enum ice_status status;
3265 mac = (u8 *)addr->sa_data;
3267 if (!is_valid_ether_addr(mac))
3268 return -EADDRNOTAVAIL;
3270 if (ether_addr_equal(netdev->dev_addr, mac)) {
3271 netdev_warn(netdev, "already using mac %pM\n", mac);
3275 if (test_bit(__ICE_DOWN, pf->state) ||
3276 ice_is_reset_in_progress(pf->state)) {
3277 netdev_err(netdev, "can't set mac %pM. device not ready\n",
3282 /* When we change the MAC address we also have to change the MAC address
3283 * based filter rules that were created previously for the old MAC
3284 * address. So first, we remove the old filter rule using ice_remove_mac
3285 * and then create a new filter rule using ice_add_mac via
3286 * ice_vsi_cfg_mac_fltr function call for both add and/or remove
3289 status = ice_vsi_cfg_mac_fltr(vsi, netdev->dev_addr, false);
3291 err = -EADDRNOTAVAIL;
3292 goto err_update_filters;
3295 status = ice_vsi_cfg_mac_fltr(vsi, mac, true);
3297 err = -EADDRNOTAVAIL;
3298 goto err_update_filters;
3303 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
3308 /* change the netdev's MAC address */
3309 memcpy(netdev->dev_addr, mac, netdev->addr_len);
3310 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
3313 /* write new MAC address to the firmware */
3314 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
3315 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
3317 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
3324 * ice_set_rx_mode - NDO callback to set the netdev filters
3325 * @netdev: network interface device structure
3327 static void ice_set_rx_mode(struct net_device *netdev)
3329 struct ice_netdev_priv *np = netdev_priv(netdev);
3330 struct ice_vsi *vsi = np->vsi;
3335 /* Set the flags to synchronize filters
3336 * ndo_set_rx_mode may be triggered even without a change in netdev
3339 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED, vsi->flags);
3340 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED, vsi->flags);
3341 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
3343 /* schedule our worker thread which will take care of
3344 * applying the new filter changes
3346 ice_service_task_schedule(vsi->back);
3350 * ice_fdb_add - add an entry to the hardware database
3351 * @ndm: the input from the stack
3352 * @tb: pointer to array of nladdr (unused)
3353 * @dev: the net device pointer
3354 * @addr: the MAC address entry being added
3356 * @flags: instructions from stack about fdb operation
3357 * @extack: netlink extended ack
3360 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
3361 struct net_device *dev, const unsigned char *addr, u16 vid,
3362 u16 flags, struct netlink_ext_ack __always_unused *extack)
3367 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3370 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
3371 netdev_err(dev, "FDB only supports static addresses\n");
3375 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
3376 err = dev_uc_add_excl(dev, addr);
3377 else if (is_multicast_ether_addr(addr))
3378 err = dev_mc_add_excl(dev, addr);
3382 /* Only return duplicate errors if NLM_F_EXCL is set */
3383 if (err == -EEXIST && !(flags & NLM_F_EXCL))
3390 * ice_fdb_del - delete an entry from the hardware database
3391 * @ndm: the input from the stack
3392 * @tb: pointer to array of nladdr (unused)
3393 * @dev: the net device pointer
3394 * @addr: the MAC address entry being added
3398 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
3399 struct net_device *dev, const unsigned char *addr,
3400 __always_unused u16 vid)
3404 if (ndm->ndm_state & NUD_PERMANENT) {
3405 netdev_err(dev, "FDB only supports static addresses\n");
3409 if (is_unicast_ether_addr(addr))
3410 err = dev_uc_del(dev, addr);
3411 else if (is_multicast_ether_addr(addr))
3412 err = dev_mc_del(dev, addr);
3420 * ice_set_features - set the netdev feature flags
3421 * @netdev: ptr to the netdev being adjusted
3422 * @features: the feature set that the stack is suggesting
3425 ice_set_features(struct net_device *netdev, netdev_features_t features)
3427 struct ice_netdev_priv *np = netdev_priv(netdev);
3428 struct ice_vsi *vsi = np->vsi;
3431 /* Don't set any netdev advanced features with device in Safe Mode */
3432 if (ice_is_safe_mode(vsi->back)) {
3433 dev_err(&vsi->back->pdev->dev,
3434 "Device is in Safe Mode - not enabling advanced netdev features\n");
3438 /* Multiple features can be changed in one call so keep features in
3439 * separate if/else statements to guarantee each feature is checked
3441 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
3442 ret = ice_vsi_manage_rss_lut(vsi, true);
3443 else if (!(features & NETIF_F_RXHASH) &&
3444 netdev->features & NETIF_F_RXHASH)
3445 ret = ice_vsi_manage_rss_lut(vsi, false);
3447 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
3448 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3449 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3450 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
3451 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
3452 ret = ice_vsi_manage_vlan_stripping(vsi, false);
3454 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
3455 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3456 ret = ice_vsi_manage_vlan_insertion(vsi);
3457 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
3458 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
3459 ret = ice_vsi_manage_vlan_insertion(vsi);
3461 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3462 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3463 ret = ice_cfg_vlan_pruning(vsi, true, false);
3464 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3465 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3466 ret = ice_cfg_vlan_pruning(vsi, false, false);
3472 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
3473 * @vsi: VSI to setup VLAN properties for
3475 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
3479 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
3480 ret = ice_vsi_manage_vlan_stripping(vsi, true);
3481 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
3482 ret = ice_vsi_manage_vlan_insertion(vsi);
3488 * ice_vsi_cfg - Setup the VSI
3489 * @vsi: the VSI being configured
3491 * Return 0 on success and negative value on error
3493 int ice_vsi_cfg(struct ice_vsi *vsi)
3498 ice_set_rx_mode(vsi->netdev);
3500 err = ice_vsi_vlan_setup(vsi);
3505 ice_vsi_cfg_dcb_rings(vsi);
3507 err = ice_vsi_cfg_lan_txqs(vsi);
3509 err = ice_vsi_cfg_rxqs(vsi);
3515 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3516 * @vsi: the VSI being configured
3518 static void ice_napi_enable_all(struct ice_vsi *vsi)
3525 ice_for_each_q_vector(vsi, q_idx) {
3526 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3528 if (q_vector->rx.ring || q_vector->tx.ring)
3529 napi_enable(&q_vector->napi);
3534 * ice_up_complete - Finish the last steps of bringing up a connection
3535 * @vsi: The VSI being configured
3537 * Return 0 on success and negative value on error
3539 static int ice_up_complete(struct ice_vsi *vsi)
3541 struct ice_pf *pf = vsi->back;
3544 ice_vsi_cfg_msix(vsi);
3546 /* Enable only Rx rings, Tx rings were enabled by the FW when the
3547 * Tx queue group list was configured and the context bits were
3548 * programmed using ice_vsi_cfg_txqs
3550 err = ice_vsi_start_rx_rings(vsi);
3554 clear_bit(__ICE_DOWN, vsi->state);
3555 ice_napi_enable_all(vsi);
3556 ice_vsi_ena_irq(vsi);
3558 if (vsi->port_info &&
3559 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
3561 ice_print_link_msg(vsi, true);
3562 netif_tx_start_all_queues(vsi->netdev);
3563 netif_carrier_on(vsi->netdev);
3566 ice_service_task_schedule(pf);
3572 * ice_up - Bring the connection back up after being down
3573 * @vsi: VSI being configured
3575 int ice_up(struct ice_vsi *vsi)
3579 err = ice_vsi_cfg(vsi);
3581 err = ice_up_complete(vsi);
3587 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
3588 * @ring: Tx or Rx ring to read stats from
3589 * @pkts: packets stats counter
3590 * @bytes: bytes stats counter
3592 * This function fetches stats from the ring considering the atomic operations
3593 * that needs to be performed to read u64 values in 32 bit machine.
3596 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
3605 start = u64_stats_fetch_begin_irq(&ring->syncp);
3606 *pkts = ring->stats.pkts;
3607 *bytes = ring->stats.bytes;
3608 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
3612 * ice_update_vsi_ring_stats - Update VSI stats counters
3613 * @vsi: the VSI to be updated
3615 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
3617 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
3618 struct ice_ring *ring;
3622 /* reset netdev stats */
3623 vsi_stats->tx_packets = 0;
3624 vsi_stats->tx_bytes = 0;
3625 vsi_stats->rx_packets = 0;
3626 vsi_stats->rx_bytes = 0;
3628 /* reset non-netdev (extended) stats */
3629 vsi->tx_restart = 0;
3631 vsi->tx_linearize = 0;
3632 vsi->rx_buf_failed = 0;
3633 vsi->rx_page_failed = 0;
3637 /* update Tx rings counters */
3638 ice_for_each_txq(vsi, i) {
3639 ring = READ_ONCE(vsi->tx_rings[i]);
3640 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3641 vsi_stats->tx_packets += pkts;
3642 vsi_stats->tx_bytes += bytes;
3643 vsi->tx_restart += ring->tx_stats.restart_q;
3644 vsi->tx_busy += ring->tx_stats.tx_busy;
3645 vsi->tx_linearize += ring->tx_stats.tx_linearize;
3648 /* update Rx rings counters */
3649 ice_for_each_rxq(vsi, i) {
3650 ring = READ_ONCE(vsi->rx_rings[i]);
3651 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
3652 vsi_stats->rx_packets += pkts;
3653 vsi_stats->rx_bytes += bytes;
3654 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
3655 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
3662 * ice_update_vsi_stats - Update VSI stats counters
3663 * @vsi: the VSI to be updated
3665 void ice_update_vsi_stats(struct ice_vsi *vsi)
3667 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
3668 struct ice_eth_stats *cur_es = &vsi->eth_stats;
3669 struct ice_pf *pf = vsi->back;
3671 if (test_bit(__ICE_DOWN, vsi->state) ||
3672 test_bit(__ICE_CFG_BUSY, pf->state))
3675 /* get stats as recorded by Tx/Rx rings */
3676 ice_update_vsi_ring_stats(vsi);
3678 /* get VSI stats as recorded by the hardware */
3679 ice_update_eth_stats(vsi);
3681 cur_ns->tx_errors = cur_es->tx_errors;
3682 cur_ns->rx_dropped = cur_es->rx_discards;
3683 cur_ns->tx_dropped = cur_es->tx_discards;
3684 cur_ns->multicast = cur_es->rx_multicast;
3686 /* update some more netdev stats if this is main VSI */
3687 if (vsi->type == ICE_VSI_PF) {
3688 cur_ns->rx_crc_errors = pf->stats.crc_errors;
3689 cur_ns->rx_errors = pf->stats.crc_errors +
3690 pf->stats.illegal_bytes;
3691 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
3692 /* record drops from the port level */
3693 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
3698 * ice_update_pf_stats - Update PF port stats counters
3699 * @pf: PF whose stats needs to be updated
3701 void ice_update_pf_stats(struct ice_pf *pf)
3703 struct ice_hw_port_stats *prev_ps, *cur_ps;
3704 struct ice_hw *hw = &pf->hw;
3707 port = hw->port_info->lport;
3708 prev_ps = &pf->stats_prev;
3709 cur_ps = &pf->stats;
3711 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
3712 &prev_ps->eth.rx_bytes,
3713 &cur_ps->eth.rx_bytes);
3715 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
3716 &prev_ps->eth.rx_unicast,
3717 &cur_ps->eth.rx_unicast);
3719 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
3720 &prev_ps->eth.rx_multicast,
3721 &cur_ps->eth.rx_multicast);
3723 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
3724 &prev_ps->eth.rx_broadcast,
3725 &cur_ps->eth.rx_broadcast);
3727 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
3728 &prev_ps->eth.rx_discards,
3729 &cur_ps->eth.rx_discards);
3731 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
3732 &prev_ps->eth.tx_bytes,
3733 &cur_ps->eth.tx_bytes);
3735 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
3736 &prev_ps->eth.tx_unicast,
3737 &cur_ps->eth.tx_unicast);
3739 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
3740 &prev_ps->eth.tx_multicast,
3741 &cur_ps->eth.tx_multicast);
3743 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
3744 &prev_ps->eth.tx_broadcast,
3745 &cur_ps->eth.tx_broadcast);
3747 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
3748 &prev_ps->tx_dropped_link_down,
3749 &cur_ps->tx_dropped_link_down);
3751 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
3752 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
3754 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
3755 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
3757 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
3758 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
3760 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
3761 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
3763 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
3764 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
3766 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
3767 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
3769 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
3770 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
3772 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
3773 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
3775 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
3776 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
3778 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
3779 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
3781 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
3782 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
3784 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
3785 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
3787 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
3788 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
3790 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
3791 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
3793 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
3794 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
3796 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
3797 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
3799 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
3800 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
3802 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
3803 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
3805 ice_update_dcb_stats(pf);
3807 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
3808 &prev_ps->crc_errors, &cur_ps->crc_errors);
3810 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
3811 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
3813 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
3814 &prev_ps->mac_local_faults,
3815 &cur_ps->mac_local_faults);
3817 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
3818 &prev_ps->mac_remote_faults,
3819 &cur_ps->mac_remote_faults);
3821 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
3822 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
3824 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
3825 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
3827 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
3828 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
3830 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
3831 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
3833 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
3834 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
3836 pf->stat_prev_loaded = true;
3840 * ice_get_stats64 - get statistics for network device structure
3841 * @netdev: network interface device structure
3842 * @stats: main device statistics structure
3845 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
3847 struct ice_netdev_priv *np = netdev_priv(netdev);
3848 struct rtnl_link_stats64 *vsi_stats;
3849 struct ice_vsi *vsi = np->vsi;
3851 vsi_stats = &vsi->net_stats;
3853 if (!vsi->num_txq || !vsi->num_rxq)
3856 /* netdev packet/byte stats come from ring counter. These are obtained
3857 * by summing up ring counters (done by ice_update_vsi_ring_stats).
3858 * But, only call the update routine and read the registers if VSI is
3861 if (!test_bit(__ICE_DOWN, vsi->state))
3862 ice_update_vsi_ring_stats(vsi);
3863 stats->tx_packets = vsi_stats->tx_packets;
3864 stats->tx_bytes = vsi_stats->tx_bytes;
3865 stats->rx_packets = vsi_stats->rx_packets;
3866 stats->rx_bytes = vsi_stats->rx_bytes;
3868 /* The rest of the stats can be read from the hardware but instead we
3869 * just return values that the watchdog task has already obtained from
3872 stats->multicast = vsi_stats->multicast;
3873 stats->tx_errors = vsi_stats->tx_errors;
3874 stats->tx_dropped = vsi_stats->tx_dropped;
3875 stats->rx_errors = vsi_stats->rx_errors;
3876 stats->rx_dropped = vsi_stats->rx_dropped;
3877 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
3878 stats->rx_length_errors = vsi_stats->rx_length_errors;
3882 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
3883 * @vsi: VSI having NAPI disabled
3885 static void ice_napi_disable_all(struct ice_vsi *vsi)
3892 ice_for_each_q_vector(vsi, q_idx) {
3893 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
3895 if (q_vector->rx.ring || q_vector->tx.ring)
3896 napi_disable(&q_vector->napi);
3901 * ice_down - Shutdown the connection
3902 * @vsi: The VSI being stopped
3904 int ice_down(struct ice_vsi *vsi)
3906 int i, tx_err, rx_err, link_err = 0;
3908 /* Caller of this function is expected to set the
3909 * vsi->state __ICE_DOWN bit
3912 netif_carrier_off(vsi->netdev);
3913 netif_tx_disable(vsi->netdev);
3916 ice_vsi_dis_irq(vsi);
3918 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
3920 netdev_err(vsi->netdev,
3921 "Failed stop Tx rings, VSI %d error %d\n",
3922 vsi->vsi_num, tx_err);
3924 rx_err = ice_vsi_stop_rx_rings(vsi);
3926 netdev_err(vsi->netdev,
3927 "Failed stop Rx rings, VSI %d error %d\n",
3928 vsi->vsi_num, rx_err);
3930 ice_napi_disable_all(vsi);
3932 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
3933 link_err = ice_force_phys_link_state(vsi, false);
3935 netdev_err(vsi->netdev,
3936 "Failed to set physical link down, VSI %d error %d\n",
3937 vsi->vsi_num, link_err);
3940 ice_for_each_txq(vsi, i)
3941 ice_clean_tx_ring(vsi->tx_rings[i]);
3943 ice_for_each_rxq(vsi, i)
3944 ice_clean_rx_ring(vsi->rx_rings[i]);
3946 if (tx_err || rx_err || link_err) {
3947 netdev_err(vsi->netdev,
3948 "Failed to close VSI 0x%04X on switch 0x%04X\n",
3949 vsi->vsi_num, vsi->vsw->sw_id);
3957 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
3958 * @vsi: VSI having resources allocated
3960 * Return 0 on success, negative on failure
3962 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
3966 if (!vsi->num_txq) {
3967 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Tx queues\n",
3972 ice_for_each_txq(vsi, i) {
3973 vsi->tx_rings[i]->netdev = vsi->netdev;
3974 err = ice_setup_tx_ring(vsi->tx_rings[i]);
3983 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
3984 * @vsi: VSI having resources allocated
3986 * Return 0 on success, negative on failure
3988 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
3992 if (!vsi->num_rxq) {
3993 dev_err(&vsi->back->pdev->dev, "VSI %d has 0 Rx queues\n",
3998 ice_for_each_rxq(vsi, i) {
3999 vsi->rx_rings[i]->netdev = vsi->netdev;
4000 err = ice_setup_rx_ring(vsi->rx_rings[i]);
4009 * ice_vsi_open - Called when a network interface is made active
4010 * @vsi: the VSI to open
4012 * Initialization of the VSI
4014 * Returns 0 on success, negative value on error
4016 static int ice_vsi_open(struct ice_vsi *vsi)
4018 char int_name[ICE_INT_NAME_STR_LEN];
4019 struct ice_pf *pf = vsi->back;
4022 /* allocate descriptors */
4023 err = ice_vsi_setup_tx_rings(vsi);
4027 err = ice_vsi_setup_rx_rings(vsi);
4031 err = ice_vsi_cfg(vsi);
4035 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
4036 dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
4037 err = ice_vsi_req_irq_msix(vsi, int_name);
4041 /* Notify the stack of the actual queue counts. */
4042 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
4046 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
4050 err = ice_up_complete(vsi);
4052 goto err_up_complete;
4059 ice_vsi_free_irq(vsi);
4061 ice_vsi_free_rx_rings(vsi);
4063 ice_vsi_free_tx_rings(vsi);
4069 * ice_vsi_release_all - Delete all VSIs
4070 * @pf: PF from which all VSIs are being removed
4072 static void ice_vsi_release_all(struct ice_pf *pf)
4079 ice_for_each_vsi(pf, i) {
4083 err = ice_vsi_release(pf->vsi[i]);
4085 dev_dbg(&pf->pdev->dev,
4086 "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
4087 i, err, pf->vsi[i]->vsi_num);
4092 * ice_ena_vsi - resume a VSI
4093 * @vsi: the VSI being resume
4094 * @locked: is the rtnl_lock already held
4096 static int ice_ena_vsi(struct ice_vsi *vsi, bool locked)
4100 if (!test_bit(__ICE_NEEDS_RESTART, vsi->state))
4103 clear_bit(__ICE_NEEDS_RESTART, vsi->state);
4105 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
4106 if (netif_running(vsi->netdev)) {
4110 err = ice_open(vsi->netdev);
4121 * ice_pf_ena_all_vsi - Resume all VSIs on a PF
4123 * @locked: is the rtnl_lock already held
4126 int ice_pf_ena_all_vsi(struct ice_pf *pf, bool locked)
4130 ice_for_each_vsi(pf, v)
4132 if (ice_ena_vsi(pf->vsi[v], locked))
4137 #endif /* CONFIG_DCB */
4140 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
4141 * @pf: pointer to the PF instance
4142 * @type: VSI type to rebuild
4144 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
4146 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
4148 enum ice_status status;
4151 ice_for_each_vsi(pf, i) {
4152 struct ice_vsi *vsi = pf->vsi[i];
4154 if (!vsi || vsi->type != type)
4157 /* rebuild the VSI */
4158 err = ice_vsi_rebuild(vsi);
4160 dev_err(&pf->pdev->dev,
4161 "rebuild VSI failed, err %d, VSI index %d, type %d\n",
4162 err, vsi->idx, type);
4166 /* replay filters for the VSI */
4167 status = ice_replay_vsi(&pf->hw, vsi->idx);
4169 dev_err(&pf->pdev->dev,
4170 "replay VSI failed, status %d, VSI index %d, type %d\n",
4171 status, vsi->idx, type);
4175 /* Re-map HW VSI number, using VSI handle that has been
4176 * previously validated in ice_replay_vsi() call above
4178 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
4180 /* enable the VSI */
4181 err = ice_ena_vsi(vsi, false);
4183 dev_err(&pf->pdev->dev,
4184 "enable VSI failed, err %d, VSI index %d, type %d\n",
4185 err, vsi->idx, type);
4189 dev_info(&pf->pdev->dev, "VSI rebuilt. VSI index %d, type %d\n",
4197 * ice_update_pf_netdev_link - Update PF netdev link status
4198 * @pf: pointer to the PF instance
4200 static void ice_update_pf_netdev_link(struct ice_pf *pf)
4205 ice_for_each_vsi(pf, i) {
4206 struct ice_vsi *vsi = pf->vsi[i];
4208 if (!vsi || vsi->type != ICE_VSI_PF)
4211 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
4213 netif_carrier_on(pf->vsi[i]->netdev);
4214 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
4216 netif_carrier_off(pf->vsi[i]->netdev);
4217 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
4223 * ice_rebuild - rebuild after reset
4224 * @pf: PF to rebuild
4225 * @reset_type: type of reset
4227 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
4229 struct device *dev = &pf->pdev->dev;
4230 struct ice_hw *hw = &pf->hw;
4231 enum ice_status ret;
4234 if (test_bit(__ICE_DOWN, pf->state))
4235 goto clear_recovery;
4237 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
4239 ret = ice_init_all_ctrlq(hw);
4241 dev_err(dev, "control queues init failed %d\n", ret);
4242 goto err_init_ctrlq;
4245 /* if DDP was previously loaded successfully */
4246 if (!ice_is_safe_mode(pf)) {
4247 /* reload the SW DB of filter tables */
4248 if (reset_type == ICE_RESET_PFR)
4249 ice_fill_blk_tbls(hw);
4251 /* Reload DDP Package after CORER/GLOBR reset */
4252 ice_load_pkg(NULL, pf);
4255 ret = ice_clear_pf_cfg(hw);
4257 dev_err(dev, "clear PF configuration failed %d\n", ret);
4258 goto err_init_ctrlq;
4261 ice_clear_pxe_mode(hw);
4263 ret = ice_get_caps(hw);
4265 dev_err(dev, "ice_get_caps failed %d\n", ret);
4266 goto err_init_ctrlq;
4269 err = ice_sched_init_port(hw->port_info);
4271 goto err_sched_init_port;
4273 err = ice_update_link_info(hw->port_info);
4275 dev_err(&pf->pdev->dev, "Get link status error %d\n", err);
4277 /* start misc vector */
4278 err = ice_req_irq_msix_misc(pf);
4280 dev_err(dev, "misc vector setup failed: %d\n", err);
4281 goto err_sched_init_port;
4284 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
4285 ice_dcb_rebuild(pf);
4287 /* rebuild PF VSI */
4288 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
4290 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
4291 goto err_vsi_rebuild;
4294 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4295 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_VF);
4297 dev_err(dev, "VF VSI rebuild failed: %d\n", err);
4298 goto err_vsi_rebuild;
4302 ice_update_pf_netdev_link(pf);
4304 /* tell the firmware we are up */
4305 ret = ice_send_version(pf);
4308 "Rebuild failed due to error sending driver version: %d\n",
4310 goto err_vsi_rebuild;
4313 ice_replay_post(hw);
4315 /* if we get here, reset flow is successful */
4316 clear_bit(__ICE_RESET_FAILED, pf->state);
4320 err_sched_init_port:
4321 ice_sched_cleanup_all(hw);
4323 ice_shutdown_all_ctrlq(hw);
4324 set_bit(__ICE_RESET_FAILED, pf->state);
4326 /* set this bit in PF state to control service task scheduling */
4327 set_bit(__ICE_NEEDS_RESTART, pf->state);
4328 dev_err(dev, "Rebuild failed, unload and reload driver\n");
4332 * ice_change_mtu - NDO callback to change the MTU
4333 * @netdev: network interface device structure
4334 * @new_mtu: new value for maximum frame size
4336 * Returns 0 on success, negative on failure
4338 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
4340 struct ice_netdev_priv *np = netdev_priv(netdev);
4341 struct ice_vsi *vsi = np->vsi;
4342 struct ice_pf *pf = vsi->back;
4345 if (new_mtu == netdev->mtu) {
4346 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
4350 if (new_mtu < netdev->min_mtu) {
4351 netdev_err(netdev, "new MTU invalid. min_mtu is %d\n",
4354 } else if (new_mtu > netdev->max_mtu) {
4355 netdev_err(netdev, "new MTU invalid. max_mtu is %d\n",
4359 /* if a reset is in progress, wait for some time for it to complete */
4361 if (ice_is_reset_in_progress(pf->state)) {
4363 usleep_range(1000, 2000);
4368 } while (count < 100);
4371 netdev_err(netdev, "can't change MTU. Device is busy\n");
4375 netdev->mtu = new_mtu;
4377 /* if VSI is up, bring it down and then back up */
4378 if (!test_and_set_bit(__ICE_DOWN, vsi->state)) {
4381 err = ice_down(vsi);
4383 netdev_err(netdev, "change MTU if_up err %d\n", err);
4389 netdev_err(netdev, "change MTU if_up err %d\n", err);
4394 netdev_info(netdev, "changed MTU to %d\n", new_mtu);
4399 * ice_set_rss - Set RSS keys and lut
4400 * @vsi: Pointer to VSI structure
4401 * @seed: RSS hash seed
4402 * @lut: Lookup table
4403 * @lut_size: Lookup table size
4405 * Returns 0 on success, negative on failure
4407 int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4409 struct ice_pf *pf = vsi->back;
4410 struct ice_hw *hw = &pf->hw;
4411 enum ice_status status;
4414 struct ice_aqc_get_set_rss_keys *buf =
4415 (struct ice_aqc_get_set_rss_keys *)seed;
4417 status = ice_aq_set_rss_key(hw, vsi->idx, buf);
4420 dev_err(&pf->pdev->dev,
4421 "Cannot set RSS key, err %d aq_err %d\n",
4422 status, hw->adminq.rq_last_status);
4428 status = ice_aq_set_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4431 dev_err(&pf->pdev->dev,
4432 "Cannot set RSS lut, err %d aq_err %d\n",
4433 status, hw->adminq.rq_last_status);
4442 * ice_get_rss - Get RSS keys and lut
4443 * @vsi: Pointer to VSI structure
4444 * @seed: Buffer to store the keys
4445 * @lut: Buffer to store the lookup table entries
4446 * @lut_size: Size of buffer to store the lookup table entries
4448 * Returns 0 on success, negative on failure
4450 int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
4452 struct ice_pf *pf = vsi->back;
4453 struct ice_hw *hw = &pf->hw;
4454 enum ice_status status;
4457 struct ice_aqc_get_set_rss_keys *buf =
4458 (struct ice_aqc_get_set_rss_keys *)seed;
4460 status = ice_aq_get_rss_key(hw, vsi->idx, buf);
4462 dev_err(&pf->pdev->dev,
4463 "Cannot get RSS key, err %d aq_err %d\n",
4464 status, hw->adminq.rq_last_status);
4470 status = ice_aq_get_rss_lut(hw, vsi->idx, vsi->rss_lut_type,
4473 dev_err(&pf->pdev->dev,
4474 "Cannot get RSS lut, err %d aq_err %d\n",
4475 status, hw->adminq.rq_last_status);
4484 * ice_bridge_getlink - Get the hardware bridge mode
4487 * @seq: RTNL message seq
4488 * @dev: the netdev being configured
4489 * @filter_mask: filter mask passed in
4490 * @nlflags: netlink flags passed in
4492 * Return the bridge mode (VEB/VEPA)
4495 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4496 struct net_device *dev, u32 filter_mask, int nlflags)
4498 struct ice_netdev_priv *np = netdev_priv(dev);
4499 struct ice_vsi *vsi = np->vsi;
4500 struct ice_pf *pf = vsi->back;
4503 bmode = pf->first_sw->bridge_mode;
4505 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
4510 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4511 * @vsi: Pointer to VSI structure
4512 * @bmode: Hardware bridge mode (VEB/VEPA)
4514 * Returns 0 on success, negative on failure
4516 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
4518 struct device *dev = &vsi->back->pdev->dev;
4519 struct ice_aqc_vsi_props *vsi_props;
4520 struct ice_hw *hw = &vsi->back->hw;
4521 struct ice_vsi_ctx *ctxt;
4522 enum ice_status status;
4525 vsi_props = &vsi->info;
4527 ctxt = devm_kzalloc(dev, sizeof(*ctxt), GFP_KERNEL);
4531 ctxt->info = vsi->info;
4533 if (bmode == BRIDGE_MODE_VEB)
4534 /* change from VEPA to VEB mode */
4535 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4537 /* change from VEB to VEPA mode */
4538 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
4539 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
4541 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4543 dev_err(dev, "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
4544 bmode, status, hw->adminq.sq_last_status);
4548 /* Update sw flags for book keeping */
4549 vsi_props->sw_flags = ctxt->info.sw_flags;
4552 devm_kfree(dev, ctxt);
4557 * ice_bridge_setlink - Set the hardware bridge mode
4558 * @dev: the netdev being configured
4559 * @nlh: RTNL message
4560 * @flags: bridge setlink flags
4561 * @extack: netlink extended ack
4563 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
4564 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
4565 * not already set for all VSIs connected to this switch. And also update the
4566 * unicast switch filter rules for the corresponding switch of the netdev.
4569 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
4570 u16 __always_unused flags,
4571 struct netlink_ext_ack __always_unused *extack)
4573 struct ice_netdev_priv *np = netdev_priv(dev);
4574 struct ice_pf *pf = np->vsi->back;
4575 struct nlattr *attr, *br_spec;
4576 struct ice_hw *hw = &pf->hw;
4577 enum ice_status status;
4578 struct ice_sw *pf_sw;
4579 int rem, v, err = 0;
4581 pf_sw = pf->first_sw;
4582 /* find the attribute in the netlink message */
4583 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4585 nla_for_each_nested(attr, br_spec, rem) {
4588 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4590 mode = nla_get_u16(attr);
4591 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4593 /* Continue if bridge mode is not being flipped */
4594 if (mode == pf_sw->bridge_mode)
4596 /* Iterates through the PF VSI list and update the loopback
4599 ice_for_each_vsi(pf, v) {
4602 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
4607 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
4608 /* Update the unicast switch filter rules for the corresponding
4609 * switch of the netdev
4611 status = ice_update_sw_rule_bridge_mode(hw);
4613 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %d\n",
4614 mode, status, hw->adminq.sq_last_status);
4615 /* revert hw->evb_veb */
4616 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
4620 pf_sw->bridge_mode = mode;
4627 * ice_tx_timeout - Respond to a Tx Hang
4628 * @netdev: network interface device structure
4630 static void ice_tx_timeout(struct net_device *netdev)
4632 struct ice_netdev_priv *np = netdev_priv(netdev);
4633 struct ice_ring *tx_ring = NULL;
4634 struct ice_vsi *vsi = np->vsi;
4635 struct ice_pf *pf = vsi->back;
4636 int hung_queue = -1;
4639 pf->tx_timeout_count++;
4641 /* find the stopped queue the same way dev_watchdog() does */
4642 for (i = 0; i < netdev->num_tx_queues; i++) {
4643 unsigned long trans_start;
4644 struct netdev_queue *q;
4646 q = netdev_get_tx_queue(netdev, i);
4647 trans_start = q->trans_start;
4648 if (netif_xmit_stopped(q) &&
4650 trans_start + netdev->watchdog_timeo)) {
4656 if (i == netdev->num_tx_queues)
4657 netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
4659 /* now that we have an index, find the tx_ring struct */
4660 for (i = 0; i < vsi->num_txq; i++)
4661 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
4662 if (hung_queue == vsi->tx_rings[i]->q_index) {
4663 tx_ring = vsi->tx_rings[i];
4667 /* Reset recovery level if enough time has elapsed after last timeout.
4668 * Also ensure no new reset action happens before next timeout period.
4670 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
4671 pf->tx_timeout_recovery_level = 1;
4672 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
4673 netdev->watchdog_timeo)))
4677 struct ice_hw *hw = &pf->hw;
4680 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[hung_queue])) &
4681 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
4682 /* Read interrupt register */
4683 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
4685 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %d, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
4686 vsi->vsi_num, hung_queue, tx_ring->next_to_clean,
4687 head, tx_ring->next_to_use, val);
4690 pf->tx_timeout_last_recovery = jiffies;
4691 netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
4692 pf->tx_timeout_recovery_level, hung_queue);
4694 switch (pf->tx_timeout_recovery_level) {
4696 set_bit(__ICE_PFR_REQ, pf->state);
4699 set_bit(__ICE_CORER_REQ, pf->state);
4702 set_bit(__ICE_GLOBR_REQ, pf->state);
4705 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
4706 set_bit(__ICE_DOWN, pf->state);
4707 set_bit(__ICE_NEEDS_RESTART, vsi->state);
4708 set_bit(__ICE_SERVICE_DIS, pf->state);
4712 ice_service_task_schedule(pf);
4713 pf->tx_timeout_recovery_level++;
4717 * ice_open - Called when a network interface becomes active
4718 * @netdev: network interface device structure
4720 * The open entry point is called when a network interface is made
4721 * active by the system (IFF_UP). At this point all resources needed
4722 * for transmit and receive operations are allocated, the interrupt
4723 * handler is registered with the OS, the netdev watchdog is enabled,
4724 * and the stack is notified that the interface is ready.
4726 * Returns 0 on success, negative value on failure
4728 int ice_open(struct net_device *netdev)
4730 struct ice_netdev_priv *np = netdev_priv(netdev);
4731 struct ice_vsi *vsi = np->vsi;
4732 struct ice_port_info *pi;
4735 if (test_bit(__ICE_NEEDS_RESTART, vsi->back->state)) {
4736 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
4740 netif_carrier_off(netdev);
4742 pi = vsi->port_info;
4743 err = ice_update_link_info(pi);
4745 netdev_err(netdev, "Failed to get link info, error %d\n",
4750 /* Set PHY if there is media, otherwise, turn off PHY */
4751 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
4752 err = ice_force_phys_link_state(vsi, true);
4755 "Failed to set physical link up, error %d\n",
4760 err = ice_aq_set_link_restart_an(pi, false, NULL);
4762 netdev_err(netdev, "Failed to set PHY state, VSI %d error %d\n",
4766 set_bit(ICE_FLAG_NO_MEDIA, vsi->back->flags);
4769 err = ice_vsi_open(vsi);
4771 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
4772 vsi->vsi_num, vsi->vsw->sw_id);
4777 * ice_stop - Disables a network interface
4778 * @netdev: network interface device structure
4780 * The stop entry point is called when an interface is de-activated by the OS,
4781 * and the netdevice enters the DOWN state. The hardware is still under the
4782 * driver's control, but the netdev interface is disabled.
4784 * Returns success only - not allowed to fail
4786 int ice_stop(struct net_device *netdev)
4788 struct ice_netdev_priv *np = netdev_priv(netdev);
4789 struct ice_vsi *vsi = np->vsi;
4797 * ice_features_check - Validate encapsulated packet conforms to limits
4799 * @netdev: This port's netdev
4800 * @features: Offload features that the stack believes apply
4802 static netdev_features_t
4803 ice_features_check(struct sk_buff *skb,
4804 struct net_device __always_unused *netdev,
4805 netdev_features_t features)
4809 /* No point in doing any of this if neither checksum nor GSO are
4810 * being requested for this frame. We can rule out both by just
4811 * checking for CHECKSUM_PARTIAL
4813 if (skb->ip_summed != CHECKSUM_PARTIAL)
4816 /* We cannot support GSO if the MSS is going to be less than
4817 * 64 bytes. If it is then we need to drop support for GSO.
4819 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
4820 features &= ~NETIF_F_GSO_MASK;
4822 len = skb_network_header(skb) - skb->data;
4823 if (len & ~(ICE_TXD_MACLEN_MAX))
4824 goto out_rm_features;
4826 len = skb_transport_header(skb) - skb_network_header(skb);
4827 if (len & ~(ICE_TXD_IPLEN_MAX))
4828 goto out_rm_features;
4830 if (skb->encapsulation) {
4831 len = skb_inner_network_header(skb) - skb_transport_header(skb);
4832 if (len & ~(ICE_TXD_L4LEN_MAX))
4833 goto out_rm_features;
4835 len = skb_inner_transport_header(skb) -
4836 skb_inner_network_header(skb);
4837 if (len & ~(ICE_TXD_IPLEN_MAX))
4838 goto out_rm_features;
4843 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
4846 static const struct net_device_ops ice_netdev_safe_mode_ops = {
4847 .ndo_open = ice_open,
4848 .ndo_stop = ice_stop,
4849 .ndo_start_xmit = ice_start_xmit,
4850 .ndo_set_mac_address = ice_set_mac_address,
4851 .ndo_validate_addr = eth_validate_addr,
4852 .ndo_change_mtu = ice_change_mtu,
4853 .ndo_get_stats64 = ice_get_stats64,
4854 .ndo_tx_timeout = ice_tx_timeout,
4857 static const struct net_device_ops ice_netdev_ops = {
4858 .ndo_open = ice_open,
4859 .ndo_stop = ice_stop,
4860 .ndo_start_xmit = ice_start_xmit,
4861 .ndo_features_check = ice_features_check,
4862 .ndo_set_rx_mode = ice_set_rx_mode,
4863 .ndo_set_mac_address = ice_set_mac_address,
4864 .ndo_validate_addr = eth_validate_addr,
4865 .ndo_change_mtu = ice_change_mtu,
4866 .ndo_get_stats64 = ice_get_stats64,
4867 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
4868 .ndo_set_vf_mac = ice_set_vf_mac,
4869 .ndo_get_vf_config = ice_get_vf_cfg,
4870 .ndo_set_vf_trust = ice_set_vf_trust,
4871 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
4872 .ndo_set_vf_link_state = ice_set_vf_link_state,
4873 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
4874 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
4875 .ndo_set_features = ice_set_features,
4876 .ndo_bridge_getlink = ice_bridge_getlink,
4877 .ndo_bridge_setlink = ice_bridge_setlink,
4878 .ndo_fdb_add = ice_fdb_add,
4879 .ndo_fdb_del = ice_fdb_del,
4880 .ndo_tx_timeout = ice_tx_timeout,