1e5390783SAndre Przywara #ifndef _UAPI_LINUX_VIRTIO_NET_H 2e5390783SAndre Przywara #define _UAPI_LINUX_VIRTIO_NET_H 3a08bb43aSAndre Przywara /* This header is BSD licensed so anyone can use the definitions to implement 4a08bb43aSAndre Przywara * compatible drivers/servers. 5a08bb43aSAndre Przywara * 6a08bb43aSAndre Przywara * Redistribution and use in source and binary forms, with or without 7a08bb43aSAndre Przywara * modification, are permitted provided that the following conditions 8a08bb43aSAndre Przywara * are met: 9a08bb43aSAndre Przywara * 1. Redistributions of source code must retain the above copyright 10a08bb43aSAndre Przywara * notice, this list of conditions and the following disclaimer. 11a08bb43aSAndre Przywara * 2. Redistributions in binary form must reproduce the above copyright 12a08bb43aSAndre Przywara * notice, this list of conditions and the following disclaimer in the 13a08bb43aSAndre Przywara * documentation and/or other materials provided with the distribution. 14a08bb43aSAndre Przywara * 3. Neither the name of IBM nor the names of its contributors 15a08bb43aSAndre Przywara * may be used to endorse or promote products derived from this software 16a08bb43aSAndre Przywara * without specific prior written permission. 17a08bb43aSAndre Przywara * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 18a08bb43aSAndre Przywara * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19a08bb43aSAndre Przywara * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20a08bb43aSAndre Przywara * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE 21a08bb43aSAndre Przywara * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22a08bb43aSAndre Przywara * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23a08bb43aSAndre Przywara * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24a08bb43aSAndre Przywara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25a08bb43aSAndre Przywara * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26a08bb43aSAndre Przywara * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27a08bb43aSAndre Przywara * SUCH DAMAGE. */ 28a08bb43aSAndre Przywara #include <linux/types.h> 29a08bb43aSAndre Przywara #include <linux/virtio_ids.h> 30a08bb43aSAndre Przywara #include <linux/virtio_config.h> 31e5390783SAndre Przywara #include <linux/virtio_types.h> 32a08bb43aSAndre Przywara #include <linux/if_ether.h> 33a08bb43aSAndre Przywara 34a08bb43aSAndre Przywara /* The feature bitmap for virtio net */ 35a08bb43aSAndre Przywara #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ 36a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ 37e5390783SAndre Przywara #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Dynamic offload configuration. */ 38e5390783SAndre Przywara #define VIRTIO_NET_F_MTU 3 /* Initial MTU advice */ 39a08bb43aSAndre Przywara #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ 40a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ 41a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ 42a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ 43a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ 44a08bb43aSAndre Przywara #define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ 45a08bb43aSAndre Przywara #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ 46a08bb43aSAndre Przywara #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ 47a08bb43aSAndre Przywara #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ 48a08bb43aSAndre Przywara #define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ 49a08bb43aSAndre Przywara #define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ 50a08bb43aSAndre Przywara #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ 51a08bb43aSAndre Przywara #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ 52a08bb43aSAndre Przywara #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ 53a08bb43aSAndre Przywara #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ 54a08bb43aSAndre Przywara #define VIRTIO_NET_F_GUEST_ANNOUNCE 21 /* Guest can announce device on the 55a08bb43aSAndre Przywara * network */ 56a08bb43aSAndre Przywara #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow 57a08bb43aSAndre Przywara * Steering */ 58a08bb43aSAndre Przywara #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ 59*01171537SAnup Patel #define VIRTIO_NET_F_DEVICE_STATS 50 /* Device can provide device-level statistics. */ 6026c85896SAnup Patel #define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notification coalescing */ 6176dfc0cfSAnup Patel #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalescing */ 62be986824SAnup Patel #define VIRTIO_NET_F_GUEST_USO4 54 /* Guest can handle USOv4 in. */ 63be986824SAnup Patel #define VIRTIO_NET_F_GUEST_USO6 55 /* Guest can handle USOv6 in. */ 64be986824SAnup Patel #define VIRTIO_NET_F_HOST_USO 56 /* Host can handle USO in. */ 65e5390783SAndre Przywara #define VIRTIO_NET_F_HASH_REPORT 57 /* Supports hash report */ 66be986824SAnup Patel #define VIRTIO_NET_F_GUEST_HDRLEN 59 /* Guest provides the exact hdr_len value. */ 67e5390783SAndre Przywara #define VIRTIO_NET_F_RSS 60 /* Supports RSS RX steering */ 68e5390783SAndre Przywara #define VIRTIO_NET_F_RSC_EXT 61 /* extended coalescing info */ 69e5390783SAndre Przywara #define VIRTIO_NET_F_STANDBY 62 /* Act as standby for another device 70e5390783SAndre Przywara * with the same MAC. 71e5390783SAndre Przywara */ 72e5390783SAndre Przywara #define VIRTIO_NET_F_SPEED_DUPLEX 63 /* Device set linkspeed and duplex */ 73e5390783SAndre Przywara 74e5390783SAndre Przywara #ifndef VIRTIO_NET_NO_LEGACY 75e5390783SAndre Przywara #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ 76e5390783SAndre Przywara #endif /* VIRTIO_NET_NO_LEGACY */ 77e5390783SAndre Przywara 78a08bb43aSAndre Przywara #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 79a08bb43aSAndre Przywara #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ 80a08bb43aSAndre Przywara 81e5390783SAndre Przywara /* supported/enabled hash types */ 82e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_IPv4 (1 << 0) 83e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_TCPv4 (1 << 1) 84e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_UDPv4 (1 << 2) 85e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_IPv6 (1 << 3) 86e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_TCPv6 (1 << 4) 87e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_UDPv6 (1 << 5) 88e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_IP_EX (1 << 6) 89e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_TCP_EX (1 << 7) 90e5390783SAndre Przywara #define VIRTIO_NET_RSS_HASH_TYPE_UDP_EX (1 << 8) 91e5390783SAndre Przywara 92a08bb43aSAndre Przywara struct virtio_net_config { 93a08bb43aSAndre Przywara /* The config defining mac address (if VIRTIO_NET_F_MAC) */ 94a08bb43aSAndre Przywara __u8 mac[ETH_ALEN]; 95a08bb43aSAndre Przywara /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ 96e5390783SAndre Przywara __virtio16 status; 97a08bb43aSAndre Przywara /* Maximum number of each of transmit and receive queues; 98a08bb43aSAndre Przywara * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. 99a08bb43aSAndre Przywara * Legal values are between 1 and 0x8000 100a08bb43aSAndre Przywara */ 101e5390783SAndre Przywara __virtio16 max_virtqueue_pairs; 102e5390783SAndre Przywara /* Default maximum transmit unit advice */ 103e5390783SAndre Przywara __virtio16 mtu; 104e5390783SAndre Przywara /* 105e5390783SAndre Przywara * speed, in units of 1Mb. All values 0 to INT_MAX are legal. 106e5390783SAndre Przywara * Any other value stands for unknown. 107e5390783SAndre Przywara */ 108e5390783SAndre Przywara __le32 speed; 109e5390783SAndre Przywara /* 110e5390783SAndre Przywara * 0x00 - half duplex 111e5390783SAndre Przywara * 0x01 - full duplex 112e5390783SAndre Przywara * Any other value stands for unknown. 113e5390783SAndre Przywara */ 114e5390783SAndre Przywara __u8 duplex; 115e5390783SAndre Przywara /* maximum size of RSS key */ 116e5390783SAndre Przywara __u8 rss_max_key_size; 117e5390783SAndre Przywara /* maximum number of indirection table entries */ 118e5390783SAndre Przywara __le16 rss_max_indirection_table_length; 119e5390783SAndre Przywara /* bitmask of supported VIRTIO_NET_RSS_HASH_ types */ 120e5390783SAndre Przywara __le32 supported_hash_types; 121a08bb43aSAndre Przywara } __attribute__((packed)); 122a08bb43aSAndre Przywara 123e5390783SAndre Przywara /* 124e5390783SAndre Przywara * This header comes first in the scatter-gather list. If you don't 125e5390783SAndre Przywara * specify GSO or CSUM features, you can simply ignore the header. 126e5390783SAndre Przywara * 127e5390783SAndre Przywara * This is bitwise-equivalent to the legacy struct virtio_net_hdr_mrg_rxbuf, 128e5390783SAndre Przywara * only flattened. 129e5390783SAndre Przywara */ 130e5390783SAndre Przywara struct virtio_net_hdr_v1 { 131e5390783SAndre Przywara #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */ 132e5390783SAndre Przywara #define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */ 133e5390783SAndre Przywara #define VIRTIO_NET_HDR_F_RSC_INFO 4 /* rsc info in csum_ fields */ 134e5390783SAndre Przywara __u8 flags; 135e5390783SAndre Przywara #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ 136e5390783SAndre Przywara #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ 137e5390783SAndre Przywara #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ 138e5390783SAndre Przywara #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ 139be986824SAnup Patel #define VIRTIO_NET_HDR_GSO_UDP_L4 5 /* GSO frame, IPv4& IPv6 UDP (USO) */ 140e5390783SAndre Przywara #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ 141e5390783SAndre Przywara __u8 gso_type; 142e5390783SAndre Przywara __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 143e5390783SAndre Przywara __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 144e5390783SAndre Przywara union { 145e5390783SAndre Przywara struct { 146e5390783SAndre Przywara __virtio16 csum_start; 147e5390783SAndre Przywara __virtio16 csum_offset; 148e5390783SAndre Przywara }; 149e5390783SAndre Przywara /* Checksum calculation */ 150e5390783SAndre Przywara struct { 151e5390783SAndre Przywara /* Position to start checksumming from */ 152e5390783SAndre Przywara __virtio16 start; 153e5390783SAndre Przywara /* Offset after that to place checksum */ 154e5390783SAndre Przywara __virtio16 offset; 155e5390783SAndre Przywara } csum; 156e5390783SAndre Przywara /* Receive Segment Coalescing */ 157e5390783SAndre Przywara struct { 158e5390783SAndre Przywara /* Number of coalesced segments */ 159e5390783SAndre Przywara __le16 segments; 160e5390783SAndre Przywara /* Number of duplicated acks */ 161e5390783SAndre Przywara __le16 dup_acks; 162e5390783SAndre Przywara } rsc; 163e5390783SAndre Przywara }; 164e5390783SAndre Przywara __virtio16 num_buffers; /* Number of merged rx buffers */ 165e5390783SAndre Przywara }; 166e5390783SAndre Przywara 167e5390783SAndre Przywara struct virtio_net_hdr_v1_hash { 168e5390783SAndre Przywara struct virtio_net_hdr_v1 hdr; 169e5390783SAndre Przywara __le32 hash_value; 170e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_NONE 0 171e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_IPv4 1 172e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_TCPv4 2 173e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_UDPv4 3 174e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_IPv6 4 175e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_TCPv6 5 176e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_UDPv6 6 177e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_IPv6_EX 7 178e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_TCPv6_EX 8 179e5390783SAndre Przywara #define VIRTIO_NET_HASH_REPORT_UDPv6_EX 9 180e5390783SAndre Przywara __le16 hash_report; 181e5390783SAndre Przywara __le16 padding; 182e5390783SAndre Przywara }; 183e5390783SAndre Przywara 184e5390783SAndre Przywara #ifndef VIRTIO_NET_NO_LEGACY 185a08bb43aSAndre Przywara /* This header comes first in the scatter-gather list. 186e5390783SAndre Przywara * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must 187a08bb43aSAndre Przywara * be the first element of the scatter-gather list. If you don't 188a08bb43aSAndre Przywara * specify GSO or CSUM features, you can simply ignore the header. */ 189a08bb43aSAndre Przywara struct virtio_net_hdr { 190e5390783SAndre Przywara /* See VIRTIO_NET_HDR_F_* */ 191a08bb43aSAndre Przywara __u8 flags; 192e5390783SAndre Przywara /* See VIRTIO_NET_HDR_GSO_* */ 193a08bb43aSAndre Przywara __u8 gso_type; 194e5390783SAndre Przywara __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 195e5390783SAndre Przywara __virtio16 gso_size; /* Bytes to append to hdr_len per frame */ 196e5390783SAndre Przywara __virtio16 csum_start; /* Position to start checksumming from */ 197e5390783SAndre Przywara __virtio16 csum_offset; /* Offset after that to place checksum */ 198a08bb43aSAndre Przywara }; 199a08bb43aSAndre Przywara 200a08bb43aSAndre Przywara /* This is the version of the header to use when the MRG_RXBUF 201a08bb43aSAndre Przywara * feature has been negotiated. */ 202a08bb43aSAndre Przywara struct virtio_net_hdr_mrg_rxbuf { 203a08bb43aSAndre Przywara struct virtio_net_hdr hdr; 204e5390783SAndre Przywara __virtio16 num_buffers; /* Number of merged rx buffers */ 205a08bb43aSAndre Przywara }; 206e5390783SAndre Przywara #endif /* ...VIRTIO_NET_NO_LEGACY */ 207a08bb43aSAndre Przywara 208a08bb43aSAndre Przywara /* 209a08bb43aSAndre Przywara * Control virtqueue data structures 210a08bb43aSAndre Przywara * 211a08bb43aSAndre Przywara * The control virtqueue expects a header in the first sg entry 212a08bb43aSAndre Przywara * and an ack/status response in the last entry. Data for the 213a08bb43aSAndre Przywara * command goes in between. 214a08bb43aSAndre Przywara */ 215a08bb43aSAndre Przywara struct virtio_net_ctrl_hdr { 216a08bb43aSAndre Przywara __u8 class; 217a08bb43aSAndre Przywara __u8 cmd; 218a08bb43aSAndre Przywara } __attribute__((packed)); 219a08bb43aSAndre Przywara 220a08bb43aSAndre Przywara typedef __u8 virtio_net_ctrl_ack; 221a08bb43aSAndre Przywara 222a08bb43aSAndre Przywara #define VIRTIO_NET_OK 0 223a08bb43aSAndre Przywara #define VIRTIO_NET_ERR 1 224a08bb43aSAndre Przywara 225a08bb43aSAndre Przywara /* 226a08bb43aSAndre Przywara * Control the RX mode, ie. promisucous, allmulti, etc... 227a08bb43aSAndre Przywara * All commands require an "out" sg entry containing a 1 byte 228a08bb43aSAndre Przywara * state value, zero = disable, non-zero = enable. Commands 229a08bb43aSAndre Przywara * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 230a08bb43aSAndre Przywara * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 231a08bb43aSAndre Przywara */ 232a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX 0 233a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_PROMISC 0 234a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 235a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_ALLUNI 2 236a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_NOMULTI 3 237a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_NOUNI 4 238a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_RX_NOBCAST 5 239a08bb43aSAndre Przywara 240a08bb43aSAndre Przywara /* 241a08bb43aSAndre Przywara * Control the MAC 242a08bb43aSAndre Przywara * 243a08bb43aSAndre Przywara * The MAC filter table is managed by the hypervisor, the guest should 244a08bb43aSAndre Przywara * assume the size is infinite. Filtering should be considered 245a08bb43aSAndre Przywara * non-perfect, ie. based on hypervisor resources, the guest may 246a08bb43aSAndre Przywara * received packets from sources not specified in the filter list. 247a08bb43aSAndre Przywara * 248a08bb43aSAndre Przywara * In addition to the class/cmd header, the TABLE_SET command requires 249a08bb43aSAndre Przywara * two out scatterlists. Each contains a 4 byte count of entries followed 250a08bb43aSAndre Przywara * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 251a08bb43aSAndre Przywara * first sg list contains unicast addresses, the second is for multicast. 252a08bb43aSAndre Przywara * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 253a08bb43aSAndre Przywara * is available. 254a08bb43aSAndre Przywara * 255a08bb43aSAndre Przywara * The ADDR_SET command requests one out scatterlist, it contains a 256a08bb43aSAndre Przywara * 6 bytes MAC address. This functionality is present if the 257a08bb43aSAndre Przywara * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available. 258a08bb43aSAndre Przywara */ 259a08bb43aSAndre Przywara struct virtio_net_ctrl_mac { 260e5390783SAndre Przywara __virtio32 entries; 261a08bb43aSAndre Przywara __u8 macs[][ETH_ALEN]; 262a08bb43aSAndre Przywara } __attribute__((packed)); 263a08bb43aSAndre Przywara 264a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MAC 1 265a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 266a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 267a08bb43aSAndre Przywara 268a08bb43aSAndre Przywara /* 269a08bb43aSAndre Przywara * Control VLAN filtering 270a08bb43aSAndre Przywara * 271a08bb43aSAndre Przywara * The VLAN filter table is controlled via a simple ADD/DEL interface. 272a08bb43aSAndre Przywara * VLAN IDs not added may be filterd by the hypervisor. Del is the 273a08bb43aSAndre Przywara * opposite of add. Both commands expect an out entry containing a 2 274a08bb43aSAndre Przywara * byte VLAN ID. VLAN filterting is available with the 275a08bb43aSAndre Przywara * VIRTIO_NET_F_CTRL_VLAN feature bit. 276a08bb43aSAndre Przywara */ 277a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_VLAN 2 278a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_VLAN_ADD 0 279a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_VLAN_DEL 1 280a08bb43aSAndre Przywara 281a08bb43aSAndre Przywara /* 282a08bb43aSAndre Przywara * Control link announce acknowledgement 283a08bb43aSAndre Przywara * 284a08bb43aSAndre Przywara * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 285a08bb43aSAndre Przywara * driver has recevied the notification; device would clear the 286a08bb43aSAndre Przywara * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 287a08bb43aSAndre Przywara * this command. 288a08bb43aSAndre Przywara */ 289a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_ANNOUNCE 3 290a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 291a08bb43aSAndre Przywara 292a08bb43aSAndre Przywara /* 293a08bb43aSAndre Przywara * Control Receive Flow Steering 294e5390783SAndre Przywara */ 295e5390783SAndre Przywara #define VIRTIO_NET_CTRL_MQ 4 296e5390783SAndre Przywara /* 297a08bb43aSAndre Przywara * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 298a08bb43aSAndre Przywara * enables Receive Flow Steering, specifying the number of the transmit and 299a08bb43aSAndre Przywara * receive queues that will be used. After the command is consumed and acked by 300a08bb43aSAndre Przywara * the device, the device will not steer new packets on receive virtqueues 301a08bb43aSAndre Przywara * other than specified nor read from transmit virtqueues other than specified. 302a08bb43aSAndre Przywara * Accordingly, driver should not transmit new packets on virtqueues other than 303a08bb43aSAndre Przywara * specified. 304a08bb43aSAndre Przywara */ 305a08bb43aSAndre Przywara struct virtio_net_ctrl_mq { 306e5390783SAndre Przywara __virtio16 virtqueue_pairs; 307a08bb43aSAndre Przywara }; 308a08bb43aSAndre Przywara 309a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 310a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 311a08bb43aSAndre Przywara #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 312a08bb43aSAndre Przywara 313e5390783SAndre Przywara /* 314e5390783SAndre Przywara * The command VIRTIO_NET_CTRL_MQ_RSS_CONFIG has the same effect as 315e5390783SAndre Przywara * VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET does and additionally configures 316e5390783SAndre Przywara * the receive steering to use a hash calculated for incoming packet 317e5390783SAndre Przywara * to decide on receive virtqueue to place the packet. The command 318e5390783SAndre Przywara * also provides parameters to calculate a hash and receive virtqueue. 319e5390783SAndre Przywara */ 320e5390783SAndre Przywara struct virtio_net_rss_config { 321e5390783SAndre Przywara __le32 hash_types; 322e5390783SAndre Przywara __le16 indirection_table_mask; 323e5390783SAndre Przywara __le16 unclassified_queue; 324e5390783SAndre Przywara __le16 indirection_table[1/* + indirection_table_mask */]; 325e5390783SAndre Przywara __le16 max_tx_vq; 326e5390783SAndre Przywara __u8 hash_key_length; 327e5390783SAndre Przywara __u8 hash_key_data[/* hash_key_length */]; 328e5390783SAndre Przywara }; 329e5390783SAndre Przywara 330e5390783SAndre Przywara #define VIRTIO_NET_CTRL_MQ_RSS_CONFIG 1 331e5390783SAndre Przywara 332e5390783SAndre Przywara /* 333e5390783SAndre Przywara * The command VIRTIO_NET_CTRL_MQ_HASH_CONFIG requests the device 334e5390783SAndre Przywara * to include in the virtio header of the packet the value of the 335e5390783SAndre Przywara * calculated hash and the report type of hash. It also provides 336e5390783SAndre Przywara * parameters for hash calculation. The command requires feature 337e5390783SAndre Przywara * VIRTIO_NET_F_HASH_REPORT to be negotiated to extend the 338e5390783SAndre Przywara * layout of virtio header as defined in virtio_net_hdr_v1_hash. 339e5390783SAndre Przywara */ 340e5390783SAndre Przywara struct virtio_net_hash_config { 341e5390783SAndre Przywara __le32 hash_types; 342e5390783SAndre Przywara /* for compatibility with virtio_net_rss_config */ 343e5390783SAndre Przywara __le16 reserved[4]; 344e5390783SAndre Przywara __u8 hash_key_length; 345e5390783SAndre Przywara __u8 hash_key_data[/* hash_key_length */]; 346e5390783SAndre Przywara }; 347e5390783SAndre Przywara 348e5390783SAndre Przywara #define VIRTIO_NET_CTRL_MQ_HASH_CONFIG 2 349e5390783SAndre Przywara 350e5390783SAndre Przywara /* 351e5390783SAndre Przywara * Control network offloads 352e5390783SAndre Przywara * 353e5390783SAndre Przywara * Reconfigures the network offloads that Guest can handle. 354e5390783SAndre Przywara * 355e5390783SAndre Przywara * Available with the VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit. 356e5390783SAndre Przywara * 357e5390783SAndre Przywara * Command data format matches the feature bit mask exactly. 358e5390783SAndre Przywara * 359e5390783SAndre Przywara * See VIRTIO_NET_F_GUEST_* for the list of offloads 360e5390783SAndre Przywara * that can be enabled/disabled. 361e5390783SAndre Przywara */ 362e5390783SAndre Przywara #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5 363e5390783SAndre Przywara #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0 364e5390783SAndre Przywara 3658d0facecSAnup Patel /* 3668d0facecSAnup Patel * Control notifications coalescing. 3678d0facecSAnup Patel * 3688d0facecSAnup Patel * Request the device to change the notifications coalescing parameters. 3698d0facecSAnup Patel * 3708d0facecSAnup Patel * Available with the VIRTIO_NET_F_NOTF_COAL feature bit. 3718d0facecSAnup Patel */ 3728d0facecSAnup Patel #define VIRTIO_NET_CTRL_NOTF_COAL 6 3738d0facecSAnup Patel /* 37476dfc0cfSAnup Patel * Set the tx-usecs/tx-max-packets parameters. 3758d0facecSAnup Patel */ 3768d0facecSAnup Patel struct virtio_net_ctrl_coal_tx { 37776dfc0cfSAnup Patel /* Maximum number of packets to send before a TX notification */ 3788d0facecSAnup Patel __le32 tx_max_packets; 37976dfc0cfSAnup Patel /* Maximum number of usecs to delay a TX notification */ 3808d0facecSAnup Patel __le32 tx_usecs; 3818d0facecSAnup Patel }; 3828d0facecSAnup Patel 3838d0facecSAnup Patel #define VIRTIO_NET_CTRL_NOTF_COAL_TX_SET 0 3848d0facecSAnup Patel 3858d0facecSAnup Patel /* 38676dfc0cfSAnup Patel * Set the rx-usecs/rx-max-packets parameters. 3878d0facecSAnup Patel */ 3888d0facecSAnup Patel struct virtio_net_ctrl_coal_rx { 38976dfc0cfSAnup Patel /* Maximum number of packets to receive before a RX notification */ 3908d0facecSAnup Patel __le32 rx_max_packets; 39176dfc0cfSAnup Patel /* Maximum number of usecs to delay a RX notification */ 3928d0facecSAnup Patel __le32 rx_usecs; 3938d0facecSAnup Patel }; 3948d0facecSAnup Patel 3958d0facecSAnup Patel #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET 1 39626c85896SAnup Patel #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET 2 39726c85896SAnup Patel #define VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET 3 39826c85896SAnup Patel 39926c85896SAnup Patel struct virtio_net_ctrl_coal { 40026c85896SAnup Patel __le32 max_packets; 40126c85896SAnup Patel __le32 max_usecs; 40226c85896SAnup Patel }; 40326c85896SAnup Patel 40426c85896SAnup Patel struct virtio_net_ctrl_coal_vq { 40526c85896SAnup Patel __le16 vqn; 40626c85896SAnup Patel __le16 reserved; 40726c85896SAnup Patel struct virtio_net_ctrl_coal coal; 40826c85896SAnup Patel }; 4098d0facecSAnup Patel 410*01171537SAnup Patel /* 411*01171537SAnup Patel * Device Statistics 412*01171537SAnup Patel */ 413*01171537SAnup Patel #define VIRTIO_NET_CTRL_STATS 8 414*01171537SAnup Patel #define VIRTIO_NET_CTRL_STATS_QUERY 0 415*01171537SAnup Patel #define VIRTIO_NET_CTRL_STATS_GET 1 416*01171537SAnup Patel 417*01171537SAnup Patel struct virtio_net_stats_capabilities { 418*01171537SAnup Patel 419*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_CVQ (1ULL << 32) 420*01171537SAnup Patel 421*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_RX_BASIC (1ULL << 0) 422*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_RX_CSUM (1ULL << 1) 423*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_RX_GSO (1ULL << 2) 424*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_RX_SPEED (1ULL << 3) 425*01171537SAnup Patel 426*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_TX_BASIC (1ULL << 16) 427*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_TX_CSUM (1ULL << 17) 428*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_TX_GSO (1ULL << 18) 429*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_TX_SPEED (1ULL << 19) 430*01171537SAnup Patel 431*01171537SAnup Patel __le64 supported_stats_types[1]; 432*01171537SAnup Patel }; 433*01171537SAnup Patel 434*01171537SAnup Patel struct virtio_net_ctrl_queue_stats { 435*01171537SAnup Patel struct { 436*01171537SAnup Patel __le16 vq_index; 437*01171537SAnup Patel __le16 reserved[3]; 438*01171537SAnup Patel __le64 types_bitmap[1]; 439*01171537SAnup Patel } stats[1]; 440*01171537SAnup Patel }; 441*01171537SAnup Patel 442*01171537SAnup Patel struct virtio_net_stats_reply_hdr { 443*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_CVQ 32 444*01171537SAnup Patel 445*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_RX_BASIC 0 446*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_RX_CSUM 1 447*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_RX_GSO 2 448*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_RX_SPEED 3 449*01171537SAnup Patel 450*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_TX_BASIC 16 451*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_TX_CSUM 17 452*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_TX_GSO 18 453*01171537SAnup Patel #define VIRTIO_NET_STATS_TYPE_REPLY_TX_SPEED 19 454*01171537SAnup Patel __u8 type; 455*01171537SAnup Patel __u8 reserved; 456*01171537SAnup Patel __le16 vq_index; 457*01171537SAnup Patel __le16 reserved1; 458*01171537SAnup Patel __le16 size; 459*01171537SAnup Patel }; 460*01171537SAnup Patel 461*01171537SAnup Patel struct virtio_net_stats_cvq { 462*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 463*01171537SAnup Patel 464*01171537SAnup Patel __le64 command_num; 465*01171537SAnup Patel __le64 ok_num; 466*01171537SAnup Patel }; 467*01171537SAnup Patel 468*01171537SAnup Patel struct virtio_net_stats_rx_basic { 469*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 470*01171537SAnup Patel 471*01171537SAnup Patel __le64 rx_notifications; 472*01171537SAnup Patel 473*01171537SAnup Patel __le64 rx_packets; 474*01171537SAnup Patel __le64 rx_bytes; 475*01171537SAnup Patel 476*01171537SAnup Patel __le64 rx_interrupts; 477*01171537SAnup Patel 478*01171537SAnup Patel __le64 rx_drops; 479*01171537SAnup Patel __le64 rx_drop_overruns; 480*01171537SAnup Patel }; 481*01171537SAnup Patel 482*01171537SAnup Patel struct virtio_net_stats_tx_basic { 483*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 484*01171537SAnup Patel 485*01171537SAnup Patel __le64 tx_notifications; 486*01171537SAnup Patel 487*01171537SAnup Patel __le64 tx_packets; 488*01171537SAnup Patel __le64 tx_bytes; 489*01171537SAnup Patel 490*01171537SAnup Patel __le64 tx_interrupts; 491*01171537SAnup Patel 492*01171537SAnup Patel __le64 tx_drops; 493*01171537SAnup Patel __le64 tx_drop_malformed; 494*01171537SAnup Patel }; 495*01171537SAnup Patel 496*01171537SAnup Patel struct virtio_net_stats_rx_csum { 497*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 498*01171537SAnup Patel 499*01171537SAnup Patel __le64 rx_csum_valid; 500*01171537SAnup Patel __le64 rx_needs_csum; 501*01171537SAnup Patel __le64 rx_csum_none; 502*01171537SAnup Patel __le64 rx_csum_bad; 503*01171537SAnup Patel }; 504*01171537SAnup Patel 505*01171537SAnup Patel struct virtio_net_stats_tx_csum { 506*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 507*01171537SAnup Patel 508*01171537SAnup Patel __le64 tx_csum_none; 509*01171537SAnup Patel __le64 tx_needs_csum; 510*01171537SAnup Patel }; 511*01171537SAnup Patel 512*01171537SAnup Patel struct virtio_net_stats_rx_gso { 513*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 514*01171537SAnup Patel 515*01171537SAnup Patel __le64 rx_gso_packets; 516*01171537SAnup Patel __le64 rx_gso_bytes; 517*01171537SAnup Patel __le64 rx_gso_packets_coalesced; 518*01171537SAnup Patel __le64 rx_gso_bytes_coalesced; 519*01171537SAnup Patel }; 520*01171537SAnup Patel 521*01171537SAnup Patel struct virtio_net_stats_tx_gso { 522*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 523*01171537SAnup Patel 524*01171537SAnup Patel __le64 tx_gso_packets; 525*01171537SAnup Patel __le64 tx_gso_bytes; 526*01171537SAnup Patel __le64 tx_gso_segments; 527*01171537SAnup Patel __le64 tx_gso_segments_bytes; 528*01171537SAnup Patel __le64 tx_gso_packets_noseg; 529*01171537SAnup Patel __le64 tx_gso_bytes_noseg; 530*01171537SAnup Patel }; 531*01171537SAnup Patel 532*01171537SAnup Patel struct virtio_net_stats_rx_speed { 533*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 534*01171537SAnup Patel 535*01171537SAnup Patel /* rx_{packets,bytes}_allowance_exceeded are too long. So rename to 536*01171537SAnup Patel * short name. 537*01171537SAnup Patel */ 538*01171537SAnup Patel __le64 rx_ratelimit_packets; 539*01171537SAnup Patel __le64 rx_ratelimit_bytes; 540*01171537SAnup Patel }; 541*01171537SAnup Patel 542*01171537SAnup Patel struct virtio_net_stats_tx_speed { 543*01171537SAnup Patel struct virtio_net_stats_reply_hdr hdr; 544*01171537SAnup Patel 545*01171537SAnup Patel /* tx_{packets,bytes}_allowance_exceeded are too long. So rename to 546*01171537SAnup Patel * short name. 547*01171537SAnup Patel */ 548*01171537SAnup Patel __le64 tx_ratelimit_packets; 549*01171537SAnup Patel __le64 tx_ratelimit_bytes; 550*01171537SAnup Patel }; 551*01171537SAnup Patel 552e5390783SAndre Przywara #endif /* _UAPI_LINUX_VIRTIO_NET_H */ 553