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