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