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"
13 struct virtio_user_queue {
15 bool avail_wrap_counter;
16 bool used_wrap_counter;
19 struct virtio_user_dev {
20 /* for vhost_user backend */
22 int listenfd; /* listening fd */
23 bool is_server; /* server or client mode */
25 /* for vhost_kernel backend */
30 /* for both vhost_user and vhost_kernel */
31 int callfds[VIRTIO_MAX_VIRTQUEUES];
32 int kickfds[VIRTIO_MAX_VIRTQUEUES];
34 uint32_t max_queue_pairs;
37 uint64_t features; /* the negotiated features with driver,
38 * and will be sync with device
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
49 uint8_t mac_addr[RTE_ETHER_ADDR_LEN];
52 struct vring vrings[VIRTIO_MAX_VIRTQUEUES];
53 struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES];
55 struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
56 bool qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS];
58 struct virtio_user_backend_ops *ops;
59 pthread_mutex_t mutex;
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,
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,
74 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);