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