1faa875a4SImre Vadasz /* 2faa875a4SImre Vadasz * This header is BSD licensed so anyone can use the definitions to implement 3faa875a4SImre Vadasz * compatible drivers/servers. 4faa875a4SImre Vadasz * 5faa875a4SImre Vadasz * $FreeBSD$ 6faa875a4SImre Vadasz */ 7faa875a4SImre Vadasz 8faa875a4SImre Vadasz #ifndef _VIRTIO_NET_H 9faa875a4SImre Vadasz #define _VIRTIO_NET_H 10faa875a4SImre Vadasz 11faa875a4SImre Vadasz #include <sys/types.h> 12faa875a4SImre Vadasz 13faa875a4SImre Vadasz /* The feature bitmap for virtio net */ 14faa875a4SImre Vadasz #define VIRTIO_NET_F_CSUM 0x00001 /* Host handles pkts w/ partial csum */ 15faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_CSUM 0x00002 /* Guest handles pkts w/ partial csum*/ 16*10039f4eSImre Vadász #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 0x00004 /* Guest can do dynamic 17*10039f4eSImre Vadász * offloads state configuration */ 18faa875a4SImre Vadasz #define VIRTIO_NET_F_MAC 0x00020 /* Host has given MAC address. */ 19faa875a4SImre Vadasz #define VIRTIO_NET_F_GSO 0x00040 /* Host handles pkts w/ any GSO type */ 20faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_TSO4 0x00080 /* Guest can handle TSOv4 in. */ 21faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_TSO6 0x00100 /* Guest can handle TSOv6 in. */ 22faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_ECN 0x00200 /* Guest can handle TSO[6] w/ ECN in.*/ 23faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_UFO 0x00400 /* Guest can handle UFO in. */ 24faa875a4SImre Vadasz #define VIRTIO_NET_F_HOST_TSO4 0x00800 /* Host can handle TSOv4 in. */ 25faa875a4SImre Vadasz #define VIRTIO_NET_F_HOST_TSO6 0x01000 /* Host can handle TSOv6 in. */ 26faa875a4SImre Vadasz #define VIRTIO_NET_F_HOST_ECN 0x02000 /* Host can handle TSO[6] w/ ECN in. */ 27faa875a4SImre Vadasz #define VIRTIO_NET_F_HOST_UFO 0x04000 /* Host can handle UFO in. */ 28faa875a4SImre Vadasz #define VIRTIO_NET_F_MRG_RXBUF 0x08000 /* Host can merge receive buffers. */ 29faa875a4SImre Vadasz #define VIRTIO_NET_F_STATUS 0x10000 /* virtio_net_config.status available*/ 30faa875a4SImre Vadasz #define VIRTIO_NET_F_CTRL_VQ 0x20000 /* Control channel available */ 31faa875a4SImre Vadasz #define VIRTIO_NET_F_CTRL_RX 0x40000 /* Control channel RX mode support */ 32faa875a4SImre Vadasz #define VIRTIO_NET_F_CTRL_VLAN 0x80000 /* Control channel VLAN filtering */ 33faa875a4SImre Vadasz #define VIRTIO_NET_F_CTRL_RX_EXTRA 0x100000 /* Extra RX mode control support */ 34faa875a4SImre Vadasz #define VIRTIO_NET_F_GUEST_ANNOUNCE 0x200000 /* Guest can announce device on the 35faa875a4SImre Vadasz * network */ 36faa875a4SImre Vadasz #define VIRTIO_NET_F_MQ 0x400000 /* Device supports Receive Flow 37faa875a4SImre Vadasz * Steering */ 3823ff515aSImre Vadász #define VIRTIO_NET_F_CTRL_MAC_ADDR 0x800000 /* Set MAC address */ 39faa875a4SImre Vadasz 40faa875a4SImre Vadasz #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 41faa875a4SImre Vadasz #define VIRTIO_NET_S_ANNOUNCE 2 /* Announcement is needed */ 42faa875a4SImre Vadasz 43faa875a4SImre Vadasz struct virtio_net_config { 44faa875a4SImre Vadasz /* The config defining mac address (if VIRTIO_NET_F_MAC) */ 45faa875a4SImre Vadasz uint8_t mac[ETHER_ADDR_LEN]; 46faa875a4SImre Vadasz /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */ 47faa875a4SImre Vadasz uint16_t status; 48faa875a4SImre Vadasz /* Maximum number of each of transmit and receive queues; 49faa875a4SImre Vadasz * see VIRTIO_NET_F_MQ and VIRTIO_NET_CTRL_MQ. 50faa875a4SImre Vadasz * Legal values are between 1 and 0x8000 51faa875a4SImre Vadasz */ 52faa875a4SImre Vadasz uint16_t max_virtqueue_pairs; 53faa875a4SImre Vadasz } __packed; 54faa875a4SImre Vadasz 55faa875a4SImre Vadasz /* 56faa875a4SImre Vadasz * This is the first element of the scatter-gather list. If you don't 57faa875a4SImre Vadasz * specify GSO or CSUM features, you can simply ignore the header. 58faa875a4SImre Vadasz */ 59faa875a4SImre Vadasz struct virtio_net_hdr { 60faa875a4SImre Vadasz #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start,csum_offset*/ 61faa875a4SImre Vadasz uint8_t flags; 62faa875a4SImre Vadasz #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ 63faa875a4SImre Vadasz #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ 64faa875a4SImre Vadasz #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ 65faa875a4SImre Vadasz #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ 66faa875a4SImre Vadasz #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ 67faa875a4SImre Vadasz uint8_t gso_type; 68faa875a4SImre Vadasz uint16_t hdr_len; /* Ethernet + IP + tcp/udp hdrs */ 69faa875a4SImre Vadasz uint16_t gso_size; /* Bytes to append to hdr_len per frame */ 70faa875a4SImre Vadasz uint16_t csum_start; /* Position to start checksumming from */ 71faa875a4SImre Vadasz uint16_t csum_offset; /* Offset after that to place checksum */ 72faa875a4SImre Vadasz }; 73faa875a4SImre Vadasz 74faa875a4SImre Vadasz /* 75faa875a4SImre Vadasz * This is the version of the header to use when the MRG_RXBUF 76faa875a4SImre Vadasz * feature has been negotiated. 77faa875a4SImre Vadasz */ 78faa875a4SImre Vadasz struct virtio_net_hdr_mrg_rxbuf { 79faa875a4SImre Vadasz struct virtio_net_hdr hdr; 80faa875a4SImre Vadasz uint16_t num_buffers; /* Number of merged rx buffers */ 81faa875a4SImre Vadasz }; 82faa875a4SImre Vadasz 83faa875a4SImre Vadasz /* 84faa875a4SImre Vadasz * Control virtqueue data structures 85faa875a4SImre Vadasz * 86faa875a4SImre Vadasz * The control virtqueue expects a header in the first sg entry 87faa875a4SImre Vadasz * and an ack/status response in the last entry. Data for the 88faa875a4SImre Vadasz * command goes in between. 89faa875a4SImre Vadasz */ 90faa875a4SImre Vadasz struct virtio_net_ctrl_hdr { 91faa875a4SImre Vadasz uint8_t class; 92faa875a4SImre Vadasz uint8_t cmd; 93faa875a4SImre Vadasz } __packed; 94faa875a4SImre Vadasz 95faa875a4SImre Vadasz typedef uint8_t virtio_net_ctrl_ack; 96faa875a4SImre Vadasz 97faa875a4SImre Vadasz #define VIRTIO_NET_OK 0 98faa875a4SImre Vadasz #define VIRTIO_NET_ERR 1 99faa875a4SImre Vadasz 100faa875a4SImre Vadasz /* 101faa875a4SImre Vadasz * Control the RX mode, ie. promiscuous, allmulti, etc... 102faa875a4SImre Vadasz * All commands require an "out" sg entry containing a 1 byte 103faa875a4SImre Vadasz * state value, zero = disable, non-zero = enable. Commands 104faa875a4SImre Vadasz * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature. 105faa875a4SImre Vadasz * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA. 106faa875a4SImre Vadasz */ 107faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX 0 108faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_PROMISC 0 109faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 110faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_ALLUNI 2 111faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_NOMULTI 3 112faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_NOUNI 4 113faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_RX_NOBCAST 5 114faa875a4SImre Vadasz 115faa875a4SImre Vadasz /* 116faa875a4SImre Vadasz * Control the MAC filter table. 117faa875a4SImre Vadasz * 118faa875a4SImre Vadasz * The MAC filter table is managed by the hypervisor, the guest should 119faa875a4SImre Vadasz * assume the size is infinite. Filtering should be considered 120faa875a4SImre Vadasz * non-perfect, ie. based on hypervisor resources, the guest may 121faa875a4SImre Vadasz * received packets from sources not specified in the filter list. 122faa875a4SImre Vadasz * 123faa875a4SImre Vadasz * In addition to the class/cmd header, the TABLE_SET command requires 124faa875a4SImre Vadasz * two out scatterlists. Each contains a 4 byte count of entries followed 125faa875a4SImre Vadasz * by a concatenated byte stream of the ETH_ALEN MAC addresses. The 126faa875a4SImre Vadasz * first sg list contains unicast addresses, the second is for multicast. 127faa875a4SImre Vadasz * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature 128faa875a4SImre Vadasz * is available. 129faa875a4SImre Vadasz */ 130faa875a4SImre Vadasz struct virtio_net_ctrl_mac { 131faa875a4SImre Vadasz uint32_t entries; 132faa875a4SImre Vadasz uint8_t macs[][ETHER_ADDR_LEN]; 133faa875a4SImre Vadasz } __packed; 134faa875a4SImre Vadasz 135faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MAC 1 136faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 13723ff515aSImre Vadász #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 138faa875a4SImre Vadasz 139faa875a4SImre Vadasz /* 140faa875a4SImre Vadasz * Control VLAN filtering 141faa875a4SImre Vadasz * 142faa875a4SImre Vadasz * The VLAN filter table is controlled via a simple ADD/DEL interface. 143faa875a4SImre Vadasz * VLAN IDs not added may be filtered by the hypervisor. Del is the 144faa875a4SImre Vadasz * opposite of add. Both commands expect an out entry containing a 2 145faa875a4SImre Vadasz * byte VLAN ID. VLAN filtering is available with the 146faa875a4SImre Vadasz * VIRTIO_NET_F_CTRL_VLAN feature bit. 147faa875a4SImre Vadasz */ 148faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_VLAN 2 149faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_VLAN_ADD 0 150faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_VLAN_DEL 1 151faa875a4SImre Vadasz 152faa875a4SImre Vadasz /* 153faa875a4SImre Vadasz * Control link announce acknowledgement 154faa875a4SImre Vadasz * 155faa875a4SImre Vadasz * The command VIRTIO_NET_CTRL_ANNOUNCE_ACK is used to indicate that 156faa875a4SImre Vadasz * driver has recevied the notification; device would clear the 157faa875a4SImre Vadasz * VIRTIO_NET_S_ANNOUNCE bit in the status field after it receives 158faa875a4SImre Vadasz * this command. 159faa875a4SImre Vadasz */ 160faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_ANNOUNCE 3 161faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_ANNOUNCE_ACK 0 162faa875a4SImre Vadasz 163faa875a4SImre Vadasz /* 164faa875a4SImre Vadasz * Control Receive Flow Steering 165faa875a4SImre Vadasz * 166faa875a4SImre Vadasz * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 167faa875a4SImre Vadasz * enables Receive Flow Steering, specifying the number of the transmit and 168faa875a4SImre Vadasz * receive queues that will be used. After the command is consumed and acked by 169faa875a4SImre Vadasz * the device, the device will not steer new packets on receive virtqueues 170faa875a4SImre Vadasz * other than specified nor read from transmit virtqueues other than specified. 171faa875a4SImre Vadasz * Accordingly, driver should not transmit new packets on virtqueues other than 172faa875a4SImre Vadasz * specified. 173faa875a4SImre Vadasz */ 174faa875a4SImre Vadasz struct virtio_net_ctrl_mq { 175faa875a4SImre Vadasz uint16_t virtqueue_pairs; 176faa875a4SImre Vadasz }; 177faa875a4SImre Vadasz 178faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MQ 4 179faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 180faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 181faa875a4SImre Vadasz #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 182faa875a4SImre Vadasz 183faa875a4SImre Vadasz #endif /* _VIRTIO_NET_H */ 184