2008-12-17 22:13:11 +03: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 14:47:03 +03:00
|
|
|
#ifndef QEMU_VIRTIO_NET_H
|
|
|
|
#define QEMU_VIRTIO_NET_H
|
2008-12-17 22:13:11 +03:00
|
|
|
|
2015-02-17 00:36:09 +03:00
|
|
|
#include "standard-headers/linux/virtio_net.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/virtio/virtio.h"
|
2008-12-17 22:13:11 +03:00
|
|
|
|
2013-04-11 18:29:57 +04:00
|
|
|
#define TYPE_VIRTIO_NET "virtio-net-device"
|
|
|
|
#define VIRTIO_NET(obj) \
|
|
|
|
OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
|
|
|
|
|
2008-12-17 22:13:11 +03:00
|
|
|
#define TX_TIMER_INTERVAL 150000 /* 150 us */
|
|
|
|
|
2010-09-02 19:00:57 +04: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 19:00:50 +04:00
|
|
|
typedef struct virtio_net_conf
|
|
|
|
{
|
|
|
|
uint32_t txtimer;
|
2010-09-02 19:00:57 +04:00
|
|
|
int32_t txburst;
|
2010-09-02 19:01:10 +04:00
|
|
|
char *tx;
|
2016-08-10 17:47:16 +03:00
|
|
|
uint16_t rx_queue_size;
|
2017-06-28 05:37:59 +03:00
|
|
|
uint16_t tx_queue_size;
|
2016-12-10 18:30:38 +03:00
|
|
|
uint16_t mtu;
|
2018-03-08 06:25:41 +03:00
|
|
|
int32_t speed;
|
|
|
|
char *duplex_str;
|
|
|
|
uint8_t duplex;
|
2010-09-02 19:00:50 +04:00
|
|
|
} virtio_net_conf;
|
|
|
|
|
2008-12-17 22:13:11 +03: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-18 20:37:18 +04:00
|
|
|
typedef struct VirtIONetQueue {
|
|
|
|
VirtQueue *rx_vq;
|
|
|
|
VirtQueue *tx_vq;
|
|
|
|
QEMUTimer *tx_timer;
|
|
|
|
QEMUBH *tx_bh;
|
2017-02-03 19:06:51 +03:00
|
|
|
uint32_t tx_waiting;
|
2013-03-18 20:37:18 +04:00
|
|
|
struct {
|
2016-02-04 17:26:51 +03:00
|
|
|
VirtQueueElement *elem;
|
2013-03-18 20:37:18 +04:00
|
|
|
} async_tx;
|
|
|
|
struct VirtIONet *n;
|
|
|
|
} VirtIONetQueue;
|
|
|
|
|
|
|
|
typedef struct VirtIONet {
|
2013-04-11 18:30:01 +04:00
|
|
|
VirtIODevice parent_obj;
|
2013-03-18 20:37:18 +04: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;
|
2018-03-08 06:25:40 +03:00
|
|
|
uint64_t host_features;
|
2013-03-18 20:37:18 +04:00
|
|
|
uint8_t has_ufo;
|
2017-02-03 19:06:51 +03:00
|
|
|
uint32_t mergeable_rx_bufs;
|
2013-03-18 20:37:18 +04: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-03 20:50:39 +04:00
|
|
|
uint32_t in_use;
|
|
|
|
uint32_t first_multi;
|
2013-03-18 20:37:18 +04:00
|
|
|
uint8_t multi_overflow;
|
|
|
|
uint8_t uni_overflow;
|
|
|
|
uint8_t *macs;
|
|
|
|
} mac_table;
|
|
|
|
uint32_t *vlans;
|
2013-04-11 18:29:57 +04:00
|
|
|
virtio_net_conf net_conf;
|
|
|
|
NICConf nic_conf;
|
2013-03-18 20:37:18 +04:00
|
|
|
DeviceState *qdev;
|
|
|
|
int multiqueue;
|
|
|
|
uint16_t max_queues;
|
|
|
|
uint16_t curr_queues;
|
|
|
|
size_t config_size;
|
2013-05-15 16:12:49 +04:00
|
|
|
char *netclient_name;
|
|
|
|
char *netclient_type;
|
2013-05-20 12:18:14 +04:00
|
|
|
uint64_t curr_guest_offloads;
|
2014-05-20 10:01:44 +04:00
|
|
|
QEMUTimer *announce_timer;
|
|
|
|
int announce_counter;
|
2016-02-05 13:43:11 +03:00
|
|
|
bool needs_vnet_hdr_swap;
|
2017-05-23 15:31:19 +03:00
|
|
|
bool mtu_bypass_backend;
|
2013-03-18 20:37:18 +04:00
|
|
|
} VirtIONet;
|
|
|
|
|
2013-05-15 16:12:49 +04:00
|
|
|
void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
|
|
|
|
const char *type);
|
2013-04-11 18:29:57 +04:00
|
|
|
|
2008-12-17 22:13:11 +03:00
|
|
|
#endif
|