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