1678ece30SMike Rapoport #ifndef _UAPI_LINUX_VIRTIO_NET_H 2678ece30SMike Rapoport #define _UAPI_LINUX_VIRTIO_NET_H 3607ca46eSDavid Howells /* This header is BSD licensed so anyone can use the definitions to implement 4607ca46eSDavid Howells * compatible drivers/servers. 5607ca46eSDavid Howells * 6607ca46eSDavid Howells * Redistribution and use in source and binary forms, with or without 7607ca46eSDavid Howells * modification, are permitted provided that the following conditions 8607ca46eSDavid Howells * are met: 9607ca46eSDavid Howells * 1. Redistributions of source code must retain the above copyright 10607ca46eSDavid Howells * notice, this list of conditions and the following disclaimer. 11607ca46eSDavid Howells * 2. Redistributions in binary form must reproduce the above copyright 12607ca46eSDavid Howells * notice, this list of conditions and the following disclaimer in the 13607ca46eSDavid Howells * documentation and/or other materials provided with the distribution. 14607ca46eSDavid Howells * 3. Neither the name of IBM nor the names of its contributors 15607ca46eSDavid Howells * may be used to endorse or promote products derived from this software 16607ca46eSDavid Howells * without specific prior written permission. 17607ca46eSDavid Howells * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18607ca46eSDavid Howells * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19607ca46eSDavid Howells * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20607ca46eSDavid Howells * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21607ca46eSDavid Howells * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22607ca46eSDavid Howells * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23607ca46eSDavid Howells * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24607ca46eSDavid Howells * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25607ca46eSDavid Howells * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26607ca46eSDavid Howells * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27607ca46eSDavid Howells * SUCH DAMAGE. */ 28607ca46eSDavid Howells #include <linux/types.h> 29607ca46eSDavid Howells #include <linux/virtio_ids.h> 30607ca46eSDavid Howells #include <linux/virtio_config.h> 31fdd819b2SMichael S. Tsirkin #include <linux/virtio_types.h> 32607ca46eSDavid Howells #include <linux/if_ether.h> 33607ca46eSDavid Howells 34607ca46eSDavid Howells /* The feature bitmap for virtio net */ 35607ca46eSDavid Howells #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ 36607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ 378b0a9d42SMichael S. Tsirkin #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */ 387d84e37eSAaron Conole #define VIRTIO_NET_F_MTU 3 /* Initial MTU advice */ 39607ca46eSDavid Howells #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ 40607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ 41607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ 42607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ 43607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ 44607ca46eSDavid Howells #define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ 45607ca46eSDavid Howells #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ 46607ca46eSDavid Howells #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ 47607ca46eSDavid Howells #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ 48607ca46eSDavid Howells #define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ 49607ca46eSDavid Howells #define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ 50607ca46eSDavid Howells #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ 51607ca46eSDavid Howells #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ 52607ca46eSDavid Howells #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ 53607ca46eSDavid Howells #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ 54607ca46eSDavid Howells #define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the 55607ca46eSDavid Howells * network */ 56986a4f4dSJason Wang #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow 57986a4f4dSJason Wang * Steering */ 587e58d5aeSAmos Kong #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ 5934cfe872SXuan Zhuo #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ 60394bd877SGavin Li #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ 61fce1c23fSAlvaro Karsz #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ 6234061b34SAndrew Melnychenko #define VIRTIO_NET_F_GUEST_USO4 54 /* Guest can handle USOv4 in. */ 6334061b34SAndrew Melnychenko #define VIRTIO_NET_F_GUEST_USO6 55 /* Guest can handle USOv6 in. */ 6434061b34SAndrew Melnychenko #define VIRTIO_NET_F_HOST_USO 56 /* Host can handle USO in. */ 653024e209SYuri Benditovich #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ 66be50da3eSJiri Pirko #define VIRTIO_NET_F_GUEST_HDRLEN 59 /* Guest provides the exact hdr_len value. */ 67fd58bf67SYuri Benditovich #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ 6822b436c9SYuri Benditovich #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ 699805069dSSridhar Samudrala #define VIRTIO_NET_F_STANDBY 62 /* Act as standby for another device 709805069dSSridhar Samudrala * with the same MAC. 719805069dSSridhar Samudrala */ 72faa9b39fSJason Baron #define VIRTIO_NET_F_SPEED_DUPLEX 63 /* Device set linkspeed and duplex */ 73faa9b39fSJason Baron 74ed9ecb04SRusty Russell #ifndef VIRTIO_NET_NO_LEGACY 75ed9ecb04SRusty Russell #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ 76ed9ecb04SRusty Russell #endif /* VIRTIO_NET_NO_LEGACY */ 77ed9ecb04SRusty Russell 78607ca46eSDavid Howells #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 79607ca46eSDavid Howells #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ 80607ca46eSDavid Howells 81fd58bf67SYuri Benditovich /* supported/enabled hash types */ 82fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_IPv4 (1 << 0) 83fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_TCPv4 (1 << 1) 84fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_UDPv4 (1 << 2) 85fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_IPv6 (1 << 3) 86fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_TCPv6 (1 << 4) 87fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_UDPv6 (1 << 5) 88fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_IP_EX (1 << 6) 89fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX (1 << 7) 90fd58bf67SYuri Benditovich #define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX (1 << 8) 91fd58bf67SYuri Benditovich 92607ca46eSDavid Howells struct virtio_net_config { 93607ca46eSDavid Howells /* The config defining mac address (if VIRTIO_NET_F_MAC) */ 94e216975aSJoe Perches __u8 mac[ETH_ALEN]; 95607ca46eSDavid Howells /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ 96577e677aSMichael S. Tsirkin __virtio16 status; 97986a4f4dSJason Wang /* Maximum number of each of transmit and receive queues; 98986a4f4dSJason Wang * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. 99986a4f4dSJason Wang * Legal values are between 1 and 0x8000 100986a4f4dSJason Wang */ 101577e677aSMichael S. Tsirkin __virtio16 max_virtqueue_pairs; 10214de9d11SAaron Conole /* Default maximum transmit unit advice */ 103577e677aSMichael S. Tsirkin __virtio16 mtu; 104faa9b39fSJason Baron /* 105faa9b39fSJason Baron * speed, in units of 1Mb. All values 0 to INT_MAX are legal. 106faa9b39fSJason Baron * Any other value stands for unknown. 107faa9b39fSJason Baron */ 10864ffa39dSMichael S. Tsirkin __le32 speed; 109faa9b39fSJason Baron /* 110faa9b39fSJason Baron * 0x00 - half duplex 111faa9b39fSJason Baron * 0x01 - full duplex 112faa9b39fSJason Baron * Any other value stands for unknown. 113faa9b39fSJason Baron */ 114faa9b39fSJason Baron __u8 duplex; 115fd58bf67SYuri Benditovich /* maximum size of RSS key */ 116fd58bf67SYuri Benditovich __u8 rss_max_key_size; 117fd58bf67SYuri Benditovich /* maximum number of indirection table entries */ 118fd58bf67SYuri Benditovich __le16 rss_max_indirection_table_length; 119fd58bf67SYuri Benditovich /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */ 120fd58bf67SYuri Benditovich __le32 supported_hash_types; 121607ca46eSDavid Howells } __attribute__((packed)); 122607ca46eSDavid Howells 123ed9ecb04SRusty Russell /* 124ed9ecb04SRusty Russell * This header comes first in the scatter-gather list. If you don't 125ed9ecb04SRusty Russell * specify GSO or CSUM features, you can simply ignore the header. 126ed9ecb04SRusty Russell * 127e68c48f9SRusty Russell * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf, 128e68c48f9SRusty Russell * only flattened. 129ed9ecb04SRusty Russell */ 130ed9ecb04SRusty Russell struct virtio_net_hdr_v1 { 131ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */ 132ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */ 13322b436c9SYuri Benditovich #define VIRTIO_NET_HDR_F_RSC_INFO 4 /* rsc info in csum_ fields */ 134ed9ecb04SRusty Russell __u8 flags; 135ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ 136ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ 137ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ 138ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ 13934061b34SAndrew Melnychenko #define VIRTIO_NET_HDR_GSO_UDP_L4 5 /* GSO frame, IPv4& IPv6 UDP (USO) */ 140ed9ecb04SRusty Russell #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ 141ed9ecb04SRusty Russell __u8 gso_type; 142ed9ecb04SRusty Russell __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 143ed9ecb04SRusty Russell __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 14422b436c9SYuri Benditovich union { 14522b436c9SYuri Benditovich struct { 14622b436c9SYuri Benditovich __virtio16 csum_start; 14722b436c9SYuri Benditovich __virtio16 csum_offset; 14822b436c9SYuri Benditovich }; 14922b436c9SYuri Benditovich /* Checksum calculation */ 15022b436c9SYuri Benditovich struct { 15122b436c9SYuri Benditovich /* Position to start checksumming from */ 15222b436c9SYuri Benditovich __virtio16 start; 15322b436c9SYuri Benditovich /* Offset after that to place checksum */ 15422b436c9SYuri Benditovich __virtio16 offset; 15522b436c9SYuri Benditovich } csum; 15622b436c9SYuri Benditovich /* Receive Segment Coalescing */ 15722b436c9SYuri Benditovich struct { 15822b436c9SYuri Benditovich /* Number of coalesced segments */ 15922b436c9SYuri Benditovich __le16 segments; 16022b436c9SYuri Benditovich /* Number of duplicated acks */ 16122b436c9SYuri Benditovich __le16 dup_acks; 16222b436c9SYuri Benditovich } rsc; 16322b436c9SYuri Benditovich }; 164ed9ecb04SRusty Russell __virtio16 num_buffers; /* Number of merged rx buffers */ 165ed9ecb04SRusty Russell }; 166e68c48f9SRusty Russell 1673024e209SYuri Benditovich struct virtio_net_hdr_v1_hash { 1683024e209SYuri Benditovich struct virtio_net_hdr_v1 hdr; 1693024e209SYuri Benditovich __le32 hash_value; 1703024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_NONE 0 1713024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_IPv4 1 1723024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_TCPv4 2 1733024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_UDPv4 3 1743024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_IPv6 4 1753024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_TCPv6 5 1763024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_UDPv6 6 1773024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_IPv6_EX 7 1783024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_TCPv6_EX 8 1793024e209SYuri Benditovich #define VIRTIO_NET_HASH_REPORT_UDPv6_EX 9 1803024e209SYuri Benditovich __le16 hash_report; 1813024e209SYuri Benditovich __le16 padding; 1823024e209SYuri Benditovich }; 1833024e209SYuri Benditovich 184e68c48f9SRusty Russell #ifndef VIRTIO_NET_NO_LEGACY 185e68c48f9SRusty Russell /* This header comes first in the scatter-gather list. 186e68c48f9SRusty Russell * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must 187e68c48f9SRusty Russell * be the first element of the scatter-gather list. If you don't 188e68c48f9SRusty Russell * specify GSO or CSUM features, you can simply ignore the header. */ 189e68c48f9SRusty Russell struct virtio_net_hdr { 190e68c48f9SRusty Russell /* See VIRTIO_NET_HDR_F_* */ 191e68c48f9SRusty Russell __u8 flags; 192e68c48f9SRusty Russell /* See VIRTIO_NET_HDR_GSO_* */ 193e68c48f9SRusty Russell __u8 gso_type; 194e68c48f9SRusty Russell __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 195e68c48f9SRusty Russell __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 196e68c48f9SRusty Russell __virtio16 csum_start; /* Position to start checksumming from */ 197e68c48f9SRusty Russell __virtio16 csum_offset; /* Offset after that to place checksum */ 198e68c48f9SRusty Russell }; 199e68c48f9SRusty Russell 200e68c48f9SRusty Russell /* This is the version of the header to use when the MRG_RXBUF 201e68c48f9SRusty Russell * feature has been negotiated. */ 202e68c48f9SRusty Russell struct virtio_net_hdr_mrg_rxbuf { 203e68c48f9SRusty Russell struct virtio_net_hdr hdr; 204e68c48f9SRusty Russell __virtio16 num_buffers; /* Number of merged rx buffers */ 205e68c48f9SRusty Russell }; 206ed9ecb04SRusty Russell #endif /* ...VIRTIO_NET_NO_LEGACY */ 207607ca46eSDavid Howells 208607ca46eSDavid Howells /* 209607ca46eSDavid Howells * Control virtqueue data structures 210607ca46eSDavid Howells * 211607ca46eSDavid Howells * The control virtqueue expects a header in the first sg entry 212607ca46eSDavid Howells * and an ack/status response in the last entry. Data for the 213607ca46eSDavid Howells * command goes in between. 214607ca46eSDavid Howells */ 215607ca46eSDavid Howells struct virtio_net_ctrl_hdr { 216607ca46eSDavid Howells __u8 class; 217607ca46eSDavid Howells __u8 cmd; 218607ca46eSDavid Howells } __attribute__((packed)); 219607ca46eSDavid Howells 220607ca46eSDavid Howells typedef __u8 virtio_net_ctrl_ack; 221607ca46eSDavid Howells 222607ca46eSDavid Howells #define VIRTIO_NET_OK 0 223607ca46eSDavid Howells #define VIRTIO_NET_ERR 1 224607ca46eSDavid Howells 225607ca46eSDavid Howells /* 226607ca46eSDavid Howells * Control the RX mode, ie. promisucous, allmulti, etc... 227607ca46eSDavid Howells * All commands require an "out" sg entry containing a 1 byte 228607ca46eSDavid Howells * state value, zero = disable, non-zero = enable. Commands 229607ca46eSDavid Howells * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 230607ca46eSDavid Howells * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 231607ca46eSDavid Howells */ 232607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX 0 233607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_PROMISC 0 234607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 235607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_ALLUNI 2 236607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_NOMULTI 3 237607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_NOUNI 4 238607ca46eSDavid Howells #define VIRTIO_NET_CTRL_RX_NOBCAST 5 239607ca46eSDavid Howells 240607ca46eSDavid Howells /* 2417e58d5aeSAmos Kong * Control the MAC 242607ca46eSDavid Howells * 243607ca46eSDavid Howells * The MAC filter table is managed by the hypervisor, the guest should 244607ca46eSDavid Howells * assume the size is infinite. Filtering should be considered 245607ca46eSDavid Howells * non-perfect, ie. based on hypervisor resources, the guest may 246607ca46eSDavid Howells * received packets from sources not specified in the filter list. 247607ca46eSDavid Howells * 248607ca46eSDavid Howells * In addition to the class/cmd header, the TABLE_SET command requires 249607ca46eSDavid Howells * two out scatterlists. Each contains a 4 byte count of entries followed 250607ca46eSDavid Howells * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 251607ca46eSDavid Howells * first sg list contains unicast addresses, the second is for multicast. 252607ca46eSDavid Howells * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 253607ca46eSDavid Howells * is available. 2547e58d5aeSAmos Kong * 2557e58d5aeSAmos Kong * The ADDR_SET command requests one out scatterlist, it contains a 2567e58d5aeSAmos Kong * 6 bytes MAC address. This functionality is present if the 2577e58d5aeSAmos Kong * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. 258607ca46eSDavid Howells */ 259607ca46eSDavid Howells struct virtio_net_ctrl_mac { 260fdd819b2SMichael S. Tsirkin __virtio32 entries; 261607ca46eSDavid Howells __u8 macs[][ETH_ALEN]; 262607ca46eSDavid Howells } __attribute__((packed)); 263607ca46eSDavid Howells 264607ca46eSDavid Howells #define VIRTIO_NET_CTRL_MAC 1 265607ca46eSDavid Howells #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 2667e58d5aeSAmos Kong #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 267607ca46eSDavid Howells 268607ca46eSDavid Howells /* 269607ca46eSDavid Howells * Control VLAN filtering 270607ca46eSDavid Howells * 271607ca46eSDavid Howells * The VLAN filter table is controlled via a simple ADD/DEL interface. 272607ca46eSDavid Howells * VLAN IDs not added may be filterd by the hypervisor. Del is the 273607ca46eSDavid Howells * opposite of add. Both commands expect an out entry containing a 2 274607ca46eSDavid Howells * byte VLAN ID. VLAN filterting is available with the 275607ca46eSDavid Howells * VIRTIO_NET_F_CTRL_VLAN feature bit. 276607ca46eSDavid Howells */ 277607ca46eSDavid Howells #define VIRTIO_NET_CTRL_VLAN 2 278607ca46eSDavid Howells #define VIRTIO_NET_CTRL_VLAN_ADD 0 279607ca46eSDavid Howells #define VIRTIO_NET_CTRL_VLAN_DEL 1 280607ca46eSDavid Howells 281607ca46eSDavid Howells /* 282607ca46eSDavid Howells * Control link announce acknowledgement 283607ca46eSDavid Howells * 284607ca46eSDavid Howells * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 285607ca46eSDavid Howells * driver has recevied the notification; device would clear the 286607ca46eSDavid Howells * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 287607ca46eSDavid Howells * this command. 288607ca46eSDavid Howells */ 289607ca46eSDavid Howells #define VIRTIO_NET_CTRL_ANNOUNCE 3 290607ca46eSDavid Howells #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 291607ca46eSDavid Howells 292986a4f4dSJason Wang /* 293986a4f4dSJason Wang * Control Receive Flow Steering 294fd58bf67SYuri Benditovich */ 295fd58bf67SYuri Benditovich #define VIRTIO_NET_CTRL_MQ 4 296fd58bf67SYuri Benditovich /* 297986a4f4dSJason Wang * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 298986a4f4dSJason Wang * enables Receive Flow Steering, specifying the number of the transmit and 299986a4f4dSJason Wang * receive queues that will be used. After the command is consumed and acked by 300986a4f4dSJason Wang * the device, the device will not steer new packets on receive virtqueues 301986a4f4dSJason Wang * other than specified nor read from transmit virtqueues other than specified. 302986a4f4dSJason Wang * Accordingly, driver should not transmit new packets on virtqueues other than 303986a4f4dSJason Wang * specified. 304986a4f4dSJason Wang */ 305986a4f4dSJason Wang struct virtio_net_ctrl_mq { 306fdd819b2SMichael S. Tsirkin __virtio16 virtqueue_pairs; 307986a4f4dSJason Wang }; 308986a4f4dSJason Wang 309986a4f4dSJason Wang #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 310986a4f4dSJason Wang #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 311986a4f4dSJason Wang #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 312986a4f4dSJason Wang 3138b0a9d42SMichael S. Tsirkin /* 314fd58bf67SYuri Benditovich * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as 315fd58bf67SYuri Benditovich * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures 316fd58bf67SYuri Benditovich * the receive steering to use a hash calculated for incoming packet 317fd58bf67SYuri Benditovich * to decide on receive virtqueue to place the packet. The command 318fd58bf67SYuri Benditovich * also provides parameters to calculate a hash and receive virtqueue. 319fd58bf67SYuri Benditovich */ 320fd58bf67SYuri Benditovich struct virtio_net_rss_config { 321fd58bf67SYuri Benditovich __le32 hash_types; 322fd58bf67SYuri Benditovich __le16 indirection_table_mask; 323fd58bf67SYuri Benditovich __le16 unclassified_queue; 324fd58bf67SYuri Benditovich __le16 indirection_table[1/* + indirection_table_mask */]; 325fd58bf67SYuri Benditovich __le16 max_tx_vq; 326fd58bf67SYuri Benditovich __u8 hash_key_length; 327fd58bf67SYuri Benditovich __u8 hash_key_data[/* hash_key_length */]; 328fd58bf67SYuri Benditovich }; 329fd58bf67SYuri Benditovich 330*976c2696SAkihiko Odaki struct virtio_net_rss_config_hdr { 331*976c2696SAkihiko Odaki __le32 hash_types; 332*976c2696SAkihiko Odaki __le16 indirection_table_mask; 333*976c2696SAkihiko Odaki __le16 unclassified_queue; 334*976c2696SAkihiko Odaki __le16 indirection_table[/* 1 + indirection_table_mask */]; 335*976c2696SAkihiko Odaki }; 336*976c2696SAkihiko Odaki 337*976c2696SAkihiko Odaki struct virtio_net_rss_config_trailer { 338*976c2696SAkihiko Odaki __le16 max_tx_vq; 339*976c2696SAkihiko Odaki __u8 hash_key_length; 340*976c2696SAkihiko Odaki __u8 hash_key_data[/* hash_key_length */]; 341*976c2696SAkihiko Odaki }; 342*976c2696SAkihiko Odaki 343fd58bf67SYuri Benditovich #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1 344fd58bf67SYuri Benditovich 345fd58bf67SYuri Benditovich /* 3463024e209SYuri Benditovich * The command VIRTIO_NET_CTRL_MQ_HASH_CONFIG requests the device 3473024e209SYuri Benditovich * to include in the virtio header of the packet the value of the 3483024e209SYuri Benditovich * calculated hash and the report type of hash. It also provides 3493024e209SYuri Benditovich * parameters for hash calculation. The command requires feature 3503024e209SYuri Benditovich * VIRTIO_NET_F_HASH_REPORT to be negotiated to extend the 3513024e209SYuri Benditovich * layout of virtio header as defined in virtio_net_hdr_v1_hash. 3523024e209SYuri Benditovich */ 3533024e209SYuri Benditovich struct virtio_net_hash_config { 3543024e209SYuri Benditovich __le32 hash_types; 3553024e209SYuri Benditovich /* for compatibility with virtio_net_rss_config */ 3563024e209SYuri Benditovich __le16 reserved[4]; 3573024e209SYuri Benditovich __u8 hash_key_length; 3583024e209SYuri Benditovich __u8 hash_key_data[/* hash_key_length */]; 3593024e209SYuri Benditovich }; 3603024e209SYuri Benditovich 3613024e209SYuri Benditovich #define VIRTIO_NET_CTRL_MQ_HASH_CONFIG 2 3623024e209SYuri Benditovich 3633024e209SYuri Benditovich /* 3648b0a9d42SMichael S. Tsirkin * Control network offloads 3658b0a9d42SMichael S. Tsirkin * 3668b0a9d42SMichael S. Tsirkin * Reconfigures the network offloads that Guest can handle. 3678b0a9d42SMichael S. Tsirkin * 3688b0a9d42SMichael S. Tsirkin * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit. 3698b0a9d42SMichael S. Tsirkin * 3708b0a9d42SMichael S. Tsirkin * Command data format matches the feature bit mask exactly. 3718b0a9d42SMichael S. Tsirkin * 3728b0a9d42SMichael S. Tsirkin * See VIRTIO_NET_F_GUEST_* for the list of offloads 3738b0a9d42SMichael S. Tsirkin * that can be enabled/disabled. 3748b0a9d42SMichael S. Tsirkin */ 3758b0a9d42SMichael S. Tsirkin #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5 3768b0a9d42SMichael S. Tsirkin #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0 3778b0a9d42SMichael S. Tsirkin 378699b045aSAlvaro Karsz /* 379699b045aSAlvaro Karsz * Control notifications coalescing. 380699b045aSAlvaro Karsz * 381699b045aSAlvaro Karsz * Request the device to change the notifications coalescing parameters. 382699b045aSAlvaro Karsz * 383699b045aSAlvaro Karsz * Available with the VIRTIO_NET_F_NOTF_COAL feature bit. 384699b045aSAlvaro Karsz */ 385699b045aSAlvaro Karsz #define VIRTIO_NET_CTRL_NOTF_COAL 6 386699b045aSAlvaro Karsz /* 387fce1c23fSAlvaro Karsz * Set the tx-usecs/tx-max-packets parameters. 388699b045aSAlvaro Karsz */ 389699b045aSAlvaro Karsz struct virtio_net_ctrl_coal_tx { 390fce1c23fSAlvaro Karsz /* Maximum number of packets to send before a TX notification */ 391699b045aSAlvaro Karsz __le32 tx_max_packets; 392fce1c23fSAlvaro Karsz /* Maximum number of usecs to delay a TX notification */ 393699b045aSAlvaro Karsz __le32 tx_usecs; 394699b045aSAlvaro Karsz }; 395699b045aSAlvaro Karsz 396699b045aSAlvaro Karsz #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET 0 397699b045aSAlvaro Karsz 398699b045aSAlvaro Karsz /* 399fce1c23fSAlvaro Karsz * Set the rx-usecs/rx-max-packets parameters. 400699b045aSAlvaro Karsz */ 401699b045aSAlvaro Karsz struct virtio_net_ctrl_coal_rx { 402fce1c23fSAlvaro Karsz /* Maximum number of packets to receive before a RX notification */ 403699b045aSAlvaro Karsz __le32 rx_max_packets; 404fce1c23fSAlvaro Karsz /* Maximum number of usecs to delay a RX notification */ 405699b045aSAlvaro Karsz __le32 rx_usecs; 406699b045aSAlvaro Karsz }; 407699b045aSAlvaro Karsz 408699b045aSAlvaro Karsz #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET 1 409394bd877SGavin Li #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET 2 410394bd877SGavin Li #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET 3 411394bd877SGavin Li 412394bd877SGavin Li struct virtio_net_ctrl_coal { 413394bd877SGavin Li __le32 max_packets; 414394bd877SGavin Li __le32 max_usecs; 415394bd877SGavin Li }; 416394bd877SGavin Li 417394bd877SGavin Li struct virtio_net_ctrl_coal_vq { 418394bd877SGavin Li __le16 vqn; 419394bd877SGavin Li __le16 reserved; 420394bd877SGavin Li struct virtio_net_ctrl_coal coal; 421394bd877SGavin Li }; 422699b045aSAlvaro Karsz 42334cfe872SXuan Zhuo /* 42434cfe872SXuan Zhuo * Device Statistics 42534cfe872SXuan Zhuo */ 42634cfe872SXuan Zhuo #define VIRTIO_NET_CTRL_STATS 8 42734cfe872SXuan Zhuo #define VIRTIO_NET_CTRL_STATS_QUERY 0 42834cfe872SXuan Zhuo #define VIRTIO_NET_CTRL_STATS_GET 1 42934cfe872SXuan Zhuo 43034cfe872SXuan Zhuo struct virtio_net_stats_capabilities { 43134cfe872SXuan Zhuo 43234cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_CVQ (1ULL << 32) 43334cfe872SXuan Zhuo 43434cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_RX_BASIC (1ULL << 0) 43534cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_RX_CSUM (1ULL << 1) 43634cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_RX_GSO (1ULL << 2) 43734cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_RX_SPEED (1ULL << 3) 43834cfe872SXuan Zhuo 43934cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_TX_BASIC (1ULL << 16) 44034cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_TX_CSUM (1ULL << 17) 44134cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_TX_GSO (1ULL << 18) 44234cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_TX_SPEED (1ULL << 19) 44334cfe872SXuan Zhuo 44434cfe872SXuan Zhuo __le64 supported_stats_types[1]; 44534cfe872SXuan Zhuo }; 44634cfe872SXuan Zhuo 44734cfe872SXuan Zhuo struct virtio_net_ctrl_queue_stats { 44834cfe872SXuan Zhuo struct { 44934cfe872SXuan Zhuo __le16 vq_index; 45034cfe872SXuan Zhuo __le16 reserved[3]; 45134cfe872SXuan Zhuo __le64 types_bitmap[1]; 45234cfe872SXuan Zhuo } stats[1]; 45334cfe872SXuan Zhuo }; 45434cfe872SXuan Zhuo 45534cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr { 45634cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_CVQ 32 45734cfe872SXuan Zhuo 45834cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC 0 45934cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM 1 46034cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO 2 46134cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED 3 46234cfe872SXuan Zhuo 46334cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC 16 46434cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM 17 46534cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO 18 46634cfe872SXuan Zhuo #define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED 19 46734cfe872SXuan Zhuo __u8 type; 46834cfe872SXuan Zhuo __u8 reserved; 46934cfe872SXuan Zhuo __le16 vq_index; 47034cfe872SXuan Zhuo __le16 reserved1; 47134cfe872SXuan Zhuo __le16 size; 47234cfe872SXuan Zhuo }; 47334cfe872SXuan Zhuo 47434cfe872SXuan Zhuo struct virtio_net_stats_cvq { 47534cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 47634cfe872SXuan Zhuo 47734cfe872SXuan Zhuo __le64 command_num; 47834cfe872SXuan Zhuo __le64 ok_num; 47934cfe872SXuan Zhuo }; 48034cfe872SXuan Zhuo 48134cfe872SXuan Zhuo struct virtio_net_stats_rx_basic { 48234cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 48334cfe872SXuan Zhuo 48434cfe872SXuan Zhuo __le64 rx_notifications; 48534cfe872SXuan Zhuo 48634cfe872SXuan Zhuo __le64 rx_packets; 48734cfe872SXuan Zhuo __le64 rx_bytes; 48834cfe872SXuan Zhuo 48934cfe872SXuan Zhuo __le64 rx_interrupts; 49034cfe872SXuan Zhuo 49134cfe872SXuan Zhuo __le64 rx_drops; 49234cfe872SXuan Zhuo __le64 rx_drop_overruns; 49334cfe872SXuan Zhuo }; 49434cfe872SXuan Zhuo 49534cfe872SXuan Zhuo struct virtio_net_stats_tx_basic { 49634cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 49734cfe872SXuan Zhuo 49834cfe872SXuan Zhuo __le64 tx_notifications; 49934cfe872SXuan Zhuo 50034cfe872SXuan Zhuo __le64 tx_packets; 50134cfe872SXuan Zhuo __le64 tx_bytes; 50234cfe872SXuan Zhuo 50334cfe872SXuan Zhuo __le64 tx_interrupts; 50434cfe872SXuan Zhuo 50534cfe872SXuan Zhuo __le64 tx_drops; 50634cfe872SXuan Zhuo __le64 tx_drop_malformed; 50734cfe872SXuan Zhuo }; 50834cfe872SXuan Zhuo 50934cfe872SXuan Zhuo struct virtio_net_stats_rx_csum { 51034cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 51134cfe872SXuan Zhuo 51234cfe872SXuan Zhuo __le64 rx_csum_valid; 51334cfe872SXuan Zhuo __le64 rx_needs_csum; 51434cfe872SXuan Zhuo __le64 rx_csum_none; 51534cfe872SXuan Zhuo __le64 rx_csum_bad; 51634cfe872SXuan Zhuo }; 51734cfe872SXuan Zhuo 51834cfe872SXuan Zhuo struct virtio_net_stats_tx_csum { 51934cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 52034cfe872SXuan Zhuo 52134cfe872SXuan Zhuo __le64 tx_csum_none; 52234cfe872SXuan Zhuo __le64 tx_needs_csum; 52334cfe872SXuan Zhuo }; 52434cfe872SXuan Zhuo 52534cfe872SXuan Zhuo struct virtio_net_stats_rx_gso { 52634cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 52734cfe872SXuan Zhuo 52834cfe872SXuan Zhuo __le64 rx_gso_packets; 52934cfe872SXuan Zhuo __le64 rx_gso_bytes; 53034cfe872SXuan Zhuo __le64 rx_gso_packets_coalesced; 53134cfe872SXuan Zhuo __le64 rx_gso_bytes_coalesced; 53234cfe872SXuan Zhuo }; 53334cfe872SXuan Zhuo 53434cfe872SXuan Zhuo struct virtio_net_stats_tx_gso { 53534cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 53634cfe872SXuan Zhuo 53734cfe872SXuan Zhuo __le64 tx_gso_packets; 53834cfe872SXuan Zhuo __le64 tx_gso_bytes; 53934cfe872SXuan Zhuo __le64 tx_gso_segments; 54034cfe872SXuan Zhuo __le64 tx_gso_segments_bytes; 54134cfe872SXuan Zhuo __le64 tx_gso_packets_noseg; 54234cfe872SXuan Zhuo __le64 tx_gso_bytes_noseg; 54334cfe872SXuan Zhuo }; 54434cfe872SXuan Zhuo 54534cfe872SXuan Zhuo struct virtio_net_stats_rx_speed { 54634cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 54734cfe872SXuan Zhuo 54834cfe872SXuan Zhuo /* rx_{packets,bytes}_allowance_exceeded are too long. So rename to 54934cfe872SXuan Zhuo * short name. 55034cfe872SXuan Zhuo */ 55134cfe872SXuan Zhuo __le64 rx_ratelimit_packets; 55234cfe872SXuan Zhuo __le64 rx_ratelimit_bytes; 55334cfe872SXuan Zhuo }; 55434cfe872SXuan Zhuo 55534cfe872SXuan Zhuo struct virtio_net_stats_tx_speed { 55634cfe872SXuan Zhuo struct virtio_net_stats_reply_hdr hdr; 55734cfe872SXuan Zhuo 55834cfe872SXuan Zhuo /* tx_{packets,bytes}_allowance_exceeded are too long. So rename to 55934cfe872SXuan Zhuo * short name. 56034cfe872SXuan Zhuo */ 56134cfe872SXuan Zhuo __le64 tx_ratelimit_packets; 56234cfe872SXuan Zhuo __le64 tx_ratelimit_bytes; 56334cfe872SXuan Zhuo }; 56434cfe872SXuan Zhuo 565678ece30SMike Rapoport #endif /* _UAPI_LINUX_VIRTIO_NET_H */ 566