1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright (c) 2020, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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.
35 * @brief main header for the iflib driver implementation
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
45 /* include kernel options first */
48 #include <sys/param.h>
49 #include <sys/types.h>
50 #include <sys/socket.h>
53 #include <net/if_var.h>
54 #include <net/if_media.h>
55 #include <net/ethernet.h>
56 #include <net/iflib.h>
60 #include "ice_osdep.h"
61 #include "ice_resmgr.h"
63 #include "ice_features.h"
66 * ASSERT_CTX_LOCKED - Assert that the iflib context lock is held
67 * @sc: ice softc pointer
69 * Macro to trigger an assertion if the iflib context lock is not
72 #define ASSERT_CTX_LOCKED(sc) sx_assert((sc)->iflib_ctx_lock, SA_XLOCKED)
75 * IFLIB_CTX_LOCK - lock the iflib context lock
76 * @sc: ice softc pointer
78 * Macro used to unlock the iflib context lock.
80 #define IFLIB_CTX_LOCK(sc) sx_xlock((sc)->iflib_ctx_lock)
83 * IFLIB_CTX_UNLOCK - unlock the iflib context lock
84 * @sc: ice softc pointer
86 * Macro used to unlock the iflib context lock.
88 #define IFLIB_CTX_UNLOCK(sc) sx_xunlock((sc)->iflib_ctx_lock)
91 * ASSERT_CFG_LOCKED - Assert that a configuration lock is held
92 * @sc: ice softc pointer
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.
98 #define ASSERT_CFG_LOCKED(sc) ASSERT_CTX_LOCKED(sc)
101 * ICE_IFLIB_MAX_DESC_COUNT - Maximum ring size for iflib
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).
108 #define ICE_IFLIB_MAX_DESC_COUNT 4096
111 * @struct ice_irq_vector
112 * @brief Driver irq vector structure
114 * ice_lib.c requires the following parameters
115 * @me: the vector number
117 * Other parameters may be iflib driver specific
119 * The iflib driver uses a single hardware interrupt per Rx queue, and uses
120 * software interrupts for the Tx queues.
122 struct ice_irq_vector {
129 * @struct ice_tx_queue
130 * @brief Driver Tx queue structure
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
141 * Other parameters may be iflib driver specific
143 struct ice_tx_queue {
145 struct ice_tx_desc *tx_base;
147 struct tx_stats stats;
151 struct ice_irq_vector *irqv;
155 /* descriptor writeback status */
159 qidx_t tx_cidx_processed;
163 * @struct ice_rx_queue
164 * @brief Driver Rx queue structure
166 * ice_lib.c requires the following parameters:
167 * @vsi: backpointer the VSI structure
168 * @me: this queue's index into the queue array
169 * @irqv: pointer to vector structure associated with this queue
170 * @desc_count: the number of descriptors
171 * @rx_paddr: the physical address for this queue
172 * @tail: the tail register address for this queue
173 * @stats: queue statistics
175 * Other parameters may be iflib driver specific
177 struct ice_rx_queue {
179 union ice_32b_rx_flex_desc *rx_base;
181 struct rx_stats stats;
184 struct ice_irq_vector *irqv;
187 struct if_irq que_irq;
192 * @brief main structure representing one device
194 * ice_lib.c requires the following parameters
195 * @all_vsi: the array of all allocated VSIs
196 * @debug_sysctls: sysctl node for debug sysctls
197 * @dev: device_t pointer
198 * @feat_en: bitmap of enabled driver features
199 * @hw: embedded ice_hw structure
200 * @ifp: pointer to the ifnet structure
201 * @link_up: boolean indicating if link is up
202 * @num_available_vsi: size of the VSI array
203 * @pf_vsi: embedded VSI structure for the main PF VSI
204 * @rx_qmgr: queue manager for Rx queues
205 * @soft_stats: software statistics for this device
206 * @state: driver state flags
207 * @stats: hardware statistics for this device
208 * @tx_qmgr: queue manager for Tx queues
209 * @vsi_sysctls: sysctl node for all VSI sysctls
210 * @enable_tx_fc_filter: boolean indicating if the Tx FC filter is enabled
211 * @enable_tx_lldp_filter: boolean indicating if the Tx LLDP filter is enabled
212 * @rebuild_ticks: indicates when a post-reset rebuild started
213 * @imgr: resource manager for interrupt allocations
214 * @pf_imap: interrupt mapping for PF LAN interrupts
215 * @lan_vectors: # of vectors used by LAN driver (length of pf_imap)
216 * @ldo_tlv: LAN Default Override settings from NVM
218 * ice_iov.c requires the following parameters (when PCI_IOV is defined):
219 * @vfs: array of VF context structures
220 * @num_vfs: number of VFs to use for SR-IOV
222 * The main representation for a single OS device, used to represent a single
227 struct ice_vsi pf_vsi; /* Main PF VSI */
229 char admin_mtx_name[16]; /* name of the admin mutex */
230 struct mtx admin_mtx; /* mutex to protect the admin timer */
231 struct callout admin_timer; /* timer to trigger admin task */
233 struct ice_vsi **all_vsi; /* Array of VSI pointers */
234 u16 num_available_vsi; /* Size of VSI array */
236 struct sysctl_oid *vsi_sysctls; /* Sysctl node for VSI sysctls */
237 struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */
241 if_shared_ctx_t sctx;
242 if_softc_ctx_t scctx;
243 struct ifmedia *media;
246 /* device statistics */
247 struct ice_pf_hw_stats stats;
248 struct ice_pf_sw_stats soft_stats;
250 /* Tx/Rx queue managers */
251 struct ice_resmgr tx_qmgr;
252 struct ice_resmgr rx_qmgr;
254 /* Interrupt allocation manager */
255 struct ice_resmgr imgr;
259 /* iflib Tx/Rx queue count sysctl values */
260 int ifc_sysctl_ntxqs;
261 int ifc_sysctl_nrxqs;
263 /* IRQ Vector data */
264 struct resource *msix_table;
266 struct ice_irq_vector *irqvs;
269 struct ice_bar_info bar0;
274 /* Ethertype filters enabled */
275 bool enable_tx_fc_filter;
276 bool enable_tx_lldp_filter;
280 /* driver state flags, only access using atomic functions */
283 /* NVM link override settings */
284 struct ice_link_default_override_tlv ldo_tlv;
286 struct sx *iflib_ctx_lock;
288 /* Tri-state feature flags (capable/enabled) */
289 ice_declare_bitmap(feat_cap, ICE_FEATURE_COUNT);
290 ice_declare_bitmap(feat_en, ICE_FEATURE_COUNT);
294 #endif /* _ICE_IFLIB_H_ */