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 VHOST_USER_PROTOCOL_F_MQ
36 #define VHOST_USER_PROTOCOL_F_MQ 0
39 #ifndef VHOST_USER_PROTOCOL_F_LOG_SHMFD
40 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
43 #ifndef VHOST_USER_PROTOCOL_F_RARP
44 #define VHOST_USER_PROTOCOL_F_RARP 2
47 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
48 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
51 #ifndef VHOST_USER_PROTOCOL_F_NET_MTU
52 #define VHOST_USER_PROTOCOL_F_NET_MTU 4
55 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_REQ
56 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
59 #ifndef VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
60 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
63 #ifndef VHOST_USER_PROTOCOL_F_PAGEFAULT
64 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
67 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD
68 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
71 #ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
72 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
76 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
77 #define VHOST_USER_F_PROTOCOL_FEATURES 30
85 uint64_t guest_phys_addr;
86 uint64_t guest_user_addr;
87 uint64_t host_user_addr;
102 struct rte_vhost_vring {
103 struct vring_desc *desc;
104 struct vring_avail *avail;
105 struct vring_used *used;
106 uint64_t log_guest_addr;
120 RTE_VHOST_MSG_RESULT_ERR = -1,
122 RTE_VHOST_MSG_RESULT_OK = 0,
124 RTE_VHOST_MSG_RESULT_REPLY = 1,
126 RTE_VHOST_MSG_RESULT_NOT_HANDLED,
172 int (*new_connection)(
int vid);
173 void (*destroy_connection)(
int vid);
200 for (i = 0; i < mem->nregions; i++) {
201 reg = &mem->regions[i];
202 if (gpa >= reg->guest_phys_addr &&
203 gpa < reg->guest_phys_addr + reg->size) {
204 return gpa - reg->guest_phys_addr +
230 uint64_t gpa, uint64_t *len)
235 for (i = 0; i < mem->nregions; i++) {
236 r = &mem->regions[i];
237 if (gpa >= r->guest_phys_addr &&
238 gpa < r->guest_phys_addr + r->size) {
240 if (
unlikely(*len > r->guest_phys_addr + r->size - gpa))
241 *len = r->guest_phys_addr + r->size - gpa;
243 return gpa - r->guest_phys_addr +
252 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL))
293 uint64_t offset, uint64_t len);
295 int rte_vhost_enable_guest_notification(
int vid, uint16_t queue_id,
int enable);
304 int rte_vhost_driver_unregister(
const char *path);
412 uint64_t protocol_features);
427 uint64_t *protocol_features);
456 int rte_vhost_driver_callback_register(
const char *path,
575 struct rte_mbuf **pkts, uint16_t count);
626 struct rte_vhost_vring *vring);
686 uint16_t *last_avail_idx, uint16_t *last_used_idx);
705 uint16_t last_avail_idx, uint16_t last_used_idx);
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)
__rte_experimental int rte_vhost_extern_callback_register(int vid, struct rte_vhost_user_extern_ops const *const ops, void *ctx)
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)
__rte_experimental int rte_vhost_get_vring_base(int vid, uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx)
__rte_experimental int rte_vhost_set_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)
__rte_experimental int rte_vhost_driver_set_protocol_features(const char *path, uint64_t protocol_features)
void(* destroy_device)(int vid)
static __rte_always_inline uint64_t rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem, uint64_t gpa, uint64_t *len)
__rte_experimental int rte_vhost_driver_detach_vdpa_device(const char *path)
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)
__rte_experimental int rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num)
int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
__rte_experimental int rte_vhost_get_vdpa_device_id(int vid)
int rte_vhost_vring_call(int vid, uint16_t vring_idx)
int rte_vhost_get_negotiated_features(int vid, uint64_t *features)
__rte_experimental int rte_vhost_driver_get_vdpa_device_id(const char *path)
uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid)
int(* new_device)(int vid)
__rte_experimental int rte_vhost_driver_attach_vdpa_device(const char *path, int did)
uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id, struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
__rte_experimental int rte_vhost_driver_get_protocol_features(const char *path, uint64_t *protocol_features)
__rte_experimental int 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(* vring_state_changed)(int vid, uint16_t queue_id, int enable)
int rte_vhost_get_ifname(int vid, char *buf, size_t len)
enum rte_vhost_msg_result(* rte_vhost_msg_handle)(int vid, void *msg)
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)