aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ice/ice_iflib.h
blob: d89d0498542946a493ba348ede9ef846bc108266 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/* SPDX-License-Identifier: BSD-3-Clause */
/*  Copyright (c) 2023, Intel Corporation
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 *   3. Neither the name of the Intel Corporation nor the names of its
 *      contributors may be used to endorse or promote products derived from
 *      this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * @file ice_iflib.h
 * @brief main header for the iflib driver implementation
 *
 * Contains the definitions for various structures used by the iflib driver
 * implementation, including the Tx and Rx queue structures and the ice_softc
 * structure.
 */

#ifndef _ICE_IFLIB_H_
#define _ICE_IFLIB_H_

/* include kernel options first */
#include "ice_opts.h"

#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_media.h>
#include <net/ethernet.h>
#include <net/iflib.h>
#include "ifdi_if.h"

#include "ice_lib.h"
#include "ice_osdep.h"
#include "ice_resmgr.h"
#include "ice_type.h"
#include "ice_features.h"

/**
 * ASSERT_CTX_LOCKED - Assert that the iflib context lock is held
 * @sc: ice softc pointer
 *
 * Macro to trigger an assertion if the iflib context lock is not
 * currently held.
 */
#define ASSERT_CTX_LOCKED(sc) sx_assert((sc)->iflib_ctx_lock, SA_XLOCKED)

/**
 * IFLIB_CTX_LOCK - lock the iflib context lock
 * @sc: ice softc pointer
 *
 * Macro used to unlock the iflib context lock.
 */
#define IFLIB_CTX_LOCK(sc) sx_xlock((sc)->iflib_ctx_lock)

/**
 * IFLIB_CTX_UNLOCK - unlock the iflib context lock
 * @sc: ice softc pointer
 *
 * Macro used to unlock the iflib context lock.
 */
#define IFLIB_CTX_UNLOCK(sc) sx_xunlock((sc)->iflib_ctx_lock)

/**
 * ASSERT_CFG_LOCKED - Assert that a configuration lock is held
 * @sc: ice softc pointer
 *
 * Macro used by ice_lib.c to verify that certain functions are called while
 * holding a configuration lock. For the iflib implementation, this will be
 * the iflib context lock.
 */
#define ASSERT_CFG_LOCKED(sc) ASSERT_CTX_LOCKED(sc)

/**
 * ICE_IFLIB_MAX_DESC_COUNT - Maximum ring size for iflib
 *
 * The iflib stack currently requires that the ring size, or number of
 * descriptors, be a power of 2. The ice hardware is limited to a maximum of
 * 8160 descriptors, which is not quite 2^13. Limit the maximum ring size for
 * iflib to just 2^12 (4096).
 */
#define ICE_IFLIB_MAX_DESC_COUNT	4096

/**
 * @struct ice_irq_vector
 * @brief Driver irq vector structure
 *
 * ice_lib.c requires the following parameters
 * @me: the vector number
 *
 * Other parameters may be iflib driver specific
 *
 * The iflib driver uses a single hardware interrupt per Rx queue, and uses
 * software interrupts for the Tx queues.
 */
struct ice_irq_vector {
	u32			me;

	struct if_irq		irq;
};

/**
 * @struct ice_tx_queue
 * @brief Driver Tx queue structure
 *
 * ice_lib.c requires the following parameters:
 * @vsi: backpointer the VSI structure
 * @me: this queue's index into the queue array
 * @irqv: always NULL for iflib
 * @desc_count: the number of descriptors
 * @tx_paddr: the physical address for this queue
 * @q_teid: the Tx queue TEID returned from firmware
 * @stats: queue statistics
 * @tc: traffic class queue belongs to
 * @q_handle: qidx in tc; used in TXQ enable functions
 *
 * Other parameters may be iflib driver specific
 */
struct ice_tx_queue {
	struct ice_vsi		*vsi;
	struct ice_tx_desc	*tx_base;
	bus_addr_t		tx_paddr;
	struct tx_stats		stats;
	u64			tso;
	u16			desc_count;
	u32			tail;
	struct ice_irq_vector	*irqv;
	u32			q_teid;
	u32			me;
	u16			q_handle;
	u8			tc;

	/* descriptor writeback status */
	qidx_t			*tx_rsq;
	qidx_t			tx_rs_cidx;
	qidx_t			tx_rs_pidx;
	qidx_t			tx_cidx_processed;
};

