xref: /qemu/include/hw/virtio/virtio-net.h (revision 0bc12c4f)
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 VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
25                                          * configuration support */
26 
27 #define TX_TIMER_INTERVAL 150000 /* 150 us */
28 
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 
36 typedef struct virtio_net_conf
37 {
38     uint32_t txtimer;
39     int32_t txburst;
40     char *tx;
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     int tx_waiting;
52     struct {
53         VirtQueueElement elem;
54         ssize_t len;
55     } async_tx;
56     struct VirtIONet *n;
57 } VirtIONetQueue;
58 
59 typedef struct VirtIONet {
60     VirtIODevice parent_obj;
61     uint8_t mac[ETH_ALEN];
62     uint16_t status;
63     VirtIONetQueue *vqs;
64     VirtQueue *ctrl_vq;
65     NICState *nic;
66     uint32_t tx_timeout;
67     int32_t tx_burst;
68     uint32_t has_vnet_hdr;
69     size_t host_hdr_len;
70     size_t guest_hdr_len;
71     uint32_t host_features;
72     uint8_t has_ufo;
73     int mergeable_rx_bufs;
74     uint8_t promisc;
75     uint8_t allmulti;
76     uint8_t alluni;
77     uint8_t nomulti;
78     uint8_t nouni;
79     uint8_t nobcast;
80     uint8_t vhost_started;
81     struct {
82         uint32_t in_use;
83         uint32_t first_multi;
84         uint8_t multi_overflow;
85         uint8_t uni_overflow;
86         uint8_t *macs;
87     } mac_table;
88     uint32_t *vlans;
89     virtio_net_conf net_conf;
90     NICConf nic_conf;
91     DeviceState *qdev;
92     int multiqueue;
93     uint16_t max_queues;
94     uint16_t curr_queues;
95     size_t config_size;
96     char *netclient_name;
97     char *netclient_type;
98     uint64_t curr_guest_offloads;
99     QEMUTimer *announce_timer;
100     int announce_counter;
101 } VirtIONet;
102 
103 /*
104  * Control network offloads
105  *
106  * Dynamic offloads are available with the
107  * VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
108  */
109 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS   5
110 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET        0
111 
112 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
113                                    const char *type);
114 
115 #endif
116