vhost: remove vDPA device count API
[dpdk.git] / lib / librte_vhost / rte_vdpa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _RTE_VDPA_H_
6 #define _RTE_VDPA_H_
7
8 /**
9  * @file
10  *
11  * Device specific vhost lib
12  */
13
14 #include <stdbool.h>
15
16 #include <rte_pci.h>
17 #include "rte_vhost.h"
18
19 #define MAX_VDPA_NAME_LEN 128
20
21 /** Maximum name length for statistics counters */
22 #define RTE_VDPA_STATS_NAME_SIZE 64
23
24 struct rte_vdpa_device;
25
26 /**
27  * A vDPA device statistic structure
28  *
29  * This structure is used by rte_vdpa_stats_get() to provide
30  * statistics from the HW vDPA device.
31  *
32  * It maps a name id, corresponding to an index in the array returned
33  * by rte_vdpa_get_stats_names, to a statistic value.
34  */
35 struct rte_vdpa_stat {
36         uint64_t id;        /**< The index in stats name array */
37         uint64_t value;     /**< The statistic counter value */
38 };
39
40 /**
41  * A name element for statistics
42  *
43  * An array of this structure is returned by rte_vdpa_get_stats_names
44  * It lists the names of extended statistics for a PMD. The rte_vdpa_stat
45  * structure references these names by their array index
46  */
47 struct rte_vdpa_stat_name {
48         char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */
49 };
50
51 /**
52  * vdpa device operations
53  */
54 struct rte_vdpa_dev_ops {
55         /** Get capabilities of this device */
56         int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
57
58         /** Get supported features of this device */
59         int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
60
61         /** Get supported protocol features of this device */
62         int (*get_protocol_features)(struct rte_vdpa_device *dev,
63                         uint64_t *protocol_features);
64
65         /** Driver configure/close the device */
66         int (*dev_conf)(int vid);
67         int (*dev_close)(int vid);
68
69         /** Enable/disable this vring */
70         int (*set_vring_state)(int vid, int vring, int state);
71
72         /** Set features when changed */
73         int (*set_features)(int vid);
74
75         /** Destination operations when migration done */
76         int (*migration_done)(int vid);
77
78         /** Get the vfio group fd */
79         int (*get_vfio_group_fd)(int vid);
80
81         /** Get the vfio device fd */
82         int (*get_vfio_device_fd)(int vid);
83
84         /** Get the notify area info of the queue */
85         int (*get_notify_area)(int vid, int qid,
86                         uint64_t *offset, uint64_t *size);
87
88         /** Get statistics name */
89         int (*get_stats_names)(struct rte_vdpa_device *dev,
90                         struct rte_vdpa_stat_name *stats_names,
91                         unsigned int size);
92
93         /** Get statistics of the queue */
94         int (*get_stats)(struct rte_vdpa_device *dev, int qid,
95                         struct rte_vdpa_stat *stats, unsigned int n);
96
97         /** Reset statistics of the queue */
98         int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
99
100         /** Reserved for future extension */
101         void *reserved[2];
102 };
103
104 /**
105  * vdpa device structure includes device address and device operations.
106  */
107 struct rte_vdpa_device {
108         TAILQ_ENTRY(rte_vdpa_device) next;
109         /** Generic device information */
110         struct rte_device *device;
111         /** vdpa device operations */
112         struct rte_vdpa_dev_ops *ops;
113 } __rte_cache_aligned;
114
115 /**
116  * @warning
117  * @b EXPERIMENTAL: this API may change without prior notice
118  *
119  * Register a vdpa device
120  *
121  * @param addr
122  *  the vdpa device address
123  * @param ops
124  *  the vdpa device operations
125  * @return
126  *  vDPA device pointer on success, NULL on failure
127  */
128 __rte_experimental
129 struct rte_vdpa_device *
130 rte_vdpa_register_device(struct rte_device *rte_dev,
131                 struct rte_vdpa_dev_ops *ops);
132
133 /**
134  * @warning
135  * @b EXPERIMENTAL: this API may change without prior notice
136  *
137  * Unregister a vdpa device
138  *
139  * @param did
140  *  vDPA device pointer
141  * @return
142  *  device id on success, -1 on failure
143  */
144 __rte_experimental
145 int
146 rte_vdpa_unregister_device(struct rte_vdpa_device *);
147
148 /**
149  * @warning
150  * @b EXPERIMENTAL: this API may change without prior notice
151  *
152  * Find the device id of a vdpa device from its name
153  *
154  * @param name
155  *  the vdpa device name
156  * @return
157  *  vDPA device pointer on success, NULL on failure
158  */
159 __rte_experimental
160 struct rte_vdpa_device *
161 rte_vdpa_find_device_by_name(const char *name);
162
163 /**
164  * @warning
165  * @b EXPERIMENTAL: this API may change without prior notice
166  *
167  * Get the generic device from the vdpa device
168  *
169  * @param vdpa_dev
170  *  the vdpa device pointer
171  * @return
172  *  generic device pointer on success, NULL on failure
173  */
174 __rte_experimental
175 struct rte_device *
176 rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev);
177
178 /**
179  * @warning
180  * @b EXPERIMENTAL: this API may change without prior notice
181  *
182  * Enable/Disable host notifier mapping for a vdpa port.
183  *
184  * @param vid
185  *  vhost device id
186  * @param enable
187  *  true for host notifier map, false for host notifier unmap
188  * @return
189  *  0 on success, -1 on failure
190  */
191 __rte_experimental
192 int
193 rte_vhost_host_notifier_ctrl(int vid, bool enable);
194
195 /**
196  * @warning
197  * @b EXPERIMENTAL: this API may change without prior notice
198  *
199  * Synchronize the used ring from mediated ring to guest, log dirty
200  * page for each writeable buffer, caller should handle the used
201  * ring logging before device stop.
202  *
203  * @param vid
204  *  vhost device id
205  * @param qid
206  *  vhost queue id
207  * @param vring_m
208  *  mediated virtio ring pointer
209  * @return
210  *  number of synced used entries on success, -1 on failure
211  */
212 __rte_experimental
213 int
214 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
215
216 /**
217  * @warning
218  * @b EXPERIMENTAL: this API may change without prior notice
219  *
220  * Get number of queue pairs supported by the vDPA device
221  *
222  * @param dev
223  *  vDP device pointer
224  * @param queue_num
225  *  pointer on where the number of queue is stored
226  * @return
227  *  0 on success, -1 on failure
228  */
229 __rte_experimental
230 int
231 rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num);
232
233 /**
234  * @warning
235  * @b EXPERIMENTAL: this API may change without prior notice
236  *
237  * Get the Virtio features supported by the vDPA device
238  *
239  * @param dev
240  *  vDP device pointer
241  * @param features
242  *  pointer on where the supported features are stored
243  * @return
244  *  0 on success, -1 on failure
245  */
246 __rte_experimental
247 int
248 rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features);
249
250 /**
251  * @warning
252  * @b EXPERIMENTAL: this API may change without prior notice
253  *
254  * Get the Vhost-user protocol features supported by the vDPA device
255  *
256  * @param dev
257  *  vDP device pointer
258  * @param features
259  *  pointer on where the supported protocol features are stored
260  * @return
261  *  0 on success, -1 on failure
262  */
263 __rte_experimental
264 int
265 rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features);
266
267 /**
268  * @warning
269  * @b EXPERIMENTAL: this API may change without prior notice
270  *
271  * Synchronize the used ring from mediated ring to guest, log dirty
272  * page for each writeable buffer, caller should handle the used
273  * ring logging before device stop.
274  *
275  * @param vid
276  *  vhost device id
277  * @param qid
278  *  vhost queue id
279  * @param vring_m
280  *  mediated virtio ring pointer
281  * @return
282  *  number of synced used entries on success, -1 on failure
283  */
284 __rte_experimental
285 int
286 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
287
288 /**
289  * @warning
290  * @b EXPERIMENTAL: this API may change without prior notice
291  *
292  * Retrieve names of statistics of a vDPA device.
293  *
294  * There is an assumption that 'stat_names' and 'stats' arrays are matched
295  * by array index: stats_names[i].name => stats[i].value
296  *
297  * And the array index is same with id field of 'struct rte_vdpa_stat':
298  * stats[i].id == i
299  *
300  * @param dev
301  *  vDPA device pointer
302  * @param stats_names
303  *   array of at least size elements to be filled.
304  *   If set to NULL, the function returns the required number of elements.
305  * @param size
306  *   The number of elements in stats_names array.
307  * @return
308  *   A negative value on error, otherwise the number of entries filled in the
309  *   stats name array.
310  */
311 __rte_experimental
312 int
313 rte_vdpa_get_stats_names(struct rte_vdpa_device *dev,
314                 struct rte_vdpa_stat_name *stats_names,
315                 unsigned int size);
316
317 /**
318  * @warning
319  * @b EXPERIMENTAL: this API may change without prior notice
320  *
321  * Retrieve statistics of a vDPA device.
322  *
323  * There is an assumption that 'stat_names' and 'stats' arrays are matched
324  * by array index: stats_names[i].name => stats[i].value
325  *
326  * And the array index is same with id field of 'struct rte_vdpa_stat':
327  * stats[i].id == i
328  *
329  * @param dev
330  *  vDPA device pointer
331  * @param qid
332  *  queue id
333  * @param stats
334  *   A pointer to a table of structure of type rte_vdpa_stat to be filled with
335  *   device statistics ids and values.
336  * @param n
337  *   The number of elements in stats array.
338  * @return
339  *   A negative value on error, otherwise the number of entries filled in the
340  *   stats table.
341  */
342 __rte_experimental
343 int
344 rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid,
345                 struct rte_vdpa_stat *stats, unsigned int n);
346 /**
347  * @warning
348  * @b EXPERIMENTAL: this API may change without prior notice
349  *
350  * Reset statistics of a vDPA device.
351  *
352  * @param dev
353  *  vDPA device pointer
354  * @param qid
355  *  queue id
356  * @return
357  *   0 on success, a negative value on error.
358  */
359 __rte_experimental
360 int
361 rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid);
362 #endif /* _RTE_VDPA_H_ */