161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 3b6c8f260SJack F Vogel Copyright (c) 2013-2015, 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 #include <sys/param.h> 4061ae650dSJack F Vogel #include <sys/systm.h> 4161ae650dSJack F Vogel #include <sys/buf_ring.h> 4261ae650dSJack F Vogel #include <sys/mbuf.h> 4361ae650dSJack F Vogel #include <sys/protosw.h> 4461ae650dSJack F Vogel #include <sys/socket.h> 4561ae650dSJack F Vogel #include <sys/malloc.h> 4661ae650dSJack F Vogel #include <sys/kernel.h> 4761ae650dSJack F Vogel #include <sys/module.h> 4861ae650dSJack F Vogel #include <sys/sockio.h> 4913b40804SSteven Hartland #include <sys/eventhandler.h> 5061ae650dSJack F Vogel 5161ae650dSJack F Vogel #include <net/if.h> 5213b40804SSteven Hartland #include <net/if_var.h> 5361ae650dSJack F Vogel #include <net/if_arp.h> 5461ae650dSJack F Vogel #include <net/bpf.h> 5561ae650dSJack F Vogel #include <net/ethernet.h> 5661ae650dSJack F Vogel #include <net/if_dl.h> 5761ae650dSJack F Vogel #include <net/if_media.h> 5861ae650dSJack F Vogel 5961ae650dSJack F Vogel #include <net/bpf.h> 6061ae650dSJack F Vogel #include <net/if_types.h> 6161ae650dSJack F Vogel #include <net/if_vlan_var.h> 6261ae650dSJack F Vogel 6361ae650dSJack F Vogel #include <netinet/in_systm.h> 6461ae650dSJack F Vogel #include <netinet/in.h> 6561ae650dSJack F Vogel #include <netinet/if_ether.h> 6661ae650dSJack F Vogel #include <netinet/ip.h> 6761ae650dSJack F Vogel #include <netinet/ip6.h> 6861ae650dSJack F Vogel #include <netinet/tcp.h> 6961ae650dSJack F Vogel #include <netinet/tcp_lro.h> 7061ae650dSJack F Vogel #include <netinet/udp.h> 7161ae650dSJack F Vogel #include <netinet/sctp.h> 7261ae650dSJack F Vogel 7361ae650dSJack F Vogel #include <machine/in_cksum.h> 7461ae650dSJack F Vogel 7561ae650dSJack F Vogel #include <sys/bus.h> 7661ae650dSJack F Vogel #include <machine/bus.h> 7761ae650dSJack F Vogel #include <sys/rman.h> 7861ae650dSJack F Vogel #include <machine/resource.h> 7961ae650dSJack F Vogel #include <vm/vm.h> 8061ae650dSJack F Vogel #include <vm/pmap.h> 8161ae650dSJack F Vogel #include <machine/clock.h> 8261ae650dSJack F Vogel #include <dev/pci/pcivar.h> 8361ae650dSJack F Vogel #include <dev/pci/pcireg.h> 8461ae650dSJack F Vogel #include <sys/proc.h> 8561ae650dSJack F Vogel #include <sys/sysctl.h> 8661ae650dSJack F Vogel #include <sys/endian.h> 8761ae650dSJack F Vogel #include <sys/taskqueue.h> 8861ae650dSJack F Vogel #include <sys/pcpu.h> 8961ae650dSJack F Vogel #include <sys/smp.h> 901d767a8eSEric Joyner #include <sys/sbuf.h> 9161ae650dSJack F Vogel #include <machine/smp.h> 92*4294f337SSean Bruno #include <machine/stdarg.h> 9361ae650dSJack F Vogel 94*4294f337SSean Bruno #ifdef RSS 95*4294f337SSean Bruno #include <net/rss_config.h> 9656c2c47bSJack F Vogel #endif 9756c2c47bSJack F Vogel 98*4294f337SSean Bruno #include "opt_inet.h" 99*4294f337SSean Bruno #include "opt_inet6.h" 100*4294f337SSean Bruno #include "opt_rss.h" 101*4294f337SSean Bruno 10261ae650dSJack F Vogel #include "i40e_type.h" 10361ae650dSJack F Vogel #include "i40e_prototype.h" 10461ae650dSJack F Vogel 10561ae650dSJack F Vogel #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" 10661ae650dSJack F Vogel #define MAC_FORMAT_ARGS(mac_addr) \ 10761ae650dSJack F Vogel (mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \ 10861ae650dSJack F Vogel (mac_addr)[4], (mac_addr)[5] 10961ae650dSJack F Vogel #define ON_OFF_STR(is_set) ((is_set) ? "On" : "Off") 11061ae650dSJack F Vogel 111393c4bb1SJack F Vogel #ifdef IXL_DEBUG 11261ae650dSJack F Vogel 11361ae650dSJack F Vogel #define _DBG_PRINTF(S, ...) printf("%s: " S "\n", __func__, ##__VA_ARGS__) 11461ae650dSJack F Vogel #define _DEV_DBG_PRINTF(dev, S, ...) device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__) 11561ae650dSJack F Vogel #define _IF_DBG_PRINTF(ifp, S, ...) if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__) 11661ae650dSJack F Vogel 11761ae650dSJack F Vogel /* Defines for printing generic debug information */ 11861ae650dSJack F Vogel #define DPRINTF(...) _DBG_PRINTF(__VA_ARGS__) 11961ae650dSJack F Vogel #define DDPRINTF(...) _DEV_DBG_PRINTF(__VA_ARGS__) 12061ae650dSJack F Vogel #define IDPRINTF(...) _IF_DBG_PRINTF(__VA_ARGS__) 12161ae650dSJack F Vogel 12261ae650dSJack F Vogel /* Defines for printing specific debug information */ 12361ae650dSJack F Vogel #define DEBUG_INIT 1 12461ae650dSJack F Vogel #define DEBUG_IOCTL 1 12561ae650dSJack F Vogel #define DEBUG_HW 1 12661ae650dSJack F Vogel 12761ae650dSJack F Vogel #define INIT_DEBUGOUT(...) if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__) 12861ae650dSJack F Vogel #define INIT_DBG_DEV(...) if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__) 12961ae650dSJack F Vogel #define INIT_DBG_IF(...) if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__) 13061ae650dSJack F Vogel 13161ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...) if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__) 13261ae650dSJack F Vogel #define IOCTL_DBG_IF2(ifp, S, ...) if (DEBUG_IOCTL) \ 13361ae650dSJack F Vogel if_printf(ifp, S "\n", ##__VA_ARGS__) 13461ae650dSJack F Vogel #define IOCTL_DBG_IF(...) if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__) 13561ae650dSJack F Vogel 13661ae650dSJack F Vogel #define HW_DEBUGOUT(...) if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__) 13761ae650dSJack F Vogel 138393c4bb1SJack F Vogel #else /* no IXL_DEBUG */ 13961ae650dSJack F Vogel #define DEBUG_INIT 0 14061ae650dSJack F Vogel #define DEBUG_IOCTL 0 14161ae650dSJack F Vogel #define DEBUG_HW 0 14261ae650dSJack F Vogel 14361ae650dSJack F Vogel #define DPRINTF(...) 14461ae650dSJack F Vogel #define DDPRINTF(...) 14561ae650dSJack F Vogel #define IDPRINTF(...) 14661ae650dSJack F Vogel 14761ae650dSJack F Vogel #define INIT_DEBUGOUT(...) 14861ae650dSJack F Vogel #define INIT_DBG_DEV(...) 14961ae650dSJack F Vogel #define INIT_DBG_IF(...) 15061ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...) 15161ae650dSJack F Vogel #define IOCTL_DBG_IF2(...) 15261ae650dSJack F Vogel #define IOCTL_DBG_IF(...) 15361ae650dSJack F Vogel #define HW_DEBUGOUT(...) 154393c4bb1SJack F Vogel #endif /* IXL_DEBUG */ 15561ae650dSJack F Vogel 156*4294f337SSean Bruno enum ixl_dbg_mask { 157*4294f337SSean Bruno IXL_DBG_INFO = 0x00000001, 158*4294f337SSean Bruno IXL_DBG_EN_DIS = 0x00000002, 159*4294f337SSean Bruno IXL_DBG_AQ = 0x00000004, 160*4294f337SSean Bruno IXL_DBG_NVMUPD = 0x00000008, 161*4294f337SSean Bruno 162*4294f337SSean Bruno IXL_DBG_IOCTL_KNOWN = 0x00000010, 163*4294f337SSean Bruno IXL_DBG_IOCTL_UNKNOWN = 0x00000020, 164*4294f337SSean Bruno IXL_DBG_IOCTL_ALL = 0x00000030, 165*4294f337SSean Bruno 166*4294f337SSean Bruno I40E_DEBUG_RSS = 0x00000100, 167*4294f337SSean Bruno 168*4294f337SSean Bruno IXL_DBG_IOV = 0x00001000, 169*4294f337SSean Bruno IXL_DBG_IOV_VC = 0x00002000, 170*4294f337SSean Bruno 171*4294f337SSean Bruno IXL_DBG_SWITCH_INFO = 0x00010000, 172*4294f337SSean Bruno 173*4294f337SSean Bruno IXL_DBG_ALL = 0xFFFFFFFF 174*4294f337SSean Bruno }; 175*4294f337SSean Bruno 17661ae650dSJack F Vogel /* Tunables */ 17761ae650dSJack F Vogel 17861ae650dSJack F Vogel /* 17961ae650dSJack F Vogel * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the 18061ae650dSJack F Vogel * number of tx/rx descriptors allocated by the driver. Increasing this 1816c426059SEric Joyner * value allows the driver to queue more operations. 1826c426059SEric Joyner * 1836c426059SEric Joyner * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes. 1846c426059SEric Joyner * The driver currently always uses 32 byte Rx descriptors. 18561ae650dSJack F Vogel */ 18661ae650dSJack F Vogel #define DEFAULT_RING 1024 187*4294f337SSean Bruno #define IXL_MAX_RING 8160 188*4294f337SSean Bruno #define IXL_MIN_RING 32 189*4294f337SSean Bruno #define IXL_RING_INCREMENT 32 190*4294f337SSean Bruno 191*4294f337SSean Bruno #define IXL_AQ_LEN 256 192*4294f337SSean Bruno #define IXL_AQ_LEN_MAX 1024 19361ae650dSJack F Vogel 19461ae650dSJack F Vogel /* 19561ae650dSJack F Vogel ** Default number of entries in Tx queue buf_ring. 19661ae650dSJack F Vogel */ 197*4294f337SSean Bruno #define DEFAULT_TXBRSZ 4096 19861ae650dSJack F Vogel 19961ae650dSJack F Vogel /* Alignment for rings */ 20061ae650dSJack F Vogel #define DBA_ALIGN 128 20161ae650dSJack F Vogel 20261ae650dSJack F Vogel /* 20361ae650dSJack F Vogel * This is the max watchdog interval, ie. the time that can 20461ae650dSJack F Vogel * pass between any two TX clean operations, such only happening 20561ae650dSJack F Vogel * when the TX hardware is functioning. 20661ae650dSJack F Vogel */ 20761ae650dSJack F Vogel #define IXL_WATCHDOG (10 * hz) 20861ae650dSJack F Vogel 20961ae650dSJack F Vogel /* 21061ae650dSJack F Vogel * This parameters control when the driver calls the routine to reclaim 21161ae650dSJack F Vogel * transmit descriptors. 21261ae650dSJack F Vogel */ 21361ae650dSJack F Vogel #define IXL_TX_CLEANUP_THRESHOLD (que->num_desc / 8) 21461ae650dSJack F Vogel #define IXL_TX_OP_THRESHOLD (que->num_desc / 32) 21561ae650dSJack F Vogel 21661ae650dSJack F Vogel #define MAX_MULTICAST_ADDR 128 21761ae650dSJack F Vogel 21861ae650dSJack F Vogel #define IXL_BAR 3 21961ae650dSJack F Vogel #define IXL_ADM_LIMIT 2 22061ae650dSJack F Vogel #define IXL_TSO_SIZE 65535 22161ae650dSJack F Vogel #define IXL_AQ_BUF_SZ ((u32) 4096) 22261ae650dSJack F Vogel #define IXL_RX_HDR 128 22361ae650dSJack F Vogel #define IXL_RX_LIMIT 512 22461ae650dSJack F Vogel #define IXL_RX_ITR 0 22561ae650dSJack F Vogel #define IXL_TX_ITR 1 22661ae650dSJack F Vogel #define IXL_ITR_NONE 3 22761ae650dSJack F Vogel #define IXL_QUEUE_EOL 0x7FF 2286c426059SEric Joyner #define IXL_MAX_FRAME 9728 22961ae650dSJack F Vogel #define IXL_MAX_TX_SEGS 8 230*4294f337SSean Bruno #define IXL_MAX_TSO_SEGS 128 23161ae650dSJack F Vogel #define IXL_SPARSE_CHAIN 6 23261ae650dSJack F Vogel #define IXL_QUEUE_HUNG 0x80000000 233*4294f337SSean Bruno 234*4294f337SSean Bruno #define IXL_RSS_KEY_SIZE_REG 13 235*4294f337SSean Bruno #define IXL_RSS_KEY_SIZE (IXL_RSS_KEY_SIZE_REG * 4) 236*4294f337SSean Bruno #define IXL_RSS_VSI_LUT_SIZE 64 /* X722 -> VSI, X710 -> VF */ 237*4294f337SSean Bruno #define IXL_RSS_VSI_LUT_ENTRY_MASK 0x3F 238*4294f337SSean Bruno #define IXL_RSS_VF_LUT_ENTRY_MASK 0xF 23961ae650dSJack F Vogel 24056c2c47bSJack F Vogel #define IXL_VF_MAX_BUFFER 0x3F80 24156c2c47bSJack F Vogel #define IXL_VF_MAX_HDR_BUFFER 0x840 24256c2c47bSJack F Vogel #define IXL_VF_MAX_FRAME 0x3FFF 24356c2c47bSJack F Vogel 244*4294f337SSean Bruno /* ERJ: hardware can support ~2k (SW5+) filters between all functions */ 24561ae650dSJack F Vogel #define IXL_MAX_FILTERS 256 24661ae650dSJack F Vogel #define IXL_MAX_TX_BUSY 10 24761ae650dSJack F Vogel 24861ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_SHIFT 0 24961ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_MASK (0xff << IXL_NVM_VERSION_LO_SHIFT) 25061ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_SHIFT 12 25161ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_MASK (0xf << IXL_NVM_VERSION_HI_SHIFT) 25261ae650dSJack F Vogel 25361ae650dSJack F Vogel /* 25461ae650dSJack F Vogel * Interrupt Moderation parameters 25561ae650dSJack F Vogel */ 25661ae650dSJack F Vogel #define IXL_MAX_ITR 0x07FF 25761ae650dSJack F Vogel #define IXL_ITR_100K 0x0005 25861ae650dSJack F Vogel #define IXL_ITR_20K 0x0019 25961ae650dSJack F Vogel #define IXL_ITR_8K 0x003E 26061ae650dSJack F Vogel #define IXL_ITR_4K 0x007A 26161ae650dSJack F Vogel #define IXL_ITR_DYNAMIC 0x8000 26261ae650dSJack F Vogel #define IXL_LOW_LATENCY 0 26361ae650dSJack F Vogel #define IXL_AVE_LATENCY 1 26461ae650dSJack F Vogel #define IXL_BULK_LATENCY 2 26561ae650dSJack F Vogel 26661ae650dSJack F Vogel /* MacVlan Flags */ 26761ae650dSJack F Vogel #define IXL_FILTER_USED (u16)(1 << 0) 26861ae650dSJack F Vogel #define IXL_FILTER_VLAN (u16)(1 << 1) 26961ae650dSJack F Vogel #define IXL_FILTER_ADD (u16)(1 << 2) 27061ae650dSJack F Vogel #define IXL_FILTER_DEL (u16)(1 << 3) 27161ae650dSJack F Vogel #define IXL_FILTER_MC (u16)(1 << 4) 27261ae650dSJack F Vogel 27361ae650dSJack F Vogel /* used in the vlan field of the filter when not a vlan */ 27461ae650dSJack F Vogel #define IXL_VLAN_ANY -1 27561ae650dSJack F Vogel 27661ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP) 27761ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6) 27861ae650dSJack F Vogel #define CSUM_OFFLOAD (CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO) 27961ae650dSJack F Vogel 28061ae650dSJack F Vogel /* Misc flags for ixl_vsi.flags */ 28161ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO4 (1 << 0) 28261ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO6 (1 << 1) 28361ae650dSJack F Vogel 28456c2c47bSJack F Vogel #define IXL_VF_RESET_TIMEOUT 100 28556c2c47bSJack F Vogel 28656c2c47bSJack F Vogel #define IXL_VSI_DATA_PORT 0x01 28756c2c47bSJack F Vogel 28856c2c47bSJack F Vogel #define IXLV_MAX_QUEUES 16 28956c2c47bSJack F Vogel #define IXL_MAX_VSI_QUEUES (2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1)) 29056c2c47bSJack F Vogel 29156c2c47bSJack F Vogel #define IXL_RX_CTX_BASE_UNITS 128 29256c2c47bSJack F Vogel #define IXL_TX_CTX_BASE_UNITS 128 29356c2c47bSJack F Vogel 29456c2c47bSJack F Vogel #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \ 29556c2c47bSJack F Vogel I40E_VPINT_LNKLSTN(((vector) - 1) + \ 29656c2c47bSJack F Vogel (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 29756c2c47bSJack F Vogel 29856c2c47bSJack F Vogel #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \ 29956c2c47bSJack F Vogel I40E_VFINT_DYN_CTLN(((vector) - 1) + \ 30056c2c47bSJack F Vogel (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 30156c2c47bSJack F Vogel 30256c2c47bSJack F Vogel #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS 0xAA 30356c2c47bSJack F Vogel 30456c2c47bSJack F Vogel #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK 0x20 30556c2c47bSJack F Vogel 30656c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf) ((glb_vf) / 32) 30756c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf) (1 << ((glb_vf) % 32)) 30856c2c47bSJack F Vogel 30956c2c47bSJack F Vogel #define IXL_MAX_ITR_IDX 3 31056c2c47bSJack F Vogel 31156c2c47bSJack F Vogel #define IXL_END_OF_INTR_LNKLST 0x7FF 31256c2c47bSJack F Vogel 313*4294f337SSean Bruno #define IXL_DEFAULT_RSS_HENA (\ 314*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \ 315*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \ 316*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \ 317*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \ 318*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) | \ 319*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \ 320*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \ 321*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \ 322*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \ 323*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) | \ 324*4294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD)) 325*4294f337SSean Bruno 32661ae650dSJack F Vogel #define IXL_TX_LOCK(_sc) mtx_lock(&(_sc)->mtx) 32761ae650dSJack F Vogel #define IXL_TX_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx) 32861ae650dSJack F Vogel #define IXL_TX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx) 32961ae650dSJack F Vogel #define IXL_TX_TRYLOCK(_sc) mtx_trylock(&(_sc)->mtx) 33061ae650dSJack F Vogel #define IXL_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED) 33161ae650dSJack F Vogel 33261ae650dSJack F Vogel #define IXL_RX_LOCK(_sc) mtx_lock(&(_sc)->mtx) 33361ae650dSJack F Vogel #define IXL_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx) 33461ae650dSJack F Vogel #define IXL_RX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx) 33561ae650dSJack F Vogel 336a48d00d2SEric Joyner /* Pre-11 counter(9) compatibility */ 337b6c8f260SJack F Vogel #if __FreeBSD_version >= 1100036 3384b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ipackets = (count) 3394b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ierrors = (count) 3404b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->opackets = (count) 3414b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->oerrors = (count) 3424b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) /* Do nothing; collisions is always 0. */ 3434b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ibytes = (count) 3444b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->obytes = (count) 3454b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->imcasts = (count) 3464b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->omcasts = (count) 3474b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->iqdrops = (count) 348625d12c6SJohn Baldwin #define IXL_SET_OQDROPS(vsi, count) (vsi)->oqdrops = (count) 3494b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 3504b443922SGleb Smirnoff #else 3514b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ifp->if_ipackets = (count) 3524b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ifp->if_ierrors = (count) 3534b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->ifp->if_opackets = (count) 3544b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->ifp->if_oerrors = (count) 3554b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) (vsi)->ifp->if_collisions = (count) 3564b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ifp->if_ibytes = (count) 3574b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->ifp->if_obytes = (count) 3584b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->ifp->if_imcasts = (count) 3594b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->ifp->if_omcasts = (count) 3604b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->ifp->if_iqdrops = (count) 3614b443922SGleb Smirnoff #define IXL_SET_OQDROPS(vsi, odrops) (vsi)->ifp->if_snd.ifq_drops = (odrops) 3624b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 3634b443922SGleb Smirnoff #endif 3644b443922SGleb Smirnoff 36561ae650dSJack F Vogel /* 36661ae650dSJack F Vogel ***************************************************************************** 36761ae650dSJack F Vogel * vendor_info_array 36861ae650dSJack F Vogel * 36961ae650dSJack F Vogel * This array contains the list of Subvendor/Subdevice IDs on which the driver 37061ae650dSJack F Vogel * should load. 37161ae650dSJack F Vogel * 37261ae650dSJack F Vogel ***************************************************************************** 37361ae650dSJack F Vogel */ 37461ae650dSJack F Vogel typedef struct _ixl_vendor_info_t { 37561ae650dSJack F Vogel unsigned int vendor_id; 37661ae650dSJack F Vogel unsigned int device_id; 37761ae650dSJack F Vogel unsigned int subvendor_id; 37861ae650dSJack F Vogel unsigned int subdevice_id; 37961ae650dSJack F Vogel unsigned int index; 38061ae650dSJack F Vogel } ixl_vendor_info_t; 38161ae650dSJack F Vogel 38261ae650dSJack F Vogel 38361ae650dSJack F Vogel struct ixl_tx_buf { 38461ae650dSJack F Vogel u32 eop_index; 38561ae650dSJack F Vogel struct mbuf *m_head; 38661ae650dSJack F Vogel bus_dmamap_t map; 38761ae650dSJack F Vogel bus_dma_tag_t tag; 38861ae650dSJack F Vogel }; 38961ae650dSJack F Vogel 39061ae650dSJack F Vogel struct ixl_rx_buf { 39161ae650dSJack F Vogel struct mbuf *m_head; 39261ae650dSJack F Vogel struct mbuf *m_pack; 39361ae650dSJack F Vogel struct mbuf *fmp; 39461ae650dSJack F Vogel bus_dmamap_t hmap; 39561ae650dSJack F Vogel bus_dmamap_t pmap; 39661ae650dSJack F Vogel }; 39761ae650dSJack F Vogel 39861ae650dSJack F Vogel /* 39961ae650dSJack F Vogel ** This struct has multiple uses, multicast 40061ae650dSJack F Vogel ** addresses, vlans, and mac filters all use it. 40161ae650dSJack F Vogel */ 40261ae650dSJack F Vogel struct ixl_mac_filter { 40361ae650dSJack F Vogel SLIST_ENTRY(ixl_mac_filter) next; 40461ae650dSJack F Vogel u8 macaddr[ETHER_ADDR_LEN]; 40561ae650dSJack F Vogel s16 vlan; 40661ae650dSJack F Vogel u16 flags; 40761ae650dSJack F Vogel }; 40861ae650dSJack F Vogel 40961ae650dSJack F Vogel /* 41061ae650dSJack F Vogel * The Transmit ring control struct 41161ae650dSJack F Vogel */ 41261ae650dSJack F Vogel struct tx_ring { 41361ae650dSJack F Vogel struct ixl_queue *que; 41461ae650dSJack F Vogel struct mtx mtx; 41561ae650dSJack F Vogel u32 tail; 41661ae650dSJack F Vogel struct i40e_tx_desc *base; 41761ae650dSJack F Vogel struct i40e_dma_mem dma; 41861ae650dSJack F Vogel u16 next_avail; 41961ae650dSJack F Vogel u16 next_to_clean; 42061ae650dSJack F Vogel u16 atr_rate; 42161ae650dSJack F Vogel u16 atr_count; 4226d011ad5SEric Joyner u32 itr; 4236d011ad5SEric Joyner u32 latency; 42461ae650dSJack F Vogel struct ixl_tx_buf *buffers; 42561ae650dSJack F Vogel volatile u16 avail; 42661ae650dSJack F Vogel u32 cmd; 42761ae650dSJack F Vogel bus_dma_tag_t tx_tag; 42861ae650dSJack F Vogel bus_dma_tag_t tso_tag; 42961ae650dSJack F Vogel char mtx_name[16]; 43061ae650dSJack F Vogel struct buf_ring *br; 43161ae650dSJack F Vogel 43261ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 43361ae650dSJack F Vogel u32 packets; 43461ae650dSJack F Vogel u32 bytes; 43561ae650dSJack F Vogel 43661ae650dSJack F Vogel /* Soft Stats */ 43761ae650dSJack F Vogel u64 tx_bytes; 43861ae650dSJack F Vogel u64 no_desc; 43961ae650dSJack F Vogel u64 total_packets; 44061ae650dSJack F Vogel }; 44161ae650dSJack F Vogel 44261ae650dSJack F Vogel 44361ae650dSJack F Vogel /* 44461ae650dSJack F Vogel * The Receive ring control struct 44561ae650dSJack F Vogel */ 44661ae650dSJack F Vogel struct rx_ring { 44761ae650dSJack F Vogel struct ixl_queue *que; 44861ae650dSJack F Vogel struct mtx mtx; 44961ae650dSJack F Vogel union i40e_rx_desc *base; 45061ae650dSJack F Vogel struct i40e_dma_mem dma; 45161ae650dSJack F Vogel struct lro_ctrl lro; 45261ae650dSJack F Vogel bool lro_enabled; 45361ae650dSJack F Vogel bool hdr_split; 45461ae650dSJack F Vogel bool discard; 4556d011ad5SEric Joyner u32 next_refresh; 4566d011ad5SEric Joyner u32 next_check; 4576d011ad5SEric Joyner u32 itr; 4586d011ad5SEric Joyner u32 latency; 45961ae650dSJack F Vogel char mtx_name[16]; 46061ae650dSJack F Vogel struct ixl_rx_buf *buffers; 46161ae650dSJack F Vogel u32 mbuf_sz; 46261ae650dSJack F Vogel u32 tail; 46361ae650dSJack F Vogel bus_dma_tag_t htag; 46461ae650dSJack F Vogel bus_dma_tag_t ptag; 46561ae650dSJack F Vogel 46661ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 46761ae650dSJack F Vogel u32 packets; 46861ae650dSJack F Vogel u32 bytes; 46961ae650dSJack F Vogel 47061ae650dSJack F Vogel /* Soft stats */ 47161ae650dSJack F Vogel u64 split; 47261ae650dSJack F Vogel u64 rx_packets; 47361ae650dSJack F Vogel u64 rx_bytes; 4746d011ad5SEric Joyner u64 desc_errs; 47561ae650dSJack F Vogel u64 not_done; 47661ae650dSJack F Vogel }; 47761ae650dSJack F Vogel 47861ae650dSJack F Vogel /* 47961ae650dSJack F Vogel ** Driver queue struct: this is the interrupt container 48061ae650dSJack F Vogel ** for the associated tx and rx ring pair. 48161ae650dSJack F Vogel */ 48261ae650dSJack F Vogel struct ixl_queue { 48361ae650dSJack F Vogel struct ixl_vsi *vsi; 48461ae650dSJack F Vogel u32 me; 48561ae650dSJack F Vogel u32 msix; /* This queue's MSIX vector */ 48661ae650dSJack F Vogel u32 eims; /* This queue's EIMS bit */ 48761ae650dSJack F Vogel struct resource *res; 48861ae650dSJack F Vogel void *tag; 48961ae650dSJack F Vogel int num_desc; /* both tx and rx */ 49061ae650dSJack F Vogel int busy; 49161ae650dSJack F Vogel struct tx_ring txr; 49261ae650dSJack F Vogel struct rx_ring rxr; 49361ae650dSJack F Vogel struct task task; 49461ae650dSJack F Vogel struct task tx_task; 49561ae650dSJack F Vogel struct taskqueue *tq; 49661ae650dSJack F Vogel 49761ae650dSJack F Vogel /* Queue stats */ 49861ae650dSJack F Vogel u64 irqs; 49961ae650dSJack F Vogel u64 tso; 50061ae650dSJack F Vogel u64 mbuf_defrag_failed; 50161ae650dSJack F Vogel u64 mbuf_hdr_failed; 50261ae650dSJack F Vogel u64 mbuf_pkt_failed; 503*4294f337SSean Bruno u64 tx_dmamap_failed; 50461ae650dSJack F Vogel u64 dropped_pkts; 50561ae650dSJack F Vogel }; 50661ae650dSJack F Vogel 50761ae650dSJack F Vogel /* 508*4294f337SSean Bruno ** Virtual Station Interface 50961ae650dSJack F Vogel */ 51061ae650dSJack F Vogel SLIST_HEAD(ixl_ftl_head, ixl_mac_filter); 51161ae650dSJack F Vogel struct ixl_vsi { 51261ae650dSJack F Vogel void *back; 51361ae650dSJack F Vogel struct ifnet *ifp; 51461ae650dSJack F Vogel struct device *dev; 51561ae650dSJack F Vogel struct i40e_hw *hw; 51661ae650dSJack F Vogel struct ifmedia media; 517ac83ea83SEric Joyner enum i40e_vsi_type type; 51861ae650dSJack F Vogel int id; 51961ae650dSJack F Vogel u16 num_queues; 5206d011ad5SEric Joyner u32 rx_itr_setting; 5216d011ad5SEric Joyner u32 tx_itr_setting; 522*4294f337SSean Bruno u16 max_frame_size; 523*4294f337SSean Bruno 52461ae650dSJack F Vogel struct ixl_queue *queues; /* head of queues */ 525*4294f337SSean Bruno 526*4294f337SSean Bruno u16 vsi_num; 52761ae650dSJack F Vogel bool link_active; 52861ae650dSJack F Vogel u16 seid; 52956c2c47bSJack F Vogel u16 uplink_seid; 53056c2c47bSJack F Vogel u16 downlink_seid; 53161ae650dSJack F Vogel 53261ae650dSJack F Vogel /* MAC/VLAN Filter list */ 53361ae650dSJack F Vogel struct ixl_ftl_head ftl; 53456c2c47bSJack F Vogel u16 num_macs; 53561ae650dSJack F Vogel 536*4294f337SSean Bruno /* Contains readylist & stat counter id */ 53761ae650dSJack F Vogel struct i40e_aqc_vsi_properties_data info; 53861ae650dSJack F Vogel 53961ae650dSJack F Vogel eventhandler_tag vlan_attach; 54061ae650dSJack F Vogel eventhandler_tag vlan_detach; 54161ae650dSJack F Vogel u16 num_vlans; 54261ae650dSJack F Vogel 54361ae650dSJack F Vogel /* Per-VSI stats from hardware */ 54461ae650dSJack F Vogel struct i40e_eth_stats eth_stats; 54561ae650dSJack F Vogel struct i40e_eth_stats eth_stats_offsets; 54661ae650dSJack F Vogel bool stat_offsets_loaded; 547e5100ee2SJack F Vogel /* VSI stat counters */ 5484b443922SGleb Smirnoff u64 ipackets; 5494b443922SGleb Smirnoff u64 ierrors; 5504b443922SGleb Smirnoff u64 opackets; 5514b443922SGleb Smirnoff u64 oerrors; 5524b443922SGleb Smirnoff u64 ibytes; 5534b443922SGleb Smirnoff u64 obytes; 5544b443922SGleb Smirnoff u64 imcasts; 5554b443922SGleb Smirnoff u64 omcasts; 5564b443922SGleb Smirnoff u64 iqdrops; 5574b443922SGleb Smirnoff u64 oqdrops; 5584b443922SGleb Smirnoff u64 noproto; 55961ae650dSJack F Vogel 56061ae650dSJack F Vogel /* Driver statistics */ 56161ae650dSJack F Vogel u64 hw_filters_del; 56261ae650dSJack F Vogel u64 hw_filters_add; 56361ae650dSJack F Vogel 56461ae650dSJack F Vogel /* Misc. */ 56561ae650dSJack F Vogel u64 active_queues; 56661ae650dSJack F Vogel u64 flags; 56756c2c47bSJack F Vogel struct sysctl_oid *vsi_node; 56861ae650dSJack F Vogel }; 56961ae650dSJack F Vogel 57061ae650dSJack F Vogel /* 57161ae650dSJack F Vogel ** Find the number of unrefreshed RX descriptors 57261ae650dSJack F Vogel */ 57361ae650dSJack F Vogel static inline u16 57461ae650dSJack F Vogel ixl_rx_unrefreshed(struct ixl_queue *que) 57561ae650dSJack F Vogel { 57661ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 57761ae650dSJack F Vogel 57861ae650dSJack F Vogel if (rxr->next_check > rxr->next_refresh) 57961ae650dSJack F Vogel return (rxr->next_check - rxr->next_refresh - 1); 58061ae650dSJack F Vogel else 58161ae650dSJack F Vogel return ((que->num_desc + rxr->next_check) - 58261ae650dSJack F Vogel rxr->next_refresh - 1); 58361ae650dSJack F Vogel } 58461ae650dSJack F Vogel 58561ae650dSJack F Vogel /* 58661ae650dSJack F Vogel ** Find the next available unused filter 58761ae650dSJack F Vogel */ 58861ae650dSJack F Vogel static inline struct ixl_mac_filter * 58961ae650dSJack F Vogel ixl_get_filter(struct ixl_vsi *vsi) 59061ae650dSJack F Vogel { 59161ae650dSJack F Vogel struct ixl_mac_filter *f; 59261ae650dSJack F Vogel 59361ae650dSJack F Vogel /* create a new empty filter */ 59461ae650dSJack F Vogel f = malloc(sizeof(struct ixl_mac_filter), 59561ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 596e5100ee2SJack F Vogel if (f) 59761ae650dSJack F Vogel SLIST_INSERT_HEAD(&vsi->ftl, f, next); 59861ae650dSJack F Vogel 59961ae650dSJack F Vogel return (f); 60061ae650dSJack F Vogel } 60161ae650dSJack F Vogel 60261ae650dSJack F Vogel /* 60361ae650dSJack F Vogel ** Compare two ethernet addresses 60461ae650dSJack F Vogel */ 60561ae650dSJack F Vogel static inline bool 60656c2c47bSJack F Vogel cmp_etheraddr(const u8 *ea1, const u8 *ea2) 60761ae650dSJack F Vogel { 60861ae650dSJack F Vogel bool cmp = FALSE; 60961ae650dSJack F Vogel 61061ae650dSJack F Vogel if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) && 61161ae650dSJack F Vogel (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) && 61261ae650dSJack F Vogel (ea1[4] == ea2[4]) && (ea1[5] == ea2[5])) 61361ae650dSJack F Vogel cmp = TRUE; 61461ae650dSJack F Vogel 61561ae650dSJack F Vogel return (cmp); 61661ae650dSJack F Vogel } 61761ae650dSJack F Vogel 61861ae650dSJack F Vogel /* 619*4294f337SSean Bruno * Return next largest power of 2, unsigned 620*4294f337SSean Bruno * 621*4294f337SSean Bruno * Public domain, from Bit Twiddling Hacks 622*4294f337SSean Bruno */ 623*4294f337SSean Bruno static inline u32 624*4294f337SSean Bruno next_power_of_two(u32 n) 625*4294f337SSean Bruno { 626*4294f337SSean Bruno n--; 627*4294f337SSean Bruno n |= n >> 1; 628*4294f337SSean Bruno n |= n >> 2; 629*4294f337SSean Bruno n |= n >> 4; 630*4294f337SSean Bruno n |= n >> 8; 631*4294f337SSean Bruno n |= n >> 16; 632*4294f337SSean Bruno n++; 633*4294f337SSean Bruno 634*4294f337SSean Bruno /* Next power of two > 0 is 1 */ 635*4294f337SSean Bruno n += (n == 0); 636*4294f337SSean Bruno 637*4294f337SSean Bruno return (n); 638*4294f337SSean Bruno } 639*4294f337SSean Bruno 640*4294f337SSean Bruno /* 64161ae650dSJack F Vogel * Info for stats sysctls 64261ae650dSJack F Vogel */ 64361ae650dSJack F Vogel struct ixl_sysctl_info { 64461ae650dSJack F Vogel u64 *stat; 64561ae650dSJack F Vogel char *name; 64661ae650dSJack F Vogel char *description; 64761ae650dSJack F Vogel }; 64861ae650dSJack F Vogel 649*4294f337SSean Bruno static uint8_t ixl_bcast_addr[ETHER_ADDR_LEN] = 650*4294f337SSean Bruno {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 65161ae650dSJack F Vogel 65261ae650dSJack F Vogel /********************************************************************* 65361ae650dSJack F Vogel * TXRX Function prototypes 65461ae650dSJack F Vogel *********************************************************************/ 65561ae650dSJack F Vogel int ixl_allocate_tx_data(struct ixl_queue *); 65661ae650dSJack F Vogel int ixl_allocate_rx_data(struct ixl_queue *); 65761ae650dSJack F Vogel void ixl_init_tx_ring(struct ixl_queue *); 65861ae650dSJack F Vogel int ixl_init_rx_ring(struct ixl_queue *); 65961ae650dSJack F Vogel bool ixl_rxeof(struct ixl_queue *, int); 66061ae650dSJack F Vogel bool ixl_txeof(struct ixl_queue *); 661*4294f337SSean Bruno void ixl_free_que_tx(struct ixl_queue *); 662*4294f337SSean Bruno void ixl_free_que_rx(struct ixl_queue *); 663*4294f337SSean Bruno 66461ae650dSJack F Vogel int ixl_mq_start(struct ifnet *, struct mbuf *); 66561ae650dSJack F Vogel int ixl_mq_start_locked(struct ifnet *, struct tx_ring *); 66661ae650dSJack F Vogel void ixl_deferred_mq_start(void *, int); 66761ae650dSJack F Vogel void ixl_free_vsi(struct ixl_vsi *); 668*4294f337SSean Bruno void ixl_qflush(struct ifnet *); 669*4294f337SSean Bruno 670*4294f337SSean Bruno /* Common function prototypes between PF/VF driver */ 6714b443922SGleb Smirnoff #if __FreeBSD_version >= 1100000 6724b443922SGleb Smirnoff uint64_t ixl_get_counter(if_t ifp, ift_counter cnt); 6734b443922SGleb Smirnoff #endif 674*4294f337SSean Bruno void ixl_get_default_rss_key(u32 *); 67561ae650dSJack F Vogel #endif /* _IXL_H_ */ 676