2008-12-18 03:13:11 +08:00
|
|
|
/*
|
|
|
|
* Virtio Network Device
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2007
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-06-29 19:47:03 +08:00
|
|
|
#ifndef QEMU_VIRTIO_NET_H
|
|
|
|
#define QEMU_VIRTIO_NET_H
|
2008-12-18 03:13:11 +08:00
|
|
|
|
2015-02-17 05:36:09 +08:00
|
|
|
#include "standard-headers/linux/virtio_net.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/virtio/virtio.h"
|
2008-12-18 03:13:11 +08:00
|
|
|
|
2013-04-11 22:29:57 +08:00
|
|
|
#define TYPE_VIRTIO_NET "virtio-net-device"
|
|
|
|
#define VIRTIO_NET(obj) \
|
|
|
|
OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
|
|
|
|
|
2008-12-18 03:13:11 +08:00
|
|
|
#define TX_TIMER_INTERVAL 150000 /* 150 us */
|
|
|
|
|
2010-09-02 23:00:57 +08:00
|
|
|
/* Limit the number of packets that can be sent via a single flush
|
|
|
|
* of the TX queue. This gives us a guaranteed exit condition and
|
|
|
|
* ensures fairness in the io path. 256 conveniently matches the
|
|
|
|
* length of the TX queue and shows a good balance of performance
|
|
|
|
* and latency. */
|
|
|
|
#define TX_BURST 256
|
|
|
|
|
2010-09-02 23:00:50 +08:00
|
|
|
typedef struct virtio_net_conf
|
|
|
|
{
|
|
|
|
uint32_t txtimer;
|
2010-09-02 23:00:57 +08:00
|
|
|
int32_t txburst;
|
2010-09-02 23:01:10 +08:00
|
|
|
char *tx;
|
2016-08-10 22:47:16 +08:00
|
|
|
uint16_t rx_queue_size;
|
2016-12-10 23:30:38 +08:00
|
|
|
uint16_t mtu;
|
2010-09-02 23:00:50 +08:00
|
|
|
} virtio_net_conf;
|
|
|
|
|
2008-12-18 03:13:11 +08:00
|
|
|
/* Maximum packet size we can receive from tap device: header + 64k */
|
|
|
|
#define VIRTIO_NET_MAX_BUFSIZE (sizeof(struct virtio_net_hdr) + (64 << 10))
|
|
|
|
|
2013-03-19 00:37:18 +08:00
|
|
|
typedef struct VirtIONetQueue {
|
|
|
|
VirtQueue *rx_vq;
|
|
|
|
VirtQueue *tx_vq;
|
|
|
|
QEMUTimer *tx_timer;
|
|
|
|
QEMUBH *tx_bh;
|
2017-02-04 00:06:51 +08:00
|
|
|
uint32_t tx_waiting;
|
2013-03-19 00:37:18 +08:00
|
|
|
struct {
|
2016-02-04 22:26:51 +08:00
|
|
|
VirtQueueElement *elem;
|
2013-03-19 00:37:18 +08:00
|
|
|
} async_tx;
|
|
|
|
struct VirtIONet *n;
|
|
|
|
} VirtIONetQueue;
|
|
|
|
|
|
|
|
typedef struct VirtIONet {
|
2013-04-11 22:30:01 +08:00
|
|
|
VirtIODevice parent_obj;
|
2013-03-19 00:37:18 +08:00
|
|
|
uint8_t mac[ETH_ALEN];
|
|
|
|
uint16_t status;
|
|
|
|
VirtIONetQueue *vqs;
|
|
|
|
VirtQueue *ctrl_vq;
|
|
|
|
NICState *nic;
|
|
|
|
uint32_t tx_timeout;
|
|
|
|
int32_t tx_burst;
|
|
|
|
uint32_t has_vnet_hdr;
|
|
|
|
size_t host_hdr_len;
|
|
|
|
size_t guest_hdr_len;
|
2015-04-28 19:51:12 +08:00
|
|
|
uint32_t host_features;
|
2013-03-19 00:37:18 +08:00
|
|
|
uint8_t has_ufo;
|
2017-02-04 00:06:51 +08:00
|
|
|
uint32_t mergeable_rx_bufs;
|
2013-03-19 00:37:18 +08:00
|
|
|
uint8_t promisc;
|
|
|
|
uint8_t allmulti;
|
|
|
|
uint8_t alluni;
|
|
|
|
uint8_t nomulti;
|
|
|
|
uint8_t nouni;
|
|
|
|
uint8_t nobcast;
|
|
|
|
uint8_t vhost_started;
|
|
|
|
struct {
|
2014-04-04 00:50:39 +08:00
|
|
|
uint32_t in_use;
|
|
|
|
uint32_t first_multi;
|
2013-03-19 00:37:18 +08:00
|
|
|
uint8_t multi_overflow;
|
|
|
|
uint8_t uni_overflow;
|
|
|
|
uint8_t *macs;
|
|
|
|
} mac_table;
|
|
|
|
uint32_t *vlans;
|
2013-04-11 22:29:57 +08:00
|
|
|
virtio_net_conf net_conf;
|
|
|
|
NICConf nic_conf;
|
2013-03-19 00:37:18 +08:00
|
|
|
DeviceState *qdev;
|
|
|
|
int multiqueue;
|
|
|
|
uint16_t max_queues;
|
|
|
|
uint16_t curr_queues;
|
|
|
|
size_t config_size;
|
2013-05-15 20:12:49 +08:00
|
|
|
char *netclient_name;
|
|
|
|
char *netclient_type;
|
2013-05-20 16:18:14 +08:00
|
|
|
uint64_t curr_guest_offloads;
|
2014-05-20 14:01:44 +08:00
|
|
|
QEMUTimer *announce_timer;
|
|
|
|
int announce_counter;
|
2016-02-05 18:43:11 +08:00
|
|
|
bool needs_vnet_hdr_swap;
|
2017-05-23 20:31:19 +08:00
|
|
|
bool mtu_bypass_backend;
|
2013-03-19 00:37:18 +08:00
|
|
|
} VirtIONet;
|
|
|
|
|
2013-05-15 20:12:49 +08:00
|
|
|
void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
|
|
|
|
const char *type);
|
2013-04-11 22:29:57 +08:00
|
|
|
|
2008-12-18 03:13:11 +08:00
|
|
|
#endif
|