1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
5 #ifndef _VIRTIO_USER_DEV_H
6 #define _VIRTIO_USER_DEV_H
11 #include "../virtio.h"
12 #include "../virtio_ring.h"
14 enum virtio_user_backend_type {
15 VIRTIO_USER_BACKEND_UNKNOWN,
16 VIRTIO_USER_BACKEND_VHOST_USER,
17 VIRTIO_USER_BACKEND_VHOST_KERNEL,
18 VIRTIO_USER_BACKEND_VHOST_VDPA,
21 struct virtio_user_queue {
23 bool avail_wrap_counter;
24 bool used_wrap_counter;
27 struct virtio_user_dev {
29 enum virtio_user_backend_type backend_type;
30 bool is_server; /* server or client mode */
32 int callfds[VIRTIO_MAX_VIRTQUEUES];
33 int kickfds[VIRTIO_MAX_VIRTQUEUES];
35 uint32_t max_queue_pairs;
38 uint64_t features; /* the negotiated features with driver,
39 * and will be sync with device
41 uint64_t device_features; /* supported features by device */
42 uint64_t frontend_features; /* enabled frontend features */
43 uint64_t unsupported_features; /* unsupported features mask */
46 uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
51 struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
52 struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES];
54 struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
55 bool qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS];
57 struct virtio_user_backend_ops *ops;
58 pthread_mutex_t mutex;
64 int virtio_user_dev_set_features(struct virtio_user_dev *dev);
65 int virtio_user_start_device(struct virtio_user_dev *dev);
66 int virtio_user_stop_device(struct virtio_user_dev *dev);
67 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
68 int cq, int queue_size, const char *mac, char **ifname,
69 int server, int mrg_rxbuf, int in_order,
71 enum virtio_user_backend_type backend_type);
72 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
73 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
74 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
76 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
77 int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status);
78 int virtio_user_dev_update_status(struct virtio_user_dev *dev);
79 int virtio_user_dev_update_link_state(struct virtio_user_dev *dev);
80 void virtio_user_dev_delayed_disconnect_handler(void *param);
81 int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);
82 extern const char * const virtio_user_backend_strings[];