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_dev {
15 /* for vhost_user backend */
17 int listenfd; /* listening fd */
18 bool is_server; /* server or client mode */
20 /* for vhost_kernel backend */
25 /* for both vhost_user and vhost_kernel */
26 int callfds[VIRTIO_MAX_VIRTQUEUES];
27 int kickfds[VIRTIO_MAX_VIRTQUEUES];
29 uint32_t max_queue_pairs;
32 uint64_t features; /* the negotiated features with driver,
33 * and will be sync with device
35 uint64_t device_features; /* supported features by device */
38 uint8_t mac_addr[ETHER_ADDR_LEN];
40 struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
41 struct virtio_user_backend_ops *ops;
42 pthread_mutex_t mutex;
46 int is_vhost_user_by_type(const char *path);
47 int virtio_user_start_device(struct virtio_user_dev *dev);
48 int virtio_user_stop_device(struct virtio_user_dev *dev);
49 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
50 int cq, int queue_size, const char *mac, char **ifname);
51 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
52 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
53 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);