fecaa8e0816b140bb01fed50da52365a6c984730
[dpdk.git] / lib / librte_vhost / rte_vdpa_dev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _RTE_VDPA_H_DEV_
6 #define _RTE_VDPA_H_DEV_
7
8 #include <stdbool.h>
9
10 #include "rte_vhost.h"
11
12 /**
13  * vdpa device operations
14  */
15 struct rte_vdpa_dev_ops {
16         /** Get capabilities of this device */
17         int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
18
19         /** Get supported features of this device */
20         int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
21
22         /** Get supported protocol features of this device */
23         int (*get_protocol_features)(struct rte_vdpa_device *dev,
24                         uint64_t *protocol_features);
25
26         /** Driver configure/close the device */
27         int (*dev_conf)(int vid);
28         int (*dev_close)(int vid);
29
30         /** Enable/disable this vring */
31         int (*set_vring_state)(int vid, int vring, int state);
32
33         /** Set features when changed */
34         int (*set_features)(int vid);
35
36         /** Destination operations when migration done */
37         int (*migration_done)(int vid);
38
39         /** Get the vfio group fd */
40         int (*get_vfio_group_fd)(int vid);
41
42         /** Get the vfio device fd */
43         int (*get_vfio_device_fd)(int vid);
44
45         /** Get the notify area info of the queue */
46         int (*get_notify_area)(int vid, int qid,
47                         uint64_t *offset, uint64_t *size);
48
49         /** Get statistics name */
50         int (*get_stats_names)(struct rte_vdpa_device *dev,
51                         struct rte_vdpa_stat_name *stats_names,
52                         unsigned int size);
53
54         /** Get statistics of the queue */
55         int (*get_stats)(struct rte_vdpa_device *dev, int qid,
56                         struct rte_vdpa_stat *stats, unsigned int n);
57
58         /** Reset statistics of the queue */
59         int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
60
61         /** Reserved for future extension */
62         void *reserved[2];
63 };
64
65 /**
66  * vdpa device structure includes device address and device operations.
67  */
68 struct rte_vdpa_device {
69         TAILQ_ENTRY(rte_vdpa_device) next;
70         /** Generic device information */
71         struct rte_device *device;
72         /** vdpa device operations */
73         struct rte_vdpa_dev_ops *ops;
74 };
75
76 /**
77  * @warning
78  * @b EXPERIMENTAL: this API may change without prior notice
79  *
80  * Register a vdpa device
81  *
82  * @param rte_dev
83  *  the generic device pointer
84  * @param ops
85  *  the vdpa device operations
86  * @return
87  *  vDPA device pointer on success, NULL on failure
88  */
89 __rte_experimental
90 struct rte_vdpa_device *
91 rte_vdpa_register_device(struct rte_device *rte_dev,
92                 struct rte_vdpa_dev_ops *ops);
93
94 /**
95  * @warning
96  * @b EXPERIMENTAL: this API may change without prior notice
97  *
98  * Unregister a vdpa device
99  *
100  * @param dev
101  *  vDPA device pointer
102  * @return
103  *  device id on success, -1 on failure
104  */
105 __rte_experimental
106 int
107 rte_vdpa_unregister_device(struct rte_vdpa_device *dev);
108
109 /**
110  * @warning
111  * @b EXPERIMENTAL: this API may change without prior notice
112  *
113  * Enable/Disable host notifier mapping for a vdpa port.
114  *
115  * @param vid
116  *  vhost device id
117  * @param enable
118  *  true for host notifier map, false for host notifier unmap
119  * @return
120  *  0 on success, -1 on failure
121  */
122 __rte_experimental
123 int
124 rte_vhost_host_notifier_ctrl(int vid, bool enable);
125
126 /**
127  * @warning
128  * @b EXPERIMENTAL: this API may change without prior notice
129  *
130  * Synchronize the used ring from mediated ring to guest, log dirty
131  * page for each writeable buffer, caller should handle the used
132  * ring logging before device stop.
133  *
134  * @param vid
135  *  vhost device id
136  * @param qid
137  *  vhost queue id
138  * @param vring_m
139  *  mediated virtio ring pointer
140  * @return
141  *  number of synced used entries on success, -1 on failure
142  */
143 __rte_experimental
144 int
145 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
146
147 #endif /* _RTE_VDPA_DEV_H_ */