1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018-2023, Intel Corporation. */
4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <generated/utsrelease.h>
9 #include <linux/crash_dump.h>
14 #include "ice_dcb_lib.h"
15 #include "ice_dcb_nl.h"
16 #include "devlink/devlink.h"
17 #include "devlink/devlink_port.h"
18 #include "ice_sf_eth.h"
19 #include "ice_hwmon.h"
20 /* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the
21 * ice tracepoint functions. This must be done exactly once across the
24 #define CREATE_TRACE_POINTS
25 #include "ice_trace.h"
26 #include "ice_eswitch.h"
27 #include "ice_tc_lib.h"
28 #include "ice_vsi_vlan_ops.h"
29 #include <net/xdp_sock_drv.h>
31 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
32 static const char ice_driver_string[] = DRV_SUMMARY;
33 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
35 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
36 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
37 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
39 MODULE_DESCRIPTION(DRV_SUMMARY);
40 MODULE_IMPORT_NS(LIBIE);
41 MODULE_LICENSE("GPL v2");
42 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
44 static int debug = -1;
45 module_param(debug, int, 0644);
46 #ifndef CONFIG_DYNAMIC_DEBUG
47 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
49 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
50 #endif /* !CONFIG_DYNAMIC_DEBUG */
52 DEFINE_STATIC_KEY_FALSE(ice_xdp_locking_key);
53 EXPORT_SYMBOL(ice_xdp_locking_key);
56 * ice_hw_to_dev - Get device pointer from the hardware structure
57 * @hw: pointer to the device HW structure
59 * Used to access the device pointer from compilation units which can't easily
60 * include the definition of struct ice_pf without leading to circular header
63 struct device *ice_hw_to_dev(struct ice_hw *hw)
65 struct ice_pf *pf = container_of(hw, struct ice_pf, hw);
67 return &pf->pdev->dev;
70 static struct workqueue_struct *ice_wq;
71 struct workqueue_struct *ice_lag_wq;
72 static const struct net_device_ops ice_netdev_safe_mode_ops;
73 static const struct net_device_ops ice_netdev_ops;
75 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
77 static void ice_vsi_release_all(struct ice_pf *pf);
79 static int ice_rebuild_channels(struct ice_pf *pf);
80 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_adv_fltr);
83 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
84 void *cb_priv, enum tc_setup_type type, void *type_data,
86 void (*cleanup)(struct flow_block_cb *block_cb));
88 bool netif_is_ice(const struct net_device *dev)
90 return dev && (dev->netdev_ops == &ice_netdev_ops);
94 * ice_get_tx_pending - returns number of Tx descriptors not processed
95 * @ring: the ring of descriptors
97 static u16 ice_get_tx_pending(struct ice_tx_ring *ring)
101 head = ring->next_to_clean;
102 tail = ring->next_to_use;
105 return (head < tail) ?
106 tail - head : (tail + ring->count - head);
111 * ice_check_for_hang_subtask - check for and recover hung queues
112 * @pf: pointer to PF struct
114 static void ice_check_for_hang_subtask(struct ice_pf *pf)
116 struct ice_vsi *vsi = NULL;
122 ice_for_each_vsi(pf, v)
123 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
128 if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state))
131 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
136 ice_for_each_txq(vsi, i) {
137 struct ice_tx_ring *tx_ring = vsi->tx_rings[i];
138 struct ice_ring_stats *ring_stats;
142 if (ice_ring_ch_enabled(tx_ring))
145 ring_stats = tx_ring->ring_stats;
150 /* If packet counter has not changed the queue is
151 * likely stalled, so force an interrupt for this
154 * prev_pkt would be negative if there was no
157 packets = ring_stats->stats.pkts & INT_MAX;
158 if (ring_stats->tx_stats.prev_pkt == packets) {
159 /* Trigger sw interrupt to revive the queue */
160 ice_trigger_sw_intr(hw, tx_ring->q_vector);
164 /* Memory barrier between read of packet count and call
165 * to ice_get_tx_pending()
168 ring_stats->tx_stats.prev_pkt =
169 ice_get_tx_pending(tx_ring) ? packets : -1;
175 * ice_init_mac_fltr - Set initial MAC filters
176 * @pf: board private structure
178 * Set initial set of MAC filters for PF VSI; configure filters for permanent
179 * address and broadcast address. If an error is encountered, netdevice will be
182 static int ice_init_mac_fltr(struct ice_pf *pf)
187 vsi = ice_get_main_vsi(pf);
191 perm_addr = vsi->port_info->mac.perm_addr;
192 return ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
196 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
197 * @netdev: the net device on which the sync is happening
198 * @addr: MAC address to sync
200 * This is a callback function which is called by the in kernel device sync
201 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
202 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
203 * MAC filters from the hardware.
205 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
207 struct ice_netdev_priv *np = netdev_priv(netdev);
208 struct ice_vsi *vsi = np->vsi;
210 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
218 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
219 * @netdev: the net device on which the unsync is happening
220 * @addr: MAC address to unsync
222 * This is a callback function which is called by the in kernel device unsync
223 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
224 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
225 * delete the MAC filters from the hardware.
227 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
229 struct ice_netdev_priv *np = netdev_priv(netdev);
230 struct ice_vsi *vsi = np->vsi;
232 /* Under some circumstances, we might receive a request to delete our
233 * own device address from our uc list. Because we store the device
234 * address in the VSI's MAC filter list, we need to ignore such
235 * requests and not delete our device address from this list.
237 if (ether_addr_equal(addr, netdev->dev_addr))
240 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
248 * ice_vsi_fltr_changed - check if filter state changed
249 * @vsi: VSI to be checked
251 * returns true if filter state has changed, false otherwise.
253 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
255 return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) ||
256 test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
260 * ice_set_promisc - Enable promiscuous mode for a given PF
261 * @vsi: the VSI being configured
262 * @promisc_m: mask of promiscuous config bits
265 static int ice_set_promisc(struct ice_vsi *vsi, u8 promisc_m)
269 if (vsi->type != ICE_VSI_PF)
272 if (ice_vsi_has_non_zero_vlans(vsi)) {
273 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX);
274 status = ice_fltr_set_vlan_vsi_promisc(&vsi->back->hw, vsi,
277 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
280 if (status && status != -EEXIST)
283 netdev_dbg(vsi->netdev, "set promisc filter bits for VSI %i: 0x%x\n",
284 vsi->vsi_num, promisc_m);
289 * ice_clear_promisc - Disable promiscuous mode for a given PF
290 * @vsi: the VSI being configured
291 * @promisc_m: mask of promiscuous config bits
294 static int ice_clear_promisc(struct ice_vsi *vsi, u8 promisc_m)
298 if (vsi->type != ICE_VSI_PF)
301 if (ice_vsi_has_non_zero_vlans(vsi)) {
302 promisc_m |= (ICE_PROMISC_VLAN_RX | ICE_PROMISC_VLAN_TX);
303 status = ice_fltr_clear_vlan_vsi_promisc(&vsi->back->hw, vsi,
306 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
310 netdev_dbg(vsi->netdev, "clear promisc filter bits for VSI %i: 0x%x\n",
311 vsi->vsi_num, promisc_m);
316 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
317 * @vsi: ptr to the VSI
319 * Push any outstanding VSI filter changes through the AdminQ.
321 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
323 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
324 struct device *dev = ice_pf_to_dev(vsi->back);
325 struct net_device *netdev = vsi->netdev;
326 bool promisc_forced_on = false;
327 struct ice_pf *pf = vsi->back;
328 struct ice_hw *hw = &pf->hw;
329 u32 changed_flags = 0;
335 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
336 usleep_range(1000, 2000);
338 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
339 vsi->current_netdev_flags = vsi->netdev->flags;
341 INIT_LIST_HEAD(&vsi->tmp_sync_list);
342 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
344 if (ice_vsi_fltr_changed(vsi)) {
345 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
346 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
348 /* grab the netdev's addr_list_lock */
349 netif_addr_lock_bh(netdev);
350 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
351 ice_add_mac_to_unsync_list);
352 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
353 ice_add_mac_to_unsync_list);
354 /* our temp lists are populated. release lock */
355 netif_addr_unlock_bh(netdev);
358 /* Remove MAC addresses in the unsync list */
359 err = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
360 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
362 netdev_err(netdev, "Failed to delete MAC filters\n");
363 /* if we failed because of alloc failures, just bail */
368 /* Add MAC addresses in the sync list */
369 err = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
370 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
371 /* If filter is added successfully or already exists, do not go into
372 * 'if' condition and report it as error. Instead continue processing
373 * rest of the function.
375 if (err && err != -EEXIST) {
376 netdev_err(netdev, "Failed to add MAC filters\n");
377 /* If there is no more space for new umac filters, VSI
378 * should go into promiscuous mode. There should be some
379 * space reserved for promiscuous filters.
381 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
382 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC,
384 promisc_forced_on = true;
385 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
392 /* check for changes in promiscuous modes */
393 if (changed_flags & IFF_ALLMULTI) {
394 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
395 err = ice_set_promisc(vsi, ICE_MCAST_PROMISC_BITS);
397 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
401 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
402 err = ice_clear_promisc(vsi, ICE_MCAST_PROMISC_BITS);
404 vsi->current_netdev_flags |= IFF_ALLMULTI;
410 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
411 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) {
412 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
413 if (vsi->current_netdev_flags & IFF_PROMISC) {
414 /* Apply Rx filter rule to get traffic from wire */
415 if (!ice_is_dflt_vsi_in_use(vsi->port_info)) {
416 err = ice_set_dflt_vsi(vsi);
417 if (err && err != -EEXIST) {
418 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
420 vsi->current_netdev_flags &=
425 vlan_ops->dis_rx_filtering(vsi);
427 /* promiscuous mode implies allmulticast so
428 * that VSIs that are in promiscuous mode are
429 * subscribed to multicast packets coming to
432 err = ice_set_promisc(vsi,
433 ICE_MCAST_PROMISC_BITS);
438 /* Clear Rx filter to remove traffic from wire */
439 if (ice_is_vsi_dflt_vsi(vsi)) {
440 err = ice_clear_dflt_vsi(vsi);
442 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
444 vsi->current_netdev_flags |=
448 if (vsi->netdev->features &
449 NETIF_F_HW_VLAN_CTAG_FILTER)
450 vlan_ops->ena_rx_filtering(vsi);
453 /* disable allmulti here, but only if allmulti is not
454 * still enabled for the netdev
456 if (!(vsi->current_netdev_flags & IFF_ALLMULTI)) {
457 err = ice_clear_promisc(vsi,
458 ICE_MCAST_PROMISC_BITS);
460 netdev_err(netdev, "Error %d clearing multicast promiscuous on VSI %i\n",
469 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
472 /* if something went wrong then set the changed flag so we try again */
473 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
474 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
476 clear_bit(ICE_CFG_BUSY, vsi->state);
481 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
482 * @pf: board private structure
484 static void ice_sync_fltr_subtask(struct ice_pf *pf)
488 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
491 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
493 ice_for_each_vsi(pf, v)
494 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
495 ice_vsi_sync_fltr(pf->vsi[v])) {
496 /* come back and try again later */
497 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
503 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
505 * @locked: is the rtnl_lock already held
507 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
512 ice_for_each_vsi(pf, v)
514 ice_dis_vsi(pf->vsi[v], locked);
516 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++)
517 pf->pf_agg_node[node].num_vsis = 0;
519 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++)
520 pf->vf_agg_node[node].num_vsis = 0;
524 * ice_clear_sw_switch_recipes - clear switch recipes
525 * @pf: board private structure
527 * Mark switch recipes as not created in sw structures. There are cases where
528 * rules (especially advanced rules) need to be restored, either re-read from
529 * hardware or added again. For example after the reset. 'recp_created' flag
530 * prevents from doing that and need to be cleared upfront.
532 static void ice_clear_sw_switch_recipes(struct ice_pf *pf)
534 struct ice_sw_recipe *recp;
537 recp = pf->hw.switch_info->recp_list;
538 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
539 recp[i].recp_created = false;
543 * ice_prepare_for_reset - prep for reset
544 * @pf: board private structure
545 * @reset_type: reset type requested
547 * Inform or close all dependent features in prep for reset.
550 ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
552 struct ice_hw *hw = &pf->hw;
557 dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type);
559 /* already prepared for reset */
560 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state))
563 synchronize_irq(pf->oicr_irq.virq);
565 ice_unplug_aux_dev(pf);
567 /* Notify VFs of impending reset */
568 if (ice_check_sq_alive(hw, &hw->mailboxq))
569 ice_vc_notify_reset(pf);
571 /* Disable VFs until reset is completed */
572 mutex_lock(&pf->vfs.table_lock);
573 ice_for_each_vf(pf, bkt, vf)
574 ice_set_vf_state_dis(vf);
575 mutex_unlock(&pf->vfs.table_lock);
577 if (ice_is_eswitch_mode_switchdev(pf)) {
578 if (reset_type != ICE_RESET_PFR)
579 ice_clear_sw_switch_recipes(pf);
582 /* release ADQ specific HW and SW resources */
583 vsi = ice_get_main_vsi(pf);
587 /* to be on safe side, reset orig_rss_size so that normal flow
588 * of deciding rss_size can take precedence
590 vsi->orig_rss_size = 0;
592 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
593 if (reset_type == ICE_RESET_PFR) {
594 vsi->old_ena_tc = vsi->all_enatc;
595 vsi->old_numtc = vsi->all_numtc;
597 ice_remove_q_channels(vsi, true);
599 /* for other reset type, do not support channel rebuild
600 * hence reset needed info
608 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
609 memset(&vsi->mqprio_qopt, 0, sizeof(vsi->mqprio_qopt));
614 netif_device_detach(vsi->netdev);
617 /* clear SW filtering DB */
618 ice_clear_hw_tbls(hw);
619 /* disable the VSIs and their queues that are not already DOWN */
620 set_bit(ICE_VSI_REBUILD_PENDING, ice_get_main_vsi(pf)->state);
621 ice_pf_dis_all_vsi(pf, false);
623 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
624 ice_ptp_prepare_for_reset(pf, reset_type);
626 if (ice_is_feature_supported(pf, ICE_F_GNSS))
630 ice_sched_clear_port(hw->port_info);
632 ice_shutdown_all_ctrlq(hw, false);
634 set_bit(ICE_PREPARED_FOR_RESET, pf->state);
638 * ice_do_reset - Initiate one of many types of resets
639 * @pf: board private structure
640 * @reset_type: reset type requested before this function was called.
642 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
644 struct device *dev = ice_pf_to_dev(pf);
645 struct ice_hw *hw = &pf->hw;
647 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
649 if (pf->lag && pf->lag->bonded && reset_type == ICE_RESET_PFR) {
650 dev_dbg(dev, "PFR on a bonded interface, promoting to CORER\n");
651 reset_type = ICE_RESET_CORER;
654 ice_prepare_for_reset(pf, reset_type);
656 /* trigger the reset */
657 if (ice_reset(hw, reset_type)) {
658 dev_err(dev, "reset %d failed\n", reset_type);
659 set_bit(ICE_RESET_FAILED, pf->state);
660 clear_bit(ICE_RESET_OICR_RECV, pf->state);
661 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
662 clear_bit(ICE_PFR_REQ, pf->state);
663 clear_bit(ICE_CORER_REQ, pf->state);
664 clear_bit(ICE_GLOBR_REQ, pf->state);
665 wake_up(&pf->reset_wait_queue);
669 /* PFR is a bit of a special case because it doesn't result in an OICR
670 * interrupt. So for PFR, rebuild after the reset and clear the reset-
671 * associated state bits.
673 if (reset_type == ICE_RESET_PFR) {
675 ice_rebuild(pf, reset_type);
676 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
677 clear_bit(ICE_PFR_REQ, pf->state);
678 wake_up(&pf->reset_wait_queue);
679 ice_reset_all_vfs(pf);
684 * ice_reset_subtask - Set up for resetting the device and driver
685 * @pf: board private structure
687 static void ice_reset_subtask(struct ice_pf *pf)
689 enum ice_reset_req reset_type = ICE_RESET_INVAL;
691 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
692 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
693 * of reset is pending and sets bits in pf->state indicating the reset
694 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set
695 * prepare for pending reset if not already (for PF software-initiated
696 * global resets the software should already be prepared for it as
697 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated
698 * by firmware or software on other PFs, that bit is not set so prepare
699 * for the reset now), poll for reset done, rebuild and return.
701 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) {
702 /* Perform the largest reset requested */
703 if (test_and_clear_bit(ICE_CORER_RECV, pf->state))
704 reset_type = ICE_RESET_CORER;
705 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state))
706 reset_type = ICE_RESET_GLOBR;
707 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state))
708 reset_type = ICE_RESET_EMPR;
709 /* return if no valid reset type requested */
710 if (reset_type == ICE_RESET_INVAL)
712 ice_prepare_for_reset(pf, reset_type);
714 /* make sure we are ready to rebuild */
715 if (ice_check_reset(&pf->hw)) {
716 set_bit(ICE_RESET_FAILED, pf->state);
718 /* done with reset. start rebuild */
719 pf->hw.reset_ongoing = false;
720 ice_rebuild(pf, reset_type);
721 /* clear bit to resume normal operations, but
722 * ICE_NEEDS_RESTART bit is set in case rebuild failed
724 clear_bit(ICE_RESET_OICR_RECV, pf->state);
725 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
726 clear_bit(ICE_PFR_REQ, pf->state);
727 clear_bit(ICE_CORER_REQ, pf->state);
728 clear_bit(ICE_GLOBR_REQ, pf->state);
729 wake_up(&pf->reset_wait_queue);
730 ice_reset_all_vfs(pf);
736 /* No pending resets to finish processing. Check for new resets */
737 if (test_bit(ICE_PFR_REQ, pf->state)) {
738 reset_type = ICE_RESET_PFR;
739 if (pf->lag && pf->lag->bonded) {
740 dev_dbg(ice_pf_to_dev(pf), "PFR on a bonded interface, promoting to CORER\n");
741 reset_type = ICE_RESET_CORER;
744 if (test_bit(ICE_CORER_REQ, pf->state))
745 reset_type = ICE_RESET_CORER;
746 if (test_bit(ICE_GLOBR_REQ, pf->state))
747 reset_type = ICE_RESET_GLOBR;
748 /* If no valid reset type requested just return */
749 if (reset_type == ICE_RESET_INVAL)
752 /* reset if not already down or busy */
753 if (!test_bit(ICE_DOWN, pf->state) &&
754 !test_bit(ICE_CFG_BUSY, pf->state)) {
755 ice_do_reset(pf, reset_type);
760 * ice_print_topo_conflict - print topology conflict message
761 * @vsi: the VSI whose topology status is being checked
763 static void ice_print_topo_conflict(struct ice_vsi *vsi)
765 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
766 case ICE_AQ_LINK_TOPO_CONFLICT:
767 case ICE_AQ_LINK_MEDIA_CONFLICT:
768 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
769 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
770 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
771 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");
773 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
774 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, vsi->back->flags))
775 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");
777 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");
785 * ice_print_link_msg - print link up or down message
786 * @vsi: the VSI whose link status is being queried
787 * @isup: boolean for if the link is now up or down
789 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
791 struct ice_aqc_get_phy_caps_data *caps;
792 const char *an_advertised;
803 if (vsi->current_isup == isup)
806 vsi->current_isup = isup;
809 netdev_info(vsi->netdev, "NIC Link is Down\n");
813 switch (vsi->port_info->phy.link_info.link_speed) {
814 case ICE_AQ_LINK_SPEED_200GB:
817 case ICE_AQ_LINK_SPEED_100GB:
820 case ICE_AQ_LINK_SPEED_50GB:
823 case ICE_AQ_LINK_SPEED_40GB:
826 case ICE_AQ_LINK_SPEED_25GB:
829 case ICE_AQ_LINK_SPEED_20GB:
832 case ICE_AQ_LINK_SPEED_10GB:
835 case ICE_AQ_LINK_SPEED_5GB:
838 case ICE_AQ_LINK_SPEED_2500MB:
841 case ICE_AQ_LINK_SPEED_1000MB:
844 case ICE_AQ_LINK_SPEED_100MB:
852 switch (vsi->port_info->fc.current_mode) {
856 case ICE_FC_TX_PAUSE:
859 case ICE_FC_RX_PAUSE:
870 /* Get FEC mode based on negotiated link info */
871 switch (vsi->port_info->phy.link_info.fec_info) {
872 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
873 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
876 case ICE_AQ_LINK_25G_KR_FEC_EN:
877 fec = "FC-FEC/BASE-R";
884 /* check if autoneg completed, might be false due to not supported */
885 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
890 /* Get FEC mode requested based on PHY caps last SW configuration */
891 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
894 an_advertised = "Unknown";
898 status = ice_aq_get_phy_caps(vsi->port_info, false,
899 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
901 netdev_info(vsi->netdev, "Get phy capability failed.\n");
903 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off";
905 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
906 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
908 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
909 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
910 fec_req = "FC-FEC/BASE-R";
917 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",
918 speed, fec_req, fec, an_advertised, an, fc);
919 ice_print_topo_conflict(vsi);
923 * ice_vsi_link_event - update the VSI's netdev
924 * @vsi: the VSI on which the link event occurred
925 * @link_up: whether or not the VSI needs to be set up or down
927 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
932 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev)
935 if (vsi->type == ICE_VSI_PF) {
936 if (link_up == netif_carrier_ok(vsi->netdev))
940 netif_carrier_on(vsi->netdev);
941 netif_tx_wake_all_queues(vsi->netdev);
943 netif_carrier_off(vsi->netdev);
944 netif_tx_stop_all_queues(vsi->netdev);
950 * ice_set_dflt_mib - send a default config MIB to the FW
951 * @pf: private PF struct
953 * This function sends a default configuration MIB to the FW.
955 * If this function errors out at any point, the driver is still able to
956 * function. The main impact is that LFC may not operate as expected.
957 * Therefore an error state in this function should be treated with a DBG
958 * message and continue on with driver rebuild/reenable.
960 static void ice_set_dflt_mib(struct ice_pf *pf)
962 struct device *dev = ice_pf_to_dev(pf);
963 u8 mib_type, *buf, *lldpmib = NULL;
964 u16 len, typelen, offset = 0;
965 struct ice_lldp_org_tlv *tlv;
966 struct ice_hw *hw = &pf->hw;
969 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
970 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
972 dev_dbg(dev, "%s Failed to allocate MIB memory\n",
977 /* Add ETS CFG TLV */
978 tlv = (struct ice_lldp_org_tlv *)lldpmib;
979 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
980 ICE_IEEE_ETS_TLV_LEN);
981 tlv->typelen = htons(typelen);
982 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
983 ICE_IEEE_SUBTYPE_ETS_CFG);
984 tlv->ouisubtype = htonl(ouisubtype);
989 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0.
990 * Octets 5 - 12 are BW values, set octet 5 to 100% BW.
991 * Octets 13 - 20 are TSA values - leave as zeros
994 len = FIELD_GET(ICE_LLDP_TLV_LEN_M, typelen);
996 tlv = (struct ice_lldp_org_tlv *)
997 ((char *)tlv + sizeof(tlv->typelen) + len);
999 /* Add ETS REC TLV */
1001 tlv->typelen = htons(typelen);
1003 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1004 ICE_IEEE_SUBTYPE_ETS_REC);
1005 tlv->ouisubtype = htonl(ouisubtype);
1007 /* First octet of buf is reserved
1008 * Octets 1 - 4 map UP to TC - all UPs map to zero
1009 * Octets 5 - 12 are BW values - set TC 0 to 100%.
1010 * Octets 13 - 20 are TSA value - leave as zeros
1014 tlv = (struct ice_lldp_org_tlv *)
1015 ((char *)tlv + sizeof(tlv->typelen) + len);
1017 /* Add PFC CFG TLV */
1018 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
1019 ICE_IEEE_PFC_TLV_LEN);
1020 tlv->typelen = htons(typelen);
1022 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
1023 ICE_IEEE_SUBTYPE_PFC_CFG);
1024 tlv->ouisubtype = htonl(ouisubtype);
1026 /* Octet 1 left as all zeros - PFC disabled */
1028 len = FIELD_GET(ICE_LLDP_TLV_LEN_M, typelen);
1031 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL))
1032 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__);
1038 * ice_check_phy_fw_load - check if PHY FW load failed
1039 * @pf: pointer to PF struct
1040 * @link_cfg_err: bitmap from the link info structure
1042 * check if external PHY FW load failed and print an error message if it did
1044 static void ice_check_phy_fw_load(struct ice_pf *pf, u8 link_cfg_err)
1046 if (!(link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE)) {
1047 clear_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
1051 if (test_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags))
1054 if (link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE) {
1055 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");
1056 set_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
1061 * ice_check_module_power
1062 * @pf: pointer to PF struct
1063 * @link_cfg_err: bitmap from the link info structure
1065 * check module power level returned by a previous call to aq_get_link_info
1066 * and print error messages if module power level is not supported
1068 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err)
1070 /* if module power level is supported, clear the flag */
1071 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT |
1072 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) {
1073 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1077 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the
1078 * above block didn't clear this bit, there's nothing to do
1080 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags))
1083 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) {
1084 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n");
1085 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1086 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) {
1087 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n");
1088 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1093 * ice_check_link_cfg_err - check if link configuration failed
1094 * @pf: pointer to the PF struct
1095 * @link_cfg_err: bitmap from the link info structure
1097 * print if any link configuration failure happens due to the value in the
1098 * link_cfg_err parameter in the link info structure
1100 static void ice_check_link_cfg_err(struct ice_pf *pf, u8 link_cfg_err)
1102 ice_check_module_power(pf, link_cfg_err);
1103 ice_check_phy_fw_load(pf, link_cfg_err);
1107 * ice_link_event - process the link event
1108 * @pf: PF that the link event is associated with
1109 * @pi: port_info for the port that the link event is associated with
1110 * @link_up: true if the physical link is up and false if it is down
1111 * @link_speed: current link speed received from the link event
1113 * Returns 0 on success and negative on failure
1116 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
1119 struct device *dev = ice_pf_to_dev(pf);
1120 struct ice_phy_info *phy_info;
1121 struct ice_vsi *vsi;
1126 phy_info = &pi->phy;
1127 phy_info->link_info_old = phy_info->link_info;
1129 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
1130 old_link_speed = phy_info->link_info_old.link_speed;
1132 /* update the link info structures and re-enable link events,
1133 * don't bail on failure due to other book keeping needed
1135 status = ice_update_link_info(pi);
1137 dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n",
1139 ice_aq_str(pi->hw->adminq.sq_last_status));
1141 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
1143 /* Check if the link state is up after updating link info, and treat
1144 * this event as an UP event since the link is actually UP now.
1146 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
1149 vsi = ice_get_main_vsi(pf);
1150 if (!vsi || !vsi->port_info)
1153 /* turn off PHY if media was removed */
1154 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
1155 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
1156 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1157 ice_set_link(vsi, false);
1160 /* if the old link up/down and speed is the same as the new */
1161 if (link_up == old_link && link_speed == old_link_speed)
1164 ice_ptp_link_change(pf, pf->hw.pf_id, link_up);
1166 if (ice_is_dcb_active(pf)) {
1167 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
1168 ice_dcb_rebuild(pf);
1171 ice_set_dflt_mib(pf);
1173 ice_vsi_link_event(vsi, link_up);
1174 ice_print_link_msg(vsi, link_up);
1176 ice_vc_notify_link_state(pf);
1182 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
1183 * @pf: board private structure
1185 static void ice_watchdog_subtask(struct ice_pf *pf)
1189 /* if interface is down do nothing */
1190 if (test_bit(ICE_DOWN, pf->state) ||
1191 test_bit(ICE_CFG_BUSY, pf->state))
1194 /* make sure we don't do these things too often */
1195 if (time_before(jiffies,
1196 pf->serv_tmr_prev + pf->serv_tmr_period))
1199 pf->serv_tmr_prev = jiffies;
1201 /* Update the stats for active netdevs so the network stack
1202 * can look at updated numbers whenever it cares to
1204 ice_update_pf_stats(pf);
1205 ice_for_each_vsi(pf, i)
1206 if (pf->vsi[i] && pf->vsi[i]->netdev)
1207 ice_update_vsi_stats(pf->vsi[i]);
1211 * ice_init_link_events - enable/initialize link events
1212 * @pi: pointer to the port_info instance
1214 * Returns -EIO on failure, 0 on success
1216 static int ice_init_link_events(struct ice_port_info *pi)
1220 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
1221 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL |
1222 ICE_AQ_LINK_EVENT_PHY_FW_LOAD_FAIL));
1224 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
1225 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
1230 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
1231 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
1240 * ice_handle_link_event - handle link event via ARQ
1241 * @pf: PF that the link event is associated with
1242 * @event: event structure containing link status info
1245 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1247 struct ice_aqc_get_link_status_data *link_data;
1248 struct ice_port_info *port_info;
1251 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
1252 port_info = pf->hw.port_info;
1256 status = ice_link_event(pf, port_info,
1257 !!(link_data->link_info & ICE_AQ_LINK_UP),
1258 le16_to_cpu(link_data->link_speed));
1260 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
1267 * ice_get_fwlog_data - copy the FW log data from ARQ event
1268 * @pf: PF that the FW log event is associated with
1269 * @event: event structure containing FW log data
1272 ice_get_fwlog_data(struct ice_pf *pf, struct ice_rq_event_info *event)
1274 struct ice_fwlog_data *fwlog;
1275 struct ice_hw *hw = &pf->hw;
1277 fwlog = &hw->fwlog_ring.rings[hw->fwlog_ring.tail];
1279 memset(fwlog->data, 0, PAGE_SIZE);
1280 fwlog->data_size = le16_to_cpu(event->desc.datalen);
1282 memcpy(fwlog->data, event->msg_buf, fwlog->data_size);
1283 ice_fwlog_ring_increment(&hw->fwlog_ring.tail, hw->fwlog_ring.size);
1285 if (ice_fwlog_ring_full(&hw->fwlog_ring)) {
1286 /* the rings are full so bump the head to create room */
1287 ice_fwlog_ring_increment(&hw->fwlog_ring.head,
1288 hw->fwlog_ring.size);
1293 * ice_aq_prep_for_event - Prepare to wait for an AdminQ event from firmware
1294 * @pf: pointer to the PF private structure
1295 * @task: intermediate helper storage and identifier for waiting
1296 * @opcode: the opcode to wait for
1298 * Prepares to wait for a specific AdminQ completion event on the ARQ for
1299 * a given PF. Actual wait would be done by a call to ice_aq_wait_for_event().
1301 * Calls are separated to allow caller registering for event before sending
1302 * the command, which mitigates a race between registering and FW responding.
1304 * To obtain only the descriptor contents, pass an task->event with null
1305 * msg_buf. If the complete data buffer is desired, allocate the
1306 * task->event.msg_buf with enough space ahead of time.
1308 void ice_aq_prep_for_event(struct ice_pf *pf, struct ice_aq_task *task,
1311 INIT_HLIST_NODE(&task->entry);
1312 task->opcode = opcode;
1313 task->state = ICE_AQ_TASK_WAITING;
1315 spin_lock_bh(&pf->aq_wait_lock);
1316 hlist_add_head(&task->entry, &pf->aq_wait_list);
1317 spin_unlock_bh(&pf->aq_wait_lock);
1321 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1322 * @pf: pointer to the PF private structure
1323 * @task: ptr prepared by ice_aq_prep_for_event()
1324 * @timeout: how long to wait, in jiffies
1326 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1327 * current thread will be put to sleep until the specified event occurs or
1328 * until the given timeout is reached.
1330 * Returns: zero on success, or a negative error code on failure.
1332 int ice_aq_wait_for_event(struct ice_pf *pf, struct ice_aq_task *task,
1333 unsigned long timeout)
1335 enum ice_aq_task_state *state = &task->state;
1336 struct device *dev = ice_pf_to_dev(pf);
1337 unsigned long start = jiffies;
1341 ret = wait_event_interruptible_timeout(pf->aq_wait_queue,
1342 *state != ICE_AQ_TASK_WAITING,
1345 case ICE_AQ_TASK_NOT_PREPARED:
1346 WARN(1, "call to %s without ice_aq_prep_for_event()", __func__);
1349 case ICE_AQ_TASK_WAITING:
1350 err = ret < 0 ? ret : -ETIMEDOUT;
1352 case ICE_AQ_TASK_CANCELED:
1353 err = ret < 0 ? ret : -ECANCELED;
1355 case ICE_AQ_TASK_COMPLETE:
1356 err = ret < 0 ? ret : 0;
1359 WARN(1, "Unexpected AdminQ wait task state %u", *state);
1364 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n",
1365 jiffies_to_msecs(jiffies - start),
1366 jiffies_to_msecs(timeout),
1369 spin_lock_bh(&pf->aq_wait_lock);
1370 hlist_del(&task->entry);
1371 spin_unlock_bh(&pf->aq_wait_lock);
1377 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event
1378 * @pf: pointer to the PF private structure
1379 * @opcode: the opcode of the event
1380 * @event: the event to check
1382 * Loops over the current list of pending threads waiting for an AdminQ event.
1383 * For each matching task, copy the contents of the event into the task
1384 * structure and wake up the thread.
1386 * If multiple threads wait for the same opcode, they will all be woken up.
1388 * Note that event->msg_buf will only be duplicated if the event has a buffer
1389 * with enough space already allocated. Otherwise, only the descriptor and
1390 * message length will be copied.
1392 * Returns: true if an event was found, false otherwise
1394 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1395 struct ice_rq_event_info *event)
1397 struct ice_rq_event_info *task_ev;
1398 struct ice_aq_task *task;
1401 spin_lock_bh(&pf->aq_wait_lock);
1402 hlist_for_each_entry(task, &pf->aq_wait_list, entry) {
1403 if (task->state != ICE_AQ_TASK_WAITING)
1405 if (task->opcode != opcode)
1408 task_ev = &task->event;
1409 memcpy(&task_ev->desc, &event->desc, sizeof(event->desc));
1410 task_ev->msg_len = event->msg_len;
1412 /* Only copy the data buffer if a destination was set */
1413 if (task_ev->msg_buf && task_ev->buf_len >= event->buf_len) {
1414 memcpy(task_ev->msg_buf, event->msg_buf,
1416 task_ev->buf_len = event->buf_len;
1419 task->state = ICE_AQ_TASK_COMPLETE;
1422 spin_unlock_bh(&pf->aq_wait_lock);
1425 wake_up(&pf->aq_wait_queue);
1429 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks
1430 * @pf: the PF private structure
1432 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads.
1433 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED.
1435 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
1437 struct ice_aq_task *task;
1439 spin_lock_bh(&pf->aq_wait_lock);
1440 hlist_for_each_entry(task, &pf->aq_wait_list, entry)
1441 task->state = ICE_AQ_TASK_CANCELED;
1442 spin_unlock_bh(&pf->aq_wait_lock);
1444 wake_up(&pf->aq_wait_queue);
1447 #define ICE_MBX_OVERFLOW_WATERMARK 64
1450 * __ice_clean_ctrlq - helper function to clean controlq rings
1451 * @pf: ptr to struct ice_pf
1452 * @q_type: specific Control queue type
1454 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
1456 struct device *dev = ice_pf_to_dev(pf);
1457 struct ice_rq_event_info event;
1458 struct ice_hw *hw = &pf->hw;
1459 struct ice_ctl_q_info *cq;
1464 /* Do not clean control queue if/when PF reset fails */
1465 if (test_bit(ICE_RESET_FAILED, pf->state))
1469 case ICE_CTL_Q_ADMIN:
1477 case ICE_CTL_Q_MAILBOX:
1480 /* we are going to try to detect a malicious VF, so set the
1481 * state to begin detection
1483 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT;
1486 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
1490 /* check for error indications - PF_xx_AxQLEN register layout for
1491 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
1493 val = rd32(hw, cq->rq.len);
1494 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1495 PF_FW_ARQLEN_ARQCRIT_M)) {
1497 if (val & PF_FW_ARQLEN_ARQVFE_M)
1498 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
1500 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1501 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
1504 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1505 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
1507 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1508 PF_FW_ARQLEN_ARQCRIT_M);
1510 wr32(hw, cq->rq.len, val);
1513 val = rd32(hw, cq->sq.len);
1514 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1515 PF_FW_ATQLEN_ATQCRIT_M)) {
1517 if (val & PF_FW_ATQLEN_ATQVFE_M)
1518 dev_dbg(dev, "%s Send Queue VF Error detected\n",
1520 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1521 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1524 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1525 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1527 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1528 PF_FW_ATQLEN_ATQCRIT_M);
1530 wr32(hw, cq->sq.len, val);
1533 event.buf_len = cq->rq_buf_size;
1534 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1539 struct ice_mbx_data data = {};
1543 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1544 if (ret == -EALREADY)
1547 dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1552 opcode = le16_to_cpu(event.desc.opcode);
1554 /* Notify any thread that might be waiting for this event */
1555 ice_aq_check_events(pf, opcode, &event);
1558 case ice_aqc_opc_get_link_status:
1559 if (ice_handle_link_event(pf, &event))
1560 dev_err(dev, "Could not handle link event\n");
1562 case ice_aqc_opc_event_lan_overflow:
1563 ice_vf_lan_overflow_event(pf, &event);
1565 case ice_mbx_opc_send_msg_to_pf:
1566 data.num_msg_proc = i;
1567 data.num_pending_arq = pending;
1568 data.max_num_msgs_mbx = hw->mailboxq.num_rq_entries;
1569 data.async_watermark_val = ICE_MBX_OVERFLOW_WATERMARK;
1571 ice_vc_process_vf_msg(pf, &event, &data);
1573 case ice_aqc_opc_fw_logs_event:
1574 ice_get_fwlog_data(pf, &event);
1576 case ice_aqc_opc_lldp_set_mib_change:
1577 ice_dcb_process_lldp_set_mib_change(pf, &event);
1580 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1584 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1586 kfree(event.msg_buf);
1588 return pending && (i == ICE_DFLT_IRQ_WORK);
1592 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1593 * @hw: pointer to hardware info
1594 * @cq: control queue information
1596 * returns true if there are pending messages in a queue, false if there aren't
1598 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1602 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1603 return cq->rq.next_to_clean != ntu;
1607 * ice_clean_adminq_subtask - clean the AdminQ rings
1608 * @pf: board private structure
1610 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1612 struct ice_hw *hw = &pf->hw;
1614 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
1617 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1620 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
1622 /* There might be a situation where new messages arrive to a control
1623 * queue between processing the last message and clearing the
1624 * EVENT_PENDING bit. So before exiting, check queue head again (using
1625 * ice_ctrlq_pending) and process new messages if any.
1627 if (ice_ctrlq_pending(hw, &hw->adminq))
1628 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1634 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1635 * @pf: board private structure
1637 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1639 struct ice_hw *hw = &pf->hw;
1641 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1644 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1647 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1649 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1650 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1656 * ice_clean_sbq_subtask - clean the Sideband Queue rings
1657 * @pf: board private structure
1659 static void ice_clean_sbq_subtask(struct ice_pf *pf)
1661 struct ice_hw *hw = &pf->hw;
1663 /* if mac_type is not generic, sideband is not supported
1664 * and there's nothing to do here
1666 if (!ice_is_generic_mac(hw)) {
1667 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1671 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state))
1674 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB))
1677 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1679 if (ice_ctrlq_pending(hw, &hw->sbq))
1680 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB);
1686 * ice_service_task_schedule - schedule the service task to wake up
1687 * @pf: board private structure
1689 * If not already scheduled, this puts the task into the work queue.
1691 void ice_service_task_schedule(struct ice_pf *pf)
1693 if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
1694 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
1695 !test_bit(ICE_NEEDS_RESTART, pf->state))
1696 queue_work(ice_wq, &pf->serv_task);
1700 * ice_service_task_complete - finish up the service task
1701 * @pf: board private structure
1703 static void ice_service_task_complete(struct ice_pf *pf)
1705 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state));
1707 /* force memory (pf->state) to sync before next service task */
1708 smp_mb__before_atomic();
1709 clear_bit(ICE_SERVICE_SCHED, pf->state);
1713 * ice_service_task_stop - stop service task and cancel works
1714 * @pf: board private structure
1716 * Return 0 if the ICE_SERVICE_DIS bit was not already set,
1719 static int ice_service_task_stop(struct ice_pf *pf)
1723 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state);
1725 if (pf->serv_tmr.function)
1726 del_timer_sync(&pf->serv_tmr);
1727 if (pf->serv_task.func)
1728 cancel_work_sync(&pf->serv_task);
1730 clear_bit(ICE_SERVICE_SCHED, pf->state);
1735 * ice_service_task_restart - restart service task and schedule works
1736 * @pf: board private structure
1738 * This function is needed for suspend and resume works (e.g WoL scenario)
1740 static void ice_service_task_restart(struct ice_pf *pf)
1742 clear_bit(ICE_SERVICE_DIS, pf->state);
1743 ice_service_task_schedule(pf);
1747 * ice_service_timer - timer callback to schedule service task
1748 * @t: pointer to timer_list
1750 static void ice_service_timer(struct timer_list *t)
1752 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1754 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1755 ice_service_task_schedule(pf);
1759 * ice_mdd_maybe_reset_vf - reset VF after MDD event
1760 * @pf: pointer to the PF structure
1761 * @vf: pointer to the VF structure
1762 * @reset_vf_tx: whether Tx MDD has occurred
1763 * @reset_vf_rx: whether Rx MDD has occurred
1765 * Since the queue can get stuck on VF MDD events, the PF can be configured to
1766 * automatically reset the VF by enabling the private ethtool flag
1767 * mdd-auto-reset-vf.
1769 static void ice_mdd_maybe_reset_vf(struct ice_pf *pf, struct ice_vf *vf,
1770 bool reset_vf_tx, bool reset_vf_rx)
1772 struct device *dev = ice_pf_to_dev(pf);
1774 if (!test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags))
1777 /* VF MDD event counters will be cleared by reset, so print the event
1781 ice_print_vf_tx_mdd_event(vf);
1784 ice_print_vf_rx_mdd_event(vf);
1786 dev_info(dev, "PF-to-VF reset on PF %d VF %d due to MDD event\n",
1787 pf->hw.pf_id, vf->vf_id);
1788 ice_reset_vf(vf, ICE_VF_RESET_NOTIFY | ICE_VF_RESET_LOCK);
1792 * ice_handle_mdd_event - handle malicious driver detect event
1793 * @pf: pointer to the PF structure
1795 * Called from service task. OICR interrupt handler indicates MDD event.
1796 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1797 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1798 * disable the queue, the PF can be configured to reset the VF using ethtool
1799 * private flag mdd-auto-reset-vf.
1801 static void ice_handle_mdd_event(struct ice_pf *pf)
1803 struct device *dev = ice_pf_to_dev(pf);
1804 struct ice_hw *hw = &pf->hw;
1809 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
1810 /* Since the VF MDD event logging is rate limited, check if
1811 * there are pending MDD events.
1813 ice_print_vfs_mdd_events(pf);
1817 /* find what triggered an MDD event */
1818 reg = rd32(hw, GL_MDET_TX_PQM);
1819 if (reg & GL_MDET_TX_PQM_VALID_M) {
1820 u8 pf_num = FIELD_GET(GL_MDET_TX_PQM_PF_NUM_M, reg);
1821 u16 vf_num = FIELD_GET(GL_MDET_TX_PQM_VF_NUM_M, reg);
1822 u8 event = FIELD_GET(GL_MDET_TX_PQM_MAL_TYPE_M, reg);
1823 u16 queue = FIELD_GET(GL_MDET_TX_PQM_QNUM_M, reg);
1825 if (netif_msg_tx_err(pf))
1826 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1827 event, queue, pf_num, vf_num);
1828 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1831 reg = rd32(hw, GL_MDET_TX_TCLAN_BY_MAC(hw));
1832 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1833 u8 pf_num = FIELD_GET(GL_MDET_TX_TCLAN_PF_NUM_M, reg);
1834 u16 vf_num = FIELD_GET(GL_MDET_TX_TCLAN_VF_NUM_M, reg);
1835 u8 event = FIELD_GET(GL_MDET_TX_TCLAN_MAL_TYPE_M, reg);
1836 u16 queue = FIELD_GET(GL_MDET_TX_TCLAN_QNUM_M, reg);
1838 if (netif_msg_tx_err(pf))
1839 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1840 event, queue, pf_num, vf_num);
1841 wr32(hw, GL_MDET_TX_TCLAN_BY_MAC(hw), U32_MAX);
1844 reg = rd32(hw, GL_MDET_RX);
1845 if (reg & GL_MDET_RX_VALID_M) {
1846 u8 pf_num = FIELD_GET(GL_MDET_RX_PF_NUM_M, reg);
1847 u16 vf_num = FIELD_GET(GL_MDET_RX_VF_NUM_M, reg);
1848 u8 event = FIELD_GET(GL_MDET_RX_MAL_TYPE_M, reg);
1849 u16 queue = FIELD_GET(GL_MDET_RX_QNUM_M, reg);
1851 if (netif_msg_rx_err(pf))
1852 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1853 event, queue, pf_num, vf_num);
1854 wr32(hw, GL_MDET_RX, 0xffffffff);
1857 /* check to see if this PF caused an MDD event */
1858 reg = rd32(hw, PF_MDET_TX_PQM);
1859 if (reg & PF_MDET_TX_PQM_VALID_M) {
1860 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1861 if (netif_msg_tx_err(pf))
1862 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1865 reg = rd32(hw, PF_MDET_TX_TCLAN_BY_MAC(hw));
1866 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1867 wr32(hw, PF_MDET_TX_TCLAN_BY_MAC(hw), 0xffff);
1868 if (netif_msg_tx_err(pf))
1869 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1872 reg = rd32(hw, PF_MDET_RX);
1873 if (reg & PF_MDET_RX_VALID_M) {
1874 wr32(hw, PF_MDET_RX, 0xFFFF);
1875 if (netif_msg_rx_err(pf))
1876 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1879 /* Check to see if one of the VFs caused an MDD event, and then
1880 * increment counters and set print pending
1882 mutex_lock(&pf->vfs.table_lock);
1883 ice_for_each_vf(pf, bkt, vf) {
1884 bool reset_vf_tx = false, reset_vf_rx = false;
1886 reg = rd32(hw, VP_MDET_TX_PQM(vf->vf_id));
1887 if (reg & VP_MDET_TX_PQM_VALID_M) {
1888 wr32(hw, VP_MDET_TX_PQM(vf->vf_id), 0xFFFF);
1889 vf->mdd_tx_events.count++;
1890 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1891 if (netif_msg_tx_err(pf))
1892 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1898 reg = rd32(hw, VP_MDET_TX_TCLAN(vf->vf_id));
1899 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1900 wr32(hw, VP_MDET_TX_TCLAN(vf->vf_id), 0xFFFF);
1901 vf->mdd_tx_events.count++;
1902 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1903 if (netif_msg_tx_err(pf))
1904 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1910 reg = rd32(hw, VP_MDET_TX_TDPU(vf->vf_id));
1911 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1912 wr32(hw, VP_MDET_TX_TDPU(vf->vf_id), 0xFFFF);
1913 vf->mdd_tx_events.count++;
1914 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1915 if (netif_msg_tx_err(pf))
1916 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1922 reg = rd32(hw, VP_MDET_RX(vf->vf_id));
1923 if (reg & VP_MDET_RX_VALID_M) {
1924 wr32(hw, VP_MDET_RX(vf->vf_id), 0xFFFF);
1925 vf->mdd_rx_events.count++;
1926 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1927 if (netif_msg_rx_err(pf))
1928 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1934 if (reset_vf_tx || reset_vf_rx)
1935 ice_mdd_maybe_reset_vf(pf, vf, reset_vf_tx,
1938 mutex_unlock(&pf->vfs.table_lock);
1940 ice_print_vfs_mdd_events(pf);
1944 * ice_force_phys_link_state - Force the physical link state
1945 * @vsi: VSI to force the physical link state to up/down
1946 * @link_up: true/false indicates to set the physical link to up/down
1948 * Force the physical link state by getting the current PHY capabilities from
1949 * hardware and setting the PHY config based on the determined capabilities. If
1950 * link changes a link event will be triggered because both the Enable Automatic
1951 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1953 * Returns 0 on success, negative on failure
1955 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1957 struct ice_aqc_get_phy_caps_data *pcaps;
1958 struct ice_aqc_set_phy_cfg_data *cfg;
1959 struct ice_port_info *pi;
1963 if (!vsi || !vsi->port_info || !vsi->back)
1965 if (vsi->type != ICE_VSI_PF)
1968 dev = ice_pf_to_dev(vsi->back);
1970 pi = vsi->port_info;
1972 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1976 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1979 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1980 vsi->vsi_num, retcode);
1985 /* No change in link */
1986 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1987 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1990 /* Use the current user PHY configuration. The current user PHY
1991 * configuration is initialized during probe from PHY capabilities
1992 * software mode, and updated on set PHY configuration.
1994 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL);
2000 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
2002 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
2004 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
2006 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL);
2008 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
2009 vsi->vsi_num, retcode);
2020 * ice_init_nvm_phy_type - Initialize the NVM PHY type
2021 * @pi: port info structure
2023 * Initialize nvm_phy_type_[low|high] for link lenient mode support
2025 static int ice_init_nvm_phy_type(struct ice_port_info *pi)
2027 struct ice_aqc_get_phy_caps_data *pcaps;
2028 struct ice_pf *pf = pi->hw->back;
2031 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2035 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA,
2039 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
2043 pf->nvm_phy_type_hi = pcaps->phy_type_high;
2044 pf->nvm_phy_type_lo = pcaps->phy_type_low;
2052 * ice_init_link_dflt_override - Initialize link default override
2053 * @pi: port info structure
2055 * Initialize link default override and PHY total port shutdown during probe
2057 static void ice_init_link_dflt_override(struct ice_port_info *pi)
2059 struct ice_link_default_override_tlv *ldo;
2060 struct ice_pf *pf = pi->hw->back;
2062 ldo = &pf->link_dflt_override;
2063 if (ice_get_link_default_override(ldo, pi))
2066 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS))
2069 /* Enable Total Port Shutdown (override/replace link-down-on-close
2070 * ethtool private flag) for ports with Port Disable bit set.
2072 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags);
2073 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
2077 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings
2078 * @pi: port info structure
2080 * If default override is enabled, initialize the user PHY cfg speed and FEC
2081 * settings using the default override mask from the NVM.
2083 * The PHY should only be configured with the default override settings the
2084 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state
2085 * is used to indicate that the user PHY cfg default override is initialized
2086 * and the PHY has not been configured with the default override settings. The
2087 * state is set here, and cleared in ice_configure_phy the first time the PHY is
2090 * This function should be called only if the FW doesn't support default
2091 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg.
2093 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi)
2095 struct ice_link_default_override_tlv *ldo;
2096 struct ice_aqc_set_phy_cfg_data *cfg;
2097 struct ice_phy_info *phy = &pi->phy;
2098 struct ice_pf *pf = pi->hw->back;
2100 ldo = &pf->link_dflt_override;
2102 /* If link default override is enabled, use to mask NVM PHY capabilities
2103 * for speed and FEC default configuration.
2105 cfg = &phy->curr_user_phy_cfg;
2107 if (ldo->phy_type_low || ldo->phy_type_high) {
2108 cfg->phy_type_low = pf->nvm_phy_type_lo &
2109 cpu_to_le64(ldo->phy_type_low);
2110 cfg->phy_type_high = pf->nvm_phy_type_hi &
2111 cpu_to_le64(ldo->phy_type_high);
2113 cfg->link_fec_opt = ldo->fec_options;
2114 phy->curr_user_fec_req = ICE_FEC_AUTO;
2116 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state);
2120 * ice_init_phy_user_cfg - Initialize the PHY user configuration
2121 * @pi: port info structure
2123 * Initialize the current user PHY configuration, speed, FEC, and FC requested
2124 * mode to default. The PHY defaults are from get PHY capabilities topology
2125 * with media so call when media is first available. An error is returned if
2126 * called when media is not available. The PHY initialization completed state is
2129 * These configurations are used when setting PHY
2130 * configuration. The user PHY configuration is updated on set PHY
2131 * configuration. Returns 0 on success, negative on failure
2133 static int ice_init_phy_user_cfg(struct ice_port_info *pi)
2135 struct ice_aqc_get_phy_caps_data *pcaps;
2136 struct ice_phy_info *phy = &pi->phy;
2137 struct ice_pf *pf = pi->hw->back;
2140 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2143 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2147 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2148 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2151 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2154 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
2158 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg);
2160 /* check if lenient mode is supported and enabled */
2161 if (ice_fw_supports_link_override(pi->hw) &&
2162 !(pcaps->module_compliance_enforcement &
2163 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) {
2164 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags);
2166 /* if the FW supports default PHY configuration mode, then the driver
2167 * does not have to apply link override settings. If not,
2168 * initialize user PHY configuration with link override values
2170 if (!ice_fw_supports_report_dflt_cfg(pi->hw) &&
2171 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) {
2172 ice_init_phy_cfg_dflt_override(pi);
2177 /* if link default override is not enabled, set user flow control and
2178 * FEC settings based on what get_phy_caps returned
2180 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps,
2181 pcaps->link_fec_options);
2182 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps);
2185 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M;
2186 set_bit(ICE_PHY_INIT_COMPLETE, pf->state);
2193 * ice_configure_phy - configure PHY
2196 * Set the PHY configuration. If the current PHY configuration is the same as
2197 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise
2198 * configure the based get PHY capabilities for topology with media.
2200 static int ice_configure_phy(struct ice_vsi *vsi)
2202 struct device *dev = ice_pf_to_dev(vsi->back);
2203 struct ice_port_info *pi = vsi->port_info;
2204 struct ice_aqc_get_phy_caps_data *pcaps;
2205 struct ice_aqc_set_phy_cfg_data *cfg;
2206 struct ice_phy_info *phy = &pi->phy;
2207 struct ice_pf *pf = vsi->back;
2210 /* Ensure we have media as we cannot configure a medialess port */
2211 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2214 ice_print_topo_conflict(vsi);
2216 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags) &&
2217 phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA)
2220 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags))
2221 return ice_force_phys_link_state(vsi, true);
2223 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2227 /* Get current PHY config */
2228 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2231 dev_err(dev, "Failed to get PHY configuration, VSI %d error %d\n",
2236 /* If PHY enable link is configured and configuration has not changed,
2237 * there's nothing to do
2239 if (pcaps->caps & ICE_AQC_PHY_EN_LINK &&
2240 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg))
2243 /* Use PHY topology as baseline for configuration */
2244 memset(pcaps, 0, sizeof(*pcaps));
2245 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2246 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2249 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2252 dev_err(dev, "Failed to get PHY caps, VSI %d error %d\n",
2257 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2263 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg);
2265 /* Speed - If default override pending, use curr_user_phy_cfg set in
2266 * ice_init_phy_user_cfg_ldo.
2268 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING,
2269 vsi->back->state)) {
2270 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low;
2271 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high;
2273 u64 phy_low = 0, phy_high = 0;
2275 ice_update_phy_type(&phy_low, &phy_high,
2276 pi->phy.curr_user_speed_req);
2277 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low);
2278 cfg->phy_type_high = pcaps->phy_type_high &
2279 cpu_to_le64(phy_high);
2282 /* Can't provide what was requested; use PHY capabilities */
2283 if (!cfg->phy_type_low && !cfg->phy_type_high) {
2284 cfg->phy_type_low = pcaps->phy_type_low;
2285 cfg->phy_type_high = pcaps->phy_type_high;
2289 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req);
2291 /* Can't provide what was requested; use PHY capabilities */
2292 if (cfg->link_fec_opt !=
2293 (cfg->link_fec_opt & pcaps->link_fec_options)) {
2294 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2295 cfg->link_fec_opt = pcaps->link_fec_options;
2298 /* Flow Control - always supported; no need to check against
2301 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req);
2303 /* Enable link and link update */
2304 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK;
2306 err = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL);
2308 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
2318 * ice_check_media_subtask - Check for media
2319 * @pf: pointer to PF struct
2321 * If media is available, then initialize PHY user configuration if it is not
2322 * been, and configure the PHY if the interface is up.
2324 static void ice_check_media_subtask(struct ice_pf *pf)
2326 struct ice_port_info *pi;
2327 struct ice_vsi *vsi;
2330 /* No need to check for media if it's already present */
2331 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags))
2334 vsi = ice_get_main_vsi(pf);
2338 /* Refresh link info and check if media is present */
2339 pi = vsi->port_info;
2340 err = ice_update_link_info(pi);
2344 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
2346 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
2347 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state))
2348 ice_init_phy_user_cfg(pi);
2350 /* PHY settings are reset on media insertion, reconfigure
2351 * PHY to preserve settings.
2353 if (test_bit(ICE_VSI_DOWN, vsi->state) &&
2354 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags))
2357 err = ice_configure_phy(vsi);
2359 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
2361 /* A Link Status Event will be generated; the event handler
2362 * will complete bringing the interface up
2368 * ice_service_task - manage and run subtasks
2369 * @work: pointer to work_struct contained by the PF struct
2371 static void ice_service_task(struct work_struct *work)
2373 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
2374 unsigned long start_time = jiffies;
2378 /* process reset requests first */
2379 ice_reset_subtask(pf);
2381 /* bail if a reset/recovery cycle is pending or rebuild failed */
2382 if (ice_is_reset_in_progress(pf->state) ||
2383 test_bit(ICE_SUSPENDED, pf->state) ||
2384 test_bit(ICE_NEEDS_RESTART, pf->state)) {
2385 ice_service_task_complete(pf);
2389 if (test_and_clear_bit(ICE_AUX_ERR_PENDING, pf->state)) {
2390 struct iidc_event *event;
2392 event = kzalloc(sizeof(*event), GFP_KERNEL);
2394 set_bit(IIDC_EVENT_CRIT_ERR, event->type);
2395 /* report the entire OICR value to AUX driver */
2396 swap(event->reg, pf->oicr_err_reg);
2397 ice_send_event_to_aux(pf, event);
2402 /* unplug aux dev per request, if an unplug request came in
2403 * while processing a plug request, this will handle it
2405 if (test_and_clear_bit(ICE_FLAG_UNPLUG_AUX_DEV, pf->flags))
2406 ice_unplug_aux_dev(pf);
2408 /* Plug aux device per request */
2409 if (test_and_clear_bit(ICE_FLAG_PLUG_AUX_DEV, pf->flags))
2410 ice_plug_aux_dev(pf);
2412 if (test_and_clear_bit(ICE_FLAG_MTU_CHANGED, pf->flags)) {
2413 struct iidc_event *event;
2415 event = kzalloc(sizeof(*event), GFP_KERNEL);
2417 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);
2418 ice_send_event_to_aux(pf, event);
2423 ice_clean_adminq_subtask(pf);
2424 ice_check_media_subtask(pf);
2425 ice_check_for_hang_subtask(pf);
2426 ice_sync_fltr_subtask(pf);
2427 ice_handle_mdd_event(pf);
2428 ice_watchdog_subtask(pf);
2430 if (ice_is_safe_mode(pf)) {
2431 ice_service_task_complete(pf);
2435 ice_process_vflr_event(pf);
2436 ice_clean_mailboxq_subtask(pf);
2437 ice_clean_sbq_subtask(pf);
2438 ice_sync_arfs_fltrs(pf);
2439 ice_flush_fdir_ctx(pf);
2441 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */
2442 ice_service_task_complete(pf);
2444 /* If the tasks have taken longer than one service timer period
2445 * or there is more work to be done, reset the service timer to
2446 * schedule the service task now.
2448 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
2449 test_bit(ICE_MDD_EVENT_PENDING, pf->state) ||
2450 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) ||
2451 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
2452 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) ||
2453 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) ||
2454 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
2455 mod_timer(&pf->serv_tmr, jiffies);
2459 * ice_set_ctrlq_len - helper function to set controlq length
2460 * @hw: pointer to the HW instance
2462 static void ice_set_ctrlq_len(struct ice_hw *hw)
2464 hw->adminq.num_rq_entries = ICE_AQ_LEN;
2465 hw->adminq.num_sq_entries = ICE_AQ_LEN;
2466 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
2467 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
2468 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
2469 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
2470 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2471 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2472 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
2473 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
2474 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2475 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2479 * ice_schedule_reset - schedule a reset
2480 * @pf: board private structure
2481 * @reset: reset being requested
2483 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
2485 struct device *dev = ice_pf_to_dev(pf);
2487 /* bail out if earlier reset has failed */
2488 if (test_bit(ICE_RESET_FAILED, pf->state)) {
2489 dev_dbg(dev, "earlier reset has failed\n");
2492 /* bail if reset/recovery already in progress */
2493 if (ice_is_reset_in_progress(pf->state)) {
2494 dev_dbg(dev, "Reset already in progress\n");
2500 set_bit(ICE_PFR_REQ, pf->state);
2502 case ICE_RESET_CORER:
2503 set_bit(ICE_CORER_REQ, pf->state);
2505 case ICE_RESET_GLOBR:
2506 set_bit(ICE_GLOBR_REQ, pf->state);
2512 ice_service_task_schedule(pf);
2517 * ice_irq_affinity_notify - Callback for affinity changes
2518 * @notify: context as to what irq was changed
2519 * @mask: the new affinity mask
2521 * This is a callback function used by the irq_set_affinity_notifier function
2522 * so that we may register to receive changes to the irq affinity masks.
2525 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
2526 const cpumask_t *mask)
2528 struct ice_q_vector *q_vector =
2529 container_of(notify, struct ice_q_vector, affinity_notify);
2531 cpumask_copy(&q_vector->affinity_mask, mask);
2535 * ice_irq_affinity_release - Callback for affinity notifier release
2536 * @ref: internal core kernel usage
2538 * This is a callback function used by the irq_set_affinity_notifier function
2539 * to inform the current notification subscriber that they will no longer
2540 * receive notifications.
2542 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
2545 * ice_vsi_ena_irq - Enable IRQ for the given VSI
2546 * @vsi: the VSI being configured
2548 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
2550 struct ice_hw *hw = &vsi->back->hw;
2553 ice_for_each_q_vector(vsi, i)
2554 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
2561 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
2562 * @vsi: the VSI being configured
2563 * @basename: name for the vector
2565 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
2567 int q_vectors = vsi->num_q_vectors;
2568 struct ice_pf *pf = vsi->back;
2575 dev = ice_pf_to_dev(pf);
2576 for (vector = 0; vector < q_vectors; vector++) {
2577 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
2579 irq_num = q_vector->irq.virq;
2581 if (q_vector->tx.tx_ring && q_vector->rx.rx_ring) {
2582 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2583 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2585 } else if (q_vector->rx.rx_ring) {
2586 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2587 "%s-%s-%d", basename, "rx", rx_int_idx++);
2588 } else if (q_vector->tx.tx_ring) {
2589 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2590 "%s-%s-%d", basename, "tx", tx_int_idx++);
2592 /* skip this unused q_vector */
2595 if (vsi->type == ICE_VSI_CTRL && vsi->vf)
2596 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2597 IRQF_SHARED, q_vector->name,
2600 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2601 0, q_vector->name, q_vector);
2603 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
2608 /* register for affinity change notifications */
2609 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
2610 struct irq_affinity_notify *affinity_notify;
2612 affinity_notify = &q_vector->affinity_notify;
2613 affinity_notify->notify = ice_irq_affinity_notify;
2614 affinity_notify->release = ice_irq_affinity_release;
2615 irq_set_affinity_notifier(irq_num, affinity_notify);
2618 /* assign the mask for this irq */
2619 irq_update_affinity_hint(irq_num, &q_vector->affinity_mask);
2622 err = ice_set_cpu_rx_rmap(vsi);
2624 netdev_err(vsi->netdev, "Failed to setup CPU RMAP on VSI %u: %pe\n",
2625 vsi->vsi_num, ERR_PTR(err));
2629 vsi->irqs_ready = true;
2634 irq_num = vsi->q_vectors[vector]->irq.virq;
2635 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2636 irq_set_affinity_notifier(irq_num, NULL);
2637 irq_update_affinity_hint(irq_num, NULL);
2638 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
2644 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
2645 * @vsi: VSI to setup Tx rings used by XDP
2647 * Return 0 on success and negative value on error
2649 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
2651 struct device *dev = ice_pf_to_dev(vsi->back);
2652 struct ice_tx_desc *tx_desc;
2655 ice_for_each_xdp_txq(vsi, i) {
2656 u16 xdp_q_idx = vsi->alloc_txq + i;
2657 struct ice_ring_stats *ring_stats;
2658 struct ice_tx_ring *xdp_ring;
2660 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
2662 goto free_xdp_rings;
2664 ring_stats = kzalloc(sizeof(*ring_stats), GFP_KERNEL);
2666 ice_free_tx_ring(xdp_ring);
2667 goto free_xdp_rings;
2670 xdp_ring->ring_stats = ring_stats;
2671 xdp_ring->q_index = xdp_q_idx;
2672 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
2673 xdp_ring->vsi = vsi;
2674 xdp_ring->netdev = NULL;
2675 xdp_ring->dev = dev;
2676 xdp_ring->count = vsi->num_tx_desc;
2677 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring);
2678 if (ice_setup_tx_ring(xdp_ring))
2679 goto free_xdp_rings;
2680 ice_set_ring_xdp(xdp_ring);
2681 spin_lock_init(&xdp_ring->tx_lock);
2682 for (j = 0; j < xdp_ring->count; j++) {
2683 tx_desc = ICE_TX_DESC(xdp_ring, j);
2684 tx_desc->cmd_type_offset_bsz = 0;
2691 for (; i >= 0; i--) {
2692 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc) {
2693 kfree_rcu(vsi->xdp_rings[i]->ring_stats, rcu);
2694 vsi->xdp_rings[i]->ring_stats = NULL;
2695 ice_free_tx_ring(vsi->xdp_rings[i]);
2702 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
2703 * @vsi: VSI to set the bpf prog on
2704 * @prog: the bpf prog pointer
2706 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
2708 struct bpf_prog *old_prog;
2711 old_prog = xchg(&vsi->xdp_prog, prog);
2712 ice_for_each_rxq(vsi, i)
2713 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
2716 bpf_prog_put(old_prog);
2719 static struct ice_tx_ring *ice_xdp_ring_from_qid(struct ice_vsi *vsi, int qid)
2721 struct ice_q_vector *q_vector;
2722 struct ice_tx_ring *ring;
2724 if (static_key_enabled(&ice_xdp_locking_key))
2725 return vsi->xdp_rings[qid % vsi->num_xdp_txq];
2727 q_vector = vsi->rx_rings[qid]->q_vector;
2728 ice_for_each_tx_ring(ring, q_vector->tx)
2729 if (ice_ring_is_xdp(ring))
2736 * ice_map_xdp_rings - Map XDP rings to interrupt vectors
2737 * @vsi: the VSI with XDP rings being configured
2739 * Map XDP rings to interrupt vectors and perform the configuration steps
2740 * dependent on the mapping.
2742 void ice_map_xdp_rings(struct ice_vsi *vsi)
2744 int xdp_rings_rem = vsi->num_xdp_txq;
2747 /* follow the logic from ice_vsi_map_rings_to_vectors */
2748 ice_for_each_q_vector(vsi, v_idx) {
2749 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2750 int xdp_rings_per_v, q_id, q_base;
2752 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
2753 vsi->num_q_vectors - v_idx);
2754 q_base = vsi->num_xdp_txq - xdp_rings_rem;
2756 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
2757 struct ice_tx_ring *xdp_ring = vsi->xdp_rings[q_id];
2759 xdp_ring->q_vector = q_vector;
2760 xdp_ring->next = q_vector->tx.tx_ring;
2761 q_vector->tx.tx_ring = xdp_ring;
2763 xdp_rings_rem -= xdp_rings_per_v;
2766 ice_for_each_rxq(vsi, q_idx) {
2767 vsi->rx_rings[q_idx]->xdp_ring = ice_xdp_ring_from_qid(vsi,
2769 ice_tx_xsk_pool(vsi, q_idx);
2774 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
2775 * @vsi: VSI to bring up Tx rings used by XDP
2776 * @prog: bpf program that will be assigned to VSI
2777 * @cfg_type: create from scratch or restore the existing configuration
2779 * Return 0 on success and negative value on error
2781 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog,
2782 enum ice_xdp_cfg cfg_type)
2784 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2785 struct ice_pf *pf = vsi->back;
2786 struct ice_qs_cfg xdp_qs_cfg = {
2787 .qs_mutex = &pf->avail_q_mutex,
2788 .pf_map = pf->avail_txqs,
2789 .pf_map_size = pf->max_pf_txqs,
2790 .q_count = vsi->num_xdp_txq,
2791 .scatter_count = ICE_MAX_SCATTER_TXQS,
2792 .vsi_map = vsi->txq_map,
2793 .vsi_map_offset = vsi->alloc_txq,
2794 .mapping_mode = ICE_VSI_MAP_CONTIG
2799 dev = ice_pf_to_dev(pf);
2800 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
2801 sizeof(*vsi->xdp_rings), GFP_KERNEL);
2802 if (!vsi->xdp_rings)
2805 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
2806 if (__ice_vsi_get_qs(&xdp_qs_cfg))
2809 if (static_key_enabled(&ice_xdp_locking_key))
2810 netdev_warn(vsi->netdev,
2811 "Could not allocate one XDP Tx ring per CPU, XDP_TX/XDP_REDIRECT actions will be slower\n");
2813 if (ice_xdp_alloc_setup_rings(vsi))
2814 goto clear_xdp_rings;
2816 /* omit the scheduler update if in reset path; XDP queues will be
2817 * taken into account at the end of ice_vsi_rebuild, where
2818 * ice_cfg_vsi_lan is being called
2820 if (cfg_type == ICE_XDP_CFG_PART)
2823 ice_map_xdp_rings(vsi);
2825 /* tell the Tx scheduler that right now we have
2828 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2829 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
2831 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2834 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %d\n",
2836 goto clear_xdp_rings;
2839 /* assign the prog only when it's not already present on VSI;
2840 * this flow is a subject of both ethtool -L and ndo_bpf flows;
2841 * VSI rebuild that happens under ethtool -L can expose us to
2842 * the bpf_prog refcount issues as we would be swapping same
2843 * bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put
2844 * on it as it would be treated as an 'old_prog'; for ndo_bpf
2845 * this is not harmful as dev_xdp_install bumps the refcount
2846 * before calling the op exposed by the driver;
2848 if (!ice_is_xdp_ena_vsi(vsi))
2849 ice_vsi_assign_bpf_prog(vsi, prog);
2853 ice_for_each_xdp_txq(vsi, i)
2854 if (vsi->xdp_rings[i]) {
2855 kfree_rcu(vsi->xdp_rings[i], rcu);
2856 vsi->xdp_rings[i] = NULL;
2860 mutex_lock(&pf->avail_q_mutex);
2861 ice_for_each_xdp_txq(vsi, i) {
2862 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2863 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2865 mutex_unlock(&pf->avail_q_mutex);
2867 devm_kfree(dev, vsi->xdp_rings);
2872 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
2873 * @vsi: VSI to remove XDP rings
2874 * @cfg_type: disable XDP permanently or allow it to be restored later
2876 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
2879 int ice_destroy_xdp_rings(struct ice_vsi *vsi, enum ice_xdp_cfg cfg_type)
2881 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2882 struct ice_pf *pf = vsi->back;
2885 /* q_vectors are freed in reset path so there's no point in detaching
2888 if (cfg_type == ICE_XDP_CFG_PART)
2891 ice_for_each_q_vector(vsi, v_idx) {
2892 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2893 struct ice_tx_ring *ring;
2895 ice_for_each_tx_ring(ring, q_vector->tx)
2896 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
2899 /* restore the value of last node prior to XDP setup */
2900 q_vector->tx.tx_ring = ring;
2904 mutex_lock(&pf->avail_q_mutex);
2905 ice_for_each_xdp_txq(vsi, i) {
2906 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2907 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2909 mutex_unlock(&pf->avail_q_mutex);
2911 ice_for_each_xdp_txq(vsi, i)
2912 if (vsi->xdp_rings[i]) {
2913 if (vsi->xdp_rings[i]->desc) {
2915 ice_free_tx_ring(vsi->xdp_rings[i]);
2917 kfree_rcu(vsi->xdp_rings[i]->ring_stats, rcu);
2918 vsi->xdp_rings[i]->ring_stats = NULL;
2919 kfree_rcu(vsi->xdp_rings[i], rcu);
2920 vsi->xdp_rings[i] = NULL;
2923 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
2924 vsi->xdp_rings = NULL;
2926 if (static_key_enabled(&ice_xdp_locking_key))
2927 static_branch_dec(&ice_xdp_locking_key);
2929 if (cfg_type == ICE_XDP_CFG_PART)
2932 ice_vsi_assign_bpf_prog(vsi, NULL);
2934 /* notify Tx scheduler that we destroyed XDP queues and bring
2935 * back the old number of child nodes
2937 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2938 max_txqs[i] = vsi->num_txq;
2940 /* change number of XDP Tx queues to 0 */
2941 vsi->num_xdp_txq = 0;
2943 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2948 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2949 * @vsi: VSI to schedule napi on
2951 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2955 ice_for_each_rxq(vsi, i) {
2956 struct ice_rx_ring *rx_ring = vsi->rx_rings[i];
2958 if (READ_ONCE(rx_ring->xsk_pool))
2959 napi_schedule(&rx_ring->q_vector->napi);
2964 * ice_vsi_determine_xdp_res - figure out how many Tx qs can XDP have
2965 * @vsi: VSI to determine the count of XDP Tx qs
2967 * returns 0 if Tx qs count is higher than at least half of CPU count,
2970 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi)
2972 u16 avail = ice_get_avail_txq_count(vsi->back);
2973 u16 cpus = num_possible_cpus();
2975 if (avail < cpus / 2)
2978 if (vsi->type == ICE_VSI_SF)
2979 avail = vsi->alloc_txq;
2981 vsi->num_xdp_txq = min_t(u16, avail, cpus);
2983 if (vsi->num_xdp_txq < cpus)
2984 static_branch_inc(&ice_xdp_locking_key);
2990 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
2991 * @vsi: Pointer to VSI structure
2993 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
2995 if (test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
2996 return ICE_RXBUF_1664;
2998 return ICE_RXBUF_3072;
3002 * ice_xdp_setup_prog - Add or remove XDP eBPF program
3003 * @vsi: VSI to setup XDP for
3004 * @prog: XDP program
3005 * @extack: netlink extended ack
3008 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
3009 struct netlink_ext_ack *extack)
3011 unsigned int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
3012 int ret = 0, xdp_ring_err = 0;
3015 if (prog && !prog->aux->xdp_has_frags) {
3016 if (frame_size > ice_max_xdp_frame_size(vsi)) {
3017 NL_SET_ERR_MSG_MOD(extack,
3018 "MTU is too large for linear frames and XDP prog does not support frags");
3023 /* hot swap progs and avoid toggling link */
3024 if (ice_is_xdp_ena_vsi(vsi) == !!prog ||
3025 test_bit(ICE_VSI_REBUILD_PENDING, vsi->state)) {
3026 ice_vsi_assign_bpf_prog(vsi, prog);
3030 if_running = netif_running(vsi->netdev) &&
3031 !test_and_set_bit(ICE_VSI_DOWN, vsi->state);
3033 /* need to stop netdev while setting up the program for Rx rings */
3035 ret = ice_down(vsi);
3037 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
3042 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
3043 xdp_ring_err = ice_vsi_determine_xdp_res(vsi);
3045 NL_SET_ERR_MSG_MOD(extack, "Not enough Tx resources for XDP");
3047 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog,
3050 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
3052 xdp_features_set_redirect_target(vsi->netdev, true);
3053 /* reallocate Rx queues that are used for zero-copy */
3054 xdp_ring_err = ice_realloc_zc_buf(vsi, true);
3056 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Rx resources failed");
3057 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
3058 xdp_features_clear_redirect_target(vsi->netdev);
3059 xdp_ring_err = ice_destroy_xdp_rings(vsi, ICE_XDP_CFG_FULL);
3061 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
3062 /* reallocate Rx queues that were used for zero-copy */
3063 xdp_ring_err = ice_realloc_zc_buf(vsi, false);
3065 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Rx resources failed");
3072 ice_vsi_rx_napi_schedule(vsi);
3074 return (ret || xdp_ring_err) ? -ENOMEM : 0;
3078 * ice_xdp_safe_mode - XDP handler for safe mode
3082 static int ice_xdp_safe_mode(struct net_device __always_unused *dev,
3083 struct netdev_bpf *xdp)
3085 NL_SET_ERR_MSG_MOD(xdp->extack,
3086 "Please provide working DDP firmware package in order to use XDP\n"
3087 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst");
3092 * ice_xdp - implements XDP handler
3096 int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
3098 struct ice_netdev_priv *np = netdev_priv(dev);
3099 struct ice_vsi *vsi = np->vsi;
3102 if (vsi->type != ICE_VSI_PF && vsi->type != ICE_VSI_SF) {
3103 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF or SF VSI");
3107 mutex_lock(&vsi->xdp_state_lock);
3109 switch (xdp->command) {
3110 case XDP_SETUP_PROG:
3111 ret = ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
3113 case XDP_SETUP_XSK_POOL:
3114 ret = ice_xsk_pool_setup(vsi, xdp->xsk.pool, xdp->xsk.queue_id);
3120 mutex_unlock(&vsi->xdp_state_lock);
3125 * ice_ena_misc_vector - enable the non-queue interrupts
3126 * @pf: board private structure
3128 static void ice_ena_misc_vector(struct ice_pf *pf)
3130 struct ice_hw *hw = &pf->hw;
3131 u32 pf_intr_start_offset;
3134 /* Disable anti-spoof detection interrupt to prevent spurious event
3135 * interrupts during a function reset. Anti-spoof functionally is
3138 val = rd32(hw, GL_MDCK_TX_TDPU);
3139 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
3140 wr32(hw, GL_MDCK_TX_TDPU, val);
3142 /* clear things first */
3143 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
3144 rd32(hw, PFINT_OICR); /* read to clear */
3146 val = (PFINT_OICR_ECC_ERR_M |
3147 PFINT_OICR_MAL_DETECT_M |
3149 PFINT_OICR_PCI_EXCEPTION_M |
3151 PFINT_OICR_HMC_ERR_M |
3152 PFINT_OICR_PE_PUSH_M |
3153 PFINT_OICR_PE_CRITERR_M);
3155 wr32(hw, PFINT_OICR_ENA, val);
3157 /* SW_ITR_IDX = 0, but don't change INTENA */
3158 wr32(hw, GLINT_DYN_CTL(pf->oicr_irq.index),
3159 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
3161 if (!pf->hw.dev_caps.ts_dev_info.ts_ll_int_read)
3163 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST;
3164 wr32(hw, GLINT_DYN_CTL(pf->ll_ts_irq.index + pf_intr_start_offset),
3165 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
3169 * ice_ll_ts_intr - ll_ts interrupt handler
3170 * @irq: interrupt number
3171 * @data: pointer to a q_vector
3173 static irqreturn_t ice_ll_ts_intr(int __always_unused irq, void *data)
3175 struct ice_pf *pf = data;
3176 u32 pf_intr_start_offset;
3177 struct ice_ptp_tx *tx;
3178 unsigned long flags;
3184 tx = &pf->ptp.port.tx;
3185 spin_lock_irqsave(&tx->lock, flags);
3186 ice_ptp_complete_tx_single_tstamp(tx);
3188 idx = find_next_bit_wrap(tx->in_use, tx->len,
3189 tx->last_ll_ts_idx_read + 1);
3191 ice_ptp_req_tx_single_tstamp(tx, idx);
3192 spin_unlock_irqrestore(&tx->lock, flags);
3194 val = GLINT_DYN_CTL_INTENA_M | GLINT_DYN_CTL_CLEARPBA_M |
3195 (ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S);
3196 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST;
3197 wr32(hw, GLINT_DYN_CTL(pf->ll_ts_irq.index + pf_intr_start_offset),
3204 * ice_misc_intr - misc interrupt handler
3205 * @irq: interrupt number
3206 * @data: pointer to a q_vector
3208 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
3210 struct ice_pf *pf = (struct ice_pf *)data;
3211 irqreturn_t ret = IRQ_HANDLED;
3212 struct ice_hw *hw = &pf->hw;
3216 dev = ice_pf_to_dev(pf);
3217 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
3218 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
3219 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
3221 oicr = rd32(hw, PFINT_OICR);
3222 ena_mask = rd32(hw, PFINT_OICR_ENA);
3224 if (oicr & PFINT_OICR_SWINT_M) {
3225 ena_mask &= ~PFINT_OICR_SWINT_M;
3229 if (oicr & PFINT_OICR_MAL_DETECT_M) {
3230 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
3231 set_bit(ICE_MDD_EVENT_PENDING, pf->state);
3233 if (oicr & PFINT_OICR_VFLR_M) {
3234 /* disable any further VFLR event notifications */
3235 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
3236 u32 reg = rd32(hw, PFINT_OICR_ENA);
3238 reg &= ~PFINT_OICR_VFLR_M;
3239 wr32(hw, PFINT_OICR_ENA, reg);
3241 ena_mask &= ~PFINT_OICR_VFLR_M;
3242 set_bit(ICE_VFLR_EVENT_PENDING, pf->state);
3246 if (oicr & PFINT_OICR_GRST_M) {
3249 /* we have a reset warning */
3250 ena_mask &= ~PFINT_OICR_GRST_M;
3251 reset = FIELD_GET(GLGEN_RSTAT_RESET_TYPE_M,
3252 rd32(hw, GLGEN_RSTAT));
3254 if (reset == ICE_RESET_CORER)
3256 else if (reset == ICE_RESET_GLOBR)
3258 else if (reset == ICE_RESET_EMPR)
3261 dev_dbg(dev, "Invalid reset type %d\n", reset);
3263 /* If a reset cycle isn't already in progress, we set a bit in
3264 * pf->state so that the service task can start a reset/rebuild.
3266 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) {
3267 if (reset == ICE_RESET_CORER)
3268 set_bit(ICE_CORER_RECV, pf->state);
3269 else if (reset == ICE_RESET_GLOBR)
3270 set_bit(ICE_GLOBR_RECV, pf->state);
3272 set_bit(ICE_EMPR_RECV, pf->state);
3274 /* There are couple of different bits at play here.
3275 * hw->reset_ongoing indicates whether the hardware is
3276 * in reset. This is set to true when a reset interrupt
3277 * is received and set back to false after the driver
3278 * has determined that the hardware is out of reset.
3280 * ICE_RESET_OICR_RECV in pf->state indicates
3281 * that a post reset rebuild is required before the
3282 * driver is operational again. This is set above.
3284 * As this is the start of the reset/rebuild cycle, set
3285 * both to indicate that.
3287 hw->reset_ongoing = true;
3291 if (oicr & PFINT_OICR_TSYN_TX_M) {
3292 ena_mask &= ~PFINT_OICR_TSYN_TX_M;
3293 if (ice_pf_state_is_nominal(pf) &&
3294 pf->hw.dev_caps.ts_dev_info.ts_ll_int_read) {
3295 struct ice_ptp_tx *tx = &pf->ptp.port.tx;
3296 unsigned long flags;
3299 spin_lock_irqsave(&tx->lock, flags);
3300 idx = find_next_bit_wrap(tx->in_use, tx->len,
3301 tx->last_ll_ts_idx_read + 1);
3303 ice_ptp_req_tx_single_tstamp(tx, idx);
3304 spin_unlock_irqrestore(&tx->lock, flags);
3305 } else if (ice_ptp_pf_handles_tx_interrupt(pf)) {
3306 set_bit(ICE_MISC_THREAD_TX_TSTAMP, pf->misc_thread);
3307 ret = IRQ_WAKE_THREAD;
3311 if (oicr & PFINT_OICR_TSYN_EVNT_M) {
3312 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
3313 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx));
3315 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M;
3317 if (ice_pf_src_tmr_owned(pf)) {
3318 /* Save EVENTs from GLTSYN register */
3319 pf->ptp.ext_ts_irq |= gltsyn_stat &
3320 (GLTSYN_STAT_EVENT0_M |
3321 GLTSYN_STAT_EVENT1_M |
3322 GLTSYN_STAT_EVENT2_M);
3324 ice_ptp_extts_event(pf);
3328 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M)
3329 if (oicr & ICE_AUX_CRIT_ERR) {
3330 pf->oicr_err_reg |= oicr;
3331 set_bit(ICE_AUX_ERR_PENDING, pf->state);
3332 ena_mask &= ~ICE_AUX_CRIT_ERR;
3335 /* Report any remaining unexpected interrupts */
3338 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
3339 /* If a critical error is pending there is no choice but to
3342 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M |
3343 PFINT_OICR_ECC_ERR_M)) {
3344 set_bit(ICE_PFR_REQ, pf->state);
3347 ice_service_task_schedule(pf);
3348 if (ret == IRQ_HANDLED)
3349 ice_irq_dynamic_ena(hw, NULL, NULL);
3355 * ice_misc_intr_thread_fn - misc interrupt thread function
3356 * @irq: interrupt number
3357 * @data: pointer to a q_vector
3359 static irqreturn_t ice_misc_intr_thread_fn(int __always_unused irq, void *data)
3361 struct ice_pf *pf = data;
3366 if (ice_is_reset_in_progress(pf->state))
3369 if (test_and_clear_bit(ICE_MISC_THREAD_TX_TSTAMP, pf->misc_thread)) {
3370 /* Process outstanding Tx timestamps. If there is more work,
3371 * re-arm the interrupt to trigger again.
3373 if (ice_ptp_process_ts(pf) == ICE_TX_TSTAMP_WORK_PENDING) {
3374 wr32(hw, PFINT_OICR, PFINT_OICR_TSYN_TX_M);
3380 ice_irq_dynamic_ena(hw, NULL, NULL);
3386 * ice_dis_ctrlq_interrupts - disable control queue interrupts
3387 * @hw: pointer to HW structure
3389 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
3391 /* disable Admin queue Interrupt causes */
3392 wr32(hw, PFINT_FW_CTL,
3393 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
3395 /* disable Mailbox queue Interrupt causes */
3396 wr32(hw, PFINT_MBX_CTL,
3397 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
3399 wr32(hw, PFINT_SB_CTL,
3400 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M);
3402 /* disable Control queue Interrupt causes */
3403 wr32(hw, PFINT_OICR_CTL,
3404 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
3410 * ice_free_irq_msix_ll_ts- Unroll ll_ts vector setup
3411 * @pf: board private structure
3413 static void ice_free_irq_msix_ll_ts(struct ice_pf *pf)
3415 int irq_num = pf->ll_ts_irq.virq;
3417 synchronize_irq(irq_num);
3418 devm_free_irq(ice_pf_to_dev(pf), irq_num, pf);
3420 ice_free_irq(pf, pf->ll_ts_irq);
3424 * ice_free_irq_msix_misc - Unroll misc vector setup
3425 * @pf: board private structure
3427 static void ice_free_irq_msix_misc(struct ice_pf *pf)
3429 int misc_irq_num = pf->oicr_irq.virq;
3430 struct ice_hw *hw = &pf->hw;
3432 ice_dis_ctrlq_interrupts(hw);
3434 /* disable OICR interrupt */
3435 wr32(hw, PFINT_OICR_ENA, 0);
3438 synchronize_irq(misc_irq_num);
3439 devm_free_irq(ice_pf_to_dev(pf), misc_irq_num, pf);
3441 ice_free_irq(pf, pf->oicr_irq);
3442 if (pf->hw.dev_caps.ts_dev_info.ts_ll_int_read)
3443 ice_free_irq_msix_ll_ts(pf);
3447 * ice_ena_ctrlq_interrupts - enable control queue interrupts
3448 * @hw: pointer to HW structure
3449 * @reg_idx: HW vector index to associate the control queue interrupts with
3451 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
3455 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
3456 PFINT_OICR_CTL_CAUSE_ENA_M);
3457 wr32(hw, PFINT_OICR_CTL, val);
3459 /* enable Admin queue Interrupt causes */
3460 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
3461 PFINT_FW_CTL_CAUSE_ENA_M);
3462 wr32(hw, PFINT_FW_CTL, val);
3464 /* enable Mailbox queue Interrupt causes */
3465 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
3466 PFINT_MBX_CTL_CAUSE_ENA_M);
3467 wr32(hw, PFINT_MBX_CTL, val);
3469 if (!hw->dev_caps.ts_dev_info.ts_ll_int_read) {
3470 /* enable Sideband queue Interrupt causes */
3471 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) |
3472 PFINT_SB_CTL_CAUSE_ENA_M);
3473 wr32(hw, PFINT_SB_CTL, val);
3480 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
3481 * @pf: board private structure
3483 * This sets up the handler for MSIX 0, which is used to manage the
3484 * non-queue interrupts, e.g. AdminQ and errors. This is not used
3485 * when in MSI or Legacy interrupt mode.
3487 static int ice_req_irq_msix_misc(struct ice_pf *pf)
3489 struct device *dev = ice_pf_to_dev(pf);
3490 struct ice_hw *hw = &pf->hw;
3491 u32 pf_intr_start_offset;
3495 if (!pf->int_name[0])
3496 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
3497 dev_driver_string(dev), dev_name(dev));
3499 if (!pf->int_name_ll_ts[0])
3500 snprintf(pf->int_name_ll_ts, sizeof(pf->int_name_ll_ts) - 1,
3501 "%s-%s:ll_ts", dev_driver_string(dev), dev_name(dev));
3502 /* Do not request IRQ but do enable OICR interrupt since settings are
3503 * lost during reset. Note that this function is called only during
3504 * rebuild path and not while reset is in progress.
3506 if (ice_is_reset_in_progress(pf->state))
3509 /* reserve one vector in irq_tracker for misc interrupts */
3510 irq = ice_alloc_irq(pf, false);
3515 err = devm_request_threaded_irq(dev, pf->oicr_irq.virq, ice_misc_intr,
3516 ice_misc_intr_thread_fn, 0,
3519 dev_err(dev, "devm_request_threaded_irq for %s failed: %d\n",
3521 ice_free_irq(pf, pf->oicr_irq);
3525 /* reserve one vector in irq_tracker for ll_ts interrupt */
3526 if (!pf->hw.dev_caps.ts_dev_info.ts_ll_int_read)
3529 irq = ice_alloc_irq(pf, false);
3533 pf->ll_ts_irq = irq;
3534 err = devm_request_irq(dev, pf->ll_ts_irq.virq, ice_ll_ts_intr, 0,
3535 pf->int_name_ll_ts, pf);
3537 dev_err(dev, "devm_request_irq for %s failed: %d\n",
3538 pf->int_name_ll_ts, err);
3539 ice_free_irq(pf, pf->ll_ts_irq);
3544 ice_ena_misc_vector(pf);
3546 ice_ena_ctrlq_interrupts(hw, pf->oicr_irq.index);
3547 /* This enables LL TS interrupt */
3548 pf_intr_start_offset = rd32(hw, PFINT_ALLOC) & PFINT_ALLOC_FIRST;
3549 if (pf->hw.dev_caps.ts_dev_info.ts_ll_int_read)
3550 wr32(hw, PFINT_SB_CTL,
3551 ((pf->ll_ts_irq.index + pf_intr_start_offset) &
3552 PFINT_SB_CTL_MSIX_INDX_M) | PFINT_SB_CTL_CAUSE_ENA_M);
3553 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_irq.index),
3554 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
3557 ice_irq_dynamic_ena(hw, NULL, NULL);
3563 * ice_set_ops - set netdev and ethtools ops for the given netdev
3564 * @vsi: the VSI associated with the new netdev
3566 static void ice_set_ops(struct ice_vsi *vsi)
3568 struct net_device *netdev = vsi->netdev;
3569 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3571 if (ice_is_safe_mode(pf)) {
3572 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
3573 ice_set_ethtool_safe_mode_ops(netdev);
3577 netdev->netdev_ops = &ice_netdev_ops;
3578 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic;
3579 netdev->xdp_metadata_ops = &ice_xdp_md_ops;
3580 ice_set_ethtool_ops(netdev);
3582 if (vsi->type != ICE_VSI_PF)
3585 netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
3586 NETDEV_XDP_ACT_XSK_ZEROCOPY |
3587 NETDEV_XDP_ACT_RX_SG;
3588 netdev->xdp_zc_max_segs = ICE_MAX_BUF_TXD;
3592 * ice_set_netdev_features - set features for the given netdev
3593 * @netdev: netdev instance
3595 void ice_set_netdev_features(struct net_device *netdev)
3597 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3598 bool is_dvm_ena = ice_is_dvm_ena(&pf->hw);
3599 netdev_features_t csumo_features;
3600 netdev_features_t vlano_features;
3601 netdev_features_t dflt_features;
3602 netdev_features_t tso_features;
3604 if (ice_is_safe_mode(pf)) {
3606 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
3607 netdev->hw_features = netdev->features;
3611 dflt_features = NETIF_F_SG |
3616 csumo_features = NETIF_F_RXCSUM |
3621 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
3622 NETIF_F_HW_VLAN_CTAG_TX |
3623 NETIF_F_HW_VLAN_CTAG_RX;
3625 /* Enable CTAG/STAG filtering by default in Double VLAN Mode (DVM) */
3627 vlano_features |= NETIF_F_HW_VLAN_STAG_FILTER;
3629 tso_features = NETIF_F_TSO |
3633 NETIF_F_GSO_UDP_TUNNEL |
3634 NETIF_F_GSO_GRE_CSUM |
3635 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3636 NETIF_F_GSO_PARTIAL |
3637 NETIF_F_GSO_IPXIP4 |
3638 NETIF_F_GSO_IPXIP6 |
3641 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3642 NETIF_F_GSO_GRE_CSUM;
3643 /* set features that user can change */
3644 netdev->hw_features = dflt_features | csumo_features |
3645 vlano_features | tso_features;
3647 /* add support for HW_CSUM on packets with MPLS header */
3648 netdev->mpls_features = NETIF_F_HW_CSUM |
3652 /* enable features */
3653 netdev->features |= netdev->hw_features;
3655 netdev->hw_features |= NETIF_F_HW_TC;
3656 netdev->hw_features |= NETIF_F_LOOPBACK;
3658 /* encap and VLAN devices inherit default, csumo and tso features */
3659 netdev->hw_enc_features |= dflt_features | csumo_features |
3661 netdev->vlan_features |= dflt_features | csumo_features |
3664 /* advertise support but don't enable by default since only one type of
3665 * VLAN offload can be enabled at a time (i.e. CTAG or STAG). When one
3666 * type turns on the other has to be turned off. This is enforced by the
3667 * ice_fix_features() ndo callback.
3670 netdev->hw_features |= NETIF_F_HW_VLAN_STAG_RX |
3671 NETIF_F_HW_VLAN_STAG_TX;
3673 /* Leave CRC / FCS stripping enabled by default, but allow the value to
3674 * be changed at runtime
3676 netdev->hw_features |= NETIF_F_RXFCS;
3678 netif_set_tso_max_size(netdev, ICE_MAX_TSO_SIZE);
3682 * ice_fill_rss_lut - Fill the RSS lookup table with default values
3683 * @lut: Lookup table
3684 * @rss_table_size: Lookup table size
3685 * @rss_size: Range of queue number for hashing
3687 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
3691 for (i = 0; i < rss_table_size; i++)
3692 lut[i] = i % rss_size;
3696 * ice_pf_vsi_setup - Set up a PF VSI
3697 * @pf: board private structure
3698 * @pi: pointer to the port_info instance
3700 * Returns pointer to the successfully allocated VSI software struct
3701 * on success, otherwise returns NULL on failure.
3703 static struct ice_vsi *
3704 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3706 struct ice_vsi_cfg_params params = {};
3708 params.type = ICE_VSI_PF;
3709 params.port_info = pi;
3710 params.flags = ICE_VSI_FLAG_INIT;
3712 return ice_vsi_setup(pf, ¶ms);
3715 static struct ice_vsi *
3716 ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
3717 struct ice_channel *ch)
3719 struct ice_vsi_cfg_params params = {};
3721 params.type = ICE_VSI_CHNL;
3722 params.port_info = pi;
3724 params.flags = ICE_VSI_FLAG_INIT;
3726 return ice_vsi_setup(pf, ¶ms);
3730 * ice_ctrl_vsi_setup - Set up a control VSI
3731 * @pf: board private structure
3732 * @pi: pointer to the port_info instance
3734 * Returns pointer to the successfully allocated VSI software struct
3735 * on success, otherwise returns NULL on failure.
3737 static struct ice_vsi *
3738 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3740 struct ice_vsi_cfg_params params = {};
3742 params.type = ICE_VSI_CTRL;
3743 params.port_info = pi;
3744 params.flags = ICE_VSI_FLAG_INIT;
3746 return ice_vsi_setup(pf, ¶ms);
3750 * ice_lb_vsi_setup - Set up a loopback VSI
3751 * @pf: board private structure
3752 * @pi: pointer to the port_info instance
3754 * Returns pointer to the successfully allocated VSI software struct
3755 * on success, otherwise returns NULL on failure.
3758 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3760 struct ice_vsi_cfg_params params = {};
3762 params.type = ICE_VSI_LB;
3763 params.port_info = pi;
3764 params.flags = ICE_VSI_FLAG_INIT;
3766 return ice_vsi_setup(pf, ¶ms);
3770 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
3771 * @netdev: network interface to be adjusted
3773 * @vid: VLAN ID to be added
3775 * net_device_ops implementation for adding VLAN IDs
3777 int ice_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
3779 struct ice_netdev_priv *np = netdev_priv(netdev);
3780 struct ice_vsi_vlan_ops *vlan_ops;
3781 struct ice_vsi *vsi = np->vsi;
3782 struct ice_vlan vlan;
3785 /* VLAN 0 is added by default during load/reset */
3789 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3790 usleep_range(1000, 2000);
3792 /* Add multicast promisc rule for the VLAN ID to be added if
3793 * all-multicast is currently enabled.
3795 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3796 ret = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3797 ICE_MCAST_VLAN_PROMISC_BITS,
3803 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3805 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
3806 * packets aren't pruned by the device's internal switch on Rx
3808 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3809 ret = vlan_ops->add_vlan(vsi, &vlan);
3813 /* If all-multicast is currently enabled and this VLAN ID is only one
3814 * besides VLAN-0 we have to update look-up type of multicast promisc
3815 * rule for VLAN-0 from ICE_SW_LKUP_PROMISC to ICE_SW_LKUP_PROMISC_VLAN.
3817 if ((vsi->current_netdev_flags & IFF_ALLMULTI) &&
3818 ice_vsi_num_non_zero_vlans(vsi) == 1) {
3819 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3820 ICE_MCAST_PROMISC_BITS, 0);
3821 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3822 ICE_MCAST_VLAN_PROMISC_BITS, 0);
3826 clear_bit(ICE_CFG_BUSY, vsi->state);
3832 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
3833 * @netdev: network interface to be adjusted
3835 * @vid: VLAN ID to be removed
3837 * net_device_ops implementation for removing VLAN IDs
3839 int ice_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3841 struct ice_netdev_priv *np = netdev_priv(netdev);
3842 struct ice_vsi_vlan_ops *vlan_ops;
3843 struct ice_vsi *vsi = np->vsi;
3844 struct ice_vlan vlan;
3847 /* don't allow removal of VLAN 0 */
3851 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
3852 usleep_range(1000, 2000);
3854 ret = ice_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3855 ICE_MCAST_VLAN_PROMISC_BITS, vid);
3857 netdev_err(netdev, "Error clearing multicast promiscuous mode on VSI %i\n",
3859 vsi->current_netdev_flags |= IFF_ALLMULTI;
3862 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3864 /* Make sure VLAN delete is successful before updating VLAN
3867 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3868 ret = vlan_ops->del_vlan(vsi, &vlan);
3872 /* Remove multicast promisc rule for the removed VLAN ID if
3873 * all-multicast is enabled.
3875 if (vsi->current_netdev_flags & IFF_ALLMULTI)
3876 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3877 ICE_MCAST_VLAN_PROMISC_BITS, vid);
3879 if (!ice_vsi_has_non_zero_vlans(vsi)) {
3880 /* Update look-up type of multicast promisc rule for VLAN 0
3881 * from ICE_SW_LKUP_PROMISC_VLAN to ICE_SW_LKUP_PROMISC when
3882 * all-multicast is enabled and VLAN 0 is the only VLAN rule.
3884 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
3885 ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx,
3886 ICE_MCAST_VLAN_PROMISC_BITS,
3888 ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx,
3889 ICE_MCAST_PROMISC_BITS, 0);
3894 clear_bit(ICE_CFG_BUSY, vsi->state);
3900 * ice_rep_indr_tc_block_unbind
3901 * @cb_priv: indirection block private data
3903 static void ice_rep_indr_tc_block_unbind(void *cb_priv)
3905 struct ice_indr_block_priv *indr_priv = cb_priv;
3907 list_del(&indr_priv->list);
3912 * ice_tc_indir_block_unregister - Unregister TC indirect block notifications
3913 * @vsi: VSI struct which has the netdev
3915 static void ice_tc_indir_block_unregister(struct ice_vsi *vsi)
3917 struct ice_netdev_priv *np = netdev_priv(vsi->netdev);
3919 flow_indr_dev_unregister(ice_indr_setup_tc_cb, np,
3920 ice_rep_indr_tc_block_unbind);
3924 * ice_tc_indir_block_register - Register TC indirect block notifications
3925 * @vsi: VSI struct which has the netdev
3927 * Returns 0 on success, negative value on failure
3929 static int ice_tc_indir_block_register(struct ice_vsi *vsi)
3931 struct ice_netdev_priv *np;
3933 if (!vsi || !vsi->netdev)
3936 np = netdev_priv(vsi->netdev);
3938 INIT_LIST_HEAD(&np->tc_indr_block_priv_list);
3939 return flow_indr_dev_register(ice_indr_setup_tc_cb, np);
3943 * ice_get_avail_q_count - Get count of queues in use
3944 * @pf_qmap: bitmap to get queue use count from
3945 * @lock: pointer to a mutex that protects access to pf_qmap
3946 * @size: size of the bitmap
3949 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
3955 for_each_clear_bit(bit, pf_qmap, size)
3963 * ice_get_avail_txq_count - Get count of Tx queues in use
3964 * @pf: pointer to an ice_pf instance
3966 u16 ice_get_avail_txq_count(struct ice_pf *pf)
3968 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
3973 * ice_get_avail_rxq_count - Get count of Rx queues in use
3974 * @pf: pointer to an ice_pf instance
3976 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
3978 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
3983 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3984 * @pf: board private structure to initialize
3986 static void ice_deinit_pf(struct ice_pf *pf)
3988 ice_service_task_stop(pf);
3989 mutex_destroy(&pf->lag_mutex);
3990 mutex_destroy(&pf->adev_mutex);
3991 mutex_destroy(&pf->sw_mutex);
3992 mutex_destroy(&pf->tc_mutex);
3993 mutex_destroy(&pf->avail_q_mutex);
3994 mutex_destroy(&pf->vfs.table_lock);
3996 if (pf->avail_txqs) {
3997 bitmap_free(pf->avail_txqs);
3998 pf->avail_txqs = NULL;
4001 if (pf->avail_rxqs) {
4002 bitmap_free(pf->avail_rxqs);
4003 pf->avail_rxqs = NULL;
4007 ptp_clock_unregister(pf->ptp.clock);
4009 xa_destroy(&pf->dyn_ports);
4010 xa_destroy(&pf->sf_nums);
4014 * ice_set_pf_caps - set PFs capability flags
4015 * @pf: pointer to the PF instance
4017 static void ice_set_pf_caps(struct ice_pf *pf)
4019 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
4021 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
4022 if (func_caps->common_cap.rdma)
4023 set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
4024 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4025 if (func_caps->common_cap.dcb)
4026 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4027 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
4028 if (func_caps->common_cap.sr_iov_1_1) {
4029 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
4030 pf->vfs.num_supported = min_t(int, func_caps->num_allocd_vfs,
4033 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
4034 if (func_caps->common_cap.rss_table_size)
4035 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
4037 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
4038 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
4041 /* ctrl_vsi_idx will be set to a valid value when flow director
4042 * is setup by ice_init_fdir
4044 pf->ctrl_vsi_idx = ICE_NO_VSI;
4045 set_bit(ICE_FLAG_FD_ENA, pf->flags);
4046 /* force guaranteed filter pool for PF */
4047 ice_alloc_fd_guar_item(&pf->hw, &unused,
4048 func_caps->fd_fltr_guar);
4049 /* force shared filter pool for PF */
4050 ice_alloc_fd_shrd_item(&pf->hw, &unused,
4051 func_caps->fd_fltr_best_effort);
4054 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
4055 if (func_caps->common_cap.ieee_1588 &&
4056 !(pf->hw.mac_type == ICE_MAC_E830))
4057 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
4059 pf->max_pf_txqs = func_caps->common_cap.num_txq;
4060 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
4064 * ice_init_pf - Initialize general software structures (struct ice_pf)
4065 * @pf: board private structure to initialize
4067 static int ice_init_pf(struct ice_pf *pf)
4069 ice_set_pf_caps(pf);
4071 mutex_init(&pf->sw_mutex);
4072 mutex_init(&pf->tc_mutex);
4073 mutex_init(&pf->adev_mutex);
4074 mutex_init(&pf->lag_mutex);
4076 INIT_HLIST_HEAD(&pf->aq_wait_list);
4077 spin_lock_init(&pf->aq_wait_lock);
4078 init_waitqueue_head(&pf->aq_wait_queue);
4080 init_waitqueue_head(&pf->reset_wait_queue);
4082 /* setup service timer and periodic service task */
4083 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
4084 pf->serv_tmr_period = HZ;
4085 INIT_WORK(&pf->serv_task, ice_service_task);
4086 clear_bit(ICE_SERVICE_SCHED, pf->state);
4088 mutex_init(&pf->avail_q_mutex);
4089 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
4090 if (!pf->avail_txqs)
4093 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
4094 if (!pf->avail_rxqs) {
4095 bitmap_free(pf->avail_txqs);
4096 pf->avail_txqs = NULL;
4100 mutex_init(&pf->vfs.table_lock);
4101 hash_init(pf->vfs.table);
4102 ice_mbx_init_snapshot(&pf->hw);
4104 xa_init(&pf->dyn_ports);
4105 xa_init(&pf->sf_nums);
4111 * ice_is_wol_supported - check if WoL is supported
4112 * @hw: pointer to hardware info
4114 * Check if WoL is supported based on the HW configuration.
4115 * Returns true if NVM supports and enables WoL for this port, false otherwise
4117 bool ice_is_wol_supported(struct ice_hw *hw)
4121 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control
4122 * word) indicates WoL is not supported on the corresponding PF ID.
4124 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl))
4127 return !(BIT(hw->port_info->lport) & wol_ctrl);
4131 * ice_vsi_recfg_qs - Change the number of queues on a VSI
4132 * @vsi: VSI being changed
4133 * @new_rx: new number of Rx queues
4134 * @new_tx: new number of Tx queues
4135 * @locked: is adev device_lock held
4137 * Only change the number of queues if new_tx, or new_rx is non-0.
4139 * Returns 0 on success.
4141 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx, bool locked)
4143 struct ice_pf *pf = vsi->back;
4144 int i, err = 0, timeout = 50;
4146 if (!new_rx && !new_tx)
4149 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
4153 usleep_range(1000, 2000);
4157 vsi->req_txq = (u16)new_tx;
4159 vsi->req_rxq = (u16)new_rx;
4161 /* set for the next time the netdev is started */
4162 if (!netif_running(vsi->netdev)) {
4163 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT);
4166 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
4171 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT);
4175 ice_for_each_traffic_class(i) {
4176 if (vsi->tc_cfg.ena_tc & BIT(i))
4177 netdev_set_tc_queue(vsi->netdev,
4178 vsi->tc_cfg.tc_info[i].netdev_tc,
4179 vsi->tc_cfg.tc_info[i].qcount_tx,
4180 vsi->tc_cfg.tc_info[i].qoffset);
4182 ice_pf_dcb_recfg(pf, locked);
4187 dev_err(ice_pf_to_dev(pf), "Error during VSI rebuild: %d. Unload and reload the driver.\n",
4190 clear_bit(ICE_CFG_BUSY, pf->state);
4195 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode
4196 * @pf: PF to configure
4198 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF
4199 * VSI can still Tx/Rx VLAN tagged packets.
4201 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf)
4203 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4204 struct ice_vsi_ctx *ctxt;
4211 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4216 ctxt->info = vsi->info;
4218 ctxt->info.valid_sections =
4219 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
4220 ICE_AQ_VSI_PROP_SECURITY_VALID |
4221 ICE_AQ_VSI_PROP_SW_VALID);
4223 /* disable VLAN anti-spoof */
4224 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
4225 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
4227 /* disable VLAN pruning and keep all other settings */
4228 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4230 /* allow all VLANs on Tx and don't strip on Rx */
4231 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL |
4232 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4234 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4236 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %d aq_err %s\n",
4237 status, ice_aq_str(hw->adminq.sq_last_status));
4239 vsi->info.sec_flags = ctxt->info.sec_flags;
4240 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
4241 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
4248 * ice_log_pkg_init - log result of DDP package load
4249 * @hw: pointer to hardware info
4250 * @state: state of package load
4252 static void ice_log_pkg_init(struct ice_hw *hw, enum ice_ddp_state state)
4254 struct ice_pf *pf = hw->back;
4257 dev = ice_pf_to_dev(pf);
4260 case ICE_DDP_PKG_SUCCESS:
4261 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
4262 hw->active_pkg_name,
4263 hw->active_pkg_ver.major,
4264 hw->active_pkg_ver.minor,
4265 hw->active_pkg_ver.update,
4266 hw->active_pkg_ver.draft);
4268 case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED:
4269 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
4270 hw->active_pkg_name,
4271 hw->active_pkg_ver.major,
4272 hw->active_pkg_ver.minor,
4273 hw->active_pkg_ver.update,
4274 hw->active_pkg_ver.draft);
4276 case ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED:
4277 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",
4278 hw->active_pkg_name,
4279 hw->active_pkg_ver.major,
4280 hw->active_pkg_ver.minor,
4281 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4283 case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED:
4284 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",
4285 hw->active_pkg_name,
4286 hw->active_pkg_ver.major,
4287 hw->active_pkg_ver.minor,
4288 hw->active_pkg_ver.update,
4289 hw->active_pkg_ver.draft,
4296 case ICE_DDP_PKG_FW_MISMATCH:
4297 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");
4299 case ICE_DDP_PKG_INVALID_FILE:
4300 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
4302 case ICE_DDP_PKG_FILE_VERSION_TOO_HIGH:
4303 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
4305 case ICE_DDP_PKG_FILE_VERSION_TOO_LOW:
4306 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",
4307 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4309 case ICE_DDP_PKG_FILE_SIGNATURE_INVALID:
4310 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");
4312 case ICE_DDP_PKG_FILE_REVISION_TOO_LOW:
4313 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");
4315 case ICE_DDP_PKG_LOAD_ERROR:
4316 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
4317 /* poll for reset to complete */
4318 if (ice_check_reset(hw))
4319 dev_err(dev, "Error resetting device. Please reload the driver\n");
4321 case ICE_DDP_PKG_ERR:
4323 dev_err(dev, "An unknown error occurred when loading the DDP package. Entering Safe Mode.\n");
4329 * ice_load_pkg - load/reload the DDP Package file
4330 * @firmware: firmware structure when firmware requested or NULL for reload
4331 * @pf: pointer to the PF instance
4333 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
4334 * initialize HW tables.
4337 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
4339 enum ice_ddp_state state = ICE_DDP_PKG_ERR;
4340 struct device *dev = ice_pf_to_dev(pf);
4341 struct ice_hw *hw = &pf->hw;
4343 /* Load DDP Package */
4344 if (firmware && !hw->pkg_copy) {
4345 state = ice_copy_and_init_pkg(hw, firmware->data,
4347 ice_log_pkg_init(hw, state);
4348 } else if (!firmware && hw->pkg_copy) {
4349 /* Reload package during rebuild after CORER/GLOBR reset */
4350 state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
4351 ice_log_pkg_init(hw, state);
4353 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
4356 if (!ice_is_init_pkg_successful(state)) {
4358 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4362 /* Successful download package is the precondition for advanced
4363 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
4365 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4369 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
4370 * @pf: pointer to the PF structure
4372 * There is no error returned here because the driver should be able to handle
4373 * 128 Byte cache lines, so we only print a warning in case issues are seen,
4374 * specifically with Tx.
4376 static void ice_verify_cacheline_size(struct ice_pf *pf)
4378 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
4379 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
4380 ICE_CACHE_LINE_BYTES);
4384 * ice_send_version - update firmware with driver version
4387 * Returns 0 on success, else error code
4389 static int ice_send_version(struct ice_pf *pf)
4391 struct ice_driver_ver dv;
4393 dv.major_ver = 0xff;
4394 dv.minor_ver = 0xff;
4395 dv.build_ver = 0xff;
4396 dv.subbuild_ver = 0;
4397 strscpy((char *)dv.driver_string, UTS_RELEASE,
4398 sizeof(dv.driver_string));
4399 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
4403 * ice_init_fdir - Initialize flow director VSI and configuration
4404 * @pf: pointer to the PF instance
4406 * returns 0 on success, negative on error
4408 static int ice_init_fdir(struct ice_pf *pf)
4410 struct device *dev = ice_pf_to_dev(pf);
4411 struct ice_vsi *ctrl_vsi;
4414 /* Side Band Flow Director needs to have a control VSI.
4415 * Allocate it and store it in the PF.
4417 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
4419 dev_dbg(dev, "could not create control VSI\n");
4423 err = ice_vsi_open_ctrl(ctrl_vsi);
4425 dev_dbg(dev, "could not open control VSI\n");
4429 mutex_init(&pf->hw.fdir_fltr_lock);
4431 err = ice_fdir_create_dflt_rules(pf);
4438 ice_fdir_release_flows(&pf->hw);
4439 ice_vsi_close(ctrl_vsi);
4441 ice_vsi_release(ctrl_vsi);
4442 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4443 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4444 pf->ctrl_vsi_idx = ICE_NO_VSI;
4449 static void ice_deinit_fdir(struct ice_pf *pf)
4451 struct ice_vsi *vsi = ice_get_ctrl_vsi(pf);
4456 ice_vsi_manage_fdir(vsi, false);
4457 ice_vsi_release(vsi);
4458 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4459 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4460 pf->ctrl_vsi_idx = ICE_NO_VSI;
4463 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
4467 * ice_get_opt_fw_name - return optional firmware file name or NULL
4468 * @pf: pointer to the PF instance
4470 static char *ice_get_opt_fw_name(struct ice_pf *pf)
4472 /* Optional firmware name same as default with additional dash
4473 * followed by a EUI-64 identifier (PCIe Device Serial Number)
4475 struct pci_dev *pdev = pf->pdev;
4476 char *opt_fw_filename;
4479 /* Determine the name of the optional file using the DSN (two
4480 * dwords following the start of the DSN Capability).
4482 dsn = pci_get_dsn(pdev);
4486 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
4487 if (!opt_fw_filename)
4490 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg",
4491 ICE_DDP_PKG_PATH, dsn);
4493 return opt_fw_filename;
4497 * ice_request_fw - Device initialization routine
4498 * @pf: pointer to the PF instance
4499 * @firmware: double pointer to firmware struct
4501 * Return: zero when successful, negative values otherwise.
4503 static int ice_request_fw(struct ice_pf *pf, const struct firmware **firmware)
4505 char *opt_fw_filename = ice_get_opt_fw_name(pf);
4506 struct device *dev = ice_pf_to_dev(pf);
4509 /* optional device-specific DDP (if present) overrides the default DDP
4510 * package file. kernel logs a debug message if the file doesn't exist,
4511 * and warning messages for other errors.
4513 if (opt_fw_filename) {
4514 err = firmware_request_nowarn(firmware, opt_fw_filename, dev);
4515 kfree(opt_fw_filename);
4519 err = request_firmware(firmware, ICE_DDP_PKG_FILE, dev);
4521 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
4527 * ice_init_tx_topology - performs Tx topology initialization
4528 * @hw: pointer to the hardware structure
4529 * @firmware: pointer to firmware structure
4531 * Return: zero when init was successful, negative values otherwise.
4534 ice_init_tx_topology(struct ice_hw *hw, const struct firmware *firmware)
4536 u8 num_tx_sched_layers = hw->num_tx_sched_layers;
4537 struct ice_pf *pf = hw->back;
4542 dev = ice_pf_to_dev(pf);
4543 /* ice_cfg_tx_topo buf argument is not a constant,
4544 * so we have to make a copy
4546 buf_copy = kmemdup(firmware->data, firmware->size, GFP_KERNEL);
4548 err = ice_cfg_tx_topo(hw, buf_copy, firmware->size);
4550 if (hw->num_tx_sched_layers > num_tx_sched_layers)
4551 dev_info(dev, "Tx scheduling layers switching feature disabled\n");
4553 dev_info(dev, "Tx scheduling layers switching feature enabled\n");
4554 /* if there was a change in topology ice_cfg_tx_topo triggered
4555 * a CORER and we need to re-init hw
4558 err = ice_init_hw(hw);
4561 } else if (err == -EIO) {
4562 dev_info(dev, "DDP package does not support Tx scheduling layers switching feature - please update to the latest DDP package and try again\n");
4569 * ice_init_ddp_config - DDP related configuration
4570 * @hw: pointer to the hardware structure
4571 * @pf: pointer to pf structure
4573 * This function loads DDP file from the disk, then initializes Tx
4574 * topology. At the end DDP package is loaded on the card.
4576 * Return: zero when init was successful, negative values otherwise.
4578 static int ice_init_ddp_config(struct ice_hw *hw, struct ice_pf *pf)
4580 struct device *dev = ice_pf_to_dev(pf);
4581 const struct firmware *firmware = NULL;
4584 err = ice_request_fw(pf, &firmware);
4586 dev_err(dev, "Fail during requesting FW: %d\n", err);
4590 err = ice_init_tx_topology(hw, firmware);
4592 dev_err(dev, "Fail during initialization of Tx topology: %d\n",
4594 release_firmware(firmware);
4598 /* Download firmware to device */
4599 ice_load_pkg(firmware, pf);
4600 release_firmware(firmware);
4606 * ice_print_wake_reason - show the wake up cause in the log
4607 * @pf: pointer to the PF struct
4609 static void ice_print_wake_reason(struct ice_pf *pf)
4611 u32 wus = pf->wakeup_reason;
4612 const char *wake_str;
4614 /* if no wake event, nothing to print */
4618 if (wus & PFPM_WUS_LNKC_M)
4619 wake_str = "Link\n";
4620 else if (wus & PFPM_WUS_MAG_M)
4621 wake_str = "Magic Packet\n";
4622 else if (wus & PFPM_WUS_MNG_M)
4623 wake_str = "Management\n";
4624 else if (wus & PFPM_WUS_FW_RST_WK_M)
4625 wake_str = "Firmware Reset\n";
4627 wake_str = "Unknown\n";
4629 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
4633 * ice_pf_fwlog_update_module - update 1 module
4634 * @pf: pointer to the PF struct
4635 * @log_level: log_level to use for the @module
4636 * @module: module to update
4638 void ice_pf_fwlog_update_module(struct ice_pf *pf, int log_level, int module)
4640 struct ice_hw *hw = &pf->hw;
4642 hw->fwlog_cfg.module_entries[module].log_level = log_level;
4646 * ice_register_netdev - register netdev
4647 * @vsi: pointer to the VSI struct
4649 static int ice_register_netdev(struct ice_vsi *vsi)
4653 if (!vsi || !vsi->netdev)
4656 err = register_netdev(vsi->netdev);
4660 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4661 netif_carrier_off(vsi->netdev);
4662 netif_tx_stop_all_queues(vsi->netdev);
4667 static void ice_unregister_netdev(struct ice_vsi *vsi)
4669 if (!vsi || !vsi->netdev)
4672 unregister_netdev(vsi->netdev);
4673 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4677 * ice_cfg_netdev - Allocate, configure and register a netdev
4678 * @vsi: the VSI associated with the new netdev
4680 * Returns 0 on success, negative value on failure
4682 static int ice_cfg_netdev(struct ice_vsi *vsi)
4684 struct ice_netdev_priv *np;
4685 struct net_device *netdev;
4686 u8 mac_addr[ETH_ALEN];
4688 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
4693 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4694 vsi->netdev = netdev;
4695 np = netdev_priv(netdev);
4698 ice_set_netdev_features(netdev);
4701 if (vsi->type == ICE_VSI_PF) {
4702 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back));
4703 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
4704 eth_hw_addr_set(netdev, mac_addr);
4707 netdev->priv_flags |= IFF_UNICAST_FLT;
4709 /* Setup netdev TC information */
4710 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
4712 netdev->max_mtu = ICE_MAX_MTU;
4717 static void ice_decfg_netdev(struct ice_vsi *vsi)
4719 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4720 free_netdev(vsi->netdev);
4725 * ice_wait_for_fw - wait for full FW readiness
4726 * @hw: pointer to the hardware structure
4727 * @timeout: milliseconds that can elapse before timing out
4729 static int ice_wait_for_fw(struct ice_hw *hw, u32 timeout)
4734 while (elapsed <= timeout) {
4735 fw_loading = rd32(hw, GL_MNG_FWSM) & GL_MNG_FWSM_FW_LOADING_M;
4737 /* firmware was not yet loaded, we have to wait more */
4749 int ice_init_dev(struct ice_pf *pf)
4751 struct device *dev = ice_pf_to_dev(pf);
4752 struct ice_hw *hw = &pf->hw;
4755 err = ice_init_hw(hw);
4757 dev_err(dev, "ice_init_hw failed: %d\n", err);
4761 /* Some cards require longer initialization times
4762 * due to necessity of loading FW from an external source.
4763 * This can take even half a minute.
4765 if (ice_is_pf_c827(hw)) {
4766 err = ice_wait_for_fw(hw, 30000);
4768 dev_err(dev, "ice_wait_for_fw timed out");
4773 ice_init_feature_support(pf);
4775 err = ice_init_ddp_config(hw, pf);
4779 /* if ice_init_ddp_config fails, ICE_FLAG_ADV_FEATURES bit won't be
4780 * set in pf->state, which will cause ice_is_safe_mode to return
4783 if (ice_is_safe_mode(pf)) {
4784 /* we already got function/device capabilities but these don't
4785 * reflect what the driver needs to do in safe mode. Instead of
4786 * adding conditional logic everywhere to ignore these
4787 * device/function capabilities, override them.
4789 ice_set_safe_mode_caps(hw);
4792 err = ice_init_pf(pf);
4794 dev_err(dev, "ice_init_pf failed: %d\n", err);
4798 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port;
4799 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port;
4800 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
4801 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared;
4802 if (pf->hw.tnl.valid_count[TNL_VXLAN]) {
4803 pf->hw.udp_tunnel_nic.tables[0].n_entries =
4804 pf->hw.tnl.valid_count[TNL_VXLAN];
4805 pf->hw.udp_tunnel_nic.tables[0].tunnel_types =
4806 UDP_TUNNEL_TYPE_VXLAN;
4808 if (pf->hw.tnl.valid_count[TNL_GENEVE]) {
4809 pf->hw.udp_tunnel_nic.tables[1].n_entries =
4810 pf->hw.tnl.valid_count[TNL_GENEVE];
4811 pf->hw.udp_tunnel_nic.tables[1].tunnel_types =
4812 UDP_TUNNEL_TYPE_GENEVE;
4815 err = ice_init_interrupt_scheme(pf);
4817 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
4819 goto err_init_interrupt_scheme;
4822 /* In case of MSIX we are going to setup the misc vector right here
4823 * to handle admin queue events etc. In case of legacy and MSI
4824 * the misc functionality and queue processing is combined in
4825 * the same vector and that gets setup at open.
4827 err = ice_req_irq_msix_misc(pf);
4829 dev_err(dev, "setup of misc vector failed: %d\n", err);
4830 goto err_req_irq_msix_misc;
4835 err_req_irq_msix_misc:
4836 ice_clear_interrupt_scheme(pf);
4837 err_init_interrupt_scheme:
4844 void ice_deinit_dev(struct ice_pf *pf)
4846 ice_free_irq_msix_misc(pf);
4848 ice_deinit_hw(&pf->hw);
4850 /* Service task is already stopped, so call reset directly. */
4851 ice_reset(&pf->hw, ICE_RESET_PFR);
4852 pci_wait_for_pending_transaction(pf->pdev);
4853 ice_clear_interrupt_scheme(pf);
4856 static void ice_init_features(struct ice_pf *pf)
4858 struct device *dev = ice_pf_to_dev(pf);
4860 if (ice_is_safe_mode(pf))
4863 /* initialize DDP driven features */
4864 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4867 if (ice_is_feature_supported(pf, ICE_F_GNSS))
4870 if (ice_is_feature_supported(pf, ICE_F_CGU) ||
4871 ice_is_feature_supported(pf, ICE_F_PHY_RCLK))
4874 /* Note: Flow director init failure is non-fatal to load */
4875 if (ice_init_fdir(pf))
4876 dev_err(dev, "could not initialize flow director\n");
4878 /* Note: DCB init failure is non-fatal to load */
4879 if (ice_init_pf_dcb(pf, false)) {
4880 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4881 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
4883 ice_cfg_lldp_mib_change(&pf->hw, true);
4886 if (ice_init_lag(pf))
4887 dev_warn(dev, "Failed to init link aggregation support\n");
4892 static void ice_deinit_features(struct ice_pf *pf)
4894 if (ice_is_safe_mode(pf))
4898 if (test_bit(ICE_FLAG_DCB_CAPABLE, pf->flags))
4899 ice_cfg_lldp_mib_change(&pf->hw, false);
4900 ice_deinit_fdir(pf);
4901 if (ice_is_feature_supported(pf, ICE_F_GNSS))
4903 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4904 ice_ptp_release(pf);
4905 if (test_bit(ICE_FLAG_DPLL, pf->flags))
4906 ice_dpll_deinit(pf);
4907 if (pf->eswitch_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV)
4908 xa_destroy(&pf->eswitch.reprs);
4911 static void ice_init_wakeup(struct ice_pf *pf)
4913 /* Save wakeup reason register for later use */
4914 pf->wakeup_reason = rd32(&pf->hw, PFPM_WUS);
4916 /* check for a power management event */
4917 ice_print_wake_reason(pf);
4919 /* clear wake status, all bits */
4920 wr32(&pf->hw, PFPM_WUS, U32_MAX);
4922 /* Disable WoL at init, wait for user to enable */
4923 device_set_wakeup_enable(ice_pf_to_dev(pf), false);
4926 static int ice_init_link(struct ice_pf *pf)
4928 struct device *dev = ice_pf_to_dev(pf);
4931 err = ice_init_link_events(pf->hw.port_info);
4933 dev_err(dev, "ice_init_link_events failed: %d\n", err);
4937 /* not a fatal error if this fails */
4938 err = ice_init_nvm_phy_type(pf->hw.port_info);
4940 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err);
4942 /* not a fatal error if this fails */
4943 err = ice_update_link_info(pf->hw.port_info);
4945 dev_err(dev, "ice_update_link_info failed: %d\n", err);
4947 ice_init_link_dflt_override(pf->hw.port_info);
4949 ice_check_link_cfg_err(pf,
4950 pf->hw.port_info->phy.link_info.link_cfg_err);
4952 /* if media available, initialize PHY settings */
4953 if (pf->hw.port_info->phy.link_info.link_info &
4954 ICE_AQ_MEDIA_AVAILABLE) {
4955 /* not a fatal error if this fails */
4956 err = ice_init_phy_user_cfg(pf->hw.port_info);
4958 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err);
4960 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) {
4961 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4964 ice_configure_phy(vsi);
4967 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
4973 static int ice_init_pf_sw(struct ice_pf *pf)
4975 bool dvm = ice_is_dvm_ena(&pf->hw);
4976 struct ice_vsi *vsi;
4979 /* create switch struct for the switch element created by FW on boot */
4980 pf->first_sw = kzalloc(sizeof(*pf->first_sw), GFP_KERNEL);
4985 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
4987 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
4989 pf->first_sw->pf = pf;
4991 /* record the sw_id available for later use */
4992 pf->first_sw->sw_id = pf->hw.port_info->sw_id;
4994 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
4996 goto err_aq_set_port_params;
4998 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
5001 goto err_pf_vsi_setup;
5007 err_aq_set_port_params:
5008 kfree(pf->first_sw);
5012 static void ice_deinit_pf_sw(struct ice_pf *pf)
5014 struct ice_vsi *vsi = ice_get_main_vsi(pf);
5019 ice_vsi_release(vsi);
5020 kfree(pf->first_sw);
5023 static int ice_alloc_vsis(struct ice_pf *pf)
5025 struct device *dev = ice_pf_to_dev(pf);
5027 pf->num_alloc_vsi = pf->hw.func_caps.guar_num_vsi;
5028 if (!pf->num_alloc_vsi)
5031 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
5033 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
5034 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
5035 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
5038 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
5043 pf->vsi_stats = devm_kcalloc(dev, pf->num_alloc_vsi,
5044 sizeof(*pf->vsi_stats), GFP_KERNEL);
5045 if (!pf->vsi_stats) {
5046 devm_kfree(dev, pf->vsi);
5053 static void ice_dealloc_vsis(struct ice_pf *pf)
5055 devm_kfree(ice_pf_to_dev(pf), pf->vsi_stats);
5056 pf->vsi_stats = NULL;
5058 pf->num_alloc_vsi = 0;
5059 devm_kfree(ice_pf_to_dev(pf), pf->vsi);
5063 static int ice_init_devlink(struct ice_pf *pf)
5067 err = ice_devlink_register_params(pf);
5071 ice_devlink_init_regions(pf);
5072 ice_devlink_register(pf);
5077 static void ice_deinit_devlink(struct ice_pf *pf)
5079 ice_devlink_unregister(pf);
5080 ice_devlink_destroy_regions(pf);
5081 ice_devlink_unregister_params(pf);
5084 static int ice_init(struct ice_pf *pf)
5088 err = ice_init_dev(pf);
5092 err = ice_alloc_vsis(pf);
5094 goto err_alloc_vsis;
5096 err = ice_init_pf_sw(pf);
5098 goto err_init_pf_sw;
5100 ice_init_wakeup(pf);
5102 err = ice_init_link(pf);
5106 err = ice_send_version(pf);
5110 ice_verify_cacheline_size(pf);
5112 if (ice_is_safe_mode(pf))
5113 ice_set_safe_mode_vlan_cfg(pf);
5115 /* print PCI link speed and width */
5116 pcie_print_link_status(pf->pdev);
5118 /* ready to go, so clear down state bit */
5119 clear_bit(ICE_DOWN, pf->state);
5120 clear_bit(ICE_SERVICE_DIS, pf->state);
5122 /* since everything is good, start the service timer */
5123 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5128 ice_deinit_pf_sw(pf);
5130 ice_dealloc_vsis(pf);
5136 static void ice_deinit(struct ice_pf *pf)
5138 set_bit(ICE_SERVICE_DIS, pf->state);
5139 set_bit(ICE_DOWN, pf->state);
5141 ice_deinit_pf_sw(pf);
5142 ice_dealloc_vsis(pf);
5147 * ice_load - load pf by init hw and starting VSI
5148 * @pf: pointer to the pf instance
5150 * This function has to be called under devl_lock.
5152 int ice_load(struct ice_pf *pf)
5154 struct ice_vsi *vsi;
5157 devl_assert_locked(priv_to_devlink(pf));
5159 vsi = ice_get_main_vsi(pf);
5161 /* init channel list */
5162 INIT_LIST_HEAD(&vsi->ch_list);
5164 err = ice_cfg_netdev(vsi);
5168 /* Setup DCB netlink interface */
5169 ice_dcbnl_setup(vsi);
5171 err = ice_init_mac_fltr(pf);
5173 goto err_init_mac_fltr;
5175 err = ice_devlink_create_pf_port(pf);
5177 goto err_devlink_create_pf_port;
5179 SET_NETDEV_DEVLINK_PORT(vsi->netdev, &pf->devlink_port);
5181 err = ice_register_netdev(vsi);
5183 goto err_register_netdev;
5185 err = ice_tc_indir_block_register(vsi);
5187 goto err_tc_indir_block_register;
5191 err = ice_init_rdma(pf);
5195 ice_init_features(pf);
5196 ice_service_task_restart(pf);
5198 clear_bit(ICE_DOWN, pf->state);
5203 ice_tc_indir_block_unregister(vsi);
5204 err_tc_indir_block_register:
5205 ice_unregister_netdev(vsi);
5206 err_register_netdev:
5207 ice_devlink_destroy_pf_port(pf);
5208 err_devlink_create_pf_port:
5210 ice_decfg_netdev(vsi);
5215 * ice_unload - unload pf by stopping VSI and deinit hw
5216 * @pf: pointer to the pf instance
5218 * This function has to be called under devl_lock.
5220 void ice_unload(struct ice_pf *pf)
5222 struct ice_vsi *vsi = ice_get_main_vsi(pf);
5224 devl_assert_locked(priv_to_devlink(pf));
5226 ice_deinit_features(pf);
5227 ice_deinit_rdma(pf);
5228 ice_tc_indir_block_unregister(vsi);
5229 ice_unregister_netdev(vsi);
5230 ice_devlink_destroy_pf_port(pf);
5231 ice_decfg_netdev(vsi);
5235 * ice_probe - Device initialization routine
5236 * @pdev: PCI device information struct
5237 * @ent: entry in ice_pci_tbl
5239 * Returns 0 on success, negative on failure
5242 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
5244 struct device *dev = &pdev->dev;
5245 struct ice_adapter *adapter;
5250 if (pdev->is_virtfn) {
5251 dev_err(dev, "can't probe a virtual function\n");
5255 /* when under a kdump kernel initiate a reset before enabling the
5256 * device in order to clear out any pending DMA transactions. These
5257 * transactions can cause some systems to machine check when doing
5258 * the pcim_enable_device() below.
5260 if (is_kdump_kernel()) {
5261 pci_save_state(pdev);
5262 pci_clear_master(pdev);
5263 err = pcie_flr(pdev);
5266 pci_restore_state(pdev);
5269 /* this driver uses devres, see
5270 * Documentation/driver-api/driver-model/devres.rst
5272 err = pcim_enable_device(pdev);
5276 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev));
5278 dev_err(dev, "BAR0 I/O map error %d\n", err);
5282 pf = ice_allocate_pf(dev);
5286 /* initialize Auxiliary index to invalid value */
5289 /* set up for high or low DMA */
5290 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
5292 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
5296 pci_set_master(pdev);
5298 adapter = ice_adapter_get(pdev);
5299 if (IS_ERR(adapter))
5300 return PTR_ERR(adapter);
5303 pf->adapter = adapter;
5304 pci_set_drvdata(pdev, pf);
5305 set_bit(ICE_DOWN, pf->state);
5306 /* Disable service task until DOWN bit is cleared */
5307 set_bit(ICE_SERVICE_DIS, pf->state);
5310 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
5311 pci_save_state(pdev);
5314 hw->port_info = NULL;
5315 hw->vendor_id = pdev->vendor;
5316 hw->device_id = pdev->device;
5317 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
5318 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5319 hw->subsystem_device_id = pdev->subsystem_device;
5320 hw->bus.device = PCI_SLOT(pdev->devfn);
5321 hw->bus.func = PCI_FUNC(pdev->devfn);
5322 ice_set_ctrlq_len(hw);
5324 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
5326 #ifndef CONFIG_DYNAMIC_DEBUG
5328 hw->debug_mask = debug;
5335 devl_lock(priv_to_devlink(pf));
5340 err = ice_init_devlink(pf);
5342 goto err_init_devlink;
5343 devl_unlock(priv_to_devlink(pf));
5350 devl_unlock(priv_to_devlink(pf));
5353 ice_adapter_put(pdev);
5358 * ice_set_wake - enable or disable Wake on LAN
5359 * @pf: pointer to the PF struct
5361 * Simple helper for WoL control
5363 static void ice_set_wake(struct ice_pf *pf)
5365 struct ice_hw *hw = &pf->hw;
5366 bool wol = pf->wol_ena;
5368 /* clear wake state, otherwise new wake events won't fire */
5369 wr32(hw, PFPM_WUS, U32_MAX);
5371 /* enable / disable APM wake up, no RMW needed */
5372 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0);
5374 /* set magic packet filter enabled */
5375 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0);
5379 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet
5380 * @pf: pointer to the PF struct
5382 * Issue firmware command to enable multicast magic wake, making
5383 * sure that any locally administered address (LAA) is used for
5384 * wake, and that PF reset doesn't undo the LAA.
5386 static void ice_setup_mc_magic_wake(struct ice_pf *pf)
5388 struct device *dev = ice_pf_to_dev(pf);
5389 struct ice_hw *hw = &pf->hw;
5390 u8 mac_addr[ETH_ALEN];
5391 struct ice_vsi *vsi;
5398 vsi = ice_get_main_vsi(pf);
5402 /* Get current MAC address in case it's an LAA */
5404 ether_addr_copy(mac_addr, vsi->netdev->dev_addr);
5406 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
5408 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN |
5409 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL |
5410 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP;
5412 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL);
5414 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %d aq_err %s\n",
5415 status, ice_aq_str(hw->adminq.sq_last_status));
5419 * ice_remove - Device removal routine
5420 * @pdev: PCI device information struct
5422 static void ice_remove(struct pci_dev *pdev)
5424 struct ice_pf *pf = pci_get_drvdata(pdev);
5427 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
5428 if (!ice_is_reset_in_progress(pf->state))
5433 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
5434 set_bit(ICE_VF_RESETS_DISABLED, pf->state);
5440 ice_service_task_stop(pf);
5441 ice_aq_cancel_waiting_tasks(pf);
5442 set_bit(ICE_DOWN, pf->state);
5444 if (!ice_is_safe_mode(pf))
5445 ice_remove_arfs(pf);
5447 devl_lock(priv_to_devlink(pf));
5448 ice_dealloc_all_dynamic_ports(pf);
5449 ice_deinit_devlink(pf);
5452 devl_unlock(priv_to_devlink(pf));
5455 ice_vsi_release_all(pf);
5457 ice_setup_mc_magic_wake(pf);
5460 ice_adapter_put(pdev);
5464 * ice_shutdown - PCI callback for shutting down device
5465 * @pdev: PCI device information struct
5467 static void ice_shutdown(struct pci_dev *pdev)
5469 struct ice_pf *pf = pci_get_drvdata(pdev);
5473 if (system_state == SYSTEM_POWER_OFF) {
5474 pci_wake_from_d3(pdev, pf->wol_ena);
5475 pci_set_power_state(pdev, PCI_D3hot);
5480 * ice_prepare_for_shutdown - prep for PCI shutdown
5481 * @pf: board private structure
5483 * Inform or close all dependent features in prep for PCI device shutdown
5485 static void ice_prepare_for_shutdown(struct ice_pf *pf)
5487 struct ice_hw *hw = &pf->hw;
5490 /* Notify VFs of impending reset */
5491 if (ice_check_sq_alive(hw, &hw->mailboxq))
5492 ice_vc_notify_reset(pf);
5494 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n");
5496 /* disable the VSIs and their queues that are not already DOWN */
5497 ice_pf_dis_all_vsi(pf, false);
5499 ice_for_each_vsi(pf, v)
5501 pf->vsi[v]->vsi_num = 0;
5503 ice_shutdown_all_ctrlq(hw, true);
5507 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme
5508 * @pf: board private structure to reinitialize
5510 * This routine reinitialize interrupt scheme that was cleared during
5511 * power management suspend callback.
5513 * This should be called during resume routine to re-allocate the q_vectors
5514 * and reacquire interrupts.
5516 static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
5518 struct device *dev = ice_pf_to_dev(pf);
5521 /* Since we clear MSIX flag during suspend, we need to
5522 * set it back during resume...
5525 ret = ice_init_interrupt_scheme(pf);
5527 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret);
5531 /* Remap vectors and rings, after successful re-init interrupts */
5532 ice_for_each_vsi(pf, v) {
5536 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]);
5539 ice_vsi_map_rings_to_vectors(pf->vsi[v]);
5541 ice_vsi_set_napi_queues(pf->vsi[v]);
5545 ret = ice_req_irq_msix_misc(pf);
5547 dev_err(dev, "Setting up misc vector failed after device suspend %d\n",
5558 ice_vsi_clear_napi_queues(pf->vsi[v]);
5560 ice_vsi_free_q_vectors(pf->vsi[v]);
5568 * @dev: generic device information structure
5570 * Power Management callback to quiesce the device and prepare
5571 * for D3 transition.
5573 static int ice_suspend(struct device *dev)
5575 struct pci_dev *pdev = to_pci_dev(dev);
5579 pf = pci_get_drvdata(pdev);
5581 if (!ice_pf_state_is_nominal(pf)) {
5582 dev_err(dev, "Device is not ready, no need to suspend it\n");
5586 /* Stop watchdog tasks until resume completion.
5587 * Even though it is most likely that the service task is
5588 * disabled if the device is suspended or down, the service task's
5589 * state is controlled by a different state bit, and we should
5590 * store and honor whatever state that bit is in at this point.
5592 disabled = ice_service_task_stop(pf);
5594 ice_deinit_rdma(pf);
5596 /* Already suspended?, then there is nothing to do */
5597 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) {
5599 ice_service_task_restart(pf);
5603 if (test_bit(ICE_DOWN, pf->state) ||
5604 ice_is_reset_in_progress(pf->state)) {
5605 dev_err(dev, "can't suspend device in reset or already down\n");
5607 ice_service_task_restart(pf);
5611 ice_setup_mc_magic_wake(pf);
5613 ice_prepare_for_shutdown(pf);
5617 /* Free vectors, clear the interrupt scheme and release IRQs
5618 * for proper hibernation, especially with large number of CPUs.
5619 * Otherwise hibernation might fail when mapping all the vectors back
5622 ice_free_irq_msix_misc(pf);
5623 ice_for_each_vsi(pf, v) {
5627 ice_vsi_clear_napi_queues(pf->vsi[v]);
5629 ice_vsi_free_q_vectors(pf->vsi[v]);
5631 ice_clear_interrupt_scheme(pf);
5633 pci_save_state(pdev);
5634 pci_wake_from_d3(pdev, pf->wol_ena);
5635 pci_set_power_state(pdev, PCI_D3hot);
5640 * ice_resume - PM callback for waking up from D3
5641 * @dev: generic device information structure
5643 static int ice_resume(struct device *dev)
5645 struct pci_dev *pdev = to_pci_dev(dev);
5646 enum ice_reset_req reset_type;
5651 pci_set_power_state(pdev, PCI_D0);
5652 pci_restore_state(pdev);
5653 pci_save_state(pdev);
5655 if (!pci_device_is_present(pdev))
5658 ret = pci_enable_device_mem(pdev);
5660 dev_err(dev, "Cannot enable device after suspend\n");
5664 pf = pci_get_drvdata(pdev);
5667 pf->wakeup_reason = rd32(hw, PFPM_WUS);
5668 ice_print_wake_reason(pf);
5670 /* We cleared the interrupt scheme when we suspended, so we need to
5671 * restore it now to resume device functionality.
5673 ret = ice_reinit_interrupt_scheme(pf);
5675 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret);
5677 ret = ice_init_rdma(pf);
5679 dev_err(dev, "Reinitialize RDMA during resume failed: %d\n",
5682 clear_bit(ICE_DOWN, pf->state);
5683 /* Now perform PF reset and rebuild */
5684 reset_type = ICE_RESET_PFR;
5685 /* re-enable service task for reset, but allow reset to schedule it */
5686 clear_bit(ICE_SERVICE_DIS, pf->state);
5688 if (ice_schedule_reset(pf, reset_type))
5689 dev_err(dev, "Reset during resume failed.\n");
5691 clear_bit(ICE_SUSPENDED, pf->state);
5692 ice_service_task_restart(pf);
5694 /* Restart the service task */
5695 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5701 * ice_pci_err_detected - warning that PCI error has been detected
5702 * @pdev: PCI device information struct
5703 * @err: the type of PCI error
5705 * Called to warn that something happened on the PCI bus and the error handling
5706 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
5708 static pci_ers_result_t
5709 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err)
5711 struct ice_pf *pf = pci_get_drvdata(pdev);
5714 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
5716 return PCI_ERS_RESULT_DISCONNECT;
5719 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5720 ice_service_task_stop(pf);
5722 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5723 set_bit(ICE_PFR_REQ, pf->state);
5724 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5728 return PCI_ERS_RESULT_NEED_RESET;
5732 * ice_pci_err_slot_reset - a PCI slot reset has just happened
5733 * @pdev: PCI device information struct
5735 * Called to determine if the driver can recover from the PCI slot reset by
5736 * using a register read to determine if the device is recoverable.
5738 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
5740 struct ice_pf *pf = pci_get_drvdata(pdev);
5741 pci_ers_result_t result;
5745 err = pci_enable_device_mem(pdev);
5747 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
5749 result = PCI_ERS_RESULT_DISCONNECT;
5751 pci_set_master(pdev);
5752 pci_restore_state(pdev);
5753 pci_save_state(pdev);
5754 pci_wake_from_d3(pdev, false);
5756 /* Check for life */
5757 reg = rd32(&pf->hw, GLGEN_RTRIG);
5759 result = PCI_ERS_RESULT_RECOVERED;
5761 result = PCI_ERS_RESULT_DISCONNECT;
5768 * ice_pci_err_resume - restart operations after PCI error recovery
5769 * @pdev: PCI device information struct
5771 * Called to allow the driver to bring things back up after PCI error and/or
5772 * reset recovery have finished
5774 static void ice_pci_err_resume(struct pci_dev *pdev)
5776 struct ice_pf *pf = pci_get_drvdata(pdev);
5779 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
5784 if (test_bit(ICE_SUSPENDED, pf->state)) {
5785 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
5790 ice_restore_all_vfs_msi_state(pf);
5792 ice_do_reset(pf, ICE_RESET_PFR);
5793 ice_service_task_restart(pf);
5794 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5798 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
5799 * @pdev: PCI device information struct
5801 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
5803 struct ice_pf *pf = pci_get_drvdata(pdev);
5805 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5806 ice_service_task_stop(pf);
5808 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5809 set_bit(ICE_PFR_REQ, pf->state);
5810 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5816 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
5817 * @pdev: PCI device information struct
5819 static void ice_pci_err_reset_done(struct pci_dev *pdev)
5821 ice_pci_err_resume(pdev);
5824 /* ice_pci_tbl - PCI Device ID Table
5826 * Wildcard entries (PCI_ANY_ID) should come last
5827 * Last entry must be all 0s
5829 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
5830 * Class, Class Mask, private data (not used) }
5832 static const struct pci_device_id ice_pci_tbl[] = {
5833 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE) },
5834 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP) },
5835 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP) },
5836 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_BACKPLANE) },
5837 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_QSFP) },
5838 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP) },
5839 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE) },
5840 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP) },
5841 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP) },
5842 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T) },
5843 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII) },
5844 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE) },
5845 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP) },
5846 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP) },
5847 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T) },
5848 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII) },
5849 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE) },
5850 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP) },
5851 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T) },
5852 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII) },
5853 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE) },
5854 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP) },
5855 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T) },
5856 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE) },
5857 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP) },
5858 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822_SI_DFLT) },
5859 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_BACKPLANE), },
5860 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_QSFP), },
5861 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_SFP), },
5862 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E825C_SGMII), },
5863 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_BACKPLANE) },
5864 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_QSFP56) },
5865 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_SFP) },
5866 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830CC_SFP_DD) },
5867 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_BACKPLANE), },
5868 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_BACKPLANE), },
5869 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_QSFP), },
5870 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_QSFP), },
5871 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830C_SFP), },
5872 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E830_XXV_SFP), },
5873 /* required last entry */
5876 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
5878 static DEFINE_SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume);
5880 static const struct pci_error_handlers ice_pci_err_handler = {
5881 .error_detected = ice_pci_err_detected,
5882 .slot_reset = ice_pci_err_slot_reset,
5883 .reset_prepare = ice_pci_err_reset_prepare,
5884 .reset_done = ice_pci_err_reset_done,
5885 .resume = ice_pci_err_resume
5888 static struct pci_driver ice_driver = {
5889 .name = KBUILD_MODNAME,
5890 .id_table = ice_pci_tbl,
5892 .remove = ice_remove,
5893 .driver.pm = pm_sleep_ptr(&ice_pm_ops),
5894 .shutdown = ice_shutdown,
5895 .sriov_configure = ice_sriov_configure,
5896 .sriov_get_vf_total_msix = ice_sriov_get_vf_total_msix,
5897 .sriov_set_msix_vec_count = ice_sriov_set_msix_vec_count,
5898 .err_handler = &ice_pci_err_handler
5902 * ice_module_init - Driver registration routine
5904 * ice_module_init is the first routine called when the driver is
5905 * loaded. All it does is register with the PCI subsystem.
5907 static int __init ice_module_init(void)
5909 int status = -ENOMEM;
5911 pr_info("%s\n", ice_driver_string);
5912 pr_info("%s\n", ice_copyright);
5914 ice_adv_lnk_speed_maps_init();
5916 ice_wq = alloc_workqueue("%s", 0, 0, KBUILD_MODNAME);
5918 pr_err("Failed to create workqueue\n");
5922 ice_lag_wq = alloc_ordered_workqueue("ice_lag_wq", 0);
5924 pr_err("Failed to create LAG workqueue\n");
5930 status = pci_register_driver(&ice_driver);
5932 pr_err("failed to register PCI driver, err %d\n", status);
5933 goto err_dest_lag_wq;
5936 status = ice_sf_driver_register();
5938 pr_err("Failed to register SF driver, err %d\n", status);
5945 pci_unregister_driver(&ice_driver);
5947 destroy_workqueue(ice_lag_wq);
5950 destroy_workqueue(ice_wq);
5953 module_init(ice_module_init);
5956 * ice_module_exit - Driver exit cleanup routine
5958 * ice_module_exit is called just before the driver is removed
5961 static void __exit ice_module_exit(void)
5963 ice_sf_driver_unregister();
5964 pci_unregister_driver(&ice_driver);
5966 destroy_workqueue(ice_wq);
5967 destroy_workqueue(ice_lag_wq);
5968 pr_info("module unloaded\n");
5970 module_exit(ice_module_exit);
5973 * ice_set_mac_address - NDO callback to set MAC address
5974 * @netdev: network interface device structure
5975 * @pi: pointer to an address structure
5977 * Returns 0 on success, negative on failure
5979 static int ice_set_mac_address(struct net_device *netdev, void *pi)
5981 struct ice_netdev_priv *np = netdev_priv(netdev);
5982 struct ice_vsi *vsi = np->vsi;
5983 struct ice_pf *pf = vsi->back;
5984 struct ice_hw *hw = &pf->hw;
5985 struct sockaddr *addr = pi;
5986 u8 old_mac[ETH_ALEN];
5991 mac = (u8 *)addr->sa_data;
5993 if (!is_valid_ether_addr(mac))
5994 return -EADDRNOTAVAIL;
5996 if (test_bit(ICE_DOWN, pf->state) ||
5997 ice_is_reset_in_progress(pf->state)) {
5998 netdev_err(netdev, "can't set mac %pM. device not ready\n",
6003 if (ice_chnl_dmac_fltr_cnt(pf)) {
6004 netdev_err(netdev, "can't set mac %pM. Device has tc-flower filters, delete all of them and try again\n",
6009 netif_addr_lock_bh(netdev);
6010 ether_addr_copy(old_mac, netdev->dev_addr);
6011 /* change the netdev's MAC address */
6012 eth_hw_addr_set(netdev, mac);
6013 netif_addr_unlock_bh(netdev);
6015 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
6016 err = ice_fltr_remove_mac(vsi, old_mac, ICE_FWD_TO_VSI);
6017 if (err && err != -ENOENT) {
6018 err = -EADDRNOTAVAIL;
6019 goto err_update_filters;
6022 /* Add filter for new MAC. If filter exists, return success */
6023 err = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
6024 if (err == -EEXIST) {
6025 /* Although this MAC filter is already present in hardware it's
6026 * possible in some cases (e.g. bonding) that dev_addr was
6027 * modified outside of the driver and needs to be restored back
6030 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
6034 /* error if the new filter addition failed */
6035 err = -EADDRNOTAVAIL;
6040 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
6042 netif_addr_lock_bh(netdev);
6043 eth_hw_addr_set(netdev, old_mac);
6044 netif_addr_unlock_bh(netdev);
6048 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
6051 /* write new MAC address to the firmware */
6052 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
6053 err = ice_aq_manage_mac_write(hw, mac, flags, NULL);
6055 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
6062 * ice_set_rx_mode - NDO callback to set the netdev filters
6063 * @netdev: network interface device structure
6065 static void ice_set_rx_mode(struct net_device *netdev)
6067 struct ice_netdev_priv *np = netdev_priv(netdev);
6068 struct ice_vsi *vsi = np->vsi;
6070 if (!vsi || ice_is_switchdev_running(vsi->back))
6073 /* Set the flags to synchronize filters
6074 * ndo_set_rx_mode may be triggered even without a change in netdev
6077 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
6078 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
6079 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
6081 /* schedule our worker thread which will take care of
6082 * applying the new filter changes
6084 ice_service_task_schedule(vsi->back);
6088 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
6089 * @netdev: network interface device structure
6090 * @queue_index: Queue ID
6091 * @maxrate: maximum bandwidth in Mbps
6094 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
6096 struct ice_netdev_priv *np = netdev_priv(netdev);
6097 struct ice_vsi *vsi = np->vsi;
6102 /* Validate maxrate requested is within permitted range */
6103 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
6104 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
6105 maxrate, queue_index);
6109 q_handle = vsi->tx_rings[queue_index]->q_handle;
6110 tc = ice_dcb_get_tc(vsi, queue_index);
6112 vsi = ice_locate_vsi_using_queue(vsi, queue_index);
6114 netdev_err(netdev, "Invalid VSI for given queue %d\n",
6119 /* Set BW back to default, when user set maxrate to 0 */
6121 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
6122 q_handle, ICE_MAX_BW);
6124 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
6125 q_handle, ICE_MAX_BW, maxrate * 1000);
6127 netdev_err(netdev, "Unable to set Tx max rate, error %d\n",
6134 * ice_fdb_add - add an entry to the hardware database
6135 * @ndm: the input from the stack
6136 * @tb: pointer to array of nladdr (unused)
6137 * @dev: the net device pointer
6138 * @addr: the MAC address entry being added
6140 * @flags: instructions from stack about fdb operation
6141 * @extack: netlink extended ack
6144 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
6145 struct net_device *dev, const unsigned char *addr, u16 vid,
6146 u16 flags, struct netlink_ext_ack __always_unused *extack)
6151 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
6154 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
6155 netdev_err(dev, "FDB only supports static addresses\n");
6159 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
6160 err = dev_uc_add_excl(dev, addr);
6161 else if (is_multicast_ether_addr(addr))
6162 err = dev_mc_add_excl(dev, addr);
6166 /* Only return duplicate errors if NLM_F_EXCL is set */
6167 if (err == -EEXIST && !(flags & NLM_F_EXCL))
6174 * ice_fdb_del - delete an entry from the hardware database
6175 * @ndm: the input from the stack
6176 * @tb: pointer to array of nladdr (unused)
6177 * @dev: the net device pointer
6178 * @addr: the MAC address entry being added
6180 * @extack: netlink extended ack
6183 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
6184 struct net_device *dev, const unsigned char *addr,
6185 __always_unused u16 vid, struct netlink_ext_ack *extack)
6189 if (ndm->ndm_state & NUD_PERMANENT) {
6190 netdev_err(dev, "FDB only supports static addresses\n");
6194 if (is_unicast_ether_addr(addr))
6195 err = dev_uc_del(dev, addr);
6196 else if (is_multicast_ether_addr(addr))
6197 err = dev_mc_del(dev, addr);
6204 #define NETIF_VLAN_OFFLOAD_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \
6205 NETIF_F_HW_VLAN_CTAG_TX | \
6206 NETIF_F_HW_VLAN_STAG_RX | \
6207 NETIF_F_HW_VLAN_STAG_TX)
6209 #define NETIF_VLAN_STRIPPING_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \
6210 NETIF_F_HW_VLAN_STAG_RX)
6212 #define NETIF_VLAN_FILTERING_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
6213 NETIF_F_HW_VLAN_STAG_FILTER)
6216 * ice_fix_features - fix the netdev features flags based on device limitations
6217 * @netdev: ptr to the netdev that flags are being fixed on
6218 * @features: features that need to be checked and possibly fixed
6220 * Make sure any fixups are made to features in this callback. This enables the
6221 * driver to not have to check unsupported configurations throughout the driver
6222 * because that's the responsiblity of this callback.
6224 * Single VLAN Mode (SVM) Supported Features:
6225 * NETIF_F_HW_VLAN_CTAG_FILTER
6226 * NETIF_F_HW_VLAN_CTAG_RX
6227 * NETIF_F_HW_VLAN_CTAG_TX
6229 * Double VLAN Mode (DVM) Supported Features:
6230 * NETIF_F_HW_VLAN_CTAG_FILTER
6231 * NETIF_F_HW_VLAN_CTAG_RX
6232 * NETIF_F_HW_VLAN_CTAG_TX
6234 * NETIF_F_HW_VLAN_STAG_FILTER
6235 * NETIF_HW_VLAN_STAG_RX
6236 * NETIF_HW_VLAN_STAG_TX
6238 * Features that need fixing:
6239 * Cannot simultaneously enable CTAG and STAG stripping and/or insertion.
6240 * These are mutually exlusive as the VSI context cannot support multiple
6241 * VLAN ethertypes simultaneously for stripping and/or insertion. If this
6242 * is not done, then default to clearing the requested STAG offload
6245 * All supported filtering has to be enabled or disabled together. For
6246 * example, in DVM, CTAG and STAG filtering have to be enabled and disabled
6247 * together. If this is not done, then default to VLAN filtering disabled.
6248 * These are mutually exclusive as there is currently no way to
6249 * enable/disable VLAN filtering based on VLAN ethertype when using VLAN
6252 static netdev_features_t
6253 ice_fix_features(struct net_device *netdev, netdev_features_t features)
6255 struct ice_netdev_priv *np = netdev_priv(netdev);
6256 netdev_features_t req_vlan_fltr, cur_vlan_fltr;
6257 bool cur_ctag, cur_stag, req_ctag, req_stag;
6259 cur_vlan_fltr = netdev->features & NETIF_VLAN_FILTERING_FEATURES;
6260 cur_ctag = cur_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER;
6261 cur_stag = cur_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER;
6263 req_vlan_fltr = features & NETIF_VLAN_FILTERING_FEATURES;
6264 req_ctag = req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER;
6265 req_stag = req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER;
6267 if (req_vlan_fltr != cur_vlan_fltr) {
6268 if (ice_is_dvm_ena(&np->vsi->back->hw)) {
6269 if (req_ctag && req_stag) {
6270 features |= NETIF_VLAN_FILTERING_FEATURES;
6271 } else if (!req_ctag && !req_stag) {
6272 features &= ~NETIF_VLAN_FILTERING_FEATURES;
6273 } else if ((!cur_ctag && req_ctag && !cur_stag) ||
6274 (!cur_stag && req_stag && !cur_ctag)) {
6275 features |= NETIF_VLAN_FILTERING_FEATURES;
6276 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been enabled for both types.\n");
6277 } else if ((cur_ctag && !req_ctag && cur_stag) ||
6278 (cur_stag && !req_stag && cur_ctag)) {
6279 features &= ~NETIF_VLAN_FILTERING_FEATURES;
6280 netdev_warn(netdev, "802.1Q and 802.1ad VLAN filtering must be either both on or both off. VLAN filtering has been disabled for both types.\n");
6283 if (req_vlan_fltr & NETIF_F_HW_VLAN_STAG_FILTER)
6284 netdev_warn(netdev, "cannot support requested 802.1ad filtering setting in SVM mode\n");
6286 if (req_vlan_fltr & NETIF_F_HW_VLAN_CTAG_FILTER)
6287 features |= NETIF_F_HW_VLAN_CTAG_FILTER;
6291 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) &&
6292 (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))) {
6293 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");
6294 features &= ~(NETIF_F_HW_VLAN_STAG_RX |
6295 NETIF_F_HW_VLAN_STAG_TX);
6298 if (!(netdev->features & NETIF_F_RXFCS) &&
6299 (features & NETIF_F_RXFCS) &&
6300 (features & NETIF_VLAN_STRIPPING_FEATURES) &&
6301 !ice_vsi_has_non_zero_vlans(np->vsi)) {
6302 netdev_warn(netdev, "Disabling VLAN stripping as FCS/CRC stripping is also disabled and there is no VLAN configured\n");
6303 features &= ~NETIF_VLAN_STRIPPING_FEATURES;
6310 * ice_set_rx_rings_vlan_proto - update rings with new stripped VLAN proto
6312 * @vlan_ethertype: VLAN ethertype (802.1Q or 802.1ad) in network byte order
6314 * Store current stripped VLAN proto in ring packet context,
6315 * so it can be accessed more efficiently by packet processing code.
6318 ice_set_rx_rings_vlan_proto(struct ice_vsi *vsi, __be16 vlan_ethertype)
6322 ice_for_each_alloc_rxq(vsi, i)
6323 vsi->rx_rings[i]->pkt_ctx.vlan_proto = vlan_ethertype;
6327 * ice_set_vlan_offload_features - set VLAN offload features for the PF VSI
6329 * @features: features used to determine VLAN offload settings
6331 * First, determine the vlan_ethertype based on the VLAN offload bits in
6332 * features. Then determine if stripping and insertion should be enabled or
6333 * disabled. Finally enable or disable VLAN stripping and insertion.
6336 ice_set_vlan_offload_features(struct ice_vsi *vsi, netdev_features_t features)
6338 bool enable_stripping = true, enable_insertion = true;
6339 struct ice_vsi_vlan_ops *vlan_ops;
6340 int strip_err = 0, insert_err = 0;
6341 u16 vlan_ethertype = 0;
6343 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
6345 if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
6346 vlan_ethertype = ETH_P_8021AD;
6347 else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
6348 vlan_ethertype = ETH_P_8021Q;
6350 if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
6351 enable_stripping = false;
6352 if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
6353 enable_insertion = false;
6355 if (enable_stripping)
6356 strip_err = vlan_ops->ena_stripping(vsi, vlan_ethertype);
6358 strip_err = vlan_ops->dis_stripping(vsi);
6360 if (enable_insertion)
6361 insert_err = vlan_ops->ena_insertion(vsi, vlan_ethertype);
6363 insert_err = vlan_ops->dis_insertion(vsi);
6365 if (strip_err || insert_err)
6368 ice_set_rx_rings_vlan_proto(vsi, enable_stripping ?
6369 htons(vlan_ethertype) : 0);
6375 * ice_set_vlan_filtering_features - set VLAN filtering features for the PF VSI
6377 * @features: features used to determine VLAN filtering settings
6379 * Enable or disable Rx VLAN filtering based on the VLAN filtering bits in the
6383 ice_set_vlan_filtering_features(struct ice_vsi *vsi, netdev_features_t features)
6385 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
6388 /* support Single VLAN Mode (SVM) and Double VLAN Mode (DVM) by checking
6389 * if either bit is set
6392 (NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER))
6393 err = vlan_ops->ena_rx_filtering(vsi);
6395 err = vlan_ops->dis_rx_filtering(vsi);
6401 * ice_set_vlan_features - set VLAN settings based on suggested feature set
6402 * @netdev: ptr to the netdev being adjusted
6403 * @features: the feature set that the stack is suggesting
6405 * Only update VLAN settings if the requested_vlan_features are different than
6406 * the current_vlan_features.
6409 ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
6411 netdev_features_t current_vlan_features, requested_vlan_features;
6412 struct ice_netdev_priv *np = netdev_priv(netdev);
6413 struct ice_vsi *vsi = np->vsi;
6416 current_vlan_features = netdev->features & NETIF_VLAN_OFFLOAD_FEATURES;
6417 requested_vlan_features = features & NETIF_VLAN_OFFLOAD_FEATURES;
6418 if (current_vlan_features ^ requested_vlan_features) {
6419 if ((features & NETIF_F_RXFCS) &&
6420 (features & NETIF_VLAN_STRIPPING_FEATURES)) {
6421 dev_err(ice_pf_to_dev(vsi->back),
6422 "To enable VLAN stripping, you must first enable FCS/CRC stripping\n");
6426 err = ice_set_vlan_offload_features(vsi, features);
6431 current_vlan_features = netdev->features &
6432 NETIF_VLAN_FILTERING_FEATURES;
6433 requested_vlan_features = features & NETIF_VLAN_FILTERING_FEATURES;
6434 if (current_vlan_features ^ requested_vlan_features) {
6435 err = ice_set_vlan_filtering_features(vsi, features);
6444 * ice_set_loopback - turn on/off loopback mode on underlying PF
6446 * @ena: flag to indicate the on/off setting
6448 static int ice_set_loopback(struct ice_vsi *vsi, bool ena)
6450 bool if_running = netif_running(vsi->netdev);
6453 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
6454 ret = ice_down(vsi);
6456 netdev_err(vsi->netdev, "Preparing device to toggle loopback failed\n");
6460 ret = ice_aq_set_mac_loopback(&vsi->back->hw, ena, NULL);
6462 netdev_err(vsi->netdev, "Failed to toggle loopback state\n");
6470 * ice_set_features - set the netdev feature flags
6471 * @netdev: ptr to the netdev being adjusted
6472 * @features: the feature set that the stack is suggesting
6475 ice_set_features(struct net_device *netdev, netdev_features_t features)
6477 netdev_features_t changed = netdev->features ^ features;
6478 struct ice_netdev_priv *np = netdev_priv(netdev);
6479 struct ice_vsi *vsi = np->vsi;
6480 struct ice_pf *pf = vsi->back;
6483 /* Don't set any netdev advanced features with device in Safe Mode */
6484 if (ice_is_safe_mode(pf)) {
6485 dev_err(ice_pf_to_dev(pf),
6486 "Device is in Safe Mode - not enabling advanced netdev features\n");
6490 /* Do not change setting during reset */
6491 if (ice_is_reset_in_progress(pf->state)) {
6492 dev_err(ice_pf_to_dev(pf),
6493 "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
6497 /* Multiple features can be changed in one call so keep features in
6498 * separate if/else statements to guarantee each feature is checked
6500 if (changed & NETIF_F_RXHASH)
6501 ice_vsi_manage_rss_lut(vsi, !!(features & NETIF_F_RXHASH));
6503 ret = ice_set_vlan_features(netdev, features);
6507 /* Turn on receive of FCS aka CRC, and after setting this
6508 * flag the packet data will have the 4 byte CRC appended
6510 if (changed & NETIF_F_RXFCS) {
6511 if ((features & NETIF_F_RXFCS) &&
6512 (features & NETIF_VLAN_STRIPPING_FEATURES)) {
6513 dev_err(ice_pf_to_dev(vsi->back),
6514 "To disable FCS/CRC stripping, you must first disable VLAN stripping\n");
6518 ice_vsi_cfg_crc_strip(vsi, !!(features & NETIF_F_RXFCS));
6519 ret = ice_down_up(vsi);
6524 if (changed & NETIF_F_NTUPLE) {
6525 bool ena = !!(features & NETIF_F_NTUPLE);
6527 ice_vsi_manage_fdir(vsi, ena);
6528 ena ? ice_init_arfs(vsi) : ice_clear_arfs(vsi);
6531 /* don't turn off hw_tc_offload when ADQ is already enabled */
6532 if (!(features & NETIF_F_HW_TC) && ice_is_adq_active(pf)) {
6533 dev_err(ice_pf_to_dev(pf), "ADQ is active, can't turn hw_tc_offload off\n");
6537 if (changed & NETIF_F_HW_TC) {
6538 bool ena = !!(features & NETIF_F_HW_TC);
6540 ena ? set_bit(ICE_FLAG_CLS_FLOWER, pf->flags) :
6541 clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
6544 if (changed & NETIF_F_LOOPBACK)
6545 ret = ice_set_loopback(vsi, !!(features & NETIF_F_LOOPBACK));
6551 * ice_vsi_vlan_setup - Setup VLAN offload properties on a PF VSI
6552 * @vsi: VSI to setup VLAN properties for
6554 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
6558 err = ice_set_vlan_offload_features(vsi, vsi->netdev->features);
6562 err = ice_set_vlan_filtering_features(vsi, vsi->netdev->features);
6566 return ice_vsi_add_vlan_zero(vsi);
6570 * ice_vsi_cfg_lan - Setup the VSI lan related config
6571 * @vsi: the VSI being configured
6573 * Return 0 on success and negative value on error
6575 int ice_vsi_cfg_lan(struct ice_vsi *vsi)
6579 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
6580 ice_set_rx_mode(vsi->netdev);
6582 err = ice_vsi_vlan_setup(vsi);
6586 ice_vsi_cfg_dcb_rings(vsi);
6588 err = ice_vsi_cfg_lan_txqs(vsi);
6589 if (!err && ice_is_xdp_ena_vsi(vsi))
6590 err = ice_vsi_cfg_xdp_txqs(vsi);
6592 err = ice_vsi_cfg_rxqs(vsi);
6597 /* THEORY OF MODERATION:
6598 * The ice driver hardware works differently than the hardware that DIMLIB was
6599 * originally made for. ice hardware doesn't have packet count limits that
6600 * can trigger an interrupt, but it *does* have interrupt rate limit support,
6601 * which is hard-coded to a limit of 250,000 ints/second.
6602 * If not using dynamic moderation, the INTRL value can be modified
6603 * by ethtool rx-usecs-high.
6606 /* the throttle rate for interrupts, basically worst case delay before
6607 * an initial interrupt fires, value is stored in microseconds.
6612 /* Make a different profile for Rx that doesn't allow quite so aggressive
6613 * moderation at the high end (it maxes out at 126us or about 8k interrupts a
6616 static const struct ice_dim rx_profile[] = {
6617 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6618 {8}, /* 125,000 ints/s */
6619 {16}, /* 62,500 ints/s */
6620 {62}, /* 16,129 ints/s */
6621 {126} /* 7,936 ints/s */
6624 /* The transmit profile, which has the same sorts of values
6625 * as the previous struct
6627 static const struct ice_dim tx_profile[] = {
6628 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
6629 {8}, /* 125,000 ints/s */
6630 {40}, /* 16,125 ints/s */
6631 {128}, /* 7,812 ints/s */
6632 {256} /* 3,906 ints/s */
6635 static void ice_tx_dim_work(struct work_struct *work)
6637 struct ice_ring_container *rc;
6641 dim = container_of(work, struct dim, work);
6644 WARN_ON(dim->profile_ix >= ARRAY_SIZE(tx_profile));
6646 /* look up the values in our local table */
6647 itr = tx_profile[dim->profile_ix].itr;
6649 ice_trace(tx_dim_work, container_of(rc, struct ice_q_vector, tx), dim);
6650 ice_write_itr(rc, itr);
6652 dim->state = DIM_START_MEASURE;
6655 static void ice_rx_dim_work(struct work_struct *work)
6657 struct ice_ring_container *rc;
6661 dim = container_of(work, struct dim, work);
6664 WARN_ON(dim->profile_ix >= ARRAY_SIZE(rx_profile));
6666 /* look up the values in our local table */
6667 itr = rx_profile[dim->profile_ix].itr;
6669 ice_trace(rx_dim_work, container_of(rc, struct ice_q_vector, rx), dim);
6670 ice_write_itr(rc, itr);
6672 dim->state = DIM_START_MEASURE;
6675 #define ICE_DIM_DEFAULT_PROFILE_IX 1
6678 * ice_init_moderation - set up interrupt moderation
6679 * @q_vector: the vector containing rings to be configured
6681 * Set up interrupt moderation registers, with the intent to do the right thing
6682 * when called from reset or from probe, and whether or not dynamic moderation
6683 * is enabled or not. Take special care to write all the registers in both
6684 * dynamic moderation mode or not in order to make sure hardware is in a known
6687 static void ice_init_moderation(struct ice_q_vector *q_vector)
6689 struct ice_ring_container *rc;
6690 bool tx_dynamic, rx_dynamic;
6693 INIT_WORK(&rc->dim.work, ice_tx_dim_work);
6694 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6695 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6697 tx_dynamic = ITR_IS_DYNAMIC(rc);
6699 /* set the initial TX ITR to match the above */
6700 ice_write_itr(rc, tx_dynamic ?
6701 tx_profile[rc->dim.profile_ix].itr : rc->itr_setting);
6704 INIT_WORK(&rc->dim.work, ice_rx_dim_work);
6705 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
6706 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6708 rx_dynamic = ITR_IS_DYNAMIC(rc);
6710 /* set the initial RX ITR to match the above */
6711 ice_write_itr(rc, rx_dynamic ? rx_profile[rc->dim.profile_ix].itr :
6714 ice_set_q_vector_intrl(q_vector);
6718 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
6719 * @vsi: the VSI being configured
6721 static void ice_napi_enable_all(struct ice_vsi *vsi)
6728 ice_for_each_q_vector(vsi, q_idx) {
6729 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6731 ice_init_moderation(q_vector);
6733 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6734 napi_enable(&q_vector->napi);
6739 * ice_up_complete - Finish the last steps of bringing up a connection
6740 * @vsi: The VSI being configured
6742 * Return 0 on success and negative value on error
6744 static int ice_up_complete(struct ice_vsi *vsi)
6746 struct ice_pf *pf = vsi->back;
6749 ice_vsi_cfg_msix(vsi);
6751 /* Enable only Rx rings, Tx rings were enabled by the FW when the
6752 * Tx queue group list was configured and the context bits were
6753 * programmed using ice_vsi_cfg_txqs
6755 err = ice_vsi_start_all_rx_rings(vsi);
6759 clear_bit(ICE_VSI_DOWN, vsi->state);
6760 ice_napi_enable_all(vsi);
6761 ice_vsi_ena_irq(vsi);
6763 if (vsi->port_info &&
6764 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
6765 ((vsi->netdev && (vsi->type == ICE_VSI_PF ||
6766 vsi->type == ICE_VSI_SF)))) {
6767 ice_print_link_msg(vsi, true);
6768 netif_tx_start_all_queues(vsi->netdev);
6769 netif_carrier_on(vsi->netdev);
6770 ice_ptp_link_change(pf, pf->hw.pf_id, true);
6773 /* Perform an initial read of the statistics registers now to
6774 * set the baseline so counters are ready when interface is up
6776 ice_update_eth_stats(vsi);
6778 if (vsi->type == ICE_VSI_PF)
6779 ice_service_task_schedule(pf);
6785 * ice_up - Bring the connection back up after being down
6786 * @vsi: VSI being configured
6788 int ice_up(struct ice_vsi *vsi)
6792 err = ice_vsi_cfg_lan(vsi);
6794 err = ice_up_complete(vsi);
6800 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
6801 * @syncp: pointer to u64_stats_sync
6802 * @stats: stats that pkts and bytes count will be taken from
6803 * @pkts: packets stats counter
6804 * @bytes: bytes stats counter
6806 * This function fetches stats from the ring considering the atomic operations
6807 * that needs to be performed to read u64 values in 32 bit machine.
6810 ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp,
6811 struct ice_q_stats stats, u64 *pkts, u64 *bytes)
6816 start = u64_stats_fetch_begin(syncp);
6818 *bytes = stats.bytes;
6819 } while (u64_stats_fetch_retry(syncp, start));
6823 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters
6824 * @vsi: the VSI to be updated
6825 * @vsi_stats: the stats struct to be updated
6826 * @rings: rings to work on
6827 * @count: number of rings
6830 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
6831 struct rtnl_link_stats64 *vsi_stats,
6832 struct ice_tx_ring **rings, u16 count)
6836 for (i = 0; i < count; i++) {
6837 struct ice_tx_ring *ring;
6838 u64 pkts = 0, bytes = 0;
6840 ring = READ_ONCE(rings[i]);
6841 if (!ring || !ring->ring_stats)
6843 ice_fetch_u64_stats_per_ring(&ring->ring_stats->syncp,
6844 ring->ring_stats->stats, &pkts,
6846 vsi_stats->tx_packets += pkts;
6847 vsi_stats->tx_bytes += bytes;
6848 vsi->tx_restart += ring->ring_stats->tx_stats.restart_q;
6849 vsi->tx_busy += ring->ring_stats->tx_stats.tx_busy;
6850 vsi->tx_linearize += ring->ring_stats->tx_stats.tx_linearize;
6855 * ice_update_vsi_ring_stats - Update VSI stats counters
6856 * @vsi: the VSI to be updated
6858 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
6860 struct rtnl_link_stats64 *net_stats, *stats_prev;
6861 struct rtnl_link_stats64 *vsi_stats;
6862 struct ice_pf *pf = vsi->back;
6866 vsi_stats = kzalloc(sizeof(*vsi_stats), GFP_ATOMIC);
6870 /* reset non-netdev (extended) stats */
6871 vsi->tx_restart = 0;
6873 vsi->tx_linearize = 0;
6874 vsi->rx_buf_failed = 0;
6875 vsi->rx_page_failed = 0;
6879 /* update Tx rings counters */
6880 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->tx_rings,
6883 /* update Rx rings counters */
6884 ice_for_each_rxq(vsi, i) {
6885 struct ice_rx_ring *ring = READ_ONCE(vsi->rx_rings[i]);
6886 struct ice_ring_stats *ring_stats;
6888 ring_stats = ring->ring_stats;
6889 ice_fetch_u64_stats_per_ring(&ring_stats->syncp,
6890 ring_stats->stats, &pkts,
6892 vsi_stats->rx_packets += pkts;
6893 vsi_stats->rx_bytes += bytes;
6894 vsi->rx_buf_failed += ring_stats->rx_stats.alloc_buf_failed;
6895 vsi->rx_page_failed += ring_stats->rx_stats.alloc_page_failed;
6898 /* update XDP Tx rings counters */
6899 if (ice_is_xdp_ena_vsi(vsi))
6900 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->xdp_rings,
6905 net_stats = &vsi->net_stats;
6906 stats_prev = &vsi->net_stats_prev;
6908 /* Update netdev counters, but keep in mind that values could start at
6909 * random value after PF reset. And as we increase the reported stat by
6910 * diff of Prev-Cur, we need to be sure that Prev is valid. If it's not,
6911 * let's skip this round.
6913 if (likely(pf->stat_prev_loaded)) {
6914 net_stats->tx_packets += vsi_stats->tx_packets - stats_prev->tx_packets;
6915 net_stats->tx_bytes += vsi_stats->tx_bytes - stats_prev->tx_bytes;
6916 net_stats->rx_packets += vsi_stats->rx_packets - stats_prev->rx_packets;
6917 net_stats->rx_bytes += vsi_stats->rx_bytes - stats_prev->rx_bytes;
6920 stats_prev->tx_packets = vsi_stats->tx_packets;
6921 stats_prev->tx_bytes = vsi_stats->tx_bytes;
6922 stats_prev->rx_packets = vsi_stats->rx_packets;
6923 stats_prev->rx_bytes = vsi_stats->rx_bytes;
6929 * ice_update_vsi_stats - Update VSI stats counters
6930 * @vsi: the VSI to be updated
6932 void ice_update_vsi_stats(struct ice_vsi *vsi)
6934 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
6935 struct ice_eth_stats *cur_es = &vsi->eth_stats;
6936 struct ice_pf *pf = vsi->back;
6938 if (test_bit(ICE_VSI_DOWN, vsi->state) ||
6939 test_bit(ICE_CFG_BUSY, pf->state))
6942 /* get stats as recorded by Tx/Rx rings */
6943 ice_update_vsi_ring_stats(vsi);
6945 /* get VSI stats as recorded by the hardware */
6946 ice_update_eth_stats(vsi);
6948 cur_ns->tx_errors = cur_es->tx_errors;
6949 cur_ns->rx_dropped = cur_es->rx_discards;
6950 cur_ns->tx_dropped = cur_es->tx_discards;
6951 cur_ns->multicast = cur_es->rx_multicast;
6953 /* update some more netdev stats if this is main VSI */
6954 if (vsi->type == ICE_VSI_PF) {
6955 cur_ns->rx_crc_errors = pf->stats.crc_errors;
6956 cur_ns->rx_errors = pf->stats.crc_errors +
6957 pf->stats.illegal_bytes +
6958 pf->stats.rx_undersize +
6959 pf->hw_csum_rx_error +
6960 pf->stats.rx_jabber +
6961 pf->stats.rx_fragments +
6962 pf->stats.rx_oversize;
6963 /* record drops from the port level */
6964 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
6969 * ice_update_pf_stats - Update PF port stats counters
6970 * @pf: PF whose stats needs to be updated
6972 void ice_update_pf_stats(struct ice_pf *pf)
6974 struct ice_hw_port_stats *prev_ps, *cur_ps;
6975 struct ice_hw *hw = &pf->hw;
6979 port = hw->port_info->lport;
6980 prev_ps = &pf->stats_prev;
6981 cur_ps = &pf->stats;
6983 if (ice_is_reset_in_progress(pf->state))
6984 pf->stat_prev_loaded = false;
6986 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
6987 &prev_ps->eth.rx_bytes,
6988 &cur_ps->eth.rx_bytes);
6990 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
6991 &prev_ps->eth.rx_unicast,
6992 &cur_ps->eth.rx_unicast);
6994 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
6995 &prev_ps->eth.rx_multicast,
6996 &cur_ps->eth.rx_multicast);
6998 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
6999 &prev_ps->eth.rx_broadcast,
7000 &cur_ps->eth.rx_broadcast);
7002 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
7003 &prev_ps->eth.rx_discards,
7004 &cur_ps->eth.rx_discards);
7006 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
7007 &prev_ps->eth.tx_bytes,
7008 &cur_ps->eth.tx_bytes);
7010 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
7011 &prev_ps->eth.tx_unicast,
7012 &cur_ps->eth.tx_unicast);
7014 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
7015 &prev_ps->eth.tx_multicast,
7016 &cur_ps->eth.tx_multicast);
7018 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
7019 &prev_ps->eth.tx_broadcast,
7020 &cur_ps->eth.tx_broadcast);
7022 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
7023 &prev_ps->tx_dropped_link_down,
7024 &cur_ps->tx_dropped_link_down);
7026 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
7027 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
7029 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
7030 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
7032 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
7033 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
7035 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
7036 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
7038 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
7039 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
7041 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
7042 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
7044 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
7045 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
7047 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
7048 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
7050 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
7051 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
7053 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
7054 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
7056 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
7057 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
7059 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
7060 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
7062 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
7063 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
7065 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
7066 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
7068 fd_ctr_base = hw->fd_ctr_base;
7070 ice_stat_update40(hw,
7071 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
7072 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
7073 &cur_ps->fd_sb_match);
7074 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
7075 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
7077 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
7078 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
7080 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
7081 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
7083 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
7084 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
7086 ice_update_dcb_stats(pf);
7088 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
7089 &prev_ps->crc_errors, &cur_ps->crc_errors);
7091 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
7092 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
7094 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
7095 &prev_ps->mac_local_faults,
7096 &cur_ps->mac_local_faults);
7098 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
7099 &prev_ps->mac_remote_faults,
7100 &cur_ps->mac_remote_faults);
7102 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
7103 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
7105 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
7106 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
7108 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
7109 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
7111 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
7112 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
7114 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
7116 pf->stat_prev_loaded = true;
7120 * ice_get_stats64 - get statistics for network device structure
7121 * @netdev: network interface device structure
7122 * @stats: main device statistics structure
7124 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
7126 struct ice_netdev_priv *np = netdev_priv(netdev);
7127 struct rtnl_link_stats64 *vsi_stats;
7128 struct ice_vsi *vsi = np->vsi;
7130 vsi_stats = &vsi->net_stats;
7132 if (!vsi->num_txq || !vsi->num_rxq)
7135 /* netdev packet/byte stats come from ring counter. These are obtained
7136 * by summing up ring counters (done by ice_update_vsi_ring_stats).
7137 * But, only call the update routine and read the registers if VSI is
7140 if (!test_bit(ICE_VSI_DOWN, vsi->state))
7141 ice_update_vsi_ring_stats(vsi);
7142 stats->tx_packets = vsi_stats->tx_packets;
7143 stats->tx_bytes = vsi_stats->tx_bytes;
7144 stats->rx_packets = vsi_stats->rx_packets;
7145 stats->rx_bytes = vsi_stats->rx_bytes;
7147 /* The rest of the stats can be read from the hardware but instead we
7148 * just return values that the watchdog task has already obtained from
7151 stats->multicast = vsi_stats->multicast;
7152 stats->tx_errors = vsi_stats->tx_errors;
7153 stats->tx_dropped = vsi_stats->tx_dropped;
7154 stats->rx_errors = vsi_stats->rx_errors;
7155 stats->rx_dropped = vsi_stats->rx_dropped;
7156 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
7157 stats->rx_length_errors = vsi_stats->rx_length_errors;
7161 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
7162 * @vsi: VSI having NAPI disabled
7164 static void ice_napi_disable_all(struct ice_vsi *vsi)
7171 ice_for_each_q_vector(vsi, q_idx) {
7172 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
7174 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
7175 napi_disable(&q_vector->napi);
7177 cancel_work_sync(&q_vector->tx.dim.work);
7178 cancel_work_sync(&q_vector->rx.dim.work);
7183 * ice_vsi_dis_irq - Mask off queue interrupt generation on the VSI
7184 * @vsi: the VSI being un-configured
7186 static void ice_vsi_dis_irq(struct ice_vsi *vsi)
7188 struct ice_pf *pf = vsi->back;
7189 struct ice_hw *hw = &pf->hw;
7193 /* disable interrupt causation from each Rx queue; Tx queues are
7194 * handled in ice_vsi_stop_tx_ring()
7196 if (vsi->rx_rings) {
7197 ice_for_each_rxq(vsi, i) {
7198 if (vsi->rx_rings[i]) {
7201 reg = vsi->rx_rings[i]->reg_idx;
7202 val = rd32(hw, QINT_RQCTL(reg));
7203 val &= ~QINT_RQCTL_CAUSE_ENA_M;
7204 wr32(hw, QINT_RQCTL(reg), val);
7209 /* disable each interrupt */
7210 ice_for_each_q_vector(vsi, i) {
7211 if (!vsi->q_vectors[i])
7213 wr32(hw, GLINT_DYN_CTL(vsi->q_vectors[i]->reg_idx), 0);
7218 /* don't call synchronize_irq() for VF's from the host */
7219 if (vsi->type == ICE_VSI_VF)
7222 ice_for_each_q_vector(vsi, i)
7223 synchronize_irq(vsi->q_vectors[i]->irq.virq);
7227 * ice_down - Shutdown the connection
7228 * @vsi: The VSI being stopped
7230 * Caller of this function is expected to set the vsi->state ICE_DOWN bit
7232 int ice_down(struct ice_vsi *vsi)
7234 int i, tx_err, rx_err, vlan_err = 0;
7236 WARN_ON(!test_bit(ICE_VSI_DOWN, vsi->state));
7239 vlan_err = ice_vsi_del_vlan_zero(vsi);
7240 ice_ptp_link_change(vsi->back, vsi->back->hw.pf_id, false);
7241 netif_carrier_off(vsi->netdev);
7242 netif_tx_disable(vsi->netdev);
7245 ice_vsi_dis_irq(vsi);
7247 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
7249 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
7250 vsi->vsi_num, tx_err);
7251 if (!tx_err && vsi->xdp_rings) {
7252 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
7254 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
7255 vsi->vsi_num, tx_err);
7258 rx_err = ice_vsi_stop_all_rx_rings(vsi);
7260 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
7261 vsi->vsi_num, rx_err);
7263 ice_napi_disable_all(vsi);
7265 ice_for_each_txq(vsi, i)
7266 ice_clean_tx_ring(vsi->tx_rings[i]);
7269 ice_for_each_xdp_txq(vsi, i)
7270 ice_clean_tx_ring(vsi->xdp_rings[i]);
7272 ice_for_each_rxq(vsi, i)
7273 ice_clean_rx_ring(vsi->rx_rings[i]);
7275 if (tx_err || rx_err || vlan_err) {
7276 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
7277 vsi->vsi_num, vsi->vsw->sw_id);
7285 * ice_down_up - shutdown the VSI connection and bring it up
7286 * @vsi: the VSI to be reconnected
7288 int ice_down_up(struct ice_vsi *vsi)
7292 /* if DOWN already set, nothing to do */
7293 if (test_and_set_bit(ICE_VSI_DOWN, vsi->state))
7296 ret = ice_down(vsi);
7302 netdev_err(vsi->netdev, "reallocating resources failed during netdev features change, may need to reload driver\n");
7310 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
7311 * @vsi: VSI having resources allocated
7313 * Return 0 on success, negative on failure
7315 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
7319 if (!vsi->num_txq) {
7320 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
7325 ice_for_each_txq(vsi, i) {
7326 struct ice_tx_ring *ring = vsi->tx_rings[i];
7332 ring->netdev = vsi->netdev;
7333 err = ice_setup_tx_ring(ring);
7342 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
7343 * @vsi: VSI having resources allocated
7345 * Return 0 on success, negative on failure
7347 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
7351 if (!vsi->num_rxq) {
7352 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
7357 ice_for_each_rxq(vsi, i) {
7358 struct ice_rx_ring *ring = vsi->rx_rings[i];
7364 ring->netdev = vsi->netdev;
7365 err = ice_setup_rx_ring(ring);
7374 * ice_vsi_open_ctrl - open control VSI for use
7375 * @vsi: the VSI to open
7377 * Initialization of the Control VSI
7379 * Returns 0 on success, negative value on error
7381 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
7383 char int_name[ICE_INT_NAME_STR_LEN];
7384 struct ice_pf *pf = vsi->back;
7388 dev = ice_pf_to_dev(pf);
7389 /* allocate descriptors */
7390 err = ice_vsi_setup_tx_rings(vsi);
7394 err = ice_vsi_setup_rx_rings(vsi);
7398 err = ice_vsi_cfg_lan(vsi);
7402 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
7403 dev_driver_string(dev), dev_name(dev));
7404 err = ice_vsi_req_irq_msix(vsi, int_name);
7408 ice_vsi_cfg_msix(vsi);
7410 err = ice_vsi_start_all_rx_rings(vsi);
7412 goto err_up_complete;
7414 clear_bit(ICE_VSI_DOWN, vsi->state);
7415 ice_vsi_ena_irq(vsi);
7422 ice_vsi_free_rx_rings(vsi);
7424 ice_vsi_free_tx_rings(vsi);
7430 * ice_vsi_open - Called when a network interface is made active
7431 * @vsi: the VSI to open
7433 * Initialization of the VSI
7435 * Returns 0 on success, negative value on error
7437 int ice_vsi_open(struct ice_vsi *vsi)
7439 char int_name[ICE_INT_NAME_STR_LEN];
7440 struct ice_pf *pf = vsi->back;
7443 /* allocate descriptors */
7444 err = ice_vsi_setup_tx_rings(vsi);
7448 err = ice_vsi_setup_rx_rings(vsi);
7452 err = ice_vsi_cfg_lan(vsi);
7456 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
7457 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
7458 err = ice_vsi_req_irq_msix(vsi, int_name);
7462 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
7464 if (vsi->type == ICE_VSI_PF || vsi->type == ICE_VSI_SF) {
7465 /* Notify the stack of the actual queue counts. */
7466 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
7470 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
7474 ice_vsi_set_napi_queues(vsi);
7477 err = ice_up_complete(vsi);
7479 goto err_up_complete;
7486 ice_vsi_free_irq(vsi);
7488 ice_vsi_free_rx_rings(vsi);
7490 ice_vsi_free_tx_rings(vsi);
7496 * ice_vsi_release_all - Delete all VSIs
7497 * @pf: PF from which all VSIs are being removed
7499 static void ice_vsi_release_all(struct ice_pf *pf)
7506 ice_for_each_vsi(pf, i) {
7510 if (pf->vsi[i]->type == ICE_VSI_CHNL)
7513 err = ice_vsi_release(pf->vsi[i]);
7515 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
7516 i, err, pf->vsi[i]->vsi_num);
7521 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
7522 * @pf: pointer to the PF instance
7523 * @type: VSI type to rebuild
7525 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
7527 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
7529 struct device *dev = ice_pf_to_dev(pf);
7532 ice_for_each_vsi(pf, i) {
7533 struct ice_vsi *vsi = pf->vsi[i];
7535 if (!vsi || vsi->type != type)
7538 /* rebuild the VSI */
7539 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT);
7541 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
7542 err, vsi->idx, ice_vsi_type_str(type));
7546 /* replay filters for the VSI */
7547 err = ice_replay_vsi(&pf->hw, vsi->idx);
7549 dev_err(dev, "replay VSI failed, error %d, VSI index %d, type %s\n",
7550 err, vsi->idx, ice_vsi_type_str(type));
7554 /* Re-map HW VSI number, using VSI handle that has been
7555 * previously validated in ice_replay_vsi() call above
7557 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
7559 /* enable the VSI */
7560 err = ice_ena_vsi(vsi, false);
7562 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
7563 err, vsi->idx, ice_vsi_type_str(type));
7567 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
7568 ice_vsi_type_str(type));
7575 * ice_update_pf_netdev_link - Update PF netdev link status
7576 * @pf: pointer to the PF instance
7578 static void ice_update_pf_netdev_link(struct ice_pf *pf)
7583 ice_for_each_vsi(pf, i) {
7584 struct ice_vsi *vsi = pf->vsi[i];
7586 if (!vsi || vsi->type != ICE_VSI_PF)
7589 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
7591 netif_carrier_on(pf->vsi[i]->netdev);
7592 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
7594 netif_carrier_off(pf->vsi[i]->netdev);
7595 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
7601 * ice_rebuild - rebuild after reset
7602 * @pf: PF to rebuild
7603 * @reset_type: type of reset
7605 * Do not rebuild VF VSI in this flow because that is already handled via
7606 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a
7607 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
7608 * to reset/rebuild all the VF VSI twice.
7610 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
7612 struct ice_vsi *vsi = ice_get_main_vsi(pf);
7613 struct device *dev = ice_pf_to_dev(pf);
7614 struct ice_hw *hw = &pf->hw;
7618 if (test_bit(ICE_DOWN, pf->state))
7619 goto clear_recovery;
7621 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
7623 #define ICE_EMP_RESET_SLEEP_MS 5000
7624 if (reset_type == ICE_RESET_EMPR) {
7625 /* If an EMP reset has occurred, any previously pending flash
7626 * update will have completed. We no longer know whether or
7627 * not the NVM update EMP reset is restricted.
7629 pf->fw_emp_reset_disabled = false;
7631 msleep(ICE_EMP_RESET_SLEEP_MS);
7634 err = ice_init_all_ctrlq(hw);
7636 dev_err(dev, "control queues init failed %d\n", err);
7637 goto err_init_ctrlq;
7640 /* if DDP was previously loaded successfully */
7641 if (!ice_is_safe_mode(pf)) {
7642 /* reload the SW DB of filter tables */
7643 if (reset_type == ICE_RESET_PFR)
7644 ice_fill_blk_tbls(hw);
7646 /* Reload DDP Package after CORER/GLOBR reset */
7647 ice_load_pkg(NULL, pf);
7650 err = ice_clear_pf_cfg(hw);
7652 dev_err(dev, "clear PF configuration failed %d\n", err);
7653 goto err_init_ctrlq;
7656 ice_clear_pxe_mode(hw);
7658 err = ice_init_nvm(hw);
7660 dev_err(dev, "ice_init_nvm failed %d\n", err);
7661 goto err_init_ctrlq;
7664 err = ice_get_caps(hw);
7666 dev_err(dev, "ice_get_caps failed %d\n", err);
7667 goto err_init_ctrlq;
7670 err = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
7672 dev_err(dev, "set_mac_cfg failed %d\n", err);
7673 goto err_init_ctrlq;
7676 dvm = ice_is_dvm_ena(hw);
7678 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
7680 goto err_init_ctrlq;
7682 err = ice_sched_init_port(hw->port_info);
7684 goto err_sched_init_port;
7686 /* start misc vector */
7687 err = ice_req_irq_msix_misc(pf);
7689 dev_err(dev, "misc vector setup failed: %d\n", err);
7690 goto err_sched_init_port;
7693 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7694 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
7695 if (!rd32(hw, PFQF_FD_SIZE)) {
7696 u16 unused, guar, b_effort;
7698 guar = hw->func_caps.fd_fltr_guar;
7699 b_effort = hw->func_caps.fd_fltr_best_effort;
7701 /* force guaranteed filter pool for PF */
7702 ice_alloc_fd_guar_item(hw, &unused, guar);
7703 /* force shared filter pool for PF */
7704 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
7708 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
7709 ice_dcb_rebuild(pf);
7711 /* If the PF previously had enabled PTP, PTP init needs to happen before
7712 * the VSI rebuild. If not, this causes the PTP link status events to
7715 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
7716 ice_ptp_rebuild(pf, reset_type);
7718 if (ice_is_feature_supported(pf, ICE_F_GNSS))
7721 /* rebuild PF VSI */
7722 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
7724 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
7725 goto err_vsi_rebuild;
7728 if (reset_type == ICE_RESET_PFR) {
7729 err = ice_rebuild_channels(pf);
7731 dev_err(dev, "failed to rebuild and replay ADQ VSIs, err %d\n",
7733 goto err_vsi_rebuild;
7737 /* If Flow Director is active */
7738 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
7739 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
7741 dev_err(dev, "control VSI rebuild failed: %d\n", err);
7742 goto err_vsi_rebuild;
7745 /* replay HW Flow Director recipes */
7747 ice_fdir_replay_flows(hw);
7749 /* replay Flow Director filters */
7750 ice_fdir_replay_fltrs(pf);
7752 ice_rebuild_arfs(pf);
7755 if (vsi && vsi->netdev)
7756 netif_device_attach(vsi->netdev);
7758 ice_update_pf_netdev_link(pf);
7760 /* tell the firmware we are up */
7761 err = ice_send_version(pf);
7763 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n",
7765 goto err_vsi_rebuild;
7768 ice_replay_post(hw);
7770 /* if we get here, reset flow is successful */
7771 clear_bit(ICE_RESET_FAILED, pf->state);
7773 ice_plug_aux_dev(pf);
7774 if (ice_is_feature_supported(pf, ICE_F_SRIOV_LAG))
7775 ice_lag_rebuild(pf);
7777 /* Restore timestamp mode settings after VSI rebuild */
7778 ice_ptp_restore_timestamp_mode(pf);
7782 err_sched_init_port:
7783 ice_sched_cleanup_all(hw);
7785 ice_shutdown_all_ctrlq(hw, false);
7786 set_bit(ICE_RESET_FAILED, pf->state);
7788 /* set this bit in PF state to control service task scheduling */
7789 set_bit(ICE_NEEDS_RESTART, pf->state);
7790 dev_err(dev, "Rebuild failed, unload and reload driver\n");
7794 * ice_change_mtu - NDO callback to change the MTU
7795 * @netdev: network interface device structure
7796 * @new_mtu: new value for maximum frame size
7798 * Returns 0 on success, negative on failure
7800 int ice_change_mtu(struct net_device *netdev, int new_mtu)
7802 struct ice_netdev_priv *np = netdev_priv(netdev);
7803 struct ice_vsi *vsi = np->vsi;
7804 struct ice_pf *pf = vsi->back;
7805 struct bpf_prog *prog;
7809 if (new_mtu == (int)netdev->mtu) {
7810 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
7814 prog = vsi->xdp_prog;
7815 if (prog && !prog->aux->xdp_has_frags) {
7816 int frame_size = ice_max_xdp_frame_size(vsi);
7818 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
7819 netdev_err(netdev, "max MTU for XDP usage is %d\n",
7820 frame_size - ICE_ETH_PKT_HDR_PAD);
7823 } else if (test_bit(ICE_FLAG_LEGACY_RX, pf->flags)) {
7824 if (new_mtu + ICE_ETH_PKT_HDR_PAD > ICE_MAX_FRAME_LEGACY_RX) {
7825 netdev_err(netdev, "Too big MTU for legacy-rx; Max is %d\n",
7826 ICE_MAX_FRAME_LEGACY_RX - ICE_ETH_PKT_HDR_PAD);
7831 /* if a reset is in progress, wait for some time for it to complete */
7833 if (ice_is_reset_in_progress(pf->state)) {
7835 usleep_range(1000, 2000);
7840 } while (count < 100);
7843 netdev_err(netdev, "can't change MTU. Device is busy\n");
7847 WRITE_ONCE(netdev->mtu, (unsigned int)new_mtu);
7848 err = ice_down_up(vsi);
7852 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
7853 set_bit(ICE_FLAG_MTU_CHANGED, pf->flags);
7859 * ice_eth_ioctl - Access the hwtstamp interface
7860 * @netdev: network interface device structure
7861 * @ifr: interface request data
7862 * @cmd: ioctl command
7864 static int ice_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7866 struct ice_netdev_priv *np = netdev_priv(netdev);
7867 struct ice_pf *pf = np->vsi->back;
7871 return ice_ptp_get_ts_config(pf, ifr);
7873 return ice_ptp_set_ts_config(pf, ifr);
7880 * ice_aq_str - convert AQ err code to a string
7881 * @aq_err: the AQ error code to convert
7883 const char *ice_aq_str(enum ice_aq_err aq_err)
7888 case ICE_AQ_RC_EPERM:
7889 return "ICE_AQ_RC_EPERM";
7890 case ICE_AQ_RC_ENOENT:
7891 return "ICE_AQ_RC_ENOENT";
7892 case ICE_AQ_RC_ENOMEM:
7893 return "ICE_AQ_RC_ENOMEM";
7894 case ICE_AQ_RC_EBUSY:
7895 return "ICE_AQ_RC_EBUSY";
7896 case ICE_AQ_RC_EEXIST:
7897 return "ICE_AQ_RC_EEXIST";
7898 case ICE_AQ_RC_EINVAL:
7899 return "ICE_AQ_RC_EINVAL";
7900 case ICE_AQ_RC_ENOSPC:
7901 return "ICE_AQ_RC_ENOSPC";
7902 case ICE_AQ_RC_ENOSYS:
7903 return "ICE_AQ_RC_ENOSYS";
7904 case ICE_AQ_RC_EMODE:
7905 return "ICE_AQ_RC_EMODE";
7906 case ICE_AQ_RC_ENOSEC:
7907 return "ICE_AQ_RC_ENOSEC";
7908 case ICE_AQ_RC_EBADSIG:
7909 return "ICE_AQ_RC_EBADSIG";
7910 case ICE_AQ_RC_ESVN:
7911 return "ICE_AQ_RC_ESVN";
7912 case ICE_AQ_RC_EBADMAN:
7913 return "ICE_AQ_RC_EBADMAN";
7914 case ICE_AQ_RC_EBADBUF:
7915 return "ICE_AQ_RC_EBADBUF";
7918 return "ICE_AQ_RC_UNKNOWN";
7922 * ice_set_rss_lut - Set RSS LUT
7923 * @vsi: Pointer to VSI structure
7924 * @lut: Lookup table
7925 * @lut_size: Lookup table size
7927 * Returns 0 on success, negative on failure
7929 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7931 struct ice_aq_get_set_rss_lut_params params = {};
7932 struct ice_hw *hw = &vsi->back->hw;
7938 params.vsi_handle = vsi->idx;
7939 params.lut_size = lut_size;
7940 params.lut_type = vsi->rss_lut_type;
7943 status = ice_aq_set_rss_lut(hw, ¶ms);
7945 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %d aq_err %s\n",
7946 status, ice_aq_str(hw->adminq.sq_last_status));
7952 * ice_set_rss_key - Set RSS key
7953 * @vsi: Pointer to the VSI structure
7954 * @seed: RSS hash seed
7956 * Returns 0 on success, negative on failure
7958 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed)
7960 struct ice_hw *hw = &vsi->back->hw;
7966 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7968 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %d aq_err %s\n",
7969 status, ice_aq_str(hw->adminq.sq_last_status));
7975 * ice_get_rss_lut - Get RSS LUT
7976 * @vsi: Pointer to VSI structure
7977 * @lut: Buffer to store the lookup table entries
7978 * @lut_size: Size of buffer to store the lookup table entries
7980 * Returns 0 on success, negative on failure
7982 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7984 struct ice_aq_get_set_rss_lut_params params = {};
7985 struct ice_hw *hw = &vsi->back->hw;
7991 params.vsi_handle = vsi->idx;
7992 params.lut_size = lut_size;
7993 params.lut_type = vsi->rss_lut_type;
7996 status = ice_aq_get_rss_lut(hw, ¶ms);
7998 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %d aq_err %s\n",
7999 status, ice_aq_str(hw->adminq.sq_last_status));
8005 * ice_get_rss_key - Get RSS key
8006 * @vsi: Pointer to VSI structure
8007 * @seed: Buffer to store the key in
8009 * Returns 0 on success, negative on failure
8011 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed)
8013 struct ice_hw *hw = &vsi->back->hw;
8019 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
8021 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %d aq_err %s\n",
8022 status, ice_aq_str(hw->adminq.sq_last_status));
8028 * ice_set_rss_hfunc - Set RSS HASH function
8029 * @vsi: Pointer to VSI structure
8030 * @hfunc: hash function (ICE_AQ_VSI_Q_OPT_RSS_*)
8032 * Returns 0 on success, negative on failure
8034 int ice_set_rss_hfunc(struct ice_vsi *vsi, u8 hfunc)
8036 struct ice_hw *hw = &vsi->back->hw;
8037 struct ice_vsi_ctx *ctx;
8041 if (hfunc == vsi->rss_hfunc)
8044 if (hfunc != ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ &&
8045 hfunc != ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ)
8048 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
8052 ctx->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
8053 ctx->info.q_opt_rss = vsi->info.q_opt_rss;
8054 ctx->info.q_opt_rss &= ~ICE_AQ_VSI_Q_OPT_RSS_HASH_M;
8055 ctx->info.q_opt_rss |=
8056 FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hfunc);
8057 ctx->info.q_opt_tc = vsi->info.q_opt_tc;
8058 ctx->info.q_opt_flags = vsi->info.q_opt_rss;
8060 err = ice_update_vsi(hw, vsi->idx, ctx, NULL);
8062 dev_err(ice_pf_to_dev(vsi->back), "Failed to configure RSS hash for VSI %d, error %d\n",
8065 vsi->info.q_opt_rss = ctx->info.q_opt_rss;
8066 vsi->rss_hfunc = hfunc;
8067 netdev_info(vsi->netdev, "Hash function set to: %sToeplitz\n",
8068 hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ ?
8075 /* Fix the symmetry setting for all existing RSS configurations */
8076 symm = !!(hfunc == ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ);
8077 return ice_set_rss_cfg_symm(hw, vsi, symm);
8081 * ice_bridge_getlink - Get the hardware bridge mode
8084 * @seq: RTNL message seq
8085 * @dev: the netdev being configured
8086 * @filter_mask: filter mask passed in
8087 * @nlflags: netlink flags passed in
8089 * Return the bridge mode (VEB/VEPA)
8092 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
8093 struct net_device *dev, u32 filter_mask, int nlflags)
8095 struct ice_netdev_priv *np = netdev_priv(dev);
8096 struct ice_vsi *vsi = np->vsi;
8097 struct ice_pf *pf = vsi->back;
8100 bmode = pf->first_sw->bridge_mode;
8102 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
8107 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
8108 * @vsi: Pointer to VSI structure
8109 * @bmode: Hardware bridge mode (VEB/VEPA)
8111 * Returns 0 on success, negative on failure
8113 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
8115 struct ice_aqc_vsi_props *vsi_props;
8116 struct ice_hw *hw = &vsi->back->hw;
8117 struct ice_vsi_ctx *ctxt;
8120 vsi_props = &vsi->info;
8122 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
8126 ctxt->info = vsi->info;
8128 if (bmode == BRIDGE_MODE_VEB)
8129 /* change from VEPA to VEB mode */
8130 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
8132 /* change from VEB to VEPA mode */
8133 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
8134 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
8136 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
8138 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %s\n",
8139 bmode, ret, ice_aq_str(hw->adminq.sq_last_status));
8142 /* Update sw flags for book keeping */
8143 vsi_props->sw_flags = ctxt->info.sw_flags;
8151 * ice_bridge_setlink - Set the hardware bridge mode
8152 * @dev: the netdev being configured
8153 * @nlh: RTNL message
8154 * @flags: bridge setlink flags
8155 * @extack: netlink extended ack
8157 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
8158 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
8159 * not already set for all VSIs connected to this switch. And also update the
8160 * unicast switch filter rules for the corresponding switch of the netdev.
8163 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
8164 u16 __always_unused flags,
8165 struct netlink_ext_ack __always_unused *extack)
8167 struct ice_netdev_priv *np = netdev_priv(dev);
8168 struct ice_pf *pf = np->vsi->back;
8169 struct nlattr *attr, *br_spec;
8170 struct ice_hw *hw = &pf->hw;
8171 struct ice_sw *pf_sw;
8172 int rem, v, err = 0;
8174 pf_sw = pf->first_sw;
8175 /* find the attribute in the netlink message */
8176 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
8180 nla_for_each_nested_type(attr, IFLA_BRIDGE_MODE, br_spec, rem) {
8181 __u16 mode = nla_get_u16(attr);
8183 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
8185 /* Continue if bridge mode is not being flipped */
8186 if (mode == pf_sw->bridge_mode)
8188 /* Iterates through the PF VSI list and update the loopback
8191 ice_for_each_vsi(pf, v) {
8194 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
8199 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
8200 /* Update the unicast switch filter rules for the corresponding
8201 * switch of the netdev
8203 err = ice_update_sw_rule_bridge_mode(hw);
8205 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %s\n",
8207 ice_aq_str(hw->adminq.sq_last_status));
8208 /* revert hw->evb_veb */
8209 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
8213 pf_sw->bridge_mode = mode;
8220 * ice_tx_timeout - Respond to a Tx Hang
8221 * @netdev: network interface device structure
8222 * @txqueue: Tx queue
8224 void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
8226 struct ice_netdev_priv *np = netdev_priv(netdev);
8227 struct ice_tx_ring *tx_ring = NULL;
8228 struct ice_vsi *vsi = np->vsi;
8229 struct ice_pf *pf = vsi->back;
8232 pf->tx_timeout_count++;
8234 /* Check if PFC is enabled for the TC to which the queue belongs
8235 * to. If yes then Tx timeout is not caused by a hung queue, no
8236 * need to reset and rebuild
8238 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
8239 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
8244 /* now that we have an index, find the tx_ring struct */
8245 ice_for_each_txq(vsi, i)
8246 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
8247 if (txqueue == vsi->tx_rings[i]->q_index) {
8248 tx_ring = vsi->tx_rings[i];
8252 /* Reset recovery level if enough time has elapsed after last timeout.
8253 * Also ensure no new reset action happens before next timeout period.
8255 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
8256 pf->tx_timeout_recovery_level = 1;
8257 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
8258 netdev->watchdog_timeo)))
8262 struct ice_hw *hw = &pf->hw;
8265 head = FIELD_GET(QTX_COMM_HEAD_HEAD_M,
8266 rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])));
8267 /* Read interrupt register */
8268 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
8270 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
8271 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
8272 head, tx_ring->next_to_use, val);
8275 pf->tx_timeout_last_recovery = jiffies;
8276 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
8277 pf->tx_timeout_recovery_level, txqueue);
8279 switch (pf->tx_timeout_recovery_level) {
8281 set_bit(ICE_PFR_REQ, pf->state);
8284 set_bit(ICE_CORER_REQ, pf->state);
8287 set_bit(ICE_GLOBR_REQ, pf->state);
8290 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
8291 set_bit(ICE_DOWN, pf->state);
8292 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
8293 set_bit(ICE_SERVICE_DIS, pf->state);
8297 ice_service_task_schedule(pf);
8298 pf->tx_timeout_recovery_level++;
8302 * ice_setup_tc_cls_flower - flower classifier offloads
8303 * @np: net device to configure
8304 * @filter_dev: device on which filter is added
8305 * @cls_flower: offload data
8308 ice_setup_tc_cls_flower(struct ice_netdev_priv *np,
8309 struct net_device *filter_dev,
8310 struct flow_cls_offload *cls_flower)
8312 struct ice_vsi *vsi = np->vsi;
8314 if (cls_flower->common.chain_index)
8317 switch (cls_flower->command) {
8318 case FLOW_CLS_REPLACE:
8319 return ice_add_cls_flower(filter_dev, vsi, cls_flower);
8320 case FLOW_CLS_DESTROY:
8321 return ice_del_cls_flower(vsi, cls_flower);
8328 * ice_setup_tc_block_cb - callback handler registered for TC block
8329 * @type: TC SETUP type
8330 * @type_data: TC flower offload data that contains user input
8331 * @cb_priv: netdev private data
8334 ice_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
8336 struct ice_netdev_priv *np = cb_priv;
8339 case TC_SETUP_CLSFLOWER:
8340 return ice_setup_tc_cls_flower(np, np->vsi->netdev,
8348 * ice_validate_mqprio_qopt - Validate TCF input parameters
8349 * @vsi: Pointer to VSI
8350 * @mqprio_qopt: input parameters for mqprio queue configuration
8352 * This function validates MQPRIO params, such as qcount (power of 2 wherever
8353 * needed), and make sure user doesn't specify qcount and BW rate limit
8354 * for TCs, which are more than "num_tc"
8357 ice_validate_mqprio_qopt(struct ice_vsi *vsi,
8358 struct tc_mqprio_qopt_offload *mqprio_qopt)
8360 int non_power_of_2_qcount = 0;
8361 struct ice_pf *pf = vsi->back;
8362 int max_rss_q_cnt = 0;
8363 u64 sum_min_rate = 0;
8368 if (vsi->type != ICE_VSI_PF)
8371 if (mqprio_qopt->qopt.offset[0] != 0 ||
8372 mqprio_qopt->qopt.num_tc < 1 ||
8373 mqprio_qopt->qopt.num_tc > ICE_CHNL_MAX_TC)
8376 dev = ice_pf_to_dev(pf);
8377 vsi->ch_rss_size = 0;
8378 num_tc = mqprio_qopt->qopt.num_tc;
8379 speed = ice_get_link_speed_kbps(vsi);
8381 for (i = 0; num_tc; i++) {
8382 int qcount = mqprio_qopt->qopt.count[i];
8383 u64 max_rate, min_rate, rem;
8388 if (is_power_of_2(qcount)) {
8389 if (non_power_of_2_qcount &&
8390 qcount > non_power_of_2_qcount) {
8391 dev_err(dev, "qcount[%d] cannot be greater than non power of 2 qcount[%d]\n",
8392 qcount, non_power_of_2_qcount);
8395 if (qcount > max_rss_q_cnt)
8396 max_rss_q_cnt = qcount;
8398 if (non_power_of_2_qcount &&
8399 qcount != non_power_of_2_qcount) {
8400 dev_err(dev, "Only one non power of 2 qcount allowed[%d,%d]\n",
8401 qcount, non_power_of_2_qcount);
8404 if (qcount < max_rss_q_cnt) {
8405 dev_err(dev, "non power of 2 qcount[%d] cannot be less than other qcount[%d]\n",
8406 qcount, max_rss_q_cnt);
8409 max_rss_q_cnt = qcount;
8410 non_power_of_2_qcount = qcount;
8413 /* TC command takes input in K/N/Gbps or K/M/Gbit etc but
8414 * converts the bandwidth rate limit into Bytes/s when
8415 * passing it down to the driver. So convert input bandwidth
8416 * from Bytes/s to Kbps
8418 max_rate = mqprio_qopt->max_rate[i];
8419 max_rate = div_u64(max_rate, ICE_BW_KBPS_DIVISOR);
8421 /* min_rate is minimum guaranteed rate and it can't be zero */
8422 min_rate = mqprio_qopt->min_rate[i];
8423 min_rate = div_u64(min_rate, ICE_BW_KBPS_DIVISOR);
8424 sum_min_rate += min_rate;
8426 if (min_rate && min_rate < ICE_MIN_BW_LIMIT) {
8427 dev_err(dev, "TC%d: min_rate(%llu Kbps) < %u Kbps\n", i,
8428 min_rate, ICE_MIN_BW_LIMIT);
8432 if (max_rate && max_rate > speed) {
8433 dev_err(dev, "TC%d: max_rate(%llu Kbps) > link speed of %u Kbps\n",
8434 i, max_rate, speed);
8438 iter_div_u64_rem(min_rate, ICE_MIN_BW_LIMIT, &rem);
8440 dev_err(dev, "TC%d: Min Rate not multiple of %u Kbps",
8441 i, ICE_MIN_BW_LIMIT);
8445 iter_div_u64_rem(max_rate, ICE_MIN_BW_LIMIT, &rem);
8447 dev_err(dev, "TC%d: Max Rate not multiple of %u Kbps",
8448 i, ICE_MIN_BW_LIMIT);
8452 /* min_rate can't be more than max_rate, except when max_rate
8453 * is zero (implies max_rate sought is max line rate). In such
8454 * a case min_rate can be more than max.
8456 if (max_rate && min_rate > max_rate) {
8457 dev_err(dev, "min_rate %llu Kbps can't be more than max_rate %llu Kbps\n",
8458 min_rate, max_rate);
8462 if (i >= mqprio_qopt->qopt.num_tc - 1)
8464 if (mqprio_qopt->qopt.offset[i + 1] !=
8465 (mqprio_qopt->qopt.offset[i] + qcount))
8469 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
8472 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
8475 if (sum_min_rate && sum_min_rate > (u64)speed) {
8476 dev_err(dev, "Invalid min Tx rate(%llu) Kbps > speed (%u) Kbps specified\n",
8477 sum_min_rate, speed);
8481 /* make sure vsi->ch_rss_size is set correctly based on TC's qcount */
8482 vsi->ch_rss_size = max_rss_q_cnt;
8488 * ice_add_vsi_to_fdir - add a VSI to the flow director group for PF
8489 * @pf: ptr to PF device
8492 static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
8494 struct device *dev = ice_pf_to_dev(pf);
8499 if (!(vsi->num_gfltr || vsi->num_bfltr))
8503 for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
8504 struct ice_fd_hw_prof *prof;
8508 if (!(hw->fdir_prof && hw->fdir_prof[flow] &&
8509 hw->fdir_prof[flow]->cnt))
8512 for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
8513 enum ice_flow_priority prio;
8515 /* add this VSI to FDir profile for this flow */
8516 prio = ICE_FLOW_PRIO_NORMAL;
8517 prof = hw->fdir_prof[flow];
8518 status = ice_flow_add_entry(hw, ICE_BLK_FD,
8520 prof->vsi_h[0], vsi->idx,
8521 prio, prof->fdir_seg[tun],
8524 dev_err(dev, "channel VSI idx %d, not able to add to group %d\n",
8529 prof->entry_h[prof->cnt][tun] = entry_h;
8532 /* store VSI for filter replay and delete */
8533 prof->vsi_h[prof->cnt] = vsi->idx;
8537 dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx,
8542 dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx);
8548 * ice_add_channel - add a channel by adding VSI
8549 * @pf: ptr to PF device
8550 * @sw_id: underlying HW switching element ID
8551 * @ch: ptr to channel structure
8553 * Add a channel (VSI) using add_vsi and queue_map
8555 static int ice_add_channel(struct ice_pf *pf, u16 sw_id, struct ice_channel *ch)
8557 struct device *dev = ice_pf_to_dev(pf);
8558 struct ice_vsi *vsi;
8560 if (ch->type != ICE_VSI_CHNL) {
8561 dev_err(dev, "add new VSI failed, ch->type %d\n", ch->type);
8565 vsi = ice_chnl_vsi_setup(pf, pf->hw.port_info, ch);
8566 if (!vsi || vsi->type != ICE_VSI_CHNL) {
8567 dev_err(dev, "create chnl VSI failure\n");
8571 ice_add_vsi_to_fdir(pf, vsi);
8574 ch->vsi_num = vsi->vsi_num;
8575 ch->info.mapping_flags = vsi->info.mapping_flags;
8577 /* set the back pointer of channel for newly created VSI */
8580 memcpy(&ch->info.q_mapping, &vsi->info.q_mapping,
8581 sizeof(vsi->info.q_mapping));
8582 memcpy(&ch->info.tc_mapping, vsi->info.tc_mapping,
8583 sizeof(vsi->info.tc_mapping));
8590 * @vsi: the VSI being setup
8591 * @ch: ptr to channel structure
8593 * Configure channel specific resources such as rings, vector.
8595 static void ice_chnl_cfg_res(struct ice_vsi *vsi, struct ice_channel *ch)
8599 for (i = 0; i < ch->num_txq; i++) {
8600 struct ice_q_vector *tx_q_vector, *rx_q_vector;
8601 struct ice_ring_container *rc;
8602 struct ice_tx_ring *tx_ring;
8603 struct ice_rx_ring *rx_ring;
8605 tx_ring = vsi->tx_rings[ch->base_q + i];
8606 rx_ring = vsi->rx_rings[ch->base_q + i];
8607 if (!tx_ring || !rx_ring)
8610 /* setup ring being channel enabled */
8614 /* following code block sets up vector specific attributes */
8615 tx_q_vector = tx_ring->q_vector;
8616 rx_q_vector = rx_ring->q_vector;
8617 if (!tx_q_vector && !rx_q_vector)
8621 tx_q_vector->ch = ch;
8622 /* setup Tx and Rx ITR setting if DIM is off */
8623 rc = &tx_q_vector->tx;
8624 if (!ITR_IS_DYNAMIC(rc))
8625 ice_write_itr(rc, rc->itr_setting);
8628 rx_q_vector->ch = ch;
8629 /* setup Tx and Rx ITR setting if DIM is off */
8630 rc = &rx_q_vector->rx;
8631 if (!ITR_IS_DYNAMIC(rc))
8632 ice_write_itr(rc, rc->itr_setting);
8636 /* it is safe to assume that, if channel has non-zero num_t[r]xq, then
8637 * GLINT_ITR register would have written to perform in-context
8638 * update, hence perform flush
8640 if (ch->num_txq || ch->num_rxq)
8641 ice_flush(&vsi->back->hw);
8645 * ice_cfg_chnl_all_res - configure channel resources
8646 * @vsi: pte to main_vsi
8647 * @ch: ptr to channel structure
8649 * This function configures channel specific resources such as flow-director
8650 * counter index, and other resources such as queues, vectors, ITR settings
8653 ice_cfg_chnl_all_res(struct ice_vsi *vsi, struct ice_channel *ch)
8655 /* configure channel (aka ADQ) resources such as queues, vectors,
8656 * ITR settings for channel specific vectors and anything else
8658 ice_chnl_cfg_res(vsi, ch);
8662 * ice_setup_hw_channel - setup new channel
8663 * @pf: ptr to PF device
8664 * @vsi: the VSI being setup
8665 * @ch: ptr to channel structure
8666 * @sw_id: underlying HW switching element ID
8667 * @type: type of channel to be created (VMDq2/VF)
8669 * Setup new channel (VSI) based on specified type (VMDq2/VF)
8670 * and configures Tx rings accordingly
8673 ice_setup_hw_channel(struct ice_pf *pf, struct ice_vsi *vsi,
8674 struct ice_channel *ch, u16 sw_id, u8 type)
8676 struct device *dev = ice_pf_to_dev(pf);
8679 ch->base_q = vsi->next_base_q;
8682 ret = ice_add_channel(pf, sw_id, ch);
8684 dev_err(dev, "failed to add_channel using sw_id %u\n", sw_id);
8688 /* configure/setup ADQ specific resources */
8689 ice_cfg_chnl_all_res(vsi, ch);
8691 /* make sure to update the next_base_q so that subsequent channel's
8692 * (aka ADQ) VSI queue map is correct
8694 vsi->next_base_q = vsi->next_base_q + ch->num_rxq;
8695 dev_dbg(dev, "added channel: vsi_num %u, num_rxq %u\n", ch->vsi_num,
8702 * ice_setup_channel - setup new channel using uplink element
8703 * @pf: ptr to PF device
8704 * @vsi: the VSI being setup
8705 * @ch: ptr to channel structure
8707 * Setup new channel (VSI) based on specified type (VMDq2/VF)
8708 * and uplink switching element
8711 ice_setup_channel(struct ice_pf *pf, struct ice_vsi *vsi,
8712 struct ice_channel *ch)
8714 struct device *dev = ice_pf_to_dev(pf);
8718 if (vsi->type != ICE_VSI_PF) {
8719 dev_err(dev, "unsupported parent VSI type(%d)\n", vsi->type);
8723 sw_id = pf->first_sw->sw_id;
8725 /* create channel (VSI) */
8726 ret = ice_setup_hw_channel(pf, vsi, ch, sw_id, ICE_VSI_CHNL);
8728 dev_err(dev, "failed to setup hw_channel\n");
8731 dev_dbg(dev, "successfully created channel()\n");
8733 return ch->ch_vsi ? true : false;
8737 * ice_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
8738 * @vsi: VSI to be configured
8739 * @max_tx_rate: max Tx rate in Kbps to be configured as maximum BW limit
8740 * @min_tx_rate: min Tx rate in Kbps to be configured as minimum BW limit
8743 ice_set_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate, u64 min_tx_rate)
8747 err = ice_set_min_bw_limit(vsi, min_tx_rate);
8751 return ice_set_max_bw_limit(vsi, max_tx_rate);
8755 * ice_create_q_channel - function to create channel
8756 * @vsi: VSI to be configured
8757 * @ch: ptr to channel (it contains channel specific params)
8759 * This function creates channel (VSI) using num_queues specified by user,
8760 * reconfigs RSS if needed.
8762 static int ice_create_q_channel(struct ice_vsi *vsi, struct ice_channel *ch)
8764 struct ice_pf *pf = vsi->back;
8770 dev = ice_pf_to_dev(pf);
8771 if (!ch->num_txq || !ch->num_rxq) {
8772 dev_err(dev, "Invalid num_queues requested: %d\n", ch->num_rxq);
8776 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_txq) {
8777 dev_err(dev, "cnt_q_avail (%u) less than num_queues %d\n",
8778 vsi->cnt_q_avail, ch->num_txq);
8782 if (!ice_setup_channel(pf, vsi, ch)) {
8783 dev_info(dev, "Failed to setup channel\n");
8786 /* configure BW rate limit */
8787 if (ch->ch_vsi && (ch->max_tx_rate || ch->min_tx_rate)) {
8790 ret = ice_set_bw_limit(ch->ch_vsi, ch->max_tx_rate,
8793 dev_err(dev, "failed to set Tx rate of %llu Kbps for VSI(%u)\n",
8794 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8796 dev_dbg(dev, "set Tx rate of %llu Kbps for VSI(%u)\n",
8797 ch->max_tx_rate, ch->ch_vsi->vsi_num);
8800 vsi->cnt_q_avail -= ch->num_txq;
8806 * ice_rem_all_chnl_fltrs - removes all channel filters
8807 * @pf: ptr to PF, TC-flower based filter are tracked at PF level
8809 * Remove all advanced switch filters only if they are channel specific
8810 * tc-flower based filter
8812 static void ice_rem_all_chnl_fltrs(struct ice_pf *pf)
8814 struct ice_tc_flower_fltr *fltr;
8815 struct hlist_node *node;
8817 /* to remove all channel filters, iterate an ordered list of filters */
8818 hlist_for_each_entry_safe(fltr, node,
8819 &pf->tc_flower_fltr_list,
8821 struct ice_rule_query_data rule;
8824 /* for now process only channel specific filters */
8825 if (!ice_is_chnl_fltr(fltr))
8828 rule.rid = fltr->rid;
8829 rule.rule_id = fltr->rule_id;
8830 rule.vsi_handle = fltr->dest_vsi_handle;
8831 status = ice_rem_adv_rule_by_id(&pf->hw, &rule);
8833 if (status == -ENOENT)
8834 dev_dbg(ice_pf_to_dev(pf), "TC flower filter (rule_id %u) does not exist\n",
8837 dev_err(ice_pf_to_dev(pf), "failed to delete TC flower filter, status %d\n",
8839 } else if (fltr->dest_vsi) {
8840 /* update advanced switch filter count */
8841 if (fltr->dest_vsi->type == ICE_VSI_CHNL) {
8842 u32 flags = fltr->flags;
8844 fltr->dest_vsi->num_chnl_fltr--;
8845 if (flags & (ICE_TC_FLWR_FIELD_DST_MAC |
8846 ICE_TC_FLWR_FIELD_ENC_DST_MAC))
8847 pf->num_dmac_chnl_fltrs--;
8851 hlist_del(&fltr->tc_flower_node);
8857 * ice_remove_q_channels - Remove queue channels for the TCs
8858 * @vsi: VSI to be configured
8859 * @rem_fltr: delete advanced switch filter or not
8861 * Remove queue channels for the TCs
8863 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_fltr)
8865 struct ice_channel *ch, *ch_tmp;
8866 struct ice_pf *pf = vsi->back;
8869 /* remove all tc-flower based filter if they are channel filters only */
8871 ice_rem_all_chnl_fltrs(pf);
8873 /* remove ntuple filters since queue configuration is being changed */
8874 if (vsi->netdev->features & NETIF_F_NTUPLE) {
8875 struct ice_hw *hw = &pf->hw;
8877 mutex_lock(&hw->fdir_fltr_lock);
8878 ice_fdir_del_all_fltrs(vsi);
8879 mutex_unlock(&hw->fdir_fltr_lock);
8882 /* perform cleanup for channels if they exist */
8883 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
8884 struct ice_vsi *ch_vsi;
8886 list_del(&ch->list);
8887 ch_vsi = ch->ch_vsi;
8893 /* Reset queue contexts */
8894 for (i = 0; i < ch->num_rxq; i++) {
8895 struct ice_tx_ring *tx_ring;
8896 struct ice_rx_ring *rx_ring;
8898 tx_ring = vsi->tx_rings[ch->base_q + i];
8899 rx_ring = vsi->rx_rings[ch->base_q + i];
8902 if (tx_ring->q_vector)
8903 tx_ring->q_vector->ch = NULL;
8907 if (rx_ring->q_vector)
8908 rx_ring->q_vector->ch = NULL;
8912 /* Release FD resources for the channel VSI */
8913 ice_fdir_rem_adq_chnl(&pf->hw, ch->ch_vsi->idx);
8915 /* clear the VSI from scheduler tree */
8916 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx);
8918 /* Delete VSI from FW, PF and HW VSI arrays */
8919 ice_vsi_delete(ch->ch_vsi);
8921 /* free the channel */
8925 /* clear the channel VSI map which is stored in main VSI */
8926 ice_for_each_chnl_tc(i)
8927 vsi->tc_map_vsi[i] = NULL;
8929 /* reset main VSI's all TC information */
8935 * ice_rebuild_channels - rebuild channel
8938 * Recreate channel VSIs and replay filters
8940 static int ice_rebuild_channels(struct ice_pf *pf)
8942 struct device *dev = ice_pf_to_dev(pf);
8943 struct ice_vsi *main_vsi;
8944 bool rem_adv_fltr = true;
8945 struct ice_channel *ch;
8946 struct ice_vsi *vsi;
8950 main_vsi = ice_get_main_vsi(pf);
8954 if (!test_bit(ICE_FLAG_TC_MQPRIO, pf->flags) ||
8955 main_vsi->old_numtc == 1)
8956 return 0; /* nothing to be done */
8958 /* reconfigure main VSI based on old value of TC and cached values
8961 err = ice_vsi_cfg_tc(main_vsi, main_vsi->old_ena_tc);
8963 dev_err(dev, "failed configuring TC(ena_tc:0x%02x) for HW VSI=%u\n",
8964 main_vsi->old_ena_tc, main_vsi->vsi_num);
8968 /* rebuild ADQ VSIs */
8969 ice_for_each_vsi(pf, i) {
8970 enum ice_vsi_type type;
8973 if (!vsi || vsi->type != ICE_VSI_CHNL)
8978 /* rebuild ADQ VSI */
8979 err = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_INIT);
8981 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n",
8982 ice_vsi_type_str(type), vsi->idx, err);
8986 /* Re-map HW VSI number, using VSI handle that has been
8987 * previously validated in ice_replay_vsi() call above
8989 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
8991 /* replay filters for the VSI */
8992 err = ice_replay_vsi(&pf->hw, vsi->idx);
8994 dev_err(dev, "VSI (type:%s) replay failed, err %d, VSI index %d\n",
8995 ice_vsi_type_str(type), err, vsi->idx);
8996 rem_adv_fltr = false;
8999 dev_info(dev, "VSI (type:%s) at index %d rebuilt successfully\n",
9000 ice_vsi_type_str(type), vsi->idx);
9002 /* store ADQ VSI at correct TC index in main VSI's
9005 main_vsi->tc_map_vsi[tc_idx++] = vsi;
9008 /* ADQ VSI(s) has been rebuilt successfully, so setup
9009 * channel for main VSI's Tx and Rx rings
9011 list_for_each_entry(ch, &main_vsi->ch_list, list) {
9012 struct ice_vsi *ch_vsi;
9014 ch_vsi = ch->ch_vsi;
9018 /* reconfig channel resources */
9019 ice_cfg_chnl_all_res(main_vsi, ch);
9021 /* replay BW rate limit if it is non-zero */
9022 if (!ch->max_tx_rate && !ch->min_tx_rate)
9025 err = ice_set_bw_limit(ch_vsi, ch->max_tx_rate,
9028 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",
9029 err, ch->max_tx_rate, ch->min_tx_rate,
9032 dev_dbg(dev, "successfully rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n",
9033 ch->max_tx_rate, ch->min_tx_rate,
9037 /* reconfig RSS for main VSI */
9038 if (main_vsi->ch_rss_size)
9039 ice_vsi_cfg_rss_lut_key(main_vsi);
9044 ice_remove_q_channels(main_vsi, rem_adv_fltr);
9049 * ice_create_q_channels - Add queue channel for the given TCs
9050 * @vsi: VSI to be configured
9052 * Configures queue channel mapping to the given TCs
9054 static int ice_create_q_channels(struct ice_vsi *vsi)
9056 struct ice_pf *pf = vsi->back;
9057 struct ice_channel *ch;
9060 ice_for_each_chnl_tc(i) {
9061 if (!(vsi->all_enatc & BIT(i)))
9064 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
9069 INIT_LIST_HEAD(&ch->list);
9070 ch->num_rxq = vsi->mqprio_qopt.qopt.count[i];
9071 ch->num_txq = vsi->mqprio_qopt.qopt.count[i];
9072 ch->base_q = vsi->mqprio_qopt.qopt.offset[i];
9073 ch->max_tx_rate = vsi->mqprio_qopt.max_rate[i];
9074 ch->min_tx_rate = vsi->mqprio_qopt.min_rate[i];
9076 /* convert to Kbits/s */
9077 if (ch->max_tx_rate)
9078 ch->max_tx_rate = div_u64(ch->max_tx_rate,
9079 ICE_BW_KBPS_DIVISOR);
9080 if (ch->min_tx_rate)
9081 ch->min_tx_rate = div_u64(ch->min_tx_rate,
9082 ICE_BW_KBPS_DIVISOR);
9084 ret = ice_create_q_channel(vsi, ch);
9086 dev_err(ice_pf_to_dev(pf),
9087 "failed creating channel TC:%d\n", i);
9091 list_add_tail(&ch->list, &vsi->ch_list);
9092 vsi->tc_map_vsi[i] = ch->ch_vsi;
9093 dev_dbg(ice_pf_to_dev(pf),
9094 "successfully created channel: VSI %pK\n", ch->ch_vsi);
9099 ice_remove_q_channels(vsi, false);
9105 * ice_setup_tc_mqprio_qdisc - configure multiple traffic classes
9106 * @netdev: net device to configure
9107 * @type_data: TC offload data
9109 static int ice_setup_tc_mqprio_qdisc(struct net_device *netdev, void *type_data)
9111 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
9112 struct ice_netdev_priv *np = netdev_priv(netdev);
9113 struct ice_vsi *vsi = np->vsi;
9114 struct ice_pf *pf = vsi->back;
9115 u16 mode, ena_tc_qdisc = 0;
9116 int cur_txq, cur_rxq;
9121 dev = ice_pf_to_dev(pf);
9122 num_tcf = mqprio_qopt->qopt.num_tc;
9123 hw = mqprio_qopt->qopt.hw;
9124 mode = mqprio_qopt->mode;
9126 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
9127 vsi->ch_rss_size = 0;
9128 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
9132 /* Generate queue region map for number of TCF requested */
9133 for (i = 0; i < num_tcf; i++)
9134 ena_tc_qdisc |= BIT(i);
9137 case TC_MQPRIO_MODE_CHANNEL:
9139 if (pf->hw.port_info->is_custom_tx_enabled) {
9140 dev_err(dev, "Custom Tx scheduler feature enabled, can't configure ADQ\n");
9143 ice_tear_down_devlink_rate_tree(pf);
9145 ret = ice_validate_mqprio_qopt(vsi, mqprio_qopt);
9147 netdev_err(netdev, "failed to validate_mqprio_qopt(), ret %d\n",
9151 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
9152 set_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
9153 /* don't assume state of hw_tc_offload during driver load
9154 * and set the flag for TC flower filter if hw_tc_offload
9157 if (vsi->netdev->features & NETIF_F_HW_TC)
9158 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
9166 /* Requesting same TCF configuration as already enabled */
9167 if (ena_tc_qdisc == vsi->tc_cfg.ena_tc &&
9168 mode != TC_MQPRIO_MODE_CHANNEL)
9171 /* Pause VSI queues */
9172 ice_dis_vsi(vsi, true);
9174 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
9175 ice_remove_q_channels(vsi, true);
9177 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
9178 vsi->req_txq = min_t(int, ice_get_avail_txq_count(pf),
9180 vsi->req_rxq = min_t(int, ice_get_avail_rxq_count(pf),
9183 /* logic to rebuild VSI, same like ethtool -L */
9184 u16 offset = 0, qcount_tx = 0, qcount_rx = 0;
9186 for (i = 0; i < num_tcf; i++) {
9187 if (!(ena_tc_qdisc & BIT(i)))
9190 offset = vsi->mqprio_qopt.qopt.offset[i];
9191 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
9192 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
9194 vsi->req_txq = offset + qcount_tx;
9195 vsi->req_rxq = offset + qcount_rx;
9197 /* store away original rss_size info, so that it gets reused
9198 * form ice_vsi_rebuild during tc-qdisc delete stage - to
9199 * determine, what should be the rss_sizefor main VSI
9201 vsi->orig_rss_size = vsi->rss_size;
9204 /* save current values of Tx and Rx queues before calling VSI rebuild
9205 * for fallback option
9207 cur_txq = vsi->num_txq;
9208 cur_rxq = vsi->num_rxq;
9210 /* proceed with rebuild main VSI using correct number of queues */
9211 ret = ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT);
9213 /* fallback to current number of queues */
9214 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n");
9215 vsi->req_txq = cur_txq;
9216 vsi->req_rxq = cur_rxq;
9217 clear_bit(ICE_RESET_FAILED, pf->state);
9218 if (ice_vsi_rebuild(vsi, ICE_VSI_FLAG_NO_INIT)) {
9219 dev_err(dev, "Rebuild of main VSI failed again\n");
9224 vsi->all_numtc = num_tcf;
9225 vsi->all_enatc = ena_tc_qdisc;
9226 ret = ice_vsi_cfg_tc(vsi, ena_tc_qdisc);
9228 netdev_err(netdev, "failed configuring TC for VSI id=%d\n",
9233 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
9234 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
9235 u64 min_tx_rate = vsi->mqprio_qopt.min_rate[0];
9237 /* set TC0 rate limit if specified */
9238 if (max_tx_rate || min_tx_rate) {
9239 /* convert to Kbits/s */
9241 max_tx_rate = div_u64(max_tx_rate, ICE_BW_KBPS_DIVISOR);
9243 min_tx_rate = div_u64(min_tx_rate, ICE_BW_KBPS_DIVISOR);
9245 ret = ice_set_bw_limit(vsi, max_tx_rate, min_tx_rate);
9247 dev_dbg(dev, "set Tx rate max %llu min %llu for VSI(%u)\n",
9248 max_tx_rate, min_tx_rate, vsi->vsi_num);
9250 dev_err(dev, "failed to set Tx rate max %llu min %llu for VSI(%u)\n",
9251 max_tx_rate, min_tx_rate, vsi->vsi_num);
9255 ret = ice_create_q_channels(vsi);
9257 netdev_err(netdev, "failed configuring queue channels\n");
9260 netdev_dbg(netdev, "successfully configured channels\n");
9264 if (vsi->ch_rss_size)
9265 ice_vsi_cfg_rss_lut_key(vsi);
9268 /* if error, reset the all_numtc and all_enatc */
9274 ice_ena_vsi(vsi, true);
9279 static LIST_HEAD(ice_block_cb_list);
9282 ice_setup_tc(struct net_device *netdev, enum tc_setup_type type,
9285 struct ice_netdev_priv *np = netdev_priv(netdev);
9286 struct ice_pf *pf = np->vsi->back;
9287 bool locked = false;
9291 case TC_SETUP_BLOCK:
9292 return flow_block_cb_setup_simple(type_data,
9294 ice_setup_tc_block_cb,
9296 case TC_SETUP_QDISC_MQPRIO:
9297 if (ice_is_eswitch_mode_switchdev(pf)) {
9298 netdev_err(netdev, "TC MQPRIO offload not supported, switchdev is enabled\n");
9303 mutex_lock(&pf->adev_mutex);
9304 device_lock(&pf->adev->dev);
9306 if (pf->adev->dev.driver) {
9307 netdev_err(netdev, "Cannot change qdisc when RDMA is active\n");
9313 /* setup traffic classifier for receive side */
9314 mutex_lock(&pf->tc_mutex);
9315 err = ice_setup_tc_mqprio_qdisc(netdev, type_data);
9316 mutex_unlock(&pf->tc_mutex);
9320 device_unlock(&pf->adev->dev);
9321 mutex_unlock(&pf->adev_mutex);
9330 static struct ice_indr_block_priv *
9331 ice_indr_block_priv_lookup(struct ice_netdev_priv *np,
9332 struct net_device *netdev)
9334 struct ice_indr_block_priv *cb_priv;
9336 list_for_each_entry(cb_priv, &np->tc_indr_block_priv_list, list) {
9337 if (!cb_priv->netdev)
9339 if (cb_priv->netdev == netdev)
9346 ice_indr_setup_block_cb(enum tc_setup_type type, void *type_data,
9349 struct ice_indr_block_priv *priv = indr_priv;
9350 struct ice_netdev_priv *np = priv->np;
9353 case TC_SETUP_CLSFLOWER:
9354 return ice_setup_tc_cls_flower(np, priv->netdev,
9355 (struct flow_cls_offload *)
9363 ice_indr_setup_tc_block(struct net_device *netdev, struct Qdisc *sch,
9364 struct ice_netdev_priv *np,
9365 struct flow_block_offload *f, void *data,
9366 void (*cleanup)(struct flow_block_cb *block_cb))
9368 struct ice_indr_block_priv *indr_priv;
9369 struct flow_block_cb *block_cb;
9371 if (!ice_is_tunnel_supported(netdev) &&
9372 !(is_vlan_dev(netdev) &&
9373 vlan_dev_real_dev(netdev) == np->vsi->netdev))
9376 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9379 switch (f->command) {
9380 case FLOW_BLOCK_BIND:
9381 indr_priv = ice_indr_block_priv_lookup(np, netdev);
9385 indr_priv = kzalloc(sizeof(*indr_priv), GFP_KERNEL);
9389 indr_priv->netdev = netdev;
9391 list_add(&indr_priv->list, &np->tc_indr_block_priv_list);
9394 flow_indr_block_cb_alloc(ice_indr_setup_block_cb,
9395 indr_priv, indr_priv,
9396 ice_rep_indr_tc_block_unbind,
9397 f, netdev, sch, data, np,
9400 if (IS_ERR(block_cb)) {
9401 list_del(&indr_priv->list);
9403 return PTR_ERR(block_cb);
9405 flow_block_cb_add(block_cb, f);
9406 list_add_tail(&block_cb->driver_list, &ice_block_cb_list);
9408 case FLOW_BLOCK_UNBIND:
9409 indr_priv = ice_indr_block_priv_lookup(np, netdev);
9413 block_cb = flow_block_cb_lookup(f->block,
9414 ice_indr_setup_block_cb,
9419 flow_indr_block_cb_remove(block_cb, f);
9421 list_del(&block_cb->driver_list);
9430 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
9431 void *cb_priv, enum tc_setup_type type, void *type_data,
9433 void (*cleanup)(struct flow_block_cb *block_cb))
9436 case TC_SETUP_BLOCK:
9437 return ice_indr_setup_tc_block(netdev, sch, cb_priv, type_data,
9446 * ice_open - Called when a network interface becomes active
9447 * @netdev: network interface device structure
9449 * The open entry point is called when a network interface is made
9450 * active by the system (IFF_UP). At this point all resources needed
9451 * for transmit and receive operations are allocated, the interrupt
9452 * handler is registered with the OS, the netdev watchdog is enabled,
9453 * and the stack is notified that the interface is ready.
9455 * Returns 0 on success, negative value on failure
9457 int ice_open(struct net_device *netdev)
9459 struct ice_netdev_priv *np = netdev_priv(netdev);
9460 struct ice_pf *pf = np->vsi->back;
9462 if (ice_is_reset_in_progress(pf->state)) {
9463 netdev_err(netdev, "can't open net device while reset is in progress");
9467 return ice_open_internal(netdev);
9471 * ice_open_internal - Called when a network interface becomes active
9472 * @netdev: network interface device structure
9474 * Internal ice_open implementation. Should not be used directly except for ice_open and reset
9477 * Returns 0 on success, negative value on failure
9479 int ice_open_internal(struct net_device *netdev)
9481 struct ice_netdev_priv *np = netdev_priv(netdev);
9482 struct ice_vsi *vsi = np->vsi;
9483 struct ice_pf *pf = vsi->back;
9484 struct ice_port_info *pi;
9487 if (test_bit(ICE_NEEDS_RESTART, pf->state)) {
9488 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
9492 netif_carrier_off(netdev);
9494 pi = vsi->port_info;
9495 err = ice_update_link_info(pi);
9497 netdev_err(netdev, "Failed to get link info, error %d\n", err);
9501 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
9503 /* Set PHY if there is media, otherwise, turn off PHY */
9504 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
9505 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
9506 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) {
9507 err = ice_init_phy_user_cfg(pi);
9509 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n",
9515 err = ice_configure_phy(vsi);
9517 netdev_err(netdev, "Failed to set physical link up, error %d\n",
9522 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
9523 ice_set_link(vsi, false);
9526 err = ice_vsi_open(vsi);
9528 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
9529 vsi->vsi_num, vsi->vsw->sw_id);
9531 /* Update existing tunnels information */
9532 udp_tunnel_get_rx_info(netdev);
9538 * ice_stop - Disables a network interface
9539 * @netdev: network interface device structure
9541 * The stop entry point is called when an interface is de-activated by the OS,
9542 * and the netdevice enters the DOWN state. The hardware is still under the
9543 * driver's control, but the netdev interface is disabled.
9545 * Returns success only - not allowed to fail
9547 int ice_stop(struct net_device *netdev)
9549 struct ice_netdev_priv *np = netdev_priv(netdev);
9550 struct ice_vsi *vsi = np->vsi;
9551 struct ice_pf *pf = vsi->back;
9553 if (ice_is_reset_in_progress(pf->state)) {
9554 netdev_err(netdev, "can't stop net device while reset is in progress");
9558 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
9559 int link_err = ice_force_phys_link_state(vsi, false);
9562 if (link_err == -ENOMEDIUM)
9563 netdev_info(vsi->netdev, "Skipping link reconfig - no media attached, VSI %d\n",
9566 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
9567 vsi->vsi_num, link_err);
9580 * ice_features_check - Validate encapsulated packet conforms to limits
9582 * @netdev: This port's netdev
9583 * @features: Offload features that the stack believes apply
9585 static netdev_features_t
9586 ice_features_check(struct sk_buff *skb,
9587 struct net_device __always_unused *netdev,
9588 netdev_features_t features)
9590 bool gso = skb_is_gso(skb);
9593 /* No point in doing any of this if neither checksum nor GSO are
9594 * being requested for this frame. We can rule out both by just
9595 * checking for CHECKSUM_PARTIAL
9597 if (skb->ip_summed != CHECKSUM_PARTIAL)
9600 /* We cannot support GSO if the MSS is going to be less than
9601 * 64 bytes. If it is then we need to drop support for GSO.
9603 if (gso && (skb_shinfo(skb)->gso_size < ICE_TXD_CTX_MIN_MSS))
9604 features &= ~NETIF_F_GSO_MASK;
9606 len = skb_network_offset(skb);
9607 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
9608 goto out_rm_features;
9610 len = skb_network_header_len(skb);
9611 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
9612 goto out_rm_features;
9614 if (skb->encapsulation) {
9615 /* this must work for VXLAN frames AND IPIP/SIT frames, and in
9616 * the case of IPIP frames, the transport header pointer is
9617 * after the inner header! So check to make sure that this
9618 * is a GRE or UDP_TUNNEL frame before doing that math.
9620 if (gso && (skb_shinfo(skb)->gso_type &
9621 (SKB_GSO_GRE | SKB_GSO_UDP_TUNNEL))) {
9622 len = skb_inner_network_header(skb) -
9623 skb_transport_header(skb);
9624 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
9625 goto out_rm_features;
9628 len = skb_inner_network_header_len(skb);
9629 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
9630 goto out_rm_features;
9635 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
9638 static const struct net_device_ops ice_netdev_safe_mode_ops = {
9639 .ndo_open = ice_open,
9640 .ndo_stop = ice_stop,
9641 .ndo_start_xmit = ice_start_xmit,
9642 .ndo_set_mac_address = ice_set_mac_address,
9643 .ndo_validate_addr = eth_validate_addr,
9644 .ndo_change_mtu = ice_change_mtu,
9645 .ndo_get_stats64 = ice_get_stats64,
9646 .ndo_tx_timeout = ice_tx_timeout,
9647 .ndo_bpf = ice_xdp_safe_mode,
9650 static const struct net_device_ops ice_netdev_ops = {
9651 .ndo_open = ice_open,
9652 .ndo_stop = ice_stop,
9653 .ndo_start_xmit = ice_start_xmit,
9654 .ndo_select_queue = ice_select_queue,
9655 .ndo_features_check = ice_features_check,
9656 .ndo_fix_features = ice_fix_features,
9657 .ndo_set_rx_mode = ice_set_rx_mode,
9658 .ndo_set_mac_address = ice_set_mac_address,
9659 .ndo_validate_addr = eth_validate_addr,
9660 .ndo_change_mtu = ice_change_mtu,
9661 .ndo_get_stats64 = ice_get_stats64,
9662 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
9663 .ndo_eth_ioctl = ice_eth_ioctl,
9664 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
9665 .ndo_set_vf_mac = ice_set_vf_mac,
9666 .ndo_get_vf_config = ice_get_vf_cfg,
9667 .ndo_set_vf_trust = ice_set_vf_trust,
9668 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
9669 .ndo_set_vf_link_state = ice_set_vf_link_state,
9670 .ndo_get_vf_stats = ice_get_vf_stats,
9671 .ndo_set_vf_rate = ice_set_vf_bw,
9672 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
9673 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
9674 .ndo_setup_tc = ice_setup_tc,
9675 .ndo_set_features = ice_set_features,
9676 .ndo_bridge_getlink = ice_bridge_getlink,
9677 .ndo_bridge_setlink = ice_bridge_setlink,
9678 .ndo_fdb_add = ice_fdb_add,
9679 .ndo_fdb_del = ice_fdb_del,
9680 #ifdef CONFIG_RFS_ACCEL
9681 .ndo_rx_flow_steer = ice_rx_flow_steer,
9683 .ndo_tx_timeout = ice_tx_timeout,
9685 .ndo_xdp_xmit = ice_xdp_xmit,
9686 .ndo_xsk_wakeup = ice_xsk_wakeup,