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
25 * A vDPA device statistic structure
27 * This structure is used by rte_vdpa_stats_get() to provide
28 * statistics from the HW vDPA device.
30 * It maps a name id, corresponding to an index in the array returned
31 * by rte_vdpa_get_stats_names, to a statistic value.
33 struct rte_vdpa_stat {
34 uint64_t id; /**< The index in stats name array */
35 uint64_t value; /**< The statistic counter value */
39 * A name element for statistics
41 * An array of this structure is returned by rte_vdpa_get_stats_names
42 * It lists the names of extended statistics for a PMD. The rte_vdpa_stat
43 * structure references these names by their array index
45 struct rte_vdpa_stat_name {
46 char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */
50 * vdpa device operations
52 struct rte_vdpa_dev_ops {
53 /** Get capabilities of this device */
54 int (*get_queue_num)(int did, uint32_t *queue_num);
56 /** Get supported features of this device */
57 int (*get_features)(int did, uint64_t *features);
59 /** Get supported protocol features of this device */
60 int (*get_protocol_features)(int did, uint64_t *protocol_features);
62 /** Driver configure/close the device */
63 int (*dev_conf)(int vid);
64 int (*dev_close)(int vid);
66 /** Enable/disable this vring */
67 int (*set_vring_state)(int vid, int vring, int state);
69 /** Set features when changed */
70 int (*set_features)(int vid);
72 /** Destination operations when migration done */
73 int (*migration_done)(int vid);
75 /** Get the vfio group fd */
76 int (*get_vfio_group_fd)(int vid);
78 /** Get the vfio device fd */
79 int (*get_vfio_device_fd)(int vid);
81 /** Get the notify area info of the queue */
82 int (*get_notify_area)(int vid, int qid,
83 uint64_t *offset, uint64_t *size);
85 /** Get statistics name */
86 int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names,
89 /** Get statistics of the queue */
90 int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats,
93 /** Reset statistics of the queue */
94 int (*reset_stats)(int did, int qid);
96 /** Reserved for future extension */
101 * vdpa device structure includes device address and device operations.
103 struct rte_vdpa_device {
104 /** Generic device information */
105 struct rte_device *device;
106 /** vdpa device operations */
107 struct rte_vdpa_dev_ops *ops;
108 } __rte_cache_aligned;
112 * @b EXPERIMENTAL: this API may change without prior notice
114 * Register a vdpa device
117 * the vdpa device address
119 * the vdpa device operations
121 * device id on success, -1 on failure
125 rte_vdpa_register_device(struct rte_device *rte_dev,
126 struct rte_vdpa_dev_ops *ops);
130 * @b EXPERIMENTAL: this API may change without prior notice
132 * Unregister a vdpa device
137 * device id on success, -1 on failure
141 rte_vdpa_unregister_device(int did);
145 * @b EXPERIMENTAL: this API may change without prior notice
147 * Find the device id of a vdpa device from its name
150 * the vdpa device name
152 * device id on success, -1 on failure
156 rte_vdpa_find_device_id_by_name(const char *name);
160 * @b EXPERIMENTAL: this API may change without prior notice
162 * Find the device id of a vdpa device
165 * the vdpa device address
167 * device id on success, -1 on failure
171 rte_vdpa_find_device_id(struct rte_vdpa_device *dev);
175 * @b EXPERIMENTAL: this API may change without prior notice
177 * Find a vdpa device based on device id
182 * rte_vdpa_device on success, NULL on failure
185 struct rte_vdpa_device *
186 rte_vdpa_get_device(int did);
190 * @b EXPERIMENTAL: this API may change without prior notice
192 * Get current available vdpa device number
195 * available vdpa device number
199 rte_vdpa_get_device_num(void);
203 * @b EXPERIMENTAL: this API may change without prior notice
205 * Enable/Disable host notifier mapping for a vdpa port.
210 * true for host notifier map, false for host notifier unmap
212 * 0 on success, -1 on failure
216 rte_vhost_host_notifier_ctrl(int vid, bool enable);
220 * @b EXPERIMENTAL: this API may change without prior notice
222 * Synchronize the used ring from mediated ring to guest, log dirty
223 * page for each writeable buffer, caller should handle the used
224 * ring logging before device stop.
231 * mediated virtio ring pointer
233 * number of synced used entries on success, -1 on failure
237 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
241 * @b EXPERIMENTAL: this API may change without prior notice
243 * Retrieve names of statistics of a vDPA device.
245 * There is an assumption that 'stat_names' and 'stats' arrays are matched
246 * by array index: stats_names[i].name => stats[i].value
248 * And the array index is same with id field of 'struct rte_vdpa_stat':
254 * array of at least size elements to be filled.
255 * If set to NULL, the function returns the required number of elements.
257 * The number of elements in stats_names array.
259 * A negative value on error, otherwise the number of entries filled in the
264 rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names,
269 * @b EXPERIMENTAL: this API may change without prior notice
271 * Retrieve statistics of a vDPA device.
273 * There is an assumption that 'stat_names' and 'stats' arrays are matched
274 * by array index: stats_names[i].name => stats[i].value
276 * And the array index is same with id field of 'struct rte_vdpa_stat':
284 * A pointer to a table of structure of type rte_vdpa_stat to be filled with
285 * device statistics ids and values.
287 * The number of elements in stats array.
289 * A negative value on error, otherwise the number of entries filled in the
294 rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats,
298 * @b EXPERIMENTAL: this API may change without prior notice
300 * Reset statistics of a vDPA device.
307 * 0 on success, a negative value on error.
311 rte_vdpa_reset_stats(int did, uint16_t qid);
312 #endif /* _RTE_VDPA_H_ */