vhost: add vDPA resource cleanup callback
[dpdk.git] / lib / vhost / vdpa_driver.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _VDPA_DRIVER_H_
6 #define _VDPA_DRIVER_H_
7
8 #include <stdbool.h>
9
10 #include <rte_compat.h>
11
12 #include "rte_vhost.h"
13 #include "rte_vdpa.h"
14
15 #define RTE_VHOST_QUEUE_ALL UINT16_MAX
16
17 /**
18  * vdpa device operations
19  */
20 struct rte_vdpa_dev_ops {
21         /** Get capabilities of this device (Mandatory) */
22         int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
23
24         /** Get supported features of this device (Mandatory) */
25         int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
26
27         /** Get supported protocol features of this device (Mandatory) */
28         int (*get_protocol_features)(struct rte_vdpa_device *dev,
29                         uint64_t *protocol_features);
30
31         /** Driver configure the device (Mandatory) */
32         int (*dev_conf)(int vid);
33
34         /** Driver close the device (Mandatory) */
35         int (*dev_close)(int vid);
36
37         /** Connection closed, clean up resources */
38         int (*dev_cleanup)(int vid);
39
40         /** Enable/disable this vring (Mandatory) */
41         int (*set_vring_state)(int vid, int vring, int state);
42
43         /** Set features when changed (Mandatory) */
44         int (*set_features)(int vid);
45
46         /** Destination operations when migration done */
47         int (*migration_done)(int vid);
48
49         /** Get the vfio group fd */
50         int (*get_vfio_group_fd)(int vid);
51
52         /** Get the vfio device fd */
53         int (*get_vfio_device_fd)(int vid);
54
55         /** Get the notify area info of the queue */
56         int (*get_notify_area)(int vid, int qid,
57                         uint64_t *offset, uint64_t *size);
58
59         /** Get statistics name */
60         int (*get_stats_names)(struct rte_vdpa_device *dev,
61                         struct rte_vdpa_stat_name *stats_names,
62                         unsigned int size);
63
64         /** Get statistics of the queue */
65         int (*get_stats)(struct rte_vdpa_device *dev, int qid,
66                         struct rte_vdpa_stat *stats, unsigned int n);
67
68         /** Reset statistics of the queue */
69         int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
70
71         /** Reserved for future extension */
72         void *reserved[2];
73 };
74
75 /**
76  * vdpa device structure includes device address and device operations.
77  */
78 struct rte_vdpa_device {
79         RTE_TAILQ_ENTRY(rte_vdpa_device) next;
80         /** Generic device information */
81         struct rte_device *device;
82         /** vdpa device operations */
83         struct rte_vdpa_dev_ops *ops;
84 };
85
86 /**
87  * Register a vdpa device
88  *
89  * @param rte_dev
90  *  the generic device pointer
91  * @param ops
92  *  the vdpa device operations
93  * @return
94  *  vDPA device pointer on success, NULL on failure
95  */
96 __rte_internal
97 struct rte_vdpa_device *
98 rte_vdpa_register_device(struct rte_device *rte_dev,
99                 struct rte_vdpa_dev_ops *ops);
100
101 /**
102  * Unregister a vdpa device
103  *
104  * @param dev
105  *  vDPA device pointer
106  * @return
107  *  device id on success, -1 on failure
108  */
109 __rte_internal
110 int
111 rte_vdpa_unregister_device(struct rte_vdpa_device *dev);
112
113 /**
114  * Enable/Disable host notifier mapping for a vdpa port.
115  *
116  * @param vid
117  *  vhost device id
118  * @param enable
119  *  true for host notifier map, false for host notifier unmap
120  * @param qid
121  *  vhost queue id, RTE_VHOST_QUEUE_ALL to configure all the device queues
122  * @return
123  *  0 on success, -1 on failure
124  */
125 __rte_internal
126 int
127 rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable);
128
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_internal
144 int
145 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
146
147 #endif /* _VDPA_DRIVER_H_ */