ixgbe.h revision 172043
1/**************************************************************************
2
3Copyright (c) 2001-2007, Intel Corporation
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10    this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31
32***************************************************************************/
33/* $FreeBSD: head/sys/dev/ixgbe/ixgbe.h 172043 2007-09-04 02:31:35Z jfv $ */
34
35#ifndef _IXGBE_H_
36#define _IXGBE_H_
37
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/mbuf.h>
42#include <sys/protosw.h>
43#include <sys/socket.h>
44#include <sys/malloc.h>
45#include <sys/kernel.h>
46#include <sys/module.h>
47#include <sys/sockio.h>
48
49#include <net/if.h>
50#include <net/if_arp.h>
51#include <net/bpf.h>
52#include <net/ethernet.h>
53#include <net/if_dl.h>
54#include <net/if_media.h>
55
56#include <net/bpf.h>
57#include <net/if_types.h>
58#include <net/if_vlan_var.h>
59
60#include <netinet/in_systm.h>
61#include <netinet/in.h>
62#include <netinet/if_ether.h>
63#include <netinet/ip.h>
64#include <netinet/ip6.h>
65#include <netinet/tcp.h>
66#include <netinet/udp.h>
67
68#include <machine/in_cksum.h>
69
70#include <sys/bus.h>
71#include <machine/bus.h>
72#include <sys/rman.h>
73#include <machine/resource.h>
74#include <vm/vm.h>
75#include <vm/pmap.h>
76#include <machine/clock.h>
77#include <dev/pci/pcivar.h>
78#include <dev/pci/pcireg.h>
79#include <sys/proc.h>
80#include <sys/sysctl.h>
81#include <sys/endian.h>
82#include <sys/taskqueue.h>
83
84#include "ixgbe_api.h"
85
86/* Tunables */
87
88/*
89 * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
90 * number of transmit descriptors allocated by the driver. Increasing this
91 * value allows the driver to queue more transmits. Each descriptor is 16
92 * bytes. Performance tests have show the 2K value to be optimal for top
93 * performance.
94 */
95#define DEFAULT_TXD	256
96#define PERFORM_TXD	2048
97#define MAX_TXD		4096
98#define MIN_TXD		64
99
100/*
101 * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
102 * number of receive descriptors allocated for each RX queue. Increasing this
103 * value allows the driver to buffer more incoming packets. Each descriptor
104 * is 16 bytes.  A receive buffer is also allocated for each descriptor.
105 *
106 * Note: with 8 rings and a dual port card, it is possible to bump up
107 *	against the system mbuf pool limit, you can tune nmbclusters
108 *	to adjust for this.
109 */
110#define DEFAULT_RXD	256
111#define PERFORM_RXD	2048
112#define MAX_RXD		4096
113#define MIN_RXD		64
114
115/* Alignment for rings */
116#define DBA_ALIGN	128
117
118/*
119 * This parameter controls the maximum no of times the driver will loop in
120 * the isr. Minimum Value = 1
121 */
122#define MAX_INTR	10
123
124/*
125 * This parameter controls the duration of transmit watchdog timer.
126 */
127#define IXGBE_TX_TIMEOUT                   5	/* set to 5 seconds */
128
129/*
130 * This parameters control when the driver calls the routine to reclaim
131 * transmit descriptors.
132 */
133#define IXGBE_TX_CLEANUP_THRESHOLD	(adapter->num_tx_desc / 8)
134#define IXGBE_TX_OP_THRESHOLD		(adapter->num_tx_desc / 32)
135
136#define IXGBE_MAX_FRAME_SIZE	0x3F00
137
138/* Flow control constants */
139#define IXGBE_FC_PAUSE		0x680
140#define IXGBE_FC_HI		0x20000
141#define IXGBE_FC_LO		0x10000
142
143/* Defines for printing debug information */
144#define DEBUG_INIT  0
145#define DEBUG_IOCTL 0
146#define DEBUG_HW    0
147
148#define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
149#define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
150#define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
151#define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
152#define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
153#define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
154#define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
155#define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
156#define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
157
158#define MAX_NUM_MULTICAST_ADDRESSES     128
159#define IXGBE_MAX_SCATTER		100
160#define	IXGBE_MMBA			0x0010
161#define IXGBE_TSO_SIZE			65535
162#define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
163#define IXGBE_RX_HDR_SIZE		((u32) 256)
164#define CSUM_OFFLOAD			7	/* Bits in csum flags */
165
166/* The number of MSIX messages the 82598 supports */
167#define IXGBE_MSGS			18
168
169/* For 6.X code compatibility */
170#if __FreeBSD_version < 700000
171#define ETHER_BPF_MTAP		BPF_MTAP
172#define CSUM_TSO		0
173#define IFCAP_TSO4		0
174#define FILTER_STRAY
175#define FILTER_HANDLED
176#endif
177
178/*
179 * Interrupt Moderation parameters
180 * 	for now we hardcode, later
181 *	it would be nice to do dynamic
182 */
183#define MAX_IRQ_SEC	8000
184#define DEFAULT_ITR	1000000000/(MAX_IRQ_SEC * 256)
185#define LINK_ITR	1000000000/(1950 * 256)
186
187/*
188 * ******************************************************************************
189 * vendor_info_array
190 *
191 * This array contains the list of Subvendor/Subdevice IDs on which the driver
192 * should load.
193 *
194*****************************************************************************
195 */
196typedef struct _ixgbe_vendor_info_t {
197	unsigned int    vendor_id;
198	unsigned int    device_id;
199	unsigned int    subvendor_id;
200	unsigned int    subdevice_id;
201	unsigned int    index;
202}               ixgbe_vendor_info_t;
203
204
205struct ixgbe_tx_buf {
206	int		next_eop;
207	struct mbuf	*m_head;
208	bus_dmamap_t	map;
209};
210
211struct ixgbe_rx_buf {
212	struct mbuf	*m_head;
213	boolean_t	bigbuf;
214	/* one small and one large map */
215	bus_dmamap_t	map[2];
216};
217
218/*
219 * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
220 */
221struct ixgbe_dma_alloc {
222	bus_addr_t		dma_paddr;
223	caddr_t			dma_vaddr;
224	bus_dma_tag_t		dma_tag;
225	bus_dmamap_t		dma_map;
226	bus_dma_segment_t	dma_seg;
227	bus_size_t		dma_size;
228	int			dma_nseg;
229};
230
231/*
232 * The transmit ring, one per tx queue
233 */
234struct tx_ring {
235        struct adapter		*adapter;
236	u32			me;
237	union ixgbe_adv_tx_desc	*tx_base;
238	struct ixgbe_dma_alloc	txdma;
239	uint32_t		next_avail_tx_desc;
240	uint32_t		next_tx_to_clean;
241	struct ixgbe_tx_buf	*tx_buffers;
242	volatile uint16_t	tx_avail;
243	uint32_t		txd_cmd;
244	bus_dma_tag_t		txtag;
245};
246
247
248/*
249 * The Receive ring, one per rx queue
250 */
251struct rx_ring {
252        struct adapter			*adapter;
253	u32				me;
254	u32				payload;
255	union 	ixgbe_adv_rx_desc	*rx_base;
256	struct ixgbe_dma_alloc		rxdma;
257        unsigned int			last_cleaned;
258        unsigned int			next_to_check;
259	struct ixgbe_rx_buf		*rx_buffers;
260	bus_dma_tag_t			rxtag[2];
261	bus_dmamap_t			spare_map[2];
262	struct mbuf			*fmp;
263	struct mbuf			*lmp;
264	/* Soft stats */
265	u64				packet_count;
266	u64 				byte_count;
267};
268
269/* Our adapter structure */
270struct adapter {
271	struct ifnet	*ifp;
272	struct ixgbe_hw	hw;
273
274	/* FreeBSD operating-system-specific structures */
275	struct ixgbe_osdep	osdep;
276
277	struct device	*dev;
278	struct resource	*res_memory;
279	struct resource	*res_msix;
280
281	/*
282	 * Interrupt resources:
283	 *  Oplin has 20 MSIX messages
284	 *  so allocate that for now.
285	 */
286	void		*tag[IXGBE_MSGS];
287	struct resource *res[IXGBE_MSGS];
288	int		rid[IXGBE_MSGS];
289
290	struct ifmedia	media;
291	struct callout	timer;
292	int		watchdog_timer;
293	int		msix;
294	int		if_flags;
295	struct mtx	core_mtx;
296	struct mtx	tx_mtx;
297	/* Legacy Fast Intr handling */
298	struct task     link_task;
299	struct task     rxtx_task;
300	struct taskqueue *tq;
301
302	/* Info about the board itself */
303	uint32_t       part_num;
304	boolean_t      link_active;
305	uint16_t       max_frame_size;
306	uint16_t       link_duplex;
307	uint32_t       tx_int_delay;
308	uint32_t       tx_abs_int_delay;
309	uint32_t       rx_int_delay;
310	uint32_t       rx_abs_int_delay;
311
312	/* Indicates the cluster size to use */
313	boolean_t	bigbufs;
314
315	/*
316	 * Transmit rings:
317	 *	Allocated at run time, an array of rings.
318	 */
319	struct tx_ring	*tx_rings;
320	int		num_tx_desc;
321	int		num_tx_queues;
322
323	/*
324	 * Receive rings:
325	 *	Allocated at run time, an array of rings.
326	 */
327	struct rx_ring	*rx_rings;
328	int		num_rx_desc;
329	int		num_rx_queues;
330	uint32_t	rx_process_limit;
331
332	/* Misc stats maintained by the driver */
333	unsigned long   dropped_pkts;
334	unsigned long   mbuf_alloc_failed;
335	unsigned long   mbuf_cluster_failed;
336	unsigned long   no_tx_desc_avail1;
337	unsigned long   no_tx_desc_avail2;
338	unsigned long   no_tx_map_avail;
339	unsigned long   no_tx_dma_setup;
340	unsigned long   watchdog_events;
341	unsigned long   tso_tx;
342
343	struct ixgbe_hw_stats stats;
344};
345
346#endif /* _IXGBE_H_ */
347