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