161ae650dSJack F Vogel /****************************************************************************** 261ae650dSJack F Vogel 3f4cc2d17SEric Joyner Copyright (c) 2013-2018, 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 #ifndef _IXL_H_ 3661ae650dSJack F Vogel #define _IXL_H_ 3761ae650dSJack F Vogel 38f7c73984SSean Bruno #include "opt_inet.h" 39f7c73984SSean Bruno #include "opt_inet6.h" 40f7c73984SSean Bruno #include "opt_rss.h" 41cb6b8299SEric Joyner #include "opt_ixl.h" 42f7c73984SSean 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> 54cb6b8299SEric Joyner #include <sys/syslog.h> 55ab43ce7aSEric Joyner #include <sys/priv.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> 641031d839SEric Joyner #include <net/iflib.h> 6561ae650dSJack F Vogel 6661ae650dSJack F Vogel #include <net/bpf.h> 6761ae650dSJack F Vogel #include <net/if_types.h> 6861ae650dSJack F Vogel #include <net/if_vlan_var.h> 6961ae650dSJack F Vogel 7061ae650dSJack F Vogel #include <netinet/in_systm.h> 7161ae650dSJack F Vogel #include <netinet/in.h> 7261ae650dSJack F Vogel #include <netinet/if_ether.h> 7361ae650dSJack F Vogel #include <netinet/ip.h> 7461ae650dSJack F Vogel #include <netinet/ip6.h> 7561ae650dSJack F Vogel #include <netinet/tcp.h> 7661ae650dSJack F Vogel #include <netinet/tcp_lro.h> 7761ae650dSJack F Vogel #include <netinet/udp.h> 7861ae650dSJack F Vogel #include <netinet/sctp.h> 7961ae650dSJack F Vogel 8061ae650dSJack F Vogel #include <machine/in_cksum.h> 8161ae650dSJack F Vogel 8261ae650dSJack F Vogel #include <sys/bus.h> 8361ae650dSJack F Vogel #include <machine/bus.h> 8461ae650dSJack F Vogel #include <sys/rman.h> 8561ae650dSJack F Vogel #include <machine/resource.h> 8661ae650dSJack F Vogel #include <vm/vm.h> 8761ae650dSJack F Vogel #include <vm/pmap.h> 8861ae650dSJack F Vogel #include <machine/clock.h> 8961ae650dSJack F Vogel #include <dev/pci/pcivar.h> 9061ae650dSJack F Vogel #include <dev/pci/pcireg.h> 9161ae650dSJack F Vogel #include <sys/proc.h> 9261ae650dSJack F Vogel #include <sys/sysctl.h> 9361ae650dSJack F Vogel #include <sys/endian.h> 9461ae650dSJack F Vogel #include <sys/taskqueue.h> 9561ae650dSJack F Vogel #include <sys/pcpu.h> 9661ae650dSJack F Vogel #include <sys/smp.h> 971d767a8eSEric Joyner #include <sys/sbuf.h> 9861ae650dSJack F Vogel #include <machine/smp.h> 994294f337SSean Bruno #include <machine/stdarg.h> 10061ae650dSJack F Vogel 1014294f337SSean Bruno #ifdef RSS 1024294f337SSean Bruno #include <net/rss_config.h> 103f7c73984SSean Bruno #include <netinet/in_rss.h> 10456c2c47bSJack F Vogel #endif 10556c2c47bSJack F Vogel 1061031d839SEric Joyner #include "ifdi_if.h" 10761ae650dSJack F Vogel #include "i40e_type.h" 10861ae650dSJack F Vogel #include "i40e_prototype.h" 1091031d839SEric Joyner #include "ixl_debug.h" 11061ae650dSJack F Vogel 1111031d839SEric Joyner #define PVIDV(vendor, devid, name) \ 1121031d839SEric Joyner PVID(vendor, devid, name " - " IXL_DRIVER_VERSION_STRING) 1134294f337SSean Bruno 11461ae650dSJack F Vogel /* Tunables */ 11561ae650dSJack F Vogel 11661ae650dSJack F Vogel /* 11761ae650dSJack F Vogel * Ring Descriptors Valid Range: 32-4096 Default Value: 1024 This value is the 11861ae650dSJack F Vogel * number of tx/rx descriptors allocated by the driver. Increasing this 1196c426059SEric Joyner * value allows the driver to queue more operations. 1206c426059SEric Joyner * 1216c426059SEric Joyner * Tx descriptors are always 16 bytes, but Rx descriptors can be 32 bytes. 1226c426059SEric Joyner * The driver currently always uses 32 byte Rx descriptors. 12361ae650dSJack F Vogel */ 124cb6b8299SEric Joyner #define IXL_DEFAULT_RING 1024 125ceebc2f3SEric Joyner #define IXL_MAX_RING 4096 126ceebc2f3SEric Joyner #define IXL_MIN_RING 64 1274294f337SSean Bruno #define IXL_RING_INCREMENT 32 1284294f337SSean Bruno 1294294f337SSean Bruno #define IXL_AQ_LEN 256 1304294f337SSean Bruno #define IXL_AQ_LEN_MAX 1024 13161ae650dSJack F Vogel 13261ae650dSJack F Vogel /* Alignment for rings */ 13361ae650dSJack F Vogel #define DBA_ALIGN 128 13461ae650dSJack F Vogel 13561ae650dSJack F Vogel #define MAX_MULTICAST_ADDR 128 13661ae650dSJack F Vogel 137cb6b8299SEric Joyner #define IXL_MSIX_BAR 3 13861ae650dSJack F Vogel #define IXL_ADM_LIMIT 2 1391031d839SEric Joyner #define IXL_TSO_SIZE ((255*1024)-1) 1401031d839SEric Joyner #define IXL_TX_BUF_SZ ((u32) 1514) 14161ae650dSJack F Vogel #define IXL_AQ_BUF_SZ ((u32) 4096) 14261ae650dSJack F Vogel #define IXL_RX_ITR 0 14361ae650dSJack F Vogel #define IXL_TX_ITR 1 14461ae650dSJack F Vogel #define IXL_ITR_NONE 3 14561ae650dSJack F Vogel #define IXL_QUEUE_EOL 0x7FF 14677c1fcecSEric Joyner #define IXL_MIN_FRAME 17 1476c426059SEric Joyner #define IXL_MAX_FRAME 9728 14861ae650dSJack F Vogel #define IXL_MAX_TX_SEGS 8 1491031d839SEric Joyner #define IXL_MAX_RX_SEGS 5 1504294f337SSean Bruno #define IXL_MAX_TSO_SEGS 128 151ceebc2f3SEric Joyner #define IXL_SPARSE_CHAIN 7 152cb6b8299SEric Joyner #define IXL_MIN_TSO_MSS 64 15377c1fcecSEric Joyner #define IXL_MAX_TSO_MSS 9668 154ceebc2f3SEric Joyner #define IXL_MAX_DMA_SEG_SIZE ((16 * 1024) - 1) 1554294f337SSean Bruno 1564294f337SSean Bruno #define IXL_RSS_KEY_SIZE_REG 13 1574294f337SSean Bruno #define IXL_RSS_KEY_SIZE (IXL_RSS_KEY_SIZE_REG * 4) 1584294f337SSean Bruno #define IXL_RSS_VSI_LUT_SIZE 64 /* X722 -> VSI, X710 -> VF */ 1594294f337SSean Bruno #define IXL_RSS_VSI_LUT_ENTRY_MASK 0x3F 1604294f337SSean Bruno #define IXL_RSS_VF_LUT_ENTRY_MASK 0xF 16161ae650dSJack F Vogel 16256c2c47bSJack F Vogel #define IXL_VF_MAX_BUFFER 0x3F80 16356c2c47bSJack F Vogel #define IXL_VF_MAX_HDR_BUFFER 0x840 16456c2c47bSJack F Vogel #define IXL_VF_MAX_FRAME 0x3FFF 16556c2c47bSJack F Vogel 1664294f337SSean Bruno /* ERJ: hardware can support ~2k (SW5+) filters between all functions */ 16761ae650dSJack F Vogel #define IXL_MAX_FILTERS 256 16861ae650dSJack F Vogel 16961ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_SHIFT 0 17061ae650dSJack F Vogel #define IXL_NVM_VERSION_LO_MASK (0xff << IXL_NVM_VERSION_LO_SHIFT) 17161ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_SHIFT 12 17261ae650dSJack F Vogel #define IXL_NVM_VERSION_HI_MASK (0xf << IXL_NVM_VERSION_HI_SHIFT) 17361ae650dSJack F Vogel 17461ae650dSJack F Vogel /* 17561ae650dSJack F Vogel * Interrupt Moderation parameters 176cb6b8299SEric Joyner * Multiply ITR values by 2 for real ITR value 17761ae650dSJack F Vogel */ 178cb6b8299SEric Joyner #define IXL_MAX_ITR 0x0FF0 17961ae650dSJack F Vogel #define IXL_ITR_100K 0x0005 18061ae650dSJack F Vogel #define IXL_ITR_20K 0x0019 18161ae650dSJack F Vogel #define IXL_ITR_8K 0x003E 18261ae650dSJack F Vogel #define IXL_ITR_4K 0x007A 183cb6b8299SEric Joyner #define IXL_ITR_1K 0x01F4 18461ae650dSJack F Vogel #define IXL_ITR_DYNAMIC 0x8000 18561ae650dSJack F Vogel #define IXL_LOW_LATENCY 0 18661ae650dSJack F Vogel #define IXL_AVE_LATENCY 1 18761ae650dSJack F Vogel #define IXL_BULK_LATENCY 2 18861ae650dSJack F Vogel 18961ae650dSJack F Vogel /* MacVlan Flags */ 19061ae650dSJack F Vogel #define IXL_FILTER_USED (u16)(1 << 0) 19161ae650dSJack F Vogel #define IXL_FILTER_VLAN (u16)(1 << 1) 19261ae650dSJack F Vogel #define IXL_FILTER_ADD (u16)(1 << 2) 19361ae650dSJack F Vogel #define IXL_FILTER_DEL (u16)(1 << 3) 19461ae650dSJack F Vogel #define IXL_FILTER_MC (u16)(1 << 4) 19561ae650dSJack F Vogel 19661ae650dSJack F Vogel /* used in the vlan field of the filter when not a vlan */ 19761ae650dSJack F Vogel #define IXL_VLAN_ANY -1 19861ae650dSJack F Vogel 19961ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV4 (CSUM_IP|CSUM_TCP|CSUM_UDP|CSUM_SCTP) 20061ae650dSJack F Vogel #define CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6|CSUM_UDP_IPV6|CSUM_SCTP_IPV6) 20161ae650dSJack F Vogel #define CSUM_OFFLOAD (CSUM_OFFLOAD_IPV4|CSUM_OFFLOAD_IPV6|CSUM_TSO) 20261ae650dSJack F Vogel 203*b4a7ce06SEric Joyner /* Misc flags for ixl_vsi.flags */ 204*b4a7ce06SEric Joyner #define IXL_FLAGS_KEEP_TSO4 (1 << 0) 205*b4a7ce06SEric Joyner #define IXL_FLAGS_KEEP_TSO6 (1 << 1) 206*b4a7ce06SEric Joyner #define IXL_FLAGS_USES_MSIX (1 << 2) 207*b4a7ce06SEric Joyner #define IXL_FLAGS_IS_VF (1 << 3) 208*b4a7ce06SEric Joyner 209*b4a7ce06SEric Joyner #define IXL_VSI_IS_PF(v) ((v->flags & IXL_FLAGS_IS_VF) == 0) 210*b4a7ce06SEric Joyner #define IXL_VSI_IS_VF(v) ((v->flags & IXL_FLAGS_IS_VF) != 0) 211*b4a7ce06SEric Joyner 21256c2c47bSJack F Vogel #define IXL_VF_RESET_TIMEOUT 100 21356c2c47bSJack F Vogel 21456c2c47bSJack F Vogel #define IXL_VSI_DATA_PORT 0x01 21556c2c47bSJack F Vogel 2163f74c027SEric Joyner #define IAVF_MAX_QUEUES 16 21756c2c47bSJack F Vogel #define IXL_MAX_VSI_QUEUES (2 * (I40E_VSILAN_QTABLE_MAX_INDEX + 1)) 21856c2c47bSJack F Vogel 21956c2c47bSJack F Vogel #define IXL_RX_CTX_BASE_UNITS 128 22056c2c47bSJack F Vogel #define IXL_TX_CTX_BASE_UNITS 128 22156c2c47bSJack F Vogel 22256c2c47bSJack F Vogel #define IXL_PF_PCI_CIAA_VF_DEVICE_STATUS 0xAA 22356c2c47bSJack F Vogel 22456c2c47bSJack F Vogel #define IXL_PF_PCI_CIAD_VF_TRANS_PENDING_MASK 0x20 22556c2c47bSJack F Vogel 22656c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_INDEX(glb_vf) ((glb_vf) / 32) 22756c2c47bSJack F Vogel #define IXL_GLGEN_VFLRSTAT_MASK(glb_vf) (1 << ((glb_vf) % 32)) 22856c2c47bSJack F Vogel 22956c2c47bSJack F Vogel #define IXL_MAX_ITR_IDX 3 23056c2c47bSJack F Vogel 23156c2c47bSJack F Vogel #define IXL_END_OF_INTR_LNKLST 0x7FF 23256c2c47bSJack F Vogel 233cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_BASE (\ 2344294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \ 2354294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \ 2364294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \ 2374294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \ 2384294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV4) | \ 2394294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \ 2404294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \ 2414294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \ 2424294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \ 2434294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_FRAG_IPV6) | \ 2444294f337SSean Bruno BIT_ULL(I40E_FILTER_PCTYPE_L2_PAYLOAD)) 2454294f337SSean Bruno 246cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_XL710 IXL_DEFAULT_RSS_HENA_BASE 247cb6b8299SEric Joyner 248cb6b8299SEric Joyner #define IXL_DEFAULT_RSS_HENA_X722 (\ 249cb6b8299SEric Joyner IXL_DEFAULT_RSS_HENA_BASE | \ 250cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \ 251cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \ 252cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \ 253cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | \ 254cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \ 255cb6b8299SEric Joyner BIT_ULL(I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK)) 256cb6b8299SEric Joyner 2571031d839SEric Joyner #define IXL_CAPS \ 2581031d839SEric Joyner (IFCAP_TSO4 | IFCAP_TSO6 | \ 2591031d839SEric Joyner IFCAP_TXCSUM | IFCAP_TXCSUM_IPV6 | \ 2601031d839SEric Joyner IFCAP_RXCSUM | IFCAP_RXCSUM_IPV6 | \ 2611031d839SEric Joyner IFCAP_VLAN_HWFILTER | IFCAP_VLAN_HWTSO | \ 2626daf59aaSMarius Strobl IFCAP_VLAN_HWTAGGING | IFCAP_VLAN_HWCSUM | \ 2631031d839SEric Joyner IFCAP_VLAN_MTU | IFCAP_JUMBO_MTU | IFCAP_LRO) 26461ae650dSJack F Vogel 2651031d839SEric Joyner #define IXL_CSUM_TCP \ 2661031d839SEric Joyner (CSUM_IP_TCP|CSUM_IP_TSO|CSUM_IP6_TSO|CSUM_IP6_TCP) 2671031d839SEric Joyner #define IXL_CSUM_UDP \ 2681031d839SEric Joyner (CSUM_IP_UDP|CSUM_IP6_UDP) 2691031d839SEric Joyner #define IXL_CSUM_SCTP \ 2701031d839SEric Joyner (CSUM_IP_SCTP|CSUM_IP6_SCTP) 27137761e2eSEric Joyner #define IXL_CSUM_IPV4 \ 27237761e2eSEric Joyner (CSUM_IP|CSUM_IP_TSO) 27361ae650dSJack F Vogel 274a48d00d2SEric Joyner /* Pre-11 counter(9) compatibility */ 275b6c8f260SJack F Vogel #if __FreeBSD_version >= 1100036 2764b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ipackets = (count) 2774b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ierrors = (count) 2784b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->opackets = (count) 2794b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->oerrors = (count) 2804b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) /* Do nothing; collisions is always 0. */ 2814b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ibytes = (count) 2824b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->obytes = (count) 2834b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->imcasts = (count) 2844b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->omcasts = (count) 2854b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->iqdrops = (count) 286625d12c6SJohn Baldwin #define IXL_SET_OQDROPS(vsi, count) (vsi)->oqdrops = (count) 2874b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 2884b443922SGleb Smirnoff #else 2894b443922SGleb Smirnoff #define IXL_SET_IPACKETS(vsi, count) (vsi)->ifp->if_ipackets = (count) 2904b443922SGleb Smirnoff #define IXL_SET_IERRORS(vsi, count) (vsi)->ifp->if_ierrors = (count) 2914b443922SGleb Smirnoff #define IXL_SET_OPACKETS(vsi, count) (vsi)->ifp->if_opackets = (count) 2924b443922SGleb Smirnoff #define IXL_SET_OERRORS(vsi, count) (vsi)->ifp->if_oerrors = (count) 2934b443922SGleb Smirnoff #define IXL_SET_COLLISIONS(vsi, count) (vsi)->ifp->if_collisions = (count) 2944b443922SGleb Smirnoff #define IXL_SET_IBYTES(vsi, count) (vsi)->ifp->if_ibytes = (count) 2954b443922SGleb Smirnoff #define IXL_SET_OBYTES(vsi, count) (vsi)->ifp->if_obytes = (count) 2964b443922SGleb Smirnoff #define IXL_SET_IMCASTS(vsi, count) (vsi)->ifp->if_imcasts = (count) 2974b443922SGleb Smirnoff #define IXL_SET_OMCASTS(vsi, count) (vsi)->ifp->if_omcasts = (count) 2984b443922SGleb Smirnoff #define IXL_SET_IQDROPS(vsi, count) (vsi)->ifp->if_iqdrops = (count) 2994b443922SGleb Smirnoff #define IXL_SET_OQDROPS(vsi, odrops) (vsi)->ifp->if_snd.ifq_drops = (odrops) 3004b443922SGleb Smirnoff #define IXL_SET_NOPROTO(vsi, count) (vsi)->noproto = (count) 3014b443922SGleb Smirnoff #endif 3024b443922SGleb Smirnoff 30377c1fcecSEric Joyner /* For stats sysctl naming */ 304*b4a7ce06SEric Joyner #define IXL_QUEUE_NAME_LEN 32 30577c1fcecSEric Joyner 3061031d839SEric Joyner #define IXL_DEV_ERR(_dev, _format, ...) \ 3071031d839SEric Joyner device_printf(_dev, "%s: " _format " (%s:%d)\n", __func__, ##__VA_ARGS__, __FILE__, __LINE__) 3081031d839SEric Joyner 30961ae650dSJack F Vogel /* 31061ae650dSJack F Vogel ***************************************************************************** 31161ae650dSJack F Vogel * vendor_info_array 31261ae650dSJack F Vogel * 31361ae650dSJack F Vogel * This array contains the list of Subvendor/Subdevice IDs on which the driver 31461ae650dSJack F Vogel * should load. 31561ae650dSJack F Vogel * 31661ae650dSJack F Vogel ***************************************************************************** 31761ae650dSJack F Vogel */ 31861ae650dSJack F Vogel typedef struct _ixl_vendor_info_t { 31961ae650dSJack F Vogel unsigned int vendor_id; 32061ae650dSJack F Vogel unsigned int device_id; 32161ae650dSJack F Vogel unsigned int subvendor_id; 32261ae650dSJack F Vogel unsigned int subdevice_id; 32361ae650dSJack F Vogel unsigned int index; 32461ae650dSJack F Vogel } ixl_vendor_info_t; 32561ae650dSJack F Vogel 32661ae650dSJack F Vogel /* 32761ae650dSJack F Vogel ** This struct has multiple uses, multicast 32861ae650dSJack F Vogel ** addresses, vlans, and mac filters all use it. 32961ae650dSJack F Vogel */ 33061ae650dSJack F Vogel struct ixl_mac_filter { 33161ae650dSJack F Vogel SLIST_ENTRY(ixl_mac_filter) next; 33261ae650dSJack F Vogel u8 macaddr[ETHER_ADDR_LEN]; 33361ae650dSJack F Vogel s16 vlan; 33461ae650dSJack F Vogel u16 flags; 33561ae650dSJack F Vogel }; 33661ae650dSJack F Vogel 33761ae650dSJack F Vogel /* 33861ae650dSJack F Vogel * The Transmit ring control struct 33961ae650dSJack F Vogel */ 34061ae650dSJack F Vogel struct tx_ring { 3411031d839SEric Joyner struct ixl_tx_queue *que; 34261ae650dSJack F Vogel u32 tail; 3431031d839SEric Joyner struct i40e_tx_desc *tx_base; 3441031d839SEric Joyner u64 tx_paddr; 3456d011ad5SEric Joyner u32 latency; 3461031d839SEric Joyner u32 packets; 3471031d839SEric Joyner u32 me; 3481031d839SEric Joyner /* 3491031d839SEric Joyner * For reporting completed packet status 3501031d839SEric Joyner * in descriptor writeback mode 3511031d839SEric Joyner */ 3521031d839SEric Joyner qidx_t *tx_rsq; 3531031d839SEric Joyner qidx_t tx_rs_cidx; 3541031d839SEric Joyner qidx_t tx_rs_pidx; 3551031d839SEric Joyner qidx_t tx_cidx_processed; 35661ae650dSJack F Vogel 35761ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 3581031d839SEric Joyner u32 itr; 35961ae650dSJack F Vogel u32 bytes; 36061ae650dSJack F Vogel 36161ae650dSJack F Vogel /* Soft Stats */ 36261ae650dSJack F Vogel u64 tx_bytes; 3631031d839SEric Joyner u64 tx_packets; 3641031d839SEric Joyner u64 mss_too_small; 36561ae650dSJack F Vogel }; 36661ae650dSJack F Vogel 36761ae650dSJack F Vogel 36861ae650dSJack F Vogel /* 36961ae650dSJack F Vogel * The Receive ring control struct 37061ae650dSJack F Vogel */ 37161ae650dSJack F Vogel struct rx_ring { 3721031d839SEric Joyner struct ixl_rx_queue *que; 3731031d839SEric Joyner union i40e_rx_desc *rx_base; 3741031d839SEric Joyner uint64_t rx_paddr; 37561ae650dSJack F Vogel bool discard; 3766d011ad5SEric Joyner u32 itr; 3776d011ad5SEric Joyner u32 latency; 37861ae650dSJack F Vogel u32 mbuf_sz; 37961ae650dSJack F Vogel u32 tail; 3801031d839SEric Joyner u32 me; 38161ae650dSJack F Vogel 38261ae650dSJack F Vogel /* Used for Dynamic ITR calculation */ 38361ae650dSJack F Vogel u32 packets; 38461ae650dSJack F Vogel u32 bytes; 38561ae650dSJack F Vogel 38661ae650dSJack F Vogel /* Soft stats */ 38761ae650dSJack F Vogel u64 rx_packets; 38861ae650dSJack F Vogel u64 rx_bytes; 3896d011ad5SEric Joyner u64 desc_errs; 39061ae650dSJack F Vogel }; 39161ae650dSJack F Vogel 39261ae650dSJack F Vogel /* 3931031d839SEric Joyner ** Driver queue structs 39461ae650dSJack F Vogel */ 3951031d839SEric Joyner struct ixl_tx_queue { 39661ae650dSJack F Vogel struct ixl_vsi *vsi; 39761ae650dSJack F Vogel struct tx_ring txr; 3981031d839SEric Joyner struct if_irq que_irq; 3991031d839SEric Joyner u32 msix; 4001031d839SEric Joyner /* Stats */ 40161ae650dSJack F Vogel u64 irqs; 40261ae650dSJack F Vogel u64 tso; 4031031d839SEric Joyner }; 4041031d839SEric Joyner 4051031d839SEric Joyner struct ixl_rx_queue { 4061031d839SEric Joyner struct ixl_vsi *vsi; 4071031d839SEric Joyner struct rx_ring rxr; 4081031d839SEric Joyner struct if_irq que_irq; 4091031d839SEric Joyner u32 msix; /* This queue's MSIX vector */ 4101031d839SEric Joyner /* Stats */ 4111031d839SEric Joyner u64 irqs; 41261ae650dSJack F Vogel }; 41361ae650dSJack F Vogel 41461ae650dSJack F Vogel /* 4154294f337SSean Bruno ** Virtual Station Interface 41661ae650dSJack F Vogel */ 41761ae650dSJack F Vogel SLIST_HEAD(ixl_ftl_head, ixl_mac_filter); 41861ae650dSJack F Vogel struct ixl_vsi { 4191031d839SEric Joyner if_ctx_t ctx; 4201031d839SEric Joyner if_softc_ctx_t shared; 42161ae650dSJack F Vogel struct ifnet *ifp; 42277c1fcecSEric Joyner device_t dev; 42361ae650dSJack F Vogel struct i40e_hw *hw; 4241031d839SEric Joyner struct ifmedia *media; 42577c1fcecSEric Joyner 42677c1fcecSEric Joyner int num_rx_queues; 42777c1fcecSEric Joyner int num_tx_queues; 4281031d839SEric Joyner 4291031d839SEric Joyner void *back; 430ac83ea83SEric Joyner enum i40e_vsi_type type; 43161ae650dSJack F Vogel int id; 4326d011ad5SEric Joyner u32 rx_itr_setting; 4336d011ad5SEric Joyner u32 tx_itr_setting; 434ceebc2f3SEric Joyner bool enable_head_writeback; 4354294f337SSean Bruno 4364294f337SSean Bruno u16 vsi_num; 43761ae650dSJack F Vogel bool link_active; 43861ae650dSJack F Vogel u16 seid; 43956c2c47bSJack F Vogel u16 uplink_seid; 44056c2c47bSJack F Vogel u16 downlink_seid; 44161ae650dSJack F Vogel 4421031d839SEric Joyner struct ixl_tx_queue *tx_queues; /* TX queue array */ 4431031d839SEric Joyner struct ixl_rx_queue *rx_queues; /* RX queue array */ 4441031d839SEric Joyner struct if_irq irq; 4451031d839SEric Joyner u32 link_speed; 4461031d839SEric Joyner 44761ae650dSJack F Vogel /* MAC/VLAN Filter list */ 44861ae650dSJack F Vogel struct ixl_ftl_head ftl; 44956c2c47bSJack F Vogel u16 num_macs; 450*b4a7ce06SEric Joyner u64 num_hw_filters; 45161ae650dSJack F Vogel 4524294f337SSean Bruno /* Contains readylist & stat counter id */ 45361ae650dSJack F Vogel struct i40e_aqc_vsi_properties_data info; 45461ae650dSJack F Vogel 45561ae650dSJack F Vogel u16 num_vlans; 45661ae650dSJack F Vogel 45761ae650dSJack F Vogel /* Per-VSI stats from hardware */ 45861ae650dSJack F Vogel struct i40e_eth_stats eth_stats; 45961ae650dSJack F Vogel struct i40e_eth_stats eth_stats_offsets; 46061ae650dSJack F Vogel bool stat_offsets_loaded; 461e5100ee2SJack F Vogel /* VSI stat counters */ 4624b443922SGleb Smirnoff u64 ipackets; 4634b443922SGleb Smirnoff u64 ierrors; 4644b443922SGleb Smirnoff u64 opackets; 4654b443922SGleb Smirnoff u64 oerrors; 4664b443922SGleb Smirnoff u64 ibytes; 4674b443922SGleb Smirnoff u64 obytes; 4684b443922SGleb Smirnoff u64 imcasts; 4694b443922SGleb Smirnoff u64 omcasts; 4704b443922SGleb Smirnoff u64 iqdrops; 4714b443922SGleb Smirnoff u64 oqdrops; 4724b443922SGleb Smirnoff u64 noproto; 47361ae650dSJack F Vogel 47461ae650dSJack F Vogel /* Misc. */ 47561ae650dSJack F Vogel u64 flags; 4761031d839SEric Joyner /* Stats sysctls for this VSI */ 47756c2c47bSJack F Vogel struct sysctl_oid *vsi_node; 478*b4a7ce06SEric Joyner struct sysctl_ctx_list sysctl_ctx; 47961ae650dSJack F Vogel }; 48061ae650dSJack F Vogel 48161ae650dSJack F Vogel /* 4821031d839SEric Joyner ** Creates new filter with given MAC address and VLAN ID 48361ae650dSJack F Vogel */ 48461ae650dSJack F Vogel static inline struct ixl_mac_filter * 4851031d839SEric Joyner ixl_new_filter(struct ixl_vsi *vsi, const u8 *macaddr, s16 vlan) 48661ae650dSJack F Vogel { 48761ae650dSJack F Vogel struct ixl_mac_filter *f; 48861ae650dSJack F Vogel 48961ae650dSJack F Vogel /* create a new empty filter */ 49061ae650dSJack F Vogel f = malloc(sizeof(struct ixl_mac_filter), 49161ae650dSJack F Vogel M_DEVBUF, M_NOWAIT | M_ZERO); 4921031d839SEric Joyner if (f) { 49361ae650dSJack F Vogel SLIST_INSERT_HEAD(&vsi->ftl, f, next); 4941031d839SEric Joyner bcopy(macaddr, f->macaddr, ETHER_ADDR_LEN); 4951031d839SEric Joyner f->vlan = vlan; 4961031d839SEric Joyner f->flags |= (IXL_FILTER_ADD | IXL_FILTER_USED); 4971031d839SEric Joyner } 49861ae650dSJack F Vogel 49961ae650dSJack F Vogel return (f); 50061ae650dSJack F Vogel } 50161ae650dSJack F Vogel 50261ae650dSJack F Vogel /* 50361ae650dSJack F Vogel ** Compare two ethernet addresses 50461ae650dSJack F Vogel */ 50561ae650dSJack F Vogel static inline bool 50656c2c47bSJack F Vogel cmp_etheraddr(const u8 *ea1, const u8 *ea2) 50761ae650dSJack F Vogel { 508*b4a7ce06SEric Joyner return (bcmp(ea1, ea2, ETHER_ADDR_LEN) == 0); 50961ae650dSJack F Vogel } 51061ae650dSJack F Vogel 51161ae650dSJack F Vogel /* 5124294f337SSean Bruno * Return next largest power of 2, unsigned 5134294f337SSean Bruno * 5144294f337SSean Bruno * Public domain, from Bit Twiddling Hacks 5154294f337SSean Bruno */ 5164294f337SSean Bruno static inline u32 5174294f337SSean Bruno next_power_of_two(u32 n) 5184294f337SSean Bruno { 5194294f337SSean Bruno n--; 5204294f337SSean Bruno n |= n >> 1; 5214294f337SSean Bruno n |= n >> 2; 5224294f337SSean Bruno n |= n >> 4; 5234294f337SSean Bruno n |= n >> 8; 5244294f337SSean Bruno n |= n >> 16; 5254294f337SSean Bruno n++; 5264294f337SSean Bruno 5274294f337SSean Bruno /* Next power of two > 0 is 1 */ 5284294f337SSean Bruno n += (n == 0); 5294294f337SSean Bruno 5304294f337SSean Bruno return (n); 5314294f337SSean Bruno } 5324294f337SSean Bruno 5334294f337SSean Bruno /* 53461ae650dSJack F Vogel * Info for stats sysctls 53561ae650dSJack F Vogel */ 53661ae650dSJack F Vogel struct ixl_sysctl_info { 53761ae650dSJack F Vogel u64 *stat; 53861ae650dSJack F Vogel char *name; 53961ae650dSJack F Vogel char *description; 54061ae650dSJack F Vogel }; 54161ae650dSJack F Vogel 54233c66d8aSRyan Libby extern const uint8_t ixl_bcast_addr[ETHER_ADDR_LEN]; 54361ae650dSJack F Vogel 5444294f337SSean Bruno /* Common function prototypes between PF/VF driver */ 54577c1fcecSEric Joyner void ixl_debug_core(device_t dev, u32 enabled_mask, u32 mask, char *fmt, ...); 5461031d839SEric Joyner void ixl_init_tx_ring(struct ixl_vsi *vsi, struct ixl_tx_queue *que); 5474294f337SSean Bruno void ixl_get_default_rss_key(u32 *); 548ceebc2f3SEric Joyner const char * i40e_vc_stat_str(struct i40e_hw *hw, 549ceebc2f3SEric Joyner enum virtchnl_status_code stat_err); 55077c1fcecSEric Joyner void ixl_init_tx_rsqs(struct ixl_vsi *vsi); 55177c1fcecSEric Joyner void ixl_init_tx_cidx(struct ixl_vsi *vsi); 55277c1fcecSEric Joyner u64 ixl_max_vc_speed_to_value(u8 link_speeds); 55377c1fcecSEric Joyner void ixl_add_vsi_sysctls(device_t dev, struct ixl_vsi *vsi, 55477c1fcecSEric Joyner struct sysctl_ctx_list *ctx, const char *sysctl_name); 55577c1fcecSEric Joyner void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *ctx, 55677c1fcecSEric Joyner struct sysctl_oid_list *child, 55777c1fcecSEric Joyner struct i40e_eth_stats *eth_stats); 558*b4a7ce06SEric Joyner void ixl_vsi_add_queues_stats(struct ixl_vsi *vsi, 559*b4a7ce06SEric Joyner struct sysctl_ctx_list *ctx); 56061ae650dSJack F Vogel #endif /* _IXL_H_ */ 561