14 #include <sys/eventfd.h>
24 #include <linux/vhost.h>
25 #include <linux/virtio_ring.h>
26 #include <linux/virtio_net.h>
28 #define RTE_VHOST_USER_CLIENT (1ULL << 0)
29 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
30 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2)
31 #define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3)
32 #define RTE_VHOST_USER_POSTCOPY_SUPPORT (1ULL << 4)
35 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
36 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
39 #ifndef VIRTIO_NET_F_MQ
40 #define VIRTIO_NET_F_MQ 22
43 #ifndef VIRTIO_NET_F_MTU
44 #define VIRTIO_NET_F_MTU 3
47 #ifndef VIRTIO_F_ANY_LAYOUT
48 #define VIRTIO_F_ANY_LAYOUT 27
52 #ifndef VHOST_USER_PROTOCOL_F_MQ
53 #define VHOST_USER_PROTOCOL_F_MQ 0
56 #ifndef VHOST_USER_PROTOCOL_F_LOG_SHMFD
57 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
60 #ifndef VHOST_USER_PROTOCOL_F_RARP
61 #define VHOST_USER_PROTOCOL_F_RARP 2
64 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
65 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
68 #ifndef VHOST_USER_PROTOCOL_F_NET_MTU
69 #define VHOST_USER_PROTOCOL_F_NET_MTU 4
72 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_REQ
73 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
76 #ifndef VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
77 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
80 #ifndef VHOST_USER_PROTOCOL_F_PAGEFAULT
81 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
84 #ifndef VHOST_USER_PROTOCOL_F_CONFIG
85 #define VHOST_USER_PROTOCOL_F_CONFIG 9
88 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD
89 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
92 #ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
93 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
97 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
98 #define VHOST_USER_F_PROTOCOL_FEATURES 30
107 uint64_t guest_phys_addr;
108 uint64_t guest_user_addr;
109 uint64_t host_user_addr;
124 struct rte_vhost_vring {
125 struct vring_desc *desc;
126 struct vring_avail *avail;
127 struct vring_used *used;
128 uint64_t log_guest_addr;
154 int (*new_connection)(
int vid);
155 void (*destroy_connection)(
int vid);
182 for (i = 0; i < mem->nregions; i++) {
183 reg = &mem->regions[i];
184 if (gpa >= reg->guest_phys_addr &&
185 gpa < reg->guest_phys_addr + reg->size) {
186 return gpa - reg->guest_phys_addr +
212 uint64_t gpa, uint64_t *len)
217 for (i = 0; i < mem->nregions; i++) {
218 r = &mem->regions[i];
219 if (gpa >= r->guest_phys_addr &&
220 gpa < r->guest_phys_addr + r->size) {
222 if (
unlikely(*len > r->guest_phys_addr + r->size - gpa))
223 *len = r->guest_phys_addr + r->size - gpa;
225 return gpa - r->guest_phys_addr +
234 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL))
275 uint64_t offset, uint64_t len);
277 int rte_vhost_enable_guest_notification(
int vid, uint16_t queue_id,
int enable);
286 int rte_vhost_driver_unregister(
const char *path);
298 int __rte_experimental
309 int __rte_experimental
320 int __rte_experimental
388 int __rte_experimental
390 uint64_t *protocol_features);
402 int __rte_experimental
418 int rte_vhost_driver_callback_register(
const char *path,
537 struct rte_mbuf **pkts, uint16_t count);
588 struct rte_vhost_vring *vring);
627 int __rte_experimental
644 int __rte_experimental
646 uint16_t *last_avail_idx, uint16_t *last_used_idx);
662 int __rte_experimental
664 uint16_t last_avail_idx, uint16_t last_used_idx);
674 int __rte_experimental
static __rte_deprecated __rte_always_inline uint64_t rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa)
int rte_vhost_driver_start(const char *path)
#define __rte_always_inline
int rte_vhost_driver_register(const char *path, uint64_t flags)
uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id)
int rte_vhost_driver_disable_features(const char *path, uint64_t features)
void rte_vhost_log_used_vring(int vid, uint16_t vring_idx, uint64_t offset, uint64_t len)
int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, struct rte_vhost_vring *vring)
uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id, struct rte_mbuf **pkts, uint16_t count)
__rte_deprecated uint32_t rte_vhost_get_queue_num(int vid)
int __rte_experimental rte_vhost_get_vring_base(int vid, uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx)
int rte_vhost_get_mtu(int vid, uint16_t *mtu)
void(* destroy_device)(int vid)
int __rte_experimental rte_vhost_set_vring_base(int vid, uint16_t queue_id, uint16_t last_avail_idx, uint16_t last_used_idx)
static __rte_always_inline uint64_t rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem, uint64_t gpa, uint64_t *len)
uint16_t rte_vhost_get_vring_num(int vid)
int rte_vhost_get_numa_node(int vid)
int(* features_changed)(int vid, uint64_t features)
int __rte_experimental rte_vhost_driver_detach_vdpa_device(const char *path)
int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
int rte_vhost_vring_call(int vid, uint16_t vring_idx)
int rte_vhost_get_negotiated_features(int vid, uint64_t *features)
uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid)
int(* new_device)(int vid)
int __rte_experimental rte_vhost_get_vdpa_device_id(int vid)
uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
int __rte_experimental rte_vhost_driver_get_protocol_features(const char *path, uint64_t *protocol_features)
int __rte_experimental rte_vhost_get_log_base(int vid, uint64_t *log_base, uint64_t *log_size)
int rte_vhost_driver_get_features(const char *path, uint64_t *features)
int rte_vhost_driver_set_features(const char *path, uint64_t features)
int __rte_experimental rte_vhost_driver_attach_vdpa_device(const char *path, int did)
int(* vring_state_changed)(int vid, uint16_t queue_id, int enable)
int rte_vhost_get_ifname(int vid, char *buf, size_t len)
int __rte_experimental rte_vhost_driver_get_vdpa_device_id(const char *path)
int __rte_experimental rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num)
int rte_vhost_driver_enable_features(const char *path, uint64_t features)
void rte_vhost_log_write(int vid, uint64_t addr, uint64_t len)