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
29 struct rte_vdpa_dev_addr {
30 /** vdpa address type */
31 enum vdpa_addr_type type;
33 /** vdpa pci address */
36 struct rte_pci_addr pci_addr;
40 /** Maximum name length for statistics counters */
41 #define RTE_VDPA_STATS_NAME_SIZE 64
44 * A vDPA device statistic structure
46 * This structure is used by rte_vdpa_stats_get() to provide
47 * statistics from the HW vDPA device.
49 * It maps a name id, corresponding to an index in the array returned
50 * by rte_vdpa_get_stats_names, to a statistic value.
52 struct rte_vdpa_stat {
53 uint64_t id; /**< The index in stats name array */
54 uint64_t value; /**< The statistic counter value */
58 * A name element for statistics
60 * An array of this structure is returned by rte_vdpa_get_stats_names
61 * It lists the names of extended statistics for a PMD. The rte_vdpa_stat
62 * structure references these names by their array index
64 struct rte_vdpa_stat_name {
65 char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */
69 * vdpa device operations
71 struct rte_vdpa_dev_ops {
72 /** Get capabilities of this device */
73 int (*get_queue_num)(int did, uint32_t *queue_num);
75 /** Get supported features of this device */
76 int (*get_features)(int did, uint64_t *features);
78 /** Get supported protocol features of this device */
79 int (*get_protocol_features)(int did, uint64_t *protocol_features);
81 /** Driver configure/close the device */
82 int (*dev_conf)(int vid);
83 int (*dev_close)(int vid);
85 /** Enable/disable this vring */
86 int (*set_vring_state)(int vid, int vring, int state);
88 /** Set features when changed */
89 int (*set_features)(int vid);
91 /** Destination operations when migration done */
92 int (*migration_done)(int vid);
94 /** Get the vfio group fd */
95 int (*get_vfio_group_fd)(int vid);
97 /** Get the vfio device fd */
98 int (*get_vfio_device_fd)(int vid);
100 /** Get the notify area info of the queue */
101 int (*get_notify_area)(int vid, int qid,
102 uint64_t *offset, uint64_t *size);
104 /** Get statistics name */
105 int (*get_stats_names)(int did, struct rte_vdpa_stat_name *stats_names,
108 /** Get statistics of the queue */
109 int (*get_stats)(int did, int qid, struct rte_vdpa_stat *stats,
112 /** Reset statistics of the queue */
113 int (*reset_stats)(int did, int qid);
115 /** Reserved for future extension */
120 * vdpa device structure includes device address and device operations.
122 struct rte_vdpa_device {
123 /** vdpa device address */
124 struct rte_vdpa_dev_addr addr;
125 /** vdpa device operations */
126 struct rte_vdpa_dev_ops *ops;
127 } __rte_cache_aligned;
131 * @b EXPERIMENTAL: this API may change without prior notice
133 * Register a vdpa device
136 * the vdpa device address
138 * the vdpa device operations
140 * device id on success, -1 on failure
144 rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr,
145 struct rte_vdpa_dev_ops *ops);
149 * @b EXPERIMENTAL: this API may change without prior notice
151 * Unregister a vdpa device
156 * device id on success, -1 on failure
160 rte_vdpa_unregister_device(int did);
164 * @b EXPERIMENTAL: this API may change without prior notice
166 * Find the device id of a vdpa device
169 * the vdpa device address
171 * device id on success, -1 on failure
175 rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr);
179 * @b EXPERIMENTAL: this API may change without prior notice
181 * Find a vdpa device based on device id
186 * rte_vdpa_device on success, NULL on failure
189 struct rte_vdpa_device *
190 rte_vdpa_get_device(int did);
194 * @b EXPERIMENTAL: this API may change without prior notice
196 * Get current available vdpa device number
199 * available vdpa device number
203 rte_vdpa_get_device_num(void);
207 * @b EXPERIMENTAL: this API may change without prior notice
209 * Enable/Disable host notifier mapping for a vdpa port.
214 * true for host notifier map, false for host notifier unmap
216 * 0 on success, -1 on failure
220 rte_vhost_host_notifier_ctrl(int vid, bool enable);
224 * @b EXPERIMENTAL: this API may change without prior notice
226 * Synchronize the used ring from mediated ring to guest, log dirty
227 * page for each writeable buffer, caller should handle the used
228 * ring logging before device stop.
235 * mediated virtio ring pointer
237 * number of synced used entries on success, -1 on failure
241 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
245 * @b EXPERIMENTAL: this API may change without prior notice
247 * Retrieve names of statistics of a vDPA device.
249 * There is an assumption that 'stat_names' and 'stats' arrays are matched
250 * by array index: stats_names[i].name => stats[i].value
252 * And the array index is same with id field of 'struct rte_vdpa_stat':
258 * array of at least size elements to be filled.
259 * If set to NULL, the function returns the required number of elements.
261 * The number of elements in stats_names array.
263 * A negative value on error, otherwise the number of entries filled in the
268 rte_vdpa_get_stats_names(int did, struct rte_vdpa_stat_name *stats_names,
273 * @b EXPERIMENTAL: this API may change without prior notice
275 * Retrieve statistics of a vDPA device.
277 * There is an assumption that 'stat_names' and 'stats' arrays are matched
278 * by array index: stats_names[i].name => stats[i].value
280 * And the array index is same with id field of 'struct rte_vdpa_stat':
288 * A pointer to a table of structure of type rte_vdpa_stat to be filled with
289 * device statistics ids and values.
291 * The number of elements in stats array.
293 * A negative value on error, otherwise the number of entries filled in the
298 rte_vdpa_get_stats(int did, uint16_t qid, struct rte_vdpa_stat *stats,
302 * @b EXPERIMENTAL: this API may change without prior notice
304 * Reset statistics of a vDPA device.
311 * 0 on success, a negative value on error.
315 rte_vdpa_reset_stats(int did, uint16_t qid);
316 #endif /* _RTE_VDPA_H_ */