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_vsi_sync_fltr - Update the VSI filter list to the HW
301 * @vsi: ptr to the VSI
303 * Push any outstanding VSI filter changes through the AdminQ.
305 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
307 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
308 struct device *dev = ice_pf_to_dev(vsi->back);
309 struct net_device *netdev = vsi->netdev;
310 bool promisc_forced_on = false;
311 struct ice_pf *pf = vsi->back;
312 struct ice_hw *hw = &pf->hw;
313 u32 changed_flags = 0;
319 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
320 usleep_range(1000, 2000);
322 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
323 vsi->current_netdev_flags = vsi->netdev->flags;
325 INIT_LIST_HEAD(&vsi->tmp_sync_list);
326 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
328 if (ice_vsi_fltr_changed(vsi)) {
329 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
330 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
332 /* grab the netdev's addr_list_lock */
333 netif_addr_lock_bh(netdev);
334 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
335 ice_add_mac_to_unsync_list);
336 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
337 ice_add_mac_to_unsync_list);
338 /* our temp lists are populated. release lock */
339 netif_addr_unlock_bh(netdev);
342 /* Remove MAC addresses in the unsync list */
343 err = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
344 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
346 netdev_err(netdev, "Failed to delete MAC filters\n");
347 /* if we failed because of alloc failures, just bail */
352 /* Add MAC addresses in the sync list */
353 err = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
354 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
355 /* If filter is added successfully or already exists, do not go into
356 * 'if' condition and report it as error. Instead continue processing
357 * rest of the function.
359 if (err && err != -EEXIST) {
360 netdev_err(netdev, "Failed to add MAC filters\n");
361 /* If there is no more space for new umac filters, VSI
362 * should go into promiscuous mode. There should be some
363 * space reserved for promiscuous filters.
365 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
366 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC,
368 promisc_forced_on = true;
369 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
376 /* check for changes in promiscuous modes */
377 if (changed_flags & IFF_ALLMULTI) {
378 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
379 err = ice_set_promisc(vsi, ICE_MCAST_PROMISC_BITS);
381 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
385 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
386 err = ice_clear_promisc(vsi, ICE_MCAST_PROMISC_BITS);
388 vsi->current_netdev_flags |= IFF_ALLMULTI;
394 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
395 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) {
396 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
397 if (vsi->current_netdev_flags & IFF_PROMISC) {
398 /* Apply Rx filter rule to get traffic from wire */
399 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) {
400 err = ice_set_dflt_vsi(pf->first_sw, vsi);
401 if (err && err != -EEXIST) {
402 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
404 vsi->current_netdev_flags &=
409 vlan_ops->dis_rx_filtering(vsi);
412 /* Clear Rx filter to remove traffic from wire */
413 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) {
414 err = ice_clear_dflt_vsi(pf->first_sw);
416 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
418 vsi->current_netdev_flags |=
422 if (vsi->current_netdev_flags &
423 NETIF_F_HW_VLAN_CTAG_FILTER)
424 vlan_ops->ena_rx_filtering(vsi);
431 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
434 /* if something went wrong then set the changed flag so we try again */
435 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
436 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
438 clear_bit(ICE_CFG_BUSY, vsi->state);
443 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
444 * @pf: board private structure
446 static void ice_sync_fltr_subtask(struct ice_pf *pf)
450 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
453 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
455 ice_for_each_vsi(pf, v)
456 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
457 ice_vsi_sync_fltr(pf->vsi[v])) {
458 /* come back and try again later */
459 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
465 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
467 * @locked: is the rtnl_lock already held
469 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
474 ice_for_each_vsi(pf, v)
476 ice_dis_vsi(pf->vsi[v], locked);
478 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++)
479 pf->pf_agg_node[node].num_vsis = 0;
481 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++)
482 pf->vf_agg_node[node].num_vsis = 0;
486 * ice_clear_sw_switch_recipes - clear switch recipes
487 * @pf: board private structure
489 * Mark switch recipes as not created in sw structures. There are cases where
490 * rules (especially advanced rules) need to be restored, either re-read from
491 * hardware or added again. For example after the reset. 'recp_created' flag
492 * prevents from doing that and need to be cleared upfront.
494 static void ice_clear_sw_switch_recipes(struct ice_pf *pf)
496 struct ice_sw_recipe *recp;
499 recp = pf->hw.switch_info->recp_list;
500 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
501 recp[i].recp_created = false;
505 * ice_prepare_for_reset - prep for reset
506 * @pf: board private structure
507 * @reset_type: reset type requested
509 * Inform or close all dependent features in prep for reset.
512 ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
514 struct ice_hw *hw = &pf->hw;
519 dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type);
521 /* already prepared for reset */
522 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state))
525 ice_unplug_aux_dev(pf);
527 /* Notify VFs of impending reset */
528 if (ice_check_sq_alive(hw, &hw->mailboxq))
529 ice_vc_notify_reset(pf);
531 /* Disable VFs until reset is completed */
532 mutex_lock(&pf->vfs.table_lock);
533 ice_for_each_vf(pf, bkt, vf)
534 ice_set_vf_state_qs_dis(vf);
535 mutex_unlock(&pf->vfs.table_lock);
537 if (ice_is_eswitch_mode_switchdev(pf)) {
538 if (reset_type != ICE_RESET_PFR)
539 ice_clear_sw_switch_recipes(pf);
542 /* release ADQ specific HW and SW resources */
543 vsi = ice_get_main_vsi(pf);
547 /* to be on safe side, reset orig_rss_size so that normal flow
548 * of deciding rss_size can take precedence
550 vsi->orig_rss_size = 0;
552 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
553 if (reset_type == ICE_RESET_PFR) {
554 vsi->old_ena_tc = vsi->all_enatc;
555 vsi->old_numtc = vsi->all_numtc;
557 ice_remove_q_channels(vsi, true);
559 /* for other reset type, do not support channel rebuild
560 * hence reset needed info
568 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
569 memset(&vsi->mqprio_qopt, 0, sizeof(vsi->mqprio_qopt));
574 /* clear SW filtering DB */
575 ice_clear_hw_tbls(hw);
576 /* disable the VSIs and their queues that are not already DOWN */
577 ice_pf_dis_all_vsi(pf, false);
579 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
580 ice_ptp_prepare_for_reset(pf);
582 if (ice_is_feature_supported(pf, ICE_F_GNSS))
586 ice_sched_clear_port(hw->port_info);
588 ice_shutdown_all_ctrlq(hw);
590 set_bit(ICE_PREPARED_FOR_RESET, pf->state);
594 * ice_do_reset - Initiate one of many types of resets
595 * @pf: board private structure
596 * @reset_type: reset type requested before this function was called.
598 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
600 struct device *dev = ice_pf_to_dev(pf);
601 struct ice_hw *hw = &pf->hw;
603 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
605 ice_prepare_for_reset(pf, reset_type);
607 /* trigger the reset */
608 if (ice_reset(hw, reset_type)) {
609 dev_err(dev, "reset %d failed\n", reset_type);
610 set_bit(ICE_RESET_FAILED, pf->state);
611 clear_bit(ICE_RESET_OICR_RECV, pf->state);
612 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
613 clear_bit(ICE_PFR_REQ, pf->state);
614 clear_bit(ICE_CORER_REQ, pf->state);
615 clear_bit(ICE_GLOBR_REQ, pf->state);
616 wake_up(&pf->reset_wait_queue);
620 /* PFR is a bit of a special case because it doesn't result in an OICR
621 * interrupt. So for PFR, rebuild after the reset and clear the reset-
622 * associated state bits.
624 if (reset_type == ICE_RESET_PFR) {
626 ice_rebuild(pf, reset_type);
627 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
628 clear_bit(ICE_PFR_REQ, pf->state);
629 wake_up(&pf->reset_wait_queue);
630 ice_reset_all_vfs(pf);
635 * ice_reset_subtask - Set up for resetting the device and driver
636 * @pf: board private structure
638 static void ice_reset_subtask(struct ice_pf *pf)
640 enum ice_reset_req reset_type = ICE_RESET_INVAL;
642 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
643 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
644 * of reset is pending and sets bits in pf->state indicating the reset
645 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set
646 * prepare for pending reset if not already (for PF software-initiated
647 * global resets the software should already be prepared for it as
648 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated
649 * by firmware or software on other PFs, that bit is not set so prepare
650 * for the reset now), poll for reset done, rebuild and return.
652 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) {
653 /* Perform the largest reset requested */
654 if (test_and_clear_bit(ICE_CORER_RECV, pf->state))
655 reset_type = ICE_RESET_CORER;
656 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state))
657 reset_type = ICE_RESET_GLOBR;
658 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state))
659 reset_type = ICE_RESET_EMPR;
660 /* return if no valid reset type requested */
661 if (reset_type == ICE_RESET_INVAL)
663 ice_prepare_for_reset(pf, reset_type);
665 /* make sure we are ready to rebuild */
666 if (ice_check_reset(&pf->hw)) {
667 set_bit(ICE_RESET_FAILED, pf->state);
669 /* done with reset. start rebuild */
670 pf->hw.reset_ongoing = false;
671 ice_rebuild(pf, reset_type);
672 /* clear bit to resume normal operations, but
673 * ICE_NEEDS_RESTART bit is set in case rebuild failed
675 clear_bit(ICE_RESET_OICR_RECV, pf->state);
676 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
677 clear_bit(ICE_PFR_REQ, pf->state);
678 clear_bit(ICE_CORER_REQ, pf->state);
679 clear_bit(ICE_GLOBR_REQ, pf->state);
680 wake_up(&pf->reset_wait_queue);
681 ice_reset_all_vfs(pf);
687 /* No pending resets to finish processing. Check for new resets */
688 if (test_bit(ICE_PFR_REQ, pf->state))
689 reset_type = ICE_RESET_PFR;
690 if (test_bit(ICE_CORER_REQ, pf->state))
691 reset_type = ICE_RESET_CORER;
692 if (test_bit(ICE_GLOBR_REQ, pf->state))
693 reset_type = ICE_RESET_GLOBR;
694 /* If no valid reset type requested just return */
695 if (reset_type == ICE_RESET_INVAL)
698 /* reset if not already down or busy */
699 if (!test_bit(ICE_DOWN, pf->state) &&
700 !test_bit(ICE_CFG_BUSY, pf->state)) {
701 ice_do_reset(pf, reset_type);
706 * ice_print_topo_conflict - print topology conflict message
707 * @vsi: the VSI whose topology status is being checked
709 static void ice_print_topo_conflict(struct ice_vsi *vsi)
711 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
712 case ICE_AQ_LINK_TOPO_CONFLICT:
713 case ICE_AQ_LINK_MEDIA_CONFLICT:
714 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
715 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
716 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
717 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");
719 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
720 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, vsi->back->flags))
721 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");
723 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");
731 * ice_print_link_msg - print link up or down message
732 * @vsi: the VSI whose link status is being queried
733 * @isup: boolean for if the link is now up or down
735 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
737 struct ice_aqc_get_phy_caps_data *caps;
738 const char *an_advertised;
749 if (vsi->current_isup == isup)
752 vsi->current_isup = isup;
755 netdev_info(vsi->netdev, "NIC Link is Down\n");
759 switch (vsi->port_info->phy.link_info.link_speed) {
760 case ICE_AQ_LINK_SPEED_100GB:
763 case ICE_AQ_LINK_SPEED_50GB:
766 case ICE_AQ_LINK_SPEED_40GB:
769 case ICE_AQ_LINK_SPEED_25GB:
772 case ICE_AQ_LINK_SPEED_20GB:
775 case ICE_AQ_LINK_SPEED_10GB:
778 case ICE_AQ_LINK_SPEED_5GB:
781 case ICE_AQ_LINK_SPEED_2500MB:
784 case ICE_AQ_LINK_SPEED_1000MB:
787 case ICE_AQ_LINK_SPEED_100MB:
795 switch (vsi->port_info->fc.current_mode) {
799 case ICE_FC_TX_PAUSE:
802 case ICE_FC_RX_PAUSE:
813 /* Get FEC mode based on negotiated link info */
814 switch (vsi->port_info->phy.link_info.fec_info) {
815 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
816 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
819 case ICE_AQ_LINK_25G_KR_FEC_EN:
820 fec = "FC-FEC/BASE-R";
827 /* check if autoneg completed, might be false due to not supported */
828 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
833 /* Get FEC mode requested based on PHY caps last SW configuration */
834 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
837 an_advertised = "Unknown";
841 status = ice_aq_get_phy_caps(vsi->port_info, false,
842 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
844 netdev_info(vsi->netdev, "Get phy capability failed.\n");
846 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off";
848 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
849 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
851 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
852 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
853 fec_req = "FC-FEC/BASE-R";
860 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",
861 speed, fec_req, fec, an_advertised, an, fc);
862 ice_print_topo_conflict(vsi);
866 * ice_vsi_link_event - update the VSI's netdev
867 * @vsi: the VSI on which the link event occurred
868 * @link_up: whether or not the VSI needs to be set up or down
870 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
875 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev)
878 if (vsi->type == ICE_VSI_PF) {
879 if (link_up == netif_carrier_ok(vsi->netdev))
883 netif_carrier_on(vsi->netdev);
884 netif_tx_wake_all_queues(vsi->netdev);
886 netif_carrier_off(vsi->netdev);
887 netif_tx_stop_all_queues(vsi->netdev);
893 * ice_set_dflt_mib - send a default config MIB to the FW
894 * @pf: private PF struct
896 * This function sends a default configuration MIB to the FW.
898 * If this function errors out at any point, the driver is still able to
899 * function. The main impact is that LFC may not operate as expected.
900 * Therefore an error state in this function should be treated with a DBG
901 * message and continue on with driver rebuild/reenable.
903 static void ice_set_dflt_mib(struct ice_pf *pf)
905 struct device *dev = ice_pf_to_dev(pf);
906 u8 mib_type, *buf, *lldpmib = NULL;
907 u16 len, typelen, offset = 0;
908 struct ice_lldp_org_tlv *tlv;
909 struct ice_hw *hw = &pf->hw;
912 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
913 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
915 dev_dbg(dev, "%s Failed to allocate MIB memory\n",
920 /* Add ETS CFG TLV */
921 tlv = (struct ice_lldp_org_tlv *)lldpmib;
922 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
923 ICE_IEEE_ETS_TLV_LEN);
924 tlv->typelen = htons(typelen);
925 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
926 ICE_IEEE_SUBTYPE_ETS_CFG);
927 tlv->ouisubtype = htonl(ouisubtype);
932 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0.
933 * Octets 5 - 12 are BW values, set octet 5 to 100% BW.
934 * Octets 13 - 20 are TSA values - leave as zeros
937 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
939 tlv = (struct ice_lldp_org_tlv *)
940 ((char *)tlv + sizeof(tlv->typelen) + len);
942 /* Add ETS REC TLV */
944 tlv->typelen = htons(typelen);
946 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
947 ICE_IEEE_SUBTYPE_ETS_REC);
948 tlv->ouisubtype = htonl(ouisubtype);
950 /* First octet of buf is reserved
951 * Octets 1 - 4 map UP to TC - all UPs map to zero
952 * Octets 5 - 12 are BW values - set TC 0 to 100%.
953 * Octets 13 - 20 are TSA value - leave as zeros
957 tlv = (struct ice_lldp_org_tlv *)
958 ((char *)tlv + sizeof(tlv->typelen) + len);
960 /* Add PFC CFG TLV */
961 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
962 ICE_IEEE_PFC_TLV_LEN);
963 tlv->typelen = htons(typelen);
965 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
966 ICE_IEEE_SUBTYPE_PFC_CFG);
967 tlv->ouisubtype = htonl(ouisubtype);
969 /* Octet 1 left as all zeros - PFC disabled */
971 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
974 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL))
975 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__);
981 * ice_check_phy_fw_load - check if PHY FW load failed
982 * @pf: pointer to PF struct
983 * @link_cfg_err: bitmap from the link info structure
985 * check if external PHY FW load failed and print an error message if it did
987 static void ice_check_phy_fw_load(struct ice_pf *pf, u8 link_cfg_err)
989 if (!(link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE)) {
990 clear_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
994 if (test_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags))
997 if (link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE) {
998 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");
999 set_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
1004 * ice_check_module_power
1005 * @pf: pointer to PF struct
1006 * @link_cfg_err: bitmap from the link info structure
1008 * check module power level returned by a previous call to aq_get_link_info
1009 * and print error messages if module power level is not supported
1011 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err)
1013 /* if module power level is supported, clear the flag */
1014 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT |
1015 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) {
1016 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1020 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the
1021 * above block didn't clear this bit, there's nothing to do
1023 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags))
1026 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) {
1027 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n");
1028 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1029 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) {
1030 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n");
1031 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1036 * ice_check_link_cfg_err - check if link configuration failed
1037 * @pf: pointer to the PF struct
1038 * @link_cfg_err: bitmap from the link info structure
1040 * print if any link configuration failure happens due to the value in the
1041 * link_cfg_err parameter in the link info structure
1043 static void ice_check_link_cfg_err(struct ice_pf *pf, u8 link_cfg_err)
1045 ice_check_module_power(pf, link_cfg_err);
1046 ice_check_phy_fw_load(pf, link_cfg_err);
1050 * ice_link_event - process the link event
1051 * @pf: PF that the link event is associated with
1052 * @pi: port_info for the port that the link event is associated with
1053 * @link_up: true if the physical link is up and false if it is down
1054 * @link_speed: current link speed received from the link event
1056 * Returns 0 on success and negative on failure
1059 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
1062 struct device *dev = ice_pf_to_dev(pf);
1063 struct ice_phy_info *phy_info;
1064 struct ice_vsi *vsi;
1069 phy_info = &pi->phy;
1070 phy_info->link_info_old = phy_info->link_info;
1072 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
1073 old_link_speed = phy_info->link_info_old.link_speed;
1075 /* update the link info structures and re-enable link events,
1076 * don't bail on failure due to other book keeping needed
1078 status = ice_update_link_info(pi);
1080 dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n",
1082 ice_aq_str(pi->hw->adminq.sq_last_status));
1084 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
1086 /* Check if the link state is up after updating link info, and treat
1087 * this event as an UP event since the link is actually UP now.
1089 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
1092 vsi = ice_get_main_vsi(pf);
1093 if (!vsi || !vsi->port_info)
1096 /* turn off PHY if media was removed */
1097 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
1098 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
1099 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1100 ice_set_link(vsi, false);
1103 /* if the old link up/down and speed is the same as the new */
1104 if (link_up == old_link && link_speed == old_link_speed)
1107 if (!ice_is_e810(&pf->hw))
1108 ice_ptp_link_change(pf, pf->hw.pf_id, link_up);
1110 if (ice_is_dcb_active(pf)) {
1111 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
1112 ice_dcb_rebuild(pf);
1115 ice_set_dflt_mib(pf);
1117 ice_vsi_link_event(vsi, link_up);
1118 ice_print_link_msg(vsi, link_up);
1120 ice_vc_notify_link_state(pf);
1126 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
1127 * @pf: board private structure
1129 static void ice_watchdog_subtask(struct ice_pf *pf)
1133 /* if interface is down do nothing */
1134 if (test_bit(ICE_DOWN, pf->state) ||
1135 test_bit(ICE_CFG_BUSY, pf->state))
1138 /* make sure we don't do these things too often */
1139 if (time_before(jiffies,
1140 pf->serv_tmr_prev + pf->serv_tmr_period))
1143 pf->serv_tmr_prev = jiffies;
1145 /* Update the stats for active netdevs so the network stack
1146 * can look at updated numbers whenever it cares to
1148 ice_update_pf_stats(pf);
1149 ice_for_each_vsi(pf, i)
1150 if (pf->vsi[i] && pf->vsi[i]->netdev)
1151 ice_update_vsi_stats(pf->vsi[i]);
1155 * ice_init_link_events - enable/initialize link events
1156 * @pi: pointer to the port_info instance
1158 * Returns -EIO on failure, 0 on success
1160 static int ice_init_link_events(struct ice_port_info *pi)
1164 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
1165 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL |
1166 ICE_AQ_LINK_EVENT_PHY_FW_LOAD_FAIL));
1168 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
1169 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
1174 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
1175 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
1184 * ice_handle_link_event - handle link event via ARQ
1185 * @pf: PF that the link event is associated with
1186 * @event: event structure containing link status info
1189 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1191 struct ice_aqc_get_link_status_data *link_data;
1192 struct ice_port_info *port_info;
1195 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
1196 port_info = pf->hw.port_info;
1200 status = ice_link_event(pf, port_info,
1201 !!(link_data->link_info & ICE_AQ_LINK_UP),
1202 le16_to_cpu(link_data->link_speed));
1204 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
1210 enum ice_aq_task_state {
1211 ICE_AQ_TASK_WAITING = 0,
1212 ICE_AQ_TASK_COMPLETE,
1213 ICE_AQ_TASK_CANCELED,
1216 struct ice_aq_task {
1217 struct hlist_node entry;
1220 struct ice_rq_event_info *event;
1221 enum ice_aq_task_state state;
1225 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1226 * @pf: pointer to the PF private structure
1227 * @opcode: the opcode to wait for
1228 * @timeout: how long to wait, in jiffies
1229 * @event: storage for the event info
1231 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1232 * current thread will be put to sleep until the specified event occurs or
1233 * until the given timeout is reached.
1235 * To obtain only the descriptor contents, pass an event without an allocated
1236 * msg_buf. If the complete data buffer is desired, allocate the
1237 * event->msg_buf with enough space ahead of time.
1239 * Returns: zero on success, or a negative error code on failure.
1241 int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout,
1242 struct ice_rq_event_info *event)
1244 struct device *dev = ice_pf_to_dev(pf);
1245 struct ice_aq_task *task;
1246 unsigned long start;
1250 task = kzalloc(sizeof(*task), GFP_KERNEL);
1254 INIT_HLIST_NODE(&task->entry);
1255 task->opcode = opcode;
1256 task->event = event;
1257 task->state = ICE_AQ_TASK_WAITING;
1259 spin_lock_bh(&pf->aq_wait_lock);
1260 hlist_add_head(&task->entry, &pf->aq_wait_list);
1261 spin_unlock_bh(&pf->aq_wait_lock);
1265 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state,
1267 switch (task->state) {
1268 case ICE_AQ_TASK_WAITING:
1269 err = ret < 0 ? ret : -ETIMEDOUT;
1271 case ICE_AQ_TASK_CANCELED:
1272 err = ret < 0 ? ret : -ECANCELED;
1274 case ICE_AQ_TASK_COMPLETE:
1275 err = ret < 0 ? ret : 0;
1278 WARN(1, "Unexpected AdminQ wait task state %u", task->state);
1283 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n",
1284 jiffies_to_msecs(jiffies - start),
1285 jiffies_to_msecs(timeout),
1288 spin_lock_bh(&pf->aq_wait_lock);
1289 hlist_del(&task->entry);
1290 spin_unlock_bh(&pf->aq_wait_lock);
1297 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event
1298 * @pf: pointer to the PF private structure
1299 * @opcode: the opcode of the event
1300 * @event: the event to check
1302 * Loops over the current list of pending threads waiting for an AdminQ event.
1303 * For each matching task, copy the contents of the event into the task
1304 * structure and wake up the thread.
1306 * If multiple threads wait for the same opcode, they will all be woken up.
1308 * Note that event->msg_buf will only be duplicated if the event has a buffer
1309 * with enough space already allocated. Otherwise, only the descriptor and
1310 * message length will be copied.
1312 * Returns: true if an event was found, false otherwise
1314 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1315 struct ice_rq_event_info *event)
1317 struct ice_aq_task *task;
1320 spin_lock_bh(&pf->aq_wait_lock);
1321 hlist_for_each_entry(task, &pf->aq_wait_list, entry) {
1322 if (task->state || task->opcode != opcode)
1325 memcpy(&task->event->desc, &event->desc, sizeof(event->desc));
1326 task->event->msg_len = event->msg_len;
1328 /* Only copy the data buffer if a destination was set */
1329 if (task->event->msg_buf &&
1330 task->event->buf_len > event->buf_len) {
1331 memcpy(task->event->msg_buf, event->msg_buf,
1333 task->event->buf_len = event->buf_len;
1336 task->state = ICE_AQ_TASK_COMPLETE;
1339 spin_unlock_bh(&pf->aq_wait_lock);
1342 wake_up(&pf->aq_wait_queue);
1346 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks
1347 * @pf: the PF private structure
1349 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads.
1350 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED.
1352 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
1354 struct ice_aq_task *task;
1356 spin_lock_bh(&pf->aq_wait_lock);
1357 hlist_for_each_entry(task, &pf->aq_wait_list, entry)
1358 task->state = ICE_AQ_TASK_CANCELED;
1359 spin_unlock_bh(&pf->aq_wait_lock);
1361 wake_up(&pf->aq_wait_queue);
1365 * __ice_clean_ctrlq - helper function to clean controlq rings
1366 * @pf: ptr to struct ice_pf
1367 * @q_type: specific Control queue type
1369 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
1371 struct device *dev = ice_pf_to_dev(pf);
1372 struct ice_rq_event_info event;
1373 struct ice_hw *hw = &pf->hw;
1374 struct ice_ctl_q_info *cq;
1379 /* Do not clean control queue if/when PF reset fails */
1380 if (test_bit(ICE_RESET_FAILED, pf->state))
1384 case ICE_CTL_Q_ADMIN:
1392 case ICE_CTL_Q_MAILBOX:
1395 /* we are going to try to detect a malicious VF, so set the
1396 * state to begin detection
1398 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT;
1401 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
1405 /* check for error indications - PF_xx_AxQLEN register layout for
1406 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
1408 val = rd32(hw, cq->rq.len);
1409 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1410 PF_FW_ARQLEN_ARQCRIT_M)) {
1412 if (val & PF_FW_ARQLEN_ARQVFE_M)
1413 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
1415 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1416 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
1419 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1420 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
1422 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1423 PF_FW_ARQLEN_ARQCRIT_M);
1425 wr32(hw, cq->rq.len, val);
1428 val = rd32(hw, cq->sq.len);
1429 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1430 PF_FW_ATQLEN_ATQCRIT_M)) {
1432 if (val & PF_FW_ATQLEN_ATQVFE_M)
1433 dev_dbg(dev, "%s Send Queue VF Error detected\n",
1435 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1436 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1439 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1440 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1442 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1443 PF_FW_ATQLEN_ATQCRIT_M);
1445 wr32(hw, cq->sq.len, val);
1448 event.buf_len = cq->rq_buf_size;
1449 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1457 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1458 if (ret == -EALREADY)
1461 dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1466 opcode = le16_to_cpu(event.desc.opcode);
1468 /* Notify any thread that might be waiting for this event */
1469 ice_aq_check_events(pf, opcode, &event);
1472 case ice_aqc_opc_get_link_status:
1473 if (ice_handle_link_event(pf, &event))
1474 dev_err(dev, "Could not handle link event\n");
1476 case ice_aqc_opc_event_lan_overflow:
1477 ice_vf_lan_overflow_event(pf, &event);
1479 case ice_mbx_opc_send_msg_to_pf:
1480 if (!ice_is_malicious_vf(pf, &event, i, pending))
1481 ice_vc_process_vf_msg(pf, &event);
1483 case ice_aqc_opc_fw_logging:
1484 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1486 case ice_aqc_opc_lldp_set_mib_change:
1487 ice_dcb_process_lldp_set_mib_change(pf, &event);
1490 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1494 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1496 kfree(event.msg_buf);
1498 return pending && (i == ICE_DFLT_IRQ_WORK);
1502 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1503 * @hw: pointer to hardware info
1504 * @cq: control queue information
1506 * returns true if there are pending messages in a queue, false if there aren't
1508 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1512 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1513 return cq->rq.next_to_clean != ntu;
1517 * ice_clean_adminq_subtask - clean the AdminQ rings
1518 * @pf: board private structure
1520 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1522 struct ice_hw *hw = &pf->hw;
1524 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
1527 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1530 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
1532 /* There might be a situation where new messages arrive to a control
1533 * queue between processing the last message and clearing the
1534 * EVENT_PENDING bit. So before exiting, check queue head again (using
1535 * ice_ctrlq_pending) and process new messages if any.
1537 if (ice_ctrlq_pending(hw, &hw->adminq))
1538 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1544 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1545 * @pf: board private structure
1547 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1549 struct ice_hw *hw = &pf->hw;
1551 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1554 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1557 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1559 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1560 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1566 * ice_clean_sbq_subtask - clean the Sideband Queue rings
1567 * @pf: board private structure
1569 static void ice_clean_sbq_subtask(struct ice_pf *pf)
1571 struct ice_hw *hw = &pf->hw;
1573 /* Nothing to do here if sideband queue is not supported */
1574 if (!ice_is_sbq_supported(hw)) {
1575 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1579 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state))
1582 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB))
1585 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1587 if (ice_ctrlq_pending(hw, &hw->sbq))
1588 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB);
1594 * ice_service_task_schedule - schedule the service task to wake up
1595 * @pf: board private structure
1597 * If not already scheduled, this puts the task into the work queue.
1599 void ice_service_task_schedule(struct ice_pf *pf)
1601 if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
1602 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
1603 !test_bit(ICE_NEEDS_RESTART, pf->state))
1604 queue_work(ice_wq, &pf->serv_task);
1608 * ice_service_task_complete - finish up the service task
1609 * @pf: board private structure
1611 static void ice_service_task_complete(struct ice_pf *pf)
1613 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state));
1615 /* force memory (pf->state) to sync before next service task */
1616 smp_mb__before_atomic();
1617 clear_bit(ICE_SERVICE_SCHED, pf->state);
1621 * ice_service_task_stop - stop service task and cancel works
1622 * @pf: board private structure
1624 * Return 0 if the ICE_SERVICE_DIS bit was not already set,
1627 static int ice_service_task_stop(struct ice_pf *pf)
1631 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state);
1633 if (pf->serv_tmr.function)
1634 del_timer_sync(&pf->serv_tmr);
1635 if (pf->serv_task.func)
1636 cancel_work_sync(&pf->serv_task);
1638 clear_bit(ICE_SERVICE_SCHED, pf->state);
1643 * ice_service_task_restart - restart service task and schedule works
1644 * @pf: board private structure
1646 * This function is needed for suspend and resume works (e.g WoL scenario)
1648 static void ice_service_task_restart(struct ice_pf *pf)
1650 clear_bit(ICE_SERVICE_DIS, pf->state);
1651 ice_service_task_schedule(pf);
1655 * ice_service_timer - timer callback to schedule service task
1656 * @t: pointer to timer_list
1658 static void ice_service_timer(struct timer_list *t)
1660 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1662 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1663 ice_service_task_schedule(pf);
1667 * ice_handle_mdd_event - handle malicious driver detect event
1668 * @pf: pointer to the PF structure
1670 * Called from service task. OICR interrupt handler indicates MDD event.
1671 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1672 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1673 * disable the queue, the PF can be configured to reset the VF using ethtool
1674 * private flag mdd-auto-reset-vf.
1676 static void ice_handle_mdd_event(struct ice_pf *pf)
1678 struct device *dev = ice_pf_to_dev(pf);
1679 struct ice_hw *hw = &pf->hw;
1684 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
1685 /* Since the VF MDD event logging is rate limited, check if
1686 * there are pending MDD events.
1688 ice_print_vfs_mdd_events(pf);
1692 /* find what triggered an MDD event */
1693 reg = rd32(hw, GL_MDET_TX_PQM);
1694 if (reg & GL_MDET_TX_PQM_VALID_M) {
1695 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1696 GL_MDET_TX_PQM_PF_NUM_S;
1697 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1698 GL_MDET_TX_PQM_VF_NUM_S;
1699 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1700 GL_MDET_TX_PQM_MAL_TYPE_S;
1701 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1702 GL_MDET_TX_PQM_QNUM_S);
1704 if (netif_msg_tx_err(pf))
1705 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1706 event, queue, pf_num, vf_num);
1707 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1710 reg = rd32(hw, GL_MDET_TX_TCLAN);
1711 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1712 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1713 GL_MDET_TX_TCLAN_PF_NUM_S;
1714 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1715 GL_MDET_TX_TCLAN_VF_NUM_S;
1716 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1717 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1718 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1719 GL_MDET_TX_TCLAN_QNUM_S);
1721 if (netif_msg_tx_err(pf))
1722 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1723 event, queue, pf_num, vf_num);
1724 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1727 reg = rd32(hw, GL_MDET_RX);
1728 if (reg & GL_MDET_RX_VALID_M) {
1729 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1730 GL_MDET_RX_PF_NUM_S;
1731 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1732 GL_MDET_RX_VF_NUM_S;
1733 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1734 GL_MDET_RX_MAL_TYPE_S;
1735 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1738 if (netif_msg_rx_err(pf))
1739 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1740 event, queue, pf_num, vf_num);
1741 wr32(hw, GL_MDET_RX, 0xffffffff);
1744 /* check to see if this PF caused an MDD event */
1745 reg = rd32(hw, PF_MDET_TX_PQM);
1746 if (reg & PF_MDET_TX_PQM_VALID_M) {
1747 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1748 if (netif_msg_tx_err(pf))
1749 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1752 reg = rd32(hw, PF_MDET_TX_TCLAN);
1753 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1754 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1755 if (netif_msg_tx_err(pf))
1756 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1759 reg = rd32(hw, PF_MDET_RX);
1760 if (reg & PF_MDET_RX_VALID_M) {
1761 wr32(hw, PF_MDET_RX, 0xFFFF);
1762 if (netif_msg_rx_err(pf))
1763 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1766 /* Check to see if one of the VFs caused an MDD event, and then
1767 * increment counters and set print pending
1769 mutex_lock(&pf->vfs.table_lock);
1770 ice_for_each_vf(pf, bkt, vf) {
1771 reg = rd32(hw, VP_MDET_TX_PQM(vf->vf_id));
1772 if (reg & VP_MDET_TX_PQM_VALID_M) {
1773 wr32(hw, VP_MDET_TX_PQM(vf->vf_id), 0xFFFF);
1774 vf->mdd_tx_events.count++;
1775 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1776 if (netif_msg_tx_err(pf))
1777 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1781 reg = rd32(hw, VP_MDET_TX_TCLAN(vf->vf_id));
1782 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1783 wr32(hw, VP_MDET_TX_TCLAN(vf->vf_id), 0xFFFF);
1784 vf->mdd_tx_events.count++;
1785 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1786 if (netif_msg_tx_err(pf))
1787 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1791 reg = rd32(hw, VP_MDET_TX_TDPU(vf->vf_id));
1792 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1793 wr32(hw, VP_MDET_TX_TDPU(vf->vf_id), 0xFFFF);
1794 vf->mdd_tx_events.count++;
1795 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1796 if (netif_msg_tx_err(pf))
1797 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1801 reg = rd32(hw, VP_MDET_RX(vf->vf_id));
1802 if (reg & VP_MDET_RX_VALID_M) {
1803 wr32(hw, VP_MDET_RX(vf->vf_id), 0xFFFF);
1804 vf->mdd_rx_events.count++;
1805 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1806 if (netif_msg_rx_err(pf))
1807 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1810 /* Since the queue is disabled on VF Rx MDD events, the
1811 * PF can be configured to reset the VF through ethtool
1812 * private flag mdd-auto-reset-vf.
1814 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) {
1815 /* VF MDD event counters will be cleared by
1816 * reset, so print the event prior to reset.
1818 ice_print_vf_rx_mdd_event(vf);
1819 ice_reset_vf(vf, ICE_VF_RESET_LOCK);
1823 mutex_unlock(&pf->vfs.table_lock);
1825 ice_print_vfs_mdd_events(pf);
1829 * ice_force_phys_link_state - Force the physical link state
1830 * @vsi: VSI to force the physical link state to up/down
1831 * @link_up: true/false indicates to set the physical link to up/down
1833 * Force the physical link state by getting the current PHY capabilities from
1834 * hardware and setting the PHY config based on the determined capabilities. If
1835 * link changes a link event will be triggered because both the Enable Automatic
1836 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1838 * Returns 0 on success, negative on failure
1840 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1842 struct ice_aqc_get_phy_caps_data *pcaps;
1843 struct ice_aqc_set_phy_cfg_data *cfg;
1844 struct ice_port_info *pi;
1848 if (!vsi || !vsi->port_info || !vsi->back)
1850 if (vsi->type != ICE_VSI_PF)
1853 dev = ice_pf_to_dev(vsi->back);
1855 pi = vsi->port_info;
1857 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1861 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1864 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1865 vsi->vsi_num, retcode);
1870 /* No change in link */
1871 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1872 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1875 /* Use the current user PHY configuration. The current user PHY
1876 * configuration is initialized during probe from PHY capabilities
1877 * software mode, and updated on set PHY configuration.
1879 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL);
1885 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1887 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1889 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1891 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL);
1893 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1894 vsi->vsi_num, retcode);
1905 * ice_init_nvm_phy_type - Initialize the NVM PHY type
1906 * @pi: port info structure
1908 * Initialize nvm_phy_type_[low|high] for link lenient mode support
1910 static int ice_init_nvm_phy_type(struct ice_port_info *pi)
1912 struct ice_aqc_get_phy_caps_data *pcaps;
1913 struct ice_pf *pf = pi->hw->back;
1916 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1920 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA,
1924 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
1928 pf->nvm_phy_type_hi = pcaps->phy_type_high;
1929 pf->nvm_phy_type_lo = pcaps->phy_type_low;
1937 * ice_init_link_dflt_override - Initialize link default override
1938 * @pi: port info structure
1940 * Initialize link default override and PHY total port shutdown during probe
1942 static void ice_init_link_dflt_override(struct ice_port_info *pi)
1944 struct ice_link_default_override_tlv *ldo;
1945 struct ice_pf *pf = pi->hw->back;
1947 ldo = &pf->link_dflt_override;
1948 if (ice_get_link_default_override(ldo, pi))
1951 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS))
1954 /* Enable Total Port Shutdown (override/replace link-down-on-close
1955 * ethtool private flag) for ports with Port Disable bit set.
1957 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags);
1958 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1962 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings
1963 * @pi: port info structure
1965 * If default override is enabled, initialize the user PHY cfg speed and FEC
1966 * settings using the default override mask from the NVM.
1968 * The PHY should only be configured with the default override settings the
1969 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state
1970 * is used to indicate that the user PHY cfg default override is initialized
1971 * and the PHY has not been configured with the default override settings. The
1972 * state is set here, and cleared in ice_configure_phy the first time the PHY is
1975 * This function should be called only if the FW doesn't support default
1976 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg.
1978 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi)
1980 struct ice_link_default_override_tlv *ldo;
1981 struct ice_aqc_set_phy_cfg_data *cfg;
1982 struct ice_phy_info *phy = &pi->phy;
1983 struct ice_pf *pf = pi->hw->back;
1985 ldo = &pf->link_dflt_override;
1987 /* If link default override is enabled, use to mask NVM PHY capabilities
1988 * for speed and FEC default configuration.
1990 cfg = &phy->curr_user_phy_cfg;
1992 if (ldo->phy_type_low || ldo->phy_type_high) {
1993 cfg->phy_type_low = pf->nvm_phy_type_lo &
1994 cpu_to_le64(ldo->phy_type_low);
1995 cfg->phy_type_high = pf->nvm_phy_type_hi &
1996 cpu_to_le64(ldo->phy_type_high);
1998 cfg->link_fec_opt = ldo->fec_options;
1999 phy->curr_user_fec_req = ICE_FEC_AUTO;
2001 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state);
2005 * ice_init_phy_user_cfg - Initialize the PHY user configuration
2006 * @pi: port info structure
2008 * Initialize the current user PHY configuration, speed, FEC, and FC requested
2009 * mode to default. The PHY defaults are from get PHY capabilities topology
2010 * with media so call when media is first available. An error is returned if
2011 * called when media is not available. The PHY initialization completed state is
2014 * These configurations are used when setting PHY
2015 * configuration. The user PHY configuration is updated on set PHY
2016 * configuration. Returns 0 on success, negative on failure
2018 static int ice_init_phy_user_cfg(struct ice_port_info *pi)
2020 struct ice_aqc_get_phy_caps_data *pcaps;
2021 struct ice_phy_info *phy = &pi->phy;
2022 struct ice_pf *pf = pi->hw->back;
2025 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2028 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2032 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2033 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2036 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2039 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
2043 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg);
2045 /* check if lenient mode is supported and enabled */
2046 if (ice_fw_supports_link_override(pi->hw) &&
2047 !(pcaps->module_compliance_enforcement &
2048 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) {
2049 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags);
2051 /* if the FW supports default PHY configuration mode, then the driver
2052 * does not have to apply link override settings. If not,
2053 * initialize user PHY configuration with link override values
2055 if (!ice_fw_supports_report_dflt_cfg(pi->hw) &&
2056 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) {
2057 ice_init_phy_cfg_dflt_override(pi);
2062 /* if link default override is not enabled, set user flow control and
2063 * FEC settings based on what get_phy_caps returned
2065 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps,
2066 pcaps->link_fec_options);
2067 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps);
2070 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M;
2071 set_bit(ICE_PHY_INIT_COMPLETE, pf->state);
2078 * ice_configure_phy - configure PHY
2081 * Set the PHY configuration. If the current PHY configuration is the same as
2082 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise
2083 * configure the based get PHY capabilities for topology with media.
2085 static int ice_configure_phy(struct ice_vsi *vsi)
2087 struct device *dev = ice_pf_to_dev(vsi->back);
2088 struct ice_port_info *pi = vsi->port_info;
2089 struct ice_aqc_get_phy_caps_data *pcaps;
2090 struct ice_aqc_set_phy_cfg_data *cfg;
2091 struct ice_phy_info *phy = &pi->phy;
2092 struct ice_pf *pf = vsi->back;
2095 /* Ensure we have media as we cannot configure a medialess port */
2096 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2099 ice_print_topo_conflict(vsi);
2101 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags) &&
2102 phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA)
2105 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags))
2106 return ice_force_phys_link_state(vsi, true);
2108 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2112 /* Get current PHY config */
2113 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2116 dev_err(dev, "Failed to get PHY configuration, VSI %d error %d\n",
2121 /* If PHY enable link is configured and configuration has not changed,
2122 * there's nothing to do
2124 if (pcaps->caps & ICE_AQC_PHY_EN_LINK &&
2125 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg))
2128 /* Use PHY topology as baseline for configuration */
2129 memset(pcaps, 0, sizeof(*pcaps));
2130 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2131 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2134 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2137 dev_err(dev, "Failed to get PHY caps, VSI %d error %d\n",
2142 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2148 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg);
2150 /* Speed - If default override pending, use curr_user_phy_cfg set in
2151 * ice_init_phy_user_cfg_ldo.
2153 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING,
2154 vsi->back->state)) {
2155 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low;
2156 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high;
2158 u64 phy_low = 0, phy_high = 0;
2160 ice_update_phy_type(&phy_low, &phy_high,
2161 pi->phy.curr_user_speed_req);
2162 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low);
2163 cfg->phy_type_high = pcaps->phy_type_high &
2164 cpu_to_le64(phy_high);
2167 /* Can't provide what was requested; use PHY capabilities */
2168 if (!cfg->phy_type_low && !cfg->phy_type_high) {
2169 cfg->phy_type_low = pcaps->phy_type_low;
2170 cfg->phy_type_high = pcaps->phy_type_high;
2174 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req);
2176 /* Can't provide what was requested; use PHY capabilities */
2177 if (cfg->link_fec_opt !=
2178 (cfg->link_fec_opt & pcaps->link_fec_options)) {
2179 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2180 cfg->link_fec_opt = pcaps->link_fec_options;
2183 /* Flow Control - always supported; no need to check against
2186 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req);
2188 /* Enable link and link update */
2189 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK;
2191 err = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL);
2193 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
2203 * ice_check_media_subtask - Check for media
2204 * @pf: pointer to PF struct
2206 * If media is available, then initialize PHY user configuration if it is not
2207 * been, and configure the PHY if the interface is up.
2209 static void ice_check_media_subtask(struct ice_pf *pf)
2211 struct ice_port_info *pi;
2212 struct ice_vsi *vsi;
2215 /* No need to check for media if it's already present */
2216 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags))
2219 vsi = ice_get_main_vsi(pf);
2223 /* Refresh link info and check if media is present */
2224 pi = vsi->port_info;
2225 err = ice_update_link_info(pi);
2229 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
2231 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
2232 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state))
2233 ice_init_phy_user_cfg(pi);
2235 /* PHY settings are reset on media insertion, reconfigure
2236 * PHY to preserve settings.
2238 if (test_bit(ICE_VSI_DOWN, vsi->state) &&
2239 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags))
2242 err = ice_configure_phy(vsi);
2244 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
2246 /* A Link Status Event will be generated; the event handler
2247 * will complete bringing the interface up
2253 * ice_service_task - manage and run subtasks
2254 * @work: pointer to work_struct contained by the PF struct
2256 static void ice_service_task(struct work_struct *work)
2258 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
2259 unsigned long start_time = jiffies;
2263 /* process reset requests first */
2264 ice_reset_subtask(pf);
2266 /* bail if a reset/recovery cycle is pending or rebuild failed */
2267 if (ice_is_reset_in_progress(pf->state) ||
2268 test_bit(ICE_SUSPENDED, pf->state) ||
2269 test_bit(ICE_NEEDS_RESTART, pf->state)) {
2270 ice_service_task_complete(pf);
2274 if (test_and_clear_bit(ICE_AUX_ERR_PENDING, pf->state)) {
2275 struct iidc_event *event;
2277 event = kzalloc(sizeof(*event), GFP_KERNEL);
2279 set_bit(IIDC_EVENT_CRIT_ERR, event->type);
2280 /* report the entire OICR value to AUX driver */
2281 swap(event->reg, pf->oicr_err_reg);
2282 ice_send_event_to_aux(pf, event);
2287 if (test_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags)) {
2288 /* Plug aux device per request */
2289 ice_plug_aux_dev(pf);
2291 /* Mark plugging as done but check whether unplug was
2292 * requested during ice_plug_aux_dev() call
2293 * (e.g. from ice_clear_rdma_cap()) and if so then
2296 if (!test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))
2297 ice_unplug_aux_dev(pf);
2300 if (test_and_clear_bit(ICE_FLAG_MTU_CHANGED, pf->flags)) {
2301 struct iidc_event *event;
2303 event = kzalloc(sizeof(*event), GFP_KERNEL);
2305 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);
2306 ice_send_event_to_aux(pf, event);
2311 ice_clean_adminq_subtask(pf);
2312 ice_check_media_subtask(pf);
2313 ice_check_for_hang_subtask(pf);
2314 ice_sync_fltr_subtask(pf);
2315 ice_handle_mdd_event(pf);
2316 ice_watchdog_subtask(pf);
2318 if (ice_is_safe_mode(pf)) {
2319 ice_service_task_complete(pf);
2323 ice_process_vflr_event(pf);
2324 ice_clean_mailboxq_subtask(pf);
2325 ice_clean_sbq_subtask(pf);
2326 ice_sync_arfs_fltrs(pf);
2327 ice_flush_fdir_ctx(pf);
2329 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */
2330 ice_service_task_complete(pf);
2332 /* If the tasks have taken longer than one service timer period
2333 * or there is more work to be done, reset the service timer to
2334 * schedule the service task now.
2336 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
2337 test_bit(ICE_MDD_EVENT_PENDING, pf->state) ||
2338 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) ||
2339 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
2340 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) ||
2341 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) ||
2342 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
2343 mod_timer(&pf->serv_tmr, jiffies);
2347 * ice_set_ctrlq_len - helper function to set controlq length
2348 * @hw: pointer to the HW instance
2350 static void ice_set_ctrlq_len(struct ice_hw *hw)
2352 hw->adminq.num_rq_entries = ICE_AQ_LEN;
2353 hw->adminq.num_sq_entries = ICE_AQ_LEN;
2354 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
2355 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
2356 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
2357 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
2358 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2359 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2360 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
2361 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
2362 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2363 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2367 * ice_schedule_reset - schedule a reset
2368 * @pf: board private structure
2369 * @reset: reset being requested
2371 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
2373 struct device *dev = ice_pf_to_dev(pf);
2375 /* bail out if earlier reset has failed */
2376 if (test_bit(ICE_RESET_FAILED, pf->state)) {
2377 dev_dbg(dev, "earlier reset has failed\n");
2380 /* bail if reset/recovery already in progress */
2381 if (ice_is_reset_in_progress(pf->state)) {
2382 dev_dbg(dev, "Reset already in progress\n");
2386 ice_unplug_aux_dev(pf);
2390 set_bit(ICE_PFR_REQ, pf->state);
2392 case ICE_RESET_CORER:
2393 set_bit(ICE_CORER_REQ, pf->state);
2395 case ICE_RESET_GLOBR:
2396 set_bit(ICE_GLOBR_REQ, pf->state);
2402 ice_service_task_schedule(pf);
2407 * ice_irq_affinity_notify - Callback for affinity changes
2408 * @notify: context as to what irq was changed
2409 * @mask: the new affinity mask
2411 * This is a callback function used by the irq_set_affinity_notifier function
2412 * so that we may register to receive changes to the irq affinity masks.
2415 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
2416 const cpumask_t *mask)
2418 struct ice_q_vector *q_vector =
2419 container_of(notify, struct ice_q_vector, affinity_notify);
2421 cpumask_copy(&q_vector->affinity_mask, mask);
2425 * ice_irq_affinity_release - Callback for affinity notifier release
2426 * @ref: internal core kernel usage
2428 * This is a callback function used by the irq_set_affinity_notifier function
2429 * to inform the current notification subscriber that they will no longer
2430 * receive notifications.
2432 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
2435 * ice_vsi_ena_irq - Enable IRQ for the given VSI
2436 * @vsi: the VSI being configured
2438 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
2440 struct ice_hw *hw = &vsi->back->hw;
2443 ice_for_each_q_vector(vsi, i)
2444 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
2451 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
2452 * @vsi: the VSI being configured
2453 * @basename: name for the vector
2455 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
2457 int q_vectors = vsi->num_q_vectors;
2458 struct ice_pf *pf = vsi->back;
2459 int base = vsi->base_vector;
2466 dev = ice_pf_to_dev(pf);
2467 for (vector = 0; vector < q_vectors; vector++) {
2468 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
2470 irq_num = pf->msix_entries[base + vector].vector;
2472 if (q_vector->tx.tx_ring && q_vector->rx.rx_ring) {
2473 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2474 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2476 } else if (q_vector->rx.rx_ring) {
2477 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2478 "%s-%s-%d", basename, "rx", rx_int_idx++);
2479 } else if (q_vector->tx.tx_ring) {
2480 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2481 "%s-%s-%d", basename, "tx", tx_int_idx++);
2483 /* skip this unused q_vector */
2486 if (vsi->type == ICE_VSI_CTRL && vsi->vf)
2487 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2488 IRQF_SHARED, q_vector->name,
2491 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2492 0, q_vector->name, q_vector);
2494 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
2499 /* register for affinity change notifications */
2500 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
2501 struct irq_affinity_notify *affinity_notify;
2503 affinity_notify = &q_vector->affinity_notify;
2504 affinity_notify->notify = ice_irq_affinity_notify;
2505 affinity_notify->release = ice_irq_affinity_release;
2506 irq_set_affinity_notifier(irq_num, affinity_notify);
2509 /* assign the mask for this irq */
2510 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
2513 vsi->irqs_ready = true;
2519 irq_num = pf->msix_entries[base + vector].vector;
2520 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2521 irq_set_affinity_notifier(irq_num, NULL);
2522 irq_set_affinity_hint(irq_num, NULL);
2523 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
2529 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
2530 * @vsi: VSI to setup Tx rings used by XDP
2532 * Return 0 on success and negative value on error
2534 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
2536 struct device *dev = ice_pf_to_dev(vsi->back);
2537 struct ice_tx_desc *tx_desc;
2540 ice_for_each_xdp_txq(vsi, i) {
2541 u16 xdp_q_idx = vsi->alloc_txq + i;
2542 struct ice_tx_ring *xdp_ring;
2544 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
2547 goto free_xdp_rings;
2549 xdp_ring->q_index = xdp_q_idx;
2550 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
2551 xdp_ring->vsi = vsi;
2552 xdp_ring->netdev = NULL;
2553 xdp_ring->dev = dev;
2554 xdp_ring->count = vsi->num_tx_desc;
2555 xdp_ring->next_dd = ICE_RING_QUARTER(xdp_ring) - 1;
2556 xdp_ring->next_rs = ICE_RING_QUARTER(xdp_ring) - 1;
2557 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring);
2558 if (ice_setup_tx_ring(xdp_ring))
2559 goto free_xdp_rings;
2560 ice_set_ring_xdp(xdp_ring);
2561 xdp_ring->xsk_pool = ice_tx_xsk_pool(xdp_ring);
2562 spin_lock_init(&xdp_ring->tx_lock);
2563 for (j = 0; j < xdp_ring->count; j++) {
2564 tx_desc = ICE_TX_DESC(xdp_ring, j);
2565 tx_desc->cmd_type_offset_bsz = 0;
2569 ice_for_each_rxq(vsi, i) {
2570 if (static_key_enabled(&ice_xdp_locking_key))
2571 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i % vsi->num_xdp_txq];
2573 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i];
2580 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2581 ice_free_tx_ring(vsi->xdp_rings[i]);
2586 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
2587 * @vsi: VSI to set the bpf prog on
2588 * @prog: the bpf prog pointer
2590 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
2592 struct bpf_prog *old_prog;
2595 old_prog = xchg(&vsi->xdp_prog, prog);
2597 bpf_prog_put(old_prog);
2599 ice_for_each_rxq(vsi, i)
2600 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
2604 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
2605 * @vsi: VSI to bring up Tx rings used by XDP
2606 * @prog: bpf program that will be assigned to VSI
2608 * Return 0 on success and negative value on error
2610 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
2612 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2613 int xdp_rings_rem = vsi->num_xdp_txq;
2614 struct ice_pf *pf = vsi->back;
2615 struct ice_qs_cfg xdp_qs_cfg = {
2616 .qs_mutex = &pf->avail_q_mutex,
2617 .pf_map = pf->avail_txqs,
2618 .pf_map_size = pf->max_pf_txqs,
2619 .q_count = vsi->num_xdp_txq,
2620 .scatter_count = ICE_MAX_SCATTER_TXQS,
2621 .vsi_map = vsi->txq_map,
2622 .vsi_map_offset = vsi->alloc_txq,
2623 .mapping_mode = ICE_VSI_MAP_CONTIG
2629 dev = ice_pf_to_dev(pf);
2630 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
2631 sizeof(*vsi->xdp_rings), GFP_KERNEL);
2632 if (!vsi->xdp_rings)
2635 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
2636 if (__ice_vsi_get_qs(&xdp_qs_cfg))
2639 if (static_key_enabled(&ice_xdp_locking_key))
2640 netdev_warn(vsi->netdev,
2641 "Could not allocate one XDP Tx ring per CPU, XDP_TX/XDP_REDIRECT actions will be slower\n");
2643 if (ice_xdp_alloc_setup_rings(vsi))
2644 goto clear_xdp_rings;
2646 /* follow the logic from ice_vsi_map_rings_to_vectors */
2647 ice_for_each_q_vector(vsi, v_idx) {
2648 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2649 int xdp_rings_per_v, q_id, q_base;
2651 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
2652 vsi->num_q_vectors - v_idx);
2653 q_base = vsi->num_xdp_txq - xdp_rings_rem;
2655 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
2656 struct ice_tx_ring *xdp_ring = vsi->xdp_rings[q_id];
2658 xdp_ring->q_vector = q_vector;
2659 xdp_ring->next = q_vector->tx.tx_ring;
2660 q_vector->tx.tx_ring = xdp_ring;
2662 xdp_rings_rem -= xdp_rings_per_v;
2665 /* omit the scheduler update if in reset path; XDP queues will be
2666 * taken into account at the end of ice_vsi_rebuild, where
2667 * ice_cfg_vsi_lan is being called
2669 if (ice_is_reset_in_progress(pf->state))
2672 /* tell the Tx scheduler that right now we have
2675 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2676 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
2678 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2681 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %d\n",
2683 goto clear_xdp_rings;
2686 /* assign the prog only when it's not already present on VSI;
2687 * this flow is a subject of both ethtool -L and ndo_bpf flows;
2688 * VSI rebuild that happens under ethtool -L can expose us to
2689 * the bpf_prog refcount issues as we would be swapping same
2690 * bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put
2691 * on it as it would be treated as an 'old_prog'; for ndo_bpf
2692 * this is not harmful as dev_xdp_install bumps the refcount
2693 * before calling the op exposed by the driver;
2695 if (!ice_is_xdp_ena_vsi(vsi))
2696 ice_vsi_assign_bpf_prog(vsi, prog);
2700 ice_for_each_xdp_txq(vsi, i)
2701 if (vsi->xdp_rings[i]) {
2702 kfree_rcu(vsi->xdp_rings[i], rcu);
2703 vsi->xdp_rings[i] = NULL;
2707 mutex_lock(&pf->avail_q_mutex);
2708 ice_for_each_xdp_txq(vsi, i) {
2709 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2710 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2712 mutex_unlock(&pf->avail_q_mutex);
2714 devm_kfree(dev, vsi->xdp_rings);
2719 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
2720 * @vsi: VSI to remove XDP rings
2722 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
2725 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
2727 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2728 struct ice_pf *pf = vsi->back;
2731 /* q_vectors are freed in reset path so there's no point in detaching
2732 * rings; in case of rebuild being triggered not from reset bits
2733 * in pf->state won't be set, so additionally check first q_vector
2736 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2739 ice_for_each_q_vector(vsi, v_idx) {
2740 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2741 struct ice_tx_ring *ring;
2743 ice_for_each_tx_ring(ring, q_vector->tx)
2744 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
2747 /* restore the value of last node prior to XDP setup */
2748 q_vector->tx.tx_ring = ring;
2752 mutex_lock(&pf->avail_q_mutex);
2753 ice_for_each_xdp_txq(vsi, i) {
2754 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2755 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2757 mutex_unlock(&pf->avail_q_mutex);
2759 ice_for_each_xdp_txq(vsi, i)
2760 if (vsi->xdp_rings[i]) {
2761 if (vsi->xdp_rings[i]->desc) {
2763 ice_free_tx_ring(vsi->xdp_rings[i]);
2765 kfree_rcu(vsi->xdp_rings[i], rcu);
2766 vsi->xdp_rings[i] = NULL;
2769 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
2770 vsi->xdp_rings = NULL;
2772 if (static_key_enabled(&ice_xdp_locking_key))
2773 static_branch_dec(&ice_xdp_locking_key);
2775 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2778 ice_vsi_assign_bpf_prog(vsi, NULL);
2780 /* notify Tx scheduler that we destroyed XDP queues and bring
2781 * back the old number of child nodes
2783 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2784 max_txqs[i] = vsi->num_txq;
2786 /* change number of XDP Tx queues to 0 */
2787 vsi->num_xdp_txq = 0;
2789 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2794 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2795 * @vsi: VSI to schedule napi on
2797 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2801 ice_for_each_rxq(vsi, i) {
2802 struct ice_rx_ring *rx_ring = vsi->rx_rings[i];
2804 if (rx_ring->xsk_pool)
2805 napi_schedule(&rx_ring->q_vector->napi);
2810 * ice_vsi_determine_xdp_res - figure out how many Tx qs can XDP have
2811 * @vsi: VSI to determine the count of XDP Tx qs
2813 * returns 0 if Tx qs count is higher than at least half of CPU count,
2816 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi)
2818 u16 avail = ice_get_avail_txq_count(vsi->back);
2819 u16 cpus = num_possible_cpus();
2821 if (avail < cpus / 2)
2824 vsi->num_xdp_txq = min_t(u16, avail, cpus);
2826 if (vsi->num_xdp_txq < cpus)
2827 static_branch_inc(&ice_xdp_locking_key);
2833 * ice_xdp_setup_prog - Add or remove XDP eBPF program
2834 * @vsi: VSI to setup XDP for
2835 * @prog: XDP program
2836 * @extack: netlink extended ack
2839 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
2840 struct netlink_ext_ack *extack)
2842 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
2843 bool if_running = netif_running(vsi->netdev);
2844 int ret = 0, xdp_ring_err = 0;
2846 if (frame_size > vsi->rx_buf_len) {
2847 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
2851 /* need to stop netdev while setting up the program for Rx rings */
2852 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2853 ret = ice_down(vsi);
2855 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
2860 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
2861 xdp_ring_err = ice_vsi_determine_xdp_res(vsi);
2863 NL_SET_ERR_MSG_MOD(extack, "Not enough Tx resources for XDP");
2865 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
2867 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
2869 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
2870 xdp_ring_err = ice_destroy_xdp_rings(vsi);
2872 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
2874 /* safe to call even when prog == vsi->xdp_prog as
2875 * dev_xdp_install in net/core/dev.c incremented prog's
2876 * refcount so corresponding bpf_prog_put won't cause
2879 ice_vsi_assign_bpf_prog(vsi, prog);
2886 ice_vsi_rx_napi_schedule(vsi);
2888 return (ret || xdp_ring_err) ? -ENOMEM : 0;
2892 * ice_xdp_safe_mode - XDP handler for safe mode
2896 static int ice_xdp_safe_mode(struct net_device __always_unused *dev,
2897 struct netdev_bpf *xdp)
2899 NL_SET_ERR_MSG_MOD(xdp->extack,
2900 "Please provide working DDP firmware package in order to use XDP\n"
2901 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst");
2906 * ice_xdp - implements XDP handler
2910 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
2912 struct ice_netdev_priv *np = netdev_priv(dev);
2913 struct ice_vsi *vsi = np->vsi;
2915 if (vsi->type != ICE_VSI_PF) {
2916 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI");
2920 switch (xdp->command) {
2921 case XDP_SETUP_PROG:
2922 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
2923 case XDP_SETUP_XSK_POOL:
2924 return ice_xsk_pool_setup(vsi, xdp->xsk.pool,
2932 * ice_ena_misc_vector - enable the non-queue interrupts
2933 * @pf: board private structure
2935 static void ice_ena_misc_vector(struct ice_pf *pf)
2937 struct ice_hw *hw = &pf->hw;
2940 /* Disable anti-spoof detection interrupt to prevent spurious event
2941 * interrupts during a function reset. Anti-spoof functionally is
2944 val = rd32(hw, GL_MDCK_TX_TDPU);
2945 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
2946 wr32(hw, GL_MDCK_TX_TDPU, val);
2948 /* clear things first */
2949 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
2950 rd32(hw, PFINT_OICR); /* read to clear */
2952 val = (PFINT_OICR_ECC_ERR_M |
2953 PFINT_OICR_MAL_DETECT_M |
2955 PFINT_OICR_PCI_EXCEPTION_M |
2957 PFINT_OICR_HMC_ERR_M |
2958 PFINT_OICR_PE_PUSH_M |
2959 PFINT_OICR_PE_CRITERR_M);
2961 wr32(hw, PFINT_OICR_ENA, val);
2963 /* SW_ITR_IDX = 0, but don't change INTENA */
2964 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2965 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2969 * ice_misc_intr - misc interrupt handler
2970 * @irq: interrupt number
2971 * @data: pointer to a q_vector
2973 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2975 struct ice_pf *pf = (struct ice_pf *)data;
2976 struct ice_hw *hw = &pf->hw;
2977 irqreturn_t ret = IRQ_NONE;
2981 dev = ice_pf_to_dev(pf);
2982 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
2983 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2984 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
2986 oicr = rd32(hw, PFINT_OICR);
2987 ena_mask = rd32(hw, PFINT_OICR_ENA);
2989 if (oicr & PFINT_OICR_SWINT_M) {
2990 ena_mask &= ~PFINT_OICR_SWINT_M;
2994 if (oicr & PFINT_OICR_MAL_DETECT_M) {
2995 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2996 set_bit(ICE_MDD_EVENT_PENDING, pf->state);
2998 if (oicr & PFINT_OICR_VFLR_M) {
2999 /* disable any further VFLR event notifications */
3000 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
3001 u32 reg = rd32(hw, PFINT_OICR_ENA);
3003 reg &= ~PFINT_OICR_VFLR_M;
3004 wr32(hw, PFINT_OICR_ENA, reg);
3006 ena_mask &= ~PFINT_OICR_VFLR_M;
3007 set_bit(ICE_VFLR_EVENT_PENDING, pf->state);
3011 if (oicr & PFINT_OICR_GRST_M) {
3014 /* we have a reset warning */
3015 ena_mask &= ~PFINT_OICR_GRST_M;
3016 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
3017 GLGEN_RSTAT_RESET_TYPE_S;
3019 if (reset == ICE_RESET_CORER)
3021 else if (reset == ICE_RESET_GLOBR)
3023 else if (reset == ICE_RESET_EMPR)
3026 dev_dbg(dev, "Invalid reset type %d\n", reset);
3028 /* If a reset cycle isn't already in progress, we set a bit in
3029 * pf->state so that the service task can start a reset/rebuild.
3031 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) {
3032 if (reset == ICE_RESET_CORER)
3033 set_bit(ICE_CORER_RECV, pf->state);
3034 else if (reset == ICE_RESET_GLOBR)
3035 set_bit(ICE_GLOBR_RECV, pf->state);
3037 set_bit(ICE_EMPR_RECV, pf->state);
3039 /* There are couple of different bits at play here.
3040 * hw->reset_ongoing indicates whether the hardware is
3041 * in reset. This is set to true when a reset interrupt
3042 * is received and set back to false after the driver
3043 * has determined that the hardware is out of reset.
3045 * ICE_RESET_OICR_RECV in pf->state indicates
3046 * that a post reset rebuild is required before the
3047 * driver is operational again. This is set above.
3049 * As this is the start of the reset/rebuild cycle, set
3050 * both to indicate that.
3052 hw->reset_ongoing = true;
3056 if (oicr & PFINT_OICR_TSYN_TX_M) {
3057 ena_mask &= ~PFINT_OICR_TSYN_TX_M;
3058 ice_ptp_process_ts(pf);
3061 if (oicr & PFINT_OICR_TSYN_EVNT_M) {
3062 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
3063 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx));
3065 /* Save EVENTs from GTSYN register */
3066 pf->ptp.ext_ts_irq |= gltsyn_stat & (GLTSYN_STAT_EVENT0_M |
3067 GLTSYN_STAT_EVENT1_M |
3068 GLTSYN_STAT_EVENT2_M);
3069 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M;
3070 kthread_queue_work(pf->ptp.kworker, &pf->ptp.extts_work);
3073 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M)
3074 if (oicr & ICE_AUX_CRIT_ERR) {
3075 pf->oicr_err_reg |= oicr;
3076 set_bit(ICE_AUX_ERR_PENDING, pf->state);
3077 ena_mask &= ~ICE_AUX_CRIT_ERR;
3080 /* Report any remaining unexpected interrupts */
3083 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
3084 /* If a critical error is pending there is no choice but to
3087 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M |
3088 PFINT_OICR_ECC_ERR_M)) {
3089 set_bit(ICE_PFR_REQ, pf->state);
3090 ice_service_task_schedule(pf);
3095 ice_service_task_schedule(pf);
3096 ice_irq_dynamic_ena(hw, NULL, NULL);
3102 * ice_dis_ctrlq_interrupts - disable control queue interrupts
3103 * @hw: pointer to HW structure
3105 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
3107 /* disable Admin queue Interrupt causes */
3108 wr32(hw, PFINT_FW_CTL,
3109 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
3111 /* disable Mailbox queue Interrupt causes */
3112 wr32(hw, PFINT_MBX_CTL,
3113 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
3115 wr32(hw, PFINT_SB_CTL,
3116 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M);
3118 /* disable Control queue Interrupt causes */
3119 wr32(hw, PFINT_OICR_CTL,
3120 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
3126 * ice_free_irq_msix_misc - Unroll misc vector setup
3127 * @pf: board private structure
3129 static void ice_free_irq_msix_misc(struct ice_pf *pf)
3131 struct ice_hw *hw = &pf->hw;
3133 ice_dis_ctrlq_interrupts(hw);
3135 /* disable OICR interrupt */
3136 wr32(hw, PFINT_OICR_ENA, 0);
3139 if (pf->msix_entries) {
3140 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
3141 devm_free_irq(ice_pf_to_dev(pf),
3142 pf->msix_entries[pf->oicr_idx].vector, pf);
3145 pf->num_avail_sw_msix += 1;
3146 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
3150 * ice_ena_ctrlq_interrupts - enable control queue interrupts
3151 * @hw: pointer to HW structure
3152 * @reg_idx: HW vector index to associate the control queue interrupts with
3154 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
3158 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
3159 PFINT_OICR_CTL_CAUSE_ENA_M);
3160 wr32(hw, PFINT_OICR_CTL, val);
3162 /* enable Admin queue Interrupt causes */
3163 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
3164 PFINT_FW_CTL_CAUSE_ENA_M);
3165 wr32(hw, PFINT_FW_CTL, val);
3167 /* enable Mailbox queue Interrupt causes */
3168 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
3169 PFINT_MBX_CTL_CAUSE_ENA_M);
3170 wr32(hw, PFINT_MBX_CTL, val);
3172 /* This enables Sideband queue Interrupt causes */
3173 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) |
3174 PFINT_SB_CTL_CAUSE_ENA_M);
3175 wr32(hw, PFINT_SB_CTL, val);
3181 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
3182 * @pf: board private structure
3184 * This sets up the handler for MSIX 0, which is used to manage the
3185 * non-queue interrupts, e.g. AdminQ and errors. This is not used
3186 * when in MSI or Legacy interrupt mode.
3188 static int ice_req_irq_msix_misc(struct ice_pf *pf)
3190 struct device *dev = ice_pf_to_dev(pf);
3191 struct ice_hw *hw = &pf->hw;
3192 int oicr_idx, err = 0;
3194 if (!pf->int_name[0])
3195 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
3196 dev_driver_string(dev), dev_name(dev));
3198 /* Do not request IRQ but do enable OICR interrupt since settings are
3199 * lost during reset. Note that this function is called only during
3200 * rebuild path and not while reset is in progress.
3202 if (ice_is_reset_in_progress(pf->state))
3205 /* reserve one vector in irq_tracker for misc interrupts */
3206 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3210 pf->num_avail_sw_msix -= 1;
3211 pf->oicr_idx = (u16)oicr_idx;
3213 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
3214 ice_misc_intr, 0, pf->int_name, pf);
3216 dev_err(dev, "devm_request_irq for %s failed: %d\n",
3218 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3219 pf->num_avail_sw_msix += 1;
3224 ice_ena_misc_vector(pf);
3226 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
3227 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
3228 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
3231 ice_irq_dynamic_ena(hw, NULL, NULL);
3237 * ice_napi_add - register NAPI handler for the VSI
3238 * @vsi: VSI for which NAPI handler is to be registered
3240 * This function is only called in the driver's load path. Registering the NAPI
3241 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
3242 * reset/rebuild, etc.)
3244 static void ice_napi_add(struct ice_vsi *vsi)
3251 ice_for_each_q_vector(vsi, v_idx)
3252 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
3253 ice_napi_poll, NAPI_POLL_WEIGHT);
3257 * ice_set_ops - set netdev and ethtools ops for the given netdev
3258 * @netdev: netdev instance
3260 static void ice_set_ops(struct net_device *netdev)
3262 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3264 if (ice_is_safe_mode(pf)) {
3265 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
3266 ice_set_ethtool_safe_mode_ops(netdev);
3270 netdev->netdev_ops = &ice_netdev_ops;
3271 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic;
3272 ice_set_ethtool_ops(netdev);
3276 * ice_set_netdev_features - set features for the given netdev
3277 * @netdev: netdev instance
3279 static void ice_set_netdev_features(struct net_device *netdev)
3281 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3282 bool is_dvm_ena = ice_is_dvm_ena(&pf->hw);
3283 netdev_features_t csumo_features;
3284 netdev_features_t vlano_features;
3285 netdev_features_t dflt_features;
3286 netdev_features_t tso_features;
3288 if (ice_is_safe_mode(pf)) {
3290 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
3291 netdev->hw_features = netdev->features;
3295 dflt_features = NETIF_F_SG |
3300 csumo_features = NETIF_F_RXCSUM |
3305 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
3306 NETIF_F_HW_VLAN_CTAG_TX |
3307 NETIF_F_HW_VLAN_CTAG_RX;
3309 /* Enable CTAG/STAG filtering by default in Double VLAN Mode (DVM) */
3311 vlano_features |= NETIF_F_HW_VLAN_STAG_FILTER;
3313 tso_features = NETIF_F_TSO |
3317 NETIF_F_GSO_UDP_TUNNEL |
3318 NETIF_F_GSO_GRE_CSUM |
3319 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3320 NETIF_F_GSO_PARTIAL |
3321 NETIF_F_GSO_IPXIP4 |
3322 NETIF_F_GSO_IPXIP6 |
3325 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3326 NETIF_F_GSO_GRE_CSUM;
3327 /* set features that user can change */
3328 netdev->hw_features = dflt_features | csumo_features |
3329 vlano_features | tso_features;
3331 /* add support for HW_CSUM on packets with MPLS header */
3332 netdev->mpls_features = NETIF_F_HW_CSUM;
3334 /* enable features */
3335 netdev->features |= netdev->hw_features;
3337 netdev->hw_features |= NETIF_F_HW_TC;
3339 /* encap and VLAN devices inherit default, csumo and tso features */
3340 netdev->hw_enc_features |= dflt_features | csumo_features |
3342 netdev->vlan_features |= dflt_features | csumo_features |
3345 /* advertise support but don't enable by default since only one type of
3346 * VLAN offload can be enabled at a time (i.e. CTAG or STAG). When one
3347 * type turns on the other has to be turned off. This is enforced by the
3348 * ice_fix_features() ndo callback.
3351 netdev->hw_features |= NETIF_F_HW_VLAN_STAG_RX |
3352 NETIF_F_HW_VLAN_STAG_TX;
3356 * ice_cfg_netdev - Allocate, configure and register a netdev
3357 * @vsi: the VSI associated with the new netdev
3359 * Returns 0 on success, negative value on failure
3361 static int ice_cfg_netdev(struct ice_vsi *vsi)
3363 struct ice_netdev_priv *np;
3364 struct net_device *netdev;
3365 u8 mac_addr[ETH_ALEN];
3367 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
3372 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3373 vsi->netdev = netdev;
3374 np = netdev_priv(netdev);
3377 ice_set_netdev_features(netdev);
3379 ice_set_ops(netdev);
3381 if (vsi->type == ICE_VSI_PF) {
3382 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back));
3383 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
3384 eth_hw_addr_set(netdev, mac_addr);
3385 ether_addr_copy(netdev->perm_addr, mac_addr);
3388 netdev->priv_flags |= IFF_UNICAST_FLT;
3390 /* Setup netdev TC information */
3391 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
3393 /* setup watchdog timeout value to be 5 second */
3394 netdev->watchdog_timeo = 5 * HZ;
3396 netdev->min_mtu = ETH_MIN_MTU;
3397 netdev->max_mtu = ICE_MAX_MTU;
3403 * ice_fill_rss_lut - Fill the RSS lookup table with default values
3404 * @lut: Lookup table
3405 * @rss_table_size: Lookup table size
3406 * @rss_size: Range of queue number for hashing
3408 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
3412 for (i = 0; i < rss_table_size; i++)
3413 lut[i] = i % rss_size;
3417 * ice_pf_vsi_setup - Set up a PF VSI
3418 * @pf: board private structure
3419 * @pi: pointer to the port_info instance
3421 * Returns pointer to the successfully allocated VSI software struct
3422 * on success, otherwise returns NULL on failure.
3424 static struct ice_vsi *
3425 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3427 return ice_vsi_setup(pf, pi, ICE_VSI_PF, NULL, NULL);
3430 static struct ice_vsi *
3431 ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
3432 struct ice_channel *ch)
3434 return ice_vsi_setup(pf, pi, ICE_VSI_CHNL, NULL, ch);
3438 * ice_ctrl_vsi_setup - Set up a control VSI
3439 * @pf: board private structure
3440 * @pi: pointer to the port_info instance
3442 * Returns pointer to the successfully allocated VSI software struct
3443 * on success, otherwise returns NULL on failure.
3445 static struct ice_vsi *
3446 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3448 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, NULL, NULL);
3452 * ice_lb_vsi_setup - Set up a loopback VSI
3453 * @pf: board private structure
3454 * @pi: pointer to the port_info instance
3456 * Returns pointer to the successfully allocated VSI software struct
3457 * on success, otherwise returns NULL on failure.
3460 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3462 return ice_vsi_setup(pf, pi, ICE_VSI_LB, NULL, NULL);
3466 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
3467 * @netdev: network interface to be adjusted
3469 * @vid: VLAN ID to be added
3471 * net_device_ops implementation for adding VLAN IDs
3474 ice_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
3476 struct ice_netdev_priv *np = netdev_priv(netdev);
3477 struct ice_vsi_vlan_ops *vlan_ops;
3478 struct ice_vsi *vsi = np->vsi;
3479 struct ice_vlan vlan;
3482 /* VLAN 0 is added by default during load/reset */
3486 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3487 usleep_range(1000, 2000);
3489 /* Add multicast promisc rule for the VLAN ID to be added if
3490 * all-multicast is currently enabled.
3492 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3493 ret = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3494 ICE_MCAST_VLAN_PROMISC_BITS,
3500 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3502 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
3503 * packets aren't pruned by the device's internal switch on Rx
3505 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3506 ret = vlan_ops->add_vlan(vsi, &vlan);
3510 /* If all-multicast is currently enabled and this VLAN ID is only one
3511 * besides VLAN-0 we have to update look-up type of multicast promisc
3512 * rule for VLAN-0 from ICE_SW_LKUP_PROMISC to ICE_SW_LKUP_PROMISC_VLAN.
3514 if ((vsi->current_netdev_flags & IFF_ALLMULTI) &&
3515 ice_vsi_num_non_zero_vlans(vsi) == 1) {
3516 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3517 ICE_MCAST_PROMISC_BITS, 0);
3518 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3519 ICE_MCAST_VLAN_PROMISC_BITS, 0);
3523 clear_bit(ICE_CFG_BUSY, vsi->state);
3529 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
3530 * @netdev: network interface to be adjusted
3532 * @vid: VLAN ID to be removed
3534 * net_device_ops implementation for removing VLAN IDs
3537 ice_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3539 struct ice_netdev_priv *np = netdev_priv(netdev);
3540 struct ice_vsi_vlan_ops *vlan_ops;
3541 struct ice_vsi *vsi = np->vsi;
3542 struct ice_vlan vlan;
3545 /* don't allow removal of VLAN 0 */
3549 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3550 usleep_range(1000, 2000);
3552 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3554 /* Make sure VLAN delete is successful before updating VLAN
3557 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3558 ret = vlan_ops->del_vlan(vsi, &vlan);
3562 /* Remove multicast promisc rule for the removed VLAN ID if
3563 * all-multicast is enabled.
3565 if (vsi->current_netdev_flags & IFF_ALLMULTI)
3566 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3567 ICE_MCAST_VLAN_PROMISC_BITS, vid);
3569 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3570 /* Update look-up type of multicast promisc rule for VLAN 0
3571 * from ICE_SW_LKUP_PROMISC_VLAN to ICE_SW_LKUP_PROMISC when
3572 * all-multicast is enabled and VLAN 0 is the only VLAN rule.
3574 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3575 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3576 ICE_MCAST_VLAN_PROMISC_BITS,
3578 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3579 ICE_MCAST_PROMISC_BITS, 0);
3584 clear_bit(ICE_CFG_BUSY, vsi->state);
3590 * ice_rep_indr_tc_block_unbind
3591 * @cb_priv: indirection block private data
3593 static void ice_rep_indr_tc_block_unbind(void *cb_priv)
3595 struct ice_indr_block_priv *indr_priv = cb_priv;
3597 list_del(&indr_priv->list);
3602 * ice_tc_indir_block_unregister - Unregister TC indirect block notifications
3603 * @vsi: VSI struct which has the netdev
3605 static void ice_tc_indir_block_unregister(struct ice_vsi *vsi)
3607 struct ice_netdev_priv *np = netdev_priv(vsi->netdev);
3609 flow_indr_dev_unregister(ice_indr_setup_tc_cb, np,
3610 ice_rep_indr_tc_block_unbind);
3614 * ice_tc_indir_block_remove - clean indirect TC block notifications
3617 static void ice_tc_indir_block_remove(struct ice_pf *pf)
3619 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3624 ice_tc_indir_block_unregister(pf_vsi);
3628 * ice_tc_indir_block_register - Register TC indirect block notifications
3629 * @vsi: VSI struct which has the netdev
3631 * Returns 0 on success, negative value on failure
3633 static int ice_tc_indir_block_register(struct ice_vsi *vsi)
3635 struct ice_netdev_priv *np;
3637 if (!vsi || !vsi->netdev)
3640 np = netdev_priv(vsi->netdev);
3642 INIT_LIST_HEAD(&np->tc_indr_block_priv_list);
3643 return flow_indr_dev_register(ice_indr_setup_tc_cb, np);
3647 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
3648 * @pf: board private structure
3650 * Returns 0 on success, negative value on failure
3652 static int ice_setup_pf_sw(struct ice_pf *pf)
3654 struct device *dev = ice_pf_to_dev(pf);
3655 bool dvm = ice_is_dvm_ena(&pf->hw);
3656 struct ice_vsi *vsi;
3659 if (ice_is_reset_in_progress(pf->state))
3662 status = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
3666 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
3670 /* init channel list */
3671 INIT_LIST_HEAD(&vsi->ch_list);
3673 status = ice_cfg_netdev(vsi);
3675 goto unroll_vsi_setup;
3676 /* netdev has to be configured before setting frame size */
3677 ice_vsi_cfg_frame_size(vsi);
3679 /* init indirect block notifications */
3680 status = ice_tc_indir_block_register(vsi);
3682 dev_err(dev, "Failed to register netdev notifier\n");
3683 goto unroll_cfg_netdev;
3686 /* Setup DCB netlink interface */
3687 ice_dcbnl_setup(vsi);
3689 /* registering the NAPI handler requires both the queues and
3690 * netdev to be created, which are done in ice_pf_vsi_setup()
3691 * and ice_cfg_netdev() respectively
3695 status = ice_set_cpu_rx_rmap(vsi);
3697 dev_err(dev, "Failed to set CPU Rx map VSI %d error %d\n",
3698 vsi->vsi_num, status);
3699 goto unroll_napi_add;
3701 status = ice_init_mac_fltr(pf);
3703 goto free_cpu_rx_map;
3708 ice_free_cpu_rx_rmap(vsi);
3710 ice_tc_indir_block_unregister(vsi);
3715 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3716 free_netdev(vsi->netdev);
3722 ice_vsi_release(vsi);
3727 * ice_get_avail_q_count - Get count of queues in use
3728 * @pf_qmap: bitmap to get queue use count from
3729 * @lock: pointer to a mutex that protects access to pf_qmap
3730 * @size: size of the bitmap
3733 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
3739 for_each_clear_bit(bit, pf_qmap, size)
3747 * ice_get_avail_txq_count - Get count of Tx queues in use
3748 * @pf: pointer to an ice_pf instance
3750 u16 ice_get_avail_txq_count(struct ice_pf *pf)
3752 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
3757 * ice_get_avail_rxq_count - Get count of Rx queues in use
3758 * @pf: pointer to an ice_pf instance
3760 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
3762 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
3767 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3768 * @pf: board private structure to initialize
3770 static void ice_deinit_pf(struct ice_pf *pf)
3772 ice_service_task_stop(pf);
3773 mutex_destroy(&pf->sw_mutex);
3774 mutex_destroy(&pf->tc_mutex);
3775 mutex_destroy(&pf->avail_q_mutex);
3776 mutex_destroy(&pf->vfs.table_lock);
3778 if (pf->avail_txqs) {
3779 bitmap_free(pf->avail_txqs);
3780 pf->avail_txqs = NULL;
3783 if (pf->avail_rxqs) {
3784 bitmap_free(pf->avail_rxqs);
3785 pf->avail_rxqs = NULL;
3789 ptp_clock_unregister(pf->ptp.clock);
3793 * ice_set_pf_caps - set PFs capability flags
3794 * @pf: pointer to the PF instance
3796 static void ice_set_pf_caps(struct ice_pf *pf)
3798 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
3800 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3801 if (func_caps->common_cap.rdma)
3802 set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3803 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3804 if (func_caps->common_cap.dcb)
3805 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3806 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3807 if (func_caps->common_cap.sr_iov_1_1) {
3808 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3809 pf->vfs.num_supported = min_t(int, func_caps->num_allocd_vfs,
3812 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
3813 if (func_caps->common_cap.rss_table_size)
3814 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
3816 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
3817 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
3820 /* ctrl_vsi_idx will be set to a valid value when flow director
3821 * is setup by ice_init_fdir
3823 pf->ctrl_vsi_idx = ICE_NO_VSI;
3824 set_bit(ICE_FLAG_FD_ENA, pf->flags);
3825 /* force guaranteed filter pool for PF */
3826 ice_alloc_fd_guar_item(&pf->hw, &unused,
3827 func_caps->fd_fltr_guar);
3828 /* force shared filter pool for PF */
3829 ice_alloc_fd_shrd_item(&pf->hw, &unused,
3830 func_caps->fd_fltr_best_effort);
3833 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3834 if (func_caps->common_cap.ieee_1588)
3835 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3837 pf->max_pf_txqs = func_caps->common_cap.num_txq;
3838 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
3842 * ice_init_pf - Initialize general software structures (struct ice_pf)
3843 * @pf: board private structure to initialize
3845 static int ice_init_pf(struct ice_pf *pf)
3847 ice_set_pf_caps(pf);
3849 mutex_init(&pf->sw_mutex);
3850 mutex_init(&pf->tc_mutex);
3852 INIT_HLIST_HEAD(&pf->aq_wait_list);
3853 spin_lock_init(&pf->aq_wait_lock);
3854 init_waitqueue_head(&pf->aq_wait_queue);
3856 init_waitqueue_head(&pf->reset_wait_queue);
3858 /* setup service timer and periodic service task */
3859 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
3860 pf->serv_tmr_period = HZ;
3861 INIT_WORK(&pf->serv_task, ice_service_task);
3862 clear_bit(ICE_SERVICE_SCHED, pf->state);
3864 mutex_init(&pf->avail_q_mutex);
3865 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
3866 if (!pf->avail_txqs)
3869 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
3870 if (!pf->avail_rxqs) {
3871 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
3872 pf->avail_txqs = NULL;
3876 mutex_init(&pf->vfs.table_lock);
3877 hash_init(pf->vfs.table);
3883 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
3884 * @pf: board private structure
3886 * compute the number of MSIX vectors required (v_budget) and request from
3887 * the OS. Return the number of vectors reserved or negative on failure
3889 static int ice_ena_msix_range(struct ice_pf *pf)
3891 int num_cpus, v_left, v_actual, v_other, v_budget = 0;
3892 struct device *dev = ice_pf_to_dev(pf);
3895 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
3896 num_cpus = num_online_cpus();
3898 /* reserve for LAN miscellaneous handler */
3899 needed = ICE_MIN_LAN_OICR_MSIX;
3900 if (v_left < needed)
3901 goto no_hw_vecs_left_err;
3905 /* reserve for flow director */
3906 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
3907 needed = ICE_FDIR_MSIX;
3908 if (v_left < needed)
3909 goto no_hw_vecs_left_err;
3914 /* reserve for switchdev */
3915 needed = ICE_ESWITCH_MSIX;
3916 if (v_left < needed)
3917 goto no_hw_vecs_left_err;
3921 /* total used for non-traffic vectors */
3924 /* reserve vectors for LAN traffic */
3926 if (v_left < needed)
3927 goto no_hw_vecs_left_err;
3928 pf->num_lan_msix = needed;
3932 /* reserve vectors for RDMA auxiliary driver */
3933 if (ice_is_rdma_ena(pf)) {
3934 needed = num_cpus + ICE_RDMA_NUM_AEQ_MSIX;
3935 if (v_left < needed)
3936 goto no_hw_vecs_left_err;
3937 pf->num_rdma_msix = needed;
3942 pf->msix_entries = devm_kcalloc(dev, v_budget,
3943 sizeof(*pf->msix_entries), GFP_KERNEL);
3944 if (!pf->msix_entries) {
3949 for (i = 0; i < v_budget; i++)
3950 pf->msix_entries[i].entry = i;
3952 /* actually reserve the vectors */
3953 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
3954 ICE_MIN_MSIX, v_budget);
3956 dev_err(dev, "unable to reserve MSI-X vectors\n");
3961 if (v_actual < v_budget) {
3962 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
3963 v_budget, v_actual);
3965 if (v_actual < ICE_MIN_MSIX) {
3966 /* error if we can't get minimum vectors */
3967 pci_disable_msix(pf->pdev);
3971 int v_remain = v_actual - v_other;
3972 int v_rdma = 0, v_min_rdma = 0;
3974 if (ice_is_rdma_ena(pf)) {
3975 /* Need at least 1 interrupt in addition to
3978 v_rdma = ICE_RDMA_NUM_AEQ_MSIX + 1;
3979 v_min_rdma = ICE_MIN_RDMA_MSIX;
3982 if (v_actual == ICE_MIN_MSIX ||
3983 v_remain < ICE_MIN_LAN_TXRX_MSIX + v_min_rdma) {
3984 dev_warn(dev, "Not enough MSI-X vectors to support RDMA.\n");
3985 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3987 pf->num_rdma_msix = 0;
3988 pf->num_lan_msix = ICE_MIN_LAN_TXRX_MSIX;
3989 } else if ((v_remain < ICE_MIN_LAN_TXRX_MSIX + v_rdma) ||
3990 (v_remain - v_rdma < v_rdma)) {
3991 /* Support minimum RDMA and give remaining
3992 * vectors to LAN MSIX
3994 pf->num_rdma_msix = v_min_rdma;
3995 pf->num_lan_msix = v_remain - v_min_rdma;
3997 /* Split remaining MSIX with RDMA after
3998 * accounting for AEQ MSIX
4000 pf->num_rdma_msix = (v_remain - ICE_RDMA_NUM_AEQ_MSIX) / 2 +
4001 ICE_RDMA_NUM_AEQ_MSIX;
4002 pf->num_lan_msix = v_remain - pf->num_rdma_msix;
4005 dev_notice(dev, "Enabled %d MSI-X vectors for LAN traffic.\n",
4008 if (ice_is_rdma_ena(pf))
4009 dev_notice(dev, "Enabled %d MSI-X vectors for RDMA.\n",
4017 devm_kfree(dev, pf->msix_entries);
4020 no_hw_vecs_left_err:
4021 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
4025 pf->num_rdma_msix = 0;
4026 pf->num_lan_msix = 0;
4031 * ice_dis_msix - Disable MSI-X interrupt setup in OS
4032 * @pf: board private structure
4034 static void ice_dis_msix(struct ice_pf *pf)
4036 pci_disable_msix(pf->pdev);
4037 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
4038 pf->msix_entries = NULL;
4042 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
4043 * @pf: board private structure
4045 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
4049 if (pf->irq_tracker) {
4050 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
4051 pf->irq_tracker = NULL;
4056 * ice_init_interrupt_scheme - Determine proper interrupt scheme
4057 * @pf: board private structure to initialize
4059 static int ice_init_interrupt_scheme(struct ice_pf *pf)
4063 vectors = ice_ena_msix_range(pf);
4068 /* set up vector assignment tracking */
4069 pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf),
4070 struct_size(pf->irq_tracker, list, vectors),
4072 if (!pf->irq_tracker) {
4077 /* populate SW interrupts pool with number of OS granted IRQs. */
4078 pf->num_avail_sw_msix = (u16)vectors;
4079 pf->irq_tracker->num_entries = (u16)vectors;
4080 pf->irq_tracker->end = pf->irq_tracker->num_entries;
4086 * ice_is_wol_supported - check if WoL is supported
4087 * @hw: pointer to hardware info
4089 * Check if WoL is supported based on the HW configuration.
4090 * Returns true if NVM supports and enables WoL for this port, false otherwise
4092 bool ice_is_wol_supported(struct ice_hw *hw)
4096 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control
4097 * word) indicates WoL is not supported on the corresponding PF ID.
4099 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl))
4102 return !(BIT(hw->port_info->lport) & wol_ctrl);
4106 * ice_vsi_recfg_qs - Change the number of queues on a VSI
4107 * @vsi: VSI being changed
4108 * @new_rx: new number of Rx queues
4109 * @new_tx: new number of Tx queues
4111 * Only change the number of queues if new_tx, or new_rx is non-0.
4113 * Returns 0 on success.
4115 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
4117 struct ice_pf *pf = vsi->back;
4118 int err = 0, timeout = 50;
4120 if (!new_rx && !new_tx)
4123 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
4127 usleep_range(1000, 2000);
4131 vsi->req_txq = (u16)new_tx;
4133 vsi->req_rxq = (u16)new_rx;
4135 /* set for the next time the netdev is started */
4136 if (!netif_running(vsi->netdev)) {
4137 ice_vsi_rebuild(vsi, false);
4138 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
4143 ice_vsi_rebuild(vsi, false);
4144 ice_pf_dcb_recfg(pf);
4147 clear_bit(ICE_CFG_BUSY, pf->state);
4152 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode
4153 * @pf: PF to configure
4155 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF
4156 * VSI can still Tx/Rx VLAN tagged packets.
4158 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf)
4160 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4161 struct ice_vsi_ctx *ctxt;
4168 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4173 ctxt->info = vsi->info;
4175 ctxt->info.valid_sections =
4176 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
4177 ICE_AQ_VSI_PROP_SECURITY_VALID |
4178 ICE_AQ_VSI_PROP_SW_VALID);
4180 /* disable VLAN anti-spoof */
4181 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
4182 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
4184 /* disable VLAN pruning and keep all other settings */
4185 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4187 /* allow all VLANs on Tx and don't strip on Rx */
4188 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL |
4189 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4191 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4193 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %d aq_err %s\n",
4194 status, ice_aq_str(hw->adminq.sq_last_status));
4196 vsi->info.sec_flags = ctxt->info.sec_flags;
4197 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
4198 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
4205 * ice_log_pkg_init - log result of DDP package load
4206 * @hw: pointer to hardware info
4207 * @state: state of package load
4209 static void ice_log_pkg_init(struct ice_hw *hw, enum ice_ddp_state state)
4211 struct ice_pf *pf = hw->back;
4214 dev = ice_pf_to_dev(pf);
4217 case ICE_DDP_PKG_SUCCESS:
4218 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
4219 hw->active_pkg_name,
4220 hw->active_pkg_ver.major,
4221 hw->active_pkg_ver.minor,
4222 hw->active_pkg_ver.update,
4223 hw->active_pkg_ver.draft);
4225 case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED:
4226 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
4227 hw->active_pkg_name,
4228 hw->active_pkg_ver.major,
4229 hw->active_pkg_ver.minor,
4230 hw->active_pkg_ver.update,
4231 hw->active_pkg_ver.draft);
4233 case ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED:
4234 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",
4235 hw->active_pkg_name,
4236 hw->active_pkg_ver.major,
4237 hw->active_pkg_ver.minor,
4238 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4240 case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED:
4241 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",
4242 hw->active_pkg_name,
4243 hw->active_pkg_ver.major,
4244 hw->active_pkg_ver.minor,
4245 hw->active_pkg_ver.update,
4246 hw->active_pkg_ver.draft,
4253 case ICE_DDP_PKG_FW_MISMATCH:
4254 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");
4256 case ICE_DDP_PKG_INVALID_FILE:
4257 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
4259 case ICE_DDP_PKG_FILE_VERSION_TOO_HIGH:
4260 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
4262 case ICE_DDP_PKG_FILE_VERSION_TOO_LOW:
4263 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",
4264 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4266 case ICE_DDP_PKG_FILE_SIGNATURE_INVALID:
4267 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");
4269 case ICE_DDP_PKG_FILE_REVISION_TOO_LOW:
4270 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");
4272 case ICE_DDP_PKG_LOAD_ERROR:
4273 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
4274 /* poll for reset to complete */
4275 if (ice_check_reset(hw))
4276 dev_err(dev, "Error resetting device. Please reload the driver\n");
4278 case ICE_DDP_PKG_ERR:
4280 dev_err(dev, "An unknown error occurred when loading the DDP package. Entering Safe Mode.\n");
4286 * ice_load_pkg - load/reload the DDP Package file
4287 * @firmware: firmware structure when firmware requested or NULL for reload
4288 * @pf: pointer to the PF instance
4290 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
4291 * initialize HW tables.
4294 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
4296 enum ice_ddp_state state = ICE_DDP_PKG_ERR;
4297 struct device *dev = ice_pf_to_dev(pf);
4298 struct ice_hw *hw = &pf->hw;
4300 /* Load DDP Package */
4301 if (firmware && !hw->pkg_copy) {
4302 state = ice_copy_and_init_pkg(hw, firmware->data,
4304 ice_log_pkg_init(hw, state);
4305 } else if (!firmware && hw->pkg_copy) {
4306 /* Reload package during rebuild after CORER/GLOBR reset */
4307 state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
4308 ice_log_pkg_init(hw, state);
4310 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
4313 if (!ice_is_init_pkg_successful(state)) {
4315 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4319 /* Successful download package is the precondition for advanced
4320 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
4322 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4326 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
4327 * @pf: pointer to the PF structure
4329 * There is no error returned here because the driver should be able to handle
4330 * 128 Byte cache lines, so we only print a warning in case issues are seen,
4331 * specifically with Tx.
4333 static void ice_verify_cacheline_size(struct ice_pf *pf)
4335 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
4336 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
4337 ICE_CACHE_LINE_BYTES);
4341 * ice_send_version - update firmware with driver version
4344 * Returns 0 on success, else error code
4346 static int ice_send_version(struct ice_pf *pf)
4348 struct ice_driver_ver dv;
4350 dv.major_ver = 0xff;
4351 dv.minor_ver = 0xff;
4352 dv.build_ver = 0xff;
4353 dv.subbuild_ver = 0;
4354 strscpy((char *)dv.driver_string, UTS_RELEASE,
4355 sizeof(dv.driver_string));
4356 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
4360 * ice_init_fdir - Initialize flow director VSI and configuration
4361 * @pf: pointer to the PF instance
4363 * returns 0 on success, negative on error
4365 static int ice_init_fdir(struct ice_pf *pf)
4367 struct device *dev = ice_pf_to_dev(pf);
4368 struct ice_vsi *ctrl_vsi;
4371 /* Side Band Flow Director needs to have a control VSI.
4372 * Allocate it and store it in the PF.
4374 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
4376 dev_dbg(dev, "could not create control VSI\n");
4380 err = ice_vsi_open_ctrl(ctrl_vsi);
4382 dev_dbg(dev, "could not open control VSI\n");
4386 mutex_init(&pf->hw.fdir_fltr_lock);
4388 err = ice_fdir_create_dflt_rules(pf);
4395 ice_fdir_release_flows(&pf->hw);
4396 ice_vsi_close(ctrl_vsi);
4398 ice_vsi_release(ctrl_vsi);
4399 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4400 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4401 pf->ctrl_vsi_idx = ICE_NO_VSI;
4407 * ice_get_opt_fw_name - return optional firmware file name or NULL
4408 * @pf: pointer to the PF instance
4410 static char *ice_get_opt_fw_name(struct ice_pf *pf)
4412 /* Optional firmware name same as default with additional dash
4413 * followed by a EUI-64 identifier (PCIe Device Serial Number)
4415 struct pci_dev *pdev = pf->pdev;
4416 char *opt_fw_filename;
4419 /* Determine the name of the optional file using the DSN (two
4420 * dwords following the start of the DSN Capability).
4422 dsn = pci_get_dsn(pdev);
4426 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
4427 if (!opt_fw_filename)
4430 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg",
4431 ICE_DDP_PKG_PATH, dsn);
4433 return opt_fw_filename;
4437 * ice_request_fw - Device initialization routine
4438 * @pf: pointer to the PF instance
4440 static void ice_request_fw(struct ice_pf *pf)
4442 char *opt_fw_filename = ice_get_opt_fw_name(pf);
4443 const struct firmware *firmware = NULL;
4444 struct device *dev = ice_pf_to_dev(pf);
4447 /* optional device-specific DDP (if present) overrides the default DDP
4448 * package file. kernel logs a debug message if the file doesn't exist,
4449 * and warning messages for other errors.
4451 if (opt_fw_filename) {
4452 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
4454 kfree(opt_fw_filename);
4458 /* request for firmware was successful. Download to device */
4459 ice_load_pkg(firmware, pf);
4460 kfree(opt_fw_filename);
4461 release_firmware(firmware);
4466 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
4468 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
4472 /* request for firmware was successful. Download to device */
4473 ice_load_pkg(firmware, pf);
4474 release_firmware(firmware);
4478 * ice_print_wake_reason - show the wake up cause in the log
4479 * @pf: pointer to the PF struct
4481 static void ice_print_wake_reason(struct ice_pf *pf)
4483 u32 wus = pf->wakeup_reason;
4484 const char *wake_str;
4486 /* if no wake event, nothing to print */
4490 if (wus & PFPM_WUS_LNKC_M)
4491 wake_str = "Link\n";
4492 else if (wus & PFPM_WUS_MAG_M)
4493 wake_str = "Magic Packet\n";
4494 else if (wus & PFPM_WUS_MNG_M)
4495 wake_str = "Management\n";
4496 else if (wus & PFPM_WUS_FW_RST_WK_M)
4497 wake_str = "Firmware Reset\n";
4499 wake_str = "Unknown\n";
4501 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
4505 * ice_register_netdev - register netdev and devlink port
4506 * @pf: pointer to the PF struct
4508 static int ice_register_netdev(struct ice_pf *pf)
4510 struct ice_vsi *vsi;
4513 vsi = ice_get_main_vsi(pf);
4514 if (!vsi || !vsi->netdev)
4517 err = register_netdev(vsi->netdev);
4519 goto err_register_netdev;
4521 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4522 netif_carrier_off(vsi->netdev);
4523 netif_tx_stop_all_queues(vsi->netdev);
4524 err = ice_devlink_create_pf_port(pf);
4526 goto err_devlink_create;
4528 devlink_port_type_eth_set(&pf->devlink_port, vsi->netdev);
4532 unregister_netdev(vsi->netdev);
4533 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4534 err_register_netdev:
4535 free_netdev(vsi->netdev);
4537 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4542 * ice_probe - Device initialization routine
4543 * @pdev: PCI device information struct
4544 * @ent: entry in ice_pci_tbl
4546 * Returns 0 on success, negative on failure
4549 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
4551 struct device *dev = &pdev->dev;
4556 if (pdev->is_virtfn) {
4557 dev_err(dev, "can't probe a virtual function\n");
4561 /* this driver uses devres, see
4562 * Documentation/driver-api/driver-model/devres.rst
4564 err = pcim_enable_device(pdev);
4568 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev));
4570 dev_err(dev, "BAR0 I/O map error %d\n", err);
4574 pf = ice_allocate_pf(dev);
4578 /* initialize Auxiliary index to invalid value */
4581 /* set up for high or low DMA */
4582 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
4584 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
4588 pci_enable_pcie_error_reporting(pdev);
4589 pci_set_master(pdev);
4592 pci_set_drvdata(pdev, pf);
4593 set_bit(ICE_DOWN, pf->state);
4594 /* Disable service task until DOWN bit is cleared */
4595 set_bit(ICE_SERVICE_DIS, pf->state);
4598 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
4599 pci_save_state(pdev);
4602 hw->vendor_id = pdev->vendor;
4603 hw->device_id = pdev->device;
4604 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
4605 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4606 hw->subsystem_device_id = pdev->subsystem_device;
4607 hw->bus.device = PCI_SLOT(pdev->devfn);
4608 hw->bus.func = PCI_FUNC(pdev->devfn);
4609 ice_set_ctrlq_len(hw);
4611 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
4613 #ifndef CONFIG_DYNAMIC_DEBUG
4615 hw->debug_mask = debug;
4618 err = ice_init_hw(hw);
4620 dev_err(dev, "ice_init_hw failed: %d\n", err);
4622 goto err_exit_unroll;
4625 ice_init_feature_support(pf);
4629 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
4630 * set in pf->state, which will cause ice_is_safe_mode to return
4633 if (ice_is_safe_mode(pf)) {
4634 /* we already got function/device capabilities but these don't
4635 * reflect what the driver needs to do in safe mode. Instead of
4636 * adding conditional logic everywhere to ignore these
4637 * device/function capabilities, override them.
4639 ice_set_safe_mode_caps(hw);
4642 err = ice_init_pf(pf);
4644 dev_err(dev, "ice_init_pf failed: %d\n", err);
4645 goto err_init_pf_unroll;
4648 ice_devlink_init_regions(pf);
4650 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port;
4651 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port;
4652 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
4653 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared;
4655 if (pf->hw.tnl.valid_count[TNL_VXLAN]) {
4656 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4657 pf->hw.tnl.valid_count[TNL_VXLAN];
4658 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4659 UDP_TUNNEL_TYPE_VXLAN;
4662 if (pf->hw.tnl.valid_count[TNL_GENEVE]) {
4663 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4664 pf->hw.tnl.valid_count[TNL_GENEVE];
4665 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4666 UDP_TUNNEL_TYPE_GENEVE;
4670 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
4671 if (!pf->num_alloc_vsi) {
4673 goto err_init_pf_unroll;
4675 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
4676 dev_warn(&pf->pdev->dev,
4677 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
4678 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
4679 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
4682 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
4686 goto err_init_pf_unroll;
4689 err = ice_init_interrupt_scheme(pf);
4691 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
4693 goto err_init_vsi_unroll;
4696 /* In case of MSIX we are going to setup the misc vector right here
4697 * to handle admin queue events etc. In case of legacy and MSI
4698 * the misc functionality and queue processing is combined in
4699 * the same vector and that gets setup at open.
4701 err = ice_req_irq_msix_misc(pf);
4703 dev_err(dev, "setup of misc vector failed: %d\n", err);
4704 goto err_init_interrupt_unroll;
4707 /* create switch struct for the switch element created by FW on boot */
4708 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
4709 if (!pf->first_sw) {
4711 goto err_msix_misc_unroll;
4715 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
4717 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
4719 pf->first_sw->pf = pf;
4721 /* record the sw_id available for later use */
4722 pf->first_sw->sw_id = hw->port_info->sw_id;
4724 err = ice_setup_pf_sw(pf);
4726 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
4727 goto err_alloc_sw_unroll;
4730 clear_bit(ICE_SERVICE_DIS, pf->state);
4732 /* tell the firmware we are up */
4733 err = ice_send_version(pf);
4735 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
4737 goto err_send_version_unroll;
4740 /* since everything is good, start the service timer */
4741 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4743 err = ice_init_link_events(pf->hw.port_info);
4745 dev_err(dev, "ice_init_link_events failed: %d\n", err);
4746 goto err_send_version_unroll;
4749 /* not a fatal error if this fails */
4750 err = ice_init_nvm_phy_type(pf->hw.port_info);
4752 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err);
4754 /* not a fatal error if this fails */
4755 err = ice_update_link_info(pf->hw.port_info);
4757 dev_err(dev, "ice_update_link_info failed: %d\n", err);
4759 ice_init_link_dflt_override(pf->hw.port_info);
4761 ice_check_link_cfg_err(pf,
4762 pf->hw.port_info->phy.link_info.link_cfg_err);
4764 /* if media available, initialize PHY settings */
4765 if (pf->hw.port_info->phy.link_info.link_info &
4766 ICE_AQ_MEDIA_AVAILABLE) {
4767 /* not a fatal error if this fails */
4768 err = ice_init_phy_user_cfg(pf->hw.port_info);
4770 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err);
4772 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) {
4773 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4776 ice_configure_phy(vsi);
4779 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
4782 ice_verify_cacheline_size(pf);
4784 /* Save wakeup reason register for later use */
4785 pf->wakeup_reason = rd32(hw, PFPM_WUS);
4787 /* check for a power management event */
4788 ice_print_wake_reason(pf);
4790 /* clear wake status, all bits */
4791 wr32(hw, PFPM_WUS, U32_MAX);
4793 /* Disable WoL at init, wait for user to enable */
4794 device_set_wakeup_enable(dev, false);
4796 if (ice_is_safe_mode(pf)) {
4797 ice_set_safe_mode_vlan_cfg(pf);
4801 /* initialize DDP driven features */
4802 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4805 if (ice_is_feature_supported(pf, ICE_F_GNSS))
4808 /* Note: Flow director init failure is non-fatal to load */
4809 if (ice_init_fdir(pf))
4810 dev_err(dev, "could not initialize flow director\n");
4812 /* Note: DCB init failure is non-fatal to load */
4813 if (ice_init_pf_dcb(pf, false)) {
4814 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4815 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
4817 ice_cfg_lldp_mib_change(&pf->hw, true);
4820 if (ice_init_lag(pf))
4821 dev_warn(dev, "Failed to init link aggregation support\n");
4823 /* print PCI link speed and width */
4824 pcie_print_link_status(pf->pdev);
4827 err = ice_register_netdev(pf);
4829 goto err_netdev_reg;
4831 err = ice_devlink_register_params(pf);
4833 goto err_netdev_reg;
4835 /* ready to go, so clear down state bit */
4836 clear_bit(ICE_DOWN, pf->state);
4837 if (ice_is_rdma_ena(pf)) {
4838 pf->aux_idx = ida_alloc(&ice_aux_ida, GFP_KERNEL);
4839 if (pf->aux_idx < 0) {
4840 dev_err(dev, "Failed to allocate device ID for AUX driver\n");
4842 goto err_devlink_reg_param;
4845 err = ice_init_rdma(pf);
4847 dev_err(dev, "Failed to initialize RDMA: %d\n", err);
4849 goto err_init_aux_unroll;
4852 dev_warn(dev, "RDMA is not supported on this device\n");
4855 ice_devlink_register(pf);
4858 err_init_aux_unroll:
4860 ida_free(&ice_aux_ida, pf->aux_idx);
4861 err_devlink_reg_param:
4862 ice_devlink_unregister_params(pf);
4864 err_send_version_unroll:
4865 ice_vsi_release_all(pf);
4866 err_alloc_sw_unroll:
4867 set_bit(ICE_SERVICE_DIS, pf->state);
4868 set_bit(ICE_DOWN, pf->state);
4869 devm_kfree(dev, pf->first_sw);
4870 err_msix_misc_unroll:
4871 ice_free_irq_msix_misc(pf);
4872 err_init_interrupt_unroll:
4873 ice_clear_interrupt_scheme(pf);
4874 err_init_vsi_unroll:
4875 devm_kfree(dev, pf->vsi);
4878 ice_devlink_destroy_regions(pf);
4881 pci_disable_pcie_error_reporting(pdev);
4882 pci_disable_device(pdev);
4887 * ice_set_wake - enable or disable Wake on LAN
4888 * @pf: pointer to the PF struct
4890 * Simple helper for WoL control
4892 static void ice_set_wake(struct ice_pf *pf)
4894 struct ice_hw *hw = &pf->hw;
4895 bool wol = pf->wol_ena;
4897 /* clear wake state, otherwise new wake events won't fire */
4898 wr32(hw, PFPM_WUS, U32_MAX);
4900 /* enable / disable APM wake up, no RMW needed */
4901 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0);
4903 /* set magic packet filter enabled */
4904 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0);
4908 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet
4909 * @pf: pointer to the PF struct
4911 * Issue firmware command to enable multicast magic wake, making
4912 * sure that any locally administered address (LAA) is used for
4913 * wake, and that PF reset doesn't undo the LAA.
4915 static void ice_setup_mc_magic_wake(struct ice_pf *pf)
4917 struct device *dev = ice_pf_to_dev(pf);
4918 struct ice_hw *hw = &pf->hw;
4919 u8 mac_addr[ETH_ALEN];
4920 struct ice_vsi *vsi;
4927 vsi = ice_get_main_vsi(pf);
4931 /* Get current MAC address in case it's an LAA */
4933 ether_addr_copy(mac_addr, vsi->netdev->dev_addr);
4935 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
4937 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN |
4938 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL |
4939 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP;
4941 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL);
4943 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %d aq_err %s\n",
4944 status, ice_aq_str(hw->adminq.sq_last_status));
4948 * ice_remove - Device removal routine
4949 * @pdev: PCI device information struct
4951 static void ice_remove(struct pci_dev *pdev)
4953 struct ice_pf *pf = pci_get_drvdata(pdev);
4956 ice_devlink_unregister(pf);
4957 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
4958 if (!ice_is_reset_in_progress(pf->state))
4963 ice_tc_indir_block_remove(pf);
4965 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4966 set_bit(ICE_VF_RESETS_DISABLED, pf->state);
4970 ice_service_task_stop(pf);
4972 ice_aq_cancel_waiting_tasks(pf);
4973 ice_unplug_aux_dev(pf);
4974 if (pf->aux_idx >= 0)
4975 ida_free(&ice_aux_ida, pf->aux_idx);
4976 ice_devlink_unregister_params(pf);
4977 set_bit(ICE_DOWN, pf->state);
4980 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4981 ice_ptp_release(pf);
4982 if (ice_is_feature_supported(pf, ICE_F_GNSS))
4984 if (!ice_is_safe_mode(pf))
4985 ice_remove_arfs(pf);
4986 ice_setup_mc_magic_wake(pf);
4987 ice_vsi_release_all(pf);
4988 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
4990 ice_free_irq_msix_misc(pf);
4991 ice_for_each_vsi(pf, i) {
4994 ice_vsi_free_q_vectors(pf->vsi[i]);
4997 ice_devlink_destroy_regions(pf);
4998 ice_deinit_hw(&pf->hw);
5000 /* Issue a PFR as part of the prescribed driver unload flow. Do not
5001 * do it via ice_schedule_reset() since there is no need to rebuild
5002 * and the service task is already stopped.
5004 ice_reset(&pf->hw, ICE_RESET_PFR);
5005 pci_wait_for_pending_transaction(pdev);
5006 ice_clear_interrupt_scheme(pf);
5007 pci_disable_pcie_error_reporting(pdev);
5008 pci_disable_device(pdev);
5012 * ice_shutdown - PCI callback for shutting down device
5013 * @pdev: PCI device information struct
5015 static void ice_shutdown(struct pci_dev *pdev)
5017 struct ice_pf *pf = pci_get_drvdata(pdev);
5021 if (system_state == SYSTEM_POWER_OFF) {
5022 pci_wake_from_d3(pdev, pf->wol_ena);
5023 pci_set_power_state(pdev, PCI_D3hot);
5029 * ice_prepare_for_shutdown - prep for PCI shutdown
5030 * @pf: board private structure
5032 * Inform or close all dependent features in prep for PCI device shutdown
5034 static void ice_prepare_for_shutdown(struct ice_pf *pf)
5036 struct ice_hw *hw = &pf->hw;
5039 /* Notify VFs of impending reset */
5040 if (ice_check_sq_alive(hw, &hw->mailboxq))
5041 ice_vc_notify_reset(pf);
5043 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n");
5045 /* disable the VSIs and their queues that are not already DOWN */
5046 ice_pf_dis_all_vsi(pf, false);
5048 ice_for_each_vsi(pf, v)
5050 pf->vsi[v]->vsi_num = 0;
5052 ice_shutdown_all_ctrlq(hw);
5056 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme
5057 * @pf: board private structure to reinitialize
5059 * This routine reinitialize interrupt scheme that was cleared during
5060 * power management suspend callback.
5062 * This should be called during resume routine to re-allocate the q_vectors
5063 * and reacquire interrupts.
5065 static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
5067 struct device *dev = ice_pf_to_dev(pf);
5070 /* Since we clear MSIX flag during suspend, we need to
5071 * set it back during resume...
5074 ret = ice_init_interrupt_scheme(pf);
5076 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret);
5080 /* Remap vectors and rings, after successful re-init interrupts */
5081 ice_for_each_vsi(pf, v) {
5085 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]);
5088 ice_vsi_map_rings_to_vectors(pf->vsi[v]);
5091 ret = ice_req_irq_msix_misc(pf);
5093 dev_err(dev, "Setting up misc vector failed after device suspend %d\n",
5103 ice_vsi_free_q_vectors(pf->vsi[v]);
5110 * @dev: generic device information structure
5112 * Power Management callback to quiesce the device and prepare
5113 * for D3 transition.
5115 static int __maybe_unused ice_suspend(struct device *dev)
5117 struct pci_dev *pdev = to_pci_dev(dev);
5121 pf = pci_get_drvdata(pdev);
5123 if (!ice_pf_state_is_nominal(pf)) {
5124 dev_err(dev, "Device is not ready, no need to suspend it\n");
5128 /* Stop watchdog tasks until resume completion.
5129 * Even though it is most likely that the service task is
5130 * disabled if the device is suspended or down, the service task's
5131 * state is controlled by a different state bit, and we should
5132 * store and honor whatever state that bit is in at this point.
5134 disabled = ice_service_task_stop(pf);
5136 ice_unplug_aux_dev(pf);
5138 /* Already suspended?, then there is nothing to do */
5139 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) {
5141 ice_service_task_restart(pf);
5145 if (test_bit(ICE_DOWN, pf->state) ||
5146 ice_is_reset_in_progress(pf->state)) {
5147 dev_err(dev, "can't suspend device in reset or already down\n");
5149 ice_service_task_restart(pf);
5153 ice_setup_mc_magic_wake(pf);
5155 ice_prepare_for_shutdown(pf);
5159 /* Free vectors, clear the interrupt scheme and release IRQs
5160 * for proper hibernation, especially with large number of CPUs.
5161 * Otherwise hibernation might fail when mapping all the vectors back
5164 ice_free_irq_msix_misc(pf);
5165 ice_for_each_vsi(pf, v) {
5168 ice_vsi_free_q_vectors(pf->vsi[v]);
5170 ice_free_cpu_rx_rmap(ice_get_main_vsi(pf));
5171 ice_clear_interrupt_scheme(pf);
5173 pci_save_state(pdev);
5174 pci_wake_from_d3(pdev, pf->wol_ena);
5175 pci_set_power_state(pdev, PCI_D3hot);
5180 * ice_resume - PM callback for waking up from D3
5181 * @dev: generic device information structure
5183 static int __maybe_unused ice_resume(struct device *dev)
5185 struct pci_dev *pdev = to_pci_dev(dev);
5186 enum ice_reset_req reset_type;
5191 pci_set_power_state(pdev, PCI_D0);
5192 pci_restore_state(pdev);
5193 pci_save_state(pdev);
5195 if (!pci_device_is_present(pdev))
5198 ret = pci_enable_device_mem(pdev);
5200 dev_err(dev, "Cannot enable device after suspend\n");
5204 pf = pci_get_drvdata(pdev);
5207 pf->wakeup_reason = rd32(hw, PFPM_WUS);
5208 ice_print_wake_reason(pf);
5210 /* We cleared the interrupt scheme when we suspended, so we need to
5211 * restore it now to resume device functionality.
5213 ret = ice_reinit_interrupt_scheme(pf);
5215 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret);
5217 clear_bit(ICE_DOWN, pf->state);
5218 /* Now perform PF reset and rebuild */
5219 reset_type = ICE_RESET_PFR;
5220 /* re-enable service task for reset, but allow reset to schedule it */
5221 clear_bit(ICE_SERVICE_DIS, pf->state);
5223 if (ice_schedule_reset(pf, reset_type))
5224 dev_err(dev, "Reset during resume failed.\n");
5226 clear_bit(ICE_SUSPENDED, pf->state);
5227 ice_service_task_restart(pf);
5229 /* Restart the service task */
5230 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5234 #endif /* CONFIG_PM */
5237 * ice_pci_err_detected - warning that PCI error has been detected
5238 * @pdev: PCI device information struct
5239 * @err: the type of PCI error
5241 * Called to warn that something happened on the PCI bus and the error handling
5242 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
5244 static pci_ers_result_t
5245 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err)
5247 struct ice_pf *pf = pci_get_drvdata(pdev);
5250 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
5252 return PCI_ERS_RESULT_DISCONNECT;
5255 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5256 ice_service_task_stop(pf);
5258 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5259 set_bit(ICE_PFR_REQ, pf->state);
5260 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5264 return PCI_ERS_RESULT_NEED_RESET;
5268 * ice_pci_err_slot_reset - a PCI slot reset has just happened
5269 * @pdev: PCI device information struct
5271 * Called to determine if the driver can recover from the PCI slot reset by
5272 * using a register read to determine if the device is recoverable.
5274 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
5276 struct ice_pf *pf = pci_get_drvdata(pdev);
5277 pci_ers_result_t result;
5281 err = pci_enable_device_mem(pdev);
5283 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
5285 result = PCI_ERS_RESULT_DISCONNECT;
5287 pci_set_master(pdev);
5288 pci_restore_state(pdev);
5289 pci_save_state(pdev);
5290 pci_wake_from_d3(pdev, false);
5292 /* Check for life */
5293 reg = rd32(&pf->hw, GLGEN_RTRIG);
5295 result = PCI_ERS_RESULT_RECOVERED;
5297 result = PCI_ERS_RESULT_DISCONNECT;
5300 err = pci_aer_clear_nonfatal_status(pdev);
5302 dev_dbg(&pdev->dev, "pci_aer_clear_nonfatal_status() failed, error %d\n",
5304 /* non-fatal, continue */
5310 * ice_pci_err_resume - restart operations after PCI error recovery
5311 * @pdev: PCI device information struct
5313 * Called to allow the driver to bring things back up after PCI error and/or
5314 * reset recovery have finished
5316 static void ice_pci_err_resume(struct pci_dev *pdev)
5318 struct ice_pf *pf = pci_get_drvdata(pdev);
5321 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
5326 if (test_bit(ICE_SUSPENDED, pf->state)) {
5327 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
5332 ice_restore_all_vfs_msi_state(pdev);
5334 ice_do_reset(pf, ICE_RESET_PFR);
5335 ice_service_task_restart(pf);
5336 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5340 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
5341 * @pdev: PCI device information struct
5343 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
5345 struct ice_pf *pf = pci_get_drvdata(pdev);
5347 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5348 ice_service_task_stop(pf);
5350 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5351 set_bit(ICE_PFR_REQ, pf->state);
5352 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5358 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
5359 * @pdev: PCI device information struct
5361 static void ice_pci_err_reset_done(struct pci_dev *pdev)
5363 ice_pci_err_resume(pdev);
5366 /* ice_pci_tbl - PCI Device ID Table
5368 * Wildcard entries (PCI_ANY_ID) should come last
5369 * Last entry must be all 0s
5371 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
5372 * Class, Class Mask, private data (not used) }
5374 static const struct pci_device_id ice_pci_tbl[] = {
5375 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
5376 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
5377 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
5378 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_BACKPLANE), 0 },
5379 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_QSFP), 0 },
5380 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 },
5381 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 },
5382 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 },
5383 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 },
5384 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 },
5385 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 },
5386 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
5387 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
5388 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
5389 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
5390 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
5391 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 },
5392 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
5393 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
5394 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
5395 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 },
5396 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 },
5397 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 },
5398 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 },
5399 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 },
5400 /* required last entry */
5403 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
5405 static __maybe_unused SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume);
5407 static const struct pci_error_handlers ice_pci_err_handler = {
5408 .error_detected = ice_pci_err_detected,
5409 .slot_reset = ice_pci_err_slot_reset,
5410 .reset_prepare = ice_pci_err_reset_prepare,
5411 .reset_done = ice_pci_err_reset_done,
5412 .resume = ice_pci_err_resume
5415 static struct pci_driver ice_driver = {
5416 .name = KBUILD_MODNAME,
5417 .id_table = ice_pci_tbl,
5419 .remove = ice_remove,
5421 .driver.pm = &ice_pm_ops,
5422 #endif /* CONFIG_PM */
5423 .shutdown = ice_shutdown,
5424 .sriov_configure = ice_sriov_configure,
5425 .err_handler = &ice_pci_err_handler
5429 * ice_module_init - Driver registration routine
5431 * ice_module_init is the first routine called when the driver is
5432 * loaded. All it does is register with the PCI subsystem.
5434 static int __init ice_module_init(void)
5438 pr_info("%s\n", ice_driver_string);
5439 pr_info("%s\n", ice_copyright);
5441 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
5443 pr_err("Failed to create workqueue\n");
5447 status = pci_register_driver(&ice_driver);
5449 pr_err("failed to register PCI driver, err %d\n", status);
5450 destroy_workqueue(ice_wq);
5455 module_init(ice_module_init);
5458 * ice_module_exit - Driver exit cleanup routine
5460 * ice_module_exit is called just before the driver is removed
5463 static void __exit ice_module_exit(void)
5465 pci_unregister_driver(&ice_driver);
5466 destroy_workqueue(ice_wq);
5467 pr_info("module unloaded\n");
5469 module_exit(ice_module_exit);
5472 * ice_set_mac_address - NDO callback to set MAC address
5473 * @netdev: network interface device structure
5474 * @pi: pointer to an address structure
5476 * Returns 0 on success, negative on failure
5478 static int ice_set_mac_address(struct net_device *netdev, void *pi)
5480 struct ice_netdev_priv *np = netdev_priv(netdev);
5481 struct ice_vsi *vsi = np->vsi;
5482 struct ice_pf *pf = vsi->back;
5483 struct ice_hw *hw = &pf->hw;
5484 struct sockaddr *addr = pi;
5485 u8 old_mac[ETH_ALEN];
5490 mac = (u8 *)addr->sa_data;
5492 if (!is_valid_ether_addr(mac))
5493 return -EADDRNOTAVAIL;
5495 if (ether_addr_equal(netdev->dev_addr, mac)) {
5496 netdev_dbg(netdev, "already using mac %pM\n", mac);
5500 if (test_bit(ICE_DOWN, pf->state) ||
5501 ice_is_reset_in_progress(pf->state)) {
5502 netdev_err(netdev, "can't set mac %pM. device not ready\n",
5507 if (ice_chnl_dmac_fltr_cnt(pf)) {
5508 netdev_err(netdev, "can't set mac %pM. Device has tc-flower filters, delete all of them and try again\n",
5513 netif_addr_lock_bh(netdev);
5514 ether_addr_copy(old_mac, netdev->dev_addr);
5515 /* change the netdev's MAC address */
5516 eth_hw_addr_set(netdev, mac);
5517 netif_addr_unlock_bh(netdev);
5519 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
5520 err = ice_fltr_remove_mac(vsi, old_mac, ICE_FWD_TO_VSI);
5521 if (err && err != -ENOENT) {
5522 err = -EADDRNOTAVAIL;
5523 goto err_update_filters;
5526 /* Add filter for new MAC. If filter exists, return success */
5527 err = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
5528 if (err == -EEXIST) {
5529 /* Although this MAC filter is already present in hardware it's
5530 * possible in some cases (e.g. bonding) that dev_addr was
5531 * modified outside of the driver and needs to be restored back
5534 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
5538 /* error if the new filter addition failed */
5539 err = -EADDRNOTAVAIL;
5544 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
5546 netif_addr_lock_bh(netdev);
5547 eth_hw_addr_set(netdev, old_mac);
5548 netif_addr_unlock_bh(netdev);
5552 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
5555 /* write new MAC address to the firmware */
5556 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
5557 err = ice_aq_manage_mac_write(hw, mac, flags, NULL);
5559 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
5566 * ice_set_rx_mode - NDO callback to set the netdev filters
5567 * @netdev: network interface device structure
5569 static void ice_set_rx_mode(struct net_device *netdev)
5571 struct ice_netdev_priv *np = netdev_priv(netdev);
5572 struct ice_vsi *vsi = np->vsi;
5577 /* Set the flags to synchronize filters
5578 * ndo_set_rx_mode may be triggered even without a change in netdev
5581 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
5582 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
5583 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
5585 /* schedule our worker thread which will take care of
5586 * applying the new filter changes
5588 ice_service_task_schedule(vsi->back);
5592 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
5593 * @netdev: network interface device structure
5594 * @queue_index: Queue ID
5595 * @maxrate: maximum bandwidth in Mbps
5598 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
5600 struct ice_netdev_priv *np = netdev_priv(netdev);
5601 struct ice_vsi *vsi = np->vsi;
5606 /* Validate maxrate requested is within permitted range */
5607 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
5608 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
5609 maxrate, queue_index);
5613 q_handle = vsi->tx_rings[queue_index]->q_handle;
5614 tc = ice_dcb_get_tc(vsi, queue_index);
5616 /* Set BW back to default, when user set maxrate to 0 */
5618 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
5619 q_handle, ICE_MAX_BW);
5621 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
5622 q_handle, ICE_MAX_BW, maxrate * 1000);
5624 netdev_err(netdev, "Unable to set Tx max rate, error %d\n",
5631 * ice_fdb_add - add an entry to the hardware database
5632 * @ndm: the input from the stack
5633 * @tb: pointer to array of nladdr (unused)
5634 * @dev: the net device pointer
5635 * @addr: the MAC address entry being added
5637 * @flags: instructions from stack about fdb operation
5638 * @extack: netlink extended ack
5641 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
5642 struct net_device *dev, const unsigned char *addr, u16 vid,
5643 u16 flags, struct netlink_ext_ack __always_unused *extack)
5648 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
5651 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
5652 netdev_err(dev, "FDB only supports static addresses\n");
5656 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
5657 err = dev_uc_add_excl(dev, addr);
5658 else if (is_multicast_ether_addr(addr))
5659 err = dev_mc_add_excl(dev, addr);
5663 /* Only return duplicate errors if NLM_F_EXCL is set */
5664 if (err == -EEXIST && !(flags & NLM_F_EXCL))
5671 * ice_fdb_del - delete an entry from the hardware database
5672 * @ndm: the input from the stack
5673 * @tb: pointer to array of nladdr (unused)
5674 * @dev: the net device pointer
5675 * @addr: the MAC address entry being added
5679 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
5680 struct net_device *dev, const unsigned char *addr,
5681 __always_unused u16 vid)
5685 if (ndm->ndm_state & NUD_PERMANENT) {
5686 netdev_err(dev, "FDB only supports static addresses\n");
5690 if (is_unicast_ether_addr(addr))
5691 err = dev_uc_del(dev, addr);
5692 else if (is_multicast_ether_addr(addr))
5693 err = dev_mc_del(dev, addr);
5700 #define NETIF_VLAN_OFFLOAD_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \
5701 NETIF_F_HW_VLAN_CTAG_TX | \
5702 NETIF_F_HW_VLAN_STAG_RX | \
5703 NETIF_F_HW_VLAN_STAG_TX)
5705 #define NETIF_VLAN_FILTERING_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
5706 NETIF_F_HW_VLAN_STAG_FILTER)
5709 * ice_fix_features - fix the netdev features flags based on device limitations
5710 * @netdev: ptr to the netdev that flags are being fixed on
5711 * @features: features that need to be checked and possibly fixed
5713 * Make sure any fixups are made to features in this callback. This enables the
5714 * driver to not have to check unsupported configurations throughout the driver
5715 * because that's the responsiblity of this callback.
5717 * Single VLAN Mode (SVM) Supported Features:
5718 * NETIF_F_HW_VLAN_CTAG_FILTER
5719 * NETIF_F_HW_VLAN_CTAG_RX
5720 * NETIF_F_HW_VLAN_CTAG_TX
5722 * Double VLAN Mode (DVM) Supported Features:
5723 * NETIF_F_HW_VLAN_CTAG_FILTER
5724 * NETIF_F_HW_VLAN_CTAG_RX
5725 * NETIF_F_HW_VLAN_CTAG_TX
5727 * NETIF_F_HW_VLAN_STAG_FILTER
5728 * NETIF_HW_VLAN_STAG_RX
5729 * NETIF_HW_VLAN_STAG_TX
5731 * Features that need fixing:
5732 * Cannot simultaneously enable CTAG and STAG stripping and/or insertion.
5733 * These are mutually exlusive as the VSI context cannot support multiple
5734 * VLAN ethertypes simultaneously for stripping and/or insertion. If this
5735 * is not done, then default to clearing the requested STAG offload
5738 * All supported filtering has to be enabled or disabled together. For
5739 * example, in DVM, CTAG and STAG filtering have to be enabled and disabled
5740 * together. If this is not done, then default to VLAN filtering disabled.
5741 * These are mutually exclusive as there is currently no way to
5742 * enable/disable VLAN filtering based on VLAN ethertype when using VLAN
5745 static netdev_features_t
5746 ice_fix_features(struct net_device *netdev, netdev_features_t features)
5748 struct ice_netdev_priv *np = netdev_priv(netdev);
5749 netdev_features_t supported_vlan_filtering;
5750 netdev_features_t requested_vlan_filtering;
5751 struct ice_vsi *vsi = np->vsi;
5753 requested_vlan_filtering = features & NETIF_VLAN_FILTERING_FEATURES;
5755 /* make sure supported_vlan_filtering works for both SVM and DVM */
5756 supported_vlan_filtering = NETIF_F_HW_VLAN_CTAG_FILTER;
5757 if (ice_is_dvm_ena(&vsi->back->hw))
5758 supported_vlan_filtering |= NETIF_F_HW_VLAN_STAG_FILTER;
5760 if (requested_vlan_filtering &&
5761 requested_vlan_filtering != supported_vlan_filtering) {
5762 if (requested_vlan_filtering & NETIF_F_HW_VLAN_CTAG_FILTER) {
5763 netdev_warn(netdev, "cannot support requested VLAN filtering settings, enabling all supported VLAN filtering settings\n");
5764 features |= supported_vlan_filtering;
5766 netdev_warn(netdev, "cannot support requested VLAN filtering settings, clearing all supported VLAN filtering settings\n");
5767 features &= ~supported_vlan_filtering;
5771 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) &&
5772 (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))) {
5773 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");
5774 features &= ~(NETIF_F_HW_VLAN_STAG_RX |
5775 NETIF_F_HW_VLAN_STAG_TX);
5782 * ice_set_vlan_offload_features - set VLAN offload features for the PF VSI
5784 * @features: features used to determine VLAN offload settings
5786 * First, determine the vlan_ethertype based on the VLAN offload bits in
5787 * features. Then determine if stripping and insertion should be enabled or
5788 * disabled. Finally enable or disable VLAN stripping and insertion.
5791 ice_set_vlan_offload_features(struct ice_vsi *vsi, netdev_features_t features)
5793 bool enable_stripping = true, enable_insertion = true;
5794 struct ice_vsi_vlan_ops *vlan_ops;
5795 int strip_err = 0, insert_err = 0;
5796 u16 vlan_ethertype = 0;
5798 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5800 if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
5801 vlan_ethertype = ETH_P_8021AD;
5802 else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
5803 vlan_ethertype = ETH_P_8021Q;
5805 if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
5806 enable_stripping = false;
5807 if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
5808 enable_insertion = false;
5810 if (enable_stripping)
5811 strip_err = vlan_ops->ena_stripping(vsi, vlan_ethertype);
5813 strip_err = vlan_ops->dis_stripping(vsi);
5815 if (enable_insertion)
5816 insert_err = vlan_ops->ena_insertion(vsi, vlan_ethertype);
5818 insert_err = vlan_ops->dis_insertion(vsi);
5820 if (strip_err || insert_err)
5827 * ice_set_vlan_filtering_features - set VLAN filtering features for the PF VSI
5829 * @features: features used to determine VLAN filtering settings
5831 * Enable or disable Rx VLAN filtering based on the VLAN filtering bits in the
5835 ice_set_vlan_filtering_features(struct ice_vsi *vsi, netdev_features_t features)
5837 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5840 /* support Single VLAN Mode (SVM) and Double VLAN Mode (DVM) by checking
5841 * if either bit is set
5844 (NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER))
5845 err = vlan_ops->ena_rx_filtering(vsi);
5847 err = vlan_ops->dis_rx_filtering(vsi);
5853 * ice_set_vlan_features - set VLAN settings based on suggested feature set
5854 * @netdev: ptr to the netdev being adjusted
5855 * @features: the feature set that the stack is suggesting
5857 * Only update VLAN settings if the requested_vlan_features are different than
5858 * the current_vlan_features.
5861 ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
5863 netdev_features_t current_vlan_features, requested_vlan_features;
5864 struct ice_netdev_priv *np = netdev_priv(netdev);
5865 struct ice_vsi *vsi = np->vsi;
5868 current_vlan_features = netdev->features & NETIF_VLAN_OFFLOAD_FEATURES;
5869 requested_vlan_features = features & NETIF_VLAN_OFFLOAD_FEATURES;
5870 if (current_vlan_features ^ requested_vlan_features) {
5871 err = ice_set_vlan_offload_features(vsi, features);
5876 current_vlan_features = netdev->features &
5877 NETIF_VLAN_FILTERING_FEATURES;
5878 requested_vlan_features = features & NETIF_VLAN_FILTERING_FEATURES;
5879 if (current_vlan_features ^ requested_vlan_features) {
5880 err = ice_set_vlan_filtering_features(vsi, features);
5889 * ice_set_features - set the netdev feature flags
5890 * @netdev: ptr to the netdev being adjusted
5891 * @features: the feature set that the stack is suggesting
5894 ice_set_features(struct net_device *netdev, netdev_features_t features)
5896 struct ice_netdev_priv *np = netdev_priv(netdev);
5897 struct ice_vsi *vsi = np->vsi;
5898 struct ice_pf *pf = vsi->back;
5901 /* Don't set any netdev advanced features with device in Safe Mode */
5902 if (ice_is_safe_mode(vsi->back)) {
5903 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
5907 /* Do not change setting during reset */
5908 if (ice_is_reset_in_progress(pf->state)) {
5909 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
5913 /* Multiple features can be changed in one call so keep features in
5914 * separate if/else statements to guarantee each feature is checked
5916 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
5917 ice_vsi_manage_rss_lut(vsi, true);
5918 else if (!(features & NETIF_F_RXHASH) &&
5919 netdev->features & NETIF_F_RXHASH)
5920 ice_vsi_manage_rss_lut(vsi, false);
5922 ret = ice_set_vlan_features(netdev, features);
5926 if ((features & NETIF_F_NTUPLE) &&
5927 !(netdev->features & NETIF_F_NTUPLE)) {
5928 ice_vsi_manage_fdir(vsi, true);
5930 } else if (!(features & NETIF_F_NTUPLE) &&
5931 (netdev->features & NETIF_F_NTUPLE)) {
5932 ice_vsi_manage_fdir(vsi, false);
5933 ice_clear_arfs(vsi);
5936 /* don't turn off hw_tc_offload when ADQ is already enabled */
5937 if (!(features & NETIF_F_HW_TC) && ice_is_adq_active(pf)) {
5938 dev_err(ice_pf_to_dev(pf), "ADQ is active, can't turn hw_tc_offload off\n");
5942 if ((features & NETIF_F_HW_TC) &&
5943 !(netdev->features & NETIF_F_HW_TC))
5944 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5946 clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5952 * ice_vsi_vlan_setup - Setup VLAN offload properties on a PF VSI
5953 * @vsi: VSI to setup VLAN properties for
5955 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
5959 err = ice_set_vlan_offload_features(vsi, vsi->netdev->features);
5963 err = ice_set_vlan_filtering_features(vsi, vsi->netdev->features);
5967 return ice_vsi_add_vlan_zero(vsi);
5971 * ice_vsi_cfg - Setup the VSI
5972 * @vsi: the VSI being configured
5974 * Return 0 on success and negative value on error
5976 int ice_vsi_cfg(struct ice_vsi *vsi)
5981 ice_set_rx_mode(vsi->netdev);
5983 err = ice_vsi_vlan_setup(vsi);
5988 ice_vsi_cfg_dcb_rings(vsi);
5990 err = ice_vsi_cfg_lan_txqs(vsi);
5991 if (!err && ice_is_xdp_ena_vsi(vsi))
5992 err = ice_vsi_cfg_xdp_txqs(vsi);
5994 err = ice_vsi_cfg_rxqs(vsi);
5999 /* THEORY OF MODERATION:
6000 * The ice driver hardware works differently than the hardware that DIMLIB was
6001 * originally made for. ice hardware doesn't have packet count limits that
6002 * can trigger an interrupt, but it *does* have interrupt rate limit support,
6003 * which is hard-coded to a limit of 250,000 ints/second.
6004 * If not using dynamic moderation, the INTRL value can be modified
6005 * by ethtool rx-usecs-high.
6008 /* the throttle rate for interrupts, basically worst case delay before
6009 * an initial interrupt fires, value is stored in microseconds.
6014 /* Make a different profile for Rx that doesn't allow quite so aggressive
6015 * moderation at the high end (it maxes out at 126us or about 8k interrupts a
6018 static const struct ice_dim rx_profile[] = {
6019 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6020 {8}, /* 125,000 ints/s */
6021 {16}, /* 62,500 ints/s */
6022 {62}, /* 16,129 ints/s */
6023 {126} /* 7,936 ints/s */
6026 /* The transmit profile, which has the same sorts of values
6027 * as the previous struct
6029 static const struct ice_dim tx_profile[] = {
6030 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6031 {8}, /* 125,000 ints/s */
6032 {40}, /* 16,125 ints/s */
6033 {128}, /* 7,812 ints/s */
6034 {256} /* 3,906 ints/s */
6037 static void ice_tx_dim_work(struct work_struct *work)
6039 struct ice_ring_container *rc;
6043 dim = container_of(work, struct dim, work);
6044 rc = (struct ice_ring_container *)dim->priv;
6046 WARN_ON(dim->profile_ix >= ARRAY_SIZE(tx_profile));
6048 /* look up the values in our local table */
6049 itr = tx_profile[dim->profile_ix].itr;
6051 ice_trace(tx_dim_work, container_of(rc, struct ice_q_vector, tx), dim);
6052 ice_write_itr(rc, itr);
6054 dim->state = DIM_START_MEASURE;
6057 static void ice_rx_dim_work(struct work_struct *work)
6059 struct ice_ring_container *rc;
6063 dim = container_of(work, struct dim, work);
6064 rc = (struct ice_ring_container *)dim->priv;
6066 WARN_ON(dim->profile_ix >= ARRAY_SIZE(rx_profile));
6068 /* look up the values in our local table */
6069 itr = rx_profile[dim->profile_ix].itr;
6071 ice_trace(rx_dim_work, container_of(rc, struct ice_q_vector, rx), dim);
6072 ice_write_itr(rc, itr);
6074 dim->state = DIM_START_MEASURE;
6077 #define ICE_DIM_DEFAULT_PROFILE_IX 1
6080 * ice_init_moderation - set up interrupt moderation
6081 * @q_vector: the vector containing rings to be configured
6083 * Set up interrupt moderation registers, with the intent to do the right thing
6084 * when called from reset or from probe, and whether or not dynamic moderation
6085 * is enabled or not. Take special care to write all the registers in both
6086 * dynamic moderation mode or not in order to make sure hardware is in a known
6089 static void ice_init_moderation(struct ice_q_vector *q_vector)
6091 struct ice_ring_container *rc;
6092 bool tx_dynamic, rx_dynamic;
6095 INIT_WORK(&rc->dim.work, ice_tx_dim_work);
6096 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6097 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6099 tx_dynamic = ITR_IS_DYNAMIC(rc);
6101 /* set the initial TX ITR to match the above */
6102 ice_write_itr(rc, tx_dynamic ?
6103 tx_profile[rc->dim.profile_ix].itr : rc->itr_setting);
6106 INIT_WORK(&rc->dim.work, ice_rx_dim_work);
6107 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6108 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6110 rx_dynamic = ITR_IS_DYNAMIC(rc);
6112 /* set the initial RX ITR to match the above */
6113 ice_write_itr(rc, rx_dynamic ? rx_profile[rc->dim.profile_ix].itr :
6116 ice_set_q_vector_intrl(q_vector);
6120 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
6121 * @vsi: the VSI being configured
6123 static void ice_napi_enable_all(struct ice_vsi *vsi)
6130 ice_for_each_q_vector(vsi, q_idx) {
6131 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6133 ice_init_moderation(q_vector);
6135 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6136 napi_enable(&q_vector->napi);
6141 * ice_up_complete - Finish the last steps of bringing up a connection
6142 * @vsi: The VSI being configured
6144 * Return 0 on success and negative value on error
6146 static int ice_up_complete(struct ice_vsi *vsi)
6148 struct ice_pf *pf = vsi->back;
6151 ice_vsi_cfg_msix(vsi);
6153 /* Enable only Rx rings, Tx rings were enabled by the FW when the
6154 * Tx queue group list was configured and the context bits were
6155 * programmed using ice_vsi_cfg_txqs
6157 err = ice_vsi_start_all_rx_rings(vsi);
6161 clear_bit(ICE_VSI_DOWN, vsi->state);
6162 ice_napi_enable_all(vsi);
6163 ice_vsi_ena_irq(vsi);
6165 if (vsi->port_info &&
6166 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
6168 ice_print_link_msg(vsi, true);
6169 netif_tx_start_all_queues(vsi->netdev);
6170 netif_carrier_on(vsi->netdev);
6171 if (!ice_is_e810(&pf->hw))
6172 ice_ptp_link_change(pf, pf->hw.pf_id, true);
6175 /* clear this now, and the first stats read will be used as baseline */
6176 vsi->stat_offsets_loaded = false;
6178 ice_service_task_schedule(pf);
6184 * ice_up - Bring the connection back up after being down
6185 * @vsi: VSI being configured
6187 int ice_up(struct ice_vsi *vsi)
6191 err = ice_vsi_cfg(vsi);
6193 err = ice_up_complete(vsi);
6199 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
6200 * @syncp: pointer to u64_stats_sync
6201 * @stats: stats that pkts and bytes count will be taken from
6202 * @pkts: packets stats counter
6203 * @bytes: bytes stats counter
6205 * This function fetches stats from the ring considering the atomic operations
6206 * that needs to be performed to read u64 values in 32 bit machine.
6209 ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp,
6210 struct ice_q_stats stats, u64 *pkts, u64 *bytes)
6215 start = u64_stats_fetch_begin_irq(syncp);
6217 *bytes = stats.bytes;
6218 } while (u64_stats_fetch_retry_irq(syncp, start));
6222 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters
6223 * @vsi: the VSI to be updated
6224 * @vsi_stats: the stats struct to be updated
6225 * @rings: rings to work on
6226 * @count: number of rings
6229 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
6230 struct rtnl_link_stats64 *vsi_stats,
6231 struct ice_tx_ring **rings, u16 count)
6235 for (i = 0; i < count; i++) {
6236 struct ice_tx_ring *ring;
6237 u64 pkts = 0, bytes = 0;
6239 ring = READ_ONCE(rings[i]);
6242 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6243 vsi_stats->tx_packets += pkts;
6244 vsi_stats->tx_bytes += bytes;
6245 vsi->tx_restart += ring->tx_stats.restart_q;
6246 vsi->tx_busy += ring->tx_stats.tx_busy;
6247 vsi->tx_linearize += ring->tx_stats.tx_linearize;
6252 * ice_update_vsi_ring_stats - Update VSI stats counters
6253 * @vsi: the VSI to be updated
6255 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
6257 struct rtnl_link_stats64 *vsi_stats;
6261 vsi_stats = kzalloc(sizeof(*vsi_stats), GFP_ATOMIC);
6265 /* reset non-netdev (extended) stats */
6266 vsi->tx_restart = 0;
6268 vsi->tx_linearize = 0;
6269 vsi->rx_buf_failed = 0;
6270 vsi->rx_page_failed = 0;
6274 /* update Tx rings counters */
6275 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->tx_rings,
6278 /* update Rx rings counters */
6279 ice_for_each_rxq(vsi, i) {
6280 struct ice_rx_ring *ring = READ_ONCE(vsi->rx_rings[i]);
6282 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6283 vsi_stats->rx_packets += pkts;
6284 vsi_stats->rx_bytes += bytes;
6285 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
6286 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
6289 /* update XDP Tx rings counters */
6290 if (ice_is_xdp_ena_vsi(vsi))
6291 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->xdp_rings,
6296 vsi->net_stats.tx_packets = vsi_stats->tx_packets;
6297 vsi->net_stats.tx_bytes = vsi_stats->tx_bytes;
6298 vsi->net_stats.rx_packets = vsi_stats->rx_packets;
6299 vsi->net_stats.rx_bytes = vsi_stats->rx_bytes;
6305 * ice_update_vsi_stats - Update VSI stats counters
6306 * @vsi: the VSI to be updated
6308 void ice_update_vsi_stats(struct ice_vsi *vsi)
6310 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
6311 struct ice_eth_stats *cur_es = &vsi->eth_stats;
6312 struct ice_pf *pf = vsi->back;
6314 if (test_bit(ICE_VSI_DOWN, vsi->state) ||
6315 test_bit(ICE_CFG_BUSY, pf->state))
6318 /* get stats as recorded by Tx/Rx rings */
6319 ice_update_vsi_ring_stats(vsi);
6321 /* get VSI stats as recorded by the hardware */
6322 ice_update_eth_stats(vsi);
6324 cur_ns->tx_errors = cur_es->tx_errors;
6325 cur_ns->rx_dropped = cur_es->rx_discards;
6326 cur_ns->tx_dropped = cur_es->tx_discards;
6327 cur_ns->multicast = cur_es->rx_multicast;
6329 /* update some more netdev stats if this is main VSI */
6330 if (vsi->type == ICE_VSI_PF) {
6331 cur_ns->rx_crc_errors = pf->stats.crc_errors;
6332 cur_ns->rx_errors = pf->stats.crc_errors +
6333 pf->stats.illegal_bytes +
6334 pf->stats.rx_len_errors +
6335 pf->stats.rx_undersize +
6336 pf->hw_csum_rx_error +
6337 pf->stats.rx_jabber +
6338 pf->stats.rx_fragments +
6339 pf->stats.rx_oversize;
6340 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
6341 /* record drops from the port level */
6342 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
6347 * ice_update_pf_stats - Update PF port stats counters
6348 * @pf: PF whose stats needs to be updated
6350 void ice_update_pf_stats(struct ice_pf *pf)
6352 struct ice_hw_port_stats *prev_ps, *cur_ps;
6353 struct ice_hw *hw = &pf->hw;
6357 port = hw->port_info->lport;
6358 prev_ps = &pf->stats_prev;
6359 cur_ps = &pf->stats;
6361 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
6362 &prev_ps->eth.rx_bytes,
6363 &cur_ps->eth.rx_bytes);
6365 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
6366 &prev_ps->eth.rx_unicast,
6367 &cur_ps->eth.rx_unicast);
6369 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
6370 &prev_ps->eth.rx_multicast,
6371 &cur_ps->eth.rx_multicast);
6373 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
6374 &prev_ps->eth.rx_broadcast,
6375 &cur_ps->eth.rx_broadcast);
6377 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
6378 &prev_ps->eth.rx_discards,
6379 &cur_ps->eth.rx_discards);
6381 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
6382 &prev_ps->eth.tx_bytes,
6383 &cur_ps->eth.tx_bytes);
6385 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
6386 &prev_ps->eth.tx_unicast,
6387 &cur_ps->eth.tx_unicast);
6389 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
6390 &prev_ps->eth.tx_multicast,
6391 &cur_ps->eth.tx_multicast);
6393 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
6394 &prev_ps->eth.tx_broadcast,
6395 &cur_ps->eth.tx_broadcast);
6397 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
6398 &prev_ps->tx_dropped_link_down,
6399 &cur_ps->tx_dropped_link_down);
6401 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
6402 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
6404 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
6405 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
6407 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
6408 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
6410 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
6411 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
6413 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
6414 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
6416 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
6417 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
6419 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
6420 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
6422 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
6423 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
6425 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
6426 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
6428 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
6429 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
6431 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
6432 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
6434 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
6435 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
6437 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
6438 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
6440 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
6441 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
6443 fd_ctr_base = hw->fd_ctr_base;
6445 ice_stat_update40(hw,
6446 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
6447 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
6448 &cur_ps->fd_sb_match);
6449 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
6450 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
6452 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
6453 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
6455 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
6456 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
6458 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
6459 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
6461 ice_update_dcb_stats(pf);
6463 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
6464 &prev_ps->crc_errors, &cur_ps->crc_errors);
6466 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
6467 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
6469 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
6470 &prev_ps->mac_local_faults,
6471 &cur_ps->mac_local_faults);
6473 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
6474 &prev_ps->mac_remote_faults,
6475 &cur_ps->mac_remote_faults);
6477 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
6478 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
6480 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
6481 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
6483 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
6484 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
6486 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
6487 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
6489 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
6490 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
6492 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
6494 pf->stat_prev_loaded = true;
6498 * ice_get_stats64 - get statistics for network device structure
6499 * @netdev: network interface device structure
6500 * @stats: main device statistics structure
6503 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
6505 struct ice_netdev_priv *np = netdev_priv(netdev);
6506 struct rtnl_link_stats64 *vsi_stats;
6507 struct ice_vsi *vsi = np->vsi;
6509 vsi_stats = &vsi->net_stats;
6511 if (!vsi->num_txq || !vsi->num_rxq)
6514 /* netdev packet/byte stats come from ring counter. These are obtained
6515 * by summing up ring counters (done by ice_update_vsi_ring_stats).
6516 * But, only call the update routine and read the registers if VSI is
6519 if (!test_bit(ICE_VSI_DOWN, vsi->state))
6520 ice_update_vsi_ring_stats(vsi);
6521 stats->tx_packets = vsi_stats->tx_packets;
6522 stats->tx_bytes = vsi_stats->tx_bytes;
6523 stats->rx_packets = vsi_stats->rx_packets;
6524 stats->rx_bytes = vsi_stats->rx_bytes;
6526 /* The rest of the stats can be read from the hardware but instead we
6527 * just return values that the watchdog task has already obtained from
6530 stats->multicast = vsi_stats->multicast;
6531 stats->tx_errors = vsi_stats->tx_errors;
6532 stats->tx_dropped = vsi_stats->tx_dropped;
6533 stats->rx_errors = vsi_stats->rx_errors;
6534 stats->rx_dropped = vsi_stats->rx_dropped;
6535 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
6536 stats->rx_length_errors = vsi_stats->rx_length_errors;
6540 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
6541 * @vsi: VSI having NAPI disabled
6543 static void ice_napi_disable_all(struct ice_vsi *vsi)
6550 ice_for_each_q_vector(vsi, q_idx) {
6551 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6553 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6554 napi_disable(&q_vector->napi);
6556 cancel_work_sync(&q_vector->tx.dim.work);
6557 cancel_work_sync(&q_vector->rx.dim.work);
6562 * ice_down - Shutdown the connection
6563 * @vsi: The VSI being stopped
6565 * Caller of this function is expected to set the vsi->state ICE_DOWN bit
6567 int ice_down(struct ice_vsi *vsi)
6569 int i, tx_err, rx_err, link_err = 0, vlan_err = 0;
6571 WARN_ON(!test_bit(ICE_VSI_DOWN, vsi->state));
6573 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
6574 vlan_err = ice_vsi_del_vlan_zero(vsi);
6575 if (!ice_is_e810(&vsi->back->hw))
6576 ice_ptp_link_change(vsi->back, vsi->back->hw.pf_id, false);
6577 netif_carrier_off(vsi->netdev);
6578 netif_tx_disable(vsi->netdev);
6579 } else if (vsi->type == ICE_VSI_SWITCHDEV_CTRL) {
6580 ice_eswitch_stop_all_tx_queues(vsi->back);
6583 ice_vsi_dis_irq(vsi);
6585 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
6587 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
6588 vsi->vsi_num, tx_err);
6589 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
6590 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
6592 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
6593 vsi->vsi_num, tx_err);
6596 rx_err = ice_vsi_stop_all_rx_rings(vsi);
6598 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
6599 vsi->vsi_num, rx_err);
6601 ice_napi_disable_all(vsi);
6603 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
6604 link_err = ice_force_phys_link_state(vsi, false);
6606 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
6607 vsi->vsi_num, link_err);
6610 ice_for_each_txq(vsi, i)
6611 ice_clean_tx_ring(vsi->tx_rings[i]);
6613 ice_for_each_rxq(vsi, i)
6614 ice_clean_rx_ring(vsi->rx_rings[i]);
6616 if (tx_err || rx_err || link_err || vlan_err) {
6617 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
6618 vsi->vsi_num, vsi->vsw->sw_id);
6626 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
6627 * @vsi: VSI having resources allocated
6629 * Return 0 on success, negative on failure
6631 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
6635 if (!vsi->num_txq) {
6636 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
6641 ice_for_each_txq(vsi, i) {
6642 struct ice_tx_ring *ring = vsi->tx_rings[i];
6648 ring->netdev = vsi->netdev;
6649 err = ice_setup_tx_ring(ring);
6658 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
6659 * @vsi: VSI having resources allocated
6661 * Return 0 on success, negative on failure
6663 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
6667 if (!vsi->num_rxq) {
6668 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
6673 ice_for_each_rxq(vsi, i) {
6674 struct ice_rx_ring *ring = vsi->rx_rings[i];
6680 ring->netdev = vsi->netdev;
6681 err = ice_setup_rx_ring(ring);
6690 * ice_vsi_open_ctrl - open control VSI for use
6691 * @vsi: the VSI to open
6693 * Initialization of the Control VSI
6695 * Returns 0 on success, negative value on error
6697 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
6699 char int_name[ICE_INT_NAME_STR_LEN];
6700 struct ice_pf *pf = vsi->back;
6704 dev = ice_pf_to_dev(pf);
6705 /* allocate descriptors */
6706 err = ice_vsi_setup_tx_rings(vsi);
6710 err = ice_vsi_setup_rx_rings(vsi);
6714 err = ice_vsi_cfg(vsi);
6718 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
6719 dev_driver_string(dev), dev_name(dev));
6720 err = ice_vsi_req_irq_msix(vsi, int_name);
6724 ice_vsi_cfg_msix(vsi);
6726 err = ice_vsi_start_all_rx_rings(vsi);
6728 goto err_up_complete;
6730 clear_bit(ICE_VSI_DOWN, vsi->state);
6731 ice_vsi_ena_irq(vsi);
6738 ice_vsi_free_rx_rings(vsi);
6740 ice_vsi_free_tx_rings(vsi);
6746 * ice_vsi_open - Called when a network interface is made active
6747 * @vsi: the VSI to open
6749 * Initialization of the VSI
6751 * Returns 0 on success, negative value on error
6753 int ice_vsi_open(struct ice_vsi *vsi)
6755 char int_name[ICE_INT_NAME_STR_LEN];
6756 struct ice_pf *pf = vsi->back;
6759 /* allocate descriptors */
6760 err = ice_vsi_setup_tx_rings(vsi);
6764 err = ice_vsi_setup_rx_rings(vsi);
6768 err = ice_vsi_cfg(vsi);
6772 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
6773 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
6774 err = ice_vsi_req_irq_msix(vsi, int_name);
6778 if (vsi->type == ICE_VSI_PF) {
6779 /* Notify the stack of the actual queue counts. */
6780 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
6784 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
6789 err = ice_up_complete(vsi);
6791 goto err_up_complete;
6798 ice_vsi_free_irq(vsi);
6800 ice_vsi_free_rx_rings(vsi);
6802 ice_vsi_free_tx_rings(vsi);
6808 * ice_vsi_release_all - Delete all VSIs
6809 * @pf: PF from which all VSIs are being removed
6811 static void ice_vsi_release_all(struct ice_pf *pf)
6818 ice_for_each_vsi(pf, i) {
6822 if (pf->vsi[i]->type == ICE_VSI_CHNL)
6825 err = ice_vsi_release(pf->vsi[i]);
6827 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
6828 i, err, pf->vsi[i]->vsi_num);
6833 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
6834 * @pf: pointer to the PF instance
6835 * @type: VSI type to rebuild
6837 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
6839 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
6841 struct device *dev = ice_pf_to_dev(pf);
6844 ice_for_each_vsi(pf, i) {
6845 struct ice_vsi *vsi = pf->vsi[i];
6847 if (!vsi || vsi->type != type)
6850 /* rebuild the VSI */
6851 err = ice_vsi_rebuild(vsi, true);
6853 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
6854 err, vsi->idx, ice_vsi_type_str(type));
6858 /* replay filters for the VSI */
6859 err = ice_replay_vsi(&pf->hw, vsi->idx);
6861 dev_err(dev, "replay VSI failed, error %d, VSI index %d, type %s\n",
6862 err, vsi->idx, ice_vsi_type_str(type));
6866 /* Re-map HW VSI number, using VSI handle that has been
6867 * previously validated in ice_replay_vsi() call above
6869 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
6871 /* enable the VSI */
6872 err = ice_ena_vsi(vsi, false);
6874 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
6875 err, vsi->idx, ice_vsi_type_str(type));
6879 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
6880 ice_vsi_type_str(type));
6887 * ice_update_pf_netdev_link - Update PF netdev link status
6888 * @pf: pointer to the PF instance
6890 static void ice_update_pf_netdev_link(struct ice_pf *pf)
6895 ice_for_each_vsi(pf, i) {
6896 struct ice_vsi *vsi = pf->vsi[i];
6898 if (!vsi || vsi->type != ICE_VSI_PF)
6901 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
6903 netif_carrier_on(pf->vsi[i]->netdev);
6904 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
6906 netif_carrier_off(pf->vsi[i]->netdev);
6907 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
6913 * ice_rebuild - rebuild after reset
6914 * @pf: PF to rebuild
6915 * @reset_type: type of reset
6917 * Do not rebuild VF VSI in this flow because that is already handled via
6918 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a
6919 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
6920 * to reset/rebuild all the VF VSI twice.
6922 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
6924 struct device *dev = ice_pf_to_dev(pf);
6925 struct ice_hw *hw = &pf->hw;
6929 if (test_bit(ICE_DOWN, pf->state))
6930 goto clear_recovery;
6932 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
6934 if (reset_type == ICE_RESET_EMPR) {
6935 /* If an EMP reset has occurred, any previously pending flash
6936 * update will have completed. We no longer know whether or
6937 * not the NVM update EMP reset is restricted.
6939 pf->fw_emp_reset_disabled = false;
6942 err = ice_init_all_ctrlq(hw);
6944 dev_err(dev, "control queues init failed %d\n", err);
6945 goto err_init_ctrlq;
6948 /* if DDP was previously loaded successfully */
6949 if (!ice_is_safe_mode(pf)) {
6950 /* reload the SW DB of filter tables */
6951 if (reset_type == ICE_RESET_PFR)
6952 ice_fill_blk_tbls(hw);
6954 /* Reload DDP Package after CORER/GLOBR reset */
6955 ice_load_pkg(NULL, pf);
6958 err = ice_clear_pf_cfg(hw);
6960 dev_err(dev, "clear PF configuration failed %d\n", err);
6961 goto err_init_ctrlq;
6964 if (pf->first_sw->dflt_vsi_ena)
6965 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n");
6966 /* clear the default VSI configuration if it exists */
6967 pf->first_sw->dflt_vsi = NULL;
6968 pf->first_sw->dflt_vsi_ena = false;
6970 ice_clear_pxe_mode(hw);
6972 err = ice_init_nvm(hw);
6974 dev_err(dev, "ice_init_nvm failed %d\n", err);
6975 goto err_init_ctrlq;
6978 err = ice_get_caps(hw);
6980 dev_err(dev, "ice_get_caps failed %d\n", err);
6981 goto err_init_ctrlq;
6984 err = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
6986 dev_err(dev, "set_mac_cfg failed %d\n", err);
6987 goto err_init_ctrlq;
6990 dvm = ice_is_dvm_ena(hw);
6992 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
6994 goto err_init_ctrlq;
6996 err = ice_sched_init_port(hw->port_info);
6998 goto err_sched_init_port;
7000 /* start misc vector */
7001 err = ice_req_irq_msix_misc(pf);
7003 dev_err(dev, "misc vector setup failed: %d\n", err);
7004 goto err_sched_init_port;
7007 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7008 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
7009 if (!rd32(hw, PFQF_FD_SIZE)) {
7010 u16 unused, guar, b_effort;
7012 guar = hw->func_caps.fd_fltr_guar;
7013 b_effort = hw->func_caps.fd_fltr_best_effort;
7015 /* force guaranteed filter pool for PF */
7016 ice_alloc_fd_guar_item(hw, &unused, guar);
7017 /* force shared filter pool for PF */
7018 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
7022 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
7023 ice_dcb_rebuild(pf);
7025 /* If the PF previously had enabled PTP, PTP init needs to happen before
7026 * the VSI rebuild. If not, this causes the PTP link status events to
7029 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
7032 if (ice_is_feature_supported(pf, ICE_F_GNSS))
7035 /* rebuild PF VSI */
7036 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
7038 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
7039 goto err_vsi_rebuild;
7042 /* configure PTP timestamping after VSI rebuild */
7043 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
7044 ice_ptp_cfg_timestamp(pf, false);
7046 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_SWITCHDEV_CTRL);
7048 dev_err(dev, "Switchdev CTRL VSI rebuild failed: %d\n", err);
7049 goto err_vsi_rebuild;
7052 if (reset_type == ICE_RESET_PFR) {
7053 err = ice_rebuild_channels(pf);
7055 dev_err(dev, "failed to rebuild and replay ADQ VSIs, err %d\n",
7057 goto err_vsi_rebuild;
7061 /* If Flow Director is active */
7062 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7063 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
7065 dev_err(dev, "control VSI rebuild failed: %d\n", err);
7066 goto err_vsi_rebuild;
7069 /* replay HW Flow Director recipes */
7071 ice_fdir_replay_flows(hw);
7073 /* replay Flow Director filters */
7074 ice_fdir_replay_fltrs(pf);
7076 ice_rebuild_arfs(pf);
7079 ice_update_pf_netdev_link(pf);
7081 /* tell the firmware we are up */
7082 err = ice_send_version(pf);
7084 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n",
7086 goto err_vsi_rebuild;
7089 ice_replay_post(hw);
7091 /* if we get here, reset flow is successful */
7092 clear_bit(ICE_RESET_FAILED, pf->state);
7094 ice_plug_aux_dev(pf);
7098 err_sched_init_port:
7099 ice_sched_cleanup_all(hw);
7101 ice_shutdown_all_ctrlq(hw);
7102 set_bit(ICE_RESET_FAILED, pf->state);
7104 /* set this bit in PF state to control service task scheduling */
7105 set_bit(ICE_NEEDS_RESTART, pf->state);
7106 dev_err(dev, "Rebuild failed, unload and reload driver\n");
7110 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
7111 * @vsi: Pointer to VSI structure
7113 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
7115 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
7116 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
7118 return ICE_RXBUF_3072;
7122 * ice_change_mtu - NDO callback to change the MTU
7123 * @netdev: network interface device structure
7124 * @new_mtu: new value for maximum frame size
7126 * Returns 0 on success, negative on failure
7128 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
7130 struct ice_netdev_priv *np = netdev_priv(netdev);
7131 struct ice_vsi *vsi = np->vsi;
7132 struct ice_pf *pf = vsi->back;
7136 if (new_mtu == (int)netdev->mtu) {
7137 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
7141 if (ice_is_xdp_ena_vsi(vsi)) {
7142 int frame_size = ice_max_xdp_frame_size(vsi);
7144 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
7145 netdev_err(netdev, "max MTU for XDP usage is %d\n",
7146 frame_size - ICE_ETH_PKT_HDR_PAD);
7151 /* if a reset is in progress, wait for some time for it to complete */
7153 if (ice_is_reset_in_progress(pf->state)) {
7155 usleep_range(1000, 2000);
7160 } while (count < 100);
7163 netdev_err(netdev, "can't change MTU. Device is busy\n");
7167 netdev->mtu = (unsigned int)new_mtu;
7169 /* if VSI is up, bring it down and then back up */
7170 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
7171 err = ice_down(vsi);
7173 netdev_err(netdev, "change MTU if_down err %d\n", err);
7179 netdev_err(netdev, "change MTU if_up err %d\n", err);
7184 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
7185 set_bit(ICE_FLAG_MTU_CHANGED, pf->flags);
7191 * ice_eth_ioctl - Access the hwtstamp interface
7192 * @netdev: network interface device structure
7193 * @ifr: interface request data
7194 * @cmd: ioctl command
7196 static int ice_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7198 struct ice_netdev_priv *np = netdev_priv(netdev);
7199 struct ice_pf *pf = np->vsi->back;
7203 return ice_ptp_get_ts_config(pf, ifr);
7205 return ice_ptp_set_ts_config(pf, ifr);
7212 * ice_aq_str - convert AQ err code to a string
7213 * @aq_err: the AQ error code to convert
7215 const char *ice_aq_str(enum ice_aq_err aq_err)
7220 case ICE_AQ_RC_EPERM:
7221 return "ICE_AQ_RC_EPERM";
7222 case ICE_AQ_RC_ENOENT:
7223 return "ICE_AQ_RC_ENOENT";
7224 case ICE_AQ_RC_ENOMEM:
7225 return "ICE_AQ_RC_ENOMEM";
7226 case ICE_AQ_RC_EBUSY:
7227 return "ICE_AQ_RC_EBUSY";
7228 case ICE_AQ_RC_EEXIST:
7229 return "ICE_AQ_RC_EEXIST";
7230 case ICE_AQ_RC_EINVAL:
7231 return "ICE_AQ_RC_EINVAL";
7232 case ICE_AQ_RC_ENOSPC:
7233 return "ICE_AQ_RC_ENOSPC";
7234 case ICE_AQ_RC_ENOSYS:
7235 return "ICE_AQ_RC_ENOSYS";
7236 case ICE_AQ_RC_EMODE:
7237 return "ICE_AQ_RC_EMODE";
7238 case ICE_AQ_RC_ENOSEC:
7239 return "ICE_AQ_RC_ENOSEC";
7240 case ICE_AQ_RC_EBADSIG:
7241 return "ICE_AQ_RC_EBADSIG";
7242 case ICE_AQ_RC_ESVN:
7243 return "ICE_AQ_RC_ESVN";
7244 case ICE_AQ_RC_EBADMAN:
7245 return "ICE_AQ_RC_EBADMAN";
7246 case ICE_AQ_RC_EBADBUF:
7247 return "ICE_AQ_RC_EBADBUF";
7250 return "ICE_AQ_RC_UNKNOWN";
7254 * ice_set_rss_lut - Set RSS LUT
7255 * @vsi: Pointer to VSI structure
7256 * @lut: Lookup table
7257 * @lut_size: Lookup table size
7259 * Returns 0 on success, negative on failure
7261 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7263 struct ice_aq_get_set_rss_lut_params params = {};
7264 struct ice_hw *hw = &vsi->back->hw;
7270 params.vsi_handle = vsi->idx;
7271 params.lut_size = lut_size;
7272 params.lut_type = vsi->rss_lut_type;
7275 status = ice_aq_set_rss_lut(hw, ¶ms);
7277 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %d aq_err %s\n",
7278 status, ice_aq_str(hw->adminq.sq_last_status));
7284 * ice_set_rss_key - Set RSS key
7285 * @vsi: Pointer to the VSI structure
7286 * @seed: RSS hash seed
7288 * Returns 0 on success, negative on failure
7290 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed)
7292 struct ice_hw *hw = &vsi->back->hw;
7298 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7300 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %d aq_err %s\n",
7301 status, ice_aq_str(hw->adminq.sq_last_status));
7307 * ice_get_rss_lut - Get RSS LUT
7308 * @vsi: Pointer to VSI structure
7309 * @lut: Buffer to store the lookup table entries
7310 * @lut_size: Size of buffer to store the lookup table entries
7312 * Returns 0 on success, negative on failure
7314 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7316 struct ice_aq_get_set_rss_lut_params params = {};
7317 struct ice_hw *hw = &vsi->back->hw;
7323 params.vsi_handle = vsi->idx;
7324 params.lut_size = lut_size;
7325 params.lut_type = vsi->rss_lut_type;
7328 status = ice_aq_get_rss_lut(hw, ¶ms);
7330 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %d aq_err %s\n",
7331 status, ice_aq_str(hw->adminq.sq_last_status));
7337 * ice_get_rss_key - Get RSS key
7338 * @vsi: Pointer to VSI structure
7339 * @seed: Buffer to store the key in
7341 * Returns 0 on success, negative on failure
7343 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed)
7345 struct ice_hw *hw = &vsi->back->hw;
7351 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7353 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %d aq_err %s\n",
7354 status, ice_aq_str(hw->adminq.sq_last_status));
7360 * ice_bridge_getlink - Get the hardware bridge mode
7363 * @seq: RTNL message seq
7364 * @dev: the netdev being configured
7365 * @filter_mask: filter mask passed in
7366 * @nlflags: netlink flags passed in
7368 * Return the bridge mode (VEB/VEPA)
7371 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7372 struct net_device *dev, u32 filter_mask, int nlflags)
7374 struct ice_netdev_priv *np = netdev_priv(dev);
7375 struct ice_vsi *vsi = np->vsi;
7376 struct ice_pf *pf = vsi->back;
7379 bmode = pf->first_sw->bridge_mode;
7381 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
7386 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
7387 * @vsi: Pointer to VSI structure
7388 * @bmode: Hardware bridge mode (VEB/VEPA)
7390 * Returns 0 on success, negative on failure
7392 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
7394 struct ice_aqc_vsi_props *vsi_props;
7395 struct ice_hw *hw = &vsi->back->hw;
7396 struct ice_vsi_ctx *ctxt;
7399 vsi_props = &vsi->info;
7401 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
7405 ctxt->info = vsi->info;
7407 if (bmode == BRIDGE_MODE_VEB)
7408 /* change from VEPA to VEB mode */
7409 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7411 /* change from VEB to VEPA mode */
7412 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7413 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
7415 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
7417 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %s\n",
7418 bmode, ret, ice_aq_str(hw->adminq.sq_last_status));
7421 /* Update sw flags for book keeping */
7422 vsi_props->sw_flags = ctxt->info.sw_flags;
7430 * ice_bridge_setlink - Set the hardware bridge mode
7431 * @dev: the netdev being configured
7432 * @nlh: RTNL message
7433 * @flags: bridge setlink flags
7434 * @extack: netlink extended ack
7436 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
7437 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
7438 * not already set for all VSIs connected to this switch. And also update the
7439 * unicast switch filter rules for the corresponding switch of the netdev.
7442 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
7443 u16 __always_unused flags,
7444 struct netlink_ext_ack __always_unused *extack)
7446 struct ice_netdev_priv *np = netdev_priv(dev);
7447 struct ice_pf *pf = np->vsi->back;
7448 struct nlattr *attr, *br_spec;
7449 struct ice_hw *hw = &pf->hw;
7450 struct ice_sw *pf_sw;
7451 int rem, v, err = 0;
7453 pf_sw = pf->first_sw;
7454 /* find the attribute in the netlink message */
7455 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7457 nla_for_each_nested(attr, br_spec, rem) {
7460 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7462 mode = nla_get_u16(attr);
7463 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
7465 /* Continue if bridge mode is not being flipped */
7466 if (mode == pf_sw->bridge_mode)
7468 /* Iterates through the PF VSI list and update the loopback
7471 ice_for_each_vsi(pf, v) {
7474 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
7479 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
7480 /* Update the unicast switch filter rules for the corresponding
7481 * switch of the netdev
7483 err = ice_update_sw_rule_bridge_mode(hw);
7485 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %s\n",
7487 ice_aq_str(hw->adminq.sq_last_status));
7488 /* revert hw->evb_veb */
7489 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
7493 pf_sw->bridge_mode = mode;
7500 * ice_tx_timeout - Respond to a Tx Hang
7501 * @netdev: network interface device structure
7502 * @txqueue: Tx queue
7504 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
7506 struct ice_netdev_priv *np = netdev_priv(netdev);
7507 struct ice_tx_ring *tx_ring = NULL;
7508 struct ice_vsi *vsi = np->vsi;
7509 struct ice_pf *pf = vsi->back;
7512 pf->tx_timeout_count++;
7514 /* Check if PFC is enabled for the TC to which the queue belongs
7515 * to. If yes then Tx timeout is not caused by a hung queue, no
7516 * need to reset and rebuild
7518 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
7519 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
7524 /* now that we have an index, find the tx_ring struct */
7525 ice_for_each_txq(vsi, i)
7526 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
7527 if (txqueue == vsi->tx_rings[i]->q_index) {
7528 tx_ring = vsi->tx_rings[i];
7532 /* Reset recovery level if enough time has elapsed after last timeout.
7533 * Also ensure no new reset action happens before next timeout period.
7535 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
7536 pf->tx_timeout_recovery_level = 1;
7537 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
7538 netdev->watchdog_timeo)))
7542 struct ice_hw *hw = &pf->hw;
7545 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
7546 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
7547 /* Read interrupt register */
7548 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
7550 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
7551 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
7552 head, tx_ring->next_to_use, val);
7555 pf->tx_timeout_last_recovery = jiffies;
7556 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
7557 pf->tx_timeout_recovery_level, txqueue);
7559 switch (pf->tx_timeout_recovery_level) {
7561 set_bit(ICE_PFR_REQ, pf->state);
7564 set_bit(ICE_CORER_REQ, pf->state);
7567 set_bit(ICE_GLOBR_REQ, pf->state);
7570 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
7571 set_bit(ICE_DOWN, pf->state);
7572 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
7573 set_bit(ICE_SERVICE_DIS, pf->state);
7577 ice_service_task_schedule(pf);
7578 pf->tx_timeout_recovery_level++;
7582 * ice_setup_tc_cls_flower - flower classifier offloads
7583 * @np: net device to configure
7584 * @filter_dev: device on which filter is added
7585 * @cls_flower: offload data
7588 ice_setup_tc_cls_flower(struct ice_netdev_priv *np,
7589 struct net_device *filter_dev,
7590 struct flow_cls_offload *cls_flower)
7592 struct ice_vsi *vsi = np->vsi;
7594 if (cls_flower->common.chain_index)
7597 switch (cls_flower->command) {
7598 case FLOW_CLS_REPLACE:
7599 return ice_add_cls_flower(filter_dev, vsi, cls_flower);
7600 case FLOW_CLS_DESTROY:
7601 return ice_del_cls_flower(vsi, cls_flower);
7608 * ice_setup_tc_block_cb - callback handler registered for TC block
7609 * @type: TC SETUP type
7610 * @type_data: TC flower offload data that contains user input
7611 * @cb_priv: netdev private data
7614 ice_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
7616 struct ice_netdev_priv *np = cb_priv;
7619 case TC_SETUP_CLSFLOWER:
7620 return ice_setup_tc_cls_flower(np, np->vsi->netdev,
7628 * ice_validate_mqprio_qopt - Validate TCF input parameters
7629 * @vsi: Pointer to VSI
7630 * @mqprio_qopt: input parameters for mqprio queue configuration
7632 * This function validates MQPRIO params, such as qcount (power of 2 wherever
7633 * needed), and make sure user doesn't specify qcount and BW rate limit
7634 * for TCs, which are more than "num_tc"
7637 ice_validate_mqprio_qopt(struct ice_vsi *vsi,
7638 struct tc_mqprio_qopt_offload *mqprio_qopt)
7640 u64 sum_max_rate = 0, sum_min_rate = 0;
7641 int non_power_of_2_qcount = 0;
7642 struct ice_pf *pf = vsi->back;
7643 int max_rss_q_cnt = 0;
7648 if (vsi->type != ICE_VSI_PF)
7651 if (mqprio_qopt->qopt.offset[0] != 0 ||
7652 mqprio_qopt->qopt.num_tc < 1 ||
7653 mqprio_qopt->qopt.num_tc > ICE_CHNL_MAX_TC)
7656 dev = ice_pf_to_dev(pf);
7657 vsi->ch_rss_size = 0;
7658 num_tc = mqprio_qopt->qopt.num_tc;
7660 for (i = 0; num_tc; i++) {
7661 int qcount = mqprio_qopt->qopt.count[i];
7662 u64 max_rate, min_rate, rem;
7667 if (is_power_of_2(qcount)) {
7668 if (non_power_of_2_qcount &&
7669 qcount > non_power_of_2_qcount) {
7670 dev_err(dev, "qcount[%d] cannot be greater than non power of 2 qcount[%d]\n",
7671 qcount, non_power_of_2_qcount);
7674 if (qcount > max_rss_q_cnt)
7675 max_rss_q_cnt = qcount;
7677 if (non_power_of_2_qcount &&
7678 qcount != non_power_of_2_qcount) {
7679 dev_err(dev, "Only one non power of 2 qcount allowed[%d,%d]\n",
7680 qcount, non_power_of_2_qcount);
7683 if (qcount < max_rss_q_cnt) {
7684 dev_err(dev, "non power of 2 qcount[%d] cannot be less than other qcount[%d]\n",
7685 qcount, max_rss_q_cnt);
7688 max_rss_q_cnt = qcount;
7689 non_power_of_2_qcount = qcount;
7692 /* TC command takes input in K/N/Gbps or K/M/Gbit etc but
7693 * converts the bandwidth rate limit into Bytes/s when
7694 * passing it down to the driver. So convert input bandwidth
7695 * from Bytes/s to Kbps
7697 max_rate = mqprio_qopt->max_rate[i];
7698 max_rate = div_u64(max_rate, ICE_BW_KBPS_DIVISOR);
7699 sum_max_rate += max_rate;
7701 /* min_rate is minimum guaranteed rate and it can't be zero */
7702 min_rate = mqprio_qopt->min_rate[i];
7703 min_rate = div_u64(min_rate, ICE_BW_KBPS_DIVISOR);
7704 sum_min_rate += min_rate;
7706 if (min_rate && min_rate < ICE_MIN_BW_LIMIT) {
7707 dev_err(dev, "TC%d: min_rate(%llu Kbps) < %u Kbps\n", i,
7708 min_rate, ICE_MIN_BW_LIMIT);
7712 iter_div_u64_rem(min_rate, ICE_MIN_BW_LIMIT, &rem);
7714 dev_err(dev, "TC%d: Min Rate not multiple of %u Kbps",
7715 i, ICE_MIN_BW_LIMIT);
7719 iter_div_u64_rem(max_rate, ICE_MIN_BW_LIMIT, &rem);
7721 dev_err(dev, "TC%d: Max Rate not multiple of %u Kbps",
7722 i, ICE_MIN_BW_LIMIT);
7726 /* min_rate can't be more than max_rate, except when max_rate
7727 * is zero (implies max_rate sought is max line rate). In such
7728 * a case min_rate can be more than max.
7730 if (max_rate && min_rate > max_rate) {
7731 dev_err(dev, "min_rate %llu Kbps can't be more than max_rate %llu Kbps\n",
7732 min_rate, max_rate);
7736 if (i >= mqprio_qopt->qopt.num_tc - 1)
7738 if (mqprio_qopt->qopt.offset[i + 1] !=
7739 (mqprio_qopt->qopt.offset[i] + qcount))
7743 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7746 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7749 speed = ice_get_link_speed_kbps(vsi);
7750 if (sum_max_rate && sum_max_rate > (u64)speed) {
7751 dev_err(dev, "Invalid max Tx rate(%llu) Kbps > speed(%u) Kbps specified\n",
7752 sum_max_rate, speed);
7755 if (sum_min_rate && sum_min_rate > (u64)speed) {
7756 dev_err(dev, "Invalid min Tx rate(%llu) Kbps > speed (%u) Kbps specified\n",
7757 sum_min_rate, speed);
7761 /* make sure vsi->ch_rss_size is set correctly based on TC's qcount */
7762 vsi->ch_rss_size = max_rss_q_cnt;
7768 * ice_add_vsi_to_fdir - add a VSI to the flow director group for PF
7769 * @pf: ptr to PF device
7772 static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
7774 struct device *dev = ice_pf_to_dev(pf);
7779 if (!(vsi->num_gfltr || vsi->num_bfltr))
7783 for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
7784 struct ice_fd_hw_prof *prof;
7788 if (!(hw->fdir_prof && hw->fdir_prof[flow] &&
7789 hw->fdir_prof[flow]->cnt))
7792 for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
7793 enum ice_flow_priority prio;
7796 /* add this VSI to FDir profile for this flow */
7797 prio = ICE_FLOW_PRIO_NORMAL;
7798 prof = hw->fdir_prof[flow];
7799 prof_id = flow + tun * ICE_FLTR_PTYPE_MAX;
7800 status = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id,
7801 prof->vsi_h[0], vsi->idx,
7802 prio, prof->fdir_seg[tun],
7805 dev_err(dev, "channel VSI idx %d, not able to add to group %d\n",
7810 prof->entry_h[prof->cnt][tun] = entry_h;
7813 /* store VSI for filter replay and delete */
7814 prof->vsi_h[prof->cnt] = vsi->idx;
7818 dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx,
7823 dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx);
7829 * ice_add_channel - add a channel by adding VSI
7830 * @pf: ptr to PF device
7831 * @sw_id: underlying HW switching element ID
7832 * @ch: ptr to channel structure
7834 * Add a channel (VSI) using add_vsi and queue_map
7836 static int ice_add_channel(struct ice_pf *pf, u16 sw_id, struct ice_channel *ch)
7838 struct device *dev = ice_pf_to_dev(pf);
7839 struct ice_vsi *vsi;
7841 if (ch->type != ICE_VSI_CHNL) {
7842 dev_err(dev, "add new VSI failed, ch->type %d\n", ch->type);
7846 vsi = ice_chnl_vsi_setup(pf, pf->hw.port_info, ch);
7847 if (!vsi || vsi->type != ICE_VSI_CHNL) {
7848 dev_err(dev, "create chnl VSI failure\n");
7852 ice_add_vsi_to_fdir(pf, vsi);
7855 ch->vsi_num = vsi->vsi_num;
7856 ch->info.mapping_flags = vsi->info.mapping_flags;
7858 /* set the back pointer of channel for newly created VSI */
7861 memcpy(&ch->info.q_mapping, &vsi->info.q_mapping,
7862 sizeof(vsi->info.q_mapping));
7863 memcpy(&ch->info.tc_mapping, vsi->info.tc_mapping,
7864 sizeof(vsi->info.tc_mapping));
7871 * @vsi: the VSI being setup
7872 * @ch: ptr to channel structure
7874 * Configure channel specific resources such as rings, vector.
7876 static void ice_chnl_cfg_res(struct ice_vsi *vsi, struct ice_channel *ch)
7880 for (i = 0; i < ch->num_txq; i++) {
7881 struct ice_q_vector *tx_q_vector, *rx_q_vector;
7882 struct ice_ring_container *rc;
7883 struct ice_tx_ring *tx_ring;
7884 struct ice_rx_ring *rx_ring;
7886 tx_ring = vsi->tx_rings[ch->base_q + i];
7887 rx_ring = vsi->rx_rings[ch->base_q + i];
7888 if (!tx_ring || !rx_ring)
7891 /* setup ring being channel enabled */
7895 /* following code block sets up vector specific attributes */
7896 tx_q_vector = tx_ring->q_vector;
7897 rx_q_vector = rx_ring->q_vector;
7898 if (!tx_q_vector && !rx_q_vector)
7902 tx_q_vector->ch = ch;
7903 /* setup Tx and Rx ITR setting if DIM is off */
7904 rc = &tx_q_vector->tx;
7905 if (!ITR_IS_DYNAMIC(rc))
7906 ice_write_itr(rc, rc->itr_setting);
7909 rx_q_vector->ch = ch;
7910 /* setup Tx and Rx ITR setting if DIM is off */
7911 rc = &rx_q_vector->rx;
7912 if (!ITR_IS_DYNAMIC(rc))
7913 ice_write_itr(rc, rc->itr_setting);
7917 /* it is safe to assume that, if channel has non-zero num_t[r]xq, then
7918 * GLINT_ITR register would have written to perform in-context
7919 * update, hence perform flush
7921 if (ch->num_txq || ch->num_rxq)
7922 ice_flush(&vsi->back->hw);
7926 * ice_cfg_chnl_all_res - configure channel resources
7927 * @vsi: pte to main_vsi
7928 * @ch: ptr to channel structure
7930 * This function configures channel specific resources such as flow-director
7931 * counter index, and other resources such as queues, vectors, ITR settings
7934 ice_cfg_chnl_all_res(struct ice_vsi *vsi, struct ice_channel *ch)
7936 /* configure channel (aka ADQ) resources such as queues, vectors,
7937 * ITR settings for channel specific vectors and anything else
7939 ice_chnl_cfg_res(vsi, ch);
7943 * ice_setup_hw_channel - setup new channel
7944 * @pf: ptr to PF device
7945 * @vsi: the VSI being setup
7946 * @ch: ptr to channel structure
7947 * @sw_id: underlying HW switching element ID
7948 * @type: type of channel to be created (VMDq2/VF)
7950 * Setup new channel (VSI) based on specified type (VMDq2/VF)
7951 * and configures Tx rings accordingly
7954 ice_setup_hw_channel(struct ice_pf *pf, struct ice_vsi *vsi,
7955 struct ice_channel *ch, u16 sw_id, u8 type)
7957 struct device *dev = ice_pf_to_dev(pf);
7960 ch->base_q = vsi->next_base_q;
7963 ret = ice_add_channel(pf, sw_id, ch);
7965 dev_err(dev, "failed to add_channel using sw_id %u\n", sw_id);
7969 /* configure/setup ADQ specific resources */
7970 ice_cfg_chnl_all_res(vsi, ch);
7972 /* make sure to update the next_base_q so that subsequent channel's
7973 * (aka ADQ) VSI queue map is correct
7975 vsi->next_base_q = vsi->next_base_q + ch->num_rxq;
7976 dev_dbg(dev, "added channel: vsi_num %u, num_rxq %u\n", ch->vsi_num,
7983 * ice_setup_channel - setup new channel using uplink element
7984 * @pf: ptr to PF device
7985 * @vsi: the VSI being setup
7986 * @ch: ptr to channel structure
7988 * Setup new channel (VSI) based on specified type (VMDq2/VF)
7989 * and uplink switching element
7992 ice_setup_channel(struct ice_pf *pf, struct ice_vsi *vsi,
7993 struct ice_channel *ch)
7995 struct device *dev = ice_pf_to_dev(pf);
7999 if (vsi->type != ICE_VSI_PF) {
8000 dev_err(dev, "unsupported parent VSI type(%d)\n", vsi->type);
8004 sw_id = pf->first_sw->sw_id;
8006 /* create channel (VSI) */
8007 ret = ice_setup_hw_channel(pf, vsi, ch, sw_id, ICE_VSI_CHNL);
8009 dev_err(dev, "failed to setup hw_channel\n");
8012 dev_dbg(dev, "successfully created channel()\n");
8014 return ch->ch_vsi ? true : false;
8018 * ice_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
8019 * @vsi: VSI to be configured
8020 * @max_tx_rate: max Tx rate in Kbps to be configured as maximum BW limit
8021 * @min_tx_rate: min Tx rate in Kbps to be configured as minimum BW limit
8024 ice_set_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate, u64 min_tx_rate)
8028 err = ice_set_min_bw_limit(vsi, min_tx_rate);
8032 return ice_set_max_bw_limit(vsi, max_tx_rate);
8036 * ice_create_q_channel - function to create channel
8037 * @vsi: VSI to be configured
8038 * @ch: ptr to channel (it contains channel specific params)
8040 * This function creates channel (VSI) using num_queues specified by user,
8041 * reconfigs RSS if needed.
8043 static int ice_create_q_channel(struct ice_vsi *vsi, struct ice_channel *ch)
8045 struct ice_pf *pf = vsi->back;
8051 dev = ice_pf_to_dev(pf);
8052 if (!ch->num_txq || !ch->num_rxq) {
8053 dev_err(dev, "Invalid num_queues requested: %d\n", ch->num_rxq);
8057 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_txq) {
8058 dev_err(dev, "cnt_q_avail (%u) less than num_queues %d\n",
8059 vsi->cnt_q_avail, ch->num_txq);
8063 if (!ice_setup_channel(pf, vsi, ch)) {
8064 dev_info(dev, "Failed to setup channel\n");
8067 /* configure BW rate limit */
8068 if (ch->ch_vsi && (ch->max_tx_rate || ch->min_tx_rate)) {
8071 ret = ice_set_bw_limit(ch->ch_vsi, ch->max_tx_rate,
8074 dev_err(dev, "failed to set Tx rate of %llu Kbps for VSI(%u)\n",
8075 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8077 dev_dbg(dev, "set Tx rate of %llu Kbps for VSI(%u)\n",
8078 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8081 vsi->cnt_q_avail -= ch->num_txq;
8087 * ice_rem_all_chnl_fltrs - removes all channel filters
8088 * @pf: ptr to PF, TC-flower based filter are tracked at PF level
8090 * Remove all advanced switch filters only if they are channel specific
8091 * tc-flower based filter
8093 static void ice_rem_all_chnl_fltrs(struct ice_pf *pf)
8095 struct ice_tc_flower_fltr *fltr;
8096 struct hlist_node *node;
8098 /* to remove all channel filters, iterate an ordered list of filters */
8099 hlist_for_each_entry_safe(fltr, node,
8100 &pf->tc_flower_fltr_list,
8102 struct ice_rule_query_data rule;
8105 /* for now process only channel specific filters */
8106 if (!ice_is_chnl_fltr(fltr))
8109 rule.rid = fltr->rid;
8110 rule.rule_id = fltr->rule_id;
8111 rule.vsi_handle = fltr->dest_id;
8112 status = ice_rem_adv_rule_by_id(&pf->hw, &rule);
8114 if (status == -ENOENT)
8115 dev_dbg(ice_pf_to_dev(pf), "TC flower filter (rule_id %u) does not exist\n",
8118 dev_err(ice_pf_to_dev(pf), "failed to delete TC flower filter, status %d\n",
8120 } else if (fltr->dest_vsi) {
8121 /* update advanced switch filter count */
8122 if (fltr->dest_vsi->type == ICE_VSI_CHNL) {
8123 u32 flags = fltr->flags;
8125 fltr->dest_vsi->num_chnl_fltr--;
8126 if (flags & (ICE_TC_FLWR_FIELD_DST_MAC |
8127 ICE_TC_FLWR_FIELD_ENC_DST_MAC))
8128 pf->num_dmac_chnl_fltrs--;
8132 hlist_del(&fltr->tc_flower_node);
8138 * ice_remove_q_channels - Remove queue channels for the TCs
8139 * @vsi: VSI to be configured
8140 * @rem_fltr: delete advanced switch filter or not
8142 * Remove queue channels for the TCs
8144 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_fltr)
8146 struct ice_channel *ch, *ch_tmp;
8147 struct ice_pf *pf = vsi->back;
8150 /* remove all tc-flower based filter if they are channel filters only */
8152 ice_rem_all_chnl_fltrs(pf);
8154 /* remove ntuple filters since queue configuration is being changed */
8155 if (vsi->netdev->features & NETIF_F_NTUPLE) {
8156 struct ice_hw *hw = &pf->hw;
8158 mutex_lock(&hw->fdir_fltr_lock);
8159 ice_fdir_del_all_fltrs(vsi);
8160 mutex_unlock(&hw->fdir_fltr_lock);
8163 /* perform cleanup for channels if they exist */
8164 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
8165 struct ice_vsi *ch_vsi;
8167 list_del(&ch->list);
8168 ch_vsi = ch->ch_vsi;
8174 /* Reset queue contexts */
8175 for (i = 0; i < ch->num_rxq; i++) {
8176 struct ice_tx_ring *tx_ring;
8177 struct ice_rx_ring *rx_ring;
8179 tx_ring = vsi->tx_rings[ch->base_q + i];
8180 rx_ring = vsi->rx_rings[ch->base_q + i];
8183 if (tx_ring->q_vector)
8184 tx_ring->q_vector->ch = NULL;
8188 if (rx_ring->q_vector)
8189 rx_ring->q_vector->ch = NULL;
8193 /* Release FD resources for the channel VSI */
8194 ice_fdir_rem_adq_chnl(&pf->hw, ch->ch_vsi->idx);
8196 /* clear the VSI from scheduler tree */
8197 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx);
8199 /* Delete VSI from FW */
8200 ice_vsi_delete(ch->ch_vsi);
8202 /* Delete VSI from PF and HW VSI arrays */
8203 ice_vsi_clear(ch->ch_vsi);
8205 /* free the channel */
8209 /* clear the channel VSI map which is stored in main VSI */
8210 ice_for_each_chnl_tc(i)
8211 vsi->tc_map_vsi[i] = NULL;
8213 /* reset main VSI's all TC information */
8219 * ice_rebuild_channels - rebuild channel
8222 * Recreate channel VSIs and replay filters
8224 static int ice_rebuild_channels(struct ice_pf *pf)
8226 struct device *dev = ice_pf_to_dev(pf);
8227 struct ice_vsi *main_vsi;
8228 bool rem_adv_fltr = true;
8229 struct ice_channel *ch;
8230 struct ice_vsi *vsi;
8234 main_vsi = ice_get_main_vsi(pf);
8238 if (!test_bit(ICE_FLAG_TC_MQPRIO, pf->flags) ||
8239 main_vsi->old_numtc == 1)
8240 return 0; /* nothing to be done */
8242 /* reconfigure main VSI based on old value of TC and cached values
8245 err = ice_vsi_cfg_tc(main_vsi, main_vsi->old_ena_tc);
8247 dev_err(dev, "failed configuring TC(ena_tc:0x%02x) for HW VSI=%u\n",
8248 main_vsi->old_ena_tc, main_vsi->vsi_num);
8252 /* rebuild ADQ VSIs */
8253 ice_for_each_vsi(pf, i) {
8254 enum ice_vsi_type type;
8257 if (!vsi || vsi->type != ICE_VSI_CHNL)
8262 /* rebuild ADQ VSI */
8263 err = ice_vsi_rebuild(vsi, true);
8265 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n",
8266 ice_vsi_type_str(type), vsi->idx, err);
8270 /* Re-map HW VSI number, using VSI handle that has been
8271 * previously validated in ice_replay_vsi() call above
8273 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
8275 /* replay filters for the VSI */
8276 err = ice_replay_vsi(&pf->hw, vsi->idx);
8278 dev_err(dev, "VSI (type:%s) replay failed, err %d, VSI index %d\n",
8279 ice_vsi_type_str(type), err, vsi->idx);
8280 rem_adv_fltr = false;
8283 dev_info(dev, "VSI (type:%s) at index %d rebuilt successfully\n",
8284 ice_vsi_type_str(type), vsi->idx);
8286 /* store ADQ VSI at correct TC index in main VSI's
8289 main_vsi->tc_map_vsi[tc_idx++] = vsi;
8292 /* ADQ VSI(s) has been rebuilt successfully, so setup
8293 * channel for main VSI's Tx and Rx rings
8295 list_for_each_entry(ch, &main_vsi->ch_list, list) {
8296 struct ice_vsi *ch_vsi;
8298 ch_vsi = ch->ch_vsi;
8302 /* reconfig channel resources */
8303 ice_cfg_chnl_all_res(main_vsi, ch);
8305 /* replay BW rate limit if it is non-zero */
8306 if (!ch->max_tx_rate && !ch->min_tx_rate)
8309 err = ice_set_bw_limit(ch_vsi, ch->max_tx_rate,
8312 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",
8313 err, ch->max_tx_rate, ch->min_tx_rate,
8316 dev_dbg(dev, "successfully rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n",
8317 ch->max_tx_rate, ch->min_tx_rate,
8321 /* reconfig RSS for main VSI */
8322 if (main_vsi->ch_rss_size)
8323 ice_vsi_cfg_rss_lut_key(main_vsi);
8328 ice_remove_q_channels(main_vsi, rem_adv_fltr);
8333 * ice_create_q_channels - Add queue channel for the given TCs
8334 * @vsi: VSI to be configured
8336 * Configures queue channel mapping to the given TCs
8338 static int ice_create_q_channels(struct ice_vsi *vsi)
8340 struct ice_pf *pf = vsi->back;
8341 struct ice_channel *ch;
8344 ice_for_each_chnl_tc(i) {
8345 if (!(vsi->all_enatc & BIT(i)))
8348 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
8353 INIT_LIST_HEAD(&ch->list);
8354 ch->num_rxq = vsi->mqprio_qopt.qopt.count[i];
8355 ch->num_txq = vsi->mqprio_qopt.qopt.count[i];
8356 ch->base_q = vsi->mqprio_qopt.qopt.offset[i];
8357 ch->max_tx_rate = vsi->mqprio_qopt.max_rate[i];
8358 ch->min_tx_rate = vsi->mqprio_qopt.min_rate[i];
8360 /* convert to Kbits/s */
8361 if (ch->max_tx_rate)
8362 ch->max_tx_rate = div_u64(ch->max_tx_rate,
8363 ICE_BW_KBPS_DIVISOR);
8364 if (ch->min_tx_rate)
8365 ch->min_tx_rate = div_u64(ch->min_tx_rate,
8366 ICE_BW_KBPS_DIVISOR);
8368 ret = ice_create_q_channel(vsi, ch);
8370 dev_err(ice_pf_to_dev(pf),
8371 "failed creating channel TC:%d\n", i);
8375 list_add_tail(&ch->list, &vsi->ch_list);
8376 vsi->tc_map_vsi[i] = ch->ch_vsi;
8377 dev_dbg(ice_pf_to_dev(pf),
8378 "successfully created channel: VSI %pK\n", ch->ch_vsi);
8383 ice_remove_q_channels(vsi, false);
8389 * ice_setup_tc_mqprio_qdisc - configure multiple traffic classes
8390 * @netdev: net device to configure
8391 * @type_data: TC offload data
8393 static int ice_setup_tc_mqprio_qdisc(struct net_device *netdev, void *type_data)
8395 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
8396 struct ice_netdev_priv *np = netdev_priv(netdev);
8397 struct ice_vsi *vsi = np->vsi;
8398 struct ice_pf *pf = vsi->back;
8399 u16 mode, ena_tc_qdisc = 0;
8400 int cur_txq, cur_rxq;
8405 dev = ice_pf_to_dev(pf);
8406 num_tcf = mqprio_qopt->qopt.num_tc;
8407 hw = mqprio_qopt->qopt.hw;
8408 mode = mqprio_qopt->mode;
8410 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8411 vsi->ch_rss_size = 0;
8412 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8416 /* Generate queue region map for number of TCF requested */
8417 for (i = 0; i < num_tcf; i++)
8418 ena_tc_qdisc |= BIT(i);
8421 case TC_MQPRIO_MODE_CHANNEL:
8423 ret = ice_validate_mqprio_qopt(vsi, mqprio_qopt);
8425 netdev_err(netdev, "failed to validate_mqprio_qopt(), ret %d\n",
8429 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8430 set_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8431 /* don't assume state of hw_tc_offload during driver load
8432 * and set the flag for TC flower filter if hw_tc_offload
8435 if (vsi->netdev->features & NETIF_F_HW_TC)
8436 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
8444 /* Requesting same TCF configuration as already enabled */
8445 if (ena_tc_qdisc == vsi->tc_cfg.ena_tc &&
8446 mode != TC_MQPRIO_MODE_CHANNEL)
8449 /* Pause VSI queues */
8450 ice_dis_vsi(vsi, true);
8452 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
8453 ice_remove_q_channels(vsi, true);
8455 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8456 vsi->req_txq = min_t(int, ice_get_avail_txq_count(pf),
8458 vsi->req_rxq = min_t(int, ice_get_avail_rxq_count(pf),
8461 /* logic to rebuild VSI, same like ethtool -L */
8462 u16 offset = 0, qcount_tx = 0, qcount_rx = 0;
8464 for (i = 0; i < num_tcf; i++) {
8465 if (!(ena_tc_qdisc & BIT(i)))
8468 offset = vsi->mqprio_qopt.qopt.offset[i];
8469 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
8470 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
8472 vsi->req_txq = offset + qcount_tx;
8473 vsi->req_rxq = offset + qcount_rx;
8475 /* store away original rss_size info, so that it gets reused
8476 * form ice_vsi_rebuild during tc-qdisc delete stage - to
8477 * determine, what should be the rss_sizefor main VSI
8479 vsi->orig_rss_size = vsi->rss_size;
8482 /* save current values of Tx and Rx queues before calling VSI rebuild
8483 * for fallback option
8485 cur_txq = vsi->num_txq;
8486 cur_rxq = vsi->num_rxq;
8488 /* proceed with rebuild main VSI using correct number of queues */
8489 ret = ice_vsi_rebuild(vsi, false);
8491 /* fallback to current number of queues */
8492 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n");
8493 vsi->req_txq = cur_txq;
8494 vsi->req_rxq = cur_rxq;
8495 clear_bit(ICE_RESET_FAILED, pf->state);
8496 if (ice_vsi_rebuild(vsi, false)) {
8497 dev_err(dev, "Rebuild of main VSI failed again\n");
8502 vsi->all_numtc = num_tcf;
8503 vsi->all_enatc = ena_tc_qdisc;
8504 ret = ice_vsi_cfg_tc(vsi, ena_tc_qdisc);
8506 netdev_err(netdev, "failed configuring TC for VSI id=%d\n",
8511 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8512 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
8513 u64 min_tx_rate = vsi->mqprio_qopt.min_rate[0];
8515 /* set TC0 rate limit if specified */
8516 if (max_tx_rate || min_tx_rate) {
8517 /* convert to Kbits/s */
8519 max_tx_rate = div_u64(max_tx_rate, ICE_BW_KBPS_DIVISOR);
8521 min_tx_rate = div_u64(min_tx_rate, ICE_BW_KBPS_DIVISOR);
8523 ret = ice_set_bw_limit(vsi, max_tx_rate, min_tx_rate);
8525 dev_dbg(dev, "set Tx rate max %llu min %llu for VSI(%u)\n",
8526 max_tx_rate, min_tx_rate, vsi->vsi_num);
8528 dev_err(dev, "failed to set Tx rate max %llu min %llu for VSI(%u)\n",
8529 max_tx_rate, min_tx_rate, vsi->vsi_num);
8533 ret = ice_create_q_channels(vsi);
8535 netdev_err(netdev, "failed configuring queue channels\n");
8538 netdev_dbg(netdev, "successfully configured channels\n");
8542 if (vsi->ch_rss_size)
8543 ice_vsi_cfg_rss_lut_key(vsi);
8546 /* if error, reset the all_numtc and all_enatc */
8552 ice_ena_vsi(vsi, true);
8557 static LIST_HEAD(ice_block_cb_list);
8560 ice_setup_tc(struct net_device *netdev, enum tc_setup_type type,
8563 struct ice_netdev_priv *np = netdev_priv(netdev);
8564 struct ice_pf *pf = np->vsi->back;
8568 case TC_SETUP_BLOCK:
8569 return flow_block_cb_setup_simple(type_data,
8571 ice_setup_tc_block_cb,
8573 case TC_SETUP_QDISC_MQPRIO:
8574 /* setup traffic classifier for receive side */
8575 mutex_lock(&pf->tc_mutex);
8576 err = ice_setup_tc_mqprio_qdisc(netdev, type_data);
8577 mutex_unlock(&pf->tc_mutex);
8585 static struct ice_indr_block_priv *
8586 ice_indr_block_priv_lookup(struct ice_netdev_priv *np,
8587 struct net_device *netdev)
8589 struct ice_indr_block_priv *cb_priv;
8591 list_for_each_entry(cb_priv, &np->tc_indr_block_priv_list, list) {
8592 if (!cb_priv->netdev)
8594 if (cb_priv->netdev == netdev)
8601 ice_indr_setup_block_cb(enum tc_setup_type type, void *type_data,
8604 struct ice_indr_block_priv *priv = indr_priv;
8605 struct ice_netdev_priv *np = priv->np;
8608 case TC_SETUP_CLSFLOWER:
8609 return ice_setup_tc_cls_flower(np, priv->netdev,
8610 (struct flow_cls_offload *)
8618 ice_indr_setup_tc_block(struct net_device *netdev, struct Qdisc *sch,
8619 struct ice_netdev_priv *np,
8620 struct flow_block_offload *f, void *data,
8621 void (*cleanup)(struct flow_block_cb *block_cb))
8623 struct ice_indr_block_priv *indr_priv;
8624 struct flow_block_cb *block_cb;
8626 if (!ice_is_tunnel_supported(netdev) &&
8627 !(is_vlan_dev(netdev) &&
8628 vlan_dev_real_dev(netdev) == np->vsi->netdev))
8631 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
8634 switch (f->command) {
8635 case FLOW_BLOCK_BIND:
8636 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8640 indr_priv = kzalloc(sizeof(*indr_priv), GFP_KERNEL);
8644 indr_priv->netdev = netdev;
8646 list_add(&indr_priv->list, &np->tc_indr_block_priv_list);
8649 flow_indr_block_cb_alloc(ice_indr_setup_block_cb,
8650 indr_priv, indr_priv,
8651 ice_rep_indr_tc_block_unbind,
8652 f, netdev, sch, data, np,
8655 if (IS_ERR(block_cb)) {
8656 list_del(&indr_priv->list);
8658 return PTR_ERR(block_cb);
8660 flow_block_cb_add(block_cb, f);
8661 list_add_tail(&block_cb->driver_list, &ice_block_cb_list);
8663 case FLOW_BLOCK_UNBIND:
8664 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8668 block_cb = flow_block_cb_lookup(f->block,
8669 ice_indr_setup_block_cb,
8674 flow_indr_block_cb_remove(block_cb, f);
8676 list_del(&block_cb->driver_list);
8685 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
8686 void *cb_priv, enum tc_setup_type type, void *type_data,
8688 void (*cleanup)(struct flow_block_cb *block_cb))
8691 case TC_SETUP_BLOCK:
8692 return ice_indr_setup_tc_block(netdev, sch, cb_priv, type_data,
8701 * ice_open - Called when a network interface becomes active
8702 * @netdev: network interface device structure
8704 * The open entry point is called when a network interface is made
8705 * active by the system (IFF_UP). At this point all resources needed
8706 * for transmit and receive operations are allocated, the interrupt
8707 * handler is registered with the OS, the netdev watchdog is enabled,
8708 * and the stack is notified that the interface is ready.
8710 * Returns 0 on success, negative value on failure
8712 int ice_open(struct net_device *netdev)
8714 struct ice_netdev_priv *np = netdev_priv(netdev);
8715 struct ice_pf *pf = np->vsi->back;
8717 if (ice_is_reset_in_progress(pf->state)) {
8718 netdev_err(netdev, "can't open net device while reset is in progress");
8722 return ice_open_internal(netdev);
8726 * ice_open_internal - Called when a network interface becomes active
8727 * @netdev: network interface device structure
8729 * Internal ice_open implementation. Should not be used directly except for ice_open and reset
8732 * Returns 0 on success, negative value on failure
8734 int ice_open_internal(struct net_device *netdev)
8736 struct ice_netdev_priv *np = netdev_priv(netdev);
8737 struct ice_vsi *vsi = np->vsi;
8738 struct ice_pf *pf = vsi->back;
8739 struct ice_port_info *pi;
8742 if (test_bit(ICE_NEEDS_RESTART, pf->state)) {
8743 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
8747 netif_carrier_off(netdev);
8749 pi = vsi->port_info;
8750 err = ice_update_link_info(pi);
8752 netdev_err(netdev, "Failed to get link info, error %d\n", err);
8756 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
8758 /* Set PHY if there is media, otherwise, turn off PHY */
8759 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
8760 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8761 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) {
8762 err = ice_init_phy_user_cfg(pi);
8764 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n",
8770 err = ice_configure_phy(vsi);
8772 netdev_err(netdev, "Failed to set physical link up, error %d\n",
8777 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8778 ice_set_link(vsi, false);
8781 err = ice_vsi_open(vsi);
8783 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
8784 vsi->vsi_num, vsi->vsw->sw_id);
8786 /* Update existing tunnels information */
8787 udp_tunnel_get_rx_info(netdev);
8793 * ice_stop - Disables a network interface
8794 * @netdev: network interface device structure
8796 * The stop entry point is called when an interface is de-activated by the OS,
8797 * and the netdevice enters the DOWN state. The hardware is still under the
8798 * driver's control, but the netdev interface is disabled.
8800 * Returns success only - not allowed to fail
8802 int ice_stop(struct net_device *netdev)
8804 struct ice_netdev_priv *np = netdev_priv(netdev);
8805 struct ice_vsi *vsi = np->vsi;
8806 struct ice_pf *pf = vsi->back;
8808 if (ice_is_reset_in_progress(pf->state)) {
8809 netdev_err(netdev, "can't stop net device while reset is in progress");
8819 * ice_features_check - Validate encapsulated packet conforms to limits
8821 * @netdev: This port's netdev
8822 * @features: Offload features that the stack believes apply
8824 static netdev_features_t
8825 ice_features_check(struct sk_buff *skb,
8826 struct net_device __always_unused *netdev,
8827 netdev_features_t features)
8829 bool gso = skb_is_gso(skb);
8832 /* No point in doing any of this if neither checksum nor GSO are
8833 * being requested for this frame. We can rule out both by just
8834 * checking for CHECKSUM_PARTIAL
8836 if (skb->ip_summed != CHECKSUM_PARTIAL)
8839 /* We cannot support GSO if the MSS is going to be less than
8840 * 64 bytes. If it is then we need to drop support for GSO.
8842 if (gso && (skb_shinfo(skb)->gso_size < ICE_TXD_CTX_MIN_MSS))
8843 features &= ~NETIF_F_GSO_MASK;
8845 len = skb_network_offset(skb);
8846 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
8847 goto out_rm_features;
8849 len = skb_network_header_len(skb);
8850 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8851 goto out_rm_features;
8853 if (skb->encapsulation) {
8854 /* this must work for VXLAN frames AND IPIP/SIT frames, and in
8855 * the case of IPIP frames, the transport header pointer is
8856 * after the inner header! So check to make sure that this
8857 * is a GRE or UDP_TUNNEL frame before doing that math.
8859 if (gso && (skb_shinfo(skb)->gso_type &
8860 (SKB_GSO_GRE | SKB_GSO_UDP_TUNNEL))) {
8861 len = skb_inner_network_header(skb) -
8862 skb_transport_header(skb);
8863 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
8864 goto out_rm_features;
8867 len = skb_inner_network_header_len(skb);
8868 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8869 goto out_rm_features;
8874 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
8877 static const struct net_device_ops ice_netdev_safe_mode_ops = {
8878 .ndo_open = ice_open,
8879 .ndo_stop = ice_stop,
8880 .ndo_start_xmit = ice_start_xmit,
8881 .ndo_set_mac_address = ice_set_mac_address,
8882 .ndo_validate_addr = eth_validate_addr,
8883 .ndo_change_mtu = ice_change_mtu,
8884 .ndo_get_stats64 = ice_get_stats64,
8885 .ndo_tx_timeout = ice_tx_timeout,
8886 .ndo_bpf = ice_xdp_safe_mode,
8889 static const struct net_device_ops ice_netdev_ops = {
8890 .ndo_open = ice_open,
8891 .ndo_stop = ice_stop,
8892 .ndo_start_xmit = ice_start_xmit,
8893 .ndo_select_queue = ice_select_queue,
8894 .ndo_features_check = ice_features_check,
8895 .ndo_fix_features = ice_fix_features,
8896 .ndo_set_rx_mode = ice_set_rx_mode,
8897 .ndo_set_mac_address = ice_set_mac_address,
8898 .ndo_validate_addr = eth_validate_addr,
8899 .ndo_change_mtu = ice_change_mtu,
8900 .ndo_get_stats64 = ice_get_stats64,
8901 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
8902 .ndo_eth_ioctl = ice_eth_ioctl,
8903 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
8904 .ndo_set_vf_mac = ice_set_vf_mac,
8905 .ndo_get_vf_config = ice_get_vf_cfg,
8906 .ndo_set_vf_trust = ice_set_vf_trust,
8907 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
8908 .ndo_set_vf_link_state = ice_set_vf_link_state,
8909 .ndo_get_vf_stats = ice_get_vf_stats,
8910 .ndo_set_vf_rate = ice_set_vf_bw,
8911 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
8912 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
8913 .ndo_setup_tc = ice_setup_tc,
8914 .ndo_set_features = ice_set_features,
8915 .ndo_bridge_getlink = ice_bridge_getlink,
8916 .ndo_bridge_setlink = ice_bridge_setlink,
8917 .ndo_fdb_add = ice_fdb_add,
8918 .ndo_fdb_del = ice_fdb_del,
8919 #ifdef CONFIG_RFS_ACCEL
8920 .ndo_rx_flow_steer = ice_rx_flow_steer,
8922 .ndo_tx_timeout = ice_tx_timeout,
8924 .ndo_xdp_xmit = ice_xdp_xmit,
8925 .ndo_xsk_wakeup = ice_xsk_wakeup,