1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _QEMU_VIRTIO_NET_H
15#define _QEMU_VIRTIO_NET_H
16
17#include "virtio.h"
18#include "net.h"
19#include "pci.h"
20
21#define ETH_ALEN 6
22
23
24
25
26#define VIRTIO_ID_NET 1
27
28
29#define VIRTIO_NET_F_CSUM 0
30#define VIRTIO_NET_F_GUEST_CSUM 1
31#define VIRTIO_NET_F_MAC 5
32#define VIRTIO_NET_F_GSO 6
33#define VIRTIO_NET_F_GUEST_TSO4 7
34#define VIRTIO_NET_F_GUEST_TSO6 8
35#define VIRTIO_NET_F_GUEST_ECN 9
36#define VIRTIO_NET_F_GUEST_UFO 10
37#define VIRTIO_NET_F_HOST_TSO4 11
38#define VIRTIO_NET_F_HOST_TSO6 12
39#define VIRTIO_NET_F_HOST_ECN 13
40#define VIRTIO_NET_F_HOST_UFO 14
41#define VIRTIO_NET_F_MRG_RXBUF 15
42#define VIRTIO_NET_F_STATUS 16
43#define VIRTIO_NET_F_CTRL_VQ 17
44#define VIRTIO_NET_F_CTRL_RX 18
45#define VIRTIO_NET_F_CTRL_VLAN 19
46#define VIRTIO_NET_F_CTRL_RX_EXTRA 20
47
48#define VIRTIO_NET_S_LINK_UP 1
49
50#define TX_TIMER_INTERVAL 150000
51
52
53
54
55
56
57#define TX_BURST 256
58
59typedef struct virtio_net_conf
60{
61 uint32_t txtimer;
62 int32_t txburst;
63 char *tx;
64} virtio_net_conf;
65
66
67#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
68
69struct virtio_net_config
70{
71
72 uint8_t mac[ETH_ALEN];
73
74 uint16_t status;
75} __attribute__((packed));
76
77
78
79struct virtio_net_hdr
80{
81#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1
82 uint8_t flags;
83#define VIRTIO_NET_HDR_GSO_NONE 0
84#define VIRTIO_NET_HDR_GSO_TCPV4 1
85#define VIRTIO_NET_HDR_GSO_UDP 3
86#define VIRTIO_NET_HDR_GSO_TCPV6 4
87#define VIRTIO_NET_HDR_GSO_ECN 0x80
88 uint8_t gso_type;
89 uint16_t hdr_len;
90 uint16_t gso_size;
91 uint16_t csum_start;
92 uint16_t csum_offset;
93};
94
95
96
97struct virtio_net_hdr_mrg_rxbuf
98{
99 struct virtio_net_hdr hdr;
100 uint16_t num_buffers;
101};
102
103
104
105
106
107
108
109
110struct virtio_net_ctrl_hdr {
111 uint8_t class;
112 uint8_t cmd;
113};
114
115typedef uint8_t virtio_net_ctrl_ack;
116
117#define VIRTIO_NET_OK 0
118#define VIRTIO_NET_ERR 1
119
120
121
122
123
124
125
126
127#define VIRTIO_NET_CTRL_RX_MODE 0
128 #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0
129 #define VIRTIO_NET_CTRL_RX_MODE_ALLMULTI 1
130 #define VIRTIO_NET_CTRL_RX_MODE_ALLUNI 2
131 #define VIRTIO_NET_CTRL_RX_MODE_NOMULTI 3
132 #define VIRTIO_NET_CTRL_RX_MODE_NOUNI 4
133 #define VIRTIO_NET_CTRL_RX_MODE_NOBCAST 5
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150struct virtio_net_ctrl_mac {
151 uint32_t entries;
152 uint8_t macs[][ETH_ALEN];
153};
154#define VIRTIO_NET_CTRL_MAC 1
155 #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
156
157
158
159
160
161
162
163
164
165
166#define VIRTIO_NET_CTRL_VLAN 2
167 #define VIRTIO_NET_CTRL_VLAN_ADD 0
168 #define VIRTIO_NET_CTRL_VLAN_DEL 1
169
170#define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \
171 DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
172 DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \
173 DEFINE_PROP_BIT("guest_csum", _state, _field, VIRTIO_NET_F_GUEST_CSUM, true), \
174 DEFINE_PROP_BIT("gso", _state, _field, VIRTIO_NET_F_GSO, true), \
175 DEFINE_PROP_BIT("guest_tso4", _state, _field, VIRTIO_NET_F_GUEST_TSO4, true), \
176 DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \
177 DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \
178 DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \
179 DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \
180 DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \
181 DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \
182 DEFINE_PROP_BIT("host_ufo", _state, _field, VIRTIO_NET_F_HOST_UFO, true), \
183 DEFINE_PROP_BIT("mrg_rxbuf", _state, _field, VIRTIO_NET_F_MRG_RXBUF, true), \
184 DEFINE_PROP_BIT("status", _state, _field, VIRTIO_NET_F_STATUS, true), \
185 DEFINE_PROP_BIT("ctrl_vq", _state, _field, VIRTIO_NET_F_CTRL_VQ, true), \
186 DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \
187 DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
188 DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true)
189#endif
190