xref: /freebsd/sys/dev/virtio/network/if_vtnetvar.h (revision 2bfab357745256342fbf7cea952c534f6680b8bb)
110b59a9bSPeter Grehan /*-
2718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3718cf2ccSPedro F. Giffuni  *
4abd6790cSBryan Venteicher  * Copyright (c) 2011, Bryan Venteicher <bryanv@FreeBSD.org>
510b59a9bSPeter Grehan  * All rights reserved.
610b59a9bSPeter Grehan  *
710b59a9bSPeter Grehan  * Redistribution and use in source and binary forms, with or without
810b59a9bSPeter Grehan  * modification, are permitted provided that the following conditions
910b59a9bSPeter Grehan  * are met:
1010b59a9bSPeter Grehan  * 1. Redistributions of source code must retain the above copyright
1110b59a9bSPeter Grehan  *    notice unmodified, this list of conditions, and the following
1210b59a9bSPeter Grehan  *    disclaimer.
1310b59a9bSPeter Grehan  * 2. Redistributions in binary form must reproduce the above copyright
1410b59a9bSPeter Grehan  *    notice, this list of conditions and the following disclaimer in the
1510b59a9bSPeter Grehan  *    documentation and/or other materials provided with the distribution.
1610b59a9bSPeter Grehan  *
1710b59a9bSPeter Grehan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1810b59a9bSPeter Grehan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1910b59a9bSPeter Grehan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2010b59a9bSPeter Grehan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2110b59a9bSPeter Grehan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2210b59a9bSPeter Grehan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310b59a9bSPeter Grehan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410b59a9bSPeter Grehan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510b59a9bSPeter Grehan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2610b59a9bSPeter Grehan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710b59a9bSPeter Grehan  *
2810b59a9bSPeter Grehan  * $FreeBSD$
2910b59a9bSPeter Grehan  */
3010b59a9bSPeter Grehan 
3110b59a9bSPeter Grehan #ifndef _IF_VTNETVAR_H
3210b59a9bSPeter Grehan #define _IF_VTNETVAR_H
3310b59a9bSPeter Grehan 
348f3600b1SBryan Venteicher struct vtnet_softc;
358f3600b1SBryan Venteicher 
3610b59a9bSPeter Grehan struct vtnet_statistics {
378f3600b1SBryan Venteicher 	uint64_t	mbuf_alloc_failed;
3810b59a9bSPeter Grehan 
398f3600b1SBryan Venteicher 	uint64_t	rx_frame_too_large;
408f3600b1SBryan Venteicher 	uint64_t	rx_enq_replacement_failed;
418f3600b1SBryan Venteicher 	uint64_t	rx_mergeable_failed;
428f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_ethtype;
438f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_ipproto;
448f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_offset;
458f3600b1SBryan Venteicher 	uint64_t	rx_csum_bad_proto;
46475a60aeSBryan Venteicher 	uint64_t	tx_csum_unknown_ethtype;
47475a60aeSBryan Venteicher 	uint64_t	tx_csum_proto_mismatch;
488f3600b1SBryan Venteicher 	uint64_t	tx_tso_not_tcp;
49475a60aeSBryan Venteicher 	uint64_t	tx_tso_without_csum;
5054fb8142SBryan Venteicher 	uint64_t	tx_defragged;
5154fb8142SBryan Venteicher 	uint64_t	tx_defrag_failed;
5210b59a9bSPeter Grehan 
538f3600b1SBryan Venteicher 	/*
548f3600b1SBryan Venteicher 	 * These are accumulated from each Rx/Tx queue.
558f3600b1SBryan Venteicher 	 */
568f3600b1SBryan Venteicher 	uint64_t	rx_csum_failed;
578f3600b1SBryan Venteicher 	uint64_t	rx_csum_offloaded;
588f3600b1SBryan Venteicher 	uint64_t	rx_task_rescheduled;
598f3600b1SBryan Venteicher 	uint64_t	tx_csum_offloaded;
608f3600b1SBryan Venteicher 	uint64_t	tx_tso_offloaded;
618f3600b1SBryan Venteicher 	uint64_t	tx_task_rescheduled;
6210b59a9bSPeter Grehan };
6310b59a9bSPeter Grehan 
648f3600b1SBryan Venteicher struct vtnet_rxq_stats {
658f3600b1SBryan Venteicher 	uint64_t	vrxs_ipackets;	/* if_ipackets */
668f3600b1SBryan Venteicher 	uint64_t	vrxs_ibytes;	/* if_ibytes */
678f3600b1SBryan Venteicher 	uint64_t	vrxs_iqdrops;	/* if_iqdrops */
688f3600b1SBryan Venteicher 	uint64_t	vrxs_ierrors;	/* if_ierrors */
698f3600b1SBryan Venteicher 	uint64_t	vrxs_csum;
708f3600b1SBryan Venteicher 	uint64_t	vrxs_csum_failed;
71*2bfab357SBryan Venteicher 	uint64_t	vrxs_host_lro;
728f3600b1SBryan Venteicher 	uint64_t	vrxs_rescheduled;
738f3600b1SBryan Venteicher };
748f3600b1SBryan Venteicher 
758f3600b1SBryan Venteicher struct vtnet_rxq {
768f3600b1SBryan Venteicher 	struct mtx		 vtnrx_mtx;
778f3600b1SBryan Venteicher 	struct vtnet_softc	*vtnrx_sc;
788f3600b1SBryan Venteicher 	struct virtqueue	*vtnrx_vq;
79443c3d0bSBryan Venteicher 	struct sglist		*vtnrx_sg;
808f3600b1SBryan Venteicher 	int			 vtnrx_id;
818f3600b1SBryan Venteicher 	struct vtnet_rxq_stats	 vtnrx_stats;
828f3600b1SBryan Venteicher 	struct taskqueue	*vtnrx_tq;
838f3600b1SBryan Venteicher 	struct task		 vtnrx_intrtask;
8442343a63SBryan Venteicher 	struct lro_ctrl		 vtnrx_lro;
852e42b74aSVincenzo Maffione #ifdef DEV_NETMAP
862d769e25SVincenzo Maffione 	uint32_t		 vtnrx_nm_refill;
872e42b74aSVincenzo Maffione 	struct virtio_net_hdr_mrg_rxbuf vtnrx_shrhdr;
882e42b74aSVincenzo Maffione #endif  /* DEV_NETMAP */
898f3600b1SBryan Venteicher 	char			 vtnrx_name[16];
908f3600b1SBryan Venteicher } __aligned(CACHE_LINE_SIZE);
918f3600b1SBryan Venteicher 
928f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK(_rxq)	mtx_lock(&(_rxq)->vtnrx_mtx)
938f3600b1SBryan Venteicher #define VTNET_RXQ_UNLOCK(_rxq)	mtx_unlock(&(_rxq)->vtnrx_mtx)
948f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK_ASSERT(_rxq)		\
958f3600b1SBryan Venteicher     mtx_assert(&(_rxq)->vtnrx_mtx, MA_OWNED)
968f3600b1SBryan Venteicher #define VTNET_RXQ_LOCK_ASSERT_NOTOWNED(_rxq)	\
978f3600b1SBryan Venteicher     mtx_assert(&(_rxq)->vtnrx_mtx, MA_NOTOWNED)
988f3600b1SBryan Venteicher 
998f3600b1SBryan Venteicher struct vtnet_txq_stats {
1008f3600b1SBryan Venteicher 	uint64_t vtxs_opackets;	/* if_opackets */
1018f3600b1SBryan Venteicher 	uint64_t vtxs_obytes;	/* if_obytes */
1028f3600b1SBryan Venteicher 	uint64_t vtxs_omcasts;	/* if_omcasts */
1038f3600b1SBryan Venteicher 	uint64_t vtxs_csum;
1048f3600b1SBryan Venteicher 	uint64_t vtxs_tso;
1058f3600b1SBryan Venteicher 	uint64_t vtxs_rescheduled;
1068f3600b1SBryan Venteicher };
1078f3600b1SBryan Venteicher 
1088f3600b1SBryan Venteicher struct vtnet_txq {
1098f3600b1SBryan Venteicher 	struct mtx		 vtntx_mtx;
1108f3600b1SBryan Venteicher 	struct vtnet_softc	*vtntx_sc;
1118f3600b1SBryan Venteicher 	struct virtqueue	*vtntx_vq;
112443c3d0bSBryan Venteicher 	struct sglist		*vtntx_sg;
1138f3600b1SBryan Venteicher #ifndef VTNET_LEGACY_TX
1148f3600b1SBryan Venteicher 	struct buf_ring		*vtntx_br;
1158f3600b1SBryan Venteicher #endif
1168f3600b1SBryan Venteicher 	int			 vtntx_id;
1178f3600b1SBryan Venteicher 	int			 vtntx_watchdog;
118baa5234fSBryan Venteicher 	int			 vtntx_intr_threshold;
1198f3600b1SBryan Venteicher 	struct vtnet_txq_stats	 vtntx_stats;
1208f3600b1SBryan Venteicher 	struct taskqueue	*vtntx_tq;
1218f3600b1SBryan Venteicher 	struct task		 vtntx_intrtask;
1228f3600b1SBryan Venteicher #ifndef VTNET_LEGACY_TX
1238f3600b1SBryan Venteicher 	struct task		 vtntx_defrtask;
1248f3600b1SBryan Venteicher #endif
1252e42b74aSVincenzo Maffione #ifdef DEV_NETMAP
1262e42b74aSVincenzo Maffione 	struct virtio_net_hdr_mrg_rxbuf vtntx_shrhdr;
1272e42b74aSVincenzo Maffione #endif  /* DEV_NETMAP */
1288f3600b1SBryan Venteicher 	char			 vtntx_name[16];
1298f3600b1SBryan Venteicher } __aligned(CACHE_LINE_SIZE);
1308f3600b1SBryan Venteicher 
1318f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK(_txq)	mtx_lock(&(_txq)->vtntx_mtx)
1328f3600b1SBryan Venteicher #define VTNET_TXQ_TRYLOCK(_txq)	mtx_trylock(&(_txq)->vtntx_mtx)
1338f3600b1SBryan Venteicher #define VTNET_TXQ_UNLOCK(_txq)	mtx_unlock(&(_txq)->vtntx_mtx)
1348f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK_ASSERT(_txq)		\
1358f3600b1SBryan Venteicher     mtx_assert(&(_txq)->vtntx_mtx, MA_OWNED)
1368f3600b1SBryan Venteicher #define VTNET_TXQ_LOCK_ASSERT_NOTOWNED(_txq)	\
1378f3600b1SBryan Venteicher     mtx_assert(&(_txq)->vtntx_mtx, MA_NOTOWNED)
1388f3600b1SBryan Venteicher 
13910b59a9bSPeter Grehan struct vtnet_softc {
14010b59a9bSPeter Grehan 	device_t		 vtnet_dev;
14110b59a9bSPeter Grehan 	struct ifnet		*vtnet_ifp;
1428f3600b1SBryan Venteicher 	struct vtnet_rxq	*vtnet_rxqs;
1438f3600b1SBryan Venteicher 	struct vtnet_txq	*vtnet_txqs;
144ed6cbf48SGleb Smirnoff 	pfil_head_t		 vtnet_pfil;
14574cd316aSBryan Venteicher 	uint64_t		 vtnet_features;
14610b59a9bSPeter Grehan 
14710b59a9bSPeter Grehan 	uint32_t		 vtnet_flags;
1485e220811SBryan Venteicher #define VTNET_FLAG_MODERN	 0x0001
1498f3600b1SBryan Venteicher #define VTNET_FLAG_MAC		 0x0002
15010b59a9bSPeter Grehan #define VTNET_FLAG_CTRL_VQ	 0x0004
15110b59a9bSPeter Grehan #define VTNET_FLAG_CTRL_RX	 0x0008
1528f3600b1SBryan Venteicher #define VTNET_FLAG_CTRL_MAC	 0x0010
1538f3600b1SBryan Venteicher #define VTNET_FLAG_VLAN_FILTER	 0x0020
1548f3600b1SBryan Venteicher #define VTNET_FLAG_TSO_ECN	 0x0040
1558f3600b1SBryan Venteicher #define VTNET_FLAG_MRG_RXBUFS	 0x0080
1568f3600b1SBryan Venteicher #define VTNET_FLAG_LRO_NOMRG	 0x0100
1575e220811SBryan Venteicher #define VTNET_FLAG_MQ		 0x0200
158ab4c2818SBryan Venteicher #define VTNET_FLAG_INDIRECT	 0x0400
159ab4c2818SBryan Venteicher #define VTNET_FLAG_EVENT_IDX	 0x0800
1605e220811SBryan Venteicher #define VTNET_FLAG_SUSPENDED	 0x1000
161fa7ca1e3SBryan Venteicher #define VTNET_FLAG_FIXUP_NEEDS_CSUM 0x2000
16242343a63SBryan Venteicher #define VTNET_FLAG_SW_LRO	 0x4000
16310b59a9bSPeter Grehan 
16410b59a9bSPeter Grehan 	int			 vtnet_hdr_size;
1658f3600b1SBryan Venteicher 	int			 vtnet_rx_nmbufs;
1665e220811SBryan Venteicher 	int			 vtnet_rx_clustersz;
16774cd316aSBryan Venteicher 	int			 vtnet_rx_nsegs;
16874cd316aSBryan Venteicher 	int			 vtnet_rx_process_limit;
16974cd316aSBryan Venteicher 	int			 vtnet_link_active;
1708f3600b1SBryan Venteicher 	int			 vtnet_act_vq_pairs;
171b470419eSBryan Venteicher 	int			 vtnet_req_vq_pairs;
1728f3600b1SBryan Venteicher 	int			 vtnet_max_vq_pairs;
17374cd316aSBryan Venteicher 	int			 vtnet_tx_nsegs;
17474cd316aSBryan Venteicher 	int			 vtnet_if_flags;
17574cd316aSBryan Venteicher 	int			 vtnet_max_mtu;
17642343a63SBryan Venteicher 	int			 vtnet_lro_entry_count;
17742343a63SBryan Venteicher 	int			 vtnet_lro_mbufq_depth;
1788f3600b1SBryan Venteicher 
1798f3600b1SBryan Venteicher 	struct virtqueue	*vtnet_ctrl_vq;
1808f3600b1SBryan Venteicher 	struct vtnet_mac_filter	*vtnet_mac_filter;
1818f3600b1SBryan Venteicher 	uint32_t		*vtnet_vlan_filter;
1828f3600b1SBryan Venteicher 
18344559b26SBryan Venteicher 	uint64_t		 vtnet_negotiated_features;
18410b59a9bSPeter Grehan 	struct vtnet_statistics	 vtnet_stats;
18510b59a9bSPeter Grehan 	struct callout		 vtnet_tick_ch;
1868f3600b1SBryan Venteicher 	struct ifmedia		 vtnet_media;
18710b59a9bSPeter Grehan 	eventhandler_tag	 vtnet_vlan_attach;
18810b59a9bSPeter Grehan 	eventhandler_tag	 vtnet_vlan_detach;
18910b59a9bSPeter Grehan 
1908f3600b1SBryan Venteicher 	struct mtx		 vtnet_mtx;
19110b59a9bSPeter Grehan 	char			 vtnet_mtx_name[16];
1928f3600b1SBryan Venteicher 	char			 vtnet_hwaddr[ETHER_ADDR_LEN];
19310b59a9bSPeter Grehan };
19410b59a9bSPeter Grehan 
1955e220811SBryan Venteicher static bool
1965e220811SBryan Venteicher vtnet_modern(struct vtnet_softc *sc)
1975e220811SBryan Venteicher {
1985e220811SBryan Venteicher 	return ((sc->vtnet_flags & VTNET_FLAG_MODERN) != 0);
1995e220811SBryan Venteicher }
2005e220811SBryan Venteicher 
20142343a63SBryan Venteicher static bool
20242343a63SBryan Venteicher vtnet_software_lro(struct vtnet_softc *sc)
20342343a63SBryan Venteicher {
20442343a63SBryan Venteicher 	return ((sc->vtnet_flags & VTNET_FLAG_SW_LRO) != 0);
20542343a63SBryan Venteicher }
20642343a63SBryan Venteicher 
20710b59a9bSPeter Grehan /*
2088f3600b1SBryan Venteicher  * Maximum number of queue pairs we will autoconfigure to.
2098f3600b1SBryan Venteicher  */
210fa7ca1e3SBryan Venteicher #define VTNET_MAX_QUEUE_PAIRS	32
2118f3600b1SBryan Venteicher 
2128f3600b1SBryan Venteicher /*
2138f3600b1SBryan Venteicher  * Additional completed entries can appear in a virtqueue before we can
2148f3600b1SBryan Venteicher  * reenable interrupts. Number of times to retry before scheduling the
2158f3600b1SBryan Venteicher  * taskqueue to process the completed entries.
2168f3600b1SBryan Venteicher  */
2178f3600b1SBryan Venteicher #define VTNET_INTR_DISABLE_RETRIES	4
2188f3600b1SBryan Venteicher 
2198f3600b1SBryan Venteicher /*
22032487a89SBryan Venteicher  * Similarly, additional completed entries can appear in a virtqueue
22132487a89SBryan Venteicher  * between when lasted checked and before notifying the host. Number
22232487a89SBryan Venteicher  * of times to retry before scheduling the taskqueue to process the
22332487a89SBryan Venteicher  * queue.
22432487a89SBryan Venteicher  */
22532487a89SBryan Venteicher #define VTNET_NOTIFY_RETRIES		4
22632487a89SBryan Venteicher 
22732487a89SBryan Venteicher /*
2288f3600b1SBryan Venteicher  * Number of words to allocate for the VLAN shadow table. There is one
2298f3600b1SBryan Venteicher  * bit for each VLAN.
2308f3600b1SBryan Venteicher  */
2318f3600b1SBryan Venteicher #define VTNET_VLAN_FILTER_NWORDS	(4096 / 32)
2328f3600b1SBryan Venteicher 
2335e220811SBryan Venteicher /* We depend on these being the same size (and same layout). */
2345e220811SBryan Venteicher CTASSERT(sizeof(struct virtio_net_hdr_mrg_rxbuf) ==
2355e220811SBryan Venteicher     sizeof(struct virtio_net_hdr_v1));
2365e220811SBryan Venteicher 
2378f3600b1SBryan Venteicher /*
2385e220811SBryan Venteicher  * In legacy VirtIO when mergeable buffers are not negotiated, this structure
2395e220811SBryan Venteicher  * is placed at the beginning of the mbuf data. Use 4 bytes of pad to keep
2405e220811SBryan Venteicher  * both the VirtIO header and the data non-contiguous and the frame's payload
2415e220811SBryan Venteicher  * 4 byte aligned. Note this padding would not be necessary if the
2425e220811SBryan Venteicher  * VIRTIO_F_ANY_LAYOUT feature was negotiated (but we don't support that yet).
24310b59a9bSPeter Grehan  *
2445e220811SBryan Venteicher  * In modern VirtIO or when mergeable buffers are negotiated, the host puts
2455e220811SBryan Venteicher  * the VirtIO header in the beginning of the first mbuf's data.
24610b59a9bSPeter Grehan  */
24710b59a9bSPeter Grehan #define VTNET_RX_HEADER_PAD	4
24810b59a9bSPeter Grehan struct vtnet_rx_header {
2491cd1ed3fSBryan Venteicher 	struct virtio_net_hdr	vrh_hdr;
25010b59a9bSPeter Grehan 	char			vrh_pad[VTNET_RX_HEADER_PAD];
25110b59a9bSPeter Grehan } __packed;
25210b59a9bSPeter Grehan 
25310b59a9bSPeter Grehan /*
25410b59a9bSPeter Grehan  * For each outgoing frame, the vtnet_tx_header below is allocated from
25510b59a9bSPeter Grehan  * the vtnet_tx_header_zone.
25610b59a9bSPeter Grehan  */
25710b59a9bSPeter Grehan struct vtnet_tx_header {
25810b59a9bSPeter Grehan 	union {
25910b59a9bSPeter Grehan 		struct virtio_net_hdr		hdr;
26010b59a9bSPeter Grehan 		struct virtio_net_hdr_mrg_rxbuf	mhdr;
2615e220811SBryan Venteicher 		struct virtio_net_hdr_v1	v1hdr;
26210b59a9bSPeter Grehan 	} vth_uhdr;
26310b59a9bSPeter Grehan 
26410b59a9bSPeter Grehan 	struct mbuf *vth_mbuf;
26510b59a9bSPeter Grehan };
26610b59a9bSPeter Grehan 
26710b59a9bSPeter Grehan /*
26810b59a9bSPeter Grehan  * The VirtIO specification does not place a limit on the number of MAC
26910b59a9bSPeter Grehan  * addresses the guest driver may request to be filtered. In practice,
27010b59a9bSPeter Grehan  * the host is constrained by available resources. To simplify this driver,
27110b59a9bSPeter Grehan  * impose a reasonably high limit of MAC addresses we will filter before
27210b59a9bSPeter Grehan  * falling back to promiscuous or all-multicast modes.
27310b59a9bSPeter Grehan  */
27410b59a9bSPeter Grehan #define VTNET_MAX_MAC_ENTRIES	128
27510b59a9bSPeter Grehan 
2765e220811SBryan Venteicher /*
2775e220811SBryan Venteicher  * The driver version of struct virtio_net_ctrl_mac but with our predefined
2785e220811SBryan Venteicher  * number of MAC addresses allocated. This structure is shared with the host,
2795e220811SBryan Venteicher  * so nentries field is in the correct VirtIO endianness.
2805e220811SBryan Venteicher  */
28110b59a9bSPeter Grehan struct vtnet_mac_table {
28210b59a9bSPeter Grehan 	uint32_t	nentries;
28310b59a9bSPeter Grehan 	uint8_t		macs[VTNET_MAX_MAC_ENTRIES][ETHER_ADDR_LEN];
28410b59a9bSPeter Grehan } __packed;
28510b59a9bSPeter Grehan 
28610b59a9bSPeter Grehan struct vtnet_mac_filter {
28710b59a9bSPeter Grehan 	struct vtnet_mac_table	vmf_unicast;
28810b59a9bSPeter Grehan 	uint32_t		vmf_pad; /* Make tables non-contiguous. */
28910b59a9bSPeter Grehan 	struct vtnet_mac_table	vmf_multicast;
29010b59a9bSPeter Grehan };
29110b59a9bSPeter Grehan 
29210b59a9bSPeter Grehan /*
29310b59a9bSPeter Grehan  * The MAC filter table is malloc(9)'d when needed. Ensure it will
29410b59a9bSPeter Grehan  * always fit in one segment.
29510b59a9bSPeter Grehan  */
29610b59a9bSPeter Grehan CTASSERT(sizeof(struct vtnet_mac_filter) <= PAGE_SIZE);
29710b59a9bSPeter Grehan 
2988f3600b1SBryan Venteicher #define VTNET_TX_TIMEOUT	5
299132ea9f2SMichael Tuexen #define VTNET_CSUM_OFFLOAD	(CSUM_TCP | CSUM_UDP)
300132ea9f2SMichael Tuexen #define VTNET_CSUM_OFFLOAD_IPV6	(CSUM_TCP_IPV6 | CSUM_UDP_IPV6)
3018f3600b1SBryan Venteicher 
3028f3600b1SBryan Venteicher #define VTNET_CSUM_ALL_OFFLOAD	\
3038f3600b1SBryan Venteicher     (VTNET_CSUM_OFFLOAD | VTNET_CSUM_OFFLOAD_IPV6 | CSUM_TSO)
30410b59a9bSPeter Grehan 
3055e220811SBryan Venteicher #define VTNET_COMMON_FEATURES \
30610b59a9bSPeter Grehan     (VIRTIO_NET_F_MAC			| \
30710b59a9bSPeter Grehan      VIRTIO_NET_F_STATUS		| \
308e36a6b1bSBryan Venteicher      VIRTIO_NET_F_CTRL_GUEST_OFFLOADS	| \
309aabdf5b6SBryan Venteicher      VIRTIO_NET_F_MTU			| \
31010b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_VQ		| \
31110b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_RX		| \
3128f3600b1SBryan Venteicher      VIRTIO_NET_F_CTRL_MAC_ADDR		| \
31310b59a9bSPeter Grehan      VIRTIO_NET_F_CTRL_VLAN		| \
31410b59a9bSPeter Grehan      VIRTIO_NET_F_CSUM			| \
31510b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_TSO4		| \
31610b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_TSO6		| \
31710b59a9bSPeter Grehan      VIRTIO_NET_F_HOST_ECN		| \
31810b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_CSUM		| \
31910b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_TSO4		| \
32010b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_TSO6		| \
32110b59a9bSPeter Grehan      VIRTIO_NET_F_GUEST_ECN		| \
32210b59a9bSPeter Grehan      VIRTIO_NET_F_MRG_RXBUF		| \
3238f3600b1SBryan Venteicher      VIRTIO_NET_F_MQ			| \
3246a733393SBryan Venteicher      VIRTIO_NET_F_SPEED_DUPLEX		| \
3258f3600b1SBryan Venteicher      VIRTIO_RING_F_EVENT_IDX		| \
3261cd1ed3fSBryan Venteicher      VIRTIO_RING_F_INDIRECT_DESC)
32710b59a9bSPeter Grehan 
3285e220811SBryan Venteicher #define VTNET_MODERN_FEATURES (VTNET_COMMON_FEATURES)
3295e220811SBryan Venteicher #define VTNET_LEGACY_FEATURES (VTNET_COMMON_FEATURES | VIRTIO_NET_F_GSO)
3305e220811SBryan Venteicher 
33110b59a9bSPeter Grehan /*
3328f3600b1SBryan Venteicher  * The VIRTIO_NET_F_HOST_TSO[46] features permit us to send the host
3338f3600b1SBryan Venteicher  * frames larger than 1514 bytes.
3348f3600b1SBryan Venteicher  */
3358f3600b1SBryan Venteicher #define VTNET_TSO_FEATURES (VIRTIO_NET_F_GSO | VIRTIO_NET_F_HOST_TSO4 | \
3368f3600b1SBryan Venteicher     VIRTIO_NET_F_HOST_TSO6 | VIRTIO_NET_F_HOST_ECN)
3378f3600b1SBryan Venteicher 
3388f3600b1SBryan Venteicher /*
33910b59a9bSPeter Grehan  * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us
34042343a63SBryan Venteicher  * frames larger than 1514 bytes.
34110b59a9bSPeter Grehan  */
34210b59a9bSPeter Grehan #define VTNET_LRO_FEATURES (VIRTIO_NET_F_GUEST_TSO4 | \
34310b59a9bSPeter Grehan     VIRTIO_NET_F_GUEST_TSO6 | VIRTIO_NET_F_GUEST_ECN)
34410b59a9bSPeter Grehan 
345c3187190SBryan Venteicher #define VTNET_MIN_MTU		68
34610b59a9bSPeter Grehan #define VTNET_MAX_MTU		65536
34710b59a9bSPeter Grehan #define VTNET_MAX_RX_SIZE	65550
34810b59a9bSPeter Grehan 
34910b59a9bSPeter Grehan /*
350fa7ca1e3SBryan Venteicher  * Used to preallocate the VQ indirect descriptors. Modern and mergeable
351fa7ca1e3SBryan Venteicher  * buffers do not required one segment for the VirtIO header since it is
352fa7ca1e3SBryan Venteicher  * placed inline at the beginning of the receive buffer.
35310b59a9bSPeter Grehan  */
354fa7ca1e3SBryan Venteicher #define VTNET_RX_SEGS_HDR_INLINE	1
355fa7ca1e3SBryan Venteicher #define VTNET_RX_SEGS_HDR_SEPARATE	2
356fa7ca1e3SBryan Venteicher #define VTNET_RX_SEGS_LRO_NOMRG		34
357fa7ca1e3SBryan Venteicher #define VTNET_TX_SEGS_MIN		32
358fa7ca1e3SBryan Venteicher #define VTNET_TX_SEGS_MAX		64
35910b59a9bSPeter Grehan 
360fa7ca1e3SBryan Venteicher CTASSERT(((VTNET_RX_SEGS_LRO_NOMRG - 1) * MCLBYTES) >= VTNET_MAX_RX_SIZE);
361fa7ca1e3SBryan Venteicher CTASSERT(((VTNET_TX_SEGS_MAX - 1) * MCLBYTES) >= VTNET_MAX_MTU);
36210b59a9bSPeter Grehan 
36310b59a9bSPeter Grehan /*
3648f3600b1SBryan Venteicher  * Number of slots in the Tx bufrings. This value matches most other
3658f3600b1SBryan Venteicher  * multiqueue drivers.
3668f3600b1SBryan Venteicher  */
3678f3600b1SBryan Venteicher #define VTNET_DEFAULT_BUFRING_SIZE	4096
3688f3600b1SBryan Venteicher 
3698f3600b1SBryan Venteicher #define VTNET_CORE_MTX(_sc)		&(_sc)->vtnet_mtx
3708f3600b1SBryan Venteicher #define VTNET_CORE_LOCK(_sc)		mtx_lock(VTNET_CORE_MTX((_sc)))
3718f3600b1SBryan Venteicher #define VTNET_CORE_UNLOCK(_sc)		mtx_unlock(VTNET_CORE_MTX((_sc)))
3728f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_DESTROY(_sc)	mtx_destroy(VTNET_CORE_MTX((_sc)))
3738f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_ASSERT(_sc)		\
3748f3600b1SBryan Venteicher     mtx_assert(VTNET_CORE_MTX((_sc)), MA_OWNED)
3758f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_ASSERT_NOTOWNED(_sc)	\
3768f3600b1SBryan Venteicher     mtx_assert(VTNET_CORE_MTX((_sc)), MA_NOTOWNED)
37710b59a9bSPeter Grehan 
3788f3600b1SBryan Venteicher #define VTNET_CORE_LOCK_INIT(_sc) do {					\
37910b59a9bSPeter Grehan     snprintf((_sc)->vtnet_mtx_name, sizeof((_sc)->vtnet_mtx_name),	\
38010b59a9bSPeter Grehan         "%s", device_get_nameunit((_sc)->vtnet_dev));			\
3818f3600b1SBryan Venteicher     mtx_init(VTNET_CORE_MTX((_sc)), (_sc)->vtnet_mtx_name,		\
38210b59a9bSPeter Grehan         "VTNET Core Lock", MTX_DEF);					\
38310b59a9bSPeter Grehan } while (0)
38410b59a9bSPeter Grehan 
38516f224b5SVincenzo Maffione /*
38616f224b5SVincenzo Maffione  * Values for the init_mode argument of vtnet_init_locked().
38716f224b5SVincenzo Maffione  */
38816f224b5SVincenzo Maffione #define VTNET_INIT_NETMAP_ENTER		1
38916f224b5SVincenzo Maffione #define VTNET_INIT_NETMAP_EXIT		2
39016f224b5SVincenzo Maffione 
39110b59a9bSPeter Grehan #endif /* _IF_VTNETVAR_H */
392