root / hw / virtio-net.h @ 9a6ee9fd
History | View | Annotate | Download (7.8 kB)
1 | fbe78f4f | aliguori | /*
|
---|---|---|---|
2 | fbe78f4f | aliguori | * Virtio Network Device
|
3 | fbe78f4f | aliguori | *
|
4 | fbe78f4f | aliguori | * Copyright IBM, Corp. 2007
|
5 | fbe78f4f | aliguori | *
|
6 | fbe78f4f | aliguori | * Authors:
|
7 | fbe78f4f | aliguori | * Anthony Liguori <aliguori@us.ibm.com>
|
8 | fbe78f4f | aliguori | *
|
9 | fbe78f4f | aliguori | * This work is licensed under the terms of the GNU GPL, version 2. See
|
10 | fbe78f4f | aliguori | * the COPYING file in the top-level directory.
|
11 | fbe78f4f | aliguori | *
|
12 | fbe78f4f | aliguori | */
|
13 | fbe78f4f | aliguori | |
14 | fbe78f4f | aliguori | #ifndef _QEMU_VIRTIO_NET_H
|
15 | fbe78f4f | aliguori | #define _QEMU_VIRTIO_NET_H
|
16 | fbe78f4f | aliguori | |
17 | fbe78f4f | aliguori | #include "virtio.h" |
18 | a2cb15b0 | Michael S. Tsirkin | #include "pci/pci.h" |
19 | fbe78f4f | aliguori | |
20 | 79674068 | aliguori | #define ETH_ALEN 6 |
21 | 79674068 | aliguori | |
22 | fbe78f4f | aliguori | /* from Linux's virtio_net.h */
|
23 | fbe78f4f | aliguori | |
24 | fbe78f4f | aliguori | /* The ID for virtio_net */
|
25 | fbe78f4f | aliguori | #define VIRTIO_ID_NET 1 |
26 | fbe78f4f | aliguori | |
27 | fbe78f4f | aliguori | /* The feature bitmap for virtio net */
|
28 | fbe78f4f | aliguori | #define VIRTIO_NET_F_CSUM 0 /* Host handles pkts w/ partial csum */ |
29 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GUEST_CSUM 1 /* Guest handles pkts w/ partial csum */ |
30 | fbe78f4f | aliguori | #define VIRTIO_NET_F_MAC 5 /* Host has given MAC address. */ |
31 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ |
32 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GUEST_TSO4 7 /* Guest can handle TSOv4 in. */ |
33 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GUEST_TSO6 8 /* Guest can handle TSOv6 in. */ |
34 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GUEST_ECN 9 /* Guest can handle TSO[6] w/ ECN in. */ |
35 | fbe78f4f | aliguori | #define VIRTIO_NET_F_GUEST_UFO 10 /* Guest can handle UFO in. */ |
36 | fbe78f4f | aliguori | #define VIRTIO_NET_F_HOST_TSO4 11 /* Host can handle TSOv4 in. */ |
37 | fbe78f4f | aliguori | #define VIRTIO_NET_F_HOST_TSO6 12 /* Host can handle TSOv6 in. */ |
38 | fbe78f4f | aliguori | #define VIRTIO_NET_F_HOST_ECN 13 /* Host can handle TSO[6] w/ ECN in. */ |
39 | fbe78f4f | aliguori | #define VIRTIO_NET_F_HOST_UFO 14 /* Host can handle UFO in. */ |
40 | fbe78f4f | aliguori | #define VIRTIO_NET_F_MRG_RXBUF 15 /* Host can merge receive buffers. */ |
41 | 554c97dd | aliguori | #define VIRTIO_NET_F_STATUS 16 /* virtio_net_config.status available */ |
42 | 3d11d36c | aliguori | #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ |
43 | 002437cd | aliguori | #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ |
44 | f21c0ed9 | aliguori | #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ |
45 | 015cb166 | Alex Williamson | #define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */ |
46 | fed699f9 | Jason Wang | #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow |
47 | fed699f9 | Jason Wang | * Steering */
|
48 | 554c97dd | aliguori | |
49 | c1943a3f | Amos Kong | #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ |
50 | c1943a3f | Amos Kong | |
51 | 554c97dd | aliguori | #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ |
52 | fbe78f4f | aliguori | |
53 | fbe78f4f | aliguori | #define TX_TIMER_INTERVAL 150000 /* 150 us */ |
54 | fbe78f4f | aliguori | |
55 | e3f30488 | Alex Williamson | /* Limit the number of packets that can be sent via a single flush
|
56 | e3f30488 | Alex Williamson | * of the TX queue. This gives us a guaranteed exit condition and
|
57 | e3f30488 | Alex Williamson | * ensures fairness in the io path. 256 conveniently matches the
|
58 | e3f30488 | Alex Williamson | * length of the TX queue and shows a good balance of performance
|
59 | e3f30488 | Alex Williamson | * and latency. */
|
60 | e3f30488 | Alex Williamson | #define TX_BURST 256 |
61 | e3f30488 | Alex Williamson | |
62 | f0c07c7c | Alex Williamson | typedef struct virtio_net_conf |
63 | f0c07c7c | Alex Williamson | { |
64 | f0c07c7c | Alex Williamson | uint32_t txtimer; |
65 | e3f30488 | Alex Williamson | int32_t txburst; |
66 | a697a334 | Alex Williamson | char *tx;
|
67 | f0c07c7c | Alex Williamson | } virtio_net_conf; |
68 | f0c07c7c | Alex Williamson | |
69 | fbe78f4f | aliguori | /* Maximum packet size we can receive from tap device: header + 64k */
|
70 | fbe78f4f | aliguori | #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10)) |
71 | fbe78f4f | aliguori | |
72 | fbe78f4f | aliguori | struct virtio_net_config
|
73 | fbe78f4f | aliguori | { |
74 | ebbeb789 | Amos Kong | /* The config defining mac address ($ETH_ALEN bytes) */
|
75 | ebbeb789 | Amos Kong | uint8_t mac[ETH_ALEN]; |
76 | 554c97dd | aliguori | /* See VIRTIO_NET_F_STATUS and VIRTIO_NET_S_* above */
|
77 | 554c97dd | aliguori | uint16_t status; |
78 | fed699f9 | Jason Wang | /* Max virtqueue pairs supported by the device */
|
79 | fed699f9 | Jason Wang | uint16_t max_virtqueue_pairs; |
80 | 541dc0d4 | Stefan Weil | } QEMU_PACKED; |
81 | fbe78f4f | aliguori | |
82 | 3d11d36c | aliguori | /*
|
83 | 3d11d36c | aliguori | * Control virtqueue data structures
|
84 | 3d11d36c | aliguori | *
|
85 | 3d11d36c | aliguori | * The control virtqueue expects a header in the first sg entry
|
86 | 3d11d36c | aliguori | * and an ack/status response in the last entry. Data for the
|
87 | 3d11d36c | aliguori | * command goes in between.
|
88 | 3d11d36c | aliguori | */
|
89 | 3d11d36c | aliguori | struct virtio_net_ctrl_hdr {
|
90 | 3d11d36c | aliguori | uint8_t class; |
91 | 3d11d36c | aliguori | uint8_t cmd; |
92 | 3d11d36c | aliguori | }; |
93 | 3d11d36c | aliguori | |
94 | 3d11d36c | aliguori | typedef uint8_t virtio_net_ctrl_ack;
|
95 | 3d11d36c | aliguori | |
96 | 3d11d36c | aliguori | #define VIRTIO_NET_OK 0 |
97 | 3d11d36c | aliguori | #define VIRTIO_NET_ERR 1 |
98 | 3d11d36c | aliguori | |
99 | 002437cd | aliguori | /*
|
100 | 015cb166 | Alex Williamson | * Control the RX mode, ie. promisucous, allmulti, etc...
|
101 | 015cb166 | Alex Williamson | * All commands require an "out" sg entry containing a 1 byte
|
102 | 015cb166 | Alex Williamson | * state value, zero = disable, non-zero = enable. Commands
|
103 | 015cb166 | Alex Williamson | * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
|
104 | 015cb166 | Alex Williamson | * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
|
105 | 002437cd | aliguori | */
|
106 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX 0 |
107 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_PROMISC 0 |
108 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_ALLMULTI 1 |
109 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_ALLUNI 2 |
110 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_NOMULTI 3 |
111 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_NOUNI 4 |
112 | dd23454b | Amos Kong | #define VIRTIO_NET_CTRL_RX_NOBCAST 5 |
113 | 002437cd | aliguori | |
114 | b6503ed9 | aliguori | /*
|
115 | c1943a3f | Amos Kong | * Control the MAC
|
116 | b6503ed9 | aliguori | *
|
117 | b6503ed9 | aliguori | * The MAC filter table is managed by the hypervisor, the guest should
|
118 | b6503ed9 | aliguori | * assume the size is infinite. Filtering should be considered
|
119 | b6503ed9 | aliguori | * non-perfect, ie. based on hypervisor resources, the guest may
|
120 | b6503ed9 | aliguori | * received packets from sources not specified in the filter list.
|
121 | b6503ed9 | aliguori | *
|
122 | b6503ed9 | aliguori | * In addition to the class/cmd header, the TABLE_SET command requires
|
123 | b6503ed9 | aliguori | * two out scatterlists. Each contains a 4 byte count of entries followed
|
124 | b6503ed9 | aliguori | * by a concatenated byte stream of the ETH_ALEN MAC addresses. The
|
125 | b6503ed9 | aliguori | * first sg list contains unicast addresses, the second is for multicast.
|
126 | b6503ed9 | aliguori | * This functionality is present if the VIRTIO_NET_F_CTRL_RX feature
|
127 | b6503ed9 | aliguori | * is available.
|
128 | c1943a3f | Amos Kong | *
|
129 | c1943a3f | Amos Kong | * The ADDR_SET command requests one out scatterlist, it contains a
|
130 | c1943a3f | Amos Kong | * 6 bytes MAC address. This functionality is present if the
|
131 | c1943a3f | Amos Kong | * VIRTIO_NET_F_CTRL_MAC_ADDR feature is available.
|
132 | b6503ed9 | aliguori | */
|
133 | b6503ed9 | aliguori | struct virtio_net_ctrl_mac {
|
134 | b6503ed9 | aliguori | uint32_t entries; |
135 | b6503ed9 | aliguori | uint8_t macs[][ETH_ALEN]; |
136 | b6503ed9 | aliguori | }; |
137 | b6503ed9 | aliguori | #define VIRTIO_NET_CTRL_MAC 1 |
138 | b6503ed9 | aliguori | #define VIRTIO_NET_CTRL_MAC_TABLE_SET 0 |
139 | c1943a3f | Amos Kong | #define VIRTIO_NET_CTRL_MAC_ADDR_SET 1 |
140 | b6503ed9 | aliguori | |
141 | f21c0ed9 | aliguori | /*
|
142 | f21c0ed9 | aliguori | * Control VLAN filtering
|
143 | f21c0ed9 | aliguori | *
|
144 | f21c0ed9 | aliguori | * The VLAN filter table is controlled via a simple ADD/DEL interface.
|
145 | f21c0ed9 | aliguori | * VLAN IDs not added may be filterd by the hypervisor. Del is the
|
146 | f21c0ed9 | aliguori | * opposite of add. Both commands expect an out entry containing a 2
|
147 | f21c0ed9 | aliguori | * byte VLAN ID. VLAN filterting is available with the
|
148 | f21c0ed9 | aliguori | * VIRTIO_NET_F_CTRL_VLAN feature bit.
|
149 | f21c0ed9 | aliguori | */
|
150 | f21c0ed9 | aliguori | #define VIRTIO_NET_CTRL_VLAN 2 |
151 | f21c0ed9 | aliguori | #define VIRTIO_NET_CTRL_VLAN_ADD 0 |
152 | f21c0ed9 | aliguori | #define VIRTIO_NET_CTRL_VLAN_DEL 1 |
153 | f21c0ed9 | aliguori | |
154 | fed699f9 | Jason Wang | /*
|
155 | fed699f9 | Jason Wang | * Control Multiqueue
|
156 | fed699f9 | Jason Wang | *
|
157 | fed699f9 | Jason Wang | * The command VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET
|
158 | fed699f9 | Jason Wang | * enables multiqueue, specifying the number of the transmit and
|
159 | fed699f9 | Jason Wang | * receive queues that will be used. After the command is consumed and acked by
|
160 | fed699f9 | Jason Wang | * the device, the device will not steer new packets on receive virtqueues
|
161 | fed699f9 | Jason Wang | * other than specified nor read from transmit virtqueues other than specified.
|
162 | fed699f9 | Jason Wang | * Accordingly, driver should not transmit new packets on virtqueues other than
|
163 | fed699f9 | Jason Wang | * specified.
|
164 | fed699f9 | Jason Wang | */
|
165 | fed699f9 | Jason Wang | struct virtio_net_ctrl_mq {
|
166 | fed699f9 | Jason Wang | uint16_t virtqueue_pairs; |
167 | fed699f9 | Jason Wang | }; |
168 | fed699f9 | Jason Wang | |
169 | fed699f9 | Jason Wang | #define VIRTIO_NET_CTRL_MQ 4 |
170 | fed699f9 | Jason Wang | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET 0 |
171 | fed699f9 | Jason Wang | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN 1 |
172 | fed699f9 | Jason Wang | #define VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX 0x8000 |
173 | fed699f9 | Jason Wang | |
174 | 8172539d | Michael S. Tsirkin | #define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \
|
175 | 8172539d | Michael S. Tsirkin | DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \ |
176 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \ |
177 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("guest_csum", _state, _field, VIRTIO_NET_F_GUEST_CSUM, true), \ |
178 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("gso", _state, _field, VIRTIO_NET_F_GSO, true), \ |
179 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("guest_tso4", _state, _field, VIRTIO_NET_F_GUEST_TSO4, true), \ |
180 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \ |
181 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \ |
182 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \ |
183 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \ |
184 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \ |
185 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \ |
186 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("host_ufo", _state, _field, VIRTIO_NET_F_HOST_UFO, true), \ |
187 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("mrg_rxbuf", _state, _field, VIRTIO_NET_F_MRG_RXBUF, true), \ |
188 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("status", _state, _field, VIRTIO_NET_F_STATUS, true), \ |
189 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("ctrl_vq", _state, _field, VIRTIO_NET_F_CTRL_VQ, true), \ |
190 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \ |
191 | 8172539d | Michael S. Tsirkin | DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \ |
192 | c1943a3f | Amos Kong | DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true), \ |
193 | fed699f9 | Jason Wang | DEFINE_PROP_BIT("ctrl_mac_addr", _state, _field, VIRTIO_NET_F_CTRL_MAC_ADDR, true), \ |
194 | 32ab06bc | Jesse Larrew | DEFINE_PROP_BIT("mq", _state, _field, VIRTIO_NET_F_MQ, false) |
195 | fed699f9 | Jason Wang | |
196 | fbe78f4f | aliguori | #endif |