xref: /freebsd-src/sys/dev/ice/ice_iflib.h (revision f2635e844dd138ac9dfba676f27d41750049af26)
171d10453SEric Joyner /* SPDX-License-Identifier: BSD-3-Clause */
2015f8cc5SEric Joyner /*  Copyright (c) 2024, Intel Corporation
371d10453SEric Joyner  *  All rights reserved.
471d10453SEric Joyner  *
571d10453SEric Joyner  *  Redistribution and use in source and binary forms, with or without
671d10453SEric Joyner  *  modification, are permitted provided that the following conditions are met:
771d10453SEric Joyner  *
871d10453SEric Joyner  *   1. Redistributions of source code must retain the above copyright notice,
971d10453SEric Joyner  *      this list of conditions and the following disclaimer.
1071d10453SEric Joyner  *
1171d10453SEric Joyner  *   2. Redistributions in binary form must reproduce the above copyright
1271d10453SEric Joyner  *      notice, this list of conditions and the following disclaimer in the
1371d10453SEric Joyner  *      documentation and/or other materials provided with the distribution.
1471d10453SEric Joyner  *
1571d10453SEric Joyner  *   3. Neither the name of the Intel Corporation nor the names of its
1671d10453SEric Joyner  *      contributors may be used to endorse or promote products derived from
1771d10453SEric Joyner  *      this software without specific prior written permission.
1871d10453SEric Joyner  *
1971d10453SEric Joyner  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2071d10453SEric Joyner  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2171d10453SEric Joyner  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2271d10453SEric Joyner  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2371d10453SEric Joyner  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2471d10453SEric Joyner  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2571d10453SEric Joyner  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2671d10453SEric Joyner  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2771d10453SEric Joyner  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2871d10453SEric Joyner  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2971d10453SEric Joyner  *  POSSIBILITY OF SUCH DAMAGE.
3071d10453SEric Joyner  */
3171d10453SEric Joyner 
3271d10453SEric Joyner /**
3371d10453SEric Joyner  * @file ice_iflib.h
3471d10453SEric Joyner  * @brief main header for the iflib driver implementation
3571d10453SEric Joyner  *
3671d10453SEric Joyner  * Contains the definitions for various structures used by the iflib driver
3771d10453SEric Joyner  * implementation, including the Tx and Rx queue structures and the ice_softc
3871d10453SEric Joyner  * structure.
3971d10453SEric Joyner  */
4071d10453SEric Joyner 
4171d10453SEric Joyner #ifndef _ICE_IFLIB_H_
4271d10453SEric Joyner #define _ICE_IFLIB_H_
4371d10453SEric Joyner 
4471d10453SEric Joyner /* include kernel options first */
4571d10453SEric Joyner #include "ice_opts.h"
4671d10453SEric Joyner 
4771d10453SEric Joyner #include <sys/param.h>
4871d10453SEric Joyner #include <sys/types.h>
4971d10453SEric Joyner #include <sys/socket.h>
5071d10453SEric Joyner #include <sys/time.h>
5171d10453SEric Joyner #include <net/if.h>
5271d10453SEric Joyner #include <net/if_var.h>
5371d10453SEric Joyner #include <net/if_media.h>
5471d10453SEric Joyner #include <net/ethernet.h>
5571d10453SEric Joyner #include <net/iflib.h>
5671d10453SEric Joyner #include "ifdi_if.h"
5771d10453SEric Joyner 
5871d10453SEric Joyner #include "ice_lib.h"
5971d10453SEric Joyner #include "ice_osdep.h"
6071d10453SEric Joyner #include "ice_resmgr.h"
6171d10453SEric Joyner #include "ice_type.h"
6271d10453SEric Joyner #include "ice_features.h"
6371d10453SEric Joyner 
6471d10453SEric Joyner /**
6571d10453SEric Joyner  * ASSERT_CTX_LOCKED - Assert that the iflib context lock is held
6671d10453SEric Joyner  * @sc: ice softc pointer
6771d10453SEric Joyner  *
6871d10453SEric Joyner  * Macro to trigger an assertion if the iflib context lock is not
6971d10453SEric Joyner  * currently held.
7071d10453SEric Joyner  */
7171d10453SEric Joyner #define ASSERT_CTX_LOCKED(sc) sx_assert((sc)->iflib_ctx_lock, SA_XLOCKED)
7271d10453SEric Joyner 
7371d10453SEric Joyner /**
7471d10453SEric Joyner  * IFLIB_CTX_LOCK - lock the iflib context lock
7571d10453SEric Joyner  * @sc: ice softc pointer
7671d10453SEric Joyner  *
7771d10453SEric Joyner  * Macro used to unlock the iflib context lock.
7871d10453SEric Joyner  */
7971d10453SEric Joyner #define IFLIB_CTX_LOCK(sc) sx_xlock((sc)->iflib_ctx_lock)
8071d10453SEric Joyner 
8171d10453SEric Joyner /**
8271d10453SEric Joyner  * IFLIB_CTX_UNLOCK - unlock the iflib context lock
8371d10453SEric Joyner  * @sc: ice softc pointer
8471d10453SEric Joyner  *
8571d10453SEric Joyner  * Macro used to unlock the iflib context lock.
8671d10453SEric Joyner  */
8771d10453SEric Joyner #define IFLIB_CTX_UNLOCK(sc) sx_xunlock((sc)->iflib_ctx_lock)
8871d10453SEric Joyner 
8971d10453SEric Joyner /**
9071d10453SEric Joyner  * ASSERT_CFG_LOCKED - Assert that a configuration lock is held
9171d10453SEric Joyner  * @sc: ice softc pointer
9271d10453SEric Joyner  *
9371d10453SEric Joyner  * Macro used by ice_lib.c to verify that certain functions are called while
9471d10453SEric Joyner  * holding a configuration lock. For the iflib implementation, this will be
9571d10453SEric Joyner  * the iflib context lock.
9671d10453SEric Joyner  */
9771d10453SEric Joyner #define ASSERT_CFG_LOCKED(sc) ASSERT_CTX_LOCKED(sc)
9871d10453SEric Joyner 
9971d10453SEric Joyner /**
10071d10453SEric Joyner  * ICE_IFLIB_MAX_DESC_COUNT - Maximum ring size for iflib
10171d10453SEric Joyner  *
10271d10453SEric Joyner  * The iflib stack currently requires that the ring size, or number of
10371d10453SEric Joyner  * descriptors, be a power of 2. The ice hardware is limited to a maximum of
10471d10453SEric Joyner  * 8160 descriptors, which is not quite 2^13. Limit the maximum ring size for
10571d10453SEric Joyner  * iflib to just 2^12 (4096).
10671d10453SEric Joyner  */
10771d10453SEric Joyner #define ICE_IFLIB_MAX_DESC_COUNT	4096
10871d10453SEric Joyner 
10971d10453SEric Joyner /**
11071d10453SEric Joyner  * @struct ice_irq_vector
11171d10453SEric Joyner  * @brief Driver irq vector structure
11271d10453SEric Joyner  *
11371d10453SEric Joyner  * ice_lib.c requires the following parameters
11471d10453SEric Joyner  * @me: the vector number
11571d10453SEric Joyner  *
11671d10453SEric Joyner  * Other parameters may be iflib driver specific
11771d10453SEric Joyner  *
11871d10453SEric Joyner  * The iflib driver uses a single hardware interrupt per Rx queue, and uses
11971d10453SEric Joyner  * software interrupts for the Tx queues.
12071d10453SEric Joyner  */
12171d10453SEric Joyner struct ice_irq_vector {
12271d10453SEric Joyner 	u32			me;
12371d10453SEric Joyner 
12471d10453SEric Joyner 	struct if_irq		irq;
12571d10453SEric Joyner };
12671d10453SEric Joyner 
12771d10453SEric Joyner /**
12871d10453SEric Joyner  * @struct ice_tx_queue
12971d10453SEric Joyner  * @brief Driver Tx queue structure
13071d10453SEric Joyner  *
13171d10453SEric Joyner  * ice_lib.c requires the following parameters:
13271d10453SEric Joyner  * @vsi: backpointer the VSI structure
13371d10453SEric Joyner  * @me: this queue's index into the queue array
13471d10453SEric Joyner  * @irqv: always NULL for iflib
13571d10453SEric Joyner  * @desc_count: the number of descriptors
13671d10453SEric Joyner  * @tx_paddr: the physical address for this queue
13771d10453SEric Joyner  * @q_teid: the Tx queue TEID returned from firmware
13871d10453SEric Joyner  * @stats: queue statistics
13956429daeSEric Joyner  * @tc: traffic class queue belongs to
14056429daeSEric Joyner  * @q_handle: qidx in tc; used in TXQ enable functions
14171d10453SEric Joyner  *
14271d10453SEric Joyner  * Other parameters may be iflib driver specific
14371d10453SEric Joyner  */
14471d10453SEric Joyner struct ice_tx_queue {
14571d10453SEric Joyner 	struct ice_vsi		*vsi;
14671d10453SEric Joyner 	struct ice_tx_desc	*tx_base;
14771d10453SEric Joyner 	bus_addr_t		tx_paddr;
14871d10453SEric Joyner 	struct tx_stats		stats;
14971d10453SEric Joyner 	u16			desc_count;
15071d10453SEric Joyner 	u32			tail;
15171d10453SEric Joyner 	struct ice_irq_vector	*irqv;
15271d10453SEric Joyner 	u32			q_teid;
15371d10453SEric Joyner 	u32			me;
15456429daeSEric Joyner 	u16			q_handle;
15556429daeSEric Joyner 	u8			tc;
15671d10453SEric Joyner 
15771d10453SEric Joyner 	/* descriptor writeback status */
15871d10453SEric Joyner 	qidx_t			*tx_rsq;
15971d10453SEric Joyner 	qidx_t			tx_rs_cidx;
16071d10453SEric Joyner 	qidx_t			tx_rs_pidx;
16171d10453SEric Joyner 	qidx_t			tx_cidx_processed;
16271d10453SEric Joyner };
16371d10453SEric Joyner 
16471d10453SEric Joyner /**
16571d10453SEric Joyner  * @struct ice_rx_queue
16671d10453SEric Joyner  * @brief Driver Rx queue structure
16771d10453SEric Joyner  *
16871d10453SEric Joyner  * ice_lib.c requires the following parameters:
16971d10453SEric Joyner  * @vsi: backpointer the VSI structure
17071d10453SEric Joyner  * @me: this queue's index into the queue array
17171d10453SEric Joyner  * @irqv: pointer to vector structure associated with this queue
17271d10453SEric Joyner  * @desc_count: the number of descriptors
17371d10453SEric Joyner  * @rx_paddr: the physical address for this queue
17471d10453SEric Joyner  * @tail: the tail register address for this queue
17571d10453SEric Joyner  * @stats: queue statistics
17656429daeSEric Joyner  * @tc: traffic class queue belongs to
17771d10453SEric Joyner  *
17871d10453SEric Joyner  * Other parameters may be iflib driver specific
17971d10453SEric Joyner  */
18071d10453SEric Joyner struct ice_rx_queue {
18171d10453SEric Joyner 	struct ice_vsi			*vsi;
18271d10453SEric Joyner 	union ice_32b_rx_flex_desc	*rx_base;
18371d10453SEric Joyner 	bus_addr_t			rx_paddr;
18471d10453SEric Joyner 	struct rx_stats			stats;
18571d10453SEric Joyner 	u16				desc_count;
18671d10453SEric Joyner 	u32				tail;
18771d10453SEric Joyner 	struct ice_irq_vector		*irqv;
18871d10453SEric Joyner 	u32				me;
18956429daeSEric Joyner 	u8				tc;
19071d10453SEric Joyner 
19171d10453SEric Joyner 	struct if_irq			que_irq;
19271d10453SEric Joyner };
19371d10453SEric Joyner 
19471d10453SEric Joyner /**
195*9e54973fSEric Joyner  * @struct ice_mirr_if
196*9e54973fSEric Joyner  * @brief structure representing a mirroring interface
197*9e54973fSEric Joyner  */
198*9e54973fSEric Joyner struct ice_mirr_if {
199*9e54973fSEric Joyner 	struct ice_softc *back;
200*9e54973fSEric Joyner 	struct ifnet *ifp;
201*9e54973fSEric Joyner 	struct ice_vsi *vsi;
202*9e54973fSEric Joyner 
203*9e54973fSEric Joyner 	device_t subdev;
204*9e54973fSEric Joyner 	if_ctx_t subctx;
205*9e54973fSEric Joyner 	if_softc_ctx_t subscctx;
206*9e54973fSEric Joyner 
207*9e54973fSEric Joyner 	u16 num_irq_vectors;
208*9e54973fSEric Joyner 	u16 *if_imap;
209*9e54973fSEric Joyner 	u16 *os_imap;
210*9e54973fSEric Joyner 	struct ice_irq_vector *rx_irqvs;
211*9e54973fSEric Joyner 
212*9e54973fSEric Joyner 	u32 state;
213*9e54973fSEric Joyner 
214*9e54973fSEric Joyner 	bool if_attached;
215*9e54973fSEric Joyner };
216*9e54973fSEric Joyner 
217*9e54973fSEric Joyner /**
21871d10453SEric Joyner  * @struct ice_softc
21971d10453SEric Joyner  * @brief main structure representing one device
22071d10453SEric Joyner  *
22171d10453SEric Joyner  * ice_lib.c requires the following parameters
22271d10453SEric Joyner  * @all_vsi: the array of all allocated VSIs
22371d10453SEric Joyner  * @debug_sysctls: sysctl node for debug sysctls
22471d10453SEric Joyner  * @dev: device_t pointer
22571d10453SEric Joyner  * @feat_en: bitmap of enabled driver features
22671d10453SEric Joyner  * @hw: embedded ice_hw structure
22771d10453SEric Joyner  * @ifp: pointer to the ifnet structure
22871d10453SEric Joyner  * @link_up: boolean indicating if link is up
22971d10453SEric Joyner  * @num_available_vsi: size of the VSI array
23071d10453SEric Joyner  * @pf_vsi: embedded VSI structure for the main PF VSI
23171d10453SEric Joyner  * @rx_qmgr: queue manager for Rx queues
23271d10453SEric Joyner  * @soft_stats: software statistics for this device
23371d10453SEric Joyner  * @state: driver state flags
23471d10453SEric Joyner  * @stats: hardware statistics for this device
23571d10453SEric Joyner  * @tx_qmgr: queue manager for Tx queues
23671d10453SEric Joyner  * @vsi_sysctls: sysctl node for all VSI sysctls
23771d10453SEric Joyner  * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
23871d10453SEric Joyner  * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
23971d10453SEric Joyner  * @rebuild_ticks: indicates when a post-reset rebuild started
24071d10453SEric Joyner  * @imgr: resource manager for interrupt allocations
24171d10453SEric Joyner  * @pf_imap: interrupt mapping for PF LAN interrupts
24271d10453SEric Joyner  * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
24371d10453SEric Joyner  * @ldo_tlv: LAN Default Override settings from NVM
24471d10453SEric Joyner  *
24571d10453SEric Joyner  * ice_iov.c requires the following parameters (when PCI_IOV is defined):
24671d10453SEric Joyner  * @vfs: array of VF context structures
24771d10453SEric Joyner  * @num_vfs: number of VFs to use for SR-IOV
24871d10453SEric Joyner  *
24971d10453SEric Joyner  * The main representation for a single OS device, used to represent a single
25071d10453SEric Joyner  * physical function.
25171d10453SEric Joyner  */
25271d10453SEric Joyner struct ice_softc {
25371d10453SEric Joyner 	struct ice_hw hw;
25471d10453SEric Joyner 	struct ice_vsi pf_vsi;		/* Main PF VSI */
25571d10453SEric Joyner 
25671d10453SEric Joyner 	char admin_mtx_name[16]; /* name of the admin mutex */
25771d10453SEric Joyner 	struct mtx admin_mtx; /* mutex to protect the admin timer */
25871d10453SEric Joyner 	struct callout admin_timer; /* timer to trigger admin task */
25971d10453SEric Joyner 
2608a13362dSEric Joyner 	/* iRDMA peer interface */
2618a13362dSEric Joyner 	struct ice_rdma_entry rdma_entry;
2628a13362dSEric Joyner 	int irdma_vectors;
2638a13362dSEric Joyner 	u16 *rdma_imap;
2648a13362dSEric Joyner 
26571d10453SEric Joyner 	struct ice_vsi **all_vsi;	/* Array of VSI pointers */
26671d10453SEric Joyner 	u16 num_available_vsi;		/* Size of VSI array */
26771d10453SEric Joyner 
26871d10453SEric Joyner 	struct sysctl_oid *vsi_sysctls;	/* Sysctl node for VSI sysctls */
26971d10453SEric Joyner 	struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */
27071d10453SEric Joyner 
27171d10453SEric Joyner 	device_t dev;
27271d10453SEric Joyner 	if_ctx_t ctx;
27371d10453SEric Joyner 	if_shared_ctx_t sctx;
27471d10453SEric Joyner 	if_softc_ctx_t scctx;
27571d10453SEric Joyner 	struct ifmedia *media;
27671d10453SEric Joyner 	struct ifnet *ifp;
27771d10453SEric Joyner 
27871d10453SEric Joyner 	/* device statistics */
27971d10453SEric Joyner 	struct ice_pf_hw_stats stats;
28071d10453SEric Joyner 	struct ice_pf_sw_stats soft_stats;
28171d10453SEric Joyner 
28271d10453SEric Joyner 	/* Tx/Rx queue managers */
28371d10453SEric Joyner 	struct ice_resmgr tx_qmgr;
28471d10453SEric Joyner 	struct ice_resmgr rx_qmgr;
28571d10453SEric Joyner 
28671d10453SEric Joyner 	/* Interrupt allocation manager */
287*9e54973fSEric Joyner 	struct ice_resmgr dev_imgr;
28871d10453SEric Joyner 	u16 *pf_imap;
28971d10453SEric Joyner 	int lan_vectors;
29071d10453SEric Joyner 
29171d10453SEric Joyner 	/* iflib Tx/Rx queue count sysctl values */
29271d10453SEric Joyner 	int ifc_sysctl_ntxqs;
29371d10453SEric Joyner 	int ifc_sysctl_nrxqs;
29471d10453SEric Joyner 
29571d10453SEric Joyner 	/* IRQ Vector data */
29671d10453SEric Joyner 	struct resource *msix_table;
29771d10453SEric Joyner 	int num_irq_vectors;
29871d10453SEric Joyner 	struct ice_irq_vector *irqvs;
29971d10453SEric Joyner 
30071d10453SEric Joyner 	/* BAR info */
30171d10453SEric Joyner 	struct ice_bar_info bar0;
30271d10453SEric Joyner 
30371d10453SEric Joyner 	/* link status */
30471d10453SEric Joyner 	bool link_up;
30571d10453SEric Joyner 
30671d10453SEric Joyner 	/* Ethertype filters enabled */
30771d10453SEric Joyner 	bool enable_tx_fc_filter;
30871d10453SEric Joyner 	bool enable_tx_lldp_filter;
3099cf1841cSEric Joyner 
3109cf1841cSEric Joyner 	/* Other tunable flags */
3119cf1841cSEric Joyner 	bool enable_health_events;
31271d10453SEric Joyner 
3138923de59SPiotr Kubaj 	/* 5-layer scheduler topology enabled */
3148923de59SPiotr Kubaj 	bool tx_balance_en;
3158923de59SPiotr Kubaj 
3168923de59SPiotr Kubaj 	/* Allow additional non-standard FEC mode */
3178923de59SPiotr Kubaj 	bool allow_no_fec_mod_in_auto;
3188923de59SPiotr Kubaj 
31971d10453SEric Joyner 	int rebuild_ticks;
32071d10453SEric Joyner 
32171d10453SEric Joyner 	/* driver state flags, only access using atomic functions */
32271d10453SEric Joyner 	u32 state;
32371d10453SEric Joyner 
32471d10453SEric Joyner 	/* NVM link override settings */
32571d10453SEric Joyner 	struct ice_link_default_override_tlv ldo_tlv;
32671d10453SEric Joyner 
327*9e54973fSEric Joyner 	u32 fw_debug_dump_cluster_mask;
3288923de59SPiotr Kubaj 
32971d10453SEric Joyner 	struct sx *iflib_ctx_lock;
33071d10453SEric Joyner 
33171d10453SEric Joyner 	/* Tri-state feature flags (capable/enabled) */
33271d10453SEric Joyner 	ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
33371d10453SEric Joyner 	ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);
33471d10453SEric Joyner 
335*9e54973fSEric Joyner 	struct ice_resmgr os_imgr;
336*9e54973fSEric Joyner 	/* For mirror interface */
337*9e54973fSEric Joyner 	struct ice_mirr_if *mirr_if;
338*9e54973fSEric Joyner 	int extra_vectors;
339*9e54973fSEric Joyner 	int last_rid;
34071d10453SEric Joyner };
34171d10453SEric Joyner 
34271d10453SEric Joyner #endif /* _ICE_IFLIB_H_ */
343