1 1.3 rin /* $NetBSD: if_igc.h,v 1.3 2024/06/27 07:31:41 rin Exp $ */ 2 1.1 rin /* $OpenBSD: if_igc.h,v 1.2 2022/01/09 05:42:50 jsg Exp $ */ 3 1.1 rin /*- 4 1.1 rin * SPDX-License-Identifier: BSD-2-Clause 5 1.1 rin * 6 1.1 rin * Copyright (c) 2016 Nicole Graziano <nicole (at) nextbsd.org> 7 1.1 rin * All rights reserved. 8 1.1 rin * Copyright (c) 2021 Rubicon Communications, LLC (Netgate) 9 1.1 rin * 10 1.1 rin * Redistribution and use in source and binary forms, with or without 11 1.1 rin * modification, are permitted provided that the following conditions 12 1.1 rin * are met: 13 1.1 rin * 1. Redistributions of source code must retain the above copyright 14 1.1 rin * notice, this list of conditions and the following disclaimer. 15 1.1 rin * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 rin * notice, this list of conditions and the following disclaimer in the 17 1.1 rin * documentation and/or other materials provided with the distribution. 18 1.1 rin * 19 1.1 rin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 1.1 rin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.1 rin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.1 rin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 1.1 rin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.1 rin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.1 rin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.1 rin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.1 rin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 rin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 rin * SUCH DAMAGE. 30 1.1 rin * 31 1.1 rin * $FreeBSD$ 32 1.1 rin */ 33 1.1 rin 34 1.1 rin #ifndef _IGC_H_ 35 1.1 rin #define _IGC_H_ 36 1.1 rin 37 1.2 rin #ifdef _KERNEL_OPT 38 1.2 rin #include "opt_if_igc.h" 39 1.2 rin #endif 40 1.2 rin 41 1.2 rin #include <sys/types.h> 42 1.3 rin #include <sys/atomic.h> 43 1.2 rin #include <sys/pcq.h> 44 1.2 rin #include <sys/workqueue.h> 45 1.2 rin 46 1.2 rin #include <dev/pci/igc/igc_api.h> 47 1.2 rin #include <dev/pci/igc/igc_i225.h> 48 1.2 rin 49 1.3 rin #ifdef __HAVE_ATOMIC64_LOADSTORE 50 1.2 rin #define IGC_EVENT_COUNTERS 51 1.2 rin #endif 52 1.1 rin 53 1.1 rin /* 54 1.1 rin * IGC_MAX_TXD: Maximum number of Transmit Descriptors 55 1.1 rin * Valid Range: 128-4096 56 1.1 rin * Default Value: 1024 57 1.1 rin * This value is the number of transmit descriptors allocated by the driver. 58 1.1 rin * Increasing this value allows the driver to queue more transmits. Each 59 1.1 rin * descriptor is 16 bytes. 60 1.1 rin * Since TDLEN should be multiple of 128bytes, the number of transmit 61 1.1 rin * descriptors should meet the following condition. 62 1.1 rin * (num_tx_desc * sizeof(struct igc_tx_desc)) % 128 == 0 63 1.1 rin */ 64 1.1 rin #define IGC_MIN_TXD 128 65 1.1 rin #define IGC_MAX_TXD 4096 66 1.1 rin #define IGC_DEFAULT_TXD 1024 67 1.1 rin #define IGC_DEFAULT_MULTI_TXD 4096 68 1.1 rin #define IGC_MAX_TXD 4096 69 1.1 rin 70 1.1 rin /* 71 1.1 rin * IGC_MAX_RXD - Maximum number of receive Descriptors 72 1.1 rin * Valid Range: 128-4096 73 1.1 rin * Default Value: 1024 74 1.1 rin * This value is the number of receive descriptors allocated by the driver. 75 1.1 rin * Increasing this value allows the driver to buffer more incoming packets. 76 1.1 rin * Each descriptor is 16 bytes. A receive buffer is also allocated for each 77 1.1 rin * descriptor. The maximum MTU size is 16110. 78 1.1 rin * Since TDLEN should be multiple of 128bytes, the number of transmit 79 1.1 rin * descriptors should meet the following condition. 80 1.1 rin * (num_tx_desc * sizeof(struct igc_tx_desc)) % 128 == 0 81 1.1 rin */ 82 1.1 rin #define IGC_MIN_RXD 128 83 1.1 rin #define IGC_MAX_RXD 4096 84 1.1 rin #define IGC_DEFAULT_RXD 1024 85 1.1 rin #define IGC_DEFAULT_MULTI_RXD 4096 86 1.1 rin #define IGC_MAX_RXD 4096 87 1.1 rin 88 1.1 rin /* 89 1.1 rin * IGC_TIDV_VAL - Transmit Interrupt Delay Value 90 1.1 rin * Valid Range: 0-65535 (0=off) 91 1.1 rin * Default Value: 64 92 1.1 rin * This value delays the generation of transmit interrupts in units of 93 1.1 rin * 1.024 microseconds. Transmit interrupt reduction can improve CPU 94 1.1 rin * efficiency if properly tuned for specific network traffic. If the 95 1.1 rin * system is reporting dropped transmits, this value may be set too high 96 1.1 rin * causing the driver to run out of available transmit descriptors. 97 1.1 rin */ 98 1.1 rin #define IGC_TIDV_VAL 64 99 1.1 rin 100 1.1 rin /* 101 1.1 rin * IGC_TADV_VAL - Transmit Absolute Interrupt Delay Value 102 1.1 rin * Valid Range: 0-65535 (0=off) 103 1.1 rin * Default Value: 64 104 1.1 rin * This value, in units of 1.024 microseconds, limits the delay in which a 105 1.1 rin * transmit interrupt is generated. Useful only if IGC_TIDV is non-zero, 106 1.1 rin * this value ensures that an interrupt is generated after the initial 107 1.1 rin * packet is sent on the wire within the set amount of time. Proper tuning, 108 1.1 rin * along with IGC_TIDV_VAL, may improve traffic throughput in specific 109 1.1 rin * network conditions. 110 1.1 rin */ 111 1.1 rin #define IGC_TADV_VAL 64 112 1.1 rin 113 1.1 rin /* 114 1.1 rin * IGC_RDTR_VAL - Receive Interrupt Delay Timer (Packet Timer) 115 1.1 rin * Valid Range: 0-65535 (0=off) 116 1.1 rin * Default Value: 0 117 1.1 rin * This value delays the generation of receive interrupts in units of 1.024 118 1.1 rin * microseconds. Receive interrupt reduction can improve CPU efficiency if 119 1.1 rin * properly tuned for specific network traffic. Increasing this value adds 120 1.1 rin * extra latency to frame reception and can end up decreasing the throughput 121 1.1 rin * of TCP traffic. If the system is reporting dropped receives, this value 122 1.1 rin * may be set too high, causing the driver to run out of available receive 123 1.1 rin * descriptors. 124 1.1 rin * 125 1.1 rin * CAUTION: When setting IGC_RDTR to a value other than 0, adapters 126 1.1 rin * may hang (stop transmitting) under certain network conditions. 127 1.1 rin * If this occurs a WATCHDOG message is logged in the system 128 1.1 rin * event log. In addition, the controller is automatically reset, 129 1.1 rin * restoring the network connection. To eliminate the potential 130 1.1 rin * for the hang ensure that IGC_RDTR is set to 0. 131 1.1 rin */ 132 1.1 rin #define IGC_RDTR_VAL 0 133 1.1 rin 134 1.1 rin /* 135 1.1 rin * Receive Interrupt Absolute Delay Timer 136 1.1 rin * Valid Range: 0-65535 (0=off) 137 1.1 rin * Default Value: 64 138 1.1 rin * This value, in units of 1.024 microseconds, limits the delay in which a 139 1.1 rin * receive interrupt is generated. Useful only if IGC_RDTR is non-zero, 140 1.1 rin * this value ensures that an interrupt is generated after the initial 141 1.1 rin * packet is received within the set amount of time. Proper tuning, 142 1.1 rin * along with IGC_RDTR, may improve traffic throughput in specific network 143 1.1 rin * conditions. 144 1.1 rin */ 145 1.1 rin #define IGC_RADV_VAL 64 146 1.1 rin 147 1.1 rin /* 148 1.1 rin * This parameter controls whether or not autonegotiation is enabled. 149 1.1 rin * 0 - Disable autonegotiation 150 1.1 rin * 1 - Enable autonegotiation 151 1.1 rin */ 152 1.1 rin #define DO_AUTO_NEG true 153 1.1 rin 154 1.1 rin #define AUTONEG_ADV_DEFAULT \ 155 1.1 rin (ADVERTISE_10_HALF | ADVERTISE_10_FULL | ADVERTISE_100_HALF | \ 156 1.1 rin ADVERTISE_100_FULL | ADVERTISE_1000_FULL | ADVERTISE_2500_FULL) 157 1.1 rin 158 1.1 rin #define AUTO_ALL_MODES 0 159 1.1 rin 160 1.1 rin /* 161 1.1 rin * Miscellaneous constants 162 1.1 rin */ 163 1.1 rin #define MAX_NUM_MULTICAST_ADDRESSES 128 164 1.1 rin #define IGC_FC_PAUSE_TIME 0x0680 165 1.1 rin 166 1.1 rin #define IGC_TXPBSIZE 20408 167 1.1 rin #define IGC_PKTTYPE_MASK 0x0000FFF0 168 1.1 rin #define IGC_DMCTLX_DCFLUSH_DIS 0x80000000 /* Disable DMA Coalesce Flush */ 169 1.1 rin 170 1.1 rin #define IGC_RX_PTHRESH 8 171 1.1 rin #define IGC_RX_HTHRESH 8 172 1.1 rin #define IGC_RX_WTHRESH 4 173 1.1 rin 174 1.1 rin #define IGC_TX_PTHRESH 8 175 1.1 rin #define IGC_TX_HTHRESH 1 176 1.1 rin 177 1.1 rin /* 178 1.1 rin * TDBA/RDBA should be aligned on 16 byte boundary. But TDLEN/RDLEN should be 179 1.1 rin * multiple of 128 bytes. So we align TDBA/RDBA on 128 byte boundary. This will 180 1.1 rin * also optimize cache line size effect. H/W supports up to cache line size 128. 181 1.1 rin */ 182 1.1 rin #define IGC_DBA_ALIGN 128 183 1.1 rin 184 1.1 rin /* 185 1.1 rin * This parameter controls the duration of transmit watchdog timer. 186 1.1 rin */ 187 1.1 rin #define IGC_TX_TIMEOUT 5 /* set to 5 seconds */ 188 1.1 rin 189 1.1 rin #define IGC_PCIREG PCI_MAPREG_START 190 1.1 rin 191 1.1 rin #define IGC_MAX_VECTORS 8 192 1.1 rin 193 1.1 rin /* Enable/disable debugging statements in shared code */ 194 1.1 rin #define DBG 0 195 1.1 rin 196 1.1 rin #define DEBUGOUT(...) \ 197 1.1 rin do { if (DBG) printf(__VA_ARGS__); } while (0) 198 1.1 rin #define DEBUGOUT1(...) DEBUGOUT(__VA_ARGS__) 199 1.1 rin #define DEBUGOUT2(...) DEBUGOUT(__VA_ARGS__) 200 1.1 rin #define DEBUGOUT3(...) DEBUGOUT(__VA_ARGS__) 201 1.1 rin #define DEBUGOUT7(...) DEBUGOUT(__VA_ARGS__) 202 1.1 rin #define DEBUGFUNC(F) DEBUGOUT(F "\n") 203 1.1 rin 204 1.1 rin /* Compatibility glue. */ 205 1.1 rin #define msec_delay(x) DELAY(1000 * (x)) 206 1.1 rin 207 1.1 rin #define IGC_MAX_SCATTER 40 208 1.1 rin #define IGC_TSO_SIZE 65535 209 1.1 rin 210 1.1 rin #define MAX_INTS_PER_SEC 8000 211 1.1 rin #define DEFAULT_ITR (1000000000/(MAX_INTS_PER_SEC * 256)) 212 1.1 rin 213 1.2 rin #define IGC_MAX_INTRS (IGC_MAX_NQUEUES + 1) 214 1.2 rin 215 1.1 rin /* Forward declaration. */ 216 1.1 rin struct igc_hw; 217 1.1 rin 218 1.1 rin struct igc_osdep { 219 1.1 rin bus_dma_tag_t os_dmat; 220 1.1 rin bus_space_tag_t os_memt; 221 1.1 rin bus_space_handle_t os_memh; 222 1.1 rin 223 1.1 rin bus_size_t os_memsize; 224 1.1 rin bus_addr_t os_membase; 225 1.1 rin 226 1.1 rin void *os_sc; 227 1.1 rin struct pci_attach_args os_pa; 228 1.1 rin }; 229 1.1 rin 230 1.1 rin 231 1.1 rin struct igc_tx_buf { 232 1.1 rin uint32_t eop_index; 233 1.1 rin struct mbuf *m_head; 234 1.1 rin bus_dmamap_t map; 235 1.1 rin }; 236 1.1 rin 237 1.1 rin struct igc_rx_buf { 238 1.1 rin struct mbuf *buf; 239 1.1 rin struct mbuf *fmp; /* First mbuf pointers. */ 240 1.1 rin bus_dmamap_t map; 241 1.1 rin }; 242 1.1 rin 243 1.1 rin /* 244 1.1 rin * Bus dma allocation structure used by igc_dma_malloc and igc_dma_free. 245 1.1 rin */ 246 1.1 rin struct igc_dma_alloc { 247 1.2 rin void *dma_vaddr; 248 1.1 rin bus_dma_tag_t dma_tag; 249 1.1 rin bus_dmamap_t dma_map; 250 1.1 rin bus_dma_segment_t dma_seg; 251 1.1 rin bus_size_t dma_size; 252 1.1 rin int dma_nseg; 253 1.1 rin }; 254 1.1 rin 255 1.1 rin /* 256 1.1 rin * Driver queue struct: this is the interrupt container 257 1.1 rin * for the associated tx and rx ring. 258 1.1 rin */ 259 1.1 rin struct igc_queue { 260 1.1 rin struct igc_softc *sc; 261 1.1 rin uint32_t msix; 262 1.1 rin uint32_t eims; 263 1.1 rin uint32_t eitr_setting; 264 1.1 rin pci_intr_handle_t ih; 265 1.1 rin void *tag; 266 1.1 rin struct tx_ring *txr; 267 1.1 rin struct rx_ring *rxr; 268 1.2 rin 269 1.2 rin void *igcq_si; 270 1.2 rin bool igcq_workqueue; 271 1.2 rin struct work igcq_wq_cookie; 272 1.2 rin 273 1.2 rin #ifdef IGC_EVENT_COUNTERS 274 1.2 rin uint64_t *igcq_driver_counters; 275 1.2 rin 276 1.2 rin struct evcnt *igcq_queue_evcnts; 277 1.2 rin char igcq_queue_evname[EVCNT_STRING_MAX]; 278 1.2 rin #endif 279 1.1 rin }; 280 1.1 rin 281 1.1 rin /* 282 1.1 rin * The transmit ring, one per tx queue. 283 1.1 rin */ 284 1.1 rin struct tx_ring { 285 1.1 rin struct igc_softc *sc; 286 1.1 rin struct ifqueue *ifq; 287 1.1 rin uint32_t me; 288 1.1 rin uint32_t watchdog_timer; 289 1.1 rin union igc_adv_tx_desc *tx_base; 290 1.1 rin struct igc_tx_buf *tx_buffers; 291 1.1 rin struct igc_dma_alloc txdma; 292 1.1 rin uint32_t next_avail_desc; 293 1.1 rin uint32_t next_to_clean; 294 1.1 rin bus_dma_tag_t txtag; 295 1.2 rin 296 1.2 rin pcq_t *txr_interq; 297 1.2 rin 298 1.2 rin kmutex_t txr_lock; 299 1.2 rin 300 1.2 rin struct igc_queue *txr_igcq; 301 1.1 rin }; 302 1.1 rin 303 1.1 rin /* 304 1.1 rin * The Receive ring, one per rx queue. 305 1.1 rin */ 306 1.1 rin struct rx_ring { 307 1.1 rin struct igc_softc *sc; 308 1.1 rin uint32_t me; 309 1.1 rin union igc_adv_rx_desc *rx_base; 310 1.1 rin struct igc_rx_buf *rx_buffers; 311 1.1 rin struct igc_dma_alloc rxdma; 312 1.1 rin uint32_t last_desc_filled; 313 1.1 rin uint32_t next_to_check; 314 1.2 rin #if IF_RXR 315 1.1 rin struct if_rxring rx_ring; 316 1.2 rin #endif 317 1.2 rin 318 1.2 rin kmutex_t rxr_lock; 319 1.2 rin 320 1.2 rin struct igc_queue *rxr_igcq; 321 1.1 rin }; 322 1.1 rin 323 1.1 rin /* Our adapter structure. */ 324 1.1 rin struct igc_softc { 325 1.2 rin device_t sc_dev; 326 1.2 rin struct ethercom sc_ec; 327 1.1 rin struct ifmedia media; 328 1.2 rin #if 1 329 1.2 rin pci_intr_type_t sc_intr_type; 330 1.2 rin int sc_nintrs; 331 1.2 rin pci_intr_handle_t *sc_intrs; 332 1.2 rin void *sc_ihs[IGC_MAX_INTRS]; 333 1.2 rin #else 334 1.1 rin struct intrmap *sc_intrmap; 335 1.2 rin #endif 336 1.1 rin 337 1.1 rin struct igc_osdep osdep; 338 1.1 rin struct igc_hw hw; 339 1.1 rin 340 1.2 rin uint16_t sc_if_flags; 341 1.1 rin uint16_t fc; 342 1.1 rin uint16_t link_active; 343 1.1 rin uint16_t link_speed; 344 1.1 rin uint16_t link_duplex; 345 1.1 rin uint32_t dmac; 346 1.1 rin 347 1.1 rin int num_tx_desc; 348 1.1 rin int num_rx_desc; 349 1.1 rin 350 1.1 rin uint32_t max_frame_size; 351 1.1 rin uint32_t rx_mbuf_sz; 352 1.1 rin uint32_t linkvec; 353 1.1 rin uint32_t msix_linkmask; 354 1.1 rin uint32_t msix_queuesmask; 355 1.1 rin 356 1.2 rin struct if_percpuq *sc_ipq; 357 1.1 rin unsigned int sc_nqueues; 358 1.1 rin struct igc_queue *queues; 359 1.2 rin bool sc_txrx_workqueue; 360 1.2 rin struct workqueue *sc_queue_wq; 361 1.2 rin 362 1.2 rin u_int sc_rx_intr_process_limit; 363 1.2 rin u_int sc_tx_intr_process_limit; 364 1.2 rin u_int sc_rx_process_limit; 365 1.2 rin u_int sc_tx_process_limit; 366 1.1 rin 367 1.1 rin struct tx_ring *tx_rings; 368 1.1 rin struct rx_ring *rx_rings; 369 1.1 rin 370 1.1 rin /* Multicast array memory */ 371 1.2 rin #define IGC_MTA_LEN (ETHER_ADDR_LEN * MAX_NUM_MULTICAST_ADDRESSES) 372 1.1 rin uint8_t *mta; 373 1.2 rin 374 1.2 rin kmutex_t sc_core_lock; 375 1.2 rin 376 1.2 rin callout_t sc_tick_ch; 377 1.2 rin bool sc_core_stopping; 378 1.2 rin 379 1.2 rin #ifdef IGC_EVENT_COUNTERS 380 1.2 rin struct evcnt *sc_global_evcnts; 381 1.2 rin 382 1.2 rin struct evcnt *sc_driver_evcnts; 383 1.2 rin 384 1.2 rin struct evcnt *sc_mac_evcnts; 385 1.2 rin char sc_mac_evname[EVCNT_STRING_MAX]; 386 1.2 rin #endif 387 1.1 rin }; 388 1.1 rin 389 1.1 rin #define DEVNAME(_sc) ((_sc)->sc_dev.dv_xname) 390 1.1 rin 391 1.1 rin /* Register READ/WRITE macros */ 392 1.1 rin #define IGC_WRITE_FLUSH(a) IGC_READ_REG(a, IGC_STATUS) 393 1.1 rin #define IGC_READ_REG(a, reg) \ 394 1.1 rin bus_space_read_4(((struct igc_osdep *)(a)->back)->os_memt, \ 395 1.1 rin ((struct igc_osdep *)(a)->back)->os_memh, reg) 396 1.1 rin #define IGC_WRITE_REG(a, reg, value) \ 397 1.1 rin bus_space_write_4(((struct igc_osdep *)(a)->back)->os_memt, \ 398 1.1 rin ((struct igc_osdep *)(a)->back)->os_memh, reg, value) 399 1.1 rin #define IGC_READ_REG_ARRAY(a, reg, off) \ 400 1.1 rin bus_space_read_4(((struct igc_osdep *)(a)->back)->os_memt, \ 401 1.1 rin ((struct igc_osdep *)(a)->back)->os_memh, (reg + ((off) << 2))) 402 1.1 rin #define IGC_WRITE_REG_ARRAY(a, reg, off, value) \ 403 1.1 rin bus_space_write_4(((struct igc_osdep *)(a)->back)->os_memt, \ 404 1.1 rin ((struct igc_osdep *)(a)->back)->os_memh, \ 405 1.1 rin (reg + ((off) << 2)),value) 406 1.1 rin 407 1.1 rin #endif /* _IGC_H_ */ 408