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