15 #include <sys/eventfd.h> 26 #include <linux/vhost.h> 27 #include <linux/virtio_ring.h> 28 #include <linux/virtio_net.h> 31 #define RTE_VHOST_USER_CLIENT (1ULL << 0) 32 #define RTE_VHOST_USER_NO_RECONNECT (1ULL << 1) 33 #define RTE_VHOST_USER_RESERVED_1 (1ULL << 2) 34 #define RTE_VHOST_USER_IOMMU_SUPPORT (1ULL << 3) 35 #define RTE_VHOST_USER_POSTCOPY_SUPPORT (1ULL << 4) 37 #define RTE_VHOST_USER_EXTBUF_SUPPORT (1ULL << 5) 39 #define RTE_VHOST_USER_LINEARBUF_SUPPORT (1ULL << 6) 40 #define RTE_VHOST_USER_ASYNC_COPY (1ULL << 7) 41 #define RTE_VHOST_USER_NET_COMPLIANT_OL_FLAGS (1ULL << 8) 42 #define RTE_VHOST_USER_NET_STATS_ENABLE (1ULL << 9) 45 #ifndef VIRTIO_NET_F_GUEST_ANNOUNCE 46 #define VIRTIO_NET_F_GUEST_ANNOUNCE 21 49 #ifndef VIRTIO_NET_F_MQ 50 #define VIRTIO_NET_F_MQ 22 53 #ifndef VIRTIO_NET_F_MTU 54 #define VIRTIO_NET_F_MTU 3 57 #ifndef VIRTIO_F_ANY_LAYOUT 58 #define VIRTIO_F_ANY_LAYOUT 27 62 #ifndef VHOST_USER_PROTOCOL_F_MQ 63 #define VHOST_USER_PROTOCOL_F_MQ 0 66 #ifndef VHOST_USER_PROTOCOL_F_LOG_SHMFD 67 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 70 #ifndef VHOST_USER_PROTOCOL_F_RARP 71 #define VHOST_USER_PROTOCOL_F_RARP 2 74 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK 75 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 78 #ifndef VHOST_USER_PROTOCOL_F_NET_MTU 79 #define VHOST_USER_PROTOCOL_F_NET_MTU 4 82 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_REQ 83 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 86 #ifndef VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 87 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7 90 #ifndef VHOST_USER_PROTOCOL_F_PAGEFAULT 91 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 94 #ifndef VHOST_USER_PROTOCOL_F_CONFIG 95 #define VHOST_USER_PROTOCOL_F_CONFIG 9 98 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 99 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 102 #ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 103 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11 106 #ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 107 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 110 #ifndef VHOST_USER_PROTOCOL_F_STATUS 111 #define VHOST_USER_PROTOCOL_F_STATUS 16 115 #ifndef VHOST_USER_F_PROTOCOL_FEATURES 116 #define VHOST_USER_F_PROTOCOL_FEATURES 30 119 #define RTE_MAX_VHOST_DEVICE 1024 121 #define RTE_VHOST_VDPA_DEVICE_TYPE_NET 0 122 #define RTE_VHOST_VDPA_DEVICE_TYPE_BLK 1 124 struct rte_vdpa_device;
131 uint64_t guest_phys_addr;
132 uint64_t guest_user_addr;
133 uint64_t host_user_addr;
148 struct rte_vhost_inflight_desc_split {
155 struct rte_vhost_inflight_info_split {
159 uint16_t last_inflight_io;
161 struct rte_vhost_inflight_desc_split desc[];
164 struct rte_vhost_inflight_desc_packed {
177 struct rte_vhost_inflight_info_packed {
182 uint16_t old_free_head;
184 uint16_t old_used_idx;
185 uint8_t used_wrap_counter;
186 uint8_t old_used_wrap_counter;
188 struct rte_vhost_inflight_desc_packed desc[];
191 struct rte_vhost_resubmit_desc {
196 struct rte_vhost_resubmit_info {
197 struct rte_vhost_resubmit_desc *resubmit_list;
198 uint16_t resubmit_num;
201 struct rte_vhost_ring_inflight {
203 struct rte_vhost_inflight_info_split *inflight_split;
204 struct rte_vhost_inflight_info_packed *inflight_packed;
207 struct rte_vhost_resubmit_info *resubmit_inflight;
210 struct rte_vhost_vring {
212 struct vring_desc *desc;
213 struct vring_packed_desc *desc_packed;
216 struct vring_avail *avail;
217 struct vring_packed_desc_event *driver_event;
220 struct vring_used *used;
221 struct vring_packed_desc_event *device_event;
223 uint64_t log_guest_addr;
237 RTE_VHOST_MSG_RESULT_ERR = -1,
239 RTE_VHOST_MSG_RESULT_OK = 0,
241 RTE_VHOST_MSG_RESULT_REPLY = 1,
243 RTE_VHOST_MSG_RESULT_NOT_HANDLED,
276 int (*new_device)(
int vid);
277 void (*destroy_device)(
int vid);
279 int (*vring_state_changed)(
int vid, uint16_t queue_id,
int enable);
287 int (*features_changed)(
int vid, uint64_t features);
289 int (*new_connection)(
int vid);
290 void (*destroy_connection)(
int vid);
298 void (*guest_notified)(
int vid);
329 #define RTE_VHOST_STATS_NAME_SIZE 64 376 for (i = 0; i < mem->nregions; i++) {
377 reg = &mem->regions[i];
378 if (gpa >= reg->guest_phys_addr &&
379 gpa < reg->guest_phys_addr + reg->size) {
380 return gpa - reg->guest_phys_addr +
406 uint64_t gpa, uint64_t *len)
411 for (i = 0; i < mem->nregions; i++) {
412 r = &mem->regions[i];
413 if (gpa >= r->guest_phys_addr &&
414 gpa < r->guest_phys_addr + r->size) {
416 if (
unlikely(*len > r->guest_phys_addr + r->size - gpa))
417 *len = r->guest_phys_addr + r->size - gpa;
419 return gpa - r->guest_phys_addr +
428 #define RTE_VHOST_NEED_LOG(features) ((features) & (1ULL << VHOST_F_LOG_ALL)) 469 uint64_t offset, uint64_t len);
471 int rte_vhost_enable_guest_notification(
int vid, uint16_t queue_id,
int enable);
480 int rte_vhost_driver_unregister(
const char *path);
494 struct rte_vdpa_device *dev);
515 struct rte_vdpa_device *
599 uint64_t protocol_features);
613 uint64_t *protocol_features);
653 uint64_t *protocol_features);
656 int rte_vhost_driver_callback_register(
const char *path,
775 struct rte_mbuf **pkts, uint16_t count);
826 struct rte_vhost_vring *vring);
842 struct rte_vhost_ring_inflight *vring);
883 uint16_t head, uint16_t last, uint16_t *inflight_entry);
899 uint16_t vring_idx, uint16_t idx);
918 uint16_t vring_idx, uint16_t head);
936 uint16_t last_used_idx, uint16_t idx);
1027 uint16_t *last_avail_idx, uint16_t *last_used_idx);
1049 uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx);
1067 uint16_t last_avail_idx, uint16_t last_used_idx);
1093 struct rte_vdpa_device *
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
__rte_experimental int rte_vhost_get_negotiated_protocol_features(int vid, uint64_t *protocol_features)
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)
struct rte_vdpa_device * rte_vhost_get_vdpa_device(int vid)
void rte_vhost_log_used_vring(int vid, uint16_t vring_idx, uint64_t offset, uint64_t len)
#define RTE_VHOST_STATS_NAME_SIZE
int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx, struct rte_vhost_vring *vring)
int rte_vhost_set_inflight_desc_packed(int vid, uint16_t vring_idx, uint16_t head, uint16_t last, uint16_t *inflight_entry)
int rte_vhost_clr_inflight_desc_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)
int rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx, struct rte_vhost_ring_inflight *vring)
int rte_vhost_driver_get_protocol_features(const char *path, uint64_t *protocol_features)
int rte_vhost_set_last_inflight_io_packed(int vid, uint16_t vring_idx, uint16_t head)
int rte_vhost_get_mtu(int vid, uint16_t *mtu)
int rte_vhost_driver_detach_vdpa_device(const char *path)
int rte_vhost_driver_set_protocol_features(const char *path, uint64_t protocol_features)
__rte_experimental int rte_vhost_slave_config_change(int vid, bool need_reply)
__rte_experimental int rte_vhost_vring_stats_get(int vid, uint16_t queue_id, struct rte_vhost_stat *stats, unsigned int n)
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_extern_callback_register(int vid, struct rte_vhost_user_extern_ops const *const ops, void *ctx)
__rte_experimental int rte_vhost_get_monitor_addr(int vid, uint16_t queue_id, struct rte_vhost_power_monitor_cond *pmc)
int rte_vhost_get_numa_node(int vid)
int rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx, uint16_t idx)
int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem)
int rte_vhost_driver_attach_vdpa_device(const char *path, struct rte_vdpa_device *dev)
__rte_experimental int rte_vhost_driver_get_vdpa_dev_type(const char *path, uint32_t *type)
int rte_vhost_set_last_inflight_io_split(int vid, uint16_t vring_idx, uint16_t idx)
int rte_vhost_vring_call(int vid, uint16_t vring_idx)
int rte_vhost_get_negotiated_features(int vid, uint64_t *features)
struct rte_vdpa_device * rte_vhost_driver_get_vdpa_device(const char *path)
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_clr_inflight_desc_split(int vid, uint16_t vring_idx, uint16_t last_used_idx, uint16_t idx)
int rte_vhost_get_log_base(int vid, uint64_t *log_base, uint64_t *log_size)
uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid)
__rte_experimental int rte_vhost_vring_stats_reset(int vid, uint16_t queue_id)
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_vhost_get_vring_base(int vid, uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx)
int rte_vhost_driver_get_features(const char *path, uint64_t *features)
__rte_experimental int rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, struct rte_vhost_stat_name *name, unsigned int size)
int rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num)
int rte_vhost_driver_set_features(const char *path, uint64_t features)
int rte_vhost_get_ifname(int vid, char *buf, size_t len)
int rte_vhost_get_vring_base_from_inflight(int vid, uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_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)