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