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 13 struct virtio_user_queue { 14 uint16_t used_idx; 15 bool avail_wrap_counter; 16 bool used_wrap_counter; 17 }; 18 19 struct virtio_user_dev { 20 /* for vhost_user backend */ 21 int vhostfd; 22 int listenfd; /* listening fd */ 23 bool is_server; /* server or client mode */ 24 25 /* for vhost_kernel backend */ 26 char *ifname; 27 int *vhostfds; 28 int *tapfds; 29 30 /* for both vhost_user and vhost_kernel */ 31 int callfds[VIRTIO_MAX_VIRTQUEUES]; 32 int kickfds[VIRTIO_MAX_VIRTQUEUES]; 33 int mac_specified; 34 uint32_t max_queue_pairs; 35 uint32_t queue_pairs; 36 uint32_t queue_size; 37 uint64_t features; /* the negotiated features with driver, 38 * and will be sync with device 39 */ 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 uint8_t status; 44 uint16_t port_id; 45 uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; 46 char path[PATH_MAX]; 47 union { 48 struct vring vrings[VIRTIO_MAX_VIRTQUEUES]; 49 struct vring_packed packed_vrings[VIRTIO_MAX_VIRTQUEUES]; 50 }; 51 struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES]; 52 53 struct virtio_user_backend_ops *ops; 54 pthread_mutex_t mutex; 55 bool started; 56 }; 57 58 int is_vhost_user_by_type(const char *path); 59 int virtio_user_start_device(struct virtio_user_dev *dev); 60 int virtio_user_stop_device(struct virtio_user_dev *dev); 61 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues, 62 int cq, int queue_size, const char *mac, char **ifname, 63 int server, int mrg_rxbuf, int in_order, 64 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, 68 uint16_t queue_idx); 69 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs); 70 #endif 71