xref: /freebsd/sys/dev/ixl/ixl.h (revision 13b408044def0296ee8de5fa64af6effca4dfad2)
161ae650dSJack F Vogel /******************************************************************************
261ae650dSJack F Vogel 
361ae650dSJack F Vogel   Copyright (c) 2013-2014, Intel Corporation
461ae650dSJack F Vogel   All rights reserved.
561ae650dSJack F Vogel 
661ae650dSJack F Vogel   Redistribution and use in source and binary forms, with or without
761ae650dSJack F Vogel   modification, are permitted provided that the following conditions are met:
861ae650dSJack F Vogel 
961ae650dSJack F Vogel    1. Redistributions of source code must retain the above copyright notice,
1061ae650dSJack F Vogel       this list of conditions and the following disclaimer.
1161ae650dSJack F Vogel 
1261ae650dSJack F Vogel    2. Redistributions in binary form must reproduce the above copyright
1361ae650dSJack F Vogel       notice, this list of conditions and the following disclaimer in the
1461ae650dSJack F Vogel       documentation and/or other materials provided with the distribution.
1561ae650dSJack F Vogel 
1661ae650dSJack F Vogel    3. Neither the name of the Intel Corporation nor the names of its
1761ae650dSJack F Vogel       contributors may be used to endorse or promote products derived from
1861ae650dSJack F Vogel       this software without specific prior written permission.
1961ae650dSJack F Vogel 
2061ae650dSJack F Vogel   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2161ae650dSJack F Vogel   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2261ae650dSJack F Vogel   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2361ae650dSJack F Vogel   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2461ae650dSJack F Vogel   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2561ae650dSJack F Vogel   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2661ae650dSJack F Vogel   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2761ae650dSJack F Vogel   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2861ae650dSJack F Vogel   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2961ae650dSJack F Vogel   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3061ae650dSJack F Vogel   POSSIBILITY OF SUCH DAMAGE.
3161ae650dSJack F Vogel 
3261ae650dSJack F Vogel ******************************************************************************/
3361ae650dSJack F Vogel /*$FreeBSD$*/
3461ae650dSJack F Vogel 
3561ae650dSJack F Vogel 
3661ae650dSJack F Vogel #ifndef _IXL_H_
3761ae650dSJack F Vogel #define _IXL_H_
3861ae650dSJack F Vogel 
3961ae650dSJack F Vogel 
4061ae650dSJack F Vogel #include <sys/param.h>
4161ae650dSJack F Vogel #include <sys/systm.h>
4261ae650dSJack F Vogel #include <sys/buf_ring.h>
4361ae650dSJack F Vogel #include <sys/mbuf.h>
4461ae650dSJack F Vogel #include <sys/protosw.h>
4561ae650dSJack F Vogel #include <sys/socket.h>
4661ae650dSJack F Vogel #include <sys/malloc.h>
4761ae650dSJack F Vogel #include <sys/kernel.h>
4861ae650dSJack F Vogel #include <sys/module.h>
4961ae650dSJack F Vogel #include <sys/sockio.h>
50*13b40804SSteven Hartland #include <sys/eventhandler.h>
5161ae650dSJack F Vogel 
5261ae650dSJack F Vogel #include <net/if.h>
53*13b40804SSteven Hartland #include <net/if_var.h>
5461ae650dSJack F Vogel #include <net/if_arp.h>
5561ae650dSJack F Vogel #include <net/bpf.h>
5661ae650dSJack F Vogel #include <net/ethernet.h>
5761ae650dSJack F Vogel #include <net/if_dl.h>
5861ae650dSJack F Vogel #include <net/if_media.h>
5961ae650dSJack F Vogel 
6061ae650dSJack F Vogel #include <net/bpf.h>
6161ae650dSJack F Vogel #include <net/if_types.h>
6261ae650dSJack F Vogel #include <net/if_vlan_var.h>
6361ae650dSJack F Vogel 
6461ae650dSJack F Vogel #include <netinet/in_systm.h>
6561ae650dSJack F Vogel #include <netinet/in.h>
6661ae650dSJack F Vogel #include <netinet/if_ether.h>
6761ae650dSJack F Vogel #include <netinet/ip.h>
6861ae650dSJack F Vogel #include <netinet/ip6.h>
6961ae650dSJack F Vogel #include <netinet/tcp.h>
7061ae650dSJack F Vogel #include <netinet/tcp_lro.h>
7161ae650dSJack F Vogel #include <netinet/udp.h>
7261ae650dSJack F Vogel #include <netinet/sctp.h>
7361ae650dSJack F Vogel 
7461ae650dSJack F Vogel #include <machine/in_cksum.h>
7561ae650dSJack F Vogel 
7661ae650dSJack F Vogel #include <sys/bus.h>
7761ae650dSJack F Vogel #include <machine/bus.h>
7861ae650dSJack F Vogel #include <sys/rman.h>
7961ae650dSJack F Vogel #include <machine/resource.h>
8061ae650dSJack F Vogel #include <vm/vm.h>
8161ae650dSJack F Vogel #include <vm/pmap.h>
8261ae650dSJack F Vogel #include <machine/clock.h>
8361ae650dSJack F Vogel #include <dev/pci/pcivar.h>
8461ae650dSJack F Vogel #include <dev/pci/pcireg.h>
8561ae650dSJack F Vogel #include <sys/proc.h>
8661ae650dSJack F Vogel #include <sys/sysctl.h>
8761ae650dSJack F Vogel #include <sys/endian.h>
8861ae650dSJack F Vogel #include <sys/taskqueue.h>
8961ae650dSJack F Vogel #include <sys/pcpu.h>
9061ae650dSJack F Vogel #include <sys/smp.h>
9161ae650dSJack F Vogel #include <machine/smp.h>
9261ae650dSJack F Vogel 
9361ae650dSJack F Vogel #include "i40e_type.h"
9461ae650dSJack F Vogel #include "i40e_prototype.h"
9561ae650dSJack F Vogel 
9661ae650dSJack F Vogel #ifdef IXL_DEBUG
9761ae650dSJack F Vogel #include <sys/sbuf.h>
9861ae650dSJack F Vogel 
9961ae650dSJack F Vogel #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
10061ae650dSJack F Vogel #define MAC_FORMAT_ARGS(mac_addr) \
10161ae650dSJack F Vogel 	(mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \
10261ae650dSJack F Vogel 	(mac_addr)[4], (mac_addr)[5]
10361ae650dSJack F Vogel #define ON_OFF_STR(is_set) ((is_set) ? "On" : "Off")
10461ae650dSJack F Vogel 
10561ae650dSJack F Vogel 
10661ae650dSJack F Vogel #define _DBG_PRINTF(S, ...)		printf("%s: " S "\n", __func__, ##__VA_ARGS__)
10761ae650dSJack F Vogel #define _DEV_DBG_PRINTF(dev, S, ...)	device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__)
10861ae650dSJack F Vogel #define _IF_DBG_PRINTF(ifp, S, ...)	if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__)
10961ae650dSJack F Vogel 
11061ae650dSJack F Vogel /* Defines for printing generic debug information */
11161ae650dSJack F Vogel #define DPRINTF(...)			_DBG_PRINTF(__VA_ARGS__)
11261ae650dSJack F Vogel #define DDPRINTF(...)			_DEV_DBG_PRINTF(__VA_ARGS__)
11361ae650dSJack F Vogel #define IDPRINTF(...)			_IF_DBG_PRINTF(__VA_ARGS__)
11461ae650dSJack F Vogel 
11561ae650dSJack F Vogel /* Defines for printing specific debug information */
11661ae650dSJack F Vogel #define DEBUG_INIT  1
11761ae650dSJack F Vogel #define DEBUG_IOCTL 1
11861ae650dSJack F Vogel #define DEBUG_HW    1
11961ae650dSJack F Vogel 
12061ae650dSJack F Vogel #define INIT_DEBUGOUT(...)		if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__)
12161ae650dSJack F Vogel #define INIT_DBG_DEV(...)		if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__)
12261ae650dSJack F Vogel #define INIT_DBG_IF(...)		if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__)
12361ae650dSJack F Vogel 
12461ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...)		if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__)
12561ae650dSJack F Vogel #define IOCTL_DBG_IF2(ifp, S, ...)	if (DEBUG_IOCTL) \
12661ae650dSJack F Vogel 					    if_printf(ifp, S "\n", ##__VA_ARGS__)
12761ae650dSJack F Vogel #define IOCTL_DBG_IF(...)		if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__)
12861ae650dSJack F Vogel 
12961ae650dSJack F Vogel #define HW_DEBUGOUT(...)		if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__)
13061ae650dSJack F Vogel 
13161ae650dSJack F Vogel #else
13261ae650dSJack F Vogel #define DEBUG_INIT  0
13361ae650dSJack F Vogel #define DEBUG_IOCTL 0
13461ae650dSJack F Vogel #define DEBUG_HW    0
13561ae650dSJack F Vogel 
13661ae650dSJack F Vogel #define DPRINTF(...)
13761ae650dSJack F Vogel #define DDPRINTF(...)
13861ae650dSJack F Vogel #define IDPRINTF(...)
13961ae650dSJack F Vogel 
14061ae650dSJack F Vogel #define INIT_DEBUGOUT(...)
14161ae650dSJack F Vogel #define INIT_DBG_DEV(...)
14261ae650dSJack F Vogel #define INIT_DBG_IF(...)
14361ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...)
14461ae650dSJack F Vogel #define IOCTL_DBG_IF2(...)
14561ae650dSJack F Vogel #define IOCTL_DBG_IF(...)
14661ae650dSJack F Vogel #define HW_DEBUGOUT(...)
14761ae650dSJack F Vogel #endif
14861ae650dSJack F Vogel 
14961ae650dSJack F Vogel /* Tunables */
15061ae650dSJack F Vogel 
15161ae650dSJack F Vogel /*
15261ae650dSJack F Vogel  * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the
15361ae650dSJack F Vogel  * number of tx/rx descriptors allocated by the driver. Increasing this
15461ae650dSJack F Vogel  * value allows the driver to queue more operations. Each descriptor is 16
15561ae650dSJack F Vogel  * or 32 bytes (configurable in FVL)
15661ae650dSJack F Vogel  */
15761ae650dSJack F Vogel #define DEFAULT_RING	1024
15861ae650dSJack F Vogel #define PERFORM_RING	2048
15961ae650dSJack F Vogel #define MAX_RING	4096
16061ae650dSJack F Vogel #define MIN_RING	32
16161ae650dSJack F Vogel 
16261ae650dSJack F Vogel /*
16361ae650dSJack F Vogel ** Default number of entries in Tx queue buf_ring.
16461ae650dSJack F Vogel */
16561ae650dSJack F Vogel #define DEFAULT_TXBRSZ	(4096 * 4096)
16661ae650dSJack F Vogel 
16761ae650dSJack F Vogel /* Alignment for rings */
16861ae650dSJack F Vogel #define DBA_ALIGN	128
16961ae650dSJack F Vogel 
17061ae650dSJack F Vogel /*
17161ae650dSJack F Vogel  * This parameter controls the maximum no of times the driver will loop in
17261ae650dSJack F Vogel  * the isr. Minimum Value = 1
17361ae650dSJack F Vogel  */
17461ae650dSJack F Vogel #define MAX_LOOP	10
17561ae650dSJack F Vogel 
17661ae650dSJack F Vogel /*
17761ae650dSJack F Vogel  * This is the max watchdog interval, ie. the time that can
17861ae650dSJack F Vogel  * pass between any two TX clean operations, such only happening
17961ae650dSJack F Vogel  * when the TX hardware is functioning.
18061ae650dSJack F Vogel  */
18161ae650dSJack F Vogel #define IXL_WATCHDOG                   (10 * hz)
18261ae650dSJack F Vogel 
18361ae650dSJack F Vogel /*
18461ae650dSJack F Vogel  * This parameters control when the driver calls the routine to reclaim
18561ae650dSJack F Vogel  * transmit descriptors.
18661ae650dSJack F Vogel  */
18761ae650dSJack F Vogel #define IXL_TX_CLEANUP_THRESHOLD	(que->num_desc / 8)
18861ae650dSJack F Vogel #define IXL_TX_OP_THRESHOLD		(que->num_desc / 32)
18961ae650dSJack F Vogel 
19061ae650dSJack F Vogel /* Flow control constants */
19161ae650dSJack F Vogel #define IXL_FC_PAUSE		0xFFFF
19261ae650dSJack F Vogel #define IXL_FC_HI		0x20000
19361ae650dSJack F Vogel #define IXL_FC_LO		0x10000
19461ae650dSJack F Vogel 
19561ae650dSJack F Vogel #define MAX_MULTICAST_ADDR	128
19661ae650dSJack F Vogel 
19761ae650dSJack F Vogel #define IXL_BAR		3
19861ae650dSJack F Vogel #define IXL_ADM_LIMIT		2
19961ae650dSJack F Vogel #define IXL_TSO_SIZE		65535
20061ae650dSJack F Vogel #define IXL_TX_BUF_SZ		((u32) 1514)
20161ae650dSJack F Vogel #define IXL_AQ_BUF_SZ		((u32) 4096)
20261ae650dSJack F Vogel #define IXL_RX_HDR		128
20361ae650dSJack F Vogel #define IXL_AQ_LEN		256
20461ae650dSJack F Vogel #define IXL_AQ_BUFSZ		4096
20561ae650dSJack F Vogel #define IXL_RX_LIMIT		512
20661ae650dSJack F Vogel #define IXL_RX_ITR		0
20761ae650dSJack F Vogel #define IXL_TX_ITR		1
20861ae650dSJack F Vogel #define IXL_ITR_NONE		3
20961ae650dSJack F Vogel #define IXL_QUEUE_EOL		0x7FF
21061ae650dSJack F Vogel #define IXL_MAX_FRAME		0x2600
21161ae650dSJack F Vogel #define IXL_MAX_TX_SEGS	8
21261ae650dSJack F Vogel #define IXL_MAX_TSO_SEGS	66
21361ae650dSJack F Vogel #define IXL_SPARSE_CHAIN	6
21461ae650dSJack F Vogel #define IXL_QUEUE_HUNG		0x80000000
21561ae650dSJack F Vogel 
21661ae650dSJack F Vogel /* ERJ: hardware can support ~1.5k filters between all functions */
21761ae650dSJack F Vogel #define IXL_MAX_FILTERS	256
21861ae650dSJack F Vogel #define IXL_MAX_TX_BUSY	10
21961ae650dSJack F Vogel 
22061ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_SHIFT	0
22161ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_MASK		(0xff << IXL_NVM_VERSION_LO_SHIFT)
22261ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_SHIFT	12
22361ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_MASK		(0xf << IXL_NVM_VERSION_HI_SHIFT)
22461ae650dSJack F Vogel 
22561ae650dSJack F Vogel 
22661ae650dSJack F Vogel /*
22761ae650dSJack F Vogel  * Interrupt Moderation parameters
22861ae650dSJack F Vogel  */
22961ae650dSJack F Vogel #define IXL_MAX_ITR		0x07FF
23061ae650dSJack F Vogel #define IXL_ITR_100K		0x0005
23161ae650dSJack F Vogel #define IXL_ITR_20K		0x0019
23261ae650dSJack F Vogel #define IXL_ITR_8K		0x003E
23361ae650dSJack F Vogel #define IXL_ITR_4K		0x007A
23461ae650dSJack F Vogel #define IXL_ITR_DYNAMIC		0x8000
23561ae650dSJack F Vogel #define IXL_LOW_LATENCY		0
23661ae650dSJack F Vogel #define IXL_AVE_LATENCY		1
23761ae650dSJack F Vogel #define IXL_BULK_LATENCY	2
23861ae650dSJack F Vogel 
23961ae650dSJack F Vogel /* MacVlan Flags */
24061ae650dSJack F Vogel #define IXL_FILTER_USED		(u16)(1 << 0)
24161ae650dSJack F Vogel #define IXL_FILTER_VLAN		(u16)(1 << 1)
24261ae650dSJack F Vogel #define IXL_FILTER_ADD		(u16)(1 << 2)
24361ae650dSJack F Vogel #define IXL_FILTER_DEL		(u16)(1 << 3)
24461ae650dSJack F Vogel #define IXL_FILTER_MC		(u16)(1 << 4)
24561ae650dSJack F Vogel 
24661ae650dSJack F Vogel /* used in the vlan field of the filter when not a vlan */
24761ae650dSJack F Vogel #define IXL_VLAN_ANY		-1
24861ae650dSJack F Vogel 
24961ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV4	(CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
25061ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV6	(CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6)
25161ae650dSJack F Vogel #define CSUM_OFFLOAD		(CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO)
25261ae650dSJack F Vogel 
25361ae650dSJack F Vogel /* Misc flags for ixl_vsi.flags */
25461ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO4	(1 << 0)
25561ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO6	(1 << 1)
25661ae650dSJack F Vogel 
25761ae650dSJack F Vogel #define IXL_TX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
25861ae650dSJack F Vogel #define IXL_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
25961ae650dSJack F Vogel #define IXL_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
26061ae650dSJack F Vogel #define IXL_TX_TRYLOCK(_sc)             mtx_trylock(&(_sc)->mtx)
26161ae650dSJack F Vogel #define IXL_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->mtx, MA_OWNED)
26261ae650dSJack F Vogel 
26361ae650dSJack F Vogel #define IXL_RX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
26461ae650dSJack F Vogel #define IXL_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
26561ae650dSJack F Vogel #define IXL_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
26661ae650dSJack F Vogel 
26761ae650dSJack F Vogel /*
26861ae650dSJack F Vogel  *****************************************************************************
26961ae650dSJack F Vogel  * vendor_info_array
27061ae650dSJack F Vogel  *
27161ae650dSJack F Vogel  * This array contains the list of Subvendor/Subdevice IDs on which the driver
27261ae650dSJack F Vogel  * should load.
27361ae650dSJack F Vogel  *
27461ae650dSJack F Vogel  *****************************************************************************
27561ae650dSJack F Vogel  */
27661ae650dSJack F Vogel typedef struct _ixl_vendor_info_t {
27761ae650dSJack F Vogel 	unsigned int    vendor_id;
27861ae650dSJack F Vogel 	unsigned int    device_id;
27961ae650dSJack F Vogel 	unsigned int    subvendor_id;
28061ae650dSJack F Vogel 	unsigned int    subdevice_id;
28161ae650dSJack F Vogel 	unsigned int    index;
28261ae650dSJack F Vogel } ixl_vendor_info_t;
28361ae650dSJack F Vogel 
28461ae650dSJack F Vogel 
28561ae650dSJack F Vogel struct ixl_tx_buf {
28661ae650dSJack F Vogel 	u32		eop_index;
28761ae650dSJack F Vogel 	struct mbuf	*m_head;
28861ae650dSJack F Vogel 	bus_dmamap_t	map;
28961ae650dSJack F Vogel 	bus_dma_tag_t	tag;
29061ae650dSJack F Vogel };
29161ae650dSJack F Vogel 
29261ae650dSJack F Vogel struct ixl_rx_buf {
29361ae650dSJack F Vogel 	struct mbuf	*m_head;
29461ae650dSJack F Vogel 	struct mbuf	*m_pack;
29561ae650dSJack F Vogel 	struct mbuf	*fmp;
29661ae650dSJack F Vogel 	bus_dmamap_t	hmap;
29761ae650dSJack F Vogel 	bus_dmamap_t	pmap;
29861ae650dSJack F Vogel #ifdef DEV_NETMAP
29961ae650dSJack F Vogel 	u64		addr;
30061ae650dSJack F Vogel #endif
30161ae650dSJack F Vogel };
30261ae650dSJack F Vogel 
30361ae650dSJack F Vogel /*
30461ae650dSJack F Vogel ** This struct has multiple uses, multicast
30561ae650dSJack F Vogel ** addresses, vlans, and mac filters all use it.
30661ae650dSJack F Vogel */
30761ae650dSJack F Vogel struct ixl_mac_filter {
30861ae650dSJack F Vogel 	SLIST_ENTRY(ixl_mac_filter) next;
30961ae650dSJack F Vogel 	u8	macaddr[ETHER_ADDR_LEN];
31061ae650dSJack F Vogel 	s16	vlan;
31161ae650dSJack F Vogel 	u16	flags;
31261ae650dSJack F Vogel };
31361ae650dSJack F Vogel 
31461ae650dSJack F Vogel 
31561ae650dSJack F Vogel /*
31661ae650dSJack F Vogel  * The Transmit ring control struct
31761ae650dSJack F Vogel  */
31861ae650dSJack F Vogel struct tx_ring {
31961ae650dSJack F Vogel         struct ixl_queue	*que;
32061ae650dSJack F Vogel 	struct mtx		mtx;
32161ae650dSJack F Vogel 	u32			tail;
32261ae650dSJack F Vogel 	struct i40e_tx_desc	*base;
32361ae650dSJack F Vogel 	struct i40e_dma_mem	dma;
32461ae650dSJack F Vogel 	u16			next_avail;
32561ae650dSJack F Vogel 	u16			next_to_clean;
32661ae650dSJack F Vogel 	u16			atr_rate;
32761ae650dSJack F Vogel 	u16			atr_count;
32861ae650dSJack F Vogel 	u16			itr;
32961ae650dSJack F Vogel 	u16			latency;
33061ae650dSJack F Vogel 	struct ixl_tx_buf	*buffers;
33161ae650dSJack F Vogel 	volatile u16		avail;
33261ae650dSJack F Vogel 	u32			cmd;
33361ae650dSJack F Vogel 	bus_dma_tag_t		tx_tag;
33461ae650dSJack F Vogel 	bus_dma_tag_t		tso_tag;
33561ae650dSJack F Vogel 	char			mtx_name[16];
33661ae650dSJack F Vogel 	struct buf_ring		*br;
33761ae650dSJack F Vogel 
33861ae650dSJack F Vogel 	/* Used for Dynamic ITR calculation */
33961ae650dSJack F Vogel 	u32			packets;
34061ae650dSJack F Vogel 	u32 			bytes;
34161ae650dSJack F Vogel 
34261ae650dSJack F Vogel 	/* Soft Stats */
34361ae650dSJack F Vogel 	u64			tx_bytes;
34461ae650dSJack F Vogel 	u64			no_desc;
34561ae650dSJack F Vogel 	u64			total_packets;
34661ae650dSJack F Vogel };
34761ae650dSJack F Vogel 
34861ae650dSJack F Vogel 
34961ae650dSJack F Vogel /*
35061ae650dSJack F Vogel  * The Receive ring control struct
35161ae650dSJack F Vogel  */
35261ae650dSJack F Vogel struct rx_ring {
35361ae650dSJack F Vogel         struct ixl_queue	*que;
35461ae650dSJack F Vogel 	struct mtx		mtx;
35561ae650dSJack F Vogel 	union i40e_rx_desc	*base;
35661ae650dSJack F Vogel 	struct i40e_dma_mem	dma;
35761ae650dSJack F Vogel 	struct lro_ctrl		lro;
35861ae650dSJack F Vogel 	bool			lro_enabled;
35961ae650dSJack F Vogel 	bool			hdr_split;
36061ae650dSJack F Vogel 	bool			discard;
36161ae650dSJack F Vogel         u16			next_refresh;
36261ae650dSJack F Vogel         u16 			next_check;
36361ae650dSJack F Vogel 	u16			itr;
36461ae650dSJack F Vogel 	u16			latency;
36561ae650dSJack F Vogel 	char			mtx_name[16];
36661ae650dSJack F Vogel 	struct ixl_rx_buf	*buffers;
36761ae650dSJack F Vogel 	u32			mbuf_sz;
36861ae650dSJack F Vogel 	u32			tail;
36961ae650dSJack F Vogel 	bus_dma_tag_t		htag;
37061ae650dSJack F Vogel 	bus_dma_tag_t		ptag;
37161ae650dSJack F Vogel 
37261ae650dSJack F Vogel 	/* Used for Dynamic ITR calculation */
37361ae650dSJack F Vogel 	u32			packets;
37461ae650dSJack F Vogel 	u32 			bytes;
37561ae650dSJack F Vogel 
37661ae650dSJack F Vogel 	/* Soft stats */
37761ae650dSJack F Vogel 	u64			split;
37861ae650dSJack F Vogel 	u64			rx_packets;
37961ae650dSJack F Vogel 	u64 			rx_bytes;
38061ae650dSJack F Vogel 	u64 			discarded;
38161ae650dSJack F Vogel 	u64 			not_done;
38261ae650dSJack F Vogel };
38361ae650dSJack F Vogel 
38461ae650dSJack F Vogel /*
38561ae650dSJack F Vogel ** Driver queue struct: this is the interrupt container
38661ae650dSJack F Vogel **  for the associated tx and rx ring pair.
38761ae650dSJack F Vogel */
38861ae650dSJack F Vogel struct ixl_queue {
38961ae650dSJack F Vogel 	struct ixl_vsi		*vsi;
39061ae650dSJack F Vogel 	u32			me;
39161ae650dSJack F Vogel 	u32			msix;           /* This queue's MSIX vector */
39261ae650dSJack F Vogel 	u32			eims;           /* This queue's EIMS bit */
39361ae650dSJack F Vogel 	struct resource		*res;
39461ae650dSJack F Vogel 	void			*tag;
39561ae650dSJack F Vogel 	int			num_desc;	/* both tx and rx */
39661ae650dSJack F Vogel 	int			busy;
39761ae650dSJack F Vogel 	struct tx_ring		txr;
39861ae650dSJack F Vogel 	struct rx_ring		rxr;
39961ae650dSJack F Vogel 	struct task		task;
40061ae650dSJack F Vogel 	struct task		tx_task;
40161ae650dSJack F Vogel 	struct taskqueue	*tq;
40261ae650dSJack F Vogel 
40361ae650dSJack F Vogel 	/* Queue stats */
40461ae650dSJack F Vogel 	u64			irqs;
40561ae650dSJack F Vogel 	u64			tso;
40661ae650dSJack F Vogel 	u64			mbuf_defrag_failed;
40761ae650dSJack F Vogel 	u64			mbuf_hdr_failed;
40861ae650dSJack F Vogel 	u64			mbuf_pkt_failed;
40961ae650dSJack F Vogel 	u64			tx_map_avail;
41061ae650dSJack F Vogel 	u64			tx_dma_setup;
41161ae650dSJack F Vogel 	u64			dropped_pkts;
41261ae650dSJack F Vogel };
41361ae650dSJack F Vogel 
41461ae650dSJack F Vogel /*
41561ae650dSJack F Vogel ** Virtual Station interface:
41661ae650dSJack F Vogel **	there would be one of these per traffic class/type
41761ae650dSJack F Vogel **	for now just one, and its embedded in the pf
41861ae650dSJack F Vogel */
41961ae650dSJack F Vogel SLIST_HEAD(ixl_ftl_head, ixl_mac_filter);
42061ae650dSJack F Vogel struct ixl_vsi {
42161ae650dSJack F Vogel 	void 			*back;
42261ae650dSJack F Vogel 	struct ifnet		*ifp;
42361ae650dSJack F Vogel 	struct device		*dev;
42461ae650dSJack F Vogel 	struct i40e_hw		*hw;
42561ae650dSJack F Vogel 	struct ifmedia		media;
42661ae650dSJack F Vogel 	u64			que_mask;
42761ae650dSJack F Vogel 	int			id;
42861ae650dSJack F Vogel 	u16			msix_base;	/* station base MSIX vector */
42961ae650dSJack F Vogel 	u16			num_queues;
43061ae650dSJack F Vogel 	u16			rx_itr_setting;
43161ae650dSJack F Vogel 	u16			tx_itr_setting;
43261ae650dSJack F Vogel 	struct ixl_queue	*queues;	/* head of queues */
43361ae650dSJack F Vogel 	bool			link_active;
43461ae650dSJack F Vogel 	u16			seid;
43561ae650dSJack F Vogel 	u16			max_frame_size;
43661ae650dSJack F Vogel 	u32			link_speed;
43761ae650dSJack F Vogel 	bool			link_up;
43861ae650dSJack F Vogel 	u32			fc; /* local flow ctrl setting */
43961ae650dSJack F Vogel 
44061ae650dSJack F Vogel 	/* MAC/VLAN Filter list */
44161ae650dSJack F Vogel 	struct ixl_ftl_head ftl;
44261ae650dSJack F Vogel 
44361ae650dSJack F Vogel 	struct i40e_aqc_vsi_properties_data info;
44461ae650dSJack F Vogel 
44561ae650dSJack F Vogel 	eventhandler_tag 	vlan_attach;
44661ae650dSJack F Vogel 	eventhandler_tag 	vlan_detach;
44761ae650dSJack F Vogel 	u16			num_vlans;
44861ae650dSJack F Vogel 
44961ae650dSJack F Vogel 	/* Per-VSI stats from hardware */
45061ae650dSJack F Vogel 	struct i40e_eth_stats	eth_stats;
45161ae650dSJack F Vogel 	struct i40e_eth_stats	eth_stats_offsets;
45261ae650dSJack F Vogel 	bool 			stat_offsets_loaded;
45361ae650dSJack F Vogel 
45461ae650dSJack F Vogel 	/* Driver statistics */
45561ae650dSJack F Vogel 	u64			hw_filters_del;
45661ae650dSJack F Vogel 	u64			hw_filters_add;
45761ae650dSJack F Vogel 
45861ae650dSJack F Vogel 	/* Misc. */
45961ae650dSJack F Vogel 	u64 			active_queues;
46061ae650dSJack F Vogel 	u64 			flags;
46161ae650dSJack F Vogel };
46261ae650dSJack F Vogel 
46361ae650dSJack F Vogel /*
46461ae650dSJack F Vogel ** Find the number of unrefreshed RX descriptors
46561ae650dSJack F Vogel */
46661ae650dSJack F Vogel static inline u16
46761ae650dSJack F Vogel ixl_rx_unrefreshed(struct ixl_queue *que)
46861ae650dSJack F Vogel {
46961ae650dSJack F Vogel         struct rx_ring	*rxr = &que->rxr;
47061ae650dSJack F Vogel 
47161ae650dSJack F Vogel 	if (rxr->next_check > rxr->next_refresh)
47261ae650dSJack F Vogel 		return (rxr->next_check - rxr->next_refresh - 1);
47361ae650dSJack F Vogel 	else
47461ae650dSJack F Vogel 		return ((que->num_desc + rxr->next_check) -
47561ae650dSJack F Vogel 		    rxr->next_refresh - 1);
47661ae650dSJack F Vogel }
47761ae650dSJack F Vogel 
47861ae650dSJack F Vogel /*
47961ae650dSJack F Vogel ** Find the next available unused filter
48061ae650dSJack F Vogel */
48161ae650dSJack F Vogel static inline struct ixl_mac_filter *
48261ae650dSJack F Vogel ixl_get_filter(struct ixl_vsi *vsi)
48361ae650dSJack F Vogel {
48461ae650dSJack F Vogel 	struct ixl_mac_filter  *f;
48561ae650dSJack F Vogel 
48661ae650dSJack F Vogel 	/* create a new empty filter */
48761ae650dSJack F Vogel 	f = malloc(sizeof(struct ixl_mac_filter),
48861ae650dSJack F Vogel 	    M_DEVBUF, M_NOWAIT | M_ZERO);
48961ae650dSJack F Vogel 	SLIST_INSERT_HEAD(&vsi->ftl, f, next);
49061ae650dSJack F Vogel 
49161ae650dSJack F Vogel 	return (f);
49261ae650dSJack F Vogel }
49361ae650dSJack F Vogel 
49461ae650dSJack F Vogel /*
49561ae650dSJack F Vogel ** Compare two ethernet addresses
49661ae650dSJack F Vogel */
49761ae650dSJack F Vogel static inline bool
49861ae650dSJack F Vogel cmp_etheraddr(u8 *ea1, u8 *ea2)
49961ae650dSJack F Vogel {
50061ae650dSJack F Vogel 	bool cmp = FALSE;
50161ae650dSJack F Vogel 
50261ae650dSJack F Vogel 	if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) &&
50361ae650dSJack F Vogel 	    (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) &&
50461ae650dSJack F Vogel 	    (ea1[4] == ea2[4]) && (ea1[5] == ea2[5]))
50561ae650dSJack F Vogel 		cmp = TRUE;
50661ae650dSJack F Vogel 
50761ae650dSJack F Vogel 	return (cmp);
50861ae650dSJack F Vogel }
50961ae650dSJack F Vogel 
51061ae650dSJack F Vogel /*
51161ae650dSJack F Vogel  * Info for stats sysctls
51261ae650dSJack F Vogel  */
51361ae650dSJack F Vogel struct ixl_sysctl_info {
51461ae650dSJack F Vogel 	u64	*stat;
51561ae650dSJack F Vogel 	char	*name;
51661ae650dSJack F Vogel 	char	*description;
51761ae650dSJack F Vogel };
51861ae650dSJack F Vogel 
51961ae650dSJack F Vogel extern int ixl_atr_rate;
52061ae650dSJack F Vogel 
52161ae650dSJack F Vogel /*
52261ae650dSJack F Vogel ** ixl_fw_version_str - format the FW and NVM version strings
52361ae650dSJack F Vogel */
52461ae650dSJack F Vogel static inline char *
52561ae650dSJack F Vogel ixl_fw_version_str(struct i40e_hw *hw)
52661ae650dSJack F Vogel {
52761ae650dSJack F Vogel 	static char buf[32];
52861ae650dSJack F Vogel 
52961ae650dSJack F Vogel 	snprintf(buf, sizeof(buf),
53061ae650dSJack F Vogel 	    "f%d.%d a%d.%d n%02x.%02x e%08x",
53161ae650dSJack F Vogel 	    hw->aq.fw_maj_ver, hw->aq.fw_min_ver,
53261ae650dSJack F Vogel 	    hw->aq.api_maj_ver, hw->aq.api_min_ver,
53361ae650dSJack F Vogel 	    (hw->nvm.version & IXL_NVM_VERSION_HI_MASK) >>
53461ae650dSJack F Vogel 	    IXL_NVM_VERSION_HI_SHIFT,
53561ae650dSJack F Vogel 	    (hw->nvm.version & IXL_NVM_VERSION_LO_MASK) >>
53661ae650dSJack F Vogel 	    IXL_NVM_VERSION_LO_SHIFT,
53761ae650dSJack F Vogel 	    hw->nvm.eetrack);
53861ae650dSJack F Vogel 	return buf;
53961ae650dSJack F Vogel }
54061ae650dSJack F Vogel 
54161ae650dSJack F Vogel /*********************************************************************
54261ae650dSJack F Vogel  *  TXRX Function prototypes
54361ae650dSJack F Vogel  *********************************************************************/
54461ae650dSJack F Vogel int	ixl_allocate_tx_data(struct ixl_queue *);
54561ae650dSJack F Vogel int	ixl_allocate_rx_data(struct ixl_queue *);
54661ae650dSJack F Vogel void	ixl_init_tx_ring(struct ixl_queue *);
54761ae650dSJack F Vogel int	ixl_init_rx_ring(struct ixl_queue *);
54861ae650dSJack F Vogel bool	ixl_rxeof(struct ixl_queue *, int);
54961ae650dSJack F Vogel bool	ixl_txeof(struct ixl_queue *);
55061ae650dSJack F Vogel int	ixl_mq_start(struct ifnet *, struct mbuf *);
55161ae650dSJack F Vogel int	ixl_mq_start_locked(struct ifnet *, struct tx_ring *);
55261ae650dSJack F Vogel void	ixl_deferred_mq_start(void *, int);
55361ae650dSJack F Vogel void	ixl_qflush(struct ifnet *);
55461ae650dSJack F Vogel void	ixl_free_vsi(struct ixl_vsi *);
55561ae650dSJack F Vogel void	ixl_free_que_tx(struct ixl_queue *);
55661ae650dSJack F Vogel void	ixl_free_que_rx(struct ixl_queue *);
55761ae650dSJack F Vogel #ifdef IXL_FDIR
55861ae650dSJack F Vogel void	ixl_atr(struct ixl_queue *, struct tcphdr *, int);
55961ae650dSJack F Vogel #endif
56061ae650dSJack F Vogel 
56161ae650dSJack F Vogel #endif /* _IXL_H_ */
562