vhost: prefix vDPA enum value for PCI address type
[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 #include <stdbool.h>
15
16 #include <rte_pci.h>
17 #include "rte_vhost.h"
18
19 #define MAX_VDPA_NAME_LEN 128
20
21 enum vdpa_addr_type {
22         VDPA_ADDR_PCI,
23         VDPA_ADDR_MAX
24 };
25
26 /**
27  * vdpa device address
28  */
29 struct rte_vdpa_dev_addr {
30         /** vdpa address type */
31         enum vdpa_addr_type type;
32
33         /** vdpa pci address */
34         union {
35                 uint8_t __dummy[64];
36                 struct rte_pci_addr pci_addr;
37         };
38 };
39
40 /**
41  * vdpa device operations
42  */
43 struct rte_vdpa_dev_ops {
44         /** Get capabilities of this device */
45         int (*get_queue_num)(int did, uint32_t *queue_num);
46
47         /** Get supported features of this device */
48         int (*get_features)(int did, uint64_t *features);
49
50         /** Get supported protocol features of this device */
51         int (*get_protocol_features)(int did, uint64_t *protocol_features);
52
53         /** Driver configure/close the device */
54         int (*dev_conf)(int vid);
55         int (*dev_close)(int vid);
56
57         /** Enable/disable this vring */
58         int (*set_vring_state)(int vid, int vring, int state);
59
60         /** Set features when changed */
61         int (*set_features)(int vid);
62
63         /** Destination operations when migration done */
64         int (*migration_done)(int vid);
65
66         /** Get the vfio group fd */
67         int (*get_vfio_group_fd)(int vid);
68
69         /** Get the vfio device fd */
70         int (*get_vfio_device_fd)(int vid);
71
72         /** Get the notify area info of the queue */
73         int (*get_notify_area)(int vid, int qid,
74                         uint64_t *offset, uint64_t *size);
75
76         /** Reserved for future extension */
77         void *reserved[5];
78 };
79
80 /**
81  * vdpa device structure includes device address and device operations.
82  */
83 struct rte_vdpa_device {
84         /** vdpa device address */
85         struct rte_vdpa_dev_addr addr;
86         /** vdpa device operations */
87         struct rte_vdpa_dev_ops *ops;
88 } __rte_cache_aligned;
89
90 /**
91  * @warning
92  * @b EXPERIMENTAL: this API may change without prior notice
93  *
94  * Register a vdpa device
95  *
96  * @param addr
97  *  the vdpa device address
98  * @param ops
99  *  the vdpa device operations
100  * @return
101  *  device id on success, -1 on failure
102  */
103 __rte_experimental
104 int
105 rte_vdpa_register_device(struct rte_vdpa_dev_addr *addr,
106                 struct rte_vdpa_dev_ops *ops);
107
108 /**
109  * @warning
110  * @b EXPERIMENTAL: this API may change without prior notice
111  *
112  * Unregister a vdpa device
113  *
114  * @param did
115  *  vdpa device id
116  * @return
117  *  device id on success, -1 on failure
118  */
119 __rte_experimental
120 int
121 rte_vdpa_unregister_device(int did);
122
123 /**
124  * @warning
125  * @b EXPERIMENTAL: this API may change without prior notice
126  *
127  * Find the device id of a vdpa device
128  *
129  * @param addr
130  *  the vdpa device address
131  * @return
132  *  device id on success, -1 on failure
133  */
134 __rte_experimental
135 int
136 rte_vdpa_find_device_id(struct rte_vdpa_dev_addr *addr);
137
138 /**
139  * @warning
140  * @b EXPERIMENTAL: this API may change without prior notice
141  *
142  * Find a vdpa device based on device id
143  *
144  * @param did
145  *  device id
146  * @return
147  *  rte_vdpa_device on success, NULL on failure
148  */
149 __rte_experimental
150 struct rte_vdpa_device *
151 rte_vdpa_get_device(int did);
152
153 /**
154  * @warning
155  * @b EXPERIMENTAL: this API may change without prior notice
156  *
157  * Get current available vdpa device number
158  *
159  * @return
160  *  available vdpa device number
161  */
162 __rte_experimental
163 int
164 rte_vdpa_get_device_num(void);
165
166 /**
167  * @warning
168  * @b EXPERIMENTAL: this API may change without prior notice
169  *
170  * Enable/Disable host notifier mapping for a vdpa port.
171  *
172  * @param vid
173  *  vhost device id
174  * @param enable
175  *  true for host notifier map, false for host notifier unmap
176  * @return
177  *  0 on success, -1 on failure
178  */
179 __rte_experimental
180 int
181 rte_vhost_host_notifier_ctrl(int vid, bool enable);
182
183 /**
184  * @warning
185  * @b EXPERIMENTAL: this API may change without prior notice
186  *
187  * Synchronize the used ring from mediated ring to guest, log dirty
188  * page for each writeable buffer, caller should handle the used
189  * ring logging before device stop.
190  *
191  * @param vid
192  *  vhost device id
193  * @param qid
194  *  vhost queue id
195  * @param vring_m
196  *  mediated virtio ring pointer
197  * @return
198  *  number of synced used entries on success, -1 on failure
199  */
200 __rte_experimental
201 int
202 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
203 #endif /* _RTE_VDPA_H_ */