1 1.100 andvar /* $NetBSD: ixgbe.h,v 1.100 2025/02/26 04:49:46 andvar Exp $ */ 2 1.26 msaitoh 3 1.1 dyoung /****************************************************************************** 4 1.29 msaitoh SPDX-License-Identifier: BSD-3-Clause 5 1.1 dyoung 6 1.26 msaitoh Copyright (c) 2001-2017, Intel Corporation 7 1.1 dyoung All rights reserved. 8 1.26 msaitoh 9 1.26 msaitoh Redistribution and use in source and binary forms, with or without 10 1.1 dyoung modification, are permitted provided that the following conditions are met: 11 1.26 msaitoh 12 1.26 msaitoh 1. Redistributions of source code must retain the above copyright notice, 13 1.1 dyoung this list of conditions and the following disclaimer. 14 1.26 msaitoh 15 1.26 msaitoh 2. Redistributions in binary form must reproduce the above copyright 16 1.26 msaitoh notice, this list of conditions and the following disclaimer in the 17 1.1 dyoung documentation and/or other materials provided with the distribution. 18 1.26 msaitoh 19 1.26 msaitoh 3. Neither the name of the Intel Corporation nor the names of its 20 1.26 msaitoh contributors may be used to endorse or promote products derived from 21 1.1 dyoung this software without specific prior written permission. 22 1.26 msaitoh 23 1.1 dyoung THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 1.26 msaitoh AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 1.26 msaitoh IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 1.26 msaitoh ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 1.26 msaitoh LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 1.26 msaitoh CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 1.26 msaitoh SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 1.26 msaitoh INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 1.26 msaitoh CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 1.1 dyoung ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 1.1 dyoung POSSIBILITY OF SUCH DAMAGE. 34 1.1 dyoung 35 1.1 dyoung ******************************************************************************/ 36 1.41 msaitoh /*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 327031 2017-12-20 18:15:06Z erj $*/ 37 1.26 msaitoh 38 1.1 dyoung /* 39 1.1 dyoung * Copyright (c) 2011 The NetBSD Foundation, Inc. 40 1.1 dyoung * All rights reserved. 41 1.1 dyoung * 42 1.1 dyoung * This code is derived from software contributed to The NetBSD Foundation 43 1.1 dyoung * by Coyote Point Systems, Inc. 44 1.1 dyoung * 45 1.1 dyoung * Redistribution and use in source and binary forms, with or without 46 1.1 dyoung * modification, are permitted provided that the following conditions 47 1.1 dyoung * are met: 48 1.1 dyoung * 1. Redistributions of source code must retain the above copyright 49 1.1 dyoung * notice, this list of conditions and the following disclaimer. 50 1.1 dyoung * 2. Redistributions in binary form must reproduce the above copyright 51 1.1 dyoung * notice, this list of conditions and the following disclaimer in the 52 1.1 dyoung * documentation and/or other materials provided with the distribution. 53 1.1 dyoung * 54 1.1 dyoung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 55 1.1 dyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 56 1.1 dyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 57 1.1 dyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 58 1.1 dyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 59 1.1 dyoung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 60 1.1 dyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 1.1 dyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 1.1 dyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 1.1 dyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 1.1 dyoung * POSSIBILITY OF SUCH DAMAGE. 65 1.1 dyoung */ 66 1.1 dyoung 67 1.1 dyoung 68 1.1 dyoung #ifndef _IXGBE_H_ 69 1.1 dyoung #define _IXGBE_H_ 70 1.1 dyoung 71 1.1 dyoung 72 1.1 dyoung #include <sys/param.h> 73 1.1 dyoung #include <sys/reboot.h> 74 1.1 dyoung #include <sys/systm.h> 75 1.22 msaitoh #include <sys/pcq.h> 76 1.1 dyoung #include <sys/mbuf.h> 77 1.1 dyoung #include <sys/protosw.h> 78 1.1 dyoung #include <sys/socket.h> 79 1.1 dyoung #include <sys/malloc.h> 80 1.1 dyoung #include <sys/kernel.h> 81 1.1 dyoung #include <sys/module.h> 82 1.1 dyoung #include <sys/sockio.h> 83 1.32 knakahar #include <sys/percpu.h> 84 1.1 dyoung 85 1.1 dyoung #include <net/if.h> 86 1.1 dyoung #include <net/if_arp.h> 87 1.1 dyoung #include <net/bpf.h> 88 1.1 dyoung #include <net/if_ether.h> 89 1.1 dyoung #include <net/if_dl.h> 90 1.1 dyoung #include <net/if_media.h> 91 1.1 dyoung 92 1.1 dyoung #include <net/if_types.h> 93 1.1 dyoung #include <net/if_vlanvar.h> 94 1.1 dyoung 95 1.1 dyoung #include <netinet/in_systm.h> 96 1.1 dyoung #include <netinet/in.h> 97 1.1 dyoung #include <netinet/ip.h> 98 1.1 dyoung #include <netinet/ip6.h> 99 1.1 dyoung #include <netinet/tcp.h> 100 1.1 dyoung #include <netinet/udp.h> 101 1.1 dyoung 102 1.1 dyoung #include <sys/bus.h> 103 1.1 dyoung #include <dev/pci/pcivar.h> 104 1.1 dyoung #include <dev/pci/pcireg.h> 105 1.1 dyoung #include <sys/proc.h> 106 1.1 dyoung #include <sys/sysctl.h> 107 1.1 dyoung #include <sys/endian.h> 108 1.1 dyoung #include <sys/workqueue.h> 109 1.7 msaitoh #include <sys/cpu.h> 110 1.9 knakahar #include <sys/interrupt.h> 111 1.22 msaitoh #include <sys/bitops.h> 112 1.1 dyoung 113 1.1 dyoung #include "ixgbe_netbsd.h" 114 1.1 dyoung #include "ixgbe_api.h" 115 1.12 msaitoh #include "ixgbe_common.h" 116 1.10 msaitoh #include "ixgbe_vf.h" 117 1.26 msaitoh #include "ixgbe_features.h" 118 1.1 dyoung 119 1.1 dyoung /* Tunables */ 120 1.1 dyoung 121 1.1 dyoung /* 122 1.91 msaitoh * TxDescriptors Valid Range: 64-4096 Default Value: 2048 This value is the 123 1.1 dyoung * number of transmit descriptors allocated by the driver. Increasing this 124 1.1 dyoung * value allows the driver to queue more transmits. Each descriptor is 16 125 1.1 dyoung * bytes. Performance tests have show the 2K value to be optimal for top 126 1.1 dyoung * performance. 127 1.1 dyoung */ 128 1.91 msaitoh #define DEFAULT_TXD 2048 129 1.1 dyoung #define MAX_TXD 4096 130 1.1 dyoung #define MIN_TXD 64 131 1.1 dyoung 132 1.1 dyoung /* 133 1.91 msaitoh * RxDescriptors Valid Range: 64-4096 Default Value: 2048 This value is the 134 1.1 dyoung * number of receive descriptors allocated for each RX queue. Increasing this 135 1.1 dyoung * value allows the driver to buffer more incoming packets. Each descriptor 136 1.60 msaitoh * is 16 bytes. A receive buffer is also allocated for each descriptor. 137 1.60 msaitoh * 138 1.60 msaitoh * Note: with 8 rings and a dual port card, it is possible to bump up 139 1.1 dyoung * against the system mbuf pool limit, you can tune nmbclusters 140 1.1 dyoung * to adjust for this. 141 1.1 dyoung */ 142 1.91 msaitoh #define DEFAULT_RXD 2048 143 1.1 dyoung #define MAX_RXD 4096 144 1.1 dyoung #define MIN_RXD 64 145 1.1 dyoung 146 1.1 dyoung /* Alignment for rings */ 147 1.1 dyoung #define DBA_ALIGN 128 148 1.1 dyoung 149 1.1 dyoung /* 150 1.1 dyoung * This is the max watchdog interval, ie. the time that can 151 1.1 dyoung * pass between any two TX clean operations, such only happening 152 1.1 dyoung * when the TX hardware is functioning. 153 1.1 dyoung */ 154 1.48 msaitoh #define IXGBE_WATCHDOG (10 * hz) 155 1.1 dyoung 156 1.1 dyoung /* 157 1.1 dyoung * This parameters control when the driver calls the routine to reclaim 158 1.1 dyoung * transmit descriptors. 159 1.1 dyoung */ 160 1.26 msaitoh #define IXGBE_TX_CLEANUP_THRESHOLD(_a) ((_a)->num_tx_desc / 8) 161 1.26 msaitoh #define IXGBE_TX_OP_THRESHOLD(_a) ((_a)->num_tx_desc / 32) 162 1.1 dyoung 163 1.12 msaitoh /* These defines are used in MTU calculations */ 164 1.26 msaitoh #define IXGBE_MAX_FRAME_SIZE 9728 165 1.26 msaitoh #define IXGBE_MTU_HDR (ETHER_HDR_LEN + ETHER_CRC_LEN) 166 1.26 msaitoh #define IXGBE_MTU_HDR_VLAN (ETHER_HDR_LEN + ETHER_CRC_LEN + \ 167 1.26 msaitoh ETHER_VLAN_ENCAP_LEN) 168 1.26 msaitoh #define IXGBE_MAX_MTU (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR) 169 1.26 msaitoh #define IXGBE_MAX_MTU_VLAN (IXGBE_MAX_FRAME_SIZE - IXGBE_MTU_HDR_VLAN) 170 1.1 dyoung 171 1.1 dyoung /* Flow control constants */ 172 1.26 msaitoh #define IXGBE_FC_PAUSE 0xFFFF 173 1.1 dyoung 174 1.6 msaitoh /* 175 1.6 msaitoh * Used for optimizing small rx mbufs. Effort is made to keep the copy 176 1.6 msaitoh * small and aligned for the CPU L1 cache. 177 1.26 msaitoh * 178 1.6 msaitoh * MHLEN is typically 168 bytes, giving us 8-byte alignment. Getting 179 1.6 msaitoh * 32 byte alignment needed for the fast bcopy results in 8 bytes being 180 1.6 msaitoh * wasted. Getting 64 byte alignment, which _should_ be ideal for 181 1.6 msaitoh * modern Intel CPUs, results in 40 bytes wasted and a significant drop 182 1.6 msaitoh * in observed efficiency of the optimization, 97.9% -> 81.8%. 183 1.6 msaitoh */ 184 1.77 msaitoh #define IXGBE_RX_COPY_LEN_MAX (MHLEN - ETHER_ALIGN) 185 1.6 msaitoh 186 1.81 msaitoh /* 187 1.81 msaitoh * Default TX WTHRESH value. 188 1.81 msaitoh * Currently, we don't use the Tx Head Pointer Write Back function. 189 1.81 msaitoh */ 190 1.81 msaitoh #define IXGBE_TX_WTHRESH 5 191 1.81 msaitoh 192 1.81 msaitoh /* 193 1.81 msaitoh * The max number of descriptors that one packet can use is 40 - WTHRESH - 2. 194 1.81 msaitoh * Though 82598 does not have this limit, we don't want long TX chain. 195 1.81 msaitoh * 33 should be large enough even for 64K TSO 196 1.81 msaitoh * (32 * 2K mbuf cluster and 1 x mbuf header). 197 1.81 msaitoh * 198 1.83 msaitoh * Reference: 82599-X550 datasheet 7.2.1.1 "Transmit Storage in System Memory". 199 1.81 msaitoh */ 200 1.81 msaitoh #define IXGBE_82599_SCATTER_MAX (40 - IXGBE_TX_WTHRESH - 2) 201 1.81 msaitoh #define IXGBE_SCATTER_DEFAULT 33 202 1.81 msaitoh 203 1.1 dyoung /* Defines for printing debug information */ 204 1.1 dyoung #define DEBUG_INIT 0 205 1.1 dyoung #define DEBUG_IOCTL 0 206 1.1 dyoung #define DEBUG_HW 0 207 1.1 dyoung 208 1.1 dyoung #define INIT_DEBUGOUT(S) if (DEBUG_INIT) printf(S "\n") 209 1.1 dyoung #define INIT_DEBUGOUT1(S, A) if (DEBUG_INIT) printf(S "\n", A) 210 1.1 dyoung #define INIT_DEBUGOUT2(S, A, B) if (DEBUG_INIT) printf(S "\n", A, B) 211 1.1 dyoung #define IOCTL_DEBUGOUT(S) if (DEBUG_IOCTL) printf(S "\n") 212 1.1 dyoung #define IOCTL_DEBUGOUT1(S, A) if (DEBUG_IOCTL) printf(S "\n", A) 213 1.1 dyoung #define IOCTL_DEBUGOUT2(S, A, B) if (DEBUG_IOCTL) printf(S "\n", A, B) 214 1.1 dyoung #define HW_DEBUGOUT(S) if (DEBUG_HW) printf(S "\n") 215 1.1 dyoung #define HW_DEBUGOUT1(S, A) if (DEBUG_HW) printf(S "\n", A) 216 1.1 dyoung #define HW_DEBUGOUT2(S, A, B) if (DEBUG_HW) printf(S "\n", A, B) 217 1.1 dyoung 218 1.1 dyoung #define MAX_NUM_MULTICAST_ADDRESSES 128 219 1.26 msaitoh #define MSIX_82598_BAR 3 220 1.26 msaitoh #define MSIX_82599_BAR 4 221 1.26 msaitoh #define IXGBE_TSO_SIZE 262140 222 1.26 msaitoh #define IXGBE_RX_HDR 128 223 1.26 msaitoh #define IXGBE_VFTA_SIZE 128 224 1.75 msaitoh #define IXGBE_BR_SIZE 2048 225 1.26 msaitoh #define IXGBE_QUEUE_MIN_FREE 32 226 1.48 msaitoh #define IXGBE_MAX_TX_BUSY 10 227 1.48 msaitoh #define IXGBE_QUEUE_HUNG 0x80000000 228 1.11 msaitoh 229 1.26 msaitoh #define IXGBE_EITR_DEFAULT 128 230 1.11 msaitoh 231 1.7 msaitoh /* IOCTL define to gather SFP+ Diagnostic data */ 232 1.7 msaitoh #define SIOCGI2C SIOCGIFGENERIC 233 1.7 msaitoh 234 1.1 dyoung /* Offload bits in mbuf flag */ 235 1.1 dyoung #define M_CSUM_OFFLOAD \ 236 1.1 dyoung (M_CSUM_IPv4|M_CSUM_UDPv4|M_CSUM_TCPv4|M_CSUM_UDPv6|M_CSUM_TCPv6) 237 1.1 dyoung 238 1.11 msaitoh /* Backward compatibility items for very old versions */ 239 1.11 msaitoh #ifndef pci_find_cap 240 1.11 msaitoh #define pci_find_cap pci_find_extcap 241 1.11 msaitoh #endif 242 1.11 msaitoh 243 1.11 msaitoh #ifndef DEVMETHOD_END 244 1.11 msaitoh #define DEVMETHOD_END { NULL, NULL } 245 1.11 msaitoh #endif 246 1.11 msaitoh 247 1.1 dyoung /* 248 1.55 msaitoh * Interrupt Moderation parameters 249 1.1 dyoung */ 250 1.1 dyoung #define IXGBE_LOW_LATENCY 128 251 1.1 dyoung #define IXGBE_AVE_LATENCY 400 252 1.1 dyoung #define IXGBE_BULK_LATENCY 1200 253 1.16 msaitoh 254 1.16 msaitoh /* Using 1FF (the max value), the interval is ~1.05ms */ 255 1.26 msaitoh #define IXGBE_LINK_ITR_QUANTA 0x1FF 256 1.26 msaitoh #define IXGBE_LINK_ITR ((IXGBE_LINK_ITR_QUANTA << 3) & \ 257 1.26 msaitoh IXGBE_EITR_ITR_INT_MASK) 258 1.13 msaitoh 259 1.13 msaitoh 260 1.26 msaitoh /************************************************************************ 261 1.1 dyoung * vendor_info_array 262 1.26 msaitoh * 263 1.26 msaitoh * Contains the list of Subvendor/Subdevice IDs on 264 1.26 msaitoh * which the driver should load. 265 1.26 msaitoh ************************************************************************/ 266 1.1 dyoung typedef struct _ixgbe_vendor_info_t { 267 1.26 msaitoh unsigned int vendor_id; 268 1.26 msaitoh unsigned int device_id; 269 1.26 msaitoh unsigned int subvendor_id; 270 1.26 msaitoh unsigned int subdevice_id; 271 1.26 msaitoh unsigned int index; 272 1.1 dyoung } ixgbe_vendor_info_t; 273 1.1 dyoung 274 1.7 msaitoh /* This is used to get SFP+ module data */ 275 1.7 msaitoh struct ixgbe_i2c_req { 276 1.66 msaitoh u8 dev_addr; 277 1.66 msaitoh u8 offset; 278 1.66 msaitoh u8 len; 279 1.66 msaitoh u8 data[8]; 280 1.7 msaitoh }; 281 1.1 dyoung 282 1.26 msaitoh struct ixgbe_bp_data { 283 1.26 msaitoh u32 low; 284 1.26 msaitoh u32 high; 285 1.26 msaitoh u32 log; 286 1.26 msaitoh }; 287 1.13 msaitoh 288 1.1 dyoung struct ixgbe_tx_buf { 289 1.7 msaitoh union ixgbe_adv_tx_desc *eop; 290 1.26 msaitoh struct mbuf *m_head; 291 1.26 msaitoh bus_dmamap_t map; 292 1.1 dyoung }; 293 1.1 dyoung 294 1.1 dyoung struct ixgbe_rx_buf { 295 1.26 msaitoh struct mbuf *buf; 296 1.26 msaitoh struct mbuf *fmp; 297 1.26 msaitoh bus_dmamap_t pmap; 298 1.26 msaitoh u_int flags; 299 1.26 msaitoh #define IXGBE_RX_COPY 0x01 300 1.26 msaitoh uint64_t addr; 301 1.1 dyoung }; 302 1.1 dyoung 303 1.1 dyoung /* 304 1.26 msaitoh * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free 305 1.1 dyoung */ 306 1.1 dyoung struct ixgbe_dma_alloc { 307 1.26 msaitoh bus_addr_t dma_paddr; 308 1.26 msaitoh void *dma_vaddr; 309 1.26 msaitoh ixgbe_dma_tag_t *dma_tag; 310 1.26 msaitoh bus_dmamap_t dma_map; 311 1.26 msaitoh bus_dma_segment_t dma_seg; 312 1.26 msaitoh bus_size_t dma_size; 313 1.1 dyoung }; 314 1.1 dyoung 315 1.13 msaitoh struct ixgbe_mc_addr { 316 1.26 msaitoh u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS]; 317 1.13 msaitoh u32 vmdq; 318 1.13 msaitoh }; 319 1.13 msaitoh 320 1.1 dyoung /* 321 1.26 msaitoh * Driver queue struct: this is the interrupt container 322 1.26 msaitoh * for the associated tx and rx ring. 323 1.26 msaitoh */ 324 1.1 dyoung struct ix_queue { 325 1.89 msaitoh struct ixgbe_softc *sc; 326 1.26 msaitoh u32 msix; /* This queue's MSI-X vector */ 327 1.26 msaitoh u32 eitr_setting; 328 1.97 msaitoh u8 me; 329 1.26 msaitoh struct resource *res; 330 1.48 msaitoh int busy; 331 1.26 msaitoh struct tx_ring *txr; 332 1.26 msaitoh struct rx_ring *rxr; 333 1.33 msaitoh struct work wq_cookie; 334 1.26 msaitoh void *que_si; 335 1.100 andvar /* Per queue event counters */ 336 1.35 msaitoh struct evcnt irqs; /* Hardware interrupt */ 337 1.35 msaitoh struct evcnt handleq; /* software_interrupt */ 338 1.35 msaitoh struct evcnt req; /* deferred */ 339 1.73 msaitoh char namebuf[32]; /* Name for sysctl */ 340 1.73 msaitoh char evnamebuf[32]; /* Name for evcnt */ 341 1.31 knakahar 342 1.66 msaitoh /* Lock for disabled_count and this queue's EIMS/EIMC bit */ 343 1.66 msaitoh kmutex_t dc_mtx; 344 1.66 msaitoh /* 345 1.66 msaitoh * disabled_count means: 346 1.66 msaitoh * 0 : this queue is enabled 347 1.66 msaitoh * > 0 : this queue is disabled 348 1.66 msaitoh * the value is ixgbe_disable_queue() called count 349 1.66 msaitoh */ 350 1.66 msaitoh int disabled_count; 351 1.42 knakahar bool txrx_use_workqueue; 352 1.1 dyoung }; 353 1.1 dyoung 354 1.1 dyoung /* 355 1.1 dyoung * The transmit ring, one per queue 356 1.1 dyoung */ 357 1.1 dyoung struct tx_ring { 358 1.89 msaitoh struct ixgbe_softc *sc; 359 1.1 dyoung kmutex_t tx_mtx; 360 1.97 msaitoh u8 me; 361 1.11 msaitoh u32 tail; 362 1.48 msaitoh int busy; 363 1.7 msaitoh union ixgbe_adv_tx_desc *tx_base; 364 1.7 msaitoh struct ixgbe_tx_buf *tx_buffers; 365 1.7 msaitoh struct ixgbe_dma_alloc txdma; 366 1.7 msaitoh volatile u16 tx_avail; 367 1.7 msaitoh u16 next_avail_desc; 368 1.7 msaitoh u16 next_to_clean; 369 1.7 msaitoh u16 num_desc; 370 1.1 dyoung ixgbe_dma_tag_t *txtag; 371 1.43 msaitoh #if 0 372 1.43 msaitoh char mtx_name[16]; /* NetBSD has no mutex name */ 373 1.43 msaitoh #endif 374 1.22 msaitoh pcq_t *txr_interq; 375 1.33 msaitoh struct work wq_cookie; 376 1.22 msaitoh void *txr_si; 377 1.49 msaitoh bool txr_no_space; /* Like IFF_OACTIVE */ 378 1.26 msaitoh 379 1.94 msaitoh #ifdef IXGBE_FDIR 380 1.26 msaitoh /* Flow Director */ 381 1.1 dyoung u16 atr_sample; 382 1.1 dyoung u16 atr_count; 383 1.94 msaitoh #endif 384 1.26 msaitoh 385 1.66 msaitoh u64 bytes; /* Used for AIM */ 386 1.38 knakahar u64 packets; 387 1.1 dyoung /* Soft Stats */ 388 1.1 dyoung struct evcnt total_packets; 389 1.22 msaitoh struct evcnt pcq_drops; 390 1.87 msaitoh struct evcnt no_desc_avail; 391 1.87 msaitoh struct evcnt tso_tx; 392 1.100 andvar /* Per queue counters. The adapter total is in struct adapter */ 393 1.35 msaitoh u64 q_efbig_tx_dma_setup; 394 1.35 msaitoh u64 q_mbuf_defrag_failed; 395 1.35 msaitoh u64 q_efbig2_tx_dma_setup; 396 1.35 msaitoh u64 q_einval_tx_dma_setup; 397 1.35 msaitoh u64 q_other_tx_dma_setup; 398 1.35 msaitoh u64 q_eagain_tx_dma_setup; 399 1.35 msaitoh u64 q_enomem_tx_dma_setup; 400 1.35 msaitoh u64 q_tso_err; 401 1.1 dyoung }; 402 1.1 dyoung 403 1.1 dyoung 404 1.1 dyoung /* 405 1.1 dyoung * The Receive ring, one per rx queue 406 1.1 dyoung */ 407 1.1 dyoung struct rx_ring { 408 1.89 msaitoh struct ixgbe_softc *sc; 409 1.1 dyoung kmutex_t rx_mtx; 410 1.97 msaitoh u8 me; 411 1.11 msaitoh u32 tail; 412 1.1 dyoung union ixgbe_adv_rx_desc *rx_base; 413 1.1 dyoung struct ixgbe_dma_alloc rxdma; 414 1.1 dyoung #ifdef LRO 415 1.1 dyoung struct lro_ctrl lro; 416 1.96 msaitoh bool lro_enabled; 417 1.1 dyoung #endif /* LRO */ 418 1.98 msaitoh #ifdef RSC 419 1.1 dyoung bool hw_rsc; 420 1.98 msaitoh #endif 421 1.4 msaitoh bool vtag_strip; 422 1.80 msaitoh bool discard_multidesc; 423 1.55 msaitoh u16 next_to_refresh; 424 1.66 msaitoh u16 next_to_check; 425 1.7 msaitoh u16 num_desc; 426 1.7 msaitoh u16 mbuf_sz; 427 1.43 msaitoh #if 0 428 1.43 msaitoh char mtx_name[16]; /* NetBSD has no mutex name */ 429 1.43 msaitoh #endif 430 1.1 dyoung struct ixgbe_rx_buf *rx_buffers; 431 1.7 msaitoh ixgbe_dma_tag_t *ptag; 432 1.1 dyoung 433 1.38 knakahar u64 bytes; /* Used for AIM calc */ 434 1.38 knakahar u64 packets; 435 1.1 dyoung 436 1.1 dyoung /* Soft stats */ 437 1.6 msaitoh struct evcnt rx_copies; 438 1.1 dyoung struct evcnt rx_packets; 439 1.66 msaitoh struct evcnt rx_bytes; 440 1.66 msaitoh struct evcnt rx_discarded; 441 1.79 msaitoh struct evcnt no_mbuf; 442 1.98 msaitoh #ifdef RSC 443 1.66 msaitoh u64 rsc_num; 444 1.98 msaitoh #endif 445 1.1 dyoung }; 446 1.1 dyoung 447 1.13 msaitoh struct ixgbe_vf { 448 1.26 msaitoh u_int pool; 449 1.26 msaitoh u_int rar_index; 450 1.26 msaitoh u_int max_frame_size; 451 1.26 msaitoh uint32_t flags; 452 1.26 msaitoh uint8_t ether_addr[ETHER_ADDR_LEN]; 453 1.26 msaitoh uint16_t mc_hash[IXGBE_MAX_VF_MC]; 454 1.26 msaitoh uint16_t num_mc_hashes; 455 1.26 msaitoh uint16_t default_vlan; 456 1.26 msaitoh uint16_t vlan_tag; 457 1.26 msaitoh uint16_t api_ver; 458 1.13 msaitoh }; 459 1.13 msaitoh 460 1.52 msaitoh /* 461 1.99 andvar * NetBSD: For traffic class 462 1.99 andvar * Currently, the following structure is only for statistics. 463 1.52 msaitoh */ 464 1.52 msaitoh struct ixgbe_tc { 465 1.52 msaitoh char evnamebuf[32]; 466 1.52 msaitoh }; 467 1.52 msaitoh 468 1.1 dyoung /* Our adapter structure */ 469 1.89 msaitoh struct ixgbe_softc { 470 1.1 dyoung struct ixgbe_hw hw; 471 1.16 msaitoh struct ixgbe_osdep osdep; 472 1.1 dyoung 473 1.1 dyoung device_t dev; 474 1.16 msaitoh struct ifnet *ifp; 475 1.24 msaitoh struct if_percpuq *ipq; /* softint-based input queues */ 476 1.1 dyoung 477 1.1 dyoung struct resource *pci_mem; 478 1.1 dyoung 479 1.43 msaitoh /* NetBSD: Interrupt resources are in osdep */ 480 1.1 dyoung 481 1.1 dyoung struct ifmedia media; 482 1.1 dyoung callout_t timer; 483 1.67 msaitoh struct workqueue *timer_wq; 484 1.67 msaitoh struct work timer_wc; 485 1.67 msaitoh u_int timer_pending; 486 1.67 msaitoh 487 1.58 msaitoh u_short if_flags; /* saved ifp->if_flags */ 488 1.56 msaitoh int ec_capenable; /* saved ec->ec_capenable */ 489 1.1 dyoung 490 1.1 dyoung kmutex_t core_mtx; 491 1.1 dyoung 492 1.1 dyoung unsigned int num_queues; 493 1.1 dyoung 494 1.1 dyoung /* 495 1.26 msaitoh * Shadow VFTA table, this is needed because 496 1.26 msaitoh * the real vlan filter table gets cleared during 497 1.26 msaitoh * a soft reset and the driver needs to be able 498 1.26 msaitoh * to repopulate it. 499 1.26 msaitoh */ 500 1.1 dyoung u32 shadow_vfta[IXGBE_VFTA_SIZE]; 501 1.1 dyoung 502 1.1 dyoung /* Info about the interface */ 503 1.1 dyoung int advertise; /* link speeds */ 504 1.18 msaitoh bool enable_aim; /* adaptive interrupt moderation */ 505 1.93 msaitoh int max_interrupt_rate; 506 1.54 msaitoh int link_active; /* Use LINK_STATE_* value */ 507 1.1 dyoung u16 max_frame_size; 508 1.1 dyoung u16 num_segs; 509 1.1 dyoung u32 link_speed; 510 1.1 dyoung bool link_up; 511 1.88 msaitoh bool link_enabled; 512 1.66 msaitoh u32 vector; 513 1.12 msaitoh u16 dmac; 514 1.13 msaitoh u32 phy_layer; 515 1.12 msaitoh 516 1.12 msaitoh /* Power management-related */ 517 1.12 msaitoh bool wol_support; 518 1.12 msaitoh u32 wufc; 519 1.1 dyoung 520 1.1 dyoung /* Mbuf cluster size */ 521 1.1 dyoung u32 rx_mbuf_sz; 522 1.1 dyoung 523 1.63 thorpej bool schedule_wqs_ok; 524 1.63 thorpej 525 1.26 msaitoh /* Flow Director */ 526 1.1 dyoung int fdir_reinit; 527 1.26 msaitoh 528 1.67 msaitoh /* Admin task */ 529 1.67 msaitoh struct workqueue *admin_wq; /* Link, SFP, PHY and FDIR */ 530 1.67 msaitoh struct work admin_wc; 531 1.67 msaitoh u_int admin_pending; 532 1.67 msaitoh volatile u32 task_requests; 533 1.72 knakahar kmutex_t admin_mtx; /* lock for admin_pending, task_request */ 534 1.72 knakahar /* 535 1.72 knakahar * Don't acquire this mutex while 536 1.72 knakahar * holding rx_mtx or tx_mtx, and 537 1.72 knakahar * vice versa. 538 1.72 knakahar */ 539 1.1 dyoung 540 1.32 knakahar bool txrx_use_workqueue; 541 1.66 msaitoh 542 1.66 msaitoh /* 543 1.66 msaitoh * Workqueue for ixgbe_handle_que_work(). 544 1.66 msaitoh * 545 1.66 msaitoh * que_wq's "enqueued flag" is not required, because twice 546 1.66 msaitoh * workqueue_enqueue() for ixgbe_handle_que_work() is avoided by 547 1.66 msaitoh * masking the queue's interrupt by EIMC. See also ixgbe_msix_que(). 548 1.66 msaitoh */ 549 1.66 msaitoh struct workqueue *que_wq; 550 1.66 msaitoh /* Workqueue for ixgbe_deferred_mq_start_work() */ 551 1.66 msaitoh struct workqueue *txr_wq; 552 1.32 knakahar percpu_t *txr_wq_enqueued; 553 1.32 knakahar 554 1.1 dyoung /* 555 1.26 msaitoh * Queues: 556 1.26 msaitoh * This is the irq holder, it has 557 1.26 msaitoh * and RX/TX pair or rings associated 558 1.26 msaitoh * with it. 559 1.26 msaitoh */ 560 1.1 dyoung struct ix_queue *queues; 561 1.1 dyoung 562 1.1 dyoung /* 563 1.26 msaitoh * Transmit rings 564 1.26 msaitoh * Allocated at run time, an array of rings 565 1.1 dyoung */ 566 1.1 dyoung struct tx_ring *tx_rings; 567 1.7 msaitoh u32 num_tx_desc; 568 1.15 msaitoh u32 tx_process_limit; 569 1.1 dyoung 570 1.1 dyoung /* 571 1.26 msaitoh * Receive rings 572 1.26 msaitoh * Allocated at run time, an array of rings 573 1.1 dyoung */ 574 1.1 dyoung struct rx_ring *rx_rings; 575 1.11 msaitoh u64 active_queues; 576 1.7 msaitoh u32 num_rx_desc; 577 1.15 msaitoh u32 rx_process_limit; 578 1.76 msaitoh u32 rx_copy_len; 579 1.1 dyoung 580 1.1 dyoung /* Multicast array memory */ 581 1.13 msaitoh struct ixgbe_mc_addr *mta; 582 1.26 msaitoh 583 1.26 msaitoh /* SR-IOV */ 584 1.26 msaitoh int iov_mode; 585 1.13 msaitoh int num_vfs; 586 1.13 msaitoh int pool; 587 1.13 msaitoh struct ixgbe_vf *vfs; 588 1.26 msaitoh 589 1.26 msaitoh /* Bypass */ 590 1.26 msaitoh struct ixgbe_bp_data bypass; 591 1.26 msaitoh 592 1.26 msaitoh /* Netmap */ 593 1.89 msaitoh void (*init_locked)(struct ixgbe_softc *); 594 1.66 msaitoh void (*stop_locked)(void *); 595 1.8 msaitoh 596 1.53 msaitoh /* Firmware error check */ 597 1.53 msaitoh u_int recovery_mode; 598 1.67 msaitoh callout_t recovery_mode_timer; 599 1.67 msaitoh struct workqueue *recovery_mode_timer_wq; 600 1.67 msaitoh struct work recovery_mode_timer_wc; 601 1.67 msaitoh u_int recovery_mode_timer_pending; 602 1.53 msaitoh 603 1.1 dyoung /* Misc stats maintained by the driver */ 604 1.66 msaitoh struct evcnt efbig_tx_dma_setup; 605 1.66 msaitoh struct evcnt mbuf_defrag_failed; 606 1.66 msaitoh struct evcnt efbig2_tx_dma_setup; 607 1.66 msaitoh struct evcnt einval_tx_dma_setup; 608 1.66 msaitoh struct evcnt other_tx_dma_setup; 609 1.66 msaitoh struct evcnt eagain_tx_dma_setup; 610 1.66 msaitoh struct evcnt enomem_tx_dma_setup; 611 1.66 msaitoh struct evcnt tso_err; 612 1.66 msaitoh struct evcnt watchdog_events; 613 1.67 msaitoh struct evcnt admin_irqev; 614 1.67 msaitoh struct evcnt link_workev; 615 1.67 msaitoh struct evcnt mod_workev; 616 1.67 msaitoh struct evcnt msf_workev; 617 1.67 msaitoh struct evcnt phy_workev; 618 1.1 dyoung 619 1.11 msaitoh union { 620 1.11 msaitoh struct ixgbe_hw_stats pf; 621 1.11 msaitoh struct ixgbevf_hw_stats vf; 622 1.11 msaitoh } stats; 623 1.11 msaitoh #if __FreeBSD_version >= 1100036 624 1.11 msaitoh /* counter(9) stats */ 625 1.11 msaitoh u64 ipackets; 626 1.11 msaitoh u64 ierrors; 627 1.11 msaitoh u64 opackets; 628 1.11 msaitoh u64 oerrors; 629 1.11 msaitoh u64 ibytes; 630 1.11 msaitoh u64 obytes; 631 1.11 msaitoh u64 imcasts; 632 1.11 msaitoh u64 omcasts; 633 1.11 msaitoh u64 iqdrops; 634 1.11 msaitoh u64 noproto; 635 1.11 msaitoh #endif 636 1.26 msaitoh /* Feature capable/enabled flags. See ixgbe_features.h */ 637 1.26 msaitoh u32 feat_cap; 638 1.26 msaitoh u32 feat_en; 639 1.26 msaitoh 640 1.52 msaitoh /* Traffic classes */ 641 1.52 msaitoh struct ixgbe_tc tcs[IXGBE_DCB_MAX_TRAFFIC_CLASS]; 642 1.52 msaitoh 643 1.1 dyoung struct sysctllog *sysctllog; 644 1.19 msaitoh const struct sysctlnode *sysctltop; 645 1.85 msaitoh struct timeval lasterr_time; 646 1.1 dyoung }; 647 1.1 dyoung 648 1.1 dyoung /* Precision Time Sync (IEEE 1588) defines */ 649 1.1 dyoung #define ETHERTYPE_IEEE1588 0x88F7 650 1.1 dyoung #define PICOSECS_PER_TICK 20833 651 1.1 dyoung #define TSYNC_UDP_PORT 319 /* UDP port for the protocol */ 652 1.26 msaitoh #define IXGBE_ADVTXD_TSTAMP 0x00080000 653 1.1 dyoung 654 1.1 dyoung 655 1.1 dyoung #define IXGBE_CORE_LOCK_INIT(_sc, _name) \ 656 1.66 msaitoh mutex_init(&(_sc)->core_mtx, MUTEX_DEFAULT, IPL_SOFTNET) 657 1.1 dyoung #define IXGBE_CORE_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->core_mtx) 658 1.1 dyoung #define IXGBE_TX_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->tx_mtx) 659 1.1 dyoung #define IXGBE_RX_LOCK_DESTROY(_sc) mutex_destroy(&(_sc)->rx_mtx) 660 1.1 dyoung #define IXGBE_CORE_LOCK(_sc) mutex_enter(&(_sc)->core_mtx) 661 1.1 dyoung #define IXGBE_TX_LOCK(_sc) mutex_enter(&(_sc)->tx_mtx) 662 1.1 dyoung #define IXGBE_TX_TRYLOCK(_sc) mutex_tryenter(&(_sc)->tx_mtx) 663 1.1 dyoung #define IXGBE_RX_LOCK(_sc) mutex_enter(&(_sc)->rx_mtx) 664 1.1 dyoung #define IXGBE_CORE_UNLOCK(_sc) mutex_exit(&(_sc)->core_mtx) 665 1.1 dyoung #define IXGBE_TX_UNLOCK(_sc) mutex_exit(&(_sc)->tx_mtx) 666 1.1 dyoung #define IXGBE_RX_UNLOCK(_sc) mutex_exit(&(_sc)->rx_mtx) 667 1.3 msaitoh #define IXGBE_CORE_LOCK_ASSERT(_sc) KASSERT(mutex_owned(&(_sc)->core_mtx)) 668 1.1 dyoung #define IXGBE_TX_LOCK_ASSERT(_sc) KASSERT(mutex_owned(&(_sc)->tx_mtx)) 669 1.1 dyoung 670 1.12 msaitoh /* External PHY register addresses */ 671 1.12 msaitoh #define IXGBE_PHY_CURRENT_TEMP 0xC820 672 1.12 msaitoh #define IXGBE_PHY_OVERTEMP_STATUS 0xC830 673 1.12 msaitoh 674 1.11 msaitoh /* Sysctl help messages; displayed with sysctl -d */ 675 1.11 msaitoh #define IXGBE_SYSCTL_DESC_ADV_SPEED \ 676 1.11 msaitoh "\nControl advertised link speed using these flags:\n" \ 677 1.84 msaitoh "\t0x1 - advertise 100M\n" \ 678 1.84 msaitoh "\t0x2 - advertise 1G\n" \ 679 1.84 msaitoh "\t0x4 - advertise 10G\n" \ 680 1.84 msaitoh "\t0x8 - advertise 10M\n" \ 681 1.55 msaitoh "\t0x10 - advertise 2.5G\n" \ 682 1.55 msaitoh "\t0x20 - advertise 5G\n\n" \ 683 1.55 msaitoh "\t5G, 2.5G, 100M and 10M are only supported on certain adapters." 684 1.11 msaitoh 685 1.11 msaitoh #define IXGBE_SYSCTL_DESC_SET_FC \ 686 1.11 msaitoh "\nSet flow control mode using these values:\n" \ 687 1.11 msaitoh "\t0 - off\n" \ 688 1.11 msaitoh "\t1 - rx pause\n" \ 689 1.11 msaitoh "\t2 - tx pause\n" \ 690 1.11 msaitoh "\t3 - tx and rx pause" 691 1.11 msaitoh 692 1.1 dyoung /* 693 1.26 msaitoh * Find the number of unrefreshed RX descriptors 694 1.26 msaitoh */ 695 1.45 christos static __inline u16 696 1.1 dyoung ixgbe_rx_unrefreshed(struct rx_ring *rxr) 697 1.26 msaitoh { 698 1.1 dyoung if (rxr->next_to_check > rxr->next_to_refresh) 699 1.1 dyoung return (rxr->next_to_check - rxr->next_to_refresh - 1); 700 1.1 dyoung else 701 1.7 msaitoh return ((rxr->num_desc + rxr->next_to_check) - 702 1.1 dyoung rxr->next_to_refresh - 1); 703 1.11 msaitoh } 704 1.11 msaitoh 705 1.45 christos static __inline int 706 1.26 msaitoh ixgbe_legacy_ring_empty(struct ifnet *ifp, pcq_t *dummy) 707 1.13 msaitoh { 708 1.26 msaitoh UNREFERENCED_1PARAMETER(dummy); 709 1.13 msaitoh 710 1.26 msaitoh return IFQ_IS_EMPTY(&ifp->if_snd); 711 1.13 msaitoh } 712 1.13 msaitoh 713 1.45 christos static __inline int 714 1.26 msaitoh ixgbe_mq_ring_empty(struct ifnet *dummy, pcq_t *interq) 715 1.13 msaitoh { 716 1.26 msaitoh UNREFERENCED_1PARAMETER(dummy); 717 1.13 msaitoh 718 1.26 msaitoh return (pcq_peek(interq) == NULL); 719 1.13 msaitoh } 720 1.13 msaitoh 721 1.26 msaitoh /* 722 1.26 msaitoh * This checks for a zero mac addr, something that will be likely 723 1.26 msaitoh * unless the Admin on the Host has created one. 724 1.26 msaitoh */ 725 1.45 christos static __inline bool 726 1.26 msaitoh ixv_check_ether_addr(u8 *addr) 727 1.13 msaitoh { 728 1.26 msaitoh bool status = TRUE; 729 1.13 msaitoh 730 1.26 msaitoh if ((addr[0] == 0 && addr[1]== 0 && addr[2] == 0 && 731 1.26 msaitoh addr[3] == 0 && addr[4]== 0 && addr[5] == 0)) 732 1.26 msaitoh status = FALSE; 733 1.13 msaitoh 734 1.26 msaitoh return (status); 735 1.13 msaitoh } 736 1.13 msaitoh 737 1.53 msaitoh /* 738 1.89 msaitoh * This checks the sc->recovery_mode software flag which is 739 1.53 msaitoh * set by ixgbe_fw_recovery_mode(). 740 1.53 msaitoh * 741 1.53 msaitoh */ 742 1.53 msaitoh static inline bool 743 1.89 msaitoh ixgbe_fw_recovery_mode_swflag(struct ixgbe_softc *sc) 744 1.53 msaitoh { 745 1.89 msaitoh return (sc->feat_en & IXGBE_FEATURE_RECOVERY_MODE) && 746 1.89 msaitoh atomic_load_acq_uint(&sc->recovery_mode); 747 1.53 msaitoh } 748 1.53 msaitoh 749 1.26 msaitoh /* Shared Prototypes */ 750 1.26 msaitoh void ixgbe_legacy_start(struct ifnet *); 751 1.26 msaitoh int ixgbe_legacy_start_locked(struct ifnet *, struct tx_ring *); 752 1.26 msaitoh int ixgbe_mq_start(struct ifnet *, struct mbuf *); 753 1.26 msaitoh int ixgbe_mq_start_locked(struct ifnet *, struct tx_ring *); 754 1.26 msaitoh void ixgbe_deferred_mq_start(void *); 755 1.32 knakahar void ixgbe_deferred_mq_start_work(struct work *, void *); 756 1.89 msaitoh void ixgbe_drain_all(struct ixgbe_softc *); 757 1.26 msaitoh 758 1.89 msaitoh int ixgbe_allocate_queues(struct ixgbe_softc *); 759 1.89 msaitoh void ixgbe_free_queues(struct ixgbe_softc *); 760 1.89 msaitoh int ixgbe_setup_transmit_structures(struct ixgbe_softc *); 761 1.89 msaitoh void ixgbe_free_transmit_structures(struct ixgbe_softc *); 762 1.89 msaitoh int ixgbe_setup_receive_structures(struct ixgbe_softc *); 763 1.89 msaitoh void ixgbe_free_receive_structures(struct ixgbe_softc *); 764 1.30 msaitoh bool ixgbe_txeof(struct tx_ring *); 765 1.26 msaitoh bool ixgbe_rxeof(struct ix_queue *); 766 1.26 msaitoh 767 1.67 msaitoh #define IXGBE_REQUEST_TASK_MOD 0x01 768 1.74 msaitoh #define IXGBE_REQUEST_TASK_MOD_WOI 0x02 769 1.74 msaitoh #define IXGBE_REQUEST_TASK_MSF 0x04 770 1.74 msaitoh #define IXGBE_REQUEST_TASK_MSF_WOI 0x08 771 1.74 msaitoh #define IXGBE_REQUEST_TASK_MBX 0x10 772 1.74 msaitoh #define IXGBE_REQUEST_TASK_FDIR 0x20 773 1.74 msaitoh #define IXGBE_REQUEST_TASK_PHY 0x40 774 1.74 msaitoh #define IXGBE_REQUEST_TASK_LSC 0x80 775 1.28 msaitoh 776 1.46 msaitoh /* For NetBSD */ 777 1.89 msaitoh const struct sysctlnode *ixgbe_sysctl_instance(struct ixgbe_softc *); 778 1.46 msaitoh 779 1.26 msaitoh #include "ixgbe_bypass.h" 780 1.26 msaitoh #include "ixgbe_fdir.h" 781 1.26 msaitoh #include "ixgbe_rss.h" 782 1.26 msaitoh #include "ixgbe_netmap.h" 783 1.13 msaitoh 784 1.1 dyoung #endif /* _IXGBE_H_ */ 785