#ifndef _IF_VTNETVAR_H
#define _IF_VTNETVAR_H
struct vtnet_statistics {
uint64_t mbuf_alloc_failed;
uint64_t rx_frame_too_large;
uint64_t rx_enq_replacement_failed;
uint64_t rx_mergeable_failed;
uint64_t rx_csum_bad_ethtype;
uint64_t rx_csum_bad_ipproto;
uint64_t rx_csum_bad_offset;
uint64_t rx_csum_failed;
uint64_t rx_csum_offloaded;
uint64_t rx_task_rescheduled;
uint64_t tx_csum_offloaded;
uint64_t tx_tso_offloaded;
uint64_t tx_csum_bad_ethtype;
uint64_t tx_tso_bad_ethtype;
uint64_t tx_defragged;
uint64_t tx_defrag_failed;
uint64_t tx_task_rescheduled;
};
struct irqmap {
int irq;
driver_intr_t *handler;
};
struct vtnet_softc {
device_t vtnet_dev;
struct ifnet *vtnet_ifp;
struct lwkt_serialize vtnet_slz;
struct lwkt_serialize vtnet_rx_slz;
struct lwkt_serialize vtnet_tx_slz;
struct lwkt_serialize *serializes[3];
uint32_t vtnet_flags;
#define VTNET_FLAG_LINK 0x0001
#define VTNET_FLAG_SUSPENDED 0x0002
#define VTNET_FLAG_MAC 0x0004
#define VTNET_FLAG_CTRL_VQ 0x0008
#define VTNET_FLAG_CTRL_RX 0x0010
#define VTNET_FLAG_CTRL_MAC 0x0020
#define VTNET_FLAG_VLAN_FILTER 0x0040
#define VTNET_FLAG_TSO_ECN 0x0080
#define VTNET_FLAG_MRG_RXBUFS 0x0100
#define VTNET_FLAG_LRO_NOMRG 0x0200
#define VTNET_FLAG_INDIRECT 0x0400
struct virtqueue *vtnet_rx_vq;
struct virtqueue *vtnet_tx_vq;
struct virtqueue *vtnet_ctrl_vq;
int vtnet_cpus[4];
int vtnet_nintr;
struct irqmap vtnet_irqmap[2];
struct lwkt_serialize *vtnet_intr_slz[3];
int vtnet_txhdrcount;
struct vtnet_tx_header *vtnet_txhdrarea;
SLIST_HEAD(, vtnet_tx_header)
vtnet_txhdr_free;
struct vtnet_mac_filter *vtnet_macfilter;
int vtnet_hdr_size;
int vtnet_tx_size;
int vtnet_tx_nsegs;
int vtnet_rx_process_limit;
int vtnet_rx_nsegs;
int vtnet_rx_mbuf_size;
int vtnet_rx_mbuf_count;
int vtnet_if_flags;
struct ifsubq_watchdog vtnet_tx_watchdog;
uint64_t vtnet_features;
struct vtnet_statistics vtnet_stats;
eventhandler_tag vtnet_vlan_attach;
eventhandler_tag vtnet_vlan_detach;
struct ifmedia vtnet_media;
#define VTNET_MEDIATYPE (IFM_ETHER | IFM_1000_T | IFM_FDX)
char vtnet_hwaddr[ETHER_ADDR_LEN];
#define VTNET_VLAN_SHADOW_SIZE (4096 / 32)
int vtnet_nvlans;
uint32_t vtnet_vlan_shadow[VTNET_VLAN_SHADOW_SIZE];
};
#define VTNET_RX_HEADER_PAD 2
struct vtnet_rx_header {
struct virtio_net_hdr vrh_hdr;
char vrh_pad[VTNET_RX_HEADER_PAD];
} __packed;
struct vtnet_tx_header {
union {
struct virtio_net_hdr hdr;
struct virtio_net_hdr_mrg_rxbuf mhdr;
} vth_uhdr;
struct mbuf *vth_mbuf;
SLIST_ENTRY(vtnet_tx_header) link;
};
#define VTNET_MAX_MAC_ENTRIES 128
struct vtnet_mac_table {
uint32_t nentries;
uint8_t macs[VTNET_MAX_MAC_ENTRIES][ETHER_ADDR_LEN];
} __packed;
struct vtnet_mac_filter {
struct vtnet_mac_table vmf_unicast;
uint32_t vmf_pad;
struct vtnet_mac_table vmf_multicast;
};
#define VTNET_WATCHDOG_TIMEOUT 5
#define VTNET_CSUM_OFFLOAD (CSUM_TCP | CSUM_UDP)
#define VTNET_FEATURES \
(VIRTIO_NET_F_MAC | \
VIRTIO_NET_F_STATUS | \
VIRTIO_NET_F_CTRL_VQ | \
VIRTIO_NET_F_CTRL_RX | \
VIRTIO_NET_F_CTRL_MAC_ADDR | \
VIRTIO_NET_F_CTRL_VLAN | \
VIRTIO_NET_F_CSUM | \
VIRTIO_NET_F_HOST_TSO4 | \
VIRTIO_NET_F_HOST_TSO6 | \
VIRTIO_NET_F_HOST_ECN | \
VIRTIO_NET_F_GUEST_CSUM | \
VIRTIO_NET_F_GUEST_TSO4 | \
VIRTIO_NET_F_GUEST_TSO6 | \
VIRTIO_NET_F_GUEST_ECN | \
VIRTIO_NET_F_MRG_RXBUF | \
VIRTIO_RING_F_INDIRECT_DESC)
#define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \
VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN)
#define VTNET_MAX_MTU 65536
#define VTNET_MAX_RX_SIZE 65550
#define VTNET_MRG_RX_SEGS 1
#define VTNET_MIN_RX_SEGS 2
#define VTNET_MAX_RX_SEGS 34
#define VTNET_MIN_TX_SEGS 4
#define VTNET_MAX_TX_SEGS 64
#if 0
#define IFCAP_LRO 0x00400
#define IFCAP_VLAN_HWFILTER 0x10000
#define IFCAP_VLAN_HWTSO 0x40000
#endif
#ifndef IFCAP_VLAN_HWFILTER
#define IFCAP_VLAN_HWFILTER 0
#endif
#ifndef IFCAP_VLAN_HWTSO
#define IFCAP_VLAN_HWTSO 0
#endif
CTASSERT(((VTNET_MAX_RX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_RX_SIZE);
CTASSERT(((VTNET_MAX_TX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_MTU);
#define VTNET_NEEDED_RX_MBUFS(_sc) \
((_sc)->vtnet_flags & VTNET_FLAG_LRO_NOMRG) == 0 ? 1 : \
howmany(sizeof(struct vtnet_rx_header) + VTNET_MAX_RX_SIZE, \
(_sc)->vtnet_rx_mbuf_size)
#endif