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