xref: /dpdk/drivers/net/virtio/virtio_user/virtio_user_dev.h (revision 35a6630e2b51b872cfbaf19459888045750592fd)
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 <stdbool.h>
10 #include "../virtio_pci.h"
11 #include "../virtio_ring.h"
12 
13 enum virtio_user_backend_type {
14 	VIRTIO_USER_BACKEND_UNKNOWN,
15 	VIRTIO_USER_BACKEND_VHOST_USER,
16 	VIRTIO_USER_BACKEND_VHOST_KERNEL,
17 	VIRTIO_USER_BACKEND_VHOST_VDPA,
18 };
19 
20 struct virtio_user_queue {
21 	uint16_t used_idx;
22 	bool avail_wrap_counter;
23 	bool used_wrap_counter;
24 };
25 
26 struct virtio_user_dev {
27 	enum virtio_user_backend_type backend_type;
28 	/* for vhost_user backend */
29 	int		vhostfd;
30 	int		listenfd;   /* listening fd */
31 	bool		is_server;  /* server or client mode */
32 
33 	/* for vhost_kernel backend */
34 	char		*ifname;
35 	int		*vhostfds;
36 	int		*tapfds;
37 
38 	/* for both vhost_user and vhost_kernel */
39 	int		callfds[VIRTIO_MAX_VIRTQUEUES];
40 	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
41 	int		mac_specified;
42 	uint32_t	max_queue_pairs;
43 	uint32_t	queue_pairs;
44 	uint32_t	queue_size;
45 	uint64_t	features; /* the negotiated features with driver,
46 				   * and will be sync with device
47 				   */
48 	uint64_t	device_features; /* supported features by device */
49 	uint64_t	frontend_features; /* enabled frontend features */
50 	uint64_t	unsupported_features; /* unsupported features mask */
51 	uint64_t	protocol_features; /* negotiated protocol features */
52 	uint8_t		status;
53 	uint16_t	net_status;
54 	uint16_t	port_id;
55 	uint8_t		mac_addr[RTE_ETHER_ADDR_LEN];
56 	char		path[PATH_MAX];
57 	union {
58 		struct vring		vrings[VIRTIO_MAX_VIRTQUEUES];
59 		struct vring_packed	packed_vrings[VIRTIO_MAX_VIRTQUEUES];
60 	};
61 	struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
62 	bool		qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS];
63 
64 	struct virtio_user_backend_ops *ops;
65 	pthread_mutex_t	mutex;
66 	bool		started;
67 };
68 
69 int virtio_user_dev_set_features(struct virtio_user_dev *dev);
70 int virtio_user_start_device(struct virtio_user_dev *dev);
71 int virtio_user_stop_device(struct virtio_user_dev *dev);
72 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
73 			 int cq, int queue_size, const char *mac, char **ifname,
74 			 int server, int mrg_rxbuf, int in_order,
75 			 int packed_vq,
76 			 enum virtio_user_backend_type backend_type);
77 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
78 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
79 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
80 				  uint16_t queue_idx);
81 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
82 int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status);
83 int virtio_user_dev_update_status(struct virtio_user_dev *dev);
84 extern const char * const virtio_user_backend_strings[];
85 #endif
86