FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
vhost_user.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __VIRTIO_VHOST_USER_H__
16 #define __VIRTIO_VHOST_USER_H__
17 
20 
21 /* vhost-user data structures */
22 
23 #define VHOST_MEMORY_MAX_NREGIONS 8
24 #define VHOST_USER_MSG_HDR_SZ 12
25 #define VHOST_VRING_MAX_N 16 //8TX + 8RX
26 #define VHOST_VRING_IDX_RX(qid) (2*qid)
27 #define VHOST_VRING_IDX_TX(qid) (2*qid + 1)
28 
29 #define VHOST_USER_VRING_NOFD_MASK 0x100
30 
31 #define VHOST_USER_PROTOCOL_F_MQ 0
32 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
33 #define VHOST_VRING_F_LOG 0
34 
35 #define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
36  (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD))
37 
38 #define vu_log_debug(dev, f, ...) \
39 { \
40  vlib_log(VLIB_LOG_LEVEL_DEBUG, vhost_user_main.log_default, "%U: " f, \
41  format_vnet_hw_if_index_name, vnet_get_main(), \
42  dev->hw_if_index, ##__VA_ARGS__); \
43 };
44 
45 #define vu_log_warn(dev, f, ...) \
46 { \
47  vlib_log(VLIB_LOG_LEVEL_WARNING, vhost_user_main.log_default, "%U: " f, \
48  format_vnet_hw_if_index_name, vnet_get_main(), \
49  dev->hw_if_index, ##__VA_ARGS__); \
50 };
51 #define vu_log_err(dev, f, ...) \
52 { \
53  vlib_log(VLIB_LOG_LEVEL_ERR, vhost_user_main.log_default, "%U: " f, \
54  format_vnet_hw_if_index_name, vnet_get_main(), \
55  dev->hw_if_index, ##__VA_ARGS__); \
56 };
57 
58 #define UNIX_GET_FD(unixfd_idx) ({ \
59  typeof(unixfd_idx) __unixfd_idx = (unixfd_idx); \
60  (__unixfd_idx != ~0) ? \
61  pool_elt_at_index (file_main.file_pool, \
62  __unixfd_idx)->file_descriptor : -1; })
63 
64 #define foreach_virtio_trace_flags \
65  _ (SIMPLE_CHAINED, 0, "Simple descriptor chaining") \
66  _ (SINGLE_DESC, 1, "Single descriptor packet") \
67  _ (INDIRECT, 2, "Indirect descriptor") \
68  _ (MAP_ERROR, 4, "Memory mapping error")
69 
70 typedef enum
71 {
72 #define _(n,i,s) VIRTIO_TRACE_F_##n,
74 #undef _
76 
77 #define FEATURE_VIRTIO_NET_F_HOST_TSO_FEATURE_BITS \
78  (VIRTIO_FEATURE (VIRTIO_NET_F_CSUM) | \
79  VIRTIO_FEATURE (VIRTIO_NET_F_HOST_UFO) | \
80  VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO4) | \
81  VIRTIO_FEATURE (VIRTIO_NET_F_HOST_TSO6))
82 
83 #define FEATURE_VIRTIO_NET_F_GUEST_TSO_FEATURE_BITS \
84  (VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_CSUM) | \
85  VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_UFO) | \
86  VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO4) | \
87  VIRTIO_FEATURE (VIRTIO_NET_F_GUEST_TSO6))
88 
89 #define FEATURE_VIRTIO_NET_F_HOST_GUEST_TSO_FEATURE_BITS \
90  (FEATURE_VIRTIO_NET_F_HOST_TSO_FEATURE_BITS | \
91  FEATURE_VIRTIO_NET_F_GUEST_TSO_FEATURE_BITS)
92 
94  const char *sock_filename, u8 is_server,
95  u32 * sw_if_index, u64 feature_mask,
96  u8 renumber, u32 custom_dev_instance, u8 * hwaddr,
97  u8 enable_gso, u8 enable_packed);
99  const char *sock_filename, u8 is_server,
100  u32 sw_if_index, u64 feature_mask,
101  u8 renumber, u32 custom_dev_instance,
102  u8 enable_gso, u8 enable_packed);
106 /* *INDENT-OFF* */
108 {
113 } __attribute ((packed)) vhost_user_memory_region_t;
114 
115 typedef struct vhost_user_memory
116 {
119  vhost_user_memory_region_t regions[VHOST_MEMORY_MAX_NREGIONS];
120 } __attribute ((packed)) vhost_user_memory_t;
121 
122 typedef enum vhost_user_req
123 {
145 
146 typedef struct vhost_user_msg {
147  vhost_user_req_t request;
150  union
151  {
155  vhost_user_memory_t memory;
157  };
158 } __attribute ((packed)) vhost_user_msg_t;
159 /* *INDENT-ON* */
160 
161 typedef struct
162 {
163  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
168  union
169  {
171  vring_packed_desc_t *packed_desc;
172  };
173  union
174  {
176  vring_desc_event_t *avail_event;
177  };
178  union
179  {
181  vring_desc_event_t *used_event;
182  };
190  //Put non-runtime in a different cache line
191  CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
192  int errfd;
196 
197  /* The rx queue policy (interrupt/adaptive/polling) for this queue */
199 
200  /*
201  * It contains the device queue number. -1 if it does not. The idea is
202  * to not invoke vnet_hw_interface_assign_rx_thread and
203  * vnet_hw_interface_unassign_rx_thread more than once for the duration of
204  * the interface even if it is disconnected and reconnected.
205  */
207 
211 
212 #define VHOST_USER_EVENT_START_TIMER 1
213 #define VHOST_USER_EVENT_STOP_TIMER 2
214 
215 typedef struct
216 {
217  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
222  char sock_filename[256];
225  u32 hw_if_index, sw_if_index;
226 
227  //Feature negotiation
231 
232  //Memory region information
234  vhost_user_memory_region_t regions[VHOST_MEMORY_MAX_NREGIONS];
235  void *region_mmap_addr[VHOST_MEMORY_MAX_NREGIONS];
236  u64 region_guest_addr_lo[VHOST_MEMORY_MAX_NREGIONS];
237  u64 region_guest_addr_hi[VHOST_MEMORY_MAX_NREGIONS];
239 
240  //Virtual rings
242  volatile u32 *vring_locks[VHOST_VRING_MAX_N];
243 
246 
249 
250  /* Whether to use spinlock or per_cpu_tx_qid assignment */
253 
255 
256  /* Packed ring configured */
258 
260 
261 typedef struct
262 {
266 } vhost_copy_t;
267 
268 typedef struct
269 {
270  u16 qid; /** The interface queue index (Not the virtio vring idx) */
271  u16 device_index; /** The device index */
272  u32 virtio_ring_flags; /** Runtime queue flags **/
273  u16 first_desc_len; /** Length of the first data descriptor **/
274  virtio_net_hdr_mrg_rxbuf_t hdr; /** Virtio header **/
275 } vhost_trace_t;
276 
277 #define VHOST_USER_RX_BUFFERS_N (2 * VLIB_FRAME_SIZE + 2)
278 #define VHOST_USER_COPY_ARRAY_N (4 * VLIB_FRAME_SIZE)
279 
280 typedef struct
281 {
284 
285  virtio_net_hdr_mrg_rxbuf_t tx_headers[VLIB_FRAME_SIZE];
287 
288  /* This is here so it doesn't end-up
289  * using stack or registers. */
291 
294 } vhost_cpu_t;
295 
296 typedef struct
297 {
305 
306  /** Per-CPU data for vhost-user */
308 
309  /** Pseudo random iterator */
311 
312  /* The number of rx interface/queue pairs in interrupt mode */
314 
315  /* logging */
317 
318  /* gso interface count */
321 
322 typedef struct
323 {
324  u8 if_name[64];
329  u8 sock_filename[256];
333 
335  vhost_user_intf_details_t ** out_vuids);
336 
341 
342 #endif
343 
344 /*
345  * fd.io coding-style-patch-verification: ON
346  *
347  * Local Variables:
348  * eval: (c-set-style "gnu")
349  * End:
350  */
u32 * to_next_list
Definition: vhost_user.h:292
Definition: mhash.h:46
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
vring_desc_t * desc
Definition: vhost_user.h:170
vhost_user_log_t log
Definition: vhost_user.h:156
u32 virtio_ring_flags
The device index.
Definition: vhost_user.h:272
int vhost_user_modify_if(vnet_main_t *vnm, vlib_main_t *vm, const char *sock_filename, u8 is_server, u32 sw_if_index, u64 feature_mask, u8 renumber, u32 custom_dev_instance, u8 enable_gso, u8 enable_packed)
Definition: vhost_user.c:1635
virtio_net_hdr_mrg_rxbuf_t hdr
Length of the first data descriptor.
Definition: vhost_user.h:274
vhost_cpu_t * cpus
Per-CPU data for vhost-user.
Definition: vhost_user.h:307
vring_desc_event_t * used_event
Definition: vhost_user.h:181
int vhost_user_dump_ifs(vnet_main_t *vnm, vlib_main_t *vm, vhost_user_intf_details_t **out_vuids)
Definition: vhost_user.c:1812
unsigned long u64
Definition: types.h:89
#define VHOST_VRING_MAX_N
Definition: vhost_user.h:25
enum vhost_user_req vhost_user_req_t
vring_packed_desc_t * packed_desc
Definition: vhost_user.h:171
vring_avail_t * avail
Definition: vhost_user.h:175
vnet_device_class_t vhost_user_device_class
vhost_vring_state_t state
Definition: vhost_user.h:153
vlib_main_t * vm
Definition: in2out_ed.c:1582
#define foreach_virtio_trace_flags
Definition: vhost_user.h:64
struct _vnet_device_class vnet_device_class_t
vring_used_t * used
Definition: vhost_user.h:180
vhost_trace_t * current_trace
Definition: vhost_user.h:290
unsigned char u8
Definition: types.h:56
int vhost_user_delete_if(vnet_main_t *vnm, vlib_main_t *vm, u32 sw_if_index)
Definition: vhost_user.c:1335
double f64
Definition: types.h:142
u32 vlib_log_class_t
Definition: vlib.h:51
void * log_base_addr
Definition: vhost_user.h:247
unsigned int u32
Definition: types.h:88
#define VLIB_FRAME_SIZE
Definition: node.h:377
#define VHOST_USER_COPY_ARRAY_N
Definition: vhost_user.h:278
u32 random
Pseudo random iterator.
Definition: vhost_user.h:310
vlib_node_registration_t vhost_user_input_node
(constructor) VLIB_REGISTER_NODE (vhost_user_input_node)
unsigned short u16
Definition: types.h:57
virtio_trace_flag_t
Definition: vhost_user.h:70
vhost_vring_addr_t addr
Definition: vhost_user.h:154
vlib_node_registration_t vhost_user_send_interrupt_node
(constructor) VLIB_REGISTER_NODE (vhost_user_send_interrupt_node)
Definition: vhost_user.c:53
vlib_log_class_t log_default
Definition: vhost_user.h:316
u32 * show_dev_instance_by_real_dev_instance
Definition: vhost_user.h:301
u16 device_index
The interface queue index (Not the virtio vring idx)
Definition: vhost_user.h:271
vhost_user_intf_t * vhost_user_interfaces
Definition: vhost_user.h:300
vhost_user_req
Definition: vhost_user.h:122
u16 first_desc_len
Runtime queue flags.
Definition: vhost_user.h:273
int vhost_user_create_if(vnet_main_t *vnm, vlib_main_t *vm, const char *sock_filename, u8 is_server, u32 *sw_if_index, u64 feature_mask, u8 renumber, u32 custom_dev_instance, u8 *hwaddr, u8 enable_gso, u8 enable_packed)
Definition: vhost_user.c:1571
#define VHOST_USER_RX_BUFFERS_N
Definition: vhost_user.h:277
vlib_buffer_t ** rx_buffers_pdesc
Definition: vhost_user.h:293
vhost_user_main_t vhost_user_main
Definition: vhost_user.c:56
vring_desc_event_t * avail_event
Definition: vhost_user.h:176
mhash_t if_index_by_sock_name
Definition: vhost_user.h:298
struct _vlib_node_registration vlib_node_registration_t
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
#define VHOST_MEMORY_MAX_NREGIONS
Definition: vhost_user.h:23
u32 rx_buffers_len
Definition: vhost_user.h:282
vhost_user_memory_t memory
Definition: vhost_user.h:155
vhost_user_memory_region_t regions[VHOST_MEMORY_MAX_NREGIONS]
Definition: vhost_user.h:106
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
vhost_user_req_t request
Definition: vhost_user.h:147
int dont_dump_vhost_user_memory
Definition: vhost_user.h:304
signed short i16
Definition: types.h:46