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 39*f7c73984SSean Bruno #include "opt_inet.h" 40*f7c73984SSean Bruno #include "opt_inet6.h" 41*f7c73984SSean Bruno #include "opt_rss.h" 42*f7c73984SSean Bruno 4361ae650dSJack F Vogel #include <sys/param.h> 4461ae650dSJack F Vogel #include <sys/systm.h> 4561ae650dSJack F Vogel #include <sys/buf_ring.h> 4661ae650dSJack F Vogel #include <sys/mbuf.h> 4761ae650dSJack F Vogel #include <sys/protosw.h> 4861ae650dSJack F Vogel #include <sys/socket.h> 4961ae650dSJack F Vogel #include <sys/malloc.h> 5061ae650dSJack F Vogel #include <sys/kernel.h> 5161ae650dSJack F Vogel #include <sys/module.h> 5261ae650dSJack F Vogel #include <sys/sockio.h> 5313b40804SSteven Hartland #include <sys/eventhandler.h> 5461ae650dSJack F Vogel 5561ae650dSJack F Vogel #include <net/if.h> 5613b40804SSteven Hartland #include <net/if_var.h> 5761ae650dSJack F Vogel #include <net/if_arp.h> 5861ae650dSJack F Vogel #include <net/bpf.h> 5961ae650dSJack F Vogel #include <net/ethernet.h> 6061ae650dSJack F Vogel #include <net/if_dl.h> 6161ae650dSJack F Vogel #include <net/if_media.h> 6261ae650dSJack F Vogel 6361ae650dSJack F Vogel #include <net/bpf.h> 6461ae650dSJack F Vogel #include <net/if_types.h> 6561ae650dSJack F Vogel #include <net/if_vlan_var.h> 6661ae650dSJack F Vogel 6761ae650dSJack F Vogel #include <netinet/in_systm.h> 6861ae650dSJack F Vogel #include <netinet/in.h> 6961ae650dSJack F Vogel #include <netinet/if_ether.h> 7061ae650dSJack F Vogel #include <netinet/ip.h> 7161ae650dSJack F Vogel #include <netinet/ip6.h> 7261ae650dSJack F Vogel #include <netinet/tcp.h> 7361ae650dSJack F Vogel #include <netinet/tcp_lro.h> 7461ae650dSJack F Vogel #include <netinet/udp.h> 7561ae650dSJack F Vogel #include <netinet/sctp.h> 7661ae650dSJack F Vogel 7761ae650dSJack F Vogel #include <machine/in_cksum.h> 7861ae650dSJack F Vogel 7961ae650dSJack F Vogel #include <sys/bus.h> 8061ae650dSJack F Vogel #include <machine/bus.h> 8161ae650dSJack F Vogel #include <sys/rman.h> 8261ae650dSJack F Vogel #include <machine/resource.h> 8361ae650dSJack F Vogel #include <vm/vm.h> 8461ae650dSJack F Vogel #include <vm/pmap.h> 8561ae650dSJack F Vogel #include <machine/clock.h> 8661ae650dSJack F Vogel #include <dev/pci/pcivar.h> 8761ae650dSJack F Vogel #include <dev/pci/pcireg.h> 8861ae650dSJack F Vogel #include <sys/proc.h> 8961ae650dSJack F Vogel #include <sys/sysctl.h> 9061ae650dSJack F Vogel #include <sys/endian.h> 9161ae650dSJack F Vogel #include <sys/taskqueue.h> 9261ae650dSJack F Vogel #include <sys/pcpu.h> 9361ae650dSJack F Vogel #include <sys/smp.h> 941d767a8eSEric Joyner #include <sys/sbuf.h> 9561ae650dSJack F Vogel #include <machine/smp.h> 964294f337SSean Bruno #include <machine/stdarg.h> 9761ae650dSJack F Vogel 984294f337SSean Bruno #ifdef RSS 994294f337SSean Bruno #include <net/rss_config.h> 100*f7c73984SSean Bruno #include <netinet/in_rss.h> 10156c2c47bSJack F Vogel #endif 10256c2c47bSJack F Vogel 10361ae650dSJack F Vogel #include "i40e_type.h" 10461ae650dSJack F Vogel #include "i40e_prototype.h" 10561ae650dSJack F Vogel 10661ae650dSJack F Vogel #define MAC_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" 10761ae650dSJack F Vogel #define MAC_FORMAT_ARGS(mac_addr) \ 10861ae650dSJack F Vogel (mac_addr)[0], (mac_addr)[1], (mac_addr)[2], (mac_addr)[3], \ 10961ae650dSJack F Vogel (mac_addr)[4], (mac_addr)[5] 11061ae650dSJack F Vogel #define ON_OFF_STR(is_set) ((is_set) ? "On" : "Off") 11161ae650dSJack F Vogel 112393c4bb1SJack F Vogel #ifdef IXL_DEBUG 11361ae650dSJack F Vogel 11461ae650dSJack F Vogel #define _DBG_PRINTF(S, ...) printf("%s: " S "\n", __func__, ##__VA_ARGS__) 11561ae650dSJack F Vogel #define _DEV_DBG_PRINTF(dev, S, ...) device_printf(dev, "%s: " S "\n", __func__, ##__VA_ARGS__) 11661ae650dSJack F Vogel #define _IF_DBG_PRINTF(ifp, S, ...) if_printf(ifp, "%s: " S "\n", __func__, ##__VA_ARGS__) 11761ae650dSJack F Vogel 11861ae650dSJack F Vogel /* Defines for printing generic debug information */ 11961ae650dSJack F Vogel #define DPRINTF(...) _DBG_PRINTF(__VA_ARGS__) 12061ae650dSJack F Vogel #define DDPRINTF(...) _DEV_DBG_PRINTF(__VA_ARGS__) 12161ae650dSJack F Vogel #define IDPRINTF(...) _IF_DBG_PRINTF(__VA_ARGS__) 12261ae650dSJack F Vogel 12361ae650dSJack F Vogel /* Defines for printing specific debug information */ 12461ae650dSJack F Vogel #define DEBUG_INIT 1 12561ae650dSJack F Vogel #define DEBUG_IOCTL 1 12661ae650dSJack F Vogel #define DEBUG_HW 1 12761ae650dSJack F Vogel 12861ae650dSJack F Vogel #define INIT_DEBUGOUT(...) if (DEBUG_INIT) _DBG_PRINTF(__VA_ARGS__) 12961ae650dSJack F Vogel #define INIT_DBG_DEV(...) if (DEBUG_INIT) _DEV_DBG_PRINTF(__VA_ARGS__) 13061ae650dSJack F Vogel #define INIT_DBG_IF(...) if (DEBUG_INIT) _IF_DBG_PRINTF(__VA_ARGS__) 13161ae650dSJack F Vogel 13261ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...) if (DEBUG_IOCTL) _DBG_PRINTF(__VA_ARGS__) 13361ae650dSJack F Vogel #define IOCTL_DBG_IF2(ifp, S, ...) if (DEBUG_IOCTL) \ 13461ae650dSJack F Vogel if_printf(ifp, S "\n", ##__VA_ARGS__) 13561ae650dSJack F Vogel #define IOCTL_DBG_IF(...) if (DEBUG_IOCTL) _IF_DBG_PRINTF(__VA_ARGS__) 13661ae650dSJack F Vogel 13761ae650dSJack F Vogel #define HW_DEBUGOUT(...) if (DEBUG_HW) _DBG_PRINTF(__VA_ARGS__) 13861ae650dSJack F Vogel 139393c4bb1SJack F Vogel #else /* no IXL_DEBUG */ 14061ae650dSJack F Vogel #define DEBUG_INIT 0 14161ae650dSJack F Vogel #define DEBUG_IOCTL 0 14261ae650dSJack F Vogel #define DEBUG_HW 0 14361ae650dSJack F Vogel 14461ae650dSJack F Vogel #define DPRINTF(...) 14561ae650dSJack F Vogel #define DDPRINTF(...) 14661ae650dSJack F Vogel #define IDPRINTF(...) 14761ae650dSJack F Vogel 14861ae650dSJack F Vogel #define INIT_DEBUGOUT(...) 14961ae650dSJack F Vogel #define INIT_DBG_DEV(...) 15061ae650dSJack F Vogel #define INIT_DBG_IF(...) 15161ae650dSJack F Vogel #define IOCTL_DEBUGOUT(...) 15261ae650dSJack F Vogel #define IOCTL_DBG_IF2(...) 15361ae650dSJack F Vogel #define IOCTL_DBG_IF(...) 15461ae650dSJack F Vogel #define HW_DEBUGOUT(...) 155393c4bb1SJack F Vogel #endif /* IXL_DEBUG */ 15661ae650dSJack F Vogel 1574294f337SSean Bruno enum ixl_dbg_mask { 1584294f337SSean Bruno IXL_DBG_INFO = 0x00000001, 1594294f337SSean Bruno IXL_DBG_EN_DIS = 0x00000002, 1604294f337SSean Bruno IXL_DBG_AQ = 0x00000004, 1614294f337SSean Bruno IXL_DBG_NVMUPD = 0x00000008, 1624294f337SSean Bruno 1634294f337SSean Bruno IXL_DBG_IOCTL_KNOWN = 0x00000010, 1644294f337SSean Bruno IXL_DBG_IOCTL_UNKNOWN = 0x00000020, 1654294f337SSean Bruno IXL_DBG_IOCTL_ALL = 0x00000030, 1664294f337SSean Bruno 1674294f337SSean Bruno I40E_DEBUG_RSS = 0x00000100, 1684294f337SSean Bruno 1694294f337SSean Bruno IXL_DBG_IOV = 0x00001000, 1704294f337SSean Bruno IXL_DBG_IOV_VC = 0x00002000, 1714294f337SSean Bruno 1724294f337SSean Bruno IXL_DBG_SWITCH_INFO = 0x00010000, 1734294f337SSean Bruno 1744294f337SSean Bruno IXL_DBG_ALL = 0xFFFFFFFF 1754294f337SSean Bruno }; 1764294f337SSean Bruno 17761ae650dSJack F Vogel /* Tunables */ 17861ae650dSJack F Vogel 17961ae650dSJack F Vogel /* 18061ae650dSJack F Vogel * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the 18161ae650dSJack F Vogel * number of tx/rx descriptors allocated by the driver. Increasing this 1826c426059SEric Joyner * value allows the driver to queue more operations. 1836c426059SEric Joyner * 1846c426059SEric Joyner * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes. 1856c426059SEric Joyner * The driver currently always uses 32 byte Rx descriptors. 18661ae650dSJack F Vogel */ 18761ae650dSJack F Vogel #define DEFAULT_RING 1024 1884294f337SSean Bruno #define IXL_MAX_RING 8160 1894294f337SSean Bruno #define IXL_MIN_RING 32 1904294f337SSean Bruno #define IXL_RING_INCREMENT 32 1914294f337SSean Bruno 1924294f337SSean Bruno #define IXL_AQ_LEN 256 1934294f337SSean Bruno #define IXL_AQ_LEN_MAX 1024 19461ae650dSJack F Vogel 19561ae650dSJack F Vogel /* 19661ae650dSJack F Vogel ** Default number of entries in Tx queue buf_ring. 19761ae650dSJack F Vogel */ 1984294f337SSean Bruno #define DEFAULT_TXBRSZ 4096 19961ae650dSJack F Vogel 20061ae650dSJack F Vogel /* Alignment for rings */ 20161ae650dSJack F Vogel #define DBA_ALIGN 128 20261ae650dSJack F Vogel 20361ae650dSJack F Vogel /* 20461ae650dSJack F Vogel * This is the max watchdog interval, ie. the time that can 20561ae650dSJack F Vogel * pass between any two TX clean operations, such only happening 20661ae650dSJack F Vogel * when the TX hardware is functioning. 20761ae650dSJack F Vogel */ 20861ae650dSJack F Vogel #define IXL_WATCHDOG (10 * hz) 20961ae650dSJack F Vogel 21061ae650dSJack F Vogel /* 21161ae650dSJack F Vogel * This parameters control when the driver calls the routine to reclaim 21261ae650dSJack F Vogel * transmit descriptors. 21361ae650dSJack F Vogel */ 21461ae650dSJack F Vogel #define IXL_TX_CLEANUP_THRESHOLD (que->num_desc / 8) 21561ae650dSJack F Vogel #define IXL_TX_OP_THRESHOLD (que->num_desc / 32) 21661ae650dSJack F Vogel 21761ae650dSJack F Vogel #define MAX_MULTICAST_ADDR 128 21861ae650dSJack F Vogel 21961ae650dSJack F Vogel #define IXL_BAR 3 22061ae650dSJack F Vogel #define IXL_ADM_LIMIT 2 22161ae650dSJack F Vogel #define IXL_TSO_SIZE 65535 22261ae650dSJack F Vogel #define IXL_AQ_BUF_SZ ((u32) 4096) 22361ae650dSJack F Vogel #define IXL_RX_HDR 128 22461ae650dSJack F Vogel #define IXL_RX_LIMIT 512 22561ae650dSJack F Vogel #define IXL_RX_ITR 0 22661ae650dSJack F Vogel #define IXL_TX_ITR 1 22761ae650dSJack F Vogel #define IXL_ITR_NONE 3 22861ae650dSJack F Vogel #define IXL_QUEUE_EOL 0x7FF 2296c426059SEric Joyner #define IXL_MAX_FRAME 9728 23061ae650dSJack F Vogel #define IXL_MAX_TX_SEGS 8 2314294f337SSean Bruno #define IXL_MAX_TSO_SEGS 128 23261ae650dSJack F Vogel #define IXL_SPARSE_CHAIN 6 23361ae650dSJack F Vogel #define IXL_QUEUE_HUNG 0x80000000 2344294f337SSean Bruno 2354294f337SSean Bruno #define IXL_RSS_KEY_SIZE_REG 13 2364294f337SSean Bruno #define IXL_RSS_KEY_SIZE (IXL_RSS_KEY_SIZE_REG * 4) 2374294f337SSean Bruno #define IXL_RSS_VSI_LUT_SIZE 64 /* X722 -> VSI, X710 -> VF */ 2384294f337SSean Bruno #define IXL_RSS_VSI_LUT_ENTRY_MASK 0x3F 2394294f337SSean Bruno #define IXL_RSS_VF_LUT_ENTRY_MASK 0xF 24061ae650dSJack F Vogel 24156c2c47bSJack F Vogel #define IXL_VF_MAX_BUFFER 0x3F80 24256c2c47bSJack F Vogel #define IXL_VF_MAX_HDR_BUFFER 0x840 24356c2c47bSJack F Vogel #define IXL_VF_MAX_FRAME 0x3FFF 24456c2c47bSJack F Vogel 2454294f337SSean Bruno /* ERJ: hardware can support ~2k (SW5+) filters between all functions */ 24661ae650dSJack F Vogel #define IXL_MAX_FILTERS 256 24761ae650dSJack F Vogel #define IXL_MAX_TX_BUSY 10 24861ae650dSJack F Vogel 24961ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_SHIFT 0 25061ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_MASK (0xff << IXL_NVM_VERSION_LO_SHIFT) 25161ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_SHIFT 12 25261ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_MASK (0xf << IXL_NVM_VERSION_HI_SHIFT) 25361ae650dSJack F Vogel 25461ae650dSJack F Vogel /* 25561ae650dSJack F Vogel * Interrupt Moderation parameters 25661ae650dSJack F Vogel */ 25761ae650dSJack F Vogel #define IXL_MAX_ITR 0x07FF 25861ae650dSJack F Vogel #define IXL_ITR_100K 0x0005 25961ae650dSJack F Vogel #define IXL_ITR_20K 0x0019 26061ae650dSJack F Vogel #define IXL_ITR_8K 0x003E 26161ae650dSJack F Vogel #define IXL_ITR_4K 0x007A 26261ae650dSJack F Vogel #define IXL_ITR_DYNAMIC 0x8000 26361ae650dSJack F Vogel #define IXL_LOW_LATENCY 0 26461ae650dSJack F Vogel #define IXL_AVE_LATENCY 1 26561ae650dSJack F Vogel #define IXL_BULK_LATENCY 2 26661ae650dSJack F Vogel 26761ae650dSJack F Vogel /* MacVlan Flags */ 26861ae650dSJack F Vogel #define IXL_FILTER_USED (u16)(1 << 0) 26961ae650dSJack F Vogel #define IXL_FILTER_VLAN (u16)(1 << 1) 27061ae650dSJack F Vogel #define IXL_FILTER_ADD (u16)(1 << 2) 27161ae650dSJack F Vogel #define IXL_FILTER_DEL (u16)(1 << 3) 27261ae650dSJack F Vogel #define IXL_FILTER_MC (u16)(1 << 4) 27361ae650dSJack F Vogel 27461ae650dSJack F Vogel /* used in the vlan field of the filter when not a vlan */ 27561ae650dSJack F Vogel #define IXL_VLAN_ANY -1 27661ae650dSJack F Vogel 27761ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP) 27861ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6) 27961ae650dSJack F Vogel #define CSUM_OFFLOAD (CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO) 28061ae650dSJack F Vogel 28161ae650dSJack F Vogel /* Misc flags for ixl_vsi.flags */ 28261ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO4 (1 << 0) 28361ae650dSJack F Vogel #define IXL_FLAGS_KEEP_TSO6 (1 << 1) 28461ae650dSJack F Vogel 28556c2c47bSJack F Vogel #define IXL_VF_RESET_TIMEOUT 100 28656c2c47bSJack F Vogel 28756c2c47bSJack F Vogel #define IXL_VSI_DATA_PORT 0x01 28856c2c47bSJack F Vogel 28956c2c47bSJack F Vogel #define IXLV_MAX_QUEUES 16 29056c2c47bSJack F Vogel #define IXL_MAX_VSI_QUEUES (2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1)) 29156c2c47bSJack F Vogel 29256c2c47bSJack F Vogel #define IXL_RX_CTX_BASE_UNITS 128 29356c2c47bSJack F Vogel #define IXL_TX_CTX_BASE_UNITS 128 29456c2c47bSJack F Vogel 29556c2c47bSJack F Vogel #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \ 29656c2c47bSJack F Vogel I40E_VPINT_LNKLSTN(((vector) - 1) + \ 29756c2c47bSJack F Vogel (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 29856c2c47bSJack F Vogel 29956c2c47bSJack F Vogel #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \ 30056c2c47bSJack F Vogel I40E_VFINT_DYN_CTLN(((vector) - 1) + \ 30156c2c47bSJack F Vogel (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 30256c2c47bSJack F Vogel 30356c2c47bSJack F Vogel #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS 0xAA 30456c2c47bSJack F Vogel 30556c2c47bSJack F Vogel #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK 0x20 30656c2c47bSJack F Vogel 30756c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf) ((glb_vf) / 32) 30856c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf) (1 << ((glb_vf) % 32)) 30956c2c47bSJack F Vogel 31056c2c47bSJack F Vogel #define IXL_MAX_ITR_IDX 3 31156c2c47bSJack F Vogel 31256c2c47bSJack F Vogel #define IXL_END_OF_INTR_LNKLST 0x7FF 31356c2c47bSJack F Vogel 3144294f337SSean Bruno #define IXL_DEFAULT_RSS_HENA (\ 3154294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \ 3164294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \ 3174294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \ 3184294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \ 3194294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) | \ 3204294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \ 3214294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \ 3224294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \ 3234294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \ 3244294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) | \ 3254294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD)) 3264294f337SSean Bruno 32761ae650dSJack F Vogel #define IXL_TX_LOCK(_sc) mtx_lock(&(_sc)->mtx) 32861ae650dSJack F Vogel #define IXL_TX_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx) 32961ae650dSJack F Vogel #define IXL_TX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx) 33061ae650dSJack F Vogel #define IXL_TX_TRYLOCK(_sc) mtx_trylock(&(_sc)->mtx) 33161ae650dSJack F Vogel #define IXL_TX_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED) 33261ae650dSJack F Vogel 33361ae650dSJack F Vogel #define IXL_RX_LOCK(_sc) mtx_lock(&(_sc)->mtx) 33461ae650dSJack F Vogel #define IXL_RX_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx) 33561ae650dSJack F Vogel #define IXL_RX_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx) 33661ae650dSJack F Vogel 337a48d00d2SEric Joyner /* Pre-11 counter(9) compatibility */ 338b6c8f260SJack F Vogel #if __FreeBSD_version >= 1100036 3394b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ipackets = (count) 3404b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ierrors = (count) 3414b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->opackets = (count) 3424b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->oerrors = (count) 3434b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) /* Do nothing; collisions is always 0. */ 3444b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ibytes = (count) 3454b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->obytes = (count) 3464b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->imcasts = (count) 3474b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->omcasts = (count) 3484b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->iqdrops = (count) 349625d12c6SJohn Baldwin #define IXL_SET_OQDROPS(vsi, count) (vsi)->oqdrops = (count) 3504b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 3514b443922SGleb Smirnoff #else 3524b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ifp->if_ipackets = (count) 3534b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ifp->if_ierrors = (count) 3544b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->ifp->if_opackets = (count) 3554b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->ifp->if_oerrors = (count) 3564b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) (vsi)->ifp->if_collisions = (count) 3574b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ifp->if_ibytes = (count) 3584b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->ifp->if_obytes = (count) 3594b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->ifp->if_imcasts = (count) 3604b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->ifp->if_omcasts = (count) 3614b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->ifp->if_iqdrops = (count) 3624b443922SGleb Smirnoff #define IXL_SET_OQDROPS(vsi, odrops) (vsi)->ifp->if_snd.ifq_drops = (odrops) 3634b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 3644b443922SGleb Smirnoff #endif 3654b443922SGleb Smirnoff 36661ae650dSJack F Vogel /* 36761ae650dSJack F Vogel ***************************************************************************** 36861ae650dSJack F Vogel * vendor_info_array 36961ae650dSJack F Vogel * 37061ae650dSJack F Vogel * This array contains the list of Subvendor/Subdevice IDs on which the driver 37161ae650dSJack F Vogel * should load. 37261ae650dSJack F Vogel * 37361ae650dSJack F Vogel ***************************************************************************** 37461ae650dSJack F Vogel */ 37561ae650dSJack F Vogel typedef struct _ixl_vendor_info_t { 37661ae650dSJack F Vogel unsigned int vendor_id; 37761ae650dSJack F Vogel unsigned int device_id; 37861ae650dSJack F Vogel unsigned int subvendor_id; 37961ae650dSJack F Vogel unsigned int subdevice_id; 38061ae650dSJack F Vogel unsigned int index; 38161ae650dSJack F Vogel } ixl_vendor_info_t; 38261ae650dSJack F Vogel 38361ae650dSJack F Vogel 38461ae650dSJack F Vogel struct ixl_tx_buf { 38561ae650dSJack F Vogel u32 eop_index; 38661ae650dSJack F Vogel struct mbuf *m_head; 38761ae650dSJack F Vogel bus_dmamap_t map; 38861ae650dSJack F Vogel bus_dma_tag_t tag; 38961ae650dSJack F Vogel }; 39061ae650dSJack F Vogel 39161ae650dSJack F Vogel struct ixl_rx_buf { 39261ae650dSJack F Vogel struct mbuf *m_head; 39361ae650dSJack F Vogel struct mbuf *m_pack; 39461ae650dSJack F Vogel struct mbuf *fmp; 39561ae650dSJack F Vogel bus_dmamap_t hmap; 39661ae650dSJack F Vogel bus_dmamap_t pmap; 39761ae650dSJack F Vogel }; 39861ae650dSJack F Vogel 39961ae650dSJack F Vogel /* 40061ae650dSJack F Vogel ** This struct has multiple uses, multicast 40161ae650dSJack F Vogel ** addresses, vlans, and mac filters all use it. 40261ae650dSJack F Vogel */ 40361ae650dSJack F Vogel struct ixl_mac_filter { 40461ae650dSJack F Vogel SLIST_ENTRY(ixl_mac_filter) next; 40561ae650dSJack F Vogel u8 macaddr[ETHER_ADDR_LEN]; 40661ae650dSJack F Vogel s16 vlan; 40761ae650dSJack F Vogel u16 flags; 40861ae650dSJack F Vogel }; 40961ae650dSJack F Vogel 41061ae650dSJack F Vogel /* 41161ae650dSJack F Vogel * The Transmit ring control struct 41261ae650dSJack F Vogel */ 41361ae650dSJack F Vogel struct tx_ring { 41461ae650dSJack F Vogel struct ixl_queue *que; 41561ae650dSJack F Vogel struct mtx mtx; 41661ae650dSJack F Vogel u32 tail; 41761ae650dSJack F Vogel struct i40e_tx_desc *base; 41861ae650dSJack F Vogel struct i40e_dma_mem dma; 41961ae650dSJack F Vogel u16 next_avail; 42061ae650dSJack F Vogel u16 next_to_clean; 42161ae650dSJack F Vogel u16 atr_rate; 42261ae650dSJack F Vogel u16 atr_count; 4236d011ad5SEric Joyner u32 itr; 4246d011ad5SEric Joyner u32 latency; 42561ae650dSJack F Vogel struct ixl_tx_buf *buffers; 42661ae650dSJack F Vogel volatile u16 avail; 42761ae650dSJack F Vogel u32 cmd; 42861ae650dSJack F Vogel bus_dma_tag_t tx_tag; 42961ae650dSJack F Vogel bus_dma_tag_t tso_tag; 43061ae650dSJack F Vogel char mtx_name[16]; 43161ae650dSJack F Vogel struct buf_ring *br; 43261ae650dSJack F Vogel 43361ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 43461ae650dSJack F Vogel u32 packets; 43561ae650dSJack F Vogel u32 bytes; 43661ae650dSJack F Vogel 43761ae650dSJack F Vogel /* Soft Stats */ 43861ae650dSJack F Vogel u64 tx_bytes; 43961ae650dSJack F Vogel u64 no_desc; 44061ae650dSJack F Vogel u64 total_packets; 44161ae650dSJack F Vogel }; 44261ae650dSJack F Vogel 44361ae650dSJack F Vogel 44461ae650dSJack F Vogel /* 44561ae650dSJack F Vogel * The Receive ring control struct 44661ae650dSJack F Vogel */ 44761ae650dSJack F Vogel struct rx_ring { 44861ae650dSJack F Vogel struct ixl_queue *que; 44961ae650dSJack F Vogel struct mtx mtx; 45061ae650dSJack F Vogel union i40e_rx_desc *base; 45161ae650dSJack F Vogel struct i40e_dma_mem dma; 45261ae650dSJack F Vogel struct lro_ctrl lro; 45361ae650dSJack F Vogel bool lro_enabled; 45461ae650dSJack F Vogel bool hdr_split; 45561ae650dSJack F Vogel bool discard; 4566d011ad5SEric Joyner u32 next_refresh; 4576d011ad5SEric Joyner u32 next_check; 4586d011ad5SEric Joyner u32 itr; 4596d011ad5SEric Joyner u32 latency; 46061ae650dSJack F Vogel char mtx_name[16]; 46161ae650dSJack F Vogel struct ixl_rx_buf *buffers; 46261ae650dSJack F Vogel u32 mbuf_sz; 46361ae650dSJack F Vogel u32 tail; 46461ae650dSJack F Vogel bus_dma_tag_t htag; 46561ae650dSJack F Vogel bus_dma_tag_t ptag; 46661ae650dSJack F Vogel 46761ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 46861ae650dSJack F Vogel u32 packets; 46961ae650dSJack F Vogel u32 bytes; 47061ae650dSJack F Vogel 47161ae650dSJack F Vogel /* Soft stats */ 47261ae650dSJack F Vogel u64 split; 47361ae650dSJack F Vogel u64 rx_packets; 47461ae650dSJack F Vogel u64 rx_bytes; 4756d011ad5SEric Joyner u64 desc_errs; 47661ae650dSJack F Vogel u64 not_done; 47761ae650dSJack F Vogel }; 47861ae650dSJack F Vogel 47961ae650dSJack F Vogel /* 48061ae650dSJack F Vogel ** Driver queue struct: this is the interrupt container 48161ae650dSJack F Vogel ** for the associated tx and rx ring pair. 48261ae650dSJack F Vogel */ 48361ae650dSJack F Vogel struct ixl_queue { 48461ae650dSJack F Vogel struct ixl_vsi *vsi; 48561ae650dSJack F Vogel u32 me; 48661ae650dSJack F Vogel u32 msix; /* This queue's MSIX vector */ 48761ae650dSJack F Vogel u32 eims; /* This queue's EIMS bit */ 48861ae650dSJack F Vogel struct resource *res; 48961ae650dSJack F Vogel void *tag; 49061ae650dSJack F Vogel int num_desc; /* both tx and rx */ 49161ae650dSJack F Vogel int busy; 49261ae650dSJack F Vogel struct tx_ring txr; 49361ae650dSJack F Vogel struct rx_ring rxr; 49461ae650dSJack F Vogel struct task task; 49561ae650dSJack F Vogel struct task tx_task; 49661ae650dSJack F Vogel struct taskqueue *tq; 49761ae650dSJack F Vogel 49861ae650dSJack F Vogel /* Queue stats */ 49961ae650dSJack F Vogel u64 irqs; 50061ae650dSJack F Vogel u64 tso; 50161ae650dSJack F Vogel u64 mbuf_defrag_failed; 50261ae650dSJack F Vogel u64 mbuf_hdr_failed; 50361ae650dSJack F Vogel u64 mbuf_pkt_failed; 5044294f337SSean Bruno u64 tx_dmamap_failed; 50561ae650dSJack F Vogel u64 dropped_pkts; 50661ae650dSJack F Vogel }; 50761ae650dSJack F Vogel 50861ae650dSJack F Vogel /* 5094294f337SSean Bruno ** Virtual Station Interface 51061ae650dSJack F Vogel */ 51161ae650dSJack F Vogel SLIST_HEAD(ixl_ftl_head, ixl_mac_filter); 51261ae650dSJack F Vogel struct ixl_vsi { 51361ae650dSJack F Vogel void *back; 51461ae650dSJack F Vogel struct ifnet *ifp; 51561ae650dSJack F Vogel struct device *dev; 51661ae650dSJack F Vogel struct i40e_hw *hw; 51761ae650dSJack F Vogel struct ifmedia media; 518ac83ea83SEric Joyner enum i40e_vsi_type type; 51961ae650dSJack F Vogel int id; 52061ae650dSJack F Vogel u16 num_queues; 5216d011ad5SEric Joyner u32 rx_itr_setting; 5226d011ad5SEric Joyner u32 tx_itr_setting; 5234294f337SSean Bruno u16 max_frame_size; 5244294f337SSean Bruno 52561ae650dSJack F Vogel struct ixl_queue *queues; /* head of queues */ 5264294f337SSean Bruno 5274294f337SSean Bruno u16 vsi_num; 52861ae650dSJack F Vogel bool link_active; 52961ae650dSJack F Vogel u16 seid; 53056c2c47bSJack F Vogel u16 uplink_seid; 53156c2c47bSJack F Vogel u16 downlink_seid; 53261ae650dSJack F Vogel 53361ae650dSJack F Vogel /* MAC/VLAN Filter list */ 53461ae650dSJack F Vogel struct ixl_ftl_head ftl; 53556c2c47bSJack F Vogel u16 num_macs; 53661ae650dSJack F Vogel 5374294f337SSean Bruno /* Contains readylist & stat counter id */ 53861ae650dSJack F Vogel struct i40e_aqc_vsi_properties_data info; 53961ae650dSJack F Vogel 54061ae650dSJack F Vogel eventhandler_tag vlan_attach; 54161ae650dSJack F Vogel eventhandler_tag vlan_detach; 54261ae650dSJack F Vogel u16 num_vlans; 54361ae650dSJack F Vogel 54461ae650dSJack F Vogel /* Per-VSI stats from hardware */ 54561ae650dSJack F Vogel struct i40e_eth_stats eth_stats; 54661ae650dSJack F Vogel struct i40e_eth_stats eth_stats_offsets; 54761ae650dSJack F Vogel bool stat_offsets_loaded; 548e5100ee2SJack F Vogel /* VSI stat counters */ 5494b443922SGleb Smirnoff u64 ipackets; 5504b443922SGleb Smirnoff u64 ierrors; 5514b443922SGleb Smirnoff u64 opackets; 5524b443922SGleb Smirnoff u64 oerrors; 5534b443922SGleb Smirnoff u64 ibytes; 5544b443922SGleb Smirnoff u64 obytes; 5554b443922SGleb Smirnoff u64 imcasts; 5564b443922SGleb Smirnoff u64 omcasts; 5574b443922SGleb Smirnoff u64 iqdrops; 5584b443922SGleb Smirnoff u64 oqdrops; 5594b443922SGleb Smirnoff u64 noproto; 56061ae650dSJack F Vogel 56161ae650dSJack F Vogel /* Driver statistics */ 56261ae650dSJack F Vogel u64 hw_filters_del; 56361ae650dSJack F Vogel u64 hw_filters_add; 56461ae650dSJack F Vogel 56561ae650dSJack F Vogel /* Misc. */ 56661ae650dSJack F Vogel u64 active_queues; 56761ae650dSJack F Vogel u64 flags; 56856c2c47bSJack F Vogel struct sysctl_oid *vsi_node; 56961ae650dSJack F Vogel }; 57061ae650dSJack F Vogel 57161ae650dSJack F Vogel /* 57261ae650dSJack F Vogel ** Find the number of unrefreshed RX descriptors 57361ae650dSJack F Vogel */ 57461ae650dSJack F Vogel static inline u16 57561ae650dSJack F Vogel ixl_rx_unrefreshed(struct ixl_queue *que) 57661ae650dSJack F Vogel { 57761ae650dSJack F Vogel struct rx_ring *rxr = &que->rxr; 57861ae650dSJack F Vogel 57961ae650dSJack F Vogel if (rxr->next_check > rxr->next_refresh) 58061ae650dSJack F Vogel return (rxr->next_check - rxr->next_refresh - 1); 58161ae650dSJack F Vogel else 58261ae650dSJack F Vogel return ((que->num_desc + rxr->next_check) - 58361ae650dSJack F Vogel rxr->next_refresh - 1); 58461ae650dSJack F Vogel } 58561ae650dSJack F Vogel 58661ae650dSJack F Vogel /* 58761ae650dSJack F Vogel ** Find the next available unused filter 58861ae650dSJack F Vogel */ 58961ae650dSJack F Vogel static inline struct ixl_mac_filter * 59061ae650dSJack F Vogel ixl_get_filter(struct ixl_vsi *vsi) 59161ae650dSJack F Vogel { 59261ae650dSJack F Vogel struct ixl_mac_filter *f; 59361ae650dSJack F Vogel 59461ae650dSJack F Vogel /* create a new empty filter */ 59561ae650dSJack F Vogel f = malloc(sizeof(struct ixl_mac_filter), 59661ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 597e5100ee2SJack F Vogel if (f) 59861ae650dSJack F Vogel SLIST_INSERT_HEAD(&vsi->ftl, f, next); 59961ae650dSJack F Vogel 60061ae650dSJack F Vogel return (f); 60161ae650dSJack F Vogel } 60261ae650dSJack F Vogel 60361ae650dSJack F Vogel /* 60461ae650dSJack F Vogel ** Compare two ethernet addresses 60561ae650dSJack F Vogel */ 60661ae650dSJack F Vogel static inline bool 60756c2c47bSJack F Vogel cmp_etheraddr(const u8 *ea1, const u8 *ea2) 60861ae650dSJack F Vogel { 60961ae650dSJack F Vogel bool cmp = FALSE; 61061ae650dSJack F Vogel 61161ae650dSJack F Vogel if ((ea1[0] == ea2[0]) && (ea1[1] == ea2[1]) && 61261ae650dSJack F Vogel (ea1[2] == ea2[2]) && (ea1[3] == ea2[3]) && 61361ae650dSJack F Vogel (ea1[4] == ea2[4]) && (ea1[5] == ea2[5])) 61461ae650dSJack F Vogel cmp = TRUE; 61561ae650dSJack F Vogel 61661ae650dSJack F Vogel return (cmp); 61761ae650dSJack F Vogel } 61861ae650dSJack F Vogel 61961ae650dSJack F Vogel /* 6204294f337SSean Bruno * Return next largest power of 2, unsigned 6214294f337SSean Bruno * 6224294f337SSean Bruno * Public domain, from Bit Twiddling Hacks 6234294f337SSean Bruno */ 6244294f337SSean Bruno static inline u32 6254294f337SSean Bruno next_power_of_two(u32 n) 6264294f337SSean Bruno { 6274294f337SSean Bruno n--; 6284294f337SSean Bruno n |= n >> 1; 6294294f337SSean Bruno n |= n >> 2; 6304294f337SSean Bruno n |= n >> 4; 6314294f337SSean Bruno n |= n >> 8; 6324294f337SSean Bruno n |= n >> 16; 6334294f337SSean Bruno n++; 6344294f337SSean Bruno 6354294f337SSean Bruno /* Next power of two > 0 is 1 */ 6364294f337SSean Bruno n += (n == 0); 6374294f337SSean Bruno 6384294f337SSean Bruno return (n); 6394294f337SSean Bruno } 6404294f337SSean Bruno 6414294f337SSean Bruno /* 64261ae650dSJack F Vogel * Info for stats sysctls 64361ae650dSJack F Vogel */ 64461ae650dSJack F Vogel struct ixl_sysctl_info { 64561ae650dSJack F Vogel u64 *stat; 64661ae650dSJack F Vogel char *name; 64761ae650dSJack F Vogel char *description; 64861ae650dSJack F Vogel }; 64961ae650dSJack F Vogel 6504294f337SSean Bruno static uint8_t ixl_bcast_addr[ETHER_ADDR_LEN] = 6514294f337SSean Bruno {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 65261ae650dSJack F Vogel 65361ae650dSJack F Vogel /********************************************************************* 65461ae650dSJack F Vogel * TXRX Function prototypes 65561ae650dSJack F Vogel *********************************************************************/ 65661ae650dSJack F Vogel int ixl_allocate_tx_data(struct ixl_queue *); 65761ae650dSJack F Vogel int ixl_allocate_rx_data(struct ixl_queue *); 65861ae650dSJack F Vogel void ixl_init_tx_ring(struct ixl_queue *); 65961ae650dSJack F Vogel int ixl_init_rx_ring(struct ixl_queue *); 66061ae650dSJack F Vogel bool ixl_rxeof(struct ixl_queue *, int); 66161ae650dSJack F Vogel bool ixl_txeof(struct ixl_queue *); 6624294f337SSean Bruno void ixl_free_que_tx(struct ixl_queue *); 6634294f337SSean Bruno void ixl_free_que_rx(struct ixl_queue *); 6644294f337SSean Bruno 66561ae650dSJack F Vogel int ixl_mq_start(struct ifnet *, struct mbuf *); 66661ae650dSJack F Vogel int ixl_mq_start_locked(struct ifnet *, struct tx_ring *); 66761ae650dSJack F Vogel void ixl_deferred_mq_start(void *, int); 66861ae650dSJack F Vogel void ixl_free_vsi(struct ixl_vsi *); 6694294f337SSean Bruno void ixl_qflush(struct ifnet *); 6704294f337SSean Bruno 6714294f337SSean Bruno /* Common function prototypes between PF/VF driver */ 6724b443922SGleb Smirnoff #if __FreeBSD_version >= 1100000 6734b443922SGleb Smirnoff uint64_t ixl_get_counter(if_t ifp, ift_counter cnt); 6744b443922SGleb Smirnoff #endif 6754294f337SSean Bruno void ixl_get_default_rss_key(u32 *); 67661ae650dSJack F Vogel #endif /* _IXL_H_ */ 677