-
Notifications
You must be signed in to change notification settings - Fork 5
/
virtio.h
87 lines (73 loc) · 1.81 KB
/
virtio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef _VIRTIO_H_
#define _VIRTIO_H_
#include "types.h"
/**
* This is the first element of the scatter-gather list. If you don't
* specify GSO or CSUM features, you can simply ignore the header.
*/
struct virtio_net_hdr {
#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /**< Use csum_start,csum_offset*/
uint8_t flags;
#define VIRTIO_NET_HDR_GSO_NONE 0 /**< Not a GSO frame */
#define VIRTIO_NET_HDR_GSO_TCPV4 1 /**< GSO frame, IPv4 TCP (TSO) */
#define VIRTIO_NET_HDR_GSO_UDP 3 /**< GSO frame, IPv4 UDP (UFO) */
#define VIRTIO_NET_HDR_GSO_TCPV6 4 /**< GSO frame, IPv6 TCP */
#define VIRTIO_NET_HDR_GSO_ECN 0x80 /**< TCP has ECN set */
uint8_t gso_type;
uint16_t hdr_len; /**< Ethernet + IP + tcp/udp hdrs */
uint16_t gso_size; /**< Bytes to append to hdr_len per frame */
uint16_t csum_start; /**< Position to start checksumming from */
uint16_t csum_offset; /**< Offset after that to place checksum */
};
#define MAX_QUEUE_SIZE (0xffff)
#define MAX_QUEUE_PAIR (1024)
#define VIRTIO_MAX_REGION (8)
#define VIRTIO_INVALID_EVENTFD (-1)
struct virtq_desc {
/* guest physical address */
u64 addr;
u32 len;
u16 flags;
u16 next;
};
struct virtq_avail {
u16 flags;
u16 idx;
u16 ring[0];
};
struct virtq_used_elem {
u32 id;
u32 len;
};
struct virtq_used {
u16 flags;
u16 idx;
struct virtq_used_elem ring[0];
};
struct virtqueue {
struct virtq_desc *desc;
struct virtq_avail *avail;
struct virtq_used *used;
u8 *log;
u64 logsz;
u32 num;
int kickfd;
int callfd;
u16 last_used_idx;
};
struct virtio_mem_region {
u64 guest_address;
u64 user_address;
u64 address_offset;
u64 size;
};
struct virtio_mem {
u32 nregions;
u32 padding;
struct virtio_mem_region regions[VIRTIO_MAX_REGION];
};
struct virtio_dev {
struct virtqueue vq[MAX_QUEUE_PAIR*2];
struct virtio_mem *mem;
};
#endif