1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018, Intel Corporation. */
4 /* Intel(R) Ethernet Connection E800 Series Linux Driver */
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <generated/utsrelease.h>
13 #include "ice_dcb_lib.h"
14 #include "ice_dcb_nl.h"
15 #include "ice_devlink.h"
16 /* Including ice_trace.h with CREATE_TRACE_POINTS defined will generate the
17 * ice tracepoint functions. This must be done exactly once across the
20 #define CREATE_TRACE_POINTS
21 #include "ice_trace.h"
22 #include "ice_eswitch.h"
23 #include "ice_tc_lib.h"
24 #include "ice_vsi_vlan_ops.h"
26 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
27 static const char ice_driver_string[] = DRV_SUMMARY;
28 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
30 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
31 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
32 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
35 MODULE_DESCRIPTION(DRV_SUMMARY);
36 MODULE_LICENSE("GPL v2");
37 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
39 static int debug = -1;
40 module_param(debug, int, 0644);
41 #ifndef CONFIG_DYNAMIC_DEBUG
42 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
44 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
45 #endif /* !CONFIG_DYNAMIC_DEBUG */
47 static DEFINE_IDA(ice_aux_ida);
48 DEFINE_STATIC_KEY_FALSE(ice_xdp_locking_key);
49 EXPORT_SYMBOL(ice_xdp_locking_key);
51 static struct workqueue_struct *ice_wq;
52 static const struct net_device_ops ice_netdev_safe_mode_ops;
53 static const struct net_device_ops ice_netdev_ops;
55 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
57 static void ice_vsi_release_all(struct ice_pf *pf);
59 static int ice_rebuild_channels(struct ice_pf *pf);
60 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_adv_fltr);
63 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
64 void *cb_priv, enum tc_setup_type type, void *type_data,
66 void (*cleanup)(struct flow_block_cb *block_cb));
68 bool netif_is_ice(struct net_device *dev)
70 return dev && (dev->netdev_ops == &ice_netdev_ops);
74 * ice_get_tx_pending - returns number of Tx descriptors not processed
75 * @ring: the ring of descriptors
77 static u16 ice_get_tx_pending(struct ice_tx_ring *ring)
81 head = ring->next_to_clean;
82 tail = ring->next_to_use;
85 return (head < tail) ?
86 tail - head : (tail + ring->count - head);
91 * ice_check_for_hang_subtask - check for and recover hung queues
92 * @pf: pointer to PF struct
94 static void ice_check_for_hang_subtask(struct ice_pf *pf)
96 struct ice_vsi *vsi = NULL;
102 ice_for_each_vsi(pf, v)
103 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
108 if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state))
111 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
116 ice_for_each_txq(vsi, i) {
117 struct ice_tx_ring *tx_ring = vsi->tx_rings[i];
121 if (ice_ring_ch_enabled(tx_ring))
125 /* If packet counter has not changed the queue is
126 * likely stalled, so force an interrupt for this
129 * prev_pkt would be negative if there was no
132 packets = tx_ring->stats.pkts & INT_MAX;
133 if (tx_ring->tx_stats.prev_pkt == packets) {
134 /* Trigger sw interrupt to revive the queue */
135 ice_trigger_sw_intr(hw, tx_ring->q_vector);
139 /* Memory barrier between read of packet count and call
140 * to ice_get_tx_pending()
143 tx_ring->tx_stats.prev_pkt =
144 ice_get_tx_pending(tx_ring) ? packets : -1;
150 * ice_init_mac_fltr - Set initial MAC filters
151 * @pf: board private structure
153 * Set initial set of MAC filters for PF VSI; configure filters for permanent
154 * address and broadcast address. If an error is encountered, netdevice will be
157 static int ice_init_mac_fltr(struct ice_pf *pf)
162 vsi = ice_get_main_vsi(pf);
166 perm_addr = vsi->port_info->mac.perm_addr;
167 return ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
171 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
172 * @netdev: the net device on which the sync is happening
173 * @addr: MAC address to sync
175 * This is a callback function which is called by the in kernel device sync
176 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
177 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
178 * MAC filters from the hardware.
180 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
182 struct ice_netdev_priv *np = netdev_priv(netdev);
183 struct ice_vsi *vsi = np->vsi;
185 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
193 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
194 * @netdev: the net device on which the unsync is happening
195 * @addr: MAC address to unsync
197 * This is a callback function which is called by the in kernel device unsync
198 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
199 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
200 * delete the MAC filters from the hardware.
202 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
204 struct ice_netdev_priv *np = netdev_priv(netdev);
205 struct ice_vsi *vsi = np->vsi;
207 /* Under some circumstances, we might receive a request to delete our
208 * own device address from our uc list. Because we store the device
209 * address in the VSI's MAC filter list, we need to ignore such
210 * requests and not delete our device address from this list.
212 if (ether_addr_equal(addr, netdev->dev_addr))
215 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
223 * ice_vsi_fltr_changed - check if filter state changed
224 * @vsi: VSI to be checked
226 * returns true if filter state has changed, false otherwise.
228 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
230 return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) ||
231 test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state) ||
232 test_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
236 * ice_set_promisc - Enable promiscuous mode for a given PF
237 * @vsi: the VSI being configured
238 * @promisc_m: mask of promiscuous config bits
241 static int ice_set_promisc(struct ice_vsi *vsi, u8 promisc_m)
245 if (vsi->type != ICE_VSI_PF)
248 if (ice_vsi_has_non_zero_vlans(vsi))
249 status = ice_fltr_set_vlan_vsi_promisc(&vsi->back->hw, vsi, promisc_m);
251 status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m, 0);
256 * ice_clear_promisc - Disable promiscuous mode for a given PF
257 * @vsi: the VSI being configured
258 * @promisc_m: mask of promiscuous config bits
261 static int ice_clear_promisc(struct ice_vsi *vsi, u8 promisc_m)
265 if (vsi->type != ICE_VSI_PF)
268 if (ice_vsi_has_non_zero_vlans(vsi))
269 status = ice_fltr_clear_vlan_vsi_promisc(&vsi->back->hw, vsi, promisc_m);
271 status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m, 0);
276 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
277 * @vsi: ptr to the VSI
279 * Push any outstanding VSI filter changes through the AdminQ.
281 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
283 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
284 struct device *dev = ice_pf_to_dev(vsi->back);
285 struct net_device *netdev = vsi->netdev;
286 bool promisc_forced_on = false;
287 struct ice_pf *pf = vsi->back;
288 struct ice_hw *hw = &pf->hw;
289 u32 changed_flags = 0;
296 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
297 usleep_range(1000, 2000);
299 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
300 vsi->current_netdev_flags = vsi->netdev->flags;
302 INIT_LIST_HEAD(&vsi->tmp_sync_list);
303 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
305 if (ice_vsi_fltr_changed(vsi)) {
306 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
307 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
308 clear_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
310 /* grab the netdev's addr_list_lock */
311 netif_addr_lock_bh(netdev);
312 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
313 ice_add_mac_to_unsync_list);
314 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
315 ice_add_mac_to_unsync_list);
316 /* our temp lists are populated. release lock */
317 netif_addr_unlock_bh(netdev);
320 /* Remove MAC addresses in the unsync list */
321 err = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
322 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
324 netdev_err(netdev, "Failed to delete MAC filters\n");
325 /* if we failed because of alloc failures, just bail */
330 /* Add MAC addresses in the sync list */
331 err = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
332 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
333 /* If filter is added successfully or already exists, do not go into
334 * 'if' condition and report it as error. Instead continue processing
335 * rest of the function.
337 if (err && err != -EEXIST) {
338 netdev_err(netdev, "Failed to add MAC filters\n");
339 /* If there is no more space for new umac filters, VSI
340 * should go into promiscuous mode. There should be some
341 * space reserved for promiscuous filters.
343 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
344 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC,
346 promisc_forced_on = true;
347 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
354 /* check for changes in promiscuous modes */
355 if (changed_flags & IFF_ALLMULTI) {
356 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
357 if (ice_vsi_has_non_zero_vlans(vsi))
358 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
360 promisc_m = ICE_MCAST_PROMISC_BITS;
362 err = ice_set_promisc(vsi, promisc_m);
364 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
366 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
370 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
371 if (ice_vsi_has_non_zero_vlans(vsi))
372 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
374 promisc_m = ICE_MCAST_PROMISC_BITS;
376 err = ice_clear_promisc(vsi, promisc_m);
378 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
380 vsi->current_netdev_flags |= IFF_ALLMULTI;
386 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
387 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) {
388 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
389 if (vsi->current_netdev_flags & IFF_PROMISC) {
390 /* Apply Rx filter rule to get traffic from wire */
391 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) {
392 err = ice_set_dflt_vsi(pf->first_sw, vsi);
393 if (err && err != -EEXIST) {
394 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
396 vsi->current_netdev_flags &=
401 vlan_ops->dis_rx_filtering(vsi);
404 /* Clear Rx filter to remove traffic from wire */
405 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) {
406 err = ice_clear_dflt_vsi(pf->first_sw);
408 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
410 vsi->current_netdev_flags |=
414 if (vsi->current_netdev_flags &
415 NETIF_F_HW_VLAN_CTAG_FILTER)
416 vlan_ops->ena_rx_filtering(vsi);
423 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
426 /* if something went wrong then set the changed flag so we try again */
427 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
428 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
430 clear_bit(ICE_CFG_BUSY, vsi->state);
435 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
436 * @pf: board private structure
438 static void ice_sync_fltr_subtask(struct ice_pf *pf)
442 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
445 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
447 ice_for_each_vsi(pf, v)
448 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
449 ice_vsi_sync_fltr(pf->vsi[v])) {
450 /* come back and try again later */
451 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
457 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
459 * @locked: is the rtnl_lock already held
461 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
466 ice_for_each_vsi(pf, v)
468 ice_dis_vsi(pf->vsi[v], locked);
470 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++)
471 pf->pf_agg_node[node].num_vsis = 0;
473 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++)
474 pf->vf_agg_node[node].num_vsis = 0;
478 * ice_clear_sw_switch_recipes - clear switch recipes
479 * @pf: board private structure
481 * Mark switch recipes as not created in sw structures. There are cases where
482 * rules (especially advanced rules) need to be restored, either re-read from
483 * hardware or added again. For example after the reset. 'recp_created' flag
484 * prevents from doing that and need to be cleared upfront.
486 static void ice_clear_sw_switch_recipes(struct ice_pf *pf)
488 struct ice_sw_recipe *recp;
491 recp = pf->hw.switch_info->recp_list;
492 for (i = 0; i < ICE_MAX_NUM_RECIPES; i++)
493 recp[i].recp_created = false;
497 * ice_prepare_for_reset - prep for reset
498 * @pf: board private structure
499 * @reset_type: reset type requested
501 * Inform or close all dependent features in prep for reset.
504 ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
506 struct ice_hw *hw = &pf->hw;
510 dev_dbg(ice_pf_to_dev(pf), "reset_type=%d\n", reset_type);
512 /* already prepared for reset */
513 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state))
516 ice_unplug_aux_dev(pf);
518 /* Notify VFs of impending reset */
519 if (ice_check_sq_alive(hw, &hw->mailboxq))
520 ice_vc_notify_reset(pf);
522 /* Disable VFs until reset is completed */
523 ice_for_each_vf(pf, i)
524 ice_set_vf_state_qs_dis(&pf->vf[i]);
526 if (ice_is_eswitch_mode_switchdev(pf)) {
527 if (reset_type != ICE_RESET_PFR)
528 ice_clear_sw_switch_recipes(pf);
531 /* release ADQ specific HW and SW resources */
532 vsi = ice_get_main_vsi(pf);
536 /* to be on safe side, reset orig_rss_size so that normal flow
537 * of deciding rss_size can take precedence
539 vsi->orig_rss_size = 0;
541 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
542 if (reset_type == ICE_RESET_PFR) {
543 vsi->old_ena_tc = vsi->all_enatc;
544 vsi->old_numtc = vsi->all_numtc;
546 ice_remove_q_channels(vsi, true);
548 /* for other reset type, do not support channel rebuild
549 * hence reset needed info
557 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
558 memset(&vsi->mqprio_qopt, 0, sizeof(vsi->mqprio_qopt));
563 /* clear SW filtering DB */
564 ice_clear_hw_tbls(hw);
565 /* disable the VSIs and their queues that are not already DOWN */
566 ice_pf_dis_all_vsi(pf, false);
568 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
569 ice_ptp_prepare_for_reset(pf);
572 ice_sched_clear_port(hw->port_info);
574 ice_shutdown_all_ctrlq(hw);
576 set_bit(ICE_PREPARED_FOR_RESET, pf->state);
580 * ice_do_reset - Initiate one of many types of resets
581 * @pf: board private structure
582 * @reset_type: reset type requested before this function was called.
584 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
586 struct device *dev = ice_pf_to_dev(pf);
587 struct ice_hw *hw = &pf->hw;
589 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
591 ice_prepare_for_reset(pf, reset_type);
593 /* trigger the reset */
594 if (ice_reset(hw, reset_type)) {
595 dev_err(dev, "reset %d failed\n", reset_type);
596 set_bit(ICE_RESET_FAILED, pf->state);
597 clear_bit(ICE_RESET_OICR_RECV, pf->state);
598 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
599 clear_bit(ICE_PFR_REQ, pf->state);
600 clear_bit(ICE_CORER_REQ, pf->state);
601 clear_bit(ICE_GLOBR_REQ, pf->state);
602 wake_up(&pf->reset_wait_queue);
606 /* PFR is a bit of a special case because it doesn't result in an OICR
607 * interrupt. So for PFR, rebuild after the reset and clear the reset-
608 * associated state bits.
610 if (reset_type == ICE_RESET_PFR) {
612 ice_rebuild(pf, reset_type);
613 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
614 clear_bit(ICE_PFR_REQ, pf->state);
615 wake_up(&pf->reset_wait_queue);
616 ice_reset_all_vfs(pf, true);
621 * ice_reset_subtask - Set up for resetting the device and driver
622 * @pf: board private structure
624 static void ice_reset_subtask(struct ice_pf *pf)
626 enum ice_reset_req reset_type = ICE_RESET_INVAL;
628 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
629 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
630 * of reset is pending and sets bits in pf->state indicating the reset
631 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set
632 * prepare for pending reset if not already (for PF software-initiated
633 * global resets the software should already be prepared for it as
634 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated
635 * by firmware or software on other PFs, that bit is not set so prepare
636 * for the reset now), poll for reset done, rebuild and return.
638 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) {
639 /* Perform the largest reset requested */
640 if (test_and_clear_bit(ICE_CORER_RECV, pf->state))
641 reset_type = ICE_RESET_CORER;
642 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state))
643 reset_type = ICE_RESET_GLOBR;
644 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state))
645 reset_type = ICE_RESET_EMPR;
646 /* return if no valid reset type requested */
647 if (reset_type == ICE_RESET_INVAL)
649 ice_prepare_for_reset(pf, reset_type);
651 /* make sure we are ready to rebuild */
652 if (ice_check_reset(&pf->hw)) {
653 set_bit(ICE_RESET_FAILED, pf->state);
655 /* done with reset. start rebuild */
656 pf->hw.reset_ongoing = false;
657 ice_rebuild(pf, reset_type);
658 /* clear bit to resume normal operations, but
659 * ICE_NEEDS_RESTART bit is set in case rebuild failed
661 clear_bit(ICE_RESET_OICR_RECV, pf->state);
662 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
663 clear_bit(ICE_PFR_REQ, pf->state);
664 clear_bit(ICE_CORER_REQ, pf->state);
665 clear_bit(ICE_GLOBR_REQ, pf->state);
666 wake_up(&pf->reset_wait_queue);
667 ice_reset_all_vfs(pf, true);
673 /* No pending resets to finish processing. Check for new resets */
674 if (test_bit(ICE_PFR_REQ, pf->state))
675 reset_type = ICE_RESET_PFR;
676 if (test_bit(ICE_CORER_REQ, pf->state))
677 reset_type = ICE_RESET_CORER;
678 if (test_bit(ICE_GLOBR_REQ, pf->state))
679 reset_type = ICE_RESET_GLOBR;
680 /* If no valid reset type requested just return */
681 if (reset_type == ICE_RESET_INVAL)
684 /* reset if not already down or busy */
685 if (!test_bit(ICE_DOWN, pf->state) &&
686 !test_bit(ICE_CFG_BUSY, pf->state)) {
687 ice_do_reset(pf, reset_type);
692 * ice_print_topo_conflict - print topology conflict message
693 * @vsi: the VSI whose topology status is being checked
695 static void ice_print_topo_conflict(struct ice_vsi *vsi)
697 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
698 case ICE_AQ_LINK_TOPO_CONFLICT:
699 case ICE_AQ_LINK_MEDIA_CONFLICT:
700 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
701 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
702 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
703 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");
705 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
706 if (test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, vsi->back->flags))
707 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");
709 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");
717 * ice_print_link_msg - print link up or down message
718 * @vsi: the VSI whose link status is being queried
719 * @isup: boolean for if the link is now up or down
721 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
723 struct ice_aqc_get_phy_caps_data *caps;
724 const char *an_advertised;
735 if (vsi->current_isup == isup)
738 vsi->current_isup = isup;
741 netdev_info(vsi->netdev, "NIC Link is Down\n");
745 switch (vsi->port_info->phy.link_info.link_speed) {
746 case ICE_AQ_LINK_SPEED_100GB:
749 case ICE_AQ_LINK_SPEED_50GB:
752 case ICE_AQ_LINK_SPEED_40GB:
755 case ICE_AQ_LINK_SPEED_25GB:
758 case ICE_AQ_LINK_SPEED_20GB:
761 case ICE_AQ_LINK_SPEED_10GB:
764 case ICE_AQ_LINK_SPEED_5GB:
767 case ICE_AQ_LINK_SPEED_2500MB:
770 case ICE_AQ_LINK_SPEED_1000MB:
773 case ICE_AQ_LINK_SPEED_100MB:
781 switch (vsi->port_info->fc.current_mode) {
785 case ICE_FC_TX_PAUSE:
788 case ICE_FC_RX_PAUSE:
799 /* Get FEC mode based on negotiated link info */
800 switch (vsi->port_info->phy.link_info.fec_info) {
801 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
802 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
805 case ICE_AQ_LINK_25G_KR_FEC_EN:
806 fec = "FC-FEC/BASE-R";
813 /* check if autoneg completed, might be false due to not supported */
814 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
819 /* Get FEC mode requested based on PHY caps last SW configuration */
820 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
823 an_advertised = "Unknown";
827 status = ice_aq_get_phy_caps(vsi->port_info, false,
828 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
830 netdev_info(vsi->netdev, "Get phy capability failed.\n");
832 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off";
834 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
835 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
837 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
838 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
839 fec_req = "FC-FEC/BASE-R";
846 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",
847 speed, fec_req, fec, an_advertised, an, fc);
848 ice_print_topo_conflict(vsi);
852 * ice_vsi_link_event - update the VSI's netdev
853 * @vsi: the VSI on which the link event occurred
854 * @link_up: whether or not the VSI needs to be set up or down
856 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
861 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev)
864 if (vsi->type == ICE_VSI_PF) {
865 if (link_up == netif_carrier_ok(vsi->netdev))
869 netif_carrier_on(vsi->netdev);
870 netif_tx_wake_all_queues(vsi->netdev);
872 netif_carrier_off(vsi->netdev);
873 netif_tx_stop_all_queues(vsi->netdev);
879 * ice_set_dflt_mib - send a default config MIB to the FW
880 * @pf: private PF struct
882 * This function sends a default configuration MIB to the FW.
884 * If this function errors out at any point, the driver is still able to
885 * function. The main impact is that LFC may not operate as expected.
886 * Therefore an error state in this function should be treated with a DBG
887 * message and continue on with driver rebuild/reenable.
889 static void ice_set_dflt_mib(struct ice_pf *pf)
891 struct device *dev = ice_pf_to_dev(pf);
892 u8 mib_type, *buf, *lldpmib = NULL;
893 u16 len, typelen, offset = 0;
894 struct ice_lldp_org_tlv *tlv;
895 struct ice_hw *hw = &pf->hw;
898 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
899 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
901 dev_dbg(dev, "%s Failed to allocate MIB memory\n",
906 /* Add ETS CFG TLV */
907 tlv = (struct ice_lldp_org_tlv *)lldpmib;
908 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
909 ICE_IEEE_ETS_TLV_LEN);
910 tlv->typelen = htons(typelen);
911 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
912 ICE_IEEE_SUBTYPE_ETS_CFG);
913 tlv->ouisubtype = htonl(ouisubtype);
918 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0.
919 * Octets 5 - 12 are BW values, set octet 5 to 100% BW.
920 * Octets 13 - 20 are TSA values - leave as zeros
923 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
925 tlv = (struct ice_lldp_org_tlv *)
926 ((char *)tlv + sizeof(tlv->typelen) + len);
928 /* Add ETS REC TLV */
930 tlv->typelen = htons(typelen);
932 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
933 ICE_IEEE_SUBTYPE_ETS_REC);
934 tlv->ouisubtype = htonl(ouisubtype);
936 /* First octet of buf is reserved
937 * Octets 1 - 4 map UP to TC - all UPs map to zero
938 * Octets 5 - 12 are BW values - set TC 0 to 100%.
939 * Octets 13 - 20 are TSA value - leave as zeros
943 tlv = (struct ice_lldp_org_tlv *)
944 ((char *)tlv + sizeof(tlv->typelen) + len);
946 /* Add PFC CFG TLV */
947 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
948 ICE_IEEE_PFC_TLV_LEN);
949 tlv->typelen = htons(typelen);
951 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
952 ICE_IEEE_SUBTYPE_PFC_CFG);
953 tlv->ouisubtype = htonl(ouisubtype);
955 /* Octet 1 left as all zeros - PFC disabled */
957 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
960 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL))
961 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__);
967 * ice_check_phy_fw_load - check if PHY FW load failed
968 * @pf: pointer to PF struct
969 * @link_cfg_err: bitmap from the link info structure
971 * check if external PHY FW load failed and print an error message if it did
973 static void ice_check_phy_fw_load(struct ice_pf *pf, u8 link_cfg_err)
975 if (!(link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE)) {
976 clear_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
980 if (test_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags))
983 if (link_cfg_err & ICE_AQ_LINK_EXTERNAL_PHY_LOAD_FAILURE) {
984 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");
985 set_bit(ICE_FLAG_PHY_FW_LOAD_FAILED, pf->flags);
990 * ice_check_module_power
991 * @pf: pointer to PF struct
992 * @link_cfg_err: bitmap from the link info structure
994 * check module power level returned by a previous call to aq_get_link_info
995 * and print error messages if module power level is not supported
997 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err)
999 /* if module power level is supported, clear the flag */
1000 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT |
1001 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) {
1002 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1006 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the
1007 * above block didn't clear this bit, there's nothing to do
1009 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags))
1012 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) {
1013 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n");
1014 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1015 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) {
1016 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n");
1017 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
1022 * ice_check_link_cfg_err - check if link configuration failed
1023 * @pf: pointer to the PF struct
1024 * @link_cfg_err: bitmap from the link info structure
1026 * print if any link configuration failure happens due to the value in the
1027 * link_cfg_err parameter in the link info structure
1029 static void ice_check_link_cfg_err(struct ice_pf *pf, u8 link_cfg_err)
1031 ice_check_module_power(pf, link_cfg_err);
1032 ice_check_phy_fw_load(pf, link_cfg_err);
1036 * ice_link_event - process the link event
1037 * @pf: PF that the link event is associated with
1038 * @pi: port_info for the port that the link event is associated with
1039 * @link_up: true if the physical link is up and false if it is down
1040 * @link_speed: current link speed received from the link event
1042 * Returns 0 on success and negative on failure
1045 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
1048 struct device *dev = ice_pf_to_dev(pf);
1049 struct ice_phy_info *phy_info;
1050 struct ice_vsi *vsi;
1055 phy_info = &pi->phy;
1056 phy_info->link_info_old = phy_info->link_info;
1058 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
1059 old_link_speed = phy_info->link_info_old.link_speed;
1061 /* update the link info structures and re-enable link events,
1062 * don't bail on failure due to other book keeping needed
1064 status = ice_update_link_info(pi);
1066 dev_dbg(dev, "Failed to update link status on port %d, err %d aq_err %s\n",
1068 ice_aq_str(pi->hw->adminq.sq_last_status));
1070 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
1072 /* Check if the link state is up after updating link info, and treat
1073 * this event as an UP event since the link is actually UP now.
1075 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
1078 vsi = ice_get_main_vsi(pf);
1079 if (!vsi || !vsi->port_info)
1082 /* turn off PHY if media was removed */
1083 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
1084 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
1085 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
1086 ice_set_link(vsi, false);
1089 /* if the old link up/down and speed is the same as the new */
1090 if (link_up == old_link && link_speed == old_link_speed)
1093 if (!ice_is_e810(&pf->hw))
1094 ice_ptp_link_change(pf, pf->hw.pf_id, link_up);
1096 if (ice_is_dcb_active(pf)) {
1097 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
1098 ice_dcb_rebuild(pf);
1101 ice_set_dflt_mib(pf);
1103 ice_vsi_link_event(vsi, link_up);
1104 ice_print_link_msg(vsi, link_up);
1106 ice_vc_notify_link_state(pf);
1112 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
1113 * @pf: board private structure
1115 static void ice_watchdog_subtask(struct ice_pf *pf)
1119 /* if interface is down do nothing */
1120 if (test_bit(ICE_DOWN, pf->state) ||
1121 test_bit(ICE_CFG_BUSY, pf->state))
1124 /* make sure we don't do these things too often */
1125 if (time_before(jiffies,
1126 pf->serv_tmr_prev + pf->serv_tmr_period))
1129 pf->serv_tmr_prev = jiffies;
1131 /* Update the stats for active netdevs so the network stack
1132 * can look at updated numbers whenever it cares to
1134 ice_update_pf_stats(pf);
1135 ice_for_each_vsi(pf, i)
1136 if (pf->vsi[i] && pf->vsi[i]->netdev)
1137 ice_update_vsi_stats(pf->vsi[i]);
1141 * ice_init_link_events - enable/initialize link events
1142 * @pi: pointer to the port_info instance
1144 * Returns -EIO on failure, 0 on success
1146 static int ice_init_link_events(struct ice_port_info *pi)
1150 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
1151 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL |
1152 ICE_AQ_LINK_EVENT_PHY_FW_LOAD_FAIL));
1154 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
1155 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
1160 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
1161 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
1170 * ice_handle_link_event - handle link event via ARQ
1171 * @pf: PF that the link event is associated with
1172 * @event: event structure containing link status info
1175 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1177 struct ice_aqc_get_link_status_data *link_data;
1178 struct ice_port_info *port_info;
1181 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
1182 port_info = pf->hw.port_info;
1186 status = ice_link_event(pf, port_info,
1187 !!(link_data->link_info & ICE_AQ_LINK_UP),
1188 le16_to_cpu(link_data->link_speed));
1190 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
1196 enum ice_aq_task_state {
1197 ICE_AQ_TASK_WAITING = 0,
1198 ICE_AQ_TASK_COMPLETE,
1199 ICE_AQ_TASK_CANCELED,
1202 struct ice_aq_task {
1203 struct hlist_node entry;
1206 struct ice_rq_event_info *event;
1207 enum ice_aq_task_state state;
1211 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1212 * @pf: pointer to the PF private structure
1213 * @opcode: the opcode to wait for
1214 * @timeout: how long to wait, in jiffies
1215 * @event: storage for the event info
1217 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1218 * current thread will be put to sleep until the specified event occurs or
1219 * until the given timeout is reached.
1221 * To obtain only the descriptor contents, pass an event without an allocated
1222 * msg_buf. If the complete data buffer is desired, allocate the
1223 * event->msg_buf with enough space ahead of time.
1225 * Returns: zero on success, or a negative error code on failure.
1227 int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout,
1228 struct ice_rq_event_info *event)
1230 struct device *dev = ice_pf_to_dev(pf);
1231 struct ice_aq_task *task;
1232 unsigned long start;
1236 task = kzalloc(sizeof(*task), GFP_KERNEL);
1240 INIT_HLIST_NODE(&task->entry);
1241 task->opcode = opcode;
1242 task->event = event;
1243 task->state = ICE_AQ_TASK_WAITING;
1245 spin_lock_bh(&pf->aq_wait_lock);
1246 hlist_add_head(&task->entry, &pf->aq_wait_list);
1247 spin_unlock_bh(&pf->aq_wait_lock);
1251 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state,
1253 switch (task->state) {
1254 case ICE_AQ_TASK_WAITING:
1255 err = ret < 0 ? ret : -ETIMEDOUT;
1257 case ICE_AQ_TASK_CANCELED:
1258 err = ret < 0 ? ret : -ECANCELED;
1260 case ICE_AQ_TASK_COMPLETE:
1261 err = ret < 0 ? ret : 0;
1264 WARN(1, "Unexpected AdminQ wait task state %u", task->state);
1269 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n",
1270 jiffies_to_msecs(jiffies - start),
1271 jiffies_to_msecs(timeout),
1274 spin_lock_bh(&pf->aq_wait_lock);
1275 hlist_del(&task->entry);
1276 spin_unlock_bh(&pf->aq_wait_lock);
1283 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event
1284 * @pf: pointer to the PF private structure
1285 * @opcode: the opcode of the event
1286 * @event: the event to check
1288 * Loops over the current list of pending threads waiting for an AdminQ event.
1289 * For each matching task, copy the contents of the event into the task
1290 * structure and wake up the thread.
1292 * If multiple threads wait for the same opcode, they will all be woken up.
1294 * Note that event->msg_buf will only be duplicated if the event has a buffer
1295 * with enough space already allocated. Otherwise, only the descriptor and
1296 * message length will be copied.
1298 * Returns: true if an event was found, false otherwise
1300 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1301 struct ice_rq_event_info *event)
1303 struct ice_aq_task *task;
1306 spin_lock_bh(&pf->aq_wait_lock);
1307 hlist_for_each_entry(task, &pf->aq_wait_list, entry) {
1308 if (task->state || task->opcode != opcode)
1311 memcpy(&task->event->desc, &event->desc, sizeof(event->desc));
1312 task->event->msg_len = event->msg_len;
1314 /* Only copy the data buffer if a destination was set */
1315 if (task->event->msg_buf &&
1316 task->event->buf_len > event->buf_len) {
1317 memcpy(task->event->msg_buf, event->msg_buf,
1319 task->event->buf_len = event->buf_len;
1322 task->state = ICE_AQ_TASK_COMPLETE;
1325 spin_unlock_bh(&pf->aq_wait_lock);
1328 wake_up(&pf->aq_wait_queue);
1332 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks
1333 * @pf: the PF private structure
1335 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads.
1336 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED.
1338 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
1340 struct ice_aq_task *task;
1342 spin_lock_bh(&pf->aq_wait_lock);
1343 hlist_for_each_entry(task, &pf->aq_wait_list, entry)
1344 task->state = ICE_AQ_TASK_CANCELED;
1345 spin_unlock_bh(&pf->aq_wait_lock);
1347 wake_up(&pf->aq_wait_queue);
1351 * __ice_clean_ctrlq - helper function to clean controlq rings
1352 * @pf: ptr to struct ice_pf
1353 * @q_type: specific Control queue type
1355 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
1357 struct device *dev = ice_pf_to_dev(pf);
1358 struct ice_rq_event_info event;
1359 struct ice_hw *hw = &pf->hw;
1360 struct ice_ctl_q_info *cq;
1365 /* Do not clean control queue if/when PF reset fails */
1366 if (test_bit(ICE_RESET_FAILED, pf->state))
1370 case ICE_CTL_Q_ADMIN:
1378 case ICE_CTL_Q_MAILBOX:
1381 /* we are going to try to detect a malicious VF, so set the
1382 * state to begin detection
1384 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT;
1387 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
1391 /* check for error indications - PF_xx_AxQLEN register layout for
1392 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
1394 val = rd32(hw, cq->rq.len);
1395 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1396 PF_FW_ARQLEN_ARQCRIT_M)) {
1398 if (val & PF_FW_ARQLEN_ARQVFE_M)
1399 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
1401 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1402 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
1405 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1406 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
1408 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1409 PF_FW_ARQLEN_ARQCRIT_M);
1411 wr32(hw, cq->rq.len, val);
1414 val = rd32(hw, cq->sq.len);
1415 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1416 PF_FW_ATQLEN_ATQCRIT_M)) {
1418 if (val & PF_FW_ATQLEN_ATQVFE_M)
1419 dev_dbg(dev, "%s Send Queue VF Error detected\n",
1421 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1422 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1425 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1426 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1428 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1429 PF_FW_ATQLEN_ATQCRIT_M);
1431 wr32(hw, cq->sq.len, val);
1434 event.buf_len = cq->rq_buf_size;
1435 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1443 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1444 if (ret == -EALREADY)
1447 dev_err(dev, "%s Receive Queue event error %d\n", qtype,
1452 opcode = le16_to_cpu(event.desc.opcode);
1454 /* Notify any thread that might be waiting for this event */
1455 ice_aq_check_events(pf, opcode, &event);
1458 case ice_aqc_opc_get_link_status:
1459 if (ice_handle_link_event(pf, &event))
1460 dev_err(dev, "Could not handle link event\n");
1462 case ice_aqc_opc_event_lan_overflow:
1463 ice_vf_lan_overflow_event(pf, &event);
1465 case ice_mbx_opc_send_msg_to_pf:
1466 if (!ice_is_malicious_vf(pf, &event, i, pending))
1467 ice_vc_process_vf_msg(pf, &event);
1469 case ice_aqc_opc_fw_logging:
1470 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1472 case ice_aqc_opc_lldp_set_mib_change:
1473 ice_dcb_process_lldp_set_mib_change(pf, &event);
1476 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1480 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1482 kfree(event.msg_buf);
1484 return pending && (i == ICE_DFLT_IRQ_WORK);
1488 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1489 * @hw: pointer to hardware info
1490 * @cq: control queue information
1492 * returns true if there are pending messages in a queue, false if there aren't
1494 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1498 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1499 return cq->rq.next_to_clean != ntu;
1503 * ice_clean_adminq_subtask - clean the AdminQ rings
1504 * @pf: board private structure
1506 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1508 struct ice_hw *hw = &pf->hw;
1510 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
1513 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1516 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
1518 /* There might be a situation where new messages arrive to a control
1519 * queue between processing the last message and clearing the
1520 * EVENT_PENDING bit. So before exiting, check queue head again (using
1521 * ice_ctrlq_pending) and process new messages if any.
1523 if (ice_ctrlq_pending(hw, &hw->adminq))
1524 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1530 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1531 * @pf: board private structure
1533 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1535 struct ice_hw *hw = &pf->hw;
1537 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1540 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1543 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1545 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1546 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1552 * ice_clean_sbq_subtask - clean the Sideband Queue rings
1553 * @pf: board private structure
1555 static void ice_clean_sbq_subtask(struct ice_pf *pf)
1557 struct ice_hw *hw = &pf->hw;
1559 /* Nothing to do here if sideband queue is not supported */
1560 if (!ice_is_sbq_supported(hw)) {
1561 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1565 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state))
1568 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB))
1571 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1573 if (ice_ctrlq_pending(hw, &hw->sbq))
1574 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB);
1580 * ice_service_task_schedule - schedule the service task to wake up
1581 * @pf: board private structure
1583 * If not already scheduled, this puts the task into the work queue.
1585 void ice_service_task_schedule(struct ice_pf *pf)
1587 if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
1588 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
1589 !test_bit(ICE_NEEDS_RESTART, pf->state))
1590 queue_work(ice_wq, &pf->serv_task);
1594 * ice_service_task_complete - finish up the service task
1595 * @pf: board private structure
1597 static void ice_service_task_complete(struct ice_pf *pf)
1599 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state));
1601 /* force memory (pf->state) to sync before next service task */
1602 smp_mb__before_atomic();
1603 clear_bit(ICE_SERVICE_SCHED, pf->state);
1607 * ice_service_task_stop - stop service task and cancel works
1608 * @pf: board private structure
1610 * Return 0 if the ICE_SERVICE_DIS bit was not already set,
1613 static int ice_service_task_stop(struct ice_pf *pf)
1617 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state);
1619 if (pf->serv_tmr.function)
1620 del_timer_sync(&pf->serv_tmr);
1621 if (pf->serv_task.func)
1622 cancel_work_sync(&pf->serv_task);
1624 clear_bit(ICE_SERVICE_SCHED, pf->state);
1629 * ice_service_task_restart - restart service task and schedule works
1630 * @pf: board private structure
1632 * This function is needed for suspend and resume works (e.g WoL scenario)
1634 static void ice_service_task_restart(struct ice_pf *pf)
1636 clear_bit(ICE_SERVICE_DIS, pf->state);
1637 ice_service_task_schedule(pf);
1641 * ice_service_timer - timer callback to schedule service task
1642 * @t: pointer to timer_list
1644 static void ice_service_timer(struct timer_list *t)
1646 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1648 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1649 ice_service_task_schedule(pf);
1653 * ice_handle_mdd_event - handle malicious driver detect event
1654 * @pf: pointer to the PF structure
1656 * Called from service task. OICR interrupt handler indicates MDD event.
1657 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1658 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1659 * disable the queue, the PF can be configured to reset the VF using ethtool
1660 * private flag mdd-auto-reset-vf.
1662 static void ice_handle_mdd_event(struct ice_pf *pf)
1664 struct device *dev = ice_pf_to_dev(pf);
1665 struct ice_hw *hw = &pf->hw;
1669 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
1670 /* Since the VF MDD event logging is rate limited, check if
1671 * there are pending MDD events.
1673 ice_print_vfs_mdd_events(pf);
1677 /* find what triggered an MDD event */
1678 reg = rd32(hw, GL_MDET_TX_PQM);
1679 if (reg & GL_MDET_TX_PQM_VALID_M) {
1680 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1681 GL_MDET_TX_PQM_PF_NUM_S;
1682 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1683 GL_MDET_TX_PQM_VF_NUM_S;
1684 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1685 GL_MDET_TX_PQM_MAL_TYPE_S;
1686 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1687 GL_MDET_TX_PQM_QNUM_S);
1689 if (netif_msg_tx_err(pf))
1690 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1691 event, queue, pf_num, vf_num);
1692 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1695 reg = rd32(hw, GL_MDET_TX_TCLAN);
1696 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1697 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1698 GL_MDET_TX_TCLAN_PF_NUM_S;
1699 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1700 GL_MDET_TX_TCLAN_VF_NUM_S;
1701 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1702 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1703 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1704 GL_MDET_TX_TCLAN_QNUM_S);
1706 if (netif_msg_tx_err(pf))
1707 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1708 event, queue, pf_num, vf_num);
1709 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1712 reg = rd32(hw, GL_MDET_RX);
1713 if (reg & GL_MDET_RX_VALID_M) {
1714 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1715 GL_MDET_RX_PF_NUM_S;
1716 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1717 GL_MDET_RX_VF_NUM_S;
1718 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1719 GL_MDET_RX_MAL_TYPE_S;
1720 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1723 if (netif_msg_rx_err(pf))
1724 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1725 event, queue, pf_num, vf_num);
1726 wr32(hw, GL_MDET_RX, 0xffffffff);
1729 /* check to see if this PF caused an MDD event */
1730 reg = rd32(hw, PF_MDET_TX_PQM);
1731 if (reg & PF_MDET_TX_PQM_VALID_M) {
1732 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1733 if (netif_msg_tx_err(pf))
1734 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1737 reg = rd32(hw, PF_MDET_TX_TCLAN);
1738 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1739 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1740 if (netif_msg_tx_err(pf))
1741 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1744 reg = rd32(hw, PF_MDET_RX);
1745 if (reg & PF_MDET_RX_VALID_M) {
1746 wr32(hw, PF_MDET_RX, 0xFFFF);
1747 if (netif_msg_rx_err(pf))
1748 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1751 /* Check to see if one of the VFs caused an MDD event, and then
1752 * increment counters and set print pending
1754 ice_for_each_vf(pf, i) {
1755 struct ice_vf *vf = &pf->vf[i];
1757 reg = rd32(hw, VP_MDET_TX_PQM(i));
1758 if (reg & VP_MDET_TX_PQM_VALID_M) {
1759 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1760 vf->mdd_tx_events.count++;
1761 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1762 if (netif_msg_tx_err(pf))
1763 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1767 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1768 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1769 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1770 vf->mdd_tx_events.count++;
1771 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1772 if (netif_msg_tx_err(pf))
1773 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1777 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1778 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1779 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1780 vf->mdd_tx_events.count++;
1781 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1782 if (netif_msg_tx_err(pf))
1783 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1787 reg = rd32(hw, VP_MDET_RX(i));
1788 if (reg & VP_MDET_RX_VALID_M) {
1789 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1790 vf->mdd_rx_events.count++;
1791 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1792 if (netif_msg_rx_err(pf))
1793 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1796 /* Since the queue is disabled on VF Rx MDD events, the
1797 * PF can be configured to reset the VF through ethtool
1798 * private flag mdd-auto-reset-vf.
1800 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) {
1801 /* VF MDD event counters will be cleared by
1802 * reset, so print the event prior to reset.
1804 ice_print_vf_rx_mdd_event(vf);
1805 ice_reset_vf(&pf->vf[i], false);
1810 ice_print_vfs_mdd_events(pf);
1814 * ice_force_phys_link_state - Force the physical link state
1815 * @vsi: VSI to force the physical link state to up/down
1816 * @link_up: true/false indicates to set the physical link to up/down
1818 * Force the physical link state by getting the current PHY capabilities from
1819 * hardware and setting the PHY config based on the determined capabilities. If
1820 * link changes a link event will be triggered because both the Enable Automatic
1821 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1823 * Returns 0 on success, negative on failure
1825 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1827 struct ice_aqc_get_phy_caps_data *pcaps;
1828 struct ice_aqc_set_phy_cfg_data *cfg;
1829 struct ice_port_info *pi;
1833 if (!vsi || !vsi->port_info || !vsi->back)
1835 if (vsi->type != ICE_VSI_PF)
1838 dev = ice_pf_to_dev(vsi->back);
1840 pi = vsi->port_info;
1842 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1846 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1849 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1850 vsi->vsi_num, retcode);
1855 /* No change in link */
1856 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1857 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1860 /* Use the current user PHY configuration. The current user PHY
1861 * configuration is initialized during probe from PHY capabilities
1862 * software mode, and updated on set PHY configuration.
1864 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL);
1870 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1872 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1874 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1876 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL);
1878 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1879 vsi->vsi_num, retcode);
1890 * ice_init_nvm_phy_type - Initialize the NVM PHY type
1891 * @pi: port info structure
1893 * Initialize nvm_phy_type_[low|high] for link lenient mode support
1895 static int ice_init_nvm_phy_type(struct ice_port_info *pi)
1897 struct ice_aqc_get_phy_caps_data *pcaps;
1898 struct ice_pf *pf = pi->hw->back;
1901 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1905 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA,
1909 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
1913 pf->nvm_phy_type_hi = pcaps->phy_type_high;
1914 pf->nvm_phy_type_lo = pcaps->phy_type_low;
1922 * ice_init_link_dflt_override - Initialize link default override
1923 * @pi: port info structure
1925 * Initialize link default override and PHY total port shutdown during probe
1927 static void ice_init_link_dflt_override(struct ice_port_info *pi)
1929 struct ice_link_default_override_tlv *ldo;
1930 struct ice_pf *pf = pi->hw->back;
1932 ldo = &pf->link_dflt_override;
1933 if (ice_get_link_default_override(ldo, pi))
1936 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS))
1939 /* Enable Total Port Shutdown (override/replace link-down-on-close
1940 * ethtool private flag) for ports with Port Disable bit set.
1942 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags);
1943 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1947 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings
1948 * @pi: port info structure
1950 * If default override is enabled, initialize the user PHY cfg speed and FEC
1951 * settings using the default override mask from the NVM.
1953 * The PHY should only be configured with the default override settings the
1954 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state
1955 * is used to indicate that the user PHY cfg default override is initialized
1956 * and the PHY has not been configured with the default override settings. The
1957 * state is set here, and cleared in ice_configure_phy the first time the PHY is
1960 * This function should be called only if the FW doesn't support default
1961 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg.
1963 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi)
1965 struct ice_link_default_override_tlv *ldo;
1966 struct ice_aqc_set_phy_cfg_data *cfg;
1967 struct ice_phy_info *phy = &pi->phy;
1968 struct ice_pf *pf = pi->hw->back;
1970 ldo = &pf->link_dflt_override;
1972 /* If link default override is enabled, use to mask NVM PHY capabilities
1973 * for speed and FEC default configuration.
1975 cfg = &phy->curr_user_phy_cfg;
1977 if (ldo->phy_type_low || ldo->phy_type_high) {
1978 cfg->phy_type_low = pf->nvm_phy_type_lo &
1979 cpu_to_le64(ldo->phy_type_low);
1980 cfg->phy_type_high = pf->nvm_phy_type_hi &
1981 cpu_to_le64(ldo->phy_type_high);
1983 cfg->link_fec_opt = ldo->fec_options;
1984 phy->curr_user_fec_req = ICE_FEC_AUTO;
1986 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state);
1990 * ice_init_phy_user_cfg - Initialize the PHY user configuration
1991 * @pi: port info structure
1993 * Initialize the current user PHY configuration, speed, FEC, and FC requested
1994 * mode to default. The PHY defaults are from get PHY capabilities topology
1995 * with media so call when media is first available. An error is returned if
1996 * called when media is not available. The PHY initialization completed state is
1999 * These configurations are used when setting PHY
2000 * configuration. The user PHY configuration is updated on set PHY
2001 * configuration. Returns 0 on success, negative on failure
2003 static int ice_init_phy_user_cfg(struct ice_port_info *pi)
2005 struct ice_aqc_get_phy_caps_data *pcaps;
2006 struct ice_phy_info *phy = &pi->phy;
2007 struct ice_pf *pf = pi->hw->back;
2010 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2013 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2017 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2018 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2021 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2024 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
2028 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg);
2030 /* check if lenient mode is supported and enabled */
2031 if (ice_fw_supports_link_override(pi->hw) &&
2032 !(pcaps->module_compliance_enforcement &
2033 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) {
2034 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags);
2036 /* if the FW supports default PHY configuration mode, then the driver
2037 * does not have to apply link override settings. If not,
2038 * initialize user PHY configuration with link override values
2040 if (!ice_fw_supports_report_dflt_cfg(pi->hw) &&
2041 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) {
2042 ice_init_phy_cfg_dflt_override(pi);
2047 /* if link default override is not enabled, set user flow control and
2048 * FEC settings based on what get_phy_caps returned
2050 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps,
2051 pcaps->link_fec_options);
2052 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps);
2055 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M;
2056 set_bit(ICE_PHY_INIT_COMPLETE, pf->state);
2063 * ice_configure_phy - configure PHY
2066 * Set the PHY configuration. If the current PHY configuration is the same as
2067 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise
2068 * configure the based get PHY capabilities for topology with media.
2070 static int ice_configure_phy(struct ice_vsi *vsi)
2072 struct device *dev = ice_pf_to_dev(vsi->back);
2073 struct ice_port_info *pi = vsi->port_info;
2074 struct ice_aqc_get_phy_caps_data *pcaps;
2075 struct ice_aqc_set_phy_cfg_data *cfg;
2076 struct ice_phy_info *phy = &pi->phy;
2077 struct ice_pf *pf = vsi->back;
2080 /* Ensure we have media as we cannot configure a medialess port */
2081 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
2084 ice_print_topo_conflict(vsi);
2086 if (!test_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags) &&
2087 phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA)
2090 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags))
2091 return ice_force_phys_link_state(vsi, true);
2093 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
2097 /* Get current PHY config */
2098 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
2101 dev_err(dev, "Failed to get PHY configuration, VSI %d error %d\n",
2106 /* If PHY enable link is configured and configuration has not changed,
2107 * there's nothing to do
2109 if (pcaps->caps & ICE_AQC_PHY_EN_LINK &&
2110 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg))
2113 /* Use PHY topology as baseline for configuration */
2114 memset(pcaps, 0, sizeof(*pcaps));
2115 if (ice_fw_supports_report_dflt_cfg(pi->hw))
2116 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
2119 err = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
2122 dev_err(dev, "Failed to get PHY caps, VSI %d error %d\n",
2127 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2133 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg);
2135 /* Speed - If default override pending, use curr_user_phy_cfg set in
2136 * ice_init_phy_user_cfg_ldo.
2138 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING,
2139 vsi->back->state)) {
2140 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low;
2141 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high;
2143 u64 phy_low = 0, phy_high = 0;
2145 ice_update_phy_type(&phy_low, &phy_high,
2146 pi->phy.curr_user_speed_req);
2147 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low);
2148 cfg->phy_type_high = pcaps->phy_type_high &
2149 cpu_to_le64(phy_high);
2152 /* Can't provide what was requested; use PHY capabilities */
2153 if (!cfg->phy_type_low && !cfg->phy_type_high) {
2154 cfg->phy_type_low = pcaps->phy_type_low;
2155 cfg->phy_type_high = pcaps->phy_type_high;
2159 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req);
2161 /* Can't provide what was requested; use PHY capabilities */
2162 if (cfg->link_fec_opt !=
2163 (cfg->link_fec_opt & pcaps->link_fec_options)) {
2164 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2165 cfg->link_fec_opt = pcaps->link_fec_options;
2168 /* Flow Control - always supported; no need to check against
2171 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req);
2173 /* Enable link and link update */
2174 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK;
2176 err = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL);
2178 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
2188 * ice_check_media_subtask - Check for media
2189 * @pf: pointer to PF struct
2191 * If media is available, then initialize PHY user configuration if it is not
2192 * been, and configure the PHY if the interface is up.
2194 static void ice_check_media_subtask(struct ice_pf *pf)
2196 struct ice_port_info *pi;
2197 struct ice_vsi *vsi;
2200 /* No need to check for media if it's already present */
2201 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags))
2204 vsi = ice_get_main_vsi(pf);
2208 /* Refresh link info and check if media is present */
2209 pi = vsi->port_info;
2210 err = ice_update_link_info(pi);
2214 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
2216 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
2217 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state))
2218 ice_init_phy_user_cfg(pi);
2220 /* PHY settings are reset on media insertion, reconfigure
2221 * PHY to preserve settings.
2223 if (test_bit(ICE_VSI_DOWN, vsi->state) &&
2224 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags))
2227 err = ice_configure_phy(vsi);
2229 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
2231 /* A Link Status Event will be generated; the event handler
2232 * will complete bringing the interface up
2238 * ice_service_task - manage and run subtasks
2239 * @work: pointer to work_struct contained by the PF struct
2241 static void ice_service_task(struct work_struct *work)
2243 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
2244 unsigned long start_time = jiffies;
2248 /* process reset requests first */
2249 ice_reset_subtask(pf);
2251 /* bail if a reset/recovery cycle is pending or rebuild failed */
2252 if (ice_is_reset_in_progress(pf->state) ||
2253 test_bit(ICE_SUSPENDED, pf->state) ||
2254 test_bit(ICE_NEEDS_RESTART, pf->state)) {
2255 ice_service_task_complete(pf);
2259 ice_clean_adminq_subtask(pf);
2260 ice_check_media_subtask(pf);
2261 ice_check_for_hang_subtask(pf);
2262 ice_sync_fltr_subtask(pf);
2263 ice_handle_mdd_event(pf);
2264 ice_watchdog_subtask(pf);
2266 if (ice_is_safe_mode(pf)) {
2267 ice_service_task_complete(pf);
2271 ice_process_vflr_event(pf);
2272 ice_clean_mailboxq_subtask(pf);
2273 ice_clean_sbq_subtask(pf);
2274 ice_sync_arfs_fltrs(pf);
2275 ice_flush_fdir_ctx(pf);
2277 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */
2278 ice_service_task_complete(pf);
2280 /* If the tasks have taken longer than one service timer period
2281 * or there is more work to be done, reset the service timer to
2282 * schedule the service task now.
2284 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
2285 test_bit(ICE_MDD_EVENT_PENDING, pf->state) ||
2286 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) ||
2287 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
2288 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) ||
2289 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) ||
2290 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
2291 mod_timer(&pf->serv_tmr, jiffies);
2295 * ice_set_ctrlq_len - helper function to set controlq length
2296 * @hw: pointer to the HW instance
2298 static void ice_set_ctrlq_len(struct ice_hw *hw)
2300 hw->adminq.num_rq_entries = ICE_AQ_LEN;
2301 hw->adminq.num_sq_entries = ICE_AQ_LEN;
2302 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
2303 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
2304 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
2305 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
2306 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2307 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2308 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
2309 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
2310 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2311 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2315 * ice_schedule_reset - schedule a reset
2316 * @pf: board private structure
2317 * @reset: reset being requested
2319 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
2321 struct device *dev = ice_pf_to_dev(pf);
2323 /* bail out if earlier reset has failed */
2324 if (test_bit(ICE_RESET_FAILED, pf->state)) {
2325 dev_dbg(dev, "earlier reset has failed\n");
2328 /* bail if reset/recovery already in progress */
2329 if (ice_is_reset_in_progress(pf->state)) {
2330 dev_dbg(dev, "Reset already in progress\n");
2334 ice_unplug_aux_dev(pf);
2338 set_bit(ICE_PFR_REQ, pf->state);
2340 case ICE_RESET_CORER:
2341 set_bit(ICE_CORER_REQ, pf->state);
2343 case ICE_RESET_GLOBR:
2344 set_bit(ICE_GLOBR_REQ, pf->state);
2350 ice_service_task_schedule(pf);
2355 * ice_irq_affinity_notify - Callback for affinity changes
2356 * @notify: context as to what irq was changed
2357 * @mask: the new affinity mask
2359 * This is a callback function used by the irq_set_affinity_notifier function
2360 * so that we may register to receive changes to the irq affinity masks.
2363 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
2364 const cpumask_t *mask)
2366 struct ice_q_vector *q_vector =
2367 container_of(notify, struct ice_q_vector, affinity_notify);
2369 cpumask_copy(&q_vector->affinity_mask, mask);
2373 * ice_irq_affinity_release - Callback for affinity notifier release
2374 * @ref: internal core kernel usage
2376 * This is a callback function used by the irq_set_affinity_notifier function
2377 * to inform the current notification subscriber that they will no longer
2378 * receive notifications.
2380 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
2383 * ice_vsi_ena_irq - Enable IRQ for the given VSI
2384 * @vsi: the VSI being configured
2386 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
2388 struct ice_hw *hw = &vsi->back->hw;
2391 ice_for_each_q_vector(vsi, i)
2392 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
2399 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
2400 * @vsi: the VSI being configured
2401 * @basename: name for the vector
2403 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
2405 int q_vectors = vsi->num_q_vectors;
2406 struct ice_pf *pf = vsi->back;
2407 int base = vsi->base_vector;
2414 dev = ice_pf_to_dev(pf);
2415 for (vector = 0; vector < q_vectors; vector++) {
2416 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
2418 irq_num = pf->msix_entries[base + vector].vector;
2420 if (q_vector->tx.tx_ring && q_vector->rx.rx_ring) {
2421 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2422 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2424 } else if (q_vector->rx.rx_ring) {
2425 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2426 "%s-%s-%d", basename, "rx", rx_int_idx++);
2427 } else if (q_vector->tx.tx_ring) {
2428 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2429 "%s-%s-%d", basename, "tx", tx_int_idx++);
2431 /* skip this unused q_vector */
2434 if (vsi->type == ICE_VSI_CTRL && vsi->vf_id != ICE_INVAL_VFID)
2435 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2436 IRQF_SHARED, q_vector->name,
2439 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2440 0, q_vector->name, q_vector);
2442 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
2447 /* register for affinity change notifications */
2448 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
2449 struct irq_affinity_notify *affinity_notify;
2451 affinity_notify = &q_vector->affinity_notify;
2452 affinity_notify->notify = ice_irq_affinity_notify;
2453 affinity_notify->release = ice_irq_affinity_release;
2454 irq_set_affinity_notifier(irq_num, affinity_notify);
2457 /* assign the mask for this irq */
2458 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
2461 vsi->irqs_ready = true;
2467 irq_num = pf->msix_entries[base + vector].vector;
2468 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2469 irq_set_affinity_notifier(irq_num, NULL);
2470 irq_set_affinity_hint(irq_num, NULL);
2471 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
2477 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
2478 * @vsi: VSI to setup Tx rings used by XDP
2480 * Return 0 on success and negative value on error
2482 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
2484 struct device *dev = ice_pf_to_dev(vsi->back);
2485 struct ice_tx_desc *tx_desc;
2488 ice_for_each_xdp_txq(vsi, i) {
2489 u16 xdp_q_idx = vsi->alloc_txq + i;
2490 struct ice_tx_ring *xdp_ring;
2492 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
2495 goto free_xdp_rings;
2497 xdp_ring->q_index = xdp_q_idx;
2498 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
2499 xdp_ring->vsi = vsi;
2500 xdp_ring->netdev = NULL;
2501 xdp_ring->dev = dev;
2502 xdp_ring->count = vsi->num_tx_desc;
2503 xdp_ring->next_dd = ICE_RING_QUARTER(xdp_ring) - 1;
2504 xdp_ring->next_rs = ICE_RING_QUARTER(xdp_ring) - 1;
2505 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring);
2506 if (ice_setup_tx_ring(xdp_ring))
2507 goto free_xdp_rings;
2508 ice_set_ring_xdp(xdp_ring);
2509 xdp_ring->xsk_pool = ice_tx_xsk_pool(xdp_ring);
2510 spin_lock_init(&xdp_ring->tx_lock);
2511 for (j = 0; j < xdp_ring->count; j++) {
2512 tx_desc = ICE_TX_DESC(xdp_ring, j);
2513 tx_desc->cmd_type_offset_bsz = cpu_to_le64(ICE_TX_DESC_DTYPE_DESC_DONE);
2517 ice_for_each_rxq(vsi, i) {
2518 if (static_key_enabled(&ice_xdp_locking_key))
2519 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i % vsi->num_xdp_txq];
2521 vsi->rx_rings[i]->xdp_ring = vsi->xdp_rings[i];
2528 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2529 ice_free_tx_ring(vsi->xdp_rings[i]);
2534 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
2535 * @vsi: VSI to set the bpf prog on
2536 * @prog: the bpf prog pointer
2538 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
2540 struct bpf_prog *old_prog;
2543 old_prog = xchg(&vsi->xdp_prog, prog);
2545 bpf_prog_put(old_prog);
2547 ice_for_each_rxq(vsi, i)
2548 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
2552 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
2553 * @vsi: VSI to bring up Tx rings used by XDP
2554 * @prog: bpf program that will be assigned to VSI
2556 * Return 0 on success and negative value on error
2558 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
2560 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2561 int xdp_rings_rem = vsi->num_xdp_txq;
2562 struct ice_pf *pf = vsi->back;
2563 struct ice_qs_cfg xdp_qs_cfg = {
2564 .qs_mutex = &pf->avail_q_mutex,
2565 .pf_map = pf->avail_txqs,
2566 .pf_map_size = pf->max_pf_txqs,
2567 .q_count = vsi->num_xdp_txq,
2568 .scatter_count = ICE_MAX_SCATTER_TXQS,
2569 .vsi_map = vsi->txq_map,
2570 .vsi_map_offset = vsi->alloc_txq,
2571 .mapping_mode = ICE_VSI_MAP_CONTIG
2577 dev = ice_pf_to_dev(pf);
2578 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
2579 sizeof(*vsi->xdp_rings), GFP_KERNEL);
2580 if (!vsi->xdp_rings)
2583 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
2584 if (__ice_vsi_get_qs(&xdp_qs_cfg))
2587 if (static_key_enabled(&ice_xdp_locking_key))
2588 netdev_warn(vsi->netdev,
2589 "Could not allocate one XDP Tx ring per CPU, XDP_TX/XDP_REDIRECT actions will be slower\n");
2591 if (ice_xdp_alloc_setup_rings(vsi))
2592 goto clear_xdp_rings;
2594 /* follow the logic from ice_vsi_map_rings_to_vectors */
2595 ice_for_each_q_vector(vsi, v_idx) {
2596 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2597 int xdp_rings_per_v, q_id, q_base;
2599 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
2600 vsi->num_q_vectors - v_idx);
2601 q_base = vsi->num_xdp_txq - xdp_rings_rem;
2603 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
2604 struct ice_tx_ring *xdp_ring = vsi->xdp_rings[q_id];
2606 xdp_ring->q_vector = q_vector;
2607 xdp_ring->next = q_vector->tx.tx_ring;
2608 q_vector->tx.tx_ring = xdp_ring;
2610 xdp_rings_rem -= xdp_rings_per_v;
2613 /* omit the scheduler update if in reset path; XDP queues will be
2614 * taken into account at the end of ice_vsi_rebuild, where
2615 * ice_cfg_vsi_lan is being called
2617 if (ice_is_reset_in_progress(pf->state))
2620 /* tell the Tx scheduler that right now we have
2623 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2624 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
2626 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2629 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %d\n",
2631 goto clear_xdp_rings;
2634 /* assign the prog only when it's not already present on VSI;
2635 * this flow is a subject of both ethtool -L and ndo_bpf flows;
2636 * VSI rebuild that happens under ethtool -L can expose us to
2637 * the bpf_prog refcount issues as we would be swapping same
2638 * bpf_prog pointers from vsi->xdp_prog and calling bpf_prog_put
2639 * on it as it would be treated as an 'old_prog'; for ndo_bpf
2640 * this is not harmful as dev_xdp_install bumps the refcount
2641 * before calling the op exposed by the driver;
2643 if (!ice_is_xdp_ena_vsi(vsi))
2644 ice_vsi_assign_bpf_prog(vsi, prog);
2648 ice_for_each_xdp_txq(vsi, i)
2649 if (vsi->xdp_rings[i]) {
2650 kfree_rcu(vsi->xdp_rings[i], rcu);
2651 vsi->xdp_rings[i] = NULL;
2655 mutex_lock(&pf->avail_q_mutex);
2656 ice_for_each_xdp_txq(vsi, i) {
2657 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2658 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2660 mutex_unlock(&pf->avail_q_mutex);
2662 devm_kfree(dev, vsi->xdp_rings);
2667 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
2668 * @vsi: VSI to remove XDP rings
2670 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
2673 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
2675 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2676 struct ice_pf *pf = vsi->back;
2679 /* q_vectors are freed in reset path so there's no point in detaching
2680 * rings; in case of rebuild being triggered not from reset bits
2681 * in pf->state won't be set, so additionally check first q_vector
2684 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2687 ice_for_each_q_vector(vsi, v_idx) {
2688 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2689 struct ice_tx_ring *ring;
2691 ice_for_each_tx_ring(ring, q_vector->tx)
2692 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
2695 /* restore the value of last node prior to XDP setup */
2696 q_vector->tx.tx_ring = ring;
2700 mutex_lock(&pf->avail_q_mutex);
2701 ice_for_each_xdp_txq(vsi, i) {
2702 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2703 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2705 mutex_unlock(&pf->avail_q_mutex);
2707 ice_for_each_xdp_txq(vsi, i)
2708 if (vsi->xdp_rings[i]) {
2709 if (vsi->xdp_rings[i]->desc)
2710 ice_free_tx_ring(vsi->xdp_rings[i]);
2711 kfree_rcu(vsi->xdp_rings[i], rcu);
2712 vsi->xdp_rings[i] = NULL;
2715 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
2716 vsi->xdp_rings = NULL;
2718 if (static_key_enabled(&ice_xdp_locking_key))
2719 static_branch_dec(&ice_xdp_locking_key);
2721 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2724 ice_vsi_assign_bpf_prog(vsi, NULL);
2726 /* notify Tx scheduler that we destroyed XDP queues and bring
2727 * back the old number of child nodes
2729 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2730 max_txqs[i] = vsi->num_txq;
2732 /* change number of XDP Tx queues to 0 */
2733 vsi->num_xdp_txq = 0;
2735 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2740 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2741 * @vsi: VSI to schedule napi on
2743 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2747 ice_for_each_rxq(vsi, i) {
2748 struct ice_rx_ring *rx_ring = vsi->rx_rings[i];
2750 if (rx_ring->xsk_pool)
2751 napi_schedule(&rx_ring->q_vector->napi);
2756 * ice_vsi_determine_xdp_res - figure out how many Tx qs can XDP have
2757 * @vsi: VSI to determine the count of XDP Tx qs
2759 * returns 0 if Tx qs count is higher than at least half of CPU count,
2762 int ice_vsi_determine_xdp_res(struct ice_vsi *vsi)
2764 u16 avail = ice_get_avail_txq_count(vsi->back);
2765 u16 cpus = num_possible_cpus();
2767 if (avail < cpus / 2)
2770 vsi->num_xdp_txq = min_t(u16, avail, cpus);
2772 if (vsi->num_xdp_txq < cpus)
2773 static_branch_inc(&ice_xdp_locking_key);
2779 * ice_xdp_setup_prog - Add or remove XDP eBPF program
2780 * @vsi: VSI to setup XDP for
2781 * @prog: XDP program
2782 * @extack: netlink extended ack
2785 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
2786 struct netlink_ext_ack *extack)
2788 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
2789 bool if_running = netif_running(vsi->netdev);
2790 int ret = 0, xdp_ring_err = 0;
2792 if (frame_size > vsi->rx_buf_len) {
2793 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
2797 /* need to stop netdev while setting up the program for Rx rings */
2798 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2799 ret = ice_down(vsi);
2801 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
2806 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
2807 xdp_ring_err = ice_vsi_determine_xdp_res(vsi);
2809 NL_SET_ERR_MSG_MOD(extack, "Not enough Tx resources for XDP");
2811 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
2813 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
2815 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
2816 xdp_ring_err = ice_destroy_xdp_rings(vsi);
2818 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
2820 /* safe to call even when prog == vsi->xdp_prog as
2821 * dev_xdp_install in net/core/dev.c incremented prog's
2822 * refcount so corresponding bpf_prog_put won't cause
2825 ice_vsi_assign_bpf_prog(vsi, prog);
2832 ice_vsi_rx_napi_schedule(vsi);
2834 return (ret || xdp_ring_err) ? -ENOMEM : 0;
2838 * ice_xdp_safe_mode - XDP handler for safe mode
2842 static int ice_xdp_safe_mode(struct net_device __always_unused *dev,
2843 struct netdev_bpf *xdp)
2845 NL_SET_ERR_MSG_MOD(xdp->extack,
2846 "Please provide working DDP firmware package in order to use XDP\n"
2847 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst");
2852 * ice_xdp - implements XDP handler
2856 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
2858 struct ice_netdev_priv *np = netdev_priv(dev);
2859 struct ice_vsi *vsi = np->vsi;
2861 if (vsi->type != ICE_VSI_PF) {
2862 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI");
2866 switch (xdp->command) {
2867 case XDP_SETUP_PROG:
2868 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
2869 case XDP_SETUP_XSK_POOL:
2870 return ice_xsk_pool_setup(vsi, xdp->xsk.pool,
2878 * ice_ena_misc_vector - enable the non-queue interrupts
2879 * @pf: board private structure
2881 static void ice_ena_misc_vector(struct ice_pf *pf)
2883 struct ice_hw *hw = &pf->hw;
2886 /* Disable anti-spoof detection interrupt to prevent spurious event
2887 * interrupts during a function reset. Anti-spoof functionally is
2890 val = rd32(hw, GL_MDCK_TX_TDPU);
2891 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
2892 wr32(hw, GL_MDCK_TX_TDPU, val);
2894 /* clear things first */
2895 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
2896 rd32(hw, PFINT_OICR); /* read to clear */
2898 val = (PFINT_OICR_ECC_ERR_M |
2899 PFINT_OICR_MAL_DETECT_M |
2901 PFINT_OICR_PCI_EXCEPTION_M |
2903 PFINT_OICR_HMC_ERR_M |
2904 PFINT_OICR_PE_PUSH_M |
2905 PFINT_OICR_PE_CRITERR_M);
2907 wr32(hw, PFINT_OICR_ENA, val);
2909 /* SW_ITR_IDX = 0, but don't change INTENA */
2910 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2911 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2915 * ice_misc_intr - misc interrupt handler
2916 * @irq: interrupt number
2917 * @data: pointer to a q_vector
2919 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2921 struct ice_pf *pf = (struct ice_pf *)data;
2922 struct ice_hw *hw = &pf->hw;
2923 irqreturn_t ret = IRQ_NONE;
2927 dev = ice_pf_to_dev(pf);
2928 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
2929 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2930 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
2932 oicr = rd32(hw, PFINT_OICR);
2933 ena_mask = rd32(hw, PFINT_OICR_ENA);
2935 if (oicr & PFINT_OICR_SWINT_M) {
2936 ena_mask &= ~PFINT_OICR_SWINT_M;
2940 if (oicr & PFINT_OICR_MAL_DETECT_M) {
2941 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2942 set_bit(ICE_MDD_EVENT_PENDING, pf->state);
2944 if (oicr & PFINT_OICR_VFLR_M) {
2945 /* disable any further VFLR event notifications */
2946 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
2947 u32 reg = rd32(hw, PFINT_OICR_ENA);
2949 reg &= ~PFINT_OICR_VFLR_M;
2950 wr32(hw, PFINT_OICR_ENA, reg);
2952 ena_mask &= ~PFINT_OICR_VFLR_M;
2953 set_bit(ICE_VFLR_EVENT_PENDING, pf->state);
2957 if (oicr & PFINT_OICR_GRST_M) {
2960 /* we have a reset warning */
2961 ena_mask &= ~PFINT_OICR_GRST_M;
2962 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
2963 GLGEN_RSTAT_RESET_TYPE_S;
2965 if (reset == ICE_RESET_CORER)
2967 else if (reset == ICE_RESET_GLOBR)
2969 else if (reset == ICE_RESET_EMPR)
2972 dev_dbg(dev, "Invalid reset type %d\n", reset);
2974 /* If a reset cycle isn't already in progress, we set a bit in
2975 * pf->state so that the service task can start a reset/rebuild.
2977 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) {
2978 if (reset == ICE_RESET_CORER)
2979 set_bit(ICE_CORER_RECV, pf->state);
2980 else if (reset == ICE_RESET_GLOBR)
2981 set_bit(ICE_GLOBR_RECV, pf->state);
2983 set_bit(ICE_EMPR_RECV, pf->state);
2985 /* There are couple of different bits at play here.
2986 * hw->reset_ongoing indicates whether the hardware is
2987 * in reset. This is set to true when a reset interrupt
2988 * is received and set back to false after the driver
2989 * has determined that the hardware is out of reset.
2991 * ICE_RESET_OICR_RECV in pf->state indicates
2992 * that a post reset rebuild is required before the
2993 * driver is operational again. This is set above.
2995 * As this is the start of the reset/rebuild cycle, set
2996 * both to indicate that.
2998 hw->reset_ongoing = true;
3002 if (oicr & PFINT_OICR_TSYN_TX_M) {
3003 ena_mask &= ~PFINT_OICR_TSYN_TX_M;
3004 ice_ptp_process_ts(pf);
3007 if (oicr & PFINT_OICR_TSYN_EVNT_M) {
3008 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
3009 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx));
3011 /* Save EVENTs from GTSYN register */
3012 pf->ptp.ext_ts_irq |= gltsyn_stat & (GLTSYN_STAT_EVENT0_M |
3013 GLTSYN_STAT_EVENT1_M |
3014 GLTSYN_STAT_EVENT2_M);
3015 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M;
3016 kthread_queue_work(pf->ptp.kworker, &pf->ptp.extts_work);
3019 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M)
3020 if (oicr & ICE_AUX_CRIT_ERR) {
3021 struct iidc_event *event;
3023 ena_mask &= ~ICE_AUX_CRIT_ERR;
3024 event = kzalloc(sizeof(*event), GFP_KERNEL);
3026 set_bit(IIDC_EVENT_CRIT_ERR, event->type);
3027 /* report the entire OICR value to AUX driver */
3029 ice_send_event_to_aux(pf, event);
3034 /* Report any remaining unexpected interrupts */
3037 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
3038 /* If a critical error is pending there is no choice but to
3041 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M |
3042 PFINT_OICR_ECC_ERR_M)) {
3043 set_bit(ICE_PFR_REQ, pf->state);
3044 ice_service_task_schedule(pf);
3049 ice_service_task_schedule(pf);
3050 ice_irq_dynamic_ena(hw, NULL, NULL);
3056 * ice_dis_ctrlq_interrupts - disable control queue interrupts
3057 * @hw: pointer to HW structure
3059 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
3061 /* disable Admin queue Interrupt causes */
3062 wr32(hw, PFINT_FW_CTL,
3063 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
3065 /* disable Mailbox queue Interrupt causes */
3066 wr32(hw, PFINT_MBX_CTL,
3067 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
3069 wr32(hw, PFINT_SB_CTL,
3070 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M);
3072 /* disable Control queue Interrupt causes */
3073 wr32(hw, PFINT_OICR_CTL,
3074 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
3080 * ice_free_irq_msix_misc - Unroll misc vector setup
3081 * @pf: board private structure
3083 static void ice_free_irq_msix_misc(struct ice_pf *pf)
3085 struct ice_hw *hw = &pf->hw;
3087 ice_dis_ctrlq_interrupts(hw);
3089 /* disable OICR interrupt */
3090 wr32(hw, PFINT_OICR_ENA, 0);
3093 if (pf->msix_entries) {
3094 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
3095 devm_free_irq(ice_pf_to_dev(pf),
3096 pf->msix_entries[pf->oicr_idx].vector, pf);
3099 pf->num_avail_sw_msix += 1;
3100 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
3104 * ice_ena_ctrlq_interrupts - enable control queue interrupts
3105 * @hw: pointer to HW structure
3106 * @reg_idx: HW vector index to associate the control queue interrupts with
3108 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
3112 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
3113 PFINT_OICR_CTL_CAUSE_ENA_M);
3114 wr32(hw, PFINT_OICR_CTL, val);
3116 /* enable Admin queue Interrupt causes */
3117 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
3118 PFINT_FW_CTL_CAUSE_ENA_M);
3119 wr32(hw, PFINT_FW_CTL, val);
3121 /* enable Mailbox queue Interrupt causes */
3122 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
3123 PFINT_MBX_CTL_CAUSE_ENA_M);
3124 wr32(hw, PFINT_MBX_CTL, val);
3126 /* This enables Sideband queue Interrupt causes */
3127 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) |
3128 PFINT_SB_CTL_CAUSE_ENA_M);
3129 wr32(hw, PFINT_SB_CTL, val);
3135 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
3136 * @pf: board private structure
3138 * This sets up the handler for MSIX 0, which is used to manage the
3139 * non-queue interrupts, e.g. AdminQ and errors. This is not used
3140 * when in MSI or Legacy interrupt mode.
3142 static int ice_req_irq_msix_misc(struct ice_pf *pf)
3144 struct device *dev = ice_pf_to_dev(pf);
3145 struct ice_hw *hw = &pf->hw;
3146 int oicr_idx, err = 0;
3148 if (!pf->int_name[0])
3149 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
3150 dev_driver_string(dev), dev_name(dev));
3152 /* Do not request IRQ but do enable OICR interrupt since settings are
3153 * lost during reset. Note that this function is called only during
3154 * rebuild path and not while reset is in progress.
3156 if (ice_is_reset_in_progress(pf->state))
3159 /* reserve one vector in irq_tracker for misc interrupts */
3160 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3164 pf->num_avail_sw_msix -= 1;
3165 pf->oicr_idx = (u16)oicr_idx;
3167 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
3168 ice_misc_intr, 0, pf->int_name, pf);
3170 dev_err(dev, "devm_request_irq for %s failed: %d\n",
3172 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
3173 pf->num_avail_sw_msix += 1;
3178 ice_ena_misc_vector(pf);
3180 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
3181 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
3182 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
3185 ice_irq_dynamic_ena(hw, NULL, NULL);
3191 * ice_napi_add - register NAPI handler for the VSI
3192 * @vsi: VSI for which NAPI handler is to be registered
3194 * This function is only called in the driver's load path. Registering the NAPI
3195 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
3196 * reset/rebuild, etc.)
3198 static void ice_napi_add(struct ice_vsi *vsi)
3205 ice_for_each_q_vector(vsi, v_idx)
3206 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
3207 ice_napi_poll, NAPI_POLL_WEIGHT);
3211 * ice_set_ops - set netdev and ethtools ops for the given netdev
3212 * @netdev: netdev instance
3214 static void ice_set_ops(struct net_device *netdev)
3216 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3218 if (ice_is_safe_mode(pf)) {
3219 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
3220 ice_set_ethtool_safe_mode_ops(netdev);
3224 netdev->netdev_ops = &ice_netdev_ops;
3225 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic;
3226 ice_set_ethtool_ops(netdev);
3230 * ice_set_netdev_features - set features for the given netdev
3231 * @netdev: netdev instance
3233 static void ice_set_netdev_features(struct net_device *netdev)
3235 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3236 bool is_dvm_ena = ice_is_dvm_ena(&pf->hw);
3237 netdev_features_t csumo_features;
3238 netdev_features_t vlano_features;
3239 netdev_features_t dflt_features;
3240 netdev_features_t tso_features;
3242 if (ice_is_safe_mode(pf)) {
3244 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
3245 netdev->hw_features = netdev->features;
3249 dflt_features = NETIF_F_SG |
3254 csumo_features = NETIF_F_RXCSUM |
3259 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
3260 NETIF_F_HW_VLAN_CTAG_TX |
3261 NETIF_F_HW_VLAN_CTAG_RX;
3263 /* Enable CTAG/STAG filtering by default in Double VLAN Mode (DVM) */
3265 vlano_features |= NETIF_F_HW_VLAN_STAG_FILTER;
3267 tso_features = NETIF_F_TSO |
3271 NETIF_F_GSO_UDP_TUNNEL |
3272 NETIF_F_GSO_GRE_CSUM |
3273 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3274 NETIF_F_GSO_PARTIAL |
3275 NETIF_F_GSO_IPXIP4 |
3276 NETIF_F_GSO_IPXIP6 |
3279 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3280 NETIF_F_GSO_GRE_CSUM;
3281 /* set features that user can change */
3282 netdev->hw_features = dflt_features | csumo_features |
3283 vlano_features | tso_features;
3285 /* add support for HW_CSUM on packets with MPLS header */
3286 netdev->mpls_features = NETIF_F_HW_CSUM;
3288 /* enable features */
3289 netdev->features |= netdev->hw_features;
3291 netdev->hw_features |= NETIF_F_HW_TC;
3293 /* encap and VLAN devices inherit default, csumo and tso features */
3294 netdev->hw_enc_features |= dflt_features | csumo_features |
3296 netdev->vlan_features |= dflt_features | csumo_features |
3299 /* advertise support but don't enable by default since only one type of
3300 * VLAN offload can be enabled at a time (i.e. CTAG or STAG). When one
3301 * type turns on the other has to be turned off. This is enforced by the
3302 * ice_fix_features() ndo callback.
3305 netdev->hw_features |= NETIF_F_HW_VLAN_STAG_RX |
3306 NETIF_F_HW_VLAN_STAG_TX;
3310 * ice_cfg_netdev - Allocate, configure and register a netdev
3311 * @vsi: the VSI associated with the new netdev
3313 * Returns 0 on success, negative value on failure
3315 static int ice_cfg_netdev(struct ice_vsi *vsi)
3317 struct ice_netdev_priv *np;
3318 struct net_device *netdev;
3319 u8 mac_addr[ETH_ALEN];
3321 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
3326 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3327 vsi->netdev = netdev;
3328 np = netdev_priv(netdev);
3331 ice_set_netdev_features(netdev);
3333 ice_set_ops(netdev);
3335 if (vsi->type == ICE_VSI_PF) {
3336 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back));
3337 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
3338 eth_hw_addr_set(netdev, mac_addr);
3339 ether_addr_copy(netdev->perm_addr, mac_addr);
3342 netdev->priv_flags |= IFF_UNICAST_FLT;
3344 /* Setup netdev TC information */
3345 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
3347 /* setup watchdog timeout value to be 5 second */
3348 netdev->watchdog_timeo = 5 * HZ;
3350 netdev->min_mtu = ETH_MIN_MTU;
3351 netdev->max_mtu = ICE_MAX_MTU;
3357 * ice_fill_rss_lut - Fill the RSS lookup table with default values
3358 * @lut: Lookup table
3359 * @rss_table_size: Lookup table size
3360 * @rss_size: Range of queue number for hashing
3362 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
3366 for (i = 0; i < rss_table_size; i++)
3367 lut[i] = i % rss_size;
3371 * ice_pf_vsi_setup - Set up a PF VSI
3372 * @pf: board private structure
3373 * @pi: pointer to the port_info instance
3375 * Returns pointer to the successfully allocated VSI software struct
3376 * on success, otherwise returns NULL on failure.
3378 static struct ice_vsi *
3379 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3381 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID, NULL);
3384 static struct ice_vsi *
3385 ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
3386 struct ice_channel *ch)
3388 return ice_vsi_setup(pf, pi, ICE_VSI_CHNL, ICE_INVAL_VFID, ch);
3392 * ice_ctrl_vsi_setup - Set up a control VSI
3393 * @pf: board private structure
3394 * @pi: pointer to the port_info instance
3396 * Returns pointer to the successfully allocated VSI software struct
3397 * on success, otherwise returns NULL on failure.
3399 static struct ice_vsi *
3400 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3402 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, ICE_INVAL_VFID, NULL);
3406 * ice_lb_vsi_setup - Set up a loopback VSI
3407 * @pf: board private structure
3408 * @pi: pointer to the port_info instance
3410 * Returns pointer to the successfully allocated VSI software struct
3411 * on success, otherwise returns NULL on failure.
3414 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3416 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID, NULL);
3420 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
3421 * @netdev: network interface to be adjusted
3423 * @vid: VLAN ID to be added
3425 * net_device_ops implementation for adding VLAN IDs
3428 ice_vlan_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
3430 struct ice_netdev_priv *np = netdev_priv(netdev);
3431 struct ice_vsi_vlan_ops *vlan_ops;
3432 struct ice_vsi *vsi = np->vsi;
3433 struct ice_vlan vlan;
3436 /* VLAN 0 is added by default during load/reset */
3440 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3442 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
3443 * packets aren't pruned by the device's internal switch on Rx
3445 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3446 ret = vlan_ops->add_vlan(vsi, &vlan);
3448 set_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
3454 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
3455 * @netdev: network interface to be adjusted
3457 * @vid: VLAN ID to be removed
3459 * net_device_ops implementation for removing VLAN IDs
3462 ice_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
3464 struct ice_netdev_priv *np = netdev_priv(netdev);
3465 struct ice_vsi_vlan_ops *vlan_ops;
3466 struct ice_vsi *vsi = np->vsi;
3467 struct ice_vlan vlan;
3470 /* don't allow removal of VLAN 0 */
3474 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
3476 /* Make sure VLAN delete is successful before updating VLAN
3479 vlan = ICE_VLAN(be16_to_cpu(proto), vid, 0);
3480 ret = vlan_ops->del_vlan(vsi, &vlan);
3484 set_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
3489 * ice_rep_indr_tc_block_unbind
3490 * @cb_priv: indirection block private data
3492 static void ice_rep_indr_tc_block_unbind(void *cb_priv)
3494 struct ice_indr_block_priv *indr_priv = cb_priv;
3496 list_del(&indr_priv->list);
3501 * ice_tc_indir_block_unregister - Unregister TC indirect block notifications
3502 * @vsi: VSI struct which has the netdev
3504 static void ice_tc_indir_block_unregister(struct ice_vsi *vsi)
3506 struct ice_netdev_priv *np = netdev_priv(vsi->netdev);
3508 flow_indr_dev_unregister(ice_indr_setup_tc_cb, np,
3509 ice_rep_indr_tc_block_unbind);
3513 * ice_tc_indir_block_remove - clean indirect TC block notifications
3516 static void ice_tc_indir_block_remove(struct ice_pf *pf)
3518 struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
3523 ice_tc_indir_block_unregister(pf_vsi);
3527 * ice_tc_indir_block_register - Register TC indirect block notifications
3528 * @vsi: VSI struct which has the netdev
3530 * Returns 0 on success, negative value on failure
3532 static int ice_tc_indir_block_register(struct ice_vsi *vsi)
3534 struct ice_netdev_priv *np;
3536 if (!vsi || !vsi->netdev)
3539 np = netdev_priv(vsi->netdev);
3541 INIT_LIST_HEAD(&np->tc_indr_block_priv_list);
3542 return flow_indr_dev_register(ice_indr_setup_tc_cb, np);
3546 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
3547 * @pf: board private structure
3549 * Returns 0 on success, negative value on failure
3551 static int ice_setup_pf_sw(struct ice_pf *pf)
3553 struct device *dev = ice_pf_to_dev(pf);
3554 bool dvm = ice_is_dvm_ena(&pf->hw);
3555 struct ice_vsi *vsi;
3558 if (ice_is_reset_in_progress(pf->state))
3561 status = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
3565 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
3569 /* init channel list */
3570 INIT_LIST_HEAD(&vsi->ch_list);
3572 status = ice_cfg_netdev(vsi);
3574 goto unroll_vsi_setup;
3575 /* netdev has to be configured before setting frame size */
3576 ice_vsi_cfg_frame_size(vsi);
3578 /* init indirect block notifications */
3579 status = ice_tc_indir_block_register(vsi);
3581 dev_err(dev, "Failed to register netdev notifier\n");
3582 goto unroll_cfg_netdev;
3585 /* Setup DCB netlink interface */
3586 ice_dcbnl_setup(vsi);
3588 /* registering the NAPI handler requires both the queues and
3589 * netdev to be created, which are done in ice_pf_vsi_setup()
3590 * and ice_cfg_netdev() respectively
3594 status = ice_set_cpu_rx_rmap(vsi);
3596 dev_err(dev, "Failed to set CPU Rx map VSI %d error %d\n",
3597 vsi->vsi_num, status);
3598 goto unroll_napi_add;
3600 status = ice_init_mac_fltr(pf);
3602 goto free_cpu_rx_map;
3607 ice_free_cpu_rx_rmap(vsi);
3609 ice_tc_indir_block_unregister(vsi);
3614 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3615 free_netdev(vsi->netdev);
3621 ice_vsi_release(vsi);
3626 * ice_get_avail_q_count - Get count of queues in use
3627 * @pf_qmap: bitmap to get queue use count from
3628 * @lock: pointer to a mutex that protects access to pf_qmap
3629 * @size: size of the bitmap
3632 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
3638 for_each_clear_bit(bit, pf_qmap, size)
3646 * ice_get_avail_txq_count - Get count of Tx queues in use
3647 * @pf: pointer to an ice_pf instance
3649 u16 ice_get_avail_txq_count(struct ice_pf *pf)
3651 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
3656 * ice_get_avail_rxq_count - Get count of Rx queues in use
3657 * @pf: pointer to an ice_pf instance
3659 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
3661 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
3666 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3667 * @pf: board private structure to initialize
3669 static void ice_deinit_pf(struct ice_pf *pf)
3671 ice_service_task_stop(pf);
3672 mutex_destroy(&pf->sw_mutex);
3673 mutex_destroy(&pf->tc_mutex);
3674 mutex_destroy(&pf->avail_q_mutex);
3676 if (pf->avail_txqs) {
3677 bitmap_free(pf->avail_txqs);
3678 pf->avail_txqs = NULL;
3681 if (pf->avail_rxqs) {
3682 bitmap_free(pf->avail_rxqs);
3683 pf->avail_rxqs = NULL;
3687 ptp_clock_unregister(pf->ptp.clock);
3691 * ice_set_pf_caps - set PFs capability flags
3692 * @pf: pointer to the PF instance
3694 static void ice_set_pf_caps(struct ice_pf *pf)
3696 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
3698 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3699 clear_bit(ICE_FLAG_AUX_ENA, pf->flags);
3700 if (func_caps->common_cap.rdma) {
3701 set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3702 set_bit(ICE_FLAG_AUX_ENA, pf->flags);
3704 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3705 if (func_caps->common_cap.dcb)
3706 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3707 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3708 if (func_caps->common_cap.sr_iov_1_1) {
3709 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3710 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
3713 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
3714 if (func_caps->common_cap.rss_table_size)
3715 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
3717 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
3718 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
3721 /* ctrl_vsi_idx will be set to a valid value when flow director
3722 * is setup by ice_init_fdir
3724 pf->ctrl_vsi_idx = ICE_NO_VSI;
3725 set_bit(ICE_FLAG_FD_ENA, pf->flags);
3726 /* force guaranteed filter pool for PF */
3727 ice_alloc_fd_guar_item(&pf->hw, &unused,
3728 func_caps->fd_fltr_guar);
3729 /* force shared filter pool for PF */
3730 ice_alloc_fd_shrd_item(&pf->hw, &unused,
3731 func_caps->fd_fltr_best_effort);
3734 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3735 if (func_caps->common_cap.ieee_1588)
3736 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3738 pf->max_pf_txqs = func_caps->common_cap.num_txq;
3739 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
3743 * ice_init_pf - Initialize general software structures (struct ice_pf)
3744 * @pf: board private structure to initialize
3746 static int ice_init_pf(struct ice_pf *pf)
3748 ice_set_pf_caps(pf);
3750 mutex_init(&pf->sw_mutex);
3751 mutex_init(&pf->tc_mutex);
3753 INIT_HLIST_HEAD(&pf->aq_wait_list);
3754 spin_lock_init(&pf->aq_wait_lock);
3755 init_waitqueue_head(&pf->aq_wait_queue);
3757 init_waitqueue_head(&pf->reset_wait_queue);
3759 /* setup service timer and periodic service task */
3760 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
3761 pf->serv_tmr_period = HZ;
3762 INIT_WORK(&pf->serv_task, ice_service_task);
3763 clear_bit(ICE_SERVICE_SCHED, pf->state);
3765 mutex_init(&pf->avail_q_mutex);
3766 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
3767 if (!pf->avail_txqs)
3770 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
3771 if (!pf->avail_rxqs) {
3772 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
3773 pf->avail_txqs = NULL;
3781 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
3782 * @pf: board private structure
3784 * compute the number of MSIX vectors required (v_budget) and request from
3785 * the OS. Return the number of vectors reserved or negative on failure
3787 static int ice_ena_msix_range(struct ice_pf *pf)
3789 int num_cpus, v_left, v_actual, v_other, v_budget = 0;
3790 struct device *dev = ice_pf_to_dev(pf);
3793 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
3794 num_cpus = num_online_cpus();
3796 /* reserve for LAN miscellaneous handler */
3797 needed = ICE_MIN_LAN_OICR_MSIX;
3798 if (v_left < needed)
3799 goto no_hw_vecs_left_err;
3803 /* reserve for flow director */
3804 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
3805 needed = ICE_FDIR_MSIX;
3806 if (v_left < needed)
3807 goto no_hw_vecs_left_err;
3812 /* reserve for switchdev */
3813 needed = ICE_ESWITCH_MSIX;
3814 if (v_left < needed)
3815 goto no_hw_vecs_left_err;
3819 /* total used for non-traffic vectors */
3822 /* reserve vectors for LAN traffic */
3824 if (v_left < needed)
3825 goto no_hw_vecs_left_err;
3826 pf->num_lan_msix = needed;
3830 /* reserve vectors for RDMA auxiliary driver */
3831 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags)) {
3832 needed = num_cpus + ICE_RDMA_NUM_AEQ_MSIX;
3833 if (v_left < needed)
3834 goto no_hw_vecs_left_err;
3835 pf->num_rdma_msix = needed;
3840 pf->msix_entries = devm_kcalloc(dev, v_budget,
3841 sizeof(*pf->msix_entries), GFP_KERNEL);
3842 if (!pf->msix_entries) {
3847 for (i = 0; i < v_budget; i++)
3848 pf->msix_entries[i].entry = i;
3850 /* actually reserve the vectors */
3851 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
3852 ICE_MIN_MSIX, v_budget);
3854 dev_err(dev, "unable to reserve MSI-X vectors\n");
3859 if (v_actual < v_budget) {
3860 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
3861 v_budget, v_actual);
3863 if (v_actual < ICE_MIN_MSIX) {
3864 /* error if we can't get minimum vectors */
3865 pci_disable_msix(pf->pdev);
3869 int v_remain = v_actual - v_other;
3870 int v_rdma = 0, v_min_rdma = 0;
3872 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags)) {
3873 /* Need at least 1 interrupt in addition to
3876 v_rdma = ICE_RDMA_NUM_AEQ_MSIX + 1;
3877 v_min_rdma = ICE_MIN_RDMA_MSIX;
3880 if (v_actual == ICE_MIN_MSIX ||
3881 v_remain < ICE_MIN_LAN_TXRX_MSIX + v_min_rdma) {
3882 dev_warn(dev, "Not enough MSI-X vectors to support RDMA.\n");
3883 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3885 pf->num_rdma_msix = 0;
3886 pf->num_lan_msix = ICE_MIN_LAN_TXRX_MSIX;
3887 } else if ((v_remain < ICE_MIN_LAN_TXRX_MSIX + v_rdma) ||
3888 (v_remain - v_rdma < v_rdma)) {
3889 /* Support minimum RDMA and give remaining
3890 * vectors to LAN MSIX
3892 pf->num_rdma_msix = v_min_rdma;
3893 pf->num_lan_msix = v_remain - v_min_rdma;
3895 /* Split remaining MSIX with RDMA after
3896 * accounting for AEQ MSIX
3898 pf->num_rdma_msix = (v_remain - ICE_RDMA_NUM_AEQ_MSIX) / 2 +
3899 ICE_RDMA_NUM_AEQ_MSIX;
3900 pf->num_lan_msix = v_remain - pf->num_rdma_msix;
3903 dev_notice(dev, "Enabled %d MSI-X vectors for LAN traffic.\n",
3906 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags))
3907 dev_notice(dev, "Enabled %d MSI-X vectors for RDMA.\n",
3915 devm_kfree(dev, pf->msix_entries);
3918 no_hw_vecs_left_err:
3919 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
3923 pf->num_rdma_msix = 0;
3924 pf->num_lan_msix = 0;
3929 * ice_dis_msix - Disable MSI-X interrupt setup in OS
3930 * @pf: board private structure
3932 static void ice_dis_msix(struct ice_pf *pf)
3934 pci_disable_msix(pf->pdev);
3935 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
3936 pf->msix_entries = NULL;
3940 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
3941 * @pf: board private structure
3943 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
3947 if (pf->irq_tracker) {
3948 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
3949 pf->irq_tracker = NULL;
3954 * ice_init_interrupt_scheme - Determine proper interrupt scheme
3955 * @pf: board private structure to initialize
3957 static int ice_init_interrupt_scheme(struct ice_pf *pf)
3961 vectors = ice_ena_msix_range(pf);
3966 /* set up vector assignment tracking */
3967 pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf),
3968 struct_size(pf->irq_tracker, list, vectors),
3970 if (!pf->irq_tracker) {
3975 /* populate SW interrupts pool with number of OS granted IRQs. */
3976 pf->num_avail_sw_msix = (u16)vectors;
3977 pf->irq_tracker->num_entries = (u16)vectors;
3978 pf->irq_tracker->end = pf->irq_tracker->num_entries;
3984 * ice_is_wol_supported - check if WoL is supported
3985 * @hw: pointer to hardware info
3987 * Check if WoL is supported based on the HW configuration.
3988 * Returns true if NVM supports and enables WoL for this port, false otherwise
3990 bool ice_is_wol_supported(struct ice_hw *hw)
3994 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control
3995 * word) indicates WoL is not supported on the corresponding PF ID.
3997 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl))
4000 return !(BIT(hw->port_info->lport) & wol_ctrl);
4004 * ice_vsi_recfg_qs - Change the number of queues on a VSI
4005 * @vsi: VSI being changed
4006 * @new_rx: new number of Rx queues
4007 * @new_tx: new number of Tx queues
4009 * Only change the number of queues if new_tx, or new_rx is non-0.
4011 * Returns 0 on success.
4013 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
4015 struct ice_pf *pf = vsi->back;
4016 int err = 0, timeout = 50;
4018 if (!new_rx && !new_tx)
4021 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
4025 usleep_range(1000, 2000);
4029 vsi->req_txq = (u16)new_tx;
4031 vsi->req_rxq = (u16)new_rx;
4033 /* set for the next time the netdev is started */
4034 if (!netif_running(vsi->netdev)) {
4035 ice_vsi_rebuild(vsi, false);
4036 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
4041 ice_vsi_rebuild(vsi, false);
4042 ice_pf_dcb_recfg(pf);
4045 clear_bit(ICE_CFG_BUSY, pf->state);
4050 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode
4051 * @pf: PF to configure
4053 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF
4054 * VSI can still Tx/Rx VLAN tagged packets.
4056 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf)
4058 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4059 struct ice_vsi_ctx *ctxt;
4066 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
4071 ctxt->info = vsi->info;
4073 ctxt->info.valid_sections =
4074 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
4075 ICE_AQ_VSI_PROP_SECURITY_VALID |
4076 ICE_AQ_VSI_PROP_SW_VALID);
4078 /* disable VLAN anti-spoof */
4079 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
4080 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
4082 /* disable VLAN pruning and keep all other settings */
4083 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
4085 /* allow all VLANs on Tx and don't strip on Rx */
4086 ctxt->info.inner_vlan_flags = ICE_AQ_VSI_INNER_VLAN_TX_MODE_ALL |
4087 ICE_AQ_VSI_INNER_VLAN_EMODE_NOTHING;
4089 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
4091 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %d aq_err %s\n",
4092 status, ice_aq_str(hw->adminq.sq_last_status));
4094 vsi->info.sec_flags = ctxt->info.sec_flags;
4095 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
4096 vsi->info.inner_vlan_flags = ctxt->info.inner_vlan_flags;
4103 * ice_log_pkg_init - log result of DDP package load
4104 * @hw: pointer to hardware info
4105 * @state: state of package load
4107 static void ice_log_pkg_init(struct ice_hw *hw, enum ice_ddp_state state)
4109 struct ice_pf *pf = hw->back;
4112 dev = ice_pf_to_dev(pf);
4115 case ICE_DDP_PKG_SUCCESS:
4116 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
4117 hw->active_pkg_name,
4118 hw->active_pkg_ver.major,
4119 hw->active_pkg_ver.minor,
4120 hw->active_pkg_ver.update,
4121 hw->active_pkg_ver.draft);
4123 case ICE_DDP_PKG_SAME_VERSION_ALREADY_LOADED:
4124 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
4125 hw->active_pkg_name,
4126 hw->active_pkg_ver.major,
4127 hw->active_pkg_ver.minor,
4128 hw->active_pkg_ver.update,
4129 hw->active_pkg_ver.draft);
4131 case ICE_DDP_PKG_ALREADY_LOADED_NOT_SUPPORTED:
4132 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",
4133 hw->active_pkg_name,
4134 hw->active_pkg_ver.major,
4135 hw->active_pkg_ver.minor,
4136 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4138 case ICE_DDP_PKG_COMPATIBLE_ALREADY_LOADED:
4139 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",
4140 hw->active_pkg_name,
4141 hw->active_pkg_ver.major,
4142 hw->active_pkg_ver.minor,
4143 hw->active_pkg_ver.update,
4144 hw->active_pkg_ver.draft,
4151 case ICE_DDP_PKG_FW_MISMATCH:
4152 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");
4154 case ICE_DDP_PKG_INVALID_FILE:
4155 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
4157 case ICE_DDP_PKG_FILE_VERSION_TOO_HIGH:
4158 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
4160 case ICE_DDP_PKG_FILE_VERSION_TOO_LOW:
4161 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",
4162 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
4164 case ICE_DDP_PKG_FILE_SIGNATURE_INVALID:
4165 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");
4167 case ICE_DDP_PKG_FILE_REVISION_TOO_LOW:
4168 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");
4170 case ICE_DDP_PKG_LOAD_ERROR:
4171 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
4172 /* poll for reset to complete */
4173 if (ice_check_reset(hw))
4174 dev_err(dev, "Error resetting device. Please reload the driver\n");
4176 case ICE_DDP_PKG_ERR:
4178 dev_err(dev, "An unknown error occurred when loading the DDP package. Entering Safe Mode.\n");
4184 * ice_load_pkg - load/reload the DDP Package file
4185 * @firmware: firmware structure when firmware requested or NULL for reload
4186 * @pf: pointer to the PF instance
4188 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
4189 * initialize HW tables.
4192 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
4194 enum ice_ddp_state state = ICE_DDP_PKG_ERR;
4195 struct device *dev = ice_pf_to_dev(pf);
4196 struct ice_hw *hw = &pf->hw;
4198 /* Load DDP Package */
4199 if (firmware && !hw->pkg_copy) {
4200 state = ice_copy_and_init_pkg(hw, firmware->data,
4202 ice_log_pkg_init(hw, state);
4203 } else if (!firmware && hw->pkg_copy) {
4204 /* Reload package during rebuild after CORER/GLOBR reset */
4205 state = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
4206 ice_log_pkg_init(hw, state);
4208 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
4211 if (!ice_is_init_pkg_successful(state)) {
4213 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4217 /* Successful download package is the precondition for advanced
4218 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
4220 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
4224 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
4225 * @pf: pointer to the PF structure
4227 * There is no error returned here because the driver should be able to handle
4228 * 128 Byte cache lines, so we only print a warning in case issues are seen,
4229 * specifically with Tx.
4231 static void ice_verify_cacheline_size(struct ice_pf *pf)
4233 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
4234 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
4235 ICE_CACHE_LINE_BYTES);
4239 * ice_send_version - update firmware with driver version
4242 * Returns 0 on success, else error code
4244 static int ice_send_version(struct ice_pf *pf)
4246 struct ice_driver_ver dv;
4248 dv.major_ver = 0xff;
4249 dv.minor_ver = 0xff;
4250 dv.build_ver = 0xff;
4251 dv.subbuild_ver = 0;
4252 strscpy((char *)dv.driver_string, UTS_RELEASE,
4253 sizeof(dv.driver_string));
4254 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
4258 * ice_init_fdir - Initialize flow director VSI and configuration
4259 * @pf: pointer to the PF instance
4261 * returns 0 on success, negative on error
4263 static int ice_init_fdir(struct ice_pf *pf)
4265 struct device *dev = ice_pf_to_dev(pf);
4266 struct ice_vsi *ctrl_vsi;
4269 /* Side Band Flow Director needs to have a control VSI.
4270 * Allocate it and store it in the PF.
4272 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
4274 dev_dbg(dev, "could not create control VSI\n");
4278 err = ice_vsi_open_ctrl(ctrl_vsi);
4280 dev_dbg(dev, "could not open control VSI\n");
4284 mutex_init(&pf->hw.fdir_fltr_lock);
4286 err = ice_fdir_create_dflt_rules(pf);
4293 ice_fdir_release_flows(&pf->hw);
4294 ice_vsi_close(ctrl_vsi);
4296 ice_vsi_release(ctrl_vsi);
4297 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4298 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4299 pf->ctrl_vsi_idx = ICE_NO_VSI;
4305 * ice_get_opt_fw_name - return optional firmware file name or NULL
4306 * @pf: pointer to the PF instance
4308 static char *ice_get_opt_fw_name(struct ice_pf *pf)
4310 /* Optional firmware name same as default with additional dash
4311 * followed by a EUI-64 identifier (PCIe Device Serial Number)
4313 struct pci_dev *pdev = pf->pdev;
4314 char *opt_fw_filename;
4317 /* Determine the name of the optional file using the DSN (two
4318 * dwords following the start of the DSN Capability).
4320 dsn = pci_get_dsn(pdev);
4324 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
4325 if (!opt_fw_filename)
4328 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg",
4329 ICE_DDP_PKG_PATH, dsn);
4331 return opt_fw_filename;
4335 * ice_request_fw - Device initialization routine
4336 * @pf: pointer to the PF instance
4338 static void ice_request_fw(struct ice_pf *pf)
4340 char *opt_fw_filename = ice_get_opt_fw_name(pf);
4341 const struct firmware *firmware = NULL;
4342 struct device *dev = ice_pf_to_dev(pf);
4345 /* optional device-specific DDP (if present) overrides the default DDP
4346 * package file. kernel logs a debug message if the file doesn't exist,
4347 * and warning messages for other errors.
4349 if (opt_fw_filename) {
4350 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
4352 kfree(opt_fw_filename);
4356 /* request for firmware was successful. Download to device */
4357 ice_load_pkg(firmware, pf);
4358 kfree(opt_fw_filename);
4359 release_firmware(firmware);
4364 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
4366 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
4370 /* request for firmware was successful. Download to device */
4371 ice_load_pkg(firmware, pf);
4372 release_firmware(firmware);
4376 * ice_print_wake_reason - show the wake up cause in the log
4377 * @pf: pointer to the PF struct
4379 static void ice_print_wake_reason(struct ice_pf *pf)
4381 u32 wus = pf->wakeup_reason;
4382 const char *wake_str;
4384 /* if no wake event, nothing to print */
4388 if (wus & PFPM_WUS_LNKC_M)
4389 wake_str = "Link\n";
4390 else if (wus & PFPM_WUS_MAG_M)
4391 wake_str = "Magic Packet\n";
4392 else if (wus & PFPM_WUS_MNG_M)
4393 wake_str = "Management\n";
4394 else if (wus & PFPM_WUS_FW_RST_WK_M)
4395 wake_str = "Firmware Reset\n";
4397 wake_str = "Unknown\n";
4399 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
4403 * ice_register_netdev - register netdev and devlink port
4404 * @pf: pointer to the PF struct
4406 static int ice_register_netdev(struct ice_pf *pf)
4408 struct ice_vsi *vsi;
4411 vsi = ice_get_main_vsi(pf);
4412 if (!vsi || !vsi->netdev)
4415 err = register_netdev(vsi->netdev);
4417 goto err_register_netdev;
4419 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4420 netif_carrier_off(vsi->netdev);
4421 netif_tx_stop_all_queues(vsi->netdev);
4422 err = ice_devlink_create_pf_port(pf);
4424 goto err_devlink_create;
4426 devlink_port_type_eth_set(&pf->devlink_port, vsi->netdev);
4430 unregister_netdev(vsi->netdev);
4431 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4432 err_register_netdev:
4433 free_netdev(vsi->netdev);
4435 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4440 * ice_probe - Device initialization routine
4441 * @pdev: PCI device information struct
4442 * @ent: entry in ice_pci_tbl
4444 * Returns 0 on success, negative on failure
4447 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
4449 struct device *dev = &pdev->dev;
4454 if (pdev->is_virtfn) {
4455 dev_err(dev, "can't probe a virtual function\n");
4459 /* this driver uses devres, see
4460 * Documentation/driver-api/driver-model/devres.rst
4462 err = pcim_enable_device(pdev);
4466 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev));
4468 dev_err(dev, "BAR0 I/O map error %d\n", err);
4472 pf = ice_allocate_pf(dev);
4476 /* initialize Auxiliary index to invalid value */
4479 /* set up for high or low DMA */
4480 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
4482 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
4486 pci_enable_pcie_error_reporting(pdev);
4487 pci_set_master(pdev);
4490 pci_set_drvdata(pdev, pf);
4491 set_bit(ICE_DOWN, pf->state);
4492 /* Disable service task until DOWN bit is cleared */
4493 set_bit(ICE_SERVICE_DIS, pf->state);
4496 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
4497 pci_save_state(pdev);
4500 hw->vendor_id = pdev->vendor;
4501 hw->device_id = pdev->device;
4502 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
4503 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4504 hw->subsystem_device_id = pdev->subsystem_device;
4505 hw->bus.device = PCI_SLOT(pdev->devfn);
4506 hw->bus.func = PCI_FUNC(pdev->devfn);
4507 ice_set_ctrlq_len(hw);
4509 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
4511 #ifndef CONFIG_DYNAMIC_DEBUG
4513 hw->debug_mask = debug;
4516 err = ice_init_hw(hw);
4518 dev_err(dev, "ice_init_hw failed: %d\n", err);
4520 goto err_exit_unroll;
4523 ice_init_feature_support(pf);
4527 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
4528 * set in pf->state, which will cause ice_is_safe_mode to return
4531 if (ice_is_safe_mode(pf)) {
4532 /* we already got function/device capabilities but these don't
4533 * reflect what the driver needs to do in safe mode. Instead of
4534 * adding conditional logic everywhere to ignore these
4535 * device/function capabilities, override them.
4537 ice_set_safe_mode_caps(hw);
4540 err = ice_init_pf(pf);
4542 dev_err(dev, "ice_init_pf failed: %d\n", err);
4543 goto err_init_pf_unroll;
4546 ice_devlink_init_regions(pf);
4548 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port;
4549 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port;
4550 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
4551 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared;
4553 if (pf->hw.tnl.valid_count[TNL_VXLAN]) {
4554 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4555 pf->hw.tnl.valid_count[TNL_VXLAN];
4556 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4557 UDP_TUNNEL_TYPE_VXLAN;
4560 if (pf->hw.tnl.valid_count[TNL_GENEVE]) {
4561 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4562 pf->hw.tnl.valid_count[TNL_GENEVE];
4563 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4564 UDP_TUNNEL_TYPE_GENEVE;
4568 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
4569 if (!pf->num_alloc_vsi) {
4571 goto err_init_pf_unroll;
4573 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
4574 dev_warn(&pf->pdev->dev,
4575 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
4576 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
4577 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
4580 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
4584 goto err_init_pf_unroll;
4587 err = ice_init_interrupt_scheme(pf);
4589 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
4591 goto err_init_vsi_unroll;
4594 /* In case of MSIX we are going to setup the misc vector right here
4595 * to handle admin queue events etc. In case of legacy and MSI
4596 * the misc functionality and queue processing is combined in
4597 * the same vector and that gets setup at open.
4599 err = ice_req_irq_msix_misc(pf);
4601 dev_err(dev, "setup of misc vector failed: %d\n", err);
4602 goto err_init_interrupt_unroll;
4605 /* create switch struct for the switch element created by FW on boot */
4606 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
4607 if (!pf->first_sw) {
4609 goto err_msix_misc_unroll;
4613 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
4615 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
4617 pf->first_sw->pf = pf;
4619 /* record the sw_id available for later use */
4620 pf->first_sw->sw_id = hw->port_info->sw_id;
4622 err = ice_setup_pf_sw(pf);
4624 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
4625 goto err_alloc_sw_unroll;
4628 clear_bit(ICE_SERVICE_DIS, pf->state);
4630 /* tell the firmware we are up */
4631 err = ice_send_version(pf);
4633 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
4635 goto err_send_version_unroll;
4638 /* since everything is good, start the service timer */
4639 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4641 err = ice_init_link_events(pf->hw.port_info);
4643 dev_err(dev, "ice_init_link_events failed: %d\n", err);
4644 goto err_send_version_unroll;
4647 /* not a fatal error if this fails */
4648 err = ice_init_nvm_phy_type(pf->hw.port_info);
4650 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err);
4652 /* not a fatal error if this fails */
4653 err = ice_update_link_info(pf->hw.port_info);
4655 dev_err(dev, "ice_update_link_info failed: %d\n", err);
4657 ice_init_link_dflt_override(pf->hw.port_info);
4659 ice_check_link_cfg_err(pf,
4660 pf->hw.port_info->phy.link_info.link_cfg_err);
4662 /* if media available, initialize PHY settings */
4663 if (pf->hw.port_info->phy.link_info.link_info &
4664 ICE_AQ_MEDIA_AVAILABLE) {
4665 /* not a fatal error if this fails */
4666 err = ice_init_phy_user_cfg(pf->hw.port_info);
4668 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err);
4670 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) {
4671 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4674 ice_configure_phy(vsi);
4677 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
4680 ice_verify_cacheline_size(pf);
4682 /* Save wakeup reason register for later use */
4683 pf->wakeup_reason = rd32(hw, PFPM_WUS);
4685 /* check for a power management event */
4686 ice_print_wake_reason(pf);
4688 /* clear wake status, all bits */
4689 wr32(hw, PFPM_WUS, U32_MAX);
4691 /* Disable WoL at init, wait for user to enable */
4692 device_set_wakeup_enable(dev, false);
4694 if (ice_is_safe_mode(pf)) {
4695 ice_set_safe_mode_vlan_cfg(pf);
4699 /* initialize DDP driven features */
4700 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4703 /* Note: Flow director init failure is non-fatal to load */
4704 if (ice_init_fdir(pf))
4705 dev_err(dev, "could not initialize flow director\n");
4707 /* Note: DCB init failure is non-fatal to load */
4708 if (ice_init_pf_dcb(pf, false)) {
4709 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4710 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
4712 ice_cfg_lldp_mib_change(&pf->hw, true);
4715 if (ice_init_lag(pf))
4716 dev_warn(dev, "Failed to init link aggregation support\n");
4718 /* print PCI link speed and width */
4719 pcie_print_link_status(pf->pdev);
4722 err = ice_register_netdev(pf);
4724 goto err_netdev_reg;
4726 err = ice_devlink_register_params(pf);
4728 goto err_netdev_reg;
4730 /* ready to go, so clear down state bit */
4731 clear_bit(ICE_DOWN, pf->state);
4732 if (ice_is_aux_ena(pf)) {
4733 pf->aux_idx = ida_alloc(&ice_aux_ida, GFP_KERNEL);
4734 if (pf->aux_idx < 0) {
4735 dev_err(dev, "Failed to allocate device ID for AUX driver\n");
4737 goto err_devlink_reg_param;
4740 err = ice_init_rdma(pf);
4742 dev_err(dev, "Failed to initialize RDMA: %d\n", err);
4744 goto err_init_aux_unroll;
4747 dev_warn(dev, "RDMA is not supported on this device\n");
4750 ice_devlink_register(pf);
4753 err_init_aux_unroll:
4755 ida_free(&ice_aux_ida, pf->aux_idx);
4756 err_devlink_reg_param:
4757 ice_devlink_unregister_params(pf);
4759 err_send_version_unroll:
4760 ice_vsi_release_all(pf);
4761 err_alloc_sw_unroll:
4762 set_bit(ICE_SERVICE_DIS, pf->state);
4763 set_bit(ICE_DOWN, pf->state);
4764 devm_kfree(dev, pf->first_sw);
4765 err_msix_misc_unroll:
4766 ice_free_irq_msix_misc(pf);
4767 err_init_interrupt_unroll:
4768 ice_clear_interrupt_scheme(pf);
4769 err_init_vsi_unroll:
4770 devm_kfree(dev, pf->vsi);
4773 ice_devlink_destroy_regions(pf);
4776 pci_disable_pcie_error_reporting(pdev);
4777 pci_disable_device(pdev);
4782 * ice_set_wake - enable or disable Wake on LAN
4783 * @pf: pointer to the PF struct
4785 * Simple helper for WoL control
4787 static void ice_set_wake(struct ice_pf *pf)
4789 struct ice_hw *hw = &pf->hw;
4790 bool wol = pf->wol_ena;
4792 /* clear wake state, otherwise new wake events won't fire */
4793 wr32(hw, PFPM_WUS, U32_MAX);
4795 /* enable / disable APM wake up, no RMW needed */
4796 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0);
4798 /* set magic packet filter enabled */
4799 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0);
4803 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet
4804 * @pf: pointer to the PF struct
4806 * Issue firmware command to enable multicast magic wake, making
4807 * sure that any locally administered address (LAA) is used for
4808 * wake, and that PF reset doesn't undo the LAA.
4810 static void ice_setup_mc_magic_wake(struct ice_pf *pf)
4812 struct device *dev = ice_pf_to_dev(pf);
4813 struct ice_hw *hw = &pf->hw;
4814 u8 mac_addr[ETH_ALEN];
4815 struct ice_vsi *vsi;
4822 vsi = ice_get_main_vsi(pf);
4826 /* Get current MAC address in case it's an LAA */
4828 ether_addr_copy(mac_addr, vsi->netdev->dev_addr);
4830 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
4832 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN |
4833 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL |
4834 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP;
4836 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL);
4838 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %d aq_err %s\n",
4839 status, ice_aq_str(hw->adminq.sq_last_status));
4843 * ice_remove - Device removal routine
4844 * @pdev: PCI device information struct
4846 static void ice_remove(struct pci_dev *pdev)
4848 struct ice_pf *pf = pci_get_drvdata(pdev);
4851 ice_devlink_unregister(pf);
4852 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
4853 if (!ice_is_reset_in_progress(pf->state))
4858 ice_tc_indir_block_remove(pf);
4860 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4861 set_bit(ICE_VF_RESETS_DISABLED, pf->state);
4865 ice_service_task_stop(pf);
4867 ice_aq_cancel_waiting_tasks(pf);
4868 ice_unplug_aux_dev(pf);
4869 if (pf->aux_idx >= 0)
4870 ida_free(&ice_aux_ida, pf->aux_idx);
4871 ice_devlink_unregister_params(pf);
4872 set_bit(ICE_DOWN, pf->state);
4874 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
4876 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4877 ice_ptp_release(pf);
4878 if (!ice_is_safe_mode(pf))
4879 ice_remove_arfs(pf);
4880 ice_setup_mc_magic_wake(pf);
4881 ice_vsi_release_all(pf);
4883 ice_free_irq_msix_misc(pf);
4884 ice_for_each_vsi(pf, i) {
4887 ice_vsi_free_q_vectors(pf->vsi[i]);
4890 ice_devlink_destroy_regions(pf);
4891 ice_deinit_hw(&pf->hw);
4893 /* Issue a PFR as part of the prescribed driver unload flow. Do not
4894 * do it via ice_schedule_reset() since there is no need to rebuild
4895 * and the service task is already stopped.
4897 ice_reset(&pf->hw, ICE_RESET_PFR);
4898 pci_wait_for_pending_transaction(pdev);
4899 ice_clear_interrupt_scheme(pf);
4900 pci_disable_pcie_error_reporting(pdev);
4901 pci_disable_device(pdev);
4905 * ice_shutdown - PCI callback for shutting down device
4906 * @pdev: PCI device information struct
4908 static void ice_shutdown(struct pci_dev *pdev)
4910 struct ice_pf *pf = pci_get_drvdata(pdev);
4914 if (system_state == SYSTEM_POWER_OFF) {
4915 pci_wake_from_d3(pdev, pf->wol_ena);
4916 pci_set_power_state(pdev, PCI_D3hot);
4922 * ice_prepare_for_shutdown - prep for PCI shutdown
4923 * @pf: board private structure
4925 * Inform or close all dependent features in prep for PCI device shutdown
4927 static void ice_prepare_for_shutdown(struct ice_pf *pf)
4929 struct ice_hw *hw = &pf->hw;
4932 /* Notify VFs of impending reset */
4933 if (ice_check_sq_alive(hw, &hw->mailboxq))
4934 ice_vc_notify_reset(pf);
4936 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n");
4938 /* disable the VSIs and their queues that are not already DOWN */
4939 ice_pf_dis_all_vsi(pf, false);
4941 ice_for_each_vsi(pf, v)
4943 pf->vsi[v]->vsi_num = 0;
4945 ice_shutdown_all_ctrlq(hw);
4949 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme
4950 * @pf: board private structure to reinitialize
4952 * This routine reinitialize interrupt scheme that was cleared during
4953 * power management suspend callback.
4955 * This should be called during resume routine to re-allocate the q_vectors
4956 * and reacquire interrupts.
4958 static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
4960 struct device *dev = ice_pf_to_dev(pf);
4963 /* Since we clear MSIX flag during suspend, we need to
4964 * set it back during resume...
4967 ret = ice_init_interrupt_scheme(pf);
4969 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret);
4973 /* Remap vectors and rings, after successful re-init interrupts */
4974 ice_for_each_vsi(pf, v) {
4978 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]);
4981 ice_vsi_map_rings_to_vectors(pf->vsi[v]);
4984 ret = ice_req_irq_msix_misc(pf);
4986 dev_err(dev, "Setting up misc vector failed after device suspend %d\n",
4996 ice_vsi_free_q_vectors(pf->vsi[v]);
5003 * @dev: generic device information structure
5005 * Power Management callback to quiesce the device and prepare
5006 * for D3 transition.
5008 static int __maybe_unused ice_suspend(struct device *dev)
5010 struct pci_dev *pdev = to_pci_dev(dev);
5014 pf = pci_get_drvdata(pdev);
5016 if (!ice_pf_state_is_nominal(pf)) {
5017 dev_err(dev, "Device is not ready, no need to suspend it\n");
5021 /* Stop watchdog tasks until resume completion.
5022 * Even though it is most likely that the service task is
5023 * disabled if the device is suspended or down, the service task's
5024 * state is controlled by a different state bit, and we should
5025 * store and honor whatever state that bit is in at this point.
5027 disabled = ice_service_task_stop(pf);
5029 ice_unplug_aux_dev(pf);
5031 /* Already suspended?, then there is nothing to do */
5032 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) {
5034 ice_service_task_restart(pf);
5038 if (test_bit(ICE_DOWN, pf->state) ||
5039 ice_is_reset_in_progress(pf->state)) {
5040 dev_err(dev, "can't suspend device in reset or already down\n");
5042 ice_service_task_restart(pf);
5046 ice_setup_mc_magic_wake(pf);
5048 ice_prepare_for_shutdown(pf);
5052 /* Free vectors, clear the interrupt scheme and release IRQs
5053 * for proper hibernation, especially with large number of CPUs.
5054 * Otherwise hibernation might fail when mapping all the vectors back
5057 ice_free_irq_msix_misc(pf);
5058 ice_for_each_vsi(pf, v) {
5061 ice_vsi_free_q_vectors(pf->vsi[v]);
5063 ice_free_cpu_rx_rmap(ice_get_main_vsi(pf));
5064 ice_clear_interrupt_scheme(pf);
5066 pci_save_state(pdev);
5067 pci_wake_from_d3(pdev, pf->wol_ena);
5068 pci_set_power_state(pdev, PCI_D3hot);
5073 * ice_resume - PM callback for waking up from D3
5074 * @dev: generic device information structure
5076 static int __maybe_unused ice_resume(struct device *dev)
5078 struct pci_dev *pdev = to_pci_dev(dev);
5079 enum ice_reset_req reset_type;
5084 pci_set_power_state(pdev, PCI_D0);
5085 pci_restore_state(pdev);
5086 pci_save_state(pdev);
5088 if (!pci_device_is_present(pdev))
5091 ret = pci_enable_device_mem(pdev);
5093 dev_err(dev, "Cannot enable device after suspend\n");
5097 pf = pci_get_drvdata(pdev);
5100 pf->wakeup_reason = rd32(hw, PFPM_WUS);
5101 ice_print_wake_reason(pf);
5103 /* We cleared the interrupt scheme when we suspended, so we need to
5104 * restore it now to resume device functionality.
5106 ret = ice_reinit_interrupt_scheme(pf);
5108 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret);
5110 clear_bit(ICE_DOWN, pf->state);
5111 /* Now perform PF reset and rebuild */
5112 reset_type = ICE_RESET_PFR;
5113 /* re-enable service task for reset, but allow reset to schedule it */
5114 clear_bit(ICE_SERVICE_DIS, pf->state);
5116 if (ice_schedule_reset(pf, reset_type))
5117 dev_err(dev, "Reset during resume failed.\n");
5119 clear_bit(ICE_SUSPENDED, pf->state);
5120 ice_service_task_restart(pf);
5122 /* Restart the service task */
5123 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5127 #endif /* CONFIG_PM */
5130 * ice_pci_err_detected - warning that PCI error has been detected
5131 * @pdev: PCI device information struct
5132 * @err: the type of PCI error
5134 * Called to warn that something happened on the PCI bus and the error handling
5135 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
5137 static pci_ers_result_t
5138 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err)
5140 struct ice_pf *pf = pci_get_drvdata(pdev);
5143 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
5145 return PCI_ERS_RESULT_DISCONNECT;
5148 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5149 ice_service_task_stop(pf);
5151 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5152 set_bit(ICE_PFR_REQ, pf->state);
5153 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5157 return PCI_ERS_RESULT_NEED_RESET;
5161 * ice_pci_err_slot_reset - a PCI slot reset has just happened
5162 * @pdev: PCI device information struct
5164 * Called to determine if the driver can recover from the PCI slot reset by
5165 * using a register read to determine if the device is recoverable.
5167 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
5169 struct ice_pf *pf = pci_get_drvdata(pdev);
5170 pci_ers_result_t result;
5174 err = pci_enable_device_mem(pdev);
5176 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
5178 result = PCI_ERS_RESULT_DISCONNECT;
5180 pci_set_master(pdev);
5181 pci_restore_state(pdev);
5182 pci_save_state(pdev);
5183 pci_wake_from_d3(pdev, false);
5185 /* Check for life */
5186 reg = rd32(&pf->hw, GLGEN_RTRIG);
5188 result = PCI_ERS_RESULT_RECOVERED;
5190 result = PCI_ERS_RESULT_DISCONNECT;
5193 err = pci_aer_clear_nonfatal_status(pdev);
5195 dev_dbg(&pdev->dev, "pci_aer_clear_nonfatal_status() failed, error %d\n",
5197 /* non-fatal, continue */
5203 * ice_pci_err_resume - restart operations after PCI error recovery
5204 * @pdev: PCI device information struct
5206 * Called to allow the driver to bring things back up after PCI error and/or
5207 * reset recovery have finished
5209 static void ice_pci_err_resume(struct pci_dev *pdev)
5211 struct ice_pf *pf = pci_get_drvdata(pdev);
5214 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
5219 if (test_bit(ICE_SUSPENDED, pf->state)) {
5220 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
5225 ice_restore_all_vfs_msi_state(pdev);
5227 ice_do_reset(pf, ICE_RESET_PFR);
5228 ice_service_task_restart(pf);
5229 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
5233 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
5234 * @pdev: PCI device information struct
5236 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
5238 struct ice_pf *pf = pci_get_drvdata(pdev);
5240 if (!test_bit(ICE_SUSPENDED, pf->state)) {
5241 ice_service_task_stop(pf);
5243 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
5244 set_bit(ICE_PFR_REQ, pf->state);
5245 ice_prepare_for_reset(pf, ICE_RESET_PFR);
5251 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
5252 * @pdev: PCI device information struct
5254 static void ice_pci_err_reset_done(struct pci_dev *pdev)
5256 ice_pci_err_resume(pdev);
5259 /* ice_pci_tbl - PCI Device ID Table
5261 * Wildcard entries (PCI_ANY_ID) should come last
5262 * Last entry must be all 0s
5264 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
5265 * Class, Class Mask, private data (not used) }
5267 static const struct pci_device_id ice_pci_tbl[] = {
5268 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
5269 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
5270 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
5271 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_BACKPLANE), 0 },
5272 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_QSFP), 0 },
5273 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 },
5274 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 },
5275 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 },
5276 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 },
5277 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 },
5278 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 },
5279 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
5280 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
5281 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
5282 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
5283 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
5284 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 },
5285 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
5286 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
5287 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
5288 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 },
5289 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 },
5290 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 },
5291 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 },
5292 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 },
5293 /* required last entry */
5296 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
5298 static __maybe_unused SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume);
5300 static const struct pci_error_handlers ice_pci_err_handler = {
5301 .error_detected = ice_pci_err_detected,
5302 .slot_reset = ice_pci_err_slot_reset,
5303 .reset_prepare = ice_pci_err_reset_prepare,
5304 .reset_done = ice_pci_err_reset_done,
5305 .resume = ice_pci_err_resume
5308 static struct pci_driver ice_driver = {
5309 .name = KBUILD_MODNAME,
5310 .id_table = ice_pci_tbl,
5312 .remove = ice_remove,
5314 .driver.pm = &ice_pm_ops,
5315 #endif /* CONFIG_PM */
5316 .shutdown = ice_shutdown,
5317 .sriov_configure = ice_sriov_configure,
5318 .err_handler = &ice_pci_err_handler
5322 * ice_module_init - Driver registration routine
5324 * ice_module_init is the first routine called when the driver is
5325 * loaded. All it does is register with the PCI subsystem.
5327 static int __init ice_module_init(void)
5331 pr_info("%s\n", ice_driver_string);
5332 pr_info("%s\n", ice_copyright);
5334 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
5336 pr_err("Failed to create workqueue\n");
5340 status = pci_register_driver(&ice_driver);
5342 pr_err("failed to register PCI driver, err %d\n", status);
5343 destroy_workqueue(ice_wq);
5348 module_init(ice_module_init);
5351 * ice_module_exit - Driver exit cleanup routine
5353 * ice_module_exit is called just before the driver is removed
5356 static void __exit ice_module_exit(void)
5358 pci_unregister_driver(&ice_driver);
5359 destroy_workqueue(ice_wq);
5360 pr_info("module unloaded\n");
5362 module_exit(ice_module_exit);
5365 * ice_set_mac_address - NDO callback to set MAC address
5366 * @netdev: network interface device structure
5367 * @pi: pointer to an address structure
5369 * Returns 0 on success, negative on failure
5371 static int ice_set_mac_address(struct net_device *netdev, void *pi)
5373 struct ice_netdev_priv *np = netdev_priv(netdev);
5374 struct ice_vsi *vsi = np->vsi;
5375 struct ice_pf *pf = vsi->back;
5376 struct ice_hw *hw = &pf->hw;
5377 struct sockaddr *addr = pi;
5378 u8 old_mac[ETH_ALEN];
5383 mac = (u8 *)addr->sa_data;
5385 if (!is_valid_ether_addr(mac))
5386 return -EADDRNOTAVAIL;
5388 if (ether_addr_equal(netdev->dev_addr, mac)) {
5389 netdev_dbg(netdev, "already using mac %pM\n", mac);
5393 if (test_bit(ICE_DOWN, pf->state) ||
5394 ice_is_reset_in_progress(pf->state)) {
5395 netdev_err(netdev, "can't set mac %pM. device not ready\n",
5400 if (ice_chnl_dmac_fltr_cnt(pf)) {
5401 netdev_err(netdev, "can't set mac %pM. Device has tc-flower filters, delete all of them and try again\n",
5406 netif_addr_lock_bh(netdev);
5407 ether_addr_copy(old_mac, netdev->dev_addr);
5408 /* change the netdev's MAC address */
5409 eth_hw_addr_set(netdev, mac);
5410 netif_addr_unlock_bh(netdev);
5412 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
5413 err = ice_fltr_remove_mac(vsi, old_mac, ICE_FWD_TO_VSI);
5414 if (err && err != -ENOENT) {
5415 err = -EADDRNOTAVAIL;
5416 goto err_update_filters;
5419 /* Add filter for new MAC. If filter exists, return success */
5420 err = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
5422 /* Although this MAC filter is already present in hardware it's
5423 * possible in some cases (e.g. bonding) that dev_addr was
5424 * modified outside of the driver and needs to be restored back
5427 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
5429 /* error if the new filter addition failed */
5430 err = -EADDRNOTAVAIL;
5434 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
5436 netif_addr_lock_bh(netdev);
5437 eth_hw_addr_set(netdev, old_mac);
5438 netif_addr_unlock_bh(netdev);
5442 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
5445 /* write new MAC address to the firmware */
5446 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
5447 err = ice_aq_manage_mac_write(hw, mac, flags, NULL);
5449 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %d\n",
5456 * ice_set_rx_mode - NDO callback to set the netdev filters
5457 * @netdev: network interface device structure
5459 static void ice_set_rx_mode(struct net_device *netdev)
5461 struct ice_netdev_priv *np = netdev_priv(netdev);
5462 struct ice_vsi *vsi = np->vsi;
5467 /* Set the flags to synchronize filters
5468 * ndo_set_rx_mode may be triggered even without a change in netdev
5471 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
5472 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
5473 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
5475 /* schedule our worker thread which will take care of
5476 * applying the new filter changes
5478 ice_service_task_schedule(vsi->back);
5482 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
5483 * @netdev: network interface device structure
5484 * @queue_index: Queue ID
5485 * @maxrate: maximum bandwidth in Mbps
5488 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
5490 struct ice_netdev_priv *np = netdev_priv(netdev);
5491 struct ice_vsi *vsi = np->vsi;
5496 /* Validate maxrate requested is within permitted range */
5497 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
5498 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
5499 maxrate, queue_index);
5503 q_handle = vsi->tx_rings[queue_index]->q_handle;
5504 tc = ice_dcb_get_tc(vsi, queue_index);
5506 /* Set BW back to default, when user set maxrate to 0 */
5508 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
5509 q_handle, ICE_MAX_BW);
5511 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
5512 q_handle, ICE_MAX_BW, maxrate * 1000);
5514 netdev_err(netdev, "Unable to set Tx max rate, error %d\n",
5521 * ice_fdb_add - add an entry to the hardware database
5522 * @ndm: the input from the stack
5523 * @tb: pointer to array of nladdr (unused)
5524 * @dev: the net device pointer
5525 * @addr: the MAC address entry being added
5527 * @flags: instructions from stack about fdb operation
5528 * @extack: netlink extended ack
5531 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
5532 struct net_device *dev, const unsigned char *addr, u16 vid,
5533 u16 flags, struct netlink_ext_ack __always_unused *extack)
5538 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
5541 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
5542 netdev_err(dev, "FDB only supports static addresses\n");
5546 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
5547 err = dev_uc_add_excl(dev, addr);
5548 else if (is_multicast_ether_addr(addr))
5549 err = dev_mc_add_excl(dev, addr);
5553 /* Only return duplicate errors if NLM_F_EXCL is set */
5554 if (err == -EEXIST && !(flags & NLM_F_EXCL))
5561 * ice_fdb_del - delete an entry from the hardware database
5562 * @ndm: the input from the stack
5563 * @tb: pointer to array of nladdr (unused)
5564 * @dev: the net device pointer
5565 * @addr: the MAC address entry being added
5569 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
5570 struct net_device *dev, const unsigned char *addr,
5571 __always_unused u16 vid)
5575 if (ndm->ndm_state & NUD_PERMANENT) {
5576 netdev_err(dev, "FDB only supports static addresses\n");
5580 if (is_unicast_ether_addr(addr))
5581 err = dev_uc_del(dev, addr);
5582 else if (is_multicast_ether_addr(addr))
5583 err = dev_mc_del(dev, addr);
5590 #define NETIF_VLAN_OFFLOAD_FEATURES (NETIF_F_HW_VLAN_CTAG_RX | \
5591 NETIF_F_HW_VLAN_CTAG_TX | \
5592 NETIF_F_HW_VLAN_STAG_RX | \
5593 NETIF_F_HW_VLAN_STAG_TX)
5595 #define NETIF_VLAN_FILTERING_FEATURES (NETIF_F_HW_VLAN_CTAG_FILTER | \
5596 NETIF_F_HW_VLAN_STAG_FILTER)
5599 * ice_fix_features - fix the netdev features flags based on device limitations
5600 * @netdev: ptr to the netdev that flags are being fixed on
5601 * @features: features that need to be checked and possibly fixed
5603 * Make sure any fixups are made to features in this callback. This enables the
5604 * driver to not have to check unsupported configurations throughout the driver
5605 * because that's the responsiblity of this callback.
5607 * Single VLAN Mode (SVM) Supported Features:
5608 * NETIF_F_HW_VLAN_CTAG_FILTER
5609 * NETIF_F_HW_VLAN_CTAG_RX
5610 * NETIF_F_HW_VLAN_CTAG_TX
5612 * Double VLAN Mode (DVM) Supported Features:
5613 * NETIF_F_HW_VLAN_CTAG_FILTER
5614 * NETIF_F_HW_VLAN_CTAG_RX
5615 * NETIF_F_HW_VLAN_CTAG_TX
5617 * NETIF_F_HW_VLAN_STAG_FILTER
5618 * NETIF_HW_VLAN_STAG_RX
5619 * NETIF_HW_VLAN_STAG_TX
5621 * Features that need fixing:
5622 * Cannot simultaneously enable CTAG and STAG stripping and/or insertion.
5623 * These are mutually exlusive as the VSI context cannot support multiple
5624 * VLAN ethertypes simultaneously for stripping and/or insertion. If this
5625 * is not done, then default to clearing the requested STAG offload
5628 * All supported filtering has to be enabled or disabled together. For
5629 * example, in DVM, CTAG and STAG filtering have to be enabled and disabled
5630 * together. If this is not done, then default to VLAN filtering disabled.
5631 * These are mutually exclusive as there is currently no way to
5632 * enable/disable VLAN filtering based on VLAN ethertype when using VLAN
5635 static netdev_features_t
5636 ice_fix_features(struct net_device *netdev, netdev_features_t features)
5638 struct ice_netdev_priv *np = netdev_priv(netdev);
5639 netdev_features_t supported_vlan_filtering;
5640 netdev_features_t requested_vlan_filtering;
5641 struct ice_vsi *vsi = np->vsi;
5643 requested_vlan_filtering = features & NETIF_VLAN_FILTERING_FEATURES;
5645 /* make sure supported_vlan_filtering works for both SVM and DVM */
5646 supported_vlan_filtering = NETIF_F_HW_VLAN_CTAG_FILTER;
5647 if (ice_is_dvm_ena(&vsi->back->hw))
5648 supported_vlan_filtering |= NETIF_F_HW_VLAN_STAG_FILTER;
5650 if (requested_vlan_filtering &&
5651 requested_vlan_filtering != supported_vlan_filtering) {
5652 if (requested_vlan_filtering & NETIF_F_HW_VLAN_CTAG_FILTER) {
5653 netdev_warn(netdev, "cannot support requested VLAN filtering settings, enabling all supported VLAN filtering settings\n");
5654 features |= supported_vlan_filtering;
5656 netdev_warn(netdev, "cannot support requested VLAN filtering settings, clearing all supported VLAN filtering settings\n");
5657 features &= ~supported_vlan_filtering;
5661 if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX)) &&
5662 (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))) {
5663 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");
5664 features &= ~(NETIF_F_HW_VLAN_STAG_RX |
5665 NETIF_F_HW_VLAN_STAG_TX);
5672 * ice_set_vlan_offload_features - set VLAN offload features for the PF VSI
5674 * @features: features used to determine VLAN offload settings
5676 * First, determine the vlan_ethertype based on the VLAN offload bits in
5677 * features. Then determine if stripping and insertion should be enabled or
5678 * disabled. Finally enable or disable VLAN stripping and insertion.
5681 ice_set_vlan_offload_features(struct ice_vsi *vsi, netdev_features_t features)
5683 bool enable_stripping = true, enable_insertion = true;
5684 struct ice_vsi_vlan_ops *vlan_ops;
5685 int strip_err = 0, insert_err = 0;
5686 u16 vlan_ethertype = 0;
5688 vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5690 if (features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX))
5691 vlan_ethertype = ETH_P_8021AD;
5692 else if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX))
5693 vlan_ethertype = ETH_P_8021Q;
5695 if (!(features & (NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_CTAG_RX)))
5696 enable_stripping = false;
5697 if (!(features & (NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_CTAG_TX)))
5698 enable_insertion = false;
5700 if (enable_stripping)
5701 strip_err = vlan_ops->ena_stripping(vsi, vlan_ethertype);
5703 strip_err = vlan_ops->dis_stripping(vsi);
5705 if (enable_insertion)
5706 insert_err = vlan_ops->ena_insertion(vsi, vlan_ethertype);
5708 insert_err = vlan_ops->dis_insertion(vsi);
5710 if (strip_err || insert_err)
5717 * ice_set_vlan_filtering_features - set VLAN filtering features for the PF VSI
5719 * @features: features used to determine VLAN filtering settings
5721 * Enable or disable Rx VLAN filtering based on the VLAN filtering bits in the
5725 ice_set_vlan_filtering_features(struct ice_vsi *vsi, netdev_features_t features)
5727 struct ice_vsi_vlan_ops *vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
5730 /* support Single VLAN Mode (SVM) and Double VLAN Mode (DVM) by checking
5731 * if either bit is set
5734 (NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER))
5735 err = vlan_ops->ena_rx_filtering(vsi);
5737 err = vlan_ops->dis_rx_filtering(vsi);
5743 * ice_set_vlan_features - set VLAN settings based on suggested feature set
5744 * @netdev: ptr to the netdev being adjusted
5745 * @features: the feature set that the stack is suggesting
5747 * Only update VLAN settings if the requested_vlan_features are different than
5748 * the current_vlan_features.
5751 ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
5753 netdev_features_t current_vlan_features, requested_vlan_features;
5754 struct ice_netdev_priv *np = netdev_priv(netdev);
5755 struct ice_vsi *vsi = np->vsi;
5758 current_vlan_features = netdev->features & NETIF_VLAN_OFFLOAD_FEATURES;
5759 requested_vlan_features = features & NETIF_VLAN_OFFLOAD_FEATURES;
5760 if (current_vlan_features ^ requested_vlan_features) {
5761 err = ice_set_vlan_offload_features(vsi, features);
5766 current_vlan_features = netdev->features &
5767 NETIF_VLAN_FILTERING_FEATURES;
5768 requested_vlan_features = features & NETIF_VLAN_FILTERING_FEATURES;
5769 if (current_vlan_features ^ requested_vlan_features) {
5770 err = ice_set_vlan_filtering_features(vsi, features);
5779 * ice_set_features - set the netdev feature flags
5780 * @netdev: ptr to the netdev being adjusted
5781 * @features: the feature set that the stack is suggesting
5784 ice_set_features(struct net_device *netdev, netdev_features_t features)
5786 struct ice_netdev_priv *np = netdev_priv(netdev);
5787 struct ice_vsi *vsi = np->vsi;
5788 struct ice_pf *pf = vsi->back;
5791 /* Don't set any netdev advanced features with device in Safe Mode */
5792 if (ice_is_safe_mode(vsi->back)) {
5793 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
5797 /* Do not change setting during reset */
5798 if (ice_is_reset_in_progress(pf->state)) {
5799 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
5803 /* Multiple features can be changed in one call so keep features in
5804 * separate if/else statements to guarantee each feature is checked
5806 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
5807 ice_vsi_manage_rss_lut(vsi, true);
5808 else if (!(features & NETIF_F_RXHASH) &&
5809 netdev->features & NETIF_F_RXHASH)
5810 ice_vsi_manage_rss_lut(vsi, false);
5812 ret = ice_set_vlan_features(netdev, features);
5816 if ((features & NETIF_F_NTUPLE) &&
5817 !(netdev->features & NETIF_F_NTUPLE)) {
5818 ice_vsi_manage_fdir(vsi, true);
5820 } else if (!(features & NETIF_F_NTUPLE) &&
5821 (netdev->features & NETIF_F_NTUPLE)) {
5822 ice_vsi_manage_fdir(vsi, false);
5823 ice_clear_arfs(vsi);
5826 /* don't turn off hw_tc_offload when ADQ is already enabled */
5827 if (!(features & NETIF_F_HW_TC) && ice_is_adq_active(pf)) {
5828 dev_err(ice_pf_to_dev(pf), "ADQ is active, can't turn hw_tc_offload off\n");
5832 if ((features & NETIF_F_HW_TC) &&
5833 !(netdev->features & NETIF_F_HW_TC))
5834 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5836 clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
5842 * ice_vsi_vlan_setup - Setup VLAN offload properties on a PF VSI
5843 * @vsi: VSI to setup VLAN properties for
5845 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
5849 err = ice_set_vlan_offload_features(vsi, vsi->netdev->features);
5853 err = ice_set_vlan_filtering_features(vsi, vsi->netdev->features);
5857 return ice_vsi_add_vlan_zero(vsi);
5861 * ice_vsi_cfg - Setup the VSI
5862 * @vsi: the VSI being configured
5864 * Return 0 on success and negative value on error
5866 int ice_vsi_cfg(struct ice_vsi *vsi)
5871 ice_set_rx_mode(vsi->netdev);
5873 err = ice_vsi_vlan_setup(vsi);
5878 ice_vsi_cfg_dcb_rings(vsi);
5880 err = ice_vsi_cfg_lan_txqs(vsi);
5881 if (!err && ice_is_xdp_ena_vsi(vsi))
5882 err = ice_vsi_cfg_xdp_txqs(vsi);
5884 err = ice_vsi_cfg_rxqs(vsi);
5889 /* THEORY OF MODERATION:
5890 * The ice driver hardware works differently than the hardware that DIMLIB was
5891 * originally made for. ice hardware doesn't have packet count limits that
5892 * can trigger an interrupt, but it *does* have interrupt rate limit support,
5893 * which is hard-coded to a limit of 250,000 ints/second.
5894 * If not using dynamic moderation, the INTRL value can be modified
5895 * by ethtool rx-usecs-high.
5898 /* the throttle rate for interrupts, basically worst case delay before
5899 * an initial interrupt fires, value is stored in microseconds.
5904 /* Make a different profile for Rx that doesn't allow quite so aggressive
5905 * moderation at the high end (it maxes out at 126us or about 8k interrupts a
5908 static const struct ice_dim rx_profile[] = {
5909 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
5910 {8}, /* 125,000 ints/s */
5911 {16}, /* 62,500 ints/s */
5912 {62}, /* 16,129 ints/s */
5913 {126} /* 7,936 ints/s */
5916 /* The transmit profile, which has the same sorts of values
5917 * as the previous struct
5919 static const struct ice_dim tx_profile[] = {
5920 {2}, /* 500,000 ints/s, capped at 250K by INTRL */
5921 {8}, /* 125,000 ints/s */
5922 {40}, /* 16,125 ints/s */
5923 {128}, /* 7,812 ints/s */
5924 {256} /* 3,906 ints/s */
5927 static void ice_tx_dim_work(struct work_struct *work)
5929 struct ice_ring_container *rc;
5933 dim = container_of(work, struct dim, work);
5934 rc = (struct ice_ring_container *)dim->priv;
5936 WARN_ON(dim->profile_ix >= ARRAY_SIZE(tx_profile));
5938 /* look up the values in our local table */
5939 itr = tx_profile[dim->profile_ix].itr;
5941 ice_trace(tx_dim_work, container_of(rc, struct ice_q_vector, tx), dim);
5942 ice_write_itr(rc, itr);
5944 dim->state = DIM_START_MEASURE;
5947 static void ice_rx_dim_work(struct work_struct *work)
5949 struct ice_ring_container *rc;
5953 dim = container_of(work, struct dim, work);
5954 rc = (struct ice_ring_container *)dim->priv;
5956 WARN_ON(dim->profile_ix >= ARRAY_SIZE(rx_profile));
5958 /* look up the values in our local table */
5959 itr = rx_profile[dim->profile_ix].itr;
5961 ice_trace(rx_dim_work, container_of(rc, struct ice_q_vector, rx), dim);
5962 ice_write_itr(rc, itr);
5964 dim->state = DIM_START_MEASURE;
5967 #define ICE_DIM_DEFAULT_PROFILE_IX 1
5970 * ice_init_moderation - set up interrupt moderation
5971 * @q_vector: the vector containing rings to be configured
5973 * Set up interrupt moderation registers, with the intent to do the right thing
5974 * when called from reset or from probe, and whether or not dynamic moderation
5975 * is enabled or not. Take special care to write all the registers in both
5976 * dynamic moderation mode or not in order to make sure hardware is in a known
5979 static void ice_init_moderation(struct ice_q_vector *q_vector)
5981 struct ice_ring_container *rc;
5982 bool tx_dynamic, rx_dynamic;
5985 INIT_WORK(&rc->dim.work, ice_tx_dim_work);
5986 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
5987 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
5989 tx_dynamic = ITR_IS_DYNAMIC(rc);
5991 /* set the initial TX ITR to match the above */
5992 ice_write_itr(rc, tx_dynamic ?
5993 tx_profile[rc->dim.profile_ix].itr : rc->itr_setting);
5996 INIT_WORK(&rc->dim.work, ice_rx_dim_work);
5997 rc->dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
5998 rc->dim.profile_ix = ICE_DIM_DEFAULT_PROFILE_IX;
6000 rx_dynamic = ITR_IS_DYNAMIC(rc);
6002 /* set the initial RX ITR to match the above */
6003 ice_write_itr(rc, rx_dynamic ? rx_profile[rc->dim.profile_ix].itr :
6006 ice_set_q_vector_intrl(q_vector);
6010 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
6011 * @vsi: the VSI being configured
6013 static void ice_napi_enable_all(struct ice_vsi *vsi)
6020 ice_for_each_q_vector(vsi, q_idx) {
6021 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6023 ice_init_moderation(q_vector);
6025 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6026 napi_enable(&q_vector->napi);
6031 * ice_up_complete - Finish the last steps of bringing up a connection
6032 * @vsi: The VSI being configured
6034 * Return 0 on success and negative value on error
6036 static int ice_up_complete(struct ice_vsi *vsi)
6038 struct ice_pf *pf = vsi->back;
6041 ice_vsi_cfg_msix(vsi);
6043 /* Enable only Rx rings, Tx rings were enabled by the FW when the
6044 * Tx queue group list was configured and the context bits were
6045 * programmed using ice_vsi_cfg_txqs
6047 err = ice_vsi_start_all_rx_rings(vsi);
6051 clear_bit(ICE_VSI_DOWN, vsi->state);
6052 ice_napi_enable_all(vsi);
6053 ice_vsi_ena_irq(vsi);
6055 if (vsi->port_info &&
6056 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
6058 ice_print_link_msg(vsi, true);
6059 netif_tx_start_all_queues(vsi->netdev);
6060 netif_carrier_on(vsi->netdev);
6061 if (!ice_is_e810(&pf->hw))
6062 ice_ptp_link_change(pf, pf->hw.pf_id, true);
6065 /* clear this now, and the first stats read will be used as baseline */
6066 vsi->stat_offsets_loaded = false;
6068 ice_service_task_schedule(pf);
6074 * ice_up - Bring the connection back up after being down
6075 * @vsi: VSI being configured
6077 int ice_up(struct ice_vsi *vsi)
6081 err = ice_vsi_cfg(vsi);
6083 err = ice_up_complete(vsi);
6089 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
6090 * @syncp: pointer to u64_stats_sync
6091 * @stats: stats that pkts and bytes count will be taken from
6092 * @pkts: packets stats counter
6093 * @bytes: bytes stats counter
6095 * This function fetches stats from the ring considering the atomic operations
6096 * that needs to be performed to read u64 values in 32 bit machine.
6099 ice_fetch_u64_stats_per_ring(struct u64_stats_sync *syncp, struct ice_q_stats stats,
6100 u64 *pkts, u64 *bytes)
6105 start = u64_stats_fetch_begin_irq(syncp);
6107 *bytes = stats.bytes;
6108 } while (u64_stats_fetch_retry_irq(syncp, start));
6112 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters
6113 * @vsi: the VSI to be updated
6114 * @vsi_stats: the stats struct to be updated
6115 * @rings: rings to work on
6116 * @count: number of rings
6119 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi,
6120 struct rtnl_link_stats64 *vsi_stats,
6121 struct ice_tx_ring **rings, u16 count)
6125 for (i = 0; i < count; i++) {
6126 struct ice_tx_ring *ring;
6127 u64 pkts = 0, bytes = 0;
6129 ring = READ_ONCE(rings[i]);
6131 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6132 vsi_stats->tx_packets += pkts;
6133 vsi_stats->tx_bytes += bytes;
6134 vsi->tx_restart += ring->tx_stats.restart_q;
6135 vsi->tx_busy += ring->tx_stats.tx_busy;
6136 vsi->tx_linearize += ring->tx_stats.tx_linearize;
6141 * ice_update_vsi_ring_stats - Update VSI stats counters
6142 * @vsi: the VSI to be updated
6144 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
6146 struct rtnl_link_stats64 *vsi_stats;
6150 vsi_stats = kzalloc(sizeof(*vsi_stats), GFP_ATOMIC);
6154 /* reset non-netdev (extended) stats */
6155 vsi->tx_restart = 0;
6157 vsi->tx_linearize = 0;
6158 vsi->rx_buf_failed = 0;
6159 vsi->rx_page_failed = 0;
6163 /* update Tx rings counters */
6164 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->tx_rings,
6167 /* update Rx rings counters */
6168 ice_for_each_rxq(vsi, i) {
6169 struct ice_rx_ring *ring = READ_ONCE(vsi->rx_rings[i]);
6171 ice_fetch_u64_stats_per_ring(&ring->syncp, ring->stats, &pkts, &bytes);
6172 vsi_stats->rx_packets += pkts;
6173 vsi_stats->rx_bytes += bytes;
6174 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
6175 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
6178 /* update XDP Tx rings counters */
6179 if (ice_is_xdp_ena_vsi(vsi))
6180 ice_update_vsi_tx_ring_stats(vsi, vsi_stats, vsi->xdp_rings,
6185 vsi->net_stats.tx_packets = vsi_stats->tx_packets;
6186 vsi->net_stats.tx_bytes = vsi_stats->tx_bytes;
6187 vsi->net_stats.rx_packets = vsi_stats->rx_packets;
6188 vsi->net_stats.rx_bytes = vsi_stats->rx_bytes;
6194 * ice_update_vsi_stats - Update VSI stats counters
6195 * @vsi: the VSI to be updated
6197 void ice_update_vsi_stats(struct ice_vsi *vsi)
6199 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
6200 struct ice_eth_stats *cur_es = &vsi->eth_stats;
6201 struct ice_pf *pf = vsi->back;
6203 if (test_bit(ICE_VSI_DOWN, vsi->state) ||
6204 test_bit(ICE_CFG_BUSY, pf->state))
6207 /* get stats as recorded by Tx/Rx rings */
6208 ice_update_vsi_ring_stats(vsi);
6210 /* get VSI stats as recorded by the hardware */
6211 ice_update_eth_stats(vsi);
6213 cur_ns->tx_errors = cur_es->tx_errors;
6214 cur_ns->rx_dropped = cur_es->rx_discards;
6215 cur_ns->tx_dropped = cur_es->tx_discards;
6216 cur_ns->multicast = cur_es->rx_multicast;
6218 /* update some more netdev stats if this is main VSI */
6219 if (vsi->type == ICE_VSI_PF) {
6220 cur_ns->rx_crc_errors = pf->stats.crc_errors;
6221 cur_ns->rx_errors = pf->stats.crc_errors +
6222 pf->stats.illegal_bytes +
6223 pf->stats.rx_len_errors +
6224 pf->stats.rx_undersize +
6225 pf->hw_csum_rx_error +
6226 pf->stats.rx_jabber +
6227 pf->stats.rx_fragments +
6228 pf->stats.rx_oversize;
6229 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
6230 /* record drops from the port level */
6231 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
6236 * ice_update_pf_stats - Update PF port stats counters
6237 * @pf: PF whose stats needs to be updated
6239 void ice_update_pf_stats(struct ice_pf *pf)
6241 struct ice_hw_port_stats *prev_ps, *cur_ps;
6242 struct ice_hw *hw = &pf->hw;
6246 port = hw->port_info->lport;
6247 prev_ps = &pf->stats_prev;
6248 cur_ps = &pf->stats;
6250 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
6251 &prev_ps->eth.rx_bytes,
6252 &cur_ps->eth.rx_bytes);
6254 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
6255 &prev_ps->eth.rx_unicast,
6256 &cur_ps->eth.rx_unicast);
6258 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
6259 &prev_ps->eth.rx_multicast,
6260 &cur_ps->eth.rx_multicast);
6262 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
6263 &prev_ps->eth.rx_broadcast,
6264 &cur_ps->eth.rx_broadcast);
6266 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
6267 &prev_ps->eth.rx_discards,
6268 &cur_ps->eth.rx_discards);
6270 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
6271 &prev_ps->eth.tx_bytes,
6272 &cur_ps->eth.tx_bytes);
6274 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
6275 &prev_ps->eth.tx_unicast,
6276 &cur_ps->eth.tx_unicast);
6278 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
6279 &prev_ps->eth.tx_multicast,
6280 &cur_ps->eth.tx_multicast);
6282 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
6283 &prev_ps->eth.tx_broadcast,
6284 &cur_ps->eth.tx_broadcast);
6286 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
6287 &prev_ps->tx_dropped_link_down,
6288 &cur_ps->tx_dropped_link_down);
6290 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
6291 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
6293 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
6294 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
6296 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
6297 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
6299 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
6300 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
6302 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
6303 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
6305 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
6306 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
6308 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
6309 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
6311 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
6312 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
6314 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
6315 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
6317 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
6318 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
6320 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
6321 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
6323 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
6324 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
6326 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
6327 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
6329 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
6330 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
6332 fd_ctr_base = hw->fd_ctr_base;
6334 ice_stat_update40(hw,
6335 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
6336 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
6337 &cur_ps->fd_sb_match);
6338 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
6339 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
6341 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
6342 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
6344 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
6345 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
6347 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
6348 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
6350 ice_update_dcb_stats(pf);
6352 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
6353 &prev_ps->crc_errors, &cur_ps->crc_errors);
6355 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
6356 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
6358 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
6359 &prev_ps->mac_local_faults,
6360 &cur_ps->mac_local_faults);
6362 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
6363 &prev_ps->mac_remote_faults,
6364 &cur_ps->mac_remote_faults);
6366 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
6367 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
6369 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
6370 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
6372 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
6373 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
6375 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
6376 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
6378 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
6379 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
6381 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
6383 pf->stat_prev_loaded = true;
6387 * ice_get_stats64 - get statistics for network device structure
6388 * @netdev: network interface device structure
6389 * @stats: main device statistics structure
6392 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
6394 struct ice_netdev_priv *np = netdev_priv(netdev);
6395 struct rtnl_link_stats64 *vsi_stats;
6396 struct ice_vsi *vsi = np->vsi;
6398 vsi_stats = &vsi->net_stats;
6400 if (!vsi->num_txq || !vsi->num_rxq)
6403 /* netdev packet/byte stats come from ring counter. These are obtained
6404 * by summing up ring counters (done by ice_update_vsi_ring_stats).
6405 * But, only call the update routine and read the registers if VSI is
6408 if (!test_bit(ICE_VSI_DOWN, vsi->state))
6409 ice_update_vsi_ring_stats(vsi);
6410 stats->tx_packets = vsi_stats->tx_packets;
6411 stats->tx_bytes = vsi_stats->tx_bytes;
6412 stats->rx_packets = vsi_stats->rx_packets;
6413 stats->rx_bytes = vsi_stats->rx_bytes;
6415 /* The rest of the stats can be read from the hardware but instead we
6416 * just return values that the watchdog task has already obtained from
6419 stats->multicast = vsi_stats->multicast;
6420 stats->tx_errors = vsi_stats->tx_errors;
6421 stats->tx_dropped = vsi_stats->tx_dropped;
6422 stats->rx_errors = vsi_stats->rx_errors;
6423 stats->rx_dropped = vsi_stats->rx_dropped;
6424 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
6425 stats->rx_length_errors = vsi_stats->rx_length_errors;
6429 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
6430 * @vsi: VSI having NAPI disabled
6432 static void ice_napi_disable_all(struct ice_vsi *vsi)
6439 ice_for_each_q_vector(vsi, q_idx) {
6440 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
6442 if (q_vector->rx.rx_ring || q_vector->tx.tx_ring)
6443 napi_disable(&q_vector->napi);
6445 cancel_work_sync(&q_vector->tx.dim.work);
6446 cancel_work_sync(&q_vector->rx.dim.work);
6451 * ice_down - Shutdown the connection
6452 * @vsi: The VSI being stopped
6454 * Caller of this function is expected to set the vsi->state ICE_DOWN bit
6456 int ice_down(struct ice_vsi *vsi)
6458 int i, tx_err, rx_err, link_err = 0, vlan_err = 0;
6460 WARN_ON(!test_bit(ICE_VSI_DOWN, vsi->state));
6462 if (vsi->netdev && vsi->type == ICE_VSI_PF) {
6463 vlan_err = ice_vsi_del_vlan_zero(vsi);
6464 if (!ice_is_e810(&vsi->back->hw))
6465 ice_ptp_link_change(vsi->back, vsi->back->hw.pf_id, false);
6466 netif_carrier_off(vsi->netdev);
6467 netif_tx_disable(vsi->netdev);
6468 } else if (vsi->type == ICE_VSI_SWITCHDEV_CTRL) {
6469 ice_eswitch_stop_all_tx_queues(vsi->back);
6472 ice_vsi_dis_irq(vsi);
6474 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
6476 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
6477 vsi->vsi_num, tx_err);
6478 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
6479 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
6481 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
6482 vsi->vsi_num, tx_err);
6485 rx_err = ice_vsi_stop_all_rx_rings(vsi);
6487 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
6488 vsi->vsi_num, rx_err);
6490 ice_napi_disable_all(vsi);
6492 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
6493 link_err = ice_force_phys_link_state(vsi, false);
6495 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
6496 vsi->vsi_num, link_err);
6499 ice_for_each_txq(vsi, i)
6500 ice_clean_tx_ring(vsi->tx_rings[i]);
6502 ice_for_each_rxq(vsi, i)
6503 ice_clean_rx_ring(vsi->rx_rings[i]);
6505 if (tx_err || rx_err || link_err || vlan_err) {
6506 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
6507 vsi->vsi_num, vsi->vsw->sw_id);
6515 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
6516 * @vsi: VSI having resources allocated
6518 * Return 0 on success, negative on failure
6520 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
6524 if (!vsi->num_txq) {
6525 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
6530 ice_for_each_txq(vsi, i) {
6531 struct ice_tx_ring *ring = vsi->tx_rings[i];
6537 ring->netdev = vsi->netdev;
6538 err = ice_setup_tx_ring(ring);
6547 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
6548 * @vsi: VSI having resources allocated
6550 * Return 0 on success, negative on failure
6552 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
6556 if (!vsi->num_rxq) {
6557 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
6562 ice_for_each_rxq(vsi, i) {
6563 struct ice_rx_ring *ring = vsi->rx_rings[i];
6569 ring->netdev = vsi->netdev;
6570 err = ice_setup_rx_ring(ring);
6579 * ice_vsi_open_ctrl - open control VSI for use
6580 * @vsi: the VSI to open
6582 * Initialization of the Control VSI
6584 * Returns 0 on success, negative value on error
6586 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
6588 char int_name[ICE_INT_NAME_STR_LEN];
6589 struct ice_pf *pf = vsi->back;
6593 dev = ice_pf_to_dev(pf);
6594 /* allocate descriptors */
6595 err = ice_vsi_setup_tx_rings(vsi);
6599 err = ice_vsi_setup_rx_rings(vsi);
6603 err = ice_vsi_cfg(vsi);
6607 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
6608 dev_driver_string(dev), dev_name(dev));
6609 err = ice_vsi_req_irq_msix(vsi, int_name);
6613 ice_vsi_cfg_msix(vsi);
6615 err = ice_vsi_start_all_rx_rings(vsi);
6617 goto err_up_complete;
6619 clear_bit(ICE_VSI_DOWN, vsi->state);
6620 ice_vsi_ena_irq(vsi);
6627 ice_vsi_free_rx_rings(vsi);
6629 ice_vsi_free_tx_rings(vsi);
6635 * ice_vsi_open - Called when a network interface is made active
6636 * @vsi: the VSI to open
6638 * Initialization of the VSI
6640 * Returns 0 on success, negative value on error
6642 int ice_vsi_open(struct ice_vsi *vsi)
6644 char int_name[ICE_INT_NAME_STR_LEN];
6645 struct ice_pf *pf = vsi->back;
6648 /* allocate descriptors */
6649 err = ice_vsi_setup_tx_rings(vsi);
6653 err = ice_vsi_setup_rx_rings(vsi);
6657 err = ice_vsi_cfg(vsi);
6661 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
6662 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
6663 err = ice_vsi_req_irq_msix(vsi, int_name);
6667 if (vsi->type == ICE_VSI_PF) {
6668 /* Notify the stack of the actual queue counts. */
6669 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
6673 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
6678 err = ice_up_complete(vsi);
6680 goto err_up_complete;
6687 ice_vsi_free_irq(vsi);
6689 ice_vsi_free_rx_rings(vsi);
6691 ice_vsi_free_tx_rings(vsi);
6697 * ice_vsi_release_all - Delete all VSIs
6698 * @pf: PF from which all VSIs are being removed
6700 static void ice_vsi_release_all(struct ice_pf *pf)
6707 ice_for_each_vsi(pf, i) {
6711 if (pf->vsi[i]->type == ICE_VSI_CHNL)
6714 err = ice_vsi_release(pf->vsi[i]);
6716 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
6717 i, err, pf->vsi[i]->vsi_num);
6722 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
6723 * @pf: pointer to the PF instance
6724 * @type: VSI type to rebuild
6726 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
6728 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
6730 struct device *dev = ice_pf_to_dev(pf);
6733 ice_for_each_vsi(pf, i) {
6734 struct ice_vsi *vsi = pf->vsi[i];
6736 if (!vsi || vsi->type != type)
6739 /* rebuild the VSI */
6740 err = ice_vsi_rebuild(vsi, true);
6742 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
6743 err, vsi->idx, ice_vsi_type_str(type));
6747 /* replay filters for the VSI */
6748 err = ice_replay_vsi(&pf->hw, vsi->idx);
6750 dev_err(dev, "replay VSI failed, error %d, VSI index %d, type %s\n",
6751 err, vsi->idx, ice_vsi_type_str(type));
6755 /* Re-map HW VSI number, using VSI handle that has been
6756 * previously validated in ice_replay_vsi() call above
6758 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
6760 /* enable the VSI */
6761 err = ice_ena_vsi(vsi, false);
6763 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
6764 err, vsi->idx, ice_vsi_type_str(type));
6768 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
6769 ice_vsi_type_str(type));
6776 * ice_update_pf_netdev_link - Update PF netdev link status
6777 * @pf: pointer to the PF instance
6779 static void ice_update_pf_netdev_link(struct ice_pf *pf)
6784 ice_for_each_vsi(pf, i) {
6785 struct ice_vsi *vsi = pf->vsi[i];
6787 if (!vsi || vsi->type != ICE_VSI_PF)
6790 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
6792 netif_carrier_on(pf->vsi[i]->netdev);
6793 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
6795 netif_carrier_off(pf->vsi[i]->netdev);
6796 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
6802 * ice_rebuild - rebuild after reset
6803 * @pf: PF to rebuild
6804 * @reset_type: type of reset
6806 * Do not rebuild VF VSI in this flow because that is already handled via
6807 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a
6808 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
6809 * to reset/rebuild all the VF VSI twice.
6811 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
6813 struct device *dev = ice_pf_to_dev(pf);
6814 struct ice_hw *hw = &pf->hw;
6818 if (test_bit(ICE_DOWN, pf->state))
6819 goto clear_recovery;
6821 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
6823 if (reset_type == ICE_RESET_EMPR) {
6824 /* If an EMP reset has occurred, any previously pending flash
6825 * update will have completed. We no longer know whether or
6826 * not the NVM update EMP reset is restricted.
6828 pf->fw_emp_reset_disabled = false;
6831 err = ice_init_all_ctrlq(hw);
6833 dev_err(dev, "control queues init failed %d\n", err);
6834 goto err_init_ctrlq;
6837 /* if DDP was previously loaded successfully */
6838 if (!ice_is_safe_mode(pf)) {
6839 /* reload the SW DB of filter tables */
6840 if (reset_type == ICE_RESET_PFR)
6841 ice_fill_blk_tbls(hw);
6843 /* Reload DDP Package after CORER/GLOBR reset */
6844 ice_load_pkg(NULL, pf);
6847 err = ice_clear_pf_cfg(hw);
6849 dev_err(dev, "clear PF configuration failed %d\n", err);
6850 goto err_init_ctrlq;
6853 if (pf->first_sw->dflt_vsi_ena)
6854 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n");
6855 /* clear the default VSI configuration if it exists */
6856 pf->first_sw->dflt_vsi = NULL;
6857 pf->first_sw->dflt_vsi_ena = false;
6859 ice_clear_pxe_mode(hw);
6861 err = ice_init_nvm(hw);
6863 dev_err(dev, "ice_init_nvm failed %d\n", err);
6864 goto err_init_ctrlq;
6867 err = ice_get_caps(hw);
6869 dev_err(dev, "ice_get_caps failed %d\n", err);
6870 goto err_init_ctrlq;
6873 err = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
6875 dev_err(dev, "set_mac_cfg failed %d\n", err);
6876 goto err_init_ctrlq;
6879 dvm = ice_is_dvm_ena(hw);
6881 err = ice_aq_set_port_params(pf->hw.port_info, dvm, NULL);
6883 goto err_init_ctrlq;
6885 err = ice_sched_init_port(hw->port_info);
6887 goto err_sched_init_port;
6889 /* start misc vector */
6890 err = ice_req_irq_msix_misc(pf);
6892 dev_err(dev, "misc vector setup failed: %d\n", err);
6893 goto err_sched_init_port;
6896 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
6897 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
6898 if (!rd32(hw, PFQF_FD_SIZE)) {
6899 u16 unused, guar, b_effort;
6901 guar = hw->func_caps.fd_fltr_guar;
6902 b_effort = hw->func_caps.fd_fltr_best_effort;
6904 /* force guaranteed filter pool for PF */
6905 ice_alloc_fd_guar_item(hw, &unused, guar);
6906 /* force shared filter pool for PF */
6907 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
6911 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
6912 ice_dcb_rebuild(pf);
6914 /* If the PF previously had enabled PTP, PTP init needs to happen before
6915 * the VSI rebuild. If not, this causes the PTP link status events to
6918 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
6921 /* rebuild PF VSI */
6922 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
6924 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
6925 goto err_vsi_rebuild;
6928 /* configure PTP timestamping after VSI rebuild */
6929 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
6930 ice_ptp_cfg_timestamp(pf, false);
6932 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_SWITCHDEV_CTRL);
6934 dev_err(dev, "Switchdev CTRL VSI rebuild failed: %d\n", err);
6935 goto err_vsi_rebuild;
6938 if (reset_type == ICE_RESET_PFR) {
6939 err = ice_rebuild_channels(pf);
6941 dev_err(dev, "failed to rebuild and replay ADQ VSIs, err %d\n",
6943 goto err_vsi_rebuild;
6947 /* If Flow Director is active */
6948 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
6949 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
6951 dev_err(dev, "control VSI rebuild failed: %d\n", err);
6952 goto err_vsi_rebuild;
6955 /* replay HW Flow Director recipes */
6957 ice_fdir_replay_flows(hw);
6959 /* replay Flow Director filters */
6960 ice_fdir_replay_fltrs(pf);
6962 ice_rebuild_arfs(pf);
6965 ice_update_pf_netdev_link(pf);
6967 /* tell the firmware we are up */
6968 err = ice_send_version(pf);
6970 dev_err(dev, "Rebuild failed due to error sending driver version: %d\n",
6972 goto err_vsi_rebuild;
6975 ice_replay_post(hw);
6977 /* if we get here, reset flow is successful */
6978 clear_bit(ICE_RESET_FAILED, pf->state);
6980 ice_plug_aux_dev(pf);
6984 err_sched_init_port:
6985 ice_sched_cleanup_all(hw);
6987 ice_shutdown_all_ctrlq(hw);
6988 set_bit(ICE_RESET_FAILED, pf->state);
6990 /* set this bit in PF state to control service task scheduling */
6991 set_bit(ICE_NEEDS_RESTART, pf->state);
6992 dev_err(dev, "Rebuild failed, unload and reload driver\n");
6996 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
6997 * @vsi: Pointer to VSI structure
6999 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
7001 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
7002 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
7004 return ICE_RXBUF_3072;
7008 * ice_change_mtu - NDO callback to change the MTU
7009 * @netdev: network interface device structure
7010 * @new_mtu: new value for maximum frame size
7012 * Returns 0 on success, negative on failure
7014 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
7016 struct ice_netdev_priv *np = netdev_priv(netdev);
7017 struct ice_vsi *vsi = np->vsi;
7018 struct ice_pf *pf = vsi->back;
7019 struct iidc_event *event;
7023 if (new_mtu == (int)netdev->mtu) {
7024 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
7028 if (ice_is_xdp_ena_vsi(vsi)) {
7029 int frame_size = ice_max_xdp_frame_size(vsi);
7031 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
7032 netdev_err(netdev, "max MTU for XDP usage is %d\n",
7033 frame_size - ICE_ETH_PKT_HDR_PAD);
7038 /* if a reset is in progress, wait for some time for it to complete */
7040 if (ice_is_reset_in_progress(pf->state)) {
7042 usleep_range(1000, 2000);
7047 } while (count < 100);
7050 netdev_err(netdev, "can't change MTU. Device is busy\n");
7054 event = kzalloc(sizeof(*event), GFP_KERNEL);
7058 set_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);
7059 ice_send_event_to_aux(pf, event);
7060 clear_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);
7062 netdev->mtu = (unsigned int)new_mtu;
7064 /* if VSI is up, bring it down and then back up */
7065 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
7066 err = ice_down(vsi);
7068 netdev_err(netdev, "change MTU if_down err %d\n", err);
7074 netdev_err(netdev, "change MTU if_up err %d\n", err);
7079 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
7081 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);
7082 ice_send_event_to_aux(pf, event);
7089 * ice_eth_ioctl - Access the hwtstamp interface
7090 * @netdev: network interface device structure
7091 * @ifr: interface request data
7092 * @cmd: ioctl command
7094 static int ice_eth_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
7096 struct ice_netdev_priv *np = netdev_priv(netdev);
7097 struct ice_pf *pf = np->vsi->back;
7101 return ice_ptp_get_ts_config(pf, ifr);
7103 return ice_ptp_set_ts_config(pf, ifr);
7110 * ice_aq_str - convert AQ err code to a string
7111 * @aq_err: the AQ error code to convert
7113 const char *ice_aq_str(enum ice_aq_err aq_err)
7118 case ICE_AQ_RC_EPERM:
7119 return "ICE_AQ_RC_EPERM";
7120 case ICE_AQ_RC_ENOENT:
7121 return "ICE_AQ_RC_ENOENT";
7122 case ICE_AQ_RC_ENOMEM:
7123 return "ICE_AQ_RC_ENOMEM";
7124 case ICE_AQ_RC_EBUSY:
7125 return "ICE_AQ_RC_EBUSY";
7126 case ICE_AQ_RC_EEXIST:
7127 return "ICE_AQ_RC_EEXIST";
7128 case ICE_AQ_RC_EINVAL:
7129 return "ICE_AQ_RC_EINVAL";
7130 case ICE_AQ_RC_ENOSPC:
7131 return "ICE_AQ_RC_ENOSPC";
7132 case ICE_AQ_RC_ENOSYS:
7133 return "ICE_AQ_RC_ENOSYS";
7134 case ICE_AQ_RC_EMODE:
7135 return "ICE_AQ_RC_EMODE";
7136 case ICE_AQ_RC_ENOSEC:
7137 return "ICE_AQ_RC_ENOSEC";
7138 case ICE_AQ_RC_EBADSIG:
7139 return "ICE_AQ_RC_EBADSIG";
7140 case ICE_AQ_RC_ESVN:
7141 return "ICE_AQ_RC_ESVN";
7142 case ICE_AQ_RC_EBADMAN:
7143 return "ICE_AQ_RC_EBADMAN";
7144 case ICE_AQ_RC_EBADBUF:
7145 return "ICE_AQ_RC_EBADBUF";
7148 return "ICE_AQ_RC_UNKNOWN";
7152 * ice_set_rss_lut - Set RSS LUT
7153 * @vsi: Pointer to VSI structure
7154 * @lut: Lookup table
7155 * @lut_size: Lookup table size
7157 * Returns 0 on success, negative on failure
7159 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7161 struct ice_aq_get_set_rss_lut_params params = {};
7162 struct ice_hw *hw = &vsi->back->hw;
7168 params.vsi_handle = vsi->idx;
7169 params.lut_size = lut_size;
7170 params.lut_type = vsi->rss_lut_type;
7173 status = ice_aq_set_rss_lut(hw, ¶ms);
7175 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %d aq_err %s\n",
7176 status, ice_aq_str(hw->adminq.sq_last_status));
7182 * ice_set_rss_key - Set RSS key
7183 * @vsi: Pointer to the VSI structure
7184 * @seed: RSS hash seed
7186 * Returns 0 on success, negative on failure
7188 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed)
7190 struct ice_hw *hw = &vsi->back->hw;
7196 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7198 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %d aq_err %s\n",
7199 status, ice_aq_str(hw->adminq.sq_last_status));
7205 * ice_get_rss_lut - Get RSS LUT
7206 * @vsi: Pointer to VSI structure
7207 * @lut: Buffer to store the lookup table entries
7208 * @lut_size: Size of buffer to store the lookup table entries
7210 * Returns 0 on success, negative on failure
7212 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
7214 struct ice_aq_get_set_rss_lut_params params = {};
7215 struct ice_hw *hw = &vsi->back->hw;
7221 params.vsi_handle = vsi->idx;
7222 params.lut_size = lut_size;
7223 params.lut_type = vsi->rss_lut_type;
7226 status = ice_aq_get_rss_lut(hw, ¶ms);
7228 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %d aq_err %s\n",
7229 status, ice_aq_str(hw->adminq.sq_last_status));
7235 * ice_get_rss_key - Get RSS key
7236 * @vsi: Pointer to VSI structure
7237 * @seed: Buffer to store the key in
7239 * Returns 0 on success, negative on failure
7241 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed)
7243 struct ice_hw *hw = &vsi->back->hw;
7249 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
7251 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %d aq_err %s\n",
7252 status, ice_aq_str(hw->adminq.sq_last_status));
7258 * ice_bridge_getlink - Get the hardware bridge mode
7261 * @seq: RTNL message seq
7262 * @dev: the netdev being configured
7263 * @filter_mask: filter mask passed in
7264 * @nlflags: netlink flags passed in
7266 * Return the bridge mode (VEB/VEPA)
7269 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
7270 struct net_device *dev, u32 filter_mask, int nlflags)
7272 struct ice_netdev_priv *np = netdev_priv(dev);
7273 struct ice_vsi *vsi = np->vsi;
7274 struct ice_pf *pf = vsi->back;
7277 bmode = pf->first_sw->bridge_mode;
7279 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
7284 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
7285 * @vsi: Pointer to VSI structure
7286 * @bmode: Hardware bridge mode (VEB/VEPA)
7288 * Returns 0 on success, negative on failure
7290 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
7292 struct ice_aqc_vsi_props *vsi_props;
7293 struct ice_hw *hw = &vsi->back->hw;
7294 struct ice_vsi_ctx *ctxt;
7297 vsi_props = &vsi->info;
7299 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
7303 ctxt->info = vsi->info;
7305 if (bmode == BRIDGE_MODE_VEB)
7306 /* change from VEPA to VEB mode */
7307 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7309 /* change from VEB to VEPA mode */
7310 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
7311 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
7313 ret = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
7315 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %d aq_err %s\n",
7316 bmode, ret, ice_aq_str(hw->adminq.sq_last_status));
7319 /* Update sw flags for book keeping */
7320 vsi_props->sw_flags = ctxt->info.sw_flags;
7328 * ice_bridge_setlink - Set the hardware bridge mode
7329 * @dev: the netdev being configured
7330 * @nlh: RTNL message
7331 * @flags: bridge setlink flags
7332 * @extack: netlink extended ack
7334 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
7335 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
7336 * not already set for all VSIs connected to this switch. And also update the
7337 * unicast switch filter rules for the corresponding switch of the netdev.
7340 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
7341 u16 __always_unused flags,
7342 struct netlink_ext_ack __always_unused *extack)
7344 struct ice_netdev_priv *np = netdev_priv(dev);
7345 struct ice_pf *pf = np->vsi->back;
7346 struct nlattr *attr, *br_spec;
7347 struct ice_hw *hw = &pf->hw;
7348 struct ice_sw *pf_sw;
7349 int rem, v, err = 0;
7351 pf_sw = pf->first_sw;
7352 /* find the attribute in the netlink message */
7353 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7355 nla_for_each_nested(attr, br_spec, rem) {
7358 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7360 mode = nla_get_u16(attr);
7361 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
7363 /* Continue if bridge mode is not being flipped */
7364 if (mode == pf_sw->bridge_mode)
7366 /* Iterates through the PF VSI list and update the loopback
7369 ice_for_each_vsi(pf, v) {
7372 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
7377 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
7378 /* Update the unicast switch filter rules for the corresponding
7379 * switch of the netdev
7381 err = ice_update_sw_rule_bridge_mode(hw);
7383 netdev_err(dev, "switch rule update failed, mode = %d err %d aq_err %s\n",
7385 ice_aq_str(hw->adminq.sq_last_status));
7386 /* revert hw->evb_veb */
7387 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
7391 pf_sw->bridge_mode = mode;
7398 * ice_tx_timeout - Respond to a Tx Hang
7399 * @netdev: network interface device structure
7400 * @txqueue: Tx queue
7402 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
7404 struct ice_netdev_priv *np = netdev_priv(netdev);
7405 struct ice_tx_ring *tx_ring = NULL;
7406 struct ice_vsi *vsi = np->vsi;
7407 struct ice_pf *pf = vsi->back;
7410 pf->tx_timeout_count++;
7412 /* Check if PFC is enabled for the TC to which the queue belongs
7413 * to. If yes then Tx timeout is not caused by a hung queue, no
7414 * need to reset and rebuild
7416 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
7417 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
7422 /* now that we have an index, find the tx_ring struct */
7423 ice_for_each_txq(vsi, i)
7424 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
7425 if (txqueue == vsi->tx_rings[i]->q_index) {
7426 tx_ring = vsi->tx_rings[i];
7430 /* Reset recovery level if enough time has elapsed after last timeout.
7431 * Also ensure no new reset action happens before next timeout period.
7433 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
7434 pf->tx_timeout_recovery_level = 1;
7435 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
7436 netdev->watchdog_timeo)))
7440 struct ice_hw *hw = &pf->hw;
7443 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
7444 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
7445 /* Read interrupt register */
7446 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
7448 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
7449 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
7450 head, tx_ring->next_to_use, val);
7453 pf->tx_timeout_last_recovery = jiffies;
7454 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
7455 pf->tx_timeout_recovery_level, txqueue);
7457 switch (pf->tx_timeout_recovery_level) {
7459 set_bit(ICE_PFR_REQ, pf->state);
7462 set_bit(ICE_CORER_REQ, pf->state);
7465 set_bit(ICE_GLOBR_REQ, pf->state);
7468 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
7469 set_bit(ICE_DOWN, pf->state);
7470 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
7471 set_bit(ICE_SERVICE_DIS, pf->state);
7475 ice_service_task_schedule(pf);
7476 pf->tx_timeout_recovery_level++;
7480 * ice_setup_tc_cls_flower - flower classifier offloads
7481 * @np: net device to configure
7482 * @filter_dev: device on which filter is added
7483 * @cls_flower: offload data
7486 ice_setup_tc_cls_flower(struct ice_netdev_priv *np,
7487 struct net_device *filter_dev,
7488 struct flow_cls_offload *cls_flower)
7490 struct ice_vsi *vsi = np->vsi;
7492 if (cls_flower->common.chain_index)
7495 switch (cls_flower->command) {
7496 case FLOW_CLS_REPLACE:
7497 return ice_add_cls_flower(filter_dev, vsi, cls_flower);
7498 case FLOW_CLS_DESTROY:
7499 return ice_del_cls_flower(vsi, cls_flower);
7506 * ice_setup_tc_block_cb - callback handler registered for TC block
7507 * @type: TC SETUP type
7508 * @type_data: TC flower offload data that contains user input
7509 * @cb_priv: netdev private data
7512 ice_setup_tc_block_cb(enum tc_setup_type type, void *type_data, void *cb_priv)
7514 struct ice_netdev_priv *np = cb_priv;
7517 case TC_SETUP_CLSFLOWER:
7518 return ice_setup_tc_cls_flower(np, np->vsi->netdev,
7526 * ice_validate_mqprio_qopt - Validate TCF input parameters
7527 * @vsi: Pointer to VSI
7528 * @mqprio_qopt: input parameters for mqprio queue configuration
7530 * This function validates MQPRIO params, such as qcount (power of 2 wherever
7531 * needed), and make sure user doesn't specify qcount and BW rate limit
7532 * for TCs, which are more than "num_tc"
7535 ice_validate_mqprio_qopt(struct ice_vsi *vsi,
7536 struct tc_mqprio_qopt_offload *mqprio_qopt)
7538 u64 sum_max_rate = 0, sum_min_rate = 0;
7539 int non_power_of_2_qcount = 0;
7540 struct ice_pf *pf = vsi->back;
7541 int max_rss_q_cnt = 0;
7546 if (vsi->type != ICE_VSI_PF)
7549 if (mqprio_qopt->qopt.offset[0] != 0 ||
7550 mqprio_qopt->qopt.num_tc < 1 ||
7551 mqprio_qopt->qopt.num_tc > ICE_CHNL_MAX_TC)
7554 dev = ice_pf_to_dev(pf);
7555 vsi->ch_rss_size = 0;
7556 num_tc = mqprio_qopt->qopt.num_tc;
7558 for (i = 0; num_tc; i++) {
7559 int qcount = mqprio_qopt->qopt.count[i];
7560 u64 max_rate, min_rate, rem;
7565 if (is_power_of_2(qcount)) {
7566 if (non_power_of_2_qcount &&
7567 qcount > non_power_of_2_qcount) {
7568 dev_err(dev, "qcount[%d] cannot be greater than non power of 2 qcount[%d]\n",
7569 qcount, non_power_of_2_qcount);
7572 if (qcount > max_rss_q_cnt)
7573 max_rss_q_cnt = qcount;
7575 if (non_power_of_2_qcount &&
7576 qcount != non_power_of_2_qcount) {
7577 dev_err(dev, "Only one non power of 2 qcount allowed[%d,%d]\n",
7578 qcount, non_power_of_2_qcount);
7581 if (qcount < max_rss_q_cnt) {
7582 dev_err(dev, "non power of 2 qcount[%d] cannot be less than other qcount[%d]\n",
7583 qcount, max_rss_q_cnt);
7586 max_rss_q_cnt = qcount;
7587 non_power_of_2_qcount = qcount;
7590 /* TC command takes input in K/N/Gbps or K/M/Gbit etc but
7591 * converts the bandwidth rate limit into Bytes/s when
7592 * passing it down to the driver. So convert input bandwidth
7593 * from Bytes/s to Kbps
7595 max_rate = mqprio_qopt->max_rate[i];
7596 max_rate = div_u64(max_rate, ICE_BW_KBPS_DIVISOR);
7597 sum_max_rate += max_rate;
7599 /* min_rate is minimum guaranteed rate and it can't be zero */
7600 min_rate = mqprio_qopt->min_rate[i];
7601 min_rate = div_u64(min_rate, ICE_BW_KBPS_DIVISOR);
7602 sum_min_rate += min_rate;
7604 if (min_rate && min_rate < ICE_MIN_BW_LIMIT) {
7605 dev_err(dev, "TC%d: min_rate(%llu Kbps) < %u Kbps\n", i,
7606 min_rate, ICE_MIN_BW_LIMIT);
7610 iter_div_u64_rem(min_rate, ICE_MIN_BW_LIMIT, &rem);
7612 dev_err(dev, "TC%d: Min Rate not multiple of %u Kbps",
7613 i, ICE_MIN_BW_LIMIT);
7617 iter_div_u64_rem(max_rate, ICE_MIN_BW_LIMIT, &rem);
7619 dev_err(dev, "TC%d: Max Rate not multiple of %u Kbps",
7620 i, ICE_MIN_BW_LIMIT);
7624 /* min_rate can't be more than max_rate, except when max_rate
7625 * is zero (implies max_rate sought is max line rate). In such
7626 * a case min_rate can be more than max.
7628 if (max_rate && min_rate > max_rate) {
7629 dev_err(dev, "min_rate %llu Kbps can't be more than max_rate %llu Kbps\n",
7630 min_rate, max_rate);
7634 if (i >= mqprio_qopt->qopt.num_tc - 1)
7636 if (mqprio_qopt->qopt.offset[i + 1] !=
7637 (mqprio_qopt->qopt.offset[i] + qcount))
7641 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7644 (mqprio_qopt->qopt.offset[i] + mqprio_qopt->qopt.count[i]))
7647 speed = ice_get_link_speed_kbps(vsi);
7648 if (sum_max_rate && sum_max_rate > (u64)speed) {
7649 dev_err(dev, "Invalid max Tx rate(%llu) Kbps > speed(%u) Kbps specified\n",
7650 sum_max_rate, speed);
7653 if (sum_min_rate && sum_min_rate > (u64)speed) {
7654 dev_err(dev, "Invalid min Tx rate(%llu) Kbps > speed (%u) Kbps specified\n",
7655 sum_min_rate, speed);
7659 /* make sure vsi->ch_rss_size is set correctly based on TC's qcount */
7660 vsi->ch_rss_size = max_rss_q_cnt;
7666 * ice_add_vsi_to_fdir - add a VSI to the flow director group for PF
7667 * @pf: ptr to PF device
7670 static int ice_add_vsi_to_fdir(struct ice_pf *pf, struct ice_vsi *vsi)
7672 struct device *dev = ice_pf_to_dev(pf);
7677 if (!(vsi->num_gfltr || vsi->num_bfltr))
7681 for (flow = 0; flow < ICE_FLTR_PTYPE_MAX; flow++) {
7682 struct ice_fd_hw_prof *prof;
7686 if (!(hw->fdir_prof && hw->fdir_prof[flow] &&
7687 hw->fdir_prof[flow]->cnt))
7690 for (tun = 0; tun < ICE_FD_HW_SEG_MAX; tun++) {
7691 enum ice_flow_priority prio;
7694 /* add this VSI to FDir profile for this flow */
7695 prio = ICE_FLOW_PRIO_NORMAL;
7696 prof = hw->fdir_prof[flow];
7697 prof_id = flow + tun * ICE_FLTR_PTYPE_MAX;
7698 status = ice_flow_add_entry(hw, ICE_BLK_FD, prof_id,
7699 prof->vsi_h[0], vsi->idx,
7700 prio, prof->fdir_seg[tun],
7703 dev_err(dev, "channel VSI idx %d, not able to add to group %d\n",
7708 prof->entry_h[prof->cnt][tun] = entry_h;
7711 /* store VSI for filter replay and delete */
7712 prof->vsi_h[prof->cnt] = vsi->idx;
7716 dev_dbg(dev, "VSI idx %d added to fdir group %d\n", vsi->idx,
7721 dev_dbg(dev, "VSI idx %d not added to fdir groups\n", vsi->idx);
7727 * ice_add_channel - add a channel by adding VSI
7728 * @pf: ptr to PF device
7729 * @sw_id: underlying HW switching element ID
7730 * @ch: ptr to channel structure
7732 * Add a channel (VSI) using add_vsi and queue_map
7734 static int ice_add_channel(struct ice_pf *pf, u16 sw_id, struct ice_channel *ch)
7736 struct device *dev = ice_pf_to_dev(pf);
7737 struct ice_vsi *vsi;
7739 if (ch->type != ICE_VSI_CHNL) {
7740 dev_err(dev, "add new VSI failed, ch->type %d\n", ch->type);
7744 vsi = ice_chnl_vsi_setup(pf, pf->hw.port_info, ch);
7745 if (!vsi || vsi->type != ICE_VSI_CHNL) {
7746 dev_err(dev, "create chnl VSI failure\n");
7750 ice_add_vsi_to_fdir(pf, vsi);
7753 ch->vsi_num = vsi->vsi_num;
7754 ch->info.mapping_flags = vsi->info.mapping_flags;
7756 /* set the back pointer of channel for newly created VSI */
7759 memcpy(&ch->info.q_mapping, &vsi->info.q_mapping,
7760 sizeof(vsi->info.q_mapping));
7761 memcpy(&ch->info.tc_mapping, vsi->info.tc_mapping,
7762 sizeof(vsi->info.tc_mapping));
7769 * @vsi: the VSI being setup
7770 * @ch: ptr to channel structure
7772 * Configure channel specific resources such as rings, vector.
7774 static void ice_chnl_cfg_res(struct ice_vsi *vsi, struct ice_channel *ch)
7778 for (i = 0; i < ch->num_txq; i++) {
7779 struct ice_q_vector *tx_q_vector, *rx_q_vector;
7780 struct ice_ring_container *rc;
7781 struct ice_tx_ring *tx_ring;
7782 struct ice_rx_ring *rx_ring;
7784 tx_ring = vsi->tx_rings[ch->base_q + i];
7785 rx_ring = vsi->rx_rings[ch->base_q + i];
7786 if (!tx_ring || !rx_ring)
7789 /* setup ring being channel enabled */
7793 /* following code block sets up vector specific attributes */
7794 tx_q_vector = tx_ring->q_vector;
7795 rx_q_vector = rx_ring->q_vector;
7796 if (!tx_q_vector && !rx_q_vector)
7800 tx_q_vector->ch = ch;
7801 /* setup Tx and Rx ITR setting if DIM is off */
7802 rc = &tx_q_vector->tx;
7803 if (!ITR_IS_DYNAMIC(rc))
7804 ice_write_itr(rc, rc->itr_setting);
7807 rx_q_vector->ch = ch;
7808 /* setup Tx and Rx ITR setting if DIM is off */
7809 rc = &rx_q_vector->rx;
7810 if (!ITR_IS_DYNAMIC(rc))
7811 ice_write_itr(rc, rc->itr_setting);
7815 /* it is safe to assume that, if channel has non-zero num_t[r]xq, then
7816 * GLINT_ITR register would have written to perform in-context
7817 * update, hence perform flush
7819 if (ch->num_txq || ch->num_rxq)
7820 ice_flush(&vsi->back->hw);
7824 * ice_cfg_chnl_all_res - configure channel resources
7825 * @vsi: pte to main_vsi
7826 * @ch: ptr to channel structure
7828 * This function configures channel specific resources such as flow-director
7829 * counter index, and other resources such as queues, vectors, ITR settings
7832 ice_cfg_chnl_all_res(struct ice_vsi *vsi, struct ice_channel *ch)
7834 /* configure channel (aka ADQ) resources such as queues, vectors,
7835 * ITR settings for channel specific vectors and anything else
7837 ice_chnl_cfg_res(vsi, ch);
7841 * ice_setup_hw_channel - setup new channel
7842 * @pf: ptr to PF device
7843 * @vsi: the VSI being setup
7844 * @ch: ptr to channel structure
7845 * @sw_id: underlying HW switching element ID
7846 * @type: type of channel to be created (VMDq2/VF)
7848 * Setup new channel (VSI) based on specified type (VMDq2/VF)
7849 * and configures Tx rings accordingly
7852 ice_setup_hw_channel(struct ice_pf *pf, struct ice_vsi *vsi,
7853 struct ice_channel *ch, u16 sw_id, u8 type)
7855 struct device *dev = ice_pf_to_dev(pf);
7858 ch->base_q = vsi->next_base_q;
7861 ret = ice_add_channel(pf, sw_id, ch);
7863 dev_err(dev, "failed to add_channel using sw_id %u\n", sw_id);
7867 /* configure/setup ADQ specific resources */
7868 ice_cfg_chnl_all_res(vsi, ch);
7870 /* make sure to update the next_base_q so that subsequent channel's
7871 * (aka ADQ) VSI queue map is correct
7873 vsi->next_base_q = vsi->next_base_q + ch->num_rxq;
7874 dev_dbg(dev, "added channel: vsi_num %u, num_rxq %u\n", ch->vsi_num,
7881 * ice_setup_channel - setup new channel using uplink element
7882 * @pf: ptr to PF device
7883 * @vsi: the VSI being setup
7884 * @ch: ptr to channel structure
7886 * Setup new channel (VSI) based on specified type (VMDq2/VF)
7887 * and uplink switching element
7890 ice_setup_channel(struct ice_pf *pf, struct ice_vsi *vsi,
7891 struct ice_channel *ch)
7893 struct device *dev = ice_pf_to_dev(pf);
7897 if (vsi->type != ICE_VSI_PF) {
7898 dev_err(dev, "unsupported parent VSI type(%d)\n", vsi->type);
7902 sw_id = pf->first_sw->sw_id;
7904 /* create channel (VSI) */
7905 ret = ice_setup_hw_channel(pf, vsi, ch, sw_id, ICE_VSI_CHNL);
7907 dev_err(dev, "failed to setup hw_channel\n");
7910 dev_dbg(dev, "successfully created channel()\n");
7912 return ch->ch_vsi ? true : false;
7916 * ice_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
7917 * @vsi: VSI to be configured
7918 * @max_tx_rate: max Tx rate in Kbps to be configured as maximum BW limit
7919 * @min_tx_rate: min Tx rate in Kbps to be configured as minimum BW limit
7922 ice_set_bw_limit(struct ice_vsi *vsi, u64 max_tx_rate, u64 min_tx_rate)
7926 err = ice_set_min_bw_limit(vsi, min_tx_rate);
7930 return ice_set_max_bw_limit(vsi, max_tx_rate);
7934 * ice_create_q_channel - function to create channel
7935 * @vsi: VSI to be configured
7936 * @ch: ptr to channel (it contains channel specific params)
7938 * This function creates channel (VSI) using num_queues specified by user,
7939 * reconfigs RSS if needed.
7941 static int ice_create_q_channel(struct ice_vsi *vsi, struct ice_channel *ch)
7943 struct ice_pf *pf = vsi->back;
7949 dev = ice_pf_to_dev(pf);
7950 if (!ch->num_txq || !ch->num_rxq) {
7951 dev_err(dev, "Invalid num_queues requested: %d\n", ch->num_rxq);
7955 if (!vsi->cnt_q_avail || vsi->cnt_q_avail < ch->num_txq) {
7956 dev_err(dev, "cnt_q_avail (%u) less than num_queues %d\n",
7957 vsi->cnt_q_avail, ch->num_txq);
7961 if (!ice_setup_channel(pf, vsi, ch)) {
7962 dev_info(dev, "Failed to setup channel\n");
7965 /* configure BW rate limit */
7966 if (ch->ch_vsi && (ch->max_tx_rate || ch->min_tx_rate)) {
7969 ret = ice_set_bw_limit(ch->ch_vsi, ch->max_tx_rate,
7972 dev_err(dev, "failed to set Tx rate of %llu Kbps for VSI(%u)\n",
7973 ch->max_tx_rate, ch->ch_vsi->vsi_num);
7975 dev_dbg(dev, "set Tx rate of %llu Kbps for VSI(%u)\n",
7976 ch->max_tx_rate, ch->ch_vsi->vsi_num);
7979 vsi->cnt_q_avail -= ch->num_txq;
7985 * ice_rem_all_chnl_fltrs - removes all channel filters
7986 * @pf: ptr to PF, TC-flower based filter are tracked at PF level
7988 * Remove all advanced switch filters only if they are channel specific
7989 * tc-flower based filter
7991 static void ice_rem_all_chnl_fltrs(struct ice_pf *pf)
7993 struct ice_tc_flower_fltr *fltr;
7994 struct hlist_node *node;
7996 /* to remove all channel filters, iterate an ordered list of filters */
7997 hlist_for_each_entry_safe(fltr, node,
7998 &pf->tc_flower_fltr_list,
8000 struct ice_rule_query_data rule;
8003 /* for now process only channel specific filters */
8004 if (!ice_is_chnl_fltr(fltr))
8007 rule.rid = fltr->rid;
8008 rule.rule_id = fltr->rule_id;
8009 rule.vsi_handle = fltr->dest_id;
8010 status = ice_rem_adv_rule_by_id(&pf->hw, &rule);
8012 if (status == -ENOENT)
8013 dev_dbg(ice_pf_to_dev(pf), "TC flower filter (rule_id %u) does not exist\n",
8016 dev_err(ice_pf_to_dev(pf), "failed to delete TC flower filter, status %d\n",
8018 } else if (fltr->dest_vsi) {
8019 /* update advanced switch filter count */
8020 if (fltr->dest_vsi->type == ICE_VSI_CHNL) {
8021 u32 flags = fltr->flags;
8023 fltr->dest_vsi->num_chnl_fltr--;
8024 if (flags & (ICE_TC_FLWR_FIELD_DST_MAC |
8025 ICE_TC_FLWR_FIELD_ENC_DST_MAC))
8026 pf->num_dmac_chnl_fltrs--;
8030 hlist_del(&fltr->tc_flower_node);
8036 * ice_remove_q_channels - Remove queue channels for the TCs
8037 * @vsi: VSI to be configured
8038 * @rem_fltr: delete advanced switch filter or not
8040 * Remove queue channels for the TCs
8042 static void ice_remove_q_channels(struct ice_vsi *vsi, bool rem_fltr)
8044 struct ice_channel *ch, *ch_tmp;
8045 struct ice_pf *pf = vsi->back;
8048 /* remove all tc-flower based filter if they are channel filters only */
8050 ice_rem_all_chnl_fltrs(pf);
8052 /* remove ntuple filters since queue configuration is being changed */
8053 if (vsi->netdev->features & NETIF_F_NTUPLE) {
8054 struct ice_hw *hw = &pf->hw;
8056 mutex_lock(&hw->fdir_fltr_lock);
8057 ice_fdir_del_all_fltrs(vsi);
8058 mutex_unlock(&hw->fdir_fltr_lock);
8061 /* perform cleanup for channels if they exist */
8062 list_for_each_entry_safe(ch, ch_tmp, &vsi->ch_list, list) {
8063 struct ice_vsi *ch_vsi;
8065 list_del(&ch->list);
8066 ch_vsi = ch->ch_vsi;
8072 /* Reset queue contexts */
8073 for (i = 0; i < ch->num_rxq; i++) {
8074 struct ice_tx_ring *tx_ring;
8075 struct ice_rx_ring *rx_ring;
8077 tx_ring = vsi->tx_rings[ch->base_q + i];
8078 rx_ring = vsi->rx_rings[ch->base_q + i];
8081 if (tx_ring->q_vector)
8082 tx_ring->q_vector->ch = NULL;
8086 if (rx_ring->q_vector)
8087 rx_ring->q_vector->ch = NULL;
8091 /* Release FD resources for the channel VSI */
8092 ice_fdir_rem_adq_chnl(&pf->hw, ch->ch_vsi->idx);
8094 /* clear the VSI from scheduler tree */
8095 ice_rm_vsi_lan_cfg(ch->ch_vsi->port_info, ch->ch_vsi->idx);
8097 /* Delete VSI from FW */
8098 ice_vsi_delete(ch->ch_vsi);
8100 /* Delete VSI from PF and HW VSI arrays */
8101 ice_vsi_clear(ch->ch_vsi);
8103 /* free the channel */
8107 /* clear the channel VSI map which is stored in main VSI */
8108 ice_for_each_chnl_tc(i)
8109 vsi->tc_map_vsi[i] = NULL;
8111 /* reset main VSI's all TC information */
8117 * ice_rebuild_channels - rebuild channel
8120 * Recreate channel VSIs and replay filters
8122 static int ice_rebuild_channels(struct ice_pf *pf)
8124 struct device *dev = ice_pf_to_dev(pf);
8125 struct ice_vsi *main_vsi;
8126 bool rem_adv_fltr = true;
8127 struct ice_channel *ch;
8128 struct ice_vsi *vsi;
8132 main_vsi = ice_get_main_vsi(pf);
8136 if (!test_bit(ICE_FLAG_TC_MQPRIO, pf->flags) ||
8137 main_vsi->old_numtc == 1)
8138 return 0; /* nothing to be done */
8140 /* reconfigure main VSI based on old value of TC and cached values
8143 err = ice_vsi_cfg_tc(main_vsi, main_vsi->old_ena_tc);
8145 dev_err(dev, "failed configuring TC(ena_tc:0x%02x) for HW VSI=%u\n",
8146 main_vsi->old_ena_tc, main_vsi->vsi_num);
8150 /* rebuild ADQ VSIs */
8151 ice_for_each_vsi(pf, i) {
8152 enum ice_vsi_type type;
8155 if (!vsi || vsi->type != ICE_VSI_CHNL)
8160 /* rebuild ADQ VSI */
8161 err = ice_vsi_rebuild(vsi, true);
8163 dev_err(dev, "VSI (type:%s) at index %d rebuild failed, err %d\n",
8164 ice_vsi_type_str(type), vsi->idx, err);
8168 /* Re-map HW VSI number, using VSI handle that has been
8169 * previously validated in ice_replay_vsi() call above
8171 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
8173 /* replay filters for the VSI */
8174 err = ice_replay_vsi(&pf->hw, vsi->idx);
8176 dev_err(dev, "VSI (type:%s) replay failed, err %d, VSI index %d\n",
8177 ice_vsi_type_str(type), err, vsi->idx);
8178 rem_adv_fltr = false;
8181 dev_info(dev, "VSI (type:%s) at index %d rebuilt successfully\n",
8182 ice_vsi_type_str(type), vsi->idx);
8184 /* store ADQ VSI at correct TC index in main VSI's
8187 main_vsi->tc_map_vsi[tc_idx++] = vsi;
8190 /* ADQ VSI(s) has been rebuilt successfully, so setup
8191 * channel for main VSI's Tx and Rx rings
8193 list_for_each_entry(ch, &main_vsi->ch_list, list) {
8194 struct ice_vsi *ch_vsi;
8196 ch_vsi = ch->ch_vsi;
8200 /* reconfig channel resources */
8201 ice_cfg_chnl_all_res(main_vsi, ch);
8203 /* replay BW rate limit if it is non-zero */
8204 if (!ch->max_tx_rate && !ch->min_tx_rate)
8207 err = ice_set_bw_limit(ch_vsi, ch->max_tx_rate,
8210 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",
8211 err, ch->max_tx_rate, ch->min_tx_rate,
8214 dev_dbg(dev, "successfully rebuild BW rate limit, max_tx_rate: %llu Kbps, min_tx_rate: %llu Kbps for VSI(%u)\n",
8215 ch->max_tx_rate, ch->min_tx_rate,
8219 /* reconfig RSS for main VSI */
8220 if (main_vsi->ch_rss_size)
8221 ice_vsi_cfg_rss_lut_key(main_vsi);
8226 ice_remove_q_channels(main_vsi, rem_adv_fltr);
8231 * ice_create_q_channels - Add queue channel for the given TCs
8232 * @vsi: VSI to be configured
8234 * Configures queue channel mapping to the given TCs
8236 static int ice_create_q_channels(struct ice_vsi *vsi)
8238 struct ice_pf *pf = vsi->back;
8239 struct ice_channel *ch;
8242 ice_for_each_chnl_tc(i) {
8243 if (!(vsi->all_enatc & BIT(i)))
8246 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
8251 INIT_LIST_HEAD(&ch->list);
8252 ch->num_rxq = vsi->mqprio_qopt.qopt.count[i];
8253 ch->num_txq = vsi->mqprio_qopt.qopt.count[i];
8254 ch->base_q = vsi->mqprio_qopt.qopt.offset[i];
8255 ch->max_tx_rate = vsi->mqprio_qopt.max_rate[i];
8256 ch->min_tx_rate = vsi->mqprio_qopt.min_rate[i];
8258 /* convert to Kbits/s */
8259 if (ch->max_tx_rate)
8260 ch->max_tx_rate = div_u64(ch->max_tx_rate,
8261 ICE_BW_KBPS_DIVISOR);
8262 if (ch->min_tx_rate)
8263 ch->min_tx_rate = div_u64(ch->min_tx_rate,
8264 ICE_BW_KBPS_DIVISOR);
8266 ret = ice_create_q_channel(vsi, ch);
8268 dev_err(ice_pf_to_dev(pf),
8269 "failed creating channel TC:%d\n", i);
8273 list_add_tail(&ch->list, &vsi->ch_list);
8274 vsi->tc_map_vsi[i] = ch->ch_vsi;
8275 dev_dbg(ice_pf_to_dev(pf),
8276 "successfully created channel: VSI %pK\n", ch->ch_vsi);
8281 ice_remove_q_channels(vsi, false);
8287 * ice_setup_tc_mqprio_qdisc - configure multiple traffic classes
8288 * @netdev: net device to configure
8289 * @type_data: TC offload data
8291 static int ice_setup_tc_mqprio_qdisc(struct net_device *netdev, void *type_data)
8293 struct tc_mqprio_qopt_offload *mqprio_qopt = type_data;
8294 struct ice_netdev_priv *np = netdev_priv(netdev);
8295 struct ice_vsi *vsi = np->vsi;
8296 struct ice_pf *pf = vsi->back;
8297 u16 mode, ena_tc_qdisc = 0;
8298 int cur_txq, cur_rxq;
8303 dev = ice_pf_to_dev(pf);
8304 num_tcf = mqprio_qopt->qopt.num_tc;
8305 hw = mqprio_qopt->qopt.hw;
8306 mode = mqprio_qopt->mode;
8308 clear_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8309 vsi->ch_rss_size = 0;
8310 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8314 /* Generate queue region map for number of TCF requested */
8315 for (i = 0; i < num_tcf; i++)
8316 ena_tc_qdisc |= BIT(i);
8319 case TC_MQPRIO_MODE_CHANNEL:
8321 ret = ice_validate_mqprio_qopt(vsi, mqprio_qopt);
8323 netdev_err(netdev, "failed to validate_mqprio_qopt(), ret %d\n",
8327 memcpy(&vsi->mqprio_qopt, mqprio_qopt, sizeof(*mqprio_qopt));
8328 set_bit(ICE_FLAG_TC_MQPRIO, pf->flags);
8329 /* don't assume state of hw_tc_offload during driver load
8330 * and set the flag for TC flower filter if hw_tc_offload
8333 if (vsi->netdev->features & NETIF_F_HW_TC)
8334 set_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
8342 /* Requesting same TCF configuration as already enabled */
8343 if (ena_tc_qdisc == vsi->tc_cfg.ena_tc &&
8344 mode != TC_MQPRIO_MODE_CHANNEL)
8347 /* Pause VSI queues */
8348 ice_dis_vsi(vsi, true);
8350 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags))
8351 ice_remove_q_channels(vsi, true);
8353 if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8354 vsi->req_txq = min_t(int, ice_get_avail_txq_count(pf),
8356 vsi->req_rxq = min_t(int, ice_get_avail_rxq_count(pf),
8359 /* logic to rebuild VSI, same like ethtool -L */
8360 u16 offset = 0, qcount_tx = 0, qcount_rx = 0;
8362 for (i = 0; i < num_tcf; i++) {
8363 if (!(ena_tc_qdisc & BIT(i)))
8366 offset = vsi->mqprio_qopt.qopt.offset[i];
8367 qcount_rx = vsi->mqprio_qopt.qopt.count[i];
8368 qcount_tx = vsi->mqprio_qopt.qopt.count[i];
8370 vsi->req_txq = offset + qcount_tx;
8371 vsi->req_rxq = offset + qcount_rx;
8373 /* store away original rss_size info, so that it gets reused
8374 * form ice_vsi_rebuild during tc-qdisc delete stage - to
8375 * determine, what should be the rss_sizefor main VSI
8377 vsi->orig_rss_size = vsi->rss_size;
8380 /* save current values of Tx and Rx queues before calling VSI rebuild
8381 * for fallback option
8383 cur_txq = vsi->num_txq;
8384 cur_rxq = vsi->num_rxq;
8386 /* proceed with rebuild main VSI using correct number of queues */
8387 ret = ice_vsi_rebuild(vsi, false);
8389 /* fallback to current number of queues */
8390 dev_info(dev, "Rebuild failed with new queues, try with current number of queues\n");
8391 vsi->req_txq = cur_txq;
8392 vsi->req_rxq = cur_rxq;
8393 clear_bit(ICE_RESET_FAILED, pf->state);
8394 if (ice_vsi_rebuild(vsi, false)) {
8395 dev_err(dev, "Rebuild of main VSI failed again\n");
8400 vsi->all_numtc = num_tcf;
8401 vsi->all_enatc = ena_tc_qdisc;
8402 ret = ice_vsi_cfg_tc(vsi, ena_tc_qdisc);
8404 netdev_err(netdev, "failed configuring TC for VSI id=%d\n",
8409 if (test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) {
8410 u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
8411 u64 min_tx_rate = vsi->mqprio_qopt.min_rate[0];
8413 /* set TC0 rate limit if specified */
8414 if (max_tx_rate || min_tx_rate) {
8415 /* convert to Kbits/s */
8417 max_tx_rate = div_u64(max_tx_rate, ICE_BW_KBPS_DIVISOR);
8419 min_tx_rate = div_u64(min_tx_rate, ICE_BW_KBPS_DIVISOR);
8421 ret = ice_set_bw_limit(vsi, max_tx_rate, min_tx_rate);
8423 dev_dbg(dev, "set Tx rate max %llu min %llu for VSI(%u)\n",
8424 max_tx_rate, min_tx_rate, vsi->vsi_num);
8426 dev_err(dev, "failed to set Tx rate max %llu min %llu for VSI(%u)\n",
8427 max_tx_rate, min_tx_rate, vsi->vsi_num);
8431 ret = ice_create_q_channels(vsi);
8433 netdev_err(netdev, "failed configuring queue channels\n");
8436 netdev_dbg(netdev, "successfully configured channels\n");
8440 if (vsi->ch_rss_size)
8441 ice_vsi_cfg_rss_lut_key(vsi);
8444 /* if error, reset the all_numtc and all_enatc */
8450 ice_ena_vsi(vsi, true);
8455 static LIST_HEAD(ice_block_cb_list);
8458 ice_setup_tc(struct net_device *netdev, enum tc_setup_type type,
8461 struct ice_netdev_priv *np = netdev_priv(netdev);
8462 struct ice_pf *pf = np->vsi->back;
8466 case TC_SETUP_BLOCK:
8467 return flow_block_cb_setup_simple(type_data,
8469 ice_setup_tc_block_cb,
8471 case TC_SETUP_QDISC_MQPRIO:
8472 /* setup traffic classifier for receive side */
8473 mutex_lock(&pf->tc_mutex);
8474 err = ice_setup_tc_mqprio_qdisc(netdev, type_data);
8475 mutex_unlock(&pf->tc_mutex);
8483 static struct ice_indr_block_priv *
8484 ice_indr_block_priv_lookup(struct ice_netdev_priv *np,
8485 struct net_device *netdev)
8487 struct ice_indr_block_priv *cb_priv;
8489 list_for_each_entry(cb_priv, &np->tc_indr_block_priv_list, list) {
8490 if (!cb_priv->netdev)
8492 if (cb_priv->netdev == netdev)
8499 ice_indr_setup_block_cb(enum tc_setup_type type, void *type_data,
8502 struct ice_indr_block_priv *priv = indr_priv;
8503 struct ice_netdev_priv *np = priv->np;
8506 case TC_SETUP_CLSFLOWER:
8507 return ice_setup_tc_cls_flower(np, priv->netdev,
8508 (struct flow_cls_offload *)
8516 ice_indr_setup_tc_block(struct net_device *netdev, struct Qdisc *sch,
8517 struct ice_netdev_priv *np,
8518 struct flow_block_offload *f, void *data,
8519 void (*cleanup)(struct flow_block_cb *block_cb))
8521 struct ice_indr_block_priv *indr_priv;
8522 struct flow_block_cb *block_cb;
8524 if (!ice_is_tunnel_supported(netdev) &&
8525 !(is_vlan_dev(netdev) &&
8526 vlan_dev_real_dev(netdev) == np->vsi->netdev))
8529 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
8532 switch (f->command) {
8533 case FLOW_BLOCK_BIND:
8534 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8538 indr_priv = kzalloc(sizeof(*indr_priv), GFP_KERNEL);
8542 indr_priv->netdev = netdev;
8544 list_add(&indr_priv->list, &np->tc_indr_block_priv_list);
8547 flow_indr_block_cb_alloc(ice_indr_setup_block_cb,
8548 indr_priv, indr_priv,
8549 ice_rep_indr_tc_block_unbind,
8550 f, netdev, sch, data, np,
8553 if (IS_ERR(block_cb)) {
8554 list_del(&indr_priv->list);
8556 return PTR_ERR(block_cb);
8558 flow_block_cb_add(block_cb, f);
8559 list_add_tail(&block_cb->driver_list, &ice_block_cb_list);
8561 case FLOW_BLOCK_UNBIND:
8562 indr_priv = ice_indr_block_priv_lookup(np, netdev);
8566 block_cb = flow_block_cb_lookup(f->block,
8567 ice_indr_setup_block_cb,
8572 flow_indr_block_cb_remove(block_cb, f);
8574 list_del(&block_cb->driver_list);
8583 ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,
8584 void *cb_priv, enum tc_setup_type type, void *type_data,
8586 void (*cleanup)(struct flow_block_cb *block_cb))
8589 case TC_SETUP_BLOCK:
8590 return ice_indr_setup_tc_block(netdev, sch, cb_priv, type_data,
8599 * ice_open - Called when a network interface becomes active
8600 * @netdev: network interface device structure
8602 * The open entry point is called when a network interface is made
8603 * active by the system (IFF_UP). At this point all resources needed
8604 * for transmit and receive operations are allocated, the interrupt
8605 * handler is registered with the OS, the netdev watchdog is enabled,
8606 * and the stack is notified that the interface is ready.
8608 * Returns 0 on success, negative value on failure
8610 int ice_open(struct net_device *netdev)
8612 struct ice_netdev_priv *np = netdev_priv(netdev);
8613 struct ice_pf *pf = np->vsi->back;
8615 if (ice_is_reset_in_progress(pf->state)) {
8616 netdev_err(netdev, "can't open net device while reset is in progress");
8620 return ice_open_internal(netdev);
8624 * ice_open_internal - Called when a network interface becomes active
8625 * @netdev: network interface device structure
8627 * Internal ice_open implementation. Should not be used directly except for ice_open and reset
8630 * Returns 0 on success, negative value on failure
8632 int ice_open_internal(struct net_device *netdev)
8634 struct ice_netdev_priv *np = netdev_priv(netdev);
8635 struct ice_vsi *vsi = np->vsi;
8636 struct ice_pf *pf = vsi->back;
8637 struct ice_port_info *pi;
8640 if (test_bit(ICE_NEEDS_RESTART, pf->state)) {
8641 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
8645 netif_carrier_off(netdev);
8647 pi = vsi->port_info;
8648 err = ice_update_link_info(pi);
8650 netdev_err(netdev, "Failed to get link info, error %d\n", err);
8654 ice_check_link_cfg_err(pf, pi->phy.link_info.link_cfg_err);
8656 /* Set PHY if there is media, otherwise, turn off PHY */
8657 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
8658 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8659 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) {
8660 err = ice_init_phy_user_cfg(pi);
8662 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n",
8668 err = ice_configure_phy(vsi);
8670 netdev_err(netdev, "Failed to set physical link up, error %d\n",
8675 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
8676 ice_set_link(vsi, false);
8679 err = ice_vsi_open(vsi);
8681 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
8682 vsi->vsi_num, vsi->vsw->sw_id);
8684 /* Update existing tunnels information */
8685 udp_tunnel_get_rx_info(netdev);
8691 * ice_stop - Disables a network interface
8692 * @netdev: network interface device structure
8694 * The stop entry point is called when an interface is de-activated by the OS,
8695 * and the netdevice enters the DOWN state. The hardware is still under the
8696 * driver's control, but the netdev interface is disabled.
8698 * Returns success only - not allowed to fail
8700 int ice_stop(struct net_device *netdev)
8702 struct ice_netdev_priv *np = netdev_priv(netdev);
8703 struct ice_vsi *vsi = np->vsi;
8704 struct ice_pf *pf = vsi->back;
8706 if (ice_is_reset_in_progress(pf->state)) {
8707 netdev_err(netdev, "can't stop net device while reset is in progress");
8717 * ice_features_check - Validate encapsulated packet conforms to limits
8719 * @netdev: This port's netdev
8720 * @features: Offload features that the stack believes apply
8722 static netdev_features_t
8723 ice_features_check(struct sk_buff *skb,
8724 struct net_device __always_unused *netdev,
8725 netdev_features_t features)
8729 /* No point in doing any of this if neither checksum nor GSO are
8730 * being requested for this frame. We can rule out both by just
8731 * checking for CHECKSUM_PARTIAL
8733 if (skb->ip_summed != CHECKSUM_PARTIAL)
8736 /* We cannot support GSO if the MSS is going to be less than
8737 * 64 bytes. If it is then we need to drop support for GSO.
8739 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
8740 features &= ~NETIF_F_GSO_MASK;
8742 len = skb_network_header(skb) - skb->data;
8743 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
8744 goto out_rm_features;
8746 len = skb_transport_header(skb) - skb_network_header(skb);
8747 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8748 goto out_rm_features;
8750 if (skb->encapsulation) {
8751 len = skb_inner_network_header(skb) - skb_transport_header(skb);
8752 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
8753 goto out_rm_features;
8755 len = skb_inner_transport_header(skb) -
8756 skb_inner_network_header(skb);
8757 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
8758 goto out_rm_features;
8763 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
8766 static const struct net_device_ops ice_netdev_safe_mode_ops = {
8767 .ndo_open = ice_open,
8768 .ndo_stop = ice_stop,
8769 .ndo_start_xmit = ice_start_xmit,
8770 .ndo_set_mac_address = ice_set_mac_address,
8771 .ndo_validate_addr = eth_validate_addr,
8772 .ndo_change_mtu = ice_change_mtu,
8773 .ndo_get_stats64 = ice_get_stats64,
8774 .ndo_tx_timeout = ice_tx_timeout,
8775 .ndo_bpf = ice_xdp_safe_mode,
8778 static const struct net_device_ops ice_netdev_ops = {
8779 .ndo_open = ice_open,
8780 .ndo_stop = ice_stop,
8781 .ndo_start_xmit = ice_start_xmit,
8782 .ndo_select_queue = ice_select_queue,
8783 .ndo_features_check = ice_features_check,
8784 .ndo_fix_features = ice_fix_features,
8785 .ndo_set_rx_mode = ice_set_rx_mode,
8786 .ndo_set_mac_address = ice_set_mac_address,
8787 .ndo_validate_addr = eth_validate_addr,
8788 .ndo_change_mtu = ice_change_mtu,
8789 .ndo_get_stats64 = ice_get_stats64,
8790 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
8791 .ndo_eth_ioctl = ice_eth_ioctl,
8792 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
8793 .ndo_set_vf_mac = ice_set_vf_mac,
8794 .ndo_get_vf_config = ice_get_vf_cfg,
8795 .ndo_set_vf_trust = ice_set_vf_trust,
8796 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
8797 .ndo_set_vf_link_state = ice_set_vf_link_state,
8798 .ndo_get_vf_stats = ice_get_vf_stats,
8799 .ndo_set_vf_rate = ice_set_vf_bw,
8800 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
8801 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
8802 .ndo_setup_tc = ice_setup_tc,
8803 .ndo_set_features = ice_set_features,
8804 .ndo_bridge_getlink = ice_bridge_getlink,
8805 .ndo_bridge_setlink = ice_bridge_setlink,
8806 .ndo_fdb_add = ice_fdb_add,
8807 .ndo_fdb_del = ice_fdb_del,
8808 #ifdef CONFIG_RFS_ACCEL
8809 .ndo_rx_flow_steer = ice_rx_flow_steer,
8811 .ndo_tx_timeout = ice_tx_timeout,
8813 .ndo_xdp_xmit = ice_xdp_xmit,
8814 .ndo_xsk_wakeup = ice_xsk_wakeup,