FD.io VPP  v19.01.3-6-g70449b9b9
Vector Packet Processing
virtio.h
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #ifndef _VNET_DEVICES_VIRTIO_VIRTIO_H_
19 #define _VNET_DEVICES_VIRTIO_VIRTIO_H_
20 
21 #define foreach_virtio_net_features \
22  _ (VIRTIO_NET_F_CSUM, 0) /* Host handles pkts w/ partial csum */ \
23  _ (VIRTIO_NET_F_GUEST_CSUM, 1) /* Guest handles pkts w/ partial csum */ \
24  _ (VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, 2) /* Dynamic offload configuration. */ \
25  _ (VIRTIO_NET_F_MTU, 3) /* Initial MTU advice. */ \
26  _ (VIRTIO_NET_F_MAC, 5) /* Host has given MAC address. */ \
27  _ (VIRTIO_NET_F_GSO, 6) /* Host handles pkts w/ any GSO. */ \
28  _ (VIRTIO_NET_F_GUEST_TSO4, 7) /* Guest can handle TSOv4 in. */ \
29  _ (VIRTIO_NET_F_GUEST_TSO6, 8) /* Guest can handle TSOv6 in. */ \
30  _ (VIRTIO_NET_F_GUEST_ECN, 9) /* Guest can handle TSO[6] w/ ECN in. */ \
31  _ (VIRTIO_NET_F_GUEST_UFO, 10) /* Guest can handle UFO in. */ \
32  _ (VIRTIO_NET_F_HOST_TSO4, 11) /* Host can handle TSOv4 in. */ \
33  _ (VIRTIO_NET_F_HOST_TSO6, 12) /* Host can handle TSOv6 in. */ \
34  _ (VIRTIO_NET_F_HOST_ECN, 13) /* Host can handle TSO[6] w/ ECN in. */ \
35  _ (VIRTIO_NET_F_HOST_UFO, 14) /* Host can handle UFO in. */ \
36  _ (VIRTIO_NET_F_MRG_RXBUF, 15) /* Host can merge receive buffers. */ \
37  _ (VIRTIO_NET_F_STATUS, 16) /* virtio_net_config.status available */ \
38  _ (VIRTIO_NET_F_CTRL_VQ, 17) /* Control channel available */ \
39  _ (VIRTIO_NET_F_CTRL_RX, 18) /* Control channel RX mode support */ \
40  _ (VIRTIO_NET_F_CTRL_VLAN, 19) /* Control channel VLAN filtering */ \
41  _ (VIRTIO_NET_F_CTRL_RX_EXTRA, 20) /* Extra RX mode control support */ \
42  _ (VIRTIO_NET_F_GUEST_ANNOUNCE, 21) /* Guest can announce device on the network */ \
43  _ (VIRTIO_NET_F_MQ, 22) /* Device supports Receive Flow Steering */ \
44  _ (VIRTIO_NET_F_CTRL_MAC_ADDR, 23) /* Set MAC address */ \
45  _ (VIRTIO_F_NOTIFY_ON_EMPTY, 24) \
46  _ (VHOST_F_LOG_ALL, 26) /* Log all write descriptors */ \
47  _ (VIRTIO_F_ANY_LAYOUT, 27) /* Can the device handle any descripor layout */ \
48  _ (VIRTIO_RING_F_INDIRECT_DESC, 28) /* Support indirect buffer descriptors */ \
49  _ (VIRTIO_RING_F_EVENT_IDX, 29) /* The Guest publishes the used index for which it expects an interrupt \
50  * at the end of the avail ring. Host should ignore the avail->flags field. */ \
51 /* The Host publishes the avail index for which it expects a kick \
52  * at the end of the used ring. Guest should ignore the used->flags field. */ \
53  _ (VHOST_USER_F_PROTOCOL_FEATURES, 30) \
54  _ (VIRTIO_F_VERSION_1, 32)
55 
56 #define foreach_virtio_if_flag \
57  _(0, ADMIN_UP, "admin-up") \
58  _(1, DELETING, "deleting")
59 
60 typedef enum
61 {
62 #define _(a, b, c) VIRTIO_IF_FLAG_##b = (1 << a),
64 #undef _
66 
67 typedef enum
68 {
72 
73 
74 typedef struct
75 {
76  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
77  struct vring_desc *desc;
78  struct vring_used *used;
79  struct vring_avail *avail;
82  int kick_fd;
83  int call_fd;
85 #define VIRTIO_RING_FLAG_MASK_INT 1
92 
93 typedef struct
94 {
97 
103  int fd;
104  int tap_fd;
106 
107  u64 features, remote_features;
108 
115  u8 host_mac_addr[6];
120 
121  int ifindex;
122 } virtio_if_t;
123 
124 typedef struct
125 {
127 } virtio_main_t;
128 
132 
134  u16 sz);
136  u32 idx);
137 extern void virtio_free_used_desc (vlib_main_t * vm, virtio_vring_t * vring);
138 
140 
143 {
144  u64 x = 1;
145  int __clib_unused r;
146 
147  r = write (vring->kick_fd, &x, sizeof (x));
148  vring->last_kick_avail_idx = vring->avail->idx;
149 }
150 
151 #endif /* _VNET_DEVICES_VIRTIO_VIRTIO_H_ */
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
u32 per_interface_next_index
Definition: virtio.h:102
struct vring_used * used
Definition: virtio.h:78
virtio_if_t * interfaces
Definition: virtio.h:126
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
ip4_address_t host_ip4_addr
Definition: virtio.h:116
clib_error_t * virtio_vring_init(vlib_main_t *vm, virtio_if_t *vif, u16 idx, u16 sz)
Definition: virtio.c:63
unsigned long u64
Definition: types.h:89
u32 dev_instance
Definition: virtio.h:99
int kick_fd
Definition: virtio.h:82
clib_error_t * virtio_vring_free(vlib_main_t *vm, virtio_if_t *vif, u32 idx)
Definition: virtio.c:155
vnet_device_class_t virtio_device_class
struct _vnet_device_class vnet_device_class_t
int call_fd
Definition: virtio.h:83
virtio_vring_t * vrings
Definition: virtio.h:105
unsigned char u8
Definition: types.h:56
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
struct vring_avail * avail
Definition: virtio.h:79
#define static_always_inline
Definition: clib.h:99
u32 hw_if_index
Definition: virtio.h:100
u8 host_ip6_prefix_len
Definition: virtio.h:119
u8 * host_bridge
Definition: virtio.h:114
int ifindex
Definition: virtio.h:121
virtio_main_t virtio_main
Definition: virtio.c:35
unsigned int u32
Definition: types.h:88
u32 id
Definition: virtio.h:98
virtio_if_flag_t
Definition: virtio.h:60
int tap_fd
Definition: virtio.h:104
unsigned short u16
Definition: types.h:57
u16 tx_ring_sz
Definition: virtio.h:110
clib_spinlock_t lockp
Definition: virtio.h:96
u16 desc_next
Definition: virtio.h:81
format_function_t format_virtio_device_name
Definition: virtio.h:139
u16 last_used_idx
Definition: virtio.h:89
static_always_inline void virtio_kick(virtio_vring_t *vring)
Definition: virtio.h:142
vlib_main_t * vm
Definition: buffer.c:301
ip6_address_t host_ip6_addr
Definition: virtio.h:118
u32 call_file_index
Definition: virtio.h:87
u8 * net_ns
Definition: virtio.h:113
u32 flags
Definition: virtio.h:95
u16 last_kick_avail_idx
Definition: virtio.h:90
u16 rx_ring_sz
Definition: virtio.h:111
virtio_if_type_t type
Definition: virtio.h:109
u64 remote_features
Definition: virtio.h:107
void virtio_free_used_desc(vlib_main_t *vm, virtio_vring_t *vring)
Definition: device.c:92
vlib_node_registration_t virtio_input_node
(constructor) VLIB_REGISTER_NODE (virtio_input_node)
Definition: node.c:285
struct _vlib_node_registration vlib_node_registration_t
#define foreach_virtio_if_flag
Definition: virtio.h:56
int fd
Definition: virtio.h:103
u32 * buffers
Definition: virtio.h:88
u8 host_ip4_prefix_len
Definition: virtio.h:117
u32 sw_if_index
Definition: virtio.h:101
struct vring_desc * desc
Definition: virtio.h:77
virtio_if_type_t
Definition: virtio.h:67
u16 desc_in_use
Definition: virtio.h:80
u8 * host_if_name
Definition: virtio.h:112