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} QEMU_PACKED;
76
77
78
79struct virtio_net_hdr
80{
81#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1
82#define VIRTIO_NET_HDR_F_DATA_VALID 2
83 uint8_t flags;
84#define VIRTIO_NET_HDR_GSO_NONE 0
85#define VIRTIO_NET_HDR_GSO_TCPV4 1
86#define VIRTIO_NET_HDR_GSO_UDP 3
87#define VIRTIO_NET_HDR_GSO_TCPV6 4
88#define VIRTIO_NET_HDR_GSO_ECN 0x80
89 uint8_t gso_type;
90 uint16_t hdr_len;
91 uint16_t gso_size;
92 uint16_t csum_start;
93 uint16_t csum_offset;
94};
95
96
97
98struct virtio_net_hdr_mrg_rxbuf
99{
100 struct virtio_net_hdr hdr;
101 uint16_t num_buffers;
102};
103
104
105
106
107
108
109
110
111struct virtio_net_ctrl_hdr {
112 uint8_t class;
113 uint8_t cmd;
114};
115
116typedef uint8_t virtio_net_ctrl_ack;
117
118#define VIRTIO_NET_OK 0
119#define VIRTIO_NET_ERR 1
120
121
122
123
124
125
126
127
128#define VIRTIO_NET_CTRL_RX_MODE 0
129 #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0
130 #define VIRTIO_NET_CTRL_RX_MODE_ALLMULTI 1
131 #define VIRTIO_NET_CTRL_RX_MODE_ALLUNI 2
132 #define VIRTIO_NET_CTRL_RX_MODE_NOMULTI 3
133 #define VIRTIO_NET_CTRL_RX_MODE_NOUNI 4
134 #define VIRTIO_NET_CTRL_RX_MODE_NOBCAST 5
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151struct virtio_net_ctrl_mac {
152 uint32_t entries;
153 uint8_t macs[][ETH_ALEN];
154};
155#define VIRTIO_NET_CTRL_MAC 1
156 #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0
157
158
159
160
161
162
163
164
165
166
167#define VIRTIO_NET_CTRL_VLAN 2
168 #define VIRTIO_NET_CTRL_VLAN_ADD 0
169 #define VIRTIO_NET_CTRL_VLAN_DEL 1
170
171#define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \
172 DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
173 DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \
174 DEFINE_PROP_BIT("guest_csum", _state, _field, VIRTIO_NET_F_GUEST_CSUM, true), \
175 DEFINE_PROP_BIT("gso", _state, _field, VIRTIO_NET_F_GSO, true), \
176 DEFINE_PROP_BIT("guest_tso4", _state, _field, VIRTIO_NET_F_GUEST_TSO4, true), \
177 DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \
178 DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \
179 DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \
180 DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \
181 DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \
182 DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \
183 DEFINE_PROP_BIT("host_ufo", _state, _field, VIRTIO_NET_F_HOST_UFO, true), \
184 DEFINE_PROP_BIT("mrg_rxbuf", _state, _field, VIRTIO_NET_F_MRG_RXBUF, true), \
185 DEFINE_PROP_BIT("status", _state, _field, VIRTIO_NET_F_STATUS, true), \
186 DEFINE_PROP_BIT("ctrl_vq", _state, _field, VIRTIO_NET_F_CTRL_VQ, true), \
187 DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \
188 DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
189 DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true)
190#endif
191