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