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
11 #include "ice_dcb_lib.h"
12 #include "ice_dcb_nl.h"
13 #include "ice_devlink.h"
15 #define DRV_VERSION_MAJOR 0
16 #define DRV_VERSION_MINOR 8
17 #define DRV_VERSION_BUILD 2
19 #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
20 __stringify(DRV_VERSION_MINOR) "." \
21 __stringify(DRV_VERSION_BUILD) "-k"
22 #define DRV_SUMMARY "Intel(R) Ethernet Connection E800 Series Linux Driver"
23 const char ice_drv_ver
[] = DRV_VERSION
;
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"
31 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
32 MODULE_DESCRIPTION(DRV_SUMMARY
);
33 MODULE_LICENSE("GPL v2");
34 MODULE_VERSION(DRV_VERSION
);
35 MODULE_FIRMWARE(ICE_DDP_PKG_FILE
);
37 static int debug
= -1;
38 module_param(debug
, int, 0644);
39 #ifndef CONFIG_DYNAMIC_DEBUG
40 MODULE_PARM_DESC(debug
, "netif level (0=none,...,16=all), hw debug_mask (0x8XXXXXXX)");
42 MODULE_PARM_DESC(debug
, "netif level (0=none,...,16=all)");
43 #endif /* !CONFIG_DYNAMIC_DEBUG */
45 static struct workqueue_struct
*ice_wq
;
46 static const struct net_device_ops ice_netdev_safe_mode_ops
;
47 static const struct net_device_ops ice_netdev_ops
;
48 static int ice_vsi_open(struct ice_vsi
*vsi
);
50 static void ice_rebuild(struct ice_pf
*pf
, enum ice_reset_req reset_type
);
52 static void ice_vsi_release_all(struct ice_pf
*pf
);
55 * ice_get_tx_pending - returns number of Tx descriptors not processed
56 * @ring: the ring of descriptors
58 static u16
ice_get_tx_pending(struct ice_ring
*ring
)
62 head
= ring
->next_to_clean
;
63 tail
= ring
->next_to_use
;
66 return (head
< tail
) ?
67 tail
- head
: (tail
+ ring
->count
- head
);
72 * ice_check_for_hang_subtask - check for and recover hung queues
73 * @pf: pointer to PF struct
75 static void ice_check_for_hang_subtask(struct ice_pf
*pf
)
77 struct ice_vsi
*vsi
= NULL
;
83 ice_for_each_vsi(pf
, v
)
84 if (pf
->vsi
[v
] && pf
->vsi
[v
]->type
== ICE_VSI_PF
) {
89 if (!vsi
|| test_bit(__ICE_DOWN
, vsi
->state
))
92 if (!(vsi
->netdev
&& netif_carrier_ok(vsi
->netdev
)))
97 for (i
= 0; i
< vsi
->num_txq
; i
++) {
98 struct ice_ring
*tx_ring
= vsi
->tx_rings
[i
];
100 if (tx_ring
&& tx_ring
->desc
) {
101 /* If packet counter has not changed the queue is
102 * likely stalled, so force an interrupt for this
105 * prev_pkt would be negative if there was no
108 packets
= tx_ring
->stats
.pkts
& INT_MAX
;
109 if (tx_ring
->tx_stats
.prev_pkt
== packets
) {
110 /* Trigger sw interrupt to revive the queue */
111 ice_trigger_sw_intr(hw
, tx_ring
->q_vector
);
115 /* Memory barrier between read of packet count and call
116 * to ice_get_tx_pending()
119 tx_ring
->tx_stats
.prev_pkt
=
120 ice_get_tx_pending(tx_ring
) ? packets
: -1;
126 * ice_init_mac_fltr - Set initial MAC filters
127 * @pf: board private structure
129 * Set initial set of MAC filters for PF VSI; configure filters for permanent
130 * address and broadcast address. If an error is encountered, netdevice will be
133 static int ice_init_mac_fltr(struct ice_pf
*pf
)
135 enum ice_status status
;
136 u8 broadcast
[ETH_ALEN
];
139 vsi
= ice_get_main_vsi(pf
);
143 /* To add a MAC filter, first add the MAC to a list and then
144 * pass the list to ice_add_mac.
147 /* Add a unicast MAC filter so the VSI can get its packets */
148 status
= ice_vsi_cfg_mac_fltr(vsi
, vsi
->port_info
->mac
.perm_addr
, true);
152 /* VSI needs to receive broadcast traffic, so add the broadcast
153 * MAC address to the list as well.
155 eth_broadcast_addr(broadcast
);
156 status
= ice_vsi_cfg_mac_fltr(vsi
, broadcast
, true);
162 /* We aren't useful with no MAC filters, so unregister if we
165 if (status
&& vsi
->netdev
->reg_state
== NETREG_REGISTERED
) {
166 dev_err(ice_pf_to_dev(pf
), "Could not add MAC filters error %d. Unregistering device\n",
168 unregister_netdev(vsi
->netdev
);
169 free_netdev(vsi
->netdev
);
177 * ice_add_mac_to_sync_list - creates list of MAC addresses to be synced
178 * @netdev: the net device on which the sync is happening
179 * @addr: MAC address to sync
181 * This is a callback function which is called by the in kernel device sync
182 * functions (like __dev_uc_sync, __dev_mc_sync, etc). This function only
183 * populates the tmp_sync_list, which is later used by ice_add_mac to add the
184 * MAC filters from the hardware.
186 static int ice_add_mac_to_sync_list(struct net_device
*netdev
, const u8
*addr
)
188 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
189 struct ice_vsi
*vsi
= np
->vsi
;
191 if (ice_add_mac_to_list(vsi
, &vsi
->tmp_sync_list
, addr
))
198 * ice_add_mac_to_unsync_list - creates list of MAC addresses to be unsynced
199 * @netdev: the net device on which the unsync is happening
200 * @addr: MAC address to unsync
202 * This is a callback function which is called by the in kernel device unsync
203 * functions (like __dev_uc_unsync, __dev_mc_unsync, etc). This function only
204 * populates the tmp_unsync_list, which is later used by ice_remove_mac to
205 * delete the MAC filters from the hardware.
207 static int ice_add_mac_to_unsync_list(struct net_device
*netdev
, const u8
*addr
)
209 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
210 struct ice_vsi
*vsi
= np
->vsi
;
212 if (ice_add_mac_to_list(vsi
, &vsi
->tmp_unsync_list
, addr
))
219 * ice_vsi_fltr_changed - check if filter state changed
220 * @vsi: VSI to be checked
222 * returns true if filter state has changed, false otherwise.
224 static bool ice_vsi_fltr_changed(struct ice_vsi
*vsi
)
226 return test_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED
, vsi
->flags
) ||
227 test_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED
, vsi
->flags
) ||
228 test_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED
, vsi
->flags
);
232 * ice_cfg_promisc - Enable or disable promiscuous mode for a given PF
233 * @vsi: the VSI being configured
234 * @promisc_m: mask of promiscuous config bits
235 * @set_promisc: enable or disable promisc flag request
238 static int ice_cfg_promisc(struct ice_vsi
*vsi
, u8 promisc_m
, bool set_promisc
)
240 struct ice_hw
*hw
= &vsi
->back
->hw
;
241 enum ice_status status
= 0;
243 if (vsi
->type
!= ICE_VSI_PF
)
247 status
= ice_set_vlan_vsi_promisc(hw
, vsi
->idx
, promisc_m
,
251 status
= ice_set_vsi_promisc(hw
, vsi
->idx
, promisc_m
,
254 status
= ice_clear_vsi_promisc(hw
, vsi
->idx
, promisc_m
,
265 * ice_vsi_sync_fltr - Update the VSI filter list to the HW
266 * @vsi: ptr to the VSI
268 * Push any outstanding VSI filter changes through the AdminQ.
270 static int ice_vsi_sync_fltr(struct ice_vsi
*vsi
)
272 struct device
*dev
= ice_pf_to_dev(vsi
->back
);
273 struct net_device
*netdev
= vsi
->netdev
;
274 bool promisc_forced_on
= false;
275 struct ice_pf
*pf
= vsi
->back
;
276 struct ice_hw
*hw
= &pf
->hw
;
277 enum ice_status status
= 0;
278 u32 changed_flags
= 0;
285 while (test_and_set_bit(__ICE_CFG_BUSY
, vsi
->state
))
286 usleep_range(1000, 2000);
288 changed_flags
= vsi
->current_netdev_flags
^ vsi
->netdev
->flags
;
289 vsi
->current_netdev_flags
= vsi
->netdev
->flags
;
291 INIT_LIST_HEAD(&vsi
->tmp_sync_list
);
292 INIT_LIST_HEAD(&vsi
->tmp_unsync_list
);
294 if (ice_vsi_fltr_changed(vsi
)) {
295 clear_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED
, vsi
->flags
);
296 clear_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED
, vsi
->flags
);
297 clear_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED
, vsi
->flags
);
299 /* grab the netdev's addr_list_lock */
300 netif_addr_lock_bh(netdev
);
301 __dev_uc_sync(netdev
, ice_add_mac_to_sync_list
,
302 ice_add_mac_to_unsync_list
);
303 __dev_mc_sync(netdev
, ice_add_mac_to_sync_list
,
304 ice_add_mac_to_unsync_list
);
305 /* our temp lists are populated. release lock */
306 netif_addr_unlock_bh(netdev
);
309 /* Remove MAC addresses in the unsync list */
310 status
= ice_remove_mac(hw
, &vsi
->tmp_unsync_list
);
311 ice_free_fltr_list(dev
, &vsi
->tmp_unsync_list
);
313 netdev_err(netdev
, "Failed to delete MAC filters\n");
314 /* if we failed because of alloc failures, just bail */
315 if (status
== ICE_ERR_NO_MEMORY
) {
321 /* Add MAC addresses in the sync list */
322 status
= ice_add_mac(hw
, &vsi
->tmp_sync_list
);
323 ice_free_fltr_list(dev
, &vsi
->tmp_sync_list
);
324 /* If filter is added successfully or already exists, do not go into
325 * 'if' condition and report it as error. Instead continue processing
326 * rest of the function.
328 if (status
&& status
!= ICE_ERR_ALREADY_EXISTS
) {
329 netdev_err(netdev
, "Failed to add MAC filters\n");
330 /* If there is no more space for new umac filters, VSI
331 * should go into promiscuous mode. There should be some
332 * space reserved for promiscuous filters.
334 if (hw
->adminq
.sq_last_status
== ICE_AQ_RC_ENOSPC
&&
335 !test_and_set_bit(__ICE_FLTR_OVERFLOW_PROMISC
,
337 promisc_forced_on
= true;
338 netdev_warn(netdev
, "Reached MAC filter limit, forcing promisc mode on VSI %d\n",
345 /* check for changes in promiscuous modes */
346 if (changed_flags
& IFF_ALLMULTI
) {
347 if (vsi
->current_netdev_flags
& IFF_ALLMULTI
) {
349 promisc_m
= ICE_MCAST_VLAN_PROMISC_BITS
;
351 promisc_m
= ICE_MCAST_PROMISC_BITS
;
353 err
= ice_cfg_promisc(vsi
, promisc_m
, true);
355 netdev_err(netdev
, "Error setting Multicast promiscuous mode on VSI %i\n",
357 vsi
->current_netdev_flags
&= ~IFF_ALLMULTI
;
360 } else if (!(vsi
->current_netdev_flags
& IFF_ALLMULTI
)) {
362 promisc_m
= ICE_MCAST_VLAN_PROMISC_BITS
;
364 promisc_m
= ICE_MCAST_PROMISC_BITS
;
366 err
= ice_cfg_promisc(vsi
, promisc_m
, false);
368 netdev_err(netdev
, "Error clearing Multicast promiscuous mode on VSI %i\n",
370 vsi
->current_netdev_flags
|= IFF_ALLMULTI
;
376 if (((changed_flags
& IFF_PROMISC
) || promisc_forced_on
) ||
377 test_bit(ICE_VSI_FLAG_PROMISC_CHANGED
, vsi
->flags
)) {
378 clear_bit(ICE_VSI_FLAG_PROMISC_CHANGED
, vsi
->flags
);
379 if (vsi
->current_netdev_flags
& IFF_PROMISC
) {
380 /* Apply Rx filter rule to get traffic from wire */
381 if (!ice_is_dflt_vsi_in_use(pf
->first_sw
)) {
382 err
= ice_set_dflt_vsi(pf
->first_sw
, vsi
);
383 if (err
&& err
!= -EEXIST
) {
384 netdev_err(netdev
, "Error %d setting default VSI %i Rx rule\n",
386 vsi
->current_netdev_flags
&=
392 /* Clear Rx filter to remove traffic from wire */
393 if (ice_is_vsi_dflt_vsi(pf
->first_sw
, vsi
)) {
394 err
= ice_clear_dflt_vsi(pf
->first_sw
);
396 netdev_err(netdev
, "Error %d clearing default VSI %i Rx rule\n",
398 vsi
->current_netdev_flags
|=
408 set_bit(ICE_VSI_FLAG_PROMISC_CHANGED
, vsi
->flags
);
411 /* if something went wrong then set the changed flag so we try again */
412 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED
, vsi
->flags
);
413 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED
, vsi
->flags
);
415 clear_bit(__ICE_CFG_BUSY
, vsi
->state
);
420 * ice_sync_fltr_subtask - Sync the VSI filter list with HW
421 * @pf: board private structure
423 static void ice_sync_fltr_subtask(struct ice_pf
*pf
)
427 if (!pf
|| !(test_bit(ICE_FLAG_FLTR_SYNC
, pf
->flags
)))
430 clear_bit(ICE_FLAG_FLTR_SYNC
, pf
->flags
);
432 ice_for_each_vsi(pf
, v
)
433 if (pf
->vsi
[v
] && ice_vsi_fltr_changed(pf
->vsi
[v
]) &&
434 ice_vsi_sync_fltr(pf
->vsi
[v
])) {
435 /* come back and try again later */
436 set_bit(ICE_FLAG_FLTR_SYNC
, pf
->flags
);
442 * ice_pf_dis_all_vsi - Pause all VSIs on a PF
444 * @locked: is the rtnl_lock already held
446 static void ice_pf_dis_all_vsi(struct ice_pf
*pf
, bool locked
)
450 ice_for_each_vsi(pf
, v
)
452 ice_dis_vsi(pf
->vsi
[v
], locked
);
456 * ice_prepare_for_reset - prep for the core to reset
457 * @pf: board private structure
459 * Inform or close all dependent features in prep for reset.
462 ice_prepare_for_reset(struct ice_pf
*pf
)
464 struct ice_hw
*hw
= &pf
->hw
;
467 /* already prepared for reset */
468 if (test_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
))
471 /* Notify VFs of impending reset */
472 if (ice_check_sq_alive(hw
, &hw
->mailboxq
))
473 ice_vc_notify_reset(pf
);
475 /* Disable VFs until reset is completed */
476 ice_for_each_vf(pf
, i
)
477 ice_set_vf_state_qs_dis(&pf
->vf
[i
]);
479 /* clear SW filtering DB */
480 ice_clear_hw_tbls(hw
);
481 /* disable the VSIs and their queues that are not already DOWN */
482 ice_pf_dis_all_vsi(pf
, false);
485 ice_sched_clear_port(hw
->port_info
);
487 ice_shutdown_all_ctrlq(hw
);
489 set_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
);
493 * ice_do_reset - Initiate one of many types of resets
494 * @pf: board private structure
495 * @reset_type: reset type requested
496 * before this function was called.
498 static void ice_do_reset(struct ice_pf
*pf
, enum ice_reset_req reset_type
)
500 struct device
*dev
= ice_pf_to_dev(pf
);
501 struct ice_hw
*hw
= &pf
->hw
;
503 dev_dbg(dev
, "reset_type 0x%x requested\n", reset_type
);
504 WARN_ON(in_interrupt());
506 ice_prepare_for_reset(pf
);
508 /* trigger the reset */
509 if (ice_reset(hw
, reset_type
)) {
510 dev_err(dev
, "reset %d failed\n", reset_type
);
511 set_bit(__ICE_RESET_FAILED
, pf
->state
);
512 clear_bit(__ICE_RESET_OICR_RECV
, pf
->state
);
513 clear_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
);
514 clear_bit(__ICE_PFR_REQ
, pf
->state
);
515 clear_bit(__ICE_CORER_REQ
, pf
->state
);
516 clear_bit(__ICE_GLOBR_REQ
, pf
->state
);
520 /* PFR is a bit of a special case because it doesn't result in an OICR
521 * interrupt. So for PFR, rebuild after the reset and clear the reset-
522 * associated state bits.
524 if (reset_type
== ICE_RESET_PFR
) {
526 ice_rebuild(pf
, reset_type
);
527 clear_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
);
528 clear_bit(__ICE_PFR_REQ
, pf
->state
);
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 ice_reset_all_vfs(pf
, true);
585 /* No pending resets to finish processing. Check for new resets */
586 if (test_bit(__ICE_PFR_REQ
, pf
->state
))
587 reset_type
= ICE_RESET_PFR
;
588 if (test_bit(__ICE_CORER_REQ
, pf
->state
))
589 reset_type
= ICE_RESET_CORER
;
590 if (test_bit(__ICE_GLOBR_REQ
, pf
->state
))
591 reset_type
= ICE_RESET_GLOBR
;
592 /* If no valid reset type requested just return */
593 if (reset_type
== ICE_RESET_INVAL
)
596 /* reset if not already down or busy */
597 if (!test_bit(__ICE_DOWN
, pf
->state
) &&
598 !test_bit(__ICE_CFG_BUSY
, pf
->state
)) {
599 ice_do_reset(pf
, reset_type
);
604 * ice_print_topo_conflict - print topology conflict message
605 * @vsi: the VSI whose topology status is being checked
607 static void ice_print_topo_conflict(struct ice_vsi
*vsi
)
609 switch (vsi
->port_info
->phy
.link_info
.topo_media_conflict
) {
610 case ICE_AQ_LINK_TOPO_CONFLICT
:
611 case ICE_AQ_LINK_MEDIA_CONFLICT
:
612 case ICE_AQ_LINK_TOPO_UNREACH_PRT
:
613 case ICE_AQ_LINK_TOPO_UNDRUTIL_PRT
:
614 case ICE_AQ_LINK_TOPO_UNDRUTIL_MEDIA
:
615 netdev_info(vsi
->netdev
, "Possible mis-configuration of the Ethernet port detected, please use the Intel(R) Ethernet Port Configuration Tool application to address the issue.\n");
617 case ICE_AQ_LINK_TOPO_UNSUPP_MEDIA
:
618 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");
626 * ice_print_link_msg - print link up or down message
627 * @vsi: the VSI whose link status is being queried
628 * @isup: boolean for if the link is now up or down
630 void ice_print_link_msg(struct ice_vsi
*vsi
, bool isup
)
632 struct ice_aqc_get_phy_caps_data
*caps
;
633 enum ice_status status
;
643 if (vsi
->current_isup
== isup
)
646 vsi
->current_isup
= isup
;
649 netdev_info(vsi
->netdev
, "NIC Link is Down\n");
653 switch (vsi
->port_info
->phy
.link_info
.link_speed
) {
654 case ICE_AQ_LINK_SPEED_100GB
:
657 case ICE_AQ_LINK_SPEED_50GB
:
660 case ICE_AQ_LINK_SPEED_40GB
:
663 case ICE_AQ_LINK_SPEED_25GB
:
666 case ICE_AQ_LINK_SPEED_20GB
:
669 case ICE_AQ_LINK_SPEED_10GB
:
672 case ICE_AQ_LINK_SPEED_5GB
:
675 case ICE_AQ_LINK_SPEED_2500MB
:
678 case ICE_AQ_LINK_SPEED_1000MB
:
681 case ICE_AQ_LINK_SPEED_100MB
:
689 switch (vsi
->port_info
->fc
.current_mode
) {
693 case ICE_FC_TX_PAUSE
:
696 case ICE_FC_RX_PAUSE
:
707 /* Get FEC mode based on negotiated link info */
708 switch (vsi
->port_info
->phy
.link_info
.fec_info
) {
709 case ICE_AQ_LINK_25G_RS_528_FEC_EN
:
710 case ICE_AQ_LINK_25G_RS_544_FEC_EN
:
713 case ICE_AQ_LINK_25G_KR_FEC_EN
:
714 fec
= "FC-FEC/BASE-R";
721 /* check if autoneg completed, might be false due to not supported */
722 if (vsi
->port_info
->phy
.link_info
.an_info
& ICE_AQ_AN_COMPLETED
)
727 /* Get FEC mode requested based on PHY caps last SW configuration */
728 caps
= kzalloc(sizeof(*caps
), GFP_KERNEL
);
734 status
= ice_aq_get_phy_caps(vsi
->port_info
, false,
735 ICE_AQC_REPORT_SW_CFG
, caps
, NULL
);
737 netdev_info(vsi
->netdev
, "Get phy capability failed.\n");
739 if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_528_REQ
||
740 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_RS_544_REQ
)
742 else if (caps
->link_fec_options
& ICE_AQC_PHY_FEC_10G_KR_40G_KR4_REQ
||
743 caps
->link_fec_options
& ICE_AQC_PHY_FEC_25G_KR_REQ
)
744 fec_req
= "FC-FEC/BASE-R";
751 netdev_info(vsi
->netdev
, "NIC Link is up %sbps Full Duplex, Requested FEC: %s, Negotiated FEC: %s, Autoneg: %s, Flow Control: %s\n",
752 speed
, fec_req
, fec
, an
, fc
);
753 ice_print_topo_conflict(vsi
);
757 * ice_vsi_link_event - update the VSI's netdev
758 * @vsi: the VSI on which the link event occurred
759 * @link_up: whether or not the VSI needs to be set up or down
761 static void ice_vsi_link_event(struct ice_vsi
*vsi
, bool link_up
)
766 if (test_bit(__ICE_DOWN
, vsi
->state
) || !vsi
->netdev
)
769 if (vsi
->type
== ICE_VSI_PF
) {
770 if (link_up
== netif_carrier_ok(vsi
->netdev
))
774 netif_carrier_on(vsi
->netdev
);
775 netif_tx_wake_all_queues(vsi
->netdev
);
777 netif_carrier_off(vsi
->netdev
);
778 netif_tx_stop_all_queues(vsi
->netdev
);
784 * ice_link_event - process the link event
785 * @pf: PF that the link event is associated with
786 * @pi: port_info for the port that the link event is associated with
787 * @link_up: true if the physical link is up and false if it is down
788 * @link_speed: current link speed received from the link event
790 * Returns 0 on success and negative on failure
793 ice_link_event(struct ice_pf
*pf
, struct ice_port_info
*pi
, bool link_up
,
796 struct device
*dev
= ice_pf_to_dev(pf
);
797 struct ice_phy_info
*phy_info
;
804 phy_info
->link_info_old
= phy_info
->link_info
;
806 old_link
= !!(phy_info
->link_info_old
.link_info
& ICE_AQ_LINK_UP
);
807 old_link_speed
= phy_info
->link_info_old
.link_speed
;
809 /* update the link info structures and re-enable link events,
810 * don't bail on failure due to other book keeping needed
812 result
= ice_update_link_info(pi
);
814 dev_dbg(dev
, "Failed to update link status and re-enable link events for port %d\n",
817 /* if the old link up/down and speed is the same as the new */
818 if (link_up
== old_link
&& link_speed
== old_link_speed
)
821 vsi
= ice_get_main_vsi(pf
);
822 if (!vsi
|| !vsi
->port_info
)
825 /* turn off PHY if media was removed */
826 if (!test_bit(ICE_FLAG_NO_MEDIA
, pf
->flags
) &&
827 !(pi
->phy
.link_info
.link_info
& ICE_AQ_MEDIA_AVAILABLE
)) {
828 set_bit(ICE_FLAG_NO_MEDIA
, pf
->flags
);
830 result
= ice_aq_set_link_restart_an(pi
, false, NULL
);
832 dev_dbg(dev
, "Failed to set link down, VSI %d error %d\n",
833 vsi
->vsi_num
, result
);
839 ice_vsi_link_event(vsi
, link_up
);
840 ice_print_link_msg(vsi
, link_up
);
842 ice_vc_notify_link_state(pf
);
848 * ice_watchdog_subtask - periodic tasks not using event driven scheduling
849 * @pf: board private structure
851 static void ice_watchdog_subtask(struct ice_pf
*pf
)
855 /* if interface is down do nothing */
856 if (test_bit(__ICE_DOWN
, pf
->state
) ||
857 test_bit(__ICE_CFG_BUSY
, pf
->state
))
860 /* make sure we don't do these things too often */
861 if (time_before(jiffies
,
862 pf
->serv_tmr_prev
+ pf
->serv_tmr_period
))
865 pf
->serv_tmr_prev
= jiffies
;
867 /* Update the stats for active netdevs so the network stack
868 * can look at updated numbers whenever it cares to
870 ice_update_pf_stats(pf
);
871 ice_for_each_vsi(pf
, i
)
872 if (pf
->vsi
[i
] && pf
->vsi
[i
]->netdev
)
873 ice_update_vsi_stats(pf
->vsi
[i
]);
877 * ice_init_link_events - enable/initialize link events
878 * @pi: pointer to the port_info instance
880 * Returns -EIO on failure, 0 on success
882 static int ice_init_link_events(struct ice_port_info
*pi
)
886 mask
= ~((u16
)(ICE_AQ_LINK_EVENT_UPDOWN
| ICE_AQ_LINK_EVENT_MEDIA_NA
|
887 ICE_AQ_LINK_EVENT_MODULE_QUAL_FAIL
));
889 if (ice_aq_set_event_mask(pi
->hw
, pi
->lport
, mask
, NULL
)) {
890 dev_dbg(ice_hw_to_dev(pi
->hw
), "Failed to set link event mask for port %d\n",
895 if (ice_aq_get_link_info(pi
, true, NULL
, NULL
)) {
896 dev_dbg(ice_hw_to_dev(pi
->hw
), "Failed to enable link events for port %d\n",
905 * ice_handle_link_event - handle link event via ARQ
906 * @pf: PF that the link event is associated with
907 * @event: event structure containing link status info
910 ice_handle_link_event(struct ice_pf
*pf
, struct ice_rq_event_info
*event
)
912 struct ice_aqc_get_link_status_data
*link_data
;
913 struct ice_port_info
*port_info
;
916 link_data
= (struct ice_aqc_get_link_status_data
*)event
->msg_buf
;
917 port_info
= pf
->hw
.port_info
;
921 status
= ice_link_event(pf
, port_info
,
922 !!(link_data
->link_info
& ICE_AQ_LINK_UP
),
923 le16_to_cpu(link_data
->link_speed
));
925 dev_dbg(ice_pf_to_dev(pf
), "Could not process link event, error %d\n",
932 * __ice_clean_ctrlq - helper function to clean controlq rings
933 * @pf: ptr to struct ice_pf
934 * @q_type: specific Control queue type
936 static int __ice_clean_ctrlq(struct ice_pf
*pf
, enum ice_ctl_q q_type
)
938 struct device
*dev
= ice_pf_to_dev(pf
);
939 struct ice_rq_event_info event
;
940 struct ice_hw
*hw
= &pf
->hw
;
941 struct ice_ctl_q_info
*cq
;
946 /* Do not clean control queue if/when PF reset fails */
947 if (test_bit(__ICE_RESET_FAILED
, pf
->state
))
951 case ICE_CTL_Q_ADMIN
:
955 case ICE_CTL_Q_MAILBOX
:
960 dev_warn(dev
, "Unknown control queue type 0x%x\n", q_type
);
964 /* check for error indications - PF_xx_AxQLEN register layout for
965 * FW/MBX/SB are identical so just use defines for PF_FW_AxQLEN.
967 val
= rd32(hw
, cq
->rq
.len
);
968 if (val
& (PF_FW_ARQLEN_ARQVFE_M
| PF_FW_ARQLEN_ARQOVFL_M
|
969 PF_FW_ARQLEN_ARQCRIT_M
)) {
971 if (val
& PF_FW_ARQLEN_ARQVFE_M
)
972 dev_dbg(dev
, "%s Receive Queue VF Error detected\n",
974 if (val
& PF_FW_ARQLEN_ARQOVFL_M
) {
975 dev_dbg(dev
, "%s Receive Queue Overflow Error detected\n",
978 if (val
& PF_FW_ARQLEN_ARQCRIT_M
)
979 dev_dbg(dev
, "%s Receive Queue Critical Error detected\n",
981 val
&= ~(PF_FW_ARQLEN_ARQVFE_M
| PF_FW_ARQLEN_ARQOVFL_M
|
982 PF_FW_ARQLEN_ARQCRIT_M
);
984 wr32(hw
, cq
->rq
.len
, val
);
987 val
= rd32(hw
, cq
->sq
.len
);
988 if (val
& (PF_FW_ATQLEN_ATQVFE_M
| PF_FW_ATQLEN_ATQOVFL_M
|
989 PF_FW_ATQLEN_ATQCRIT_M
)) {
991 if (val
& PF_FW_ATQLEN_ATQVFE_M
)
992 dev_dbg(dev
, "%s Send Queue VF Error detected\n",
994 if (val
& PF_FW_ATQLEN_ATQOVFL_M
) {
995 dev_dbg(dev
, "%s Send Queue Overflow Error detected\n",
998 if (val
& PF_FW_ATQLEN_ATQCRIT_M
)
999 dev_dbg(dev
, "%s Send Queue Critical Error detected\n",
1001 val
&= ~(PF_FW_ATQLEN_ATQVFE_M
| PF_FW_ATQLEN_ATQOVFL_M
|
1002 PF_FW_ATQLEN_ATQCRIT_M
);
1004 wr32(hw
, cq
->sq
.len
, val
);
1007 event
.buf_len
= cq
->rq_buf_size
;
1008 event
.msg_buf
= kzalloc(event
.buf_len
, GFP_KERNEL
);
1013 enum ice_status ret
;
1016 ret
= ice_clean_rq_elem(hw
, cq
, &event
, &pending
);
1017 if (ret
== ICE_ERR_AQ_NO_WORK
)
1020 dev_err(dev
, "%s Receive Queue event error %d\n", qtype
,
1025 opcode
= le16_to_cpu(event
.desc
.opcode
);
1028 case ice_aqc_opc_get_link_status
:
1029 if (ice_handle_link_event(pf
, &event
))
1030 dev_err(dev
, "Could not handle link event\n");
1032 case ice_aqc_opc_event_lan_overflow
:
1033 ice_vf_lan_overflow_event(pf
, &event
);
1035 case ice_mbx_opc_send_msg_to_pf
:
1036 ice_vc_process_vf_msg(pf
, &event
);
1038 case ice_aqc_opc_fw_logging
:
1039 ice_output_fw_log(hw
, &event
.desc
, event
.msg_buf
);
1041 case ice_aqc_opc_lldp_set_mib_change
:
1042 ice_dcb_process_lldp_set_mib_change(pf
, &event
);
1045 dev_dbg(dev
, "%s Receive Queue unknown event 0x%04x ignored\n",
1049 } while (pending
&& (i
++ < ICE_DFLT_IRQ_WORK
));
1051 kfree(event
.msg_buf
);
1053 return pending
&& (i
== ICE_DFLT_IRQ_WORK
);
1057 * ice_ctrlq_pending - check if there is a difference between ntc and ntu
1058 * @hw: pointer to hardware info
1059 * @cq: control queue information
1061 * returns true if there are pending messages in a queue, false if there aren't
1063 static bool ice_ctrlq_pending(struct ice_hw
*hw
, struct ice_ctl_q_info
*cq
)
1067 ntu
= (u16
)(rd32(hw
, cq
->rq
.head
) & cq
->rq
.head_mask
);
1068 return cq
->rq
.next_to_clean
!= ntu
;
1072 * ice_clean_adminq_subtask - clean the AdminQ rings
1073 * @pf: board private structure
1075 static void ice_clean_adminq_subtask(struct ice_pf
*pf
)
1077 struct ice_hw
*hw
= &pf
->hw
;
1079 if (!test_bit(__ICE_ADMINQ_EVENT_PENDING
, pf
->state
))
1082 if (__ice_clean_ctrlq(pf
, ICE_CTL_Q_ADMIN
))
1085 clear_bit(__ICE_ADMINQ_EVENT_PENDING
, pf
->state
);
1087 /* There might be a situation where new messages arrive to a control
1088 * queue between processing the last message and clearing the
1089 * EVENT_PENDING bit. So before exiting, check queue head again (using
1090 * ice_ctrlq_pending) and process new messages if any.
1092 if (ice_ctrlq_pending(hw
, &hw
->adminq
))
1093 __ice_clean_ctrlq(pf
, ICE_CTL_Q_ADMIN
);
1099 * ice_clean_mailboxq_subtask - clean the MailboxQ rings
1100 * @pf: board private structure
1102 static void ice_clean_mailboxq_subtask(struct ice_pf
*pf
)
1104 struct ice_hw
*hw
= &pf
->hw
;
1106 if (!test_bit(__ICE_MAILBOXQ_EVENT_PENDING
, pf
->state
))
1109 if (__ice_clean_ctrlq(pf
, ICE_CTL_Q_MAILBOX
))
1112 clear_bit(__ICE_MAILBOXQ_EVENT_PENDING
, pf
->state
);
1114 if (ice_ctrlq_pending(hw
, &hw
->mailboxq
))
1115 __ice_clean_ctrlq(pf
, ICE_CTL_Q_MAILBOX
);
1121 * ice_service_task_schedule - schedule the service task to wake up
1122 * @pf: board private structure
1124 * If not already scheduled, this puts the task into the work queue.
1126 static void ice_service_task_schedule(struct ice_pf
*pf
)
1128 if (!test_bit(__ICE_SERVICE_DIS
, pf
->state
) &&
1129 !test_and_set_bit(__ICE_SERVICE_SCHED
, pf
->state
) &&
1130 !test_bit(__ICE_NEEDS_RESTART
, pf
->state
))
1131 queue_work(ice_wq
, &pf
->serv_task
);
1135 * ice_service_task_complete - finish up the service task
1136 * @pf: board private structure
1138 static void ice_service_task_complete(struct ice_pf
*pf
)
1140 WARN_ON(!test_bit(__ICE_SERVICE_SCHED
, pf
->state
));
1142 /* force memory (pf->state) to sync before next service task */
1143 smp_mb__before_atomic();
1144 clear_bit(__ICE_SERVICE_SCHED
, pf
->state
);
1148 * ice_service_task_stop - stop service task and cancel works
1149 * @pf: board private structure
1151 static void ice_service_task_stop(struct ice_pf
*pf
)
1153 set_bit(__ICE_SERVICE_DIS
, pf
->state
);
1155 if (pf
->serv_tmr
.function
)
1156 del_timer_sync(&pf
->serv_tmr
);
1157 if (pf
->serv_task
.func
)
1158 cancel_work_sync(&pf
->serv_task
);
1160 clear_bit(__ICE_SERVICE_SCHED
, pf
->state
);
1164 * ice_service_task_restart - restart service task and schedule works
1165 * @pf: board private structure
1167 * This function is needed for suspend and resume works (e.g WoL scenario)
1169 static void ice_service_task_restart(struct ice_pf
*pf
)
1171 clear_bit(__ICE_SERVICE_DIS
, pf
->state
);
1172 ice_service_task_schedule(pf
);
1176 * ice_service_timer - timer callback to schedule service task
1177 * @t: pointer to timer_list
1179 static void ice_service_timer(struct timer_list
*t
)
1181 struct ice_pf
*pf
= from_timer(pf
, t
, serv_tmr
);
1183 mod_timer(&pf
->serv_tmr
, round_jiffies(pf
->serv_tmr_period
+ jiffies
));
1184 ice_service_task_schedule(pf
);
1188 * ice_handle_mdd_event - handle malicious driver detect event
1189 * @pf: pointer to the PF structure
1191 * Called from service task. OICR interrupt handler indicates MDD event.
1192 * VF MDD logging is guarded by net_ratelimit. Additional PF and VF log
1193 * messages are wrapped by netif_msg_[rx|tx]_err. Since VF Rx MDD events
1194 * disable the queue, the PF can be configured to reset the VF using ethtool
1195 * private flag mdd-auto-reset-vf.
1197 static void ice_handle_mdd_event(struct ice_pf
*pf
)
1199 struct device
*dev
= ice_pf_to_dev(pf
);
1200 struct ice_hw
*hw
= &pf
->hw
;
1204 if (!test_and_clear_bit(__ICE_MDD_EVENT_PENDING
, pf
->state
)) {
1205 /* Since the VF MDD event logging is rate limited, check if
1206 * there are pending MDD events.
1208 ice_print_vfs_mdd_events(pf
);
1212 /* find what triggered an MDD event */
1213 reg
= rd32(hw
, GL_MDET_TX_PQM
);
1214 if (reg
& GL_MDET_TX_PQM_VALID_M
) {
1215 u8 pf_num
= (reg
& GL_MDET_TX_PQM_PF_NUM_M
) >>
1216 GL_MDET_TX_PQM_PF_NUM_S
;
1217 u16 vf_num
= (reg
& GL_MDET_TX_PQM_VF_NUM_M
) >>
1218 GL_MDET_TX_PQM_VF_NUM_S
;
1219 u8 event
= (reg
& GL_MDET_TX_PQM_MAL_TYPE_M
) >>
1220 GL_MDET_TX_PQM_MAL_TYPE_S
;
1221 u16 queue
= ((reg
& GL_MDET_TX_PQM_QNUM_M
) >>
1222 GL_MDET_TX_PQM_QNUM_S
);
1224 if (netif_msg_tx_err(pf
))
1225 dev_info(dev
, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1226 event
, queue
, pf_num
, vf_num
);
1227 wr32(hw
, GL_MDET_TX_PQM
, 0xffffffff);
1230 reg
= rd32(hw
, GL_MDET_TX_TCLAN
);
1231 if (reg
& GL_MDET_TX_TCLAN_VALID_M
) {
1232 u8 pf_num
= (reg
& GL_MDET_TX_TCLAN_PF_NUM_M
) >>
1233 GL_MDET_TX_TCLAN_PF_NUM_S
;
1234 u16 vf_num
= (reg
& GL_MDET_TX_TCLAN_VF_NUM_M
) >>
1235 GL_MDET_TX_TCLAN_VF_NUM_S
;
1236 u8 event
= (reg
& GL_MDET_TX_TCLAN_MAL_TYPE_M
) >>
1237 GL_MDET_TX_TCLAN_MAL_TYPE_S
;
1238 u16 queue
= ((reg
& GL_MDET_TX_TCLAN_QNUM_M
) >>
1239 GL_MDET_TX_TCLAN_QNUM_S
);
1241 if (netif_msg_tx_err(pf
))
1242 dev_info(dev
, "Malicious Driver Detection event %d on TX queue %d PF# %d VF# %d\n",
1243 event
, queue
, pf_num
, vf_num
);
1244 wr32(hw
, GL_MDET_TX_TCLAN
, 0xffffffff);
1247 reg
= rd32(hw
, GL_MDET_RX
);
1248 if (reg
& GL_MDET_RX_VALID_M
) {
1249 u8 pf_num
= (reg
& GL_MDET_RX_PF_NUM_M
) >>
1250 GL_MDET_RX_PF_NUM_S
;
1251 u16 vf_num
= (reg
& GL_MDET_RX_VF_NUM_M
) >>
1252 GL_MDET_RX_VF_NUM_S
;
1253 u8 event
= (reg
& GL_MDET_RX_MAL_TYPE_M
) >>
1254 GL_MDET_RX_MAL_TYPE_S
;
1255 u16 queue
= ((reg
& GL_MDET_RX_QNUM_M
) >>
1258 if (netif_msg_rx_err(pf
))
1259 dev_info(dev
, "Malicious Driver Detection event %d on RX queue %d PF# %d VF# %d\n",
1260 event
, queue
, pf_num
, vf_num
);
1261 wr32(hw
, GL_MDET_RX
, 0xffffffff);
1264 /* check to see if this PF caused an MDD event */
1265 reg
= rd32(hw
, PF_MDET_TX_PQM
);
1266 if (reg
& PF_MDET_TX_PQM_VALID_M
) {
1267 wr32(hw
, PF_MDET_TX_PQM
, 0xFFFF);
1268 if (netif_msg_tx_err(pf
))
1269 dev_info(dev
, "Malicious Driver Detection event TX_PQM detected on PF\n");
1272 reg
= rd32(hw
, PF_MDET_TX_TCLAN
);
1273 if (reg
& PF_MDET_TX_TCLAN_VALID_M
) {
1274 wr32(hw
, PF_MDET_TX_TCLAN
, 0xFFFF);
1275 if (netif_msg_tx_err(pf
))
1276 dev_info(dev
, "Malicious Driver Detection event TX_TCLAN detected on PF\n");
1279 reg
= rd32(hw
, PF_MDET_RX
);
1280 if (reg
& PF_MDET_RX_VALID_M
) {
1281 wr32(hw
, PF_MDET_RX
, 0xFFFF);
1282 if (netif_msg_rx_err(pf
))
1283 dev_info(dev
, "Malicious Driver Detection event RX detected on PF\n");
1286 /* Check to see if one of the VFs caused an MDD event, and then
1287 * increment counters and set print pending
1289 ice_for_each_vf(pf
, i
) {
1290 struct ice_vf
*vf
= &pf
->vf
[i
];
1292 reg
= rd32(hw
, VP_MDET_TX_PQM(i
));
1293 if (reg
& VP_MDET_TX_PQM_VALID_M
) {
1294 wr32(hw
, VP_MDET_TX_PQM(i
), 0xFFFF);
1295 vf
->mdd_tx_events
.count
++;
1296 set_bit(__ICE_MDD_VF_PRINT_PENDING
, pf
->state
);
1297 if (netif_msg_tx_err(pf
))
1298 dev_info(dev
, "Malicious Driver Detection event TX_PQM detected on VF %d\n",
1302 reg
= rd32(hw
, VP_MDET_TX_TCLAN(i
));
1303 if (reg
& VP_MDET_TX_TCLAN_VALID_M
) {
1304 wr32(hw
, VP_MDET_TX_TCLAN(i
), 0xFFFF);
1305 vf
->mdd_tx_events
.count
++;
1306 set_bit(__ICE_MDD_VF_PRINT_PENDING
, pf
->state
);
1307 if (netif_msg_tx_err(pf
))
1308 dev_info(dev
, "Malicious Driver Detection event TX_TCLAN detected on VF %d\n",
1312 reg
= rd32(hw
, VP_MDET_TX_TDPU(i
));
1313 if (reg
& VP_MDET_TX_TDPU_VALID_M
) {
1314 wr32(hw
, VP_MDET_TX_TDPU(i
), 0xFFFF);
1315 vf
->mdd_tx_events
.count
++;
1316 set_bit(__ICE_MDD_VF_PRINT_PENDING
, pf
->state
);
1317 if (netif_msg_tx_err(pf
))
1318 dev_info(dev
, "Malicious Driver Detection event TX_TDPU detected on VF %d\n",
1322 reg
= rd32(hw
, VP_MDET_RX(i
));
1323 if (reg
& VP_MDET_RX_VALID_M
) {
1324 wr32(hw
, VP_MDET_RX(i
), 0xFFFF);
1325 vf
->mdd_rx_events
.count
++;
1326 set_bit(__ICE_MDD_VF_PRINT_PENDING
, pf
->state
);
1327 if (netif_msg_rx_err(pf
))
1328 dev_info(dev
, "Malicious Driver Detection event RX detected on VF %d\n",
1331 /* Since the queue is disabled on VF Rx MDD events, the
1332 * PF can be configured to reset the VF through ethtool
1333 * private flag mdd-auto-reset-vf.
1335 if (test_bit(ICE_FLAG_MDD_AUTO_RESET_VF
, pf
->flags
))
1336 ice_reset_vf(&pf
->vf
[i
], false);
1340 ice_print_vfs_mdd_events(pf
);
1344 * ice_force_phys_link_state - Force the physical link state
1345 * @vsi: VSI to force the physical link state to up/down
1346 * @link_up: true/false indicates to set the physical link to up/down
1348 * Force the physical link state by getting the current PHY capabilities from
1349 * hardware and setting the PHY config based on the determined capabilities. If
1350 * link changes a link event will be triggered because both the Enable Automatic
1351 * Link Update and LESM Enable bits are set when setting the PHY capabilities.
1353 * Returns 0 on success, negative on failure
1355 static int ice_force_phys_link_state(struct ice_vsi
*vsi
, bool link_up
)
1357 struct ice_aqc_get_phy_caps_data
*pcaps
;
1358 struct ice_aqc_set_phy_cfg_data
*cfg
;
1359 struct ice_port_info
*pi
;
1363 if (!vsi
|| !vsi
->port_info
|| !vsi
->back
)
1365 if (vsi
->type
!= ICE_VSI_PF
)
1368 dev
= ice_pf_to_dev(vsi
->back
);
1370 pi
= vsi
->port_info
;
1372 pcaps
= kzalloc(sizeof(*pcaps
), GFP_KERNEL
);
1376 retcode
= ice_aq_get_phy_caps(pi
, false, ICE_AQC_REPORT_SW_CFG
, pcaps
,
1379 dev_err(dev
, "Failed to get phy capabilities, VSI %d error %d\n",
1380 vsi
->vsi_num
, retcode
);
1385 /* No change in link */
1386 if (link_up
== !!(pcaps
->caps
& ICE_AQC_PHY_EN_LINK
) &&
1387 link_up
== !!(pi
->phy
.link_info
.link_info
& ICE_AQ_LINK_UP
))
1390 cfg
= kzalloc(sizeof(*cfg
), GFP_KERNEL
);
1396 cfg
->phy_type_low
= pcaps
->phy_type_low
;
1397 cfg
->phy_type_high
= pcaps
->phy_type_high
;
1398 cfg
->caps
= pcaps
->caps
| ICE_AQ_PHY_ENA_AUTO_LINK_UPDT
;
1399 cfg
->low_power_ctrl
= pcaps
->low_power_ctrl
;
1400 cfg
->eee_cap
= pcaps
->eee_cap
;
1401 cfg
->eeer_value
= pcaps
->eeer_value
;
1402 cfg
->link_fec_opt
= pcaps
->link_fec_options
;
1404 cfg
->caps
|= ICE_AQ_PHY_ENA_LINK
;
1406 cfg
->caps
&= ~ICE_AQ_PHY_ENA_LINK
;
1408 retcode
= ice_aq_set_phy_cfg(&vsi
->back
->hw
, pi
->lport
, cfg
, NULL
);
1410 dev_err(dev
, "Failed to set phy config, VSI %d error %d\n",
1411 vsi
->vsi_num
, retcode
);
1422 * ice_check_media_subtask - Check for media; bring link up if detected.
1423 * @pf: pointer to PF struct
1425 static void ice_check_media_subtask(struct ice_pf
*pf
)
1427 struct ice_port_info
*pi
;
1428 struct ice_vsi
*vsi
;
1431 vsi
= ice_get_main_vsi(pf
);
1435 /* No need to check for media if it's already present or the interface
1438 if (!test_bit(ICE_FLAG_NO_MEDIA
, pf
->flags
) ||
1439 test_bit(__ICE_DOWN
, vsi
->state
))
1442 /* Refresh link info and check if media is present */
1443 pi
= vsi
->port_info
;
1444 err
= ice_update_link_info(pi
);
1448 if (pi
->phy
.link_info
.link_info
& ICE_AQ_MEDIA_AVAILABLE
) {
1449 err
= ice_force_phys_link_state(vsi
, true);
1452 clear_bit(ICE_FLAG_NO_MEDIA
, pf
->flags
);
1454 /* A Link Status Event will be generated; the event handler
1455 * will complete bringing the interface up
1461 * ice_service_task - manage and run subtasks
1462 * @work: pointer to work_struct contained by the PF struct
1464 static void ice_service_task(struct work_struct
*work
)
1466 struct ice_pf
*pf
= container_of(work
, struct ice_pf
, serv_task
);
1467 unsigned long start_time
= jiffies
;
1471 /* process reset requests first */
1472 ice_reset_subtask(pf
);
1474 /* bail if a reset/recovery cycle is pending or rebuild failed */
1475 if (ice_is_reset_in_progress(pf
->state
) ||
1476 test_bit(__ICE_SUSPENDED
, pf
->state
) ||
1477 test_bit(__ICE_NEEDS_RESTART
, pf
->state
)) {
1478 ice_service_task_complete(pf
);
1482 ice_clean_adminq_subtask(pf
);
1483 ice_check_media_subtask(pf
);
1484 ice_check_for_hang_subtask(pf
);
1485 ice_sync_fltr_subtask(pf
);
1486 ice_handle_mdd_event(pf
);
1487 ice_watchdog_subtask(pf
);
1489 if (ice_is_safe_mode(pf
)) {
1490 ice_service_task_complete(pf
);
1494 ice_process_vflr_event(pf
);
1495 ice_clean_mailboxq_subtask(pf
);
1497 /* Clear __ICE_SERVICE_SCHED flag to allow scheduling next event */
1498 ice_service_task_complete(pf
);
1500 /* If the tasks have taken longer than one service timer period
1501 * or there is more work to be done, reset the service timer to
1502 * schedule the service task now.
1504 if (time_after(jiffies
, (start_time
+ pf
->serv_tmr_period
)) ||
1505 test_bit(__ICE_MDD_EVENT_PENDING
, pf
->state
) ||
1506 test_bit(__ICE_VFLR_EVENT_PENDING
, pf
->state
) ||
1507 test_bit(__ICE_MAILBOXQ_EVENT_PENDING
, pf
->state
) ||
1508 test_bit(__ICE_ADMINQ_EVENT_PENDING
, pf
->state
))
1509 mod_timer(&pf
->serv_tmr
, jiffies
);
1513 * ice_set_ctrlq_len - helper function to set controlq length
1514 * @hw: pointer to the HW instance
1516 static void ice_set_ctrlq_len(struct ice_hw
*hw
)
1518 hw
->adminq
.num_rq_entries
= ICE_AQ_LEN
;
1519 hw
->adminq
.num_sq_entries
= ICE_AQ_LEN
;
1520 hw
->adminq
.rq_buf_size
= ICE_AQ_MAX_BUF_LEN
;
1521 hw
->adminq
.sq_buf_size
= ICE_AQ_MAX_BUF_LEN
;
1522 hw
->mailboxq
.num_rq_entries
= PF_MBX_ARQLEN_ARQLEN_M
;
1523 hw
->mailboxq
.num_sq_entries
= ICE_MBXSQ_LEN
;
1524 hw
->mailboxq
.rq_buf_size
= ICE_MBXQ_MAX_BUF_LEN
;
1525 hw
->mailboxq
.sq_buf_size
= ICE_MBXQ_MAX_BUF_LEN
;
1529 * ice_schedule_reset - schedule a reset
1530 * @pf: board private structure
1531 * @reset: reset being requested
1533 int ice_schedule_reset(struct ice_pf
*pf
, enum ice_reset_req reset
)
1535 struct device
*dev
= ice_pf_to_dev(pf
);
1537 /* bail out if earlier reset has failed */
1538 if (test_bit(__ICE_RESET_FAILED
, pf
->state
)) {
1539 dev_dbg(dev
, "earlier reset has failed\n");
1542 /* bail if reset/recovery already in progress */
1543 if (ice_is_reset_in_progress(pf
->state
)) {
1544 dev_dbg(dev
, "Reset already in progress\n");
1550 set_bit(__ICE_PFR_REQ
, pf
->state
);
1552 case ICE_RESET_CORER
:
1553 set_bit(__ICE_CORER_REQ
, pf
->state
);
1555 case ICE_RESET_GLOBR
:
1556 set_bit(__ICE_GLOBR_REQ
, pf
->state
);
1562 ice_service_task_schedule(pf
);
1567 * ice_irq_affinity_notify - Callback for affinity changes
1568 * @notify: context as to what irq was changed
1569 * @mask: the new affinity mask
1571 * This is a callback function used by the irq_set_affinity_notifier function
1572 * so that we may register to receive changes to the irq affinity masks.
1575 ice_irq_affinity_notify(struct irq_affinity_notify
*notify
,
1576 const cpumask_t
*mask
)
1578 struct ice_q_vector
*q_vector
=
1579 container_of(notify
, struct ice_q_vector
, affinity_notify
);
1581 cpumask_copy(&q_vector
->affinity_mask
, mask
);
1585 * ice_irq_affinity_release - Callback for affinity notifier release
1586 * @ref: internal core kernel usage
1588 * This is a callback function used by the irq_set_affinity_notifier function
1589 * to inform the current notification subscriber that they will no longer
1590 * receive notifications.
1592 static void ice_irq_affinity_release(struct kref __always_unused
*ref
) {}
1595 * ice_vsi_ena_irq - Enable IRQ for the given VSI
1596 * @vsi: the VSI being configured
1598 static int ice_vsi_ena_irq(struct ice_vsi
*vsi
)
1600 struct ice_hw
*hw
= &vsi
->back
->hw
;
1603 ice_for_each_q_vector(vsi
, i
)
1604 ice_irq_dynamic_ena(hw
, vsi
, vsi
->q_vectors
[i
]);
1611 * ice_vsi_req_irq_msix - get MSI-X vectors from the OS for the VSI
1612 * @vsi: the VSI being configured
1613 * @basename: name for the vector
1615 static int ice_vsi_req_irq_msix(struct ice_vsi
*vsi
, char *basename
)
1617 int q_vectors
= vsi
->num_q_vectors
;
1618 struct ice_pf
*pf
= vsi
->back
;
1619 int base
= vsi
->base_vector
;
1626 dev
= ice_pf_to_dev(pf
);
1627 for (vector
= 0; vector
< q_vectors
; vector
++) {
1628 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[vector
];
1630 irq_num
= pf
->msix_entries
[base
+ vector
].vector
;
1632 if (q_vector
->tx
.ring
&& q_vector
->rx
.ring
) {
1633 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
1634 "%s-%s-%d", basename
, "TxRx", rx_int_idx
++);
1636 } else if (q_vector
->rx
.ring
) {
1637 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
1638 "%s-%s-%d", basename
, "rx", rx_int_idx
++);
1639 } else if (q_vector
->tx
.ring
) {
1640 snprintf(q_vector
->name
, sizeof(q_vector
->name
) - 1,
1641 "%s-%s-%d", basename
, "tx", tx_int_idx
++);
1643 /* skip this unused q_vector */
1646 err
= devm_request_irq(dev
, irq_num
, vsi
->irq_handler
, 0,
1647 q_vector
->name
, q_vector
);
1649 netdev_err(vsi
->netdev
, "MSIX request_irq failed, error: %d\n",
1654 /* register for affinity change notifications */
1655 q_vector
->affinity_notify
.notify
= ice_irq_affinity_notify
;
1656 q_vector
->affinity_notify
.release
= ice_irq_affinity_release
;
1657 irq_set_affinity_notifier(irq_num
, &q_vector
->affinity_notify
);
1659 /* assign the mask for this irq */
1660 irq_set_affinity_hint(irq_num
, &q_vector
->affinity_mask
);
1663 vsi
->irqs_ready
= true;
1669 irq_num
= pf
->msix_entries
[base
+ vector
].vector
,
1670 irq_set_affinity_notifier(irq_num
, NULL
);
1671 irq_set_affinity_hint(irq_num
, NULL
);
1672 devm_free_irq(dev
, irq_num
, &vsi
->q_vectors
[vector
]);
1678 * ice_xdp_alloc_setup_rings - Allocate and setup Tx rings for XDP
1679 * @vsi: VSI to setup Tx rings used by XDP
1681 * Return 0 on success and negative value on error
1683 static int ice_xdp_alloc_setup_rings(struct ice_vsi
*vsi
)
1685 struct device
*dev
= ice_pf_to_dev(vsi
->back
);
1688 for (i
= 0; i
< vsi
->num_xdp_txq
; i
++) {
1689 u16 xdp_q_idx
= vsi
->alloc_txq
+ i
;
1690 struct ice_ring
*xdp_ring
;
1692 xdp_ring
= kzalloc(sizeof(*xdp_ring
), GFP_KERNEL
);
1695 goto free_xdp_rings
;
1697 xdp_ring
->q_index
= xdp_q_idx
;
1698 xdp_ring
->reg_idx
= vsi
->txq_map
[xdp_q_idx
];
1699 xdp_ring
->ring_active
= false;
1700 xdp_ring
->vsi
= vsi
;
1701 xdp_ring
->netdev
= NULL
;
1702 xdp_ring
->dev
= dev
;
1703 xdp_ring
->count
= vsi
->num_tx_desc
;
1704 vsi
->xdp_rings
[i
] = xdp_ring
;
1705 if (ice_setup_tx_ring(xdp_ring
))
1706 goto free_xdp_rings
;
1707 ice_set_ring_xdp(xdp_ring
);
1708 xdp_ring
->xsk_umem
= ice_xsk_umem(xdp_ring
);
1715 if (vsi
->xdp_rings
[i
] && vsi
->xdp_rings
[i
]->desc
)
1716 ice_free_tx_ring(vsi
->xdp_rings
[i
]);
1721 * ice_vsi_assign_bpf_prog - set or clear bpf prog pointer on VSI
1722 * @vsi: VSI to set the bpf prog on
1723 * @prog: the bpf prog pointer
1725 static void ice_vsi_assign_bpf_prog(struct ice_vsi
*vsi
, struct bpf_prog
*prog
)
1727 struct bpf_prog
*old_prog
;
1730 old_prog
= xchg(&vsi
->xdp_prog
, prog
);
1732 bpf_prog_put(old_prog
);
1734 ice_for_each_rxq(vsi
, i
)
1735 WRITE_ONCE(vsi
->rx_rings
[i
]->xdp_prog
, vsi
->xdp_prog
);
1739 * ice_prepare_xdp_rings - Allocate, configure and setup Tx rings for XDP
1740 * @vsi: VSI to bring up Tx rings used by XDP
1741 * @prog: bpf program that will be assigned to VSI
1743 * Return 0 on success and negative value on error
1745 int ice_prepare_xdp_rings(struct ice_vsi
*vsi
, struct bpf_prog
*prog
)
1747 u16 max_txqs
[ICE_MAX_TRAFFIC_CLASS
] = { 0 };
1748 int xdp_rings_rem
= vsi
->num_xdp_txq
;
1749 struct ice_pf
*pf
= vsi
->back
;
1750 struct ice_qs_cfg xdp_qs_cfg
= {
1751 .qs_mutex
= &pf
->avail_q_mutex
,
1752 .pf_map
= pf
->avail_txqs
,
1753 .pf_map_size
= pf
->max_pf_txqs
,
1754 .q_count
= vsi
->num_xdp_txq
,
1755 .scatter_count
= ICE_MAX_SCATTER_TXQS
,
1756 .vsi_map
= vsi
->txq_map
,
1757 .vsi_map_offset
= vsi
->alloc_txq
,
1758 .mapping_mode
= ICE_VSI_MAP_CONTIG
1760 enum ice_status status
;
1764 dev
= ice_pf_to_dev(pf
);
1765 vsi
->xdp_rings
= devm_kcalloc(dev
, vsi
->num_xdp_txq
,
1766 sizeof(*vsi
->xdp_rings
), GFP_KERNEL
);
1767 if (!vsi
->xdp_rings
)
1770 vsi
->xdp_mapping_mode
= xdp_qs_cfg
.mapping_mode
;
1771 if (__ice_vsi_get_qs(&xdp_qs_cfg
))
1774 if (ice_xdp_alloc_setup_rings(vsi
))
1775 goto clear_xdp_rings
;
1777 /* follow the logic from ice_vsi_map_rings_to_vectors */
1778 ice_for_each_q_vector(vsi
, v_idx
) {
1779 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
1780 int xdp_rings_per_v
, q_id
, q_base
;
1782 xdp_rings_per_v
= DIV_ROUND_UP(xdp_rings_rem
,
1783 vsi
->num_q_vectors
- v_idx
);
1784 q_base
= vsi
->num_xdp_txq
- xdp_rings_rem
;
1786 for (q_id
= q_base
; q_id
< (q_base
+ xdp_rings_per_v
); q_id
++) {
1787 struct ice_ring
*xdp_ring
= vsi
->xdp_rings
[q_id
];
1789 xdp_ring
->q_vector
= q_vector
;
1790 xdp_ring
->next
= q_vector
->tx
.ring
;
1791 q_vector
->tx
.ring
= xdp_ring
;
1793 xdp_rings_rem
-= xdp_rings_per_v
;
1796 /* omit the scheduler update if in reset path; XDP queues will be
1797 * taken into account at the end of ice_vsi_rebuild, where
1798 * ice_cfg_vsi_lan is being called
1800 if (ice_is_reset_in_progress(pf
->state
))
1803 /* tell the Tx scheduler that right now we have
1806 for (i
= 0; i
< vsi
->tc_cfg
.numtc
; i
++)
1807 max_txqs
[i
] = vsi
->num_txq
+ vsi
->num_xdp_txq
;
1809 status
= ice_cfg_vsi_lan(vsi
->port_info
, vsi
->idx
, vsi
->tc_cfg
.ena_tc
,
1812 dev_err(dev
, "Failed VSI LAN queue config for XDP, error:%d\n",
1814 goto clear_xdp_rings
;
1816 ice_vsi_assign_bpf_prog(vsi
, prog
);
1820 for (i
= 0; i
< vsi
->num_xdp_txq
; i
++)
1821 if (vsi
->xdp_rings
[i
]) {
1822 kfree_rcu(vsi
->xdp_rings
[i
], rcu
);
1823 vsi
->xdp_rings
[i
] = NULL
;
1827 mutex_lock(&pf
->avail_q_mutex
);
1828 for (i
= 0; i
< vsi
->num_xdp_txq
; i
++) {
1829 clear_bit(vsi
->txq_map
[i
+ vsi
->alloc_txq
], pf
->avail_txqs
);
1830 vsi
->txq_map
[i
+ vsi
->alloc_txq
] = ICE_INVAL_Q_INDEX
;
1832 mutex_unlock(&pf
->avail_q_mutex
);
1834 devm_kfree(dev
, vsi
->xdp_rings
);
1839 * ice_destroy_xdp_rings - undo the configuration made by ice_prepare_xdp_rings
1840 * @vsi: VSI to remove XDP rings
1842 * Detach XDP rings from irq vectors, clean up the PF bitmap and free
1845 int ice_destroy_xdp_rings(struct ice_vsi
*vsi
)
1847 u16 max_txqs
[ICE_MAX_TRAFFIC_CLASS
] = { 0 };
1848 struct ice_pf
*pf
= vsi
->back
;
1851 /* q_vectors are freed in reset path so there's no point in detaching
1852 * rings; in case of rebuild being triggered not from reset reset bits
1853 * in pf->state won't be set, so additionally check first q_vector
1856 if (ice_is_reset_in_progress(pf
->state
) || !vsi
->q_vectors
[0])
1859 ice_for_each_q_vector(vsi
, v_idx
) {
1860 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[v_idx
];
1861 struct ice_ring
*ring
;
1863 ice_for_each_ring(ring
, q_vector
->tx
)
1864 if (!ring
->tx_buf
|| !ice_ring_is_xdp(ring
))
1867 /* restore the value of last node prior to XDP setup */
1868 q_vector
->tx
.ring
= ring
;
1872 mutex_lock(&pf
->avail_q_mutex
);
1873 for (i
= 0; i
< vsi
->num_xdp_txq
; i
++) {
1874 clear_bit(vsi
->txq_map
[i
+ vsi
->alloc_txq
], pf
->avail_txqs
);
1875 vsi
->txq_map
[i
+ vsi
->alloc_txq
] = ICE_INVAL_Q_INDEX
;
1877 mutex_unlock(&pf
->avail_q_mutex
);
1879 for (i
= 0; i
< vsi
->num_xdp_txq
; i
++)
1880 if (vsi
->xdp_rings
[i
]) {
1881 if (vsi
->xdp_rings
[i
]->desc
)
1882 ice_free_tx_ring(vsi
->xdp_rings
[i
]);
1883 kfree_rcu(vsi
->xdp_rings
[i
], rcu
);
1884 vsi
->xdp_rings
[i
] = NULL
;
1887 devm_kfree(ice_pf_to_dev(pf
), vsi
->xdp_rings
);
1888 vsi
->xdp_rings
= NULL
;
1890 if (ice_is_reset_in_progress(pf
->state
) || !vsi
->q_vectors
[0])
1893 ice_vsi_assign_bpf_prog(vsi
, NULL
);
1895 /* notify Tx scheduler that we destroyed XDP queues and bring
1896 * back the old number of child nodes
1898 for (i
= 0; i
< vsi
->tc_cfg
.numtc
; i
++)
1899 max_txqs
[i
] = vsi
->num_txq
;
1901 return ice_cfg_vsi_lan(vsi
->port_info
, vsi
->idx
, vsi
->tc_cfg
.ena_tc
,
1906 * ice_xdp_setup_prog - Add or remove XDP eBPF program
1907 * @vsi: VSI to setup XDP for
1908 * @prog: XDP program
1909 * @extack: netlink extended ack
1912 ice_xdp_setup_prog(struct ice_vsi
*vsi
, struct bpf_prog
*prog
,
1913 struct netlink_ext_ack
*extack
)
1915 int frame_size
= vsi
->netdev
->mtu
+ ICE_ETH_PKT_HDR_PAD
;
1916 bool if_running
= netif_running(vsi
->netdev
);
1917 int ret
= 0, xdp_ring_err
= 0;
1919 if (frame_size
> vsi
->rx_buf_len
) {
1920 NL_SET_ERR_MSG_MOD(extack
, "MTU too large for loading XDP");
1924 /* need to stop netdev while setting up the program for Rx rings */
1925 if (if_running
&& !test_and_set_bit(__ICE_DOWN
, vsi
->state
)) {
1926 ret
= ice_down(vsi
);
1928 NL_SET_ERR_MSG_MOD(extack
, "Preparing device for XDP attach failed");
1933 if (!ice_is_xdp_ena_vsi(vsi
) && prog
) {
1934 vsi
->num_xdp_txq
= vsi
->alloc_txq
;
1935 xdp_ring_err
= ice_prepare_xdp_rings(vsi
, prog
);
1937 NL_SET_ERR_MSG_MOD(extack
, "Setting up XDP Tx resources failed");
1938 } else if (ice_is_xdp_ena_vsi(vsi
) && !prog
) {
1939 xdp_ring_err
= ice_destroy_xdp_rings(vsi
);
1941 NL_SET_ERR_MSG_MOD(extack
, "Freeing XDP Tx resources failed");
1943 ice_vsi_assign_bpf_prog(vsi
, prog
);
1949 if (!ret
&& prog
&& vsi
->xsk_umems
) {
1952 ice_for_each_rxq(vsi
, i
) {
1953 struct ice_ring
*rx_ring
= vsi
->rx_rings
[i
];
1955 if (rx_ring
->xsk_umem
)
1956 napi_schedule(&rx_ring
->q_vector
->napi
);
1960 return (ret
|| xdp_ring_err
) ? -ENOMEM
: 0;
1964 * ice_xdp - implements XDP handler
1968 static int ice_xdp(struct net_device
*dev
, struct netdev_bpf
*xdp
)
1970 struct ice_netdev_priv
*np
= netdev_priv(dev
);
1971 struct ice_vsi
*vsi
= np
->vsi
;
1973 if (vsi
->type
!= ICE_VSI_PF
) {
1974 NL_SET_ERR_MSG_MOD(xdp
->extack
, "XDP can be loaded only on PF VSI");
1978 switch (xdp
->command
) {
1979 case XDP_SETUP_PROG
:
1980 return ice_xdp_setup_prog(vsi
, xdp
->prog
, xdp
->extack
);
1981 case XDP_QUERY_PROG
:
1982 xdp
->prog_id
= vsi
->xdp_prog
? vsi
->xdp_prog
->aux
->id
: 0;
1984 case XDP_SETUP_XSK_UMEM
:
1985 return ice_xsk_umem_setup(vsi
, xdp
->xsk
.umem
,
1993 * ice_ena_misc_vector - enable the non-queue interrupts
1994 * @pf: board private structure
1996 static void ice_ena_misc_vector(struct ice_pf
*pf
)
1998 struct ice_hw
*hw
= &pf
->hw
;
2001 /* Disable anti-spoof detection interrupt to prevent spurious event
2002 * interrupts during a function reset. Anti-spoof functionally is
2005 val
= rd32(hw
, GL_MDCK_TX_TDPU
);
2006 val
|= GL_MDCK_TX_TDPU_RCU_ANTISPOOF_ITR_DIS_M
;
2007 wr32(hw
, GL_MDCK_TX_TDPU
, val
);
2009 /* clear things first */
2010 wr32(hw
, PFINT_OICR_ENA
, 0); /* disable all */
2011 rd32(hw
, PFINT_OICR
); /* read to clear */
2013 val
= (PFINT_OICR_ECC_ERR_M
|
2014 PFINT_OICR_MAL_DETECT_M
|
2016 PFINT_OICR_PCI_EXCEPTION_M
|
2018 PFINT_OICR_HMC_ERR_M
|
2019 PFINT_OICR_PE_CRITERR_M
);
2021 wr32(hw
, PFINT_OICR_ENA
, val
);
2023 /* SW_ITR_IDX = 0, but don't change INTENA */
2024 wr32(hw
, GLINT_DYN_CTL(pf
->oicr_idx
),
2025 GLINT_DYN_CTL_SW_ITR_INDX_M
| GLINT_DYN_CTL_INTENA_MSK_M
);
2029 * ice_misc_intr - misc interrupt handler
2030 * @irq: interrupt number
2031 * @data: pointer to a q_vector
2033 static irqreturn_t
ice_misc_intr(int __always_unused irq
, void *data
)
2035 struct ice_pf
*pf
= (struct ice_pf
*)data
;
2036 struct ice_hw
*hw
= &pf
->hw
;
2037 irqreturn_t ret
= IRQ_NONE
;
2041 dev
= ice_pf_to_dev(pf
);
2042 set_bit(__ICE_ADMINQ_EVENT_PENDING
, pf
->state
);
2043 set_bit(__ICE_MAILBOXQ_EVENT_PENDING
, pf
->state
);
2045 oicr
= rd32(hw
, PFINT_OICR
);
2046 ena_mask
= rd32(hw
, PFINT_OICR_ENA
);
2048 if (oicr
& PFINT_OICR_SWINT_M
) {
2049 ena_mask
&= ~PFINT_OICR_SWINT_M
;
2053 if (oicr
& PFINT_OICR_MAL_DETECT_M
) {
2054 ena_mask
&= ~PFINT_OICR_MAL_DETECT_M
;
2055 set_bit(__ICE_MDD_EVENT_PENDING
, pf
->state
);
2057 if (oicr
& PFINT_OICR_VFLR_M
) {
2058 /* disable any further VFLR event notifications */
2059 if (test_bit(__ICE_VF_RESETS_DISABLED
, pf
->state
)) {
2060 u32 reg
= rd32(hw
, PFINT_OICR_ENA
);
2062 reg
&= ~PFINT_OICR_VFLR_M
;
2063 wr32(hw
, PFINT_OICR_ENA
, reg
);
2065 ena_mask
&= ~PFINT_OICR_VFLR_M
;
2066 set_bit(__ICE_VFLR_EVENT_PENDING
, pf
->state
);
2070 if (oicr
& PFINT_OICR_GRST_M
) {
2073 /* we have a reset warning */
2074 ena_mask
&= ~PFINT_OICR_GRST_M
;
2075 reset
= (rd32(hw
, GLGEN_RSTAT
) & GLGEN_RSTAT_RESET_TYPE_M
) >>
2076 GLGEN_RSTAT_RESET_TYPE_S
;
2078 if (reset
== ICE_RESET_CORER
)
2080 else if (reset
== ICE_RESET_GLOBR
)
2082 else if (reset
== ICE_RESET_EMPR
)
2085 dev_dbg(dev
, "Invalid reset type %d\n", reset
);
2087 /* If a reset cycle isn't already in progress, we set a bit in
2088 * pf->state so that the service task can start a reset/rebuild.
2089 * We also make note of which reset happened so that peer
2090 * devices/drivers can be informed.
2092 if (!test_and_set_bit(__ICE_RESET_OICR_RECV
, pf
->state
)) {
2093 if (reset
== ICE_RESET_CORER
)
2094 set_bit(__ICE_CORER_RECV
, pf
->state
);
2095 else if (reset
== ICE_RESET_GLOBR
)
2096 set_bit(__ICE_GLOBR_RECV
, pf
->state
);
2098 set_bit(__ICE_EMPR_RECV
, pf
->state
);
2100 /* There are couple of different bits at play here.
2101 * hw->reset_ongoing indicates whether the hardware is
2102 * in reset. This is set to true when a reset interrupt
2103 * is received and set back to false after the driver
2104 * has determined that the hardware is out of reset.
2106 * __ICE_RESET_OICR_RECV in pf->state indicates
2107 * that a post reset rebuild is required before the
2108 * driver is operational again. This is set above.
2110 * As this is the start of the reset/rebuild cycle, set
2111 * both to indicate that.
2113 hw
->reset_ongoing
= true;
2117 if (oicr
& PFINT_OICR_HMC_ERR_M
) {
2118 ena_mask
&= ~PFINT_OICR_HMC_ERR_M
;
2119 dev_dbg(dev
, "HMC Error interrupt - info 0x%x, data 0x%x\n",
2120 rd32(hw
, PFHMC_ERRORINFO
),
2121 rd32(hw
, PFHMC_ERRORDATA
));
2124 /* Report any remaining unexpected interrupts */
2127 dev_dbg(dev
, "unhandled interrupt oicr=0x%08x\n", oicr
);
2128 /* If a critical error is pending there is no choice but to
2131 if (oicr
& (PFINT_OICR_PE_CRITERR_M
|
2132 PFINT_OICR_PCI_EXCEPTION_M
|
2133 PFINT_OICR_ECC_ERR_M
)) {
2134 set_bit(__ICE_PFR_REQ
, pf
->state
);
2135 ice_service_task_schedule(pf
);
2140 if (!test_bit(__ICE_DOWN
, pf
->state
)) {
2141 ice_service_task_schedule(pf
);
2142 ice_irq_dynamic_ena(hw
, NULL
, NULL
);
2149 * ice_dis_ctrlq_interrupts - disable control queue interrupts
2150 * @hw: pointer to HW structure
2152 static void ice_dis_ctrlq_interrupts(struct ice_hw
*hw
)
2154 /* disable Admin queue Interrupt causes */
2155 wr32(hw
, PFINT_FW_CTL
,
2156 rd32(hw
, PFINT_FW_CTL
) & ~PFINT_FW_CTL_CAUSE_ENA_M
);
2158 /* disable Mailbox queue Interrupt causes */
2159 wr32(hw
, PFINT_MBX_CTL
,
2160 rd32(hw
, PFINT_MBX_CTL
) & ~PFINT_MBX_CTL_CAUSE_ENA_M
);
2162 /* disable Control queue Interrupt causes */
2163 wr32(hw
, PFINT_OICR_CTL
,
2164 rd32(hw
, PFINT_OICR_CTL
) & ~PFINT_OICR_CTL_CAUSE_ENA_M
);
2170 * ice_free_irq_msix_misc - Unroll misc vector setup
2171 * @pf: board private structure
2173 static void ice_free_irq_msix_misc(struct ice_pf
*pf
)
2175 struct ice_hw
*hw
= &pf
->hw
;
2177 ice_dis_ctrlq_interrupts(hw
);
2179 /* disable OICR interrupt */
2180 wr32(hw
, PFINT_OICR_ENA
, 0);
2183 if (pf
->msix_entries
) {
2184 synchronize_irq(pf
->msix_entries
[pf
->oicr_idx
].vector
);
2185 devm_free_irq(ice_pf_to_dev(pf
),
2186 pf
->msix_entries
[pf
->oicr_idx
].vector
, pf
);
2189 pf
->num_avail_sw_msix
+= 1;
2190 ice_free_res(pf
->irq_tracker
, pf
->oicr_idx
, ICE_RES_MISC_VEC_ID
);
2194 * ice_ena_ctrlq_interrupts - enable control queue interrupts
2195 * @hw: pointer to HW structure
2196 * @reg_idx: HW vector index to associate the control queue interrupts with
2198 static void ice_ena_ctrlq_interrupts(struct ice_hw
*hw
, u16 reg_idx
)
2202 val
= ((reg_idx
& PFINT_OICR_CTL_MSIX_INDX_M
) |
2203 PFINT_OICR_CTL_CAUSE_ENA_M
);
2204 wr32(hw
, PFINT_OICR_CTL
, val
);
2206 /* enable Admin queue Interrupt causes */
2207 val
= ((reg_idx
& PFINT_FW_CTL_MSIX_INDX_M
) |
2208 PFINT_FW_CTL_CAUSE_ENA_M
);
2209 wr32(hw
, PFINT_FW_CTL
, val
);
2211 /* enable Mailbox queue Interrupt causes */
2212 val
= ((reg_idx
& PFINT_MBX_CTL_MSIX_INDX_M
) |
2213 PFINT_MBX_CTL_CAUSE_ENA_M
);
2214 wr32(hw
, PFINT_MBX_CTL
, val
);
2220 * ice_req_irq_msix_misc - Setup the misc vector to handle non queue events
2221 * @pf: board private structure
2223 * This sets up the handler for MSIX 0, which is used to manage the
2224 * non-queue interrupts, e.g. AdminQ and errors. This is not used
2225 * when in MSI or Legacy interrupt mode.
2227 static int ice_req_irq_msix_misc(struct ice_pf
*pf
)
2229 struct device
*dev
= ice_pf_to_dev(pf
);
2230 struct ice_hw
*hw
= &pf
->hw
;
2231 int oicr_idx
, err
= 0;
2233 if (!pf
->int_name
[0])
2234 snprintf(pf
->int_name
, sizeof(pf
->int_name
) - 1, "%s-%s:misc",
2235 dev_driver_string(dev
), dev_name(dev
));
2237 /* Do not request IRQ but do enable OICR interrupt since settings are
2238 * lost during reset. Note that this function is called only during
2239 * rebuild path and not while reset is in progress.
2241 if (ice_is_reset_in_progress(pf
->state
))
2244 /* reserve one vector in irq_tracker for misc interrupts */
2245 oicr_idx
= ice_get_res(pf
, pf
->irq_tracker
, 1, ICE_RES_MISC_VEC_ID
);
2249 pf
->num_avail_sw_msix
-= 1;
2250 pf
->oicr_idx
= oicr_idx
;
2252 err
= devm_request_irq(dev
, pf
->msix_entries
[pf
->oicr_idx
].vector
,
2253 ice_misc_intr
, 0, pf
->int_name
, pf
);
2255 dev_err(dev
, "devm_request_irq for %s failed: %d\n",
2257 ice_free_res(pf
->irq_tracker
, 1, ICE_RES_MISC_VEC_ID
);
2258 pf
->num_avail_sw_msix
+= 1;
2263 ice_ena_misc_vector(pf
);
2265 ice_ena_ctrlq_interrupts(hw
, pf
->oicr_idx
);
2266 wr32(hw
, GLINT_ITR(ICE_RX_ITR
, pf
->oicr_idx
),
2267 ITR_REG_ALIGN(ICE_ITR_8K
) >> ICE_ITR_GRAN_S
);
2270 ice_irq_dynamic_ena(hw
, NULL
, NULL
);
2276 * ice_napi_add - register NAPI handler for the VSI
2277 * @vsi: VSI for which NAPI handler is to be registered
2279 * This function is only called in the driver's load path. Registering the NAPI
2280 * handler is done in ice_vsi_alloc_q_vector() for all other cases (i.e. resume,
2281 * reset/rebuild, etc.)
2283 static void ice_napi_add(struct ice_vsi
*vsi
)
2290 ice_for_each_q_vector(vsi
, v_idx
)
2291 netif_napi_add(vsi
->netdev
, &vsi
->q_vectors
[v_idx
]->napi
,
2292 ice_napi_poll
, NAPI_POLL_WEIGHT
);
2296 * ice_set_ops - set netdev and ethtools ops for the given netdev
2297 * @netdev: netdev instance
2299 static void ice_set_ops(struct net_device
*netdev
)
2301 struct ice_pf
*pf
= ice_netdev_to_pf(netdev
);
2303 if (ice_is_safe_mode(pf
)) {
2304 netdev
->netdev_ops
= &ice_netdev_safe_mode_ops
;
2305 ice_set_ethtool_safe_mode_ops(netdev
);
2309 netdev
->netdev_ops
= &ice_netdev_ops
;
2310 ice_set_ethtool_ops(netdev
);
2314 * ice_set_netdev_features - set features for the given netdev
2315 * @netdev: netdev instance
2317 static void ice_set_netdev_features(struct net_device
*netdev
)
2319 struct ice_pf
*pf
= ice_netdev_to_pf(netdev
);
2320 netdev_features_t csumo_features
;
2321 netdev_features_t vlano_features
;
2322 netdev_features_t dflt_features
;
2323 netdev_features_t tso_features
;
2325 if (ice_is_safe_mode(pf
)) {
2327 netdev
->features
= NETIF_F_SG
| NETIF_F_HIGHDMA
;
2328 netdev
->hw_features
= netdev
->features
;
2332 dflt_features
= NETIF_F_SG
|
2336 csumo_features
= NETIF_F_RXCSUM
|
2341 vlano_features
= NETIF_F_HW_VLAN_CTAG_FILTER
|
2342 NETIF_F_HW_VLAN_CTAG_TX
|
2343 NETIF_F_HW_VLAN_CTAG_RX
;
2345 tso_features
= NETIF_F_TSO
|
2348 /* set features that user can change */
2349 netdev
->hw_features
= dflt_features
| csumo_features
|
2350 vlano_features
| tso_features
;
2352 /* enable features */
2353 netdev
->features
|= netdev
->hw_features
;
2354 /* encap and VLAN devices inherit default, csumo and tso features */
2355 netdev
->hw_enc_features
|= dflt_features
| csumo_features
|
2357 netdev
->vlan_features
|= dflt_features
| csumo_features
|
2362 * ice_cfg_netdev - Allocate, configure and register a netdev
2363 * @vsi: the VSI associated with the new netdev
2365 * Returns 0 on success, negative value on failure
2367 static int ice_cfg_netdev(struct ice_vsi
*vsi
)
2369 struct ice_pf
*pf
= vsi
->back
;
2370 struct ice_netdev_priv
*np
;
2371 struct net_device
*netdev
;
2372 u8 mac_addr
[ETH_ALEN
];
2375 err
= ice_devlink_create_port(pf
);
2379 netdev
= alloc_etherdev_mqs(sizeof(*np
), vsi
->alloc_txq
,
2383 goto err_destroy_devlink_port
;
2386 vsi
->netdev
= netdev
;
2387 np
= netdev_priv(netdev
);
2390 ice_set_netdev_features(netdev
);
2392 ice_set_ops(netdev
);
2394 if (vsi
->type
== ICE_VSI_PF
) {
2395 SET_NETDEV_DEV(netdev
, ice_pf_to_dev(pf
));
2396 ether_addr_copy(mac_addr
, vsi
->port_info
->mac
.perm_addr
);
2397 ether_addr_copy(netdev
->dev_addr
, mac_addr
);
2398 ether_addr_copy(netdev
->perm_addr
, mac_addr
);
2401 netdev
->priv_flags
|= IFF_UNICAST_FLT
;
2403 /* Setup netdev TC information */
2404 ice_vsi_cfg_netdev_tc(vsi
, vsi
->tc_cfg
.ena_tc
);
2406 /* setup watchdog timeout value to be 5 second */
2407 netdev
->watchdog_timeo
= 5 * HZ
;
2409 netdev
->min_mtu
= ETH_MIN_MTU
;
2410 netdev
->max_mtu
= ICE_MAX_MTU
;
2412 err
= register_netdev(vsi
->netdev
);
2414 goto err_destroy_devlink_port
;
2416 devlink_port_type_eth_set(&pf
->devlink_port
, vsi
->netdev
);
2418 netif_carrier_off(vsi
->netdev
);
2420 /* make sure transmit queues start off as stopped */
2421 netif_tx_stop_all_queues(vsi
->netdev
);
2425 err_destroy_devlink_port
:
2426 ice_devlink_destroy_port(pf
);
2432 * ice_fill_rss_lut - Fill the RSS lookup table with default values
2433 * @lut: Lookup table
2434 * @rss_table_size: Lookup table size
2435 * @rss_size: Range of queue number for hashing
2437 void ice_fill_rss_lut(u8
*lut
, u16 rss_table_size
, u16 rss_size
)
2441 for (i
= 0; i
< rss_table_size
; i
++)
2442 lut
[i
] = i
% rss_size
;
2446 * ice_pf_vsi_setup - Set up a PF VSI
2447 * @pf: board private structure
2448 * @pi: pointer to the port_info instance
2450 * Returns pointer to the successfully allocated VSI software struct
2451 * on success, otherwise returns NULL on failure.
2453 static struct ice_vsi
*
2454 ice_pf_vsi_setup(struct ice_pf
*pf
, struct ice_port_info
*pi
)
2456 return ice_vsi_setup(pf
, pi
, ICE_VSI_PF
, ICE_INVAL_VFID
);
2460 * ice_lb_vsi_setup - Set up a loopback VSI
2461 * @pf: board private structure
2462 * @pi: pointer to the port_info instance
2464 * Returns pointer to the successfully allocated VSI software struct
2465 * on success, otherwise returns NULL on failure.
2468 ice_lb_vsi_setup(struct ice_pf
*pf
, struct ice_port_info
*pi
)
2470 return ice_vsi_setup(pf
, pi
, ICE_VSI_LB
, ICE_INVAL_VFID
);
2474 * ice_vlan_rx_add_vid - Add a VLAN ID filter to HW offload
2475 * @netdev: network interface to be adjusted
2476 * @proto: unused protocol
2477 * @vid: VLAN ID to be added
2479 * net_device_ops implementation for adding VLAN IDs
2482 ice_vlan_rx_add_vid(struct net_device
*netdev
, __always_unused __be16 proto
,
2485 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2486 struct ice_vsi
*vsi
= np
->vsi
;
2489 if (vid
>= VLAN_N_VID
) {
2490 netdev_err(netdev
, "VLAN id requested %d is out of range %d\n",
2498 /* VLAN 0 is added by default during load/reset */
2502 /* Enable VLAN pruning when a VLAN other than 0 is added */
2503 if (!ice_vsi_is_vlan_pruning_ena(vsi
)) {
2504 ret
= ice_cfg_vlan_pruning(vsi
, true, false);
2509 /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
2510 * packets aren't pruned by the device's internal switch on Rx
2512 ret
= ice_vsi_add_vlan(vsi
, vid
);
2514 vsi
->vlan_ena
= true;
2515 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED
, vsi
->flags
);
2522 * ice_vlan_rx_kill_vid - Remove a VLAN ID filter from HW offload
2523 * @netdev: network interface to be adjusted
2524 * @proto: unused protocol
2525 * @vid: VLAN ID to be removed
2527 * net_device_ops implementation for removing VLAN IDs
2530 ice_vlan_rx_kill_vid(struct net_device
*netdev
, __always_unused __be16 proto
,
2533 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
2534 struct ice_vsi
*vsi
= np
->vsi
;
2540 /* don't allow removal of VLAN 0 */
2544 /* Make sure ice_vsi_kill_vlan is successful before updating VLAN
2547 ret
= ice_vsi_kill_vlan(vsi
, vid
);
2551 /* Disable pruning when VLAN 0 is the only VLAN rule */
2552 if (vsi
->num_vlan
== 1 && ice_vsi_is_vlan_pruning_ena(vsi
))
2553 ret
= ice_cfg_vlan_pruning(vsi
, false, false);
2555 vsi
->vlan_ena
= false;
2556 set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED
, vsi
->flags
);
2561 * ice_setup_pf_sw - Setup the HW switch on startup or after reset
2562 * @pf: board private structure
2564 * Returns 0 on success, negative value on failure
2566 static int ice_setup_pf_sw(struct ice_pf
*pf
)
2568 struct ice_vsi
*vsi
;
2571 if (ice_is_reset_in_progress(pf
->state
))
2574 vsi
= ice_pf_vsi_setup(pf
, pf
->hw
.port_info
);
2577 goto unroll_vsi_setup
;
2580 status
= ice_cfg_netdev(vsi
);
2583 goto unroll_vsi_setup
;
2585 /* netdev has to be configured before setting frame size */
2586 ice_vsi_cfg_frame_size(vsi
);
2588 /* Setup DCB netlink interface */
2589 ice_dcbnl_setup(vsi
);
2591 /* registering the NAPI handler requires both the queues and
2592 * netdev to be created, which are done in ice_pf_vsi_setup()
2593 * and ice_cfg_netdev() respectively
2597 status
= ice_init_mac_fltr(pf
);
2599 goto unroll_napi_add
;
2607 if (vsi
->netdev
->reg_state
== NETREG_REGISTERED
)
2608 unregister_netdev(vsi
->netdev
);
2609 free_netdev(vsi
->netdev
);
2616 ice_vsi_free_q_vectors(vsi
);
2617 ice_vsi_delete(vsi
);
2618 ice_vsi_put_qs(vsi
);
2625 * ice_get_avail_q_count - Get count of queues in use
2626 * @pf_qmap: bitmap to get queue use count from
2627 * @lock: pointer to a mutex that protects access to pf_qmap
2628 * @size: size of the bitmap
2631 ice_get_avail_q_count(unsigned long *pf_qmap
, struct mutex
*lock
, u16 size
)
2636 for_each_clear_bit(bit
, pf_qmap
, size
)
2644 * ice_get_avail_txq_count - Get count of Tx queues in use
2645 * @pf: pointer to an ice_pf instance
2647 u16
ice_get_avail_txq_count(struct ice_pf
*pf
)
2649 return ice_get_avail_q_count(pf
->avail_txqs
, &pf
->avail_q_mutex
,
2654 * ice_get_avail_rxq_count - Get count of Rx queues in use
2655 * @pf: pointer to an ice_pf instance
2657 u16
ice_get_avail_rxq_count(struct ice_pf
*pf
)
2659 return ice_get_avail_q_count(pf
->avail_rxqs
, &pf
->avail_q_mutex
,
2664 * ice_deinit_pf - Unrolls initialziations done by ice_init_pf
2665 * @pf: board private structure to initialize
2667 static void ice_deinit_pf(struct ice_pf
*pf
)
2669 ice_service_task_stop(pf
);
2670 mutex_destroy(&pf
->sw_mutex
);
2671 mutex_destroy(&pf
->tc_mutex
);
2672 mutex_destroy(&pf
->avail_q_mutex
);
2674 if (pf
->avail_txqs
) {
2675 bitmap_free(pf
->avail_txqs
);
2676 pf
->avail_txqs
= NULL
;
2679 if (pf
->avail_rxqs
) {
2680 bitmap_free(pf
->avail_rxqs
);
2681 pf
->avail_rxqs
= NULL
;
2686 * ice_set_pf_caps - set PFs capability flags
2687 * @pf: pointer to the PF instance
2689 static void ice_set_pf_caps(struct ice_pf
*pf
)
2691 struct ice_hw_func_caps
*func_caps
= &pf
->hw
.func_caps
;
2693 clear_bit(ICE_FLAG_DCB_CAPABLE
, pf
->flags
);
2694 if (func_caps
->common_cap
.dcb
)
2695 set_bit(ICE_FLAG_DCB_CAPABLE
, pf
->flags
);
2696 clear_bit(ICE_FLAG_SRIOV_CAPABLE
, pf
->flags
);
2697 if (func_caps
->common_cap
.sr_iov_1_1
) {
2698 set_bit(ICE_FLAG_SRIOV_CAPABLE
, pf
->flags
);
2699 pf
->num_vfs_supported
= min_t(int, func_caps
->num_allocd_vfs
,
2702 clear_bit(ICE_FLAG_RSS_ENA
, pf
->flags
);
2703 if (func_caps
->common_cap
.rss_table_size
)
2704 set_bit(ICE_FLAG_RSS_ENA
, pf
->flags
);
2706 pf
->max_pf_txqs
= func_caps
->common_cap
.num_txq
;
2707 pf
->max_pf_rxqs
= func_caps
->common_cap
.num_rxq
;
2711 * ice_init_pf - Initialize general software structures (struct ice_pf)
2712 * @pf: board private structure to initialize
2714 static int ice_init_pf(struct ice_pf
*pf
)
2716 ice_set_pf_caps(pf
);
2718 mutex_init(&pf
->sw_mutex
);
2719 mutex_init(&pf
->tc_mutex
);
2721 /* setup service timer and periodic service task */
2722 timer_setup(&pf
->serv_tmr
, ice_service_timer
, 0);
2723 pf
->serv_tmr_period
= HZ
;
2724 INIT_WORK(&pf
->serv_task
, ice_service_task
);
2725 clear_bit(__ICE_SERVICE_SCHED
, pf
->state
);
2727 mutex_init(&pf
->avail_q_mutex
);
2728 pf
->avail_txqs
= bitmap_zalloc(pf
->max_pf_txqs
, GFP_KERNEL
);
2729 if (!pf
->avail_txqs
)
2732 pf
->avail_rxqs
= bitmap_zalloc(pf
->max_pf_rxqs
, GFP_KERNEL
);
2733 if (!pf
->avail_rxqs
) {
2734 devm_kfree(ice_pf_to_dev(pf
), pf
->avail_txqs
);
2735 pf
->avail_txqs
= NULL
;
2743 * ice_ena_msix_range - Request a range of MSIX vectors from the OS
2744 * @pf: board private structure
2746 * compute the number of MSIX vectors required (v_budget) and request from
2747 * the OS. Return the number of vectors reserved or negative on failure
2749 static int ice_ena_msix_range(struct ice_pf
*pf
)
2751 struct device
*dev
= ice_pf_to_dev(pf
);
2752 int v_left
, v_actual
, v_budget
= 0;
2755 v_left
= pf
->hw
.func_caps
.common_cap
.num_msix_vectors
;
2757 /* reserve one vector for miscellaneous handler */
2759 if (v_left
< needed
)
2760 goto no_hw_vecs_left_err
;
2764 /* reserve vectors for LAN traffic */
2765 needed
= min_t(int, num_online_cpus(), v_left
);
2766 if (v_left
< needed
)
2767 goto no_hw_vecs_left_err
;
2768 pf
->num_lan_msix
= needed
;
2772 pf
->msix_entries
= devm_kcalloc(dev
, v_budget
,
2773 sizeof(*pf
->msix_entries
), GFP_KERNEL
);
2775 if (!pf
->msix_entries
) {
2780 for (i
= 0; i
< v_budget
; i
++)
2781 pf
->msix_entries
[i
].entry
= i
;
2783 /* actually reserve the vectors */
2784 v_actual
= pci_enable_msix_range(pf
->pdev
, pf
->msix_entries
,
2785 ICE_MIN_MSIX
, v_budget
);
2788 dev_err(dev
, "unable to reserve MSI-X vectors\n");
2793 if (v_actual
< v_budget
) {
2794 dev_warn(dev
, "not enough OS MSI-X vectors. requested = %d, obtained = %d\n",
2795 v_budget
, v_actual
);
2796 /* 2 vectors for LAN (traffic + OICR) */
2797 #define ICE_MIN_LAN_VECS 2
2799 if (v_actual
< ICE_MIN_LAN_VECS
) {
2800 /* error if we can't get minimum vectors */
2801 pci_disable_msix(pf
->pdev
);
2805 pf
->num_lan_msix
= ICE_MIN_LAN_VECS
;
2812 devm_kfree(dev
, pf
->msix_entries
);
2815 no_hw_vecs_left_err
:
2816 dev_err(dev
, "not enough device MSI-X vectors. requested = %d, available = %d\n",
2820 pf
->num_lan_msix
= 0;
2825 * ice_dis_msix - Disable MSI-X interrupt setup in OS
2826 * @pf: board private structure
2828 static void ice_dis_msix(struct ice_pf
*pf
)
2830 pci_disable_msix(pf
->pdev
);
2831 devm_kfree(ice_pf_to_dev(pf
), pf
->msix_entries
);
2832 pf
->msix_entries
= NULL
;
2836 * ice_clear_interrupt_scheme - Undo things done by ice_init_interrupt_scheme
2837 * @pf: board private structure
2839 static void ice_clear_interrupt_scheme(struct ice_pf
*pf
)
2843 if (pf
->irq_tracker
) {
2844 devm_kfree(ice_pf_to_dev(pf
), pf
->irq_tracker
);
2845 pf
->irq_tracker
= NULL
;
2850 * ice_init_interrupt_scheme - Determine proper interrupt scheme
2851 * @pf: board private structure to initialize
2853 static int ice_init_interrupt_scheme(struct ice_pf
*pf
)
2857 vectors
= ice_ena_msix_range(pf
);
2862 /* set up vector assignment tracking */
2864 devm_kzalloc(ice_pf_to_dev(pf
), sizeof(*pf
->irq_tracker
) +
2865 (sizeof(u16
) * vectors
), GFP_KERNEL
);
2866 if (!pf
->irq_tracker
) {
2871 /* populate SW interrupts pool with number of OS granted IRQs. */
2872 pf
->num_avail_sw_msix
= vectors
;
2873 pf
->irq_tracker
->num_entries
= vectors
;
2874 pf
->irq_tracker
->end
= pf
->irq_tracker
->num_entries
;
2880 * ice_vsi_recfg_qs - Change the number of queues on a VSI
2881 * @vsi: VSI being changed
2882 * @new_rx: new number of Rx queues
2883 * @new_tx: new number of Tx queues
2885 * Only change the number of queues if new_tx, or new_rx is non-0.
2887 * Returns 0 on success.
2889 int ice_vsi_recfg_qs(struct ice_vsi
*vsi
, int new_rx
, int new_tx
)
2891 struct ice_pf
*pf
= vsi
->back
;
2892 int err
= 0, timeout
= 50;
2894 if (!new_rx
&& !new_tx
)
2897 while (test_and_set_bit(__ICE_CFG_BUSY
, pf
->state
)) {
2901 usleep_range(1000, 2000);
2905 vsi
->req_txq
= new_tx
;
2907 vsi
->req_rxq
= new_rx
;
2909 /* set for the next time the netdev is started */
2910 if (!netif_running(vsi
->netdev
)) {
2911 ice_vsi_rebuild(vsi
, false);
2912 dev_dbg(ice_pf_to_dev(pf
), "Link is down, queue count change happens when link is brought up\n");
2917 ice_vsi_rebuild(vsi
, false);
2918 ice_pf_dcb_recfg(pf
);
2921 clear_bit(__ICE_CFG_BUSY
, pf
->state
);
2926 * ice_log_pkg_init - log result of DDP package load
2927 * @hw: pointer to hardware info
2928 * @status: status of package load
2931 ice_log_pkg_init(struct ice_hw
*hw
, enum ice_status
*status
)
2933 struct ice_pf
*pf
= (struct ice_pf
*)hw
->back
;
2934 struct device
*dev
= ice_pf_to_dev(pf
);
2938 /* The package download AdminQ command returned success because
2939 * this download succeeded or ICE_ERR_AQ_NO_WORK since there is
2940 * already a package loaded on the device.
2942 if (hw
->pkg_ver
.major
== hw
->active_pkg_ver
.major
&&
2943 hw
->pkg_ver
.minor
== hw
->active_pkg_ver
.minor
&&
2944 hw
->pkg_ver
.update
== hw
->active_pkg_ver
.update
&&
2945 hw
->pkg_ver
.draft
== hw
->active_pkg_ver
.draft
&&
2946 !memcmp(hw
->pkg_name
, hw
->active_pkg_name
,
2947 sizeof(hw
->pkg_name
))) {
2948 if (hw
->pkg_dwnld_status
== ICE_AQ_RC_EEXIST
)
2949 dev_info(dev
, "DDP package already present on device: %s version %d.%d.%d.%d\n",
2950 hw
->active_pkg_name
,
2951 hw
->active_pkg_ver
.major
,
2952 hw
->active_pkg_ver
.minor
,
2953 hw
->active_pkg_ver
.update
,
2954 hw
->active_pkg_ver
.draft
);
2956 dev_info(dev
, "The DDP package was successfully loaded: %s version %d.%d.%d.%d\n",
2957 hw
->active_pkg_name
,
2958 hw
->active_pkg_ver
.major
,
2959 hw
->active_pkg_ver
.minor
,
2960 hw
->active_pkg_ver
.update
,
2961 hw
->active_pkg_ver
.draft
);
2962 } else if (hw
->active_pkg_ver
.major
!= ICE_PKG_SUPP_VER_MAJ
||
2963 hw
->active_pkg_ver
.minor
!= ICE_PKG_SUPP_VER_MNR
) {
2964 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",
2965 hw
->active_pkg_name
,
2966 hw
->active_pkg_ver
.major
,
2967 hw
->active_pkg_ver
.minor
,
2968 ICE_PKG_SUPP_VER_MAJ
, ICE_PKG_SUPP_VER_MNR
);
2969 *status
= ICE_ERR_NOT_SUPPORTED
;
2970 } else if (hw
->active_pkg_ver
.major
== ICE_PKG_SUPP_VER_MAJ
&&
2971 hw
->active_pkg_ver
.minor
== ICE_PKG_SUPP_VER_MNR
) {
2972 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",
2973 hw
->active_pkg_name
,
2974 hw
->active_pkg_ver
.major
,
2975 hw
->active_pkg_ver
.minor
,
2976 hw
->active_pkg_ver
.update
,
2977 hw
->active_pkg_ver
.draft
,
2984 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");
2985 *status
= ICE_ERR_NOT_SUPPORTED
;
2988 case ICE_ERR_BUF_TOO_SHORT
:
2990 dev_err(dev
, "The DDP package file is invalid. Entering Safe Mode.\n");
2992 case ICE_ERR_NOT_SUPPORTED
:
2993 /* Package File version not supported */
2994 if (hw
->pkg_ver
.major
> ICE_PKG_SUPP_VER_MAJ
||
2995 (hw
->pkg_ver
.major
== ICE_PKG_SUPP_VER_MAJ
&&
2996 hw
->pkg_ver
.minor
> ICE_PKG_SUPP_VER_MNR
))
2997 dev_err(dev
, "The DDP package file version is higher than the driver supports. Please use an updated driver. Entering Safe Mode.\n");
2998 else if (hw
->pkg_ver
.major
< ICE_PKG_SUPP_VER_MAJ
||
2999 (hw
->pkg_ver
.major
== ICE_PKG_SUPP_VER_MAJ
&&
3000 hw
->pkg_ver
.minor
< ICE_PKG_SUPP_VER_MNR
))
3001 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",
3002 ICE_PKG_SUPP_VER_MAJ
, ICE_PKG_SUPP_VER_MNR
);
3004 case ICE_ERR_AQ_ERROR
:
3005 switch (hw
->pkg_dwnld_status
) {
3006 case ICE_AQ_RC_ENOSEC
:
3007 case ICE_AQ_RC_EBADSIG
:
3008 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");
3010 case ICE_AQ_RC_ESVN
:
3011 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");
3013 case ICE_AQ_RC_EBADMAN
:
3014 case ICE_AQ_RC_EBADBUF
:
3015 dev_err(dev
, "An error occurred on the device while loading the DDP package. The device will be reset.\n");
3022 dev_err(dev
, "An unknown error (%d) occurred when loading the DDP package. Entering Safe Mode.\n",
3029 * ice_load_pkg - load/reload the DDP Package file
3030 * @firmware: firmware structure when firmware requested or NULL for reload
3031 * @pf: pointer to the PF instance
3033 * Called on probe and post CORER/GLOBR rebuild to load DDP Package and
3034 * initialize HW tables.
3037 ice_load_pkg(const struct firmware
*firmware
, struct ice_pf
*pf
)
3039 enum ice_status status
= ICE_ERR_PARAM
;
3040 struct device
*dev
= ice_pf_to_dev(pf
);
3041 struct ice_hw
*hw
= &pf
->hw
;
3043 /* Load DDP Package */
3044 if (firmware
&& !hw
->pkg_copy
) {
3045 status
= ice_copy_and_init_pkg(hw
, firmware
->data
,
3047 ice_log_pkg_init(hw
, &status
);
3048 } else if (!firmware
&& hw
->pkg_copy
) {
3049 /* Reload package during rebuild after CORER/GLOBR reset */
3050 status
= ice_init_pkg(hw
, hw
->pkg_copy
, hw
->pkg_size
);
3051 ice_log_pkg_init(hw
, &status
);
3053 dev_err(dev
, "The DDP package file failed to load. Entering Safe Mode.\n");
3058 clear_bit(ICE_FLAG_ADV_FEATURES
, pf
->flags
);
3062 /* Successful download package is the precondition for advanced
3063 * features, hence setting the ICE_FLAG_ADV_FEATURES flag
3065 set_bit(ICE_FLAG_ADV_FEATURES
, pf
->flags
);
3069 * ice_verify_cacheline_size - verify driver's assumption of 64 Byte cache lines
3070 * @pf: pointer to the PF structure
3072 * There is no error returned here because the driver should be able to handle
3073 * 128 Byte cache lines, so we only print a warning in case issues are seen,
3074 * specifically with Tx.
3076 static void ice_verify_cacheline_size(struct ice_pf
*pf
)
3078 if (rd32(&pf
->hw
, GLPCI_CNF2
) & GLPCI_CNF2_CACHELINE_SIZE_M
)
3079 dev_warn(ice_pf_to_dev(pf
), "%d Byte cache line assumption is invalid, driver may have Tx timeouts!\n",
3080 ICE_CACHE_LINE_BYTES
);
3084 * ice_send_version - update firmware with driver version
3087 * Returns ICE_SUCCESS on success, else error code
3089 static enum ice_status
ice_send_version(struct ice_pf
*pf
)
3091 struct ice_driver_ver dv
;
3093 dv
.major_ver
= DRV_VERSION_MAJOR
;
3094 dv
.minor_ver
= DRV_VERSION_MINOR
;
3095 dv
.build_ver
= DRV_VERSION_BUILD
;
3096 dv
.subbuild_ver
= 0;
3097 strscpy((char *)dv
.driver_string
, DRV_VERSION
,
3098 sizeof(dv
.driver_string
));
3099 return ice_aq_send_driver_ver(&pf
->hw
, &dv
, NULL
);
3103 * ice_get_opt_fw_name - return optional firmware file name or NULL
3104 * @pf: pointer to the PF instance
3106 static char *ice_get_opt_fw_name(struct ice_pf
*pf
)
3108 /* Optional firmware name same as default with additional dash
3109 * followed by a EUI-64 identifier (PCIe Device Serial Number)
3111 struct pci_dev
*pdev
= pf
->pdev
;
3112 char *opt_fw_filename
;
3115 /* Determine the name of the optional file using the DSN (two
3116 * dwords following the start of the DSN Capability).
3118 dsn
= pci_get_dsn(pdev
);
3122 opt_fw_filename
= kzalloc(NAME_MAX
, GFP_KERNEL
);
3123 if (!opt_fw_filename
)
3126 snprintf(opt_fw_filename
, NAME_MAX
, "%sice-%016llX.pkg",
3127 ICE_DDP_PKG_PATH
, dsn
);
3129 return opt_fw_filename
;
3133 * ice_request_fw - Device initialization routine
3134 * @pf: pointer to the PF instance
3136 static void ice_request_fw(struct ice_pf
*pf
)
3138 char *opt_fw_filename
= ice_get_opt_fw_name(pf
);
3139 const struct firmware
*firmware
= NULL
;
3140 struct device
*dev
= ice_pf_to_dev(pf
);
3143 /* optional device-specific DDP (if present) overrides the default DDP
3144 * package file. kernel logs a debug message if the file doesn't exist,
3145 * and warning messages for other errors.
3147 if (opt_fw_filename
) {
3148 err
= firmware_request_nowarn(&firmware
, opt_fw_filename
, dev
);
3150 kfree(opt_fw_filename
);
3154 /* request for firmware was successful. Download to device */
3155 ice_load_pkg(firmware
, pf
);
3156 kfree(opt_fw_filename
);
3157 release_firmware(firmware
);
3162 err
= request_firmware(&firmware
, ICE_DDP_PKG_FILE
, dev
);
3164 dev_err(dev
, "The DDP package file was not found or could not be read. Entering Safe Mode\n");
3168 /* request for firmware was successful. Download to device */
3169 ice_load_pkg(firmware
, pf
);
3170 release_firmware(firmware
);
3174 * ice_probe - Device initialization routine
3175 * @pdev: PCI device information struct
3176 * @ent: entry in ice_pci_tbl
3178 * Returns 0 on success, negative on failure
3181 ice_probe(struct pci_dev
*pdev
, const struct pci_device_id __always_unused
*ent
)
3183 struct device
*dev
= &pdev
->dev
;
3188 /* this driver uses devres, see
3189 * Documentation/driver-api/driver-model/devres.rst
3191 err
= pcim_enable_device(pdev
);
3195 err
= pcim_iomap_regions(pdev
, BIT(ICE_BAR0
), pci_name(pdev
));
3197 dev_err(dev
, "BAR0 I/O map error %d\n", err
);
3201 pf
= ice_allocate_pf(dev
);
3205 /* set up for high or low DMA */
3206 err
= dma_set_mask_and_coherent(dev
, DMA_BIT_MASK(64));
3208 err
= dma_set_mask_and_coherent(dev
, DMA_BIT_MASK(32));
3210 dev_err(dev
, "DMA configuration failed: 0x%x\n", err
);
3214 pci_enable_pcie_error_reporting(pdev
);
3215 pci_set_master(pdev
);
3218 pci_set_drvdata(pdev
, pf
);
3219 set_bit(__ICE_DOWN
, pf
->state
);
3220 /* Disable service task until DOWN bit is cleared */
3221 set_bit(__ICE_SERVICE_DIS
, pf
->state
);
3224 hw
->hw_addr
= pcim_iomap_table(pdev
)[ICE_BAR0
];
3225 pci_save_state(pdev
);
3228 hw
->vendor_id
= pdev
->vendor
;
3229 hw
->device_id
= pdev
->device
;
3230 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &hw
->revision_id
);
3231 hw
->subsystem_vendor_id
= pdev
->subsystem_vendor
;
3232 hw
->subsystem_device_id
= pdev
->subsystem_device
;
3233 hw
->bus
.device
= PCI_SLOT(pdev
->devfn
);
3234 hw
->bus
.func
= PCI_FUNC(pdev
->devfn
);
3235 ice_set_ctrlq_len(hw
);
3237 pf
->msg_enable
= netif_msg_init(debug
, ICE_DFLT_NETIF_M
);
3239 err
= ice_devlink_register(pf
);
3241 dev_err(dev
, "ice_devlink_register failed: %d\n", err
);
3242 goto err_exit_unroll
;
3245 #ifndef CONFIG_DYNAMIC_DEBUG
3247 hw
->debug_mask
= debug
;
3250 err
= ice_init_hw(hw
);
3252 dev_err(dev
, "ice_init_hw failed: %d\n", err
);
3254 goto err_exit_unroll
;
3259 /* if ice_request_fw fails, ICE_FLAG_ADV_FEATURES bit won't be
3260 * set in pf->state, which will cause ice_is_safe_mode to return
3263 if (ice_is_safe_mode(pf
)) {
3264 dev_err(dev
, "Package download failed. Advanced features disabled - Device now in Safe Mode\n");
3265 /* we already got function/device capabilities but these don't
3266 * reflect what the driver needs to do in safe mode. Instead of
3267 * adding conditional logic everywhere to ignore these
3268 * device/function capabilities, override them.
3270 ice_set_safe_mode_caps(hw
);
3273 err
= ice_init_pf(pf
);
3275 dev_err(dev
, "ice_init_pf failed: %d\n", err
);
3276 goto err_init_pf_unroll
;
3279 ice_devlink_init_regions(pf
);
3281 pf
->num_alloc_vsi
= hw
->func_caps
.guar_num_vsi
;
3282 if (!pf
->num_alloc_vsi
) {
3284 goto err_init_pf_unroll
;
3287 pf
->vsi
= devm_kcalloc(dev
, pf
->num_alloc_vsi
, sizeof(*pf
->vsi
),
3291 goto err_init_pf_unroll
;
3294 err
= ice_init_interrupt_scheme(pf
);
3296 dev_err(dev
, "ice_init_interrupt_scheme failed: %d\n", err
);
3298 goto err_init_interrupt_unroll
;
3301 /* Driver is mostly up */
3302 clear_bit(__ICE_DOWN
, pf
->state
);
3304 /* In case of MSIX we are going to setup the misc vector right here
3305 * to handle admin queue events etc. In case of legacy and MSI
3306 * the misc functionality and queue processing is combined in
3307 * the same vector and that gets setup at open.
3309 err
= ice_req_irq_msix_misc(pf
);
3311 dev_err(dev
, "setup of misc vector failed: %d\n", err
);
3312 goto err_init_interrupt_unroll
;
3315 /* create switch struct for the switch element created by FW on boot */
3316 pf
->first_sw
= devm_kzalloc(dev
, sizeof(*pf
->first_sw
), GFP_KERNEL
);
3317 if (!pf
->first_sw
) {
3319 goto err_msix_misc_unroll
;
3323 pf
->first_sw
->bridge_mode
= BRIDGE_MODE_VEB
;
3325 pf
->first_sw
->bridge_mode
= BRIDGE_MODE_VEPA
;
3327 pf
->first_sw
->pf
= pf
;
3329 /* record the sw_id available for later use */
3330 pf
->first_sw
->sw_id
= hw
->port_info
->sw_id
;
3332 err
= ice_setup_pf_sw(pf
);
3334 dev_err(dev
, "probe failed due to setup PF switch: %d\n", err
);
3335 goto err_alloc_sw_unroll
;
3338 clear_bit(__ICE_SERVICE_DIS
, pf
->state
);
3340 /* tell the firmware we are up */
3341 err
= ice_send_version(pf
);
3343 dev_err(dev
, "probe failed sending driver version %s. error: %d\n",
3345 goto err_alloc_sw_unroll
;
3348 /* since everything is good, start the service timer */
3349 mod_timer(&pf
->serv_tmr
, round_jiffies(jiffies
+ pf
->serv_tmr_period
));
3351 err
= ice_init_link_events(pf
->hw
.port_info
);
3353 dev_err(dev
, "ice_init_link_events failed: %d\n", err
);
3354 goto err_alloc_sw_unroll
;
3357 ice_verify_cacheline_size(pf
);
3359 /* If no DDP driven features have to be setup, return here */
3360 if (ice_is_safe_mode(pf
))
3363 /* initialize DDP driven features */
3365 /* Note: DCB init failure is non-fatal to load */
3366 if (ice_init_pf_dcb(pf
, false)) {
3367 clear_bit(ICE_FLAG_DCB_CAPABLE
, pf
->flags
);
3368 clear_bit(ICE_FLAG_DCB_ENA
, pf
->flags
);
3370 ice_cfg_lldp_mib_change(&pf
->hw
, true);
3373 /* print PCI link speed and width */
3374 pcie_print_link_status(pf
->pdev
);
3378 err_alloc_sw_unroll
:
3379 ice_devlink_destroy_port(pf
);
3380 set_bit(__ICE_SERVICE_DIS
, pf
->state
);
3381 set_bit(__ICE_DOWN
, pf
->state
);
3382 devm_kfree(dev
, pf
->first_sw
);
3383 err_msix_misc_unroll
:
3384 ice_free_irq_msix_misc(pf
);
3385 err_init_interrupt_unroll
:
3386 ice_clear_interrupt_scheme(pf
);
3387 devm_kfree(dev
, pf
->vsi
);
3390 ice_devlink_destroy_regions(pf
);
3393 ice_devlink_unregister(pf
);
3394 pci_disable_pcie_error_reporting(pdev
);
3399 * ice_remove - Device removal routine
3400 * @pdev: PCI device information struct
3402 static void ice_remove(struct pci_dev
*pdev
)
3404 struct ice_pf
*pf
= pci_get_drvdata(pdev
);
3410 for (i
= 0; i
< ICE_MAX_RESET_WAIT
; i
++) {
3411 if (!ice_is_reset_in_progress(pf
->state
))
3416 if (test_bit(ICE_FLAG_SRIOV_ENA
, pf
->flags
)) {
3417 set_bit(__ICE_VF_RESETS_DISABLED
, pf
->state
);
3421 set_bit(__ICE_DOWN
, pf
->state
);
3422 ice_service_task_stop(pf
);
3424 ice_devlink_destroy_port(pf
);
3425 ice_vsi_release_all(pf
);
3426 ice_free_irq_msix_misc(pf
);
3427 ice_for_each_vsi(pf
, i
) {
3430 ice_vsi_free_q_vectors(pf
->vsi
[i
]);
3433 ice_devlink_destroy_regions(pf
);
3434 ice_deinit_hw(&pf
->hw
);
3435 ice_devlink_unregister(pf
);
3437 /* Issue a PFR as part of the prescribed driver unload flow. Do not
3438 * do it via ice_schedule_reset() since there is no need to rebuild
3439 * and the service task is already stopped.
3441 ice_reset(&pf
->hw
, ICE_RESET_PFR
);
3442 pci_wait_for_pending_transaction(pdev
);
3443 ice_clear_interrupt_scheme(pf
);
3444 pci_disable_pcie_error_reporting(pdev
);
3448 * ice_pci_err_detected - warning that PCI error has been detected
3449 * @pdev: PCI device information struct
3450 * @err: the type of PCI error
3452 * Called to warn that something happened on the PCI bus and the error handling
3453 * is in progress. Allows the driver to gracefully prepare/handle PCI errors.
3455 static pci_ers_result_t
3456 ice_pci_err_detected(struct pci_dev
*pdev
, enum pci_channel_state err
)
3458 struct ice_pf
*pf
= pci_get_drvdata(pdev
);
3461 dev_err(&pdev
->dev
, "%s: unrecoverable device error %d\n",
3463 return PCI_ERS_RESULT_DISCONNECT
;
3466 if (!test_bit(__ICE_SUSPENDED
, pf
->state
)) {
3467 ice_service_task_stop(pf
);
3469 if (!test_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
)) {
3470 set_bit(__ICE_PFR_REQ
, pf
->state
);
3471 ice_prepare_for_reset(pf
);
3475 return PCI_ERS_RESULT_NEED_RESET
;
3479 * ice_pci_err_slot_reset - a PCI slot reset has just happened
3480 * @pdev: PCI device information struct
3482 * Called to determine if the driver can recover from the PCI slot reset by
3483 * using a register read to determine if the device is recoverable.
3485 static pci_ers_result_t
ice_pci_err_slot_reset(struct pci_dev
*pdev
)
3487 struct ice_pf
*pf
= pci_get_drvdata(pdev
);
3488 pci_ers_result_t result
;
3492 err
= pci_enable_device_mem(pdev
);
3494 dev_err(&pdev
->dev
, "Cannot re-enable PCI device after reset, error %d\n",
3496 result
= PCI_ERS_RESULT_DISCONNECT
;
3498 pci_set_master(pdev
);
3499 pci_restore_state(pdev
);
3500 pci_save_state(pdev
);
3501 pci_wake_from_d3(pdev
, false);
3503 /* Check for life */
3504 reg
= rd32(&pf
->hw
, GLGEN_RTRIG
);
3506 result
= PCI_ERS_RESULT_RECOVERED
;
3508 result
= PCI_ERS_RESULT_DISCONNECT
;
3511 err
= pci_aer_clear_nonfatal_status(pdev
);
3513 dev_dbg(&pdev
->dev
, "pci_aer_clear_nonfatal_status() failed, error %d\n",
3515 /* non-fatal, continue */
3521 * ice_pci_err_resume - restart operations after PCI error recovery
3522 * @pdev: PCI device information struct
3524 * Called to allow the driver to bring things back up after PCI error and/or
3525 * reset recovery have finished
3527 static void ice_pci_err_resume(struct pci_dev
*pdev
)
3529 struct ice_pf
*pf
= pci_get_drvdata(pdev
);
3532 dev_err(&pdev
->dev
, "%s failed, device is unrecoverable\n",
3537 if (test_bit(__ICE_SUSPENDED
, pf
->state
)) {
3538 dev_dbg(&pdev
->dev
, "%s failed to resume normal operations!\n",
3543 ice_do_reset(pf
, ICE_RESET_PFR
);
3544 ice_service_task_restart(pf
);
3545 mod_timer(&pf
->serv_tmr
, round_jiffies(jiffies
+ pf
->serv_tmr_period
));
3549 * ice_pci_err_reset_prepare - prepare device driver for PCI reset
3550 * @pdev: PCI device information struct
3552 static void ice_pci_err_reset_prepare(struct pci_dev
*pdev
)
3554 struct ice_pf
*pf
= pci_get_drvdata(pdev
);
3556 if (!test_bit(__ICE_SUSPENDED
, pf
->state
)) {
3557 ice_service_task_stop(pf
);
3559 if (!test_bit(__ICE_PREPARED_FOR_RESET
, pf
->state
)) {
3560 set_bit(__ICE_PFR_REQ
, pf
->state
);
3561 ice_prepare_for_reset(pf
);
3567 * ice_pci_err_reset_done - PCI reset done, device driver reset can begin
3568 * @pdev: PCI device information struct
3570 static void ice_pci_err_reset_done(struct pci_dev
*pdev
)
3572 ice_pci_err_resume(pdev
);
3575 /* ice_pci_tbl - PCI Device ID Table
3577 * Wildcard entries (PCI_ANY_ID) should come last
3578 * Last entry must be all 0s
3580 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
3581 * Class, Class Mask, private data (not used) }
3583 static const struct pci_device_id ice_pci_tbl
[] = {
3584 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E810C_BACKPLANE
), 0 },
3585 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E810C_QSFP
), 0 },
3586 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E810C_SFP
), 0 },
3587 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E810_XXV_SFP
), 0 },
3588 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823C_BACKPLANE
), 0 },
3589 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823C_QSFP
), 0 },
3590 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823C_SFP
), 0 },
3591 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823C_10G_BASE_T
), 0 },
3592 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823C_SGMII
), 0 },
3593 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822C_BACKPLANE
), 0 },
3594 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822C_QSFP
), 0 },
3595 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822C_SFP
), 0 },
3596 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822C_10G_BASE_T
), 0 },
3597 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822C_SGMII
), 0 },
3598 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822L_BACKPLANE
), 0 },
3599 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822L_SFP
), 0 },
3600 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822L_10G_BASE_T
), 0 },
3601 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E822L_SGMII
), 0 },
3602 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823L_BACKPLANE
), 0 },
3603 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823L_SFP
), 0 },
3604 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823L_10G_BASE_T
), 0 },
3605 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823L_1GBE
), 0 },
3606 { PCI_VDEVICE(INTEL
, ICE_DEV_ID_E823L_QSFP
), 0 },
3607 /* required last entry */
3610 MODULE_DEVICE_TABLE(pci
, ice_pci_tbl
);
3612 static const struct pci_error_handlers ice_pci_err_handler
= {
3613 .error_detected
= ice_pci_err_detected
,
3614 .slot_reset
= ice_pci_err_slot_reset
,
3615 .reset_prepare
= ice_pci_err_reset_prepare
,
3616 .reset_done
= ice_pci_err_reset_done
,
3617 .resume
= ice_pci_err_resume
3620 static struct pci_driver ice_driver
= {
3621 .name
= KBUILD_MODNAME
,
3622 .id_table
= ice_pci_tbl
,
3624 .remove
= ice_remove
,
3625 .sriov_configure
= ice_sriov_configure
,
3626 .err_handler
= &ice_pci_err_handler
3630 * ice_module_init - Driver registration routine
3632 * ice_module_init is the first routine called when the driver is
3633 * loaded. All it does is register with the PCI subsystem.
3635 static int __init
ice_module_init(void)
3639 pr_info("%s - version %s\n", ice_driver_string
, ice_drv_ver
);
3640 pr_info("%s\n", ice_copyright
);
3642 ice_wq
= alloc_workqueue("%s", WQ_MEM_RECLAIM
, 0, KBUILD_MODNAME
);
3644 pr_err("Failed to create workqueue\n");
3648 status
= pci_register_driver(&ice_driver
);
3650 pr_err("failed to register PCI driver, err %d\n", status
);
3651 destroy_workqueue(ice_wq
);
3656 module_init(ice_module_init
);
3659 * ice_module_exit - Driver exit cleanup routine
3661 * ice_module_exit is called just before the driver is removed
3664 static void __exit
ice_module_exit(void)
3666 pci_unregister_driver(&ice_driver
);
3667 destroy_workqueue(ice_wq
);
3668 pr_info("module unloaded\n");
3670 module_exit(ice_module_exit
);
3673 * ice_set_mac_address - NDO callback to set MAC address
3674 * @netdev: network interface device structure
3675 * @pi: pointer to an address structure
3677 * Returns 0 on success, negative on failure
3679 static int ice_set_mac_address(struct net_device
*netdev
, void *pi
)
3681 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3682 struct ice_vsi
*vsi
= np
->vsi
;
3683 struct ice_pf
*pf
= vsi
->back
;
3684 struct ice_hw
*hw
= &pf
->hw
;
3685 struct sockaddr
*addr
= pi
;
3686 enum ice_status status
;
3691 mac
= (u8
*)addr
->sa_data
;
3693 if (!is_valid_ether_addr(mac
))
3694 return -EADDRNOTAVAIL
;
3696 if (ether_addr_equal(netdev
->dev_addr
, mac
)) {
3697 netdev_warn(netdev
, "already using mac %pM\n", mac
);
3701 if (test_bit(__ICE_DOWN
, pf
->state
) ||
3702 ice_is_reset_in_progress(pf
->state
)) {
3703 netdev_err(netdev
, "can't set mac %pM. device not ready\n",
3708 /* When we change the MAC address we also have to change the MAC address
3709 * based filter rules that were created previously for the old MAC
3710 * address. So first, we remove the old filter rule using ice_remove_mac
3711 * and then create a new filter rule using ice_add_mac via
3712 * ice_vsi_cfg_mac_fltr function call for both add and/or remove
3715 status
= ice_vsi_cfg_mac_fltr(vsi
, netdev
->dev_addr
, false);
3717 err
= -EADDRNOTAVAIL
;
3718 goto err_update_filters
;
3721 status
= ice_vsi_cfg_mac_fltr(vsi
, mac
, true);
3723 err
= -EADDRNOTAVAIL
;
3724 goto err_update_filters
;
3729 netdev_err(netdev
, "can't set MAC %pM. filter update failed\n",
3734 /* change the netdev's MAC address */
3735 memcpy(netdev
->dev_addr
, mac
, netdev
->addr_len
);
3736 netdev_dbg(vsi
->netdev
, "updated MAC address to %pM\n",
3739 /* write new MAC address to the firmware */
3740 flags
= ICE_AQC_MAN_MAC_UPDATE_LAA_WOL
;
3741 status
= ice_aq_manage_mac_write(hw
, mac
, flags
, NULL
);
3743 netdev_err(netdev
, "can't set MAC %pM. write to firmware failed error %d\n",
3750 * ice_set_rx_mode - NDO callback to set the netdev filters
3751 * @netdev: network interface device structure
3753 static void ice_set_rx_mode(struct net_device
*netdev
)
3755 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3756 struct ice_vsi
*vsi
= np
->vsi
;
3761 /* Set the flags to synchronize filters
3762 * ndo_set_rx_mode may be triggered even without a change in netdev
3765 set_bit(ICE_VSI_FLAG_UMAC_FLTR_CHANGED
, vsi
->flags
);
3766 set_bit(ICE_VSI_FLAG_MMAC_FLTR_CHANGED
, vsi
->flags
);
3767 set_bit(ICE_FLAG_FLTR_SYNC
, vsi
->back
->flags
);
3769 /* schedule our worker thread which will take care of
3770 * applying the new filter changes
3772 ice_service_task_schedule(vsi
->back
);
3776 * ice_set_tx_maxrate - NDO callback to set the maximum per-queue bitrate
3777 * @netdev: network interface device structure
3778 * @queue_index: Queue ID
3779 * @maxrate: maximum bandwidth in Mbps
3782 ice_set_tx_maxrate(struct net_device
*netdev
, int queue_index
, u32 maxrate
)
3784 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3785 struct ice_vsi
*vsi
= np
->vsi
;
3786 enum ice_status status
;
3790 /* Validate maxrate requested is within permitted range */
3791 if (maxrate
&& (maxrate
> (ICE_SCHED_MAX_BW
/ 1000))) {
3792 netdev_err(netdev
, "Invalid max rate %d specified for the queue %d\n",
3793 maxrate
, queue_index
);
3797 q_handle
= vsi
->tx_rings
[queue_index
]->q_handle
;
3798 tc
= ice_dcb_get_tc(vsi
, queue_index
);
3800 /* Set BW back to default, when user set maxrate to 0 */
3802 status
= ice_cfg_q_bw_dflt_lmt(vsi
->port_info
, vsi
->idx
, tc
,
3803 q_handle
, ICE_MAX_BW
);
3805 status
= ice_cfg_q_bw_lmt(vsi
->port_info
, vsi
->idx
, tc
,
3806 q_handle
, ICE_MAX_BW
, maxrate
* 1000);
3808 netdev_err(netdev
, "Unable to set Tx max rate, error %d\n",
3817 * ice_fdb_add - add an entry to the hardware database
3818 * @ndm: the input from the stack
3819 * @tb: pointer to array of nladdr (unused)
3820 * @dev: the net device pointer
3821 * @addr: the MAC address entry being added
3823 * @flags: instructions from stack about fdb operation
3824 * @extack: netlink extended ack
3827 ice_fdb_add(struct ndmsg
*ndm
, struct nlattr __always_unused
*tb
[],
3828 struct net_device
*dev
, const unsigned char *addr
, u16 vid
,
3829 u16 flags
, struct netlink_ext_ack __always_unused
*extack
)
3834 netdev_err(dev
, "VLANs aren't supported yet for dev_uc|mc_add()\n");
3837 if (ndm
->ndm_state
&& !(ndm
->ndm_state
& NUD_PERMANENT
)) {
3838 netdev_err(dev
, "FDB only supports static addresses\n");
3842 if (is_unicast_ether_addr(addr
) || is_link_local_ether_addr(addr
))
3843 err
= dev_uc_add_excl(dev
, addr
);
3844 else if (is_multicast_ether_addr(addr
))
3845 err
= dev_mc_add_excl(dev
, addr
);
3849 /* Only return duplicate errors if NLM_F_EXCL is set */
3850 if (err
== -EEXIST
&& !(flags
& NLM_F_EXCL
))
3857 * ice_fdb_del - delete an entry from the hardware database
3858 * @ndm: the input from the stack
3859 * @tb: pointer to array of nladdr (unused)
3860 * @dev: the net device pointer
3861 * @addr: the MAC address entry being added
3865 ice_fdb_del(struct ndmsg
*ndm
, __always_unused
struct nlattr
*tb
[],
3866 struct net_device
*dev
, const unsigned char *addr
,
3867 __always_unused u16 vid
)
3871 if (ndm
->ndm_state
& NUD_PERMANENT
) {
3872 netdev_err(dev
, "FDB only supports static addresses\n");
3876 if (is_unicast_ether_addr(addr
))
3877 err
= dev_uc_del(dev
, addr
);
3878 else if (is_multicast_ether_addr(addr
))
3879 err
= dev_mc_del(dev
, addr
);
3887 * ice_set_features - set the netdev feature flags
3888 * @netdev: ptr to the netdev being adjusted
3889 * @features: the feature set that the stack is suggesting
3892 ice_set_features(struct net_device
*netdev
, netdev_features_t features
)
3894 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
3895 struct ice_vsi
*vsi
= np
->vsi
;
3896 struct ice_pf
*pf
= vsi
->back
;
3899 /* Don't set any netdev advanced features with device in Safe Mode */
3900 if (ice_is_safe_mode(vsi
->back
)) {
3901 dev_err(ice_pf_to_dev(vsi
->back
), "Device is in Safe Mode - not enabling advanced netdev features\n");
3905 /* Do not change setting during reset */
3906 if (ice_is_reset_in_progress(pf
->state
)) {
3907 dev_err(ice_pf_to_dev(vsi
->back
), "Device is resetting, changing advanced netdev features temporarily unavailable.\n");
3911 /* Multiple features can be changed in one call so keep features in
3912 * separate if/else statements to guarantee each feature is checked
3914 if (features
& NETIF_F_RXHASH
&& !(netdev
->features
& NETIF_F_RXHASH
))
3915 ret
= ice_vsi_manage_rss_lut(vsi
, true);
3916 else if (!(features
& NETIF_F_RXHASH
) &&
3917 netdev
->features
& NETIF_F_RXHASH
)
3918 ret
= ice_vsi_manage_rss_lut(vsi
, false);
3920 if ((features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
3921 !(netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
))
3922 ret
= ice_vsi_manage_vlan_stripping(vsi
, true);
3923 else if (!(features
& NETIF_F_HW_VLAN_CTAG_RX
) &&
3924 (netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
))
3925 ret
= ice_vsi_manage_vlan_stripping(vsi
, false);
3927 if ((features
& NETIF_F_HW_VLAN_CTAG_TX
) &&
3928 !(netdev
->features
& NETIF_F_HW_VLAN_CTAG_TX
))
3929 ret
= ice_vsi_manage_vlan_insertion(vsi
);
3930 else if (!(features
& NETIF_F_HW_VLAN_CTAG_TX
) &&
3931 (netdev
->features
& NETIF_F_HW_VLAN_CTAG_TX
))
3932 ret
= ice_vsi_manage_vlan_insertion(vsi
);
3934 if ((features
& NETIF_F_HW_VLAN_CTAG_FILTER
) &&
3935 !(netdev
->features
& NETIF_F_HW_VLAN_CTAG_FILTER
))
3936 ret
= ice_cfg_vlan_pruning(vsi
, true, false);
3937 else if (!(features
& NETIF_F_HW_VLAN_CTAG_FILTER
) &&
3938 (netdev
->features
& NETIF_F_HW_VLAN_CTAG_FILTER
))
3939 ret
= ice_cfg_vlan_pruning(vsi
, false, false);
3945 * ice_vsi_vlan_setup - Setup VLAN offload properties on a VSI
3946 * @vsi: VSI to setup VLAN properties for
3948 static int ice_vsi_vlan_setup(struct ice_vsi
*vsi
)
3952 if (vsi
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_RX
)
3953 ret
= ice_vsi_manage_vlan_stripping(vsi
, true);
3954 if (vsi
->netdev
->features
& NETIF_F_HW_VLAN_CTAG_TX
)
3955 ret
= ice_vsi_manage_vlan_insertion(vsi
);
3961 * ice_vsi_cfg - Setup the VSI
3962 * @vsi: the VSI being configured
3964 * Return 0 on success and negative value on error
3966 int ice_vsi_cfg(struct ice_vsi
*vsi
)
3971 ice_set_rx_mode(vsi
->netdev
);
3973 err
= ice_vsi_vlan_setup(vsi
);
3978 ice_vsi_cfg_dcb_rings(vsi
);
3980 err
= ice_vsi_cfg_lan_txqs(vsi
);
3981 if (!err
&& ice_is_xdp_ena_vsi(vsi
))
3982 err
= ice_vsi_cfg_xdp_txqs(vsi
);
3984 err
= ice_vsi_cfg_rxqs(vsi
);
3990 * ice_napi_enable_all - Enable NAPI for all q_vectors in the VSI
3991 * @vsi: the VSI being configured
3993 static void ice_napi_enable_all(struct ice_vsi
*vsi
)
4000 ice_for_each_q_vector(vsi
, q_idx
) {
4001 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4003 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4004 napi_enable(&q_vector
->napi
);
4009 * ice_up_complete - Finish the last steps of bringing up a connection
4010 * @vsi: The VSI being configured
4012 * Return 0 on success and negative value on error
4014 static int ice_up_complete(struct ice_vsi
*vsi
)
4016 struct ice_pf
*pf
= vsi
->back
;
4019 ice_vsi_cfg_msix(vsi
);
4021 /* Enable only Rx rings, Tx rings were enabled by the FW when the
4022 * Tx queue group list was configured and the context bits were
4023 * programmed using ice_vsi_cfg_txqs
4025 err
= ice_vsi_start_all_rx_rings(vsi
);
4029 clear_bit(__ICE_DOWN
, vsi
->state
);
4030 ice_napi_enable_all(vsi
);
4031 ice_vsi_ena_irq(vsi
);
4033 if (vsi
->port_info
&&
4034 (vsi
->port_info
->phy
.link_info
.link_info
& ICE_AQ_LINK_UP
) &&
4036 ice_print_link_msg(vsi
, true);
4037 netif_tx_start_all_queues(vsi
->netdev
);
4038 netif_carrier_on(vsi
->netdev
);
4041 ice_service_task_schedule(pf
);
4047 * ice_up - Bring the connection back up after being down
4048 * @vsi: VSI being configured
4050 int ice_up(struct ice_vsi
*vsi
)
4054 err
= ice_vsi_cfg(vsi
);
4056 err
= ice_up_complete(vsi
);
4062 * ice_fetch_u64_stats_per_ring - get packets and bytes stats per ring
4063 * @ring: Tx or Rx ring to read stats from
4064 * @pkts: packets stats counter
4065 * @bytes: bytes stats counter
4067 * This function fetches stats from the ring considering the atomic operations
4068 * that needs to be performed to read u64 values in 32 bit machine.
4071 ice_fetch_u64_stats_per_ring(struct ice_ring
*ring
, u64
*pkts
, u64
*bytes
)
4080 start
= u64_stats_fetch_begin_irq(&ring
->syncp
);
4081 *pkts
= ring
->stats
.pkts
;
4082 *bytes
= ring
->stats
.bytes
;
4083 } while (u64_stats_fetch_retry_irq(&ring
->syncp
, start
));
4087 * ice_update_vsi_ring_stats - Update VSI stats counters
4088 * @vsi: the VSI to be updated
4090 static void ice_update_vsi_ring_stats(struct ice_vsi
*vsi
)
4092 struct rtnl_link_stats64
*vsi_stats
= &vsi
->net_stats
;
4093 struct ice_ring
*ring
;
4097 /* reset netdev stats */
4098 vsi_stats
->tx_packets
= 0;
4099 vsi_stats
->tx_bytes
= 0;
4100 vsi_stats
->rx_packets
= 0;
4101 vsi_stats
->rx_bytes
= 0;
4103 /* reset non-netdev (extended) stats */
4104 vsi
->tx_restart
= 0;
4106 vsi
->tx_linearize
= 0;
4107 vsi
->rx_buf_failed
= 0;
4108 vsi
->rx_page_failed
= 0;
4112 /* update Tx rings counters */
4113 ice_for_each_txq(vsi
, i
) {
4114 ring
= READ_ONCE(vsi
->tx_rings
[i
]);
4115 ice_fetch_u64_stats_per_ring(ring
, &pkts
, &bytes
);
4116 vsi_stats
->tx_packets
+= pkts
;
4117 vsi_stats
->tx_bytes
+= bytes
;
4118 vsi
->tx_restart
+= ring
->tx_stats
.restart_q
;
4119 vsi
->tx_busy
+= ring
->tx_stats
.tx_busy
;
4120 vsi
->tx_linearize
+= ring
->tx_stats
.tx_linearize
;
4123 /* update Rx rings counters */
4124 ice_for_each_rxq(vsi
, i
) {
4125 ring
= READ_ONCE(vsi
->rx_rings
[i
]);
4126 ice_fetch_u64_stats_per_ring(ring
, &pkts
, &bytes
);
4127 vsi_stats
->rx_packets
+= pkts
;
4128 vsi_stats
->rx_bytes
+= bytes
;
4129 vsi
->rx_buf_failed
+= ring
->rx_stats
.alloc_buf_failed
;
4130 vsi
->rx_page_failed
+= ring
->rx_stats
.alloc_page_failed
;
4137 * ice_update_vsi_stats - Update VSI stats counters
4138 * @vsi: the VSI to be updated
4140 void ice_update_vsi_stats(struct ice_vsi
*vsi
)
4142 struct rtnl_link_stats64
*cur_ns
= &vsi
->net_stats
;
4143 struct ice_eth_stats
*cur_es
= &vsi
->eth_stats
;
4144 struct ice_pf
*pf
= vsi
->back
;
4146 if (test_bit(__ICE_DOWN
, vsi
->state
) ||
4147 test_bit(__ICE_CFG_BUSY
, pf
->state
))
4150 /* get stats as recorded by Tx/Rx rings */
4151 ice_update_vsi_ring_stats(vsi
);
4153 /* get VSI stats as recorded by the hardware */
4154 ice_update_eth_stats(vsi
);
4156 cur_ns
->tx_errors
= cur_es
->tx_errors
;
4157 cur_ns
->rx_dropped
= cur_es
->rx_discards
;
4158 cur_ns
->tx_dropped
= cur_es
->tx_discards
;
4159 cur_ns
->multicast
= cur_es
->rx_multicast
;
4161 /* update some more netdev stats if this is main VSI */
4162 if (vsi
->type
== ICE_VSI_PF
) {
4163 cur_ns
->rx_crc_errors
= pf
->stats
.crc_errors
;
4164 cur_ns
->rx_errors
= pf
->stats
.crc_errors
+
4165 pf
->stats
.illegal_bytes
;
4166 cur_ns
->rx_length_errors
= pf
->stats
.rx_len_errors
;
4167 /* record drops from the port level */
4168 cur_ns
->rx_missed_errors
= pf
->stats
.eth
.rx_discards
;
4173 * ice_update_pf_stats - Update PF port stats counters
4174 * @pf: PF whose stats needs to be updated
4176 void ice_update_pf_stats(struct ice_pf
*pf
)
4178 struct ice_hw_port_stats
*prev_ps
, *cur_ps
;
4179 struct ice_hw
*hw
= &pf
->hw
;
4182 port
= hw
->port_info
->lport
;
4183 prev_ps
= &pf
->stats_prev
;
4184 cur_ps
= &pf
->stats
;
4186 ice_stat_update40(hw
, GLPRT_GORCL(port
), pf
->stat_prev_loaded
,
4187 &prev_ps
->eth
.rx_bytes
,
4188 &cur_ps
->eth
.rx_bytes
);
4190 ice_stat_update40(hw
, GLPRT_UPRCL(port
), pf
->stat_prev_loaded
,
4191 &prev_ps
->eth
.rx_unicast
,
4192 &cur_ps
->eth
.rx_unicast
);
4194 ice_stat_update40(hw
, GLPRT_MPRCL(port
), pf
->stat_prev_loaded
,
4195 &prev_ps
->eth
.rx_multicast
,
4196 &cur_ps
->eth
.rx_multicast
);
4198 ice_stat_update40(hw
, GLPRT_BPRCL(port
), pf
->stat_prev_loaded
,
4199 &prev_ps
->eth
.rx_broadcast
,
4200 &cur_ps
->eth
.rx_broadcast
);
4202 ice_stat_update32(hw
, PRTRPB_RDPC
, pf
->stat_prev_loaded
,
4203 &prev_ps
->eth
.rx_discards
,
4204 &cur_ps
->eth
.rx_discards
);
4206 ice_stat_update40(hw
, GLPRT_GOTCL(port
), pf
->stat_prev_loaded
,
4207 &prev_ps
->eth
.tx_bytes
,
4208 &cur_ps
->eth
.tx_bytes
);
4210 ice_stat_update40(hw
, GLPRT_UPTCL(port
), pf
->stat_prev_loaded
,
4211 &prev_ps
->eth
.tx_unicast
,
4212 &cur_ps
->eth
.tx_unicast
);
4214 ice_stat_update40(hw
, GLPRT_MPTCL(port
), pf
->stat_prev_loaded
,
4215 &prev_ps
->eth
.tx_multicast
,
4216 &cur_ps
->eth
.tx_multicast
);
4218 ice_stat_update40(hw
, GLPRT_BPTCL(port
), pf
->stat_prev_loaded
,
4219 &prev_ps
->eth
.tx_broadcast
,
4220 &cur_ps
->eth
.tx_broadcast
);
4222 ice_stat_update32(hw
, GLPRT_TDOLD(port
), pf
->stat_prev_loaded
,
4223 &prev_ps
->tx_dropped_link_down
,
4224 &cur_ps
->tx_dropped_link_down
);
4226 ice_stat_update40(hw
, GLPRT_PRC64L(port
), pf
->stat_prev_loaded
,
4227 &prev_ps
->rx_size_64
, &cur_ps
->rx_size_64
);
4229 ice_stat_update40(hw
, GLPRT_PRC127L(port
), pf
->stat_prev_loaded
,
4230 &prev_ps
->rx_size_127
, &cur_ps
->rx_size_127
);
4232 ice_stat_update40(hw
, GLPRT_PRC255L(port
), pf
->stat_prev_loaded
,
4233 &prev_ps
->rx_size_255
, &cur_ps
->rx_size_255
);
4235 ice_stat_update40(hw
, GLPRT_PRC511L(port
), pf
->stat_prev_loaded
,
4236 &prev_ps
->rx_size_511
, &cur_ps
->rx_size_511
);
4238 ice_stat_update40(hw
, GLPRT_PRC1023L(port
), pf
->stat_prev_loaded
,
4239 &prev_ps
->rx_size_1023
, &cur_ps
->rx_size_1023
);
4241 ice_stat_update40(hw
, GLPRT_PRC1522L(port
), pf
->stat_prev_loaded
,
4242 &prev_ps
->rx_size_1522
, &cur_ps
->rx_size_1522
);
4244 ice_stat_update40(hw
, GLPRT_PRC9522L(port
), pf
->stat_prev_loaded
,
4245 &prev_ps
->rx_size_big
, &cur_ps
->rx_size_big
);
4247 ice_stat_update40(hw
, GLPRT_PTC64L(port
), pf
->stat_prev_loaded
,
4248 &prev_ps
->tx_size_64
, &cur_ps
->tx_size_64
);
4250 ice_stat_update40(hw
, GLPRT_PTC127L(port
), pf
->stat_prev_loaded
,
4251 &prev_ps
->tx_size_127
, &cur_ps
->tx_size_127
);
4253 ice_stat_update40(hw
, GLPRT_PTC255L(port
), pf
->stat_prev_loaded
,
4254 &prev_ps
->tx_size_255
, &cur_ps
->tx_size_255
);
4256 ice_stat_update40(hw
, GLPRT_PTC511L(port
), pf
->stat_prev_loaded
,
4257 &prev_ps
->tx_size_511
, &cur_ps
->tx_size_511
);
4259 ice_stat_update40(hw
, GLPRT_PTC1023L(port
), pf
->stat_prev_loaded
,
4260 &prev_ps
->tx_size_1023
, &cur_ps
->tx_size_1023
);
4262 ice_stat_update40(hw
, GLPRT_PTC1522L(port
), pf
->stat_prev_loaded
,
4263 &prev_ps
->tx_size_1522
, &cur_ps
->tx_size_1522
);
4265 ice_stat_update40(hw
, GLPRT_PTC9522L(port
), pf
->stat_prev_loaded
,
4266 &prev_ps
->tx_size_big
, &cur_ps
->tx_size_big
);
4268 ice_stat_update32(hw
, GLPRT_LXONRXC(port
), pf
->stat_prev_loaded
,
4269 &prev_ps
->link_xon_rx
, &cur_ps
->link_xon_rx
);
4271 ice_stat_update32(hw
, GLPRT_LXOFFRXC(port
), pf
->stat_prev_loaded
,
4272 &prev_ps
->link_xoff_rx
, &cur_ps
->link_xoff_rx
);
4274 ice_stat_update32(hw
, GLPRT_LXONTXC(port
), pf
->stat_prev_loaded
,
4275 &prev_ps
->link_xon_tx
, &cur_ps
->link_xon_tx
);
4277 ice_stat_update32(hw
, GLPRT_LXOFFTXC(port
), pf
->stat_prev_loaded
,
4278 &prev_ps
->link_xoff_tx
, &cur_ps
->link_xoff_tx
);
4280 ice_update_dcb_stats(pf
);
4282 ice_stat_update32(hw
, GLPRT_CRCERRS(port
), pf
->stat_prev_loaded
,
4283 &prev_ps
->crc_errors
, &cur_ps
->crc_errors
);
4285 ice_stat_update32(hw
, GLPRT_ILLERRC(port
), pf
->stat_prev_loaded
,
4286 &prev_ps
->illegal_bytes
, &cur_ps
->illegal_bytes
);
4288 ice_stat_update32(hw
, GLPRT_MLFC(port
), pf
->stat_prev_loaded
,
4289 &prev_ps
->mac_local_faults
,
4290 &cur_ps
->mac_local_faults
);
4292 ice_stat_update32(hw
, GLPRT_MRFC(port
), pf
->stat_prev_loaded
,
4293 &prev_ps
->mac_remote_faults
,
4294 &cur_ps
->mac_remote_faults
);
4296 ice_stat_update32(hw
, GLPRT_RLEC(port
), pf
->stat_prev_loaded
,
4297 &prev_ps
->rx_len_errors
, &cur_ps
->rx_len_errors
);
4299 ice_stat_update32(hw
, GLPRT_RUC(port
), pf
->stat_prev_loaded
,
4300 &prev_ps
->rx_undersize
, &cur_ps
->rx_undersize
);
4302 ice_stat_update32(hw
, GLPRT_RFC(port
), pf
->stat_prev_loaded
,
4303 &prev_ps
->rx_fragments
, &cur_ps
->rx_fragments
);
4305 ice_stat_update32(hw
, GLPRT_ROC(port
), pf
->stat_prev_loaded
,
4306 &prev_ps
->rx_oversize
, &cur_ps
->rx_oversize
);
4308 ice_stat_update32(hw
, GLPRT_RJC(port
), pf
->stat_prev_loaded
,
4309 &prev_ps
->rx_jabber
, &cur_ps
->rx_jabber
);
4311 pf
->stat_prev_loaded
= true;
4315 * ice_get_stats64 - get statistics for network device structure
4316 * @netdev: network interface device structure
4317 * @stats: main device statistics structure
4320 void ice_get_stats64(struct net_device
*netdev
, struct rtnl_link_stats64
*stats
)
4322 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
4323 struct rtnl_link_stats64
*vsi_stats
;
4324 struct ice_vsi
*vsi
= np
->vsi
;
4326 vsi_stats
= &vsi
->net_stats
;
4328 if (!vsi
->num_txq
|| !vsi
->num_rxq
)
4331 /* netdev packet/byte stats come from ring counter. These are obtained
4332 * by summing up ring counters (done by ice_update_vsi_ring_stats).
4333 * But, only call the update routine and read the registers if VSI is
4336 if (!test_bit(__ICE_DOWN
, vsi
->state
))
4337 ice_update_vsi_ring_stats(vsi
);
4338 stats
->tx_packets
= vsi_stats
->tx_packets
;
4339 stats
->tx_bytes
= vsi_stats
->tx_bytes
;
4340 stats
->rx_packets
= vsi_stats
->rx_packets
;
4341 stats
->rx_bytes
= vsi_stats
->rx_bytes
;
4343 /* The rest of the stats can be read from the hardware but instead we
4344 * just return values that the watchdog task has already obtained from
4347 stats
->multicast
= vsi_stats
->multicast
;
4348 stats
->tx_errors
= vsi_stats
->tx_errors
;
4349 stats
->tx_dropped
= vsi_stats
->tx_dropped
;
4350 stats
->rx_errors
= vsi_stats
->rx_errors
;
4351 stats
->rx_dropped
= vsi_stats
->rx_dropped
;
4352 stats
->rx_crc_errors
= vsi_stats
->rx_crc_errors
;
4353 stats
->rx_length_errors
= vsi_stats
->rx_length_errors
;
4357 * ice_napi_disable_all - Disable NAPI for all q_vectors in the VSI
4358 * @vsi: VSI having NAPI disabled
4360 static void ice_napi_disable_all(struct ice_vsi
*vsi
)
4367 ice_for_each_q_vector(vsi
, q_idx
) {
4368 struct ice_q_vector
*q_vector
= vsi
->q_vectors
[q_idx
];
4370 if (q_vector
->rx
.ring
|| q_vector
->tx
.ring
)
4371 napi_disable(&q_vector
->napi
);
4376 * ice_down - Shutdown the connection
4377 * @vsi: The VSI being stopped
4379 int ice_down(struct ice_vsi
*vsi
)
4381 int i
, tx_err
, rx_err
, link_err
= 0;
4383 /* Caller of this function is expected to set the
4384 * vsi->state __ICE_DOWN bit
4387 netif_carrier_off(vsi
->netdev
);
4388 netif_tx_disable(vsi
->netdev
);
4391 ice_vsi_dis_irq(vsi
);
4393 tx_err
= ice_vsi_stop_lan_tx_rings(vsi
, ICE_NO_RESET
, 0);
4395 netdev_err(vsi
->netdev
, "Failed stop Tx rings, VSI %d error %d\n",
4396 vsi
->vsi_num
, tx_err
);
4397 if (!tx_err
&& ice_is_xdp_ena_vsi(vsi
)) {
4398 tx_err
= ice_vsi_stop_xdp_tx_rings(vsi
);
4400 netdev_err(vsi
->netdev
, "Failed stop XDP rings, VSI %d error %d\n",
4401 vsi
->vsi_num
, tx_err
);
4404 rx_err
= ice_vsi_stop_all_rx_rings(vsi
);
4406 netdev_err(vsi
->netdev
, "Failed stop Rx rings, VSI %d error %d\n",
4407 vsi
->vsi_num
, rx_err
);
4409 ice_napi_disable_all(vsi
);
4411 if (test_bit(ICE_FLAG_LINK_DOWN_ON_CLOSE_ENA
, vsi
->back
->flags
)) {
4412 link_err
= ice_force_phys_link_state(vsi
, false);
4414 netdev_err(vsi
->netdev
, "Failed to set physical link down, VSI %d error %d\n",
4415 vsi
->vsi_num
, link_err
);
4418 ice_for_each_txq(vsi
, i
)
4419 ice_clean_tx_ring(vsi
->tx_rings
[i
]);
4421 ice_for_each_rxq(vsi
, i
)
4422 ice_clean_rx_ring(vsi
->rx_rings
[i
]);
4424 if (tx_err
|| rx_err
|| link_err
) {
4425 netdev_err(vsi
->netdev
, "Failed to close VSI 0x%04X on switch 0x%04X\n",
4426 vsi
->vsi_num
, vsi
->vsw
->sw_id
);
4434 * ice_vsi_setup_tx_rings - Allocate VSI Tx queue resources
4435 * @vsi: VSI having resources allocated
4437 * Return 0 on success, negative on failure
4439 int ice_vsi_setup_tx_rings(struct ice_vsi
*vsi
)
4443 if (!vsi
->num_txq
) {
4444 dev_err(ice_pf_to_dev(vsi
->back
), "VSI %d has 0 Tx queues\n",
4449 ice_for_each_txq(vsi
, i
) {
4450 struct ice_ring
*ring
= vsi
->tx_rings
[i
];
4455 ring
->netdev
= vsi
->netdev
;
4456 err
= ice_setup_tx_ring(ring
);
4465 * ice_vsi_setup_rx_rings - Allocate VSI Rx queue resources
4466 * @vsi: VSI having resources allocated
4468 * Return 0 on success, negative on failure
4470 int ice_vsi_setup_rx_rings(struct ice_vsi
*vsi
)
4474 if (!vsi
->num_rxq
) {
4475 dev_err(ice_pf_to_dev(vsi
->back
), "VSI %d has 0 Rx queues\n",
4480 ice_for_each_rxq(vsi
, i
) {
4481 struct ice_ring
*ring
= vsi
->rx_rings
[i
];
4486 ring
->netdev
= vsi
->netdev
;
4487 err
= ice_setup_rx_ring(ring
);
4496 * ice_vsi_open - Called when a network interface is made active
4497 * @vsi: the VSI to open
4499 * Initialization of the VSI
4501 * Returns 0 on success, negative value on error
4503 static int ice_vsi_open(struct ice_vsi
*vsi
)
4505 char int_name
[ICE_INT_NAME_STR_LEN
];
4506 struct ice_pf
*pf
= vsi
->back
;
4509 /* allocate descriptors */
4510 err
= ice_vsi_setup_tx_rings(vsi
);
4514 err
= ice_vsi_setup_rx_rings(vsi
);
4518 err
= ice_vsi_cfg(vsi
);
4522 snprintf(int_name
, sizeof(int_name
) - 1, "%s-%s",
4523 dev_driver_string(ice_pf_to_dev(pf
)), vsi
->netdev
->name
);
4524 err
= ice_vsi_req_irq_msix(vsi
, int_name
);
4528 /* Notify the stack of the actual queue counts. */
4529 err
= netif_set_real_num_tx_queues(vsi
->netdev
, vsi
->num_txq
);
4533 err
= netif_set_real_num_rx_queues(vsi
->netdev
, vsi
->num_rxq
);
4537 err
= ice_up_complete(vsi
);
4539 goto err_up_complete
;
4546 ice_vsi_free_irq(vsi
);
4548 ice_vsi_free_rx_rings(vsi
);
4550 ice_vsi_free_tx_rings(vsi
);
4556 * ice_vsi_release_all - Delete all VSIs
4557 * @pf: PF from which all VSIs are being removed
4559 static void ice_vsi_release_all(struct ice_pf
*pf
)
4566 ice_for_each_vsi(pf
, i
) {
4570 err
= ice_vsi_release(pf
->vsi
[i
]);
4572 dev_dbg(ice_pf_to_dev(pf
), "Failed to release pf->vsi[%d], err %d, vsi_num = %d\n",
4573 i
, err
, pf
->vsi
[i
]->vsi_num
);
4578 * ice_vsi_rebuild_by_type - Rebuild VSI of a given type
4579 * @pf: pointer to the PF instance
4580 * @type: VSI type to rebuild
4582 * Iterates through the pf->vsi array and rebuilds VSIs of the requested type
4584 static int ice_vsi_rebuild_by_type(struct ice_pf
*pf
, enum ice_vsi_type type
)
4586 struct device
*dev
= ice_pf_to_dev(pf
);
4587 enum ice_status status
;
4590 ice_for_each_vsi(pf
, i
) {
4591 struct ice_vsi
*vsi
= pf
->vsi
[i
];
4593 if (!vsi
|| vsi
->type
!= type
)
4596 /* rebuild the VSI */
4597 err
= ice_vsi_rebuild(vsi
, true);
4599 dev_err(dev
, "rebuild VSI failed, err %d, VSI index %d, type %s\n",
4600 err
, vsi
->idx
, ice_vsi_type_str(type
));
4604 /* replay filters for the VSI */
4605 status
= ice_replay_vsi(&pf
->hw
, vsi
->idx
);
4607 dev_err(dev
, "replay VSI failed, status %d, VSI index %d, type %s\n",
4608 status
, vsi
->idx
, ice_vsi_type_str(type
));
4612 /* Re-map HW VSI number, using VSI handle that has been
4613 * previously validated in ice_replay_vsi() call above
4615 vsi
->vsi_num
= ice_get_hw_vsi_num(&pf
->hw
, vsi
->idx
);
4617 /* enable the VSI */
4618 err
= ice_ena_vsi(vsi
, false);
4620 dev_err(dev
, "enable VSI failed, err %d, VSI index %d, type %s\n",
4621 err
, vsi
->idx
, ice_vsi_type_str(type
));
4625 dev_info(dev
, "VSI rebuilt. VSI index %d, type %s\n", vsi
->idx
,
4626 ice_vsi_type_str(type
));
4633 * ice_update_pf_netdev_link - Update PF netdev link status
4634 * @pf: pointer to the PF instance
4636 static void ice_update_pf_netdev_link(struct ice_pf
*pf
)
4641 ice_for_each_vsi(pf
, i
) {
4642 struct ice_vsi
*vsi
= pf
->vsi
[i
];
4644 if (!vsi
|| vsi
->type
!= ICE_VSI_PF
)
4647 ice_get_link_status(pf
->vsi
[i
]->port_info
, &link_up
);
4649 netif_carrier_on(pf
->vsi
[i
]->netdev
);
4650 netif_tx_wake_all_queues(pf
->vsi
[i
]->netdev
);
4652 netif_carrier_off(pf
->vsi
[i
]->netdev
);
4653 netif_tx_stop_all_queues(pf
->vsi
[i
]->netdev
);
4659 * ice_rebuild - rebuild after reset
4660 * @pf: PF to rebuild
4661 * @reset_type: type of reset
4663 static void ice_rebuild(struct ice_pf
*pf
, enum ice_reset_req reset_type
)
4665 struct device
*dev
= ice_pf_to_dev(pf
);
4666 struct ice_hw
*hw
= &pf
->hw
;
4667 enum ice_status ret
;
4670 if (test_bit(__ICE_DOWN
, pf
->state
))
4671 goto clear_recovery
;
4673 dev_dbg(dev
, "rebuilding PF after reset_type=%d\n", reset_type
);
4675 ret
= ice_init_all_ctrlq(hw
);
4677 dev_err(dev
, "control queues init failed %d\n", ret
);
4678 goto err_init_ctrlq
;
4681 /* if DDP was previously loaded successfully */
4682 if (!ice_is_safe_mode(pf
)) {
4683 /* reload the SW DB of filter tables */
4684 if (reset_type
== ICE_RESET_PFR
)
4685 ice_fill_blk_tbls(hw
);
4687 /* Reload DDP Package after CORER/GLOBR reset */
4688 ice_load_pkg(NULL
, pf
);
4691 ret
= ice_clear_pf_cfg(hw
);
4693 dev_err(dev
, "clear PF configuration failed %d\n", ret
);
4694 goto err_init_ctrlq
;
4697 if (pf
->first_sw
->dflt_vsi_ena
)
4698 dev_info(dev
, "Clearing default VSI, re-enable after reset completes\n");
4699 /* clear the default VSI configuration if it exists */
4700 pf
->first_sw
->dflt_vsi
= NULL
;
4701 pf
->first_sw
->dflt_vsi_ena
= false;
4703 ice_clear_pxe_mode(hw
);
4705 ret
= ice_get_caps(hw
);
4707 dev_err(dev
, "ice_get_caps failed %d\n", ret
);
4708 goto err_init_ctrlq
;
4711 err
= ice_sched_init_port(hw
->port_info
);
4713 goto err_sched_init_port
;
4715 err
= ice_update_link_info(hw
->port_info
);
4717 dev_err(dev
, "Get link status error %d\n", err
);
4719 /* start misc vector */
4720 err
= ice_req_irq_msix_misc(pf
);
4722 dev_err(dev
, "misc vector setup failed: %d\n", err
);
4723 goto err_sched_init_port
;
4726 if (test_bit(ICE_FLAG_DCB_ENA
, pf
->flags
))
4727 ice_dcb_rebuild(pf
);
4729 /* rebuild PF VSI */
4730 err
= ice_vsi_rebuild_by_type(pf
, ICE_VSI_PF
);
4732 dev_err(dev
, "PF VSI rebuild failed: %d\n", err
);
4733 goto err_vsi_rebuild
;
4736 if (test_bit(ICE_FLAG_SRIOV_ENA
, pf
->flags
)) {
4737 err
= ice_vsi_rebuild_by_type(pf
, ICE_VSI_VF
);
4739 dev_err(dev
, "VF VSI rebuild failed: %d\n", err
);
4740 goto err_vsi_rebuild
;
4744 ice_update_pf_netdev_link(pf
);
4746 /* tell the firmware we are up */
4747 ret
= ice_send_version(pf
);
4749 dev_err(dev
, "Rebuild failed due to error sending driver version: %d\n",
4751 goto err_vsi_rebuild
;
4754 ice_replay_post(hw
);
4756 /* if we get here, reset flow is successful */
4757 clear_bit(__ICE_RESET_FAILED
, pf
->state
);
4761 err_sched_init_port
:
4762 ice_sched_cleanup_all(hw
);
4764 ice_shutdown_all_ctrlq(hw
);
4765 set_bit(__ICE_RESET_FAILED
, pf
->state
);
4767 /* set this bit in PF state to control service task scheduling */
4768 set_bit(__ICE_NEEDS_RESTART
, pf
->state
);
4769 dev_err(dev
, "Rebuild failed, unload and reload driver\n");
4773 * ice_max_xdp_frame_size - returns the maximum allowed frame size for XDP
4774 * @vsi: Pointer to VSI structure
4776 static int ice_max_xdp_frame_size(struct ice_vsi
*vsi
)
4778 if (PAGE_SIZE
>= 8192 || test_bit(ICE_FLAG_LEGACY_RX
, vsi
->back
->flags
))
4779 return ICE_RXBUF_2048
- XDP_PACKET_HEADROOM
;
4781 return ICE_RXBUF_3072
;
4785 * ice_change_mtu - NDO callback to change the MTU
4786 * @netdev: network interface device structure
4787 * @new_mtu: new value for maximum frame size
4789 * Returns 0 on success, negative on failure
4791 static int ice_change_mtu(struct net_device
*netdev
, int new_mtu
)
4793 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
4794 struct ice_vsi
*vsi
= np
->vsi
;
4795 struct ice_pf
*pf
= vsi
->back
;
4798 if (new_mtu
== netdev
->mtu
) {
4799 netdev_warn(netdev
, "MTU is already %u\n", netdev
->mtu
);
4803 if (ice_is_xdp_ena_vsi(vsi
)) {
4804 int frame_size
= ice_max_xdp_frame_size(vsi
);
4806 if (new_mtu
+ ICE_ETH_PKT_HDR_PAD
> frame_size
) {
4807 netdev_err(netdev
, "max MTU for XDP usage is %d\n",
4808 frame_size
- ICE_ETH_PKT_HDR_PAD
);
4813 if (new_mtu
< netdev
->min_mtu
) {
4814 netdev_err(netdev
, "new MTU invalid. min_mtu is %d\n",
4817 } else if (new_mtu
> netdev
->max_mtu
) {
4818 netdev_err(netdev
, "new MTU invalid. max_mtu is %d\n",
4822 /* if a reset is in progress, wait for some time for it to complete */
4824 if (ice_is_reset_in_progress(pf
->state
)) {
4826 usleep_range(1000, 2000);
4831 } while (count
< 100);
4834 netdev_err(netdev
, "can't change MTU. Device is busy\n");
4838 netdev
->mtu
= new_mtu
;
4840 /* if VSI is up, bring it down and then back up */
4841 if (!test_and_set_bit(__ICE_DOWN
, vsi
->state
)) {
4844 err
= ice_down(vsi
);
4846 netdev_err(netdev
, "change MTU if_up err %d\n", err
);
4852 netdev_err(netdev
, "change MTU if_up err %d\n", err
);
4857 netdev_dbg(netdev
, "changed MTU to %d\n", new_mtu
);
4862 * ice_set_rss - Set RSS keys and lut
4863 * @vsi: Pointer to VSI structure
4864 * @seed: RSS hash seed
4865 * @lut: Lookup table
4866 * @lut_size: Lookup table size
4868 * Returns 0 on success, negative on failure
4870 int ice_set_rss(struct ice_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
4872 struct ice_pf
*pf
= vsi
->back
;
4873 struct ice_hw
*hw
= &pf
->hw
;
4874 enum ice_status status
;
4877 dev
= ice_pf_to_dev(pf
);
4879 struct ice_aqc_get_set_rss_keys
*buf
=
4880 (struct ice_aqc_get_set_rss_keys
*)seed
;
4882 status
= ice_aq_set_rss_key(hw
, vsi
->idx
, buf
);
4885 dev_err(dev
, "Cannot set RSS key, err %d aq_err %d\n",
4886 status
, hw
->adminq
.rq_last_status
);
4892 status
= ice_aq_set_rss_lut(hw
, vsi
->idx
, vsi
->rss_lut_type
,
4895 dev_err(dev
, "Cannot set RSS lut, err %d aq_err %d\n",
4896 status
, hw
->adminq
.rq_last_status
);
4905 * ice_get_rss - Get RSS keys and lut
4906 * @vsi: Pointer to VSI structure
4907 * @seed: Buffer to store the keys
4908 * @lut: Buffer to store the lookup table entries
4909 * @lut_size: Size of buffer to store the lookup table entries
4911 * Returns 0 on success, negative on failure
4913 int ice_get_rss(struct ice_vsi
*vsi
, u8
*seed
, u8
*lut
, u16 lut_size
)
4915 struct ice_pf
*pf
= vsi
->back
;
4916 struct ice_hw
*hw
= &pf
->hw
;
4917 enum ice_status status
;
4920 dev
= ice_pf_to_dev(pf
);
4922 struct ice_aqc_get_set_rss_keys
*buf
=
4923 (struct ice_aqc_get_set_rss_keys
*)seed
;
4925 status
= ice_aq_get_rss_key(hw
, vsi
->idx
, buf
);
4927 dev_err(dev
, "Cannot get RSS key, err %d aq_err %d\n",
4928 status
, hw
->adminq
.rq_last_status
);
4934 status
= ice_aq_get_rss_lut(hw
, vsi
->idx
, vsi
->rss_lut_type
,
4937 dev_err(dev
, "Cannot get RSS lut, err %d aq_err %d\n",
4938 status
, hw
->adminq
.rq_last_status
);
4947 * ice_bridge_getlink - Get the hardware bridge mode
4950 * @seq: RTNL message seq
4951 * @dev: the netdev being configured
4952 * @filter_mask: filter mask passed in
4953 * @nlflags: netlink flags passed in
4955 * Return the bridge mode (VEB/VEPA)
4958 ice_bridge_getlink(struct sk_buff
*skb
, u32 pid
, u32 seq
,
4959 struct net_device
*dev
, u32 filter_mask
, int nlflags
)
4961 struct ice_netdev_priv
*np
= netdev_priv(dev
);
4962 struct ice_vsi
*vsi
= np
->vsi
;
4963 struct ice_pf
*pf
= vsi
->back
;
4966 bmode
= pf
->first_sw
->bridge_mode
;
4968 return ndo_dflt_bridge_getlink(skb
, pid
, seq
, dev
, bmode
, 0, 0, nlflags
,
4973 * ice_vsi_update_bridge_mode - Update VSI for switching bridge mode (VEB/VEPA)
4974 * @vsi: Pointer to VSI structure
4975 * @bmode: Hardware bridge mode (VEB/VEPA)
4977 * Returns 0 on success, negative on failure
4979 static int ice_vsi_update_bridge_mode(struct ice_vsi
*vsi
, u16 bmode
)
4981 struct ice_aqc_vsi_props
*vsi_props
;
4982 struct ice_hw
*hw
= &vsi
->back
->hw
;
4983 struct ice_vsi_ctx
*ctxt
;
4984 enum ice_status status
;
4987 vsi_props
= &vsi
->info
;
4989 ctxt
= kzalloc(sizeof(*ctxt
), GFP_KERNEL
);
4993 ctxt
->info
= vsi
->info
;
4995 if (bmode
== BRIDGE_MODE_VEB
)
4996 /* change from VEPA to VEB mode */
4997 ctxt
->info
.sw_flags
|= ICE_AQ_VSI_SW_FLAG_ALLOW_LB
;
4999 /* change from VEB to VEPA mode */
5000 ctxt
->info
.sw_flags
&= ~ICE_AQ_VSI_SW_FLAG_ALLOW_LB
;
5001 ctxt
->info
.valid_sections
= cpu_to_le16(ICE_AQ_VSI_PROP_SW_VALID
);
5003 status
= ice_update_vsi(hw
, vsi
->idx
, ctxt
, NULL
);
5005 dev_err(ice_pf_to_dev(vsi
->back
), "update VSI for bridge mode failed, bmode = %d err %d aq_err %d\n",
5006 bmode
, status
, hw
->adminq
.sq_last_status
);
5010 /* Update sw flags for book keeping */
5011 vsi_props
->sw_flags
= ctxt
->info
.sw_flags
;
5019 * ice_bridge_setlink - Set the hardware bridge mode
5020 * @dev: the netdev being configured
5021 * @nlh: RTNL message
5022 * @flags: bridge setlink flags
5023 * @extack: netlink extended ack
5025 * Sets the bridge mode (VEB/VEPA) of the switch to which the netdev (VSI) is
5026 * hooked up to. Iterates through the PF VSI list and sets the loopback mode (if
5027 * not already set for all VSIs connected to this switch. And also update the
5028 * unicast switch filter rules for the corresponding switch of the netdev.
5031 ice_bridge_setlink(struct net_device
*dev
, struct nlmsghdr
*nlh
,
5032 u16 __always_unused flags
,
5033 struct netlink_ext_ack __always_unused
*extack
)
5035 struct ice_netdev_priv
*np
= netdev_priv(dev
);
5036 struct ice_pf
*pf
= np
->vsi
->back
;
5037 struct nlattr
*attr
, *br_spec
;
5038 struct ice_hw
*hw
= &pf
->hw
;
5039 enum ice_status status
;
5040 struct ice_sw
*pf_sw
;
5041 int rem
, v
, err
= 0;
5043 pf_sw
= pf
->first_sw
;
5044 /* find the attribute in the netlink message */
5045 br_spec
= nlmsg_find_attr(nlh
, sizeof(struct ifinfomsg
), IFLA_AF_SPEC
);
5047 nla_for_each_nested(attr
, br_spec
, rem
) {
5050 if (nla_type(attr
) != IFLA_BRIDGE_MODE
)
5052 mode
= nla_get_u16(attr
);
5053 if (mode
!= BRIDGE_MODE_VEPA
&& mode
!= BRIDGE_MODE_VEB
)
5055 /* Continue if bridge mode is not being flipped */
5056 if (mode
== pf_sw
->bridge_mode
)
5058 /* Iterates through the PF VSI list and update the loopback
5061 ice_for_each_vsi(pf
, v
) {
5064 err
= ice_vsi_update_bridge_mode(pf
->vsi
[v
], mode
);
5069 hw
->evb_veb
= (mode
== BRIDGE_MODE_VEB
);
5070 /* Update the unicast switch filter rules for the corresponding
5071 * switch of the netdev
5073 status
= ice_update_sw_rule_bridge_mode(hw
);
5075 netdev_err(dev
, "switch rule update failed, mode = %d err %d aq_err %d\n",
5076 mode
, status
, hw
->adminq
.sq_last_status
);
5077 /* revert hw->evb_veb */
5078 hw
->evb_veb
= (pf_sw
->bridge_mode
== BRIDGE_MODE_VEB
);
5082 pf_sw
->bridge_mode
= mode
;
5089 * ice_tx_timeout - Respond to a Tx Hang
5090 * @netdev: network interface device structure
5091 * @txqueue: Tx queue
5093 static void ice_tx_timeout(struct net_device
*netdev
, unsigned int txqueue
)
5095 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
5096 struct ice_ring
*tx_ring
= NULL
;
5097 struct ice_vsi
*vsi
= np
->vsi
;
5098 struct ice_pf
*pf
= vsi
->back
;
5101 pf
->tx_timeout_count
++;
5103 /* now that we have an index, find the tx_ring struct */
5104 for (i
= 0; i
< vsi
->num_txq
; i
++)
5105 if (vsi
->tx_rings
[i
] && vsi
->tx_rings
[i
]->desc
)
5106 if (txqueue
== vsi
->tx_rings
[i
]->q_index
) {
5107 tx_ring
= vsi
->tx_rings
[i
];
5111 /* Reset recovery level if enough time has elapsed after last timeout.
5112 * Also ensure no new reset action happens before next timeout period.
5114 if (time_after(jiffies
, (pf
->tx_timeout_last_recovery
+ HZ
* 20)))
5115 pf
->tx_timeout_recovery_level
= 1;
5116 else if (time_before(jiffies
, (pf
->tx_timeout_last_recovery
+
5117 netdev
->watchdog_timeo
)))
5121 struct ice_hw
*hw
= &pf
->hw
;
5124 head
= (rd32(hw
, QTX_COMM_HEAD(vsi
->txq_map
[txqueue
])) &
5125 QTX_COMM_HEAD_HEAD_M
) >> QTX_COMM_HEAD_HEAD_S
;
5126 /* Read interrupt register */
5127 val
= rd32(hw
, GLINT_DYN_CTL(tx_ring
->q_vector
->reg_idx
));
5129 netdev_info(netdev
, "tx_timeout: VSI_num: %d, Q %u, NTC: 0x%x, HW_HEAD: 0x%x, NTU: 0x%x, INT: 0x%x\n",
5130 vsi
->vsi_num
, txqueue
, tx_ring
->next_to_clean
,
5131 head
, tx_ring
->next_to_use
, val
);
5134 pf
->tx_timeout_last_recovery
= jiffies
;
5135 netdev_info(netdev
, "tx_timeout recovery level %d, txqueue %u\n",
5136 pf
->tx_timeout_recovery_level
, txqueue
);
5138 switch (pf
->tx_timeout_recovery_level
) {
5140 set_bit(__ICE_PFR_REQ
, pf
->state
);
5143 set_bit(__ICE_CORER_REQ
, pf
->state
);
5146 set_bit(__ICE_GLOBR_REQ
, pf
->state
);
5149 netdev_err(netdev
, "tx_timeout recovery unsuccessful, device is in unrecoverable state.\n");
5150 set_bit(__ICE_DOWN
, pf
->state
);
5151 set_bit(__ICE_NEEDS_RESTART
, vsi
->state
);
5152 set_bit(__ICE_SERVICE_DIS
, pf
->state
);
5156 ice_service_task_schedule(pf
);
5157 pf
->tx_timeout_recovery_level
++;
5161 * ice_open - Called when a network interface becomes active
5162 * @netdev: network interface device structure
5164 * The open entry point is called when a network interface is made
5165 * active by the system (IFF_UP). At this point all resources needed
5166 * for transmit and receive operations are allocated, the interrupt
5167 * handler is registered with the OS, the netdev watchdog is enabled,
5168 * and the stack is notified that the interface is ready.
5170 * Returns 0 on success, negative value on failure
5172 int ice_open(struct net_device
*netdev
)
5174 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
5175 struct ice_vsi
*vsi
= np
->vsi
;
5176 struct ice_port_info
*pi
;
5179 if (test_bit(__ICE_NEEDS_RESTART
, vsi
->back
->state
)) {
5180 netdev_err(netdev
, "driver needs to be unloaded and reloaded\n");
5184 netif_carrier_off(netdev
);
5186 pi
= vsi
->port_info
;
5187 err
= ice_update_link_info(pi
);
5189 netdev_err(netdev
, "Failed to get link info, error %d\n",
5194 /* Set PHY if there is media, otherwise, turn off PHY */
5195 if (pi
->phy
.link_info
.link_info
& ICE_AQ_MEDIA_AVAILABLE
) {
5196 err
= ice_force_phys_link_state(vsi
, true);
5198 netdev_err(netdev
, "Failed to set physical link up, error %d\n",
5203 err
= ice_aq_set_link_restart_an(pi
, false, NULL
);
5205 netdev_err(netdev
, "Failed to set PHY state, VSI %d error %d\n",
5209 set_bit(ICE_FLAG_NO_MEDIA
, vsi
->back
->flags
);
5212 err
= ice_vsi_open(vsi
);
5214 netdev_err(netdev
, "Failed to open VSI 0x%04X on switch 0x%04X\n",
5215 vsi
->vsi_num
, vsi
->vsw
->sw_id
);
5220 * ice_stop - Disables a network interface
5221 * @netdev: network interface device structure
5223 * The stop entry point is called when an interface is de-activated by the OS,
5224 * and the netdevice enters the DOWN state. The hardware is still under the
5225 * driver's control, but the netdev interface is disabled.
5227 * Returns success only - not allowed to fail
5229 int ice_stop(struct net_device
*netdev
)
5231 struct ice_netdev_priv
*np
= netdev_priv(netdev
);
5232 struct ice_vsi
*vsi
= np
->vsi
;
5240 * ice_features_check - Validate encapsulated packet conforms to limits
5242 * @netdev: This port's netdev
5243 * @features: Offload features that the stack believes apply
5245 static netdev_features_t
5246 ice_features_check(struct sk_buff
*skb
,
5247 struct net_device __always_unused
*netdev
,
5248 netdev_features_t features
)
5252 /* No point in doing any of this if neither checksum nor GSO are
5253 * being requested for this frame. We can rule out both by just
5254 * checking for CHECKSUM_PARTIAL
5256 if (skb
->ip_summed
!= CHECKSUM_PARTIAL
)
5259 /* We cannot support GSO if the MSS is going to be less than
5260 * 64 bytes. If it is then we need to drop support for GSO.
5262 if (skb_is_gso(skb
) && (skb_shinfo(skb
)->gso_size
< 64))
5263 features
&= ~NETIF_F_GSO_MASK
;
5265 len
= skb_network_header(skb
) - skb
->data
;
5266 if (len
& ~(ICE_TXD_MACLEN_MAX
))
5267 goto out_rm_features
;
5269 len
= skb_transport_header(skb
) - skb_network_header(skb
);
5270 if (len
& ~(ICE_TXD_IPLEN_MAX
))
5271 goto out_rm_features
;
5273 if (skb
->encapsulation
) {
5274 len
= skb_inner_network_header(skb
) - skb_transport_header(skb
);
5275 if (len
& ~(ICE_TXD_L4LEN_MAX
))
5276 goto out_rm_features
;
5278 len
= skb_inner_transport_header(skb
) -
5279 skb_inner_network_header(skb
);
5280 if (len
& ~(ICE_TXD_IPLEN_MAX
))
5281 goto out_rm_features
;
5286 return features
& ~(NETIF_F_CSUM_MASK
| NETIF_F_GSO_MASK
);
5289 static const struct net_device_ops ice_netdev_safe_mode_ops
= {
5290 .ndo_open
= ice_open
,
5291 .ndo_stop
= ice_stop
,
5292 .ndo_start_xmit
= ice_start_xmit
,
5293 .ndo_set_mac_address
= ice_set_mac_address
,
5294 .ndo_validate_addr
= eth_validate_addr
,
5295 .ndo_change_mtu
= ice_change_mtu
,
5296 .ndo_get_stats64
= ice_get_stats64
,
5297 .ndo_tx_timeout
= ice_tx_timeout
,
5300 static const struct net_device_ops ice_netdev_ops
= {
5301 .ndo_open
= ice_open
,
5302 .ndo_stop
= ice_stop
,
5303 .ndo_start_xmit
= ice_start_xmit
,
5304 .ndo_features_check
= ice_features_check
,
5305 .ndo_set_rx_mode
= ice_set_rx_mode
,
5306 .ndo_set_mac_address
= ice_set_mac_address
,
5307 .ndo_validate_addr
= eth_validate_addr
,
5308 .ndo_change_mtu
= ice_change_mtu
,
5309 .ndo_get_stats64
= ice_get_stats64
,
5310 .ndo_set_tx_maxrate
= ice_set_tx_maxrate
,
5311 .ndo_set_vf_spoofchk
= ice_set_vf_spoofchk
,
5312 .ndo_set_vf_mac
= ice_set_vf_mac
,
5313 .ndo_get_vf_config
= ice_get_vf_cfg
,
5314 .ndo_set_vf_trust
= ice_set_vf_trust
,
5315 .ndo_set_vf_vlan
= ice_set_vf_port_vlan
,
5316 .ndo_set_vf_link_state
= ice_set_vf_link_state
,
5317 .ndo_get_vf_stats
= ice_get_vf_stats
,
5318 .ndo_vlan_rx_add_vid
= ice_vlan_rx_add_vid
,
5319 .ndo_vlan_rx_kill_vid
= ice_vlan_rx_kill_vid
,
5320 .ndo_set_features
= ice_set_features
,
5321 .ndo_bridge_getlink
= ice_bridge_getlink
,
5322 .ndo_bridge_setlink
= ice_bridge_setlink
,
5323 .ndo_fdb_add
= ice_fdb_add
,
5324 .ndo_fdb_del
= ice_fdb_del
,
5325 .ndo_tx_timeout
= ice_tx_timeout
,
5327 .ndo_xdp_xmit
= ice_xdp_xmit
,
5328 .ndo_xsk_wakeup
= ice_xsk_wakeup
,