numa: introduce machine callback for VCPU to node mapping
[qemu/cris-port.git] / include / hw / virtio / virtio-net.h
blob4c2fe83b6bcf579a348fe1a6314f3870c185666c
1 /*
2 * Virtio Network Device
4 * Copyright IBM, Corp. 2007
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #ifndef _QEMU_VIRTIO_NET_H
15 #define _QEMU_VIRTIO_NET_H
17 #include "standard-headers/linux/virtio_net.h"
18 #include "hw/virtio/virtio.h"
20 #define TYPE_VIRTIO_NET "virtio-net-device"
21 #define VIRTIO_NET(obj) \
22 OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
24 #define VIRTIO_NET_F_CTRL_GUEST_OFFLOADS 2 /* Control channel offload
25 * configuration support */
27 #define TX_TIMER_INTERVAL 150000 /* 150 us */
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
36 typedef struct virtio_net_conf
38 uint32_t txtimer;
39 int32_t txburst;
40 char *tx;
41 } virtio_net_conf;
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))
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;
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 uint8_t has_ufo;
72 int mergeable_rx_bufs;
73 uint8_t promisc;
74 uint8_t allmulti;
75 uint8_t alluni;
76 uint8_t nomulti;
77 uint8_t nouni;
78 uint8_t nobcast;
79 uint8_t vhost_started;
80 struct {
81 uint32_t in_use;
82 uint32_t first_multi;
83 uint8_t multi_overflow;
84 uint8_t uni_overflow;
85 uint8_t *macs;
86 } mac_table;
87 uint32_t *vlans;
88 virtio_net_conf net_conf;
89 NICConf nic_conf;
90 DeviceState *qdev;
91 int multiqueue;
92 uint16_t max_queues;
93 uint16_t curr_queues;
94 size_t config_size;
95 char *netclient_name;
96 char *netclient_type;
97 uint64_t curr_guest_offloads;
98 QEMUTimer *announce_timer;
99 int announce_counter;
100 } VirtIONet;
103 * Control network offloads
105 * Dynamic offloads are available with the
106 * VIRTIO_NET_F_CTRL_GUEST_OFFLOADS feature bit.
108 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS 5
109 #define VIRTIO_NET_CTRL_GUEST_OFFLOADS_SET 0
111 #define DEFINE_VIRTIO_NET_FEATURES(_state, _field) \
112 DEFINE_PROP_BIT("any_layout", _state, _field, VIRTIO_F_ANY_LAYOUT, true), \
113 DEFINE_PROP_BIT("csum", _state, _field, VIRTIO_NET_F_CSUM, true), \
114 DEFINE_PROP_BIT("guest_csum", _state, _field, VIRTIO_NET_F_GUEST_CSUM, true), \
115 DEFINE_PROP_BIT("gso", _state, _field, VIRTIO_NET_F_GSO, true), \
116 DEFINE_PROP_BIT("guest_tso4", _state, _field, VIRTIO_NET_F_GUEST_TSO4, true), \
117 DEFINE_PROP_BIT("guest_tso6", _state, _field, VIRTIO_NET_F_GUEST_TSO6, true), \
118 DEFINE_PROP_BIT("guest_ecn", _state, _field, VIRTIO_NET_F_GUEST_ECN, true), \
119 DEFINE_PROP_BIT("guest_ufo", _state, _field, VIRTIO_NET_F_GUEST_UFO, true), \
120 DEFINE_PROP_BIT("guest_announce", _state, _field, VIRTIO_NET_F_GUEST_ANNOUNCE, true), \
121 DEFINE_PROP_BIT("host_tso4", _state, _field, VIRTIO_NET_F_HOST_TSO4, true), \
122 DEFINE_PROP_BIT("host_tso6", _state, _field, VIRTIO_NET_F_HOST_TSO6, true), \
123 DEFINE_PROP_BIT("host_ecn", _state, _field, VIRTIO_NET_F_HOST_ECN, true), \
124 DEFINE_PROP_BIT("host_ufo", _state, _field, VIRTIO_NET_F_HOST_UFO, true), \
125 DEFINE_PROP_BIT("mrg_rxbuf", _state, _field, VIRTIO_NET_F_MRG_RXBUF, true), \
126 DEFINE_PROP_BIT("status", _state, _field, VIRTIO_NET_F_STATUS, true), \
127 DEFINE_PROP_BIT("ctrl_vq", _state, _field, VIRTIO_NET_F_CTRL_VQ, true), \
128 DEFINE_PROP_BIT("ctrl_rx", _state, _field, VIRTIO_NET_F_CTRL_RX, true), \
129 DEFINE_PROP_BIT("ctrl_vlan", _state, _field, VIRTIO_NET_F_CTRL_VLAN, true), \
130 DEFINE_PROP_BIT("ctrl_rx_extra", _state, _field, VIRTIO_NET_F_CTRL_RX_EXTRA, true), \
131 DEFINE_PROP_BIT("ctrl_mac_addr", _state, _field, VIRTIO_NET_F_CTRL_MAC_ADDR, true), \
132 DEFINE_PROP_BIT("ctrl_guest_offloads", _state, _field, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), \
133 DEFINE_PROP_BIT("mq", _state, _field, VIRTIO_NET_F_MQ, false)
135 #define DEFINE_VIRTIO_NET_PROPERTIES(_state, _field) \
136 DEFINE_PROP_UINT32("x-txtimer", _state, _field.txtimer, TX_TIMER_INTERVAL),\
137 DEFINE_PROP_INT32("x-txburst", _state, _field.txburst, TX_BURST), \
138 DEFINE_PROP_STRING("tx", _state, _field.tx)
140 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features);
141 void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
142 const char *type);
144 #endif