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