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