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