xref: /freebsd/sys/dev/virtio/network/if_vtnetvar.h (revision 443c3d0bd1abfd59becf5c0839e532c99755fdec)
110b59a9bSPeter Grehan /*-
2abd6790cSBryan Venteicher  * Copyright (c) 2011, Bryan Venteicher <bryanv@FreeBSD.org>
310b59a9bSPeter Grehan  * All rights reserved.
410b59a9bSPeter Grehan  *
510b59a9bSPeter Grehan  * Redistribution and use in source and binary forms, with or without
610b59a9bSPeter Grehan  * modification, are permitted provided that the following conditions
710b59a9bSPeter Grehan  * are met:
810b59a9bSPeter Grehan  * 1. Redistributions of source code must retain the above copyright
910b59a9bSPeter Grehan  *    notice unmodified, this list of conditions, and the following
1010b59a9bSPeter Grehan  *    disclaimer.
1110b59a9bSPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
1210b59a9bSPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
1310b59a9bSPeter Grehan  *    documentation and/or other materials provided with the distribution.
1410b59a9bSPeter Grehan  *
1510b59a9bSPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1610b59a9bSPeter Grehan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1710b59a9bSPeter Grehan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1810b59a9bSPeter Grehan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1910b59a9bSPeter Grehan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2010b59a9bSPeter Grehan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2110b59a9bSPeter Grehan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2210b59a9bSPeter Grehan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2310b59a9bSPeter Grehan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2410b59a9bSPeter Grehan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2510b59a9bSPeter Grehan  *
2610b59a9bSPeter Grehan  * $FreeBSD$
2710b59a9bSPeter Grehan  */
2810b59a9bSPeter Grehan 
2910b59a9bSPeter Grehan #ifndef _IF_VTNETVAR_H
3010b59a9bSPeter Grehan #define _IF_VTNETVAR_H
3110b59a9bSPeter Grehan 
328f3600b1SBryan Venteicher struct vtnet_softc;
338f3600b1SBryan Venteicher 
3410b59a9bSPeter Grehan struct vtnet_statistics {
358f3600b1SBryan Venteicher 	uint64_t	mbuf_alloc_failed;
3610b59a9bSPeter Grehan 
378f3600b1SBryan Venteicher 	uint64_t	rx_frame_too_large;
388f3600b1SBryan Venteicher 	uint64_t	rx_enq_replacement_failed;
398f3600b1SBryan Venteicher 	uint64_t	rx_mergeable_failed;
408f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_ethtype;
418f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_ipproto;
428f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_offset;
438f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_proto;
448f3600b1SBryan Venteicher 	uint64_t	tx_csum_bad_ethtype;
458f3600b1SBryan Venteicher 	uint64_t	tx_tso_bad_ethtype;
468f3600b1SBryan Venteicher 	uint64_t	tx_tso_not_tcp;
4710b59a9bSPeter Grehan 
488f3600b1SBryan Venteicher 	/*
498f3600b1SBryan Venteicher 	 * These are accumulated from each Rx/Tx queue.
508f3600b1SBryan Venteicher 	 */
518f3600b1SBryan Venteicher 	uint64_t	rx_csum_failed;
528f3600b1SBryan Venteicher 	uint64_t	rx_csum_offloaded;
538f3600b1SBryan Venteicher 	uint64_t	rx_task_rescheduled;
548f3600b1SBryan Venteicher 	uint64_t	tx_csum_offloaded;
558f3600b1SBryan Venteicher 	uint64_t	tx_tso_offloaded;
568f3600b1SBryan Venteicher 	uint64_t	tx_task_rescheduled;
5710b59a9bSPeter Grehan };
5810b59a9bSPeter Grehan 
598f3600b1SBryan Venteicher struct vtnet_rxq_stats {
608f3600b1SBryan Venteicher 	uint64_t	vrxs_ipackets;	/* if_ipackets */
618f3600b1SBryan Venteicher 	uint64_t	vrxs_ibytes;	/* if_ibytes */
628f3600b1SBryan Venteicher 	uint64_t	vrxs_iqdrops;	/* if_iqdrops */
638f3600b1SBryan Venteicher 	uint64_t	vrxs_ierrors;	/* if_ierrors */
648f3600b1SBryan Venteicher 	uint64_t	vrxs_csum;
658f3600b1SBryan Venteicher 	uint64_t	vrxs_csum_failed;
668f3600b1SBryan Venteicher 	uint64_t	vrxs_rescheduled;
678f3600b1SBryan Venteicher };
688f3600b1SBryan Venteicher 
698f3600b1SBryan Venteicher struct vtnet_rxq {
708f3600b1SBryan Venteicher 	struct mtx		 vtnrx_mtx;
718f3600b1SBryan Venteicher 	struct vtnet_softc	*vtnrx_sc;
728f3600b1SBryan Venteicher 	struct virtqueue	*vtnrx_vq;
73*443c3d0bSBryan Venteicher 	struct sglist		*vtnrx_sg;
748f3600b1SBryan Venteicher 	int			 vtnrx_id;
758f3600b1SBryan Venteicher 	int			 vtnrx_process_limit;
768f3600b1SBryan Venteicher 	struct vtnet_rxq_stats	 vtnrx_stats;
778f3600b1SBryan Venteicher 	struct taskqueue	*vtnrx_tq;
788f3600b1SBryan Venteicher 	struct task		 vtnrx_intrtask;
798f3600b1SBryan Venteicher 	char			 vtnrx_name[16];
808f3600b1SBryan Venteicher } __aligned(CACHE_LINE_SIZE);
818f3600b1SBryan Venteicher 
828f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK(_rxq)	mtx_lock(&(_rxq)->vtnrx_mtx)
838f3600b1SBryan Venteicher #define VTNET_RXQ_UNLOCK(_rxq)	mtx_unlock(&(_rxq)->vtnrx_mtx)
848f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK_ASSERT(_rxq)		\
858f3600b1SBryan Venteicher     mtx_assert(&(_rxq)->vtnrx_mtx, MA_OWNED)
868f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK_ASSERT_NOTOWNED(_rxq)	\
878f3600b1SBryan Venteicher     mtx_assert(&(_rxq)->vtnrx_mtx, MA_NOTOWNED)
888f3600b1SBryan Venteicher 
898f3600b1SBryan Venteicher struct vtnet_txq_stats {
908f3600b1SBryan Venteicher 	uint64_t vtxs_opackets;	/* if_opackets */
918f3600b1SBryan Venteicher 	uint64_t vtxs_obytes;	/* if_obytes */
928f3600b1SBryan Venteicher 	uint64_t vtxs_omcasts;	/* if_omcasts */
938f3600b1SBryan Venteicher 	uint64_t vtxs_csum;
948f3600b1SBryan Venteicher 	uint64_t vtxs_tso;
958f3600b1SBryan Venteicher 	uint64_t vtxs_collapsed;
968f3600b1SBryan Venteicher 	uint64_t vtxs_rescheduled;
978f3600b1SBryan Venteicher };
988f3600b1SBryan Venteicher 
998f3600b1SBryan Venteicher struct vtnet_txq {
1008f3600b1SBryan Venteicher 	struct mtx		 vtntx_mtx;
1018f3600b1SBryan Venteicher 	struct vtnet_softc	*vtntx_sc;
1028f3600b1SBryan Venteicher 	struct virtqueue	*vtntx_vq;
103*443c3d0bSBryan Venteicher 	struct sglist		*vtntx_sg;
1048f3600b1SBryan Venteicher #ifndef VTNET_LEGACY_TX
1058f3600b1SBryan Venteicher 	struct buf_ring		*vtntx_br;
1068f3600b1SBryan Venteicher #endif
1078f3600b1SBryan Venteicher 	int			 vtntx_id;
1088f3600b1SBryan Venteicher 	int			 vtntx_watchdog;
1098f3600b1SBryan Venteicher 	struct vtnet_txq_stats	 vtntx_stats;
1108f3600b1SBryan Venteicher 	struct taskqueue	*vtntx_tq;
1118f3600b1SBryan Venteicher 	struct task		 vtntx_intrtask;
1128f3600b1SBryan Venteicher #ifndef VTNET_LEGACY_TX
1138f3600b1SBryan Venteicher 	struct task		 vtntx_defrtask;
1148f3600b1SBryan Venteicher #endif
1158f3600b1SBryan Venteicher 	char			 vtntx_name[16];
1168f3600b1SBryan Venteicher } __aligned(CACHE_LINE_SIZE);
1178f3600b1SBryan Venteicher 
1188f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK(_txq)	mtx_lock(&(_txq)->vtntx_mtx)
1198f3600b1SBryan Venteicher #define VTNET_TXQ_TRYLOCK(_txq)	mtx_trylock(&(_txq)->vtntx_mtx)
1208f3600b1SBryan Venteicher #define VTNET_TXQ_UNLOCK(_txq)	mtx_unlock(&(_txq)->vtntx_mtx)
1218f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK_ASSERT(_txq)		\
1228f3600b1SBryan Venteicher     mtx_assert(&(_txq)->vtntx_mtx, MA_OWNED)
1238f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK_ASSERT_NOTOWNED(_txq)	\
1248f3600b1SBryan Venteicher     mtx_assert(&(_txq)->vtntx_mtx, MA_NOTOWNED)
1258f3600b1SBryan Venteicher 
12610b59a9bSPeter Grehan struct vtnet_softc {
12710b59a9bSPeter Grehan 	device_t		 vtnet_dev;
12810b59a9bSPeter Grehan 	struct ifnet		*vtnet_ifp;
1298f3600b1SBryan Venteicher 	struct vtnet_rxq	*vtnet_rxqs;
1308f3600b1SBryan Venteicher 	struct vtnet_txq	*vtnet_txqs;
13110b59a9bSPeter Grehan 
13210b59a9bSPeter Grehan 	uint32_t		 vtnet_flags;
1338f3600b1SBryan Venteicher #define VTNET_FLAG_SUSPENDED	 0x0001
1348f3600b1SBryan Venteicher #define VTNET_FLAG_MAC		 0x0002
13510b59a9bSPeter Grehan #define VTNET_FLAG_CTRL_VQ	 0x0004
13610b59a9bSPeter Grehan #define VTNET_FLAG_CTRL_RX	 0x0008
1378f3600b1SBryan Venteicher #define VTNET_FLAG_CTRL_MAC	 0x0010
1388f3600b1SBryan Venteicher #define VTNET_FLAG_VLAN_FILTER	 0x0020
1398f3600b1SBryan Venteicher #define VTNET_FLAG_TSO_ECN	 0x0040
1408f3600b1SBryan Venteicher #define VTNET_FLAG_MRG_RXBUFS	 0x0080
1418f3600b1SBryan Venteicher #define VTNET_FLAG_LRO_NOMRG	 0x0100
1428f3600b1SBryan Venteicher #define VTNET_FLAG_MULTIQ	 0x0200
1436e03f319SBryan Venteicher #define VTNET_FLAG_EVENT_IDX	 0x0400
14410b59a9bSPeter Grehan 
1458f3600b1SBryan Venteicher 	int			 vtnet_link_active;
14610b59a9bSPeter Grehan 	int			 vtnet_hdr_size;
14710b59a9bSPeter Grehan 	int			 vtnet_rx_process_limit;
148*443c3d0bSBryan Venteicher 	int			 vtnet_rx_nsegs;
1498f3600b1SBryan Venteicher 	int			 vtnet_rx_nmbufs;
1508f3600b1SBryan Venteicher 	int			 vtnet_rx_clsize;
1518f3600b1SBryan Venteicher 	int			 vtnet_rx_new_clsize;
152*443c3d0bSBryan Venteicher 	int			 vtnet_tx_nsegs;
15310b59a9bSPeter Grehan 	int			 vtnet_if_flags;
1548f3600b1SBryan Venteicher 	int			 vtnet_act_vq_pairs;
1558f3600b1SBryan Venteicher 	int			 vtnet_max_vq_pairs;
1568f3600b1SBryan Venteicher 
1578f3600b1SBryan Venteicher 	struct virtqueue	*vtnet_ctrl_vq;
1588f3600b1SBryan Venteicher 	struct vtnet_mac_filter	*vtnet_mac_filter;
1598f3600b1SBryan Venteicher 	uint32_t		*vtnet_vlan_filter;
1608f3600b1SBryan Venteicher 
16110b59a9bSPeter Grehan 	uint64_t		 vtnet_features;
16210b59a9bSPeter Grehan 	struct vtnet_statistics	 vtnet_stats;
16310b59a9bSPeter Grehan 	struct callout		 vtnet_tick_ch;
1648f3600b1SBryan Venteicher 	struct ifmedia		 vtnet_media;
16510b59a9bSPeter Grehan 	eventhandler_tag	 vtnet_vlan_attach;
16610b59a9bSPeter Grehan 	eventhandler_tag	 vtnet_vlan_detach;
16710b59a9bSPeter Grehan 
1688f3600b1SBryan Venteicher 	struct mtx		 vtnet_mtx;
16910b59a9bSPeter Grehan 	char			 vtnet_mtx_name[16];
1708f3600b1SBryan Venteicher 	char			 vtnet_hwaddr[ETHER_ADDR_LEN];
17110b59a9bSPeter Grehan };
17210b59a9bSPeter Grehan 
17310b59a9bSPeter Grehan /*
1748f3600b1SBryan Venteicher  * Maximum number of queue pairs we will autoconfigure to.
1758f3600b1SBryan Venteicher  */
1768f3600b1SBryan Venteicher #define VTNET_MAX_QUEUE_PAIRS	8
1778f3600b1SBryan Venteicher 
1788f3600b1SBryan Venteicher /*
1798f3600b1SBryan Venteicher  * Additional completed entries can appear in a virtqueue before we can
1808f3600b1SBryan Venteicher  * reenable interrupts. Number of times to retry before scheduling the
1818f3600b1SBryan Venteicher  * taskqueue to process the completed entries.
1828f3600b1SBryan Venteicher  */
1838f3600b1SBryan Venteicher #define VTNET_INTR_DISABLE_RETRIES	4
1848f3600b1SBryan Venteicher 
1858f3600b1SBryan Venteicher /*
1868f3600b1SBryan Venteicher  * Fake the media type. The host does not provide us with any real media
1878f3600b1SBryan Venteicher  * information.
1888f3600b1SBryan Venteicher  */
1898f3600b1SBryan Venteicher #define VTNET_MEDIATYPE		 (IFM_ETHER | IFM_10G_T | IFM_FDX)
1908f3600b1SBryan Venteicher 
1918f3600b1SBryan Venteicher /*
1928f3600b1SBryan Venteicher  * Number of words to allocate for the VLAN shadow table. There is one
1938f3600b1SBryan Venteicher  * bit for each VLAN.
1948f3600b1SBryan Venteicher  */
1958f3600b1SBryan Venteicher #define VTNET_VLAN_FILTER_NWORDS	(4096 / 32)
1968f3600b1SBryan Venteicher 
1978f3600b1SBryan Venteicher /*
19810b59a9bSPeter Grehan  * When mergeable buffers are not negotiated, the vtnet_rx_header structure
19910b59a9bSPeter Grehan  * below is placed at the beginning of the mbuf data. Use 4 bytes of pad to
20010b59a9bSPeter Grehan  * both keep the VirtIO header and the data non-contiguous and to keep the
20110b59a9bSPeter Grehan  * frame's payload 4 byte aligned.
20210b59a9bSPeter Grehan  *
20310b59a9bSPeter Grehan  * When mergeable buffers are negotiated, the host puts the VirtIO header in
20410b59a9bSPeter Grehan  * the beginning of the first mbuf's data.
20510b59a9bSPeter Grehan  */
20610b59a9bSPeter Grehan #define VTNET_RX_HEADER_PAD	4
20710b59a9bSPeter Grehan struct vtnet_rx_header {
20810b59a9bSPeter Grehan 	struct virtio_net_hdr	vrh_hdr;
20910b59a9bSPeter Grehan 	char			vrh_pad[VTNET_RX_HEADER_PAD];
21010b59a9bSPeter Grehan } __packed;
21110b59a9bSPeter Grehan 
21210b59a9bSPeter Grehan /*
21310b59a9bSPeter Grehan  * For each outgoing frame, the vtnet_tx_header below is allocated from
21410b59a9bSPeter Grehan  * the vtnet_tx_header_zone.
21510b59a9bSPeter Grehan  */
21610b59a9bSPeter Grehan struct vtnet_tx_header {
21710b59a9bSPeter Grehan 	union {
21810b59a9bSPeter Grehan 		struct virtio_net_hdr		hdr;
21910b59a9bSPeter Grehan 		struct virtio_net_hdr_mrg_rxbuf	mhdr;
22010b59a9bSPeter Grehan 	} vth_uhdr;
22110b59a9bSPeter Grehan 
22210b59a9bSPeter Grehan 	struct mbuf *vth_mbuf;
22310b59a9bSPeter Grehan };
22410b59a9bSPeter Grehan 
22510b59a9bSPeter Grehan /*
22610b59a9bSPeter Grehan  * The VirtIO specification does not place a limit on the number of MAC
22710b59a9bSPeter Grehan  * addresses the guest driver may request to be filtered. In practice,
22810b59a9bSPeter Grehan  * the host is constrained by available resources. To simplify this driver,
22910b59a9bSPeter Grehan  * impose a reasonably high limit of MAC addresses we will filter before
23010b59a9bSPeter Grehan  * falling back to promiscuous or all-multicast modes.
23110b59a9bSPeter Grehan  */
23210b59a9bSPeter Grehan #define VTNET_MAX_MAC_ENTRIES	128
23310b59a9bSPeter Grehan 
23410b59a9bSPeter Grehan struct vtnet_mac_table {
23510b59a9bSPeter Grehan 	uint32_t	nentries;
23610b59a9bSPeter Grehan 	uint8_t		macs[VTNET_MAX_MAC_ENTRIES][ETHER_ADDR_LEN];
23710b59a9bSPeter Grehan } __packed;
23810b59a9bSPeter Grehan 
23910b59a9bSPeter Grehan struct vtnet_mac_filter {
24010b59a9bSPeter Grehan 	struct vtnet_mac_table	vmf_unicast;
24110b59a9bSPeter Grehan 	uint32_t		vmf_pad; /* Make tables non-contiguous. */
24210b59a9bSPeter Grehan 	struct vtnet_mac_table	vmf_multicast;
24310b59a9bSPeter Grehan };
24410b59a9bSPeter Grehan 
24510b59a9bSPeter Grehan /*
24610b59a9bSPeter Grehan  * The MAC filter table is malloc(9)'d when needed. Ensure it will
24710b59a9bSPeter Grehan  * always fit in one segment.
24810b59a9bSPeter Grehan  */
24910b59a9bSPeter Grehan CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE);
25010b59a9bSPeter Grehan 
2518f3600b1SBryan Venteicher #define VTNET_TX_TIMEOUT	5
25210b59a9bSPeter Grehan #define VTNET_CSUM_OFFLOAD	(CSUM_TCP | CSUM_UDP | CSUM_SCTP)
2538f3600b1SBryan Venteicher #define VTNET_CSUM_OFFLOAD_IPV6	(CSUM_TCP_IPV6 | CSUM_UDP_IPV6 | CSUM_SCTP_IPV6)
2548f3600b1SBryan Venteicher 
2558f3600b1SBryan Venteicher #define VTNET_CSUM_ALL_OFFLOAD	\
2568f3600b1SBryan Venteicher     (VTNET_CSUM_OFFLOAD | VTNET_CSUM_OFFLOAD_IPV6 | CSUM_TSO)
25710b59a9bSPeter Grehan 
25810b59a9bSPeter Grehan /* Features desired/implemented by this driver. */
25910b59a9bSPeter Grehan #define VTNET_FEATURES \
26010b59a9bSPeter Grehan     (VIRTIO_NET_F_MAC			| \
26110b59a9bSPeter Grehan      VIRTIO_NET_F_STATUS		| \
26210b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_VQ		| \
26310b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_RX		| \
2648f3600b1SBryan Venteicher      VIRTIO_NET_F_CTRL_MAC_ADDR		| \
26510b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_VLAN		| \
26610b59a9bSPeter Grehan      VIRTIO_NET_F_CSUM			| \
2678f3600b1SBryan Venteicher      VIRTIO_NET_F_GSO			| \
26810b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_TSO4		| \
26910b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_TSO6		| \
27010b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_ECN		| \
27110b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_CSUM		| \
27210b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_TSO4		| \
27310b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_TSO6		| \
27410b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_ECN		| \
27510b59a9bSPeter Grehan      VIRTIO_NET_F_MRG_RXBUF		| \
2768f3600b1SBryan Venteicher      VIRTIO_NET_F_MQ			| \
2778f3600b1SBryan Venteicher      VIRTIO_RING_F_EVENT_IDX		| \
27810b59a9bSPeter Grehan      VIRTIO_RING_F_INDIRECT_DESC)
27910b59a9bSPeter Grehan 
28010b59a9bSPeter Grehan /*
2818f3600b1SBryan Venteicher  * The VIRTIO_NET_F_HOST_TSO[46] features permit us to send the host
2828f3600b1SBryan Venteicher  * frames larger than 1514 bytes.
2838f3600b1SBryan Venteicher  */
2848f3600b1SBryan Venteicher #define VTNET_TSO_FEATURES (VIRTIO_NET_F_GSO | VIRTIO_NET_F_HOST_TSO4 | \
2858f3600b1SBryan Venteicher     VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_ECN)
2868f3600b1SBryan Venteicher 
2878f3600b1SBryan Venteicher /*
28810b59a9bSPeter Grehan  * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us
28910b59a9bSPeter Grehan  * frames larger than 1514 bytes. We do not yet support software LRO
29010b59a9bSPeter Grehan  * via tcp_lro_rx().
29110b59a9bSPeter Grehan  */
29210b59a9bSPeter Grehan #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \
29310b59a9bSPeter Grehan     VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN)
29410b59a9bSPeter Grehan 
29510b59a9bSPeter Grehan #define VTNET_MAX_MTU		65536
29610b59a9bSPeter Grehan #define VTNET_MAX_RX_SIZE	65550
29710b59a9bSPeter Grehan 
29810b59a9bSPeter Grehan /*
29910b59a9bSPeter Grehan  * Used to preallocate the Vq indirect descriptors. The first segment
300*443c3d0bSBryan Venteicher  * is reserved for the header, except for mergeable buffers since the
301*443c3d0bSBryan Venteicher  * header is placed inline with the data.
30210b59a9bSPeter Grehan  */
303*443c3d0bSBryan Venteicher #define VTNET_MRG_RX_SEGS	1
30410b59a9bSPeter Grehan #define VTNET_MIN_RX_SEGS	2
30510b59a9bSPeter Grehan #define VTNET_MAX_RX_SEGS	34
306*443c3d0bSBryan Venteicher #define VTNET_MIN_TX_SEGS	4
307*443c3d0bSBryan Venteicher #define VTNET_MAX_TX_SEGS	64
30810b59a9bSPeter Grehan 
30910b59a9bSPeter Grehan /*
31010b59a9bSPeter Grehan  * Assert we can receive and transmit the maximum with regular
31110b59a9bSPeter Grehan  * size clusters.
31210b59a9bSPeter Grehan  */
31310b59a9bSPeter Grehan CTASSERT(((VTNET_MAX_RX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_RX_SIZE);
31410b59a9bSPeter Grehan CTASSERT(((VTNET_MAX_TX_SEGS - 1) * MCLBYTES) >= VTNET_MAX_MTU);
31510b59a9bSPeter Grehan 
31610b59a9bSPeter Grehan /*
3178f3600b1SBryan Venteicher  * Number of slots in the Tx bufrings. This value matches most other
3188f3600b1SBryan Venteicher  * multiqueue drivers.
3198f3600b1SBryan Venteicher  */
3208f3600b1SBryan Venteicher #define VTNET_DEFAULT_BUFRING_SIZE	4096
3218f3600b1SBryan Venteicher 
3228f3600b1SBryan Venteicher /*
32310b59a9bSPeter Grehan  * Determine how many mbufs are in each receive buffer. For LRO without
324*443c3d0bSBryan Venteicher  * mergeable buffers, we must allocate an mbuf chain large enough to
32510b59a9bSPeter Grehan  * hold both the vtnet_rx_header and the maximum receivable data.
32610b59a9bSPeter Grehan  */
3278f3600b1SBryan Venteicher #define VTNET_NEEDED_RX_MBUFS(_sc, _clsize)				\
32810b59a9bSPeter Grehan 	((_sc)->vtnet_flags & VTNET_FLAG_LRO_NOMRG) == 0 ? 1 :		\
32910b59a9bSPeter Grehan 	    howmany(sizeof(struct vtnet_rx_header) + VTNET_MAX_RX_SIZE,	\
3308f3600b1SBryan Venteicher 	        (_clsize))
33110b59a9bSPeter Grehan 
3328f3600b1SBryan Venteicher #define VTNET_CORE_MTX(_sc)		&(_sc)->vtnet_mtx
3338f3600b1SBryan Venteicher #define VTNET_CORE_LOCK(_sc)		mtx_lock(VTNET_CORE_MTX((_sc)))
3348f3600b1SBryan Venteicher #define VTNET_CORE_UNLOCK(_sc)		mtx_unlock(VTNET_CORE_MTX((_sc)))
3358f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_DESTROY(_sc)	mtx_destroy(VTNET_CORE_MTX((_sc)))
3368f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_ASSERT(_sc)		\
3378f3600b1SBryan Venteicher     mtx_assert(VTNET_CORE_MTX((_sc)), MA_OWNED)
3388f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_ASSERT_NOTOWNED(_sc)	\
3398f3600b1SBryan Venteicher     mtx_assert(VTNET_CORE_MTX((_sc)), MA_NOTOWNED)
34010b59a9bSPeter Grehan 
3418f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_INIT(_sc) do {					\
34210b59a9bSPeter Grehan     snprintf((_sc)->vtnet_mtx_name, sizeof((_sc)->vtnet_mtx_name),	\
34310b59a9bSPeter Grehan         "%s", device_get_nameunit((_sc)->vtnet_dev));			\
3448f3600b1SBryan Venteicher     mtx_init(VTNET_CORE_MTX((_sc)), (_sc)->vtnet_mtx_name,		\
34510b59a9bSPeter Grehan         "VTNET Core Lock", MTX_DEF);					\
34610b59a9bSPeter Grehan } while (0)
34710b59a9bSPeter Grehan 
34810b59a9bSPeter Grehan #endif /* _IF_VTNETVAR_H */
349