19fbe302bSMichael S. Tsirkin #ifndef _LINUX_VIRTIO_NET_H
29fbe302bSMichael S. Tsirkin #define _LINUX_VIRTIO_NET_H
39fbe302bSMichael S. Tsirkin /* This header is BSD licensed so anyone can use the definitions to implement
49fbe302bSMichael S. Tsirkin  * compatible drivers/servers.
59fbe302bSMichael S. Tsirkin  *
69fbe302bSMichael S. Tsirkin  * Redistribution and use in source and binary forms, with or without
79fbe302bSMichael S. Tsirkin  * modification, are permitted provided that the following conditions
89fbe302bSMichael S. Tsirkin  * are met:
99fbe302bSMichael S. Tsirkin  * 1. Redistributions of source code must retain the above copyright
109fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer.
119fbe302bSMichael S. Tsirkin  * 2. Redistributions in binary form must reproduce the above copyright
129fbe302bSMichael S. Tsirkin  *    notice, this list of conditions and the following disclaimer in the
139fbe302bSMichael S. Tsirkin  *    documentation and/or other materials provided with the distribution.
149fbe302bSMichael S. Tsirkin  * 3. Neither the name of IBM nor the names of its contributors
159fbe302bSMichael S. Tsirkin  *    may be used to endorse or promote products derived from this software
169fbe302bSMichael S. Tsirkin  *    without specific prior written permission.
179fbe302bSMichael S. Tsirkin  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
189fbe302bSMichael S. Tsirkin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199fbe302bSMichael S. Tsirkin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209fbe302bSMichael S. Tsirkin  * ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
219fbe302bSMichael S. Tsirkin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229fbe302bSMichael S. Tsirkin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239fbe302bSMichael S. Tsirkin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249fbe302bSMichael S. Tsirkin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259fbe302bSMichael S. Tsirkin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269fbe302bSMichael S. Tsirkin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279fbe302bSMichael S. Tsirkin  * SUCH DAMAGE. */
289fbe302bSMichael S. Tsirkin #include "standard-headers/linux/types.h"
299fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_ids.h"
309fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_config.h"
319fbe302bSMichael S. Tsirkin #include "standard-headers/linux/virtio_types.h"
329fbe302bSMichael S. Tsirkin #include "standard-headers/linux/if_ether.h"
339fbe302bSMichael S. Tsirkin 
349fbe302bSMichael S. Tsirkin /* The feature bitmap for virtio net */
359fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CSUM	0	/* Host handles pkts w/ partial csum */
369fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_CSUM	1	/* Guest handles pkts w/ partial csum */
37f56fc2d3SMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */
38dbdfea92SCornelia Huck #define VIRTIO_NET_F_MTU	3	/* Initial MTU advice */
399fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_MAC	5	/* Host has given MAC address. */
409fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_TSO4	7	/* Guest can handle TSOv4 in. */
419fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_TSO6	8	/* Guest can handle TSOv6 in. */
429fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_ECN	9	/* Guest can handle TSO[6] w/ ECN in. */
439fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_UFO	10	/* Guest can handle UFO in. */
449fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_HOST_TSO4	11	/* Host can handle TSOv4 in. */
459fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_HOST_TSO6	12	/* Host can handle TSOv6 in. */
469fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_HOST_ECN	13	/* Host can handle TSO[6] w/ ECN in. */
479fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_HOST_UFO	14	/* Host can handle UFO in. */
489fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_MRG_RXBUF	15	/* Host can merge receive buffers. */
499fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_STATUS	16	/* virtio_net_config.status available */
509fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_VQ	17	/* Control channel available */
519fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_RX	18	/* Control channel RX mode support */
529fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_VLAN	19	/* Control channel VLAN filtering */
539fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_RX_EXTRA 20	/* Extra RX mode control support */
549fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GUEST_ANNOUNCE 21	/* Guest can announce device on the
559fbe302bSMichael S. Tsirkin 					 * network */
569fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_MQ	22	/* Device supports Receive Flow
579fbe302bSMichael S. Tsirkin 					 * Steering */
589fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_MAC_ADDR 23	/* Set MAC address */
59*c5614ee3SThomas Weißschuh #define VIRTIO_NET_F_DEVICE_STATS 50	/* Device can provide device-level statistics. */
60da3c22c7SThomas Huth #define VIRTIO_NET_F_VQ_NOTF_COAL 52	/* Device supports virtqueue notification coalescing */
61d525f73fSChenyi Qiang #define VIRTIO_NET_F_NOTF_COAL	53	/* Device supports notifications coalescing */
6293d7620cSAvihai Horon #define VIRTIO_NET_F_GUEST_USO4	54	/* Guest can handle USOv4 in. */
6393d7620cSAvihai Horon #define VIRTIO_NET_F_GUEST_USO6	55	/* Guest can handle USOv6 in. */
6493d7620cSAvihai Horon #define VIRTIO_NET_F_HOST_USO	56	/* Host can handle USO in. */
65dc6f8d45SCornelia Huck #define VIRTIO_NET_F_HASH_REPORT  57	/* Supports hash report */
66d0bf492fSCédric Le Goater #define VIRTIO_NET_F_GUEST_HDRLEN  59	/* Guest provides the exact hdr_len value. */
67dc6f8d45SCornelia Huck #define VIRTIO_NET_F_RSS	  60	/* Supports RSS RX steering */
68dc6f8d45SCornelia Huck #define VIRTIO_NET_F_RSC_EXT	  61	/* extended coalescing info */
6977d361b1SEric Auger #define VIRTIO_NET_F_STANDBY	  62	/* Act as standby for another device
7077d361b1SEric Auger 					 * with the same MAC.
7177d361b1SEric Auger 					 */
729f2d175dSPaolo Bonzini #define VIRTIO_NET_F_SPEED_DUPLEX 63	/* Device set linkspeed and duplex */
739f2d175dSPaolo Bonzini 
749fbe302bSMichael S. Tsirkin #ifndef VIRTIO_NET_NO_LEGACY
759fbe302bSMichael S. Tsirkin #define VIRTIO_NET_F_GSO	6	/* Host handles pkts w/ any GSO type */
769fbe302bSMichael S. Tsirkin #endif /* VIRTIO_NET_NO_LEGACY */
779fbe302bSMichael S. Tsirkin 
789fbe302bSMichael S. Tsirkin #define VIRTIO_NET_S_LINK_UP	1	/* Link is up */
799fbe302bSMichael S. Tsirkin #define VIRTIO_NET_S_ANNOUNCE	2	/* Announcement is needed */
809fbe302bSMichael S. Tsirkin 
81dc6f8d45SCornelia Huck /* supported/enabled hash types */
82dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_IPv4          (1 << 0)
83dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_TCPv4         (1 << 1)
84dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_UDPv4         (1 << 2)
85dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_IPv6          (1 << 3)
86dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_TCPv6         (1 << 4)
87dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_UDPv6         (1 << 5)
88dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_IP_EX         (1 << 6)
89dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX        (1 << 7)
90dc6f8d45SCornelia Huck #define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX        (1 << 8)
91dc6f8d45SCornelia Huck 
929fbe302bSMichael S. Tsirkin struct virtio_net_config {
939fbe302bSMichael S. Tsirkin 	/* The config defining mac address (if VIRTIO_NET_F_MAC) */
949fbe302bSMichael S. Tsirkin 	uint8_t mac[ETH_ALEN];
959fbe302bSMichael S. Tsirkin 	/* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
96e6546342SJason Wang 	__virtio16 status;
979fbe302bSMichael S. Tsirkin 	/* Maximum number of each of transmit and receive queues;
989fbe302bSMichael S. Tsirkin 	 * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ.
999fbe302bSMichael S. Tsirkin 	 * Legal values are between 1 and 0x8000
1009fbe302bSMichael S. Tsirkin 	 */
101e6546342SJason Wang 	__virtio16 max_virtqueue_pairs;
102dbdfea92SCornelia Huck 	/* Default maximum transmit unit advice */
103e6546342SJason Wang 	__virtio16 mtu;
1049f2d175dSPaolo Bonzini 	/*
1059f2d175dSPaolo Bonzini 	 * speed, in units of 1Mb. All values 0 to INT_MAX are legal.
1069f2d175dSPaolo Bonzini 	 * Any other value stands for unknown.
1079f2d175dSPaolo Bonzini 	 */
1089f2d175dSPaolo Bonzini 	uint32_t speed;
1099f2d175dSPaolo Bonzini 	/*
1109f2d175dSPaolo Bonzini 	 * 0x00 - half duplex
1119f2d175dSPaolo Bonzini 	 * 0x01 - full duplex
1129f2d175dSPaolo Bonzini 	 * Any other value stands for unknown.
1139f2d175dSPaolo Bonzini 	 */
1149f2d175dSPaolo Bonzini 	uint8_t duplex;
115dc6f8d45SCornelia Huck 	/* maximum size of RSS key */
116dc6f8d45SCornelia Huck 	uint8_t rss_max_key_size;
117dc6f8d45SCornelia Huck 	/* maximum number of indirection table entries */
118dc6f8d45SCornelia Huck 	uint16_t rss_max_indirection_table_length;
119dc6f8d45SCornelia Huck 	/* bitmask of supported VIRTIO_NET_RSS_HASH_ types */
120dc6f8d45SCornelia Huck 	uint32_t supported_hash_types;
1219fbe302bSMichael S. Tsirkin } QEMU_PACKED;
1229fbe302bSMichael S. Tsirkin 
1239fbe302bSMichael S. Tsirkin /*
1249fbe302bSMichael S. Tsirkin  * This header comes first in the scatter-gather list.  If you don't
1259fbe302bSMichael S. Tsirkin  * specify GSO or CSUM features, you can simply ignore the header.
1269fbe302bSMichael S. Tsirkin  *
12751628b18SChristian Borntraeger  * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf,
12851628b18SChristian Borntraeger  * only flattened.
1299fbe302bSMichael S. Tsirkin  */
1309fbe302bSMichael S. Tsirkin struct virtio_net_hdr_v1 {
1319fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_F_NEEDS_CSUM	1	/* Use csum_start, csum_offset */
1329fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_F_DATA_VALID	2	/* Csum is valid */
133dc6f8d45SCornelia Huck #define VIRTIO_NET_HDR_F_RSC_INFO	4	/* rsc info in csum_ fields */
1349fbe302bSMichael S. Tsirkin 	uint8_t flags;
1359fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_GSO_NONE		0	/* Not a GSO frame */
1369fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_GSO_TCPV4	1	/* GSO frame, IPv4 TCP (TSO) */
1379fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_GSO_UDP		3	/* GSO frame, IPv4 UDP (UFO) */
1389fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_GSO_TCPV6	4	/* GSO frame, IPv6 TCP */
13993d7620cSAvihai Horon #define VIRTIO_NET_HDR_GSO_UDP_L4	5	/* GSO frame, IPv4& IPv6 UDP (USO) */
1409fbe302bSMichael S. Tsirkin #define VIRTIO_NET_HDR_GSO_ECN		0x80	/* TCP has ECN set */
1419fbe302bSMichael S. Tsirkin 	uint8_t gso_type;
1429fbe302bSMichael S. Tsirkin 	__virtio16 hdr_len;	/* Ethernet + IP + tcp/udp hdrs */
1439fbe302bSMichael S. Tsirkin 	__virtio16 gso_size;	/* Bytes to append to hdr_len per frame */
144dc6f8d45SCornelia Huck 	union {
145dc6f8d45SCornelia Huck 		struct {
146dc6f8d45SCornelia Huck 			__virtio16 csum_start;
147dc6f8d45SCornelia Huck 			__virtio16 csum_offset;
148dc6f8d45SCornelia Huck 		};
149dc6f8d45SCornelia Huck 		/* Checksum calculation */
150dc6f8d45SCornelia Huck 		struct {
151dc6f8d45SCornelia Huck 			/* Position to start checksumming from */
152dc6f8d45SCornelia Huck 			__virtio16 start;
153dc6f8d45SCornelia Huck 			/* Offset after that to place checksum */
154dc6f8d45SCornelia Huck 			__virtio16 offset;
155dc6f8d45SCornelia Huck 		} csum;
156dc6f8d45SCornelia Huck 		/* Receive Segment Coalescing */
157dc6f8d45SCornelia Huck 		struct {
158dc6f8d45SCornelia Huck 			/* Number of coalesced segments */
159dc6f8d45SCornelia Huck 			uint16_t segments;
160dc6f8d45SCornelia Huck 			/* Number of duplicated acks */
161dc6f8d45SCornelia Huck 			uint16_t dup_acks;
162dc6f8d45SCornelia Huck 		} rsc;
163dc6f8d45SCornelia Huck 	};
1649fbe302bSMichael S. Tsirkin 	__virtio16 num_buffers;	/* Number of merged rx buffers */
1659fbe302bSMichael S. Tsirkin };
16651628b18SChristian Borntraeger 
167dc6f8d45SCornelia Huck struct virtio_net_hdr_v1_hash {
168dc6f8d45SCornelia Huck 	struct virtio_net_hdr_v1 hdr;
169dc6f8d45SCornelia Huck 	uint32_t hash_value;
170dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_NONE            0
171dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_IPv4            1
172dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_TCPv4           2
173dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_UDPv4           3
174dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_IPv6            4
175dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_TCPv6           5
176dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_UDPv6           6
177dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_IPv6_EX         7
178dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_TCPv6_EX        8
179dc6f8d45SCornelia Huck #define VIRTIO_NET_HASH_REPORT_UDPv6_EX        9
180dc6f8d45SCornelia Huck 	uint16_t hash_report;
181dc6f8d45SCornelia Huck 	uint16_t padding;
182dc6f8d45SCornelia Huck };
183dc6f8d45SCornelia Huck 
18451628b18SChristian Borntraeger #ifndef VIRTIO_NET_NO_LEGACY
18551628b18SChristian Borntraeger /* This header comes first in the scatter-gather list.
18651628b18SChristian Borntraeger  * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must
18751628b18SChristian Borntraeger  * be the first element of the scatter-gather list.  If you don't
18851628b18SChristian Borntraeger  * specify GSO or CSUM features, you can simply ignore the header. */
18951628b18SChristian Borntraeger struct virtio_net_hdr {
19051628b18SChristian Borntraeger 	/* See VIRTIO_NET_HDR_F_* */
19151628b18SChristian Borntraeger 	uint8_t flags;
19251628b18SChristian Borntraeger 	/* See VIRTIO_NET_HDR_GSO_* */
19351628b18SChristian Borntraeger 	uint8_t gso_type;
19451628b18SChristian Borntraeger 	__virtio16 hdr_len;		/* Ethernet + IP + tcp/udp hdrs */
19551628b18SChristian Borntraeger 	__virtio16 gso_size;		/* Bytes to append to hdr_len per frame */
19651628b18SChristian Borntraeger 	__virtio16 csum_start;	/* Position to start checksumming from */
19751628b18SChristian Borntraeger 	__virtio16 csum_offset;	/* Offset after that to place checksum */
19851628b18SChristian Borntraeger };
19951628b18SChristian Borntraeger 
20051628b18SChristian Borntraeger /* This is the version of the header to use when the MRG_RXBUF
20151628b18SChristian Borntraeger  * feature has been negotiated. */
20251628b18SChristian Borntraeger struct virtio_net_hdr_mrg_rxbuf {
20351628b18SChristian Borntraeger 	struct virtio_net_hdr hdr;
20451628b18SChristian Borntraeger 	__virtio16 num_buffers;	/* Number of merged rx buffers */
20551628b18SChristian Borntraeger };
2069fbe302bSMichael S. Tsirkin #endif /* ...VIRTIO_NET_NO_LEGACY */
2079fbe302bSMichael S. Tsirkin 
2089fbe302bSMichael S. Tsirkin /*
2099fbe302bSMichael S. Tsirkin  * Control virtqueue data structures
2109fbe302bSMichael S. Tsirkin  *
2119fbe302bSMichael S. Tsirkin  * The control virtqueue expects a header in the first sg entry
2129fbe302bSMichael S. Tsirkin  * and an ack/status response in the last entry.  Data for the
2139fbe302bSMichael S. Tsirkin  * command goes in between.
2149fbe302bSMichael S. Tsirkin  */
2159fbe302bSMichael S. Tsirkin struct virtio_net_ctrl_hdr {
2169fbe302bSMichael S. Tsirkin 	uint8_t class;
2179fbe302bSMichael S. Tsirkin 	uint8_t cmd;
2189fbe302bSMichael S. Tsirkin } QEMU_PACKED;
2199fbe302bSMichael S. Tsirkin 
2209fbe302bSMichael S. Tsirkin typedef uint8_t virtio_net_ctrl_ack;
2219fbe302bSMichael S. Tsirkin 
2229fbe302bSMichael S. Tsirkin #define VIRTIO_NET_OK     0
2239fbe302bSMichael S. Tsirkin #define VIRTIO_NET_ERR    1
2249fbe302bSMichael S. Tsirkin 
2259fbe302bSMichael S. Tsirkin /*
2269fbe302bSMichael S. Tsirkin  * Control the RX mode, ie. promisucous, allmulti, etc...
2279fbe302bSMichael S. Tsirkin  * All commands require an "out" sg entry containing a 1 byte
2289fbe302bSMichael S. Tsirkin  * state value, zero = disable, non-zero = enable.  Commands
2299fbe302bSMichael S. Tsirkin  * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
2309fbe302bSMichael S. Tsirkin  * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
2319fbe302bSMichael S. Tsirkin  */
2329fbe302bSMichael S. Tsirkin #define VIRTIO_NET_CTRL_RX    0
2339fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_PROMISC      0
2349fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_ALLMULTI     1
2359fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_ALLUNI       2
2369fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_NOMULTI      3
2379fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_NOUNI        4
2389fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_RX_NOBCAST      5
2399fbe302bSMichael S. Tsirkin 
2409fbe302bSMichael S. Tsirkin /*
2419fbe302bSMichael S. Tsirkin  * Control the MAC
2429fbe302bSMichael S. Tsirkin  *
2439fbe302bSMichael S. Tsirkin  * The MAC filter table is managed by the hypervisor, the guest should
2449fbe302bSMichael S. Tsirkin  * assume the size is infinite.  Filtering should be considered
2459fbe302bSMichael S. Tsirkin  * non-perfect, ie. based on hypervisor resources, the guest may
2469fbe302bSMichael S. Tsirkin  * received packets from sources not specified in the filter list.
2479fbe302bSMichael S. Tsirkin  *
2489fbe302bSMichael S. Tsirkin  * In addition to the class/cmd header, the TABLE_SET command requires
2499fbe302bSMichael S. Tsirkin  * two out scatterlists.  Each contains a 4 byte count of entries followed
2509fbe302bSMichael S. Tsirkin  * by a concatenated byte stream of the ETH_ALEN MAC addresses.  The
2519fbe302bSMichael S. Tsirkin  * first sg list contains unicast addresses, the second is for multicast.
2529fbe302bSMichael S. Tsirkin  * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
2539fbe302bSMichael S. Tsirkin  * is available.
2549fbe302bSMichael S. Tsirkin  *
2559fbe302bSMichael S. Tsirkin  * The ADDR_SET command requests one out scatterlist, it contains a
2569fbe302bSMichael S. Tsirkin  * 6 bytes MAC address. This functionality is present if the
2579fbe302bSMichael S. Tsirkin  * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
2589fbe302bSMichael S. Tsirkin  */
2599fbe302bSMichael S. Tsirkin struct virtio_net_ctrl_mac {
2609fbe302bSMichael S. Tsirkin 	__virtio32 entries;
2619fbe302bSMichael S. Tsirkin 	uint8_t macs[][ETH_ALEN];
2629fbe302bSMichael S. Tsirkin } QEMU_PACKED;
2639fbe302bSMichael S. Tsirkin 
2649fbe302bSMichael S. Tsirkin #define VIRTIO_NET_CTRL_MAC    1
2659fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_MAC_TABLE_SET        0
2669fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_MAC_ADDR_SET         1
2679fbe302bSMichael S. Tsirkin 
2689fbe302bSMichael S. Tsirkin /*
2699fbe302bSMichael S. Tsirkin  * Control VLAN filtering
2709fbe302bSMichael S. Tsirkin  *
2719fbe302bSMichael S. Tsirkin  * The VLAN filter table is controlled via a simple ADD/DEL interface.
2729fbe302bSMichael S. Tsirkin  * VLAN IDs not added may be filterd by the hypervisor.  Del is the
2739fbe302bSMichael S. Tsirkin  * opposite of add.  Both commands expect an out entry containing a 2
2749fbe302bSMichael S. Tsirkin  * byte VLAN ID.  VLAN filterting is available with the
2759fbe302bSMichael S. Tsirkin  * VIRTIO_NET_F_CTRL_VLAN feature bit.
2769fbe302bSMichael S. Tsirkin  */
2779fbe302bSMichael S. Tsirkin #define VIRTIO_NET_CTRL_VLAN       2
2789fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_VLAN_ADD             0
2799fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_VLAN_DEL             1
2809fbe302bSMichael S. Tsirkin 
2819fbe302bSMichael S. Tsirkin /*
2829fbe302bSMichael S. Tsirkin  * Control link announce acknowledgement
2839fbe302bSMichael S. Tsirkin  *
2849fbe302bSMichael S. Tsirkin  * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that
2859fbe302bSMichael S. Tsirkin  * driver has recevied the notification; device would clear the
2869fbe302bSMichael S. Tsirkin  * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives
2879fbe302bSMichael S. Tsirkin  * this command.
2889fbe302bSMichael S. Tsirkin  */
2899fbe302bSMichael S. Tsirkin #define VIRTIO_NET_CTRL_ANNOUNCE       3
2909fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_ANNOUNCE_ACK         0
2919fbe302bSMichael S. Tsirkin 
2929fbe302bSMichael S. Tsirkin /*
2939fbe302bSMichael S. Tsirkin  * Control Receive Flow Steering
294dc6f8d45SCornelia Huck  */
295dc6f8d45SCornelia Huck #define VIRTIO_NET_CTRL_MQ   4
296dc6f8d45SCornelia Huck /*
2979fbe302bSMichael S. Tsirkin  * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
2989fbe302bSMichael S. Tsirkin  * enables Receive Flow Steering, specifying the number of the transmit and
2999fbe302bSMichael S. Tsirkin  * receive queues that will be used. After the command is consumed and acked by
3009fbe302bSMichael S. Tsirkin  * the device, the device will not steer new packets on receive virtqueues
3019fbe302bSMichael S. Tsirkin  * other than specified nor read from transmit virtqueues other than specified.
3029fbe302bSMichael S. Tsirkin  * Accordingly, driver should not transmit new packets  on virtqueues other than
3039fbe302bSMichael S. Tsirkin  * specified.
3049fbe302bSMichael S. Tsirkin  */
3059fbe302bSMichael S. Tsirkin struct virtio_net_ctrl_mq {
3069fbe302bSMichael S. Tsirkin 	__virtio16 virtqueue_pairs;
3079fbe302bSMichael S. Tsirkin };
3089fbe302bSMichael S. Tsirkin 
3099fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET        0
3109fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN        1
3119fbe302bSMichael S. Tsirkin  #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX        0x8000
3129fbe302bSMichael S. Tsirkin 
313f56fc2d3SMichael S. Tsirkin /*
314dc6f8d45SCornelia Huck  * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as
315dc6f8d45SCornelia Huck  * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures
316dc6f8d45SCornelia Huck  * the receive steering to use a hash calculated for incoming packet
317dc6f8d45SCornelia Huck  * to decide on receive virtqueue to place the packet. The command
318dc6f8d45SCornelia Huck  * also provides parameters to calculate a hash and receive virtqueue.
319dc6f8d45SCornelia Huck  */
320dc6f8d45SCornelia Huck struct virtio_net_rss_config {
321dc6f8d45SCornelia Huck 	uint32_t hash_types;
322dc6f8d45SCornelia Huck 	uint16_t indirection_table_mask;
323dc6f8d45SCornelia Huck 	uint16_t unclassified_queue;
324dc6f8d45SCornelia Huck 	uint16_t indirection_table[1/* + indirection_table_mask */];
325dc6f8d45SCornelia Huck 	uint16_t max_tx_vq;
326dc6f8d45SCornelia Huck 	uint8_t hash_key_length;
327dc6f8d45SCornelia Huck 	uint8_t hash_key_data[/* hash_key_length */];
328dc6f8d45SCornelia Huck };
329dc6f8d45SCornelia Huck 
330dc6f8d45SCornelia Huck  #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG          1
331dc6f8d45SCornelia Huck 
332dc6f8d45SCornelia Huck /*
333dc6f8d45SCornelia Huck  * The command VIRTIO_NET_CTRL_MQ_HASH_CONFIG requests the device
334dc6f8d45SCornelia Huck  * to include in the virtio header of the packet the value of the
335dc6f8d45SCornelia Huck  * calculated hash and the report type of hash. It also provides
336dc6f8d45SCornelia Huck  * parameters for hash calculation. The command requires feature
337dc6f8d45SCornelia Huck  * VIRTIO_NET_F_HASH_REPORT to be negotiated to extend the
338dc6f8d45SCornelia Huck  * layout of virtio header as defined in virtio_net_hdr_v1_hash.
339dc6f8d45SCornelia Huck  */
340dc6f8d45SCornelia Huck struct virtio_net_hash_config {
341dc6f8d45SCornelia Huck 	uint32_t hash_types;
342dc6f8d45SCornelia Huck 	/* for compatibility with virtio_net_rss_config */
343dc6f8d45SCornelia Huck 	uint16_t reserved[4];
344dc6f8d45SCornelia Huck 	uint8_t hash_key_length;
345dc6f8d45SCornelia Huck 	uint8_t hash_key_data[/* hash_key_length */];
346dc6f8d45SCornelia Huck };
347dc6f8d45SCornelia Huck 
348dc6f8d45SCornelia Huck  #define VIRTIO_NET_CTRL_MQ_HASH_CONFIG         2
349dc6f8d45SCornelia Huck 
350dc6f8d45SCornelia Huck /*
351f56fc2d3SMichael S. Tsirkin  * Control network offloads
352f56fc2d3SMichael S. Tsirkin  *
353f56fc2d3SMichael S. Tsirkin  * Reconfigures the network offloads that Guest can handle.
354f56fc2d3SMichael S. Tsirkin  *
355f56fc2d3SMichael S. Tsirkin  * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
356f56fc2d3SMichael S. Tsirkin  *
357f56fc2d3SMichael S. Tsirkin  * Command data format matches the feature bit mask exactly.
358f56fc2d3SMichael S. Tsirkin  *
359f56fc2d3SMichael S. Tsirkin  * See VIRTIO_NET_F_GUEST_* for the list of offloads
360f56fc2d3SMichael S. Tsirkin  * that can be enabled/disabled.
361f56fc2d3SMichael S. Tsirkin  */
362f56fc2d3SMichael S. Tsirkin #define VIRTIO_NET_CTRL_GUEST_OFFLOADS   5
363f56fc2d3SMichael S. Tsirkin #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET        0
364f56fc2d3SMichael S. Tsirkin 
365d525f73fSChenyi Qiang /*
366d525f73fSChenyi Qiang  * Control notifications coalescing.
367d525f73fSChenyi Qiang  *
368d525f73fSChenyi Qiang  * Request the device to change the notifications coalescing parameters.
369d525f73fSChenyi Qiang  *
370d525f73fSChenyi Qiang  * Available with the VIRTIO_NET_F_NOTF_COAL feature bit.
371d525f73fSChenyi Qiang  */
372d525f73fSChenyi Qiang #define VIRTIO_NET_CTRL_NOTF_COAL		6
373d525f73fSChenyi Qiang /*
374d525f73fSChenyi Qiang  * Set the tx-usecs/tx-max-packets parameters.
375d525f73fSChenyi Qiang  */
376d525f73fSChenyi Qiang struct virtio_net_ctrl_coal_tx {
377d525f73fSChenyi Qiang 	/* Maximum number of packets to send before a TX notification */
378d525f73fSChenyi Qiang 	uint32_t tx_max_packets;
379d525f73fSChenyi Qiang 	/* Maximum number of usecs to delay a TX notification */
380d525f73fSChenyi Qiang 	uint32_t tx_usecs;
381d525f73fSChenyi Qiang };
382d525f73fSChenyi Qiang 
383d525f73fSChenyi Qiang #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET		0
384d525f73fSChenyi Qiang 
385d525f73fSChenyi Qiang /*
386d525f73fSChenyi Qiang  * Set the rx-usecs/rx-max-packets parameters.
387d525f73fSChenyi Qiang  */
388d525f73fSChenyi Qiang struct virtio_net_ctrl_coal_rx {
389d525f73fSChenyi Qiang 	/* Maximum number of packets to receive before a RX notification */
390d525f73fSChenyi Qiang 	uint32_t rx_max_packets;
391d525f73fSChenyi Qiang 	/* Maximum number of usecs to delay a RX notification */
392d525f73fSChenyi Qiang 	uint32_t rx_usecs;
393d525f73fSChenyi Qiang };
394d525f73fSChenyi Qiang 
395d525f73fSChenyi Qiang #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET		1
396da3c22c7SThomas Huth #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET		2
397da3c22c7SThomas Huth #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET		3
398da3c22c7SThomas Huth 
399da3c22c7SThomas Huth struct virtio_net_ctrl_coal {
400da3c22c7SThomas Huth 	uint32_t max_packets;
401da3c22c7SThomas Huth 	uint32_t max_usecs;
402da3c22c7SThomas Huth };
403da3c22c7SThomas Huth 
404da3c22c7SThomas Huth struct  virtio_net_ctrl_coal_vq {
405da3c22c7SThomas Huth 	uint16_t vqn;
406da3c22c7SThomas Huth 	uint16_t reserved;
407da3c22c7SThomas Huth 	struct virtio_net_ctrl_coal coal;
408da3c22c7SThomas Huth };
409d525f73fSChenyi Qiang 
410*c5614ee3SThomas Weißschuh /*
411*c5614ee3SThomas Weißschuh  * Device Statistics
412*c5614ee3SThomas Weißschuh  */
413*c5614ee3SThomas Weißschuh #define VIRTIO_NET_CTRL_STATS         8
414*c5614ee3SThomas Weißschuh #define VIRTIO_NET_CTRL_STATS_QUERY   0
415*c5614ee3SThomas Weißschuh #define VIRTIO_NET_CTRL_STATS_GET     1
416*c5614ee3SThomas Weißschuh 
417*c5614ee3SThomas Weißschuh struct virtio_net_stats_capabilities {
418*c5614ee3SThomas Weißschuh 
419*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_CVQ       (1ULL << 32)
420*c5614ee3SThomas Weißschuh 
421*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_RX_BASIC  (1ULL << 0)
422*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_RX_CSUM   (1ULL << 1)
423*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_RX_GSO    (1ULL << 2)
424*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_RX_SPEED  (1ULL << 3)
425*c5614ee3SThomas Weißschuh 
426*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_TX_BASIC  (1ULL << 16)
427*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_TX_CSUM   (1ULL << 17)
428*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_TX_GSO    (1ULL << 18)
429*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_TX_SPEED  (1ULL << 19)
430*c5614ee3SThomas Weißschuh 
431*c5614ee3SThomas Weißschuh 	uint64_t supported_stats_types[1];
432*c5614ee3SThomas Weißschuh };
433*c5614ee3SThomas Weißschuh 
434*c5614ee3SThomas Weißschuh struct virtio_net_ctrl_queue_stats {
435*c5614ee3SThomas Weißschuh 	struct {
436*c5614ee3SThomas Weißschuh 		uint16_t vq_index;
437*c5614ee3SThomas Weißschuh 		uint16_t reserved[3];
438*c5614ee3SThomas Weißschuh 		uint64_t types_bitmap[1];
439*c5614ee3SThomas Weißschuh 	} stats[1];
440*c5614ee3SThomas Weißschuh };
441*c5614ee3SThomas Weißschuh 
442*c5614ee3SThomas Weißschuh struct virtio_net_stats_reply_hdr {
443*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_CVQ       32
444*c5614ee3SThomas Weißschuh 
445*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC  0
446*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM   1
447*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO    2
448*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED  3
449*c5614ee3SThomas Weißschuh 
450*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC  16
451*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM   17
452*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO    18
453*c5614ee3SThomas Weißschuh #define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED  19
454*c5614ee3SThomas Weißschuh 	uint8_t type;
455*c5614ee3SThomas Weißschuh 	uint8_t reserved;
456*c5614ee3SThomas Weißschuh 	uint16_t vq_index;
457*c5614ee3SThomas Weißschuh 	uint16_t reserved1;
458*c5614ee3SThomas Weißschuh 	uint16_t size;
459*c5614ee3SThomas Weißschuh };
460*c5614ee3SThomas Weißschuh 
461*c5614ee3SThomas Weißschuh struct virtio_net_stats_cvq {
462*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
463*c5614ee3SThomas Weißschuh 
464*c5614ee3SThomas Weißschuh 	uint64_t command_num;
465*c5614ee3SThomas Weißschuh 	uint64_t ok_num;
466*c5614ee3SThomas Weißschuh };
467*c5614ee3SThomas Weißschuh 
468*c5614ee3SThomas Weißschuh struct virtio_net_stats_rx_basic {
469*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
470*c5614ee3SThomas Weißschuh 
471*c5614ee3SThomas Weißschuh 	uint64_t rx_notifications;
472*c5614ee3SThomas Weißschuh 
473*c5614ee3SThomas Weißschuh 	uint64_t rx_packets;
474*c5614ee3SThomas Weißschuh 	uint64_t rx_bytes;
475*c5614ee3SThomas Weißschuh 
476*c5614ee3SThomas Weißschuh 	uint64_t rx_interrupts;
477*c5614ee3SThomas Weißschuh 
478*c5614ee3SThomas Weißschuh 	uint64_t rx_drops;
479*c5614ee3SThomas Weißschuh 	uint64_t rx_drop_overruns;
480*c5614ee3SThomas Weißschuh };
481*c5614ee3SThomas Weißschuh 
482*c5614ee3SThomas Weißschuh struct virtio_net_stats_tx_basic {
483*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
484*c5614ee3SThomas Weißschuh 
485*c5614ee3SThomas Weißschuh 	uint64_t tx_notifications;
486*c5614ee3SThomas Weißschuh 
487*c5614ee3SThomas Weißschuh 	uint64_t tx_packets;
488*c5614ee3SThomas Weißschuh 	uint64_t tx_bytes;
489*c5614ee3SThomas Weißschuh 
490*c5614ee3SThomas Weißschuh 	uint64_t tx_interrupts;
491*c5614ee3SThomas Weißschuh 
492*c5614ee3SThomas Weißschuh 	uint64_t tx_drops;
493*c5614ee3SThomas Weißschuh 	uint64_t tx_drop_malformed;
494*c5614ee3SThomas Weißschuh };
495*c5614ee3SThomas Weißschuh 
496*c5614ee3SThomas Weißschuh struct virtio_net_stats_rx_csum {
497*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
498*c5614ee3SThomas Weißschuh 
499*c5614ee3SThomas Weißschuh 	uint64_t rx_csum_valid;
500*c5614ee3SThomas Weißschuh 	uint64_t rx_needs_csum;
501*c5614ee3SThomas Weißschuh 	uint64_t rx_csum_none;
502*c5614ee3SThomas Weißschuh 	uint64_t rx_csum_bad;
503*c5614ee3SThomas Weißschuh };
504*c5614ee3SThomas Weißschuh 
505*c5614ee3SThomas Weißschuh struct virtio_net_stats_tx_csum {
506*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
507*c5614ee3SThomas Weißschuh 
508*c5614ee3SThomas Weißschuh 	uint64_t tx_csum_none;
509*c5614ee3SThomas Weißschuh 	uint64_t tx_needs_csum;
510*c5614ee3SThomas Weißschuh };
511*c5614ee3SThomas Weißschuh 
512*c5614ee3SThomas Weißschuh struct virtio_net_stats_rx_gso {
513*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
514*c5614ee3SThomas Weißschuh 
515*c5614ee3SThomas Weißschuh 	uint64_t rx_gso_packets;
516*c5614ee3SThomas Weißschuh 	uint64_t rx_gso_bytes;
517*c5614ee3SThomas Weißschuh 	uint64_t rx_gso_packets_coalesced;
518*c5614ee3SThomas Weißschuh 	uint64_t rx_gso_bytes_coalesced;
519*c5614ee3SThomas Weißschuh };
520*c5614ee3SThomas Weißschuh 
521*c5614ee3SThomas Weißschuh struct virtio_net_stats_tx_gso {
522*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
523*c5614ee3SThomas Weißschuh 
524*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_packets;
525*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_bytes;
526*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_segments;
527*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_segments_bytes;
528*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_packets_noseg;
529*c5614ee3SThomas Weißschuh 	uint64_t tx_gso_bytes_noseg;
530*c5614ee3SThomas Weißschuh };
531*c5614ee3SThomas Weißschuh 
532*c5614ee3SThomas Weißschuh struct virtio_net_stats_rx_speed {
533*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
534*c5614ee3SThomas Weißschuh 
535*c5614ee3SThomas Weißschuh 	/* rx_{packets,bytes}_allowance_exceeded are too long. So rename to
536*c5614ee3SThomas Weißschuh 	 * short name.
537*c5614ee3SThomas Weißschuh 	 */
538*c5614ee3SThomas Weißschuh 	uint64_t rx_ratelimit_packets;
539*c5614ee3SThomas Weißschuh 	uint64_t rx_ratelimit_bytes;
540*c5614ee3SThomas Weißschuh };
541*c5614ee3SThomas Weißschuh 
542*c5614ee3SThomas Weißschuh struct virtio_net_stats_tx_speed {
543*c5614ee3SThomas Weißschuh 	struct virtio_net_stats_reply_hdr hdr;
544*c5614ee3SThomas Weißschuh 
545*c5614ee3SThomas Weißschuh 	/* tx_{packets,bytes}_allowance_exceeded are too long. So rename to
546*c5614ee3SThomas Weißschuh 	 * short name.
547*c5614ee3SThomas Weißschuh 	 */
548*c5614ee3SThomas Weißschuh 	uint64_t tx_ratelimit_packets;
549*c5614ee3SThomas Weißschuh 	uint64_t tx_ratelimit_bytes;
550*c5614ee3SThomas Weißschuh };
551*c5614ee3SThomas Weißschuh 
5529fbe302bSMichael S. Tsirkin #endif /* _LINUX_VIRTIO_NET_H */
553