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