]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ixgb/if_ixgb.h
MFV r329799, r329800:
[FreeBSD/FreeBSD.git] / sys / dev / ixgb / if_ixgb.h
1 /*******************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
3
4 Copyright (c) 2001-2004, Intel Corporation
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10  1. Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12
13  2. Redistributions in binary form must reproduce the above copyright
14     notice, this list of conditions and the following disclaimer in the
15     documentation and/or other materials provided with the distribution.
16
17  3. Neither the name of the Intel Corporation nor the names of its
18     contributors may be used to endorse or promote products derived from
19     this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
32
33 ***************************************************************************/
34 /*$FreeBSD$*/
35
36 #ifndef _IXGB_H_DEFINED_
37 #define _IXGB_H_DEFINED_
38
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/mbuf.h>
43 #include <sys/protosw.h>
44 #include <sys/socket.h>
45 #include <sys/malloc.h>
46 #include <sys/module.h>
47 #include <sys/kernel.h>
48 #include <sys/sockio.h>
49
50 #include <net/if.h>
51 #include <net/if_var.h>
52 #include <net/if_arp.h>
53 #include <net/ethernet.h>
54 #include <net/if_dl.h>
55 #include <net/if_media.h>
56 #include <net/if_types.h>
57
58 #include <net/bpf.h>
59 #include <net/if_types.h>
60 #include <net/if_vlan_var.h>
61
62 #include <netinet/in_systm.h>
63 #include <netinet/in.h>
64 #include <netinet/ip.h>
65 #include <netinet/tcp.h>
66 #include <netinet/udp.h>
67
68 #include <sys/bus.h>
69 #include <machine/bus.h>
70 #include <sys/rman.h>
71 #include <machine/resource.h>
72 #if __FreeBSD_version >= 502000
73 #include <dev/pci/pcivar.h>
74 #include <dev/pci/pcireg.h>
75 #else
76 #include <pci/pcivar.h>
77 #include <pci/pcireg.h>
78 #endif
79 #include <sys/proc.h>
80 #include <sys/sysctl.h>
81 #include <sys/endian.h>
82
83 #include <dev/ixgb/ixgb_hw.h>
84 #include <dev/ixgb/ixgb_ee.h>
85 #include <dev/ixgb/ixgb_ids.h>
86
87 /* Tunables */
88
89 /*
90  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
91  * number of transmit descriptors allocated by the driver. Increasing this
92  * value allows the driver to queue more transmits. Each descriptor is 16
93  * bytes.
94  */
95 #define IXGB_MAX_TXD                      256
96
97 /*
98  * RxDescriptors Valid Range: 64-4096 Default Value: 1024 This value is the
99  * number of receive descriptors allocated by the driver. Increasing this
100  * value allows the driver to buffer more incoming packets. Each descriptor
101  * is 16 bytes.  A receive buffer is also allocated for each descriptor. The
102  * maximum MTU size is 16110.
103  * 
104  */
105 #define IXGB_MAX_RXD                     1024
106
107 /*
108  * TxIntDelay Valid Range: 0-65535 (0=off) Default Value: 32 This value
109  * delays the generation of transmit interrupts in units of 1.024
110  * microseconds. Transmit interrupt reduction can improve CPU efficiency if
111  * properly tuned for specific network traffic. If the system is reporting
112  * dropped transmits, this value may be set too high causing the driver to
113  * run out of available transmit descriptors.
114  */
115 #define TIDV 32
116
117 /*
118  * RxIntDelay Valid Range: 0-65535 (0=off) Default Value: 72 This value
119  * delays the generation of receive interrupts in units of 1.024
120  * microseconds.  Receive interrupt reduction can improve CPU efficiency if
121  * properly tuned for specific network traffic. Increasing this value adds
122  * extra latency to frame reception and can end up decreasing the throughput
123  * of TCP traffic. If the system is reporting dropped receives, this value
124  * may be set too high, causing the driver to run out of available receive
125  * descriptors.
126  * 
127  */
128 #define RDTR 72
129
130
131 /*
132  * This parameter controls the maximum no of times the driver will loop in
133  * the isr. Minimum Value = 1
134  */
135 #define IXGB_MAX_INTR                     3
136
137
138 /*
139  * Inform the stack about transmit checksum offload capabilities.
140  */
141 #define IXGB_CHECKSUM_FEATURES            (CSUM_TCP | CSUM_UDP)
142
143 /*
144  * This parameter controls the duration of transmit watchdog timer.
145  */
146 #define IXGB_TX_TIMEOUT                   5     /* set to 5 seconds */
147
148 /*
149  * This parameter controls when the driver calls the routine to reclaim
150  * transmit descriptors.
151  */
152 #define IXGB_TX_CLEANUP_THRESHOLD         IXGB_MAX_TXD / 8
153
154 /* 
155  * Flow Control Types. 
156  * 1. ixgb_fc_none - Flow Control Disabled 
157  * 2. ixgb_fc_rx_pause - Flow Control Receive Only
158  * 3. ixgb_fc_tx_pause - Flow Control Transmit Only
159  * 4. ixgb_fc_full - Flow Control Enabled
160  */
161 #define FLOW_CONTROL_NONE       ixgb_fc_none 
162 #define FLOW_CONTROL_RX_PAUSE   ixgb_fc_rx_pause
163 #define FLOW_CONTROL_TX_PAUSE   ixgb_fc_tx_pause
164 #define FLOW_CONTROL_FULL       ixgb_fc_full
165
166 /*
167  * Set the flow control type. Assign one of the above flow control types to be enabled.
168  * Default Value: FLOW_CONTROL_FULL   
169  */    
170 #define FLOW_CONTROL            FLOW_CONTROL_FULL
171
172 /*
173  * Receive Flow control low threshold (when we send a resume frame) (FCRTL)
174  * Valid Range: 64 - 262,136 (0x40 - 0x3FFF8, 8 byte granularity) must be
175  * less than high threshold by at least 8 bytes Default Value:  163,840
176  * (0x28000)
177  */
178 #define FCRTL                   0x28000
179
180 /*
181  * Receive Flow control high threshold (when we send a pause frame) (FCRTH)
182  * Valid Range: 1,536 - 262,136 (0x600 - 0x3FFF8, 8 byte granularity) Default
183  * Value: 196,608 (0x30000)
184  */
185 #define FCRTH                   0x30000
186
187 /*
188  * Flow control request timeout (how long to pause the link partner's tx)
189  * (PAP 15:0) Valid Range: 1 - 65535 Default Value:  256 (0x100)
190  */
191 #define FCPAUSE              0x100
192
193 /* Tunables -- End */
194
195
196 #define IXGB_VENDOR_ID                    0x8086
197 #define IXGB_MMBA                         0x0010        /* Mem base address */
198 #define IXGB_ROUNDUP(size, unit) (((size) + (unit) - 1) & ~((unit) - 1))
199
200 #define IOCTL_CMD_TYPE                  u_long
201 #define MAX_NUM_MULTICAST_ADDRESSES     128
202 #define PCI_ANY_ID                      (~0U)
203 #define ETHER_ALIGN                     2
204
205 /* Defines for printing debug information */
206 #define DEBUG_INIT  0
207 #define DEBUG_IOCTL 0
208 #define DEBUG_HW    0
209 #define _SV_        0
210
211 #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
212 #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
213 #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
214 #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
215 #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
216 #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
217 #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
218 #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
219 #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
220
221
222 /* Supported RX Buffer Sizes */
223 #define IXGB_RXBUFFER_2048        2048
224 #define IXGB_RXBUFFER_4096        4096
225 #define IXGB_RXBUFFER_8192        8192
226 #define IXGB_RXBUFFER_16384      16384
227
228 #define IXGB_MAX_SCATTER           100
229
230 /*
231  * ******************************************************************************
232  * vendor_info_array
233  * 
234  * This array contains the list of Subvendor/Subdevice IDs on which the driver
235  * should load.
236  * 
237 *****************************************************************************
238  */
239 typedef struct _ixgb_vendor_info_t {
240         unsigned int    vendor_id;
241         unsigned int    device_id;
242         unsigned int    subvendor_id;
243         unsigned int    subdevice_id;
244         unsigned int    index;
245 }               ixgb_vendor_info_t;
246
247
248 struct ixgb_buffer {
249         struct mbuf    *m_head;
250         bus_dmamap_t    map;    /* bus_dma map for packet */
251 };
252
253 /*
254  * Bus dma allocation structure used by ixgb_dma_malloc and ixgb_dma_free.
255  */
256 struct ixgb_dma_alloc {
257         bus_addr_t      dma_paddr;
258         caddr_t         dma_vaddr;
259         bus_dma_tag_t   dma_tag;
260         bus_dmamap_t    dma_map;
261         bus_dma_segment_t dma_seg;
262         bus_size_t      dma_size;
263         int             dma_nseg;
264 };
265
266 typedef enum _XSUM_CONTEXT_T {
267         OFFLOAD_NONE,
268         OFFLOAD_TCP_IP,
269         OFFLOAD_UDP_IP
270 }               XSUM_CONTEXT_T;
271
272 /* Our adapter structure */
273 struct adapter {
274         struct ifnet   *ifp;
275         struct adapter *next;
276         struct adapter *prev;
277         struct ixgb_hw  hw;
278
279         /* FreeBSD operating-system-specific structures */
280         struct ixgb_osdep osdep;
281         device_t        dev;
282         struct resource *res_memory;
283         struct resource *res_ioport;
284         struct resource *res_interrupt;
285         void           *int_handler_tag;
286         struct ifmedia  media;
287         struct callout  timer;
288         int             io_rid;
289         int             tx_timer;
290         struct mtx      mtx;
291
292         /* Info about the board itself */
293         u_int32_t       part_num;
294         u_int8_t        link_active;
295         u_int16_t       link_speed;
296         u_int16_t       link_duplex;
297         u_int32_t       tx_int_delay;
298         u_int32_t       tx_abs_int_delay;
299         u_int32_t       rx_int_delay;
300         u_int32_t       rx_abs_int_delay;
301
302         int             raidc;
303
304         XSUM_CONTEXT_T  active_checksum_context;
305
306         /*
307          * Transmit definitions
308          * 
309          * We have an array of num_tx_desc descriptors (handled by the
310          * controller) paired with an array of tx_buffers (at
311          * tx_buffer_area). The index of the next available descriptor is
312          * next_avail_tx_desc. The number of remaining tx_desc is
313          * num_tx_desc_avail.
314          */
315         struct ixgb_dma_alloc txdma;    /* bus_dma glue for tx desc */
316         struct ixgb_tx_desc *tx_desc_base;
317         u_int32_t       next_avail_tx_desc;
318         u_int32_t       oldest_used_tx_desc;
319                         volatile u_int16_t num_tx_desc_avail;
320         u_int16_t       num_tx_desc;
321         u_int32_t       txd_cmd;
322         struct ixgb_buffer *tx_buffer_area;
323         bus_dma_tag_t   txtag;  /* dma tag for tx */
324
325         /*
326          * Receive definitions
327          * 
328          * we have an array of num_rx_desc rx_desc (handled by the controller),
329          * and paired with an array of rx_buffers (at rx_buffer_area). The
330          * next pair to check on receive is at offset next_rx_desc_to_check
331          */
332         struct ixgb_dma_alloc rxdma;    /* bus_dma glue for rx desc */
333         struct ixgb_rx_desc *rx_desc_base;
334         u_int32_t       next_rx_desc_to_check;
335         u_int16_t       num_rx_desc;
336         u_int32_t       rx_buffer_len;
337         struct ixgb_buffer *rx_buffer_area;
338         bus_dma_tag_t   rxtag;  /* dma tag for Rx */
339         u_int32_t       next_rx_desc_to_use;
340
341
342         /* Jumbo frame */
343         struct mbuf    *fmp;
344         struct mbuf    *lmp;
345
346         struct sysctl_ctx_list sysctl_ctx;
347         struct sysctl_oid *sysctl_tree;
348
349         /* Multicast array memory */
350         u_int8_t        *mta;
351         /* Misc stats maintained by the driver */
352         unsigned long   dropped_pkts;
353         unsigned long   mbuf_alloc_failed;
354         unsigned long   mbuf_cluster_failed;
355         unsigned long   no_tx_desc_avail1;
356         unsigned long   no_tx_desc_avail2;
357         unsigned long   no_tx_map_avail;
358         unsigned long   no_tx_dma_setup;
359
360         boolean_t       in_detach;
361
362         /* Board specific private data */
363 #ifdef _SV_
364         struct ixgb_sv_stats {
365                 uint64_t        icr_rxdmt0;
366                 uint64_t        icr_rxo;
367                 uint64_t        icr_rxt0;
368                 uint64_t        icr_TXDW;
369         }               sv_stats;
370         unsigned long   no_pkts_avail;
371         unsigned long   clean_tx_interrupts;
372 #endif
373
374         struct ixgb_hw_stats stats;
375 };
376
377 #define IXGB_LOCK_INIT(_sc, _name) \
378         mtx_init(&(_sc)->mtx, _name, MTX_NETWORK_LOCK, MTX_DEF)
379 #define IXGB_LOCK_DESTROY(_sc)  mtx_destroy(&(_sc)->mtx)
380 #define IXGB_LOCK(_sc)          mtx_lock(&(_sc)->mtx)
381 #define IXGB_UNLOCK(_sc)        mtx_unlock(&(_sc)->mtx)
382 #define IXGB_LOCK_ASSERT(_sc)   mtx_assert(&(_sc)->mtx, MA_OWNED)
383
384 #endif                          /* _IXGB_H_DEFINED_ */