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