xref: /qemu/include/hw/virtio/virtio-net.h (revision 7ee9edfd)
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     int32_t speed;
42     char *duplex_str;
43     uint8_t duplex;
44 } virtio_net_conf;
45 
46 /* Maximum packet size we can receive from tap device: header + 64k */
47 #define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
48 
49 typedef struct VirtIONetQueue {
50     VirtQueue *rx_vq;
51     VirtQueue *tx_vq;
52     QEMUTimer *tx_timer;
53     QEMUBH *tx_bh;
54     uint32_t tx_waiting;
55     struct {
56         VirtQueueElement *elem;
57     } async_tx;
58     struct VirtIONet *n;
59 } VirtIONetQueue;
60 
61 typedef struct VirtIONet {
62     VirtIODevice parent_obj;
63     uint8_t mac[ETH_ALEN];
64     uint16_t status;
65     VirtIONetQueue *vqs;
66     VirtQueue *ctrl_vq;
67     NICState *nic;
68     uint32_t tx_timeout;
69     int32_t tx_burst;
70     uint32_t has_vnet_hdr;
71     size_t host_hdr_len;
72     size_t guest_hdr_len;
73     uint64_t host_features;
74     uint8_t has_ufo;
75     uint32_t mergeable_rx_bufs;
76     uint8_t promisc;
77     uint8_t allmulti;
78     uint8_t alluni;
79     uint8_t nomulti;
80     uint8_t nouni;
81     uint8_t nobcast;
82     uint8_t vhost_started;
83     struct {
84         uint32_t in_use;
85         uint32_t first_multi;
86         uint8_t multi_overflow;
87         uint8_t uni_overflow;
88         uint8_t *macs;
89     } mac_table;
90     uint32_t *vlans;
91     virtio_net_conf net_conf;
92     NICConf nic_conf;
93     DeviceState *qdev;
94     int multiqueue;
95     uint16_t max_queues;
96     uint16_t curr_queues;
97     size_t config_size;
98     char *netclient_name;
99     char *netclient_type;
100     uint64_t curr_guest_offloads;
101     QEMUTimer *announce_timer;
102     int announce_counter;
103     bool needs_vnet_hdr_swap;
104     bool mtu_bypass_backend;
105 } VirtIONet;
106 
107 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
108                                    const char *type);
109 
110 #endif
111