/**
 * @struct ice_rx_queue
 * @brief Driver Rx queue structure
 *
 * ice_lib.c requires the following parameters:
 * @vsi: backpointer the VSI structure
 * @me: this queue's index into the queue array
 * @irqv: pointer to vector structure associated with this queue
 * @desc_count: the number of descriptors
 * @rx_paddr: the physical address for this queue
 * @tail: the tail register address for this queue
 * @stats: queue statistics
 * @tc: traffic class queue belongs to
 *
 * Other parameters may be iflib driver specific
 */
struct ice_rx_queue {
	struct ice_vsi			*vsi;
	union ice_32b_rx_flex_desc	*rx_base;
	bus_addr_t			rx_paddr;
	struct rx_stats			stats;
	u16				desc_count;
	u32				tail;
	struct ice_irq_vector		*irqv;
	u32				me;
	u8				tc;

	struct if_irq			que_irq;
};

/**
 * @struct ice_softc
 * @brief main structure representing one device
 *
 * ice_lib.c requires the following parameters
 * @all_vsi: the array of all allocated VSIs
 * @debug_sysctls: sysctl node for debug sysctls
 * @dev: device_t pointer
 * @feat_en: bitmap of enabled driver features
 * @hw: embedded ice_hw structure
 * @ifp: pointer to the ifnet structure
 * @link_up: boolean indicating if link is up
 * @num_available_vsi: size of the VSI array
 * @pf_vsi: embedded VSI structure for the main PF VSI
 * @rx_qmgr: queue manager for Rx queues
 * @soft_stats: software statistics for this device
 * @state: driver state flags
 * @stats: hardware statistics for this device
 * @tx_qmgr: queue manager for Tx queues
 * @vsi_sysctls: sysctl node for all VSI sysctls
 * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
 * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
 * @rebuild_ticks: indicates when a post-reset rebuild started
 * @imgr: resource manager for interrupt allocations
 * @pf_imap: interrupt mapping for PF LAN interrupts
 * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
 * @ldo_tlv: LAN Default Override settings from NVM
 *
 * ice_iov.c requires the following parameters (when PCI_IOV is defined):
 * @vfs: array of VF context structures
 * @num_vfs: number of VFs to use for SR-IOV
 *
 * The main representation for a single OS device, used to represent a single
 * physical function.
 */
struct ice_softc {
	struct ice_hw hw;
	struct ice_vsi pf_vsi;		/* Main PF VSI */

	char admin_mtx_name[16]; /* name of the admin mutex */
	struct mtx admin_mtx; /* mutex to protect the admin timer */
	struct callout admin_timer; /* timer to trigger admin task */

	/* iRDMA peer interface */
	struct ice_rdma_entry rdma_entry;
	int irdma_vectors;
	u16 *rdma_imap;

	struct ice_vsi **all_vsi;	/* Array of VSI pointers */
	u16 num_available_vsi;		/* Size of VSI array */

	struct sysctl_oid *vsi_sysctls;	/* Sysctl node for VSI sysctls */
	struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */

	device_t dev;
	if_ctx_t ctx;
	if_shared_ctx_t sctx;
	if_softc_ctx_t scctx;
	struct ifmedia *media;
	struct ifnet *ifp;

	/* device statistics */
	struct ice_pf_hw_stats stats;
	struct ice_pf_sw_stats soft_stats;

	/* Tx/Rx queue managers */
	struct ice_resmgr tx_qmgr;
	struct ice_resmgr rx_qmgr;

	/* Interrupt allocation manager */
	struct ice_resmgr imgr;
	u16 *pf_imap;
	int lan_vectors;

	/* iflib Tx/Rx queue count sysctl values */
	int ifc_sysctl_ntxqs;
	int ifc_sysctl_nrxqs;

	/* IRQ Vector data */
	struct resource *msix_table;
	int num_irq_vectors;
	struct ice_irq_vector *irqvs;

	/* BAR info */
	struct ice_bar_info bar0;

	/* link status */
	bool link_up;

	/* Ethertype filters enabled */
	bool enable_tx_fc_filter;
	bool enable_tx_lldp_filter;

	/* Other tunable flags */
	bool enable_health_events;

	/* 5-layer scheduler topology enabled */
	bool tx_balance_en;

	/* Allow additional non-standard FEC mode */
	bool allow_no_fec_mod_in_auto;

	int rebuild_ticks;

	/* driver state flags, only access using atomic functions */
	u32 state;

	/* NVM link override settings */
	struct ice_link_default_override_tlv ldo_tlv;

	u16 fw_debug_dump_cluster_mask;

	struct sx *iflib_ctx_lock;

	/* Tri-state feature flags (capable/enabled) */
	ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
	ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);

};

#endif /* _ICE_IFLIB_H_ */