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"
23 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
24 static const char ice_driver_string[] = DRV_SUMMARY;
25 static const char ice_copyright[] = "Copyright (c) 2018, Intel Corporation.";
27 /* DDP Package file located in firmware search paths (e.g. /lib/firmware/) */
28 #define ICE_DDP_PKG_PATH "intel/ice/ddp/"
29 #define ICE_DDP_PKG_FILE ICE_DDP_PKG_PATH "ice.pkg"
32 MODULE_DESCRIPTION(DRV_SUMMARY);
33 MODULE_LICENSE("GPL v2");
34 MODULE_FIRMWARE(ICE_DDP_PKG_FILE);
36 static int debug = -1;
37 module_param(debug, int, 0644);
38 #ifndef CONFIG_DYNAMIC_DEBUG
39 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
41 MODULE_PARM_DESC(debug, "netif level (0=none,...,16=all)");
42 #endif /* !CONFIG_DYNAMIC_DEBUG */
44 static DEFINE_IDA(ice_aux_ida);
46 static struct workqueue_struct *ice_wq;
47 static const struct net_device_ops ice_netdev_safe_mode_ops;
48 static const struct net_device_ops ice_netdev_ops;
49 static int ice_vsi_open(struct ice_vsi *vsi);
51 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type);
53 static void ice_vsi_release_all(struct ice_pf *pf);
55 bool netif_is_ice(struct net_device *dev)
57 return dev && (dev->netdev_ops == &ice_netdev_ops);
61 * ice_get_tx_pending - returns number of Tx descriptors not processed
62 * @ring: the ring of descriptors
64 static u16 ice_get_tx_pending(struct ice_ring *ring)
68 head = ring->next_to_clean;
69 tail = ring->next_to_use;
72 return (head < tail) ?
73 tail - head : (tail + ring->count - head);
78 * ice_check_for_hang_subtask - check for and recover hung queues
79 * @pf: pointer to PF struct
81 static void ice_check_for_hang_subtask(struct ice_pf *pf)
83 struct ice_vsi *vsi = NULL;
89 ice_for_each_vsi(pf, v)
90 if (pf->vsi[v] && pf->vsi[v]->type == ICE_VSI_PF) {
95 if (!vsi || test_bit(ICE_VSI_DOWN, vsi->state))
98 if (!(vsi->netdev && netif_carrier_ok(vsi->netdev)))
103 for (i = 0; i < vsi->num_txq; i++) {
104 struct ice_ring *tx_ring = vsi->tx_rings[i];
106 if (tx_ring && tx_ring->desc) {
107 /* If packet counter has not changed the queue is
108 * likely stalled, so force an interrupt for this
111 * prev_pkt would be negative if there was no
114 packets = tx_ring->stats.pkts & INT_MAX;
115 if (tx_ring->tx_stats.prev_pkt == packets) {
116 /* Trigger sw interrupt to revive the queue */
117 ice_trigger_sw_intr(hw, tx_ring->q_vector);
121 /* Memory barrier between read of packet count and call
122 * to ice_get_tx_pending()
125 tx_ring->tx_stats.prev_pkt =
126 ice_get_tx_pending(tx_ring) ? packets : -1;
132 * ice_init_mac_fltr - Set initial MAC filters
133 * @pf: board private structure
135 * Set initial set of MAC filters for PF VSI; configure filters for permanent
136 * address and broadcast address. If an error is encountered, netdevice will be
139 static int ice_init_mac_fltr(struct ice_pf *pf)
141 enum ice_status status;
145 vsi = ice_get_main_vsi(pf);
149 perm_addr = vsi->port_info->mac.perm_addr;
150 status = ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
158 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
159 * @netdev: the net device on which the sync is happening
160 * @addr: MAC address to sync
162 * This is a callback function which is called by the in kernel device sync
163 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
164 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
165 * MAC filters from the hardware.
167 static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
169 struct ice_netdev_priv *np = netdev_priv(netdev);
170 struct ice_vsi *vsi = np->vsi;
172 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
180 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
181 * @netdev: the net device on which the unsync is happening
182 * @addr: MAC address to unsync
184 * This is a callback function which is called by the in kernel device unsync
185 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
186 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
187 * delete the MAC filters from the hardware.
189 static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
191 struct ice_netdev_priv *np = netdev_priv(netdev);
192 struct ice_vsi *vsi = np->vsi;
194 if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
202 * ice_vsi_fltr_changed - check if filter state changed
203 * @vsi: VSI to be checked
205 * returns true if filter state has changed, false otherwise.
207 static bool ice_vsi_fltr_changed(struct ice_vsi *vsi)
209 return test_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state) ||
210 test_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state) ||
211 test_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
215 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
216 * @vsi: the VSI being configured
217 * @promisc_m: mask of promiscuous config bits
218 * @set_promisc: enable or disable promisc flag request
221 static int ice_cfg_promisc(struct ice_vsi *vsi, u8 promisc_m, bool set_promisc)
223 struct ice_hw *hw = &vsi->back->hw;
224 enum ice_status status = 0;
226 if (vsi->type != ICE_VSI_PF)
229 if (vsi->num_vlan > 1) {
230 status = ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_m,
234 status = ice_set_vsi_promisc(hw, vsi->idx, promisc_m,
237 status = ice_clear_vsi_promisc(hw, vsi->idx, promisc_m,
248 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
249 * @vsi: ptr to the VSI
251 * Push any outstanding VSI filter changes through the AdminQ.
253 static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
255 struct device *dev = ice_pf_to_dev(vsi->back);
256 struct net_device *netdev = vsi->netdev;
257 bool promisc_forced_on = false;
258 struct ice_pf *pf = vsi->back;
259 struct ice_hw *hw = &pf->hw;
260 enum ice_status status = 0;
261 u32 changed_flags = 0;
268 while (test_and_set_bit(ICE_CFG_BUSY, vsi->state))
269 usleep_range(1000, 2000);
271 changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
272 vsi->current_netdev_flags = vsi->netdev->flags;
274 INIT_LIST_HEAD(&vsi->tmp_sync_list);
275 INIT_LIST_HEAD(&vsi->tmp_unsync_list);
277 if (ice_vsi_fltr_changed(vsi)) {
278 clear_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
279 clear_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
280 clear_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
282 /* grab the netdev's addr_list_lock */
283 netif_addr_lock_bh(netdev);
284 __dev_uc_sync(netdev, ice_add_mac_to_sync_list,
285 ice_add_mac_to_unsync_list);
286 __dev_mc_sync(netdev, ice_add_mac_to_sync_list,
287 ice_add_mac_to_unsync_list);
288 /* our temp lists are populated. release lock */
289 netif_addr_unlock_bh(netdev);
292 /* Remove MAC addresses in the unsync list */
293 status = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
294 ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
296 netdev_err(netdev, "Failed to delete MAC filters\n");
297 /* if we failed because of alloc failures, just bail */
298 if (status == ICE_ERR_NO_MEMORY) {
304 /* Add MAC addresses in the sync list */
305 status = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
306 ice_fltr_free_list(dev, &vsi->tmp_sync_list);
307 /* If filter is added successfully or already exists, do not go into
308 * 'if' condition and report it as error. Instead continue processing
309 * rest of the function.
311 if (status && status != ICE_ERR_ALREADY_EXISTS) {
312 netdev_err(netdev, "Failed to add MAC filters\n");
313 /* If there is no more space for new umac filters, VSI
314 * should go into promiscuous mode. There should be some
315 * space reserved for promiscuous filters.
317 if (hw->adminq.sq_last_status == ICE_AQ_RC_ENOSPC &&
318 !test_and_set_bit(ICE_FLTR_OVERFLOW_PROMISC,
320 promisc_forced_on = true;
321 netdev_warn(netdev, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
328 /* check for changes in promiscuous modes */
329 if (changed_flags & IFF_ALLMULTI) {
330 if (vsi->current_netdev_flags & IFF_ALLMULTI) {
331 if (vsi->num_vlan > 1)
332 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
334 promisc_m = ICE_MCAST_PROMISC_BITS;
336 err = ice_cfg_promisc(vsi, promisc_m, true);
338 netdev_err(netdev, "Error setting Multicast promiscuous mode on VSI %i\n",
340 vsi->current_netdev_flags &= ~IFF_ALLMULTI;
344 /* !(vsi->current_netdev_flags & IFF_ALLMULTI) */
345 if (vsi->num_vlan > 1)
346 promisc_m = ICE_MCAST_VLAN_PROMISC_BITS;
348 promisc_m = ICE_MCAST_PROMISC_BITS;
350 err = ice_cfg_promisc(vsi, promisc_m, false);
352 netdev_err(netdev, "Error clearing Multicast promiscuous mode on VSI %i\n",
354 vsi->current_netdev_flags |= IFF_ALLMULTI;
360 if (((changed_flags & IFF_PROMISC) || promisc_forced_on) ||
361 test_bit(ICE_VSI_PROMISC_CHANGED, vsi->state)) {
362 clear_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
363 if (vsi->current_netdev_flags & IFF_PROMISC) {
364 /* Apply Rx filter rule to get traffic from wire */
365 if (!ice_is_dflt_vsi_in_use(pf->first_sw)) {
366 err = ice_set_dflt_vsi(pf->first_sw, vsi);
367 if (err && err != -EEXIST) {
368 netdev_err(netdev, "Error %d setting default VSI %i Rx rule\n",
370 vsi->current_netdev_flags &=
374 ice_cfg_vlan_pruning(vsi, false, false);
377 /* Clear Rx filter to remove traffic from wire */
378 if (ice_is_vsi_dflt_vsi(pf->first_sw, vsi)) {
379 err = ice_clear_dflt_vsi(pf->first_sw);
381 netdev_err(netdev, "Error %d clearing default VSI %i Rx rule\n",
383 vsi->current_netdev_flags |=
387 if (vsi->num_vlan > 1)
388 ice_cfg_vlan_pruning(vsi, true, false);
395 set_bit(ICE_VSI_PROMISC_CHANGED, vsi->state);
398 /* if something went wrong then set the changed flag so we try again */
399 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
400 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
402 clear_bit(ICE_CFG_BUSY, vsi->state);
407 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
408 * @pf: board private structure
410 static void ice_sync_fltr_subtask(struct ice_pf *pf)
414 if (!pf || !(test_bit(ICE_FLAG_FLTR_SYNC, pf->flags)))
417 clear_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
419 ice_for_each_vsi(pf, v)
420 if (pf->vsi[v] && ice_vsi_fltr_changed(pf->vsi[v]) &&
421 ice_vsi_sync_fltr(pf->vsi[v])) {
422 /* come back and try again later */
423 set_bit(ICE_FLAG_FLTR_SYNC, pf->flags);
429 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
431 * @locked: is the rtnl_lock already held
433 static void ice_pf_dis_all_vsi(struct ice_pf *pf, bool locked)
438 ice_for_each_vsi(pf, v)
440 ice_dis_vsi(pf->vsi[v], locked);
442 for (node = 0; node < ICE_MAX_PF_AGG_NODES; node++)
443 pf->pf_agg_node[node].num_vsis = 0;
445 for (node = 0; node < ICE_MAX_VF_AGG_NODES; node++)
446 pf->vf_agg_node[node].num_vsis = 0;
450 * ice_prepare_for_reset - prep for the core to reset
451 * @pf: board private structure
453 * Inform or close all dependent features in prep for reset.
456 ice_prepare_for_reset(struct ice_pf *pf)
458 struct ice_hw *hw = &pf->hw;
461 /* already prepared for reset */
462 if (test_bit(ICE_PREPARED_FOR_RESET, pf->state))
465 ice_unplug_aux_dev(pf);
467 /* Notify VFs of impending reset */
468 if (ice_check_sq_alive(hw, &hw->mailboxq))
469 ice_vc_notify_reset(pf);
471 /* Disable VFs until reset is completed */
472 ice_for_each_vf(pf, i)
473 ice_set_vf_state_qs_dis(&pf->vf[i]);
475 /* clear SW filtering DB */
476 ice_clear_hw_tbls(hw);
477 /* disable the VSIs and their queues that are not already DOWN */
478 ice_pf_dis_all_vsi(pf, false);
480 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
484 ice_sched_clear_port(hw->port_info);
486 ice_shutdown_all_ctrlq(hw);
488 set_bit(ICE_PREPARED_FOR_RESET, pf->state);
492 * ice_do_reset - Initiate one of many types of resets
493 * @pf: board private structure
494 * @reset_type: reset type requested
495 * before this function was called.
497 static void ice_do_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
499 struct device *dev = ice_pf_to_dev(pf);
500 struct ice_hw *hw = &pf->hw;
502 dev_dbg(dev, "reset_type 0x%x requested\n", reset_type);
504 ice_prepare_for_reset(pf);
506 /* trigger the reset */
507 if (ice_reset(hw, reset_type)) {
508 dev_err(dev, "reset %d failed\n", reset_type);
509 set_bit(ICE_RESET_FAILED, pf->state);
510 clear_bit(ICE_RESET_OICR_RECV, pf->state);
511 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
512 clear_bit(ICE_PFR_REQ, pf->state);
513 clear_bit(ICE_CORER_REQ, pf->state);
514 clear_bit(ICE_GLOBR_REQ, pf->state);
515 wake_up(&pf->reset_wait_queue);
519 /* PFR is a bit of a special case because it doesn't result in an OICR
520 * interrupt. So for PFR, rebuild after the reset and clear the reset-
521 * associated state bits.
523 if (reset_type == ICE_RESET_PFR) {
525 ice_rebuild(pf, reset_type);
526 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
527 clear_bit(ICE_PFR_REQ, pf->state);
528 wake_up(&pf->reset_wait_queue);
529 ice_reset_all_vfs(pf, true);
534 * ice_reset_subtask - Set up for resetting the device and driver
535 * @pf: board private structure
537 static void ice_reset_subtask(struct ice_pf *pf)
539 enum ice_reset_req reset_type = ICE_RESET_INVAL;
541 /* When a CORER/GLOBR/EMPR is about to happen, the hardware triggers an
542 * OICR interrupt. The OICR handler (ice_misc_intr) determines what type
543 * of reset is pending and sets bits in pf->state indicating the reset
544 * type and ICE_RESET_OICR_RECV. So, if the latter bit is set
545 * prepare for pending reset if not already (for PF software-initiated
546 * global resets the software should already be prepared for it as
547 * indicated by ICE_PREPARED_FOR_RESET; for global resets initiated
548 * by firmware or software on other PFs, that bit is not set so prepare
549 * for the reset now), poll for reset done, rebuild and return.
551 if (test_bit(ICE_RESET_OICR_RECV, pf->state)) {
552 /* Perform the largest reset requested */
553 if (test_and_clear_bit(ICE_CORER_RECV, pf->state))
554 reset_type = ICE_RESET_CORER;
555 if (test_and_clear_bit(ICE_GLOBR_RECV, pf->state))
556 reset_type = ICE_RESET_GLOBR;
557 if (test_and_clear_bit(ICE_EMPR_RECV, pf->state))
558 reset_type = ICE_RESET_EMPR;
559 /* return if no valid reset type requested */
560 if (reset_type == ICE_RESET_INVAL)
562 ice_prepare_for_reset(pf);
564 /* make sure we are ready to rebuild */
565 if (ice_check_reset(&pf->hw)) {
566 set_bit(ICE_RESET_FAILED, pf->state);
568 /* done with reset. start rebuild */
569 pf->hw.reset_ongoing = false;
570 ice_rebuild(pf, reset_type);
571 /* clear bit to resume normal operations, but
572 * ICE_NEEDS_RESTART bit is set in case rebuild failed
574 clear_bit(ICE_RESET_OICR_RECV, pf->state);
575 clear_bit(ICE_PREPARED_FOR_RESET, pf->state);
576 clear_bit(ICE_PFR_REQ, pf->state);
577 clear_bit(ICE_CORER_REQ, pf->state);
578 clear_bit(ICE_GLOBR_REQ, pf->state);
579 wake_up(&pf->reset_wait_queue);
580 ice_reset_all_vfs(pf, true);
586 /* No pending resets to finish processing. Check for new resets */
587 if (test_bit(ICE_PFR_REQ, pf->state))
588 reset_type = ICE_RESET_PFR;
589 if (test_bit(ICE_CORER_REQ, pf->state))
590 reset_type = ICE_RESET_CORER;
591 if (test_bit(ICE_GLOBR_REQ, pf->state))
592 reset_type = ICE_RESET_GLOBR;
593 /* If no valid reset type requested just return */
594 if (reset_type == ICE_RESET_INVAL)
597 /* reset if not already down or busy */
598 if (!test_bit(ICE_DOWN, pf->state) &&
599 !test_bit(ICE_CFG_BUSY, pf->state)) {
600 ice_do_reset(pf, reset_type);
605 * ice_print_topo_conflict - print topology conflict message
606 * @vsi: the VSI whose topology status is being checked
608 static void ice_print_topo_conflict(struct ice_vsi *vsi)
610 switch (vsi->port_info->phy.link_info.topo_media_conflict) {
611 case ICE_AQ_LINK_TOPO_CONFLICT:
612 case ICE_AQ_LINK_MEDIA_CONFLICT:
613 case ICE_AQ_LINK_TOPO_UNREACH_PRT:
614 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT:
615 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA:
616 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");
618 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA:
619 netdev_info(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");
627 * ice_print_link_msg - print link up or down message
628 * @vsi: the VSI whose link status is being queried
629 * @isup: boolean for if the link is now up or down
631 void ice_print_link_msg(struct ice_vsi *vsi, bool isup)
633 struct ice_aqc_get_phy_caps_data *caps;
634 const char *an_advertised;
635 enum ice_status status;
645 if (vsi->current_isup == isup)
648 vsi->current_isup = isup;
651 netdev_info(vsi->netdev, "NIC Link is Down\n");
655 switch (vsi->port_info->phy.link_info.link_speed) {
656 case ICE_AQ_LINK_SPEED_100GB:
659 case ICE_AQ_LINK_SPEED_50GB:
662 case ICE_AQ_LINK_SPEED_40GB:
665 case ICE_AQ_LINK_SPEED_25GB:
668 case ICE_AQ_LINK_SPEED_20GB:
671 case ICE_AQ_LINK_SPEED_10GB:
674 case ICE_AQ_LINK_SPEED_5GB:
677 case ICE_AQ_LINK_SPEED_2500MB:
680 case ICE_AQ_LINK_SPEED_1000MB:
683 case ICE_AQ_LINK_SPEED_100MB:
691 switch (vsi->port_info->fc.current_mode) {
695 case ICE_FC_TX_PAUSE:
698 case ICE_FC_RX_PAUSE:
709 /* Get FEC mode based on negotiated link info */
710 switch (vsi->port_info->phy.link_info.fec_info) {
711 case ICE_AQ_LINK_25G_RS_528_FEC_EN:
712 case ICE_AQ_LINK_25G_RS_544_FEC_EN:
715 case ICE_AQ_LINK_25G_KR_FEC_EN:
716 fec = "FC-FEC/BASE-R";
723 /* check if autoneg completed, might be false due to not supported */
724 if (vsi->port_info->phy.link_info.an_info & ICE_AQ_AN_COMPLETED)
729 /* Get FEC mode requested based on PHY caps last SW configuration */
730 caps = kzalloc(sizeof(*caps), GFP_KERNEL);
733 an_advertised = "Unknown";
737 status = ice_aq_get_phy_caps(vsi->port_info, false,
738 ICE_AQC_REPORT_ACTIVE_CFG, caps, NULL);
740 netdev_info(vsi->netdev, "Get phy capability failed.\n");
742 an_advertised = ice_is_phy_caps_an_enabled(caps) ? "On" : "Off";
744 if (caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_528_REQ ||
745 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_RS_544_REQ)
747 else if (caps->link_fec_options & ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ ||
748 caps->link_fec_options & ICE_AQC_PHY_FEC_25G_KR_REQ)
749 fec_req = "FC-FEC/BASE-R";
756 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",
757 speed, fec_req, fec, an_advertised, an, fc);
758 ice_print_topo_conflict(vsi);
762 * ice_vsi_link_event - update the VSI's netdev
763 * @vsi: the VSI on which the link event occurred
764 * @link_up: whether or not the VSI needs to be set up or down
766 static void ice_vsi_link_event(struct ice_vsi *vsi, bool link_up)
771 if (test_bit(ICE_VSI_DOWN, vsi->state) || !vsi->netdev)
774 if (vsi->type == ICE_VSI_PF) {
775 if (link_up == netif_carrier_ok(vsi->netdev))
779 netif_carrier_on(vsi->netdev);
780 netif_tx_wake_all_queues(vsi->netdev);
782 netif_carrier_off(vsi->netdev);
783 netif_tx_stop_all_queues(vsi->netdev);
789 * ice_set_dflt_mib - send a default config MIB to the FW
790 * @pf: private PF struct
792 * This function sends a default configuration MIB to the FW.
794 * If this function errors out at any point, the driver is still able to
795 * function. The main impact is that LFC may not operate as expected.
796 * Therefore an error state in this function should be treated with a DBG
797 * message and continue on with driver rebuild/reenable.
799 static void ice_set_dflt_mib(struct ice_pf *pf)
801 struct device *dev = ice_pf_to_dev(pf);
802 u8 mib_type, *buf, *lldpmib = NULL;
803 u16 len, typelen, offset = 0;
804 struct ice_lldp_org_tlv *tlv;
805 struct ice_hw *hw = &pf->hw;
808 mib_type = SET_LOCAL_MIB_TYPE_LOCAL_MIB;
809 lldpmib = kzalloc(ICE_LLDPDU_SIZE, GFP_KERNEL);
811 dev_dbg(dev, "%s Failed to allocate MIB memory\n",
816 /* Add ETS CFG TLV */
817 tlv = (struct ice_lldp_org_tlv *)lldpmib;
818 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
819 ICE_IEEE_ETS_TLV_LEN);
820 tlv->typelen = htons(typelen);
821 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
822 ICE_IEEE_SUBTYPE_ETS_CFG);
823 tlv->ouisubtype = htonl(ouisubtype);
828 /* ETS CFG all UPs map to TC 0. Next 4 (1 - 4) Octets = 0.
829 * Octets 5 - 12 are BW values, set octet 5 to 100% BW.
830 * Octets 13 - 20 are TSA values - leave as zeros
833 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
835 tlv = (struct ice_lldp_org_tlv *)
836 ((char *)tlv + sizeof(tlv->typelen) + len);
838 /* Add ETS REC TLV */
840 tlv->typelen = htons(typelen);
842 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
843 ICE_IEEE_SUBTYPE_ETS_REC);
844 tlv->ouisubtype = htonl(ouisubtype);
846 /* First octet of buf is reserved
847 * Octets 1 - 4 map UP to TC - all UPs map to zero
848 * Octets 5 - 12 are BW values - set TC 0 to 100%.
849 * Octets 13 - 20 are TSA value - leave as zeros
853 tlv = (struct ice_lldp_org_tlv *)
854 ((char *)tlv + sizeof(tlv->typelen) + len);
856 /* Add PFC CFG TLV */
857 typelen = ((ICE_TLV_TYPE_ORG << ICE_LLDP_TLV_TYPE_S) |
858 ICE_IEEE_PFC_TLV_LEN);
859 tlv->typelen = htons(typelen);
861 ouisubtype = ((ICE_IEEE_8021QAZ_OUI << ICE_LLDP_TLV_OUI_S) |
862 ICE_IEEE_SUBTYPE_PFC_CFG);
863 tlv->ouisubtype = htonl(ouisubtype);
865 /* Octet 1 left as all zeros - PFC disabled */
867 len = (typelen & ICE_LLDP_TLV_LEN_M) >> ICE_LLDP_TLV_LEN_S;
870 if (ice_aq_set_lldp_mib(hw, mib_type, (void *)lldpmib, offset, NULL))
871 dev_dbg(dev, "%s Failed to set default LLDP MIB\n", __func__);
877 * ice_check_module_power
878 * @pf: pointer to PF struct
879 * @link_cfg_err: bitmap from the link info structure
881 * check module power level returned by a previous call to aq_get_link_info
882 * and print error messages if module power level is not supported
884 static void ice_check_module_power(struct ice_pf *pf, u8 link_cfg_err)
886 /* if module power level is supported, clear the flag */
887 if (!(link_cfg_err & (ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT |
888 ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED))) {
889 clear_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
893 /* if ICE_FLAG_MOD_POWER_UNSUPPORTED was previously set and the
894 * above block didn't clear this bit, there's nothing to do
896 if (test_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags))
899 if (link_cfg_err & ICE_AQ_LINK_INVAL_MAX_POWER_LIMIT) {
900 dev_err(ice_pf_to_dev(pf), "The installed module is incompatible with the device's NVM image. Cannot start link\n");
901 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
902 } else if (link_cfg_err & ICE_AQ_LINK_MODULE_POWER_UNSUPPORTED) {
903 dev_err(ice_pf_to_dev(pf), "The module's power requirements exceed the device's power supply. Cannot start link\n");
904 set_bit(ICE_FLAG_MOD_POWER_UNSUPPORTED, pf->flags);
909 * ice_link_event - process the link event
910 * @pf: PF that the link event is associated with
911 * @pi: port_info for the port that the link event is associated with
912 * @link_up: true if the physical link is up and false if it is down
913 * @link_speed: current link speed received from the link event
915 * Returns 0 on success and negative on failure
918 ice_link_event(struct ice_pf *pf, struct ice_port_info *pi, bool link_up,
921 struct device *dev = ice_pf_to_dev(pf);
922 struct ice_phy_info *phy_info;
923 enum ice_status status;
929 phy_info->link_info_old = phy_info->link_info;
931 old_link = !!(phy_info->link_info_old.link_info & ICE_AQ_LINK_UP);
932 old_link_speed = phy_info->link_info_old.link_speed;
934 /* update the link info structures and re-enable link events,
935 * don't bail on failure due to other book keeping needed
937 status = ice_update_link_info(pi);
939 dev_dbg(dev, "Failed to update link status on port %d, err %s aq_err %s\n",
940 pi->lport, ice_stat_str(status),
941 ice_aq_str(pi->hw->adminq.sq_last_status));
943 ice_check_module_power(pf, pi->phy.link_info.link_cfg_err);
945 /* Check if the link state is up after updating link info, and treat
946 * this event as an UP event since the link is actually UP now.
948 if (phy_info->link_info.link_info & ICE_AQ_LINK_UP)
951 vsi = ice_get_main_vsi(pf);
952 if (!vsi || !vsi->port_info)
955 /* turn off PHY if media was removed */
956 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags) &&
957 !(pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE)) {
958 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
959 ice_set_link(vsi, false);
962 /* if the old link up/down and speed is the same as the new */
963 if (link_up == old_link && link_speed == old_link_speed)
966 if (ice_is_dcb_active(pf)) {
967 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
971 ice_set_dflt_mib(pf);
973 ice_vsi_link_event(vsi, link_up);
974 ice_print_link_msg(vsi, link_up);
976 ice_vc_notify_link_state(pf);
982 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
983 * @pf: board private structure
985 static void ice_watchdog_subtask(struct ice_pf *pf)
989 /* if interface is down do nothing */
990 if (test_bit(ICE_DOWN, pf->state) ||
991 test_bit(ICE_CFG_BUSY, pf->state))
994 /* make sure we don't do these things too often */
995 if (time_before(jiffies,
996 pf->serv_tmr_prev + pf->serv_tmr_period))
999 pf->serv_tmr_prev = jiffies;
1001 /* Update the stats for active netdevs so the network stack
1002 * can look at updated numbers whenever it cares to
1004 ice_update_pf_stats(pf);
1005 ice_for_each_vsi(pf, i)
1006 if (pf->vsi[i] && pf->vsi[i]->netdev)
1007 ice_update_vsi_stats(pf->vsi[i]);
1011 * ice_init_link_events - enable/initialize link events
1012 * @pi: pointer to the port_info instance
1014 * Returns -EIO on failure, 0 on success
1016 static int ice_init_link_events(struct ice_port_info *pi)
1020 mask = ~((u16)(ICE_AQ_LINK_EVENT_UPDOWN | ICE_AQ_LINK_EVENT_MEDIA_NA |
1021 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL));
1023 if (ice_aq_set_event_mask(pi->hw, pi->lport, mask, NULL)) {
1024 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to set link event mask for port %d\n",
1029 if (ice_aq_get_link_info(pi, true, NULL, NULL)) {
1030 dev_dbg(ice_hw_to_dev(pi->hw), "Failed to enable link events for port %d\n",
1039 * ice_handle_link_event - handle link event via ARQ
1040 * @pf: PF that the link event is associated with
1041 * @event: event structure containing link status info
1044 ice_handle_link_event(struct ice_pf *pf, struct ice_rq_event_info *event)
1046 struct ice_aqc_get_link_status_data *link_data;
1047 struct ice_port_info *port_info;
1050 link_data = (struct ice_aqc_get_link_status_data *)event->msg_buf;
1051 port_info = pf->hw.port_info;
1055 status = ice_link_event(pf, port_info,
1056 !!(link_data->link_info & ICE_AQ_LINK_UP),
1057 le16_to_cpu(link_data->link_speed));
1059 dev_dbg(ice_pf_to_dev(pf), "Could not process link event, error %d\n",
1065 enum ice_aq_task_state {
1066 ICE_AQ_TASK_WAITING = 0,
1067 ICE_AQ_TASK_COMPLETE,
1068 ICE_AQ_TASK_CANCELED,
1071 struct ice_aq_task {
1072 struct hlist_node entry;
1075 struct ice_rq_event_info *event;
1076 enum ice_aq_task_state state;
1080 * ice_aq_wait_for_event - Wait for an AdminQ event from firmware
1081 * @pf: pointer to the PF private structure
1082 * @opcode: the opcode to wait for
1083 * @timeout: how long to wait, in jiffies
1084 * @event: storage for the event info
1086 * Waits for a specific AdminQ completion event on the ARQ for a given PF. The
1087 * current thread will be put to sleep until the specified event occurs or
1088 * until the given timeout is reached.
1090 * To obtain only the descriptor contents, pass an event without an allocated
1091 * msg_buf. If the complete data buffer is desired, allocate the
1092 * event->msg_buf with enough space ahead of time.
1094 * Returns: zero on success, or a negative error code on failure.
1096 int ice_aq_wait_for_event(struct ice_pf *pf, u16 opcode, unsigned long timeout,
1097 struct ice_rq_event_info *event)
1099 struct device *dev = ice_pf_to_dev(pf);
1100 struct ice_aq_task *task;
1101 unsigned long start;
1105 task = kzalloc(sizeof(*task), GFP_KERNEL);
1109 INIT_HLIST_NODE(&task->entry);
1110 task->opcode = opcode;
1111 task->event = event;
1112 task->state = ICE_AQ_TASK_WAITING;
1114 spin_lock_bh(&pf->aq_wait_lock);
1115 hlist_add_head(&task->entry, &pf->aq_wait_list);
1116 spin_unlock_bh(&pf->aq_wait_lock);
1120 ret = wait_event_interruptible_timeout(pf->aq_wait_queue, task->state,
1122 switch (task->state) {
1123 case ICE_AQ_TASK_WAITING:
1124 err = ret < 0 ? ret : -ETIMEDOUT;
1126 case ICE_AQ_TASK_CANCELED:
1127 err = ret < 0 ? ret : -ECANCELED;
1129 case ICE_AQ_TASK_COMPLETE:
1130 err = ret < 0 ? ret : 0;
1133 WARN(1, "Unexpected AdminQ wait task state %u", task->state);
1138 dev_dbg(dev, "Waited %u msecs (max %u msecs) for firmware response to op 0x%04x\n",
1139 jiffies_to_msecs(jiffies - start),
1140 jiffies_to_msecs(timeout),
1143 spin_lock_bh(&pf->aq_wait_lock);
1144 hlist_del(&task->entry);
1145 spin_unlock_bh(&pf->aq_wait_lock);
1152 * ice_aq_check_events - Check if any thread is waiting for an AdminQ event
1153 * @pf: pointer to the PF private structure
1154 * @opcode: the opcode of the event
1155 * @event: the event to check
1157 * Loops over the current list of pending threads waiting for an AdminQ event.
1158 * For each matching task, copy the contents of the event into the task
1159 * structure and wake up the thread.
1161 * If multiple threads wait for the same opcode, they will all be woken up.
1163 * Note that event->msg_buf will only be duplicated if the event has a buffer
1164 * with enough space already allocated. Otherwise, only the descriptor and
1165 * message length will be copied.
1167 * Returns: true if an event was found, false otherwise
1169 static void ice_aq_check_events(struct ice_pf *pf, u16 opcode,
1170 struct ice_rq_event_info *event)
1172 struct ice_aq_task *task;
1175 spin_lock_bh(&pf->aq_wait_lock);
1176 hlist_for_each_entry(task, &pf->aq_wait_list, entry) {
1177 if (task->state || task->opcode != opcode)
1180 memcpy(&task->event->desc, &event->desc, sizeof(event->desc));
1181 task->event->msg_len = event->msg_len;
1183 /* Only copy the data buffer if a destination was set */
1184 if (task->event->msg_buf &&
1185 task->event->buf_len > event->buf_len) {
1186 memcpy(task->event->msg_buf, event->msg_buf,
1188 task->event->buf_len = event->buf_len;
1191 task->state = ICE_AQ_TASK_COMPLETE;
1194 spin_unlock_bh(&pf->aq_wait_lock);
1197 wake_up(&pf->aq_wait_queue);
1201 * ice_aq_cancel_waiting_tasks - Immediately cancel all waiting tasks
1202 * @pf: the PF private structure
1204 * Set all waiting tasks to ICE_AQ_TASK_CANCELED, and wake up their threads.
1205 * This will then cause ice_aq_wait_for_event to exit with -ECANCELED.
1207 static void ice_aq_cancel_waiting_tasks(struct ice_pf *pf)
1209 struct ice_aq_task *task;
1211 spin_lock_bh(&pf->aq_wait_lock);
1212 hlist_for_each_entry(task, &pf->aq_wait_list, entry)
1213 task->state = ICE_AQ_TASK_CANCELED;
1214 spin_unlock_bh(&pf->aq_wait_lock);
1216 wake_up(&pf->aq_wait_queue);
1220 * __ice_clean_ctrlq - helper function to clean controlq rings
1221 * @pf: ptr to struct ice_pf
1222 * @q_type: specific Control queue type
1224 static int __ice_clean_ctrlq(struct ice_pf *pf, enum ice_ctl_q q_type)
1226 struct device *dev = ice_pf_to_dev(pf);
1227 struct ice_rq_event_info event;
1228 struct ice_hw *hw = &pf->hw;
1229 struct ice_ctl_q_info *cq;
1234 /* Do not clean control queue if/when PF reset fails */
1235 if (test_bit(ICE_RESET_FAILED, pf->state))
1239 case ICE_CTL_Q_ADMIN:
1247 case ICE_CTL_Q_MAILBOX:
1250 /* we are going to try to detect a malicious VF, so set the
1251 * state to begin detection
1253 hw->mbx_snapshot.mbx_buf.state = ICE_MAL_VF_DETECT_STATE_NEW_SNAPSHOT;
1256 dev_warn(dev, "Unknown control queue type 0x%x\n", q_type);
1260 /* check for error indications - PF_xx_AxQLEN register layout for
1261 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
1263 val = rd32(hw, cq->rq.len);
1264 if (val & (PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1265 PF_FW_ARQLEN_ARQCRIT_M)) {
1267 if (val & PF_FW_ARQLEN_ARQVFE_M)
1268 dev_dbg(dev, "%s Receive Queue VF Error detected\n",
1270 if (val & PF_FW_ARQLEN_ARQOVFL_M) {
1271 dev_dbg(dev, "%s Receive Queue Overflow Error detected\n",
1274 if (val & PF_FW_ARQLEN_ARQCRIT_M)
1275 dev_dbg(dev, "%s Receive Queue Critical Error detected\n",
1277 val &= ~(PF_FW_ARQLEN_ARQVFE_M | PF_FW_ARQLEN_ARQOVFL_M |
1278 PF_FW_ARQLEN_ARQCRIT_M);
1280 wr32(hw, cq->rq.len, val);
1283 val = rd32(hw, cq->sq.len);
1284 if (val & (PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1285 PF_FW_ATQLEN_ATQCRIT_M)) {
1287 if (val & PF_FW_ATQLEN_ATQVFE_M)
1288 dev_dbg(dev, "%s Send Queue VF Error detected\n",
1290 if (val & PF_FW_ATQLEN_ATQOVFL_M) {
1291 dev_dbg(dev, "%s Send Queue Overflow Error detected\n",
1294 if (val & PF_FW_ATQLEN_ATQCRIT_M)
1295 dev_dbg(dev, "%s Send Queue Critical Error detected\n",
1297 val &= ~(PF_FW_ATQLEN_ATQVFE_M | PF_FW_ATQLEN_ATQOVFL_M |
1298 PF_FW_ATQLEN_ATQCRIT_M);
1300 wr32(hw, cq->sq.len, val);
1303 event.buf_len = cq->rq_buf_size;
1304 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1309 enum ice_status ret;
1312 ret = ice_clean_rq_elem(hw, cq, &event, &pending);
1313 if (ret == ICE_ERR_AQ_NO_WORK)
1316 dev_err(dev, "%s Receive Queue event error %s\n", qtype,
1321 opcode = le16_to_cpu(event.desc.opcode);
1323 /* Notify any thread that might be waiting for this event */
1324 ice_aq_check_events(pf, opcode, &event);
1327 case ice_aqc_opc_get_link_status:
1328 if (ice_handle_link_event(pf, &event))
1329 dev_err(dev, "Could not handle link event\n");
1331 case ice_aqc_opc_event_lan_overflow:
1332 ice_vf_lan_overflow_event(pf, &event);
1334 case ice_mbx_opc_send_msg_to_pf:
1335 if (!ice_is_malicious_vf(pf, &event, i, pending))
1336 ice_vc_process_vf_msg(pf, &event);
1338 case ice_aqc_opc_fw_logging:
1339 ice_output_fw_log(hw, &event.desc, event.msg_buf);
1341 case ice_aqc_opc_lldp_set_mib_change:
1342 ice_dcb_process_lldp_set_mib_change(pf, &event);
1345 dev_dbg(dev, "%s Receive Queue unknown event 0x%04x ignored\n",
1349 } while (pending && (i++ < ICE_DFLT_IRQ_WORK));
1351 kfree(event.msg_buf);
1353 return pending && (i == ICE_DFLT_IRQ_WORK);
1357 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1358 * @hw: pointer to hardware info
1359 * @cq: control queue information
1361 * returns true if there are pending messages in a queue, false if there aren't
1363 static bool ice_ctrlq_pending(struct ice_hw *hw, struct ice_ctl_q_info *cq)
1367 ntu = (u16)(rd32(hw, cq->rq.head) & cq->rq.head_mask);
1368 return cq->rq.next_to_clean != ntu;
1372 * ice_clean_adminq_subtask - clean the AdminQ rings
1373 * @pf: board private structure
1375 static void ice_clean_adminq_subtask(struct ice_pf *pf)
1377 struct ice_hw *hw = &pf->hw;
1379 if (!test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
1382 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN))
1385 clear_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
1387 /* There might be a situation where new messages arrive to a control
1388 * queue between processing the last message and clearing the
1389 * EVENT_PENDING bit. So before exiting, check queue head again (using
1390 * ice_ctrlq_pending) and process new messages if any.
1392 if (ice_ctrlq_pending(hw, &hw->adminq))
1393 __ice_clean_ctrlq(pf, ICE_CTL_Q_ADMIN);
1399 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1400 * @pf: board private structure
1402 static void ice_clean_mailboxq_subtask(struct ice_pf *pf)
1404 struct ice_hw *hw = &pf->hw;
1406 if (!test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state))
1409 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX))
1412 clear_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
1414 if (ice_ctrlq_pending(hw, &hw->mailboxq))
1415 __ice_clean_ctrlq(pf, ICE_CTL_Q_MAILBOX);
1421 * ice_clean_sbq_subtask - clean the Sideband Queue rings
1422 * @pf: board private structure
1424 static void ice_clean_sbq_subtask(struct ice_pf *pf)
1426 struct ice_hw *hw = &pf->hw;
1428 /* Nothing to do here if sideband queue is not supported */
1429 if (!ice_is_sbq_supported(hw)) {
1430 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1434 if (!test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state))
1437 if (__ice_clean_ctrlq(pf, ICE_CTL_Q_SB))
1440 clear_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
1442 if (ice_ctrlq_pending(hw, &hw->sbq))
1443 __ice_clean_ctrlq(pf, ICE_CTL_Q_SB);
1449 * ice_service_task_schedule - schedule the service task to wake up
1450 * @pf: board private structure
1452 * If not already scheduled, this puts the task into the work queue.
1454 void ice_service_task_schedule(struct ice_pf *pf)
1456 if (!test_bit(ICE_SERVICE_DIS, pf->state) &&
1457 !test_and_set_bit(ICE_SERVICE_SCHED, pf->state) &&
1458 !test_bit(ICE_NEEDS_RESTART, pf->state))
1459 queue_work(ice_wq, &pf->serv_task);
1463 * ice_service_task_complete - finish up the service task
1464 * @pf: board private structure
1466 static void ice_service_task_complete(struct ice_pf *pf)
1468 WARN_ON(!test_bit(ICE_SERVICE_SCHED, pf->state));
1470 /* force memory (pf->state) to sync before next service task */
1471 smp_mb__before_atomic();
1472 clear_bit(ICE_SERVICE_SCHED, pf->state);
1476 * ice_service_task_stop - stop service task and cancel works
1477 * @pf: board private structure
1479 * Return 0 if the ICE_SERVICE_DIS bit was not already set,
1482 static int ice_service_task_stop(struct ice_pf *pf)
1486 ret = test_and_set_bit(ICE_SERVICE_DIS, pf->state);
1488 if (pf->serv_tmr.function)
1489 del_timer_sync(&pf->serv_tmr);
1490 if (pf->serv_task.func)
1491 cancel_work_sync(&pf->serv_task);
1493 clear_bit(ICE_SERVICE_SCHED, pf->state);
1498 * ice_service_task_restart - restart service task and schedule works
1499 * @pf: board private structure
1501 * This function is needed for suspend and resume works (e.g WoL scenario)
1503 static void ice_service_task_restart(struct ice_pf *pf)
1505 clear_bit(ICE_SERVICE_DIS, pf->state);
1506 ice_service_task_schedule(pf);
1510 * ice_service_timer - timer callback to schedule service task
1511 * @t: pointer to timer_list
1513 static void ice_service_timer(struct timer_list *t)
1515 struct ice_pf *pf = from_timer(pf, t, serv_tmr);
1517 mod_timer(&pf->serv_tmr, round_jiffies(pf->serv_tmr_period + jiffies));
1518 ice_service_task_schedule(pf);
1522 * ice_handle_mdd_event - handle malicious driver detect event
1523 * @pf: pointer to the PF structure
1525 * Called from service task. OICR interrupt handler indicates MDD event.
1526 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1527 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1528 * disable the queue, the PF can be configured to reset the VF using ethtool
1529 * private flag mdd-auto-reset-vf.
1531 static void ice_handle_mdd_event(struct ice_pf *pf)
1533 struct device *dev = ice_pf_to_dev(pf);
1534 struct ice_hw *hw = &pf->hw;
1538 if (!test_and_clear_bit(ICE_MDD_EVENT_PENDING, pf->state)) {
1539 /* Since the VF MDD event logging is rate limited, check if
1540 * there are pending MDD events.
1542 ice_print_vfs_mdd_events(pf);
1546 /* find what triggered an MDD event */
1547 reg = rd32(hw, GL_MDET_TX_PQM);
1548 if (reg & GL_MDET_TX_PQM_VALID_M) {
1549 u8 pf_num = (reg & GL_MDET_TX_PQM_PF_NUM_M) >>
1550 GL_MDET_TX_PQM_PF_NUM_S;
1551 u16 vf_num = (reg & GL_MDET_TX_PQM_VF_NUM_M) >>
1552 GL_MDET_TX_PQM_VF_NUM_S;
1553 u8 event = (reg & GL_MDET_TX_PQM_MAL_TYPE_M) >>
1554 GL_MDET_TX_PQM_MAL_TYPE_S;
1555 u16 queue = ((reg & GL_MDET_TX_PQM_QNUM_M) >>
1556 GL_MDET_TX_PQM_QNUM_S);
1558 if (netif_msg_tx_err(pf))
1559 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1560 event, queue, pf_num, vf_num);
1561 wr32(hw, GL_MDET_TX_PQM, 0xffffffff);
1564 reg = rd32(hw, GL_MDET_TX_TCLAN);
1565 if (reg & GL_MDET_TX_TCLAN_VALID_M) {
1566 u8 pf_num = (reg & GL_MDET_TX_TCLAN_PF_NUM_M) >>
1567 GL_MDET_TX_TCLAN_PF_NUM_S;
1568 u16 vf_num = (reg & GL_MDET_TX_TCLAN_VF_NUM_M) >>
1569 GL_MDET_TX_TCLAN_VF_NUM_S;
1570 u8 event = (reg & GL_MDET_TX_TCLAN_MAL_TYPE_M) >>
1571 GL_MDET_TX_TCLAN_MAL_TYPE_S;
1572 u16 queue = ((reg & GL_MDET_TX_TCLAN_QNUM_M) >>
1573 GL_MDET_TX_TCLAN_QNUM_S);
1575 if (netif_msg_tx_err(pf))
1576 dev_info(dev, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1577 event, queue, pf_num, vf_num);
1578 wr32(hw, GL_MDET_TX_TCLAN, 0xffffffff);
1581 reg = rd32(hw, GL_MDET_RX);
1582 if (reg & GL_MDET_RX_VALID_M) {
1583 u8 pf_num = (reg & GL_MDET_RX_PF_NUM_M) >>
1584 GL_MDET_RX_PF_NUM_S;
1585 u16 vf_num = (reg & GL_MDET_RX_VF_NUM_M) >>
1586 GL_MDET_RX_VF_NUM_S;
1587 u8 event = (reg & GL_MDET_RX_MAL_TYPE_M) >>
1588 GL_MDET_RX_MAL_TYPE_S;
1589 u16 queue = ((reg & GL_MDET_RX_QNUM_M) >>
1592 if (netif_msg_rx_err(pf))
1593 dev_info(dev, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1594 event, queue, pf_num, vf_num);
1595 wr32(hw, GL_MDET_RX, 0xffffffff);
1598 /* check to see if this PF caused an MDD event */
1599 reg = rd32(hw, PF_MDET_TX_PQM);
1600 if (reg & PF_MDET_TX_PQM_VALID_M) {
1601 wr32(hw, PF_MDET_TX_PQM, 0xFFFF);
1602 if (netif_msg_tx_err(pf))
1603 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on PF\n");
1606 reg = rd32(hw, PF_MDET_TX_TCLAN);
1607 if (reg & PF_MDET_TX_TCLAN_VALID_M) {
1608 wr32(hw, PF_MDET_TX_TCLAN, 0xFFFF);
1609 if (netif_msg_tx_err(pf))
1610 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1613 reg = rd32(hw, PF_MDET_RX);
1614 if (reg & PF_MDET_RX_VALID_M) {
1615 wr32(hw, PF_MDET_RX, 0xFFFF);
1616 if (netif_msg_rx_err(pf))
1617 dev_info(dev, "Malicious Driver Detection event RX detected on PF\n");
1620 /* Check to see if one of the VFs caused an MDD event, and then
1621 * increment counters and set print pending
1623 ice_for_each_vf(pf, i) {
1624 struct ice_vf *vf = &pf->vf[i];
1626 reg = rd32(hw, VP_MDET_TX_PQM(i));
1627 if (reg & VP_MDET_TX_PQM_VALID_M) {
1628 wr32(hw, VP_MDET_TX_PQM(i), 0xFFFF);
1629 vf->mdd_tx_events.count++;
1630 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1631 if (netif_msg_tx_err(pf))
1632 dev_info(dev, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1636 reg = rd32(hw, VP_MDET_TX_TCLAN(i));
1637 if (reg & VP_MDET_TX_TCLAN_VALID_M) {
1638 wr32(hw, VP_MDET_TX_TCLAN(i), 0xFFFF);
1639 vf->mdd_tx_events.count++;
1640 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1641 if (netif_msg_tx_err(pf))
1642 dev_info(dev, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1646 reg = rd32(hw, VP_MDET_TX_TDPU(i));
1647 if (reg & VP_MDET_TX_TDPU_VALID_M) {
1648 wr32(hw, VP_MDET_TX_TDPU(i), 0xFFFF);
1649 vf->mdd_tx_events.count++;
1650 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1651 if (netif_msg_tx_err(pf))
1652 dev_info(dev, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1656 reg = rd32(hw, VP_MDET_RX(i));
1657 if (reg & VP_MDET_RX_VALID_M) {
1658 wr32(hw, VP_MDET_RX(i), 0xFFFF);
1659 vf->mdd_rx_events.count++;
1660 set_bit(ICE_MDD_VF_PRINT_PENDING, pf->state);
1661 if (netif_msg_rx_err(pf))
1662 dev_info(dev, "Malicious Driver Detection event RX detected on VF %d\n",
1665 /* Since the queue is disabled on VF Rx MDD events, the
1666 * PF can be configured to reset the VF through ethtool
1667 * private flag mdd-auto-reset-vf.
1669 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)) {
1670 /* VF MDD event counters will be cleared by
1671 * reset, so print the event prior to reset.
1673 ice_print_vf_rx_mdd_event(vf);
1674 ice_reset_vf(&pf->vf[i], false);
1679 ice_print_vfs_mdd_events(pf);
1683 * ice_force_phys_link_state - Force the physical link state
1684 * @vsi: VSI to force the physical link state to up/down
1685 * @link_up: true/false indicates to set the physical link to up/down
1687 * Force the physical link state by getting the current PHY capabilities from
1688 * hardware and setting the PHY config based on the determined capabilities. If
1689 * link changes a link event will be triggered because both the Enable Automatic
1690 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1692 * Returns 0 on success, negative on failure
1694 static int ice_force_phys_link_state(struct ice_vsi *vsi, bool link_up)
1696 struct ice_aqc_get_phy_caps_data *pcaps;
1697 struct ice_aqc_set_phy_cfg_data *cfg;
1698 struct ice_port_info *pi;
1702 if (!vsi || !vsi->port_info || !vsi->back)
1704 if (vsi->type != ICE_VSI_PF)
1707 dev = ice_pf_to_dev(vsi->back);
1709 pi = vsi->port_info;
1711 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1715 retcode = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1718 dev_err(dev, "Failed to get phy capabilities, VSI %d error %d\n",
1719 vsi->vsi_num, retcode);
1724 /* No change in link */
1725 if (link_up == !!(pcaps->caps & ICE_AQC_PHY_EN_LINK) &&
1726 link_up == !!(pi->phy.link_info.link_info & ICE_AQ_LINK_UP))
1729 /* Use the current user PHY configuration. The current user PHY
1730 * configuration is initialized during probe from PHY capabilities
1731 * software mode, and updated on set PHY configuration.
1733 cfg = kmemdup(&pi->phy.curr_user_phy_cfg, sizeof(*cfg), GFP_KERNEL);
1739 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT;
1741 cfg->caps |= ICE_AQ_PHY_ENA_LINK;
1743 cfg->caps &= ~ICE_AQ_PHY_ENA_LINK;
1745 retcode = ice_aq_set_phy_cfg(&vsi->back->hw, pi, cfg, NULL);
1747 dev_err(dev, "Failed to set phy config, VSI %d error %d\n",
1748 vsi->vsi_num, retcode);
1759 * ice_init_nvm_phy_type - Initialize the NVM PHY type
1760 * @pi: port info structure
1762 * Initialize nvm_phy_type_[low|high] for link lenient mode support
1764 static int ice_init_nvm_phy_type(struct ice_port_info *pi)
1766 struct ice_aqc_get_phy_caps_data *pcaps;
1767 struct ice_pf *pf = pi->hw->back;
1768 enum ice_status status;
1771 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1775 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_NO_MEDIA, pcaps,
1779 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
1784 pf->nvm_phy_type_hi = pcaps->phy_type_high;
1785 pf->nvm_phy_type_lo = pcaps->phy_type_low;
1793 * ice_init_link_dflt_override - Initialize link default override
1794 * @pi: port info structure
1796 * Initialize link default override and PHY total port shutdown during probe
1798 static void ice_init_link_dflt_override(struct ice_port_info *pi)
1800 struct ice_link_default_override_tlv *ldo;
1801 struct ice_pf *pf = pi->hw->back;
1803 ldo = &pf->link_dflt_override;
1804 if (ice_get_link_default_override(ldo, pi))
1807 if (!(ldo->options & ICE_LINK_OVERRIDE_PORT_DIS))
1810 /* Enable Total Port Shutdown (override/replace link-down-on-close
1811 * ethtool private flag) for ports with Port Disable bit set.
1813 set_bit(ICE_FLAG_TOTAL_PORT_SHUTDOWN_ENA, pf->flags);
1814 set_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags);
1818 * ice_init_phy_cfg_dflt_override - Initialize PHY cfg default override settings
1819 * @pi: port info structure
1821 * If default override is enabled, initialize the user PHY cfg speed and FEC
1822 * settings using the default override mask from the NVM.
1824 * The PHY should only be configured with the default override settings the
1825 * first time media is available. The ICE_LINK_DEFAULT_OVERRIDE_PENDING state
1826 * is used to indicate that the user PHY cfg default override is initialized
1827 * and the PHY has not been configured with the default override settings. The
1828 * state is set here, and cleared in ice_configure_phy the first time the PHY is
1831 * This function should be called only if the FW doesn't support default
1832 * configuration mode, as reported by ice_fw_supports_report_dflt_cfg.
1834 static void ice_init_phy_cfg_dflt_override(struct ice_port_info *pi)
1836 struct ice_link_default_override_tlv *ldo;
1837 struct ice_aqc_set_phy_cfg_data *cfg;
1838 struct ice_phy_info *phy = &pi->phy;
1839 struct ice_pf *pf = pi->hw->back;
1841 ldo = &pf->link_dflt_override;
1843 /* If link default override is enabled, use to mask NVM PHY capabilities
1844 * for speed and FEC default configuration.
1846 cfg = &phy->curr_user_phy_cfg;
1848 if (ldo->phy_type_low || ldo->phy_type_high) {
1849 cfg->phy_type_low = pf->nvm_phy_type_lo &
1850 cpu_to_le64(ldo->phy_type_low);
1851 cfg->phy_type_high = pf->nvm_phy_type_hi &
1852 cpu_to_le64(ldo->phy_type_high);
1854 cfg->link_fec_opt = ldo->fec_options;
1855 phy->curr_user_fec_req = ICE_FEC_AUTO;
1857 set_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING, pf->state);
1861 * ice_init_phy_user_cfg - Initialize the PHY user configuration
1862 * @pi: port info structure
1864 * Initialize the current user PHY configuration, speed, FEC, and FC requested
1865 * mode to default. The PHY defaults are from get PHY capabilities topology
1866 * with media so call when media is first available. An error is returned if
1867 * called when media is not available. The PHY initialization completed state is
1870 * These configurations are used when setting PHY
1871 * configuration. The user PHY configuration is updated on set PHY
1872 * configuration. Returns 0 on success, negative on failure
1874 static int ice_init_phy_user_cfg(struct ice_port_info *pi)
1876 struct ice_aqc_get_phy_caps_data *pcaps;
1877 struct ice_phy_info *phy = &pi->phy;
1878 struct ice_pf *pf = pi->hw->back;
1879 enum ice_status status;
1882 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
1885 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1889 if (ice_fw_supports_report_dflt_cfg(pi->hw))
1890 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
1893 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1896 dev_err(ice_pf_to_dev(pf), "Get PHY capability failed.\n");
1901 ice_copy_phy_caps_to_cfg(pi, pcaps, &pi->phy.curr_user_phy_cfg);
1903 /* check if lenient mode is supported and enabled */
1904 if (ice_fw_supports_link_override(pi->hw) &&
1905 !(pcaps->module_compliance_enforcement &
1906 ICE_AQC_MOD_ENFORCE_STRICT_MODE)) {
1907 set_bit(ICE_FLAG_LINK_LENIENT_MODE_ENA, pf->flags);
1909 /* if the FW supports default PHY configuration mode, then the driver
1910 * does not have to apply link override settings. If not,
1911 * initialize user PHY configuration with link override values
1913 if (!ice_fw_supports_report_dflt_cfg(pi->hw) &&
1914 (pf->link_dflt_override.options & ICE_LINK_OVERRIDE_EN)) {
1915 ice_init_phy_cfg_dflt_override(pi);
1920 /* if link default override is not enabled, set user flow control and
1921 * FEC settings based on what get_phy_caps returned
1923 phy->curr_user_fec_req = ice_caps_to_fec_mode(pcaps->caps,
1924 pcaps->link_fec_options);
1925 phy->curr_user_fc_req = ice_caps_to_fc_mode(pcaps->caps);
1928 phy->curr_user_speed_req = ICE_AQ_LINK_SPEED_M;
1929 set_bit(ICE_PHY_INIT_COMPLETE, pf->state);
1936 * ice_configure_phy - configure PHY
1939 * Set the PHY configuration. If the current PHY configuration is the same as
1940 * the curr_user_phy_cfg, then do nothing to avoid link flap. Otherwise
1941 * configure the based get PHY capabilities for topology with media.
1943 static int ice_configure_phy(struct ice_vsi *vsi)
1945 struct device *dev = ice_pf_to_dev(vsi->back);
1946 struct ice_port_info *pi = vsi->port_info;
1947 struct ice_aqc_get_phy_caps_data *pcaps;
1948 struct ice_aqc_set_phy_cfg_data *cfg;
1949 struct ice_phy_info *phy = &pi->phy;
1950 struct ice_pf *pf = vsi->back;
1951 enum ice_status status;
1954 /* Ensure we have media as we cannot configure a medialess port */
1955 if (!(phy->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE))
1958 ice_print_topo_conflict(vsi);
1960 if (phy->link_info.topo_media_conflict == ICE_AQ_LINK_TOPO_UNSUPP_MEDIA)
1963 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags))
1964 return ice_force_phys_link_state(vsi, true);
1966 pcaps = kzalloc(sizeof(*pcaps), GFP_KERNEL);
1970 /* Get current PHY config */
1971 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_ACTIVE_CFG, pcaps,
1974 dev_err(dev, "Failed to get PHY configuration, VSI %d error %s\n",
1975 vsi->vsi_num, ice_stat_str(status));
1980 /* If PHY enable link is configured and configuration has not changed,
1981 * there's nothing to do
1983 if (pcaps->caps & ICE_AQC_PHY_EN_LINK &&
1984 ice_phy_caps_equals_cfg(pcaps, &phy->curr_user_phy_cfg))
1987 /* Use PHY topology as baseline for configuration */
1988 memset(pcaps, 0, sizeof(*pcaps));
1989 if (ice_fw_supports_report_dflt_cfg(pi->hw))
1990 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_DFLT_CFG,
1993 status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_TOPO_CAP_MEDIA,
1996 dev_err(dev, "Failed to get PHY caps, VSI %d error %s\n",
1997 vsi->vsi_num, ice_stat_str(status));
2002 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
2008 ice_copy_phy_caps_to_cfg(pi, pcaps, cfg);
2010 /* Speed - If default override pending, use curr_user_phy_cfg set in
2011 * ice_init_phy_user_cfg_ldo.
2013 if (test_and_clear_bit(ICE_LINK_DEFAULT_OVERRIDE_PENDING,
2014 vsi->back->state)) {
2015 cfg->phy_type_low = phy->curr_user_phy_cfg.phy_type_low;
2016 cfg->phy_type_high = phy->curr_user_phy_cfg.phy_type_high;
2018 u64 phy_low = 0, phy_high = 0;
2020 ice_update_phy_type(&phy_low, &phy_high,
2021 pi->phy.curr_user_speed_req);
2022 cfg->phy_type_low = pcaps->phy_type_low & cpu_to_le64(phy_low);
2023 cfg->phy_type_high = pcaps->phy_type_high &
2024 cpu_to_le64(phy_high);
2027 /* Can't provide what was requested; use PHY capabilities */
2028 if (!cfg->phy_type_low && !cfg->phy_type_high) {
2029 cfg->phy_type_low = pcaps->phy_type_low;
2030 cfg->phy_type_high = pcaps->phy_type_high;
2034 ice_cfg_phy_fec(pi, cfg, phy->curr_user_fec_req);
2036 /* Can't provide what was requested; use PHY capabilities */
2037 if (cfg->link_fec_opt !=
2038 (cfg->link_fec_opt & pcaps->link_fec_options)) {
2039 cfg->caps |= pcaps->caps & ICE_AQC_PHY_EN_AUTO_FEC;
2040 cfg->link_fec_opt = pcaps->link_fec_options;
2043 /* Flow Control - always supported; no need to check against
2046 ice_cfg_phy_fc(pi, cfg, phy->curr_user_fc_req);
2048 /* Enable link and link update */
2049 cfg->caps |= ICE_AQ_PHY_ENA_AUTO_LINK_UPDT | ICE_AQ_PHY_ENA_LINK;
2051 status = ice_aq_set_phy_cfg(&pf->hw, pi, cfg, NULL);
2053 dev_err(dev, "Failed to set phy config, VSI %d error %s\n",
2054 vsi->vsi_num, ice_stat_str(status));
2065 * ice_check_media_subtask - Check for media
2066 * @pf: pointer to PF struct
2068 * If media is available, then initialize PHY user configuration if it is not
2069 * been, and configure the PHY if the interface is up.
2071 static void ice_check_media_subtask(struct ice_pf *pf)
2073 struct ice_port_info *pi;
2074 struct ice_vsi *vsi;
2077 /* No need to check for media if it's already present */
2078 if (!test_bit(ICE_FLAG_NO_MEDIA, pf->flags))
2081 vsi = ice_get_main_vsi(pf);
2085 /* Refresh link info and check if media is present */
2086 pi = vsi->port_info;
2087 err = ice_update_link_info(pi);
2091 ice_check_module_power(pf, pi->phy.link_info.link_cfg_err);
2093 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
2094 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state))
2095 ice_init_phy_user_cfg(pi);
2097 /* PHY settings are reset on media insertion, reconfigure
2098 * PHY to preserve settings.
2100 if (test_bit(ICE_VSI_DOWN, vsi->state) &&
2101 test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags))
2104 err = ice_configure_phy(vsi);
2106 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
2108 /* A Link Status Event will be generated; the event handler
2109 * will complete bringing the interface up
2115 * ice_service_task - manage and run subtasks
2116 * @work: pointer to work_struct contained by the PF struct
2118 static void ice_service_task(struct work_struct *work)
2120 struct ice_pf *pf = container_of(work, struct ice_pf, serv_task);
2121 unsigned long start_time = jiffies;
2125 /* process reset requests first */
2126 ice_reset_subtask(pf);
2128 /* bail if a reset/recovery cycle is pending or rebuild failed */
2129 if (ice_is_reset_in_progress(pf->state) ||
2130 test_bit(ICE_SUSPENDED, pf->state) ||
2131 test_bit(ICE_NEEDS_RESTART, pf->state)) {
2132 ice_service_task_complete(pf);
2136 ice_clean_adminq_subtask(pf);
2137 ice_check_media_subtask(pf);
2138 ice_check_for_hang_subtask(pf);
2139 ice_sync_fltr_subtask(pf);
2140 ice_handle_mdd_event(pf);
2141 ice_watchdog_subtask(pf);
2143 if (ice_is_safe_mode(pf)) {
2144 ice_service_task_complete(pf);
2148 ice_process_vflr_event(pf);
2149 ice_clean_mailboxq_subtask(pf);
2150 ice_clean_sbq_subtask(pf);
2151 ice_sync_arfs_fltrs(pf);
2152 ice_flush_fdir_ctx(pf);
2154 /* Clear ICE_SERVICE_SCHED flag to allow scheduling next event */
2155 ice_service_task_complete(pf);
2157 /* If the tasks have taken longer than one service timer period
2158 * or there is more work to be done, reset the service timer to
2159 * schedule the service task now.
2161 if (time_after(jiffies, (start_time + pf->serv_tmr_period)) ||
2162 test_bit(ICE_MDD_EVENT_PENDING, pf->state) ||
2163 test_bit(ICE_VFLR_EVENT_PENDING, pf->state) ||
2164 test_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state) ||
2165 test_bit(ICE_FD_VF_FLUSH_CTX, pf->state) ||
2166 test_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state) ||
2167 test_bit(ICE_ADMINQ_EVENT_PENDING, pf->state))
2168 mod_timer(&pf->serv_tmr, jiffies);
2172 * ice_set_ctrlq_len - helper function to set controlq length
2173 * @hw: pointer to the HW instance
2175 static void ice_set_ctrlq_len(struct ice_hw *hw)
2177 hw->adminq.num_rq_entries = ICE_AQ_LEN;
2178 hw->adminq.num_sq_entries = ICE_AQ_LEN;
2179 hw->adminq.rq_buf_size = ICE_AQ_MAX_BUF_LEN;
2180 hw->adminq.sq_buf_size = ICE_AQ_MAX_BUF_LEN;
2181 hw->mailboxq.num_rq_entries = PF_MBX_ARQLEN_ARQLEN_M;
2182 hw->mailboxq.num_sq_entries = ICE_MBXSQ_LEN;
2183 hw->mailboxq.rq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2184 hw->mailboxq.sq_buf_size = ICE_MBXQ_MAX_BUF_LEN;
2185 hw->sbq.num_rq_entries = ICE_SBQ_LEN;
2186 hw->sbq.num_sq_entries = ICE_SBQ_LEN;
2187 hw->sbq.rq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2188 hw->sbq.sq_buf_size = ICE_SBQ_MAX_BUF_LEN;
2192 * ice_schedule_reset - schedule a reset
2193 * @pf: board private structure
2194 * @reset: reset being requested
2196 int ice_schedule_reset(struct ice_pf *pf, enum ice_reset_req reset)
2198 struct device *dev = ice_pf_to_dev(pf);
2200 /* bail out if earlier reset has failed */
2201 if (test_bit(ICE_RESET_FAILED, pf->state)) {
2202 dev_dbg(dev, "earlier reset has failed\n");
2205 /* bail if reset/recovery already in progress */
2206 if (ice_is_reset_in_progress(pf->state)) {
2207 dev_dbg(dev, "Reset already in progress\n");
2211 ice_unplug_aux_dev(pf);
2215 set_bit(ICE_PFR_REQ, pf->state);
2217 case ICE_RESET_CORER:
2218 set_bit(ICE_CORER_REQ, pf->state);
2220 case ICE_RESET_GLOBR:
2221 set_bit(ICE_GLOBR_REQ, pf->state);
2227 ice_service_task_schedule(pf);
2232 * ice_irq_affinity_notify - Callback for affinity changes
2233 * @notify: context as to what irq was changed
2234 * @mask: the new affinity mask
2236 * This is a callback function used by the irq_set_affinity_notifier function
2237 * so that we may register to receive changes to the irq affinity masks.
2240 ice_irq_affinity_notify(struct irq_affinity_notify *notify,
2241 const cpumask_t *mask)
2243 struct ice_q_vector *q_vector =
2244 container_of(notify, struct ice_q_vector, affinity_notify);
2246 cpumask_copy(&q_vector->affinity_mask, mask);
2250 * ice_irq_affinity_release - Callback for affinity notifier release
2251 * @ref: internal core kernel usage
2253 * This is a callback function used by the irq_set_affinity_notifier function
2254 * to inform the current notification subscriber that they will no longer
2255 * receive notifications.
2257 static void ice_irq_affinity_release(struct kref __always_unused *ref) {}
2260 * ice_vsi_ena_irq - Enable IRQ for the given VSI
2261 * @vsi: the VSI being configured
2263 static int ice_vsi_ena_irq(struct ice_vsi *vsi)
2265 struct ice_hw *hw = &vsi->back->hw;
2268 ice_for_each_q_vector(vsi, i)
2269 ice_irq_dynamic_ena(hw, vsi, vsi->q_vectors[i]);
2276 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
2277 * @vsi: the VSI being configured
2278 * @basename: name for the vector
2280 static int ice_vsi_req_irq_msix(struct ice_vsi *vsi, char *basename)
2282 int q_vectors = vsi->num_q_vectors;
2283 struct ice_pf *pf = vsi->back;
2284 int base = vsi->base_vector;
2291 dev = ice_pf_to_dev(pf);
2292 for (vector = 0; vector < q_vectors; vector++) {
2293 struct ice_q_vector *q_vector = vsi->q_vectors[vector];
2295 irq_num = pf->msix_entries[base + vector].vector;
2297 if (q_vector->tx.ring && q_vector->rx.ring) {
2298 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2299 "%s-%s-%d", basename, "TxRx", rx_int_idx++);
2301 } else if (q_vector->rx.ring) {
2302 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2303 "%s-%s-%d", basename, "rx", rx_int_idx++);
2304 } else if (q_vector->tx.ring) {
2305 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2306 "%s-%s-%d", basename, "tx", tx_int_idx++);
2308 /* skip this unused q_vector */
2311 if (vsi->type == ICE_VSI_CTRL && vsi->vf_id != ICE_INVAL_VFID)
2312 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2313 IRQF_SHARED, q_vector->name,
2316 err = devm_request_irq(dev, irq_num, vsi->irq_handler,
2317 0, q_vector->name, q_vector);
2319 netdev_err(vsi->netdev, "MSIX request_irq failed, error: %d\n",
2324 /* register for affinity change notifications */
2325 if (!IS_ENABLED(CONFIG_RFS_ACCEL)) {
2326 struct irq_affinity_notify *affinity_notify;
2328 affinity_notify = &q_vector->affinity_notify;
2329 affinity_notify->notify = ice_irq_affinity_notify;
2330 affinity_notify->release = ice_irq_affinity_release;
2331 irq_set_affinity_notifier(irq_num, affinity_notify);
2334 /* assign the mask for this irq */
2335 irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
2338 vsi->irqs_ready = true;
2344 irq_num = pf->msix_entries[base + vector].vector;
2345 if (!IS_ENABLED(CONFIG_RFS_ACCEL))
2346 irq_set_affinity_notifier(irq_num, NULL);
2347 irq_set_affinity_hint(irq_num, NULL);
2348 devm_free_irq(dev, irq_num, &vsi->q_vectors[vector]);
2354 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
2355 * @vsi: VSI to setup Tx rings used by XDP
2357 * Return 0 on success and negative value on error
2359 static int ice_xdp_alloc_setup_rings(struct ice_vsi *vsi)
2361 struct device *dev = ice_pf_to_dev(vsi->back);
2364 for (i = 0; i < vsi->num_xdp_txq; i++) {
2365 u16 xdp_q_idx = vsi->alloc_txq + i;
2366 struct ice_ring *xdp_ring;
2368 xdp_ring = kzalloc(sizeof(*xdp_ring), GFP_KERNEL);
2371 goto free_xdp_rings;
2373 xdp_ring->q_index = xdp_q_idx;
2374 xdp_ring->reg_idx = vsi->txq_map[xdp_q_idx];
2375 xdp_ring->ring_active = false;
2376 xdp_ring->vsi = vsi;
2377 xdp_ring->netdev = NULL;
2378 xdp_ring->dev = dev;
2379 xdp_ring->count = vsi->num_tx_desc;
2380 WRITE_ONCE(vsi->xdp_rings[i], xdp_ring);
2381 if (ice_setup_tx_ring(xdp_ring))
2382 goto free_xdp_rings;
2383 ice_set_ring_xdp(xdp_ring);
2384 xdp_ring->xsk_pool = ice_xsk_pool(xdp_ring);
2391 if (vsi->xdp_rings[i] && vsi->xdp_rings[i]->desc)
2392 ice_free_tx_ring(vsi->xdp_rings[i]);
2397 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
2398 * @vsi: VSI to set the bpf prog on
2399 * @prog: the bpf prog pointer
2401 static void ice_vsi_assign_bpf_prog(struct ice_vsi *vsi, struct bpf_prog *prog)
2403 struct bpf_prog *old_prog;
2406 old_prog = xchg(&vsi->xdp_prog, prog);
2408 bpf_prog_put(old_prog);
2410 ice_for_each_rxq(vsi, i)
2411 WRITE_ONCE(vsi->rx_rings[i]->xdp_prog, vsi->xdp_prog);
2415 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
2416 * @vsi: VSI to bring up Tx rings used by XDP
2417 * @prog: bpf program that will be assigned to VSI
2419 * Return 0 on success and negative value on error
2421 int ice_prepare_xdp_rings(struct ice_vsi *vsi, struct bpf_prog *prog)
2423 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2424 int xdp_rings_rem = vsi->num_xdp_txq;
2425 struct ice_pf *pf = vsi->back;
2426 struct ice_qs_cfg xdp_qs_cfg = {
2427 .qs_mutex = &pf->avail_q_mutex,
2428 .pf_map = pf->avail_txqs,
2429 .pf_map_size = pf->max_pf_txqs,
2430 .q_count = vsi->num_xdp_txq,
2431 .scatter_count = ICE_MAX_SCATTER_TXQS,
2432 .vsi_map = vsi->txq_map,
2433 .vsi_map_offset = vsi->alloc_txq,
2434 .mapping_mode = ICE_VSI_MAP_CONTIG
2436 enum ice_status status;
2440 dev = ice_pf_to_dev(pf);
2441 vsi->xdp_rings = devm_kcalloc(dev, vsi->num_xdp_txq,
2442 sizeof(*vsi->xdp_rings), GFP_KERNEL);
2443 if (!vsi->xdp_rings)
2446 vsi->xdp_mapping_mode = xdp_qs_cfg.mapping_mode;
2447 if (__ice_vsi_get_qs(&xdp_qs_cfg))
2450 if (ice_xdp_alloc_setup_rings(vsi))
2451 goto clear_xdp_rings;
2453 /* follow the logic from ice_vsi_map_rings_to_vectors */
2454 ice_for_each_q_vector(vsi, v_idx) {
2455 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2456 int xdp_rings_per_v, q_id, q_base;
2458 xdp_rings_per_v = DIV_ROUND_UP(xdp_rings_rem,
2459 vsi->num_q_vectors - v_idx);
2460 q_base = vsi->num_xdp_txq - xdp_rings_rem;
2462 for (q_id = q_base; q_id < (q_base + xdp_rings_per_v); q_id++) {
2463 struct ice_ring *xdp_ring = vsi->xdp_rings[q_id];
2465 xdp_ring->q_vector = q_vector;
2466 xdp_ring->next = q_vector->tx.ring;
2467 q_vector->tx.ring = xdp_ring;
2469 xdp_rings_rem -= xdp_rings_per_v;
2472 /* omit the scheduler update if in reset path; XDP queues will be
2473 * taken into account at the end of ice_vsi_rebuild, where
2474 * ice_cfg_vsi_lan is being called
2476 if (ice_is_reset_in_progress(pf->state))
2479 /* tell the Tx scheduler that right now we have
2482 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2483 max_txqs[i] = vsi->num_txq + vsi->num_xdp_txq;
2485 status = ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2488 dev_err(dev, "Failed VSI LAN queue config for XDP, error: %s\n",
2489 ice_stat_str(status));
2490 goto clear_xdp_rings;
2492 ice_vsi_assign_bpf_prog(vsi, prog);
2496 for (i = 0; i < vsi->num_xdp_txq; i++)
2497 if (vsi->xdp_rings[i]) {
2498 kfree_rcu(vsi->xdp_rings[i], rcu);
2499 vsi->xdp_rings[i] = NULL;
2503 mutex_lock(&pf->avail_q_mutex);
2504 for (i = 0; i < vsi->num_xdp_txq; i++) {
2505 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2506 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2508 mutex_unlock(&pf->avail_q_mutex);
2510 devm_kfree(dev, vsi->xdp_rings);
2515 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
2516 * @vsi: VSI to remove XDP rings
2518 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
2521 int ice_destroy_xdp_rings(struct ice_vsi *vsi)
2523 u16 max_txqs[ICE_MAX_TRAFFIC_CLASS] = { 0 };
2524 struct ice_pf *pf = vsi->back;
2527 /* q_vectors are freed in reset path so there's no point in detaching
2528 * rings; in case of rebuild being triggered not from reset bits
2529 * in pf->state won't be set, so additionally check first q_vector
2532 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2535 ice_for_each_q_vector(vsi, v_idx) {
2536 struct ice_q_vector *q_vector = vsi->q_vectors[v_idx];
2537 struct ice_ring *ring;
2539 ice_for_each_ring(ring, q_vector->tx)
2540 if (!ring->tx_buf || !ice_ring_is_xdp(ring))
2543 /* restore the value of last node prior to XDP setup */
2544 q_vector->tx.ring = ring;
2548 mutex_lock(&pf->avail_q_mutex);
2549 for (i = 0; i < vsi->num_xdp_txq; i++) {
2550 clear_bit(vsi->txq_map[i + vsi->alloc_txq], pf->avail_txqs);
2551 vsi->txq_map[i + vsi->alloc_txq] = ICE_INVAL_Q_INDEX;
2553 mutex_unlock(&pf->avail_q_mutex);
2555 for (i = 0; i < vsi->num_xdp_txq; i++)
2556 if (vsi->xdp_rings[i]) {
2557 if (vsi->xdp_rings[i]->desc)
2558 ice_free_tx_ring(vsi->xdp_rings[i]);
2559 kfree_rcu(vsi->xdp_rings[i], rcu);
2560 vsi->xdp_rings[i] = NULL;
2563 devm_kfree(ice_pf_to_dev(pf), vsi->xdp_rings);
2564 vsi->xdp_rings = NULL;
2566 if (ice_is_reset_in_progress(pf->state) || !vsi->q_vectors[0])
2569 ice_vsi_assign_bpf_prog(vsi, NULL);
2571 /* notify Tx scheduler that we destroyed XDP queues and bring
2572 * back the old number of child nodes
2574 for (i = 0; i < vsi->tc_cfg.numtc; i++)
2575 max_txqs[i] = vsi->num_txq;
2577 /* change number of XDP Tx queues to 0 */
2578 vsi->num_xdp_txq = 0;
2580 return ice_cfg_vsi_lan(vsi->port_info, vsi->idx, vsi->tc_cfg.ena_tc,
2585 * ice_vsi_rx_napi_schedule - Schedule napi on RX queues from VSI
2586 * @vsi: VSI to schedule napi on
2588 static void ice_vsi_rx_napi_schedule(struct ice_vsi *vsi)
2592 ice_for_each_rxq(vsi, i) {
2593 struct ice_ring *rx_ring = vsi->rx_rings[i];
2595 if (rx_ring->xsk_pool)
2596 napi_schedule(&rx_ring->q_vector->napi);
2601 * ice_xdp_setup_prog - Add or remove XDP eBPF program
2602 * @vsi: VSI to setup XDP for
2603 * @prog: XDP program
2604 * @extack: netlink extended ack
2607 ice_xdp_setup_prog(struct ice_vsi *vsi, struct bpf_prog *prog,
2608 struct netlink_ext_ack *extack)
2610 int frame_size = vsi->netdev->mtu + ICE_ETH_PKT_HDR_PAD;
2611 bool if_running = netif_running(vsi->netdev);
2612 int ret = 0, xdp_ring_err = 0;
2614 if (frame_size > vsi->rx_buf_len) {
2615 NL_SET_ERR_MSG_MOD(extack, "MTU too large for loading XDP");
2619 /* need to stop netdev while setting up the program for Rx rings */
2620 if (if_running && !test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
2621 ret = ice_down(vsi);
2623 NL_SET_ERR_MSG_MOD(extack, "Preparing device for XDP attach failed");
2628 if (!ice_is_xdp_ena_vsi(vsi) && prog) {
2629 vsi->num_xdp_txq = vsi->alloc_rxq;
2630 xdp_ring_err = ice_prepare_xdp_rings(vsi, prog);
2632 NL_SET_ERR_MSG_MOD(extack, "Setting up XDP Tx resources failed");
2633 } else if (ice_is_xdp_ena_vsi(vsi) && !prog) {
2634 xdp_ring_err = ice_destroy_xdp_rings(vsi);
2636 NL_SET_ERR_MSG_MOD(extack, "Freeing XDP Tx resources failed");
2638 ice_vsi_assign_bpf_prog(vsi, prog);
2645 ice_vsi_rx_napi_schedule(vsi);
2647 return (ret || xdp_ring_err) ? -ENOMEM : 0;
2651 * ice_xdp_safe_mode - XDP handler for safe mode
2655 static int ice_xdp_safe_mode(struct net_device __always_unused *dev,
2656 struct netdev_bpf *xdp)
2658 NL_SET_ERR_MSG_MOD(xdp->extack,
2659 "Please provide working DDP firmware package in order to use XDP\n"
2660 "Refer to Documentation/networking/device_drivers/ethernet/intel/ice.rst");
2665 * ice_xdp - implements XDP handler
2669 static int ice_xdp(struct net_device *dev, struct netdev_bpf *xdp)
2671 struct ice_netdev_priv *np = netdev_priv(dev);
2672 struct ice_vsi *vsi = np->vsi;
2674 if (vsi->type != ICE_VSI_PF) {
2675 NL_SET_ERR_MSG_MOD(xdp->extack, "XDP can be loaded only on PF VSI");
2679 switch (xdp->command) {
2680 case XDP_SETUP_PROG:
2681 return ice_xdp_setup_prog(vsi, xdp->prog, xdp->extack);
2682 case XDP_SETUP_XSK_POOL:
2683 return ice_xsk_pool_setup(vsi, xdp->xsk.pool,
2691 * ice_ena_misc_vector - enable the non-queue interrupts
2692 * @pf: board private structure
2694 static void ice_ena_misc_vector(struct ice_pf *pf)
2696 struct ice_hw *hw = &pf->hw;
2699 /* Disable anti-spoof detection interrupt to prevent spurious event
2700 * interrupts during a function reset. Anti-spoof functionally is
2703 val = rd32(hw, GL_MDCK_TX_TDPU);
2704 val |= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M;
2705 wr32(hw, GL_MDCK_TX_TDPU, val);
2707 /* clear things first */
2708 wr32(hw, PFINT_OICR_ENA, 0); /* disable all */
2709 rd32(hw, PFINT_OICR); /* read to clear */
2711 val = (PFINT_OICR_ECC_ERR_M |
2712 PFINT_OICR_MAL_DETECT_M |
2714 PFINT_OICR_PCI_EXCEPTION_M |
2716 PFINT_OICR_HMC_ERR_M |
2717 PFINT_OICR_PE_PUSH_M |
2718 PFINT_OICR_PE_CRITERR_M);
2720 wr32(hw, PFINT_OICR_ENA, val);
2722 /* SW_ITR_IDX = 0, but don't change INTENA */
2723 wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
2724 GLINT_DYN_CTL_SW_ITR_INDX_M | GLINT_DYN_CTL_INTENA_MSK_M);
2728 * ice_misc_intr - misc interrupt handler
2729 * @irq: interrupt number
2730 * @data: pointer to a q_vector
2732 static irqreturn_t ice_misc_intr(int __always_unused irq, void *data)
2734 struct ice_pf *pf = (struct ice_pf *)data;
2735 struct ice_hw *hw = &pf->hw;
2736 irqreturn_t ret = IRQ_NONE;
2740 dev = ice_pf_to_dev(pf);
2741 set_bit(ICE_ADMINQ_EVENT_PENDING, pf->state);
2742 set_bit(ICE_MAILBOXQ_EVENT_PENDING, pf->state);
2743 set_bit(ICE_SIDEBANDQ_EVENT_PENDING, pf->state);
2745 oicr = rd32(hw, PFINT_OICR);
2746 ena_mask = rd32(hw, PFINT_OICR_ENA);
2748 if (oicr & PFINT_OICR_SWINT_M) {
2749 ena_mask &= ~PFINT_OICR_SWINT_M;
2753 if (oicr & PFINT_OICR_MAL_DETECT_M) {
2754 ena_mask &= ~PFINT_OICR_MAL_DETECT_M;
2755 set_bit(ICE_MDD_EVENT_PENDING, pf->state);
2757 if (oicr & PFINT_OICR_VFLR_M) {
2758 /* disable any further VFLR event notifications */
2759 if (test_bit(ICE_VF_RESETS_DISABLED, pf->state)) {
2760 u32 reg = rd32(hw, PFINT_OICR_ENA);
2762 reg &= ~PFINT_OICR_VFLR_M;
2763 wr32(hw, PFINT_OICR_ENA, reg);
2765 ena_mask &= ~PFINT_OICR_VFLR_M;
2766 set_bit(ICE_VFLR_EVENT_PENDING, pf->state);
2770 if (oicr & PFINT_OICR_GRST_M) {
2773 /* we have a reset warning */
2774 ena_mask &= ~PFINT_OICR_GRST_M;
2775 reset = (rd32(hw, GLGEN_RSTAT) & GLGEN_RSTAT_RESET_TYPE_M) >>
2776 GLGEN_RSTAT_RESET_TYPE_S;
2778 if (reset == ICE_RESET_CORER)
2780 else if (reset == ICE_RESET_GLOBR)
2782 else if (reset == ICE_RESET_EMPR)
2785 dev_dbg(dev, "Invalid reset type %d\n", reset);
2787 /* If a reset cycle isn't already in progress, we set a bit in
2788 * pf->state so that the service task can start a reset/rebuild.
2790 if (!test_and_set_bit(ICE_RESET_OICR_RECV, pf->state)) {
2791 if (reset == ICE_RESET_CORER)
2792 set_bit(ICE_CORER_RECV, pf->state);
2793 else if (reset == ICE_RESET_GLOBR)
2794 set_bit(ICE_GLOBR_RECV, pf->state);
2796 set_bit(ICE_EMPR_RECV, pf->state);
2798 /* There are couple of different bits at play here.
2799 * hw->reset_ongoing indicates whether the hardware is
2800 * in reset. This is set to true when a reset interrupt
2801 * is received and set back to false after the driver
2802 * has determined that the hardware is out of reset.
2804 * ICE_RESET_OICR_RECV in pf->state indicates
2805 * that a post reset rebuild is required before the
2806 * driver is operational again. This is set above.
2808 * As this is the start of the reset/rebuild cycle, set
2809 * both to indicate that.
2811 hw->reset_ongoing = true;
2815 if (oicr & PFINT_OICR_TSYN_TX_M) {
2816 ena_mask &= ~PFINT_OICR_TSYN_TX_M;
2817 ice_ptp_process_ts(pf);
2820 if (oicr & PFINT_OICR_TSYN_EVNT_M) {
2821 u8 tmr_idx = hw->func_caps.ts_func_info.tmr_index_owned;
2822 u32 gltsyn_stat = rd32(hw, GLTSYN_STAT(tmr_idx));
2824 /* Save EVENTs from GTSYN register */
2825 pf->ptp.ext_ts_irq |= gltsyn_stat & (GLTSYN_STAT_EVENT0_M |
2826 GLTSYN_STAT_EVENT1_M |
2827 GLTSYN_STAT_EVENT2_M);
2828 ena_mask &= ~PFINT_OICR_TSYN_EVNT_M;
2829 kthread_queue_work(pf->ptp.kworker, &pf->ptp.extts_work);
2832 #define ICE_AUX_CRIT_ERR (PFINT_OICR_PE_CRITERR_M | PFINT_OICR_HMC_ERR_M | PFINT_OICR_PE_PUSH_M)
2833 if (oicr & ICE_AUX_CRIT_ERR) {
2834 struct iidc_event *event;
2836 ena_mask &= ~ICE_AUX_CRIT_ERR;
2837 event = kzalloc(sizeof(*event), GFP_KERNEL);
2839 set_bit(IIDC_EVENT_CRIT_ERR, event->type);
2840 /* report the entire OICR value to AUX driver */
2842 ice_send_event_to_aux(pf, event);
2847 /* Report any remaining unexpected interrupts */
2850 dev_dbg(dev, "unhandled interrupt oicr=0x%08x\n", oicr);
2851 /* If a critical error is pending there is no choice but to
2854 if (oicr & (PFINT_OICR_PCI_EXCEPTION_M |
2855 PFINT_OICR_ECC_ERR_M)) {
2856 set_bit(ICE_PFR_REQ, pf->state);
2857 ice_service_task_schedule(pf);
2862 ice_service_task_schedule(pf);
2863 ice_irq_dynamic_ena(hw, NULL, NULL);
2869 * ice_dis_ctrlq_interrupts - disable control queue interrupts
2870 * @hw: pointer to HW structure
2872 static void ice_dis_ctrlq_interrupts(struct ice_hw *hw)
2874 /* disable Admin queue Interrupt causes */
2875 wr32(hw, PFINT_FW_CTL,
2876 rd32(hw, PFINT_FW_CTL) & ~PFINT_FW_CTL_CAUSE_ENA_M);
2878 /* disable Mailbox queue Interrupt causes */
2879 wr32(hw, PFINT_MBX_CTL,
2880 rd32(hw, PFINT_MBX_CTL) & ~PFINT_MBX_CTL_CAUSE_ENA_M);
2882 wr32(hw, PFINT_SB_CTL,
2883 rd32(hw, PFINT_SB_CTL) & ~PFINT_SB_CTL_CAUSE_ENA_M);
2885 /* disable Control queue Interrupt causes */
2886 wr32(hw, PFINT_OICR_CTL,
2887 rd32(hw, PFINT_OICR_CTL) & ~PFINT_OICR_CTL_CAUSE_ENA_M);
2893 * ice_free_irq_msix_misc - Unroll misc vector setup
2894 * @pf: board private structure
2896 static void ice_free_irq_msix_misc(struct ice_pf *pf)
2898 struct ice_hw *hw = &pf->hw;
2900 ice_dis_ctrlq_interrupts(hw);
2902 /* disable OICR interrupt */
2903 wr32(hw, PFINT_OICR_ENA, 0);
2906 if (pf->msix_entries) {
2907 synchronize_irq(pf->msix_entries[pf->oicr_idx].vector);
2908 devm_free_irq(ice_pf_to_dev(pf),
2909 pf->msix_entries[pf->oicr_idx].vector, pf);
2912 pf->num_avail_sw_msix += 1;
2913 ice_free_res(pf->irq_tracker, pf->oicr_idx, ICE_RES_MISC_VEC_ID);
2917 * ice_ena_ctrlq_interrupts - enable control queue interrupts
2918 * @hw: pointer to HW structure
2919 * @reg_idx: HW vector index to associate the control queue interrupts with
2921 static void ice_ena_ctrlq_interrupts(struct ice_hw *hw, u16 reg_idx)
2925 val = ((reg_idx & PFINT_OICR_CTL_MSIX_INDX_M) |
2926 PFINT_OICR_CTL_CAUSE_ENA_M);
2927 wr32(hw, PFINT_OICR_CTL, val);
2929 /* enable Admin queue Interrupt causes */
2930 val = ((reg_idx & PFINT_FW_CTL_MSIX_INDX_M) |
2931 PFINT_FW_CTL_CAUSE_ENA_M);
2932 wr32(hw, PFINT_FW_CTL, val);
2934 /* enable Mailbox queue Interrupt causes */
2935 val = ((reg_idx & PFINT_MBX_CTL_MSIX_INDX_M) |
2936 PFINT_MBX_CTL_CAUSE_ENA_M);
2937 wr32(hw, PFINT_MBX_CTL, val);
2939 /* This enables Sideband queue Interrupt causes */
2940 val = ((reg_idx & PFINT_SB_CTL_MSIX_INDX_M) |
2941 PFINT_SB_CTL_CAUSE_ENA_M);
2942 wr32(hw, PFINT_SB_CTL, val);
2948 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2949 * @pf: board private structure
2951 * This sets up the handler for MSIX 0, which is used to manage the
2952 * non-queue interrupts, e.g. AdminQ and errors. This is not used
2953 * when in MSI or Legacy interrupt mode.
2955 static int ice_req_irq_msix_misc(struct ice_pf *pf)
2957 struct device *dev = ice_pf_to_dev(pf);
2958 struct ice_hw *hw = &pf->hw;
2959 int oicr_idx, err = 0;
2961 if (!pf->int_name[0])
2962 snprintf(pf->int_name, sizeof(pf->int_name) - 1, "%s-%s:misc",
2963 dev_driver_string(dev), dev_name(dev));
2965 /* Do not request IRQ but do enable OICR interrupt since settings are
2966 * lost during reset. Note that this function is called only during
2967 * rebuild path and not while reset is in progress.
2969 if (ice_is_reset_in_progress(pf->state))
2972 /* reserve one vector in irq_tracker for misc interrupts */
2973 oicr_idx = ice_get_res(pf, pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2977 pf->num_avail_sw_msix -= 1;
2978 pf->oicr_idx = (u16)oicr_idx;
2980 err = devm_request_irq(dev, pf->msix_entries[pf->oicr_idx].vector,
2981 ice_misc_intr, 0, pf->int_name, pf);
2983 dev_err(dev, "devm_request_irq for %s failed: %d\n",
2985 ice_free_res(pf->irq_tracker, 1, ICE_RES_MISC_VEC_ID);
2986 pf->num_avail_sw_msix += 1;
2991 ice_ena_misc_vector(pf);
2993 ice_ena_ctrlq_interrupts(hw, pf->oicr_idx);
2994 wr32(hw, GLINT_ITR(ICE_RX_ITR, pf->oicr_idx),
2995 ITR_REG_ALIGN(ICE_ITR_8K) >> ICE_ITR_GRAN_S);
2998 ice_irq_dynamic_ena(hw, NULL, NULL);
3004 * ice_napi_add - register NAPI handler for the VSI
3005 * @vsi: VSI for which NAPI handler is to be registered
3007 * This function is only called in the driver's load path. Registering the NAPI
3008 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
3009 * reset/rebuild, etc.)
3011 static void ice_napi_add(struct ice_vsi *vsi)
3018 ice_for_each_q_vector(vsi, v_idx)
3019 netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi,
3020 ice_napi_poll, NAPI_POLL_WEIGHT);
3024 * ice_set_ops - set netdev and ethtools ops for the given netdev
3025 * @netdev: netdev instance
3027 static void ice_set_ops(struct net_device *netdev)
3029 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3031 if (ice_is_safe_mode(pf)) {
3032 netdev->netdev_ops = &ice_netdev_safe_mode_ops;
3033 ice_set_ethtool_safe_mode_ops(netdev);
3037 netdev->netdev_ops = &ice_netdev_ops;
3038 netdev->udp_tunnel_nic_info = &pf->hw.udp_tunnel_nic;
3039 ice_set_ethtool_ops(netdev);
3043 * ice_set_netdev_features - set features for the given netdev
3044 * @netdev: netdev instance
3046 static void ice_set_netdev_features(struct net_device *netdev)
3048 struct ice_pf *pf = ice_netdev_to_pf(netdev);
3049 netdev_features_t csumo_features;
3050 netdev_features_t vlano_features;
3051 netdev_features_t dflt_features;
3052 netdev_features_t tso_features;
3054 if (ice_is_safe_mode(pf)) {
3056 netdev->features = NETIF_F_SG | NETIF_F_HIGHDMA;
3057 netdev->hw_features = netdev->features;
3061 dflt_features = NETIF_F_SG |
3066 csumo_features = NETIF_F_RXCSUM |
3071 vlano_features = NETIF_F_HW_VLAN_CTAG_FILTER |
3072 NETIF_F_HW_VLAN_CTAG_TX |
3073 NETIF_F_HW_VLAN_CTAG_RX;
3075 tso_features = NETIF_F_TSO |
3079 NETIF_F_GSO_UDP_TUNNEL |
3080 NETIF_F_GSO_GRE_CSUM |
3081 NETIF_F_GSO_UDP_TUNNEL_CSUM |
3082 NETIF_F_GSO_PARTIAL |
3083 NETIF_F_GSO_IPXIP4 |
3084 NETIF_F_GSO_IPXIP6 |
3087 netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM |
3088 NETIF_F_GSO_GRE_CSUM;
3089 /* set features that user can change */
3090 netdev->hw_features = dflt_features | csumo_features |
3091 vlano_features | tso_features;
3093 /* add support for HW_CSUM on packets with MPLS header */
3094 netdev->mpls_features = NETIF_F_HW_CSUM;
3096 /* enable features */
3097 netdev->features |= netdev->hw_features;
3098 /* encap and VLAN devices inherit default, csumo and tso features */
3099 netdev->hw_enc_features |= dflt_features | csumo_features |
3101 netdev->vlan_features |= dflt_features | csumo_features |
3106 * ice_cfg_netdev - Allocate, configure and register a netdev
3107 * @vsi: the VSI associated with the new netdev
3109 * Returns 0 on success, negative value on failure
3111 static int ice_cfg_netdev(struct ice_vsi *vsi)
3113 struct ice_netdev_priv *np;
3114 struct net_device *netdev;
3115 u8 mac_addr[ETH_ALEN];
3117 netdev = alloc_etherdev_mqs(sizeof(*np), vsi->alloc_txq,
3122 set_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3123 vsi->netdev = netdev;
3124 np = netdev_priv(netdev);
3127 ice_set_netdev_features(netdev);
3129 ice_set_ops(netdev);
3131 if (vsi->type == ICE_VSI_PF) {
3132 SET_NETDEV_DEV(netdev, ice_pf_to_dev(vsi->back));
3133 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
3134 ether_addr_copy(netdev->dev_addr, mac_addr);
3135 ether_addr_copy(netdev->perm_addr, mac_addr);
3138 netdev->priv_flags |= IFF_UNICAST_FLT;
3140 /* Setup netdev TC information */
3141 ice_vsi_cfg_netdev_tc(vsi, vsi->tc_cfg.ena_tc);
3143 /* setup watchdog timeout value to be 5 second */
3144 netdev->watchdog_timeo = 5 * HZ;
3146 netdev->min_mtu = ETH_MIN_MTU;
3147 netdev->max_mtu = ICE_MAX_MTU;
3153 * ice_fill_rss_lut - Fill the RSS lookup table with default values
3154 * @lut: Lookup table
3155 * @rss_table_size: Lookup table size
3156 * @rss_size: Range of queue number for hashing
3158 void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
3162 for (i = 0; i < rss_table_size; i++)
3163 lut[i] = i % rss_size;
3167 * ice_pf_vsi_setup - Set up a PF VSI
3168 * @pf: board private structure
3169 * @pi: pointer to the port_info instance
3171 * Returns pointer to the successfully allocated VSI software struct
3172 * on success, otherwise returns NULL on failure.
3174 static struct ice_vsi *
3175 ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3177 return ice_vsi_setup(pf, pi, ICE_VSI_PF, ICE_INVAL_VFID);
3181 * ice_ctrl_vsi_setup - Set up a control VSI
3182 * @pf: board private structure
3183 * @pi: pointer to the port_info instance
3185 * Returns pointer to the successfully allocated VSI software struct
3186 * on success, otherwise returns NULL on failure.
3188 static struct ice_vsi *
3189 ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3191 return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, ICE_INVAL_VFID);
3195 * ice_lb_vsi_setup - Set up a loopback VSI
3196 * @pf: board private structure
3197 * @pi: pointer to the port_info instance
3199 * Returns pointer to the successfully allocated VSI software struct
3200 * on success, otherwise returns NULL on failure.
3203 ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
3205 return ice_vsi_setup(pf, pi, ICE_VSI_LB, ICE_INVAL_VFID);
3209 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
3210 * @netdev: network interface to be adjusted
3211 * @proto: unused protocol
3212 * @vid: VLAN ID to be added
3214 * net_device_ops implementation for adding VLAN IDs
3217 ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
3220 struct ice_netdev_priv *np = netdev_priv(netdev);
3221 struct ice_vsi *vsi = np->vsi;
3224 /* VLAN 0 is added by default during load/reset */
3228 /* Enable VLAN pruning when a VLAN other than 0 is added */
3229 if (!ice_vsi_is_vlan_pruning_ena(vsi)) {
3230 ret = ice_cfg_vlan_pruning(vsi, true, false);
3235 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
3236 * packets aren't pruned by the device's internal switch on Rx
3238 ret = ice_vsi_add_vlan(vsi, vid, ICE_FWD_TO_VSI);
3240 set_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
3246 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
3247 * @netdev: network interface to be adjusted
3248 * @proto: unused protocol
3249 * @vid: VLAN ID to be removed
3251 * net_device_ops implementation for removing VLAN IDs
3254 ice_vlan_rx_kill_vid(struct net_device *netdev, __always_unused __be16 proto,
3257 struct ice_netdev_priv *np = netdev_priv(netdev);
3258 struct ice_vsi *vsi = np->vsi;
3261 /* don't allow removal of VLAN 0 */
3265 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
3268 ret = ice_vsi_kill_vlan(vsi, vid);
3272 /* Disable pruning when VLAN 0 is the only VLAN rule */
3273 if (vsi->num_vlan == 1 && ice_vsi_is_vlan_pruning_ena(vsi))
3274 ret = ice_cfg_vlan_pruning(vsi, false, false);
3276 set_bit(ICE_VSI_VLAN_FLTR_CHANGED, vsi->state);
3281 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
3282 * @pf: board private structure
3284 * Returns 0 on success, negative value on failure
3286 static int ice_setup_pf_sw(struct ice_pf *pf)
3288 struct ice_vsi *vsi;
3291 if (ice_is_reset_in_progress(pf->state))
3294 vsi = ice_pf_vsi_setup(pf, pf->hw.port_info);
3298 status = ice_cfg_netdev(vsi);
3301 goto unroll_vsi_setup;
3303 /* netdev has to be configured before setting frame size */
3304 ice_vsi_cfg_frame_size(vsi);
3306 /* Setup DCB netlink interface */
3307 ice_dcbnl_setup(vsi);
3309 /* registering the NAPI handler requires both the queues and
3310 * netdev to be created, which are done in ice_pf_vsi_setup()
3311 * and ice_cfg_netdev() respectively
3315 status = ice_set_cpu_rx_rmap(vsi);
3317 dev_err(ice_pf_to_dev(pf), "Failed to set CPU Rx map VSI %d error %d\n",
3318 vsi->vsi_num, status);
3320 goto unroll_napi_add;
3322 status = ice_init_mac_fltr(pf);
3324 goto free_cpu_rx_map;
3329 ice_free_cpu_rx_rmap(vsi);
3335 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
3336 free_netdev(vsi->netdev);
3342 ice_vsi_release(vsi);
3347 * ice_get_avail_q_count - Get count of queues in use
3348 * @pf_qmap: bitmap to get queue use count from
3349 * @lock: pointer to a mutex that protects access to pf_qmap
3350 * @size: size of the bitmap
3353 ice_get_avail_q_count(unsigned long *pf_qmap, struct mutex *lock, u16 size)
3359 for_each_clear_bit(bit, pf_qmap, size)
3367 * ice_get_avail_txq_count - Get count of Tx queues in use
3368 * @pf: pointer to an ice_pf instance
3370 u16 ice_get_avail_txq_count(struct ice_pf *pf)
3372 return ice_get_avail_q_count(pf->avail_txqs, &pf->avail_q_mutex,
3377 * ice_get_avail_rxq_count - Get count of Rx queues in use
3378 * @pf: pointer to an ice_pf instance
3380 u16 ice_get_avail_rxq_count(struct ice_pf *pf)
3382 return ice_get_avail_q_count(pf->avail_rxqs, &pf->avail_q_mutex,
3387 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
3388 * @pf: board private structure to initialize
3390 static void ice_deinit_pf(struct ice_pf *pf)
3392 ice_service_task_stop(pf);
3393 mutex_destroy(&pf->sw_mutex);
3394 mutex_destroy(&pf->tc_mutex);
3395 mutex_destroy(&pf->avail_q_mutex);
3397 if (pf->avail_txqs) {
3398 bitmap_free(pf->avail_txqs);
3399 pf->avail_txqs = NULL;
3402 if (pf->avail_rxqs) {
3403 bitmap_free(pf->avail_rxqs);
3404 pf->avail_rxqs = NULL;
3408 ptp_clock_unregister(pf->ptp.clock);
3412 * ice_set_pf_caps - set PFs capability flags
3413 * @pf: pointer to the PF instance
3415 static void ice_set_pf_caps(struct ice_pf *pf)
3417 struct ice_hw_func_caps *func_caps = &pf->hw.func_caps;
3419 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3420 clear_bit(ICE_FLAG_AUX_ENA, pf->flags);
3421 if (func_caps->common_cap.rdma) {
3422 set_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3423 set_bit(ICE_FLAG_AUX_ENA, pf->flags);
3425 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3426 if (func_caps->common_cap.dcb)
3427 set_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
3428 clear_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3429 if (func_caps->common_cap.sr_iov_1_1) {
3430 set_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags);
3431 pf->num_vfs_supported = min_t(int, func_caps->num_allocd_vfs,
3434 clear_bit(ICE_FLAG_RSS_ENA, pf->flags);
3435 if (func_caps->common_cap.rss_table_size)
3436 set_bit(ICE_FLAG_RSS_ENA, pf->flags);
3438 clear_bit(ICE_FLAG_FD_ENA, pf->flags);
3439 if (func_caps->fd_fltr_guar > 0 || func_caps->fd_fltr_best_effort > 0) {
3442 /* ctrl_vsi_idx will be set to a valid value when flow director
3443 * is setup by ice_init_fdir
3445 pf->ctrl_vsi_idx = ICE_NO_VSI;
3446 set_bit(ICE_FLAG_FD_ENA, pf->flags);
3447 /* force guaranteed filter pool for PF */
3448 ice_alloc_fd_guar_item(&pf->hw, &unused,
3449 func_caps->fd_fltr_guar);
3450 /* force shared filter pool for PF */
3451 ice_alloc_fd_shrd_item(&pf->hw, &unused,
3452 func_caps->fd_fltr_best_effort);
3455 clear_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3456 if (func_caps->common_cap.ieee_1588)
3457 set_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags);
3459 pf->max_pf_txqs = func_caps->common_cap.num_txq;
3460 pf->max_pf_rxqs = func_caps->common_cap.num_rxq;
3464 * ice_init_pf - Initialize general software structures (struct ice_pf)
3465 * @pf: board private structure to initialize
3467 static int ice_init_pf(struct ice_pf *pf)
3469 ice_set_pf_caps(pf);
3471 mutex_init(&pf->sw_mutex);
3472 mutex_init(&pf->tc_mutex);
3474 INIT_HLIST_HEAD(&pf->aq_wait_list);
3475 spin_lock_init(&pf->aq_wait_lock);
3476 init_waitqueue_head(&pf->aq_wait_queue);
3478 init_waitqueue_head(&pf->reset_wait_queue);
3480 /* setup service timer and periodic service task */
3481 timer_setup(&pf->serv_tmr, ice_service_timer, 0);
3482 pf->serv_tmr_period = HZ;
3483 INIT_WORK(&pf->serv_task, ice_service_task);
3484 clear_bit(ICE_SERVICE_SCHED, pf->state);
3486 mutex_init(&pf->avail_q_mutex);
3487 pf->avail_txqs = bitmap_zalloc(pf->max_pf_txqs, GFP_KERNEL);
3488 if (!pf->avail_txqs)
3491 pf->avail_rxqs = bitmap_zalloc(pf->max_pf_rxqs, GFP_KERNEL);
3492 if (!pf->avail_rxqs) {
3493 devm_kfree(ice_pf_to_dev(pf), pf->avail_txqs);
3494 pf->avail_txqs = NULL;
3502 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
3503 * @pf: board private structure
3505 * compute the number of MSIX vectors required (v_budget) and request from
3506 * the OS. Return the number of vectors reserved or negative on failure
3508 static int ice_ena_msix_range(struct ice_pf *pf)
3510 int num_cpus, v_left, v_actual, v_other, v_budget = 0;
3511 struct device *dev = ice_pf_to_dev(pf);
3514 v_left = pf->hw.func_caps.common_cap.num_msix_vectors;
3515 num_cpus = num_online_cpus();
3517 /* reserve for LAN miscellaneous handler */
3518 needed = ICE_MIN_LAN_OICR_MSIX;
3519 if (v_left < needed)
3520 goto no_hw_vecs_left_err;
3524 /* reserve for flow director */
3525 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
3526 needed = ICE_FDIR_MSIX;
3527 if (v_left < needed)
3528 goto no_hw_vecs_left_err;
3533 /* total used for non-traffic vectors */
3536 /* reserve vectors for LAN traffic */
3538 if (v_left < needed)
3539 goto no_hw_vecs_left_err;
3540 pf->num_lan_msix = needed;
3544 /* reserve vectors for RDMA auxiliary driver */
3545 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags)) {
3546 needed = num_cpus + ICE_RDMA_NUM_AEQ_MSIX;
3547 if (v_left < needed)
3548 goto no_hw_vecs_left_err;
3549 pf->num_rdma_msix = needed;
3554 pf->msix_entries = devm_kcalloc(dev, v_budget,
3555 sizeof(*pf->msix_entries), GFP_KERNEL);
3556 if (!pf->msix_entries) {
3561 for (i = 0; i < v_budget; i++)
3562 pf->msix_entries[i].entry = i;
3564 /* actually reserve the vectors */
3565 v_actual = pci_enable_msix_range(pf->pdev, pf->msix_entries,
3566 ICE_MIN_MSIX, v_budget);
3568 dev_err(dev, "unable to reserve MSI-X vectors\n");
3573 if (v_actual < v_budget) {
3574 dev_warn(dev, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
3575 v_budget, v_actual);
3577 if (v_actual < ICE_MIN_MSIX) {
3578 /* error if we can't get minimum vectors */
3579 pci_disable_msix(pf->pdev);
3583 int v_remain = v_actual - v_other;
3584 int v_rdma = 0, v_min_rdma = 0;
3586 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags)) {
3587 /* Need at least 1 interrupt in addition to
3590 v_rdma = ICE_RDMA_NUM_AEQ_MSIX + 1;
3591 v_min_rdma = ICE_MIN_RDMA_MSIX;
3594 if (v_actual == ICE_MIN_MSIX ||
3595 v_remain < ICE_MIN_LAN_TXRX_MSIX + v_min_rdma) {
3596 dev_warn(dev, "Not enough MSI-X vectors to support RDMA.\n");
3597 clear_bit(ICE_FLAG_RDMA_ENA, pf->flags);
3599 pf->num_rdma_msix = 0;
3600 pf->num_lan_msix = ICE_MIN_LAN_TXRX_MSIX;
3601 } else if ((v_remain < ICE_MIN_LAN_TXRX_MSIX + v_rdma) ||
3602 (v_remain - v_rdma < v_rdma)) {
3603 /* Support minimum RDMA and give remaining
3604 * vectors to LAN MSIX
3606 pf->num_rdma_msix = v_min_rdma;
3607 pf->num_lan_msix = v_remain - v_min_rdma;
3609 /* Split remaining MSIX with RDMA after
3610 * accounting for AEQ MSIX
3612 pf->num_rdma_msix = (v_remain - ICE_RDMA_NUM_AEQ_MSIX) / 2 +
3613 ICE_RDMA_NUM_AEQ_MSIX;
3614 pf->num_lan_msix = v_remain - pf->num_rdma_msix;
3617 dev_notice(dev, "Enabled %d MSI-X vectors for LAN traffic.\n",
3620 if (test_bit(ICE_FLAG_RDMA_ENA, pf->flags))
3621 dev_notice(dev, "Enabled %d MSI-X vectors for RDMA.\n",
3629 devm_kfree(dev, pf->msix_entries);
3632 no_hw_vecs_left_err:
3633 dev_err(dev, "not enough device MSI-X vectors. requested = %d, available = %d\n",
3637 pf->num_rdma_msix = 0;
3638 pf->num_lan_msix = 0;
3643 * ice_dis_msix - Disable MSI-X interrupt setup in OS
3644 * @pf: board private structure
3646 static void ice_dis_msix(struct ice_pf *pf)
3648 pci_disable_msix(pf->pdev);
3649 devm_kfree(ice_pf_to_dev(pf), pf->msix_entries);
3650 pf->msix_entries = NULL;
3654 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
3655 * @pf: board private structure
3657 static void ice_clear_interrupt_scheme(struct ice_pf *pf)
3661 if (pf->irq_tracker) {
3662 devm_kfree(ice_pf_to_dev(pf), pf->irq_tracker);
3663 pf->irq_tracker = NULL;
3668 * ice_init_interrupt_scheme - Determine proper interrupt scheme
3669 * @pf: board private structure to initialize
3671 static int ice_init_interrupt_scheme(struct ice_pf *pf)
3675 vectors = ice_ena_msix_range(pf);
3680 /* set up vector assignment tracking */
3681 pf->irq_tracker = devm_kzalloc(ice_pf_to_dev(pf),
3682 struct_size(pf->irq_tracker, list, vectors),
3684 if (!pf->irq_tracker) {
3689 /* populate SW interrupts pool with number of OS granted IRQs. */
3690 pf->num_avail_sw_msix = (u16)vectors;
3691 pf->irq_tracker->num_entries = (u16)vectors;
3692 pf->irq_tracker->end = pf->irq_tracker->num_entries;
3698 * ice_is_wol_supported - check if WoL is supported
3699 * @hw: pointer to hardware info
3701 * Check if WoL is supported based on the HW configuration.
3702 * Returns true if NVM supports and enables WoL for this port, false otherwise
3704 bool ice_is_wol_supported(struct ice_hw *hw)
3708 /* A bit set to 1 in the NVM Software Reserved Word 2 (WoL control
3709 * word) indicates WoL is not supported on the corresponding PF ID.
3711 if (ice_read_sr_word(hw, ICE_SR_NVM_WOL_CFG, &wol_ctrl))
3714 return !(BIT(hw->port_info->lport) & wol_ctrl);
3718 * ice_vsi_recfg_qs - Change the number of queues on a VSI
3719 * @vsi: VSI being changed
3720 * @new_rx: new number of Rx queues
3721 * @new_tx: new number of Tx queues
3723 * Only change the number of queues if new_tx, or new_rx is non-0.
3725 * Returns 0 on success.
3727 int ice_vsi_recfg_qs(struct ice_vsi *vsi, int new_rx, int new_tx)
3729 struct ice_pf *pf = vsi->back;
3730 int err = 0, timeout = 50;
3732 if (!new_rx && !new_tx)
3735 while (test_and_set_bit(ICE_CFG_BUSY, pf->state)) {
3739 usleep_range(1000, 2000);
3743 vsi->req_txq = (u16)new_tx;
3745 vsi->req_rxq = (u16)new_rx;
3747 /* set for the next time the netdev is started */
3748 if (!netif_running(vsi->netdev)) {
3749 ice_vsi_rebuild(vsi, false);
3750 dev_dbg(ice_pf_to_dev(pf), "Link is down, queue count change happens when link is brought up\n");
3755 ice_vsi_rebuild(vsi, false);
3756 ice_pf_dcb_recfg(pf);
3759 clear_bit(ICE_CFG_BUSY, pf->state);
3764 * ice_set_safe_mode_vlan_cfg - configure PF VSI to allow all VLANs in safe mode
3765 * @pf: PF to configure
3767 * No VLAN offloads/filtering are advertised in safe mode so make sure the PF
3768 * VSI can still Tx/Rx VLAN tagged packets.
3770 static void ice_set_safe_mode_vlan_cfg(struct ice_pf *pf)
3772 struct ice_vsi *vsi = ice_get_main_vsi(pf);
3773 struct ice_vsi_ctx *ctxt;
3774 enum ice_status status;
3780 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
3785 ctxt->info = vsi->info;
3787 ctxt->info.valid_sections =
3788 cpu_to_le16(ICE_AQ_VSI_PROP_VLAN_VALID |
3789 ICE_AQ_VSI_PROP_SECURITY_VALID |
3790 ICE_AQ_VSI_PROP_SW_VALID);
3792 /* disable VLAN anti-spoof */
3793 ctxt->info.sec_flags &= ~(ICE_AQ_VSI_SEC_TX_VLAN_PRUNE_ENA <<
3794 ICE_AQ_VSI_SEC_TX_PRUNE_ENA_S);
3796 /* disable VLAN pruning and keep all other settings */
3797 ctxt->info.sw_flags2 &= ~ICE_AQ_VSI_SW_FLAG_RX_VLAN_PRUNE_ENA;
3799 /* allow all VLANs on Tx and don't strip on Rx */
3800 ctxt->info.vlan_flags = ICE_AQ_VSI_VLAN_MODE_ALL |
3801 ICE_AQ_VSI_VLAN_EMOD_NOTHING;
3803 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
3805 dev_err(ice_pf_to_dev(vsi->back), "Failed to update VSI for safe mode VLANs, err %s aq_err %s\n",
3806 ice_stat_str(status),
3807 ice_aq_str(hw->adminq.sq_last_status));
3809 vsi->info.sec_flags = ctxt->info.sec_flags;
3810 vsi->info.sw_flags2 = ctxt->info.sw_flags2;
3811 vsi->info.vlan_flags = ctxt->info.vlan_flags;
3818 * ice_log_pkg_init - log result of DDP package load
3819 * @hw: pointer to hardware info
3820 * @status: status of package load
3823 ice_log_pkg_init(struct ice_hw *hw, enum ice_status *status)
3825 struct ice_pf *pf = (struct ice_pf *)hw->back;
3826 struct device *dev = ice_pf_to_dev(pf);
3830 /* The package download AdminQ command returned success because
3831 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
3832 * already a package loaded on the device.
3834 if (hw->pkg_ver.major == hw->active_pkg_ver.major &&
3835 hw->pkg_ver.minor == hw->active_pkg_ver.minor &&
3836 hw->pkg_ver.update == hw->active_pkg_ver.update &&
3837 hw->pkg_ver.draft == hw->active_pkg_ver.draft &&
3838 !memcmp(hw->pkg_name, hw->active_pkg_name,
3839 sizeof(hw->pkg_name))) {
3840 if (hw->pkg_dwnld_status == ICE_AQ_RC_EEXIST)
3841 dev_info(dev, "DDP package already present on device: %s version %d.%d.%d.%d\n",
3842 hw->active_pkg_name,
3843 hw->active_pkg_ver.major,
3844 hw->active_pkg_ver.minor,
3845 hw->active_pkg_ver.update,
3846 hw->active_pkg_ver.draft);
3848 dev_info(dev, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
3849 hw->active_pkg_name,
3850 hw->active_pkg_ver.major,
3851 hw->active_pkg_ver.minor,
3852 hw->active_pkg_ver.update,
3853 hw->active_pkg_ver.draft);
3854 } else if (hw->active_pkg_ver.major != ICE_PKG_SUPP_VER_MAJ ||
3855 hw->active_pkg_ver.minor != ICE_PKG_SUPP_VER_MNR) {
3856 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",
3857 hw->active_pkg_name,
3858 hw->active_pkg_ver.major,
3859 hw->active_pkg_ver.minor,
3860 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
3861 *status = ICE_ERR_NOT_SUPPORTED;
3862 } else if (hw->active_pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3863 hw->active_pkg_ver.minor == ICE_PKG_SUPP_VER_MNR) {
3864 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",
3865 hw->active_pkg_name,
3866 hw->active_pkg_ver.major,
3867 hw->active_pkg_ver.minor,
3868 hw->active_pkg_ver.update,
3869 hw->active_pkg_ver.draft,
3876 dev_err(dev, "An unknown error occurred when loading the DDP package, please reboot the system. If the problem persists, update the NVM. Entering Safe Mode.\n");
3877 *status = ICE_ERR_NOT_SUPPORTED;
3880 case ICE_ERR_FW_DDP_MISMATCH:
3881 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");
3883 case ICE_ERR_BUF_TOO_SHORT:
3885 dev_err(dev, "The DDP package file is invalid. Entering Safe Mode.\n");
3887 case ICE_ERR_NOT_SUPPORTED:
3888 /* Package File version not supported */
3889 if (hw->pkg_ver.major > ICE_PKG_SUPP_VER_MAJ ||
3890 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3891 hw->pkg_ver.minor > ICE_PKG_SUPP_VER_MNR))
3892 dev_err(dev, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
3893 else if (hw->pkg_ver.major < ICE_PKG_SUPP_VER_MAJ ||
3894 (hw->pkg_ver.major == ICE_PKG_SUPP_VER_MAJ &&
3895 hw->pkg_ver.minor < ICE_PKG_SUPP_VER_MNR))
3896 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",
3897 ICE_PKG_SUPP_VER_MAJ, ICE_PKG_SUPP_VER_MNR);
3899 case ICE_ERR_AQ_ERROR:
3900 switch (hw->pkg_dwnld_status) {
3901 case ICE_AQ_RC_ENOSEC:
3902 case ICE_AQ_RC_EBADSIG:
3903 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");
3905 case ICE_AQ_RC_ESVN:
3906 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");
3908 case ICE_AQ_RC_EBADMAN:
3909 case ICE_AQ_RC_EBADBUF:
3910 dev_err(dev, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
3911 /* poll for reset to complete */
3912 if (ice_check_reset(hw))
3913 dev_err(dev, "Error resetting device. Please reload the driver\n");
3920 dev_err(dev, "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n",
3927 * ice_load_pkg - load/reload the DDP Package file
3928 * @firmware: firmware structure when firmware requested or NULL for reload
3929 * @pf: pointer to the PF instance
3931 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
3932 * initialize HW tables.
3935 ice_load_pkg(const struct firmware *firmware, struct ice_pf *pf)
3937 enum ice_status status = ICE_ERR_PARAM;
3938 struct device *dev = ice_pf_to_dev(pf);
3939 struct ice_hw *hw = &pf->hw;
3941 /* Load DDP Package */
3942 if (firmware && !hw->pkg_copy) {
3943 status = ice_copy_and_init_pkg(hw, firmware->data,
3945 ice_log_pkg_init(hw, &status);
3946 } else if (!firmware && hw->pkg_copy) {
3947 /* Reload package during rebuild after CORER/GLOBR reset */
3948 status = ice_init_pkg(hw, hw->pkg_copy, hw->pkg_size);
3949 ice_log_pkg_init(hw, &status);
3951 dev_err(dev, "The DDP package file failed to load. Entering Safe Mode.\n");
3956 clear_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3960 /* Successful download package is the precondition for advanced
3961 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
3963 set_bit(ICE_FLAG_ADV_FEATURES, pf->flags);
3967 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
3968 * @pf: pointer to the PF structure
3970 * There is no error returned here because the driver should be able to handle
3971 * 128 Byte cache lines, so we only print a warning in case issues are seen,
3972 * specifically with Tx.
3974 static void ice_verify_cacheline_size(struct ice_pf *pf)
3976 if (rd32(&pf->hw, GLPCI_CNF2) & GLPCI_CNF2_CACHELINE_SIZE_M)
3977 dev_warn(ice_pf_to_dev(pf), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
3978 ICE_CACHE_LINE_BYTES);
3982 * ice_send_version - update firmware with driver version
3985 * Returns ICE_SUCCESS on success, else error code
3987 static enum ice_status ice_send_version(struct ice_pf *pf)
3989 struct ice_driver_ver dv;
3991 dv.major_ver = 0xff;
3992 dv.minor_ver = 0xff;
3993 dv.build_ver = 0xff;
3994 dv.subbuild_ver = 0;
3995 strscpy((char *)dv.driver_string, UTS_RELEASE,
3996 sizeof(dv.driver_string));
3997 return ice_aq_send_driver_ver(&pf->hw, &dv, NULL);
4001 * ice_init_fdir - Initialize flow director VSI and configuration
4002 * @pf: pointer to the PF instance
4004 * returns 0 on success, negative on error
4006 static int ice_init_fdir(struct ice_pf *pf)
4008 struct device *dev = ice_pf_to_dev(pf);
4009 struct ice_vsi *ctrl_vsi;
4012 /* Side Band Flow Director needs to have a control VSI.
4013 * Allocate it and store it in the PF.
4015 ctrl_vsi = ice_ctrl_vsi_setup(pf, pf->hw.port_info);
4017 dev_dbg(dev, "could not create control VSI\n");
4021 err = ice_vsi_open_ctrl(ctrl_vsi);
4023 dev_dbg(dev, "could not open control VSI\n");
4027 mutex_init(&pf->hw.fdir_fltr_lock);
4029 err = ice_fdir_create_dflt_rules(pf);
4036 ice_fdir_release_flows(&pf->hw);
4037 ice_vsi_close(ctrl_vsi);
4039 ice_vsi_release(ctrl_vsi);
4040 if (pf->ctrl_vsi_idx != ICE_NO_VSI) {
4041 pf->vsi[pf->ctrl_vsi_idx] = NULL;
4042 pf->ctrl_vsi_idx = ICE_NO_VSI;
4048 * ice_get_opt_fw_name - return optional firmware file name or NULL
4049 * @pf: pointer to the PF instance
4051 static char *ice_get_opt_fw_name(struct ice_pf *pf)
4053 /* Optional firmware name same as default with additional dash
4054 * followed by a EUI-64 identifier (PCIe Device Serial Number)
4056 struct pci_dev *pdev = pf->pdev;
4057 char *opt_fw_filename;
4060 /* Determine the name of the optional file using the DSN (two
4061 * dwords following the start of the DSN Capability).
4063 dsn = pci_get_dsn(pdev);
4067 opt_fw_filename = kzalloc(NAME_MAX, GFP_KERNEL);
4068 if (!opt_fw_filename)
4071 snprintf(opt_fw_filename, NAME_MAX, "%sice-%016llx.pkg",
4072 ICE_DDP_PKG_PATH, dsn);
4074 return opt_fw_filename;
4078 * ice_request_fw - Device initialization routine
4079 * @pf: pointer to the PF instance
4081 static void ice_request_fw(struct ice_pf *pf)
4083 char *opt_fw_filename = ice_get_opt_fw_name(pf);
4084 const struct firmware *firmware = NULL;
4085 struct device *dev = ice_pf_to_dev(pf);
4088 /* optional device-specific DDP (if present) overrides the default DDP
4089 * package file. kernel logs a debug message if the file doesn't exist,
4090 * and warning messages for other errors.
4092 if (opt_fw_filename) {
4093 err = firmware_request_nowarn(&firmware, opt_fw_filename, dev);
4095 kfree(opt_fw_filename);
4099 /* request for firmware was successful. Download to device */
4100 ice_load_pkg(firmware, pf);
4101 kfree(opt_fw_filename);
4102 release_firmware(firmware);
4107 err = request_firmware(&firmware, ICE_DDP_PKG_FILE, dev);
4109 dev_err(dev, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
4113 /* request for firmware was successful. Download to device */
4114 ice_load_pkg(firmware, pf);
4115 release_firmware(firmware);
4119 * ice_print_wake_reason - show the wake up cause in the log
4120 * @pf: pointer to the PF struct
4122 static void ice_print_wake_reason(struct ice_pf *pf)
4124 u32 wus = pf->wakeup_reason;
4125 const char *wake_str;
4127 /* if no wake event, nothing to print */
4131 if (wus & PFPM_WUS_LNKC_M)
4132 wake_str = "Link\n";
4133 else if (wus & PFPM_WUS_MAG_M)
4134 wake_str = "Magic Packet\n";
4135 else if (wus & PFPM_WUS_MNG_M)
4136 wake_str = "Management\n";
4137 else if (wus & PFPM_WUS_FW_RST_WK_M)
4138 wake_str = "Firmware Reset\n";
4140 wake_str = "Unknown\n";
4142 dev_info(ice_pf_to_dev(pf), "Wake reason: %s", wake_str);
4146 * ice_register_netdev - register netdev and devlink port
4147 * @pf: pointer to the PF struct
4149 static int ice_register_netdev(struct ice_pf *pf)
4151 struct ice_vsi *vsi;
4154 vsi = ice_get_main_vsi(pf);
4155 if (!vsi || !vsi->netdev)
4158 err = register_netdev(vsi->netdev);
4160 goto err_register_netdev;
4162 set_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4163 netif_carrier_off(vsi->netdev);
4164 netif_tx_stop_all_queues(vsi->netdev);
4165 err = ice_devlink_create_port(vsi);
4167 goto err_devlink_create;
4169 devlink_port_type_eth_set(&vsi->devlink_port, vsi->netdev);
4173 unregister_netdev(vsi->netdev);
4174 clear_bit(ICE_VSI_NETDEV_REGISTERED, vsi->state);
4175 err_register_netdev:
4176 free_netdev(vsi->netdev);
4178 clear_bit(ICE_VSI_NETDEV_ALLOCD, vsi->state);
4183 * ice_probe - Device initialization routine
4184 * @pdev: PCI device information struct
4185 * @ent: entry in ice_pci_tbl
4187 * Returns 0 on success, negative on failure
4190 ice_probe(struct pci_dev *pdev, const struct pci_device_id __always_unused *ent)
4192 struct device *dev = &pdev->dev;
4197 /* this driver uses devres, see
4198 * Documentation/driver-api/driver-model/devres.rst
4200 err = pcim_enable_device(pdev);
4204 err = pcim_iomap_regions(pdev, BIT(ICE_BAR0), dev_driver_string(dev));
4206 dev_err(dev, "BAR0 I/O map error %d\n", err);
4210 pf = ice_allocate_pf(dev);
4214 /* set up for high or low DMA */
4215 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
4217 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
4219 dev_err(dev, "DMA configuration failed: 0x%x\n", err);
4223 pci_enable_pcie_error_reporting(pdev);
4224 pci_set_master(pdev);
4227 pci_set_drvdata(pdev, pf);
4228 set_bit(ICE_DOWN, pf->state);
4229 /* Disable service task until DOWN bit is cleared */
4230 set_bit(ICE_SERVICE_DIS, pf->state);
4233 hw->hw_addr = pcim_iomap_table(pdev)[ICE_BAR0];
4234 pci_save_state(pdev);
4237 hw->vendor_id = pdev->vendor;
4238 hw->device_id = pdev->device;
4239 pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
4240 hw->subsystem_vendor_id = pdev->subsystem_vendor;
4241 hw->subsystem_device_id = pdev->subsystem_device;
4242 hw->bus.device = PCI_SLOT(pdev->devfn);
4243 hw->bus.func = PCI_FUNC(pdev->devfn);
4244 ice_set_ctrlq_len(hw);
4246 pf->msg_enable = netif_msg_init(debug, ICE_DFLT_NETIF_M);
4248 err = ice_devlink_register(pf);
4250 dev_err(dev, "ice_devlink_register failed: %d\n", err);
4251 goto err_exit_unroll;
4254 #ifndef CONFIG_DYNAMIC_DEBUG
4256 hw->debug_mask = debug;
4259 err = ice_init_hw(hw);
4261 dev_err(dev, "ice_init_hw failed: %d\n", err);
4263 goto err_exit_unroll;
4268 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
4269 * set in pf->state, which will cause ice_is_safe_mode to return
4272 if (ice_is_safe_mode(pf)) {
4273 dev_err(dev, "Package download failed. Advanced features disabled - Device now in Safe Mode\n");
4274 /* we already got function/device capabilities but these don't
4275 * reflect what the driver needs to do in safe mode. Instead of
4276 * adding conditional logic everywhere to ignore these
4277 * device/function capabilities, override them.
4279 ice_set_safe_mode_caps(hw);
4282 err = ice_init_pf(pf);
4284 dev_err(dev, "ice_init_pf failed: %d\n", err);
4285 goto err_init_pf_unroll;
4288 ice_devlink_init_regions(pf);
4290 pf->hw.udp_tunnel_nic.set_port = ice_udp_tunnel_set_port;
4291 pf->hw.udp_tunnel_nic.unset_port = ice_udp_tunnel_unset_port;
4292 pf->hw.udp_tunnel_nic.flags = UDP_TUNNEL_NIC_INFO_MAY_SLEEP;
4293 pf->hw.udp_tunnel_nic.shared = &pf->hw.udp_tunnel_shared;
4295 if (pf->hw.tnl.valid_count[TNL_VXLAN]) {
4296 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4297 pf->hw.tnl.valid_count[TNL_VXLAN];
4298 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4299 UDP_TUNNEL_TYPE_VXLAN;
4302 if (pf->hw.tnl.valid_count[TNL_GENEVE]) {
4303 pf->hw.udp_tunnel_nic.tables[i].n_entries =
4304 pf->hw.tnl.valid_count[TNL_GENEVE];
4305 pf->hw.udp_tunnel_nic.tables[i].tunnel_types =
4306 UDP_TUNNEL_TYPE_GENEVE;
4310 pf->num_alloc_vsi = hw->func_caps.guar_num_vsi;
4311 if (!pf->num_alloc_vsi) {
4313 goto err_init_pf_unroll;
4315 if (pf->num_alloc_vsi > UDP_TUNNEL_NIC_MAX_SHARING_DEVICES) {
4316 dev_warn(&pf->pdev->dev,
4317 "limiting the VSI count due to UDP tunnel limitation %d > %d\n",
4318 pf->num_alloc_vsi, UDP_TUNNEL_NIC_MAX_SHARING_DEVICES);
4319 pf->num_alloc_vsi = UDP_TUNNEL_NIC_MAX_SHARING_DEVICES;
4322 pf->vsi = devm_kcalloc(dev, pf->num_alloc_vsi, sizeof(*pf->vsi),
4326 goto err_init_pf_unroll;
4329 err = ice_init_interrupt_scheme(pf);
4331 dev_err(dev, "ice_init_interrupt_scheme failed: %d\n", err);
4333 goto err_init_vsi_unroll;
4336 /* In case of MSIX we are going to setup the misc vector right here
4337 * to handle admin queue events etc. In case of legacy and MSI
4338 * the misc functionality and queue processing is combined in
4339 * the same vector and that gets setup at open.
4341 err = ice_req_irq_msix_misc(pf);
4343 dev_err(dev, "setup of misc vector failed: %d\n", err);
4344 goto err_init_interrupt_unroll;
4347 /* create switch struct for the switch element created by FW on boot */
4348 pf->first_sw = devm_kzalloc(dev, sizeof(*pf->first_sw), GFP_KERNEL);
4349 if (!pf->first_sw) {
4351 goto err_msix_misc_unroll;
4355 pf->first_sw->bridge_mode = BRIDGE_MODE_VEB;
4357 pf->first_sw->bridge_mode = BRIDGE_MODE_VEPA;
4359 pf->first_sw->pf = pf;
4361 /* record the sw_id available for later use */
4362 pf->first_sw->sw_id = hw->port_info->sw_id;
4364 err = ice_setup_pf_sw(pf);
4366 dev_err(dev, "probe failed due to setup PF switch: %d\n", err);
4367 goto err_alloc_sw_unroll;
4370 clear_bit(ICE_SERVICE_DIS, pf->state);
4372 /* tell the firmware we are up */
4373 err = ice_send_version(pf);
4375 dev_err(dev, "probe failed sending driver version %s. error: %d\n",
4377 goto err_send_version_unroll;
4380 /* since everything is good, start the service timer */
4381 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4383 err = ice_init_link_events(pf->hw.port_info);
4385 dev_err(dev, "ice_init_link_events failed: %d\n", err);
4386 goto err_send_version_unroll;
4389 /* not a fatal error if this fails */
4390 err = ice_init_nvm_phy_type(pf->hw.port_info);
4392 dev_err(dev, "ice_init_nvm_phy_type failed: %d\n", err);
4394 /* not a fatal error if this fails */
4395 err = ice_update_link_info(pf->hw.port_info);
4397 dev_err(dev, "ice_update_link_info failed: %d\n", err);
4399 ice_init_link_dflt_override(pf->hw.port_info);
4401 ice_check_module_power(pf, pf->hw.port_info->phy.link_info.link_cfg_err);
4403 /* if media available, initialize PHY settings */
4404 if (pf->hw.port_info->phy.link_info.link_info &
4405 ICE_AQ_MEDIA_AVAILABLE) {
4406 /* not a fatal error if this fails */
4407 err = ice_init_phy_user_cfg(pf->hw.port_info);
4409 dev_err(dev, "ice_init_phy_user_cfg failed: %d\n", err);
4411 if (!test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, pf->flags)) {
4412 struct ice_vsi *vsi = ice_get_main_vsi(pf);
4415 ice_configure_phy(vsi);
4418 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
4421 ice_verify_cacheline_size(pf);
4423 /* Save wakeup reason register for later use */
4424 pf->wakeup_reason = rd32(hw, PFPM_WUS);
4426 /* check for a power management event */
4427 ice_print_wake_reason(pf);
4429 /* clear wake status, all bits */
4430 wr32(hw, PFPM_WUS, U32_MAX);
4432 /* Disable WoL at init, wait for user to enable */
4433 device_set_wakeup_enable(dev, false);
4435 if (ice_is_safe_mode(pf)) {
4436 ice_set_safe_mode_vlan_cfg(pf);
4440 /* initialize DDP driven features */
4441 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4444 /* Note: Flow director init failure is non-fatal to load */
4445 if (ice_init_fdir(pf))
4446 dev_err(dev, "could not initialize flow director\n");
4448 /* Note: DCB init failure is non-fatal to load */
4449 if (ice_init_pf_dcb(pf, false)) {
4450 clear_bit(ICE_FLAG_DCB_CAPABLE, pf->flags);
4451 clear_bit(ICE_FLAG_DCB_ENA, pf->flags);
4453 ice_cfg_lldp_mib_change(&pf->hw, true);
4456 if (ice_init_lag(pf))
4457 dev_warn(dev, "Failed to init link aggregation support\n");
4459 /* print PCI link speed and width */
4460 pcie_print_link_status(pf->pdev);
4463 err = ice_register_netdev(pf);
4465 goto err_netdev_reg;
4467 /* ready to go, so clear down state bit */
4468 clear_bit(ICE_DOWN, pf->state);
4469 if (ice_is_aux_ena(pf)) {
4470 pf->aux_idx = ida_alloc(&ice_aux_ida, GFP_KERNEL);
4471 if (pf->aux_idx < 0) {
4472 dev_err(dev, "Failed to allocate device ID for AUX driver\n");
4474 goto err_netdev_reg;
4477 err = ice_init_rdma(pf);
4479 dev_err(dev, "Failed to initialize RDMA: %d\n", err);
4481 goto err_init_aux_unroll;
4484 dev_warn(dev, "RDMA is not supported on this device\n");
4489 err_init_aux_unroll:
4491 ida_free(&ice_aux_ida, pf->aux_idx);
4493 err_send_version_unroll:
4494 ice_vsi_release_all(pf);
4495 err_alloc_sw_unroll:
4496 set_bit(ICE_SERVICE_DIS, pf->state);
4497 set_bit(ICE_DOWN, pf->state);
4498 devm_kfree(dev, pf->first_sw);
4499 err_msix_misc_unroll:
4500 ice_free_irq_msix_misc(pf);
4501 err_init_interrupt_unroll:
4502 ice_clear_interrupt_scheme(pf);
4503 err_init_vsi_unroll:
4504 devm_kfree(dev, pf->vsi);
4507 ice_devlink_destroy_regions(pf);
4510 ice_devlink_unregister(pf);
4511 pci_disable_pcie_error_reporting(pdev);
4512 pci_disable_device(pdev);
4517 * ice_set_wake - enable or disable Wake on LAN
4518 * @pf: pointer to the PF struct
4520 * Simple helper for WoL control
4522 static void ice_set_wake(struct ice_pf *pf)
4524 struct ice_hw *hw = &pf->hw;
4525 bool wol = pf->wol_ena;
4527 /* clear wake state, otherwise new wake events won't fire */
4528 wr32(hw, PFPM_WUS, U32_MAX);
4530 /* enable / disable APM wake up, no RMW needed */
4531 wr32(hw, PFPM_APM, wol ? PFPM_APM_APME_M : 0);
4533 /* set magic packet filter enabled */
4534 wr32(hw, PFPM_WUFC, wol ? PFPM_WUFC_MAG_M : 0);
4538 * ice_setup_mc_magic_wake - setup device to wake on multicast magic packet
4539 * @pf: pointer to the PF struct
4541 * Issue firmware command to enable multicast magic wake, making
4542 * sure that any locally administered address (LAA) is used for
4543 * wake, and that PF reset doesn't undo the LAA.
4545 static void ice_setup_mc_magic_wake(struct ice_pf *pf)
4547 struct device *dev = ice_pf_to_dev(pf);
4548 struct ice_hw *hw = &pf->hw;
4549 enum ice_status status;
4550 u8 mac_addr[ETH_ALEN];
4551 struct ice_vsi *vsi;
4557 vsi = ice_get_main_vsi(pf);
4561 /* Get current MAC address in case it's an LAA */
4563 ether_addr_copy(mac_addr, vsi->netdev->dev_addr);
4565 ether_addr_copy(mac_addr, vsi->port_info->mac.perm_addr);
4567 flags = ICE_AQC_MAN_MAC_WR_MC_MAG_EN |
4568 ICE_AQC_MAN_MAC_UPDATE_LAA_WOL |
4569 ICE_AQC_MAN_MAC_WR_WOL_LAA_PFR_KEEP;
4571 status = ice_aq_manage_mac_write(hw, mac_addr, flags, NULL);
4573 dev_err(dev, "Failed to enable Multicast Magic Packet wake, err %s aq_err %s\n",
4574 ice_stat_str(status),
4575 ice_aq_str(hw->adminq.sq_last_status));
4579 * ice_remove - Device removal routine
4580 * @pdev: PCI device information struct
4582 static void ice_remove(struct pci_dev *pdev)
4584 struct ice_pf *pf = pci_get_drvdata(pdev);
4590 for (i = 0; i < ICE_MAX_RESET_WAIT; i++) {
4591 if (!ice_is_reset_in_progress(pf->state))
4596 if (test_bit(ICE_FLAG_SRIOV_ENA, pf->flags)) {
4597 set_bit(ICE_VF_RESETS_DISABLED, pf->state);
4601 ice_service_task_stop(pf);
4603 ice_aq_cancel_waiting_tasks(pf);
4604 ice_unplug_aux_dev(pf);
4605 ida_free(&ice_aux_ida, pf->aux_idx);
4606 set_bit(ICE_DOWN, pf->state);
4608 mutex_destroy(&(&pf->hw)->fdir_fltr_lock);
4610 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
4611 ice_ptp_release(pf);
4612 if (!ice_is_safe_mode(pf))
4613 ice_remove_arfs(pf);
4614 ice_setup_mc_magic_wake(pf);
4615 ice_vsi_release_all(pf);
4617 ice_free_irq_msix_misc(pf);
4618 ice_for_each_vsi(pf, i) {
4621 ice_vsi_free_q_vectors(pf->vsi[i]);
4624 ice_devlink_destroy_regions(pf);
4625 ice_deinit_hw(&pf->hw);
4626 ice_devlink_unregister(pf);
4628 /* Issue a PFR as part of the prescribed driver unload flow. Do not
4629 * do it via ice_schedule_reset() since there is no need to rebuild
4630 * and the service task is already stopped.
4632 ice_reset(&pf->hw, ICE_RESET_PFR);
4633 pci_wait_for_pending_transaction(pdev);
4634 ice_clear_interrupt_scheme(pf);
4635 pci_disable_pcie_error_reporting(pdev);
4636 pci_disable_device(pdev);
4640 * ice_shutdown - PCI callback for shutting down device
4641 * @pdev: PCI device information struct
4643 static void ice_shutdown(struct pci_dev *pdev)
4645 struct ice_pf *pf = pci_get_drvdata(pdev);
4649 if (system_state == SYSTEM_POWER_OFF) {
4650 pci_wake_from_d3(pdev, pf->wol_ena);
4651 pci_set_power_state(pdev, PCI_D3hot);
4657 * ice_prepare_for_shutdown - prep for PCI shutdown
4658 * @pf: board private structure
4660 * Inform or close all dependent features in prep for PCI device shutdown
4662 static void ice_prepare_for_shutdown(struct ice_pf *pf)
4664 struct ice_hw *hw = &pf->hw;
4667 /* Notify VFs of impending reset */
4668 if (ice_check_sq_alive(hw, &hw->mailboxq))
4669 ice_vc_notify_reset(pf);
4671 dev_dbg(ice_pf_to_dev(pf), "Tearing down internal switch for shutdown\n");
4673 /* disable the VSIs and their queues that are not already DOWN */
4674 ice_pf_dis_all_vsi(pf, false);
4676 ice_for_each_vsi(pf, v)
4678 pf->vsi[v]->vsi_num = 0;
4680 ice_shutdown_all_ctrlq(hw);
4684 * ice_reinit_interrupt_scheme - Reinitialize interrupt scheme
4685 * @pf: board private structure to reinitialize
4687 * This routine reinitialize interrupt scheme that was cleared during
4688 * power management suspend callback.
4690 * This should be called during resume routine to re-allocate the q_vectors
4691 * and reacquire interrupts.
4693 static int ice_reinit_interrupt_scheme(struct ice_pf *pf)
4695 struct device *dev = ice_pf_to_dev(pf);
4698 /* Since we clear MSIX flag during suspend, we need to
4699 * set it back during resume...
4702 ret = ice_init_interrupt_scheme(pf);
4704 dev_err(dev, "Failed to re-initialize interrupt %d\n", ret);
4708 /* Remap vectors and rings, after successful re-init interrupts */
4709 ice_for_each_vsi(pf, v) {
4713 ret = ice_vsi_alloc_q_vectors(pf->vsi[v]);
4716 ice_vsi_map_rings_to_vectors(pf->vsi[v]);
4719 ret = ice_req_irq_msix_misc(pf);
4721 dev_err(dev, "Setting up misc vector failed after device suspend %d\n",
4731 ice_vsi_free_q_vectors(pf->vsi[v]);
4738 * @dev: generic device information structure
4740 * Power Management callback to quiesce the device and prepare
4741 * for D3 transition.
4743 static int __maybe_unused ice_suspend(struct device *dev)
4745 struct pci_dev *pdev = to_pci_dev(dev);
4749 pf = pci_get_drvdata(pdev);
4751 if (!ice_pf_state_is_nominal(pf)) {
4752 dev_err(dev, "Device is not ready, no need to suspend it\n");
4756 /* Stop watchdog tasks until resume completion.
4757 * Even though it is most likely that the service task is
4758 * disabled if the device is suspended or down, the service task's
4759 * state is controlled by a different state bit, and we should
4760 * store and honor whatever state that bit is in at this point.
4762 disabled = ice_service_task_stop(pf);
4764 ice_unplug_aux_dev(pf);
4766 /* Already suspended?, then there is nothing to do */
4767 if (test_and_set_bit(ICE_SUSPENDED, pf->state)) {
4769 ice_service_task_restart(pf);
4773 if (test_bit(ICE_DOWN, pf->state) ||
4774 ice_is_reset_in_progress(pf->state)) {
4775 dev_err(dev, "can't suspend device in reset or already down\n");
4777 ice_service_task_restart(pf);
4781 ice_setup_mc_magic_wake(pf);
4783 ice_prepare_for_shutdown(pf);
4787 /* Free vectors, clear the interrupt scheme and release IRQs
4788 * for proper hibernation, especially with large number of CPUs.
4789 * Otherwise hibernation might fail when mapping all the vectors back
4792 ice_free_irq_msix_misc(pf);
4793 ice_for_each_vsi(pf, v) {
4796 ice_vsi_free_q_vectors(pf->vsi[v]);
4798 ice_free_cpu_rx_rmap(ice_get_main_vsi(pf));
4799 ice_clear_interrupt_scheme(pf);
4801 pci_save_state(pdev);
4802 pci_wake_from_d3(pdev, pf->wol_ena);
4803 pci_set_power_state(pdev, PCI_D3hot);
4808 * ice_resume - PM callback for waking up from D3
4809 * @dev: generic device information structure
4811 static int __maybe_unused ice_resume(struct device *dev)
4813 struct pci_dev *pdev = to_pci_dev(dev);
4814 enum ice_reset_req reset_type;
4819 pci_set_power_state(pdev, PCI_D0);
4820 pci_restore_state(pdev);
4821 pci_save_state(pdev);
4823 if (!pci_device_is_present(pdev))
4826 ret = pci_enable_device_mem(pdev);
4828 dev_err(dev, "Cannot enable device after suspend\n");
4832 pf = pci_get_drvdata(pdev);
4835 pf->wakeup_reason = rd32(hw, PFPM_WUS);
4836 ice_print_wake_reason(pf);
4838 /* We cleared the interrupt scheme when we suspended, so we need to
4839 * restore it now to resume device functionality.
4841 ret = ice_reinit_interrupt_scheme(pf);
4843 dev_err(dev, "Cannot restore interrupt scheme: %d\n", ret);
4845 clear_bit(ICE_DOWN, pf->state);
4846 /* Now perform PF reset and rebuild */
4847 reset_type = ICE_RESET_PFR;
4848 /* re-enable service task for reset, but allow reset to schedule it */
4849 clear_bit(ICE_SERVICE_DIS, pf->state);
4851 if (ice_schedule_reset(pf, reset_type))
4852 dev_err(dev, "Reset during resume failed.\n");
4854 clear_bit(ICE_SUSPENDED, pf->state);
4855 ice_service_task_restart(pf);
4857 /* Restart the service task */
4858 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4862 #endif /* CONFIG_PM */
4865 * ice_pci_err_detected - warning that PCI error has been detected
4866 * @pdev: PCI device information struct
4867 * @err: the type of PCI error
4869 * Called to warn that something happened on the PCI bus and the error handling
4870 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
4872 static pci_ers_result_t
4873 ice_pci_err_detected(struct pci_dev *pdev, pci_channel_state_t err)
4875 struct ice_pf *pf = pci_get_drvdata(pdev);
4878 dev_err(&pdev->dev, "%s: unrecoverable device error %d\n",
4880 return PCI_ERS_RESULT_DISCONNECT;
4883 if (!test_bit(ICE_SUSPENDED, pf->state)) {
4884 ice_service_task_stop(pf);
4886 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
4887 set_bit(ICE_PFR_REQ, pf->state);
4888 ice_prepare_for_reset(pf);
4892 return PCI_ERS_RESULT_NEED_RESET;
4896 * ice_pci_err_slot_reset - a PCI slot reset has just happened
4897 * @pdev: PCI device information struct
4899 * Called to determine if the driver can recover from the PCI slot reset by
4900 * using a register read to determine if the device is recoverable.
4902 static pci_ers_result_t ice_pci_err_slot_reset(struct pci_dev *pdev)
4904 struct ice_pf *pf = pci_get_drvdata(pdev);
4905 pci_ers_result_t result;
4909 err = pci_enable_device_mem(pdev);
4911 dev_err(&pdev->dev, "Cannot re-enable PCI device after reset, error %d\n",
4913 result = PCI_ERS_RESULT_DISCONNECT;
4915 pci_set_master(pdev);
4916 pci_restore_state(pdev);
4917 pci_save_state(pdev);
4918 pci_wake_from_d3(pdev, false);
4920 /* Check for life */
4921 reg = rd32(&pf->hw, GLGEN_RTRIG);
4923 result = PCI_ERS_RESULT_RECOVERED;
4925 result = PCI_ERS_RESULT_DISCONNECT;
4928 err = pci_aer_clear_nonfatal_status(pdev);
4930 dev_dbg(&pdev->dev, "pci_aer_clear_nonfatal_status() failed, error %d\n",
4932 /* non-fatal, continue */
4938 * ice_pci_err_resume - restart operations after PCI error recovery
4939 * @pdev: PCI device information struct
4941 * Called to allow the driver to bring things back up after PCI error and/or
4942 * reset recovery have finished
4944 static void ice_pci_err_resume(struct pci_dev *pdev)
4946 struct ice_pf *pf = pci_get_drvdata(pdev);
4949 dev_err(&pdev->dev, "%s failed, device is unrecoverable\n",
4954 if (test_bit(ICE_SUSPENDED, pf->state)) {
4955 dev_dbg(&pdev->dev, "%s failed to resume normal operations!\n",
4960 ice_restore_all_vfs_msi_state(pdev);
4962 ice_do_reset(pf, ICE_RESET_PFR);
4963 ice_service_task_restart(pf);
4964 mod_timer(&pf->serv_tmr, round_jiffies(jiffies + pf->serv_tmr_period));
4968 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
4969 * @pdev: PCI device information struct
4971 static void ice_pci_err_reset_prepare(struct pci_dev *pdev)
4973 struct ice_pf *pf = pci_get_drvdata(pdev);
4975 if (!test_bit(ICE_SUSPENDED, pf->state)) {
4976 ice_service_task_stop(pf);
4978 if (!test_bit(ICE_PREPARED_FOR_RESET, pf->state)) {
4979 set_bit(ICE_PFR_REQ, pf->state);
4980 ice_prepare_for_reset(pf);
4986 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
4987 * @pdev: PCI device information struct
4989 static void ice_pci_err_reset_done(struct pci_dev *pdev)
4991 ice_pci_err_resume(pdev);
4994 /* ice_pci_tbl - PCI Device ID Table
4996 * Wildcard entries (PCI_ANY_ID) should come last
4997 * Last entry must be all 0s
4999 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
5000 * Class, Class Mask, private data (not used) }
5002 static const struct pci_device_id ice_pci_tbl[] = {
5003 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_BACKPLANE), 0 },
5004 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_QSFP), 0 },
5005 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810C_SFP), 0 },
5006 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E810_XXV_SFP), 0 },
5007 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_BACKPLANE), 0 },
5008 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_QSFP), 0 },
5009 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SFP), 0 },
5010 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_10G_BASE_T), 0 },
5011 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823C_SGMII), 0 },
5012 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_BACKPLANE), 0 },
5013 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_QSFP), 0 },
5014 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SFP), 0 },
5015 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_10G_BASE_T), 0 },
5016 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822C_SGMII), 0 },
5017 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_BACKPLANE), 0 },
5018 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SFP), 0 },
5019 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_10G_BASE_T), 0 },
5020 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E822L_SGMII), 0 },
5021 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_BACKPLANE), 0 },
5022 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_SFP), 0 },
5023 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_10G_BASE_T), 0 },
5024 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_1GBE), 0 },
5025 { PCI_VDEVICE(INTEL, ICE_DEV_ID_E823L_QSFP), 0 },
5026 /* required last entry */
5029 MODULE_DEVICE_TABLE(pci, ice_pci_tbl);
5031 static __maybe_unused SIMPLE_DEV_PM_OPS(ice_pm_ops, ice_suspend, ice_resume);
5033 static const struct pci_error_handlers ice_pci_err_handler = {
5034 .error_detected = ice_pci_err_detected,
5035 .slot_reset = ice_pci_err_slot_reset,
5036 .reset_prepare = ice_pci_err_reset_prepare,
5037 .reset_done = ice_pci_err_reset_done,
5038 .resume = ice_pci_err_resume
5041 static struct pci_driver ice_driver = {
5042 .name = KBUILD_MODNAME,
5043 .id_table = ice_pci_tbl,
5045 .remove = ice_remove,
5047 .driver.pm = &ice_pm_ops,
5048 #endif /* CONFIG_PM */
5049 .shutdown = ice_shutdown,
5050 .sriov_configure = ice_sriov_configure,
5051 .err_handler = &ice_pci_err_handler
5055 * ice_module_init - Driver registration routine
5057 * ice_module_init is the first routine called when the driver is
5058 * loaded. All it does is register with the PCI subsystem.
5060 static int __init ice_module_init(void)
5064 pr_info("%s\n", ice_driver_string);
5065 pr_info("%s\n", ice_copyright);
5067 ice_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0, KBUILD_MODNAME);
5069 pr_err("Failed to create workqueue\n");
5073 status = pci_register_driver(&ice_driver);
5075 pr_err("failed to register PCI driver, err %d\n", status);
5076 destroy_workqueue(ice_wq);
5081 module_init(ice_module_init);
5084 * ice_module_exit - Driver exit cleanup routine
5086 * ice_module_exit is called just before the driver is removed
5089 static void __exit ice_module_exit(void)
5091 pci_unregister_driver(&ice_driver);
5092 destroy_workqueue(ice_wq);
5093 pr_info("module unloaded\n");
5095 module_exit(ice_module_exit);
5098 * ice_set_mac_address - NDO callback to set MAC address
5099 * @netdev: network interface device structure
5100 * @pi: pointer to an address structure
5102 * Returns 0 on success, negative on failure
5104 static int ice_set_mac_address(struct net_device *netdev, void *pi)
5106 struct ice_netdev_priv *np = netdev_priv(netdev);
5107 struct ice_vsi *vsi = np->vsi;
5108 struct ice_pf *pf = vsi->back;
5109 struct ice_hw *hw = &pf->hw;
5110 struct sockaddr *addr = pi;
5111 enum ice_status status;
5116 mac = (u8 *)addr->sa_data;
5118 if (!is_valid_ether_addr(mac))
5119 return -EADDRNOTAVAIL;
5121 if (ether_addr_equal(netdev->dev_addr, mac)) {
5122 netdev_warn(netdev, "already using mac %pM\n", mac);
5126 if (test_bit(ICE_DOWN, pf->state) ||
5127 ice_is_reset_in_progress(pf->state)) {
5128 netdev_err(netdev, "can't set mac %pM. device not ready\n",
5133 /* Clean up old MAC filter. Not an error if old filter doesn't exist */
5134 status = ice_fltr_remove_mac(vsi, netdev->dev_addr, ICE_FWD_TO_VSI);
5135 if (status && status != ICE_ERR_DOES_NOT_EXIST) {
5136 err = -EADDRNOTAVAIL;
5137 goto err_update_filters;
5140 /* Add filter for new MAC. If filter exists, return success */
5141 status = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
5142 if (status == ICE_ERR_ALREADY_EXISTS) {
5143 /* Although this MAC filter is already present in hardware it's
5144 * possible in some cases (e.g. bonding) that dev_addr was
5145 * modified outside of the driver and needs to be restored back
5148 memcpy(netdev->dev_addr, mac, netdev->addr_len);
5149 netdev_dbg(netdev, "filter for MAC %pM already exists\n", mac);
5153 /* error if the new filter addition failed */
5155 err = -EADDRNOTAVAIL;
5159 netdev_err(netdev, "can't set MAC %pM. filter update failed\n",
5164 /* change the netdev's MAC address */
5165 memcpy(netdev->dev_addr, mac, netdev->addr_len);
5166 netdev_dbg(vsi->netdev, "updated MAC address to %pM\n",
5169 /* write new MAC address to the firmware */
5170 flags = ICE_AQC_MAN_MAC_UPDATE_LAA_WOL;
5171 status = ice_aq_manage_mac_write(hw, mac, flags, NULL);
5173 netdev_err(netdev, "can't set MAC %pM. write to firmware failed error %s\n",
5174 mac, ice_stat_str(status));
5180 * ice_set_rx_mode - NDO callback to set the netdev filters
5181 * @netdev: network interface device structure
5183 static void ice_set_rx_mode(struct net_device *netdev)
5185 struct ice_netdev_priv *np = netdev_priv(netdev);
5186 struct ice_vsi *vsi = np->vsi;
5191 /* Set the flags to synchronize filters
5192 * ndo_set_rx_mode may be triggered even without a change in netdev
5195 set_bit(ICE_VSI_UMAC_FLTR_CHANGED, vsi->state);
5196 set_bit(ICE_VSI_MMAC_FLTR_CHANGED, vsi->state);
5197 set_bit(ICE_FLAG_FLTR_SYNC, vsi->back->flags);
5199 /* schedule our worker thread which will take care of
5200 * applying the new filter changes
5202 ice_service_task_schedule(vsi->back);
5206 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
5207 * @netdev: network interface device structure
5208 * @queue_index: Queue ID
5209 * @maxrate: maximum bandwidth in Mbps
5212 ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
5214 struct ice_netdev_priv *np = netdev_priv(netdev);
5215 struct ice_vsi *vsi = np->vsi;
5216 enum ice_status status;
5220 /* Validate maxrate requested is within permitted range */
5221 if (maxrate && (maxrate > (ICE_SCHED_MAX_BW / 1000))) {
5222 netdev_err(netdev, "Invalid max rate %d specified for the queue %d\n",
5223 maxrate, queue_index);
5227 q_handle = vsi->tx_rings[queue_index]->q_handle;
5228 tc = ice_dcb_get_tc(vsi, queue_index);
5230 /* Set BW back to default, when user set maxrate to 0 */
5232 status = ice_cfg_q_bw_dflt_lmt(vsi->port_info, vsi->idx, tc,
5233 q_handle, ICE_MAX_BW);
5235 status = ice_cfg_q_bw_lmt(vsi->port_info, vsi->idx, tc,
5236 q_handle, ICE_MAX_BW, maxrate * 1000);
5238 netdev_err(netdev, "Unable to set Tx max rate, error %s\n",
5239 ice_stat_str(status));
5247 * ice_fdb_add - add an entry to the hardware database
5248 * @ndm: the input from the stack
5249 * @tb: pointer to array of nladdr (unused)
5250 * @dev: the net device pointer
5251 * @addr: the MAC address entry being added
5253 * @flags: instructions from stack about fdb operation
5254 * @extack: netlink extended ack
5257 ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
5258 struct net_device *dev, const unsigned char *addr, u16 vid,
5259 u16 flags, struct netlink_ext_ack __always_unused *extack)
5264 netdev_err(dev, "VLANs aren't supported yet for dev_uc|mc_add()\n");
5267 if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
5268 netdev_err(dev, "FDB only supports static addresses\n");
5272 if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
5273 err = dev_uc_add_excl(dev, addr);
5274 else if (is_multicast_ether_addr(addr))
5275 err = dev_mc_add_excl(dev, addr);
5279 /* Only return duplicate errors if NLM_F_EXCL is set */
5280 if (err == -EEXIST && !(flags & NLM_F_EXCL))
5287 * ice_fdb_del - delete an entry from the hardware database
5288 * @ndm: the input from the stack
5289 * @tb: pointer to array of nladdr (unused)
5290 * @dev: the net device pointer
5291 * @addr: the MAC address entry being added
5295 ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
5296 struct net_device *dev, const unsigned char *addr,
5297 __always_unused u16 vid)
5301 if (ndm->ndm_state & NUD_PERMANENT) {
5302 netdev_err(dev, "FDB only supports static addresses\n");
5306 if (is_unicast_ether_addr(addr))
5307 err = dev_uc_del(dev, addr);
5308 else if (is_multicast_ether_addr(addr))
5309 err = dev_mc_del(dev, addr);
5317 * ice_set_features - set the netdev feature flags
5318 * @netdev: ptr to the netdev being adjusted
5319 * @features: the feature set that the stack is suggesting
5322 ice_set_features(struct net_device *netdev, netdev_features_t features)
5324 struct ice_netdev_priv *np = netdev_priv(netdev);
5325 struct ice_vsi *vsi = np->vsi;
5326 struct ice_pf *pf = vsi->back;
5329 /* Don't set any netdev advanced features with device in Safe Mode */
5330 if (ice_is_safe_mode(vsi->back)) {
5331 dev_err(ice_pf_to_dev(vsi->back), "Device is in Safe Mode - not enabling advanced netdev features\n");
5335 /* Do not change setting during reset */
5336 if (ice_is_reset_in_progress(pf->state)) {
5337 dev_err(ice_pf_to_dev(vsi->back), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
5341 /* Multiple features can be changed in one call so keep features in
5342 * separate if/else statements to guarantee each feature is checked
5344 if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
5345 ice_vsi_manage_rss_lut(vsi, true);
5346 else if (!(features & NETIF_F_RXHASH) &&
5347 netdev->features & NETIF_F_RXHASH)
5348 ice_vsi_manage_rss_lut(vsi, false);
5350 if ((features & NETIF_F_HW_VLAN_CTAG_RX) &&
5351 !(netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
5352 ret = ice_vsi_manage_vlan_stripping(vsi, true);
5353 else if (!(features & NETIF_F_HW_VLAN_CTAG_RX) &&
5354 (netdev->features & NETIF_F_HW_VLAN_CTAG_RX))
5355 ret = ice_vsi_manage_vlan_stripping(vsi, false);
5357 if ((features & NETIF_F_HW_VLAN_CTAG_TX) &&
5358 !(netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
5359 ret = ice_vsi_manage_vlan_insertion(vsi);
5360 else if (!(features & NETIF_F_HW_VLAN_CTAG_TX) &&
5361 (netdev->features & NETIF_F_HW_VLAN_CTAG_TX))
5362 ret = ice_vsi_manage_vlan_insertion(vsi);
5364 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
5365 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
5366 ret = ice_cfg_vlan_pruning(vsi, true, false);
5367 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
5368 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
5369 ret = ice_cfg_vlan_pruning(vsi, false, false);
5371 if ((features & NETIF_F_NTUPLE) &&
5372 !(netdev->features & NETIF_F_NTUPLE)) {
5373 ice_vsi_manage_fdir(vsi, true);
5375 } else if (!(features & NETIF_F_NTUPLE) &&
5376 (netdev->features & NETIF_F_NTUPLE)) {
5377 ice_vsi_manage_fdir(vsi, false);
5378 ice_clear_arfs(vsi);
5385 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
5386 * @vsi: VSI to setup VLAN properties for
5388 static int ice_vsi_vlan_setup(struct ice_vsi *vsi)
5392 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
5393 ret = ice_vsi_manage_vlan_stripping(vsi, true);
5394 if (vsi->netdev->features & NETIF_F_HW_VLAN_CTAG_TX)
5395 ret = ice_vsi_manage_vlan_insertion(vsi);
5401 * ice_vsi_cfg - Setup the VSI
5402 * @vsi: the VSI being configured
5404 * Return 0 on success and negative value on error
5406 int ice_vsi_cfg(struct ice_vsi *vsi)
5411 ice_set_rx_mode(vsi->netdev);
5413 err = ice_vsi_vlan_setup(vsi);
5418 ice_vsi_cfg_dcb_rings(vsi);
5420 err = ice_vsi_cfg_lan_txqs(vsi);
5421 if (!err && ice_is_xdp_ena_vsi(vsi))
5422 err = ice_vsi_cfg_xdp_txqs(vsi);
5424 err = ice_vsi_cfg_rxqs(vsi);
5429 /* THEORY OF MODERATION:
5430 * The below code creates custom DIM profiles for use by this driver, because
5431 * the ice driver hardware works differently than the hardware that DIMLIB was
5432 * originally made for. ice hardware doesn't have packet count limits that
5433 * can trigger an interrupt, but it *does* have interrupt rate limit support,
5434 * and this code adds that capability to be used by the driver when it's using
5435 * DIMLIB. The DIMLIB code was always designed to be a suggestion to the driver
5436 * for how to "respond" to traffic and interrupts, so this driver uses a
5437 * slightly different set of moderation parameters to get best performance.
5440 /* the throttle rate for interrupts, basically worst case delay before
5441 * an initial interrupt fires, value is stored in microseconds.
5444 /* the rate limit for interrupts, which can cap a delay from a small
5445 * ITR at a certain amount of interrupts per second. f.e. a 2us ITR
5446 * could yield as much as 500,000 interrupts per second, but with a
5447 * 10us rate limit, it limits to 100,000 interrupts per second. Value
5448 * is stored in microseconds.
5453 /* Make a different profile for Rx that doesn't allow quite so aggressive
5454 * moderation at the high end (it maxes out at 128us or about 8k interrupts a
5455 * second. The INTRL/rate parameters here are only useful to cap small ITR
5456 * values, which is why for larger ITR's - like 128, which can only generate
5457 * 8k interrupts per second, there is no point to rate limit and the values
5458 * are set to zero. The rate limit values do affect latency, and so must
5459 * be reasonably small so to not impact latency sensitive tests.
5461 static const struct ice_dim rx_profile[] = {
5469 /* The transmit profile, which has the same sorts of values
5470 * as the previous struct
5472 static const struct ice_dim tx_profile[] = {
5480 static void ice_tx_dim_work(struct work_struct *work)
5482 struct ice_ring_container *rc;
5483 struct ice_q_vector *q_vector;
5487 dim = container_of(work, struct dim, work);
5488 rc = container_of(dim, struct ice_ring_container, dim);
5489 q_vector = container_of(rc, struct ice_q_vector, tx);
5491 if (dim->profile_ix >= ARRAY_SIZE(tx_profile))
5492 dim->profile_ix = ARRAY_SIZE(tx_profile) - 1;
5494 /* look up the values in our local table */
5495 itr = tx_profile[dim->profile_ix].itr;
5496 intrl = tx_profile[dim->profile_ix].intrl;
5498 ice_trace(tx_dim_work, q_vector, dim);
5499 ice_write_itr(rc, itr);
5500 ice_write_intrl(q_vector, intrl);
5502 dim->state = DIM_START_MEASURE;
5505 static void ice_rx_dim_work(struct work_struct *work)
5507 struct ice_ring_container *rc;
5508 struct ice_q_vector *q_vector;
5512 dim = container_of(work, struct dim, work);
5513 rc = container_of(dim, struct ice_ring_container, dim);
5514 q_vector = container_of(rc, struct ice_q_vector, rx);
5516 if (dim->profile_ix >= ARRAY_SIZE(rx_profile))
5517 dim->profile_ix = ARRAY_SIZE(rx_profile) - 1;
5519 /* look up the values in our local table */
5520 itr = rx_profile[dim->profile_ix].itr;
5521 intrl = rx_profile[dim->profile_ix].intrl;
5523 ice_trace(rx_dim_work, q_vector, dim);
5524 ice_write_itr(rc, itr);
5525 ice_write_intrl(q_vector, intrl);
5527 dim->state = DIM_START_MEASURE;
5531 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
5532 * @vsi: the VSI being configured
5534 static void ice_napi_enable_all(struct ice_vsi *vsi)
5541 ice_for_each_q_vector(vsi, q_idx) {
5542 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
5544 INIT_WORK(&q_vector->tx.dim.work, ice_tx_dim_work);
5545 q_vector->tx.dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
5547 INIT_WORK(&q_vector->rx.dim.work, ice_rx_dim_work);
5548 q_vector->rx.dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
5550 if (q_vector->rx.ring || q_vector->tx.ring)
5551 napi_enable(&q_vector->napi);
5556 * ice_up_complete - Finish the last steps of bringing up a connection
5557 * @vsi: The VSI being configured
5559 * Return 0 on success and negative value on error
5561 static int ice_up_complete(struct ice_vsi *vsi)
5563 struct ice_pf *pf = vsi->back;
5566 ice_vsi_cfg_msix(vsi);
5568 /* Enable only Rx rings, Tx rings were enabled by the FW when the
5569 * Tx queue group list was configured and the context bits were
5570 * programmed using ice_vsi_cfg_txqs
5572 err = ice_vsi_start_all_rx_rings(vsi);
5576 clear_bit(ICE_VSI_DOWN, vsi->state);
5577 ice_napi_enable_all(vsi);
5578 ice_vsi_ena_irq(vsi);
5580 if (vsi->port_info &&
5581 (vsi->port_info->phy.link_info.link_info & ICE_AQ_LINK_UP) &&
5583 ice_print_link_msg(vsi, true);
5584 netif_tx_start_all_queues(vsi->netdev);
5585 netif_carrier_on(vsi->netdev);
5588 ice_service_task_schedule(pf);
5594 * ice_up - Bring the connection back up after being down
5595 * @vsi: VSI being configured
5597 int ice_up(struct ice_vsi *vsi)
5601 err = ice_vsi_cfg(vsi);
5603 err = ice_up_complete(vsi);
5609 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
5610 * @ring: Tx or Rx ring to read stats from
5611 * @pkts: packets stats counter
5612 * @bytes: bytes stats counter
5614 * This function fetches stats from the ring considering the atomic operations
5615 * that needs to be performed to read u64 values in 32 bit machine.
5618 ice_fetch_u64_stats_per_ring(struct ice_ring *ring, u64 *pkts, u64 *bytes)
5627 start = u64_stats_fetch_begin_irq(&ring->syncp);
5628 *pkts = ring->stats.pkts;
5629 *bytes = ring->stats.bytes;
5630 } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
5634 * ice_update_vsi_tx_ring_stats - Update VSI Tx ring stats counters
5635 * @vsi: the VSI to be updated
5636 * @rings: rings to work on
5637 * @count: number of rings
5640 ice_update_vsi_tx_ring_stats(struct ice_vsi *vsi, struct ice_ring **rings,
5643 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
5646 for (i = 0; i < count; i++) {
5647 struct ice_ring *ring;
5650 ring = READ_ONCE(rings[i]);
5651 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
5652 vsi_stats->tx_packets += pkts;
5653 vsi_stats->tx_bytes += bytes;
5654 vsi->tx_restart += ring->tx_stats.restart_q;
5655 vsi->tx_busy += ring->tx_stats.tx_busy;
5656 vsi->tx_linearize += ring->tx_stats.tx_linearize;
5661 * ice_update_vsi_ring_stats - Update VSI stats counters
5662 * @vsi: the VSI to be updated
5664 static void ice_update_vsi_ring_stats(struct ice_vsi *vsi)
5666 struct rtnl_link_stats64 *vsi_stats = &vsi->net_stats;
5670 /* reset netdev stats */
5671 vsi_stats->tx_packets = 0;
5672 vsi_stats->tx_bytes = 0;
5673 vsi_stats->rx_packets = 0;
5674 vsi_stats->rx_bytes = 0;
5676 /* reset non-netdev (extended) stats */
5677 vsi->tx_restart = 0;
5679 vsi->tx_linearize = 0;
5680 vsi->rx_buf_failed = 0;
5681 vsi->rx_page_failed = 0;
5685 /* update Tx rings counters */
5686 ice_update_vsi_tx_ring_stats(vsi, vsi->tx_rings, vsi->num_txq);
5688 /* update Rx rings counters */
5689 ice_for_each_rxq(vsi, i) {
5690 struct ice_ring *ring = READ_ONCE(vsi->rx_rings[i]);
5692 ice_fetch_u64_stats_per_ring(ring, &pkts, &bytes);
5693 vsi_stats->rx_packets += pkts;
5694 vsi_stats->rx_bytes += bytes;
5695 vsi->rx_buf_failed += ring->rx_stats.alloc_buf_failed;
5696 vsi->rx_page_failed += ring->rx_stats.alloc_page_failed;
5699 /* update XDP Tx rings counters */
5700 if (ice_is_xdp_ena_vsi(vsi))
5701 ice_update_vsi_tx_ring_stats(vsi, vsi->xdp_rings,
5708 * ice_update_vsi_stats - Update VSI stats counters
5709 * @vsi: the VSI to be updated
5711 void ice_update_vsi_stats(struct ice_vsi *vsi)
5713 struct rtnl_link_stats64 *cur_ns = &vsi->net_stats;
5714 struct ice_eth_stats *cur_es = &vsi->eth_stats;
5715 struct ice_pf *pf = vsi->back;
5717 if (test_bit(ICE_VSI_DOWN, vsi->state) ||
5718 test_bit(ICE_CFG_BUSY, pf->state))
5721 /* get stats as recorded by Tx/Rx rings */
5722 ice_update_vsi_ring_stats(vsi);
5724 /* get VSI stats as recorded by the hardware */
5725 ice_update_eth_stats(vsi);
5727 cur_ns->tx_errors = cur_es->tx_errors;
5728 cur_ns->rx_dropped = cur_es->rx_discards;
5729 cur_ns->tx_dropped = cur_es->tx_discards;
5730 cur_ns->multicast = cur_es->rx_multicast;
5732 /* update some more netdev stats if this is main VSI */
5733 if (vsi->type == ICE_VSI_PF) {
5734 cur_ns->rx_crc_errors = pf->stats.crc_errors;
5735 cur_ns->rx_errors = pf->stats.crc_errors +
5736 pf->stats.illegal_bytes +
5737 pf->stats.rx_len_errors +
5738 pf->stats.rx_undersize +
5739 pf->hw_csum_rx_error +
5740 pf->stats.rx_jabber +
5741 pf->stats.rx_fragments +
5742 pf->stats.rx_oversize;
5743 cur_ns->rx_length_errors = pf->stats.rx_len_errors;
5744 /* record drops from the port level */
5745 cur_ns->rx_missed_errors = pf->stats.eth.rx_discards;
5750 * ice_update_pf_stats - Update PF port stats counters
5751 * @pf: PF whose stats needs to be updated
5753 void ice_update_pf_stats(struct ice_pf *pf)
5755 struct ice_hw_port_stats *prev_ps, *cur_ps;
5756 struct ice_hw *hw = &pf->hw;
5760 port = hw->port_info->lport;
5761 prev_ps = &pf->stats_prev;
5762 cur_ps = &pf->stats;
5764 ice_stat_update40(hw, GLPRT_GORCL(port), pf->stat_prev_loaded,
5765 &prev_ps->eth.rx_bytes,
5766 &cur_ps->eth.rx_bytes);
5768 ice_stat_update40(hw, GLPRT_UPRCL(port), pf->stat_prev_loaded,
5769 &prev_ps->eth.rx_unicast,
5770 &cur_ps->eth.rx_unicast);
5772 ice_stat_update40(hw, GLPRT_MPRCL(port), pf->stat_prev_loaded,
5773 &prev_ps->eth.rx_multicast,
5774 &cur_ps->eth.rx_multicast);
5776 ice_stat_update40(hw, GLPRT_BPRCL(port), pf->stat_prev_loaded,
5777 &prev_ps->eth.rx_broadcast,
5778 &cur_ps->eth.rx_broadcast);
5780 ice_stat_update32(hw, PRTRPB_RDPC, pf->stat_prev_loaded,
5781 &prev_ps->eth.rx_discards,
5782 &cur_ps->eth.rx_discards);
5784 ice_stat_update40(hw, GLPRT_GOTCL(port), pf->stat_prev_loaded,
5785 &prev_ps->eth.tx_bytes,
5786 &cur_ps->eth.tx_bytes);
5788 ice_stat_update40(hw, GLPRT_UPTCL(port), pf->stat_prev_loaded,
5789 &prev_ps->eth.tx_unicast,
5790 &cur_ps->eth.tx_unicast);
5792 ice_stat_update40(hw, GLPRT_MPTCL(port), pf->stat_prev_loaded,
5793 &prev_ps->eth.tx_multicast,
5794 &cur_ps->eth.tx_multicast);
5796 ice_stat_update40(hw, GLPRT_BPTCL(port), pf->stat_prev_loaded,
5797 &prev_ps->eth.tx_broadcast,
5798 &cur_ps->eth.tx_broadcast);
5800 ice_stat_update32(hw, GLPRT_TDOLD(port), pf->stat_prev_loaded,
5801 &prev_ps->tx_dropped_link_down,
5802 &cur_ps->tx_dropped_link_down);
5804 ice_stat_update40(hw, GLPRT_PRC64L(port), pf->stat_prev_loaded,
5805 &prev_ps->rx_size_64, &cur_ps->rx_size_64);
5807 ice_stat_update40(hw, GLPRT_PRC127L(port), pf->stat_prev_loaded,
5808 &prev_ps->rx_size_127, &cur_ps->rx_size_127);
5810 ice_stat_update40(hw, GLPRT_PRC255L(port), pf->stat_prev_loaded,
5811 &prev_ps->rx_size_255, &cur_ps->rx_size_255);
5813 ice_stat_update40(hw, GLPRT_PRC511L(port), pf->stat_prev_loaded,
5814 &prev_ps->rx_size_511, &cur_ps->rx_size_511);
5816 ice_stat_update40(hw, GLPRT_PRC1023L(port), pf->stat_prev_loaded,
5817 &prev_ps->rx_size_1023, &cur_ps->rx_size_1023);
5819 ice_stat_update40(hw, GLPRT_PRC1522L(port), pf->stat_prev_loaded,
5820 &prev_ps->rx_size_1522, &cur_ps->rx_size_1522);
5822 ice_stat_update40(hw, GLPRT_PRC9522L(port), pf->stat_prev_loaded,
5823 &prev_ps->rx_size_big, &cur_ps->rx_size_big);
5825 ice_stat_update40(hw, GLPRT_PTC64L(port), pf->stat_prev_loaded,
5826 &prev_ps->tx_size_64, &cur_ps->tx_size_64);
5828 ice_stat_update40(hw, GLPRT_PTC127L(port), pf->stat_prev_loaded,
5829 &prev_ps->tx_size_127, &cur_ps->tx_size_127);
5831 ice_stat_update40(hw, GLPRT_PTC255L(port), pf->stat_prev_loaded,
5832 &prev_ps->tx_size_255, &cur_ps->tx_size_255);
5834 ice_stat_update40(hw, GLPRT_PTC511L(port), pf->stat_prev_loaded,
5835 &prev_ps->tx_size_511, &cur_ps->tx_size_511);
5837 ice_stat_update40(hw, GLPRT_PTC1023L(port), pf->stat_prev_loaded,
5838 &prev_ps->tx_size_1023, &cur_ps->tx_size_1023);
5840 ice_stat_update40(hw, GLPRT_PTC1522L(port), pf->stat_prev_loaded,
5841 &prev_ps->tx_size_1522, &cur_ps->tx_size_1522);
5843 ice_stat_update40(hw, GLPRT_PTC9522L(port), pf->stat_prev_loaded,
5844 &prev_ps->tx_size_big, &cur_ps->tx_size_big);
5846 fd_ctr_base = hw->fd_ctr_base;
5848 ice_stat_update40(hw,
5849 GLSTAT_FD_CNT0L(ICE_FD_SB_STAT_IDX(fd_ctr_base)),
5850 pf->stat_prev_loaded, &prev_ps->fd_sb_match,
5851 &cur_ps->fd_sb_match);
5852 ice_stat_update32(hw, GLPRT_LXONRXC(port), pf->stat_prev_loaded,
5853 &prev_ps->link_xon_rx, &cur_ps->link_xon_rx);
5855 ice_stat_update32(hw, GLPRT_LXOFFRXC(port), pf->stat_prev_loaded,
5856 &prev_ps->link_xoff_rx, &cur_ps->link_xoff_rx);
5858 ice_stat_update32(hw, GLPRT_LXONTXC(port), pf->stat_prev_loaded,
5859 &prev_ps->link_xon_tx, &cur_ps->link_xon_tx);
5861 ice_stat_update32(hw, GLPRT_LXOFFTXC(port), pf->stat_prev_loaded,
5862 &prev_ps->link_xoff_tx, &cur_ps->link_xoff_tx);
5864 ice_update_dcb_stats(pf);
5866 ice_stat_update32(hw, GLPRT_CRCERRS(port), pf->stat_prev_loaded,
5867 &prev_ps->crc_errors, &cur_ps->crc_errors);
5869 ice_stat_update32(hw, GLPRT_ILLERRC(port), pf->stat_prev_loaded,
5870 &prev_ps->illegal_bytes, &cur_ps->illegal_bytes);
5872 ice_stat_update32(hw, GLPRT_MLFC(port), pf->stat_prev_loaded,
5873 &prev_ps->mac_local_faults,
5874 &cur_ps->mac_local_faults);
5876 ice_stat_update32(hw, GLPRT_MRFC(port), pf->stat_prev_loaded,
5877 &prev_ps->mac_remote_faults,
5878 &cur_ps->mac_remote_faults);
5880 ice_stat_update32(hw, GLPRT_RLEC(port), pf->stat_prev_loaded,
5881 &prev_ps->rx_len_errors, &cur_ps->rx_len_errors);
5883 ice_stat_update32(hw, GLPRT_RUC(port), pf->stat_prev_loaded,
5884 &prev_ps->rx_undersize, &cur_ps->rx_undersize);
5886 ice_stat_update32(hw, GLPRT_RFC(port), pf->stat_prev_loaded,
5887 &prev_ps->rx_fragments, &cur_ps->rx_fragments);
5889 ice_stat_update32(hw, GLPRT_ROC(port), pf->stat_prev_loaded,
5890 &prev_ps->rx_oversize, &cur_ps->rx_oversize);
5892 ice_stat_update32(hw, GLPRT_RJC(port), pf->stat_prev_loaded,
5893 &prev_ps->rx_jabber, &cur_ps->rx_jabber);
5895 cur_ps->fd_sb_status = test_bit(ICE_FLAG_FD_ENA, pf->flags) ? 1 : 0;
5897 pf->stat_prev_loaded = true;
5901 * ice_get_stats64 - get statistics for network device structure
5902 * @netdev: network interface device structure
5903 * @stats: main device statistics structure
5906 void ice_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats)
5908 struct ice_netdev_priv *np = netdev_priv(netdev);
5909 struct rtnl_link_stats64 *vsi_stats;
5910 struct ice_vsi *vsi = np->vsi;
5912 vsi_stats = &vsi->net_stats;
5914 if (!vsi->num_txq || !vsi->num_rxq)
5917 /* netdev packet/byte stats come from ring counter. These are obtained
5918 * by summing up ring counters (done by ice_update_vsi_ring_stats).
5919 * But, only call the update routine and read the registers if VSI is
5922 if (!test_bit(ICE_VSI_DOWN, vsi->state))
5923 ice_update_vsi_ring_stats(vsi);
5924 stats->tx_packets = vsi_stats->tx_packets;
5925 stats->tx_bytes = vsi_stats->tx_bytes;
5926 stats->rx_packets = vsi_stats->rx_packets;
5927 stats->rx_bytes = vsi_stats->rx_bytes;
5929 /* The rest of the stats can be read from the hardware but instead we
5930 * just return values that the watchdog task has already obtained from
5933 stats->multicast = vsi_stats->multicast;
5934 stats->tx_errors = vsi_stats->tx_errors;
5935 stats->tx_dropped = vsi_stats->tx_dropped;
5936 stats->rx_errors = vsi_stats->rx_errors;
5937 stats->rx_dropped = vsi_stats->rx_dropped;
5938 stats->rx_crc_errors = vsi_stats->rx_crc_errors;
5939 stats->rx_length_errors = vsi_stats->rx_length_errors;
5943 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
5944 * @vsi: VSI having NAPI disabled
5946 static void ice_napi_disable_all(struct ice_vsi *vsi)
5953 ice_for_each_q_vector(vsi, q_idx) {
5954 struct ice_q_vector *q_vector = vsi->q_vectors[q_idx];
5956 if (q_vector->rx.ring || q_vector->tx.ring)
5957 napi_disable(&q_vector->napi);
5959 cancel_work_sync(&q_vector->tx.dim.work);
5960 cancel_work_sync(&q_vector->rx.dim.work);
5965 * ice_down - Shutdown the connection
5966 * @vsi: The VSI being stopped
5968 int ice_down(struct ice_vsi *vsi)
5970 int i, tx_err, rx_err, link_err = 0;
5972 /* Caller of this function is expected to set the
5973 * vsi->state ICE_DOWN bit
5976 netif_carrier_off(vsi->netdev);
5977 netif_tx_disable(vsi->netdev);
5980 ice_vsi_dis_irq(vsi);
5982 tx_err = ice_vsi_stop_lan_tx_rings(vsi, ICE_NO_RESET, 0);
5984 netdev_err(vsi->netdev, "Failed stop Tx rings, VSI %d error %d\n",
5985 vsi->vsi_num, tx_err);
5986 if (!tx_err && ice_is_xdp_ena_vsi(vsi)) {
5987 tx_err = ice_vsi_stop_xdp_tx_rings(vsi);
5989 netdev_err(vsi->netdev, "Failed stop XDP rings, VSI %d error %d\n",
5990 vsi->vsi_num, tx_err);
5993 rx_err = ice_vsi_stop_all_rx_rings(vsi);
5995 netdev_err(vsi->netdev, "Failed stop Rx rings, VSI %d error %d\n",
5996 vsi->vsi_num, rx_err);
5998 ice_napi_disable_all(vsi);
6000 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA, vsi->back->flags)) {
6001 link_err = ice_force_phys_link_state(vsi, false);
6003 netdev_err(vsi->netdev, "Failed to set physical link down, VSI %d error %d\n",
6004 vsi->vsi_num, link_err);
6007 ice_for_each_txq(vsi, i)
6008 ice_clean_tx_ring(vsi->tx_rings[i]);
6010 ice_for_each_rxq(vsi, i)
6011 ice_clean_rx_ring(vsi->rx_rings[i]);
6013 if (tx_err || rx_err || link_err) {
6014 netdev_err(vsi->netdev, "Failed to close VSI 0x%04X on switch 0x%04X\n",
6015 vsi->vsi_num, vsi->vsw->sw_id);
6023 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
6024 * @vsi: VSI having resources allocated
6026 * Return 0 on success, negative on failure
6028 int ice_vsi_setup_tx_rings(struct ice_vsi *vsi)
6032 if (!vsi->num_txq) {
6033 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Tx queues\n",
6038 ice_for_each_txq(vsi, i) {
6039 struct ice_ring *ring = vsi->tx_rings[i];
6044 ring->netdev = vsi->netdev;
6045 err = ice_setup_tx_ring(ring);
6054 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
6055 * @vsi: VSI having resources allocated
6057 * Return 0 on success, negative on failure
6059 int ice_vsi_setup_rx_rings(struct ice_vsi *vsi)
6063 if (!vsi->num_rxq) {
6064 dev_err(ice_pf_to_dev(vsi->back), "VSI %d has 0 Rx queues\n",
6069 ice_for_each_rxq(vsi, i) {
6070 struct ice_ring *ring = vsi->rx_rings[i];
6075 ring->netdev = vsi->netdev;
6076 err = ice_setup_rx_ring(ring);
6085 * ice_vsi_open_ctrl - open control VSI for use
6086 * @vsi: the VSI to open
6088 * Initialization of the Control VSI
6090 * Returns 0 on success, negative value on error
6092 int ice_vsi_open_ctrl(struct ice_vsi *vsi)
6094 char int_name[ICE_INT_NAME_STR_LEN];
6095 struct ice_pf *pf = vsi->back;
6099 dev = ice_pf_to_dev(pf);
6100 /* allocate descriptors */
6101 err = ice_vsi_setup_tx_rings(vsi);
6105 err = ice_vsi_setup_rx_rings(vsi);
6109 err = ice_vsi_cfg(vsi);
6113 snprintf(int_name, sizeof(int_name) - 1, "%s-%s:ctrl",
6114 dev_driver_string(dev), dev_name(dev));
6115 err = ice_vsi_req_irq_msix(vsi, int_name);
6119 ice_vsi_cfg_msix(vsi);
6121 err = ice_vsi_start_all_rx_rings(vsi);
6123 goto err_up_complete;
6125 clear_bit(ICE_VSI_DOWN, vsi->state);
6126 ice_vsi_ena_irq(vsi);
6133 ice_vsi_free_rx_rings(vsi);
6135 ice_vsi_free_tx_rings(vsi);
6141 * ice_vsi_open - Called when a network interface is made active
6142 * @vsi: the VSI to open
6144 * Initialization of the VSI
6146 * Returns 0 on success, negative value on error
6148 static int ice_vsi_open(struct ice_vsi *vsi)
6150 char int_name[ICE_INT_NAME_STR_LEN];
6151 struct ice_pf *pf = vsi->back;
6154 /* allocate descriptors */
6155 err = ice_vsi_setup_tx_rings(vsi);
6159 err = ice_vsi_setup_rx_rings(vsi);
6163 err = ice_vsi_cfg(vsi);
6167 snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
6168 dev_driver_string(ice_pf_to_dev(pf)), vsi->netdev->name);
6169 err = ice_vsi_req_irq_msix(vsi, int_name);
6173 /* Notify the stack of the actual queue counts. */
6174 err = netif_set_real_num_tx_queues(vsi->netdev, vsi->num_txq);
6178 err = netif_set_real_num_rx_queues(vsi->netdev, vsi->num_rxq);
6182 err = ice_up_complete(vsi);
6184 goto err_up_complete;
6191 ice_vsi_free_irq(vsi);
6193 ice_vsi_free_rx_rings(vsi);
6195 ice_vsi_free_tx_rings(vsi);
6201 * ice_vsi_release_all - Delete all VSIs
6202 * @pf: PF from which all VSIs are being removed
6204 static void ice_vsi_release_all(struct ice_pf *pf)
6211 ice_for_each_vsi(pf, i) {
6215 err = ice_vsi_release(pf->vsi[i]);
6217 dev_dbg(ice_pf_to_dev(pf), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
6218 i, err, pf->vsi[i]->vsi_num);
6223 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
6224 * @pf: pointer to the PF instance
6225 * @type: VSI type to rebuild
6227 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
6229 static int ice_vsi_rebuild_by_type(struct ice_pf *pf, enum ice_vsi_type type)
6231 struct device *dev = ice_pf_to_dev(pf);
6232 enum ice_status status;
6235 ice_for_each_vsi(pf, i) {
6236 struct ice_vsi *vsi = pf->vsi[i];
6238 if (!vsi || vsi->type != type)
6241 /* rebuild the VSI */
6242 err = ice_vsi_rebuild(vsi, true);
6244 dev_err(dev, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
6245 err, vsi->idx, ice_vsi_type_str(type));
6249 /* replay filters for the VSI */
6250 status = ice_replay_vsi(&pf->hw, vsi->idx);
6252 dev_err(dev, "replay VSI failed, status %s, VSI index %d, type %s\n",
6253 ice_stat_str(status), vsi->idx,
6254 ice_vsi_type_str(type));
6258 /* Re-map HW VSI number, using VSI handle that has been
6259 * previously validated in ice_replay_vsi() call above
6261 vsi->vsi_num = ice_get_hw_vsi_num(&pf->hw, vsi->idx);
6263 /* enable the VSI */
6264 err = ice_ena_vsi(vsi, false);
6266 dev_err(dev, "enable VSI failed, err %d, VSI index %d, type %s\n",
6267 err, vsi->idx, ice_vsi_type_str(type));
6271 dev_info(dev, "VSI rebuilt. VSI index %d, type %s\n", vsi->idx,
6272 ice_vsi_type_str(type));
6279 * ice_update_pf_netdev_link - Update PF netdev link status
6280 * @pf: pointer to the PF instance
6282 static void ice_update_pf_netdev_link(struct ice_pf *pf)
6287 ice_for_each_vsi(pf, i) {
6288 struct ice_vsi *vsi = pf->vsi[i];
6290 if (!vsi || vsi->type != ICE_VSI_PF)
6293 ice_get_link_status(pf->vsi[i]->port_info, &link_up);
6295 netif_carrier_on(pf->vsi[i]->netdev);
6296 netif_tx_wake_all_queues(pf->vsi[i]->netdev);
6298 netif_carrier_off(pf->vsi[i]->netdev);
6299 netif_tx_stop_all_queues(pf->vsi[i]->netdev);
6305 * ice_rebuild - rebuild after reset
6306 * @pf: PF to rebuild
6307 * @reset_type: type of reset
6309 * Do not rebuild VF VSI in this flow because that is already handled via
6310 * ice_reset_all_vfs(). This is because requirements for resetting a VF after a
6311 * PFR/CORER/GLOBER/etc. are different than the normal flow. Also, we don't want
6312 * to reset/rebuild all the VF VSI twice.
6314 static void ice_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)
6316 struct device *dev = ice_pf_to_dev(pf);
6317 struct ice_hw *hw = &pf->hw;
6318 enum ice_status ret;
6321 if (test_bit(ICE_DOWN, pf->state))
6322 goto clear_recovery;
6324 dev_dbg(dev, "rebuilding PF after reset_type=%d\n", reset_type);
6326 ret = ice_init_all_ctrlq(hw);
6328 dev_err(dev, "control queues init failed %s\n",
6330 goto err_init_ctrlq;
6333 /* if DDP was previously loaded successfully */
6334 if (!ice_is_safe_mode(pf)) {
6335 /* reload the SW DB of filter tables */
6336 if (reset_type == ICE_RESET_PFR)
6337 ice_fill_blk_tbls(hw);
6339 /* Reload DDP Package after CORER/GLOBR reset */
6340 ice_load_pkg(NULL, pf);
6343 ret = ice_clear_pf_cfg(hw);
6345 dev_err(dev, "clear PF configuration failed %s\n",
6347 goto err_init_ctrlq;
6350 if (pf->first_sw->dflt_vsi_ena)
6351 dev_info(dev, "Clearing default VSI, re-enable after reset completes\n");
6352 /* clear the default VSI configuration if it exists */
6353 pf->first_sw->dflt_vsi = NULL;
6354 pf->first_sw->dflt_vsi_ena = false;
6356 ice_clear_pxe_mode(hw);
6358 ret = ice_init_nvm(hw);
6360 dev_err(dev, "ice_init_nvm failed %s\n", ice_stat_str(ret));
6361 goto err_init_ctrlq;
6364 ret = ice_get_caps(hw);
6366 dev_err(dev, "ice_get_caps failed %s\n", ice_stat_str(ret));
6367 goto err_init_ctrlq;
6370 ret = ice_aq_set_mac_cfg(hw, ICE_AQ_SET_MAC_FRAME_SIZE_MAX, NULL);
6372 dev_err(dev, "set_mac_cfg failed %s\n", ice_stat_str(ret));
6373 goto err_init_ctrlq;
6376 err = ice_sched_init_port(hw->port_info);
6378 goto err_sched_init_port;
6380 /* start misc vector */
6381 err = ice_req_irq_msix_misc(pf);
6383 dev_err(dev, "misc vector setup failed: %d\n", err);
6384 goto err_sched_init_port;
6387 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
6388 wr32(hw, PFQF_FD_ENA, PFQF_FD_ENA_FD_ENA_M);
6389 if (!rd32(hw, PFQF_FD_SIZE)) {
6390 u16 unused, guar, b_effort;
6392 guar = hw->func_caps.fd_fltr_guar;
6393 b_effort = hw->func_caps.fd_fltr_best_effort;
6395 /* force guaranteed filter pool for PF */
6396 ice_alloc_fd_guar_item(hw, &unused, guar);
6397 /* force shared filter pool for PF */
6398 ice_alloc_fd_shrd_item(hw, &unused, b_effort);
6402 if (test_bit(ICE_FLAG_DCB_ENA, pf->flags))
6403 ice_dcb_rebuild(pf);
6405 /* If the PF previously had enabled PTP, PTP init needs to happen before
6406 * the VSI rebuild. If not, this causes the PTP link status events to
6409 if (test_bit(ICE_FLAG_PTP_SUPPORTED, pf->flags))
6412 /* rebuild PF VSI */
6413 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_PF);
6415 dev_err(dev, "PF VSI rebuild failed: %d\n", err);
6416 goto err_vsi_rebuild;
6419 /* If Flow Director is active */
6420 if (test_bit(ICE_FLAG_FD_ENA, pf->flags)) {
6421 err = ice_vsi_rebuild_by_type(pf, ICE_VSI_CTRL);
6423 dev_err(dev, "control VSI rebuild failed: %d\n", err);
6424 goto err_vsi_rebuild;
6427 /* replay HW Flow Director recipes */
6429 ice_fdir_replay_flows(hw);
6431 /* replay Flow Director filters */
6432 ice_fdir_replay_fltrs(pf);
6434 ice_rebuild_arfs(pf);
6437 ice_update_pf_netdev_link(pf);
6439 /* tell the firmware we are up */
6440 ret = ice_send_version(pf);
6442 dev_err(dev, "Rebuild failed due to error sending driver version: %s\n",
6444 goto err_vsi_rebuild;
6447 ice_replay_post(hw);
6449 /* if we get here, reset flow is successful */
6450 clear_bit(ICE_RESET_FAILED, pf->state);
6452 ice_plug_aux_dev(pf);
6456 err_sched_init_port:
6457 ice_sched_cleanup_all(hw);
6459 ice_shutdown_all_ctrlq(hw);
6460 set_bit(ICE_RESET_FAILED, pf->state);
6462 /* set this bit in PF state to control service task scheduling */
6463 set_bit(ICE_NEEDS_RESTART, pf->state);
6464 dev_err(dev, "Rebuild failed, unload and reload driver\n");
6468 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
6469 * @vsi: Pointer to VSI structure
6471 static int ice_max_xdp_frame_size(struct ice_vsi *vsi)
6473 if (PAGE_SIZE >= 8192 || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
6474 return ICE_RXBUF_2048 - XDP_PACKET_HEADROOM;
6476 return ICE_RXBUF_3072;
6480 * ice_change_mtu - NDO callback to change the MTU
6481 * @netdev: network interface device structure
6482 * @new_mtu: new value for maximum frame size
6484 * Returns 0 on success, negative on failure
6486 static int ice_change_mtu(struct net_device *netdev, int new_mtu)
6488 struct ice_netdev_priv *np = netdev_priv(netdev);
6489 struct ice_vsi *vsi = np->vsi;
6490 struct ice_pf *pf = vsi->back;
6491 struct iidc_event *event;
6495 if (new_mtu == (int)netdev->mtu) {
6496 netdev_warn(netdev, "MTU is already %u\n", netdev->mtu);
6500 if (ice_is_xdp_ena_vsi(vsi)) {
6501 int frame_size = ice_max_xdp_frame_size(vsi);
6503 if (new_mtu + ICE_ETH_PKT_HDR_PAD > frame_size) {
6504 netdev_err(netdev, "max MTU for XDP usage is %d\n",
6505 frame_size - ICE_ETH_PKT_HDR_PAD);
6510 /* if a reset is in progress, wait for some time for it to complete */
6512 if (ice_is_reset_in_progress(pf->state)) {
6514 usleep_range(1000, 2000);
6519 } while (count < 100);
6522 netdev_err(netdev, "can't change MTU. Device is busy\n");
6526 event = kzalloc(sizeof(*event), GFP_KERNEL);
6530 set_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);
6531 ice_send_event_to_aux(pf, event);
6532 clear_bit(IIDC_EVENT_BEFORE_MTU_CHANGE, event->type);
6534 netdev->mtu = (unsigned int)new_mtu;
6536 /* if VSI is up, bring it down and then back up */
6537 if (!test_and_set_bit(ICE_VSI_DOWN, vsi->state)) {
6538 err = ice_down(vsi);
6540 netdev_err(netdev, "change MTU if_down err %d\n", err);
6546 netdev_err(netdev, "change MTU if_up err %d\n", err);
6551 netdev_dbg(netdev, "changed MTU to %d\n", new_mtu);
6553 set_bit(IIDC_EVENT_AFTER_MTU_CHANGE, event->type);
6554 ice_send_event_to_aux(pf, event);
6561 * ice_do_ioctl - Access the hwtstamp interface
6562 * @netdev: network interface device structure
6563 * @ifr: interface request data
6564 * @cmd: ioctl command
6566 static int ice_do_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
6568 struct ice_netdev_priv *np = netdev_priv(netdev);
6569 struct ice_pf *pf = np->vsi->back;
6573 return ice_ptp_get_ts_config(pf, ifr);
6575 return ice_ptp_set_ts_config(pf, ifr);
6582 * ice_aq_str - convert AQ err code to a string
6583 * @aq_err: the AQ error code to convert
6585 const char *ice_aq_str(enum ice_aq_err aq_err)
6590 case ICE_AQ_RC_EPERM:
6591 return "ICE_AQ_RC_EPERM";
6592 case ICE_AQ_RC_ENOENT:
6593 return "ICE_AQ_RC_ENOENT";
6594 case ICE_AQ_RC_ENOMEM:
6595 return "ICE_AQ_RC_ENOMEM";
6596 case ICE_AQ_RC_EBUSY:
6597 return "ICE_AQ_RC_EBUSY";
6598 case ICE_AQ_RC_EEXIST:
6599 return "ICE_AQ_RC_EEXIST";
6600 case ICE_AQ_RC_EINVAL:
6601 return "ICE_AQ_RC_EINVAL";
6602 case ICE_AQ_RC_ENOSPC:
6603 return "ICE_AQ_RC_ENOSPC";
6604 case ICE_AQ_RC_ENOSYS:
6605 return "ICE_AQ_RC_ENOSYS";
6606 case ICE_AQ_RC_EMODE:
6607 return "ICE_AQ_RC_EMODE";
6608 case ICE_AQ_RC_ENOSEC:
6609 return "ICE_AQ_RC_ENOSEC";
6610 case ICE_AQ_RC_EBADSIG:
6611 return "ICE_AQ_RC_EBADSIG";
6612 case ICE_AQ_RC_ESVN:
6613 return "ICE_AQ_RC_ESVN";
6614 case ICE_AQ_RC_EBADMAN:
6615 return "ICE_AQ_RC_EBADMAN";
6616 case ICE_AQ_RC_EBADBUF:
6617 return "ICE_AQ_RC_EBADBUF";
6620 return "ICE_AQ_RC_UNKNOWN";
6624 * ice_stat_str - convert status err code to a string
6625 * @stat_err: the status error code to convert
6627 const char *ice_stat_str(enum ice_status stat_err)
6633 return "ICE_ERR_PARAM";
6634 case ICE_ERR_NOT_IMPL:
6635 return "ICE_ERR_NOT_IMPL";
6636 case ICE_ERR_NOT_READY:
6637 return "ICE_ERR_NOT_READY";
6638 case ICE_ERR_NOT_SUPPORTED:
6639 return "ICE_ERR_NOT_SUPPORTED";
6640 case ICE_ERR_BAD_PTR:
6641 return "ICE_ERR_BAD_PTR";
6642 case ICE_ERR_INVAL_SIZE:
6643 return "ICE_ERR_INVAL_SIZE";
6644 case ICE_ERR_DEVICE_NOT_SUPPORTED:
6645 return "ICE_ERR_DEVICE_NOT_SUPPORTED";
6646 case ICE_ERR_RESET_FAILED:
6647 return "ICE_ERR_RESET_FAILED";
6648 case ICE_ERR_FW_API_VER:
6649 return "ICE_ERR_FW_API_VER";
6650 case ICE_ERR_NO_MEMORY:
6651 return "ICE_ERR_NO_MEMORY";
6653 return "ICE_ERR_CFG";
6654 case ICE_ERR_OUT_OF_RANGE:
6655 return "ICE_ERR_OUT_OF_RANGE";
6656 case ICE_ERR_ALREADY_EXISTS:
6657 return "ICE_ERR_ALREADY_EXISTS";
6659 return "ICE_ERR_NVM";
6660 case ICE_ERR_NVM_CHECKSUM:
6661 return "ICE_ERR_NVM_CHECKSUM";
6662 case ICE_ERR_BUF_TOO_SHORT:
6663 return "ICE_ERR_BUF_TOO_SHORT";
6664 case ICE_ERR_NVM_BLANK_MODE:
6665 return "ICE_ERR_NVM_BLANK_MODE";
6666 case ICE_ERR_IN_USE:
6667 return "ICE_ERR_IN_USE";
6668 case ICE_ERR_MAX_LIMIT:
6669 return "ICE_ERR_MAX_LIMIT";
6670 case ICE_ERR_RESET_ONGOING:
6671 return "ICE_ERR_RESET_ONGOING";
6672 case ICE_ERR_HW_TABLE:
6673 return "ICE_ERR_HW_TABLE";
6674 case ICE_ERR_DOES_NOT_EXIST:
6675 return "ICE_ERR_DOES_NOT_EXIST";
6676 case ICE_ERR_FW_DDP_MISMATCH:
6677 return "ICE_ERR_FW_DDP_MISMATCH";
6678 case ICE_ERR_AQ_ERROR:
6679 return "ICE_ERR_AQ_ERROR";
6680 case ICE_ERR_AQ_TIMEOUT:
6681 return "ICE_ERR_AQ_TIMEOUT";
6682 case ICE_ERR_AQ_FULL:
6683 return "ICE_ERR_AQ_FULL";
6684 case ICE_ERR_AQ_NO_WORK:
6685 return "ICE_ERR_AQ_NO_WORK";
6686 case ICE_ERR_AQ_EMPTY:
6687 return "ICE_ERR_AQ_EMPTY";
6688 case ICE_ERR_AQ_FW_CRITICAL:
6689 return "ICE_ERR_AQ_FW_CRITICAL";
6692 return "ICE_ERR_UNKNOWN";
6696 * ice_set_rss_lut - Set RSS LUT
6697 * @vsi: Pointer to VSI structure
6698 * @lut: Lookup table
6699 * @lut_size: Lookup table size
6701 * Returns 0 on success, negative on failure
6703 int ice_set_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
6705 struct ice_aq_get_set_rss_lut_params params = {};
6706 struct ice_hw *hw = &vsi->back->hw;
6707 enum ice_status status;
6712 params.vsi_handle = vsi->idx;
6713 params.lut_size = lut_size;
6714 params.lut_type = vsi->rss_lut_type;
6717 status = ice_aq_set_rss_lut(hw, ¶ms);
6719 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS lut, err %s aq_err %s\n",
6720 ice_stat_str(status),
6721 ice_aq_str(hw->adminq.sq_last_status));
6729 * ice_set_rss_key - Set RSS key
6730 * @vsi: Pointer to the VSI structure
6731 * @seed: RSS hash seed
6733 * Returns 0 on success, negative on failure
6735 int ice_set_rss_key(struct ice_vsi *vsi, u8 *seed)
6737 struct ice_hw *hw = &vsi->back->hw;
6738 enum ice_status status;
6743 status = ice_aq_set_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
6745 dev_err(ice_pf_to_dev(vsi->back), "Cannot set RSS key, err %s aq_err %s\n",
6746 ice_stat_str(status),
6747 ice_aq_str(hw->adminq.sq_last_status));
6755 * ice_get_rss_lut - Get RSS LUT
6756 * @vsi: Pointer to VSI structure
6757 * @lut: Buffer to store the lookup table entries
6758 * @lut_size: Size of buffer to store the lookup table entries
6760 * Returns 0 on success, negative on failure
6762 int ice_get_rss_lut(struct ice_vsi *vsi, u8 *lut, u16 lut_size)
6764 struct ice_aq_get_set_rss_lut_params params = {};
6765 struct ice_hw *hw = &vsi->back->hw;
6766 enum ice_status status;
6771 params.vsi_handle = vsi->idx;
6772 params.lut_size = lut_size;
6773 params.lut_type = vsi->rss_lut_type;
6776 status = ice_aq_get_rss_lut(hw, ¶ms);
6778 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS lut, err %s aq_err %s\n",
6779 ice_stat_str(status),
6780 ice_aq_str(hw->adminq.sq_last_status));
6788 * ice_get_rss_key - Get RSS key
6789 * @vsi: Pointer to VSI structure
6790 * @seed: Buffer to store the key in
6792 * Returns 0 on success, negative on failure
6794 int ice_get_rss_key(struct ice_vsi *vsi, u8 *seed)
6796 struct ice_hw *hw = &vsi->back->hw;
6797 enum ice_status status;
6802 status = ice_aq_get_rss_key(hw, vsi->idx, (struct ice_aqc_get_set_rss_keys *)seed);
6804 dev_err(ice_pf_to_dev(vsi->back), "Cannot get RSS key, err %s aq_err %s\n",
6805 ice_stat_str(status),
6806 ice_aq_str(hw->adminq.sq_last_status));
6814 * ice_bridge_getlink - Get the hardware bridge mode
6817 * @seq: RTNL message seq
6818 * @dev: the netdev being configured
6819 * @filter_mask: filter mask passed in
6820 * @nlflags: netlink flags passed in
6822 * Return the bridge mode (VEB/VEPA)
6825 ice_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
6826 struct net_device *dev, u32 filter_mask, int nlflags)
6828 struct ice_netdev_priv *np = netdev_priv(dev);
6829 struct ice_vsi *vsi = np->vsi;
6830 struct ice_pf *pf = vsi->back;
6833 bmode = pf->first_sw->bridge_mode;
6835 return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bmode, 0, 0, nlflags,
6840 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
6841 * @vsi: Pointer to VSI structure
6842 * @bmode: Hardware bridge mode (VEB/VEPA)
6844 * Returns 0 on success, negative on failure
6846 static int ice_vsi_update_bridge_mode(struct ice_vsi *vsi, u16 bmode)
6848 struct ice_aqc_vsi_props *vsi_props;
6849 struct ice_hw *hw = &vsi->back->hw;
6850 struct ice_vsi_ctx *ctxt;
6851 enum ice_status status;
6854 vsi_props = &vsi->info;
6856 ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
6860 ctxt->info = vsi->info;
6862 if (bmode == BRIDGE_MODE_VEB)
6863 /* change from VEPA to VEB mode */
6864 ctxt->info.sw_flags |= ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
6866 /* change from VEB to VEPA mode */
6867 ctxt->info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB;
6868 ctxt->info.valid_sections = cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID);
6870 status = ice_update_vsi(hw, vsi->idx, ctxt, NULL);
6872 dev_err(ice_pf_to_dev(vsi->back), "update VSI for bridge mode failed, bmode = %d err %s aq_err %s\n",
6873 bmode, ice_stat_str(status),
6874 ice_aq_str(hw->adminq.sq_last_status));
6878 /* Update sw flags for book keeping */
6879 vsi_props->sw_flags = ctxt->info.sw_flags;
6887 * ice_bridge_setlink - Set the hardware bridge mode
6888 * @dev: the netdev being configured
6889 * @nlh: RTNL message
6890 * @flags: bridge setlink flags
6891 * @extack: netlink extended ack
6893 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
6894 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
6895 * not already set for all VSIs connected to this switch. And also update the
6896 * unicast switch filter rules for the corresponding switch of the netdev.
6899 ice_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh,
6900 u16 __always_unused flags,
6901 struct netlink_ext_ack __always_unused *extack)
6903 struct ice_netdev_priv *np = netdev_priv(dev);
6904 struct ice_pf *pf = np->vsi->back;
6905 struct nlattr *attr, *br_spec;
6906 struct ice_hw *hw = &pf->hw;
6907 enum ice_status status;
6908 struct ice_sw *pf_sw;
6909 int rem, v, err = 0;
6911 pf_sw = pf->first_sw;
6912 /* find the attribute in the netlink message */
6913 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
6915 nla_for_each_nested(attr, br_spec, rem) {
6918 if (nla_type(attr) != IFLA_BRIDGE_MODE)
6920 mode = nla_get_u16(attr);
6921 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
6923 /* Continue if bridge mode is not being flipped */
6924 if (mode == pf_sw->bridge_mode)
6926 /* Iterates through the PF VSI list and update the loopback
6929 ice_for_each_vsi(pf, v) {
6932 err = ice_vsi_update_bridge_mode(pf->vsi[v], mode);
6937 hw->evb_veb = (mode == BRIDGE_MODE_VEB);
6938 /* Update the unicast switch filter rules for the corresponding
6939 * switch of the netdev
6941 status = ice_update_sw_rule_bridge_mode(hw);
6943 netdev_err(dev, "switch rule update failed, mode = %d err %s aq_err %s\n",
6944 mode, ice_stat_str(status),
6945 ice_aq_str(hw->adminq.sq_last_status));
6946 /* revert hw->evb_veb */
6947 hw->evb_veb = (pf_sw->bridge_mode == BRIDGE_MODE_VEB);
6951 pf_sw->bridge_mode = mode;
6958 * ice_tx_timeout - Respond to a Tx Hang
6959 * @netdev: network interface device structure
6960 * @txqueue: Tx queue
6962 static void ice_tx_timeout(struct net_device *netdev, unsigned int txqueue)
6964 struct ice_netdev_priv *np = netdev_priv(netdev);
6965 struct ice_ring *tx_ring = NULL;
6966 struct ice_vsi *vsi = np->vsi;
6967 struct ice_pf *pf = vsi->back;
6970 pf->tx_timeout_count++;
6972 /* Check if PFC is enabled for the TC to which the queue belongs
6973 * to. If yes then Tx timeout is not caused by a hung queue, no
6974 * need to reset and rebuild
6976 if (ice_is_pfc_causing_hung_q(pf, txqueue)) {
6977 dev_info(ice_pf_to_dev(pf), "Fake Tx hang detected on queue %u, timeout caused by PFC storm\n",
6982 /* now that we have an index, find the tx_ring struct */
6983 for (i = 0; i < vsi->num_txq; i++)
6984 if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
6985 if (txqueue == vsi->tx_rings[i]->q_index) {
6986 tx_ring = vsi->tx_rings[i];
6990 /* Reset recovery level if enough time has elapsed after last timeout.
6991 * Also ensure no new reset action happens before next timeout period.
6993 if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ * 20)))
6994 pf->tx_timeout_recovery_level = 1;
6995 else if (time_before(jiffies, (pf->tx_timeout_last_recovery +
6996 netdev->watchdog_timeo)))
7000 struct ice_hw *hw = &pf->hw;
7003 head = (rd32(hw, QTX_COMM_HEAD(vsi->txq_map[txqueue])) &
7004 QTX_COMM_HEAD_HEAD_M) >> QTX_COMM_HEAD_HEAD_S;
7005 /* Read interrupt register */
7006 val = rd32(hw, GLINT_DYN_CTL(tx_ring->q_vector->reg_idx));
7008 netdev_info(netdev, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
7009 vsi->vsi_num, txqueue, tx_ring->next_to_clean,
7010 head, tx_ring->next_to_use, val);
7013 pf->tx_timeout_last_recovery = jiffies;
7014 netdev_info(netdev, "tx_timeout recovery level %d, txqueue %u\n",
7015 pf->tx_timeout_recovery_level, txqueue);
7017 switch (pf->tx_timeout_recovery_level) {
7019 set_bit(ICE_PFR_REQ, pf->state);
7022 set_bit(ICE_CORER_REQ, pf->state);
7025 set_bit(ICE_GLOBR_REQ, pf->state);
7028 netdev_err(netdev, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
7029 set_bit(ICE_DOWN, pf->state);
7030 set_bit(ICE_VSI_NEEDS_RESTART, vsi->state);
7031 set_bit(ICE_SERVICE_DIS, pf->state);
7035 ice_service_task_schedule(pf);
7036 pf->tx_timeout_recovery_level++;
7040 * ice_open - Called when a network interface becomes active
7041 * @netdev: network interface device structure
7043 * The open entry point is called when a network interface is made
7044 * active by the system (IFF_UP). At this point all resources needed
7045 * for transmit and receive operations are allocated, the interrupt
7046 * handler is registered with the OS, the netdev watchdog is enabled,
7047 * and the stack is notified that the interface is ready.
7049 * Returns 0 on success, negative value on failure
7051 int ice_open(struct net_device *netdev)
7053 struct ice_netdev_priv *np = netdev_priv(netdev);
7054 struct ice_pf *pf = np->vsi->back;
7056 if (ice_is_reset_in_progress(pf->state)) {
7057 netdev_err(netdev, "can't open net device while reset is in progress");
7061 return ice_open_internal(netdev);
7065 * ice_open_internal - Called when a network interface becomes active
7066 * @netdev: network interface device structure
7068 * Internal ice_open implementation. Should not be used directly except for ice_open and reset
7071 * Returns 0 on success, negative value on failure
7073 int ice_open_internal(struct net_device *netdev)
7075 struct ice_netdev_priv *np = netdev_priv(netdev);
7076 struct ice_vsi *vsi = np->vsi;
7077 struct ice_pf *pf = vsi->back;
7078 struct ice_port_info *pi;
7079 enum ice_status status;
7082 if (test_bit(ICE_NEEDS_RESTART, pf->state)) {
7083 netdev_err(netdev, "driver needs to be unloaded and reloaded\n");
7087 netif_carrier_off(netdev);
7089 pi = vsi->port_info;
7090 status = ice_update_link_info(pi);
7092 netdev_err(netdev, "Failed to get link info, error %s\n",
7093 ice_stat_str(status));
7097 ice_check_module_power(pf, pi->phy.link_info.link_cfg_err);
7099 /* Set PHY if there is media, otherwise, turn off PHY */
7100 if (pi->phy.link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
7101 clear_bit(ICE_FLAG_NO_MEDIA, pf->flags);
7102 if (!test_bit(ICE_PHY_INIT_COMPLETE, pf->state)) {
7103 err = ice_init_phy_user_cfg(pi);
7105 netdev_err(netdev, "Failed to initialize PHY settings, error %d\n",
7111 err = ice_configure_phy(vsi);
7113 netdev_err(netdev, "Failed to set physical link up, error %d\n",
7118 set_bit(ICE_FLAG_NO_MEDIA, pf->flags);
7119 ice_set_link(vsi, false);
7122 err = ice_vsi_open(vsi);
7124 netdev_err(netdev, "Failed to open VSI 0x%04X on switch 0x%04X\n",
7125 vsi->vsi_num, vsi->vsw->sw_id);
7127 /* Update existing tunnels information */
7128 udp_tunnel_get_rx_info(netdev);
7134 * ice_stop - Disables a network interface
7135 * @netdev: network interface device structure
7137 * The stop entry point is called when an interface is de-activated by the OS,
7138 * and the netdevice enters the DOWN state. The hardware is still under the
7139 * driver's control, but the netdev interface is disabled.
7141 * Returns success only - not allowed to fail
7143 int ice_stop(struct net_device *netdev)
7145 struct ice_netdev_priv *np = netdev_priv(netdev);
7146 struct ice_vsi *vsi = np->vsi;
7147 struct ice_pf *pf = vsi->back;
7149 if (ice_is_reset_in_progress(pf->state)) {
7150 netdev_err(netdev, "can't stop net device while reset is in progress");
7160 * ice_features_check - Validate encapsulated packet conforms to limits
7162 * @netdev: This port's netdev
7163 * @features: Offload features that the stack believes apply
7165 static netdev_features_t
7166 ice_features_check(struct sk_buff *skb,
7167 struct net_device __always_unused *netdev,
7168 netdev_features_t features)
7172 /* No point in doing any of this if neither checksum nor GSO are
7173 * being requested for this frame. We can rule out both by just
7174 * checking for CHECKSUM_PARTIAL
7176 if (skb->ip_summed != CHECKSUM_PARTIAL)
7179 /* We cannot support GSO if the MSS is going to be less than
7180 * 64 bytes. If it is then we need to drop support for GSO.
7182 if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
7183 features &= ~NETIF_F_GSO_MASK;
7185 len = skb_network_header(skb) - skb->data;
7186 if (len > ICE_TXD_MACLEN_MAX || len & 0x1)
7187 goto out_rm_features;
7189 len = skb_transport_header(skb) - skb_network_header(skb);
7190 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
7191 goto out_rm_features;
7193 if (skb->encapsulation) {
7194 len = skb_inner_network_header(skb) - skb_transport_header(skb);
7195 if (len > ICE_TXD_L4LEN_MAX || len & 0x1)
7196 goto out_rm_features;
7198 len = skb_inner_transport_header(skb) -
7199 skb_inner_network_header(skb);
7200 if (len > ICE_TXD_IPLEN_MAX || len & 0x1)
7201 goto out_rm_features;
7206 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
7209 static const struct net_device_ops ice_netdev_safe_mode_ops = {
7210 .ndo_open = ice_open,
7211 .ndo_stop = ice_stop,
7212 .ndo_start_xmit = ice_start_xmit,
7213 .ndo_set_mac_address = ice_set_mac_address,
7214 .ndo_validate_addr = eth_validate_addr,
7215 .ndo_change_mtu = ice_change_mtu,
7216 .ndo_get_stats64 = ice_get_stats64,
7217 .ndo_tx_timeout = ice_tx_timeout,
7218 .ndo_bpf = ice_xdp_safe_mode,
7221 static const struct net_device_ops ice_netdev_ops = {
7222 .ndo_open = ice_open,
7223 .ndo_stop = ice_stop,
7224 .ndo_start_xmit = ice_start_xmit,
7225 .ndo_features_check = ice_features_check,
7226 .ndo_set_rx_mode = ice_set_rx_mode,
7227 .ndo_set_mac_address = ice_set_mac_address,
7228 .ndo_validate_addr = eth_validate_addr,
7229 .ndo_change_mtu = ice_change_mtu,
7230 .ndo_get_stats64 = ice_get_stats64,
7231 .ndo_set_tx_maxrate = ice_set_tx_maxrate,
7232 .ndo_do_ioctl = ice_do_ioctl,
7233 .ndo_set_vf_spoofchk = ice_set_vf_spoofchk,
7234 .ndo_set_vf_mac = ice_set_vf_mac,
7235 .ndo_get_vf_config = ice_get_vf_cfg,
7236 .ndo_set_vf_trust = ice_set_vf_trust,
7237 .ndo_set_vf_vlan = ice_set_vf_port_vlan,
7238 .ndo_set_vf_link_state = ice_set_vf_link_state,
7239 .ndo_get_vf_stats = ice_get_vf_stats,
7240 .ndo_vlan_rx_add_vid = ice_vlan_rx_add_vid,
7241 .ndo_vlan_rx_kill_vid = ice_vlan_rx_kill_vid,
7242 .ndo_set_features = ice_set_features,
7243 .ndo_bridge_getlink = ice_bridge_getlink,
7244 .ndo_bridge_setlink = ice_bridge_setlink,
7245 .ndo_fdb_add = ice_fdb_add,
7246 .ndo_fdb_del = ice_fdb_del,
7247 #ifdef CONFIG_RFS_ACCEL
7248 .ndo_rx_flow_steer = ice_rx_flow_steer,
7250 .ndo_tx_timeout = ice_tx_timeout,
7252 .ndo_xdp_xmit = ice_xdp_xmit,
7253 .ndo_xsk_wakeup = ice_xsk_wakeup,