xref: /freebsd/sys/dev/ice/ice_iflib.h (revision 6580f5c38dd5b01aeeaed16b370f1a12423437f0)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2024, Intel Corporation
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above copyright notice,
9  *      this list of conditions and the following disclaimer.
10  *
11  *   2. Redistributions in binary form must reproduce the above copyright
12  *      notice, this list of conditions and the following disclaimer in the
13  *      documentation and/or other materials provided with the distribution.
14  *
15  *   3. Neither the name of the Intel Corporation nor the names of its
16  *      contributors may be used to endorse or promote products derived from
17  *      this software without specific prior written permission.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @file ice_iflib.h
34  * @brief main header for the iflib driver implementation
35  *
36  * Contains the definitions for various structures used by the iflib driver
37  * implementation, including the Tx and Rx queue structures and the ice_softc
38  * structure.
39  */
40 
41 #ifndef _ICE_IFLIB_H_
42 #define _ICE_IFLIB_H_
43 
44 /* include kernel options first */
45 #include "ice_opts.h"
46 
47 #include <sys/param.h>
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <sys/time.h>
51 #include <net/if.h>
52 #include <net/if_var.h>
53 #include <net/if_media.h>
54 #include <net/ethernet.h>
55 #include <net/iflib.h>
56 #include "ifdi_if.h"
57 
58 #include "ice_lib.h"
59 #include "ice_osdep.h"
60 #include "ice_resmgr.h"
61 #include "ice_type.h"
62 #include "ice_features.h"
63 
64 /**
65  * ASSERT_CTX_LOCKED - Assert that the iflib context lock is held
66  * @sc: ice softc pointer
67  *
68  * Macro to trigger an assertion if the iflib context lock is not
69  * currently held.
70  */
71 #define ASSERT_CTX_LOCKED(sc) sx_assert((sc)->iflib_ctx_lock, SA_XLOCKED)
72 
73 /**
74  * IFLIB_CTX_LOCK - lock the iflib context lock
75  * @sc: ice softc pointer
76  *
77  * Macro used to unlock the iflib context lock.
78  */
79 #define IFLIB_CTX_LOCK(sc) sx_xlock((sc)->iflib_ctx_lock)
80 
81 /**
82  * IFLIB_CTX_UNLOCK - unlock the iflib context lock
83  * @sc: ice softc pointer
84  *
85  * Macro used to unlock the iflib context lock.
86  */
87 #define IFLIB_CTX_UNLOCK(sc) sx_xunlock((sc)->iflib_ctx_lock)
88 
89 /**
90  * ASSERT_CFG_LOCKED - Assert that a configuration lock is held
91  * @sc: ice softc pointer
92  *
93  * Macro used by ice_lib.c to verify that certain functions are called while
94  * holding a configuration lock. For the iflib implementation, this will be
95  * the iflib context lock.
96  */
97 #define ASSERT_CFG_LOCKED(sc) ASSERT_CTX_LOCKED(sc)
98 
99 /**
100  * ICE_IFLIB_MAX_DESC_COUNT - Maximum ring size for iflib
101  *
102  * The iflib stack currently requires that the ring size, or number of
103  * descriptors, be a power of 2. The ice hardware is limited to a maximum of
104  * 8160 descriptors, which is not quite 2^13. Limit the maximum ring size for
105  * iflib to just 2^12 (4096).
106  */
107 #define ICE_IFLIB_MAX_DESC_COUNT	4096
108 
109 /**
110  * @struct ice_irq_vector
111  * @brief Driver irq vector structure
112  *
113  * ice_lib.c requires the following parameters
114  * @me: the vector number
115  *
116  * Other parameters may be iflib driver specific
117  *
118  * The iflib driver uses a single hardware interrupt per Rx queue, and uses
119  * software interrupts for the Tx queues.
120  */
121 struct ice_irq_vector {
122 	u32			me;
123 
124 	struct if_irq		irq;
125 };
126 
127 /**
128  * @struct ice_tx_queue
129  * @brief Driver Tx queue structure
130  *
131  * ice_lib.c requires the following parameters:
132  * @vsi: backpointer the VSI structure
133  * @me: this queue's index into the queue array
134  * @irqv: always NULL for iflib
135  * @desc_count: the number of descriptors
136  * @tx_paddr: the physical address for this queue
137  * @q_teid: the Tx queue TEID returned from firmware
138  * @stats: queue statistics
139  * @tc: traffic class queue belongs to
140  * @q_handle: qidx in tc; used in TXQ enable functions
141  *
142  * Other parameters may be iflib driver specific
143  */
144 struct ice_tx_queue {
145 	struct ice_vsi		*vsi;
146 	struct ice_tx_desc	*tx_base;
147 	bus_addr_t		tx_paddr;
148 	struct tx_stats		stats;
149 	u64			tso;
150 	u16			desc_count;
151 	u32			tail;
152 	struct ice_irq_vector	*irqv;
153 	u32			q_teid;
154 	u32			me;
155 	u16			q_handle;
156 	u8			tc;
157 
158 	/* descriptor writeback status */
159 	qidx_t			*tx_rsq;
160 	qidx_t			tx_rs_cidx;
161 	qidx_t			tx_rs_pidx;
162 	qidx_t			tx_cidx_processed;
163 };
164 
165 /**
166  * @struct ice_rx_queue
167  * @brief Driver Rx queue structure
168  *
169  * ice_lib.c requires the following parameters:
170  * @vsi: backpointer the VSI structure
171  * @me: this queue's index into the queue array
172  * @irqv: pointer to vector structure associated with this queue
173  * @desc_count: the number of descriptors
174  * @rx_paddr: the physical address for this queue
175  * @tail: the tail register address for this queue
176  * @stats: queue statistics
177  * @tc: traffic class queue belongs to
178  *
179  * Other parameters may be iflib driver specific
180  */
181 struct ice_rx_queue {
182 	struct ice_vsi			*vsi;
183 	union ice_32b_rx_flex_desc	*rx_base;
184 	bus_addr_t			rx_paddr;
185 	struct rx_stats			stats;
186 	u16				desc_count;
187 	u32				tail;
188 	struct ice_irq_vector		*irqv;
189 	u32				me;
190 	u8				tc;
191 
192 	struct if_irq			que_irq;
193 };
194 
195 /**
196  * @struct ice_mirr_if
197  * @brief structure representing a mirroring interface
198  */
199 struct ice_mirr_if {
200 	struct ice_softc *back;
201 	struct ifnet *ifp;
202 	struct ice_vsi *vsi;
203 
204 	device_t subdev;
205 	if_ctx_t subctx;
206 	if_softc_ctx_t subscctx;
207 
208 	u16 num_irq_vectors;
209 	u16 *if_imap;
210 	u16 *os_imap;
211 	struct ice_irq_vector *rx_irqvs;
212 
213 	u32 state;
214 
215 	bool if_attached;
216 };
217 
218 /**
219  * @struct ice_softc
220  * @brief main structure representing one device
221  *
222  * ice_lib.c requires the following parameters
223  * @all_vsi: the array of all allocated VSIs
224  * @debug_sysctls: sysctl node for debug sysctls
225  * @dev: device_t pointer
226  * @feat_en: bitmap of enabled driver features
227  * @hw: embedded ice_hw structure
228  * @ifp: pointer to the ifnet structure
229  * @link_up: boolean indicating if link is up
230  * @num_available_vsi: size of the VSI array
231  * @pf_vsi: embedded VSI structure for the main PF VSI
232  * @rx_qmgr: queue manager for Rx queues
233  * @soft_stats: software statistics for this device
234  * @state: driver state flags
235  * @stats: hardware statistics for this device
236  * @tx_qmgr: queue manager for Tx queues
237  * @vsi_sysctls: sysctl node for all VSI sysctls
238  * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
239  * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
240  * @rebuild_ticks: indicates when a post-reset rebuild started
241  * @imgr: resource manager for interrupt allocations
242  * @pf_imap: interrupt mapping for PF LAN interrupts
243  * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
244  * @ldo_tlv: LAN Default Override settings from NVM
245  *
246  * ice_iov.c requires the following parameters (when PCI_IOV is defined):
247  * @vfs: array of VF context structures
248  * @num_vfs: number of VFs to use for SR-IOV
249  *
250  * The main representation for a single OS device, used to represent a single
251  * physical function.
252  */
253 struct ice_softc {
254 	struct ice_hw hw;
255 	struct ice_vsi pf_vsi;		/* Main PF VSI */
256 
257 	char admin_mtx_name[16]; /* name of the admin mutex */
258 	struct mtx admin_mtx; /* mutex to protect the admin timer */
259 	struct callout admin_timer; /* timer to trigger admin task */
260 
261 	/* iRDMA peer interface */
262 	struct ice_rdma_entry rdma_entry;
263 	int irdma_vectors;
264 	u16 *rdma_imap;
265 
266 	struct ice_vsi **all_vsi;	/* Array of VSI pointers */
267 	u16 num_available_vsi;		/* Size of VSI array */
268 
269 	struct sysctl_oid *vsi_sysctls;	/* Sysctl node for VSI sysctls */
270 	struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */
271 
272 	device_t dev;
273 	if_ctx_t ctx;
274 	if_shared_ctx_t sctx;
275 	if_softc_ctx_t scctx;
276 	struct ifmedia *media;
277 	struct ifnet *ifp;
278 
279 	/* device statistics */
280 	struct ice_pf_hw_stats stats;
281 	struct ice_pf_sw_stats soft_stats;
282 
283 	/* Tx/Rx queue managers */
284 	struct ice_resmgr tx_qmgr;
285 	struct ice_resmgr rx_qmgr;
286 
287 	/* Interrupt allocation manager */
288 	struct ice_resmgr dev_imgr;
289 	u16 *pf_imap;
290 	int lan_vectors;
291 
292 	/* iflib Tx/Rx queue count sysctl values */
293 	int ifc_sysctl_ntxqs;
294 	int ifc_sysctl_nrxqs;
295 
296 	/* IRQ Vector data */
297 	struct resource *msix_table;
298 	int num_irq_vectors;
299 	struct ice_irq_vector *irqvs;
300 
301 	/* BAR info */
302 	struct ice_bar_info bar0;
303 
304 	/* link status */
305 	bool link_up;
306 
307 	/* Ethertype filters enabled */
308 	bool enable_tx_fc_filter;
309 	bool enable_tx_lldp_filter;
310 
311 	/* Other tunable flags */
312 	bool enable_health_events;
313 
314 	/* 5-layer scheduler topology enabled */
315 	bool tx_balance_en;
316 
317 	/* Allow additional non-standard FEC mode */
318 	bool allow_no_fec_mod_in_auto;
319 
320 	int rebuild_ticks;
321 
322 	/* driver state flags, only access using atomic functions */
323 	u32 state;
324 
325 	/* NVM link override settings */
326 	struct ice_link_default_override_tlv ldo_tlv;
327 
328 	u32 fw_debug_dump_cluster_mask;
329 
330 	struct sx *iflib_ctx_lock;
331 
332 	/* Tri-state feature flags (capable/enabled) */
333 	ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
334 	ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);
335 
336 	struct ice_resmgr os_imgr;
337 	/* For mirror interface */
338 	struct ice_mirr_if *mirr_if;
339 	int extra_vectors;
340 	int last_rid;
341 };
342 
343 #endif /* _ICE_IFLIB_H_ */
344