vhost: make some vDPA callbacks mandatory
[dpdk.git] / lib / librte_vhost / rte_vdpa_dev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _RTE_VDPA_H_DEV_
6 #define _RTE_VDPA_H_DEV_
7
8 #include <stdbool.h>
9
10 #include "rte_vhost.h"
11
12 #define RTE_VHOST_QUEUE_ALL UINT16_MAX
13
14 /**
15  * vdpa device operations
16  */
17 struct rte_vdpa_dev_ops {
18         /** Get capabilities of this device (Mandatory) */
19         int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
20
21         /** Get supported features of this device (Mandatory) */
22         int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
23
24         /** Get supported protocol features of this device (Mandatory) */
25         int (*get_protocol_features)(struct rte_vdpa_device *dev,
26                         uint64_t *protocol_features);
27
28         /** Driver configure the device (Mandatory) */
29         int (*dev_conf)(int vid);
30
31         /** Driver close the device (Mandatory) */
32         int (*dev_close)(int vid);
33
34         /** Enable/disable this vring (Mandatory) */
35         int (*set_vring_state)(int vid, int vring, int state);
36
37         /** Set features when changed (Mandatory) */
38         int (*set_features)(int vid);
39
40         /** Destination operations when migration done */
41         int (*migration_done)(int vid);
42
43         /** Get the vfio group fd */
44         int (*get_vfio_group_fd)(int vid);
45
46         /** Get the vfio device fd */
47         int (*get_vfio_device_fd)(int vid);
48
49         /** Get the notify area info of the queue */
50         int (*get_notify_area)(int vid, int qid,
51                         uint64_t *offset, uint64_t *size);
52
53         /** Get statistics name */
54         int (*get_stats_names)(struct rte_vdpa_device *dev,
55                         struct rte_vdpa_stat_name *stats_names,
56                         unsigned int size);
57
58         /** Get statistics of the queue */
59         int (*get_stats)(struct rte_vdpa_device *dev, int qid,
60                         struct rte_vdpa_stat *stats, unsigned int n);
61
62         /** Reset statistics of the queue */
63         int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
64
65         /** Reserved for future extension */
66         void *reserved[2];
67 };
68
69 /**
70  * vdpa device structure includes device address and device operations.
71  */
72 struct rte_vdpa_device {
73         TAILQ_ENTRY(rte_vdpa_device) next;
74         /** Generic device information */
75         struct rte_device *device;
76         /** vdpa device operations */
77         struct rte_vdpa_dev_ops *ops;
78 };
79
80 /**
81  * @warning
82  * @b EXPERIMENTAL: this API may change without prior notice
83  *
84  * Register a vdpa device
85  *
86  * @param rte_dev
87  *  the generic device pointer
88  * @param ops
89  *  the vdpa device operations
90  * @return
91  *  vDPA device pointer on success, NULL on failure
92  */
93 __rte_experimental
94 struct rte_vdpa_device *
95 rte_vdpa_register_device(struct rte_device *rte_dev,
96                 struct rte_vdpa_dev_ops *ops);
97
98 /**
99  * @warning
100  * @b EXPERIMENTAL: this API may change without prior notice
101  *
102  * Unregister a vdpa device
103  *
104  * @param dev
105  *  vDPA device pointer
106  * @return
107  *  device id on success, -1 on failure
108  */
109 __rte_experimental
110 int
111 rte_vdpa_unregister_device(struct rte_vdpa_device *dev);
112
113 /**
114  * @warning
115  * @b EXPERIMENTAL: this API may change without prior notice
116  *
117  * Enable/Disable host notifier mapping for a vdpa port.
118  *
119  * @param vid
120  *  vhost device id
121  * @param enable
122  *  true for host notifier map, false for host notifier unmap
123  * @param qid
124  *  vhost queue id, RTE_VHOST_QUEUE_ALL to configure all the device queues
125  * @return
126  *  0 on success, -1 on failure
127  */
128 __rte_experimental
129 int
130 rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable);
131
132 /**
133  * @warning
134  * @b EXPERIMENTAL: this API may change without prior notice
135  *
136  * Synchronize the used ring from mediated ring to guest, log dirty
137  * page for each writeable buffer, caller should handle the used
138  * ring logging before device stop.
139  *
140  * @param vid
141  *  vhost device id
142  * @param qid
143  *  vhost queue id
144  * @param vring_m
145  *  mediated virtio ring pointer
146  * @return
147  *  number of synced used entries on success, -1 on failure
148  */
149 __rte_experimental
150 int
151 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
152
153 #endif /* _RTE_VDPA_DEV_H_ */