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
8 #include <generated/utsrelease.h>
13 #include "ice_dcb_lib.h"
14 #include "ice_dcb_nl.h"
15 #include "ice_devlink.h"
16 /* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the
17 * ice tracepoint functions. This must be done exactly once across the
20 #define CREATE_TRACE_POINTS
21 #include "ice_trace.h"
22 #include "ice_eswitch.h"
23 #include "ice_tc_lib.h"
24 #include "ice_vsi_vlan_ops.h"
26 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
27 static const char ice_driver_string[] = DRV_SUMMARY;
28 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
30 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
31 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
32 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
34 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
35 MODULE_DESCRIPTION(DRV_SUMMARY);
36 MODULE_LICENSE("GPL v2");
37 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
39 static int debug = -1;
40 module_param(debug, int, 0644);
41 #ifndef CONFIG_DYNAMIC_DEBUG
42 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
44 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
45 #endif /* !CONFIG_DYNAMIC_DEBUG */
47 static DEFINE_IDA(ice_aux_ida);
48 DEFINE_STATIC_KEY_FALSE(ice_xdp_locking_key);
49 EXPORT_SYMBOL(ice_xdp_locking_key);
52 * ice_hw_to_dev - Get device pointer from the hardware structure
53 * @hw: pointer to the device HW structure
55 * Used to access the device pointer from compilation units which can't easily
56 * include the definition of struct ice_pf without leading to circular header
59 struct device *ice_hw_to_dev(struct ice_hw *hw)
61 struct ice_pf *pf = container_of(hw, struct ice_pf, hw);
63 return &pf->pdev->dev;
66 static struct workqueue_struct *ice_wq;
67 static const struct net_device_ops ice_netdev_safe_mode_ops;
68 static const struct net_device_ops ice_netdev_ops;
70 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
72 static void ice_vsi_release_all(struct ice_pf *pf);
74 static int ice_rebuild_channels(struct ice_pf *pf);
75 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_adv_fltr);
78 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
79 void *cb_priv, enum tc_setup_type type, void *type_data,
81 void (*cleanup)(struct flow_block_cb *block_cb));
83 bool netif_is_ice(struct net_device *dev)
85 return dev && (dev->netdev_ops == &ice_netdev_ops);
89 * ice_get_tx_pending - returns number of Tx descriptors not processed
90 * @ring: the ring of descriptors
92 static u16 ice_get_tx_pending(struct ice_tx_ring *ring)
96 head = ring->next_to_clean;
97 tail = ring->next_to_use;
100 return (head < tail) ?
101 tail - head : (tail + ring->count - head);
106 * ice_check_for_hang_subtask - check for and recover hung queues
107 * @pf: pointer to PF struct
109 static void ice_check_for_hang_subtask(struct ice_pf *pf)
111 struct ice_vsi *vsi = NULL;
117 ice_for_each_vsi(pf, v)
118 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
123 if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state))
126 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
131 ice_for_each_txq(vsi, i) {
132 struct ice_tx_ring *tx_ring = vsi->tx_rings[i];
136 if (ice_ring_ch_enabled(tx_ring))
140 /* If packet counter has not changed the queue is
141 * likely stalled, so force an interrupt for this
144 * prev_pkt would be negative if there was no
147 packets = tx_ring->stats.pkts & INT_MAX;
148 if (tx_ring->tx_stats.prev_pkt == packets) {
149 /* Trigger sw interrupt to revive the queue */
150 ice_trigger_sw_intr(hw, tx_ring->q_vector);
154 /* Memory barrier between read of packet count and call
155 * to ice_get_tx_pending()
158 tx_ring->tx_stats.prev_pkt =
159 ice_get_tx_pending(tx_ring) ? packets : -1;
165 * ice_init_mac_fltr - Set initial MAC filters
166 * @pf: board private structure
168 * Set initial set of MAC filters for PF VSI; configure filters for permanent
169 * address and broadcast address. If an error is encountered, netdevice will be
172 static int ice_init_mac_fltr(struct ice_pf *pf)
177 vsi = ice_get_main_vsi(pf);
181 perm_addr = vsi->port_info->mac.perm_addr;
182 return ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
186 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
187 * @netdev: the net device on which the sync is happening
188 * @addr: MAC address to sync
190 * This is a callback function which is called by the in kernel device sync
191 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
192 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
193 * MAC filters from the hardware.
195 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
197 struct ice_netdev_priv *np = netdev_priv(netdev);
198 struct ice_vsi *vsi = np->vsi;
200 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
208 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
209 * @netdev: the net device on which the unsync is happening
210 * @addr: MAC address to unsync
212 * This is a callback function which is called by the in kernel device unsync
213 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
214 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
215 * delete the MAC filters from the hardware.
217 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
219 struct ice_netdev_priv *np = netdev_priv(netdev);
220 struct ice_vsi *vsi = np->vsi;
222 /* Under some circumstances, we might receive a request to delete our
223 * own device address from our uc list. Because we store the device
224 * address in the VSI's MAC filter list, we need to ignore such
225 * requests and not delete our device address from this list.
227 if (ether_addr_equal(addr, netdev->dev_addr))
230 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
238 * ice_vsi_fltr_changed - check if filter state changed
239 * @vsi: VSI to be checked
241 * returns true if filter state has changed, false otherwise.
243 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
245 return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) ||
246 test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
250 * ice_set_promisc - Enable promiscuous mode for a given PF
251 * @vsi: the VSI being configured
252 * @promisc_m: mask of promiscuous config bits
255 static int ice_set_promisc(struct ice_vsi *vsi, u8 promisc_m)
259 if (vsi->type != ICE_VSI_PF)
262 if (ice_vsi_has_non_zero_vlans(vsi)) {
263 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX);
264 status = ice_fltr_set_vlan_vsi_promisc(&vsi->back->hw, vsi,
267 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
275 * ice_clear_promisc - Disable promiscuous mode for a given PF
276 * @vsi: the VSI being configured
277 * @promisc_m: mask of promiscuous config bits
280 static int ice_clear_promisc(struct ice_vsi *vsi, u8 promisc_m)
284 if (vsi->type != ICE_VSI_PF)
287 if (ice_vsi_has_non_zero_vlans(vsi)) {
288 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX);
289 status = ice_fltr_clear_vlan_vsi_promisc(&vsi->back->hw, vsi,
292 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
300 * ice_get_devlink_port - Get devlink port from netdev
301 * @netdev: the netdevice structure
303 static struct devlink_port *ice_get_devlink_port(struct net_device *netdev)
305 struct ice_pf *pf = ice_netdev_to_pf(netdev);
307 if (!ice_is_switchdev_running(pf))
310 return &pf->devlink_port;
314 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
315 * @vsi: ptr to the VSI
317 * Push any outstanding VSI filter changes through the AdminQ.
319 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
321 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
322 struct device *dev = ice_pf_to_dev(vsi->back);
323 struct net_device *netdev = vsi->netdev;
324 bool promisc_forced_on = false;
325 struct ice_pf *pf = vsi->back;
326 struct ice_hw *hw = &pf->hw;
327 u32 changed_flags = 0;
333 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
334 usleep_range(1000, 2000);
336 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
337 vsi->current_netdev_flags = vsi->netdev->flags;
339 INIT_LIST_HEAD(&vsi->tmp_sync_list);
340 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
342 if (ice_vsi_fltr_changed(vsi)) {
343 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
344 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
346 /* grab the netdev's addr_list_lock */
347 netif_addr_lock_bh(netdev);
348 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
349 ice_add_mac_to_unsync_list);
350 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
351 ice_add_mac_to_unsync_list);
352 /* our temp lists are populated. release lock */
353 netif_addr_unlock_bh(netdev);
356 /* Remove MAC addresses in the unsync list */
357 err = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
358 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
360 netdev_err(netdev, "Failed to delete MAC filters\n");
361 /* if we failed because of alloc failures, just bail */
366 /* Add MAC addresses in the sync list */
367 err = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
368 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
369 /* If filter is added successfully or already exists, do not go into
370 * 'if' condition and report it as error. Instead continue processing
371 * rest of the function.
373 if (err && err != -EEXIST) {
374 netdev_err(netdev, "Failed to add MAC filters\n");
375 /* If there is no more space for new umac filters, VSI
376 * should go into promiscuous mode. There should be some
377 * space reserved for promiscuous filters.
379 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
380 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC,
382 promisc_forced_on = true;
383 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
390 /* check for changes in promiscuous modes */
391 if (changed_flags & IFF_ALLMULTI) {
392 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
393 err = ice_set_promisc(vsi, ICE_MCAST_PROMISC_BITS);
395 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
399 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
400 err = ice_clear_promisc(vsi, ICE_MCAST_PROMISC_BITS);
402 vsi->current_netdev_flags |= IFF_ALLMULTI;
408 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
409 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) {
410 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
411 if (vsi->current_netdev_flags & IFF_PROMISC) {
412 /* Apply Rx filter rule to get traffic from wire */
413 if (!ice_is_dflt_vsi_in_use(vsi->port_info)) {
414 err = ice_set_dflt_vsi(vsi);
415 if (err && err != -EEXIST) {
416 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
418 vsi->current_netdev_flags &=
423 vlan_ops->dis_rx_filtering(vsi);
426 /* Clear Rx filter to remove traffic from wire */
427 if (ice_is_vsi_dflt_vsi(vsi)) {
428 err = ice_clear_dflt_vsi(vsi);
430 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
432 vsi->current_netdev_flags |=
436 if (vsi->netdev->features &
437 NETIF_F_HW_VLAN_CTAG_FILTER)
438 vlan_ops->ena_rx_filtering(vsi);
445 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
448 /* if something went wrong then set the changed flag so we try again */
449 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
450 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
452 clear_bit(ICE_CFG_BUSY, vsi->state);
457 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
458 * @pf: board private structure
460 static void ice_sync_fltr_subtask(struct ice_pf *pf)
464 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
467 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
469 ice_for_each_vsi(pf, v)
470 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
471 ice_vsi_sync_fltr(pf->vsi[v])) {
472 /* come back and try again later */
473 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
479 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
481 * @locked: is the rtnl_lock already held
483 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
488 ice_for_each_vsi(pf, v)
490 ice_dis_vsi(pf->vsi[v], locked);
492 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++)
493 pf->pf_agg_node[node].num_vsis = 0;
495 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++)
496 pf->vf_agg_node[node].num_vsis = 0;
500 * ice_clear_sw_switch_recipes - clear switch recipes
501 * @pf: board private structure
503 * Mark switch recipes as not created in sw structures. There are cases where
504 * rules (especially advanced rules) need to be restored, either re-read from
505 * hardware or added again. For example after the reset. 'recp_created' flag
506 * prevents from doing that and need to be cleared upfront.
508 static void ice_clear_sw_switch_recipes(struct ice_pf *pf)
510 struct ice_sw_recipe *recp;
513 recp = pf->hw.switch_info->recp_list;
514 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
515 recp[i].recp_created = false;
519 * ice_prepare_for_reset - prep for reset
520 * @pf: board private structure
521 * @reset_type: reset type requested
523 * Inform or close all dependent features in prep for reset.
526 ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
528 struct ice_hw *hw = &pf->hw;
533 dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type);
535 /* already prepared for reset */
536 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state))
539 ice_unplug_aux_dev(pf);
541 /* Notify VFs of impending reset */
542 if (ice_check_sq_alive(hw, &hw->mailboxq))
543 ice_vc_notify_reset(pf);
545 /* Disable VFs until reset is completed */
546 mutex_lock(&pf->vfs.table_lock);
547 ice_for_each_vf(pf, bkt, vf)
548 ice_set_vf_state_qs_dis(vf);
549 mutex_unlock(&pf->vfs.table_lock);
551 if (ice_is_eswitch_mode_switchdev(pf)) {
552 if (reset_type != ICE_RESET_PFR)
553 ice_clear_sw_switch_recipes(pf);
556 /* release ADQ specific HW and SW resources */
557 vsi = ice_get_main_vsi(pf);
561 /* to be on safe side, reset orig_rss_size so that normal flow
562 * of deciding rss_size can take precedence
564 vsi->orig_rss_size = 0;
566 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
567 if (reset_type == ICE_RESET_PFR) {
568 vsi->old_ena_tc = vsi->all_enatc;
569 vsi->old_numtc = vsi->all_numtc;
571 ice_remove_q_channels(vsi, true);
573 /* for other reset type, do not support channel rebuild
574 * hence reset needed info
582 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
583 memset(&vsi->mqprio_qopt, 0, sizeof(vsi->mqprio_qopt));
588 /* clear SW filtering DB */
589 ice_clear_hw_tbls(hw);
590 /* disable the VSIs and their queues that are not already DOWN */
591 ice_pf_dis_all_vsi(pf, false);
593 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
594 ice_ptp_prepare_for_reset(pf);
596 if (ice_is_feature_supported(pf, ICE_F_GNSS))
600 ice_sched_clear_port(hw->port_info);
602 ice_shutdown_all_ctrlq(hw);
604 set_bit(ICE_PREPARED_FOR_RESET, pf->state);
608 * ice_do_reset - Initiate one of many types of resets
609 * @pf: board private structure
610 * @reset_type: reset type requested before this function was called.
612 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
614 struct device *dev = ice_pf_to_dev(pf);
615 struct ice_hw *hw = &pf->hw;
617 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
619 ice_prepare_for_reset(pf, reset_type);
621 /* trigger the reset */
622 if (ice_reset(hw, reset_type)) {
623 dev_err(dev, "reset %d failed\n", reset_type);
624 set_bit(ICE_RESET_FAILED, pf->state);
625 clear_bit(ICE_RESET_OICR_RECV, pf->state);
626 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
627 clear_bit(ICE_PFR_REQ, pf->state);
628 clear_bit(ICE_CORER_REQ, pf->state);
629 clear_bit(ICE_GLOBR_REQ, pf->state);
630 wake_up(&pf->reset_wait_queue);
634 /* PFR is a bit of a special case because it doesn't result in an OICR
635 * interrupt. So for PFR, rebuild after the reset and clear the reset-
636 * associated state bits.
638 if (reset_type == ICE_RESET_PFR) {
640 ice_rebuild(pf, reset_type);
641 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
642 clear_bit(ICE_PFR_REQ, pf->state);
643 wake_up(&pf->reset_wait_queue);
644 ice_reset_all_vfs(pf);
649 * ice_reset_subtask - Set up for resetting the device and driver
650 * @pf: board private structure
652 static void ice_reset_subtask(struct ice_pf *pf)
654 enum ice_reset_req reset_type = ICE_RESET_INVAL;
656 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
657 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
658 * of reset is pending and sets bits in pf->state indicating the reset
659 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set
660 * prepare for pending reset if not already (for PF software-initiated
661 * global resets the software should already be prepared for it as
662 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated
663 * by firmware or software on other PFs, that bit is not set so prepare
664 * for the reset now), poll for reset done, rebuild and return.
666 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) {
667 /* Perform the largest reset requested */
668 if (test_and_clear_bit(ICE_CORER_RECV, pf->state))
669 reset_type = ICE_RESET_CORER;
670 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state))
671 reset_type = ICE_RESET_GLOBR;
672 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state))
673 reset_type = ICE_RESET_EMPR;
674 /* return if no valid reset type requested */
675 if (reset_type == ICE_RESET_INVAL)
677 ice_prepare_for_reset(pf, reset_type);
679 /* make sure we are ready to rebuild */
680 if (ice_check_reset(&pf->hw)) {
681 set_bit(ICE_RESET_FAILED, pf->state);
683 /* done with reset. start rebuild */
684 pf->hw.reset_ongoing = false;
685 ice_rebuild(pf, reset_type);
686 /* clear bit to resume normal operations, but
687 * ICE_NEEDS_RESTART bit is set in case rebuild failed
689 clear_bit(ICE_RESET_OICR_RECV, pf->state);
690 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
691 clear_bit(ICE_PFR_REQ, pf->state);
692 clear_bit(ICE_CORER_REQ, pf->state);
693 clear_bit(ICE_GLOBR_REQ, pf->state);
694 wake_up(&pf->reset_wait_queue);
695 ice_reset_all_vfs(pf);
701 /* No pending resets to finish processing. Check for new resets */
702 if (test_bit(ICE_PFR_REQ, pf->state))
703 reset_type = ICE_RESET_PFR;
704 if (test_bit(ICE_CORER_REQ, pf->state))
705 reset_type = ICE_RESET_CORER;
706 if (test_bit(ICE_GLOBR_REQ, pf->state))
707 reset_type = ICE_RESET_GLOBR;
708 /* If no valid reset type requested just return */
709 if (reset_type == ICE_RESET_INVAL)
712 /* reset if not already down or busy */
713 if (!test_bit(ICE_DOWN, pf->state) &&
714 !test_bit(ICE_CFG_BUSY, pf->state)) {
715 ice_do_reset(pf, reset_type);
720 * ice_print_topo_conflict - print topology conflict message
721 * @vsi: the VSI whose topology status is being checked
723 static void ice_print_topo_conflict(struct ice_vsi *vsi)
725 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
726 case ICE_AQ_LINK_TOPO_CONFLICT:
727 case ICE_AQ_LINK_MEDIA_CONFLICT:
728 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
729 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
730 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
731 netdev_info(vsi->netdev, "Potential misconfiguration of the Ethernet port detected. If it was not intended, please use the Intel (R) Ethernet Port Configuration Tool to address the issue.\n");
733 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
734 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, vsi->back->flags))
735 netdev_warn(vsi->netdev, "An unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules\n");
737 netdev_err(vsi->netdev, "Rx/Tx is disabled on this device because an unsupported module type was detected. Refer to the Intel(R) Ethernet Adapters and Devices User Guide for a list of supported modules.\n");
745 * ice_print_link_msg - print link up or down message
746 * @vsi: the VSI whose link status is being queried
747 * @isup: boolean for if the link is now up or down
749 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
751 struct ice_aqc_get_phy_caps_data *caps;
752 const char *an_advertised;
763 if (vsi->current_isup == isup)
766 vsi->current_isup = isup;
769 netdev_info(vsi->netdev, "NIC Link is Down\n");
773 switch (vsi->port_info->phy.link_info.link_speed) {
774 case ICE_AQ_LINK_SPEED_100GB:
777 case ICE_AQ_LINK_SPEED_50GB:
780 case ICE_AQ_LINK_SPEED_40GB:
783 case ICE_AQ_LINK_SPEED_25GB:
786 case ICE_AQ_LINK_SPEED_20GB:
789 case ICE_AQ_LINK_SPEED_10GB:
792 case ICE_AQ_LINK_SPEED_5GB:
795 case ICE_AQ_LINK_SPEED_2500MB:
798 case ICE_AQ_LINK_SPEED_1000MB:
801 case ICE_AQ_LINK_SPEED_100MB:
809 switch (vsi->port_info->fc.current_mode) {
813 case ICE_FC_TX_PAUSE:
816 case ICE_FC_RX_PAUSE:
827 /* Get FEC mode based on negotiated link info */
828 switch (vsi->port_info->phy.link_info.fec_info) {
829 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
830 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
833 case ICE_AQ_LINK_25G_KR_FEC_EN:
834 fec = "FC-FEC/BASE-R";
841 /* check if autoneg completed, might be false due to not supported */
842 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
847 /* Get FEC mode requested based on PHY caps last SW configuration */
848 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
851 an_advertised = "Unknown";
855 status = ice_aq_get_phy_caps(vsi->port_info, false,
856 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
858 netdev_info(vsi->netdev, "Get phy capability failed.\n");
860 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off";
862 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
863 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
865 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
866 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
867 fec_req = "FC-FEC/BASE-R";
874 netdev_info(vsi->netdev, "NIC Link is up %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg Advertised: %s, Autoneg Negotiated: %s, Flow Control: %s\n",
875 speed, fec_req, fec, an_advertised, an, fc);
876 ice_print_topo_conflict(vsi);
880 * ice_vsi_link_event - update the VSI's netdev
881 * @vsi: the VSI on which the link event occurred
882 * @link_up: whether or not the VSI needs to be set up or down
884 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
889 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev)
892 if (vsi->type == ICE_VSI_PF) {
893 if (link_up == netif_carrier_ok(vsi->netdev))
897 netif_carrier_on(vsi->netdev);
898 netif_tx_wake_all_queues(vsi->netdev);
900 netif_carrier_off(vsi->netdev);
901 netif_tx_stop_all_queues(vsi->netdev);
907 * ice_set_dflt_mib - send a default config MIB to the FW
908 * @pf: private PF struct
910 * This function sends a default configuration MIB to the FW.
912 * If this function errors out at any point, the driver is still able to
913 * function. The main impact is that LFC may not operate as expected.
914 * Therefore an error state in this function should be treated with a DBG
915 * message and continue on with driver rebuild/reenable.
917 static void ice_set_dflt_mib(struct ice_pf *pf)
919 struct device *dev = ice_pf_to_dev(pf);
920 u8 mib_type, *buf, *lldpmib = NULL;
921 u16 len, typelen, offset = 0;
922 struct ice_lldp_org_tlv *tlv;
923 struct ice_hw *hw = &pf->hw;
926 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
927 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
929 dev_dbg(dev, "%s Failed to allocate MIB memory\n",
934 /* Add ETS CFG TLV */
935 tlv = (struct ice_lldp_org_tlv *)lldpmib;
936 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
937 ICE_IEEE_ETS_TLV_LEN);
938 tlv->typelen = htons(typelen);
939 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
940 ICE_IEEE_SUBTYPE_ETS_CFG);
941 tlv->ouisubtype = htonl(ouisubtype);
946 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0.
947 * Octets 5 - 12 are BW values, set octet 5 to 100% BW.
948 * Octets 13 - 20 are TSA values - leave as zeros
951 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
953 tlv = (struct ice_lldp_org_tlv *)
954 ((char *)tlv + sizeof(tlv->typelen) + len);
956 /* Add ETS REC TLV */
958 tlv->typelen = htons(typelen);
960 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
961 ICE_IEEE_SUBTYPE_ETS_REC);
962 tlv->ouisubtype = htonl(ouisubtype);
964 /* First octet of buf is reserved
965 * Octets 1 - 4 map UP to TC - all UPs map to zero
966 * Octets 5 - 12 are BW values - set TC 0 to 100%.
967 * Octets 13 - 20 are TSA value - leave as zeros
971 tlv = (struct ice_lldp_org_tlv *)
972 ((char *)tlv + sizeof(tlv->typelen) + len);
974 /* Add PFC CFG TLV */
975 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
976 ICE_IEEE_PFC_TLV_LEN);
977 tlv->typelen = htons(typelen);
979 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
980 ICE_IEEE_SUBTYPE_PFC_CFG);
981 tlv->ouisubtype = htonl(ouisubtype);
983 /* Octet 1 left as all zeros - PFC disabled */
985 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
988 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL))
989 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__);
995 * ice_check_phy_fw_load - check if PHY FW load failed
996 * @pf: pointer to PF struct
997 * @link_cfg_err: bitmap from the link info structure
999 * check if external PHY FW load failed and print an error message if it did
1001 static void ice_check_phy_fw_load(struct ice_pf *pf, u8 link_cfg_err)
1003 if (!(link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE)) {
1004 clear_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
1008 if (test_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags))
1011 if (link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE) {
1012 dev_err(ice_pf_to_dev(pf), "Device failed to load the FW for the external PHY. Please download and install the latest NVM for your device and try again\n");
1013 set_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
1018 * ice_check_module_power
1019 * @pf: pointer to PF struct
1020 * @link_cfg_err: bitmap from the link info structure
1022 * check module power level returned by a previous call to aq_get_link_info
1023 * and print error messages if module power level is not supported
1025 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err)
1027 /* if module power level is supported, clear the flag */
1028 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT |
1029 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) {
1030 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1034 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the
1035 * above block didn't clear this bit, there's nothing to do
1037 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags))
1040 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) {
1041 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n");
1042 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1043 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) {
1044 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n");
1045 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1050 * ice_check_link_cfg_err - check if link configuration failed
1051 * @pf: pointer to the PF struct
1052 * @link_cfg_err: bitmap from the link info structure
1054 * print if any link configuration failure happens due to the value in the
1055 * link_cfg_err parameter in the link info structure
1057 static void ice_check_link_cfg_err(struct ice_pf *pf, u8 link_cfg_err)
1059 ice_check_module_power(pf, link_cfg_err);
1060 ice_check_phy_fw_load(pf, link_cfg_err);
1064 * ice_link_event - process the link event
1065 * @pf: PF that the link event is associated with
1066 * @pi: port_info for the port that the link event is associated with
1067 * @link_up: true if the physical link is up and false if it is down
1068 * @link_speed: current link speed received from the link event
1070 * Returns 0 on success and negative on failure
1073 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
1076 struct device *dev = ice_pf_to_dev(pf);
1077 struct ice_phy_info *phy_info;
1078 struct ice_vsi *vsi;
1083 phy_info = &pi->phy;
1084 phy_info->link_info_old = phy_info->link_info;
1086 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
1087 old_link_speed = phy_info->link_info_old.link_speed;
1089 /* update the link info structures and re-enable link events,
1090 * don't bail on failure due to other book keeping needed
1092 status = ice_update_link_info(pi);
1094 dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n",
1096 ice_aq_str(pi->hw->adminq.sq_last_status));
1098 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
1100 /* Check if the link state is up after updating link info, and treat
1101 * this event as an UP event since the link is actually UP now.
1103 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
1106 vsi = ice_get_main_vsi(pf);
1107 if (!vsi || !vsi->port_info)
1110 /* turn off PHY if media was removed */
1111 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
1112 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
1113 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1114 ice_set_link(vsi, false);
1117 /* if the old link up/down and speed is the same as the new */
1118 if (link_up == old_link && link_speed == old_link_speed)
1121 if (!ice_is_e810(&pf->hw))
1122 ice_ptp_link_change(pf, pf->hw.pf_id, link_up);
1124 if (ice_is_dcb_active(pf)) {
1125 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
1126 ice_dcb_rebuild(pf);
1129 ice_set_dflt_mib(pf);
1131 ice_vsi_link_event(vsi, link_up);
1132 ice_print_link_msg(vsi, link_up);
1134 ice_vc_notify_link_state(pf);
1140 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
1141 * @pf: board private structure
1143 static void ice_watchdog_subtask(struct ice_pf *pf)
1147 /* if interface is down do nothing */
1148 if (test_bit(ICE_DOWN, pf->state) ||
1149 test_bit(ICE_CFG_BUSY, pf->state))
1152 /* make sure we don't do these things too often */
1153 if (time_before(jiffies,
1154 pf->serv_tmr_prev + pf->serv_tmr_period))
1157 pf->serv_tmr_prev = jiffies;
1159 /* Update the stats for active netdevs so the network stack
1160 * can look at updated numbers whenever it cares to
1162 ice_update_pf_stats(pf);
1163 ice_for_each_vsi(pf, i)
1164 if (pf->vsi[i] && pf->vsi[i]->netdev)
1165 ice_update_vsi_stats(pf->vsi[i]);
1169 * ice_init_link_events - enable/initialize link events
1170 * @pi: pointer to the port_info instance
1172 * Returns -EIO on failure, 0 on success
1174 static int ice_init_link_events(struct ice_port_info *pi)
1178 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
1179 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL |
1180 ICE_AQ_LINK_EVENT_PHY_FW_LOAD_FAIL));
1182 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
1183 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
1188 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
1189 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
1198 * ice_handle_link_event - handle link event via ARQ
1199 * @pf: PF that the link event is associated with
1200 * @event: event structure containing link status info
1203 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1205 struct ice_aqc_get_link_status_data *link_data;
1206 struct ice_port_info *port_info;
1209 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
1210 port_info = pf->hw.port_info;
1214 status = ice_link_event(pf, port_info,
1215 !!(link_data->link_info & ICE_AQ_LINK_UP),
1216 le16_to_cpu(link_data->link_speed));
1218 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
1224 enum ice_aq_task_state {
1225 ICE_AQ_TASK_WAITING = 0,
1226 ICE_AQ_TASK_COMPLETE,
1227 ICE_AQ_TASK_CANCELED,
1230 struct ice_aq_task {
1231 struct hlist_node entry;
1234 struct ice_rq_event_info *event;
1235 enum ice_aq_task_state state;
1239 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1240 * @pf: pointer to the PF private structure
1241 * @opcode: the opcode to wait for
1242 * @timeout: how long to wait, in jiffies
1243 * @event: storage for the event info
1245 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1246 * current thread will be put to sleep until the specified event occurs or
1247 * until the given timeout is reached.
1249 * To obtain only the descriptor contents, pass an event without an allocated
1250 * msg_buf. If the complete data buffer is desired, allocate the
1251 * event->msg_buf with enough space ahead of time.
1253 * Returns: zero on success, or a negative error code on failure.
1255 int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout,
1256 struct ice_rq_event_info *event)
1258 struct device *dev = ice_pf_to_dev(pf);
1259 struct ice_aq_task *task;
1260 unsigned long start;
1264 task = kzalloc(sizeof(*task), GFP_KERNEL);
1268 INIT_HLIST_NODE(&task->entry);
1269 task->opcode = opcode;
1270 task->event = event;
1271 task->state = ICE_AQ_TASK_WAITING;
1273 spin_lock_bh(&pf->aq_wait_lock);
1274 hlist_add_head(&task->entry, &pf->aq_wait_list);
1275 spin_unlock_bh(&pf->aq_wait_lock);
1279 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state,
1281 switch (task->state) {
1282 case ICE_AQ_TASK_WAITING:
1283 err = ret < 0 ? ret : -ETIMEDOUT;
1285 case ICE_AQ_TASK_CANCELED:
1286 err = ret < 0 ? ret : -ECANCELED;
1288 case ICE_AQ_TASK_COMPLETE:
1289 err = ret < 0 ? ret : 0;
1292 WARN(1, "Unexpected AdminQ wait task state %u", task->state);
1297 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n",
1298 jiffies_to_msecs(jiffies - start),
1299 jiffies_to_msecs(timeout),
1302 spin_lock_bh(&pf->aq_wait_lock);
1303 hlist_del(&task->entry);
1304 spin_unlock_bh(&pf->aq_wait_lock);
1311 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event
1312 * @pf: pointer to the PF private structure
1313 * @opcode: the opcode of the event
1314 * @event: the event to check
1316 * Loops over the current list of pending threads waiting for an AdminQ event.
1317 * For each matching task, copy the contents of the event into the task
1318 * structure and wake up the thread.
1320 * If multiple threads wait for the same opcode, they will all be woken up.
1322 * Note that event->msg_buf will only be duplicated if the event has a buffer
1323 * with enough space already allocated. Otherwise, only the descriptor and
1324 * message length will be copied.
1326 * Returns: true if an event was found, false otherwise
1328 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1329 struct ice_rq_event_info *event)
1331 struct ice_aq_task *task;
1334 spin_lock_bh(&pf->aq_wait_lock);
1335 hlist_for_each_entry(task, &pf->aq_wait_list, entry) {
1336 if (task->state || task->opcode != opcode)
1339 memcpy(&task->event->desc, &event->desc, sizeof(event->desc));
1340 task->event->msg_len = event->msg_len;
1342 /* Only copy the data buffer if a destination was set */
1343 if (task->event->msg_buf &&
1344 task->event->buf_len > event->buf_len) {
1345 memcpy(task->event->msg_buf, event->msg_buf,
1347 task->event->buf_len = event->buf_len;
1350 task->state = ICE_AQ_TASK_COMPLETE;
1353 spin_unlock_bh(&pf->aq_wait_lock);
1356 wake_up(&pf->aq_wait_queue);
1360 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks
1361 * @pf: the PF private structure
1363 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads.
1364 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED.
1366 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
1368 struct ice_aq_task *task;
1370 spin_lock_bh(&pf->aq_wait_lock);
1371 hlist_for_each_entry(task, &pf->aq_wait_list, entry)
1372 task->state = ICE_AQ_TASK_CANCELED;
1373 spin_unlock_bh(&pf->aq_wait_lock);
1375 wake_up(&pf->aq_wait_queue);
1379 * __ice_clean_ctrlq - helper function to clean controlq rings
1380 * @pf: ptr to struct ice_pf
1381 * @q_type: specific Control queue type
1383 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
1385 struct device *dev = ice_pf_to_dev(pf);
1386 struct ice_rq_event_info event;
1387 struct ice_hw *hw = &pf->hw;
1388 struct ice_ctl_q_info *cq;
1393 /* Do not clean control queue if/when PF reset fails */
1394 if (test_bit(ICE_RESET_FAILED, pf->state))
1398 case ICE_CTL_Q_ADMIN:
1406 case ICE_CTL_Q_MAILBOX:
1409 /* we are going to try to detect a malicious VF, so set the
1410 * state to begin detection
1412 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT;
1415 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
1419 /* check for error indications - PF_xx_AxQLEN register layout for
1420 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
1422 val = rd32(hw, cq->rq.len);
1423 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1424 PF_FW_ARQLEN_ARQCRIT_M)) {
1426 if (val & PF_FW_ARQLEN_ARQVFE_M)
1427 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
1429 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1430 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
1433 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1434 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
1436 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1437 PF_FW_ARQLEN_ARQCRIT_M);
1439 wr32(hw, cq->rq.len, val);
1442 val = rd32(hw, cq->sq.len);
1443 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1444 PF_FW_ATQLEN_ATQCRIT_M)) {
1446 if (val & PF_FW_ATQLEN_ATQVFE_M)
1447 dev_dbg(dev, "%s Send Queue VF Error detected\n",
1449 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1450 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1453 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1454 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1456 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1457 PF_FW_ATQLEN_ATQCRIT_M);
1459 wr32(hw, cq->sq.len, val);
1462 event.buf_len = cq->rq_buf_size;
1463 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1471 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1472 if (ret == -EALREADY)
1475 dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1480 opcode = le16_to_cpu(event.desc.opcode);
1482 /* Notify any thread that might be waiting for this event */
1483 ice_aq_check_events(pf, opcode, &event);
1486 case ice_aqc_opc_get_link_status:
1487 if (ice_handle_link_event(pf, &event))
1488 dev_err(dev, "Could not handle link event\n");
1490 case ice_aqc_opc_event_lan_overflow:
1491 ice_vf_lan_overflow_event(pf, &event);
1493 case ice_mbx_opc_send_msg_to_pf:
1494 if (!ice_is_malicious_vf(pf, &event, i, pending))
1495 ice_vc_process_vf_msg(pf, &event);
1497 case ice_aqc_opc_fw_logging:
1498 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1500 case ice_aqc_opc_lldp_set_mib_change:
1501 ice_dcb_process_lldp_set_mib_change(pf, &event);
1504 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1508 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1510 kfree(event.msg_buf);
1512 return pending && (i == ICE_DFLT_IRQ_WORK);
1516 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1517 * @hw: pointer to hardware info
1518 * @cq: control queue information
1520 * returns true if there are pending messages in a queue, false if there aren't
1522 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1526 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1527 return cq->rq.next_to_clean != ntu;
1531 * ice_clean_adminq_subtask - clean the AdminQ rings
1532 * @pf: board private structure
1534 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1536 struct ice_hw *hw = &pf->hw;
1538 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
1541 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1544 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
1546 /* There might be a situation where new messages arrive to a control
1547 * queue between processing the last message and clearing the
1548 * EVENT_PENDING bit. So before exiting, check queue head again (using
1549 * ice_ctrlq_pending) and process new messages if any.
1551 if (ice_ctrlq_pending(hw, &hw->adminq))
1552 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1558 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1559 * @pf: board private structure
1561 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1563 struct ice_hw *hw = &pf->hw;
1565 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1568 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1571 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1573 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1574 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1580 * ice_clean_sbq_subtask - clean the Sideband Queue rings
1581 * @pf: board private structure
1583 static void ice_clean_sbq_subtask(struct ice_pf *pf)
1585 struct ice_hw *hw = &pf->hw;
1587 /* Nothing to do here if sideband queue is not supported */
1588 if (!ice_is_sbq_supported(hw)) {
1589 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1593 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state))
1596 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB))
1599 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1601 if (ice_ctrlq_pending(hw, &hw->sbq))
1602 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB);
1608 * ice_service_task_schedule - schedule the service task to wake up
1609 * @pf: board private structure
1611 * If not already scheduled, this puts the task into the work queue.
1613 void ice_service_task_schedule(struct ice_pf *pf)
1615 if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
1616 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
1617 !test_bit(ICE_NEEDS_RESTART, pf->state))
1618 queue_work(ice_wq, &pf->serv_task);
1622 * ice_service_task_complete - finish up the service task
1623 * @pf: board private structure
1625 static void ice_service_task_complete(struct ice_pf *pf)
1627 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state));
1629 /* force memory (pf->state) to sync before next service task */
1630 smp_mb__before_atomic();
1631 clear_bit(ICE_SERVICE_SCHED, pf->state);
1635 * ice_service_task_stop - stop service task and cancel works
1636 * @pf: board private structure
1638 * Return 0 if the ICE_SERVICE_DIS bit was not already set,
1641 static int ice_service_task_stop(struct ice_pf *pf)
1645 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state);
1647 if (pf->serv_tmr.function)
1648 del_timer_sync(&pf->serv_tmr);
1649 if (pf->serv_task.func)
1650 cancel_work_sync(&pf->serv_task);
1652 clear_bit(ICE_SERVICE_SCHED, pf->state);
1657 * ice_service_task_restart - restart service task and schedule works
1658 * @pf: board private structure
1660 * This function is needed for suspend and resume works (e.g WoL scenario)
1662 static void ice_service_task_restart(struct ice_pf *pf)
1664 clear_bit(ICE_SERVICE_DIS, pf->state);
1665 ice_service_task_schedule(pf);
1669 * ice_service_timer - timer callback to schedule service task
1670 * @t: pointer to timer_list
1672 static void ice_service_timer(struct timer_list *t)
1674 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1676 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1677 ice_service_task_schedule(pf);
1681 * ice_handle_mdd_event - handle malicious driver detect event
1682 * @pf: pointer to the PF structure
1684 * Called from service task. OICR interrupt handler indicates MDD event.
1685 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1686 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1687 * disable the queue, the PF can be configured to reset the VF using ethtool
1688 * private flag mdd-auto-reset-vf.
1690 static void ice_handle_mdd_event(struct ice_pf *pf)
1692 struct device *dev = ice_pf_to_dev(pf);
1693 struct ice_hw *hw = &pf->hw;
1698 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
1699 /* Since the VF MDD event logging is rate limited, check if
1700 * there are pending MDD events.
1702 ice_print_vfs_mdd_events(pf);
1706 /* find what triggered an MDD event */
1707 reg = rd32(hw, GL_MDET_TX_PQM);
1708 if (reg & GL_MDET_TX_PQM_VALID_M) {
1709 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1710 GL_MDET_TX_PQM_PF_NUM_S;
1711 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1712 GL_MDET_TX_PQM_VF_NUM_S;
1713 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1714 GL_MDET_TX_PQM_MAL_TYPE_S;
1715 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1716 GL_MDET_TX_PQM_QNUM_S);
1718 if (netif_msg_tx_err(pf))
1719 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1720 event, queue, pf_num, vf_num);
1721 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1724 reg = rd32(hw, GL_MDET_TX_TCLAN);
1725 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1726 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1727 GL_MDET_TX_TCLAN_PF_NUM_S;
1728 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1729 GL_MDET_TX_TCLAN_VF_NUM_S;
1730 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1731 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1732 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1733 GL_MDET_TX_TCLAN_QNUM_S);
1735 if (netif_msg_tx_err(pf))
1736 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1737 event, queue, pf_num, vf_num);
1738 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1741 reg = rd32(hw, GL_MDET_RX);
1742 if (reg & GL_MDET_RX_VALID_M) {
1743 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1744 GL_MDET_RX_PF_NUM_S;
1745 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1746 GL_MDET_RX_VF_NUM_S;
1747 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1748 GL_MDET_RX_MAL_TYPE_S;
1749 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1752 if (netif_msg_rx_err(pf))
1753 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1754 event, queue, pf_num, vf_num);
1755 wr32(hw, GL_MDET_RX, 0xffffffff);
1758 /* check to see if this PF caused an MDD event */
1759 reg = rd32(hw, PF_MDET_TX_PQM);
1760 if (reg & PF_MDET_TX_PQM_VALID_M) {
1761 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1762 if (netif_msg_tx_err(pf))
1763 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1766 reg = rd32(hw, PF_MDET_TX_TCLAN);
1767 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1768 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1769 if (netif_msg_tx_err(pf))
1770 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1773 reg = rd32(hw, PF_MDET_RX);
1774 if (reg & PF_MDET_RX_VALID_M) {
1775 wr32(hw, PF_MDET_RX, 0xFFFF);
1776 if (netif_msg_rx_err(pf))
1777 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1780 /* Check to see if one of the VFs caused an MDD event, and then
1781 * increment counters and set print pending
1783 mutex_lock(&pf->vfs.table_lock);
1784 ice_for_each_vf(pf, bkt, vf) {
1785 reg = rd32(hw, VP_MDET_TX_PQM(vf->vf_id));
1786 if (reg & VP_MDET_TX_PQM_VALID_M) {
1787 wr32(hw, VP_MDET_TX_PQM(vf->vf_id), 0xFFFF);
1788 vf->mdd_tx_events.count++;
1789 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1790 if (netif_msg_tx_err(pf))
1791 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1795 reg = rd32(hw, VP_MDET_TX_TCLAN(vf->vf_id));
1796 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1797 wr32(hw, VP_MDET_TX_TCLAN(vf->vf_id), 0xFFFF);
1798 vf->mdd_tx_events.count++;
1799 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1800 if (netif_msg_tx_err(pf))
1801 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1805 reg = rd32(hw, VP_MDET_TX_TDPU(vf->vf_id));
1806 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1807 wr32(hw, VP_MDET_TX_TDPU(vf->vf_id), 0xFFFF);
1808 vf->mdd_tx_events.count++;
1809 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1810 if (netif_msg_tx_err(pf))
1811 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1815 reg = rd32(hw, VP_MDET_RX(vf->vf_id));
1816 if (reg & VP_MDET_RX_VALID_M) {
1817 wr32(hw, VP_MDET_RX(vf->vf_id), 0xFFFF);
1818 vf->mdd_rx_events.count++;
1819 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1820 if (netif_msg_rx_err(pf))
1821 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1824 /* Since the queue is disabled on VF Rx MDD events, the
1825 * PF can be configured to reset the VF through ethtool
1826 * private flag mdd-auto-reset-vf.
1828 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) {
1829 /* VF MDD event counters will be cleared by
1830 * reset, so print the event prior to reset.
1832 ice_print_vf_rx_mdd_event(vf);
1833 ice_reset_vf(vf, ICE_VF_RESET_LOCK);
1837 mutex_unlock(&pf->vfs.table_lock);
1839 ice_print_vfs_mdd_events(pf);
1843 * ice_force_phys_link_state - Force the physical link state
1844 * @vsi: VSI to force the physical link state to up/down
1845 * @link_up: true/false indicates to set the physical link to up/down
1847 * Force the physical link state by getting the current PHY capabilities from
1848 * hardware and setting the PHY config based on the determined capabilities. If
1849 * link changes a link event will be triggered because both the Enable Automatic
1850 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1852 * Returns 0 on success, negative on failure
1854 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1856 struct ice_aqc_get_phy_caps_data *pcaps;
1857 struct ice_aqc_set_phy_cfg_data *cfg;
1858 struct ice_port_info *pi;
1862 if (!vsi || !vsi->port_info || !vsi->back)
1864 if (vsi->type != ICE_VSI_PF)
1867 dev = ice_pf_to_dev(vsi->back);
1869 pi = vsi->port_info;
1871 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1875 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1878 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1879 vsi->vsi_num, retcode);
1884 /* No change in link */
1885 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1886 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1889 /* Use the current user PHY configuration. The current user PHY
1890 * configuration is initialized during probe from PHY capabilities
1891 * software mode, and updated on set PHY configuration.
1893 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL);
1899 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1901 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1903 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1905 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL);
1907 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1908 vsi->vsi_num, retcode);
1919 * ice_init_nvm_phy_type - Initialize the NVM PHY type
1920 * @pi: port info structure
1922 * Initialize nvm_phy_type_[low|high] for link lenient mode support
1924 static int ice_init_nvm_phy_type(struct ice_port_info *pi)
1926 struct ice_aqc_get_phy_caps_data *pcaps;
1927 struct ice_pf *pf = pi->hw->back;
1930 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1934 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA,
1938 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
1942 pf->nvm_phy_type_hi = pcaps->phy_type_high;
1943 pf->nvm_phy_type_lo = pcaps->phy_type_low;
1951 * ice_init_link_dflt_override - Initialize link default override
1952 * @pi: port info structure
1954 * Initialize link default override and PHY total port shutdown during probe
1956 static void ice_init_link_dflt_override(struct ice_port_info *pi)
1958 struct ice_link_default_override_tlv *ldo;
1959 struct ice_pf *pf = pi->hw->back;
1961 ldo = &pf->link_dflt_override;
1962 if (ice_get_link_default_override(ldo, pi))
1965 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS))
1968 /* Enable Total Port Shutdown (override/replace link-down-on-close
1969 * ethtool private flag) for ports with Port Disable bit set.
1971 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags);
1972 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1976 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings
1977 * @pi: port info structure
1979 * If default override is enabled, initialize the user PHY cfg speed and FEC
1980 * settings using the default override mask from the NVM.
1982 * The PHY should only be configured with the default override settings the
1983 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state
1984 * is used to indicate that the user PHY cfg default override is initialized
1985 * and the PHY has not been configured with the default override settings. The
1986 * state is set here, and cleared in ice_configure_phy the first time the PHY is
1989 * This function should be called only if the FW doesn't support default
1990 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg.
1992 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi)
1994 struct ice_link_default_override_tlv *ldo;
1995 struct ice_aqc_set_phy_cfg_data *cfg;
1996 struct ice_phy_info *phy = &pi->phy;
1997 struct ice_pf *pf = pi->hw->back;
1999 ldo = &pf->link_dflt_override;
2001 /* If link default override is enabled, use to mask NVM PHY capabilities
2002 * for speed and FEC default configuration.
2004 cfg = &phy->curr_user_phy_cfg;
2006 if (ldo->phy_type_low || ldo->phy_type_high) {
2007 cfg->phy_type_low = pf->nvm_phy_type_lo &
2008 cpu_to_le64(ldo->phy_type_low);
2009 cfg->phy_type_high = pf->nvm_phy_type_hi &
2010 cpu_to_le64(ldo->phy_type_high);
2012 cfg->link_fec_opt = ldo->fec_options;
2013 phy->curr_user_fec_req = ICE_FEC_AUTO;
2015 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state);
2019 * ice_init_phy_user_cfg - Initialize the PHY user configuration
2020 * @pi: port info structure
2022 * Initialize the current user PHY configuration, speed, FEC, and FC requested
2023 * mode to default. The PHY defaults are from get PHY capabilities topology
2024 * with media so call when media is first available. An error is returned if
2025 * called when media is not available. The PHY initialization completed state is
2028 * These configurations are used when setting PHY
2029 * configuration. The user PHY configuration is updated on set PHY
2030 * configuration. Returns 0 on success, negative on failure
2032 static int ice_init_phy_user_cfg(struct ice_port_info *pi)
2034 struct ice_aqc_get_phy_caps_data *pcaps;
2035 struct ice_phy_info *phy = &pi->phy;
2036 struct ice_pf *pf = pi->hw->back;
2039 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2042 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2046 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2047 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2050 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2053 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
2057 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg);
2059 /* check if lenient mode is supported and enabled */
2060 if (ice_fw_supports_link_override(pi->hw) &&
2061 !(pcaps->module_compliance_enforcement &
2062 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) {
2063 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags);
2065 /* if the FW supports default PHY configuration mode, then the driver
2066 * does not have to apply link override settings. If not,
2067 * initialize user PHY configuration with link override values
2069 if (!ice_fw_supports_report_dflt_cfg(pi->hw) &&
2070 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) {
2071 ice_init_phy_cfg_dflt_override(pi);
2076 /* if link default override is not enabled, set user flow control and
2077 * FEC settings based on what get_phy_caps returned
2079 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps,
2080 pcaps->link_fec_options);
2081 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps);
2084 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M;
2085 set_bit(ICE_PHY_INIT_COMPLETE, pf->state);
2092 * ice_configure_phy - configure PHY
2095 * Set the PHY configuration. If the current PHY configuration is the same as
2096 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise
2097 * configure the based get PHY capabilities for topology with media.
2099 static int ice_configure_phy(struct ice_vsi *vsi)
2101 struct device *dev = ice_pf_to_dev(vsi->back);
2102 struct ice_port_info *pi = vsi->port_info;
2103 struct ice_aqc_get_phy_caps_data *pcaps;
2104 struct ice_aqc_set_phy_cfg_data *cfg;
2105 struct ice_phy_info *phy = &pi->phy;
2106 struct ice_pf *pf = vsi->back;
2109 /* Ensure we have media as we cannot configure a medialess port */
2110 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2113 ice_print_topo_conflict(vsi);
2115 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags) &&
2116 phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA)
2119 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags))
2120 return ice_force_phys_link_state(vsi, true);
2122 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2126 /* Get current PHY config */
2127 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2130 dev_err(dev, "Failed to get PHY configuration, VSI %d error %d\n",
2135 /* If PHY enable link is configured and configuration has not changed,
2136 * there's nothing to do
2138 if (pcaps->caps & ICE_AQC_PHY_EN_LINK &&
2139 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg))
2142 /* Use PHY topology as baseline for configuration */
2143 memset(pcaps, 0, sizeof(*pcaps));
2144 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2145 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2148 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2151 dev_err(dev, "Failed to get PHY caps, VSI %d error %d\n",
2156 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2162 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg);
2164 /* Speed - If default override pending, use curr_user_phy_cfg set in
2165 * ice_init_phy_user_cfg_ldo.
2167 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING,
2168 vsi->back->state)) {
2169 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low;
2170 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high;
2172 u64 phy_low = 0, phy_high = 0;
2174 ice_update_phy_type(&phy_low, &phy_high,
2175 pi->phy.curr_user_speed_req);
2176 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low);
2177 cfg->phy_type_high = pcaps->phy_type_high &
2178 cpu_to_le64(phy_high);
2181 /* Can't provide what was requested; use PHY capabilities */
2182 if (!cfg->phy_type_low && !cfg->phy_type_high) {
2183 cfg->phy_type_low = pcaps->phy_type_low;
2184 cfg->phy_type_high = pcaps->phy_type_high;
2188 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req);
2190 /* Can't provide what was requested; use PHY capabilities */
2191 if (cfg->link_fec_opt !=
2192 (cfg->link_fec_opt & pcaps->link_fec_options)) {
2193 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2194 cfg->link_fec_opt = pcaps->link_fec_options;
2197 /* Flow Control - always supported; no need to check against
2200 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req);
2202 /* Enable link and link update */
2203 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK;
2205 err = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL);
2207 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
2217 * ice_check_media_subtask - Check for media
2218 * @pf: pointer to PF struct
2220 * If media is available, then initialize PHY user configuration if it is not
2221 * been, and configure the PHY if the interface is up.
2223 static void ice_check_media_subtask(struct ice_pf *pf)
2225 struct ice_port_info *pi;
2226 struct ice_vsi *vsi;
2229 /* No need to check for media if it's already present */
2230 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags))
2233 vsi = ice_get_main_vsi(pf);
2237 /* Refresh link info and check if media is present */
2238 pi = vsi->port_info;
2239 err = ice_update_link_info(pi);
2243 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
2245 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
2246 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state))
2247 ice_init_phy_user_cfg(pi);
2249 /* PHY settings are reset on media insertion, reconfigure
2250 * PHY to preserve settings.
2252 if (test_bit(ICE_VSI_DOWN, vsi->state) &&
2253 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags))
2256 err = ice_configure_phy(vsi);
2258 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
2260 /* A Link Status Event will be generated; the event handler
2261 * will complete bringing the interface up
2267 * ice_service_task - manage and run subtasks
2268 * @work: pointer to work_struct contained by the PF struct
2270 static void ice_service_task(struct work_struct *work)
2272 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
2273 unsigned long start_time = jiffies;
2277 /* process reset requests first */
2278 ice_reset_subtask(pf);
2280 /* bail if a reset/recovery cycle is pending or rebuild failed */
2281 if (ice_is_reset_in_progress(pf->state) ||
2282 test_bit(ICE_SUSPENDED, pf->state) ||
2283 test_bit(ICE_NEEDS_RESTART, pf->state)) {
2284 ice_service_task_complete(pf);
2288 if (test_and_clear_bit(ICE_AUX_ERR_PENDING, pf->state)) {
2289 struct iidc_event *event;
2291 event = kzalloc(sizeof(*event), GFP_KERNEL);
2293 set_bit(IIDC_EVENT_CRIT_ERR, event->type);
2294 /* report the entire OICR value to AUX driver */
2295 swap(event->reg, pf->oicr_err_reg);
2296 ice_send_event_to_aux(pf, event);
2301 if (test_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags)) {
2302 /* Plug aux device per request */
2303 ice_plug_aux_dev(pf);
2305 /* Mark plugging as done but check whether unplug was
2306 * requested during ice_plug_aux_dev() call
2307 * (e.g. from ice_clear_rdma_cap()) and if so then
2310 if (!test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))
2311 ice_unplug_aux_dev(pf);
2314 if (test_and_clear_bit(ICE_FLAG_MTU_CHANGED, pf->flags)) {
2315 struct iidc_event *event;
2317 event = kzalloc(sizeof(*event), GFP_KERNEL);
2319 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);
2320 ice_send_event_to_aux(pf, event);
2325 ice_clean_adminq_subtask(pf);
2326 ice_check_media_subtask(pf);
2327 ice_check_for_hang_subtask(pf);
2328 ice_sync_fltr_subtask(pf);
2329 ice_handle_mdd_event(pf);
2330 ice_watchdog_subtask(pf);
2332 if (ice_is_safe_mode(pf)) {
2333 ice_service_task_complete(pf);
2337 ice_process_vflr_event(pf);
2338 ice_clean_mailboxq_subtask(pf);
2339 ice_clean_sbq_subtask(pf);
2340 ice_sync_arfs_fltrs(pf);
2341 ice_flush_fdir_ctx(pf);
2343 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */
2344 ice_service_task_complete(pf);
2346 /* If the tasks have taken longer than one service timer period
2347 * or there is more work to be done, reset the service timer to
2348 * schedule the service task now.
2350 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
2351 test_bit(ICE_MDD_EVENT_PENDING, pf->state) ||
2352 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) ||
2353 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
2354 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) ||
2355 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) ||
2356 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
2357 mod_timer(&pf->serv_tmr, jiffies);
2361 * ice_set_ctrlq_len - helper function to set controlq length
2362 * @hw: pointer to the HW instance
2364 static void ice_set_ctrlq_len(struct ice_hw *hw)
2366 hw->adminq.num_rq_entries = ICE_AQ_LEN;
2367 hw->adminq.num_sq_entries = ICE_AQ_LEN;
2368 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
2369 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
2370 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
2371 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
2372 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2373 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2374 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
2375 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
2376 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2377 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2381 * ice_schedule_reset - schedule a reset
2382 * @pf: board private structure
2383 * @reset: reset being requested
2385 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
2387 struct device *dev = ice_pf_to_dev(pf);
2389 /* bail out if earlier reset has failed */
2390 if (test_bit(ICE_RESET_FAILED, pf->state)) {
2391 dev_dbg(dev, "earlier reset has failed\n");
2394 /* bail if reset/recovery already in progress */
2395 if (ice_is_reset_in_progress(pf->state)) {
2396 dev_dbg(dev, "Reset already in progress\n");
2400 ice_unplug_aux_dev(pf);
2404 set_bit(ICE_PFR_REQ, pf->state);
2406 case ICE_RESET_CORER:
2407 set_bit(ICE_CORER_REQ, pf->state);
2409 case ICE_RESET_GLOBR:
2410 set_bit(ICE_GLOBR_REQ, pf->state);
2416 ice_service_task_schedule(pf);
2421 * ice_irq_affinity_notify - Callback for affinity changes
2422 * @notify: context as to what irq was changed
2423 * @mask: the new affinity mask
2425 * This is a callback function used by the irq_set_affinity_notifier function
2426 * so that we may register to receive changes to the irq affinity masks.
2429 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
2430 const cpumask_t *mask)
2432 struct ice_q_vector *q_vector =
2433 container_of(notify, struct ice_q_vector, affinity_notify);
2435 cpumask_copy(&q_vector->affinity_mask, mask);
2439 * ice_irq_affinity_release - Callback for affinity notifier release
2440 * @ref: internal core kernel usage
2442 * This is a callback function used by the irq_set_affinity_notifier function
2443 * to inform the current notification subscriber that they will no longer
2444 * receive notifications.
2446 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
2449 * ice_vsi_ena_irq - Enable IRQ for the given VSI
2450 * @vsi: the VSI being configured
2452 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
2454 struct ice_hw *hw = &vsi->back->hw;
2457 ice_for_each_q_vector(vsi, i)
2458 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
2465 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
2466 * @vsi: the VSI being configured
2467 * @basename: name for the vector
2469 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
2471 int q_vectors = vsi->num_q_vectors;
2472 struct ice_pf *pf = vsi->back;
2473 int base = vsi->base_vector;
2480 dev = ice_pf_to_dev(pf);
2481 for (vector = 0; vector < q_vectors; vector++) {
2482 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
2484 irq_num = pf->msix_entries[base + vector].vector;
2486 if (q_vector->tx.tx_ring && q_vector->rx.rx_ring) {
2487 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2488 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2490 } else if (q_vector->rx.rx_ring) {
2491 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2492 "%s-%s-%d", basename, "rx", rx_int_idx++);
2493 } else if (q_vector->tx.tx_ring) {
2494 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2495 "%s-%s-%d", basename, "tx", tx_int_idx++);
2497 /* skip this unused q_vector */
2500 if (vsi->type == ICE_VSI_CTRL && vsi->vf)
2501 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2502 IRQF_SHARED, q_vector->name,
2505 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2506 0, q_vector->name, q_vector);
2508 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
2513 /* register for affinity change notifications */
2514 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
2515 struct irq_affinity_notify *affinity_notify;
2517 affinity_notify = &q_vector->affinity_notify;
2518 affinity_notify->notify = ice_irq_affinity_notify;
2519 affinity_notify->release = ice_irq_affinity_release;
2520 irq_set_affinity_notifier(irq_num, affinity_notify);
2523 /* assign the mask for this irq */
2524 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
2527 err = ice_set_cpu_rx_rmap(vsi);
2529 netdev_err(vsi->netdev, "Failed to setup CPU RMAP on VSI %u: %pe\n",
2530 vsi->vsi_num, ERR_PTR(err));
2534 vsi->irqs_ready = true;
2540 irq_num = pf->msix_entries[base + vector].vector;
2541 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2542 irq_set_affinity_notifier(irq_num, NULL);
2543 irq_set_affinity_hint(irq_num, NULL);
2544 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
2550 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
2551 * @vsi: VSI to setup Tx rings used by XDP
2553 * Return 0 on success and negative value on error
2555 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
2557 struct device *dev = ice_pf_to_dev(vsi->back);
2558 struct ice_tx_desc *tx_desc;
2561 ice_for_each_xdp_txq(vsi, i) {
2562 u16 xdp_q_idx = vsi->alloc_txq + i;
2563 struct ice_tx_ring *xdp_ring;
2565 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
2568 goto free_xdp_rings;
2570 xdp_ring->q_index = xdp_q_idx;
2571 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
2572 xdp_ring->vsi = vsi;
2573 xdp_ring->netdev = NULL;
2574 xdp_ring->dev = dev;
2575 xdp_ring->count = vsi->num_tx_desc;
2576 xdp_ring->next_dd = ICE_RING_QUARTER(xdp_ring) - 1;
2577 xdp_ring->next_rs = ICE_RING_QUARTER(xdp_ring) - 1;
2578 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring);
2579 if (ice_setup_tx_ring(xdp_ring))
2580 goto free_xdp_rings;
2581 ice_set_ring_xdp(xdp_ring);
2582 xdp_ring->xsk_pool = ice_tx_xsk_pool(xdp_ring);
2583 spin_lock_init(&xdp_ring->tx_lock);
2584 for (j = 0; j < xdp_ring->count; j++) {
2585 tx_desc = ICE_TX_DESC(xdp_ring, j);
2586 tx_desc->cmd_type_offset_bsz = 0;
2590 ice_for_each_rxq(vsi, i) {
2591 if (static_key_enabled(&ice_xdp_locking_key))
2592 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i % vsi->num_xdp_txq];
2594 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i];
2601 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2602 ice_free_tx_ring(vsi->xdp_rings[i]);
2607 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
2608 * @vsi: VSI to set the bpf prog on
2609 * @prog: the bpf prog pointer
2611 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
2613 struct bpf_prog *old_prog;
2616 old_prog = xchg(&vsi->xdp_prog, prog);
2618 bpf_prog_put(old_prog);
2620 ice_for_each_rxq(vsi, i)
2621 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
2625 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
2626 * @vsi: VSI to bring up Tx rings used by XDP
2627 * @prog: bpf program that will be assigned to VSI
2629 * Return 0 on success and negative value on error
2631 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
2633 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2634 int xdp_rings_rem = vsi->num_xdp_txq;
2635 struct ice_pf *pf = vsi->back;
2636 struct ice_qs_cfg xdp_qs_cfg = {
2637 .qs_mutex = &pf->avail_q_mutex,
2638 .pf_map = pf->avail_txqs,
2639 .pf_map_size = pf->max_pf_txqs,
2640 .q_count = vsi->num_xdp_txq,
2641 .scatter_count = ICE_MAX_SCATTER_TXQS,
2642 .vsi_map = vsi->txq_map,
2643 .vsi_map_offset = vsi->alloc_txq,
2644 .mapping_mode = ICE_VSI_MAP_CONTIG
2650 dev = ice_pf_to_dev(pf);
2651 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
2652 sizeof(*vsi->xdp_rings), GFP_KERNEL);
2653 if (!vsi->xdp_rings)
2656 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
2657 if (__ice_vsi_get_qs(&xdp_qs_cfg))
2660 if (static_key_enabled(&ice_xdp_locking_key))
2661 netdev_warn(vsi->netdev,
2662 "Could not allocate one XDP Tx ring per CPU, XDP_TX/XDP_REDIRECT actions will be slower\n");
2664 if (ice_xdp_alloc_setup_rings(vsi))
2665 goto clear_xdp_rings;
2667 /* follow the logic from ice_vsi_map_rings_to_vectors */
2668 ice_for_each_q_vector(vsi, v_idx) {
2669 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2670 int xdp_rings_per_v, q_id, q_base;
2672 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
2673 vsi->num_q_vectors - v_idx);
2674 q_base = vsi->num_xdp_txq - xdp_rings_rem;
2676 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
2677 struct ice_tx_ring *xdp_ring = vsi->xdp_rings[q_id];
2679 xdp_ring->q_vector = q_vector;
2680 xdp_ring->next = q_vector->tx.tx_ring;
2681 q_vector->tx.tx_ring = xdp_ring;
2683 xdp_rings_rem -= xdp_rings_per_v;
2686 /* omit the scheduler update if in reset path; XDP queues will be
2687 * taken into account at the end of ice_vsi_rebuild, where
2688 * ice_cfg_vsi_lan is being called
2690 if (ice_is_reset_in_progress(pf->state))
2693 /* tell the Tx scheduler that right now we have
2696 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2697 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
2699 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2702 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %d\n",
2704 goto clear_xdp_rings;
2707 /* assign the prog only when it's not already present on VSI;
2708 * this flow is a subject of both ethtool -L and ndo_bpf flows;
2709 * VSI rebuild that happens under ethtool -L can expose us to
2710 * the bpf_prog refcount issues as we would be swapping same
2711 * bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put
2712 * on it as it would be treated as an 'old_prog'; for ndo_bpf
2713 * this is not harmful as dev_xdp_install bumps the refcount
2714 * before calling the op exposed by the driver;
2716 if (!ice_is_xdp_ena_vsi(vsi))
2717 ice_vsi_assign_bpf_prog(vsi, prog);
2721 ice_for_each_xdp_txq(vsi, i)
2722 if (vsi->xdp_rings[i]) {
2723 kfree_rcu(vsi->xdp_rings[i], rcu);
2724 vsi->xdp_rings[i] = NULL;
2728 mutex_lock(&pf->avail_q_mutex);
2729 ice_for_each_xdp_txq(vsi, i) {
2730 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2731 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2733 mutex_unlock(&pf->avail_q_mutex);
2735 devm_kfree(dev, vsi->xdp_rings);
2740 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
2741 * @vsi: VSI to remove XDP rings
2743 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
2746 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
2748 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2749 struct ice_pf *pf = vsi->back;
2752 /* q_vectors are freed in reset path so there's no point in detaching
2753 * rings; in case of rebuild being triggered not from reset bits
2754 * in pf->state won't be set, so additionally check first q_vector
2757 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2760 ice_for_each_q_vector(vsi, v_idx) {
2761 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2762 struct ice_tx_ring *ring;
2764 ice_for_each_tx_ring(ring, q_vector->tx)
2765 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
2768 /* restore the value of last node prior to XDP setup */
2769 q_vector->tx.tx_ring = ring;
2773 mutex_lock(&pf->avail_q_mutex);
2774 ice_for_each_xdp_txq(vsi, i) {
2775 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2776 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2778 mutex_unlock(&pf->avail_q_mutex);
2780 ice_for_each_xdp_txq(vsi, i)
2781 if (vsi->xdp_rings[i]) {
2782 if (vsi->xdp_rings[i]->desc) {
2784 ice_free_tx_ring(vsi->xdp_rings[i]);
2786 kfree_rcu(vsi->xdp_rings[i], rcu);
2787 vsi->xdp_rings[i] = NULL;
2790 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
2791 vsi->xdp_rings = NULL;
2793 if (static_key_enabled(&ice_xdp_locking_key))
2794 static_branch_dec(&ice_xdp_locking_key);
2796 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2799 ice_vsi_assign_bpf_prog(vsi, NULL);
2801 /* notify Tx scheduler that we destroyed XDP queues and bring
2802 * back the old number of child nodes
2804 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2805 max_txqs[i] = vsi->num_txq;
2807 /* change number of XDP Tx queues to 0 */
2808 vsi->num_xdp_txq = 0;
2810 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2815 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2816 * @vsi: VSI to schedule napi on
2818 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2822 ice_for_each_rxq(vsi, i) {
2823 struct ice_rx_ring *rx_ring = vsi->rx_rings[i];
2825 if (rx_ring->xsk_pool)
2826 napi_schedule(&rx_ring->q_vector->napi);
2831 * ice_vsi_determine_xdp_res - figure out how many Tx qs can XDP have
2832 * @vsi: VSI to determine the count of XDP Tx qs
2834 * returns 0 if Tx qs count is higher than at least half of CPU count,
2837 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi)
2839 u16 avail = ice_get_avail_txq_count(vsi->back);
2840 u16 cpus = num_possible_cpus();
2842 if (avail < cpus / 2)
2845 vsi->num_xdp_txq = min_t(u16, avail, cpus);
2847 if (vsi->num_xdp_txq < cpus)
2848 static_branch_inc(&ice_xdp_locking_key);
2854 * ice_xdp_setup_prog - Add or remove XDP eBPF program
2855 * @vsi: VSI to setup XDP for
2856 * @prog: XDP program
2857 * @extack: netlink extended ack
2860 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
2861 struct netlink_ext_ack *extack)
2863 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
2864 bool if_running = netif_running(vsi->netdev);
2865 int ret = 0, xdp_ring_err = 0;
2867 if (frame_size > vsi->rx_buf_len) {
2868 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
2872 /* need to stop netdev while setting up the program for Rx rings */
2873 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2874 ret = ice_down(vsi);
2876 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
2881 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
2882 xdp_ring_err = ice_vsi_determine_xdp_res(vsi);
2884 NL_SET_ERR_MSG_MOD(extack, "Not enough Tx resources for XDP");
2886 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
2888 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
2890 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
2891 xdp_ring_err = ice_destroy_xdp_rings(vsi);
2893 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
2895 /* safe to call even when prog == vsi->xdp_prog as
2896 * dev_xdp_install in net/core/dev.c incremented prog's
2897 * refcount so corresponding bpf_prog_put won't cause
2900 ice_vsi_assign_bpf_prog(vsi, prog);
2907 ice_vsi_rx_napi_schedule(vsi);
2909 return (ret || xdp_ring_err) ? -ENOMEM : 0;
2913 * ice_xdp_safe_mode - XDP handler for safe mode
2917 static int ice_xdp_safe_mode(struct net_device __always_unused *dev,
2918 struct netdev_bpf *xdp)
2920 NL_SET_ERR_MSG_MOD(xdp->extack,
2921 "Please provide working DDP firmware package in order to use XDP\n"
2922 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst");
2927 * ice_xdp - implements XDP handler
2931 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
2933 struct ice_netdev_priv *np = netdev_priv(dev);
2934 struct ice_vsi *vsi = np->vsi;
2936 if (vsi->type != ICE_VSI_PF) {
2937 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI");
2941 switch (xdp->command) {
2942 case XDP_SETUP_PROG:
2943 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
2944 case XDP_SETUP_XSK_POOL:
2945 return ice_xsk_pool_setup(vsi, xdp->xsk.pool,
2953 * ice_ena_misc_vector - enable the non-queue interrupts
2954 * @pf: board private structure
2956 static void ice_ena_misc_vector(struct ice_pf *pf)
2958 struct ice_hw *hw = &pf->hw;
2961 /* Disable anti-spoof detection interrupt to prevent spurious event
2962 * interrupts during a function reset. Anti-spoof functionally is
2965 val = rd32(hw, GL_MDCK_TX_TDPU);
2966 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
2967 wr32(hw, GL_MDCK_TX_TDPU, val);
2969 /* clear things first */
2970 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
2971 rd32(hw, PFINT_OICR); /* read to clear */
2973 val = (PFINT_OICR_ECC_ERR_M |
2974 PFINT_OICR_MAL_DETECT_M |
2976 PFINT_OICR_PCI_EXCEPTION_M |
2978 PFINT_OICR_HMC_ERR_M |
2979 PFINT_OICR_PE_PUSH_M |
2980 PFINT_OICR_PE_CRITERR_M);
2982 wr32(hw, PFINT_OICR_ENA, val);
2984 /* SW_ITR_IDX = 0, but don't change INTENA */
2985 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2986 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2990 * ice_misc_intr - misc interrupt handler
2991 * @irq: interrupt number
2992 * @data: pointer to a q_vector
2994 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2996 struct ice_pf *pf = (struct ice_pf *)data;
2997 struct ice_hw *hw = &pf->hw;
2998 irqreturn_t ret = IRQ_NONE;
3002 dev = ice_pf_to_dev(pf);
3003 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
3004 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
3005 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
3007 oicr = rd32(hw, PFINT_OICR);
3008 ena_mask = rd32(hw, PFINT_OICR_ENA);
3010 if (oicr & PFINT_OICR_SWINT_M) {
3011 ena_mask &= ~PFINT_OICR_SWINT_M;
3015 if (oicr & PFINT_OICR_MAL_DETECT_M) {
3016 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
3017 set_bit(ICE_MDD_EVENT_PENDING, pf->state);
3019 if (oicr & PFINT_OICR_VFLR_M) {
3020 /* disable any further VFLR event notifications */
3021 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
3022 u32 reg = rd32(hw, PFINT_OICR_ENA);
3024 reg &= ~PFINT_OICR_VFLR_M;
3025 wr32(hw, PFINT_OICR_ENA, reg);
3027 ena_mask &= ~PFINT_OICR_VFLR_M;
3028 set_bit(ICE_VFLR_EVENT_PENDING, pf->state);
3032 if (oicr & PFINT_OICR_GRST_M) {
3035 /* we have a reset warning */
3036 ena_mask &= ~PFINT_OICR_GRST_M;
3037 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
3038 GLGEN_RSTAT_RESET_TYPE_S;
3040 if (reset == ICE_RESET_CORER)
3042 else if (reset == ICE_RESET_GLOBR)
3044 else if (reset == ICE_RESET_EMPR)
3047 dev_dbg(dev, "Invalid reset type %d\n", reset);
3049 /* If a reset cycle isn't already in progress, we set a bit in
3050 * pf->state so that the service task can start a reset/rebuild.
3052 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) {
3053 if (reset == ICE_RESET_CORER)
3054 set_bit(ICE_CORER_RECV, pf->state);
3055 else if (reset == ICE_RESET_GLOBR)
3056 set_bit(ICE_GLOBR_RECV, pf->state);
3058 set_bit(ICE_EMPR_RECV, pf->state);
3060 /* There are couple of different bits at play here.
3061 * hw->reset_ongoing indicates whether the hardware is
3062 * in reset. This is set to true when a reset interrupt
3063 * is received and set back to false after the driver
3064 * has determined that the hardware is out of reset.
3066 * ICE_RESET_OICR_RECV in pf->state indicates
3067 * that a post reset rebuild is required before the
3068 * driver is operational again. This is set above.
3070 * As this is the start of the reset/rebuild cycle, set
3071 * both to indicate that.
3073 hw->reset_ongoing = true;
3077 if (oicr & PFINT_OICR_TSYN_TX_M) {
3078 ena_mask &= ~PFINT_OICR_TSYN_TX_M;
3079 ice_ptp_process_ts(pf);
3082 if (oicr & PFINT_OICR_TSYN_EVNT_M) {
3083 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
3084 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx));
3086 /* Save EVENTs from GTSYN register */
3087 pf->ptp.ext_ts_irq |= gltsyn_stat & (GLTSYN_STAT_EVENT0_M |
3088 GLTSYN_STAT_EVENT1_M |
3089 GLTSYN_STAT_EVENT2_M);
3090 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M;
3091 kthread_queue_work(pf->ptp.kworker, &pf->ptp.extts_work);
3094 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M)
3095 if (oicr & ICE_AUX_CRIT_ERR) {
3096 pf->oicr_err_reg |= oicr;
3097 set_bit(ICE_AUX_ERR_PENDING, pf->state);
3098 ena_mask &= ~ICE_AUX_CRIT_ERR;
3101 /* Report any remaining unexpected interrupts */
3104 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
3105 /* If a critical error is pending there is no choice but to
3108 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M |
3109 PFINT_OICR_ECC_ERR_M)) {
3110 set_bit(ICE_PFR_REQ, pf->state);
3111 ice_service_task_schedule(pf);
3116 ice_service_task_schedule(pf);
3117 ice_irq_dynamic_ena(hw, NULL, NULL);
3123 * ice_dis_ctrlq_interrupts - disable control queue interrupts
3124 * @hw: pointer to HW structure
3126 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
3128 /* disable Admin queue Interrupt causes */
3129 wr32(hw, PFINT_FW_CTL,
3130 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
3132 /* disable Mailbox queue Interrupt causes */
3133 wr32(hw, PFINT_MBX_CTL,
3134 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
3136 wr32(hw, PFINT_SB_CTL,
3137 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M);
3139 /* disable Control queue Interrupt causes */
3140 wr32(hw, PFINT_OICR_CTL,
3141 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
3147 * ice_free_irq_msix_misc - Unroll misc vector setup
3148 * @pf: board private structure
3150 static void ice_free_irq_msix_misc(struct ice_pf *pf)
3152 struct ice_hw *hw = &pf->hw;
3154 ice_dis_ctrlq_interrupts(hw);
3156 /* disable OICR interrupt */
3157 wr32(hw, PFINT_OICR_ENA, 0);
3160 if (pf->msix_entries) {
3161 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
3162 devm_free_irq(ice_pf_to_dev(pf),
3163 pf->msix_entries[pf->oicr_idx].vector, pf);
3166 pf->num_avail_sw_msix += 1;
3167 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
3171 * ice_ena_ctrlq_interrupts - enable control queue interrupts
3172 * @hw: pointer to HW structure
3173 * @reg_idx: HW vector index to associate the control queue interrupts with
3175 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
3179 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
3180 PFINT_OICR_CTL_CAUSE_ENA_M);
3181 wr32(hw, PFINT_OICR_CTL, val);
3183 /* enable Admin queue Interrupt causes */
3184 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
3185 PFINT_FW_CTL_CAUSE_ENA_M);
3186 wr32(hw, PFINT_FW_CTL, val);
3188 /* enable Mailbox queue Interrupt causes */
3189 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
3190 PFINT_MBX_CTL_CAUSE_ENA_M);
3191 wr32(hw, PFINT_MBX_CTL, val);
3193 /* This enables Sideband queue Interrupt causes */
3194 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) |
3195 PFINT_SB_CTL_CAUSE_ENA_M);
3196 wr32(hw, PFINT_SB_CTL, val);
3202 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
3203 * @pf: board private structure
3205 * This sets up the handler for MSIX 0, which is used to manage the
3206 * non-queue interrupts, e.g. AdminQ and errors. This is not used
3207 * when in MSI or Legacy interrupt mode.
3209 static int ice_req_irq_msix_misc(struct ice_pf *pf)
3211 struct device *dev = ice_pf_to_dev(pf);
3212 struct ice_hw *hw = &pf->hw;
3213 int oicr_idx, err = 0;
3215 if (!pf->int_name[0])
3216 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
3217 dev_driver_string(dev), dev_name(dev));
3219 /* Do not request IRQ but do enable OICR interrupt since settings are
3220 * lost during reset. Note that this function is called only during
3221 * rebuild path and not while reset is in progress.
3223 if (ice_is_reset_in_progress(pf->state))
3226 /* reserve one vector in irq_tracker for misc interrupts */
3227 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3231 pf->num_avail_sw_msix -= 1;
3232 pf->oicr_idx = (u16)oicr_idx;
3234 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
3235 ice_misc_intr, 0, pf->int_name, pf);
3237 dev_err(dev, "devm_request_irq for %s failed: %d\n",
3239 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3240 pf->num_avail_sw_msix += 1;
3245 ice_ena_misc_vector(pf);
3247 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
3248 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
3249 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
3252 ice_irq_dynamic_ena(hw, NULL, NULL);
3258 * ice_napi_add - register NAPI handler for the VSI
3259 * @vsi: VSI for which NAPI handler is to be registered
3261 * This function is only called in the driver's load path. Registering the NAPI
3262 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
3263 * reset/rebuild, etc.)
3265 static void ice_napi_add(struct ice_vsi *vsi)
3272 ice_for_each_q_vector(vsi, v_idx)
3273 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
3274 ice_napi_poll, NAPI_POLL_WEIGHT);
3278 * ice_set_ops - set netdev and ethtools ops for the given netdev
3279 * @netdev: netdev instance
3281 static void ice_set_ops(struct net_device *netdev)
3283 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3285 if (ice_is_safe_mode(pf)) {
3286 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
3287 ice_set_ethtool_safe_mode_ops(netdev);
3291 netdev->netdev_ops = &ice_netdev_ops;
3292 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic;
3293 ice_set_ethtool_ops(netdev);
3297 * ice_set_netdev_features - set features for the given netdev
3298 * @netdev: netdev instance
3300 static void ice_set_netdev_features(struct net_device *netdev)
3302 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3303 bool is_dvm_ena = ice_is_dvm_ena(&pf->hw);
3304 netdev_features_t csumo_features;
3305 netdev_features_t vlano_features;
3306 netdev_features_t dflt_features;
3307 netdev_features_t tso_features;
3309 if (ice_is_safe_mode(pf)) {
3311 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
3312 netdev->hw_features = netdev->features;
3316 dflt_features = NETIF_F_SG |
3321 csumo_features = NETIF_F_RXCSUM |
3326 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
3327 NETIF_F_HW_VLAN_CTAG_TX |
3328 NETIF_F_HW_VLAN_CTAG_RX;
3330 /* Enable CTAG/STAG filtering by default in Double VLAN Mode (DVM) */
3332 vlano_features |= NETIF_F_HW_VLAN_STAG_FILTER;
3334 tso_features = NETIF_F_TSO |
3338 NETIF_F_GSO_UDP_TUNNEL |
3339 NETIF_F_GSO_GRE_CSUM |
3340 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3341 NETIF_F_GSO_PARTIAL |
3342 NETIF_F_GSO_IPXIP4 |
3343 NETIF_F_GSO_IPXIP6 |
3346 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3347 NETIF_F_GSO_GRE_CSUM;
3348 /* set features that user can change */
3349 netdev->hw_features = dflt_features | csumo_features |
3350 vlano_features | tso_features;
3352 /* add support for HW_CSUM on packets with MPLS header */
3353 netdev->mpls_features = NETIF_F_HW_CSUM |
3357 /* enable features */
3358 netdev->features |= netdev->hw_features;
3360 netdev->hw_features |= NETIF_F_HW_TC;
3361 netdev->hw_features |= NETIF_F_LOOPBACK;
3363 /* encap and VLAN devices inherit default, csumo and tso features */
3364 netdev->hw_enc_features |= dflt_features | csumo_features |
3366 netdev->vlan_features |= dflt_features | csumo_features |
3369 /* advertise support but don't enable by default since only one type of
3370 * VLAN offload can be enabled at a time (i.e. CTAG or STAG). When one
3371 * type turns on the other has to be turned off. This is enforced by the
3372 * ice_fix_features() ndo callback.
3375 netdev->hw_features |= NETIF_F_HW_VLAN_STAG_RX |
3376 NETIF_F_HW_VLAN_STAG_TX;
3380 * ice_cfg_netdev - Allocate, configure and register a netdev
3381 * @vsi: the VSI associated with the new netdev
3383 * Returns 0 on success, negative value on failure
3385 static int ice_cfg_netdev(struct ice_vsi *vsi)
3387 struct ice_netdev_priv *np;
3388 struct net_device *netdev;
3389 u8 mac_addr[ETH_ALEN];
3391 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
3396 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3397 vsi->netdev = netdev;
3398 np = netdev_priv(netdev);
3401 ice_set_netdev_features(netdev);
3403 ice_set_ops(netdev);
3405 if (vsi->type == ICE_VSI_PF) {
3406 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back));
3407 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
3408 eth_hw_addr_set(netdev, mac_addr);
3409 ether_addr_copy(netdev->perm_addr, mac_addr);
3412 netdev->priv_flags |= IFF_UNICAST_FLT;
3414 /* Setup netdev TC information */
3415 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
3417 /* setup watchdog timeout value to be 5 second */
3418 netdev->watchdog_timeo = 5 * HZ;
3420 netdev->min_mtu = ETH_MIN_MTU;
3421 netdev->max_mtu = ICE_MAX_MTU;
3427 * ice_fill_rss_lut - Fill the RSS lookup table with default values
3428 * @lut: Lookup table
3429 * @rss_table_size: Lookup table size
3430 * @rss_size: Range of queue number for hashing
3432 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
3436 for (i = 0; i < rss_table_size; i++)
3437 lut[i] = i % rss_size;
3441 * ice_pf_vsi_setup - Set up a PF VSI
3442 * @pf: board private structure
3443 * @pi: pointer to the port_info instance
3445 * Returns pointer to the successfully allocated VSI software struct
3446 * on success, otherwise returns NULL on failure.
3448 static struct ice_vsi *
3449 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3451 return ice_vsi_setup(pf, pi, ICE_VSI_PF, NULL, NULL);
3454 static struct ice_vsi *
3455 ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
3456 struct ice_channel *ch)
3458 return ice_vsi_setup(pf, pi, ICE_VSI_CHNL, NULL, ch);
3462 * ice_ctrl_vsi_setup - Set up a control VSI
3463 * @pf: board private structure
3464 * @pi: pointer to the port_info instance
3466 * Returns pointer to the successfully allocated VSI software struct
3467 * on success, otherwise returns NULL on failure.
3469 static struct ice_vsi *
3470 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3472 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, NULL, NULL);
3476 * ice_lb_vsi_setup - Set up a loopback VSI
3477 * @pf: board private structure
3478 * @pi: pointer to the port_info instance
3480 * Returns pointer to the successfully allocated VSI software struct
3481 * on success, otherwise returns NULL on failure.
3484 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3486 return ice_vsi_setup(pf, pi, ICE_VSI_LB, NULL, NULL);
3490 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
3491 * @netdev: network interface to be adjusted
3493 * @vid: VLAN ID to be added
3495 * net_device_ops implementation for adding VLAN IDs
3498 ice_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
3500 struct ice_netdev_priv *np = netdev_priv(netdev);
3501 struct ice_vsi_vlan_ops *vlan_ops;
3502 struct ice_vsi *vsi = np->vsi;
3503 struct ice_vlan vlan;
3506 /* VLAN 0 is added by default during load/reset */
3510 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3511 usleep_range(1000, 2000);
3513 /* Add multicast promisc rule for the VLAN ID to be added if
3514 * all-multicast is currently enabled.
3516 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3517 ret = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3518 ICE_MCAST_VLAN_PROMISC_BITS,
3524 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3526 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
3527 * packets aren't pruned by the device's internal switch on Rx
3529 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3530 ret = vlan_ops->add_vlan(vsi, &vlan);
3534 /* If all-multicast is currently enabled and this VLAN ID is only one
3535 * besides VLAN-0 we have to update look-up type of multicast promisc
3536 * rule for VLAN-0 from ICE_SW_LKUP_PROMISC to ICE_SW_LKUP_PROMISC_VLAN.
3538 if ((vsi->current_netdev_flags & IFF_ALLMULTI) &&
3539 ice_vsi_num_non_zero_vlans(vsi) == 1) {
3540 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3541 ICE_MCAST_PROMISC_BITS, 0);
3542 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3543 ICE_MCAST_VLAN_PROMISC_BITS, 0);
3547 clear_bit(ICE_CFG_BUSY, vsi->state);
3553 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
3554 * @netdev: network interface to be adjusted
3556 * @vid: VLAN ID to be removed
3558 * net_device_ops implementation for removing VLAN IDs
3561 ice_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3563 struct ice_netdev_priv *np = netdev_priv(netdev);
3564 struct ice_vsi_vlan_ops *vlan_ops;
3565 struct ice_vsi *vsi = np->vsi;
3566 struct ice_vlan vlan;
3569 /* don't allow removal of VLAN 0 */
3573 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3574 usleep_range(1000, 2000);
3576 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3578 /* Make sure VLAN delete is successful before updating VLAN
3581 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3582 ret = vlan_ops->del_vlan(vsi, &vlan);
3586 /* Remove multicast promisc rule for the removed VLAN ID if
3587 * all-multicast is enabled.
3589 if (vsi->current_netdev_flags & IFF_ALLMULTI)
3590 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3591 ICE_MCAST_VLAN_PROMISC_BITS, vid);
3593 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3594 /* Update look-up type of multicast promisc rule for VLAN 0
3595 * from ICE_SW_LKUP_PROMISC_VLAN to ICE_SW_LKUP_PROMISC when
3596 * all-multicast is enabled and VLAN 0 is the only VLAN rule.
3598 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3599 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3600 ICE_MCAST_VLAN_PROMISC_BITS,
3602 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3603 ICE_MCAST_PROMISC_BITS, 0);
3608 clear_bit(ICE_CFG_BUSY, vsi->state);
3614 * ice_rep_indr_tc_block_unbind
3615 * @cb_priv: indirection block private data
3617 static void ice_rep_indr_tc_block_unbind(void *cb_priv)
3619 struct ice_indr_block_priv *indr_priv = cb_priv;
3621 list_del(&indr_priv->list);
3626 * ice_tc_indir_block_unregister - Unregister TC indirect block notifications
3627 * @vsi: VSI struct which has the netdev
3629 static void ice_tc_indir_block_unregister(struct ice_vsi *vsi)
3631 struct ice_netdev_priv *np = netdev_priv(vsi->netdev);
3633 flow_indr_dev_unregister(ice_indr_setup_tc_cb, np,
3634 ice_rep_indr_tc_block_unbind);
3638 * ice_tc_indir_block_remove - clean indirect TC block notifications
3641 static void ice_tc_indir_block_remove(struct ice_pf *pf)
3643 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3648 ice_tc_indir_block_unregister(pf_vsi);
3652 * ice_tc_indir_block_register - Register TC indirect block notifications
3653 * @vsi: VSI struct which has the netdev
3655 * Returns 0 on success, negative value on failure
3657 static int ice_tc_indir_block_register(struct ice_vsi *vsi)
3659 struct ice_netdev_priv *np;
3661 if (!vsi || !vsi->netdev)
3664 np = netdev_priv(vsi->netdev);
3666 INIT_LIST_HEAD(&np->tc_indr_block_priv_list);
3667 return flow_indr_dev_register(ice_indr_setup_tc_cb, np);
3671 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
3672 * @pf: board private structure
3674 * Returns 0 on success, negative value on failure
3676 static int ice_setup_pf_sw(struct ice_pf *pf)
3678 struct device *dev = ice_pf_to_dev(pf);
3679 bool dvm = ice_is_dvm_ena(&pf->hw);
3680 struct ice_vsi *vsi;
3683 if (ice_is_reset_in_progress(pf->state))
3686 status = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
3690 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
3694 /* init channel list */
3695 INIT_LIST_HEAD(&vsi->ch_list);
3697 status = ice_cfg_netdev(vsi);
3699 goto unroll_vsi_setup;
3700 /* netdev has to be configured before setting frame size */
3701 ice_vsi_cfg_frame_size(vsi);
3703 /* init indirect block notifications */
3704 status = ice_tc_indir_block_register(vsi);
3706 dev_err(dev, "Failed to register netdev notifier\n");
3707 goto unroll_cfg_netdev;
3710 /* Setup DCB netlink interface */
3711 ice_dcbnl_setup(vsi);
3713 /* registering the NAPI handler requires both the queues and
3714 * netdev to be created, which are done in ice_pf_vsi_setup()
3715 * and ice_cfg_netdev() respectively
3719 status = ice_init_mac_fltr(pf);
3721 goto unroll_napi_add;
3726 ice_tc_indir_block_unregister(vsi);
3731 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3732 free_netdev(vsi->netdev);
3738 ice_vsi_release(vsi);
3743 * ice_get_avail_q_count - Get count of queues in use
3744 * @pf_qmap: bitmap to get queue use count from
3745 * @lock: pointer to a mutex that protects access to pf_qmap
3746 * @size: size of the bitmap
3749 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
3755 for_each_clear_bit(bit, pf_qmap, size)
3763 * ice_get_avail_txq_count - Get count of Tx queues in use
3764 * @pf: pointer to an ice_pf instance
3766 u16 ice_get_avail_txq_count(struct ice_pf *pf)
3768 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
3773 * ice_get_avail_rxq_count - Get count of Rx queues in use
3774 * @pf: pointer to an ice_pf instance
3776 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
3778 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
3783 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3784 * @pf: board private structure to initialize
3786 static void ice_deinit_pf(struct ice_pf *pf)
3788 ice_service_task_stop(pf);
3789 mutex_destroy(&pf->adev_mutex);
3790 mutex_destroy(&pf->sw_mutex);
3791 mutex_destroy(&pf->tc_mutex);
3792 mutex_destroy(&pf->avail_q_mutex);
3793 mutex_destroy(&pf->vfs.table_lock);
3795 if (pf->avail_txqs) {
3796 bitmap_free(pf->avail_txqs);
3797 pf->avail_txqs = NULL;
3800 if (pf->avail_rxqs) {
3801 bitmap_free(pf->avail_rxqs);
3802 pf->avail_rxqs = NULL;
3806 ptp_clock_unregister(pf->ptp.clock);
3810 * ice_set_pf_caps - set PFs capability flags
3811 * @pf: pointer to the PF instance
3813 static void ice_set_pf_caps(struct ice_pf *pf)
3815 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
3817 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3818 if (func_caps->common_cap.rdma)
3819 set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3820 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3821 if (func_caps->common_cap.dcb)
3822 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3823 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3824 if (func_caps->common_cap.sr_iov_1_1) {
3825 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3826 pf->vfs.num_supported = min_t(int, func_caps->num_allocd_vfs,
3829 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
3830 if (func_caps->common_cap.rss_table_size)
3831 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
3833 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
3834 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
3837 /* ctrl_vsi_idx will be set to a valid value when flow director
3838 * is setup by ice_init_fdir
3840 pf->ctrl_vsi_idx = ICE_NO_VSI;
3841 set_bit(ICE_FLAG_FD_ENA, pf->flags);
3842 /* force guaranteed filter pool for PF */
3843 ice_alloc_fd_guar_item(&pf->hw, &unused,
3844 func_caps->fd_fltr_guar);
3845 /* force shared filter pool for PF */
3846 ice_alloc_fd_shrd_item(&pf->hw, &unused,
3847 func_caps->fd_fltr_best_effort);
3850 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3851 if (func_caps->common_cap.ieee_1588)
3852 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3854 pf->max_pf_txqs = func_caps->common_cap.num_txq;
3855 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
3859 * ice_init_pf - Initialize general software structures (struct ice_pf)
3860 * @pf: board private structure to initialize
3862 static int ice_init_pf(struct ice_pf *pf)
3864 ice_set_pf_caps(pf);
3866 mutex_init(&pf->sw_mutex);
3867 mutex_init(&pf->tc_mutex);
3868 mutex_init(&pf->adev_mutex);
3870 INIT_HLIST_HEAD(&pf->aq_wait_list);
3871 spin_lock_init(&pf->aq_wait_lock);
3872 init_waitqueue_head(&pf->aq_wait_queue);
3874 init_waitqueue_head(&pf->reset_wait_queue);
3876 /* setup service timer and periodic service task */
3877 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
3878 pf->serv_tmr_period = HZ;
3879 INIT_WORK(&pf->serv_task, ice_service_task);
3880 clear_bit(ICE_SERVICE_SCHED, pf->state);
3882 mutex_init(&pf->avail_q_mutex);
3883 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
3884 if (!pf->avail_txqs)
3887 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
3888 if (!pf->avail_rxqs) {
3889 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
3890 pf->avail_txqs = NULL;
3894 mutex_init(&pf->vfs.table_lock);
3895 hash_init(pf->vfs.table);
3901 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
3902 * @pf: board private structure
3904 * compute the number of MSIX vectors required (v_budget) and request from
3905 * the OS. Return the number of vectors reserved or negative on failure
3907 static int ice_ena_msix_range(struct ice_pf *pf)
3909 int num_cpus, v_left, v_actual, v_other, v_budget = 0;
3910 struct device *dev = ice_pf_to_dev(pf);
3913 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
3914 num_cpus = num_online_cpus();
3916 /* reserve for LAN miscellaneous handler */
3917 needed = ICE_MIN_LAN_OICR_MSIX;
3918 if (v_left < needed)
3919 goto no_hw_vecs_left_err;
3923 /* reserve for flow director */
3924 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
3925 needed = ICE_FDIR_MSIX;
3926 if (v_left < needed)
3927 goto no_hw_vecs_left_err;
3932 /* reserve for switchdev */
3933 needed = ICE_ESWITCH_MSIX;
3934 if (v_left < needed)
3935 goto no_hw_vecs_left_err;
3939 /* total used for non-traffic vectors */
3942 /* reserve vectors for LAN traffic */
3944 if (v_left < needed)
3945 goto no_hw_vecs_left_err;
3946 pf->num_lan_msix = needed;
3950 /* reserve vectors for RDMA auxiliary driver */
3951 if (ice_is_rdma_ena(pf)) {
3952 needed = num_cpus + ICE_RDMA_NUM_AEQ_MSIX;
3953 if (v_left < needed)
3954 goto no_hw_vecs_left_err;
3955 pf->num_rdma_msix = needed;
3960 pf->msix_entries = devm_kcalloc(dev, v_budget,
3961 sizeof(*pf->msix_entries), GFP_KERNEL);
3962 if (!pf->msix_entries) {
3967 for (i = 0; i < v_budget; i++)
3968 pf->msix_entries[i].entry = i;
3970 /* actually reserve the vectors */
3971 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
3972 ICE_MIN_MSIX, v_budget);
3974 dev_err(dev, "unable to reserve MSI-X vectors\n");
3979 if (v_actual < v_budget) {
3980 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
3981 v_budget, v_actual);
3983 if (v_actual < ICE_MIN_MSIX) {
3984 /* error if we can't get minimum vectors */
3985 pci_disable_msix(pf->pdev);
3989 int v_remain = v_actual - v_other;
3990 int v_rdma = 0, v_min_rdma = 0;
3992 if (ice_is_rdma_ena(pf)) {
3993 /* Need at least 1 interrupt in addition to
3996 v_rdma = ICE_RDMA_NUM_AEQ_MSIX + 1;
3997 v_min_rdma = ICE_MIN_RDMA_MSIX;
4000 if (v_actual == ICE_MIN_MSIX ||
4001 v_remain < ICE_MIN_LAN_TXRX_MSIX + v_min_rdma) {
4002 dev_warn(dev, "Not enough MSI-X vectors to support RDMA.\n");
4003 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
4005 pf->num_rdma_msix = 0;
4006 pf->num_lan_msix = ICE_MIN_LAN_TXRX_MSIX;
4007 } else if ((v_remain < ICE_MIN_LAN_TXRX_MSIX + v_rdma) ||
4008 (v_remain - v_rdma < v_rdma)) {
4009 /* Support minimum RDMA and give remaining
4010 * vectors to LAN MSIX
4012 pf->num_rdma_msix = v_min_rdma;
4013 pf->num_lan_msix = v_remain - v_min_rdma;
4015 /* Split remaining MSIX with RDMA after
4016 * accounting for AEQ MSIX
4018 pf->num_rdma_msix = (v_remain - ICE_RDMA_NUM_AEQ_MSIX) / 2 +
4019 ICE_RDMA_NUM_AEQ_MSIX;
4020 pf->num_lan_msix = v_remain - pf->num_rdma_msix;
4023 dev_notice(dev, "Enabled %d MSI-X vectors for LAN traffic.\n",
4026 if (ice_is_rdma_ena(pf))
4027 dev_notice(dev, "Enabled %d MSI-X vectors for RDMA.\n",
4035 devm_kfree(dev, pf->msix_entries);
4038 no_hw_vecs_left_err:
4039 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
4043 pf->num_rdma_msix = 0;
4044 pf->num_lan_msix = 0;
4049 * ice_dis_msix - Disable MSI-X interrupt setup in OS
4050 * @pf: board private structure
4052 static void ice_dis_msix(struct ice_pf *pf)
4054 pci_disable_msix(pf->pdev);
4055 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
4056 pf->msix_entries = NULL;
4060 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
4061 * @pf: board private structure
4063 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
4067 if (pf->irq_tracker) {
4068 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
4069 pf->irq_tracker = NULL;
4074 * ice_init_interrupt_scheme - Determine proper interrupt scheme
4075 * @pf: board private structure to initialize
4077 static int ice_init_interrupt_scheme(struct ice_pf *pf)
4081 vectors = ice_ena_msix_range(pf);
4086 /* set up vector assignment tracking */
4087 pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf),
4088 struct_size(pf->irq_tracker, list, vectors),
4090 if (!pf->irq_tracker) {
4095 /* populate SW interrupts pool with number of OS granted IRQs. */
4096 pf->num_avail_sw_msix = (u16)vectors;
4097 pf->irq_tracker->num_entries = (u16)vectors;
4098 pf->irq_tracker->end = pf->irq_tracker->num_entries;
4104 * ice_is_wol_supported - check if WoL is supported
4105 * @hw: pointer to hardware info
4107 * Check if WoL is supported based on the HW configuration.
4108 * Returns true if NVM supports and enables WoL for this port, false otherwise
4110 bool ice_is_wol_supported(struct ice_hw *hw)
4114 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control
4115 * word) indicates WoL is not supported on the corresponding PF ID.
4117 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl))
4120 return !(BIT(hw->port_info->lport) & wol_ctrl);
4124 * ice_vsi_recfg_qs - Change the number of queues on a VSI
4125 * @vsi: VSI being changed
4126 * @new_rx: new number of Rx queues
4127 * @new_tx: new number of Tx queues
4129 * Only change the number of queues if new_tx, or new_rx is non-0.
4131 * Returns 0 on success.
4133 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
4135 struct ice_pf *pf = vsi->back;
4136 int err = 0, timeout = 50;
4138 if (!new_rx && !new_tx)
4141 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
4145 usleep_range(1000, 2000);
4149 vsi->req_txq = (u16)new_tx;
4151 vsi->req_rxq = (u16)new_rx;
4153 /* set for the next time the netdev is started */
4154 if (!netif_running(vsi->netdev)) {
4155 ice_vsi_rebuild(vsi, false);
4156 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
4161 ice_vsi_rebuild(vsi, false);
4162 ice_pf_dcb_recfg(pf);
4165 clear_bit(ICE_CFG_BUSY, pf->state);
4170 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode
4171 * @pf: PF to configure
4173 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF
4174 * VSI can still Tx/Rx VLAN tagged packets.
4176 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf)
4178 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4179 struct ice_vsi_ctx *ctxt;
4186 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4191 ctxt->info = vsi->info;
4193 ctxt->info.valid_sections =
4194 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
4195 ICE_AQ_VSI_PROP_SECURITY_VALID |
4196 ICE_AQ_VSI_PROP_SW_VALID);
4198 /* disable VLAN anti-spoof */
4199 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
4200 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
4202 /* disable VLAN pruning and keep all other settings */
4203 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4205 /* allow all VLANs on Tx and don't strip on Rx */
4206 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL |
4207 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4209 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4211 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %d aq_err %s\n",
4212 status, ice_aq_str(hw->adminq.sq_last_status));
4214 vsi->info.sec_flags = ctxt->info.sec_flags;
4215 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
4216 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
4223 * ice_log_pkg_init - log result of DDP package load
4224 * @hw: pointer to hardware info
4225 * @state: state of package load
4227 static void ice_log_pkg_init(struct ice_hw *hw, enum ice_ddp_state state)
4229 struct ice_pf *pf = hw->back;
4232 dev = ice_pf_to_dev(pf);
4235 case ICE_DDP_PKG_SUCCESS:
4236 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
4237 hw->active_pkg_name,
4238 hw->active_pkg_ver.major,
4239 hw->active_pkg_ver.minor,
4240 hw->active_pkg_ver.update,
4241 hw->active_pkg_ver.draft);
4243 case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED:
4244 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
4245 hw->active_pkg_name,
4246 hw->active_pkg_ver.major,
4247 hw->active_pkg_ver.minor,
4248 hw->active_pkg_ver.update,
4249 hw->active_pkg_ver.draft);
4251 case ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED:
4252 dev_err(dev, "The device has a DDP package that is not supported by the driver. The device has package '%s' version %d.%d.x.x. The driver requires version %d.%d.x.x. Entering Safe Mode.\n",
4253 hw->active_pkg_name,
4254 hw->active_pkg_ver.major,
4255 hw->active_pkg_ver.minor,
4256 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4258 case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED:
4259 dev_info(dev, "The driver could not load the DDP package file because a compatible DDP package is already present on the device. The device has package '%s' version %d.%d.%d.%d. The package file found by the driver: '%s' version %d.%d.%d.%d.\n",
4260 hw->active_pkg_name,
4261 hw->active_pkg_ver.major,
4262 hw->active_pkg_ver.minor,
4263 hw->active_pkg_ver.update,
4264 hw->active_pkg_ver.draft,
4271 case ICE_DDP_PKG_FW_MISMATCH:
4272 dev_err(dev, "The firmware loaded on the device is not compatible with the DDP package. Please update the device's NVM. Entering safe mode.\n");
4274 case ICE_DDP_PKG_INVALID_FILE:
4275 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
4277 case ICE_DDP_PKG_FILE_VERSION_TOO_HIGH:
4278 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
4280 case ICE_DDP_PKG_FILE_VERSION_TOO_LOW:
4281 dev_err(dev, "The DDP package file version is lower than the driver supports. The driver requires version %d.%d.x.x. Please use an updated DDP Package file. Entering Safe Mode.\n",
4282 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4284 case ICE_DDP_PKG_FILE_SIGNATURE_INVALID:
4285 dev_err(dev, "The DDP package could not be loaded because its signature is not valid. Please use a valid DDP Package. Entering Safe Mode.\n");
4287 case ICE_DDP_PKG_FILE_REVISION_TOO_LOW:
4288 dev_err(dev, "The DDP Package could not be loaded because its security revision is too low. Please use an updated DDP Package. Entering Safe Mode.\n");
4290 case ICE_DDP_PKG_LOAD_ERROR:
4291 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
4292 /* poll for reset to complete */
4293 if (ice_check_reset(hw))
4294 dev_err(dev, "Error resetting device. Please reload the driver\n");
4296 case ICE_DDP_PKG_ERR:
4298 dev_err(dev, "An unknown error occurred when loading the DDP package. Entering Safe Mode.\n");
4304 * ice_load_pkg - load/reload the DDP Package file
4305 * @firmware: firmware structure when firmware requested or NULL for reload
4306 * @pf: pointer to the PF instance
4308 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
4309 * initialize HW tables.
4312 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
4314 enum ice_ddp_state state = ICE_DDP_PKG_ERR;
4315 struct device *dev = ice_pf_to_dev(pf);
4316 struct ice_hw *hw = &pf->hw;
4318 /* Load DDP Package */
4319 if (firmware && !hw->pkg_copy) {
4320 state = ice_copy_and_init_pkg(hw, firmware->data,
4322 ice_log_pkg_init(hw, state);
4323 } else if (!firmware && hw->pkg_copy) {
4324 /* Reload package during rebuild after CORER/GLOBR reset */
4325 state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
4326 ice_log_pkg_init(hw, state);
4328 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
4331 if (!ice_is_init_pkg_successful(state)) {
4333 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4337 /* Successful download package is the precondition for advanced
4338 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
4340 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4344 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
4345 * @pf: pointer to the PF structure
4347 * There is no error returned here because the driver should be able to handle
4348 * 128 Byte cache lines, so we only print a warning in case issues are seen,
4349 * specifically with Tx.
4351 static void ice_verify_cacheline_size(struct ice_pf *pf)
4353 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
4354 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
4355 ICE_CACHE_LINE_BYTES);
4359 * ice_send_version - update firmware with driver version
4362 * Returns 0 on success, else error code
4364 static int ice_send_version(struct ice_pf *pf)
4366 struct ice_driver_ver dv;
4368 dv.major_ver = 0xff;
4369 dv.minor_ver = 0xff;
4370 dv.build_ver = 0xff;
4371 dv.subbuild_ver = 0;
4372 strscpy((char *)dv.driver_string, UTS_RELEASE,
4373 sizeof(dv.driver_string));
4374 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
4378 * ice_init_fdir - Initialize flow director VSI and configuration
4379 * @pf: pointer to the PF instance
4381 * returns 0 on success, negative on error
4383 static int ice_init_fdir(struct ice_pf *pf)
4385 struct device *dev = ice_pf_to_dev(pf);
4386 struct ice_vsi *ctrl_vsi;
4389 /* Side Band Flow Director needs to have a control VSI.
4390 * Allocate it and store it in the PF.
4392 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
4394 dev_dbg(dev, "could not create control VSI\n");
4398 err = ice_vsi_open_ctrl(ctrl_vsi);
4400 dev_dbg(dev, "could not open control VSI\n");
4404 mutex_init(&pf->hw.fdir_fltr_lock);
4406 err = ice_fdir_create_dflt_rules(pf);
4413 ice_fdir_release_flows(&pf->hw);
4414 ice_vsi_close(ctrl_vsi);
4416 ice_vsi_release(ctrl_vsi);
4417 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4418 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4419 pf->ctrl_vsi_idx = ICE_NO_VSI;
4425 * ice_get_opt_fw_name - return optional firmware file name or NULL
4426 * @pf: pointer to the PF instance
4428 static char *ice_get_opt_fw_name(struct ice_pf *pf)
4430 /* Optional firmware name same as default with additional dash
4431 * followed by a EUI-64 identifier (PCIe Device Serial Number)
4433 struct pci_dev *pdev = pf->pdev;
4434 char *opt_fw_filename;
4437 /* Determine the name of the optional file using the DSN (two
4438 * dwords following the start of the DSN Capability).
4440 dsn = pci_get_dsn(pdev);
4444 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
4445 if (!opt_fw_filename)
4448 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg",
4449 ICE_DDP_PKG_PATH, dsn);
4451 return opt_fw_filename;
4455 * ice_request_fw - Device initialization routine
4456 * @pf: pointer to the PF instance
4458 static void ice_request_fw(struct ice_pf *pf)
4460 char *opt_fw_filename = ice_get_opt_fw_name(pf);
4461 const struct firmware *firmware = NULL;
4462 struct device *dev = ice_pf_to_dev(pf);
4465 /* optional device-specific DDP (if present) overrides the default DDP
4466 * package file. kernel logs a debug message if the file doesn't exist,
4467 * and warning messages for other errors.
4469 if (opt_fw_filename) {
4470 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
4472 kfree(opt_fw_filename);
4476 /* request for firmware was successful. Download to device */
4477 ice_load_pkg(firmware, pf);
4478 kfree(opt_fw_filename);
4479 release_firmware(firmware);
4484 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
4486 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
4490 /* request for firmware was successful. Download to device */
4491 ice_load_pkg(firmware, pf);
4492 release_firmware(firmware);
4496 * ice_print_wake_reason - show the wake up cause in the log
4497 * @pf: pointer to the PF struct
4499 static void ice_print_wake_reason(struct ice_pf *pf)
4501 u32 wus = pf->wakeup_reason;
4502 const char *wake_str;
4504 /* if no wake event, nothing to print */
4508 if (wus & PFPM_WUS_LNKC_M)
4509 wake_str = "Link\n";
4510 else if (wus & PFPM_WUS_MAG_M)
4511 wake_str = "Magic Packet\n";
4512 else if (wus & PFPM_WUS_MNG_M)
4513 wake_str = "Management\n";
4514 else if (wus & PFPM_WUS_FW_RST_WK_M)
4515 wake_str = "Firmware Reset\n";
4517 wake_str = "Unknown\n";
4519 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
4523 * ice_register_netdev - register netdev and devlink port
4524 * @pf: pointer to the PF struct
4526 static int ice_register_netdev(struct ice_pf *pf)
4528 struct ice_vsi *vsi;
4531 vsi = ice_get_main_vsi(pf);
4532 if (!vsi || !vsi->netdev)
4535 err = register_netdev(vsi->netdev);
4537 goto err_register_netdev;
4539 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4540 netif_carrier_off(vsi->netdev);
4541 netif_tx_stop_all_queues(vsi->netdev);
4542 err = ice_devlink_create_pf_port(pf);
4544 goto err_devlink_create;
4546 devlink_port_type_eth_set(&pf->devlink_port, vsi->netdev);
4550 unregister_netdev(vsi->netdev);
4551 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4552 err_register_netdev:
4553 free_netdev(vsi->netdev);
4555 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4560 * ice_probe - Device initialization routine
4561 * @pdev: PCI device information struct
4562 * @ent: entry in ice_pci_tbl
4564 * Returns 0 on success, negative on failure
4567 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
4569 struct device *dev = &pdev->dev;
4574 if (pdev->is_virtfn) {
4575 dev_err(dev, "can't probe a virtual function\n");
4579 /* this driver uses devres, see
4580 * Documentation/driver-api/driver-model/devres.rst
4582 err = pcim_enable_device(pdev);
4586 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev));
4588 dev_err(dev, "BAR0 I/O map error %d\n", err);
4592 pf = ice_allocate_pf(dev);
4596 /* initialize Auxiliary index to invalid value */
4599 /* set up for high or low DMA */
4600 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
4602 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
4606 pci_enable_pcie_error_reporting(pdev);
4607 pci_set_master(pdev);
4610 pci_set_drvdata(pdev, pf);
4611 set_bit(ICE_DOWN, pf->state);
4612 /* Disable service task until DOWN bit is cleared */
4613 set_bit(ICE_SERVICE_DIS, pf->state);
4616 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
4617 pci_save_state(pdev);
4620 hw->vendor_id = pdev->vendor;
4621 hw->device_id = pdev->device;
4622 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
4623 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4624 hw->subsystem_device_id = pdev->subsystem_device;
4625 hw->bus.device = PCI_SLOT(pdev->devfn);
4626 hw->bus.func = PCI_FUNC(pdev->devfn);
4627 ice_set_ctrlq_len(hw);
4629 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
4631 #ifndef CONFIG_DYNAMIC_DEBUG
4633 hw->debug_mask = debug;
4636 err = ice_init_hw(hw);
4638 dev_err(dev, "ice_init_hw failed: %d\n", err);
4640 goto err_exit_unroll;
4643 ice_init_feature_support(pf);
4647 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
4648 * set in pf->state, which will cause ice_is_safe_mode to return
4651 if (ice_is_safe_mode(pf)) {
4652 /* we already got function/device capabilities but these don't
4653 * reflect what the driver needs to do in safe mode. Instead of
4654 * adding conditional logic everywhere to ignore these
4655 * device/function capabilities, override them.
4657 ice_set_safe_mode_caps(hw);
4660 hw->ucast_shared = true;
4662 err = ice_init_pf(pf);
4664 dev_err(dev, "ice_init_pf failed: %d\n", err);
4665 goto err_init_pf_unroll;
4668 ice_devlink_init_regions(pf);
4670 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port;
4671 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port;
4672 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
4673 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared;
4675 if (pf->hw.tnl.valid_count[TNL_VXLAN]) {
4676 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4677 pf->hw.tnl.valid_count[TNL_VXLAN];
4678 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4679 UDP_TUNNEL_TYPE_VXLAN;
4682 if (pf->hw.tnl.valid_count[TNL_GENEVE]) {
4683 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4684 pf->hw.tnl.valid_count[TNL_GENEVE];
4685 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4686 UDP_TUNNEL_TYPE_GENEVE;
4690 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
4691 if (!pf->num_alloc_vsi) {
4693 goto err_init_pf_unroll;
4695 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
4696 dev_warn(&pf->pdev->dev,
4697 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
4698 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
4699 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
4702 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
4706 goto err_init_pf_unroll;
4709 err = ice_init_interrupt_scheme(pf);
4711 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
4713 goto err_init_vsi_unroll;
4716 /* In case of MSIX we are going to setup the misc vector right here
4717 * to handle admin queue events etc. In case of legacy and MSI
4718 * the misc functionality and queue processing is combined in
4719 * the same vector and that gets setup at open.
4721 err = ice_req_irq_msix_misc(pf);
4723 dev_err(dev, "setup of misc vector failed: %d\n", err);
4724 goto err_init_interrupt_unroll;
4727 /* create switch struct for the switch element created by FW on boot */
4728 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
4729 if (!pf->first_sw) {
4731 goto err_msix_misc_unroll;
4735 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
4737 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
4739 pf->first_sw->pf = pf;
4741 /* record the sw_id available for later use */
4742 pf->first_sw->sw_id = hw->port_info->sw_id;
4744 err = ice_setup_pf_sw(pf);
4746 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
4747 goto err_alloc_sw_unroll;
4750 clear_bit(ICE_SERVICE_DIS, pf->state);
4752 /* tell the firmware we are up */
4753 err = ice_send_version(pf);
4755 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
4757 goto err_send_version_unroll;
4760 /* since everything is good, start the service timer */
4761 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4763 err = ice_init_link_events(pf->hw.port_info);
4765 dev_err(dev, "ice_init_link_events failed: %d\n", err);
4766 goto err_send_version_unroll;
4769 /* not a fatal error if this fails */
4770 err = ice_init_nvm_phy_type(pf->hw.port_info);
4772 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err);
4774 /* not a fatal error if this fails */
4775 err = ice_update_link_info(pf->hw.port_info);
4777 dev_err(dev, "ice_update_link_info failed: %d\n", err);
4779 ice_init_link_dflt_override(pf->hw.port_info);
4781 ice_check_link_cfg_err(pf,
4782 pf->hw.port_info->phy.link_info.link_cfg_err);
4784 /* if media available, initialize PHY settings */
4785 if (pf->hw.port_info->phy.link_info.link_info &
4786 ICE_AQ_MEDIA_AVAILABLE) {
4787 /* not a fatal error if this fails */
4788 err = ice_init_phy_user_cfg(pf->hw.port_info);
4790 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err);
4792 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) {
4793 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4796 ice_configure_phy(vsi);
4799 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
4802 ice_verify_cacheline_size(pf);
4804 /* Save wakeup reason register for later use */
4805 pf->wakeup_reason = rd32(hw, PFPM_WUS);
4807 /* check for a power management event */
4808 ice_print_wake_reason(pf);
4810 /* clear wake status, all bits */
4811 wr32(hw, PFPM_WUS, U32_MAX);
4813 /* Disable WoL at init, wait for user to enable */
4814 device_set_wakeup_enable(dev, false);
4816 if (ice_is_safe_mode(pf)) {
4817 ice_set_safe_mode_vlan_cfg(pf);
4821 /* initialize DDP driven features */
4822 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4825 if (ice_is_feature_supported(pf, ICE_F_GNSS))
4828 /* Note: Flow director init failure is non-fatal to load */
4829 if (ice_init_fdir(pf))
4830 dev_err(dev, "could not initialize flow director\n");
4832 /* Note: DCB init failure is non-fatal to load */
4833 if (ice_init_pf_dcb(pf, false)) {
4834 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4835 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
4837 ice_cfg_lldp_mib_change(&pf->hw, true);
4840 if (ice_init_lag(pf))
4841 dev_warn(dev, "Failed to init link aggregation support\n");
4843 /* print PCI link speed and width */
4844 pcie_print_link_status(pf->pdev);
4847 err = ice_register_netdev(pf);
4849 goto err_netdev_reg;
4851 err = ice_devlink_register_params(pf);
4853 goto err_netdev_reg;
4855 /* ready to go, so clear down state bit */
4856 clear_bit(ICE_DOWN, pf->state);
4857 if (ice_is_rdma_ena(pf)) {
4858 pf->aux_idx = ida_alloc(&ice_aux_ida, GFP_KERNEL);
4859 if (pf->aux_idx < 0) {
4860 dev_err(dev, "Failed to allocate device ID for AUX driver\n");
4862 goto err_devlink_reg_param;
4865 err = ice_init_rdma(pf);
4867 dev_err(dev, "Failed to initialize RDMA: %d\n", err);
4869 goto err_init_aux_unroll;
4872 dev_warn(dev, "RDMA is not supported on this device\n");
4875 ice_devlink_register(pf);
4878 err_init_aux_unroll:
4880 ida_free(&ice_aux_ida, pf->aux_idx);
4881 err_devlink_reg_param:
4882 ice_devlink_unregister_params(pf);
4884 err_send_version_unroll:
4885 ice_vsi_release_all(pf);
4886 err_alloc_sw_unroll:
4887 set_bit(ICE_SERVICE_DIS, pf->state);
4888 set_bit(ICE_DOWN, pf->state);
4889 devm_kfree(dev, pf->first_sw);
4890 err_msix_misc_unroll:
4891 ice_free_irq_msix_misc(pf);
4892 err_init_interrupt_unroll:
4893 ice_clear_interrupt_scheme(pf);
4894 err_init_vsi_unroll:
4895 devm_kfree(dev, pf->vsi);
4898 ice_devlink_destroy_regions(pf);
4901 pci_disable_pcie_error_reporting(pdev);
4902 pci_disable_device(pdev);
4907 * ice_set_wake - enable or disable Wake on LAN
4908 * @pf: pointer to the PF struct
4910 * Simple helper for WoL control
4912 static void ice_set_wake(struct ice_pf *pf)
4914 struct ice_hw *hw = &pf->hw;
4915 bool wol = pf->wol_ena;
4917 /* clear wake state, otherwise new wake events won't fire */
4918 wr32(hw, PFPM_WUS, U32_MAX);
4920 /* enable / disable APM wake up, no RMW needed */
4921 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0);
4923 /* set magic packet filter enabled */
4924 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0);
4928 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet
4929 * @pf: pointer to the PF struct
4931 * Issue firmware command to enable multicast magic wake, making
4932 * sure that any locally administered address (LAA) is used for
4933 * wake, and that PF reset doesn't undo the LAA.
4935 static void ice_setup_mc_magic_wake(struct ice_pf *pf)
4937 struct device *dev = ice_pf_to_dev(pf);
4938 struct ice_hw *hw = &pf->hw;
4939 u8 mac_addr[ETH_ALEN];
4940 struct ice_vsi *vsi;
4947 vsi = ice_get_main_vsi(pf);
4951 /* Get current MAC address in case it's an LAA */
4953 ether_addr_copy(mac_addr, vsi->netdev->dev_addr);
4955 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
4957 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN |
4958 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL |
4959 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP;
4961 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL);
4963 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %d aq_err %s\n",
4964 status, ice_aq_str(hw->adminq.sq_last_status));
4968 * ice_remove - Device removal routine
4969 * @pdev: PCI device information struct
4971 static void ice_remove(struct pci_dev *pdev)
4973 struct ice_pf *pf = pci_get_drvdata(pdev);
4976 ice_devlink_unregister(pf);
4977 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
4978 if (!ice_is_reset_in_progress(pf->state))
4983 ice_tc_indir_block_remove(pf);
4985 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4986 set_bit(ICE_VF_RESETS_DISABLED, pf->state);
4990 ice_service_task_stop(pf);
4992 ice_aq_cancel_waiting_tasks(pf);
4993 ice_unplug_aux_dev(pf);
4994 if (pf->aux_idx >= 0)
4995 ida_free(&ice_aux_ida, pf->aux_idx);
4996 ice_devlink_unregister_params(pf);
4997 set_bit(ICE_DOWN, pf->state);
5000 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
5001 ice_ptp_release(pf);
5002 if (ice_is_feature_supported(pf, ICE_F_GNSS))
5004 if (!ice_is_safe_mode(pf))
5005 ice_remove_arfs(pf);
5006 ice_setup_mc_magic_wake(pf);
5007 ice_vsi_release_all(pf);
5008 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
5010 ice_free_irq_msix_misc(pf);
5011 ice_for_each_vsi(pf, i) {
5014 ice_vsi_free_q_vectors(pf->vsi[i]);
5017 ice_devlink_destroy_regions(pf);
5018 ice_deinit_hw(&pf->hw);
5020 /* Issue a PFR as part of the prescribed driver unload flow. Do not
5021 * do it via ice_schedule_reset() since there is no need to rebuild
5022 * and the service task is already stopped.
5024 ice_reset(&pf->hw, ICE_RESET_PFR);
5025 pci_wait_for_pending_transaction(pdev);
5026 ice_clear_interrupt_scheme(pf);
5027 pci_disable_pcie_error_reporting(pdev);
5028 pci_disable_device(pdev);
5032 * ice_shutdown - PCI callback for shutting down device
5033 * @pdev: PCI device information struct
5035 static void ice_shutdown(struct pci_dev *pdev)
5037 struct ice_pf *pf = pci_get_drvdata(pdev);
5041 if (system_state == SYSTEM_POWER_OFF) {
5042 pci_wake_from_d3(pdev, pf->wol_ena);
5043 pci_set_power_state(pdev, PCI_D3hot);
5049 * ice_prepare_for_shutdown - prep for PCI shutdown
5050 * @pf: board private structure
5052 * Inform or close all dependent features in prep for PCI device shutdown
5054 static void ice_prepare_for_shutdown(struct ice_pf *pf)
5056 struct ice_hw *hw = &pf->hw;
5059 /* Notify VFs of impending reset */
5060 if (ice_check_sq_alive(hw, &hw->mailboxq))
5061 ice_vc_notify_reset(pf);
5063 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n");
5065 /* disable the VSIs and their queues that are not already DOWN */
5066 ice_pf_dis_all_vsi(pf, false);
5068 ice_for_each_vsi(pf, v)
5070 pf->vsi[v]->vsi_num = 0;
5072 ice_shutdown_all_ctrlq(hw);
5076 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme
5077 * @pf: board private structure to reinitialize
5079 * This routine reinitialize interrupt scheme that was cleared during
5080 * power management suspend callback.
5082 * This should be called during resume routine to re-allocate the q_vectors
5083 * and reacquire interrupts.
5085 static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
5087 struct device *dev = ice_pf_to_dev(pf);
5090 /* Since we clear MSIX flag during suspend, we need to
5091 * set it back during resume...
5094 ret = ice_init_interrupt_scheme(pf);
5096 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret);
5100 /* Remap vectors and rings, after successful re-init interrupts */
5101 ice_for_each_vsi(pf, v) {
5105 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]);
5108 ice_vsi_map_rings_to_vectors(pf->vsi[v]);
5111 ret = ice_req_irq_msix_misc(pf);
5113 dev_err(dev, "Setting up misc vector failed after device suspend %d\n",
5123 ice_vsi_free_q_vectors(pf->vsi[v]);
5130 * @dev: generic device information structure
5132 * Power Management callback to quiesce the device and prepare
5133 * for D3 transition.
5135 static int __maybe_unused ice_suspend(struct device *dev)
5137 struct pci_dev *pdev = to_pci_dev(dev);
5141 pf = pci_get_drvdata(pdev);
5143 if (!ice_pf_state_is_nominal(pf)) {
5144 dev_err(dev, "Device is not ready, no need to suspend it\n");
5148 /* Stop watchdog tasks until resume completion.
5149 * Even though it is most likely that the service task is
5150 * disabled if the device is suspended or down, the service task's
5151 * state is controlled by a different state bit, and we should
5152 * store and honor whatever state that bit is in at this point.
5154 disabled = ice_service_task_stop(pf);
5156 ice_unplug_aux_dev(pf);
5158 /* Already suspended?, then there is nothing to do */
5159 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) {
5161 ice_service_task_restart(pf);
5165 if (test_bit(ICE_DOWN, pf->state) ||
5166 ice_is_reset_in_progress(pf->state)) {
5167 dev_err(dev, "can't suspend device in reset or already down\n");
5169 ice_service_task_restart(pf);
5173 ice_setup_mc_magic_wake(pf);
5175 ice_prepare_for_shutdown(pf);
5179 /* Free vectors, clear the interrupt scheme and release IRQs
5180 * for proper hibernation, especially with large number of CPUs.
5181 * Otherwise hibernation might fail when mapping all the vectors back
5184 ice_free_irq_msix_misc(pf);
5185 ice_for_each_vsi(pf, v) {
5188 ice_vsi_free_q_vectors(pf->vsi[v]);
5190 ice_clear_interrupt_scheme(pf);
5192 pci_save_state(pdev);
5193 pci_wake_from_d3(pdev, pf->wol_ena);
5194 pci_set_power_state(pdev, PCI_D3hot);
5199 * ice_resume - PM callback for waking up from D3
5200 * @dev: generic device information structure
5202 static int __maybe_unused ice_resume(struct device *dev)
5204 struct pci_dev *pdev = to_pci_dev(dev);
5205 enum ice_reset_req reset_type;
5210 pci_set_power_state(pdev, PCI_D0);
5211 pci_restore_state(pdev);
5212 pci_save_state(pdev);
5214 if (!pci_device_is_present(pdev))
5217 ret = pci_enable_device_mem(pdev);
5219 dev_err(dev, "Cannot enable device after suspend\n");
5223 pf = pci_get_drvdata(pdev);
5226 pf->wakeup_reason = rd32(hw, PFPM_WUS);
5227 ice_print_wake_reason(pf);
5229 /* We cleared the interrupt scheme when we suspended, so we need to
5230 * restore it now to resume device functionality.
5232 ret = ice_reinit_interrupt_scheme(pf);
5234 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret);
5236 clear_bit(ICE_DOWN, pf->state);
5237 /* Now perform PF reset and rebuild */
5238 reset_type = ICE_RESET_PFR;
5239 /* re-enable service task for reset, but allow reset to schedule it */
5240 clear_bit(ICE_SERVICE_DIS, pf->state);
5242 if (ice_schedule_reset(pf, reset_type))
5243 dev_err(dev, "Reset during resume failed.\n");
5245 clear_bit(ICE_SUSPENDED, pf->state);
5246 ice_service_task_restart(pf);
5248 /* Restart the service task */
5249 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5253 #endif /* CONFIG_PM */
5256 * ice_pci_err_detected - warning that PCI error has been detected
5257 * @pdev: PCI device information struct
5258 * @err: the type of PCI error
5260 * Called to warn that something happened on the PCI bus and the error handling
5261 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
5263 static pci_ers_result_t
5264 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err)
5266 struct ice_pf *pf = pci_get_drvdata(pdev);
5269 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
5271 return PCI_ERS_RESULT_DISCONNECT;
5274 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5275 ice_service_task_stop(pf);
5277 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5278 set_bit(ICE_PFR_REQ, pf->state);
5279 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5283 return PCI_ERS_RESULT_NEED_RESET;
5287 * ice_pci_err_slot_reset - a PCI slot reset has just happened
5288 * @pdev: PCI device information struct
5290 * Called to determine if the driver can recover from the PCI slot reset by
5291 * using a register read to determine if the device is recoverable.
5293 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
5295 struct ice_pf *pf = pci_get_drvdata(pdev);
5296 pci_ers_result_t result;
5300 err = pci_enable_device_mem(pdev);
5302 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
5304 result = PCI_ERS_RESULT_DISCONNECT;
5306 pci_set_master(pdev);
5307 pci_restore_state(pdev);
5308 pci_save_state(pdev);
5309 pci_wake_from_d3(pdev, false);
5311 /* Check for life */
5312 reg = rd32(&pf->hw, GLGEN_RTRIG);
5314 result = PCI_ERS_RESULT_RECOVERED;
5316 result = PCI_ERS_RESULT_DISCONNECT;
5323 * ice_pci_err_resume - restart operations after PCI error recovery
5324 * @pdev: PCI device information struct
5326 * Called to allow the driver to bring things back up after PCI error and/or
5327 * reset recovery have finished
5329 static void ice_pci_err_resume(struct pci_dev *pdev)
5331 struct ice_pf *pf = pci_get_drvdata(pdev);
5334 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
5339 if (test_bit(ICE_SUSPENDED, pf->state)) {
5340 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
5345 ice_restore_all_vfs_msi_state(pdev);
5347 ice_do_reset(pf, ICE_RESET_PFR);
5348 ice_service_task_restart(pf);
5349 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5353 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
5354 * @pdev: PCI device information struct
5356 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
5358 struct ice_pf *pf = pci_get_drvdata(pdev);
5360 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5361 ice_service_task_stop(pf);
5363 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5364 set_bit(ICE_PFR_REQ, pf->state);
5365 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5371 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
5372 * @pdev: PCI device information struct
5374 static void ice_pci_err_reset_done(struct pci_dev *pdev)
5376 ice_pci_err_resume(pdev);
5379 /* ice_pci_tbl - PCI Device ID Table
5381 * Wildcard entries (PCI_ANY_ID) should come last
5382 * Last entry must be all 0s
5384 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
5385 * Class, Class Mask, private data (not used) }
5387 static const struct pci_device_id ice_pci_tbl[] = {
5388 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
5389 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
5390 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
5391 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_BACKPLANE), 0 },
5392 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_QSFP), 0 },
5393 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 },
5394 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 },
5395 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 },
5396 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 },
5397 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 },
5398 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 },
5399 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
5400 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
5401 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
5402 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
5403 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
5404 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 },
5405 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
5406 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
5407 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
5408 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 },
5409 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 },
5410 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 },
5411 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 },
5412 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 },
5413 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822_SI_DFLT), 0 },
5414 /* required last entry */
5417 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
5419 static __maybe_unused SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume);
5421 static const struct pci_error_handlers ice_pci_err_handler = {
5422 .error_detected = ice_pci_err_detected,
5423 .slot_reset = ice_pci_err_slot_reset,
5424 .reset_prepare = ice_pci_err_reset_prepare,
5425 .reset_done = ice_pci_err_reset_done,
5426 .resume = ice_pci_err_resume
5429 static struct pci_driver ice_driver = {
5430 .name = KBUILD_MODNAME,
5431 .id_table = ice_pci_tbl,
5433 .remove = ice_remove,
5435 .driver.pm = &ice_pm_ops,
5436 #endif /* CONFIG_PM */
5437 .shutdown = ice_shutdown,
5438 .sriov_configure = ice_sriov_configure,
5439 .err_handler = &ice_pci_err_handler
5443 * ice_module_init - Driver registration routine
5445 * ice_module_init is the first routine called when the driver is
5446 * loaded. All it does is register with the PCI subsystem.
5448 static int __init ice_module_init(void)
5452 pr_info("%s\n", ice_driver_string);
5453 pr_info("%s\n", ice_copyright);
5455 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
5457 pr_err("Failed to create workqueue\n");
5461 status = pci_register_driver(&ice_driver);
5463 pr_err("failed to register PCI driver, err %d\n", status);
5464 destroy_workqueue(ice_wq);
5469 module_init(ice_module_init);
5472 * ice_module_exit - Driver exit cleanup routine
5474 * ice_module_exit is called just before the driver is removed
5477 static void __exit ice_module_exit(void)
5479 pci_unregister_driver(&ice_driver);
5480 destroy_workqueue(ice_wq);
5481 pr_info("module unloaded\n");
5483 module_exit(ice_module_exit);
5486 * ice_set_mac_address - NDO callback to set MAC address
5487 * @netdev: network interface device structure
5488 * @pi: pointer to an address structure
5490 * Returns 0 on success, negative on failure
5492 static int ice_set_mac_address(struct net_device *netdev, void *pi)
5494 struct ice_netdev_priv *np = netdev_priv(netdev);
5495 struct ice_vsi *vsi = np->vsi;
5496 struct ice_pf *pf = vsi->back;
5497 struct ice_hw *hw = &pf->hw;
5498 struct sockaddr *addr = pi;
5499 u8 old_mac[ETH_ALEN];
5504 mac = (u8 *)addr->sa_data;
5506 if (!is_valid_ether_addr(mac))
5507 return -EADDRNOTAVAIL;
5509 if (ether_addr_equal(netdev->dev_addr, mac)) {
5510 netdev_dbg(netdev, "already using mac %pM\n", mac);
5514 if (test_bit(ICE_DOWN, pf->state) ||
5515 ice_is_reset_in_progress(pf->state)) {
5516 netdev_err(netdev, "can't set mac %pM. device not ready\n",
5521 if (ice_chnl_dmac_fltr_cnt(pf)) {
5522 netdev_err(netdev, "can't set mac %pM. Device has tc-flower filters, delete all of them and try again\n",
5527 netif_addr_lock_bh(netdev);
5528 ether_addr_copy(old_mac, netdev->dev_addr);
5529 /* change the netdev's MAC address */
5530 eth_hw_addr_set(netdev, mac);
5531 netif_addr_unlock_bh(netdev);
5533 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
5534 err = ice_fltr_remove_mac(vsi, old_mac, ICE_FWD_TO_VSI);
5535 if (err && err != -ENOENT) {
5536 err = -EADDRNOTAVAIL;
5537 goto err_update_filters;
5540 /* Add filter for new MAC. If filter exists, return success */
5541 err = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
5542 if (err == -EEXIST) {
5543 /* Although this MAC filter is already present in hardware it's
5544 * possible in some cases (e.g. bonding) that dev_addr was
5545 * modified outside of the driver and needs to be restored back
5548 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
5552 /* error if the new filter addition failed */
5553 err = -EADDRNOTAVAIL;
5558 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
5560 netif_addr_lock_bh(netdev);
5561 eth_hw_addr_set(netdev, old_mac);
5562 netif_addr_unlock_bh(netdev);
5566 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
5569 /* write new MAC address to the firmware */
5570 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
5571 err = ice_aq_manage_mac_write(hw, mac, flags, NULL);
5573 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
5580 * ice_set_rx_mode - NDO callback to set the netdev filters
5581 * @netdev: network interface device structure
5583 static void ice_set_rx_mode(struct net_device *netdev)
5585 struct ice_netdev_priv *np = netdev_priv(netdev);
5586 struct ice_vsi *vsi = np->vsi;
5591 /* Set the flags to synchronize filters
5592 * ndo_set_rx_mode may be triggered even without a change in netdev
5595 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
5596 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
5597 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
5599 /* schedule our worker thread which will take care of
5600 * applying the new filter changes
5602 ice_service_task_schedule(vsi->back);
5606 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
5607 * @netdev: network interface device structure
5608 * @queue_index: Queue ID
5609 * @maxrate: maximum bandwidth in Mbps
5612 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
5614 struct ice_netdev_priv *np = netdev_priv(netdev);
5615 struct ice_vsi *vsi = np->vsi;
5620 /* Validate maxrate requested is within permitted range */
5621 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
5622 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
5623 maxrate, queue_index);
5627 q_handle = vsi->tx_rings[queue_index]->q_handle;
5628 tc = ice_dcb_get_tc(vsi, queue_index);
5630 /* Set BW back to default, when user set maxrate to 0 */
5632 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
5633 q_handle, ICE_MAX_BW);
5635 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
5636 q_handle, ICE_MAX_BW, maxrate * 1000);
5638 netdev_err(netdev, "Unable to set Tx max rate, error %d\n",
5645 * ice_fdb_add - add an entry to the hardware database
5646 * @ndm: the input from the stack
5647 * @tb: pointer to array of nladdr (unused)
5648 * @dev: the net device pointer
5649 * @addr: the MAC address entry being added
5651 * @flags: instructions from stack about fdb operation
5652 * @extack: netlink extended ack
5655 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
5656 struct net_device *dev, const unsigned char *addr, u16 vid,
5657 u16 flags, struct netlink_ext_ack __always_unused *extack)
5662 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
5665 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
5666 netdev_err(dev, "FDB only supports static addresses\n");
5670 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
5671 err = dev_uc_add_excl(dev, addr);
5672 else if (is_multicast_ether_addr(addr))
5673 err = dev_mc_add_excl(dev, addr);
5677 /* Only return duplicate errors if NLM_F_EXCL is set */
5678 if (err == -EEXIST && !(flags & NLM_F_EXCL))
5685 * ice_fdb_del - delete an entry from the hardware database
5686 * @ndm: the input from the stack
5687 * @tb: pointer to array of nladdr (unused)
5688 * @dev: the net device pointer
5689 * @addr: the MAC address entry being added
5691 * @extack: netlink extended ack
5694 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
5695 struct net_device *dev, const unsigned char *addr,
5696 __always_unused u16 vid, struct netlink_ext_ack *extack)
5700 if (ndm->ndm_state & NUD_PERMANENT) {
5701 netdev_err(dev, "FDB only supports static addresses\n");
5705 if (is_unicast_ether_addr(addr))
5706 err = dev_uc_del(dev, addr);
5707 else if (is_multicast_ether_addr(addr))
5708 err = dev_mc_del(dev, addr);
5715 #define NETIF_VLAN_OFFLOAD_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \
5716 NETIF_F_HW_VLAN_CTAG_TX | \
5717 NETIF_F_HW_VLAN_STAG_RX | \
5718 NETIF_F_HW_VLAN_STAG_TX)
5720 #define NETIF_VLAN_FILTERING_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
5721 NETIF_F_HW_VLAN_STAG_FILTER)
5724 * ice_fix_features - fix the netdev features flags based on device limitations
5725 * @netdev: ptr to the netdev that flags are being fixed on
5726 * @features: features that need to be checked and possibly fixed
5728 * Make sure any fixups are made to features in this callback. This enables the
5729 * driver to not have to check unsupported configurations throughout the driver
5730 * because that's the responsiblity of this callback.
5732 * Single VLAN Mode (SVM) Supported Features:
5733 * NETIF_F_HW_VLAN_CTAG_FILTER
5734 * NETIF_F_HW_VLAN_CTAG_RX
5735 * NETIF_F_HW_VLAN_CTAG_TX
5737 * Double VLAN Mode (DVM) Supported Features:
5738 * NETIF_F_HW_VLAN_CTAG_FILTER
5739 * NETIF_F_HW_VLAN_CTAG_RX
5740 * NETIF_F_HW_VLAN_CTAG_TX
5742 * NETIF_F_HW_VLAN_STAG_FILTER
5743 * NETIF_HW_VLAN_STAG_RX
5744 * NETIF_HW_VLAN_STAG_TX
5746 * Features that need fixing:
5747 * Cannot simultaneously enable CTAG and STAG stripping and/or insertion.
5748 * These are mutually exlusive as the VSI context cannot support multiple
5749 * VLAN ethertypes simultaneously for stripping and/or insertion. If this
5750 * is not done, then default to clearing the requested STAG offload
5753 * All supported filtering has to be enabled or disabled together. For
5754 * example, in DVM, CTAG and STAG filtering have to be enabled and disabled
5755 * together. If this is not done, then default to VLAN filtering disabled.
5756 * These are mutually exclusive as there is currently no way to
5757 * enable/disable VLAN filtering based on VLAN ethertype when using VLAN
5760 static netdev_features_t
5761 ice_fix_features(struct net_device *netdev, netdev_features_t features)
5763 struct ice_netdev_priv *np = netdev_priv(netdev);
5764 netdev_features_t req_vlan_fltr, cur_vlan_fltr;
5765 bool cur_ctag, cur_stag, req_ctag, req_stag;
5767 cur_vlan_fltr = netdev->features & NETIF_VLAN_FILTERING_FEATURES;
5768 cur_ctag = cur_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER;
5769 cur_stag = cur_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER;
5771 req_vlan_fltr = features & NETIF_VLAN_FILTERING_FEATURES;
5772 req_ctag = req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER;
5773 req_stag = req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER;
5775 if (req_vlan_fltr != cur_vlan_fltr) {
5776 if (ice_is_dvm_ena(&np->vsi->back->hw)) {
5777 if (req_ctag && req_stag) {
5778 features |= NETIF_VLAN_FILTERING_FEATURES;
5779 } else if (!req_ctag && !req_stag) {
5780 features &= ~NETIF_VLAN_FILTERING_FEATURES;
5781 } else if ((!cur_ctag && req_ctag && !cur_stag) ||
5782 (!cur_stag && req_stag && !cur_ctag)) {
5783 features |= NETIF_VLAN_FILTERING_FEATURES;
5784 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been enabled for both types.\n");
5785 } else if ((cur_ctag && !req_ctag && cur_stag) ||
5786 (cur_stag && !req_stag && cur_ctag)) {
5787 features &= ~NETIF_VLAN_FILTERING_FEATURES;
5788 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been disabled for both types.\n");
5791 if (req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER)
5792 netdev_warn(netdev, "cannot support requested 802.1ad filtering setting in SVM mode\n");
5794 if (req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER)
5795 features |= NETIF_F_HW_VLAN_CTAG_FILTER;
5799 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) &&
5800 (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))) {
5801 netdev_warn(netdev, "cannot support CTAG and STAG VLAN stripping and/or insertion simultaneously since CTAG and STAG offloads are mutually exclusive, clearing STAG offload settings\n");
5802 features &= ~(NETIF_F_HW_VLAN_STAG_RX |
5803 NETIF_F_HW_VLAN_STAG_TX);
5810 * ice_set_vlan_offload_features - set VLAN offload features for the PF VSI
5812 * @features: features used to determine VLAN offload settings
5814 * First, determine the vlan_ethertype based on the VLAN offload bits in
5815 * features. Then determine if stripping and insertion should be enabled or
5816 * disabled. Finally enable or disable VLAN stripping and insertion.
5819 ice_set_vlan_offload_features(struct ice_vsi *vsi, netdev_features_t features)
5821 bool enable_stripping = true, enable_insertion = true;
5822 struct ice_vsi_vlan_ops *vlan_ops;
5823 int strip_err = 0, insert_err = 0;
5824 u16 vlan_ethertype = 0;
5826 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5828 if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
5829 vlan_ethertype = ETH_P_8021AD;
5830 else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
5831 vlan_ethertype = ETH_P_8021Q;
5833 if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
5834 enable_stripping = false;
5835 if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
5836 enable_insertion = false;
5838 if (enable_stripping)
5839 strip_err = vlan_ops->ena_stripping(vsi, vlan_ethertype);
5841 strip_err = vlan_ops->dis_stripping(vsi);
5843 if (enable_insertion)
5844 insert_err = vlan_ops->ena_insertion(vsi, vlan_ethertype);
5846 insert_err = vlan_ops->dis_insertion(vsi);
5848 if (strip_err || insert_err)
5855 * ice_set_vlan_filtering_features - set VLAN filtering features for the PF VSI
5857 * @features: features used to determine VLAN filtering settings
5859 * Enable or disable Rx VLAN filtering based on the VLAN filtering bits in the
5863 ice_set_vlan_filtering_features(struct ice_vsi *vsi, netdev_features_t features)
5865 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5868 /* support Single VLAN Mode (SVM) and Double VLAN Mode (DVM) by checking
5869 * if either bit is set
5872 (NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER))
5873 err = vlan_ops->ena_rx_filtering(vsi);
5875 err = vlan_ops->dis_rx_filtering(vsi);
5881 * ice_set_vlan_features - set VLAN settings based on suggested feature set
5882 * @netdev: ptr to the netdev being adjusted
5883 * @features: the feature set that the stack is suggesting
5885 * Only update VLAN settings if the requested_vlan_features are different than
5886 * the current_vlan_features.
5889 ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
5891 netdev_features_t current_vlan_features, requested_vlan_features;
5892 struct ice_netdev_priv *np = netdev_priv(netdev);
5893 struct ice_vsi *vsi = np->vsi;
5896 current_vlan_features = netdev->features & NETIF_VLAN_OFFLOAD_FEATURES;
5897 requested_vlan_features = features & NETIF_VLAN_OFFLOAD_FEATURES;
5898 if (current_vlan_features ^ requested_vlan_features) {
5899 err = ice_set_vlan_offload_features(vsi, features);
5904 current_vlan_features = netdev->features &
5905 NETIF_VLAN_FILTERING_FEATURES;
5906 requested_vlan_features = features & NETIF_VLAN_FILTERING_FEATURES;
5907 if (current_vlan_features ^ requested_vlan_features) {
5908 err = ice_set_vlan_filtering_features(vsi, features);
5917 * ice_set_loopback - turn on/off loopback mode on underlying PF
5919 * @ena: flag to indicate the on/off setting
5921 static int ice_set_loopback(struct ice_vsi *vsi, bool ena)
5923 bool if_running = netif_running(vsi->netdev);
5926 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
5927 ret = ice_down(vsi);
5929 netdev_err(vsi->netdev, "Preparing device to toggle loopback failed\n");
5933 ret = ice_aq_set_mac_loopback(&vsi->back->hw, ena, NULL);
5935 netdev_err(vsi->netdev, "Failed to toggle loopback state\n");
5943 * ice_set_features - set the netdev feature flags
5944 * @netdev: ptr to the netdev being adjusted
5945 * @features: the feature set that the stack is suggesting
5948 ice_set_features(struct net_device *netdev, netdev_features_t features)
5950 netdev_features_t changed = netdev->features ^ features;
5951 struct ice_netdev_priv *np = netdev_priv(netdev);
5952 struct ice_vsi *vsi = np->vsi;
5953 struct ice_pf *pf = vsi->back;
5956 /* Don't set any netdev advanced features with device in Safe Mode */
5957 if (ice_is_safe_mode(pf)) {
5958 dev_err(ice_pf_to_dev(pf),
5959 "Device is in Safe Mode - not enabling advanced netdev features\n");
5963 /* Do not change setting during reset */
5964 if (ice_is_reset_in_progress(pf->state)) {
5965 dev_err(ice_pf_to_dev(pf),
5966 "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
5970 /* Multiple features can be changed in one call so keep features in
5971 * separate if/else statements to guarantee each feature is checked
5973 if (changed & NETIF_F_RXHASH)
5974 ice_vsi_manage_rss_lut(vsi, !!(features & NETIF_F_RXHASH));
5976 ret = ice_set_vlan_features(netdev, features);
5980 if (changed & NETIF_F_NTUPLE) {
5981 bool ena = !!(features & NETIF_F_NTUPLE);
5983 ice_vsi_manage_fdir(vsi, ena);
5984 ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi);
5987 /* don't turn off hw_tc_offload when ADQ is already enabled */
5988 if (!(features & NETIF_F_HW_TC) && ice_is_adq_active(pf)) {
5989 dev_err(ice_pf_to_dev(pf), "ADQ is active, can't turn hw_tc_offload off\n");
5993 if (changed & NETIF_F_HW_TC) {
5994 bool ena = !!(features & NETIF_F_HW_TC);
5996 ena ? set_bit(ICE_FLAG_CLS_FLOWER, pf->flags) :
5997 clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
6000 if (changed & NETIF_F_LOOPBACK)
6001 ret = ice_set_loopback(vsi, !!(features & NETIF_F_LOOPBACK));
6007 * ice_vsi_vlan_setup - Setup VLAN offload properties on a PF VSI
6008 * @vsi: VSI to setup VLAN properties for
6010 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
6014 err = ice_set_vlan_offload_features(vsi, vsi->netdev->features);
6018 err = ice_set_vlan_filtering_features(vsi, vsi->netdev->features);
6022 return ice_vsi_add_vlan_zero(vsi);
6026 * ice_vsi_cfg - Setup the VSI
6027 * @vsi: the VSI being configured
6029 * Return 0 on success and negative value on error
6031 int ice_vsi_cfg(struct ice_vsi *vsi)
6036 ice_set_rx_mode(vsi->netdev);
6038 if (vsi->type != ICE_VSI_LB) {
6039 err = ice_vsi_vlan_setup(vsi);
6045 ice_vsi_cfg_dcb_rings(vsi);
6047 err = ice_vsi_cfg_lan_txqs(vsi);
6048 if (!err && ice_is_xdp_ena_vsi(vsi))
6049 err = ice_vsi_cfg_xdp_txqs(vsi);
6051 err = ice_vsi_cfg_rxqs(vsi);
6056 /* THEORY OF MODERATION:
6057 * The ice driver hardware works differently than the hardware that DIMLIB was
6058 * originally made for. ice hardware doesn't have packet count limits that
6059 * can trigger an interrupt, but it *does* have interrupt rate limit support,
6060 * which is hard-coded to a limit of 250,000 ints/second.
6061 * If not using dynamic moderation, the INTRL value can be modified
6062 * by ethtool rx-usecs-high.
6065 /* the throttle rate for interrupts, basically worst case delay before
6066 * an initial interrupt fires, value is stored in microseconds.
6071 /* Make a different profile for Rx that doesn't allow quite so aggressive
6072 * moderation at the high end (it maxes out at 126us or about 8k interrupts a
6075 static const struct ice_dim rx_profile[] = {
6076 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6077 {8}, /* 125,000 ints/s */
6078 {16}, /* 62,500 ints/s */
6079 {62}, /* 16,129 ints/s */
6080 {126} /* 7,936 ints/s */
6083 /* The transmit profile, which has the same sorts of values
6084 * as the previous struct
6086 static const struct ice_dim tx_profile[] = {
6087 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6088 {8}, /* 125,000 ints/s */
6089 {40}, /* 16,125 ints/s */
6090 {128}, /* 7,812 ints/s */
6091 {256} /* 3,906 ints/s */
6094 static void ice_tx_dim_work(struct work_struct *work)
6096 struct ice_ring_container *rc;
6100 dim = container_of(work, struct dim, work);
6101 rc = (struct ice_ring_container *)dim->priv;
6103 WARN_ON(dim->profile_ix >= ARRAY_SIZE(tx_profile));
6105 /* look up the values in our local table */
6106 itr = tx_profile[dim->profile_ix].itr;
6108 ice_trace(tx_dim_work, container_of(rc, struct ice_q_vector, tx), dim);
6109 ice_write_itr(rc, itr);
6111 dim->state = DIM_START_MEASURE;
6114 static void ice_rx_dim_work(struct work_struct *work)
6116 struct ice_ring_container *rc;
6120 dim = container_of(work, struct dim, work);
6121 rc = (struct ice_ring_container *)dim->priv;
6123 WARN_ON(dim->profile_ix >= ARRAY_SIZE(rx_profile));
6125 /* look up the values in our local table */
6126 itr = rx_profile[dim->profile_ix].itr;
6128 ice_trace(rx_dim_work, container_of(rc, struct ice_q_vector, rx), dim);
6129 ice_write_itr(rc, itr);
6131 dim->state = DIM_START_MEASURE;
6134 #define ICE_DIM_DEFAULT_PROFILE_IX 1
6137 * ice_init_moderation - set up interrupt moderation
6138 * @q_vector: the vector containing rings to be configured
6140 * Set up interrupt moderation registers, with the intent to do the right thing
6141 * when called from reset or from probe, and whether or not dynamic moderation
6142 * is enabled or not. Take special care to write all the registers in both
6143 * dynamic moderation mode or not in order to make sure hardware is in a known
6146 static void ice_init_moderation(struct ice_q_vector *q_vector)
6148 struct ice_ring_container *rc;
6149 bool tx_dynamic, rx_dynamic;
6152 INIT_WORK(&rc->dim.work, ice_tx_dim_work);
6153 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6154 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6156 tx_dynamic = ITR_IS_DYNAMIC(rc);
6158 /* set the initial TX ITR to match the above */
6159 ice_write_itr(rc, tx_dynamic ?
6160 tx_profile[rc->dim.profile_ix].itr : rc->itr_setting);
6163 INIT_WORK(&rc->dim.work, ice_rx_dim_work);
6164 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6165 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6167 rx_dynamic = ITR_IS_DYNAMIC(rc);
6169 /* set the initial RX ITR to match the above */
6170 ice_write_itr(rc, rx_dynamic ? rx_profile[rc->dim.profile_ix].itr :
6173 ice_set_q_vector_intrl(q_vector);
6177 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
6178 * @vsi: the VSI being configured
6180 static void ice_napi_enable_all(struct ice_vsi *vsi)
6187 ice_for_each_q_vector(vsi, q_idx) {
6188 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6190 ice_init_moderation(q_vector);
6192 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6193 napi_enable(&q_vector->napi);
6198 * ice_up_complete - Finish the last steps of bringing up a connection
6199 * @vsi: The VSI being configured
6201 * Return 0 on success and negative value on error
6203 static int ice_up_complete(struct ice_vsi *vsi)
6205 struct ice_pf *pf = vsi->back;
6208 ice_vsi_cfg_msix(vsi);
6210 /* Enable only Rx rings, Tx rings were enabled by the FW when the
6211 * Tx queue group list was configured and the context bits were
6212 * programmed using ice_vsi_cfg_txqs
6214 err = ice_vsi_start_all_rx_rings(vsi);
6218 clear_bit(ICE_VSI_DOWN, vsi->state);
6219 ice_napi_enable_all(vsi);
6220 ice_vsi_ena_irq(vsi);
6222 if (vsi->port_info &&
6223 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
6225 ice_print_link_msg(vsi, true);
6226 netif_tx_start_all_queues(vsi->netdev);
6227 netif_carrier_on(vsi->netdev);
6228 if (!ice_is_e810(&pf->hw))
6229 ice_ptp_link_change(pf, pf->hw.pf_id, true);
6232 /* Perform an initial read of the statistics registers now to
6233 * set the baseline so counters are ready when interface is up
6235 ice_update_eth_stats(vsi);
6236 ice_service_task_schedule(pf);
6242 * ice_up - Bring the connection back up after being down
6243 * @vsi: VSI being configured
6245 int ice_up(struct ice_vsi *vsi)
6249 err = ice_vsi_cfg(vsi);
6251 err = ice_up_complete(vsi);
6257 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
6258 * @syncp: pointer to u64_stats_sync
6259 * @stats: stats that pkts and bytes count will be taken from
6260 * @pkts: packets stats counter
6261 * @bytes: bytes stats counter
6263 * This function fetches stats from the ring considering the atomic operations
6264 * that needs to be performed to read u64 values in 32 bit machine.
6267 ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp,
6268 struct ice_q_stats stats, u64 *pkts, u64 *bytes)
6273 start = u64_stats_fetch_begin_irq(syncp);
6275 *bytes = stats.bytes;
6276 } while (u64_stats_fetch_retry_irq(syncp, start));
6280 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters
6281 * @vsi: the VSI to be updated
6282 * @vsi_stats: the stats struct to be updated
6283 * @rings: rings to work on
6284 * @count: number of rings
6287 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
6288 struct rtnl_link_stats64 *vsi_stats,
6289 struct ice_tx_ring **rings, u16 count)
6293 for (i = 0; i < count; i++) {
6294 struct ice_tx_ring *ring;
6295 u64 pkts = 0, bytes = 0;
6297 ring = READ_ONCE(rings[i]);
6300 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6301 vsi_stats->tx_packets += pkts;
6302 vsi_stats->tx_bytes += bytes;
6303 vsi->tx_restart += ring->tx_stats.restart_q;
6304 vsi->tx_busy += ring->tx_stats.tx_busy;
6305 vsi->tx_linearize += ring->tx_stats.tx_linearize;
6310 * ice_update_vsi_ring_stats - Update VSI stats counters
6311 * @vsi: the VSI to be updated
6313 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
6315 struct rtnl_link_stats64 *vsi_stats;
6319 vsi_stats = kzalloc(sizeof(*vsi_stats), GFP_ATOMIC);
6323 /* reset non-netdev (extended) stats */
6324 vsi->tx_restart = 0;
6326 vsi->tx_linearize = 0;
6327 vsi->rx_buf_failed = 0;
6328 vsi->rx_page_failed = 0;
6332 /* update Tx rings counters */
6333 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->tx_rings,
6336 /* update Rx rings counters */
6337 ice_for_each_rxq(vsi, i) {
6338 struct ice_rx_ring *ring = READ_ONCE(vsi->rx_rings[i]);
6340 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6341 vsi_stats->rx_packets += pkts;
6342 vsi_stats->rx_bytes += bytes;
6343 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
6344 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
6347 /* update XDP Tx rings counters */
6348 if (ice_is_xdp_ena_vsi(vsi))
6349 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->xdp_rings,
6354 vsi->net_stats.tx_packets = vsi_stats->tx_packets;
6355 vsi->net_stats.tx_bytes = vsi_stats->tx_bytes;
6356 vsi->net_stats.rx_packets = vsi_stats->rx_packets;
6357 vsi->net_stats.rx_bytes = vsi_stats->rx_bytes;
6363 * ice_update_vsi_stats - Update VSI stats counters
6364 * @vsi: the VSI to be updated
6366 void ice_update_vsi_stats(struct ice_vsi *vsi)
6368 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
6369 struct ice_eth_stats *cur_es = &vsi->eth_stats;
6370 struct ice_pf *pf = vsi->back;
6372 if (test_bit(ICE_VSI_DOWN, vsi->state) ||
6373 test_bit(ICE_CFG_BUSY, pf->state))
6376 /* get stats as recorded by Tx/Rx rings */
6377 ice_update_vsi_ring_stats(vsi);
6379 /* get VSI stats as recorded by the hardware */
6380 ice_update_eth_stats(vsi);
6382 cur_ns->tx_errors = cur_es->tx_errors;
6383 cur_ns->rx_dropped = cur_es->rx_discards;
6384 cur_ns->tx_dropped = cur_es->tx_discards;
6385 cur_ns->multicast = cur_es->rx_multicast;
6387 /* update some more netdev stats if this is main VSI */
6388 if (vsi->type == ICE_VSI_PF) {
6389 cur_ns->rx_crc_errors = pf->stats.crc_errors;
6390 cur_ns->rx_errors = pf->stats.crc_errors +
6391 pf->stats.illegal_bytes +
6392 pf->stats.rx_len_errors +
6393 pf->stats.rx_undersize +
6394 pf->hw_csum_rx_error +
6395 pf->stats.rx_jabber +
6396 pf->stats.rx_fragments +
6397 pf->stats.rx_oversize;
6398 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
6399 /* record drops from the port level */
6400 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
6405 * ice_update_pf_stats - Update PF port stats counters
6406 * @pf: PF whose stats needs to be updated
6408 void ice_update_pf_stats(struct ice_pf *pf)
6410 struct ice_hw_port_stats *prev_ps, *cur_ps;
6411 struct ice_hw *hw = &pf->hw;
6415 port = hw->port_info->lport;
6416 prev_ps = &pf->stats_prev;
6417 cur_ps = &pf->stats;
6419 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
6420 &prev_ps->eth.rx_bytes,
6421 &cur_ps->eth.rx_bytes);
6423 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
6424 &prev_ps->eth.rx_unicast,
6425 &cur_ps->eth.rx_unicast);
6427 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
6428 &prev_ps->eth.rx_multicast,
6429 &cur_ps->eth.rx_multicast);
6431 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
6432 &prev_ps->eth.rx_broadcast,
6433 &cur_ps->eth.rx_broadcast);
6435 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
6436 &prev_ps->eth.rx_discards,
6437 &cur_ps->eth.rx_discards);
6439 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
6440 &prev_ps->eth.tx_bytes,
6441 &cur_ps->eth.tx_bytes);
6443 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
6444 &prev_ps->eth.tx_unicast,
6445 &cur_ps->eth.tx_unicast);
6447 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
6448 &prev_ps->eth.tx_multicast,
6449 &cur_ps->eth.tx_multicast);
6451 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
6452 &prev_ps->eth.tx_broadcast,
6453 &cur_ps->eth.tx_broadcast);
6455 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
6456 &prev_ps->tx_dropped_link_down,
6457 &cur_ps->tx_dropped_link_down);
6459 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
6460 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
6462 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
6463 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
6465 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
6466 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
6468 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
6469 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
6471 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
6472 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
6474 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
6475 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
6477 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
6478 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
6480 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
6481 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
6483 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
6484 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
6486 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
6487 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
6489 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
6490 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
6492 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
6493 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
6495 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
6496 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
6498 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
6499 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
6501 fd_ctr_base = hw->fd_ctr_base;
6503 ice_stat_update40(hw,
6504 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
6505 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
6506 &cur_ps->fd_sb_match);
6507 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
6508 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
6510 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
6511 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
6513 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
6514 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
6516 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
6517 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
6519 ice_update_dcb_stats(pf);
6521 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
6522 &prev_ps->crc_errors, &cur_ps->crc_errors);
6524 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
6525 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
6527 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
6528 &prev_ps->mac_local_faults,
6529 &cur_ps->mac_local_faults);
6531 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
6532 &prev_ps->mac_remote_faults,
6533 &cur_ps->mac_remote_faults);
6535 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
6536 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
6538 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
6539 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
6541 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
6542 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
6544 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
6545 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
6547 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
6548 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
6550 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
6552 pf->stat_prev_loaded = true;
6556 * ice_get_stats64 - get statistics for network device structure
6557 * @netdev: network interface device structure
6558 * @stats: main device statistics structure
6561 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
6563 struct ice_netdev_priv *np = netdev_priv(netdev);
6564 struct rtnl_link_stats64 *vsi_stats;
6565 struct ice_vsi *vsi = np->vsi;
6567 vsi_stats = &vsi->net_stats;
6569 if (!vsi->num_txq || !vsi->num_rxq)
6572 /* netdev packet/byte stats come from ring counter. These are obtained
6573 * by summing up ring counters (done by ice_update_vsi_ring_stats).
6574 * But, only call the update routine and read the registers if VSI is
6577 if (!test_bit(ICE_VSI_DOWN, vsi->state))
6578 ice_update_vsi_ring_stats(vsi);
6579 stats->tx_packets = vsi_stats->tx_packets;
6580 stats->tx_bytes = vsi_stats->tx_bytes;
6581 stats->rx_packets = vsi_stats->rx_packets;
6582 stats->rx_bytes = vsi_stats->rx_bytes;
6584 /* The rest of the stats can be read from the hardware but instead we
6585 * just return values that the watchdog task has already obtained from
6588 stats->multicast = vsi_stats->multicast;
6589 stats->tx_errors = vsi_stats->tx_errors;
6590 stats->tx_dropped = vsi_stats->tx_dropped;
6591 stats->rx_errors = vsi_stats->rx_errors;
6592 stats->rx_dropped = vsi_stats->rx_dropped;
6593 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
6594 stats->rx_length_errors = vsi_stats->rx_length_errors;
6598 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
6599 * @vsi: VSI having NAPI disabled
6601 static void ice_napi_disable_all(struct ice_vsi *vsi)
6608 ice_for_each_q_vector(vsi, q_idx) {
6609 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6611 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6612 napi_disable(&q_vector->napi);
6614 cancel_work_sync(&q_vector->tx.dim.work);
6615 cancel_work_sync(&q_vector->rx.dim.work);
6620 * ice_down - Shutdown the connection
6621 * @vsi: The VSI being stopped
6623 * Caller of this function is expected to set the vsi->state ICE_DOWN bit
6625 int ice_down(struct ice_vsi *vsi)
6627 int i, tx_err, rx_err, link_err = 0, vlan_err = 0;
6629 WARN_ON(!test_bit(ICE_VSI_DOWN, vsi->state));
6631 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
6632 vlan_err = ice_vsi_del_vlan_zero(vsi);
6633 if (!ice_is_e810(&vsi->back->hw))
6634 ice_ptp_link_change(vsi->back, vsi->back->hw.pf_id, false);
6635 netif_carrier_off(vsi->netdev);
6636 netif_tx_disable(vsi->netdev);
6637 } else if (vsi->type == ICE_VSI_SWITCHDEV_CTRL) {
6638 ice_eswitch_stop_all_tx_queues(vsi->back);
6641 ice_vsi_dis_irq(vsi);
6643 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
6645 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
6646 vsi->vsi_num, tx_err);
6647 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
6648 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
6650 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
6651 vsi->vsi_num, tx_err);
6654 rx_err = ice_vsi_stop_all_rx_rings(vsi);
6656 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
6657 vsi->vsi_num, rx_err);
6659 ice_napi_disable_all(vsi);
6661 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
6662 link_err = ice_force_phys_link_state(vsi, false);
6664 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
6665 vsi->vsi_num, link_err);
6668 ice_for_each_txq(vsi, i)
6669 ice_clean_tx_ring(vsi->tx_rings[i]);
6671 ice_for_each_rxq(vsi, i)
6672 ice_clean_rx_ring(vsi->rx_rings[i]);
6674 if (tx_err || rx_err || link_err || vlan_err) {
6675 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
6676 vsi->vsi_num, vsi->vsw->sw_id);
6684 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
6685 * @vsi: VSI having resources allocated
6687 * Return 0 on success, negative on failure
6689 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
6693 if (!vsi->num_txq) {
6694 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
6699 ice_for_each_txq(vsi, i) {
6700 struct ice_tx_ring *ring = vsi->tx_rings[i];
6706 ring->netdev = vsi->netdev;
6707 err = ice_setup_tx_ring(ring);
6716 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
6717 * @vsi: VSI having resources allocated
6719 * Return 0 on success, negative on failure
6721 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
6725 if (!vsi->num_rxq) {
6726 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
6731 ice_for_each_rxq(vsi, i) {
6732 struct ice_rx_ring *ring = vsi->rx_rings[i];
6738 ring->netdev = vsi->netdev;
6739 err = ice_setup_rx_ring(ring);
6748 * ice_vsi_open_ctrl - open control VSI for use
6749 * @vsi: the VSI to open
6751 * Initialization of the Control VSI
6753 * Returns 0 on success, negative value on error
6755 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
6757 char int_name[ICE_INT_NAME_STR_LEN];
6758 struct ice_pf *pf = vsi->back;
6762 dev = ice_pf_to_dev(pf);
6763 /* allocate descriptors */
6764 err = ice_vsi_setup_tx_rings(vsi);
6768 err = ice_vsi_setup_rx_rings(vsi);
6772 err = ice_vsi_cfg(vsi);
6776 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
6777 dev_driver_string(dev), dev_name(dev));
6778 err = ice_vsi_req_irq_msix(vsi, int_name);
6782 ice_vsi_cfg_msix(vsi);
6784 err = ice_vsi_start_all_rx_rings(vsi);
6786 goto err_up_complete;
6788 clear_bit(ICE_VSI_DOWN, vsi->state);
6789 ice_vsi_ena_irq(vsi);
6796 ice_vsi_free_rx_rings(vsi);
6798 ice_vsi_free_tx_rings(vsi);
6804 * ice_vsi_open - Called when a network interface is made active
6805 * @vsi: the VSI to open
6807 * Initialization of the VSI
6809 * Returns 0 on success, negative value on error
6811 int ice_vsi_open(struct ice_vsi *vsi)
6813 char int_name[ICE_INT_NAME_STR_LEN];
6814 struct ice_pf *pf = vsi->back;
6817 /* allocate descriptors */
6818 err = ice_vsi_setup_tx_rings(vsi);
6822 err = ice_vsi_setup_rx_rings(vsi);
6826 err = ice_vsi_cfg(vsi);
6830 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
6831 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
6832 err = ice_vsi_req_irq_msix(vsi, int_name);
6836 if (vsi->type == ICE_VSI_PF) {
6837 /* Notify the stack of the actual queue counts. */
6838 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
6842 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
6847 err = ice_up_complete(vsi);
6849 goto err_up_complete;
6856 ice_vsi_free_irq(vsi);
6858 ice_vsi_free_rx_rings(vsi);
6860 ice_vsi_free_tx_rings(vsi);
6866 * ice_vsi_release_all - Delete all VSIs
6867 * @pf: PF from which all VSIs are being removed
6869 static void ice_vsi_release_all(struct ice_pf *pf)
6876 ice_for_each_vsi(pf, i) {
6880 if (pf->vsi[i]->type == ICE_VSI_CHNL)
6883 err = ice_vsi_release(pf->vsi[i]);
6885 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
6886 i, err, pf->vsi[i]->vsi_num);
6891 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
6892 * @pf: pointer to the PF instance
6893 * @type: VSI type to rebuild
6895 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
6897 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
6899 struct device *dev = ice_pf_to_dev(pf);
6902 ice_for_each_vsi(pf, i) {
6903 struct ice_vsi *vsi = pf->vsi[i];
6905 if (!vsi || vsi->type != type)
6908 /* rebuild the VSI */
6909 err = ice_vsi_rebuild(vsi, true);
6911 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
6912 err, vsi->idx, ice_vsi_type_str(type));
6916 /* replay filters for the VSI */
6917 err = ice_replay_vsi(&pf->hw, vsi->idx);
6919 dev_err(dev, "replay VSI failed, error %d, VSI index %d, type %s\n",
6920 err, vsi->idx, ice_vsi_type_str(type));
6924 /* Re-map HW VSI number, using VSI handle that has been
6925 * previously validated in ice_replay_vsi() call above
6927 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
6929 /* enable the VSI */
6930 err = ice_ena_vsi(vsi, false);
6932 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
6933 err, vsi->idx, ice_vsi_type_str(type));
6937 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
6938 ice_vsi_type_str(type));
6945 * ice_update_pf_netdev_link - Update PF netdev link status
6946 * @pf: pointer to the PF instance
6948 static void ice_update_pf_netdev_link(struct ice_pf *pf)
6953 ice_for_each_vsi(pf, i) {
6954 struct ice_vsi *vsi = pf->vsi[i];
6956 if (!vsi || vsi->type != ICE_VSI_PF)
6959 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
6961 netif_carrier_on(pf->vsi[i]->netdev);
6962 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
6964 netif_carrier_off(pf->vsi[i]->netdev);
6965 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
6971 * ice_rebuild - rebuild after reset
6972 * @pf: PF to rebuild
6973 * @reset_type: type of reset
6975 * Do not rebuild VF VSI in this flow because that is already handled via
6976 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a
6977 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
6978 * to reset/rebuild all the VF VSI twice.
6980 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
6982 struct device *dev = ice_pf_to_dev(pf);
6983 struct ice_hw *hw = &pf->hw;
6987 if (test_bit(ICE_DOWN, pf->state))
6988 goto clear_recovery;
6990 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
6992 #define ICE_EMP_RESET_SLEEP_MS 5000
6993 if (reset_type == ICE_RESET_EMPR) {
6994 /* If an EMP reset has occurred, any previously pending flash
6995 * update will have completed. We no longer know whether or
6996 * not the NVM update EMP reset is restricted.
6998 pf->fw_emp_reset_disabled = false;
7000 msleep(ICE_EMP_RESET_SLEEP_MS);
7003 err = ice_init_all_ctrlq(hw);
7005 dev_err(dev, "control queues init failed %d\n", err);
7006 goto err_init_ctrlq;
7009 /* if DDP was previously loaded successfully */
7010 if (!ice_is_safe_mode(pf)) {
7011 /* reload the SW DB of filter tables */
7012 if (reset_type == ICE_RESET_PFR)
7013 ice_fill_blk_tbls(hw);
7015 /* Reload DDP Package after CORER/GLOBR reset */
7016 ice_load_pkg(NULL, pf);
7019 err = ice_clear_pf_cfg(hw);
7021 dev_err(dev, "clear PF configuration failed %d\n", err);
7022 goto err_init_ctrlq;
7025 ice_clear_pxe_mode(hw);
7027 err = ice_init_nvm(hw);
7029 dev_err(dev, "ice_init_nvm failed %d\n", err);
7030 goto err_init_ctrlq;
7033 err = ice_get_caps(hw);
7035 dev_err(dev, "ice_get_caps failed %d\n", err);
7036 goto err_init_ctrlq;
7039 err = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
7041 dev_err(dev, "set_mac_cfg failed %d\n", err);
7042 goto err_init_ctrlq;
7045 dvm = ice_is_dvm_ena(hw);
7047 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
7049 goto err_init_ctrlq;
7051 err = ice_sched_init_port(hw->port_info);
7053 goto err_sched_init_port;
7055 /* start misc vector */
7056 err = ice_req_irq_msix_misc(pf);
7058 dev_err(dev, "misc vector setup failed: %d\n", err);
7059 goto err_sched_init_port;
7062 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7063 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
7064 if (!rd32(hw, PFQF_FD_SIZE)) {
7065 u16 unused, guar, b_effort;
7067 guar = hw->func_caps.fd_fltr_guar;
7068 b_effort = hw->func_caps.fd_fltr_best_effort;
7070 /* force guaranteed filter pool for PF */
7071 ice_alloc_fd_guar_item(hw, &unused, guar);
7072 /* force shared filter pool for PF */
7073 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
7077 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
7078 ice_dcb_rebuild(pf);
7080 /* If the PF previously had enabled PTP, PTP init needs to happen before
7081 * the VSI rebuild. If not, this causes the PTP link status events to
7084 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
7087 if (ice_is_feature_supported(pf, ICE_F_GNSS))
7090 /* rebuild PF VSI */
7091 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
7093 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
7094 goto err_vsi_rebuild;
7097 /* configure PTP timestamping after VSI rebuild */
7098 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
7099 ice_ptp_cfg_timestamp(pf, false);
7101 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_SWITCHDEV_CTRL);
7103 dev_err(dev, "Switchdev CTRL VSI rebuild failed: %d\n", err);
7104 goto err_vsi_rebuild;
7107 if (reset_type == ICE_RESET_PFR) {
7108 err = ice_rebuild_channels(pf);
7110 dev_err(dev, "failed to rebuild and replay ADQ VSIs, err %d\n",
7112 goto err_vsi_rebuild;
7116 /* If Flow Director is active */
7117 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7118 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
7120 dev_err(dev, "control VSI rebuild failed: %d\n", err);
7121 goto err_vsi_rebuild;
7124 /* replay HW Flow Director recipes */
7126 ice_fdir_replay_flows(hw);
7128 /* replay Flow Director filters */
7129 ice_fdir_replay_fltrs(pf);
7131 ice_rebuild_arfs(pf);
7134 ice_update_pf_netdev_link(pf);
7136 /* tell the firmware we are up */
7137 err = ice_send_version(pf);
7139 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n",
7141 goto err_vsi_rebuild;
7144 ice_replay_post(hw);
7146 /* if we get here, reset flow is successful */
7147 clear_bit(ICE_RESET_FAILED, pf->state);
7149 ice_plug_aux_dev(pf);
7153 err_sched_init_port:
7154 ice_sched_cleanup_all(hw);
7156 ice_shutdown_all_ctrlq(hw);
7157 set_bit(ICE_RESET_FAILED, pf->state);
7159 /* set this bit in PF state to control service task scheduling */
7160 set_bit(ICE_NEEDS_RESTART, pf->state);
7161 dev_err(dev, "Rebuild failed, unload and reload driver\n");
7165 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
7166 * @vsi: Pointer to VSI structure
7168 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
7170 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
7171 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
7173 return ICE_RXBUF_3072;
7177 * ice_change_mtu - NDO callback to change the MTU
7178 * @netdev: network interface device structure
7179 * @new_mtu: new value for maximum frame size
7181 * Returns 0 on success, negative on failure
7183 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
7185 struct ice_netdev_priv *np = netdev_priv(netdev);
7186 struct ice_vsi *vsi = np->vsi;
7187 struct ice_pf *pf = vsi->back;
7191 if (new_mtu == (int)netdev->mtu) {
7192 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
7196 if (ice_is_xdp_ena_vsi(vsi)) {
7197 int frame_size = ice_max_xdp_frame_size(vsi);
7199 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
7200 netdev_err(netdev, "max MTU for XDP usage is %d\n",
7201 frame_size - ICE_ETH_PKT_HDR_PAD);
7206 /* if a reset is in progress, wait for some time for it to complete */
7208 if (ice_is_reset_in_progress(pf->state)) {
7210 usleep_range(1000, 2000);
7215 } while (count < 100);
7218 netdev_err(netdev, "can't change MTU. Device is busy\n");
7222 netdev->mtu = (unsigned int)new_mtu;
7224 /* if VSI is up, bring it down and then back up */
7225 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
7226 err = ice_down(vsi);
7228 netdev_err(netdev, "change MTU if_down err %d\n", err);
7234 netdev_err(netdev, "change MTU if_up err %d\n", err);
7239 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
7240 set_bit(ICE_FLAG_MTU_CHANGED, pf->flags);
7246 * ice_eth_ioctl - Access the hwtstamp interface
7247 * @netdev: network interface device structure
7248 * @ifr: interface request data
7249 * @cmd: ioctl command
7251 static int ice_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7253 struct ice_netdev_priv *np = netdev_priv(netdev);
7254 struct ice_pf *pf = np->vsi->back;
7258 return ice_ptp_get_ts_config(pf, ifr);
7260 return ice_ptp_set_ts_config(pf, ifr);
7267 * ice_aq_str - convert AQ err code to a string
7268 * @aq_err: the AQ error code to convert
7270 const char *ice_aq_str(enum ice_aq_err aq_err)
7275 case ICE_AQ_RC_EPERM:
7276 return "ICE_AQ_RC_EPERM";
7277 case ICE_AQ_RC_ENOENT:
7278 return "ICE_AQ_RC_ENOENT";
7279 case ICE_AQ_RC_ENOMEM:
7280 return "ICE_AQ_RC_ENOMEM";
7281 case ICE_AQ_RC_EBUSY:
7282 return "ICE_AQ_RC_EBUSY";
7283 case ICE_AQ_RC_EEXIST:
7284 return "ICE_AQ_RC_EEXIST";
7285 case ICE_AQ_RC_EINVAL:
7286 return "ICE_AQ_RC_EINVAL";
7287 case ICE_AQ_RC_ENOSPC:
7288 return "ICE_AQ_RC_ENOSPC";
7289 case ICE_AQ_RC_ENOSYS:
7290 return "ICE_AQ_RC_ENOSYS";
7291 case ICE_AQ_RC_EMODE:
7292 return "ICE_AQ_RC_EMODE";
7293 case ICE_AQ_RC_ENOSEC:
7294 return "ICE_AQ_RC_ENOSEC";
7295 case ICE_AQ_RC_EBADSIG:
7296 return "ICE_AQ_RC_EBADSIG";
7297 case ICE_AQ_RC_ESVN:
7298 return "ICE_AQ_RC_ESVN";
7299 case ICE_AQ_RC_EBADMAN:
7300 return "ICE_AQ_RC_EBADMAN";
7301 case ICE_AQ_RC_EBADBUF:
7302 return "ICE_AQ_RC_EBADBUF";
7305 return "ICE_AQ_RC_UNKNOWN";
7309 * ice_set_rss_lut - Set RSS LUT
7310 * @vsi: Pointer to VSI structure
7311 * @lut: Lookup table
7312 * @lut_size: Lookup table size
7314 * Returns 0 on success, negative on failure
7316 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7318 struct ice_aq_get_set_rss_lut_params params = {};
7319 struct ice_hw *hw = &vsi->back->hw;
7325 params.vsi_handle = vsi->idx;
7326 params.lut_size = lut_size;
7327 params.lut_type = vsi->rss_lut_type;
7330 status = ice_aq_set_rss_lut(hw, ¶ms);
7332 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %d aq_err %s\n",
7333 status, ice_aq_str(hw->adminq.sq_last_status));
7339 * ice_set_rss_key - Set RSS key
7340 * @vsi: Pointer to the VSI structure
7341 * @seed: RSS hash seed
7343 * Returns 0 on success, negative on failure
7345 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed)
7347 struct ice_hw *hw = &vsi->back->hw;
7353 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7355 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %d aq_err %s\n",
7356 status, ice_aq_str(hw->adminq.sq_last_status));
7362 * ice_get_rss_lut - Get RSS LUT
7363 * @vsi: Pointer to VSI structure
7364 * @lut: Buffer to store the lookup table entries
7365 * @lut_size: Size of buffer to store the lookup table entries
7367 * Returns 0 on success, negative on failure
7369 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7371 struct ice_aq_get_set_rss_lut_params params = {};
7372 struct ice_hw *hw = &vsi->back->hw;
7378 params.vsi_handle = vsi->idx;
7379 params.lut_size = lut_size;
7380 params.lut_type = vsi->rss_lut_type;
7383 status = ice_aq_get_rss_lut(hw, ¶ms);
7385 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %d aq_err %s\n",
7386 status, ice_aq_str(hw->adminq.sq_last_status));
7392 * ice_get_rss_key - Get RSS key
7393 * @vsi: Pointer to VSI structure
7394 * @seed: Buffer to store the key in
7396 * Returns 0 on success, negative on failure
7398 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed)
7400 struct ice_hw *hw = &vsi->back->hw;
7406 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7408 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %d aq_err %s\n",
7409 status, ice_aq_str(hw->adminq.sq_last_status));
7415 * ice_bridge_getlink - Get the hardware bridge mode
7418 * @seq: RTNL message seq
7419 * @dev: the netdev being configured
7420 * @filter_mask: filter mask passed in
7421 * @nlflags: netlink flags passed in
7423 * Return the bridge mode (VEB/VEPA)
7426 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7427 struct net_device *dev, u32 filter_mask, int nlflags)
7429 struct ice_netdev_priv *np = netdev_priv(dev);
7430 struct ice_vsi *vsi = np->vsi;
7431 struct ice_pf *pf = vsi->back;
7434 bmode = pf->first_sw->bridge_mode;
7436 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
7441 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
7442 * @vsi: Pointer to VSI structure
7443 * @bmode: Hardware bridge mode (VEB/VEPA)
7445 * Returns 0 on success, negative on failure
7447 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
7449 struct ice_aqc_vsi_props *vsi_props;
7450 struct ice_hw *hw = &vsi->back->hw;
7451 struct ice_vsi_ctx *ctxt;
7454 vsi_props = &vsi->info;
7456 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
7460 ctxt->info = vsi->info;
7462 if (bmode == BRIDGE_MODE_VEB)
7463 /* change from VEPA to VEB mode */
7464 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7466 /* change from VEB to VEPA mode */
7467 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7468 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
7470 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
7472 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %s\n",
7473 bmode, ret, ice_aq_str(hw->adminq.sq_last_status));
7476 /* Update sw flags for book keeping */
7477 vsi_props->sw_flags = ctxt->info.sw_flags;
7485 * ice_bridge_setlink - Set the hardware bridge mode
7486 * @dev: the netdev being configured
7487 * @nlh: RTNL message
7488 * @flags: bridge setlink flags
7489 * @extack: netlink extended ack
7491 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
7492 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
7493 * not already set for all VSIs connected to this switch. And also update the
7494 * unicast switch filter rules for the corresponding switch of the netdev.
7497 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
7498 u16 __always_unused flags,
7499 struct netlink_ext_ack __always_unused *extack)
7501 struct ice_netdev_priv *np = netdev_priv(dev);
7502 struct ice_pf *pf = np->vsi->back;
7503 struct nlattr *attr, *br_spec;
7504 struct ice_hw *hw = &pf->hw;
7505 struct ice_sw *pf_sw;
7506 int rem, v, err = 0;
7508 pf_sw = pf->first_sw;
7509 /* find the attribute in the netlink message */
7510 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7512 nla_for_each_nested(attr, br_spec, rem) {
7515 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7517 mode = nla_get_u16(attr);
7518 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
7520 /* Continue if bridge mode is not being flipped */
7521 if (mode == pf_sw->bridge_mode)
7523 /* Iterates through the PF VSI list and update the loopback
7526 ice_for_each_vsi(pf, v) {
7529 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
7534 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
7535 /* Update the unicast switch filter rules for the corresponding
7536 * switch of the netdev
7538 err = ice_update_sw_rule_bridge_mode(hw);
7540 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %s\n",
7542 ice_aq_str(hw->adminq.sq_last_status));
7543 /* revert hw->evb_veb */
7544 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
7548 pf_sw->bridge_mode = mode;
7555 * ice_tx_timeout - Respond to a Tx Hang
7556 * @netdev: network interface device structure
7557 * @txqueue: Tx queue
7559 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
7561 struct ice_netdev_priv *np = netdev_priv(netdev);
7562 struct ice_tx_ring *tx_ring = NULL;
7563 struct ice_vsi *vsi = np->vsi;
7564 struct ice_pf *pf = vsi->back;
7567 pf->tx_timeout_count++;
7569 /* Check if PFC is enabled for the TC to which the queue belongs
7570 * to. If yes then Tx timeout is not caused by a hung queue, no
7571 * need to reset and rebuild
7573 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
7574 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
7579 /* now that we have an index, find the tx_ring struct */
7580 ice_for_each_txq(vsi, i)
7581 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
7582 if (txqueue == vsi->tx_rings[i]->q_index) {
7583 tx_ring = vsi->tx_rings[i];
7587 /* Reset recovery level if enough time has elapsed after last timeout.
7588 * Also ensure no new reset action happens before next timeout period.
7590 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
7591 pf->tx_timeout_recovery_level = 1;
7592 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
7593 netdev->watchdog_timeo)))
7597 struct ice_hw *hw = &pf->hw;
7600 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
7601 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
7602 /* Read interrupt register */
7603 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
7605 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
7606 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
7607 head, tx_ring->next_to_use, val);
7610 pf->tx_timeout_last_recovery = jiffies;
7611 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
7612 pf->tx_timeout_recovery_level, txqueue);
7614 switch (pf->tx_timeout_recovery_level) {
7616 set_bit(ICE_PFR_REQ, pf->state);
7619 set_bit(ICE_CORER_REQ, pf->state);
7622 set_bit(ICE_GLOBR_REQ, pf->state);
7625 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
7626 set_bit(ICE_DOWN, pf->state);
7627 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
7628 set_bit(ICE_SERVICE_DIS, pf->state);
7632 ice_service_task_schedule(pf);
7633 pf->tx_timeout_recovery_level++;
7637 * ice_setup_tc_cls_flower - flower classifier offloads
7638 * @np: net device to configure
7639 * @filter_dev: device on which filter is added
7640 * @cls_flower: offload data
7643 ice_setup_tc_cls_flower(struct ice_netdev_priv *np,
7644 struct net_device *filter_dev,
7645 struct flow_cls_offload *cls_flower)
7647 struct ice_vsi *vsi = np->vsi;
7649 if (cls_flower->common.chain_index)
7652 switch (cls_flower->command) {
7653 case FLOW_CLS_REPLACE:
7654 return ice_add_cls_flower(filter_dev, vsi, cls_flower);
7655 case FLOW_CLS_DESTROY:
7656 return ice_del_cls_flower(vsi, cls_flower);
7663 * ice_setup_tc_block_cb - callback handler registered for TC block
7664 * @type: TC SETUP type
7665 * @type_data: TC flower offload data that contains user input
7666 * @cb_priv: netdev private data
7669 ice_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
7671 struct ice_netdev_priv *np = cb_priv;
7674 case TC_SETUP_CLSFLOWER:
7675 return ice_setup_tc_cls_flower(np, np->vsi->netdev,
7683 * ice_validate_mqprio_qopt - Validate TCF input parameters
7684 * @vsi: Pointer to VSI
7685 * @mqprio_qopt: input parameters for mqprio queue configuration
7687 * This function validates MQPRIO params, such as qcount (power of 2 wherever
7688 * needed), and make sure user doesn't specify qcount and BW rate limit
7689 * for TCs, which are more than "num_tc"
7692 ice_validate_mqprio_qopt(struct ice_vsi *vsi,
7693 struct tc_mqprio_qopt_offload *mqprio_qopt)
7695 u64 sum_max_rate = 0, sum_min_rate = 0;
7696 int non_power_of_2_qcount = 0;
7697 struct ice_pf *pf = vsi->back;
7698 int max_rss_q_cnt = 0;
7703 if (vsi->type != ICE_VSI_PF)
7706 if (mqprio_qopt->qopt.offset[0] != 0 ||
7707 mqprio_qopt->qopt.num_tc < 1 ||
7708 mqprio_qopt->qopt.num_tc > ICE_CHNL_MAX_TC)
7711 dev = ice_pf_to_dev(pf);
7712 vsi->ch_rss_size = 0;
7713 num_tc = mqprio_qopt->qopt.num_tc;
7715 for (i = 0; num_tc; i++) {
7716 int qcount = mqprio_qopt->qopt.count[i];
7717 u64 max_rate, min_rate, rem;
7722 if (is_power_of_2(qcount)) {
7723 if (non_power_of_2_qcount &&
7724 qcount > non_power_of_2_qcount) {
7725 dev_err(dev, "qcount[%d] cannot be greater than non power of 2 qcount[%d]\n",
7726 qcount, non_power_of_2_qcount);
7729 if (qcount > max_rss_q_cnt)
7730 max_rss_q_cnt = qcount;
7732 if (non_power_of_2_qcount &&
7733 qcount != non_power_of_2_qcount) {
7734 dev_err(dev, "Only one non power of 2 qcount allowed[%d,%d]\n",
7735 qcount, non_power_of_2_qcount);
7738 if (qcount < max_rss_q_cnt) {
7739 dev_err(dev, "non power of 2 qcount[%d] cannot be less than other qcount[%d]\n",
7740 qcount, max_rss_q_cnt);
7743 max_rss_q_cnt = qcount;
7744 non_power_of_2_qcount = qcount;
7747 /* TC command takes input in K/N/Gbps or K/M/Gbit etc but
7748 * converts the bandwidth rate limit into Bytes/s when
7749 * passing it down to the driver. So convert input bandwidth
7750 * from Bytes/s to Kbps
7752 max_rate = mqprio_qopt->max_rate[i];
7753 max_rate = div_u64(max_rate, ICE_BW_KBPS_DIVISOR);
7754 sum_max_rate += max_rate;
7756 /* min_rate is minimum guaranteed rate and it can't be zero */
7757 min_rate = mqprio_qopt->min_rate[i];
7758 min_rate = div_u64(min_rate, ICE_BW_KBPS_DIVISOR);
7759 sum_min_rate += min_rate;
7761 if (min_rate && min_rate < ICE_MIN_BW_LIMIT) {
7762 dev_err(dev, "TC%d: min_rate(%llu Kbps) < %u Kbps\n", i,
7763 min_rate, ICE_MIN_BW_LIMIT);
7767 iter_div_u64_rem(min_rate, ICE_MIN_BW_LIMIT, &rem);
7769 dev_err(dev, "TC%d: Min Rate not multiple of %u Kbps",
7770 i, ICE_MIN_BW_LIMIT);
7774 iter_div_u64_rem(max_rate, ICE_MIN_BW_LIMIT, &rem);
7776 dev_err(dev, "TC%d: Max Rate not multiple of %u Kbps",
7777 i, ICE_MIN_BW_LIMIT);
7781 /* min_rate can't be more than max_rate, except when max_rate
7782 * is zero (implies max_rate sought is max line rate). In such
7783 * a case min_rate can be more than max.
7785 if (max_rate && min_rate > max_rate) {
7786 dev_err(dev, "min_rate %llu Kbps can't be more than max_rate %llu Kbps\n",
7787 min_rate, max_rate);
7791 if (i >= mqprio_qopt->qopt.num_tc - 1)
7793 if (mqprio_qopt->qopt.offset[i + 1] !=
7794 (mqprio_qopt->qopt.offset[i] + qcount))
7798 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7801 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7804 speed = ice_get_link_speed_kbps(vsi);
7805 if (sum_max_rate && sum_max_rate > (u64)speed) {
7806 dev_err(dev, "Invalid max Tx rate(%llu) Kbps > speed(%u) Kbps specified\n",
7807 sum_max_rate, speed);
7810 if (sum_min_rate && sum_min_rate > (u64)speed) {
7811 dev_err(dev, "Invalid min Tx rate(%llu) Kbps > speed (%u) Kbps specified\n",
7812 sum_min_rate, speed);
7816 /* make sure vsi->ch_rss_size is set correctly based on TC's qcount */
7817 vsi->ch_rss_size = max_rss_q_cnt;
7823 * ice_add_vsi_to_fdir - add a VSI to the flow director group for PF
7824 * @pf: ptr to PF device
7827 static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
7829 struct device *dev = ice_pf_to_dev(pf);
7834 if (!(vsi->num_gfltr || vsi->num_bfltr))
7838 for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
7839 struct ice_fd_hw_prof *prof;
7843 if (!(hw->fdir_prof && hw->fdir_prof[flow] &&
7844 hw->fdir_prof[flow]->cnt))
7847 for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
7848 enum ice_flow_priority prio;
7851 /* add this VSI to FDir profile for this flow */
7852 prio = ICE_FLOW_PRIO_NORMAL;
7853 prof = hw->fdir_prof[flow];
7854 prof_id = flow + tun * ICE_FLTR_PTYPE_MAX;
7855 status = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id,
7856 prof->vsi_h[0], vsi->idx,
7857 prio, prof->fdir_seg[tun],
7860 dev_err(dev, "channel VSI idx %d, not able to add to group %d\n",
7865 prof->entry_h[prof->cnt][tun] = entry_h;
7868 /* store VSI for filter replay and delete */
7869 prof->vsi_h[prof->cnt] = vsi->idx;
7873 dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx,
7878 dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx);
7884 * ice_add_channel - add a channel by adding VSI
7885 * @pf: ptr to PF device
7886 * @sw_id: underlying HW switching element ID
7887 * @ch: ptr to channel structure
7889 * Add a channel (VSI) using add_vsi and queue_map
7891 static int ice_add_channel(struct ice_pf *pf, u16 sw_id, struct ice_channel *ch)
7893 struct device *dev = ice_pf_to_dev(pf);
7894 struct ice_vsi *vsi;
7896 if (ch->type != ICE_VSI_CHNL) {
7897 dev_err(dev, "add new VSI failed, ch->type %d\n", ch->type);
7901 vsi = ice_chnl_vsi_setup(pf, pf->hw.port_info, ch);
7902 if (!vsi || vsi->type != ICE_VSI_CHNL) {
7903 dev_err(dev, "create chnl VSI failure\n");
7907 ice_add_vsi_to_fdir(pf, vsi);
7910 ch->vsi_num = vsi->vsi_num;
7911 ch->info.mapping_flags = vsi->info.mapping_flags;
7913 /* set the back pointer of channel for newly created VSI */
7916 memcpy(&ch->info.q_mapping, &vsi->info.q_mapping,
7917 sizeof(vsi->info.q_mapping));
7918 memcpy(&ch->info.tc_mapping, vsi->info.tc_mapping,
7919 sizeof(vsi->info.tc_mapping));
7926 * @vsi: the VSI being setup
7927 * @ch: ptr to channel structure
7929 * Configure channel specific resources such as rings, vector.
7931 static void ice_chnl_cfg_res(struct ice_vsi *vsi, struct ice_channel *ch)
7935 for (i = 0; i < ch->num_txq; i++) {
7936 struct ice_q_vector *tx_q_vector, *rx_q_vector;
7937 struct ice_ring_container *rc;
7938 struct ice_tx_ring *tx_ring;
7939 struct ice_rx_ring *rx_ring;
7941 tx_ring = vsi->tx_rings[ch->base_q + i];
7942 rx_ring = vsi->rx_rings[ch->base_q + i];
7943 if (!tx_ring || !rx_ring)
7946 /* setup ring being channel enabled */
7950 /* following code block sets up vector specific attributes */
7951 tx_q_vector = tx_ring->q_vector;
7952 rx_q_vector = rx_ring->q_vector;
7953 if (!tx_q_vector && !rx_q_vector)
7957 tx_q_vector->ch = ch;
7958 /* setup Tx and Rx ITR setting if DIM is off */
7959 rc = &tx_q_vector->tx;
7960 if (!ITR_IS_DYNAMIC(rc))
7961 ice_write_itr(rc, rc->itr_setting);
7964 rx_q_vector->ch = ch;
7965 /* setup Tx and Rx ITR setting if DIM is off */
7966 rc = &rx_q_vector->rx;
7967 if (!ITR_IS_DYNAMIC(rc))
7968 ice_write_itr(rc, rc->itr_setting);
7972 /* it is safe to assume that, if channel has non-zero num_t[r]xq, then
7973 * GLINT_ITR register would have written to perform in-context
7974 * update, hence perform flush
7976 if (ch->num_txq || ch->num_rxq)
7977 ice_flush(&vsi->back->hw);
7981 * ice_cfg_chnl_all_res - configure channel resources
7982 * @vsi: pte to main_vsi
7983 * @ch: ptr to channel structure
7985 * This function configures channel specific resources such as flow-director
7986 * counter index, and other resources such as queues, vectors, ITR settings
7989 ice_cfg_chnl_all_res(struct ice_vsi *vsi, struct ice_channel *ch)
7991 /* configure channel (aka ADQ) resources such as queues, vectors,
7992 * ITR settings for channel specific vectors and anything else
7994 ice_chnl_cfg_res(vsi, ch);
7998 * ice_setup_hw_channel - setup new channel
7999 * @pf: ptr to PF device
8000 * @vsi: the VSI being setup
8001 * @ch: ptr to channel structure
8002 * @sw_id: underlying HW switching element ID
8003 * @type: type of channel to be created (VMDq2/VF)
8005 * Setup new channel (VSI) based on specified type (VMDq2/VF)
8006 * and configures Tx rings accordingly
8009 ice_setup_hw_channel(struct ice_pf *pf, struct ice_vsi *vsi,
8010 struct ice_channel *ch, u16 sw_id, u8 type)
8012 struct device *dev = ice_pf_to_dev(pf);
8015 ch->base_q = vsi->next_base_q;
8018 ret = ice_add_channel(pf, sw_id, ch);
8020 dev_err(dev, "failed to add_channel using sw_id %u\n", sw_id);
8024 /* configure/setup ADQ specific resources */
8025 ice_cfg_chnl_all_res(vsi, ch);
8027 /* make sure to update the next_base_q so that subsequent channel's
8028 * (aka ADQ) VSI queue map is correct
8030 vsi->next_base_q = vsi->next_base_q + ch->num_rxq;
8031 dev_dbg(dev, "added channel: vsi_num %u, num_rxq %u\n", ch->vsi_num,
8038 * ice_setup_channel - setup new channel using uplink element
8039 * @pf: ptr to PF device
8040 * @vsi: the VSI being setup
8041 * @ch: ptr to channel structure
8043 * Setup new channel (VSI) based on specified type (VMDq2/VF)
8044 * and uplink switching element
8047 ice_setup_channel(struct ice_pf *pf, struct ice_vsi *vsi,
8048 struct ice_channel *ch)
8050 struct device *dev = ice_pf_to_dev(pf);
8054 if (vsi->type != ICE_VSI_PF) {
8055 dev_err(dev, "unsupported parent VSI type(%d)\n", vsi->type);
8059 sw_id = pf->first_sw->sw_id;
8061 /* create channel (VSI) */
8062 ret = ice_setup_hw_channel(pf, vsi, ch, sw_id, ICE_VSI_CHNL);
8064 dev_err(dev, "failed to setup hw_channel\n");
8067 dev_dbg(dev, "successfully created channel()\n");
8069 return ch->ch_vsi ? true : false;
8073 * ice_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
8074 * @vsi: VSI to be configured
8075 * @max_tx_rate: max Tx rate in Kbps to be configured as maximum BW limit
8076 * @min_tx_rate: min Tx rate in Kbps to be configured as minimum BW limit
8079 ice_set_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate, u64 min_tx_rate)
8083 err = ice_set_min_bw_limit(vsi, min_tx_rate);
8087 return ice_set_max_bw_limit(vsi, max_tx_rate);
8091 * ice_create_q_channel - function to create channel
8092 * @vsi: VSI to be configured
8093 * @ch: ptr to channel (it contains channel specific params)
8095 * This function creates channel (VSI) using num_queues specified by user,
8096 * reconfigs RSS if needed.
8098 static int ice_create_q_channel(struct ice_vsi *vsi, struct ice_channel *ch)
8100 struct ice_pf *pf = vsi->back;
8106 dev = ice_pf_to_dev(pf);
8107 if (!ch->num_txq || !ch->num_rxq) {
8108 dev_err(dev, "Invalid num_queues requested: %d\n", ch->num_rxq);
8112 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_txq) {
8113 dev_err(dev, "cnt_q_avail (%u) less than num_queues %d\n",
8114 vsi->cnt_q_avail, ch->num_txq);
8118 if (!ice_setup_channel(pf, vsi, ch)) {
8119 dev_info(dev, "Failed to setup channel\n");
8122 /* configure BW rate limit */
8123 if (ch->ch_vsi && (ch->max_tx_rate || ch->min_tx_rate)) {
8126 ret = ice_set_bw_limit(ch->ch_vsi, ch->max_tx_rate,
8129 dev_err(dev, "failed to set Tx rate of %llu Kbps for VSI(%u)\n",
8130 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8132 dev_dbg(dev, "set Tx rate of %llu Kbps for VSI(%u)\n",
8133 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8136 vsi->cnt_q_avail -= ch->num_txq;
8142 * ice_rem_all_chnl_fltrs - removes all channel filters
8143 * @pf: ptr to PF, TC-flower based filter are tracked at PF level
8145 * Remove all advanced switch filters only if they are channel specific
8146 * tc-flower based filter
8148 static void ice_rem_all_chnl_fltrs(struct ice_pf *pf)
8150 struct ice_tc_flower_fltr *fltr;
8151 struct hlist_node *node;
8153 /* to remove all channel filters, iterate an ordered list of filters */
8154 hlist_for_each_entry_safe(fltr, node,
8155 &pf->tc_flower_fltr_list,
8157 struct ice_rule_query_data rule;
8160 /* for now process only channel specific filters */
8161 if (!ice_is_chnl_fltr(fltr))
8164 rule.rid = fltr->rid;
8165 rule.rule_id = fltr->rule_id;
8166 rule.vsi_handle = fltr->dest_id;
8167 status = ice_rem_adv_rule_by_id(&pf->hw, &rule);
8169 if (status == -ENOENT)
8170 dev_dbg(ice_pf_to_dev(pf), "TC flower filter (rule_id %u) does not exist\n",
8173 dev_err(ice_pf_to_dev(pf), "failed to delete TC flower filter, status %d\n",
8175 } else if (fltr->dest_vsi) {
8176 /* update advanced switch filter count */
8177 if (fltr->dest_vsi->type == ICE_VSI_CHNL) {
8178 u32 flags = fltr->flags;
8180 fltr->dest_vsi->num_chnl_fltr--;
8181 if (flags & (ICE_TC_FLWR_FIELD_DST_MAC |
8182 ICE_TC_FLWR_FIELD_ENC_DST_MAC))
8183 pf->num_dmac_chnl_fltrs--;
8187 hlist_del(&fltr->tc_flower_node);
8193 * ice_remove_q_channels - Remove queue channels for the TCs
8194 * @vsi: VSI to be configured
8195 * @rem_fltr: delete advanced switch filter or not
8197 * Remove queue channels for the TCs
8199 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_fltr)
8201 struct ice_channel *ch, *ch_tmp;
8202 struct ice_pf *pf = vsi->back;
8205 /* remove all tc-flower based filter if they are channel filters only */
8207 ice_rem_all_chnl_fltrs(pf);
8209 /* remove ntuple filters since queue configuration is being changed */
8210 if (vsi->netdev->features & NETIF_F_NTUPLE) {
8211 struct ice_hw *hw = &pf->hw;
8213 mutex_lock(&hw->fdir_fltr_lock);
8214 ice_fdir_del_all_fltrs(vsi);
8215 mutex_unlock(&hw->fdir_fltr_lock);
8218 /* perform cleanup for channels if they exist */
8219 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
8220 struct ice_vsi *ch_vsi;
8222 list_del(&ch->list);
8223 ch_vsi = ch->ch_vsi;
8229 /* Reset queue contexts */
8230 for (i = 0; i < ch->num_rxq; i++) {
8231 struct ice_tx_ring *tx_ring;
8232 struct ice_rx_ring *rx_ring;
8234 tx_ring = vsi->tx_rings[ch->base_q + i];
8235 rx_ring = vsi->rx_rings[ch->base_q + i];
8238 if (tx_ring->q_vector)
8239 tx_ring->q_vector->ch = NULL;
8243 if (rx_ring->q_vector)
8244 rx_ring->q_vector->ch = NULL;
8248 /* Release FD resources for the channel VSI */
8249 ice_fdir_rem_adq_chnl(&pf->hw, ch->ch_vsi->idx);
8251 /* clear the VSI from scheduler tree */
8252 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx);
8254 /* Delete VSI from FW */
8255 ice_vsi_delete(ch->ch_vsi);
8257 /* Delete VSI from PF and HW VSI arrays */
8258 ice_vsi_clear(ch->ch_vsi);
8260 /* free the channel */
8264 /* clear the channel VSI map which is stored in main VSI */
8265 ice_for_each_chnl_tc(i)
8266 vsi->tc_map_vsi[i] = NULL;
8268 /* reset main VSI's all TC information */
8274 * ice_rebuild_channels - rebuild channel
8277 * Recreate channel VSIs and replay filters
8279 static int ice_rebuild_channels(struct ice_pf *pf)
8281 struct device *dev = ice_pf_to_dev(pf);
8282 struct ice_vsi *main_vsi;
8283 bool rem_adv_fltr = true;
8284 struct ice_channel *ch;
8285 struct ice_vsi *vsi;
8289 main_vsi = ice_get_main_vsi(pf);
8293 if (!test_bit(ICE_FLAG_TC_MQPRIO, pf->flags) ||
8294 main_vsi->old_numtc == 1)
8295 return 0; /* nothing to be done */
8297 /* reconfigure main VSI based on old value of TC and cached values
8300 err = ice_vsi_cfg_tc(main_vsi, main_vsi->old_ena_tc);
8302 dev_err(dev, "failed configuring TC(ena_tc:0x%02x) for HW VSI=%u\n",
8303 main_vsi->old_ena_tc, main_vsi->vsi_num);
8307 /* rebuild ADQ VSIs */
8308 ice_for_each_vsi(pf, i) {
8309 enum ice_vsi_type type;
8312 if (!vsi || vsi->type != ICE_VSI_CHNL)
8317 /* rebuild ADQ VSI */
8318 err = ice_vsi_rebuild(vsi, true);
8320 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n",
8321 ice_vsi_type_str(type), vsi->idx, err);
8325 /* Re-map HW VSI number, using VSI handle that has been
8326 * previously validated in ice_replay_vsi() call above
8328 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
8330 /* replay filters for the VSI */
8331 err = ice_replay_vsi(&pf->hw, vsi->idx);
8333 dev_err(dev, "VSI (type:%s) replay failed, err %d, VSI index %d\n",
8334 ice_vsi_type_str(type), err, vsi->idx);
8335 rem_adv_fltr = false;
8338 dev_info(dev, "VSI (type:%s) at index %d rebuilt successfully\n",
8339 ice_vsi_type_str(type), vsi->idx);
8341 /* store ADQ VSI at correct TC index in main VSI's
8344 main_vsi->tc_map_vsi[tc_idx++] = vsi;
8347 /* ADQ VSI(s) has been rebuilt successfully, so setup
8348 * channel for main VSI's Tx and Rx rings
8350 list_for_each_entry(ch, &main_vsi->ch_list, list) {
8351 struct ice_vsi *ch_vsi;
8353 ch_vsi = ch->ch_vsi;
8357 /* reconfig channel resources */
8358 ice_cfg_chnl_all_res(main_vsi, ch);
8360 /* replay BW rate limit if it is non-zero */
8361 if (!ch->max_tx_rate && !ch->min_tx_rate)
8364 err = ice_set_bw_limit(ch_vsi, ch->max_tx_rate,
8367 dev_err(dev, "failed (err:%d) to rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n",
8368 err, ch->max_tx_rate, ch->min_tx_rate,
8371 dev_dbg(dev, "successfully rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n",
8372 ch->max_tx_rate, ch->min_tx_rate,
8376 /* reconfig RSS for main VSI */
8377 if (main_vsi->ch_rss_size)
8378 ice_vsi_cfg_rss_lut_key(main_vsi);
8383 ice_remove_q_channels(main_vsi, rem_adv_fltr);
8388 * ice_create_q_channels - Add queue channel for the given TCs
8389 * @vsi: VSI to be configured
8391 * Configures queue channel mapping to the given TCs
8393 static int ice_create_q_channels(struct ice_vsi *vsi)
8395 struct ice_pf *pf = vsi->back;
8396 struct ice_channel *ch;
8399 ice_for_each_chnl_tc(i) {
8400 if (!(vsi->all_enatc & BIT(i)))
8403 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
8408 INIT_LIST_HEAD(&ch->list);
8409 ch->num_rxq = vsi->mqprio_qopt.qopt.count[i];
8410 ch->num_txq = vsi->mqprio_qopt.qopt.count[i];
8411 ch->base_q = vsi->mqprio_qopt.qopt.offset[i];
8412 ch->max_tx_rate = vsi->mqprio_qopt.max_rate[i];
8413 ch->min_tx_rate = vsi->mqprio_qopt.min_rate[i];
8415 /* convert to Kbits/s */
8416 if (ch->max_tx_rate)
8417 ch->max_tx_rate = div_u64(ch->max_tx_rate,
8418 ICE_BW_KBPS_DIVISOR);
8419 if (ch->min_tx_rate)
8420 ch->min_tx_rate = div_u64(ch->min_tx_rate,
8421 ICE_BW_KBPS_DIVISOR);
8423 ret = ice_create_q_channel(vsi, ch);
8425 dev_err(ice_pf_to_dev(pf),
8426 "failed creating channel TC:%d\n", i);
8430 list_add_tail(&ch->list, &vsi->ch_list);
8431 vsi->tc_map_vsi[i] = ch->ch_vsi;
8432 dev_dbg(ice_pf_to_dev(pf),
8433 "successfully created channel: VSI %pK\n", ch->ch_vsi);
8438 ice_remove_q_channels(vsi, false);
8444 * ice_setup_tc_mqprio_qdisc - configure multiple traffic classes
8445 * @netdev: net device to configure
8446 * @type_data: TC offload data
8448 static int ice_setup_tc_mqprio_qdisc(struct net_device *netdev, void *type_data)
8450 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
8451 struct ice_netdev_priv *np = netdev_priv(netdev);
8452 struct ice_vsi *vsi = np->vsi;
8453 struct ice_pf *pf = vsi->back;
8454 u16 mode, ena_tc_qdisc = 0;
8455 int cur_txq, cur_rxq;
8460 dev = ice_pf_to_dev(pf);
8461 num_tcf = mqprio_qopt->qopt.num_tc;
8462 hw = mqprio_qopt->qopt.hw;
8463 mode = mqprio_qopt->mode;
8465 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8466 vsi->ch_rss_size = 0;
8467 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8471 /* Generate queue region map for number of TCF requested */
8472 for (i = 0; i < num_tcf; i++)
8473 ena_tc_qdisc |= BIT(i);
8476 case TC_MQPRIO_MODE_CHANNEL:
8478 ret = ice_validate_mqprio_qopt(vsi, mqprio_qopt);
8480 netdev_err(netdev, "failed to validate_mqprio_qopt(), ret %d\n",
8484 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8485 set_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8486 /* don't assume state of hw_tc_offload during driver load
8487 * and set the flag for TC flower filter if hw_tc_offload
8490 if (vsi->netdev->features & NETIF_F_HW_TC)
8491 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
8499 /* Requesting same TCF configuration as already enabled */
8500 if (ena_tc_qdisc == vsi->tc_cfg.ena_tc &&
8501 mode != TC_MQPRIO_MODE_CHANNEL)
8504 /* Pause VSI queues */
8505 ice_dis_vsi(vsi, true);
8507 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
8508 ice_remove_q_channels(vsi, true);
8510 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8511 vsi->req_txq = min_t(int, ice_get_avail_txq_count(pf),
8513 vsi->req_rxq = min_t(int, ice_get_avail_rxq_count(pf),
8516 /* logic to rebuild VSI, same like ethtool -L */
8517 u16 offset = 0, qcount_tx = 0, qcount_rx = 0;
8519 for (i = 0; i < num_tcf; i++) {
8520 if (!(ena_tc_qdisc & BIT(i)))
8523 offset = vsi->mqprio_qopt.qopt.offset[i];
8524 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
8525 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
8527 vsi->req_txq = offset + qcount_tx;
8528 vsi->req_rxq = offset + qcount_rx;
8530 /* store away original rss_size info, so that it gets reused
8531 * form ice_vsi_rebuild during tc-qdisc delete stage - to
8532 * determine, what should be the rss_sizefor main VSI
8534 vsi->orig_rss_size = vsi->rss_size;
8537 /* save current values of Tx and Rx queues before calling VSI rebuild
8538 * for fallback option
8540 cur_txq = vsi->num_txq;
8541 cur_rxq = vsi->num_rxq;
8543 /* proceed with rebuild main VSI using correct number of queues */
8544 ret = ice_vsi_rebuild(vsi, false);
8546 /* fallback to current number of queues */
8547 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n");
8548 vsi->req_txq = cur_txq;
8549 vsi->req_rxq = cur_rxq;
8550 clear_bit(ICE_RESET_FAILED, pf->state);
8551 if (ice_vsi_rebuild(vsi, false)) {
8552 dev_err(dev, "Rebuild of main VSI failed again\n");
8557 vsi->all_numtc = num_tcf;
8558 vsi->all_enatc = ena_tc_qdisc;
8559 ret = ice_vsi_cfg_tc(vsi, ena_tc_qdisc);
8561 netdev_err(netdev, "failed configuring TC for VSI id=%d\n",
8566 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8567 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
8568 u64 min_tx_rate = vsi->mqprio_qopt.min_rate[0];
8570 /* set TC0 rate limit if specified */
8571 if (max_tx_rate || min_tx_rate) {
8572 /* convert to Kbits/s */
8574 max_tx_rate = div_u64(max_tx_rate, ICE_BW_KBPS_DIVISOR);
8576 min_tx_rate = div_u64(min_tx_rate, ICE_BW_KBPS_DIVISOR);
8578 ret = ice_set_bw_limit(vsi, max_tx_rate, min_tx_rate);
8580 dev_dbg(dev, "set Tx rate max %llu min %llu for VSI(%u)\n",
8581 max_tx_rate, min_tx_rate, vsi->vsi_num);
8583 dev_err(dev, "failed to set Tx rate max %llu min %llu for VSI(%u)\n",
8584 max_tx_rate, min_tx_rate, vsi->vsi_num);
8588 ret = ice_create_q_channels(vsi);
8590 netdev_err(netdev, "failed configuring queue channels\n");
8593 netdev_dbg(netdev, "successfully configured channels\n");
8597 if (vsi->ch_rss_size)
8598 ice_vsi_cfg_rss_lut_key(vsi);
8601 /* if error, reset the all_numtc and all_enatc */
8607 ice_ena_vsi(vsi, true);
8612 static LIST_HEAD(ice_block_cb_list);
8615 ice_setup_tc(struct net_device *netdev, enum tc_setup_type type,
8618 struct ice_netdev_priv *np = netdev_priv(netdev);
8619 struct ice_pf *pf = np->vsi->back;
8623 case TC_SETUP_BLOCK:
8624 return flow_block_cb_setup_simple(type_data,
8626 ice_setup_tc_block_cb,
8628 case TC_SETUP_QDISC_MQPRIO:
8629 /* setup traffic classifier for receive side */
8630 mutex_lock(&pf->tc_mutex);
8631 err = ice_setup_tc_mqprio_qdisc(netdev, type_data);
8632 mutex_unlock(&pf->tc_mutex);
8640 static struct ice_indr_block_priv *
8641 ice_indr_block_priv_lookup(struct ice_netdev_priv *np,
8642 struct net_device *netdev)
8644 struct ice_indr_block_priv *cb_priv;
8646 list_for_each_entry(cb_priv, &np->tc_indr_block_priv_list, list) {
8647 if (!cb_priv->netdev)
8649 if (cb_priv->netdev == netdev)
8656 ice_indr_setup_block_cb(enum tc_setup_type type, void *type_data,
8659 struct ice_indr_block_priv *priv = indr_priv;
8660 struct ice_netdev_priv *np = priv->np;
8663 case TC_SETUP_CLSFLOWER:
8664 return ice_setup_tc_cls_flower(np, priv->netdev,
8665 (struct flow_cls_offload *)
8673 ice_indr_setup_tc_block(struct net_device *netdev, struct Qdisc *sch,
8674 struct ice_netdev_priv *np,
8675 struct flow_block_offload *f, void *data,
8676 void (*cleanup)(struct flow_block_cb *block_cb))
8678 struct ice_indr_block_priv *indr_priv;
8679 struct flow_block_cb *block_cb;
8681 if (!ice_is_tunnel_supported(netdev) &&
8682 !(is_vlan_dev(netdev) &&
8683 vlan_dev_real_dev(netdev) == np->vsi->netdev))
8686 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
8689 switch (f->command) {
8690 case FLOW_BLOCK_BIND:
8691 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8695 indr_priv = kzalloc(sizeof(*indr_priv), GFP_KERNEL);
8699 indr_priv->netdev = netdev;
8701 list_add(&indr_priv->list, &np->tc_indr_block_priv_list);
8704 flow_indr_block_cb_alloc(ice_indr_setup_block_cb,
8705 indr_priv, indr_priv,
8706 ice_rep_indr_tc_block_unbind,
8707 f, netdev, sch, data, np,
8710 if (IS_ERR(block_cb)) {
8711 list_del(&indr_priv->list);
8713 return PTR_ERR(block_cb);
8715 flow_block_cb_add(block_cb, f);
8716 list_add_tail(&block_cb->driver_list, &ice_block_cb_list);
8718 case FLOW_BLOCK_UNBIND:
8719 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8723 block_cb = flow_block_cb_lookup(f->block,
8724 ice_indr_setup_block_cb,
8729 flow_indr_block_cb_remove(block_cb, f);
8731 list_del(&block_cb->driver_list);
8740 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
8741 void *cb_priv, enum tc_setup_type type, void *type_data,
8743 void (*cleanup)(struct flow_block_cb *block_cb))
8746 case TC_SETUP_BLOCK:
8747 return ice_indr_setup_tc_block(netdev, sch, cb_priv, type_data,
8756 * ice_open - Called when a network interface becomes active
8757 * @netdev: network interface device structure
8759 * The open entry point is called when a network interface is made
8760 * active by the system (IFF_UP). At this point all resources needed
8761 * for transmit and receive operations are allocated, the interrupt
8762 * handler is registered with the OS, the netdev watchdog is enabled,
8763 * and the stack is notified that the interface is ready.
8765 * Returns 0 on success, negative value on failure
8767 int ice_open(struct net_device *netdev)
8769 struct ice_netdev_priv *np = netdev_priv(netdev);
8770 struct ice_pf *pf = np->vsi->back;
8772 if (ice_is_reset_in_progress(pf->state)) {
8773 netdev_err(netdev, "can't open net device while reset is in progress");
8777 return ice_open_internal(netdev);
8781 * ice_open_internal - Called when a network interface becomes active
8782 * @netdev: network interface device structure
8784 * Internal ice_open implementation. Should not be used directly except for ice_open and reset
8787 * Returns 0 on success, negative value on failure
8789 int ice_open_internal(struct net_device *netdev)
8791 struct ice_netdev_priv *np = netdev_priv(netdev);
8792 struct ice_vsi *vsi = np->vsi;
8793 struct ice_pf *pf = vsi->back;
8794 struct ice_port_info *pi;
8797 if (test_bit(ICE_NEEDS_RESTART, pf->state)) {
8798 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
8802 netif_carrier_off(netdev);
8804 pi = vsi->port_info;
8805 err = ice_update_link_info(pi);
8807 netdev_err(netdev, "Failed to get link info, error %d\n", err);
8811 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
8813 /* Set PHY if there is media, otherwise, turn off PHY */
8814 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
8815 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8816 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) {
8817 err = ice_init_phy_user_cfg(pi);
8819 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n",
8825 err = ice_configure_phy(vsi);
8827 netdev_err(netdev, "Failed to set physical link up, error %d\n",
8832 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8833 ice_set_link(vsi, false);
8836 err = ice_vsi_open(vsi);
8838 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
8839 vsi->vsi_num, vsi->vsw->sw_id);
8841 /* Update existing tunnels information */
8842 udp_tunnel_get_rx_info(netdev);
8848 * ice_stop - Disables a network interface
8849 * @netdev: network interface device structure
8851 * The stop entry point is called when an interface is de-activated by the OS,
8852 * and the netdevice enters the DOWN state. The hardware is still under the
8853 * driver's control, but the netdev interface is disabled.
8855 * Returns success only - not allowed to fail
8857 int ice_stop(struct net_device *netdev)
8859 struct ice_netdev_priv *np = netdev_priv(netdev);
8860 struct ice_vsi *vsi = np->vsi;
8861 struct ice_pf *pf = vsi->back;
8863 if (ice_is_reset_in_progress(pf->state)) {
8864 netdev_err(netdev, "can't stop net device while reset is in progress");
8874 * ice_features_check - Validate encapsulated packet conforms to limits
8876 * @netdev: This port's netdev
8877 * @features: Offload features that the stack believes apply
8879 static netdev_features_t
8880 ice_features_check(struct sk_buff *skb,
8881 struct net_device __always_unused *netdev,
8882 netdev_features_t features)
8884 bool gso = skb_is_gso(skb);
8887 /* No point in doing any of this if neither checksum nor GSO are
8888 * being requested for this frame. We can rule out both by just
8889 * checking for CHECKSUM_PARTIAL
8891 if (skb->ip_summed != CHECKSUM_PARTIAL)
8894 /* We cannot support GSO if the MSS is going to be less than
8895 * 64 bytes. If it is then we need to drop support for GSO.
8897 if (gso && (skb_shinfo(skb)->gso_size < ICE_TXD_CTX_MIN_MSS))
8898 features &= ~NETIF_F_GSO_MASK;
8900 len = skb_network_offset(skb);
8901 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
8902 goto out_rm_features;
8904 len = skb_network_header_len(skb);
8905 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8906 goto out_rm_features;
8908 if (skb->encapsulation) {
8909 /* this must work for VXLAN frames AND IPIP/SIT frames, and in
8910 * the case of IPIP frames, the transport header pointer is
8911 * after the inner header! So check to make sure that this
8912 * is a GRE or UDP_TUNNEL frame before doing that math.
8914 if (gso && (skb_shinfo(skb)->gso_type &
8915 (SKB_GSO_GRE | SKB_GSO_UDP_TUNNEL))) {
8916 len = skb_inner_network_header(skb) -
8917 skb_transport_header(skb);
8918 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
8919 goto out_rm_features;
8922 len = skb_inner_network_header_len(skb);
8923 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8924 goto out_rm_features;
8929 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
8932 static const struct net_device_ops ice_netdev_safe_mode_ops = {
8933 .ndo_open = ice_open,
8934 .ndo_stop = ice_stop,
8935 .ndo_start_xmit = ice_start_xmit,
8936 .ndo_set_mac_address = ice_set_mac_address,
8937 .ndo_validate_addr = eth_validate_addr,
8938 .ndo_change_mtu = ice_change_mtu,
8939 .ndo_get_stats64 = ice_get_stats64,
8940 .ndo_tx_timeout = ice_tx_timeout,
8941 .ndo_bpf = ice_xdp_safe_mode,
8944 static const struct net_device_ops ice_netdev_ops = {
8945 .ndo_open = ice_open,
8946 .ndo_stop = ice_stop,
8947 .ndo_start_xmit = ice_start_xmit,
8948 .ndo_select_queue = ice_select_queue,
8949 .ndo_features_check = ice_features_check,
8950 .ndo_fix_features = ice_fix_features,
8951 .ndo_set_rx_mode = ice_set_rx_mode,
8952 .ndo_set_mac_address = ice_set_mac_address,
8953 .ndo_validate_addr = eth_validate_addr,
8954 .ndo_change_mtu = ice_change_mtu,
8955 .ndo_get_stats64 = ice_get_stats64,
8956 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
8957 .ndo_eth_ioctl = ice_eth_ioctl,
8958 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
8959 .ndo_set_vf_mac = ice_set_vf_mac,
8960 .ndo_get_vf_config = ice_get_vf_cfg,
8961 .ndo_set_vf_trust = ice_set_vf_trust,
8962 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
8963 .ndo_set_vf_link_state = ice_set_vf_link_state,
8964 .ndo_get_vf_stats = ice_get_vf_stats,
8965 .ndo_set_vf_rate = ice_set_vf_bw,
8966 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
8967 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
8968 .ndo_setup_tc = ice_setup_tc,
8969 .ndo_set_features = ice_set_features,
8970 .ndo_bridge_getlink = ice_bridge_getlink,
8971 .ndo_bridge_setlink = ice_bridge_setlink,
8972 .ndo_fdb_add = ice_fdb_add,
8973 .ndo_fdb_del = ice_fdb_del,
8974 #ifdef CONFIG_RFS_ACCEL
8975 .ndo_rx_flow_steer = ice_rx_flow_steer,
8977 .ndo_tx_timeout = ice_tx_timeout,
8979 .ndo_xdp_xmit = ice_xdp_xmit,
8980 .ndo_xsk_wakeup = ice_xsk_wakeup,
8981 .ndo_get_devlink_port = ice_get_devlink_port,