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 * $FreeBSD$ 19e3c97c2cSBryan Venteicher */ 20e3c97c2cSBryan Venteicher 21e3c97c2cSBryan Venteicher #ifndef _IF_VMXVAR_H 22e3c97c2cSBryan Venteicher #define _IF_VMXVAR_H 23e3c97c2cSBryan Venteicher 24e3c97c2cSBryan Venteicher struct vmxnet3_softc; 25e3c97c2cSBryan Venteicher 26e3c97c2cSBryan Venteicher /* 27e557c1ddSBryan Venteicher * The number of Rx/Tx queues this driver prefers. 28e3c97c2cSBryan Venteicher */ 29e557c1ddSBryan Venteicher #define VMXNET3_DEF_RX_QUEUES 8 30e557c1ddSBryan Venteicher #define VMXNET3_DEF_TX_QUEUES 8 31e3c97c2cSBryan Venteicher 32e3c97c2cSBryan Venteicher /* 33e3c97c2cSBryan Venteicher * The number of Rx rings in each Rx queue. 34e3c97c2cSBryan Venteicher */ 35e3c97c2cSBryan Venteicher #define VMXNET3_RXRINGS_PERQ 2 36e3c97c2cSBryan Venteicher 37e3c97c2cSBryan Venteicher /* 383c5dfe89SBryan Venteicher * The number of descriptors in each Rx/Tx ring. 39e3c97c2cSBryan Venteicher */ 403c5dfe89SBryan Venteicher #define VMXNET3_DEF_TX_NDESC 512 413c5dfe89SBryan Venteicher #define VMXNET3_MAX_TX_NDESC 4096 423c5dfe89SBryan Venteicher #define VMXNET3_MIN_TX_NDESC 32 433c5dfe89SBryan Venteicher #define VMXNET3_MASK_TX_NDESC 0x1F 44*1342c8c6SPatrick Kelsey #define VMXNET3_DEF_RX_NDESC 512 453c5dfe89SBryan Venteicher #define VMXNET3_MAX_RX_NDESC 2048 463c5dfe89SBryan Venteicher #define VMXNET3_MIN_RX_NDESC 32 473c5dfe89SBryan Venteicher #define VMXNET3_MASK_RX_NDESC 0x1F 483c5dfe89SBryan Venteicher 49e3c97c2cSBryan Venteicher #define VMXNET3_MAX_TX_NCOMPDESC VMXNET3_MAX_TX_NDESC 50e3c97c2cSBryan Venteicher #define VMXNET3_MAX_RX_NCOMPDESC \ 51e3c97c2cSBryan Venteicher (VMXNET3_MAX_RX_NDESC * VMXNET3_RXRINGS_PERQ) 52e3c97c2cSBryan Venteicher 53e3c97c2cSBryan Venteicher struct vmxnet3_txring { 54e3c97c2cSBryan Venteicher u_int vxtxr_next; 55e3c97c2cSBryan Venteicher u_int vxtxr_ndesc; 56e3c97c2cSBryan Venteicher int vxtxr_gen; 57e3c97c2cSBryan Venteicher struct vmxnet3_txdesc *vxtxr_txd; 588f82136aSPatrick Kelsey bus_addr_t vxtxr_paddr; 59e3c97c2cSBryan Venteicher }; 60e3c97c2cSBryan Venteicher 61e3c97c2cSBryan Venteicher struct vmxnet3_rxring { 62e3c97c2cSBryan Venteicher struct vmxnet3_rxdesc *vxrxr_rxd; 63e3c97c2cSBryan Venteicher u_int vxrxr_ndesc; 64e3c97c2cSBryan Venteicher int vxrxr_gen; 658f82136aSPatrick Kelsey bus_addr_t vxrxr_paddr; 66f50375eeSPatrick Kelsey uint64_t vxrxr_desc_skips; 67f50375eeSPatrick Kelsey uint16_t vxrxr_refill_start; 68e3c97c2cSBryan Venteicher }; 69e3c97c2cSBryan Venteicher 70e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring { 71e3c97c2cSBryan Venteicher union { 72e3c97c2cSBryan Venteicher struct vmxnet3_txcompdesc *txcd; 73e3c97c2cSBryan Venteicher struct vmxnet3_rxcompdesc *rxcd; 74e3c97c2cSBryan Venteicher } vxcr_u; 758f82136aSPatrick Kelsey /* 768f82136aSPatrick Kelsey * vxcr_next is used on the transmit side to track the next index to 778f82136aSPatrick Kelsey * begin cleaning at. It is not used on the receive side. 788f82136aSPatrick Kelsey */ 79e3c97c2cSBryan Venteicher u_int vxcr_next; 80e3c97c2cSBryan Venteicher u_int vxcr_ndesc; 81e3c97c2cSBryan Venteicher int vxcr_gen; 828f82136aSPatrick Kelsey bus_addr_t vxcr_paddr; 83f50375eeSPatrick Kelsey uint64_t vxcr_zero_length; 84f50375eeSPatrick Kelsey uint64_t vxcr_pkt_errors; 85e3c97c2cSBryan Venteicher }; 86e3c97c2cSBryan Venteicher 87e3c97c2cSBryan Venteicher struct vmxnet3_txqueue { 88e3c97c2cSBryan Venteicher struct vmxnet3_softc *vxtxq_sc; 89e3c97c2cSBryan Venteicher int vxtxq_id; 908f82136aSPatrick Kelsey int vxtxq_last_flush; 91e3c97c2cSBryan Venteicher int vxtxq_intr_idx; 92e3c97c2cSBryan Venteicher struct vmxnet3_txring vxtxq_cmd_ring; 93e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring vxtxq_comp_ring; 94e3c97c2cSBryan Venteicher struct vmxnet3_txq_shared *vxtxq_ts; 95e3c97c2cSBryan Venteicher struct sysctl_oid_list *vxtxq_sysctl; 96e3c97c2cSBryan Venteicher char vxtxq_name[16]; 97e557c1ddSBryan Venteicher } __aligned(CACHE_LINE_SIZE); 98e3c97c2cSBryan Venteicher 99e3c97c2cSBryan Venteicher struct vmxnet3_rxqueue { 100e3c97c2cSBryan Venteicher struct vmxnet3_softc *vxrxq_sc; 101e3c97c2cSBryan Venteicher int vxrxq_id; 102e3c97c2cSBryan Venteicher int vxrxq_intr_idx; 1038f82136aSPatrick Kelsey struct if_irq vxrxq_irq; 104e3c97c2cSBryan Venteicher struct vmxnet3_rxring vxrxq_cmd_ring[VMXNET3_RXRINGS_PERQ]; 105e3c97c2cSBryan Venteicher struct vmxnet3_comp_ring vxrxq_comp_ring; 106e3c97c2cSBryan Venteicher struct vmxnet3_rxq_shared *vxrxq_rs; 107e3c97c2cSBryan Venteicher struct sysctl_oid_list *vxrxq_sysctl; 108e3c97c2cSBryan Venteicher char vxrxq_name[16]; 109e557c1ddSBryan Venteicher } __aligned(CACHE_LINE_SIZE); 110e3c97c2cSBryan Venteicher 111e3c97c2cSBryan Venteicher struct vmxnet3_softc { 112e3c97c2cSBryan Venteicher device_t vmx_dev; 1138f82136aSPatrick Kelsey if_ctx_t vmx_ctx; 1148f82136aSPatrick Kelsey if_shared_ctx_t vmx_sctx; 1158f82136aSPatrick Kelsey if_softc_ctx_t vmx_scctx; 116e3c97c2cSBryan Venteicher struct ifnet *vmx_ifp; 117e3c97c2cSBryan Venteicher struct vmxnet3_driver_shared *vmx_ds; 118e3c97c2cSBryan Venteicher uint32_t vmx_flags; 119e557c1ddSBryan Venteicher #define VMXNET3_FLAG_RSS 0x0002 120281cab4dSAndriy Gapon #define VMXNET3_FLAG_SOFT_RSS 0x0004 /* Software RSS is enabled with 121281cab4dSAndriy Gapon compatible algorithm. */ 122e3c97c2cSBryan Venteicher 123e3c97c2cSBryan Venteicher struct vmxnet3_rxqueue *vmx_rxq; 124e3c97c2cSBryan Venteicher struct vmxnet3_txqueue *vmx_txq; 125e3c97c2cSBryan Venteicher 126e3c97c2cSBryan Venteicher struct resource *vmx_res0; 127e3c97c2cSBryan Venteicher bus_space_tag_t vmx_iot0; 128e3c97c2cSBryan Venteicher bus_space_handle_t vmx_ioh0; 129e3c97c2cSBryan Venteicher struct resource *vmx_res1; 130e3c97c2cSBryan Venteicher bus_space_tag_t vmx_iot1; 131e3c97c2cSBryan Venteicher bus_space_handle_t vmx_ioh1; 132e3c97c2cSBryan Venteicher 133e3c97c2cSBryan Venteicher int vmx_link_active; 134e3c97c2cSBryan Venteicher 135e3c97c2cSBryan Venteicher int vmx_intr_mask_mode; 136e3c97c2cSBryan Venteicher int vmx_event_intr_idx; 1378f82136aSPatrick Kelsey struct if_irq vmx_event_intr_irq; 138e3c97c2cSBryan Venteicher 139e3c97c2cSBryan Venteicher uint8_t *vmx_mcast; 140e557c1ddSBryan Venteicher struct vmxnet3_rss_shared *vmx_rss; 1418f82136aSPatrick Kelsey struct iflib_dma_info vmx_ds_dma; 1428f82136aSPatrick Kelsey struct iflib_dma_info vmx_qs_dma; 1438f82136aSPatrick Kelsey struct iflib_dma_info vmx_mcast_dma; 1448f82136aSPatrick Kelsey struct iflib_dma_info vmx_rss_dma; 1458f82136aSPatrick Kelsey struct ifmedia *vmx_media; 146c02d19b6SBryan Venteicher uint32_t vmx_vlan_filter[4096/32]; 147e3c97c2cSBryan Venteicher uint8_t vmx_lladdr[ETHER_ADDR_LEN]; 148e3c97c2cSBryan Venteicher }; 149e3c97c2cSBryan Venteicher 150e3c97c2cSBryan Venteicher /* 151e3c97c2cSBryan Venteicher * Our driver version we report to the hypervisor; we just keep 152e3c97c2cSBryan Venteicher * this value constant. 153e3c97c2cSBryan Venteicher */ 154e3c97c2cSBryan Venteicher #define VMXNET3_DRIVER_VERSION 0x00010000 155e3c97c2cSBryan Venteicher 156e3c97c2cSBryan Venteicher /* 157e3c97c2cSBryan Venteicher * Max descriptors per Tx packet. We must limit the size of the 158e3c97c2cSBryan Venteicher * any TSO packets based on the number of segments. 159e3c97c2cSBryan Venteicher */ 1608f82136aSPatrick Kelsey #define VMXNET3_TX_MAXSEGS 32 /* 64K @ 2K segment size */ 161e557c1ddSBryan Venteicher #define VMXNET3_TX_MAXSIZE (VMXNET3_TX_MAXSEGS * MCLBYTES) 1628f82136aSPatrick Kelsey #define VMXNET3_TSO_MAXSIZE (VMXNET3_TX_MAXSIZE - ETHER_VLAN_ENCAP_LEN) 163e3c97c2cSBryan Venteicher 164e3c97c2cSBryan Venteicher /* 1658f82136aSPatrick Kelsey * Maximum supported Tx segment size. The length field in the 166e3c97c2cSBryan Venteicher * Tx descriptor is 14 bits. 1678f82136aSPatrick Kelsey * 1688f82136aSPatrick Kelsey * XXX It's possible a descriptor length field of 0 means 2^14, but this 1698f82136aSPatrick Kelsey * isn't confirmed, so limit to 2^14 - 1 for now. 170e3c97c2cSBryan Venteicher */ 1718f82136aSPatrick Kelsey #define VMXNET3_TX_MAXSEGSIZE ((1 << 14) - 1) 172e3c97c2cSBryan Venteicher 173e3c97c2cSBryan Venteicher /* 1748f82136aSPatrick Kelsey * Maximum supported Rx segment size. The length field in the 1758f82136aSPatrick Kelsey * Rx descriptor is 14 bits. 1768f82136aSPatrick Kelsey * 1778f82136aSPatrick Kelsey * The reference drivers skip zero-length descriptors, which seems to be a 1788f82136aSPatrick Kelsey * strong indication that on the receive side, a descriptor length field of 1798f82136aSPatrick Kelsey * zero does not mean 2^14. 1803c965775SBryan Venteicher */ 1818f82136aSPatrick Kelsey #define VMXNET3_RX_MAXSEGSIZE ((1 << 14) - 1) 1823c965775SBryan Venteicher 1833c965775SBryan Venteicher /* 184e3c97c2cSBryan Venteicher * Predetermined size of the multicast MACs filter table. If the 185e3c97c2cSBryan Venteicher * number of multicast addresses exceeds this size, then the 186e3c97c2cSBryan Venteicher * ALL_MULTI mode is use instead. 187e3c97c2cSBryan Venteicher */ 188e3c97c2cSBryan Venteicher #define VMXNET3_MULTICAST_MAX 32 189e3c97c2cSBryan Venteicher 190e3c97c2cSBryan Venteicher /* 191e3c97c2cSBryan Venteicher * IP protocols that we can perform Tx checksum offloading of. 192e3c97c2cSBryan Venteicher */ 193e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP) 194e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_OFFLOAD_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6) 195e3c97c2cSBryan Venteicher 196e3c97c2cSBryan Venteicher #define VMXNET3_CSUM_ALL_OFFLOAD \ 197e3c97c2cSBryan Venteicher (VMXNET3_CSUM_OFFLOAD | VMXNET3_CSUM_OFFLOAD_IPV6 | CSUM_TSO) 198e3c97c2cSBryan Venteicher 199e3c97c2cSBryan Venteicher #endif /* _IF_VMXVAR_H */ 200