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 11 #include "../virtio.h" 12 #include "../virtio_ring.h" 13 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, 19 }; 20 21 struct virtio_user_queue { 22 uint16_t used_idx; 23 bool avail_wrap_counter; 24 bool used_wrap_counter; 25 }; 26 27 struct virtio_user_dev { 28 struct virtio_hw hw; 29 enum virtio_user_backend_type backend_type; 30 bool is_server; /* server or client mode */ 31 32 int *callfds; 33 int *kickfds; 34 int mac_specified; 35 uint16_t max_queue_pairs; 36 uint16_t queue_pairs; 37 uint32_t queue_size; 38 uint64_t features; /* the negotiated features with driver, 39 * and will be sync with device 40 */ 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 */ 44 uint8_t status; 45 uint16_t net_status; 46 uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; 47 char path[PATH_MAX]; 48 char *ifname; 49 50 union { 51 void *ptr; 52 struct vring *split; 53 struct vring_packed *packed; 54 } vrings; 55 56 struct virtio_user_queue *packed_queues; 57 bool *qp_enabled; 58 59 struct virtio_user_backend_ops *ops; 60 pthread_mutex_t mutex; 61 bool started; 62 63 bool hw_cvq; 64 struct virtqueue *scvq; 65 66 void *backend_data; 67 68 uint16_t **notify_area; 69 }; 70 71 int virtio_user_dev_set_features(struct virtio_user_dev *dev); 72 int virtio_user_start_device(struct virtio_user_dev *dev); 73 int virtio_user_stop_device(struct virtio_user_dev *dev); 74 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues, 75 int cq, int queue_size, const char *mac, char **ifname, 76 int server, int mrg_rxbuf, int in_order, 77 int packed_vq, 78 enum virtio_user_backend_type backend_type); 79 void virtio_user_dev_uninit(struct virtio_user_dev *dev); 80 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx); 81 int virtio_user_dev_create_shadow_cvq(struct virtio_user_dev *dev, struct virtqueue *vq); 82 void virtio_user_dev_destroy_shadow_cvq(struct virtio_user_dev *dev); 83 int virtio_user_dev_set_status(struct virtio_user_dev *dev, uint8_t status); 84 int virtio_user_dev_update_status(struct virtio_user_dev *dev); 85 int virtio_user_dev_update_link_state(struct virtio_user_dev *dev); 86 int virtio_user_dev_set_mac(struct virtio_user_dev *dev); 87 int virtio_user_dev_get_mac(struct virtio_user_dev *dev); 88 int virtio_user_dev_get_rss_config(struct virtio_user_dev *dev, void *dst, size_t offset, 89 int length); 90 void virtio_user_dev_delayed_disconnect_handler(void *param); 91 int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev); 92 extern const char * const virtio_user_backend_strings[]; 93 #endif 94