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 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 #include <stdbool.h> 13 14 #include <rte_compat.h> 15 16 #include "rte_vhost.h" 17 #include "rte_vdpa.h" 18 19 #define RTE_VHOST_QUEUE_ALL UINT16_MAX 20 21 /** 22 * vdpa device operations 23 */ 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); 27 28 /** Get supported features of this device (Mandatory) */ 29 int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features); 30 31 /** Get supported protocol features of this device (Mandatory) */ 32 int (*get_protocol_features)(struct rte_vdpa_device *dev, 33 uint64_t *protocol_features); 34 35 /** Driver configure the device (Mandatory) */ 36 int (*dev_conf)(int vid); 37 38 /** Driver close the device (Mandatory) */ 39 int (*dev_close)(int vid); 40 41 /** Connection closed, clean up resources */ 42 int (*dev_cleanup)(int vid); 43 44 /** Enable/disable this vring (Mandatory) */ 45 int (*set_vring_state)(int vid, int vring, int state); 46 47 /** Set features when changed (Mandatory) */ 48 int (*set_features)(int vid); 49 50 /** Destination operations when migration done */ 51 int (*migration_done)(int vid); 52 53 /** Get the vfio group fd */ 54 int (*get_vfio_group_fd)(int vid); 55 56 /** Get the vfio device fd */ 57 int (*get_vfio_device_fd)(int vid); 58 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); 62 63 /** Get statistics name */ 64 int (*get_stats_names)(struct rte_vdpa_device *dev, 65 struct rte_vdpa_stat_name *stats_names, 66 unsigned int size); 67 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); 71 72 /** Reset statistics of the queue */ 73 int (*reset_stats)(struct rte_vdpa_device *dev, int qid); 74 75 /** Reserved for future extension */ 76 void *reserved[2]; 77 }; 78 79 /** 80 * vdpa device structure includes device address and device operations. 81 */ 82 struct rte_vdpa_device { 83 RTE_TAILQ_ENTRY(rte_vdpa_device) next; 84 /** Generic device information */ 85 struct rte_device *device; 86 /** vdpa device operations */ 87 struct rte_vdpa_dev_ops *ops; 88 }; 89 90 /** 91 * Register a vdpa device 92 * 93 * @param rte_dev 94 * the generic device pointer 95 * @param ops 96 * the vdpa device operations 97 * @return 98 * vDPA device pointer on success, NULL on failure 99 */ 100 __rte_internal 101 struct rte_vdpa_device * 102 rte_vdpa_register_device(struct rte_device *rte_dev, 103 struct rte_vdpa_dev_ops *ops); 104 105 /** 106 * Unregister a vdpa device 107 * 108 * @param dev 109 * vDPA device pointer 110 * @return 111 * device id on success, -1 on failure 112 */ 113 __rte_internal 114 int 115 rte_vdpa_unregister_device(struct rte_vdpa_device *dev); 116 117 /** 118 * Enable/Disable host notifier mapping for a vdpa port. 119 * 120 * @param vid 121 * vhost device id 122 * @param enable 123 * true for host notifier map, false for host notifier unmap 124 * @param qid 125 * vhost queue id, RTE_VHOST_QUEUE_ALL to configure all the device queues 126 * @return 127 * 0 on success, -1 on failure 128 */ 129 __rte_internal 130 int 131 rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable); 132 133 /** 134 * Synchronize the used ring from mediated ring to guest, log dirty 135 * page for each writeable buffer, caller should handle the used 136 * ring logging before device stop. 137 * 138 * @param vid 139 * vhost device id 140 * @param qid 141 * vhost queue id 142 * @param vring_m 143 * mediated virtio ring pointer 144 * @return 145 * number of synced used entries on success, -1 on failure 146 */ 147 __rte_internal 148 int 149 rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m); 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 #endif /* _VDPA_DRIVER_H_ */ 156