1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef _VDPA_DRIVER_H_
6 #define _VDPA_DRIVER_H_
14 #include <rte_compat.h>
16 #include "rte_vhost.h"
19 #define RTE_VHOST_QUEUE_ALL UINT16_MAX
22 * vdpa device operations
24 struct rte_vdpa_dev_ops {
25 /** Get capabilities of this device (Mandatory) */
26 int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
28 /** Get supported features of this device (Mandatory) */
29 int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
31 /** Get supported protocol features of this device (Mandatory) */
32 int (*get_protocol_features)(struct rte_vdpa_device *dev,
33 uint64_t *protocol_features);
35 /** Driver configure the device (Mandatory) */
36 int (*dev_conf)(int vid);
38 /** Driver close the device (Mandatory) */
39 int (*dev_close)(int vid);
41 /** Connection closed, clean up resources */
42 int (*dev_cleanup)(int vid);
44 /** Enable/disable this vring (Mandatory) */
45 int (*set_vring_state)(int vid, int vring, int state);
47 /** Set features when changed (Mandatory) */
48 int (*set_features)(int vid);
50 /** Destination operations when migration done */
51 int (*migration_done)(int vid);
53 /** Get the vfio group fd */
54 int (*get_vfio_group_fd)(int vid);
56 /** Get the vfio device fd */
57 int (*get_vfio_device_fd)(int vid);
59 /** Get the notify area info of the queue */
60 int (*get_notify_area)(int vid, int qid,
61 uint64_t *offset, uint64_t *size);
63 /** Get statistics name */
64 int (*get_stats_names)(struct rte_vdpa_device *dev,
65 struct rte_vdpa_stat_name *stats_names,
68 /** Get statistics of the queue */
69 int (*get_stats)(struct rte_vdpa_device *dev, int qid,
70 struct rte_vdpa_stat *stats, unsigned int n);
72 /** Reset statistics of the queue */
73 int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
75 /** Get the device configuration space */
76 int (*get_config)(int vid, uint8_t *config, uint32_t size);
78 /** Set the device configuration space */
79 int (*set_config)(int vid, uint8_t *config, uint32_t offset,
80 uint32_t size, uint32_t flags);
84 * vdpa device structure includes device address and device operations.
86 struct rte_vdpa_device {
87 RTE_TAILQ_ENTRY(rte_vdpa_device) next;
88 /** Generic device information */
89 struct rte_device *device;
90 /** vdpa device operations */
91 struct rte_vdpa_dev_ops *ops;
95 * Register a vdpa device
98 * the generic device pointer
100 * the vdpa device operations
102 * vDPA device pointer on success, NULL on failure
105 struct rte_vdpa_device *
106 rte_vdpa_register_device(struct rte_device *rte_dev,
107 struct rte_vdpa_dev_ops *ops);
110 * Unregister a vdpa device
113 * vDPA device pointer
115 * device id on success, -1 on failure
119 rte_vdpa_unregister_device(struct rte_vdpa_device *dev);
122 * Enable/Disable host notifier mapping for a vdpa port.
127 * true for host notifier map, false for host notifier unmap
129 * vhost queue id, RTE_VHOST_QUEUE_ALL to configure all the device queues
131 * 0 on success, -1 on failure
135 rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable);
138 * Synchronize the used ring from mediated ring to guest, log dirty
139 * page for each writeable buffer, caller should handle the used
140 * ring logging before device stop.
147 * mediated virtio ring pointer
149 * number of synced used entries on success, -1 on failure
153 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
159 #endif /* _VDPA_DRIVER_H_ */