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