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