]> git.ipfire.org Git - thirdparty/qemu.git/blame - include/hw/virtio/virtio-net.h
Use OBJECT_DECLARE_SIMPLE_TYPE when possible
[thirdparty/qemu.git] / include / hw / virtio / virtio-net.h
CommitLineData
fbe78f4f
AL
1/*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
2a6a4076
MA
14#ifndef QEMU_VIRTIO_NET_H
15#define QEMU_VIRTIO_NET_H
fbe78f4f 16
c9ad15d7 17#include "qemu/units.h"
b93a5ba3 18#include "standard-headers/linux/virtio_net.h"
0d09e41a 19#include "hw/virtio/virtio.h"
9d8c6a25 20#include "net/announce.h"
9711cd0d 21#include "qemu/option_int.h"
db1015e9 22#include "qom/object.h"
fbe78f4f 23
17ec5a86 24#define TYPE_VIRTIO_NET "virtio-net-device"
8063396b 25OBJECT_DECLARE_SIMPLE_TYPE(VirtIONet, VIRTIO_NET)
17ec5a86 26
fbe78f4f
AL
27#define TX_TIMER_INTERVAL 150000 /* 150 us */
28
e3f30488
AW
29/* Limit the number of packets that can be sent via a single flush
30 * of the TX queue. This gives us a guaranteed exit condition and
31 * ensures fairness in the io path. 256 conveniently matches the
32 * length of the TX queue and shows a good balance of performance
33 * and latency. */
34#define TX_BURST 256
35
f0c07c7c
AW
36typedef struct virtio_net_conf
37{
38 uint32_t txtimer;
e3f30488 39 int32_t txburst;
a697a334 40 char *tx;
1c0fbfa3 41 uint16_t rx_queue_size;
9b02e161 42 uint16_t tx_queue_size;
a93e599d 43 uint16_t mtu;
9473939e
JB
44 int32_t speed;
45 char *duplex_str;
46 uint8_t duplex;
9711cd0d 47 char *primary_id_str;
f0c07c7c
AW
48} virtio_net_conf;
49
2974e916
YB
50/* Coalesced packets type & status */
51typedef enum {
52 RSC_COALESCE, /* Data been coalesced */
53 RSC_FINAL, /* Will terminate current connection */
54 RSC_NO_MATCH, /* No matched in the buffer pool */
55 RSC_BYPASS, /* Packet to be bypass, not tcp, tcp ctrl, etc */
56 RSC_CANDIDATE /* Data want to be coalesced */
57} CoalesceStatus;
58
59typedef struct VirtioNetRscStat {
60 uint32_t received;
61 uint32_t coalesced;
62 uint32_t over_size;
63 uint32_t cache;
64 uint32_t empty_cache;
65 uint32_t no_match_cache;
66 uint32_t win_update;
67 uint32_t no_match;
68 uint32_t tcp_syn;
69 uint32_t tcp_ctrl_drain;
70 uint32_t dup_ack;
71 uint32_t dup_ack1;
72 uint32_t dup_ack2;
73 uint32_t pure_ack;
74 uint32_t ack_out_of_win;
75 uint32_t data_out_of_win;
76 uint32_t data_out_of_order;
77 uint32_t data_after_pure_ack;
78 uint32_t bypass_not_tcp;
79 uint32_t tcp_option;
80 uint32_t tcp_all_opt;
81 uint32_t ip_frag;
82 uint32_t ip_ecn;
83 uint32_t ip_hacked;
84 uint32_t ip_option;
85 uint32_t purge_failed;
86 uint32_t drain_failed;
87 uint32_t final_failed;
88 int64_t timer;
89} VirtioNetRscStat;
90
91/* Rsc unit general info used to checking if can coalescing */
92typedef struct VirtioNetRscUnit {
93 void *ip; /* ip header */
94 uint16_t *ip_plen; /* data len pointer in ip header field */
95 struct tcp_header *tcp; /* tcp header */
96 uint16_t tcp_hdrlen; /* tcp header len */
97 uint16_t payload; /* pure payload without virtio/eth/ip/tcp */
98} VirtioNetRscUnit;
99
fbf7b20b 100/* Coalesced segment */
2974e916
YB
101typedef struct VirtioNetRscSeg {
102 QTAILQ_ENTRY(VirtioNetRscSeg) next;
103 void *buf;
104 size_t size;
105 uint16_t packets;
106 uint16_t dup_ack;
107 bool is_coalesced; /* need recal ipv4 header checksum, mark here */
108 VirtioNetRscUnit unit;
109 NetClientState *nc;
110} VirtioNetRscSeg;
111
2974e916
YB
112
113/* Chain is divided by protocol(ipv4/v6) and NetClientInfo */
114typedef struct VirtioNetRscChain {
115 QTAILQ_ENTRY(VirtioNetRscChain) next;
116 VirtIONet *n; /* VirtIONet */
117 uint16_t proto;
118 uint8_t gso_type;
119 uint16_t max_payload;
120 QEMUTimer *drain_timer;
121 QTAILQ_HEAD(, VirtioNetRscSeg) buffers;
122 VirtioNetRscStat stat;
123} VirtioNetRscChain;
124
fbe78f4f 125/* Maximum packet size we can receive from tap device: header + 64k */
c9ad15d7 126#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 * KiB))
fbe78f4f 127
59079029
YB
128#define VIRTIO_NET_RSS_MAX_KEY_SIZE 40
129#define VIRTIO_NET_RSS_MAX_TABLE_LEN 128
130
131typedef struct VirtioNetRssData {
132 bool enabled;
e22f0603
YB
133 bool redirect;
134 bool populate_hash;
59079029
YB
135 uint32_t hash_types;
136 uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE];
137 uint16_t indirections_len;
138 uint16_t *indirections_table;
139 uint16_t default_queue;
140} VirtioNetRssData;
141
f1b24e84
FK
142typedef struct VirtIONetQueue {
143 VirtQueue *rx_vq;
144 VirtQueue *tx_vq;
145 QEMUTimer *tx_timer;
146 QEMUBH *tx_bh;
982b78c5 147 uint32_t tx_waiting;
f1b24e84 148 struct {
51b19ebe 149 VirtQueueElement *elem;
f1b24e84
FK
150 } async_tx;
151 struct VirtIONet *n;
152} VirtIONetQueue;
153
b0b36c02 154struct VirtIONet {
17a0ca55 155 VirtIODevice parent_obj;
f1b24e84
FK
156 uint8_t mac[ETH_ALEN];
157 uint16_t status;
158 VirtIONetQueue *vqs;
159 VirtQueue *ctrl_vq;
160 NICState *nic;
2974e916
YB
161 /* RSC Chains - temporary storage of coalesced data,
162 all these data are lost in case of migration */
163 QTAILQ_HEAD(, VirtioNetRscChain) rsc_chains;
f1b24e84
FK
164 uint32_t tx_timeout;
165 int32_t tx_burst;
166 uint32_t has_vnet_hdr;
167 size_t host_hdr_len;
168 size_t guest_hdr_len;
127833ee 169 uint64_t host_features;
2974e916
YB
170 uint32_t rsc_timeout;
171 uint8_t rsc4_enabled;
172 uint8_t rsc6_enabled;
f1b24e84 173 uint8_t has_ufo;
982b78c5 174 uint32_t mergeable_rx_bufs;
f1b24e84
FK
175 uint8_t promisc;
176 uint8_t allmulti;
177 uint8_t alluni;
178 uint8_t nomulti;
179 uint8_t nouni;
180 uint8_t nobcast;
181 uint8_t vhost_started;
182 struct {
71f7fe48
MT
183 uint32_t in_use;
184 uint32_t first_multi;
f1b24e84
FK
185 uint8_t multi_overflow;
186 uint8_t uni_overflow;
187 uint8_t *macs;
188 } mac_table;
189 uint32_t *vlans;
17ec5a86
FK
190 virtio_net_conf net_conf;
191 NICConf nic_conf;
f1b24e84
FK
192 DeviceState *qdev;
193 int multiqueue;
194 uint16_t max_queues;
195 uint16_t curr_queues;
196 size_t config_size;
8a253ec2
FK
197 char *netclient_name;
198 char *netclient_type;
644c9858 199 uint64_t curr_guest_offloads;
7788c3f2
MS
200 /* used on saved state restore phase to preserve the curr_guest_offloads */
201 uint64_t saved_guest_offloads;
9d8c6a25 202 AnnounceTimer announce_timer;
1bfa316c 203 bool needs_vnet_hdr_swap;
75ebec11 204 bool mtu_bypass_backend;
9711cd0d
JF
205 QemuOpts *primary_device_opts;
206 QDict *primary_device_dict;
207 DeviceState *primary_dev;
208 BusState *primary_bus;
209 char *primary_device_id;
210 char *standby_id;
211 bool primary_should_be_hidden;
212 bool failover;
213 DeviceListener primary_listener;
214 Notifier migration_state;
59079029 215 VirtioNetRssData rss_data;
4474e37a 216 struct NetRxPkt *rx_pkt;
b0b36c02 217};
f1b24e84 218
8a253ec2
FK
219void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
220 const char *type);
17ec5a86 221
fbe78f4f 222#endif