1e3c97c2cSBryan Venteicher /*- 2e3c97c2cSBryan Venteicher * Copyright (c) 2013 Tsubai Masanari 3e3c97c2cSBryan Venteicher * Copyright (c) 2013 Bryan Venteicher <bryanv@FreeBSD.org> 48f82136aSPatrick Kelsey * Copyright (c) 2018 Patrick Kelsey 5e3c97c2cSBryan Venteicher * 6e3c97c2cSBryan Venteicher * Permission to use, copy, modify, and distribute this software for any 7e3c97c2cSBryan Venteicher * purpose with or without fee is hereby granted, provided that the above 8e3c97c2cSBryan Venteicher * copyright notice and this permission notice appear in all copies. 9e3c97c2cSBryan Venteicher * 10e3c97c2cSBryan Venteicher * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11e3c97c2cSBryan Venteicher * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12e3c97c2cSBryan Venteicher * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13e3c97c2cSBryan Venteicher * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14e3c97c2cSBryan Venteicher * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15e3c97c2cSBryan Venteicher * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16e3c97c2cSBryan Venteicher * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17e3c97c2cSBryan Venteicher */ 18e3c97c2cSBryan Venteicher 19e3c97c2cSBryan Venteicher #ifndef _IF_VMXVAR_H 20e3c97c2cSBryan Venteicher #define _IF_VMXVAR_H 21e3c97c2cSBryan Venteicher 22e3c97c2cSBryan Venteicher struct vmxnet3_softc; 23e3c97c2cSBryan Venteicher 24e3c97c2cSBryan Venteicher /* 25e557c1ddSBryan Venteicher * The number of Rx/Tx queues this driver prefers. 26e3c97c2cSBryan Venteicher */ 27e557c1ddSBryan Venteicher #define VMXNET3_DEF_RX_QUEUES 8 28e557c1ddSBryan Venteicher #define VMXNET3_DEF_TX_QUEUES 8 29e3c97c2cSBryan Venteicher 30e3c97c2cSBryan Venteicher /* 31e3c97c2cSBryan Venteicher * The number of Rx rings in each Rx queue. 32e3c97c2cSBryan Venteicher */ 33e3c97c2cSBryan Venteicher #define VMXNET3_RXRINGS_PERQ 2 34e3c97c2cSBryan Venteicher 35e3c97c2cSBryan Venteicher /* 363c5dfe89SBryan Venteicher * The number of descriptors in each Rx/Tx ring. 37e3c97c2cSBryan Venteicher */ 383c5dfe89SBryan Venteicher #define VMXNET3_DEF_TX_NDESC 512 393c5dfe89SBryan Venteicher #define VMXNET3_MAX_TX_NDESC 4096 403c5dfe89SBryan Venteicher #define VMXNET3_MIN_TX_NDESC 32 413c5dfe89SBryan Venteicher #define VMXNET3_MASK_TX_NDESC 0x1F 421342c8c6SPatrick Kelsey #define VMXNET3_DEF_RX_NDESC 512 433c5dfe89SBryan Venteicher #define VMXNET3_MAX_RX_NDESC 2048 443c5dfe89SBryan Venteicher #define VMXNET3_MIN_RX_NDESC 32 453c5dfe89SBryan Venteicher #define VMXNET3_MASK_RX_NDESC 0x1F 463c5dfe89SBryan Venteicher 47e3c97c2cSBryan Venteicher #define VMXNET3_MAX_TX_NCOMPDESC VMXNET3_MAX_TX_NDESC 48e3c97c2cSBryan Venteicher #define VMXNET3_MAX_RX_NCOMPDESC \ 49e3c97c2cSBryan Venteicher (VMXNET3_MAX_RX_NDESC * VMXNET3_RXRINGS_PERQ) 50e3c97c2cSBryan Venteicher 51e3c97c2cSBryan Venteicher struct vmxnet3_txring { 52e3c97c2cSBryan Venteicher u_int vxtxr_next; 53e3c97c2cSBryan Venteicher u_int vxtxr_ndesc; 54e3c97c2cSBryan Venteicher int vxtxr_gen; 55e3c97c2cSBryan Venteicher struct vmxnet3_txdesc *vxtxr_txd; 568f82136aSPatrick Kelsey bus_addr_t vxtxr_paddr; 57e3c97c2cSBryan Venteicher }; 58e3c97c2cSBryan Venteicher 59e3c97c2cSBryan Venteicher struct vmxnet3_rxring { 60e3c97c2cSBryan Venteicher struct vmxnet3_rxdesc *vxrxr_rxd; 61e3c97c2cSBryan Venteicher u_int vxrxr_ndesc; 62e3c97c2cSBryan Venteicher int vxrxr_gen; 638f82136aSPatrick Kelsey bus_addr_t vxrxr_paddr; 64f50375eeSPatrick Kelsey uint64_t vxrxr_desc_skips; 65f50375eeSPatrick Kelsey uint16_t vxrxr_refill_start; 66e3c97c2cSBryan Venteicher }; 67e3c97c2cSBryan Venteicher 68e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring { 69e3c97c2cSBryan Venteicher union { 70e3c97c2cSBryan Venteicher struct vmxnet3_txcompdesc *txcd; 71e3c97c2cSBryan Venteicher struct vmxnet3_rxcompdesc *rxcd; 72e3c97c2cSBryan Venteicher } vxcr_u; 738f82136aSPatrick Kelsey /* 748f82136aSPatrick Kelsey * vxcr_next is used on the transmit side to track the next index to 758f82136aSPatrick Kelsey * begin cleaning at. It is not used on the receive side. 768f82136aSPatrick Kelsey */ 77e3c97c2cSBryan Venteicher u_int vxcr_next; 78e3c97c2cSBryan Venteicher u_int vxcr_ndesc; 79e3c97c2cSBryan Venteicher int vxcr_gen; 808f82136aSPatrick Kelsey bus_addr_t vxcr_paddr; 81f50375eeSPatrick Kelsey uint64_t vxcr_zero_length; 829c612a5dSAndriy Gapon uint64_t vcxr_zero_length_frag; 83f50375eeSPatrick Kelsey uint64_t vxcr_pkt_errors; 84e3c97c2cSBryan Venteicher }; 85e3c97c2cSBryan Venteicher 86e3c97c2cSBryan Venteicher struct vmxnet3_txqueue { 87e3c97c2cSBryan Venteicher struct vmxnet3_softc *vxtxq_sc; 88e3c97c2cSBryan Venteicher int vxtxq_id; 898f82136aSPatrick Kelsey int vxtxq_last_flush; 90e3c97c2cSBryan Venteicher int vxtxq_intr_idx; 91e3c97c2cSBryan Venteicher struct vmxnet3_txring vxtxq_cmd_ring; 92e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring vxtxq_comp_ring; 93e3c97c2cSBryan Venteicher struct vmxnet3_txq_shared *vxtxq_ts; 94e3c97c2cSBryan Venteicher struct sysctl_oid_list *vxtxq_sysctl; 95e3c97c2cSBryan Venteicher char vxtxq_name[16]; 96e557c1ddSBryan Venteicher } __aligned(CACHE_LINE_SIZE); 97e3c97c2cSBryan Venteicher 98e3c97c2cSBryan Venteicher struct vmxnet3_rxqueue { 99e3c97c2cSBryan Venteicher struct vmxnet3_softc *vxrxq_sc; 100e3c97c2cSBryan Venteicher int vxrxq_id; 101e3c97c2cSBryan Venteicher int vxrxq_intr_idx; 1028f82136aSPatrick Kelsey struct if_irq vxrxq_irq; 103e3c97c2cSBryan Venteicher struct vmxnet3_rxring vxrxq_cmd_ring[VMXNET3_RXRINGS_PERQ]; 104e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring vxrxq_comp_ring; 105e3c97c2cSBryan Venteicher struct vmxnet3_rxq_shared *vxrxq_rs; 106e3c97c2cSBryan Venteicher struct sysctl_oid_list *vxrxq_sysctl; 107e3c97c2cSBryan Venteicher char vxrxq_name[16]; 108e557c1ddSBryan Venteicher } __aligned(CACHE_LINE_SIZE); 109e3c97c2cSBryan Venteicher 110e3c97c2cSBryan Venteicher struct vmxnet3_softc { 111e3c97c2cSBryan Venteicher device_t vmx_dev; 1128f82136aSPatrick Kelsey if_ctx_t vmx_ctx; 1138f82136aSPatrick Kelsey if_shared_ctx_t vmx_sctx; 1148f82136aSPatrick Kelsey if_softc_ctx_t vmx_scctx; 115*402810d3SJustin Hibbits if_t vmx_ifp; 116e3c97c2cSBryan Venteicher struct vmxnet3_driver_shared *vmx_ds; 117e3c97c2cSBryan Venteicher uint32_t vmx_flags; 118e557c1ddSBryan Venteicher #define VMXNET3_FLAG_RSS 0x0002 119281cab4dSAndriy Gapon #define VMXNET3_FLAG_SOFT_RSS 0x0004 /* Software RSS is enabled with 120281cab4dSAndriy Gapon compatible algorithm. */ 121e3c97c2cSBryan Venteicher 122e3c97c2cSBryan Venteicher struct vmxnet3_rxqueue *vmx_rxq; 123e3c97c2cSBryan Venteicher struct vmxnet3_txqueue *vmx_txq; 124e3c97c2cSBryan Venteicher 125e3c97c2cSBryan Venteicher struct resource *vmx_res0; 126e3c97c2cSBryan Venteicher bus_space_tag_t vmx_iot0; 127e3c97c2cSBryan Venteicher bus_space_handle_t vmx_ioh0; 128e3c97c2cSBryan Venteicher struct resource *vmx_res1; 129e3c97c2cSBryan Venteicher bus_space_tag_t vmx_iot1; 130e3c97c2cSBryan Venteicher bus_space_handle_t vmx_ioh1; 131e3c97c2cSBryan Venteicher 132e3c97c2cSBryan Venteicher int vmx_link_active; 133e3c97c2cSBryan Venteicher 134e3c97c2cSBryan Venteicher int vmx_intr_mask_mode; 135e3c97c2cSBryan Venteicher int vmx_event_intr_idx; 1368f82136aSPatrick Kelsey struct if_irq vmx_event_intr_irq; 137e3c97c2cSBryan Venteicher 138e3c97c2cSBryan Venteicher uint8_t *vmx_mcast; 139e557c1ddSBryan Venteicher struct vmxnet3_rss_shared *vmx_rss; 1408f82136aSPatrick Kelsey struct iflib_dma_info vmx_ds_dma; 1418f82136aSPatrick Kelsey struct iflib_dma_info vmx_qs_dma; 1428f82136aSPatrick Kelsey struct iflib_dma_info vmx_mcast_dma; 1438f82136aSPatrick Kelsey struct iflib_dma_info vmx_rss_dma; 1448f82136aSPatrick Kelsey struct ifmedia *vmx_media; 145c02d19b6SBryan Venteicher uint32_t vmx_vlan_filter[4096/32]; 146e3c97c2cSBryan Venteicher uint8_t vmx_lladdr[ETHER_ADDR_LEN]; 147e3c97c2cSBryan Venteicher }; 148e3c97c2cSBryan Venteicher 149e3c97c2cSBryan Venteicher /* 150e3c97c2cSBryan Venteicher * Our driver version we report to the hypervisor; we just keep 151e3c97c2cSBryan Venteicher * this value constant. 152e3c97c2cSBryan Venteicher */ 153e3c97c2cSBryan Venteicher #define VMXNET3_DRIVER_VERSION 0x00010000 154e3c97c2cSBryan Venteicher 155e3c97c2cSBryan Venteicher /* 156e3c97c2cSBryan Venteicher * Max descriptors per Tx packet. We must limit the size of the 157e3c97c2cSBryan Venteicher * any TSO packets based on the number of segments. 158e3c97c2cSBryan Venteicher */ 1598f82136aSPatrick Kelsey #define VMXNET3_TX_MAXSEGS 32 /* 64K @ 2K segment size */ 160e557c1ddSBryan Venteicher #define VMXNET3_TX_MAXSIZE (VMXNET3_TX_MAXSEGS * MCLBYTES) 1618f82136aSPatrick Kelsey #define VMXNET3_TSO_MAXSIZE (VMXNET3_TX_MAXSIZE - ETHER_VLAN_ENCAP_LEN) 162e3c97c2cSBryan Venteicher 163e3c97c2cSBryan Venteicher /* 1648f82136aSPatrick Kelsey * Maximum supported Tx segment size. The length field in the 165e3c97c2cSBryan Venteicher * Tx descriptor is 14 bits. 1668f82136aSPatrick Kelsey * 1678f82136aSPatrick Kelsey * XXX It's possible a descriptor length field of 0 means 2^14, but this 1688f82136aSPatrick Kelsey * isn't confirmed, so limit to 2^14 - 1 for now. 169e3c97c2cSBryan Venteicher */ 1708f82136aSPatrick Kelsey #define VMXNET3_TX_MAXSEGSIZE ((1 << 14) - 1) 171e3c97c2cSBryan Venteicher 172e3c97c2cSBryan Venteicher /* 1738f82136aSPatrick Kelsey * Maximum supported Rx segment size. The length field in the 1748f82136aSPatrick Kelsey * Rx descriptor is 14 bits. 1758f82136aSPatrick Kelsey * 1768f82136aSPatrick Kelsey * The reference drivers skip zero-length descriptors, which seems to be a 1778f82136aSPatrick Kelsey * strong indication that on the receive side, a descriptor length field of 1788f82136aSPatrick Kelsey * zero does not mean 2^14. 1793c965775SBryan Venteicher */ 1808f82136aSPatrick Kelsey #define VMXNET3_RX_MAXSEGSIZE ((1 << 14) - 1) 1813c965775SBryan Venteicher 1823c965775SBryan Venteicher /* 183e3c97c2cSBryan Venteicher * Predetermined size of the multicast MACs filter table. If the 184e3c97c2cSBryan Venteicher * number of multicast addresses exceeds this size, then the 185e3c97c2cSBryan Venteicher * ALL_MULTI mode is use instead. 186e3c97c2cSBryan Venteicher */ 187e3c97c2cSBryan Venteicher #define VMXNET3_MULTICAST_MAX 32 188e3c97c2cSBryan Venteicher 189e3c97c2cSBryan Venteicher /* 190e3c97c2cSBryan Venteicher * IP protocols that we can perform Tx checksum offloading of. 191e3c97c2cSBryan Venteicher */ 192e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP) 193e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6) 194e3c97c2cSBryan Venteicher 195e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_ALL_OFFLOAD \ 196e3c97c2cSBryan Venteicher (VMXNET3_CSUM_OFFLOAD | VMXNET3_CSUM_OFFLOAD_IPV6 | CSUM_TSO) 197e3c97c2cSBryan Venteicher 198e3c97c2cSBryan Venteicher #endif /* _IF_VMXVAR_H */ 199