15 #include <sys/eventfd.h>
25 #include <linux/vhost.h>
26 #include <linux/virtio_ring.h>
27 #include <linux/virtio_net.h>
29 #define RTE_VHOST_USER_CLIENT (1ULL << 0)
30 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1)
31 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2)
32 #define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3)
33 #define RTE_VHOST_USER_POSTCOPY_SUPPORT (1ULL << 4)
35 #define RTE_VHOST_USER_EXTBUF_SUPPORT (1ULL << 5)
37 #define RTE_VHOST_USER_LINEARBUF_SUPPORT (1ULL << 6)
38 #define RTE_VHOST_USER_ASYNC_COPY (1ULL << 7)
41 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE
42 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
45 #ifndef VIRTIO_NET_F_MQ
46 #define VIRTIO_NET_F_MQ 22
49 #ifndef VIRTIO_NET_F_MTU
50 #define VIRTIO_NET_F_MTU 3
53 #ifndef VIRTIO_F_ANY_LAYOUT
54 #define VIRTIO_F_ANY_LAYOUT 27
58 #ifndef VHOST_USER_PROTOCOL_F_MQ
59 #define VHOST_USER_PROTOCOL_F_MQ 0
62 #ifndef VHOST_USER_PROTOCOL_F_LOG_SHMFD
63 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
66 #ifndef VHOST_USER_PROTOCOL_F_RARP
67 #define VHOST_USER_PROTOCOL_F_RARP 2
70 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
71 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
74 #ifndef VHOST_USER_PROTOCOL_F_NET_MTU
75 #define VHOST_USER_PROTOCOL_F_NET_MTU 4
78 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_REQ
79 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
82 #ifndef VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
83 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
86 #ifndef VHOST_USER_PROTOCOL_F_PAGEFAULT
87 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
90 #ifndef VHOST_USER_PROTOCOL_F_CONFIG
91 #define VHOST_USER_PROTOCOL_F_CONFIG 9
94 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD
95 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
98 #ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
99 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
102 #ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD
103 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12
106 #ifndef VHOST_USER_PROTOCOL_F_STATUS
107 #define VHOST_USER_PROTOCOL_F_STATUS 16
111 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
112 #define VHOST_USER_F_PROTOCOL_FEATURES 30
122 uint64_t guest_phys_addr;
123 uint64_t guest_user_addr;
124 uint64_t host_user_addr;
139 struct rte_vhost_inflight_desc_split {
146 struct rte_vhost_inflight_info_split {
150 uint16_t last_inflight_io;
152 struct rte_vhost_inflight_desc_split desc[0];
155 struct rte_vhost_inflight_desc_packed {
168 struct rte_vhost_inflight_info_packed {
173 uint16_t old_free_head;
175 uint16_t old_used_idx;
176 uint8_t used_wrap_counter;
177 uint8_t old_used_wrap_counter;
179 struct rte_vhost_inflight_desc_packed desc[0];
182 struct rte_vhost_resubmit_desc {
187 struct rte_vhost_resubmit_info {
188 struct rte_vhost_resubmit_desc *resubmit_list;
189 uint16_t resubmit_num;
192 struct rte_vhost_ring_inflight {
194 struct rte_vhost_inflight_info_split *inflight_split;
195 struct rte_vhost_inflight_info_packed *inflight_packed;
198 struct rte_vhost_resubmit_info *resubmit_inflight;
201 struct rte_vhost_vring {
203 struct vring_desc *desc;
204 struct vring_packed_desc *desc_packed;
207 struct vring_avail *avail;
208 struct vring_packed_desc_event *driver_event;
211 struct vring_used *used;
212 struct vring_packed_desc_event *device_event;
214 uint64_t log_guest_addr;
228 RTE_VHOST_MSG_RESULT_ERR = -1,
230 RTE_VHOST_MSG_RESULT_OK = 0,
232 RTE_VHOST_MSG_RESULT_REPLY = 1,
234 RTE_VHOST_MSG_RESULT_NOT_HANDLED,
280 int (*new_connection)(
int vid);
281 void (*destroy_connection)(
int vid);
316 for (i = 0; i < mem->nregions; i++) {
317 reg = &mem->regions[i];
318 if (gpa >= reg->guest_phys_addr &&
319 gpa < reg->guest_phys_addr + reg->size) {
320 return gpa - reg->guest_phys_addr +
347 uint64_t gpa, uint64_t *len)
352 for (i = 0; i < mem->nregions; i++) {
353 r = &mem->regions[i];
354 if (gpa >= r->guest_phys_addr &&
355 gpa < r->guest_phys_addr + r->size) {
357 if (
unlikely(*len > r->guest_phys_addr + r->size - gpa))
358 *len = r->guest_phys_addr + r->size - gpa;
360 return gpa - r->guest_phys_addr +
369 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL))
410 uint64_t offset, uint64_t len);
412 int rte_vhost_enable_guest_notification(
int vid, uint16_t queue_id,
int enable);
421 int rte_vhost_driver_unregister(
const char *path);
530 uint64_t protocol_features);
545 uint64_t *protocol_features);
574 int rte_vhost_driver_callback_register(
const char *path,
693 struct rte_mbuf **pkts, uint16_t count);
744 struct rte_vhost_vring *vring);
761 struct rte_vhost_ring_inflight *vring);
804 uint16_t head, uint16_t last, uint16_t *inflight_entry);
821 uint16_t vring_idx, uint16_t idx);
841 uint16_t vring_idx, uint16_t head);
860 uint16_t last_used_idx, uint16_t idx);
937 uint16_t *last_avail_idx, uint16_t *last_used_idx);
960 uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx);
979 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)
__rte_experimental int rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, uint16_t idx)
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)
__rte_experimental int rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx, uint16_t last_used_idx, uint16_t idx)
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)
__rte_experimental struct rte_vdpa_device * rte_vhost_driver_get_vdpa_device(const char *path)
__rte_experimental int rte_vhost_set_last_inflight_io_packed(int vid, uint16_t vring_idx, uint16_t head)
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)
void(* guest_notified)(int vid)
__rte_experimental int rte_vhost_slave_config_change(int vid, bool need_reply)
__rte_experimental int rte_vhost_driver_set_protocol_features(const char *path, uint64_t protocol_features)
void(* destroy_device)(int vid)
__rte_experimental struct rte_vdpa_device * rte_vhost_get_vdpa_device(int vid)
__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)
struct rte_vdpa_dev_ops * ops
static __rte_experimental __rte_always_inline uint64_t rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem, uint64_t gpa, uint64_t *len)
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_driver_attach_vdpa_device(const char *path, struct rte_vdpa_device *dev)
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_set_inflight_desc_packed(int vid, uint16_t vring_idx, uint16_t head, uint16_t last, uint16_t *inflight_entry)
uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid)
int(* new_device)(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)
__rte_experimental int rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx, uint16_t head)
__rte_experimental int rte_vhost_driver_get_protocol_features(const char *path, uint64_t *protocol_features)
__rte_experimental int rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx, struct rte_vhost_ring_inflight *vring)
__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)
__rte_experimental int rte_vhost_get_vring_base_from_inflight(int vid, uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx)
__rte_experimental int rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx, uint16_t idx)
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)