xref: /qemu/include/hw/virtio/virtio-net.h (revision 6402cbbb)
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 
14 #ifndef QEMU_VIRTIO_NET_H
15 #define QEMU_VIRTIO_NET_H
16 
17 #include "standard-headers/linux/virtio_net.h"
18 #include "hw/virtio/virtio.h"
19 
20 #define TYPE_VIRTIO_NET "virtio-net-device"
21 #define VIRTIO_NET(obj) \
22         OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
23 
24 #define TX_TIMER_INTERVAL 150000 /* 150 us */
25 
26 /* Limit the number of packets that can be sent via a single flush
27  * of the TX queue.  This gives us a guaranteed exit condition and
28  * ensures fairness in the io path.  256 conveniently matches the
29  * length of the TX queue and shows a good balance of performance
30  * and latency. */
31 #define TX_BURST 256
32 
33 typedef struct virtio_net_conf
34 {
35     uint32_t txtimer;
36     int32_t txburst;
37     char *tx;
38     uint16_t rx_queue_size;
39     uint16_t tx_queue_size;
40     uint16_t mtu;
41 } virtio_net_conf;
42 
43 /* Maximum packet size we can receive from tap device: header + 64k */
44 #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
45 
46 typedef struct VirtIONetQueue {
47     VirtQueue *rx_vq;
48     VirtQueue *tx_vq;
49     QEMUTimer *tx_timer;
50     QEMUBH *tx_bh;
51     uint32_t tx_waiting;
52     struct {
53         VirtQueueElement *elem;
54     } async_tx;
55     struct VirtIONet *n;
56 } VirtIONetQueue;
57 
58 typedef struct VirtIONet {
59     VirtIODevice parent_obj;
60     uint8_t mac[ETH_ALEN];
61     uint16_t status;
62     VirtIONetQueue *vqs;
63     VirtQueue *ctrl_vq;
64     NICState *nic;
65     uint32_t tx_timeout;
66     int32_t tx_burst;
67     uint32_t has_vnet_hdr;
68     size_t host_hdr_len;
69     size_t guest_hdr_len;
70     uint32_t host_features;
71     uint8_t has_ufo;
72     uint32_t mergeable_rx_bufs;
73     uint8_t promisc;
74     uint8_t allmulti;
75     uint8_t alluni;
76     uint8_t nomulti;
77     uint8_t nouni;
78     uint8_t nobcast;
79     uint8_t vhost_started;
80     struct {
81         uint32_t in_use;
82         uint32_t first_multi;
83         uint8_t multi_overflow;
84         uint8_t uni_overflow;
85         uint8_t *macs;
86     } mac_table;
87     uint32_t *vlans;
88     virtio_net_conf net_conf;
89     NICConf nic_conf;
90     DeviceState *qdev;
91     int multiqueue;
92     uint16_t max_queues;
93     uint16_t curr_queues;
94     size_t config_size;
95     char *netclient_name;
96     char *netclient_type;
97     uint64_t curr_guest_offloads;
98     QEMUTimer *announce_timer;
99     int announce_counter;
100     bool needs_vnet_hdr_swap;
101     bool mtu_bypass_backend;
102 } VirtIONet;
103 
104 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
105                                    const char *type);
106 
107 #endif
108