xref: /dpdk/drivers/net/virtio/virtio_user/virtio_user_dev.h (revision ceccf8dc7c3d7797e380f12b45cd3ea1d7396b58)
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 #include "vhost.h"
13 
14 struct virtio_user_dev {
15 	/* for vhost_user backend */
16 	int		vhostfd;
17 	int		listenfd;   /* listening fd */
18 	bool		is_server;  /* server or client mode */
19 
20 	/* for vhost_kernel backend */
21 	char		*ifname;
22 	int		*vhostfds;
23 	int		*tapfds;
24 
25 	/* for both vhost_user and vhost_kernel */
26 	int		callfds[VIRTIO_MAX_VIRTQUEUES];
27 	int		kickfds[VIRTIO_MAX_VIRTQUEUES];
28 	int		mac_specified;
29 	uint32_t	max_queue_pairs;
30 	uint32_t	queue_pairs;
31 	uint32_t	queue_size;
32 	uint64_t	features; /* the negotiated features with driver,
33 				   * and will be sync with device
34 				   */
35 	uint64_t	device_features; /* supported features by device */
36 	uint64_t	frontend_features; /* enabled frontend features */
37 	uint64_t	unsupported_features; /* unsupported features mask */
38 	uint8_t		status;
39 	uint16_t	port_id;
40 	uint8_t		mac_addr[ETHER_ADDR_LEN];
41 	char		path[PATH_MAX];
42 	struct vring	vrings[VIRTIO_MAX_VIRTQUEUES];
43 	struct virtio_user_backend_ops *ops;
44 	pthread_mutex_t	mutex;
45 	bool		started;
46 };
47 
48 int is_vhost_user_by_type(const char *path);
49 int virtio_user_start_device(struct virtio_user_dev *dev);
50 int virtio_user_stop_device(struct virtio_user_dev *dev);
51 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
52 			 int cq, int queue_size, const char *mac, char **ifname,
53 			 int mrg_rxbuf, int in_order);
54 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
55 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
56 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
57 #endif
58