xref: /freebsd/sys/dev/ice/ice_iflib.h (revision f2635e844dd138ac9dfba676f27d41750049af26)
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 	u16			desc_count;
150 	u32			tail;
151 	struct ice_irq_vector	*irqv;
152 	u32			q_teid;
153 	u32			me;
154 	u16			q_handle;
155 	u8			tc;
156 
157 	/* descriptor writeback status */
158 	qidx_t			*tx_rsq;
159 	qidx_t			tx_rs_cidx;
160 	qidx_t			tx_rs_pidx;
161 	qidx_t			tx_cidx_processed;
162 };
163 
164 /**
165  * @struct ice_rx_queue
166  * @brief Driver Rx queue structure
167  *
168  * ice_lib.c requires the following parameters:
169  * @vsi: backpointer the VSI structure
170  * @me: this queue's index into the queue array
171  * @irqv: pointer to vector structure associated with this queue
172  * @desc_count: the number of descriptors
173  * @rx_paddr: the physical address for this queue
174  * @tail: the tail register address for this queue
175  * @stats: queue statistics
176  * @tc: traffic class queue belongs to
177  *
178  * Other parameters may be iflib driver specific
179  */
180 struct ice_rx_queue {
181 	struct ice_vsi			*vsi;
182 	union ice_32b_rx_flex_desc	*rx_base;
183 	bus_addr_t			rx_paddr;
184 	struct rx_stats			stats;
185 	u16				desc_count;
186 	u32				tail;
187 	struct ice_irq_vector		*irqv;
188 	u32				me;
189 	u8				tc;
190 
191 	struct if_irq			que_irq;
192 };
193 
194 /**
195  * @struct ice_mirr_if
196  * @brief structure representing a mirroring interface
197  */
198 struct ice_mirr_if {
199 	struct ice_softc *back;
200 	struct ifnet *ifp;
201 	struct ice_vsi *vsi;
202 
203 	device_t subdev;
204 	if_ctx_t subctx;
205 	if_softc_ctx_t subscctx;
206 
207 	u16 num_irq_vectors;
208 	u16 *if_imap;
209 	u16 *os_imap;
210 	struct ice_irq_vector *rx_irqvs;
211 
212 	u32 state;
213 
214 	bool if_attached;
215 };
216 
217 /**
218  * @struct ice_softc
219  * @brief main structure representing one device
220  *
221  * ice_lib.c requires the following parameters
222  * @all_vsi: the array of all allocated VSIs
223  * @debug_sysctls: sysctl node for debug sysctls
224  * @dev: device_t pointer
225  * @feat_en: bitmap of enabled driver features
226  * @hw: embedded ice_hw structure
227  * @ifp: pointer to the ifnet structure
228  * @link_up: boolean indicating if link is up
229  * @num_available_vsi: size of the VSI array
230  * @pf_vsi: embedded VSI structure for the main PF VSI
231  * @rx_qmgr: queue manager for Rx queues
232  * @soft_stats: software statistics for this device
233  * @state: driver state flags
234  * @stats: hardware statistics for this device
235  * @tx_qmgr: queue manager for Tx queues
236  * @vsi_sysctls: sysctl node for all VSI sysctls
237  * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
238  * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
239  * @rebuild_ticks: indicates when a post-reset rebuild started
240  * @imgr: resource manager for interrupt allocations
241  * @pf_imap: interrupt mapping for PF LAN interrupts
242  * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
243  * @ldo_tlv: LAN Default Override settings from NVM
244  *
245  * ice_iov.c requires the following parameters (when PCI_IOV is defined):
246  * @vfs: array of VF context structures
247  * @num_vfs: number of VFs to use for SR-IOV
248  *
249  * The main representation for a single OS device, used to represent a single
250  * physical function.
251  */
252 struct ice_softc {
253 	struct ice_hw hw;
254 	struct ice_vsi pf_vsi;		/* Main PF VSI */
255 
256 	char admin_mtx_name[16]; /* name of the admin mutex */
257 	struct mtx admin_mtx; /* mutex to protect the admin timer */
258 	struct callout admin_timer; /* timer to trigger admin task */
259 
260 	/* iRDMA peer interface */
261 	struct ice_rdma_entry rdma_entry;
262 	int irdma_vectors;
263 	u16 *rdma_imap;
264 
265 	struct ice_vsi **all_vsi;	/* Array of VSI pointers */
266 	u16 num_available_vsi;		/* Size of VSI array */
267 
268 	struct sysctl_oid *vsi_sysctls;	/* Sysctl node for VSI sysctls */
269 	struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */
270 
271 	device_t dev;
272 	if_ctx_t ctx;
273 	if_shared_ctx_t sctx;
274 	if_softc_ctx_t scctx;
275 	struct ifmedia *media;
276 	struct ifnet *ifp;
277 
278 	/* device statistics */
279 	struct ice_pf_hw_stats stats;
280 	struct ice_pf_sw_stats soft_stats;
281 
282 	/* Tx/Rx queue managers */
283 	struct ice_resmgr tx_qmgr;
284 	struct ice_resmgr rx_qmgr;
285 
286 	/* Interrupt allocation manager */
287 	struct ice_resmgr dev_imgr;
288 	u16 *pf_imap;
289 	int lan_vectors;
290 
291 	/* iflib Tx/Rx queue count sysctl values */
292 	int ifc_sysctl_ntxqs;
293 	int ifc_sysctl_nrxqs;
294 
295 	/* IRQ Vector data */
296 	struct resource *msix_table;
297 	int num_irq_vectors;
298 	struct ice_irq_vector *irqvs;
299 
300 	/* BAR info */
301 	struct ice_bar_info bar0;
302 
303 	/* link status */
304 	bool link_up;
305 
306 	/* Ethertype filters enabled */
307 	bool enable_tx_fc_filter;
308 	bool enable_tx_lldp_filter;
309 
310 	/* Other tunable flags */
311 	bool enable_health_events;
312 
313 	/* 5-layer scheduler topology enabled */
314 	bool tx_balance_en;
315 
316 	/* Allow additional non-standard FEC mode */
317 	bool allow_no_fec_mod_in_auto;
318 
319 	int rebuild_ticks;
320 
321 	/* driver state flags, only access using atomic functions */
322 	u32 state;
323 
324 	/* NVM link override settings */
325 	struct ice_link_default_override_tlv ldo_tlv;
326 
327 	u32 fw_debug_dump_cluster_mask;
328 
329 	struct sx *iflib_ctx_lock;
330 
331 	/* Tri-state feature flags (capable/enabled) */
332 	ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
333 	ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);
334 
335 	struct ice_resmgr os_imgr;
336 	/* For mirror interface */
337 	struct ice_mirr_if *mirr_if;
338 	int extra_vectors;
339 	int last_rid;
340 };
341 
342 #endif /* _ICE_IFLIB_H_ */
343