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
10 #include "../virtio_pci.h"
11 #include "../virtio_ring.h"
14 struct virtio_user_queue {
16 bool avail_wrap_counter;
17 bool used_wrap_counter;
20 struct virtio_user_dev {
21 /* for vhost_user backend */
23 int listenfd; /* listening fd */
24 bool is_server; /* server or client mode */
26 /* for vhost_kernel backend */
31 /* for both vhost_user and vhost_kernel */
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[ETHER_ADDR_LEN];
49 struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
50 struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES];
52 struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
54 struct virtio_user_backend_ops *ops;
55 pthread_mutex_t mutex;
59 int is_vhost_user_by_type(const char *path);
60 int virtio_user_start_device(struct virtio_user_dev *dev);
61 int virtio_user_stop_device(struct virtio_user_dev *dev);
62 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
63 int cq, int queue_size, const char *mac, char **ifname,
64 int mrg_rxbuf, int in_order, int packed_vq);
65 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
66 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
67 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
69 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);