xref: /freebsd/sys/dev/ixgbe/ixgbe.h (revision cfc0969ad4417f17f8c5226441ade35b2ba4ad3e)
19ca4041bSJack F Vogel /******************************************************************************
213705f88SJack F Vogel 
385d0a26eSJack F Vogel   Copyright (c) 2001-2012, Intel Corporation
413705f88SJack F Vogel   All rights reserved.
513705f88SJack F Vogel 
613705f88SJack F Vogel   Redistribution and use in source and binary forms, with or without
713705f88SJack F Vogel   modification, are permitted provided that the following conditions are met:
813705f88SJack F Vogel 
913705f88SJack F Vogel    1. Redistributions of source code must retain the above copyright notice,
1013705f88SJack F Vogel       this list of conditions and the following disclaimer.
1113705f88SJack F Vogel 
1213705f88SJack F Vogel    2. Redistributions in binary form must reproduce the above copyright
1313705f88SJack F Vogel       notice, this list of conditions and the following disclaimer in the
1413705f88SJack F Vogel       documentation and/or other materials provided with the distribution.
1513705f88SJack F Vogel 
1613705f88SJack F Vogel    3. Neither the name of the Intel Corporation nor the names of its
1713705f88SJack F Vogel       contributors may be used to endorse or promote products derived from
1813705f88SJack F Vogel       this software without specific prior written permission.
1913705f88SJack F Vogel 
2013705f88SJack F Vogel   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2113705f88SJack F Vogel   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2213705f88SJack F Vogel   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2313705f88SJack F Vogel   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2413705f88SJack F Vogel   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2513705f88SJack F Vogel   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2613705f88SJack F Vogel   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2713705f88SJack F Vogel   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2813705f88SJack F Vogel   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2913705f88SJack F Vogel   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3013705f88SJack F Vogel   POSSIBILITY OF SUCH DAMAGE.
3113705f88SJack F Vogel 
329ca4041bSJack F Vogel ******************************************************************************/
3313705f88SJack F Vogel /*$FreeBSD$*/
3413705f88SJack F Vogel 
351b6e0dbaSJack F Vogel 
3613705f88SJack F Vogel #ifndef _IXGBE_H_
3713705f88SJack F Vogel #define _IXGBE_H_
3813705f88SJack F Vogel 
3913705f88SJack F Vogel 
4013705f88SJack F Vogel #include <sys/param.h>
4113705f88SJack F Vogel #include <sys/systm.h>
42d8602bb9SJack F Vogel #if __FreeBSD_version >= 800000
43d8602bb9SJack F Vogel #include <sys/buf_ring.h>
44d8602bb9SJack F Vogel #endif
4513705f88SJack F Vogel #include <sys/mbuf.h>
4613705f88SJack F Vogel #include <sys/protosw.h>
4713705f88SJack F Vogel #include <sys/socket.h>
4813705f88SJack F Vogel #include <sys/malloc.h>
4913705f88SJack F Vogel #include <sys/kernel.h>
5013705f88SJack F Vogel #include <sys/module.h>
5113705f88SJack F Vogel #include <sys/sockio.h>
5213705f88SJack F Vogel 
5313705f88SJack F Vogel #include <net/if.h>
5413705f88SJack F Vogel #include <net/if_arp.h>
5513705f88SJack F Vogel #include <net/bpf.h>
5613705f88SJack F Vogel #include <net/ethernet.h>
5713705f88SJack F Vogel #include <net/if_dl.h>
5813705f88SJack F Vogel #include <net/if_media.h>
5913705f88SJack F Vogel 
6013705f88SJack F Vogel #include <net/bpf.h>
6113705f88SJack F Vogel #include <net/if_types.h>
6213705f88SJack F Vogel #include <net/if_vlan_var.h>
6313705f88SJack F Vogel 
6413705f88SJack F Vogel #include <netinet/in_systm.h>
6513705f88SJack F Vogel #include <netinet/in.h>
6613705f88SJack F Vogel #include <netinet/if_ether.h>
6713705f88SJack F Vogel #include <netinet/ip.h>
6813705f88SJack F Vogel #include <netinet/ip6.h>
6913705f88SJack F Vogel #include <netinet/tcp.h>
700ac6dfecSJack F Vogel #include <netinet/tcp_lro.h>
7113705f88SJack F Vogel #include <netinet/udp.h>
7213705f88SJack F Vogel 
7313705f88SJack F Vogel #include <machine/in_cksum.h>
7413705f88SJack F Vogel 
7513705f88SJack F Vogel #include <sys/bus.h>
7613705f88SJack F Vogel #include <machine/bus.h>
7713705f88SJack F Vogel #include <sys/rman.h>
7813705f88SJack F Vogel #include <machine/resource.h>
7913705f88SJack F Vogel #include <vm/vm.h>
8013705f88SJack F Vogel #include <vm/pmap.h>
8113705f88SJack F Vogel #include <machine/clock.h>
8213705f88SJack F Vogel #include <dev/pci/pcivar.h>
8313705f88SJack F Vogel #include <dev/pci/pcireg.h>
8413705f88SJack F Vogel #include <sys/proc.h>
8513705f88SJack F Vogel #include <sys/sysctl.h>
8613705f88SJack F Vogel #include <sys/endian.h>
8713705f88SJack F Vogel #include <sys/taskqueue.h>
889ca4041bSJack F Vogel #include <sys/pcpu.h>
89d8602bb9SJack F Vogel #include <sys/smp.h>
90d8602bb9SJack F Vogel #include <machine/smp.h>
9113705f88SJack F Vogel 
92d8602bb9SJack F Vogel #ifdef IXGBE_IEEE1588
93d8602bb9SJack F Vogel #include <sys/ieee1588.h>
940ac6dfecSJack F Vogel #endif
950ac6dfecSJack F Vogel 
9613705f88SJack F Vogel #include "ixgbe_api.h"
9713705f88SJack F Vogel 
9813705f88SJack F Vogel /* Tunables */
9913705f88SJack F Vogel 
10013705f88SJack F Vogel /*
1013ec35e52SJack F Vogel  * TxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
10213705f88SJack F Vogel  * number of transmit descriptors allocated by the driver. Increasing this
10313705f88SJack F Vogel  * value allows the driver to queue more transmits. Each descriptor is 16
1043ec35e52SJack F Vogel  * bytes. Performance tests have show the 2K value to be optimal for top
1053ec35e52SJack F Vogel  * performance.
10613705f88SJack F Vogel  */
1070ac6dfecSJack F Vogel #define DEFAULT_TXD	1024
1083ec35e52SJack F Vogel #define PERFORM_TXD	2048
10913705f88SJack F Vogel #define MAX_TXD		4096
11013705f88SJack F Vogel #define MIN_TXD		64
11113705f88SJack F Vogel 
11213705f88SJack F Vogel /*
1133ec35e52SJack F Vogel  * RxDescriptors Valid Range: 64-4096 Default Value: 256 This value is the
1143ec35e52SJack F Vogel  * number of receive descriptors allocated for each RX queue. Increasing this
11513705f88SJack F Vogel  * value allows the driver to buffer more incoming packets. Each descriptor
1163ec35e52SJack F Vogel  * is 16 bytes.  A receive buffer is also allocated for each descriptor.
11713705f88SJack F Vogel  *
1183ec35e52SJack F Vogel  * Note: with 8 rings and a dual port card, it is possible to bump up
1193ec35e52SJack F Vogel  *	against the system mbuf pool limit, you can tune nmbclusters
1203ec35e52SJack F Vogel  *	to adjust for this.
12113705f88SJack F Vogel  */
1220ac6dfecSJack F Vogel #define DEFAULT_RXD	1024
1233ec35e52SJack F Vogel #define PERFORM_RXD	2048
12413705f88SJack F Vogel #define MAX_RXD		4096
12513705f88SJack F Vogel #define MIN_RXD		64
12613705f88SJack F Vogel 
1273ec35e52SJack F Vogel /* Alignment for rings */
1283ec35e52SJack F Vogel #define DBA_ALIGN	128
1293ec35e52SJack F Vogel 
13013705f88SJack F Vogel /*
13113705f88SJack F Vogel  * This parameter controls the maximum no of times the driver will loop in
13213705f88SJack F Vogel  * the isr. Minimum Value = 1
13313705f88SJack F Vogel  */
1341b6e0dbaSJack F Vogel #define MAX_LOOP	10
13513705f88SJack F Vogel 
13613705f88SJack F Vogel /*
1372969bf0eSJack F Vogel  * This is the max watchdog interval, ie. the time that can
1382969bf0eSJack F Vogel  * pass between any two TX clean operations, such only happening
1392969bf0eSJack F Vogel  * when the TX hardware is functioning.
14013705f88SJack F Vogel  */
1412969bf0eSJack F Vogel #define IXGBE_WATCHDOG                   (10 * hz)
14213705f88SJack F Vogel 
14313705f88SJack F Vogel /*
14413705f88SJack F Vogel  * This parameters control when the driver calls the routine to reclaim
14513705f88SJack F Vogel  * transmit descriptors.
14613705f88SJack F Vogel  */
14713705f88SJack F Vogel #define IXGBE_TX_CLEANUP_THRESHOLD	(adapter->num_tx_desc / 8)
14813705f88SJack F Vogel #define IXGBE_TX_OP_THRESHOLD		(adapter->num_tx_desc / 32)
14913705f88SJack F Vogel 
15013705f88SJack F Vogel #define IXGBE_MAX_FRAME_SIZE	0x3F00
15113705f88SJack F Vogel 
1523ec35e52SJack F Vogel /* Flow control constants */
1532969bf0eSJack F Vogel #define IXGBE_FC_PAUSE		0xFFFF
1543ec35e52SJack F Vogel #define IXGBE_FC_HI		0x20000
1553ec35e52SJack F Vogel #define IXGBE_FC_LO		0x10000
15613705f88SJack F Vogel 
157*cfc0969aSScott Long /*
158*cfc0969aSScott Long  * Used for optimizing small rx mbufs.  Effort is made to keep the copy
159*cfc0969aSScott Long  * small and aligned for the CPU L1 cache.
160*cfc0969aSScott Long  *
161*cfc0969aSScott Long  * MHLEN is typically 168 bytes, giving us 8-byte alignment.  Getting
162*cfc0969aSScott Long  * 32 byte alignment needed for the fast bcopy results in 8 bytes being
163*cfc0969aSScott Long  * wasted.  Getting 64 byte alignment, which _should_ be ideal for
164*cfc0969aSScott Long  * modern Intel CPUs, results in 40 bytes wasted and a significant drop
165*cfc0969aSScott Long  * in observed efficiency of the optimization, 97.9% -> 81.8%.
166*cfc0969aSScott Long  */
167*cfc0969aSScott Long #define IXGBE_RX_COPY_LEN	160
168*cfc0969aSScott Long #define IXGBE_RX_COPY_ALIGN	(MHLEN - IXGBE_RX_COPY_LEN)
169*cfc0969aSScott Long 
1700e6fa41fSJack F Vogel /* Keep older OS drivers building... */
1710e6fa41fSJack F Vogel #if !defined(SYSCTL_ADD_UQUAD)
1720e6fa41fSJack F Vogel #define SYSCTL_ADD_UQUAD SYSCTL_ADD_QUAD
1730e6fa41fSJack F Vogel #endif
1740e6fa41fSJack F Vogel 
17513705f88SJack F Vogel /* Defines for printing debug information */
17613705f88SJack F Vogel #define DEBUG_INIT  0
17713705f88SJack F Vogel #define DEBUG_IOCTL 0
17813705f88SJack F Vogel #define DEBUG_HW    0
17913705f88SJack F Vogel 
18013705f88SJack F Vogel #define INIT_DEBUGOUT(S)            if (DEBUG_INIT)  printf(S "\n")
18113705f88SJack F Vogel #define INIT_DEBUGOUT1(S, A)        if (DEBUG_INIT)  printf(S "\n", A)
18213705f88SJack F Vogel #define INIT_DEBUGOUT2(S, A, B)     if (DEBUG_INIT)  printf(S "\n", A, B)
18313705f88SJack F Vogel #define IOCTL_DEBUGOUT(S)           if (DEBUG_IOCTL) printf(S "\n")
18413705f88SJack F Vogel #define IOCTL_DEBUGOUT1(S, A)       if (DEBUG_IOCTL) printf(S "\n", A)
18513705f88SJack F Vogel #define IOCTL_DEBUGOUT2(S, A, B)    if (DEBUG_IOCTL) printf(S "\n", A, B)
18613705f88SJack F Vogel #define HW_DEBUGOUT(S)              if (DEBUG_HW) printf(S "\n")
18713705f88SJack F Vogel #define HW_DEBUGOUT1(S, A)          if (DEBUG_HW) printf(S "\n", A)
18813705f88SJack F Vogel #define HW_DEBUGOUT2(S, A, B)       if (DEBUG_HW) printf(S "\n", A, B)
18913705f88SJack F Vogel 
19013705f88SJack F Vogel #define MAX_NUM_MULTICAST_ADDRESSES     128
1910ac6dfecSJack F Vogel #define IXGBE_82598_SCATTER		100
1920ac6dfecSJack F Vogel #define IXGBE_82599_SCATTER		32
1931b6e0dbaSJack F Vogel #define MSIX_82598_BAR			3
1941b6e0dbaSJack F Vogel #define MSIX_82599_BAR			4
19539fc714aSBjoern A. Zeeb #define IXGBE_TSO_SIZE			262140
19613705f88SJack F Vogel #define IXGBE_TX_BUFFER_SIZE		((u32) 1514)
197c0014855SJack F Vogel #define IXGBE_RX_HDR			128
198d8602bb9SJack F Vogel #define IXGBE_VFTA_SIZE			128
199d8602bb9SJack F Vogel #define IXGBE_BR_SIZE			4096
20085d0a26eSJack F Vogel #define IXGBE_QUEUE_MIN_FREE		32
20185d0a26eSJack F Vogel #define IXGBE_QUEUE_IDLE		1
20285d0a26eSJack F Vogel #define IXGBE_QUEUE_WORKING		2
20385d0a26eSJack F Vogel #define IXGBE_QUEUE_HUNG		4
20485d0a26eSJack F Vogel #define IXGBE_QUEUE_DEPLETED		8
2059de5aff5SJack F Vogel 
2069de5aff5SJack F Vogel /* Offload bits in mbuf flag */
2079de5aff5SJack F Vogel #if __FreeBSD_version >= 800000
2089de5aff5SJack F Vogel #define CSUM_OFFLOAD		(CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
2099de5aff5SJack F Vogel #else
2109de5aff5SJack F Vogel #define CSUM_OFFLOAD		(CSUM_IP|CSUM_TCP|CSUM_UDP)
2119de5aff5SJack F Vogel #endif
21213705f88SJack F Vogel 
2133ec35e52SJack F Vogel /* For 6.X code compatibility */
2140ac6dfecSJack F Vogel #if !defined(ETHER_BPF_MTAP)
2153ec35e52SJack F Vogel #define ETHER_BPF_MTAP		BPF_MTAP
2160ac6dfecSJack F Vogel #endif
2170ac6dfecSJack F Vogel 
2180ac6dfecSJack F Vogel #if __FreeBSD_version < 700000
2193ec35e52SJack F Vogel #define CSUM_TSO		0
2203ec35e52SJack F Vogel #define IFCAP_TSO4		0
2213ec35e52SJack F Vogel #endif
2223ec35e52SJack F Vogel 
22313705f88SJack F Vogel /*
22413705f88SJack F Vogel  * Interrupt Moderation parameters
22513705f88SJack F Vogel  */
2261b6e0dbaSJack F Vogel #define IXGBE_LOW_LATENCY	128
2271b6e0dbaSJack F Vogel #define IXGBE_AVE_LATENCY	400
2281b6e0dbaSJack F Vogel #define IXGBE_BULK_LATENCY	1200
2291b6e0dbaSJack F Vogel #define IXGBE_LINK_ITR		2000
2301b6e0dbaSJack F Vogel 
23113705f88SJack F Vogel /*
2321b6e0dbaSJack F Vogel  *****************************************************************************
23313705f88SJack F Vogel  * vendor_info_array
23413705f88SJack F Vogel  *
23513705f88SJack F Vogel  * This array contains the list of Subvendor/Subdevice IDs on which the driver
23613705f88SJack F Vogel  * should load.
23713705f88SJack F Vogel  *
23813705f88SJack F Vogel  *****************************************************************************
23913705f88SJack F Vogel  */
24013705f88SJack F Vogel typedef struct _ixgbe_vendor_info_t {
24113705f88SJack F Vogel 	unsigned int    vendor_id;
24213705f88SJack F Vogel 	unsigned int    device_id;
24313705f88SJack F Vogel 	unsigned int    subvendor_id;
24413705f88SJack F Vogel 	unsigned int    subdevice_id;
24513705f88SJack F Vogel 	unsigned int    index;
24613705f88SJack F Vogel } ixgbe_vendor_info_t;
24713705f88SJack F Vogel 
24813705f88SJack F Vogel 
24913705f88SJack F Vogel struct ixgbe_tx_buf {
2500ac6dfecSJack F Vogel 	u32		eop_index;
25113705f88SJack F Vogel 	struct mbuf	*m_head;
25213705f88SJack F Vogel 	bus_dmamap_t	map;
25313705f88SJack F Vogel };
25413705f88SJack F Vogel 
25513705f88SJack F Vogel struct ixgbe_rx_buf {
25613705f88SJack F Vogel 	struct mbuf	*m_head;
2571b6e0dbaSJack F Vogel 	struct mbuf	*m_pack;
258c0014855SJack F Vogel 	struct mbuf	*fmp;
2593f13ffabSJack F Vogel 	bus_dmamap_t	hmap;
2603f13ffabSJack F Vogel 	bus_dmamap_t	pmap;
261*cfc0969aSScott Long 	u_int		flags;
262*cfc0969aSScott Long #define IXGBE_RX_COPY	0x01
263*cfc0969aSScott Long 	uint64_t	paddr;
26413705f88SJack F Vogel };
26513705f88SJack F Vogel 
26613705f88SJack F Vogel /*
26713705f88SJack F Vogel  * Bus dma allocation structure used by ixgbe_dma_malloc and ixgbe_dma_free.
26813705f88SJack F Vogel  */
26913705f88SJack F Vogel struct ixgbe_dma_alloc {
27013705f88SJack F Vogel 	bus_addr_t		dma_paddr;
27113705f88SJack F Vogel 	caddr_t			dma_vaddr;
27213705f88SJack F Vogel 	bus_dma_tag_t		dma_tag;
27313705f88SJack F Vogel 	bus_dmamap_t		dma_map;
27413705f88SJack F Vogel 	bus_dma_segment_t	dma_seg;
27513705f88SJack F Vogel 	bus_size_t		dma_size;
27613705f88SJack F Vogel 	int			dma_nseg;
27713705f88SJack F Vogel };
27813705f88SJack F Vogel 
27913705f88SJack F Vogel /*
280c0014855SJack F Vogel ** Driver queue struct: this is the interrupt container
281c0014855SJack F Vogel **  for the associated tx and rx ring.
282c0014855SJack F Vogel */
283c0014855SJack F Vogel struct ix_queue {
284c0014855SJack F Vogel 	struct adapter		*adapter;
285c0014855SJack F Vogel 	u32			msix;           /* This queue's MSIX vector */
286c0014855SJack F Vogel 	u32			eims;           /* This queue's EIMS bit */
287c0014855SJack F Vogel 	u32			eitr_setting;
288c0014855SJack F Vogel 	struct resource		*res;
289c0014855SJack F Vogel 	void			*tag;
290c0014855SJack F Vogel 	struct tx_ring		*txr;
291c0014855SJack F Vogel 	struct rx_ring		*rxr;
292c0014855SJack F Vogel 	struct task		que_task;
293c0014855SJack F Vogel 	struct taskqueue	*tq;
294c0014855SJack F Vogel 	u64			irqs;
295c0014855SJack F Vogel };
296c0014855SJack F Vogel 
297c0014855SJack F Vogel /*
298c0014855SJack F Vogel  * The transmit ring, one per queue
29913705f88SJack F Vogel  */
30013705f88SJack F Vogel struct tx_ring {
30113705f88SJack F Vogel         struct adapter		*adapter;
3029ca4041bSJack F Vogel 	struct mtx		tx_mtx;
30313705f88SJack F Vogel 	u32			me;
3041a4e3449SJack F Vogel 	int			queue_status;
3052969bf0eSJack F Vogel 	int			watchdog_time;
30613705f88SJack F Vogel 	union ixgbe_adv_tx_desc	*tx_base;
30713705f88SJack F Vogel 	struct ixgbe_dma_alloc	txdma;
3082969bf0eSJack F Vogel 	u32			next_avail_desc;
3092969bf0eSJack F Vogel 	u32			next_to_clean;
31013705f88SJack F Vogel 	struct ixgbe_tx_buf	*tx_buffers;
3119ca4041bSJack F Vogel 	volatile u16		tx_avail;
3129ca4041bSJack F Vogel 	u32			txd_cmd;
31313705f88SJack F Vogel 	bus_dma_tag_t		txtag;
3141b6e0dbaSJack F Vogel 	char			mtx_name[16];
315d8602bb9SJack F Vogel #if __FreeBSD_version >= 800000
316d8602bb9SJack F Vogel 	struct buf_ring		*br;
317d8602bb9SJack F Vogel #endif
3182969bf0eSJack F Vogel #ifdef IXGBE_FDIR
3192969bf0eSJack F Vogel 	u16			atr_sample;
3202969bf0eSJack F Vogel 	u16			atr_count;
3212969bf0eSJack F Vogel #endif
322c0014855SJack F Vogel 	u32			bytes;  /* used for AIM */
323c0014855SJack F Vogel 	u32			packets;
3249ca4041bSJack F Vogel 	/* Soft Stats */
325c0014855SJack F Vogel 	u64			no_desc_avail;
3261b6e0dbaSJack F Vogel 	u64			total_packets;
32713705f88SJack F Vogel };
32813705f88SJack F Vogel 
32913705f88SJack F Vogel 
33013705f88SJack F Vogel /*
33113705f88SJack F Vogel  * The Receive ring, one per rx queue
33213705f88SJack F Vogel  */
33313705f88SJack F Vogel struct rx_ring {
33413705f88SJack F Vogel         struct adapter		*adapter;
3359ca4041bSJack F Vogel 	struct mtx		rx_mtx;
33613705f88SJack F Vogel 	u32			me;
33713705f88SJack F Vogel 	union ixgbe_adv_rx_desc	*rx_base;
33813705f88SJack F Vogel 	struct ixgbe_dma_alloc	rxdma;
3399ca4041bSJack F Vogel 	struct lro_ctrl		lro;
340d8602bb9SJack F Vogel 	bool			lro_enabled;
341d8602bb9SJack F Vogel 	bool			hdr_split;
3422969bf0eSJack F Vogel 	bool			hw_rsc;
343c0014855SJack F Vogel 	bool			discard;
34485d0a26eSJack F Vogel 	bool			vtag_strip;
345c0014855SJack F Vogel         u32			next_to_refresh;
346c0014855SJack F Vogel         u32 			next_to_check;
347c0014855SJack F Vogel 	char			mtx_name[16];
34813705f88SJack F Vogel 	struct ixgbe_rx_buf	*rx_buffers;
3493f13ffabSJack F Vogel 	bus_dma_tag_t		htag;
3503f13ffabSJack F Vogel 	bus_dma_tag_t		ptag;
3511b6e0dbaSJack F Vogel 
3521b6e0dbaSJack F Vogel 	u32			bytes; /* Used for AIM calc */
353c0014855SJack F Vogel 	u32			packets;
354d8602bb9SJack F Vogel 
35513705f88SJack F Vogel 	/* Soft stats */
3569ca4041bSJack F Vogel 	u64			rx_irq;
3571b6e0dbaSJack F Vogel 	u64			rx_split_packets;
358*cfc0969aSScott Long 	u64			rx_copies;
3591b6e0dbaSJack F Vogel 	u64			rx_packets;
3601b6e0dbaSJack F Vogel 	u64 			rx_bytes;
361c0014855SJack F Vogel 	u64 			rx_discarded;
3622969bf0eSJack F Vogel 	u64 			rsc_num;
3632969bf0eSJack F Vogel #ifdef IXGBE_FDIR
3642969bf0eSJack F Vogel 	u64			flm;
3652969bf0eSJack F Vogel #endif
36613705f88SJack F Vogel };
36713705f88SJack F Vogel 
36813705f88SJack F Vogel /* Our adapter structure */
36913705f88SJack F Vogel struct adapter {
37013705f88SJack F Vogel 	struct ifnet		*ifp;
37113705f88SJack F Vogel 	struct ixgbe_hw		hw;
37213705f88SJack F Vogel 
37313705f88SJack F Vogel 	struct ixgbe_osdep	osdep;
37413705f88SJack F Vogel 	struct device		*dev;
3759ca4041bSJack F Vogel 
3769ca4041bSJack F Vogel 	struct resource		*pci_mem;
3779ca4041bSJack F Vogel 	struct resource		*msix_mem;
37813705f88SJack F Vogel 
37913705f88SJack F Vogel 	/*
380d8602bb9SJack F Vogel 	 * Interrupt resources: this set is
381d8602bb9SJack F Vogel 	 * either used for legacy, or for Link
382d8602bb9SJack F Vogel 	 * when doing MSIX
38313705f88SJack F Vogel 	 */
384d8602bb9SJack F Vogel 	void			*tag;
385d8602bb9SJack F Vogel 	struct resource 	*res;
38613705f88SJack F Vogel 
38713705f88SJack F Vogel 	struct ifmedia		media;
38813705f88SJack F Vogel 	struct callout		timer;
38913705f88SJack F Vogel 	int			msix;
39013705f88SJack F Vogel 	int			if_flags;
3919ca4041bSJack F Vogel 
3923ec35e52SJack F Vogel 	struct mtx		core_mtx;
3939ca4041bSJack F Vogel 
394d8602bb9SJack F Vogel 	eventhandler_tag 	vlan_attach;
395d8602bb9SJack F Vogel 	eventhandler_tag 	vlan_detach;
396d8602bb9SJack F Vogel 
3972969bf0eSJack F Vogel 	u16			num_vlans;
398d8602bb9SJack F Vogel 	u16			num_queues;
399d8602bb9SJack F Vogel 
4001a4e3449SJack F Vogel 	/*
4011a4e3449SJack F Vogel 	** Shadow VFTA table, this is needed because
4021a4e3449SJack F Vogel 	** the real vlan filter table gets cleared during
4031a4e3449SJack F Vogel 	** a soft reset and the driver needs to be able
4041a4e3449SJack F Vogel 	** to repopulate it.
4051a4e3449SJack F Vogel 	*/
4061a4e3449SJack F Vogel 	u32			shadow_vfta[IXGBE_VFTA_SIZE];
4071a4e3449SJack F Vogel 
4081a4e3449SJack F Vogel 	/* Info about the interface */
4091b6e0dbaSJack F Vogel 	u32			optics;
41085d0a26eSJack F Vogel 	u32			fc; /* local flow ctrl setting */
41117d2646bSJack F Vogel 	int			advertise;  /* link speeds */
4129ca4041bSJack F Vogel 	bool			link_active;
4139ca4041bSJack F Vogel 	u16			max_frame_size;
414182b3808SJack F Vogel 	u16			num_segs;
4159ca4041bSJack F Vogel 	u32			link_speed;
4160ac6dfecSJack F Vogel 	bool			link_up;
4171b6e0dbaSJack F Vogel 	u32 			linkvec;
41813705f88SJack F Vogel 
4191b6e0dbaSJack F Vogel 	/* Mbuf cluster size */
4201b6e0dbaSJack F Vogel 	u32			rx_mbuf_sz;
4211b6e0dbaSJack F Vogel 
4220ac6dfecSJack F Vogel 	/* Support for pluggable optics */
4231b6e0dbaSJack F Vogel 	bool			sfp_probe;
4240ac6dfecSJack F Vogel 	struct task     	link_task;  /* Link tasklet */
4250ac6dfecSJack F Vogel 	struct task     	mod_task;   /* SFP tasklet */
426c0014855SJack F Vogel 	struct task     	msf_task;   /* Multispeed Fiber */
4272969bf0eSJack F Vogel #ifdef IXGBE_FDIR
4282969bf0eSJack F Vogel 	int			fdir_reinit;
4292969bf0eSJack F Vogel 	struct task     	fdir_task;
4302969bf0eSJack F Vogel #endif
4310ac6dfecSJack F Vogel 	struct taskqueue	*tq;
43213705f88SJack F Vogel 
43313705f88SJack F Vogel 	/*
434c0014855SJack F Vogel 	** Queues:
435c0014855SJack F Vogel 	**   This is the irq holder, it has
436c0014855SJack F Vogel 	**   and RX/TX pair or rings associated
437c0014855SJack F Vogel 	**   with it.
438c0014855SJack F Vogel 	*/
439c0014855SJack F Vogel 	struct ix_queue		*queues;
440c0014855SJack F Vogel 
441c0014855SJack F Vogel 	/*
44213705f88SJack F Vogel 	 * Transmit rings:
44313705f88SJack F Vogel 	 *	Allocated at run time, an array of rings.
44413705f88SJack F Vogel 	 */
44513705f88SJack F Vogel 	struct tx_ring		*tx_rings;
44613705f88SJack F Vogel 	int			num_tx_desc;
44713705f88SJack F Vogel 
44813705f88SJack F Vogel 	/*
44913705f88SJack F Vogel 	 * Receive rings:
45013705f88SJack F Vogel 	 *	Allocated at run time, an array of rings.
45113705f88SJack F Vogel 	 */
45213705f88SJack F Vogel 	struct rx_ring		*rx_rings;
45313705f88SJack F Vogel 	int			num_rx_desc;
454c0014855SJack F Vogel 	u64			que_mask;
4559ca4041bSJack F Vogel 	u32			rx_process_limit;
45613705f88SJack F Vogel 
45738104eccSJack F Vogel 	/* Multicast array memory */
45838104eccSJack F Vogel 	u8			*mta;
45938104eccSJack F Vogel 
46013705f88SJack F Vogel 	/* Misc stats maintained by the driver */
46113705f88SJack F Vogel 	unsigned long   	dropped_pkts;
4621b6e0dbaSJack F Vogel 	unsigned long   	mbuf_defrag_failed;
4631b6e0dbaSJack F Vogel 	unsigned long   	mbuf_header_failed;
4641b6e0dbaSJack F Vogel 	unsigned long   	mbuf_packet_failed;
46513705f88SJack F Vogel 	unsigned long   	no_tx_map_avail;
46613705f88SJack F Vogel 	unsigned long   	no_tx_dma_setup;
46713705f88SJack F Vogel 	unsigned long   	watchdog_events;
46813705f88SJack F Vogel 	unsigned long   	tso_tx;
4699ca4041bSJack F Vogel 	unsigned long		link_irq;
47013705f88SJack F Vogel 
47113705f88SJack F Vogel 	struct ixgbe_hw_stats 	stats;
47213705f88SJack F Vogel };
47313705f88SJack F Vogel 
4740ac6dfecSJack F Vogel /* Precision Time Sync (IEEE 1588) defines */
4750ac6dfecSJack F Vogel #define ETHERTYPE_IEEE1588      0x88F7
4760ac6dfecSJack F Vogel #define PICOSECS_PER_TICK       20833
4770ac6dfecSJack F Vogel #define TSYNC_UDP_PORT          319 /* UDP port for the protocol */
4780ac6dfecSJack F Vogel #define IXGBE_ADVTXD_TSTAMP	0x00080000
4790ac6dfecSJack F Vogel 
4800ac6dfecSJack F Vogel 
4819ca4041bSJack F Vogel #define IXGBE_CORE_LOCK_INIT(_sc, _name) \
4829ca4041bSJack F Vogel         mtx_init(&(_sc)->core_mtx, _name, "IXGBE Core Lock", MTX_DEF)
4839ca4041bSJack F Vogel #define IXGBE_CORE_LOCK_DESTROY(_sc)      mtx_destroy(&(_sc)->core_mtx)
4849ca4041bSJack F Vogel #define IXGBE_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->tx_mtx)
4859ca4041bSJack F Vogel #define IXGBE_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->rx_mtx)
4869ca4041bSJack F Vogel #define IXGBE_CORE_LOCK(_sc)              mtx_lock(&(_sc)->core_mtx)
4879ca4041bSJack F Vogel #define IXGBE_TX_LOCK(_sc)                mtx_lock(&(_sc)->tx_mtx)
4880ac6dfecSJack F Vogel #define IXGBE_TX_TRYLOCK(_sc)             mtx_trylock(&(_sc)->tx_mtx)
4899ca4041bSJack F Vogel #define IXGBE_RX_LOCK(_sc)                mtx_lock(&(_sc)->rx_mtx)
4909ca4041bSJack F Vogel #define IXGBE_CORE_UNLOCK(_sc)            mtx_unlock(&(_sc)->core_mtx)
4919ca4041bSJack F Vogel #define IXGBE_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->tx_mtx)
4929ca4041bSJack F Vogel #define IXGBE_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->rx_mtx)
4939ca4041bSJack F Vogel #define IXGBE_CORE_LOCK_ASSERT(_sc)       mtx_assert(&(_sc)->core_mtx, MA_OWNED)
4949ca4041bSJack F Vogel #define IXGBE_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->tx_mtx, MA_OWNED)
4959ca4041bSJack F Vogel 
4969ca4041bSJack F Vogel 
4970ac6dfecSJack F Vogel static inline bool
4980ac6dfecSJack F Vogel ixgbe_is_sfp(struct ixgbe_hw *hw)
4990ac6dfecSJack F Vogel {
5000ac6dfecSJack F Vogel 	switch (hw->phy.type) {
5010ac6dfecSJack F Vogel 	case ixgbe_phy_sfp_avago:
5020ac6dfecSJack F Vogel 	case ixgbe_phy_sfp_ftl:
5030ac6dfecSJack F Vogel 	case ixgbe_phy_sfp_intel:
5040ac6dfecSJack F Vogel 	case ixgbe_phy_sfp_unknown:
505c0014855SJack F Vogel 	case ixgbe_phy_sfp_passive_tyco:
506c0014855SJack F Vogel 	case ixgbe_phy_sfp_passive_unknown:
5070ac6dfecSJack F Vogel 		return TRUE;
5080ac6dfecSJack F Vogel 	default:
5090ac6dfecSJack F Vogel 		return FALSE;
5100ac6dfecSJack F Vogel 	}
5110ac6dfecSJack F Vogel }
5120ac6dfecSJack F Vogel 
5132d8f84cbSJack F Vogel /* Workaround to make 8.0 buildable */
5144655a392SJack F Vogel #if __FreeBSD_version >= 800000 && __FreeBSD_version < 800504
5152d8f84cbSJack F Vogel static __inline int
5162d8f84cbSJack F Vogel drbr_needs_enqueue(struct ifnet *ifp, struct buf_ring *br)
5172d8f84cbSJack F Vogel {
5182d8f84cbSJack F Vogel #ifdef ALTQ
5192d8f84cbSJack F Vogel         if (ALTQ_IS_ENABLED(&ifp->if_snd))
5202d8f84cbSJack F Vogel                 return (1);
5212d8f84cbSJack F Vogel #endif
5222d8f84cbSJack F Vogel         return (!buf_ring_empty(br));
5232d8f84cbSJack F Vogel }
5242d8f84cbSJack F Vogel #endif
5252d8f84cbSJack F Vogel 
526e2314c6cSJack F Vogel /*
527e2314c6cSJack F Vogel ** Find the number of unrefreshed RX descriptors
528e2314c6cSJack F Vogel */
529e2314c6cSJack F Vogel static inline u16
530e2314c6cSJack F Vogel ixgbe_rx_unrefreshed(struct rx_ring *rxr)
531e2314c6cSJack F Vogel {
532e2314c6cSJack F Vogel 	struct adapter  *adapter = rxr->adapter;
533e2314c6cSJack F Vogel 
534e2314c6cSJack F Vogel 	if (rxr->next_to_check > rxr->next_to_refresh)
535e2314c6cSJack F Vogel 		return (rxr->next_to_check - rxr->next_to_refresh - 1);
536e2314c6cSJack F Vogel 	else
537e2314c6cSJack F Vogel 		return ((adapter->num_rx_desc + rxr->next_to_check) -
538e2314c6cSJack F Vogel 		    rxr->next_to_refresh - 1);
539e2314c6cSJack F Vogel }
540e2314c6cSJack F Vogel 
54113705f88SJack F Vogel #endif /* _IXGBE_H_ */
542