1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright (c) 2020, 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 * 141 * Other parameters may be iflib driver specific 142 */ 143 struct ice_tx_queue { 144 struct ice_vsi *vsi; 145 struct ice_tx_desc *tx_base; 146 bus_addr_t tx_paddr; 147 struct tx_stats stats; 148 u64 tso; 149 u16 desc_count; 150 u32 tail; 151 struct ice_irq_vector *irqv; 152 u32 q_teid; 153 u32 me; 154 155 /* descriptor writeback status */ 156 qidx_t *tx_rsq; 157 qidx_t tx_rs_cidx; 158 qidx_t tx_rs_pidx; 159 qidx_t tx_cidx_processed; 160 }; 161 162 /** 163 * @struct ice_rx_queue 164 * @brief Driver Rx queue structure 165 * 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 174 * 175 * Other parameters may be iflib driver specific 176 */ 177 struct ice_rx_queue { 178 struct ice_vsi *vsi; 179 union ice_32b_rx_flex_desc *rx_base; 180 bus_addr_t rx_paddr; 181 struct rx_stats stats; 182 u16 desc_count; 183 u32 tail; 184 struct ice_irq_vector *irqv; 185 u32 me; 186 187 struct if_irq que_irq; 188 }; 189 190 /** 191 * @struct ice_softc 192 * @brief main structure representing one device 193 * 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 217 * 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 221 * 222 * The main representation for a single OS device, used to represent a single 223 * physical function. 224 */ 225 struct ice_softc { 226 struct ice_hw hw; 227 struct ice_vsi pf_vsi; /* Main PF VSI */ 228 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 */ 232 233 struct ice_vsi **all_vsi; /* Array of VSI pointers */ 234 u16 num_available_vsi; /* Size of VSI array */ 235 236 struct sysctl_oid *vsi_sysctls; /* Sysctl node for VSI sysctls */ 237 struct sysctl_oid *debug_sysctls; /* Sysctl node for debug sysctls */ 238 239 device_t dev; 240 if_ctx_t ctx; 241 if_shared_ctx_t sctx; 242 if_softc_ctx_t scctx; 243 struct ifmedia *media; 244 struct ifnet *ifp; 245 246 /* device statistics */ 247 struct ice_pf_hw_stats stats; 248 struct ice_pf_sw_stats soft_stats; 249 250 /* Tx/Rx queue managers */ 251 struct ice_resmgr tx_qmgr; 252 struct ice_resmgr rx_qmgr; 253 254 /* Interrupt allocation manager */ 255 struct ice_resmgr imgr; 256 u16 *pf_imap; 257 int lan_vectors; 258 259 /* iflib Tx/Rx queue count sysctl values */ 260 int ifc_sysctl_ntxqs; 261 int ifc_sysctl_nrxqs; 262 263 /* IRQ Vector data */ 264 struct resource *msix_table; 265 int num_irq_vectors; 266 struct ice_irq_vector *irqvs; 267 268 /* BAR info */ 269 struct ice_bar_info bar0; 270 271 /* link status */ 272 bool link_up; 273 274 /* Ethertype filters enabled */ 275 bool enable_tx_fc_filter; 276 bool enable_tx_lldp_filter; 277 278 int rebuild_ticks; 279 280 /* driver state flags, only access using atomic functions */ 281 u32 state; 282 283 /* NVM link override settings */ 284 struct ice_link_default_override_tlv ldo_tlv; 285 286 struct sx *iflib_ctx_lock; 287 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); 291 292 }; 293 294 #endif /* _ICE_IFLIB_H_ */ 295