vhost: fix virtqueue not accessible
[dpdk.git] / lib / librte_vhost / rte_vhost.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #ifndef _RTE_VHOST_H_
6 #define _RTE_VHOST_H_
7
8 /**
9  * @file
10  * Interface to vhost-user
11  */
12
13 #include <stdint.h>
14 #include <sys/eventfd.h>
15
16 #include <rte_memory.h>
17 #include <rte_mempool.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /* These are not C++-aware. */
24 #include <linux/vhost.h>
25 #include <linux/virtio_ring.h>
26 #include <linux/virtio_net.h>
27
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)
33 /* support mbuf with external buffer attached */
34 #define RTE_VHOST_USER_EXTBUF_SUPPORT   (1ULL << 5)
35 /* support only linear buffers (no chained mbufs) */
36 #define RTE_VHOST_USER_LINEARBUF_SUPPORT        (1ULL << 6)
37
38 /** Protocol features. */
39 #ifndef VHOST_USER_PROTOCOL_F_MQ
40 #define VHOST_USER_PROTOCOL_F_MQ        0
41 #endif
42
43 #ifndef VHOST_USER_PROTOCOL_F_LOG_SHMFD
44 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1
45 #endif
46
47 #ifndef VHOST_USER_PROTOCOL_F_RARP
48 #define VHOST_USER_PROTOCOL_F_RARP      2
49 #endif
50
51 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
52 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
53 #endif
54
55 #ifndef VHOST_USER_PROTOCOL_F_NET_MTU
56 #define VHOST_USER_PROTOCOL_F_NET_MTU   4
57 #endif
58
59 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_REQ
60 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
61 #endif
62
63 #ifndef VHOST_USER_PROTOCOL_F_CRYPTO_SESSION
64 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
65 #endif
66
67 #ifndef VHOST_USER_PROTOCOL_F_PAGEFAULT
68 #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8
69 #endif
70
71 #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD
72 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10
73 #endif
74
75 #ifndef VHOST_USER_PROTOCOL_F_HOST_NOTIFIER
76 #define VHOST_USER_PROTOCOL_F_HOST_NOTIFIER 11
77 #endif
78
79 #ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD
80 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12
81 #endif
82
83 /** Indicate whether protocol features negotiation is supported. */
84 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
85 #define VHOST_USER_F_PROTOCOL_FEATURES  30
86 #endif
87
88 /**
89  * Information relating to memory regions including offsets to
90  * addresses in QEMUs memory file.
91  */
92 struct rte_vhost_mem_region {
93         uint64_t guest_phys_addr;
94         uint64_t guest_user_addr;
95         uint64_t host_user_addr;
96         uint64_t size;
97         void     *mmap_addr;
98         uint64_t mmap_size;
99         int fd;
100 };
101
102 /**
103  * Memory structure includes region and mapping information.
104  */
105 struct rte_vhost_memory {
106         uint32_t nregions;
107         struct rte_vhost_mem_region regions[];
108 };
109
110 struct rte_vhost_inflight_desc_split {
111         uint8_t inflight;
112         uint8_t padding[5];
113         uint16_t next;
114         uint64_t counter;
115 };
116
117 struct rte_vhost_inflight_info_split {
118         uint64_t features;
119         uint16_t version;
120         uint16_t desc_num;
121         uint16_t last_inflight_io;
122         uint16_t used_idx;
123         struct rte_vhost_inflight_desc_split desc[0];
124 };
125
126 struct rte_vhost_inflight_desc_packed {
127         uint8_t inflight;
128         uint8_t padding;
129         uint16_t next;
130         uint16_t last;
131         uint16_t num;
132         uint64_t counter;
133         uint16_t id;
134         uint16_t flags;
135         uint32_t len;
136         uint64_t addr;
137 };
138
139 struct rte_vhost_inflight_info_packed {
140         uint64_t features;
141         uint16_t version;
142         uint16_t desc_num;
143         uint16_t free_head;
144         uint16_t old_free_head;
145         uint16_t used_idx;
146         uint16_t old_used_idx;
147         uint8_t used_wrap_counter;
148         uint8_t old_used_wrap_counter;
149         uint8_t padding[7];
150         struct rte_vhost_inflight_desc_packed desc[0];
151 };
152
153 struct rte_vhost_resubmit_desc {
154         uint16_t index;
155         uint64_t counter;
156 };
157
158 struct rte_vhost_resubmit_info {
159         struct rte_vhost_resubmit_desc *resubmit_list;
160         uint16_t resubmit_num;
161 };
162
163 struct rte_vhost_ring_inflight {
164         union {
165                 struct rte_vhost_inflight_info_split *inflight_split;
166                 struct rte_vhost_inflight_info_packed *inflight_packed;
167         };
168
169         struct rte_vhost_resubmit_info *resubmit_inflight;
170 };
171
172 struct rte_vhost_vring {
173         union {
174                 struct vring_desc *desc;
175                 struct vring_packed_desc *desc_packed;
176         };
177         union {
178                 struct vring_avail *avail;
179                 struct vring_packed_desc_event *driver_event;
180         };
181         union {
182                 struct vring_used *used;
183                 struct vring_packed_desc_event *device_event;
184         };
185         uint64_t                log_guest_addr;
186
187         /** Deprecated, use rte_vhost_vring_call() instead. */
188         int                     callfd;
189
190         int                     kickfd;
191         uint16_t                size;
192 };
193
194 /**
195  * Possible results of the vhost user message handling callbacks
196  */
197 enum rte_vhost_msg_result {
198         /* Message handling failed */
199         RTE_VHOST_MSG_RESULT_ERR = -1,
200         /* Message handling successful */
201         RTE_VHOST_MSG_RESULT_OK =  0,
202         /* Message handling successful and reply prepared */
203         RTE_VHOST_MSG_RESULT_REPLY =  1,
204         /* Message not handled */
205         RTE_VHOST_MSG_RESULT_NOT_HANDLED,
206 };
207
208 /**
209  * Function prototype for the vhost backend to handle specific vhost user
210  * messages.
211  *
212  * @param vid
213  *  vhost device id
214  * @param msg
215  *  Message pointer.
216  * @return
217  *  RTE_VHOST_MSG_RESULT_OK on success,
218  *  RTE_VHOST_MSG_RESULT_REPLY on success with reply,
219  *  RTE_VHOST_MSG_RESULT_ERR on failure,
220  *  RTE_VHOST_MSG_RESULT_NOT_HANDLED if message was not handled.
221  */
222 typedef enum rte_vhost_msg_result (*rte_vhost_msg_handle)(int vid, void *msg);
223
224 /**
225  * Optional vhost user message handlers.
226  */
227 struct rte_vhost_user_extern_ops {
228         /* Called prior to the master message handling. */
229         rte_vhost_msg_handle pre_msg_handle;
230         /* Called after the master message handling. */
231         rte_vhost_msg_handle post_msg_handle;
232 };
233
234 /**
235  * Device and vring operations.
236  */
237 struct vhost_device_ops {
238         int (*new_device)(int vid);             /**< Add device. */
239         void (*destroy_device)(int vid);        /**< Remove device. */
240
241         int (*vring_state_changed)(int vid, uint16_t queue_id, int enable);     /**< triggered when a vring is enabled or disabled */
242
243         /**
244          * Features could be changed after the feature negotiation.
245          * For example, VHOST_F_LOG_ALL will be set/cleared at the
246          * start/end of live migration, respectively. This callback
247          * is used to inform the application on such change.
248          */
249         int (*features_changed)(int vid, uint64_t features);
250
251         int (*new_connection)(int vid);
252         void (*destroy_connection)(int vid);
253
254         /**
255          * This callback gets called each time a guest gets notified
256          * about waiting packets. This is the interrupt handling trough
257          * the eventfd_write(callfd), which can be used for counting these
258          * "slow" syscalls.
259          */
260         void (*guest_notified)(int vid);
261
262         void *reserved[1]; /**< Reserved for future extension */
263 };
264
265 /**
266  * Convert guest physical address to host virtual address
267  *
268  * This function is deprecated because unsafe.
269  * New rte_vhost_va_from_guest_pa() should be used instead to ensure
270  * guest physical ranges are fully and contiguously mapped into
271  * process virtual address space.
272  *
273  * @param mem
274  *  the guest memory regions
275  * @param gpa
276  *  the guest physical address for querying
277  * @return
278  *  the host virtual address on success, 0 on failure
279  */
280 __rte_deprecated
281 static __rte_always_inline uint64_t
282 rte_vhost_gpa_to_vva(struct rte_vhost_memory *mem, uint64_t gpa)
283 {
284         struct rte_vhost_mem_region *reg;
285         uint32_t i;
286
287         for (i = 0; i < mem->nregions; i++) {
288                 reg = &mem->regions[i];
289                 if (gpa >= reg->guest_phys_addr &&
290                     gpa <  reg->guest_phys_addr + reg->size) {
291                         return gpa - reg->guest_phys_addr +
292                                reg->host_user_addr;
293                 }
294         }
295
296         return 0;
297 }
298
299 /**
300  * Convert guest physical address to host virtual address safely
301  *
302  * This variant of rte_vhost_gpa_to_vva() takes care all the
303  * requested length is mapped and contiguous in process address
304  * space.
305  *
306  * @param mem
307  *  the guest memory regions
308  * @param gpa
309  *  the guest physical address for querying
310  * @param len
311  *  the size of the requested area to map, updated with actual size mapped
312  * @return
313  *  the host virtual address on success, 0 on failure
314  */
315 __rte_experimental
316 static __rte_always_inline uint64_t
317 rte_vhost_va_from_guest_pa(struct rte_vhost_memory *mem,
318                                                    uint64_t gpa, uint64_t *len)
319 {
320         struct rte_vhost_mem_region *r;
321         uint32_t i;
322
323         for (i = 0; i < mem->nregions; i++) {
324                 r = &mem->regions[i];
325                 if (gpa >= r->guest_phys_addr &&
326                     gpa <  r->guest_phys_addr + r->size) {
327
328                         if (unlikely(*len > r->guest_phys_addr + r->size - gpa))
329                                 *len = r->guest_phys_addr + r->size - gpa;
330
331                         return gpa - r->guest_phys_addr +
332                                r->host_user_addr;
333                 }
334         }
335         *len = 0;
336
337         return 0;
338 }
339
340 #define RTE_VHOST_NEED_LOG(features)    ((features) & (1ULL << VHOST_F_LOG_ALL))
341
342 /**
343  * Log the memory write start with given address.
344  *
345  * This function only need be invoked when the live migration starts.
346  * Therefore, we won't need call it at all in the most of time. For
347  * making the performance impact be minimum, it's suggested to do a
348  * check before calling it:
349  *
350  *        if (unlikely(RTE_VHOST_NEED_LOG(features)))
351  *                rte_vhost_log_write(vid, addr, len);
352  *
353  * @param vid
354  *  vhost device ID
355  * @param addr
356  *  the starting address for write (in guest physical address space)
357  * @param len
358  *  the length to write
359  */
360 void rte_vhost_log_write(int vid, uint64_t addr, uint64_t len);
361
362 /**
363  * Log the used ring update start at given offset.
364  *
365  * Same as rte_vhost_log_write, it's suggested to do a check before
366  * calling it:
367  *
368  *        if (unlikely(RTE_VHOST_NEED_LOG(features)))
369  *                rte_vhost_log_used_vring(vid, vring_idx, offset, len);
370  *
371  * @param vid
372  *  vhost device ID
373  * @param vring_idx
374  *  the vring index
375  * @param offset
376  *  the offset inside the used ring
377  * @param len
378  *  the length to write
379  */
380 void rte_vhost_log_used_vring(int vid, uint16_t vring_idx,
381                               uint64_t offset, uint64_t len);
382
383 int rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable);
384
385 /**
386  * Register vhost driver. path could be different for multiple
387  * instance support.
388  */
389 int rte_vhost_driver_register(const char *path, uint64_t flags);
390
391 /* Unregister vhost driver. This is only meaningful to vhost user. */
392 int rte_vhost_driver_unregister(const char *path);
393
394 /**
395  * Set the vdpa device id, enforce single connection per socket
396  *
397  * @param path
398  *  The vhost-user socket file path
399  * @param did
400  *  Device id
401  * @return
402  *  0 on success, -1 on failure
403  */
404 __rte_experimental
405 int
406 rte_vhost_driver_attach_vdpa_device(const char *path, int did);
407
408 /**
409  * Unset the vdpa device id
410  *
411  * @param path
412  *  The vhost-user socket file path
413  * @return
414  *  0 on success, -1 on failure
415  */
416 __rte_experimental
417 int
418 rte_vhost_driver_detach_vdpa_device(const char *path);
419
420 /**
421  * Get the device id
422  *
423  * @param path
424  *  The vhost-user socket file path
425  * @return
426  *  Device id, -1 on failure
427  */
428 __rte_experimental
429 int
430 rte_vhost_driver_get_vdpa_device_id(const char *path);
431
432 /**
433  * Set the feature bits the vhost-user driver supports.
434  *
435  * @param path
436  *  The vhost-user socket file path
437  * @param features
438  *  Supported features
439  * @return
440  *  0 on success, -1 on failure
441  */
442 int rte_vhost_driver_set_features(const char *path, uint64_t features);
443
444 /**
445  * Enable vhost-user driver features.
446  *
447  * Note that
448  * - the param features should be a subset of the feature bits provided
449  *   by rte_vhost_driver_set_features().
450  * - it must be invoked before vhost-user negotiation starts.
451  *
452  * @param path
453  *  The vhost-user socket file path
454  * @param features
455  *  Features to enable
456  * @return
457  *  0 on success, -1 on failure
458  */
459 int rte_vhost_driver_enable_features(const char *path, uint64_t features);
460
461 /**
462  * Disable vhost-user driver features.
463  *
464  * The two notes at rte_vhost_driver_enable_features() also apply here.
465  *
466  * @param path
467  *  The vhost-user socket file path
468  * @param features
469  *  Features to disable
470  * @return
471  *  0 on success, -1 on failure
472  */
473 int rte_vhost_driver_disable_features(const char *path, uint64_t features);
474
475 /**
476  * Get the feature bits before feature negotiation.
477  *
478  * @param path
479  *  The vhost-user socket file path
480  * @param features
481  *  A pointer to store the queried feature bits
482  * @return
483  *  0 on success, -1 on failure
484  */
485 int rte_vhost_driver_get_features(const char *path, uint64_t *features);
486
487 /**
488  * Set the protocol feature bits before feature negotiation.
489  *
490  * @param path
491  *  The vhost-user socket file path
492  * @param protocol_features
493  *  Supported protocol features
494  * @return
495  *  0 on success, -1 on failure
496  */
497 __rte_experimental
498 int
499 rte_vhost_driver_set_protocol_features(const char *path,
500                 uint64_t protocol_features);
501
502 /**
503  * Get the protocol feature bits before feature negotiation.
504  *
505  * @param path
506  *  The vhost-user socket file path
507  * @param protocol_features
508  *  A pointer to store the queried protocol feature bits
509  * @return
510  *  0 on success, -1 on failure
511  */
512 __rte_experimental
513 int
514 rte_vhost_driver_get_protocol_features(const char *path,
515                 uint64_t *protocol_features);
516
517 /**
518  * Get the queue number bits before feature negotiation.
519  *
520  * @param path
521  *  The vhost-user socket file path
522  * @param queue_num
523  *  A pointer to store the queried queue number bits
524  * @return
525  *  0 on success, -1 on failure
526  */
527 __rte_experimental
528 int
529 rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num);
530
531 /**
532  * Get the feature bits after negotiation
533  *
534  * @param vid
535  *  Vhost device ID
536  * @param features
537  *  A pointer to store the queried feature bits
538  * @return
539  *  0 on success, -1 on failure
540  */
541 int rte_vhost_get_negotiated_features(int vid, uint64_t *features);
542
543 /* Register callbacks. */
544 int rte_vhost_driver_callback_register(const char *path,
545         struct vhost_device_ops const * const ops);
546
547 /**
548  *
549  * Start the vhost-user driver.
550  *
551  * This function triggers the vhost-user negotiation.
552  *
553  * @param path
554  *  The vhost-user socket file path
555  * @return
556  *  0 on success, -1 on failure
557  */
558 int rte_vhost_driver_start(const char *path);
559
560 /**
561  * Get the MTU value of the device if set in QEMU.
562  *
563  * @param vid
564  *  virtio-net device ID
565  * @param mtu
566  *  The variable to store the MTU value
567  *
568  * @return
569  *  0: success
570  *  -EAGAIN: device not yet started
571  *  -ENOTSUP: device does not support MTU feature
572  */
573 int rte_vhost_get_mtu(int vid, uint16_t *mtu);
574
575 /**
576  * Get the numa node from which the virtio net device's memory
577  * is allocated.
578  *
579  * @param vid
580  *  vhost device ID
581  *
582  * @return
583  *  The numa node, -1 on failure
584  */
585 int rte_vhost_get_numa_node(int vid);
586
587 /**
588  * @deprecated
589  * Get the number of queues the device supports.
590  *
591  * Note this function is deprecated, as it returns a queue pair number,
592  * which is vhost specific. Instead, rte_vhost_get_vring_num should
593  * be used.
594  *
595  * @param vid
596  *  vhost device ID
597  *
598  * @return
599  *  The number of queues, 0 on failure
600  */
601 __rte_deprecated
602 uint32_t rte_vhost_get_queue_num(int vid);
603
604 /**
605  * Get the number of vrings the device supports.
606  *
607  * @param vid
608  *  vhost device ID
609  *
610  * @return
611  *  The number of vrings, 0 on failure
612  */
613 uint16_t rte_vhost_get_vring_num(int vid);
614
615 /**
616  * Get the virtio net device's ifname, which is the vhost-user socket
617  * file path.
618  *
619  * @param vid
620  *  vhost device ID
621  * @param buf
622  *  The buffer to stored the queried ifname
623  * @param len
624  *  The length of buf
625  *
626  * @return
627  *  0 on success, -1 on failure
628  */
629 int rte_vhost_get_ifname(int vid, char *buf, size_t len);
630
631 /**
632  * Get how many avail entries are left in the queue
633  *
634  * @param vid
635  *  vhost device ID
636  * @param queue_id
637  *  virtio queue index
638  *
639  * @return
640  *  num of avail entries left
641  */
642 uint16_t rte_vhost_avail_entries(int vid, uint16_t queue_id);
643
644 struct rte_mbuf;
645 struct rte_mempool;
646 /**
647  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
648  * be received from the physical port or from another virtual device. A packet
649  * count is returned to indicate the number of packets that were successfully
650  * added to the RX queue.
651  * @param vid
652  *  vhost device ID
653  * @param queue_id
654  *  virtio queue index in mq case
655  * @param pkts
656  *  array to contain packets to be enqueued
657  * @param count
658  *  packets num to be enqueued
659  * @return
660  *  num of packets enqueued
661  */
662 uint16_t rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
663         struct rte_mbuf **pkts, uint16_t count);
664
665 /**
666  * This function gets guest buffers from the virtio device TX virtqueue,
667  * construct host mbufs, copies guest buffer content to host mbufs and
668  * store them in pkts to be processed.
669  * @param vid
670  *  vhost device ID
671  * @param queue_id
672  *  virtio queue index in mq case
673  * @param mbuf_pool
674  *  mbuf_pool where host mbuf is allocated.
675  * @param pkts
676  *  array to contain packets to be dequeued
677  * @param count
678  *  packets num to be dequeued
679  * @return
680  *  num of packets dequeued
681  */
682 uint16_t rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
683         struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count);
684
685 /**
686  * Get guest mem table: a list of memory regions.
687  *
688  * An rte_vhost_vhost_memory object will be allocated internally, to hold the
689  * guest memory regions. Application should free it at destroy_device()
690  * callback.
691  *
692  * @param vid
693  *  vhost device ID
694  * @param mem
695  *  To store the returned mem regions
696  * @return
697  *  0 on success, -1 on failure
698  */
699 int rte_vhost_get_mem_table(int vid, struct rte_vhost_memory **mem);
700
701 /**
702  * Get guest vring info, including the vring address, vring size, etc.
703  *
704  * @param vid
705  *  vhost device ID
706  * @param vring_idx
707  *  vring index
708  * @param vring
709  *  the structure to hold the requested vring info
710  * @return
711  *  0 on success, -1 on failure
712  */
713 int rte_vhost_get_vhost_vring(int vid, uint16_t vring_idx,
714                               struct rte_vhost_vring *vring);
715
716 /**
717  * Get guest inflight vring info, including inflight ring and resubmit list.
718  *
719  * @param vid
720  *  vhost device ID
721  * @param vring_idx
722  *  vring index
723  * @param vring
724  *  the structure to hold the requested inflight vring info
725  * @return
726  *  0 on success, -1 on failure
727  */
728 __rte_experimental
729 int
730 rte_vhost_get_vhost_ring_inflight(int vid, uint16_t vring_idx,
731         struct rte_vhost_ring_inflight *vring);
732
733 /**
734  * Set split inflight descriptor.
735  *
736  * This function save descriptors that has been comsumed in available
737  * ring
738  *
739  * @param vid
740  *  vhost device ID
741  * @param vring_idx
742  *  vring index
743  * @param idx
744  *  inflight entry index
745  * @return
746  *  0 on success, -1 on failure
747  */
748 __rte_experimental
749 int
750 rte_vhost_set_inflight_desc_split(int vid, uint16_t vring_idx,
751         uint16_t idx);
752
753 /**
754  * Set packed inflight descriptor and get corresponding inflight entry
755  *
756  * This function save descriptors that has been comsumed
757  *
758  * @param vid
759  *  vhost device ID
760  * @param vring_idx
761  *  vring index
762  * @param head
763  *  head of descriptors
764  * @param last
765  *  last of descriptors
766  * @param inflight_entry
767  *  corresponding inflight entry
768  * @return
769  *  0 on success, -1 on failure
770  */
771 __rte_experimental
772 int
773 rte_vhost_set_inflight_desc_packed(int vid, uint16_t vring_idx,
774         uint16_t head, uint16_t last, uint16_t *inflight_entry);
775
776 /**
777  * Save the head of list that the last batch of used descriptors.
778  *
779  * @param vid
780  *  vhost device ID
781  * @param vring_idx
782  *  vring index
783  * @param idx
784  *  descriptor entry index
785  * @return
786  *  0 on success, -1 on failure
787  */
788 __rte_experimental
789 int
790 rte_vhost_set_last_inflight_io_split(int vid,
791         uint16_t vring_idx, uint16_t idx);
792
793 /**
794  * Update the inflight free_head, used_idx and used_wrap_counter.
795  *
796  * This function will update status first before updating descriptors
797  * to used
798  *
799  * @param vid
800  *  vhost device ID
801  * @param vring_idx
802  *  vring index
803  * @param head
804  *  head of descriptors
805  * @return
806  *  0 on success, -1 on failure
807  */
808 __rte_experimental
809 int
810 rte_vhost_set_last_inflight_io_packed(int vid,
811         uint16_t vring_idx, uint16_t head);
812
813 /**
814  * Clear the split inflight status.
815  *
816  * @param vid
817  *  vhost device ID
818  * @param vring_idx
819  *  vring index
820  * @param last_used_idx
821  *  last used idx of used ring
822  * @param idx
823  *  inflight entry index
824  * @return
825  *  0 on success, -1 on failure
826  */
827 __rte_experimental
828 int
829 rte_vhost_clr_inflight_desc_split(int vid, uint16_t vring_idx,
830         uint16_t last_used_idx, uint16_t idx);
831
832 /**
833  * Clear the packed inflight status.
834  *
835  * @param vid
836  *  vhost device ID
837  * @param vring_idx
838  *  vring index
839  * @param head
840  *  inflight entry index
841  * @return
842  *  0 on success, -1 on failure
843  */
844 __rte_experimental
845 int
846 rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx,
847         uint16_t head);
848
849 /**
850  * Notify the guest that used descriptors have been added to the vring.  This
851  * function acts as a memory barrier.
852  *
853  * @param vid
854  *  vhost device ID
855  * @param vring_idx
856  *  vring index
857  * @return
858  *  0 on success, -1 on failure
859  */
860 int rte_vhost_vring_call(int vid, uint16_t vring_idx);
861
862 /**
863  * Get vhost RX queue avail count.
864  *
865  * @param vid
866  *  vhost device ID
867  * @param qid
868  *  virtio queue index in mq case
869  * @return
870  *  num of desc available
871  */
872 uint32_t rte_vhost_rx_queue_count(int vid, uint16_t qid);
873
874 /**
875  * Get log base and log size of the vhost device
876  *
877  * @param vid
878  *  vhost device ID
879  * @param log_base
880  *  vhost log base
881  * @param log_size
882  *  vhost log size
883  * @return
884  *  0 on success, -1 on failure
885  */
886 __rte_experimental
887 int
888 rte_vhost_get_log_base(int vid, uint64_t *log_base, uint64_t *log_size);
889
890 /**
891  * Get last_avail/used_idx of the vhost virtqueue
892  *
893  * @param vid
894  *  vhost device ID
895  * @param queue_id
896  *  vhost queue index
897  * @param last_avail_idx
898  *  vhost last_avail_idx to get
899  * @param last_used_idx
900  *  vhost last_used_idx to get
901  * @return
902  *  0 on success, -1 on failure
903  */
904 __rte_experimental
905 int
906 rte_vhost_get_vring_base(int vid, uint16_t queue_id,
907                 uint16_t *last_avail_idx, uint16_t *last_used_idx);
908
909 /**
910  * Get last_avail/last_used of the vhost virtqueue
911  *
912  * This function is designed for the reconnection and it's specific for
913  * the packed ring as we can get the two parameters from the inflight
914  * queueregion
915  *
916  * @param vid
917  *  vhost device ID
918  * @param queue_id
919  *  vhost queue index
920  * @param last_avail_idx
921  *  vhost last_avail_idx to get
922  * @param last_used_idx
923  *  vhost last_used_idx to get
924  * @return
925  *  0 on success, -1 on failure
926  */
927 __rte_experimental
928 int
929 rte_vhost_get_vring_base_from_inflight(int vid,
930         uint16_t queue_id, uint16_t *last_avail_idx, uint16_t *last_used_idx);
931
932 /**
933  * Set last_avail/used_idx of the vhost virtqueue
934  *
935  * @param vid
936  *  vhost device ID
937  * @param queue_id
938  *  vhost queue index
939  * @param last_avail_idx
940  *  last_avail_idx to set
941  * @param last_used_idx
942  *  last_used_idx to set
943  * @return
944  *  0 on success, -1 on failure
945  */
946 __rte_experimental
947 int
948 rte_vhost_set_vring_base(int vid, uint16_t queue_id,
949                 uint16_t last_avail_idx, uint16_t last_used_idx);
950
951 /**
952  * Register external message handling callbacks
953  *
954  * @param vid
955  *  vhost device ID
956  * @param ops
957  *  virtio external callbacks to register
958  * @param ctx
959  *  additional context passed to the callbacks
960  * @return
961  *  0 on success, -1 on failure
962  */
963 __rte_experimental
964 int
965 rte_vhost_extern_callback_register(int vid,
966                 struct rte_vhost_user_extern_ops const * const ops, void *ctx);
967
968 /**
969  * Get vdpa device id for vhost device.
970  *
971  * @param vid
972  *  vhost device id
973  * @return
974  *  device id
975  */
976 __rte_experimental
977 int
978 rte_vhost_get_vdpa_device_id(int vid);
979
980 #ifdef __cplusplus
981 }
982 #endif
983
984 #endif /* _RTE_VHOST_H_ */