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