DPDK  18.02.2
rte_vhost.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4 
5 #ifndef _RTE_VHOST_H_
6 #define _RTE_VHOST_H_
7 
13 #include <stdint.h>
14 #include <sys/eventfd.h>
15 
16 #include <rte_memory.h>
17 #include <rte_mempool.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* These are not C++-aware. */
24 #include <linux/vhost.h>
25 #include <linux/virtio_ring.h>
26 
27 #define RTE_VHOST_USER_CLIENT (1ULL << 0)
28 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
29 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2)
30 #define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3)
31 
37  uint64_t guest_phys_addr;
38  uint64_t guest_user_addr;
39  uint64_t host_user_addr;
40  uint64_t size;
41  void *mmap_addr;
42  uint64_t mmap_size;
43  int fd;
44 };
45 
50  uint32_t nregions;
51  struct rte_vhost_mem_region regions[];
52 };
53 
54 struct rte_vhost_vring {
55  struct vring_desc *desc;
56  struct vring_avail *avail;
57  struct vring_used *used;
58  uint64_t log_guest_addr;
59 
61  int callfd;
62 
63  int kickfd;
64  uint16_t size;
65 };
66 
71  int (*new_device)(int vid);
72  void (*destroy_device)(int vid);
74  int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);
82  int (*features_changed)(int vid, uint64_t features);
83 
84  int (*new_connection)(int vid);
85  void (*destroy_connection)(int vid);
86 
87  void *reserved[2];
88 };
89 
105 __rte_deprecated
106 static __rte_always_inline uint64_t
107 rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa)
108 {
109  struct rte_vhost_mem_region *reg;
110  uint32_t i;
111 
112  for (i = 0; i < mem->nregions; i++) {
113  reg = &mem->regions[i];
114  if (gpa >= reg->guest_phys_addr &&
115  gpa < reg->guest_phys_addr + reg->size) {
116  return gpa - reg->guest_phys_addr +
117  reg->host_user_addr;
118  }
119  }
120 
121  return 0;
122 }
123 
140 static __rte_always_inline uint64_t
142  uint64_t gpa, uint64_t *len)
143 {
144  struct rte_vhost_mem_region *r;
145  uint32_t i;
146 
147  for (i = 0; i < mem->nregions; i++) {
148  r = &mem->regions[i];
149  if (gpa >= r->guest_phys_addr &&
150  gpa < r->guest_phys_addr + r->size) {
151 
152  if (unlikely(*len > r->guest_phys_addr + r->size - gpa))
153  *len = r->guest_phys_addr + r->size - gpa;
154 
155  return gpa - r->guest_phys_addr +
156  r->host_user_addr;
157  }
158  }
159  *len = 0;
160 
161  return 0;
162 }
163 
164 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL))
165 
184 void rte_vhost_log_write(int vid, uint64_t addr, uint64_t len);
185 
204 void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
205  uint64_t offset, uint64_t len);
206 
207 int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
208 
213 int rte_vhost_driver_register(const char *path, uint64_t flags);
214 
215 /* Unregister vhost driver. This is only meaningful to vhost user. */
216 int rte_vhost_driver_unregister(const char *path);
217 
228 int rte_vhost_driver_set_features(const char *path, uint64_t features);
229 
245 int rte_vhost_driver_enable_features(const char *path, uint64_t features);
246 
259 int rte_vhost_driver_disable_features(const char *path, uint64_t features);
260 
271 int rte_vhost_driver_get_features(const char *path, uint64_t *features);
272 
283 int rte_vhost_get_negotiated_features(int vid, uint64_t *features);
284 
285 /* Register callbacks. */
286 int rte_vhost_driver_callback_register(const char *path,
287  struct vhost_device_ops const * const ops);
288 
300 int rte_vhost_driver_start(const char *path);
301 
315 int rte_vhost_get_mtu(int vid, uint16_t *mtu);
316 
327 int rte_vhost_get_numa_node(int vid);
328 
343 __rte_deprecated
344 uint32_t rte_vhost_get_queue_num(int vid);
345 
355 uint16_t rte_vhost_get_vring_num(int vid);
356 
371 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
372 
384 uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
385 
386 struct rte_mbuf;
387 struct rte_mempool;
404 uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
405  struct rte_mbuf **pkts, uint16_t count);
406 
424 uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
425  struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
426 
441 int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
442 
455 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
456  struct rte_vhost_vring *vring);
457 
469 int rte_vhost_vring_call(int vid, uint16_t vring_idx);
470 
481 uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
482 
483 #ifdef __cplusplus
484 }
485 #endif
486 
487 #endif /* _RTE_VHOST_H_ */