1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4 
5 #ifndef _VIRTIO_USER_DEV_H
6 #define _VIRTIO_USER_DEV_H
7 
8 #include <limits.h>
9 #include "../virtio_pci.h"
10 #include "../virtio_ring.h"
11 #include "vhost.h"
12 
13 struct virtio_user_dev {
14 	/* for vhost_user backend */
15 	int		vhostfd;
16 
17 	/* for vhost_kernel backend */
18 	char		*ifname;
19 	int		*vhostfds;
20 	int		*tapfds;
21 
22 	/* for both vhost_user and vhost_kernel */
23 	int		callfds[VIRTIO_MAX_VIRTQUEUES];
24 	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
25 	int		mac_specified;
26 	uint32_t	max_queue_pairs;
27 	uint32_t	queue_pairs;
28 	uint32_t	queue_size;
29 	uint64_t	features; /* the negotiated features with driver,
30 				   * and will be sync with device
31 				   */
32 	uint64_t	device_features; /* supported features by device */
33 	uint8_t		status;
34 	uint16_t	port_id;
35 	uint8_t		mac_addr[ETHER_ADDR_LEN];
36 	char		path[PATH_MAX];
37 	struct vring	vrings[VIRTIO_MAX_VIRTQUEUES];
38 	struct virtio_user_backend_ops *ops;
39 };
40 
41 int is_vhost_user_by_type(const char *path);
42 int virtio_user_start_device(struct virtio_user_dev *dev);
43 int virtio_user_stop_device(struct virtio_user_dev *dev);
44 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
45 			 int cq, int queue_size, const char *mac, char **ifname);
46 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
47 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
48 #endif
49