1 /* 2 * This file contains common guest/host definition, related 3 * to VirtIO network adapter 4 * 5 * Copyright (c) 2008-2017 Red Hat, Inc. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met : 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and / or other materials provided with the distribution. 15 * 3. Neither the names of the copyright holders nor the names of their contributors 16 * may be used to endorse or promote products derived from this software 17 * without specific prior written permission. 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 #ifndef IONETDESCRIPTOR_H 31 #define IONETDESCRIPTOR_H 32 33 #pragma pack (push) 34 #pragma pack (1) 35 /* This is the first element of the scatter-gather list. If you don't 36 * specify GSO or CSUM features, you can simply ignore the header. */ 37 typedef struct _tagvirtio_net_hdr 38 { 39 #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset 40 #define VIRTIO_NET_HDR_F_DATA_VALID 2 // Host checked checksum, no need to recheck 41 u8 flags; 42 #define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame 43 #define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO) 44 #define VIRTIO_NET_HDR_GSO_UDP 3 // GSO frame, IPv4 UDP (UFO) 45 #define VIRTIO_NET_HDR_GSO_TCPV6 4 // GSO frame, IPv6 TCP 46 #define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set 47 u8 gso_type; 48 u16 hdr_len; // Ethernet + IP + tcp/udp hdrs 49 u16 gso_size; // Bytes to append to gso_hdr_len per frame 50 u16 csum_start; // Position to start checksumming from 51 u16 csum_offset; // Offset after that to place checksum 52 }virtio_net_hdr_basic; 53 54 typedef struct _tagvirtio_net_hdr_ext 55 { 56 virtio_net_hdr_basic BasicHeader; 57 u16 nBuffers; 58 }virtio_net_hdr_ext; 59 60 /* 61 * Control virtqueue data structures 62 * 63 * The control virtqueue expects a header in the first sg entry 64 * and an ack/status response in the last entry. Data for the 65 * command goes in between. 66 */ 67 typedef struct tag_virtio_net_ctrl_hdr { 68 u8 class_of_command; 69 u8 cmd; 70 }virtio_net_ctrl_hdr; 71 72 typedef u8 virtio_net_ctrl_ack; 73 74 #define VIRTIO_NET_OK 0 75 #define VIRTIO_NET_ERR 1 76 77 /* 78 * Control the RX mode, ie. promiscuous, allmulti, etc... 79 * All commands require an "out" sg entry containing a 1 byte 80 * state value, zero = disable, non-zero = enable. Commands 81 * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 82 * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 83 */ 84 #define VIRTIO_NET_CTRL_RX_MODE 0 85 #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0 86 #define VIRTIO_NET_CTRL_RX_MODE_ALLMULTI 1 87 #define VIRTIO_NET_CTRL_RX_MODE_ALLUNI 2 88 #define VIRTIO_NET_CTRL_RX_MODE_NOMULTI 3 89 #define VIRTIO_NET_CTRL_RX_MODE_NOUNI 4 90 #define VIRTIO_NET_CTRL_RX_MODE_NOBCAST 5 91 92 /* 93 * Control the MAC filter table. 94 * 95 * The MAC filter table is managed by the hypervisor, the guest should 96 * assume the size is infinite. Filtering should be considered 97 * non-perfect, ie. based on hypervisor resources, the guest may 98 * received packets from sources not specified in the filter list. 99 * 100 * In addition to the class/cmd header, the TABLE_SET command requires 101 * two out scatterlists. Each contains a 4 byte count of entries followed 102 * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 103 * first sg list contains unicast addresses, the second is for multicast. 104 * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 105 * is available. 106 */ 107 #define ETH_ALEN 6 108 109 struct virtio_net_ctrl_mac { 110 u32 entries; 111 // follows 112 //u8 macs[][ETH_ALEN]; 113 }; 114 #define VIRTIO_NET_CTRL_MAC 1 115 #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 116 117 /* 118 * Control VLAN filtering 119 * 120 * The VLAN filter table is controlled via a simple ADD/DEL interface. 121 * VLAN IDs not added may be filterd by the hypervisor. Del is the 122 * opposite of add. Both commands expect an out entry containing a 2 123 * byte VLAN ID. VLAN filtering is available with the 124 * VIRTIO_NET_F_CTRL_VLAN feature bit. 125 */ 126 #define VIRTIO_NET_CTRL_VLAN 2 127 #define VIRTIO_NET_CTRL_VLAN_ADD 0 128 #define VIRTIO_NET_CTRL_VLAN_DEL 1 129 130 131 #pragma pack (pop) 132 133 #endif 134