1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
11 * Device specific vhost lib
17 #include "rte_vhost.h"
19 #define MAX_VDPA_NAME_LEN 128
21 /** Maximum name length for statistics counters */
22 #define RTE_VDPA_STATS_NAME_SIZE 64
24 struct rte_vdpa_device;
27 * A vDPA device statistic structure
29 * This structure is used by rte_vdpa_stats_get() to provide
30 * statistics from the HW vDPA device.
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.
35 struct rte_vdpa_stat {
36 uint64_t id; /**< The index in stats name array */
37 uint64_t value; /**< The statistic counter value */
41 * A name element for statistics
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
47 struct rte_vdpa_stat_name {
48 char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */
52 * vdpa device operations
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);
58 /** Get supported features of this device */
59 int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
61 /** Get supported protocol features of this device */
62 int (*get_protocol_features)(struct rte_vdpa_device *dev,
63 uint64_t *protocol_features);
65 /** Driver configure/close the device */
66 int (*dev_conf)(int vid);
67 int (*dev_close)(int vid);
69 /** Enable/disable this vring */
70 int (*set_vring_state)(int vid, int vring, int state);
72 /** Set features when changed */
73 int (*set_features)(int vid);
75 /** Destination operations when migration done */
76 int (*migration_done)(int vid);
78 /** Get the vfio group fd */
79 int (*get_vfio_group_fd)(int vid);
81 /** Get the vfio device fd */
82 int (*get_vfio_device_fd)(int vid);
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);
88 /** Get statistics name */
89 int (*get_stats_names)(struct rte_vdpa_device *dev,
90 struct rte_vdpa_stat_name *stats_names,
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);
97 /** Reset statistics of the queue */
98 int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
100 /** Reserved for future extension */
105 * vdpa device structure includes device address and device operations.
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;
117 * @b EXPERIMENTAL: this API may change without prior notice
119 * Register a vdpa device
122 * the vdpa device address
124 * the vdpa device operations
126 * vDPA device pointer on success, NULL on failure
129 struct rte_vdpa_device *
130 rte_vdpa_register_device(struct rte_device *rte_dev,
131 struct rte_vdpa_dev_ops *ops);
135 * @b EXPERIMENTAL: this API may change without prior notice
137 * Unregister a vdpa device
140 * vDPA device pointer
142 * device id on success, -1 on failure
146 rte_vdpa_unregister_device(struct rte_vdpa_device *);
150 * @b EXPERIMENTAL: this API may change without prior notice
152 * Find the device id of a vdpa device from its name
155 * the vdpa device name
157 * vDPA device pointer on success, NULL on failure
160 struct rte_vdpa_device *
161 rte_vdpa_find_device_by_name(const char *name);
165 * @b EXPERIMENTAL: this API may change without prior notice
167 * Get the generic device from the vdpa device
170 * the vdpa device pointer
172 * generic device pointer on success, NULL on failure
176 rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev);
180 * @b EXPERIMENTAL: this API may change without prior notice
182 * Get current available vdpa device number
185 * available vdpa device number
189 rte_vdpa_get_device_num(void);
193 * @b EXPERIMENTAL: this API may change without prior notice
195 * Enable/Disable host notifier mapping for a vdpa port.
200 * true for host notifier map, false for host notifier unmap
202 * 0 on success, -1 on failure
206 rte_vhost_host_notifier_ctrl(int vid, bool enable);
210 * @b EXPERIMENTAL: this API may change without prior notice
212 * Synchronize the used ring from mediated ring to guest, log dirty
213 * page for each writeable buffer, caller should handle the used
214 * ring logging before device stop.
221 * mediated virtio ring pointer
223 * number of synced used entries on success, -1 on failure
227 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
231 * @b EXPERIMENTAL: this API may change without prior notice
233 * Get number of queue pairs supported by the vDPA device
238 * pointer on where the number of queue is stored
240 * 0 on success, -1 on failure
244 rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num);
248 * @b EXPERIMENTAL: this API may change without prior notice
250 * Get the Virtio features supported by the vDPA device
255 * pointer on where the supported features are stored
257 * 0 on success, -1 on failure
261 rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features);
265 * @b EXPERIMENTAL: this API may change without prior notice
267 * Get the Vhost-user protocol features supported by the vDPA device
272 * pointer on where the supported protocol features are stored
274 * 0 on success, -1 on failure
278 rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features);
282 * @b EXPERIMENTAL: this API may change without prior notice
284 * Synchronize the used ring from mediated ring to guest, log dirty
285 * page for each writeable buffer, caller should handle the used
286 * ring logging before device stop.
293 * mediated virtio ring pointer
295 * number of synced used entries on success, -1 on failure
299 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
303 * @b EXPERIMENTAL: this API may change without prior notice
305 * Retrieve names of statistics of a vDPA device.
307 * There is an assumption that 'stat_names' and 'stats' arrays are matched
308 * by array index: stats_names[i].name => stats[i].value
310 * And the array index is same with id field of 'struct rte_vdpa_stat':
314 * vDPA device pointer
316 * array of at least size elements to be filled.
317 * If set to NULL, the function returns the required number of elements.
319 * The number of elements in stats_names array.
321 * A negative value on error, otherwise the number of entries filled in the
326 rte_vdpa_get_stats_names(struct rte_vdpa_device *dev,
327 struct rte_vdpa_stat_name *stats_names,
332 * @b EXPERIMENTAL: this API may change without prior notice
334 * Retrieve statistics of a vDPA device.
336 * There is an assumption that 'stat_names' and 'stats' arrays are matched
337 * by array index: stats_names[i].name => stats[i].value
339 * And the array index is same with id field of 'struct rte_vdpa_stat':
343 * vDPA device pointer
347 * A pointer to a table of structure of type rte_vdpa_stat to be filled with
348 * device statistics ids and values.
350 * The number of elements in stats array.
352 * A negative value on error, otherwise the number of entries filled in the
357 rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid,
358 struct rte_vdpa_stat *stats, unsigned int n);
361 * @b EXPERIMENTAL: this API may change without prior notice
363 * Reset statistics of a vDPA device.
366 * vDPA device pointer
370 * 0 on success, a negative value on error.
374 rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid);
375 #endif /* _RTE_VDPA_H_ */