xref: /freebsd/sys/dev/ice/ice_iflib.h (revision 84823cc70824c8d842f503d8c2e6d7b0c2d95b61)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*  Copyright (c) 2021, 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 /*$FreeBSD$*/
32 
33 /**
34  * @file ice_iflib.h
35  * @brief main header for the iflib driver implementation
36  *
37  * Contains the definitions for various structures used by the iflib driver
38  * implementation, including the Tx and Rx queue structures and the ice_softc
39  * structure.
40  */
41 
42 #ifndef _ICE_IFLIB_H_
43 #define _ICE_IFLIB_H_
44 
45 /* include kernel options first */
46 #include "ice_opts.h"
47 
48 #include <sys/param.h>
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <sys/time.h>
52 #include <net/if.h>
53 #include <net/if_var.h>
54 #include <net/if_media.h>
55 #include <net/ethernet.h>
56 #include <net/iflib.h>
57 #include "ifdi_if.h"
58 
59 #include "ice_lib.h"
60 #include "ice_osdep.h"
61 #include "ice_resmgr.h"
62 #include "ice_type.h"
63 #include "ice_features.h"
64 
65 /**
66  * ASSERT_CTX_LOCKED - Assert that the iflib context lock is held
67  * @sc: ice softc pointer
68  *
69  * Macro to trigger an assertion if the iflib context lock is not
70  * currently held.
71  */
72 #define ASSERT_CTX_LOCKED(sc) sx_assert((sc)->iflib_ctx_lock, SA_XLOCKED)
73 
74 /**
75  * IFLIB_CTX_LOCK - lock the iflib context lock
76  * @sc: ice softc pointer
77  *
78  * Macro used to unlock the iflib context lock.
79  */
80 #define IFLIB_CTX_LOCK(sc) sx_xlock((sc)->iflib_ctx_lock)
81 
82 /**
83  * IFLIB_CTX_UNLOCK - unlock the iflib context lock
84  * @sc: ice softc pointer
85  *
86  * Macro used to unlock the iflib context lock.
87  */
88 #define IFLIB_CTX_UNLOCK(sc) sx_xunlock((sc)->iflib_ctx_lock)
89 
90 /**
91  * ASSERT_CFG_LOCKED - Assert that a configuration lock is held
92  * @sc: ice softc pointer
93  *
94  * Macro used by ice_lib.c to verify that certain functions are called while
95  * holding a configuration lock. For the iflib implementation, this will be
96  * the iflib context lock.
97  */
98 #define ASSERT_CFG_LOCKED(sc) ASSERT_CTX_LOCKED(sc)
99 
100 /**
101  * ICE_IFLIB_MAX_DESC_COUNT - Maximum ring size for iflib
102  *
103  * The iflib stack currently requires that the ring size, or number of
104  * descriptors, be a power of 2. The ice hardware is limited to a maximum of
105  * 8160 descriptors, which is not quite 2^13. Limit the maximum ring size for
106  * iflib to just 2^12 (4096).
107  */
108 #define ICE_IFLIB_MAX_DESC_COUNT	4096
109 
110 /**
111  * @struct ice_irq_vector
112  * @brief Driver irq vector structure
113  *
114  * ice_lib.c requires the following parameters
115  * @me: the vector number
116  *
117  * Other parameters may be iflib driver specific
118  *
119  * The iflib driver uses a single hardware interrupt per Rx queue, and uses
120  * software interrupts for the Tx queues.
121  */
122 struct ice_irq_vector {
123 	u32			me;
124 
125 	struct if_irq		irq;
126 };
127 
128 /**
129  * @struct ice_tx_queue
130  * @brief Driver Tx queue structure
131  *
132  * ice_lib.c requires the following parameters:
133  * @vsi: backpointer the VSI structure
134  * @me: this queue's index into the queue array
135  * @irqv: always NULL for iflib
136  * @desc_count: the number of descriptors
137  * @tx_paddr: the physical address for this queue
138  * @q_teid: the Tx queue TEID returned from firmware
139  * @stats: queue statistics
140  * @tc: traffic class queue belongs to
141  * @q_handle: qidx in tc; used in TXQ enable functions
142  *
143  * Other parameters may be iflib driver specific
144  */
145 struct ice_tx_queue {
146 	struct ice_vsi		*vsi;
147 	struct ice_tx_desc	*tx_base;
148 	bus_addr_t		tx_paddr;
149 	struct tx_stats		stats;
150 	u64			tso;
151 	u16			desc_count;
152 	u32			tail;
153 	struct ice_irq_vector	*irqv;
154 	u32			q_teid;
155 	u32			me;
156 	u16			q_handle;
157 	u8			tc;
158 
159 	/* descriptor writeback status */
160 	qidx_t			*tx_rsq;
161 	qidx_t			tx_rs_cidx;
162 	qidx_t			tx_rs_pidx;
163 	qidx_t			tx_cidx_processed;
164 };
165 
166 /**
167  * @struct ice_rx_queue
168  * @brief Driver Rx queue structure
169  *
170  * ice_lib.c requires the following parameters:
171  * @vsi: backpointer the VSI structure
172  * @me: this queue's index into the queue array
173  * @irqv: pointer to vector structure associated with this queue
174  * @desc_count: the number of descriptors
175  * @rx_paddr: the physical address for this queue
176  * @tail: the tail register address for this queue
177  * @stats: queue statistics
178  * @tc: traffic class queue belongs to
179  *
180  * Other parameters may be iflib driver specific
181  */
182 struct ice_rx_queue {
183 	struct ice_vsi			*vsi;
184 	union ice_32b_rx_flex_desc	*rx_base;
185 	bus_addr_t			rx_paddr;
186 	struct rx_stats			stats;
187 	u16				desc_count;
188 	u32				tail;
189 	struct ice_irq_vector		*irqv;
190 	u32				me;
191 	u8				tc;
192 
193 	struct if_irq			que_irq;
194 };
195 
196 /**
197  * @struct ice_softc
198  * @brief main structure representing one device
199  *
200  * ice_lib.c requires the following parameters
201  * @all_vsi: the array of all allocated VSIs
202  * @debug_sysctls: sysctl node for debug sysctls
203  * @dev: device_t pointer
204  * @feat_en: bitmap of enabled driver features
205  * @hw: embedded ice_hw structure
206  * @ifp: pointer to the ifnet structure
207  * @link_up: boolean indicating if link is up
208  * @num_available_vsi: size of the VSI array
209  * @pf_vsi: embedded VSI structure for the main PF VSI
210  * @rx_qmgr: queue manager for Rx queues
211  * @soft_stats: software statistics for this device
212  * @state: driver state flags
213  * @stats: hardware statistics for this device
214  * @tx_qmgr: queue manager for Tx queues
215  * @vsi_sysctls: sysctl node for all VSI sysctls
216  * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
217  * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
218  * @rebuild_ticks: indicates when a post-reset rebuild started
219  * @imgr: resource manager for interrupt allocations
220  * @pf_imap: interrupt mapping for PF LAN interrupts
221  * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
222  * @ldo_tlv: LAN Default Override settings from NVM
223  *
224  * ice_iov.c requires the following parameters (when PCI_IOV is defined):
225  * @vfs: array of VF context structures
226  * @num_vfs: number of VFs to use for SR-IOV
227  *
228  * The main representation for a single OS device, used to represent a single
229  * physical function.
230  */
231 struct ice_softc {
232 	struct ice_hw hw;
233 	struct ice_vsi pf_vsi;		/* Main PF VSI */
234 
235 	char admin_mtx_name[16]; /* name of the admin mutex */
236 	struct mtx admin_mtx; /* mutex to protect the admin timer */
237 	struct callout admin_timer; /* timer to trigger admin task */
238 
239 	/* iRDMA peer interface */
240 	struct ice_rdma_entry rdma_entry;
241 	int irdma_vectors;
242 	u16 *rdma_imap;
243 
244 	struct ice_vsi **all_vsi;	/* Array of VSI pointers */
245 	u16 num_available_vsi;		/* Size of VSI array */
246 
247 	struct sysctl_oid *vsi_sysctls;	/* Sysctl node for VSI sysctls */
248 	struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */
249 
250 	device_t dev;
251 	if_ctx_t ctx;
252 	if_shared_ctx_t sctx;
253 	if_softc_ctx_t scctx;
254 	struct ifmedia *media;
255 	struct ifnet *ifp;
256 
257 	/* device statistics */
258 	struct ice_pf_hw_stats stats;
259 	struct ice_pf_sw_stats soft_stats;
260 
261 	/* Tx/Rx queue managers */
262 	struct ice_resmgr tx_qmgr;
263 	struct ice_resmgr rx_qmgr;
264 
265 	/* Interrupt allocation manager */
266 	struct ice_resmgr imgr;
267 	u16 *pf_imap;
268 	int lan_vectors;
269 
270 	/* iflib Tx/Rx queue count sysctl values */
271 	int ifc_sysctl_ntxqs;
272 	int ifc_sysctl_nrxqs;
273 
274 	/* IRQ Vector data */
275 	struct resource *msix_table;
276 	int num_irq_vectors;
277 	struct ice_irq_vector *irqvs;
278 
279 	/* BAR info */
280 	struct ice_bar_info bar0;
281 
282 	/* link status */
283 	bool link_up;
284 
285 	/* Ethertype filters enabled */
286 	bool enable_tx_fc_filter;
287 	bool enable_tx_lldp_filter;
288 
289 	/* Other tunable flags */
290 	bool enable_health_events;
291 
292 	int rebuild_ticks;
293 
294 	/* driver state flags, only access using atomic functions */
295 	u32 state;
296 
297 	/* NVM link override settings */
298 	struct ice_link_default_override_tlv ldo_tlv;
299 
300 	struct sx *iflib_ctx_lock;
301 
302 	/* Tri-state feature flags (capable/enabled) */
303 	ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
304 	ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);
305 
306 };
307 
308 #endif /* _ICE_IFLIB_H_ */
309