14 #include <sys/eventfd.h> 25 #include <linux/vhost.h> 26 #include <linux/virtio_ring.h> 27 #include <linux/virtio_net.h> 30 #define RTE_VHOST_USER_CLIENT (1ULL << 0) 31 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1) 32 #define RTE_VHOST_USER_DEQUEUE_ZERO_COPY (1ULL << 2) 33 #define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3) 34 #define RTE_VHOST_USER_POSTCOPY_SUPPORT (1ULL << 4) 36 #define RTE_VHOST_USER_EXTBUF_SUPPORT (1ULL << 5) 38 #define RTE_VHOST_USER_LINEARBUF_SUPPORT (1ULL << 6) 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 107 #ifndef VHOST_USER_F_PROTOCOL_FEATURES 108 #define VHOST_USER_F_PROTOCOL_FEATURES 30 117 uint64_t guest_phys_addr;
118 uint64_t guest_user_addr;
119 uint64_t host_user_addr;
134 struct rte_vhost_inflight_desc_split {
141 struct rte_vhost_inflight_info_split {
145 uint16_t last_inflight_io;
147 struct rte_vhost_inflight_desc_split desc[0];
150 struct rte_vhost_inflight_desc_packed {
163 struct rte_vhost_inflight_info_packed {
168 uint16_t old_free_head;
170 uint16_t old_used_idx;
171 uint8_t used_wrap_counter;
172 uint8_t old_used_wrap_counter;
174 struct rte_vhost_inflight_desc_packed desc[0];
177 struct rte_vhost_resubmit_desc {
182 struct rte_vhost_resubmit_info {
183 struct rte_vhost_resubmit_desc *resubmit_list;
184 uint16_t resubmit_num;
187 struct rte_vhost_ring_inflight {
189 struct rte_vhost_inflight_info_split *inflight_split;
190 struct rte_vhost_inflight_info_packed *inflight_packed;
193 struct rte_vhost_resubmit_info *resubmit_inflight;
196 struct rte_vhost_vring {
198 struct vring_desc *desc;
199 struct vring_packed_desc *desc_packed;
202 struct vring_avail *avail;
203 struct vring_packed_desc_event *driver_event;
206 struct vring_used *used;
207 struct vring_packed_desc_event *device_event;
209 uint64_t log_guest_addr;
223 RTE_VHOST_MSG_RESULT_ERR = -1,
225 RTE_VHOST_MSG_RESULT_OK = 0,
227 RTE_VHOST_MSG_RESULT_REPLY = 1,
229 RTE_VHOST_MSG_RESULT_NOT_HANDLED,
262 int (*new_device)(
int vid);
263 void (*destroy_device)(
int vid);
265 int (*vring_state_changed)(
int vid, uint16_t queue_id,
int enable);
273 int (*features_changed)(
int vid, uint64_t features);
275 int (*new_connection)(
int vid);
276 void (*destroy_connection)(
int vid);
284 void (*guest_notified)(
int vid);
311 for (i = 0; i < mem->nregions; i++) {
312 reg = &mem->regions[i];
313 if (gpa >= reg->guest_phys_addr &&
314 gpa < reg->guest_phys_addr + reg->size) {
315 return gpa - reg->guest_phys_addr +
342 uint64_t gpa, uint64_t *len)
347 for (i = 0; i < mem->nregions; i++) {
348 r = &mem->regions[i];
349 if (gpa >= r->guest_phys_addr &&
350 gpa < r->guest_phys_addr + r->size) {
352 if (
unlikely(*len > r->guest_phys_addr + r->size - gpa))
353 *len = r->guest_phys_addr + r->size - gpa;
355 return gpa - r->guest_phys_addr +
364 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL)) 405 uint64_t offset, uint64_t len);
407 int rte_vhost_enable_guest_notification(
int vid, uint16_t queue_id,
int enable);
416 int rte_vhost_driver_unregister(
const char *path);
524 uint64_t protocol_features);
539 uint64_t *protocol_features);
568 int rte_vhost_driver_callback_register(
const char *path,
687 struct rte_mbuf **pkts, uint16_t count);
738 struct rte_vhost_vring *vring);
755 struct rte_vhost_ring_inflight *vring);
798 uint16_t head, uint16_t last, uint16_t *inflight_entry);
815 uint16_t vring_idx, uint16_t idx);
835 uint16_t vring_idx, uint16_t head);
854 uint16_t last_used_idx, uint16_t idx);
931 uint16_t *last_avail_idx, uint16_t *last_used_idx);
954 uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx);
973 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 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)
__rte_experimental int rte_vhost_driver_set_protocol_features(const char *path, uint64_t protocol_features)
__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)
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)
__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_set_inflight_desc_packed(int vid, uint16_t vring_idx, uint16_t head, uint16_t last, uint16_t *inflight_entry)
__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)
__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_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 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)