xref: /dpdk/lib/vhost/vdpa_driver.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
194c16e89SMaxime Coquelin /* SPDX-License-Identifier: BSD-3-Clause
294c16e89SMaxime Coquelin  * Copyright(c) 2018 Intel Corporation
394c16e89SMaxime Coquelin  */
494c16e89SMaxime Coquelin 
594c16e89SMaxime Coquelin #ifndef _VDPA_DRIVER_H_
694c16e89SMaxime Coquelin #define _VDPA_DRIVER_H_
794c16e89SMaxime Coquelin 
894c16e89SMaxime Coquelin #include <stdbool.h>
994c16e89SMaxime Coquelin 
1094c16e89SMaxime Coquelin #include <rte_compat.h>
1194c16e89SMaxime Coquelin 
1294c16e89SMaxime Coquelin #include "rte_vhost.h"
1394c16e89SMaxime Coquelin #include "rte_vdpa.h"
1494c16e89SMaxime Coquelin 
15*719834a6SMattias Rönnblom #ifdef __cplusplus
16*719834a6SMattias Rönnblom extern "C" {
17*719834a6SMattias Rönnblom #endif
18*719834a6SMattias Rönnblom 
1994c16e89SMaxime Coquelin #define RTE_VHOST_QUEUE_ALL UINT16_MAX
2094c16e89SMaxime Coquelin 
2194c16e89SMaxime Coquelin /**
2294c16e89SMaxime Coquelin  * vdpa device operations
2394c16e89SMaxime Coquelin  */
2494c16e89SMaxime Coquelin struct rte_vdpa_dev_ops {
2594c16e89SMaxime Coquelin 	/** Get capabilities of this device (Mandatory) */
2694c16e89SMaxime Coquelin 	int (*get_queue_num)(struct rte_vdpa_device *dev, uint32_t *queue_num);
2794c16e89SMaxime Coquelin 
2894c16e89SMaxime Coquelin 	/** Get supported features of this device (Mandatory) */
2994c16e89SMaxime Coquelin 	int (*get_features)(struct rte_vdpa_device *dev, uint64_t *features);
3094c16e89SMaxime Coquelin 
3194c16e89SMaxime Coquelin 	/** Get supported protocol features of this device (Mandatory) */
3294c16e89SMaxime Coquelin 	int (*get_protocol_features)(struct rte_vdpa_device *dev,
3394c16e89SMaxime Coquelin 			uint64_t *protocol_features);
3494c16e89SMaxime Coquelin 
3594c16e89SMaxime Coquelin 	/** Driver configure the device (Mandatory) */
3694c16e89SMaxime Coquelin 	int (*dev_conf)(int vid);
3794c16e89SMaxime Coquelin 
3894c16e89SMaxime Coquelin 	/** Driver close the device (Mandatory) */
3994c16e89SMaxime Coquelin 	int (*dev_close)(int vid);
4094c16e89SMaxime Coquelin 
4167cdaea0SXueming Li 	/** Connection closed, clean up resources */
4267cdaea0SXueming Li 	int (*dev_cleanup)(int vid);
4367cdaea0SXueming Li 
4494c16e89SMaxime Coquelin 	/** Enable/disable this vring (Mandatory) */
4594c16e89SMaxime Coquelin 	int (*set_vring_state)(int vid, int vring, int state);
4694c16e89SMaxime Coquelin 
4794c16e89SMaxime Coquelin 	/** Set features when changed (Mandatory) */
4894c16e89SMaxime Coquelin 	int (*set_features)(int vid);
4994c16e89SMaxime Coquelin 
5094c16e89SMaxime Coquelin 	/** Destination operations when migration done */
5194c16e89SMaxime Coquelin 	int (*migration_done)(int vid);
5294c16e89SMaxime Coquelin 
5394c16e89SMaxime Coquelin 	/** Get the vfio group fd */
5494c16e89SMaxime Coquelin 	int (*get_vfio_group_fd)(int vid);
5594c16e89SMaxime Coquelin 
5694c16e89SMaxime Coquelin 	/** Get the vfio device fd */
5794c16e89SMaxime Coquelin 	int (*get_vfio_device_fd)(int vid);
5894c16e89SMaxime Coquelin 
5994c16e89SMaxime Coquelin 	/** Get the notify area info of the queue */
6094c16e89SMaxime Coquelin 	int (*get_notify_area)(int vid, int qid,
6194c16e89SMaxime Coquelin 			uint64_t *offset, uint64_t *size);
6294c16e89SMaxime Coquelin 
6394c16e89SMaxime Coquelin 	/** Get statistics name */
6494c16e89SMaxime Coquelin 	int (*get_stats_names)(struct rte_vdpa_device *dev,
6594c16e89SMaxime Coquelin 			struct rte_vdpa_stat_name *stats_names,
6694c16e89SMaxime Coquelin 			unsigned int size);
6794c16e89SMaxime Coquelin 
6894c16e89SMaxime Coquelin 	/** Get statistics of the queue */
6994c16e89SMaxime Coquelin 	int (*get_stats)(struct rte_vdpa_device *dev, int qid,
7094c16e89SMaxime Coquelin 			struct rte_vdpa_stat *stats, unsigned int n);
7194c16e89SMaxime Coquelin 
7294c16e89SMaxime Coquelin 	/** Reset statistics of the queue */
7394c16e89SMaxime Coquelin 	int (*reset_stats)(struct rte_vdpa_device *dev, int qid);
7494c16e89SMaxime Coquelin 
75fb231556SAndy Pei 	/** Get the device configuration space */
76fb231556SAndy Pei 	int (*get_config)(int vid, uint8_t *config, uint32_t size);
77fb231556SAndy Pei 
78fb231556SAndy Pei 	/** Set the device configuration space */
79fb231556SAndy Pei 	int (*set_config)(int vid, uint8_t *config, uint32_t offset,
80fb231556SAndy Pei 		      uint32_t size, uint32_t flags);
81486f65e6SAndy Pei 
82486f65e6SAndy Pei 	/** get device type: net device, blk device... */
83486f65e6SAndy Pei 	int (*get_dev_type)(struct rte_vdpa_device *dev, uint32_t *type);
8494c16e89SMaxime Coquelin };
8594c16e89SMaxime Coquelin 
8694c16e89SMaxime Coquelin /**
8794c16e89SMaxime Coquelin  * vdpa device structure includes device address and device operations.
8894c16e89SMaxime Coquelin  */
8994c16e89SMaxime Coquelin struct rte_vdpa_device {
9094c16e89SMaxime Coquelin 	RTE_TAILQ_ENTRY(rte_vdpa_device) next;
9194c16e89SMaxime Coquelin 	/** Generic device information */
9294c16e89SMaxime Coquelin 	struct rte_device *device;
9394c16e89SMaxime Coquelin 	/** vdpa device operations */
9494c16e89SMaxime Coquelin 	struct rte_vdpa_dev_ops *ops;
95f92ab3f0SAndy Pei 	/** vdpa device type: net, blk... */
96f92ab3f0SAndy Pei 	uint32_t type;
9794c16e89SMaxime Coquelin };
9894c16e89SMaxime Coquelin 
9994c16e89SMaxime Coquelin /**
10094c16e89SMaxime Coquelin  * Register a vdpa device
10194c16e89SMaxime Coquelin  *
10294c16e89SMaxime Coquelin  * @param rte_dev
10394c16e89SMaxime Coquelin  *  the generic device pointer
10494c16e89SMaxime Coquelin  * @param ops
10594c16e89SMaxime Coquelin  *  the vdpa device operations
10694c16e89SMaxime Coquelin  * @return
10794c16e89SMaxime Coquelin  *  vDPA device pointer on success, NULL on failure
10894c16e89SMaxime Coquelin  */
10994c16e89SMaxime Coquelin __rte_internal
11094c16e89SMaxime Coquelin struct rte_vdpa_device *
11194c16e89SMaxime Coquelin rte_vdpa_register_device(struct rte_device *rte_dev,
11294c16e89SMaxime Coquelin 		struct rte_vdpa_dev_ops *ops);
11394c16e89SMaxime Coquelin 
11494c16e89SMaxime Coquelin /**
11594c16e89SMaxime Coquelin  * Unregister a vdpa device
11694c16e89SMaxime Coquelin  *
11794c16e89SMaxime Coquelin  * @param dev
11894c16e89SMaxime Coquelin  *  vDPA device pointer
11994c16e89SMaxime Coquelin  * @return
12094c16e89SMaxime Coquelin  *  device id on success, -1 on failure
12194c16e89SMaxime Coquelin  */
12294c16e89SMaxime Coquelin __rte_internal
12394c16e89SMaxime Coquelin int
12494c16e89SMaxime Coquelin rte_vdpa_unregister_device(struct rte_vdpa_device *dev);
12594c16e89SMaxime Coquelin 
12694c16e89SMaxime Coquelin /**
12794c16e89SMaxime Coquelin  * Enable/Disable host notifier mapping for a vdpa port.
12894c16e89SMaxime Coquelin  *
12994c16e89SMaxime Coquelin  * @param vid
13094c16e89SMaxime Coquelin  *  vhost device id
13194c16e89SMaxime Coquelin  * @param enable
13294c16e89SMaxime Coquelin  *  true for host notifier map, false for host notifier unmap
13394c16e89SMaxime Coquelin  * @param qid
13494c16e89SMaxime Coquelin  *  vhost queue id, RTE_VHOST_QUEUE_ALL to configure all the device queues
13594c16e89SMaxime Coquelin  * @return
13694c16e89SMaxime Coquelin  *  0 on success, -1 on failure
13794c16e89SMaxime Coquelin  */
13894c16e89SMaxime Coquelin __rte_internal
13994c16e89SMaxime Coquelin int
14094c16e89SMaxime Coquelin rte_vhost_host_notifier_ctrl(int vid, uint16_t qid, bool enable);
14194c16e89SMaxime Coquelin 
14294c16e89SMaxime Coquelin /**
14394c16e89SMaxime Coquelin  * Synchronize the used ring from mediated ring to guest, log dirty
14494c16e89SMaxime Coquelin  * page for each writeable buffer, caller should handle the used
14594c16e89SMaxime Coquelin  * ring logging before device stop.
14694c16e89SMaxime Coquelin  *
14794c16e89SMaxime Coquelin  * @param vid
14894c16e89SMaxime Coquelin  *  vhost device id
14994c16e89SMaxime Coquelin  * @param qid
15094c16e89SMaxime Coquelin  *  vhost queue id
15194c16e89SMaxime Coquelin  * @param vring_m
15294c16e89SMaxime Coquelin  *  mediated virtio ring pointer
15394c16e89SMaxime Coquelin  * @return
15494c16e89SMaxime Coquelin  *  number of synced used entries on success, -1 on failure
15594c16e89SMaxime Coquelin  */
15694c16e89SMaxime Coquelin __rte_internal
15794c16e89SMaxime Coquelin int
15894c16e89SMaxime Coquelin rte_vdpa_relay_vring_used(int vid, uint16_t qid, void *vring_m);
15994c16e89SMaxime Coquelin 
160cedca408SBrian Dooley #ifdef __cplusplus
161cedca408SBrian Dooley }
162cedca408SBrian Dooley #endif
163cedca408SBrian Dooley 
16494c16e89SMaxime Coquelin #endif /* _VDPA_DRIVER_H_ */
165