56e638f8a6d600b560f13e773d8715c02d49b132
[dpdk.git] / drivers / net / virtio / virtio_user / virtio_user_dev.h
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         uint64_t        protocol_features; /* negotiated protocol features
44                                             * (Vhost-user only)
45                                             */
46         uint8_t         status;
47         uint16_t        port_id;
48         uint8_t         mac_addr[RTE_ETHER_ADDR_LEN];
49         char            path[PATH_MAX];
50         union {
51                 struct vring            vrings[VIRTIO_MAX_VIRTQUEUES];
52                 struct vring_packed     packed_vrings[VIRTIO_MAX_VIRTQUEUES];
53         };
54         struct virtio_user_queue packed_queues[VIRTIO_MAX_VIRTQUEUES];
55         bool            qp_enabled[VIRTIO_MAX_VIRTQUEUE_PAIRS];
56
57         struct virtio_user_backend_ops *ops;
58         pthread_mutex_t mutex;
59         bool            started;
60 };
61
62 int is_vhost_user_by_type(const char *path);
63 int virtio_user_start_device(struct virtio_user_dev *dev);
64 int virtio_user_stop_device(struct virtio_user_dev *dev);
65 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
66                          int cq, int queue_size, const char *mac, char **ifname,
67                          int server, int mrg_rxbuf, int in_order,
68                          int packed_vq);
69 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
70 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
71 void virtio_user_handle_cq_packed(struct virtio_user_dev *dev,
72                                   uint16_t queue_idx);
73 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
74 #endif