ixgbe.h revision 179055
1193323Sed/******************************************************************************
2193323Sed
3193323Sed  Copyright (c) 2001-2008, Intel Corporation
4193323Sed  All rights reserved.
5193323Sed
6193323Sed  Redistribution and use in source and binary forms, with or without
7193323Sed  modification, are permitted provided that the following conditions are met:
8193323Sed
9193323Sed   1. Redistributions of source code must retain the above copyright notice,
10193323Sed      this list of conditions and the following disclaimer.
11193323Sed
12193323Sed   2. Redistributions in binary form must reproduce the above copyright
13193323Sed      notice, this list of conditions and the following disclaimer in the
14193323Sed      documentation and/or other materials provided with the distribution.
15193323Sed
16193323Sed   3. Neither the name of the Intel Corporation nor the names of its
17193323Sed      contributors may be used to endorse or promote products derived from
18193323Sed      this software without specific prior written permission.
19218893Sdim
20199481Srdivacky  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21193323Sed  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22193323Sed  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23193323Sed  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24193323Sed  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25234353Sdim  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26198090Srdivacky  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27193323Sed  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28218893Sdim  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29218893Sdim  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30218893Sdim  POSSIBILITY OF SUCH DAMAGE.
31218893Sdim
32218893Sdim******************************************************************************/
33218893Sdim/*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 179055 2008-05-16 18:46:30Z jfv $*/
34218893Sdim
35218893Sdim#ifndef _IXGBE_H_
36218893Sdim#define _IXGBE_H_
37251662Sdim
38218893Sdim
39218893Sdim#include <sys/param.h>
40251662Sdim#include <sys/systm.h>
41218893Sdim#include <sys/mbuf.h>
42218893Sdim#include <sys/protosw.h>
43251662Sdim#include <sys/socket.h>
44218893Sdim#include <sys/malloc.h>
45218893Sdim#include <sys/kernel.h>
46218893Sdim#include <sys/module.h>
47218893Sdim#include <sys/sockio.h>
48251662Sdim
49218893Sdim#include <net/if.h>
50218893Sdim#include <net/if_arp.h>
51218893Sdim#include <net/bpf.h>
52251662Sdim#include <net/ethernet.h>
53218893Sdim#include <net/if_dl.h>
54218893Sdim#include <net/if_media.h>
55218893Sdim
56218893Sdim#include <net/bpf.h>
57218893Sdim#include <net/if_types.h>
58218893Sdim#include <net/if_vlan_var.h>
59218893Sdim
60251662Sdim#include <netinet/in_systm.h>
61218893Sdim#include <netinet/in.h>
62218893Sdim#include <netinet/if_ether.h>
63218893Sdim#include <netinet/ip.h>
64251662Sdim#include <netinet/ip6.h>
65218893Sdim#include <netinet/tcp.h>
66218893Sdim#include <netinet/udp.h>
67218893Sdim
68251662Sdim#include <machine/in_cksum.h>
69218893Sdim
70218893Sdim#include <sys/bus.h>
71218893Sdim#include <machine/bus.h>
72251662Sdim#include <sys/rman.h>
73251662Sdim#include <machine/resource.h>
74193323Sed#include <vm/vm.h>
75193323Sed#include <vm/pmap.h>
76193323Sed#include <machine/clock.h>
77193323Sed#include <dev/pci/pcivar.h>
78193323Sed#include <dev/pci/pcireg.h>
79193323Sed#include <sys/proc.h>
80193323Sed#include <sys/sysctl.h>
81193323Sed#include <sys/endian.h>
82193323Sed#include <sys/taskqueue.h>
83218893Sdim#include <sys/pcpu.h>
84193323Sed
85218893Sdim#include "ixgbe_api.h"
86218893Sdim#include "tcp_lro.h"
87234353Sdim
88193323Sed/* Tunables */
89193323Sed
90193323Sed/*
91193323Sed * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
92193323Sed * number of transmit descriptors allocated by the driver. Increasing this
93193323Sed * value allows the driver to queue more transmits. Each descriptor is 16
94193323Sed * bytes. Performance tests have show the 2K value to be optimal for top
95193323Sed * performance.
96193323Sed */
97203954Srdivacky#define DEFAULT_TXD	256
98203954Srdivacky#define PERFORM_TXD	2048
99203954Srdivacky#define MAX_TXD		4096
100234353Sdim#define MIN_TXD		64
101234353Sdim
102251662Sdim/*
103251662Sdim * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
104251662Sdim * number of receive descriptors allocated for each RX queue. Increasing this
105203954Srdivacky * value allows the driver to buffer more incoming packets. Each descriptor
106251662Sdim * is 16 bytes.  A receive buffer is also allocated for each descriptor.
107193323Sed *
108193323Sed * Note: with 8 rings and a dual port card, it is possible to bump up
109193323Sed *	against the system mbuf pool limit, you can tune nmbclusters
110218893Sdim *	to adjust for this.
111218893Sdim */
112234353Sdim#define DEFAULT_RXD	256
113234353Sdim#define PERFORM_RXD	2048
114193323Sed#define MAX_RXD		4096
115218893Sdim#define MIN_RXD		64
116251662Sdim
117198090Srdivacky/* Alignment for rings */
118198090Srdivacky#define DBA_ALIGN	128
119198090Srdivacky
120198090Srdivacky/*
121198090Srdivacky * This parameter controls the maximum no of times the driver will loop in
122198090Srdivacky * the isr. Minimum Value = 1
123198090Srdivacky */
124218893Sdim#define MAX_INTR	10
125193323Sed
126193323Sed/*
127203954Srdivacky * This parameter controls the duration of transmit watchdog timer.
128193323Sed */
129251662Sdim#define IXGBE_TX_TIMEOUT                   5	/* set to 5 seconds */
130251662Sdim
131251662Sdim/*
132193323Sed * This parameters control when the driver calls the routine to reclaim
133193323Sed * transmit descriptors.
134193323Sed */
135218893Sdim#define IXGBE_TX_CLEANUP_THRESHOLD	(adapter->num_tx_desc / 8)
136193323Sed#define IXGBE_TX_OP_THRESHOLD		(adapter->num_tx_desc / 32)
137193323Sed
138193323Sed#define IXGBE_MAX_FRAME_SIZE	0x3F00
139193323Sed
140193323Sed/* Flow control constants */
141198090Srdivacky#define IXGBE_FC_PAUSE		0x680
142198090Srdivacky#define IXGBE_FC_HI		0x20000
143193323Sed#define IXGBE_FC_LO		0x10000
144198090Srdivacky
145198090Srdivacky/* Defines for printing debug information */
146203954Srdivacky#define DEBUG_INIT  0
147198090Srdivacky#define DEBUG_IOCTL 0
148218893Sdim#define DEBUG_HW    0
149218893Sdim
150218893Sdim#define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
151234353Sdim#define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
152234353Sdim#define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
153234353Sdim#define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
154193323Sed#define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
155193323Sed#define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
156193323Sed#define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
157203954Srdivacky#define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
158234353Sdim#define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
159193323Sed
160243830Sdim#define MAX_NUM_MULTICAST_ADDRESSES     128
161243830Sdim#define IXGBE_MAX_SCATTER		100
162243830Sdim#define IXGBE_MSIX_BAR			3
163243830Sdim#define IXGBE_TSO_SIZE			65535
164243830Sdim#define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
165243830Sdim#define IXGBE_RX_HDR_SIZE		((u32) 256)
166243830Sdim#define CSUM_OFFLOAD			7	/* Bits in csum flags */
167243830Sdim
168243830Sdim/* The number of MSIX messages the 82598 supports */
169198090Srdivacky#define IXGBE_MSGS			18
170198090Srdivacky
171198090Srdivacky/* For 6.X code compatibility */
172198090Srdivacky#if __FreeBSD_version < 700000
173198090Srdivacky#define ETHER_BPF_MTAP		BPF_MTAP
174198090Srdivacky#define CSUM_TSO		0
175198090Srdivacky#define IFCAP_TSO4		0
176198090Srdivacky#define FILTER_STRAY
177218893Sdim#define FILTER_HANDLED
178218893Sdim#endif
179198090Srdivacky
180193323Sed/*
181193323Sed * Interrupt Moderation parameters
182193323Sed * 	for now we hardcode, later
183193323Sed *	it would be nice to do dynamic
184193323Sed */
185198090Srdivacky#define MAX_IRQ_SEC	8000
186198090Srdivacky#define DEFAULT_ITR	1000000000/(MAX_IRQ_SEC * 256)
187193323Sed#define LINK_ITR	1000000000/(1950 * 256)
188193323Sed
189193323Sed/* Used for auto RX queue configuration */
190extern int mp_ncpus;
191
192/*
193 * ******************************************************************************
194 * vendor_info_array
195 *
196 * This array contains the list of Subvendor/Subdevice IDs on which the driver
197 * should load.
198 *
199*****************************************************************************
200 */
201typedef struct _ixgbe_vendor_info_t {
202	unsigned int    vendor_id;
203	unsigned int    device_id;
204	unsigned int    subvendor_id;
205	unsigned int    subdevice_id;
206	unsigned int    index;
207}               ixgbe_vendor_info_t;
208
209
210struct ixgbe_tx_buf {
211	struct mbuf	*m_head;
212	bus_dmamap_t	map;
213};
214
215struct ixgbe_rx_buf {
216	struct mbuf	*m_head;
217	boolean_t	bigbuf;
218	/* one small and one large map */
219	bus_dmamap_t	map[2];
220};
221
222/*
223 * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
224 */
225struct ixgbe_dma_alloc {
226	bus_addr_t		dma_paddr;
227	caddr_t			dma_vaddr;
228	bus_dma_tag_t		dma_tag;
229	bus_dmamap_t		dma_map;
230	bus_dma_segment_t	dma_seg;
231	bus_size_t		dma_size;
232	int			dma_nseg;
233};
234
235/*
236 * The transmit ring, one per tx queue
237 */
238struct tx_ring {
239        struct adapter		*adapter;
240	struct mtx		tx_mtx;
241	u32			me;
242	u32			msix;
243	u32			eims;
244	u32			watchdog_timer;
245	union ixgbe_adv_tx_desc	*tx_base;
246	volatile u32		tx_hwb;
247	struct ixgbe_dma_alloc	txdma;
248	struct task     	tx_task;
249	struct taskqueue	*tq;
250	u32			next_avail_tx_desc;
251	u32			next_tx_to_clean;
252	struct ixgbe_tx_buf	*tx_buffers;
253	volatile u16		tx_avail;
254	u32			txd_cmd;
255	bus_dma_tag_t		txtag;
256	/* Soft Stats */
257	u32			no_tx_desc_avail;
258	u32			no_tx_desc_late;
259	u64			tx_irq;
260	u64			tx_packets;
261};
262
263
264/*
265 * The Receive ring, one per rx queue
266 */
267struct rx_ring {
268        struct adapter		*adapter;
269	struct mtx		rx_mtx;
270	u32			me;
271	u32			msix;
272	u32			eims;
273	u32			payload;
274	struct task     	rx_task;
275	struct taskqueue	*tq;
276	union ixgbe_adv_rx_desc	*rx_base;
277	struct ixgbe_dma_alloc	rxdma;
278	struct lro_ctrl		lro;
279        unsigned int		last_cleaned;
280        unsigned int		next_to_check;
281	struct ixgbe_rx_buf	*rx_buffers;
282	bus_dma_tag_t		rxtag[2];
283	bus_dmamap_t		spare_map[2];
284	struct mbuf		*fmp;
285	struct mbuf		*lmp;
286	/* Soft stats */
287	u64			rx_irq;
288	u64			packet_count;
289	u64 			byte_count;
290};
291
292/* Our adapter structure */
293struct adapter {
294	struct ifnet	*ifp;
295	struct ixgbe_hw	hw;
296
297	/* FreeBSD operating-system-specific structures */
298	struct ixgbe_osdep	osdep;
299	struct device	*dev;
300
301	struct resource	*pci_mem;
302	struct resource	*msix_mem;
303
304	/*
305	 * Interrupt resources:
306	 *  Oplin has 20 MSIX messages
307	 *  so allocate that for now.
308	 */
309	void		*tag[IXGBE_MSGS];
310	struct resource *res[IXGBE_MSGS];
311	int		rid[IXGBE_MSGS];
312	u32		eims_mask;
313
314	struct ifmedia	media;
315	struct callout	timer;
316	int		msix;
317	int		if_flags;
318
319	struct mtx	core_mtx;
320
321	/* Legacy Fast Intr handling */
322	struct task     link_task;
323
324	/* Info about the board itself */
325	u32		part_num;
326	bool		link_active;
327	u16		max_frame_size;
328	u32		link_speed;
329	u32		tx_int_delay;
330	u32		tx_abs_int_delay;
331	u32		rx_int_delay;
332	u32		rx_abs_int_delay;
333
334	/* Indicates the cluster size to use */
335	bool		bigbufs;
336
337	/*
338	 * Transmit rings:
339	 *	Allocated at run time, an array of rings.
340	 */
341	struct tx_ring	*tx_rings;
342	int		num_tx_desc;
343	int		num_tx_queues;
344
345	/*
346	 * Receive rings:
347	 *	Allocated at run time, an array of rings.
348	 */
349	struct rx_ring	*rx_rings;
350	int		num_rx_desc;
351	int		num_rx_queues;
352	u32		rx_process_limit;
353
354	/* Misc stats maintained by the driver */
355	unsigned long   dropped_pkts;
356	unsigned long   mbuf_alloc_failed;
357	unsigned long   mbuf_cluster_failed;
358	unsigned long   no_tx_map_avail;
359	unsigned long   no_tx_dma_setup;
360	unsigned long   watchdog_events;
361	unsigned long   tso_tx;
362	unsigned long	linkvec;
363	unsigned long	link_irq;
364
365	struct ixgbe_hw_stats stats;
366};
367
368#define IXGBE_CORE_LOCK_INIT(_sc, _name) \
369        mtx_init(&(_sc)->core_mtx, _name, "IXGBE Core Lock", MTX_DEF)
370#define IXGBE_CORE_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->core_mtx)
371#define IXGBE_TX_LOCK_DESTROY(_sc)                mtx_destroy(&(_sc)->tx_mtx)
372#define IXGBE_RX_LOCK_DESTROY(_sc)                mtx_destroy(&(_sc)->rx_mtx)
373#define IXGBE_CORE_LOCK(_sc)              mtx_lock(&(_sc)->core_mtx)
374#define IXGBE_TX_LOCK(_sc)                        mtx_lock(&(_sc)->tx_mtx)
375#define IXGBE_RX_LOCK(_sc)                        mtx_lock(&(_sc)->rx_mtx)
376#define IXGBE_CORE_UNLOCK(_sc)            mtx_unlock(&(_sc)->core_mtx)
377#define IXGBE_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->tx_mtx)
378#define IXGBE_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->rx_mtx)
379#define IXGBE_CORE_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->core_mtx, MA_OWNED)
380#define IXGBE_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->tx_mtx, MA_OWNED)
381
382
383#endif /* _IXGBE_H_ */
384