xref: /dpdk/lib/vhost/rte_vdpa.h (revision 85dbfcb1be49e512fde5c7455f9872158421ca66)
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 <stdint.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /** Maximum name length for statistics counters */
21 #define RTE_VDPA_STATS_NAME_SIZE 64
22 
23 struct rte_vdpa_device;
24 
25 /**
26  * A vDPA device statistic structure
27  *
28  * This structure is used by rte_vdpa_stats_get() to provide
29  * statistics from the HW vDPA device.
30  *
31  * It maps a name id, corresponding to an index in the array returned
32  * by rte_vdpa_get_stats_names, to a statistic value.
33  */
34 struct rte_vdpa_stat {
35 	uint64_t id;        /**< The index in stats name array */
36 	uint64_t value;     /**< The statistic counter value */
37 };
38 
39 /**
40  * A name element for statistics
41  *
42  * An array of this structure is returned by rte_vdpa_get_stats_names
43  * It lists the names of extended statistics for a PMD. The rte_vdpa_stat
44  * structure references these names by their array index
45  */
46 struct rte_vdpa_stat_name {
47 	char name[RTE_VDPA_STATS_NAME_SIZE]; /**< The statistic name */
48 };
49 
50 /**
51  * Find the device id of a vdpa device from its name
52  *
53  * @param name
54  *  the vdpa device name
55  * @return
56  *  vDPA device pointer on success, NULL on failure
57  */
58 struct rte_vdpa_device *
59 rte_vdpa_find_device_by_name(const char *name);
60 
61 /**
62  * Get the generic device from the vdpa device
63  *
64  * @param vdpa_dev
65  *  the vdpa device pointer
66  * @return
67  *  generic device pointer on success, NULL on failure
68  */
69 struct rte_device *
70 rte_vdpa_get_rte_device(struct rte_vdpa_device *vdpa_dev);
71 
72 /**
73  * Get number of queue pairs supported by the vDPA device
74  *
75  * @param dev
76  *  vDP device pointer
77  * @param queue_num
78  *  pointer on where the number of queue is stored
79  * @return
80  *  0 on success, -1 on failure
81  */
82 int
83 rte_vdpa_get_queue_num(struct rte_vdpa_device *dev, uint32_t *queue_num);
84 
85 /**
86  * Get the Virtio features supported by the vDPA device
87  *
88  * @param dev
89  *  vDP device pointer
90  * @param features
91  *  pointer on where the supported features are stored
92  * @return
93  *  0 on success, -1 on failure
94  */
95 int
96 rte_vdpa_get_features(struct rte_vdpa_device *dev, uint64_t *features);
97 
98 /**
99  * Get the Vhost-user protocol features supported by the vDPA device
100  *
101  * @param dev
102  *  vDP device pointer
103  * @param features
104  *  pointer on where the supported protocol features are stored
105  * @return
106  *  0 on success, -1 on failure
107  */
108 int
109 rte_vdpa_get_protocol_features(struct rte_vdpa_device *dev, uint64_t *features);
110 
111 /**
112  * Retrieve names of statistics of a vDPA device.
113  *
114  * There is an assumption that 'stat_names' and 'stats' arrays are matched
115  * by array index: stats_names[i].name => stats[i].value
116  *
117  * And the array index is same with id field of 'struct rte_vdpa_stat':
118  * stats[i].id == i
119  *
120  * @param dev
121  *  vDPA device pointer
122  * @param stats_names
123  *   array of at least size elements to be filled.
124  *   If set to NULL, the function returns the required number of elements.
125  * @param size
126  *   The number of elements in stats_names array.
127  * @return
128  *   A negative value on error, otherwise the number of entries filled in the
129  *   stats name array.
130  */
131 int
132 rte_vdpa_get_stats_names(struct rte_vdpa_device *dev,
133 		struct rte_vdpa_stat_name *stats_names,
134 		unsigned int size);
135 
136 /**
137  * Retrieve statistics of a vDPA device.
138  *
139  * There is an assumption that 'stat_names' and 'stats' arrays are matched
140  * by array index: stats_names[i].name => stats[i].value
141  *
142  * And the array index is same with id field of 'struct rte_vdpa_stat':
143  * stats[i].id == i
144  *
145  * @param dev
146  *  vDPA device pointer
147  * @param qid
148  *  queue id
149  * @param stats
150  *   A pointer to a table of structure of type rte_vdpa_stat to be filled with
151  *   device statistics ids and values.
152  * @param n
153  *   The number of elements in stats array.
154  * @return
155  *   A negative value on error, otherwise the number of entries filled in the
156  *   stats table.
157  */
158 int
159 rte_vdpa_get_stats(struct rte_vdpa_device *dev, uint16_t qid,
160 		struct rte_vdpa_stat *stats, unsigned int n);
161 /**
162  * Reset statistics of a vDPA device.
163  *
164  * @param dev
165  *  vDPA device pointer
166  * @param qid
167  *  queue id
168  * @return
169  *   0 on success, a negative value on error.
170  */
171 int
172 rte_vdpa_reset_stats(struct rte_vdpa_device *dev, uint16_t qid);
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
178 #endif /* _RTE_VDPA_H_ */
179