xref: /freebsd/sys/dev/ixl/ixl.h (revision ceebc2f348c028b21bf9bcc99f7a3c4b0cb7d926)
161ae650dSJack F Vogel /******************************************************************************
261ae650dSJack F Vogel 
3*ceebc2f3SEric Joyner   Copyright (c) 2013-2017, 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 
39f7c73984SSean Bruno #include "opt_inet.h"
40f7c73984SSean Bruno #include "opt_inet6.h"
41f7c73984SSean Bruno #include "opt_rss.h"
42cb6b8299SEric Joyner #include "opt_ixl.h"
43f7c73984SSean Bruno 
4461ae650dSJack F Vogel #include <sys/param.h>
4561ae650dSJack F Vogel #include <sys/systm.h>
4661ae650dSJack F Vogel #include <sys/buf_ring.h>
4761ae650dSJack F Vogel #include <sys/mbuf.h>
4861ae650dSJack F Vogel #include <sys/protosw.h>
4961ae650dSJack F Vogel #include <sys/socket.h>
5061ae650dSJack F Vogel #include <sys/malloc.h>
5161ae650dSJack F Vogel #include <sys/kernel.h>
5261ae650dSJack F Vogel #include <sys/module.h>
5361ae650dSJack F Vogel #include <sys/sockio.h>
5413b40804SSteven Hartland #include <sys/eventhandler.h>
55cb6b8299SEric Joyner #include <sys/syslog.h>
5661ae650dSJack F Vogel 
5761ae650dSJack F Vogel #include <net/if.h>
5813b40804SSteven Hartland #include <net/if_var.h>
5961ae650dSJack F Vogel #include <net/if_arp.h>
6061ae650dSJack F Vogel #include <net/bpf.h>
6161ae650dSJack F Vogel #include <net/ethernet.h>
6261ae650dSJack F Vogel #include <net/if_dl.h>
6361ae650dSJack F Vogel #include <net/if_media.h>
6461ae650dSJack F Vogel 
6561ae650dSJack F Vogel #include <net/bpf.h>
6661ae650dSJack F Vogel #include <net/if_types.h>
6761ae650dSJack F Vogel #include <net/if_vlan_var.h>
6861ae650dSJack F Vogel 
6961ae650dSJack F Vogel #include <netinet/in_systm.h>
7061ae650dSJack F Vogel #include <netinet/in.h>
7161ae650dSJack F Vogel #include <netinet/if_ether.h>
7261ae650dSJack F Vogel #include <netinet/ip.h>
7361ae650dSJack F Vogel #include <netinet/ip6.h>
7461ae650dSJack F Vogel #include <netinet/tcp.h>
7561ae650dSJack F Vogel #include <netinet/tcp_lro.h>
7661ae650dSJack F Vogel #include <netinet/udp.h>
7761ae650dSJack F Vogel #include <netinet/sctp.h>
7861ae650dSJack F Vogel 
7961ae650dSJack F Vogel #include <machine/in_cksum.h>
8061ae650dSJack F Vogel 
8161ae650dSJack F Vogel #include <sys/bus.h>
8261ae650dSJack F Vogel #include <machine/bus.h>
8361ae650dSJack F Vogel #include <sys/rman.h>
8461ae650dSJack F Vogel #include <machine/resource.h>
8561ae650dSJack F Vogel #include <vm/vm.h>
8661ae650dSJack F Vogel #include <vm/pmap.h>
8761ae650dSJack F Vogel #include <machine/clock.h>
8861ae650dSJack F Vogel #include <dev/pci/pcivar.h>
8961ae650dSJack F Vogel #include <dev/pci/pcireg.h>
9061ae650dSJack F Vogel #include <sys/proc.h>
9161ae650dSJack F Vogel #include <sys/sysctl.h>
9261ae650dSJack F Vogel #include <sys/endian.h>
9361ae650dSJack F Vogel #include <sys/taskqueue.h>
9461ae650dSJack F Vogel #include <sys/pcpu.h>
9561ae650dSJack F Vogel #include <sys/smp.h>
961d767a8eSEric Joyner #include <sys/sbuf.h>
9761ae650dSJack F Vogel #include <machine/smp.h>
984294f337SSean Bruno #include <machine/stdarg.h>
9961ae650dSJack F Vogel 
1004294f337SSean Bruno #ifdef RSS
1014294f337SSean Bruno #include <net/rss_config.h>
102f7c73984SSean Bruno #include <netinet/in_rss.h>
10356c2c47bSJack F Vogel #endif
10456c2c47bSJack F Vogel 
10561ae650dSJack F Vogel #include "i40e_type.h"
10661ae650dSJack F Vogel #include "i40e_prototype.h"
10761ae650dSJack F Vogel 
10861ae650dSJack F Vogel #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x"
10961ae650dSJack F Vogel #define MAC_FORMAT_ARGS(mac_addr) \
11061ae650dSJack F Vogel 	(mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \
11161ae650dSJack F Vogel 	(mac_addr)[4], (mac_addr)[5]
11261ae650dSJack F Vogel #define ON_OFF_STR(is_set) ((is_set) ? "On" : "Off")
11361ae650dSJack F Vogel 
114393c4bb1SJack F Vogel #ifdef IXL_DEBUG
11561ae650dSJack F Vogel 
11661ae650dSJack F Vogel #define _DBG_PRINTF(S, ...)		printf("%s: " S "\n", __func__, ##__VA_ARGS__)
11761ae650dSJack F Vogel #define _DEV_DBG_PRINTF(dev, S, ...)	device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__)
11861ae650dSJack F Vogel #define _IF_DBG_PRINTF(ifp, S, ...)	if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__)
11961ae650dSJack F Vogel 
12061ae650dSJack F Vogel /* Defines for printing generic debug information */
12161ae650dSJack F Vogel #define DPRINTF(...)			_DBG_PRINTF(__VA_ARGS__)
12261ae650dSJack F Vogel #define DDPRINTF(...)			_DEV_DBG_PRINTF(__VA_ARGS__)
12361ae650dSJack F Vogel #define IDPRINTF(...)			_IF_DBG_PRINTF(__VA_ARGS__)
12461ae650dSJack F Vogel 
12561ae650dSJack F Vogel /* Defines for printing specific debug information */
12661ae650dSJack F Vogel #define DEBUG_INIT  1
12761ae650dSJack F Vogel #define DEBUG_IOCTL 1
12861ae650dSJack F Vogel #define DEBUG_HW    1
12961ae650dSJack F Vogel 
13061ae650dSJack F Vogel #define INIT_DEBUGOUT(...)		if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__)
13161ae650dSJack F Vogel #define INIT_DBG_DEV(...)		if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__)
13261ae650dSJack F Vogel #define INIT_DBG_IF(...)		if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__)
13361ae650dSJack F Vogel 
13461ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...)		if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__)
13561ae650dSJack F Vogel #define IOCTL_DBG_IF2(ifp, S, ...)	if (DEBUG_IOCTL) \
13661ae650dSJack F Vogel 					    if_printf(ifp, S "\n", ##__VA_ARGS__)
13761ae650dSJack F Vogel #define IOCTL_DBG_IF(...)		if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__)
13861ae650dSJack F Vogel 
13961ae650dSJack F Vogel #define HW_DEBUGOUT(...)		if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__)
14061ae650dSJack F Vogel 
141393c4bb1SJack F Vogel #else /* no IXL_DEBUG */
14261ae650dSJack F Vogel #define DEBUG_INIT  0
14361ae650dSJack F Vogel #define DEBUG_IOCTL 0
14461ae650dSJack F Vogel #define DEBUG_HW    0
14561ae650dSJack F Vogel 
14661ae650dSJack F Vogel #define DPRINTF(...)
14761ae650dSJack F Vogel #define DDPRINTF(...)
14861ae650dSJack F Vogel #define IDPRINTF(...)
14961ae650dSJack F Vogel 
15061ae650dSJack F Vogel #define INIT_DEBUGOUT(...)
15161ae650dSJack F Vogel #define INIT_DBG_DEV(...)
15261ae650dSJack F Vogel #define INIT_DBG_IF(...)
15361ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...)
15461ae650dSJack F Vogel #define IOCTL_DBG_IF2(...)
15561ae650dSJack F Vogel #define IOCTL_DBG_IF(...)
15661ae650dSJack F Vogel #define HW_DEBUGOUT(...)
157393c4bb1SJack F Vogel #endif /* IXL_DEBUG */
15861ae650dSJack F Vogel 
1594294f337SSean Bruno enum ixl_dbg_mask {
1604294f337SSean Bruno 	IXL_DBG_INFO			= 0x00000001,
1614294f337SSean Bruno 	IXL_DBG_EN_DIS			= 0x00000002,
1624294f337SSean Bruno 	IXL_DBG_AQ			= 0x00000004,
1634294f337SSean Bruno 	IXL_DBG_NVMUPD			= 0x00000008,
1644294f337SSean Bruno 
1654294f337SSean Bruno 	IXL_DBG_IOCTL_KNOWN		= 0x00000010,
1664294f337SSean Bruno 	IXL_DBG_IOCTL_UNKNOWN		= 0x00000020,
1674294f337SSean Bruno 	IXL_DBG_IOCTL_ALL		= 0x00000030,
1684294f337SSean Bruno 
1694294f337SSean Bruno 	I40E_DEBUG_RSS			= 0x00000100,
1704294f337SSean Bruno 
1714294f337SSean Bruno 	IXL_DBG_IOV			= 0x00001000,
1724294f337SSean Bruno 	IXL_DBG_IOV_VC			= 0x00002000,
1734294f337SSean Bruno 
1744294f337SSean Bruno 	IXL_DBG_SWITCH_INFO		= 0x00010000,
175cb6b8299SEric Joyner 	IXL_DBG_I2C			= 0x00020000,
1764294f337SSean Bruno 
1774294f337SSean Bruno 	IXL_DBG_ALL			= 0xFFFFFFFF
1784294f337SSean Bruno };
1794294f337SSean Bruno 
18061ae650dSJack F Vogel /* Tunables */
18161ae650dSJack F Vogel 
18261ae650dSJack F Vogel /*
18361ae650dSJack F Vogel  * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the
18461ae650dSJack F Vogel  * number of tx/rx descriptors allocated by the driver. Increasing this
1856c426059SEric Joyner  * value allows the driver to queue more operations.
1866c426059SEric Joyner  *
1876c426059SEric Joyner  * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes.
1886c426059SEric Joyner  * The driver currently always uses 32 byte Rx descriptors.
18961ae650dSJack F Vogel  */
190cb6b8299SEric Joyner #define IXL_DEFAULT_RING	1024
191*ceebc2f3SEric Joyner #define IXL_MAX_RING		4096
192*ceebc2f3SEric Joyner #define IXL_MIN_RING		64
1934294f337SSean Bruno #define IXL_RING_INCREMENT	32
1944294f337SSean Bruno 
1954294f337SSean Bruno #define IXL_AQ_LEN		256
1964294f337SSean Bruno #define IXL_AQ_LEN_MAX		1024
19761ae650dSJack F Vogel 
19861ae650dSJack F Vogel /*
19961ae650dSJack F Vogel ** Default number of entries in Tx queue buf_ring.
20061ae650dSJack F Vogel */
2014294f337SSean Bruno #define DEFAULT_TXBRSZ		4096
20261ae650dSJack F Vogel 
20361ae650dSJack F Vogel /* Alignment for rings */
20461ae650dSJack F Vogel #define DBA_ALIGN		128
20561ae650dSJack F Vogel 
20661ae650dSJack F Vogel /*
20761ae650dSJack F Vogel  * This is the max watchdog interval, ie. the time that can
20861ae650dSJack F Vogel  * pass between any two TX clean operations, such only happening
20961ae650dSJack F Vogel  * when the TX hardware is functioning.
210*ceebc2f3SEric Joyner  *
211*ceebc2f3SEric Joyner  * XXX: Watchdog currently counts down in units of (hz)
212*ceebc2f3SEric Joyner  * Set this to just (hz) if you want queues to hang under a little bit of stress
21361ae650dSJack F Vogel  */
21461ae650dSJack F Vogel #define IXL_WATCHDOG		(10 * hz)
21561ae650dSJack F Vogel 
21661ae650dSJack F Vogel /*
21761ae650dSJack F Vogel  * This parameters control when the driver calls the routine to reclaim
21861ae650dSJack F Vogel  * transmit descriptors.
21961ae650dSJack F Vogel  */
220*ceebc2f3SEric Joyner #define IXL_TX_CLEANUP_THRESHOLD	(que->num_tx_desc / 8)
221*ceebc2f3SEric Joyner #define IXL_TX_OP_THRESHOLD		(que->num_tx_desc / 32)
22261ae650dSJack F Vogel 
22361ae650dSJack F Vogel #define MAX_MULTICAST_ADDR	128
22461ae650dSJack F Vogel 
225cb6b8299SEric Joyner #define IXL_MSIX_BAR		3
22661ae650dSJack F Vogel #define IXL_ADM_LIMIT		2
22761ae650dSJack F Vogel #define IXL_TSO_SIZE		65535
22861ae650dSJack F Vogel #define IXL_AQ_BUF_SZ		((u32) 4096)
22961ae650dSJack F Vogel #define IXL_RX_HDR		128
23061ae650dSJack F Vogel #define IXL_RX_LIMIT		512
23161ae650dSJack F Vogel #define IXL_RX_ITR		0
23261ae650dSJack F Vogel #define IXL_TX_ITR		1
23361ae650dSJack F Vogel #define IXL_ITR_NONE		3
23461ae650dSJack F Vogel #define IXL_QUEUE_EOL		0x7FF
2356c426059SEric Joyner #define IXL_MAX_FRAME		9728
23661ae650dSJack F Vogel #define IXL_MAX_TX_SEGS		8
2374294f337SSean Bruno #define IXL_MAX_TSO_SEGS	128
238*ceebc2f3SEric Joyner #define IXL_SPARSE_CHAIN	7
23961ae650dSJack F Vogel #define IXL_QUEUE_HUNG		0x80000000
240cb6b8299SEric Joyner #define IXL_MIN_TSO_MSS		64
241*ceebc2f3SEric Joyner #define IXL_MAX_DMA_SEG_SIZE	((16 * 1024) - 1)
2424294f337SSean Bruno 
2434294f337SSean Bruno #define IXL_RSS_KEY_SIZE_REG		13
2444294f337SSean Bruno #define IXL_RSS_KEY_SIZE		(IXL_RSS_KEY_SIZE_REG * 4)
2454294f337SSean Bruno #define IXL_RSS_VSI_LUT_SIZE		64	/* X722 -> VSI, X710 -> VF */
2464294f337SSean Bruno #define IXL_RSS_VSI_LUT_ENTRY_MASK	0x3F
2474294f337SSean Bruno #define IXL_RSS_VF_LUT_ENTRY_MASK	0xF
24861ae650dSJack F Vogel 
24956c2c47bSJack F Vogel #define IXL_VF_MAX_BUFFER	0x3F80
25056c2c47bSJack F Vogel #define IXL_VF_MAX_HDR_BUFFER	0x840
25156c2c47bSJack F Vogel #define IXL_VF_MAX_FRAME	0x3FFF
25256c2c47bSJack F Vogel 
2534294f337SSean Bruno /* ERJ: hardware can support ~2k (SW5+) filters between all functions */
25461ae650dSJack F Vogel #define IXL_MAX_FILTERS		256
25561ae650dSJack F Vogel #define IXL_MAX_TX_BUSY		10
25661ae650dSJack F Vogel 
25761ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_SHIFT	0
25861ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_MASK		(0xff << IXL_NVM_VERSION_LO_SHIFT)
25961ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_SHIFT	12
26061ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_MASK		(0xf << IXL_NVM_VERSION_HI_SHIFT)
26161ae650dSJack F Vogel 
26261ae650dSJack F Vogel /*
26361ae650dSJack F Vogel  * Interrupt Moderation parameters
264cb6b8299SEric Joyner  * Multiply ITR values by 2 for real ITR value
26561ae650dSJack F Vogel  */
266cb6b8299SEric Joyner #define IXL_MAX_ITR		0x0FF0
26761ae650dSJack F Vogel #define IXL_ITR_100K		0x0005
26861ae650dSJack F Vogel #define IXL_ITR_20K		0x0019
26961ae650dSJack F Vogel #define IXL_ITR_8K		0x003E
27061ae650dSJack F Vogel #define IXL_ITR_4K		0x007A
271cb6b8299SEric Joyner #define IXL_ITR_1K		0x01F4
27261ae650dSJack F Vogel #define IXL_ITR_DYNAMIC		0x8000
27361ae650dSJack F Vogel #define IXL_LOW_LATENCY		0
27461ae650dSJack F Vogel #define IXL_AVE_LATENCY		1
27561ae650dSJack F Vogel #define IXL_BULK_LATENCY	2
27661ae650dSJack F Vogel 
27761ae650dSJack F Vogel /* MacVlan Flags */
27861ae650dSJack F Vogel #define IXL_FILTER_USED		(u16)(1 << 0)
27961ae650dSJack F Vogel #define IXL_FILTER_VLAN		(u16)(1 << 1)
28061ae650dSJack F Vogel #define IXL_FILTER_ADD		(u16)(1 << 2)
28161ae650dSJack F Vogel #define IXL_FILTER_DEL		(u16)(1 << 3)
28261ae650dSJack F Vogel #define IXL_FILTER_MC		(u16)(1 << 4)
28361ae650dSJack F Vogel 
28461ae650dSJack F Vogel /* used in the vlan field of the filter when not a vlan */
28561ae650dSJack F Vogel #define IXL_VLAN_ANY		-1
28661ae650dSJack F Vogel 
28761ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV4	(CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP)
28861ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV6	(CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6)
28961ae650dSJack F Vogel #define CSUM_OFFLOAD		(CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO)
29061ae650dSJack F Vogel 
29161ae650dSJack F Vogel /* Misc flags for ixl_vsi.flags */
29261ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO4	(1 << 0)
29361ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO6	(1 << 1)
294*ceebc2f3SEric Joyner #define IXL_FLAGS_USES_MSIX	(1 << 2)
295*ceebc2f3SEric Joyner #define IXL_FLAGS_IS_VF		(1 << 3)
29661ae650dSJack F Vogel 
29756c2c47bSJack F Vogel #define IXL_VF_RESET_TIMEOUT	100
29856c2c47bSJack F Vogel 
29956c2c47bSJack F Vogel #define IXL_VSI_DATA_PORT	0x01
30056c2c47bSJack F Vogel 
30156c2c47bSJack F Vogel #define IXLV_MAX_QUEUES		16
30256c2c47bSJack F Vogel #define IXL_MAX_VSI_QUEUES	(2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1))
30356c2c47bSJack F Vogel 
30456c2c47bSJack F Vogel #define IXL_RX_CTX_BASE_UNITS	128
30556c2c47bSJack F Vogel #define IXL_TX_CTX_BASE_UNITS	128
30656c2c47bSJack F Vogel 
30756c2c47bSJack F Vogel #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \
30856c2c47bSJack F Vogel 	I40E_VPINT_LNKLSTN(((vector) - 1) + \
30956c2c47bSJack F Vogel 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
31056c2c47bSJack F Vogel 
31156c2c47bSJack F Vogel #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \
31256c2c47bSJack F Vogel 	I40E_VFINT_DYN_CTLN(((vector) - 1) + \
31356c2c47bSJack F Vogel 	    (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num)))
31456c2c47bSJack F Vogel 
31556c2c47bSJack F Vogel #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS	0xAA
31656c2c47bSJack F Vogel 
31756c2c47bSJack F Vogel #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK	0x20
31856c2c47bSJack F Vogel 
31956c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf)	((glb_vf) / 32)
32056c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf)	(1 << ((glb_vf) % 32))
32156c2c47bSJack F Vogel 
32256c2c47bSJack F Vogel #define IXL_MAX_ITR_IDX		3
32356c2c47bSJack F Vogel 
32456c2c47bSJack F Vogel #define IXL_END_OF_INTR_LNKLST	0x7FF
32556c2c47bSJack F Vogel 
326cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_BASE (\
3274294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) |	\
3284294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) |	\
3294294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) |	\
3304294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) |	\
3314294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) |		\
3324294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) |	\
3334294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) |	\
3344294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) |	\
3354294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) |	\
3364294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) |		\
3374294f337SSean Bruno 	BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD))
3384294f337SSean Bruno 
339cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_XL710	IXL_DEFAULT_RSS_HENA_BASE
340cb6b8299SEric Joyner 
341cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_X722 (\
342cb6b8299SEric Joyner 	IXL_DEFAULT_RSS_HENA_BASE |			\
343cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \
344cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \
345cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
346cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | \
347cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \
348cb6b8299SEric Joyner 	BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK))
349cb6b8299SEric Joyner 
35061ae650dSJack F Vogel #define IXL_TX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
35161ae650dSJack F Vogel #define IXL_TX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
35261ae650dSJack F Vogel #define IXL_TX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
35361ae650dSJack F Vogel #define IXL_TX_TRYLOCK(_sc)             mtx_trylock(&(_sc)->mtx)
35461ae650dSJack F Vogel #define IXL_TX_LOCK_ASSERT(_sc)         mtx_assert(&(_sc)->mtx, MA_OWNED)
35561ae650dSJack F Vogel 
35661ae650dSJack F Vogel #define IXL_RX_LOCK(_sc)                mtx_lock(&(_sc)->mtx)
35761ae650dSJack F Vogel #define IXL_RX_UNLOCK(_sc)              mtx_unlock(&(_sc)->mtx)
35861ae650dSJack F Vogel #define IXL_RX_LOCK_DESTROY(_sc)        mtx_destroy(&(_sc)->mtx)
35961ae650dSJack F Vogel 
360a48d00d2SEric Joyner /* Pre-11 counter(9) compatibility */
361b6c8f260SJack F Vogel #if __FreeBSD_version >= 1100036
3624b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count)	(vsi)->ipackets = (count)
3634b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count)	(vsi)->ierrors = (count)
3644b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count)	(vsi)->opackets = (count)
3654b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count)	(vsi)->oerrors = (count)
3664b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count)	/* Do nothing; collisions is always 0. */
3674b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count)	(vsi)->ibytes = (count)
3684b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count)	(vsi)->obytes = (count)
3694b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count)	(vsi)->imcasts = (count)
3704b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count)	(vsi)->omcasts = (count)
3714b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count)	(vsi)->iqdrops = (count)
372625d12c6SJohn Baldwin #define IXL_SET_OQDROPS(vsi, count)	(vsi)->oqdrops = (count)
3734b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count)	(vsi)->noproto = (count)
3744b443922SGleb Smirnoff #else
3754b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count)	(vsi)->ifp->if_ipackets = (count)
3764b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count)	(vsi)->ifp->if_ierrors = (count)
3774b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count)	(vsi)->ifp->if_opackets = (count)
3784b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count)	(vsi)->ifp->if_oerrors = (count)
3794b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count)	(vsi)->ifp->if_collisions = (count)
3804b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count)	(vsi)->ifp->if_ibytes = (count)
3814b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count)	(vsi)->ifp->if_obytes = (count)
3824b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count)	(vsi)->ifp->if_imcasts = (count)
3834b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count)	(vsi)->ifp->if_omcasts = (count)
3844b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count)	(vsi)->ifp->if_iqdrops = (count)
3854b443922SGleb Smirnoff #define IXL_SET_OQDROPS(vsi, odrops)	(vsi)->ifp->if_snd.ifq_drops = (odrops)
3864b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count)	(vsi)->noproto = (count)
3874b443922SGleb Smirnoff #endif
3884b443922SGleb Smirnoff 
38961ae650dSJack F Vogel /*
39061ae650dSJack F Vogel  *****************************************************************************
39161ae650dSJack F Vogel  * vendor_info_array
39261ae650dSJack F Vogel  *
39361ae650dSJack F Vogel  * This array contains the list of Subvendor/Subdevice IDs on which the driver
39461ae650dSJack F Vogel  * should load.
39561ae650dSJack F Vogel  *
39661ae650dSJack F Vogel  *****************************************************************************
39761ae650dSJack F Vogel  */
39861ae650dSJack F Vogel typedef struct _ixl_vendor_info_t {
39961ae650dSJack F Vogel 	unsigned int    vendor_id;
40061ae650dSJack F Vogel 	unsigned int    device_id;
40161ae650dSJack F Vogel 	unsigned int    subvendor_id;
40261ae650dSJack F Vogel 	unsigned int    subdevice_id;
40361ae650dSJack F Vogel 	unsigned int    index;
40461ae650dSJack F Vogel } ixl_vendor_info_t;
40561ae650dSJack F Vogel 
40661ae650dSJack F Vogel 
40761ae650dSJack F Vogel struct ixl_tx_buf {
40861ae650dSJack F Vogel 	u32		eop_index;
40961ae650dSJack F Vogel 	struct mbuf	*m_head;
41061ae650dSJack F Vogel 	bus_dmamap_t	map;
41161ae650dSJack F Vogel 	bus_dma_tag_t	tag;
41261ae650dSJack F Vogel };
41361ae650dSJack F Vogel 
41461ae650dSJack F Vogel struct ixl_rx_buf {
41561ae650dSJack F Vogel 	struct mbuf	*m_head;
41661ae650dSJack F Vogel 	struct mbuf	*m_pack;
41761ae650dSJack F Vogel 	struct mbuf	*fmp;
41861ae650dSJack F Vogel 	bus_dmamap_t	hmap;
41961ae650dSJack F Vogel 	bus_dmamap_t	pmap;
42061ae650dSJack F Vogel };
42161ae650dSJack F Vogel 
42261ae650dSJack F Vogel /*
42361ae650dSJack F Vogel ** This struct has multiple uses, multicast
42461ae650dSJack F Vogel ** addresses, vlans, and mac filters all use it.
42561ae650dSJack F Vogel */
42661ae650dSJack F Vogel struct ixl_mac_filter {
42761ae650dSJack F Vogel 	SLIST_ENTRY(ixl_mac_filter) next;
42861ae650dSJack F Vogel 	u8	macaddr[ETHER_ADDR_LEN];
42961ae650dSJack F Vogel 	s16	vlan;
43061ae650dSJack F Vogel 	u16	flags;
43161ae650dSJack F Vogel };
43261ae650dSJack F Vogel 
43361ae650dSJack F Vogel /*
43461ae650dSJack F Vogel  * The Transmit ring control struct
43561ae650dSJack F Vogel  */
43661ae650dSJack F Vogel struct tx_ring {
43761ae650dSJack F Vogel         struct ixl_queue	*que;
43861ae650dSJack F Vogel 	struct mtx		mtx;
43961ae650dSJack F Vogel 	u32			tail;
44061ae650dSJack F Vogel 	struct i40e_tx_desc	*base;
44161ae650dSJack F Vogel 	struct i40e_dma_mem	dma;
44261ae650dSJack F Vogel 	u16			next_avail;
44361ae650dSJack F Vogel 	u16			next_to_clean;
44461ae650dSJack F Vogel 	u16			atr_rate;
44561ae650dSJack F Vogel 	u16			atr_count;
4466d011ad5SEric Joyner 	u32			itr;
4476d011ad5SEric Joyner 	u32			latency;
44861ae650dSJack F Vogel 	struct ixl_tx_buf	*buffers;
44961ae650dSJack F Vogel 	volatile u16		avail;
45061ae650dSJack F Vogel 	u32			cmd;
45161ae650dSJack F Vogel 	bus_dma_tag_t		tx_tag;
45261ae650dSJack F Vogel 	bus_dma_tag_t		tso_tag;
45361ae650dSJack F Vogel 	char			mtx_name[16];
45461ae650dSJack F Vogel 	struct buf_ring		*br;
455cb6b8299SEric Joyner 	s32			watchdog_timer;
45661ae650dSJack F Vogel 
45761ae650dSJack F Vogel 	/* Used for Dynamic ITR calculation */
45861ae650dSJack F Vogel 	u32			packets;
45961ae650dSJack F Vogel 	u32 			bytes;
46061ae650dSJack F Vogel 
46161ae650dSJack F Vogel 	/* Soft Stats */
46261ae650dSJack F Vogel 	u64			tx_bytes;
46361ae650dSJack F Vogel 	u64			no_desc;
46461ae650dSJack F Vogel 	u64			total_packets;
46561ae650dSJack F Vogel };
46661ae650dSJack F Vogel 
46761ae650dSJack F Vogel 
46861ae650dSJack F Vogel /*
46961ae650dSJack F Vogel  * The Receive ring control struct
47061ae650dSJack F Vogel  */
47161ae650dSJack F Vogel struct rx_ring {
47261ae650dSJack F Vogel         struct ixl_queue	*que;
47361ae650dSJack F Vogel 	struct mtx		mtx;
47461ae650dSJack F Vogel 	union i40e_rx_desc	*base;
47561ae650dSJack F Vogel 	struct i40e_dma_mem	dma;
47661ae650dSJack F Vogel 	struct lro_ctrl		lro;
47761ae650dSJack F Vogel 	bool			lro_enabled;
47861ae650dSJack F Vogel 	bool			hdr_split;
47961ae650dSJack F Vogel 	bool			discard;
4806d011ad5SEric Joyner         u32			next_refresh;
4816d011ad5SEric Joyner         u32 			next_check;
4826d011ad5SEric Joyner 	u32			itr;
4836d011ad5SEric Joyner 	u32			latency;
48461ae650dSJack F Vogel 	char			mtx_name[16];
48561ae650dSJack F Vogel 	struct ixl_rx_buf	*buffers;
48661ae650dSJack F Vogel 	u32			mbuf_sz;
48761ae650dSJack F Vogel 	u32			tail;
48861ae650dSJack F Vogel 	bus_dma_tag_t		htag;
48961ae650dSJack F Vogel 	bus_dma_tag_t		ptag;
49061ae650dSJack F Vogel 
49161ae650dSJack F Vogel 	/* Used for Dynamic ITR calculation */
49261ae650dSJack F Vogel 	u32			packets;
49361ae650dSJack F Vogel 	u32 			bytes;
49461ae650dSJack F Vogel 
49561ae650dSJack F Vogel 	/* Soft stats */
49661ae650dSJack F Vogel 	u64			split;
49761ae650dSJack F Vogel 	u64			rx_packets;
49861ae650dSJack F Vogel 	u64 			rx_bytes;
4996d011ad5SEric Joyner 	u64 			desc_errs;
50061ae650dSJack F Vogel 	u64 			not_done;
50161ae650dSJack F Vogel };
50261ae650dSJack F Vogel 
50361ae650dSJack F Vogel /*
50461ae650dSJack F Vogel ** Driver queue struct: this is the interrupt container
50561ae650dSJack F Vogel **  for the associated tx and rx ring pair.
50661ae650dSJack F Vogel */
50761ae650dSJack F Vogel struct ixl_queue {
50861ae650dSJack F Vogel 	struct ixl_vsi		*vsi;
50961ae650dSJack F Vogel 	u32			me;
51061ae650dSJack F Vogel 	u32			msix;           /* This queue's MSIX vector */
51161ae650dSJack F Vogel 	u32			eims;           /* This queue's EIMS bit */
51261ae650dSJack F Vogel 	struct resource		*res;
51361ae650dSJack F Vogel 	void			*tag;
514*ceebc2f3SEric Joyner 	int			num_tx_desc;	/* both tx and rx */
515*ceebc2f3SEric Joyner 	int			num_rx_desc;	/* both tx and rx */
516*ceebc2f3SEric Joyner #ifdef DEV_NETMAP
517*ceebc2f3SEric Joyner 	int			num_desc;	/* for compatibility with current netmap code in kernel */
518*ceebc2f3SEric Joyner #endif
51961ae650dSJack F Vogel 	struct tx_ring		txr;
52061ae650dSJack F Vogel 	struct rx_ring		rxr;
52161ae650dSJack F Vogel 	struct task		task;
52261ae650dSJack F Vogel 	struct task		tx_task;
52361ae650dSJack F Vogel 	struct taskqueue	*tq;
52461ae650dSJack F Vogel 
52561ae650dSJack F Vogel 	/* Queue stats */
52661ae650dSJack F Vogel 	u64			irqs;
52761ae650dSJack F Vogel 	u64			tso;
52861ae650dSJack F Vogel 	u64			mbuf_defrag_failed;
52961ae650dSJack F Vogel 	u64			mbuf_hdr_failed;
53061ae650dSJack F Vogel 	u64			mbuf_pkt_failed;
5314294f337SSean Bruno 	u64			tx_dmamap_failed;
53261ae650dSJack F Vogel 	u64			dropped_pkts;
533cb6b8299SEric Joyner 	u64			mss_too_small;
53461ae650dSJack F Vogel };
53561ae650dSJack F Vogel 
53661ae650dSJack F Vogel /*
5374294f337SSean Bruno ** Virtual Station Interface
53861ae650dSJack F Vogel */
53961ae650dSJack F Vogel SLIST_HEAD(ixl_ftl_head, ixl_mac_filter);
54061ae650dSJack F Vogel struct ixl_vsi {
54161ae650dSJack F Vogel 	void 			*back;
54261ae650dSJack F Vogel 	struct ifnet		*ifp;
543bd937497SJean-Sébastien Pédron 	device_t		dev;
54461ae650dSJack F Vogel 	struct i40e_hw		*hw;
54561ae650dSJack F Vogel 	struct ifmedia		media;
546ac83ea83SEric Joyner 	enum i40e_vsi_type	type;
54761ae650dSJack F Vogel 	int			id;
54861ae650dSJack F Vogel 	u16			num_queues;
549*ceebc2f3SEric Joyner 	int			num_tx_desc;
550*ceebc2f3SEric Joyner 	int			num_rx_desc;
5516d011ad5SEric Joyner 	u32			rx_itr_setting;
5526d011ad5SEric Joyner 	u32			tx_itr_setting;
5534294f337SSean Bruno 	u16			max_frame_size;
554*ceebc2f3SEric Joyner 	bool			enable_head_writeback;
5554294f337SSean Bruno 
55661ae650dSJack F Vogel 	struct ixl_queue	*queues;	/* head of queues */
5574294f337SSean Bruno 
5584294f337SSean Bruno 	u16			vsi_num;
55961ae650dSJack F Vogel 	bool			link_active;
56061ae650dSJack F Vogel 	u16			seid;
56156c2c47bSJack F Vogel 	u16			uplink_seid;
56256c2c47bSJack F Vogel 	u16			downlink_seid;
56361ae650dSJack F Vogel 
56461ae650dSJack F Vogel 	/* MAC/VLAN Filter list */
56561ae650dSJack F Vogel 	struct ixl_ftl_head	ftl;
56656c2c47bSJack F Vogel 	u16			num_macs;
56761ae650dSJack F Vogel 
5684294f337SSean Bruno 	/* Contains readylist & stat counter id */
56961ae650dSJack F Vogel 	struct i40e_aqc_vsi_properties_data info;
57061ae650dSJack F Vogel 
57161ae650dSJack F Vogel 	eventhandler_tag 	vlan_attach;
57261ae650dSJack F Vogel 	eventhandler_tag 	vlan_detach;
57361ae650dSJack F Vogel 	u16			num_vlans;
57461ae650dSJack F Vogel 
57561ae650dSJack F Vogel 	/* Per-VSI stats from hardware */
57661ae650dSJack F Vogel 	struct i40e_eth_stats	eth_stats;
57761ae650dSJack F Vogel 	struct i40e_eth_stats	eth_stats_offsets;
57861ae650dSJack F Vogel 	bool 			stat_offsets_loaded;
579e5100ee2SJack F Vogel 	/* VSI stat counters */
5804b443922SGleb Smirnoff 	u64			ipackets;
5814b443922SGleb Smirnoff 	u64			ierrors;
5824b443922SGleb Smirnoff 	u64			opackets;
5834b443922SGleb Smirnoff 	u64			oerrors;
5844b443922SGleb Smirnoff 	u64			ibytes;
5854b443922SGleb Smirnoff 	u64			obytes;
5864b443922SGleb Smirnoff 	u64			imcasts;
5874b443922SGleb Smirnoff 	u64			omcasts;
5884b443922SGleb Smirnoff 	u64			iqdrops;
5894b443922SGleb Smirnoff 	u64			oqdrops;
5904b443922SGleb Smirnoff 	u64			noproto;
59161ae650dSJack F Vogel 
59261ae650dSJack F Vogel 	/* Driver statistics */
59361ae650dSJack F Vogel 	u64			hw_filters_del;
59461ae650dSJack F Vogel 	u64			hw_filters_add;
59561ae650dSJack F Vogel 
59661ae650dSJack F Vogel 	/* Misc. */
59761ae650dSJack F Vogel 	u64 			flags;
59856c2c47bSJack F Vogel 	struct sysctl_oid	*vsi_node;
59961ae650dSJack F Vogel };
60061ae650dSJack F Vogel 
60161ae650dSJack F Vogel /*
60261ae650dSJack F Vogel ** Find the number of unrefreshed RX descriptors
60361ae650dSJack F Vogel */
60461ae650dSJack F Vogel static inline u16
60561ae650dSJack F Vogel ixl_rx_unrefreshed(struct ixl_queue *que)
60661ae650dSJack F Vogel {
60761ae650dSJack F Vogel         struct rx_ring	*rxr = &que->rxr;
60861ae650dSJack F Vogel 
60961ae650dSJack F Vogel 	if (rxr->next_check > rxr->next_refresh)
61061ae650dSJack F Vogel 		return (rxr->next_check - rxr->next_refresh - 1);
61161ae650dSJack F Vogel 	else
612*ceebc2f3SEric Joyner 		return ((que->num_rx_desc + rxr->next_check) -
61361ae650dSJack F Vogel 		    rxr->next_refresh - 1);
61461ae650dSJack F Vogel }
61561ae650dSJack F Vogel 
61661ae650dSJack F Vogel /*
61761ae650dSJack F Vogel ** Find the next available unused filter
61861ae650dSJack F Vogel */
61961ae650dSJack F Vogel static inline struct ixl_mac_filter *
62061ae650dSJack F Vogel ixl_get_filter(struct ixl_vsi *vsi)
62161ae650dSJack F Vogel {
62261ae650dSJack F Vogel 	struct ixl_mac_filter  *f;
62361ae650dSJack F Vogel 
62461ae650dSJack F Vogel 	/* create a new empty filter */
62561ae650dSJack F Vogel 	f = malloc(sizeof(struct ixl_mac_filter),
62661ae650dSJack F Vogel 	    M_DEVBUF, M_NOWAIT | M_ZERO);
627e5100ee2SJack F Vogel 	if (f)
62861ae650dSJack F Vogel 		SLIST_INSERT_HEAD(&vsi->ftl, f, next);
62961ae650dSJack F Vogel 
63061ae650dSJack F Vogel 	return (f);
63161ae650dSJack F Vogel }
63261ae650dSJack F Vogel 
63361ae650dSJack F Vogel /*
63461ae650dSJack F Vogel ** Compare two ethernet addresses
63561ae650dSJack F Vogel */
63661ae650dSJack F Vogel static inline bool
63756c2c47bSJack F Vogel cmp_etheraddr(const u8 *ea1, const u8 *ea2)
63861ae650dSJack F Vogel {
63961ae650dSJack F Vogel 	bool cmp = FALSE;
64061ae650dSJack F Vogel 
64161ae650dSJack F Vogel 	if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) &&
64261ae650dSJack F Vogel 	    (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) &&
64361ae650dSJack F Vogel 	    (ea1[4] == ea2[4]) && (ea1[5] == ea2[5]))
64461ae650dSJack F Vogel 		cmp = TRUE;
64561ae650dSJack F Vogel 
64661ae650dSJack F Vogel 	return (cmp);
64761ae650dSJack F Vogel }
64861ae650dSJack F Vogel 
64961ae650dSJack F Vogel /*
6504294f337SSean Bruno  * Return next largest power of 2, unsigned
6514294f337SSean Bruno  *
6524294f337SSean Bruno  * Public domain, from Bit Twiddling Hacks
6534294f337SSean Bruno  */
6544294f337SSean Bruno static inline u32
6554294f337SSean Bruno next_power_of_two(u32 n)
6564294f337SSean Bruno {
6574294f337SSean Bruno 	n--;
6584294f337SSean Bruno 	n |= n >> 1;
6594294f337SSean Bruno 	n |= n >> 2;
6604294f337SSean Bruno 	n |= n >> 4;
6614294f337SSean Bruno 	n |= n >> 8;
6624294f337SSean Bruno 	n |= n >> 16;
6634294f337SSean Bruno 	n++;
6644294f337SSean Bruno 
6654294f337SSean Bruno 	/* Next power of two > 0 is 1 */
6664294f337SSean Bruno 	n += (n == 0);
6674294f337SSean Bruno 
6684294f337SSean Bruno 	return (n);
6694294f337SSean Bruno }
6704294f337SSean Bruno 
6714294f337SSean Bruno /*
67261ae650dSJack F Vogel  * Info for stats sysctls
67361ae650dSJack F Vogel  */
67461ae650dSJack F Vogel struct ixl_sysctl_info {
67561ae650dSJack F Vogel 	u64	*stat;
67661ae650dSJack F Vogel 	char	*name;
67761ae650dSJack F Vogel 	char	*description;
67861ae650dSJack F Vogel };
67961ae650dSJack F Vogel 
68033c66d8aSRyan Libby extern const uint8_t ixl_bcast_addr[ETHER_ADDR_LEN];
68161ae650dSJack F Vogel 
68261ae650dSJack F Vogel /*********************************************************************
68361ae650dSJack F Vogel  *  TXRX Function prototypes
68461ae650dSJack F Vogel  *********************************************************************/
68561ae650dSJack F Vogel int	ixl_allocate_tx_data(struct ixl_queue *);
68661ae650dSJack F Vogel int	ixl_allocate_rx_data(struct ixl_queue *);
68761ae650dSJack F Vogel void	ixl_init_tx_ring(struct ixl_queue *);
68861ae650dSJack F Vogel int	ixl_init_rx_ring(struct ixl_queue *);
68961ae650dSJack F Vogel bool	ixl_rxeof(struct ixl_queue *, int);
69061ae650dSJack F Vogel bool	ixl_txeof(struct ixl_queue *);
6914294f337SSean Bruno void	ixl_free_que_tx(struct ixl_queue *);
6924294f337SSean Bruno void	ixl_free_que_rx(struct ixl_queue *);
6934294f337SSean Bruno 
69461ae650dSJack F Vogel int	ixl_mq_start(struct ifnet *, struct mbuf *);
69561ae650dSJack F Vogel int	ixl_mq_start_locked(struct ifnet *, struct tx_ring *);
69661ae650dSJack F Vogel void	ixl_deferred_mq_start(void *, int);
697*ceebc2f3SEric Joyner 
698*ceebc2f3SEric Joyner void	ixl_vsi_setup_rings_size(struct ixl_vsi *, int, int);
699*ceebc2f3SEric Joyner int	ixl_queue_hang_check(struct ixl_vsi *);
70061ae650dSJack F Vogel void	ixl_free_vsi(struct ixl_vsi *);
7014294f337SSean Bruno void	ixl_qflush(struct ifnet *);
7024294f337SSean Bruno 
7034294f337SSean Bruno /* Common function prototypes between PF/VF driver */
7044b443922SGleb Smirnoff #if __FreeBSD_version >= 1100000
7054b443922SGleb Smirnoff uint64_t ixl_get_counter(if_t ifp, ift_counter cnt);
7064b443922SGleb Smirnoff #endif
7074294f337SSean Bruno void	ixl_get_default_rss_key(u32 *);
708*ceebc2f3SEric Joyner const char *	i40e_vc_stat_str(struct i40e_hw *hw,
709*ceebc2f3SEric Joyner     enum virtchnl_status_code stat_err);
710*ceebc2f3SEric Joyner void	ixl_set_busmaster(device_t);
711*ceebc2f3SEric Joyner void	ixl_set_msix_enable(device_t);
71261ae650dSJack F Vogel #endif /* _IXL_H_ */
713