New upstream version 18.08
[deb_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 #include "vhost.h"
13
14 struct virtio_user_dev {
15         /* for vhost_user backend */
16         int             vhostfd;
17         int             listenfd;   /* listening fd */
18         bool            is_server;  /* server or client mode */
19
20         /* for vhost_kernel backend */
21         char            *ifname;
22         int             *vhostfds;
23         int             *tapfds;
24
25         /* for both vhost_user and vhost_kernel */
26         int             callfds[VIRTIO_MAX_VIRTQUEUES];
27         int             kickfds[VIRTIO_MAX_VIRTQUEUES];
28         int             mac_specified;
29         uint32_t        max_queue_pairs;
30         uint32_t        queue_pairs;
31         uint32_t        queue_size;
32         uint64_t        features; /* the negotiated features with driver,
33                                    * and will be sync with device
34                                    */
35         uint64_t        device_features; /* supported features by device */
36         uint64_t        unsupported_features; /* unsupported features mask */
37         uint8_t         status;
38         uint16_t        port_id;
39         uint8_t         mac_addr[ETHER_ADDR_LEN];
40         char            path[PATH_MAX];
41         struct vring    vrings[VIRTIO_MAX_VIRTQUEUES];
42         struct virtio_user_backend_ops *ops;
43         pthread_mutex_t mutex;
44         bool            started;
45 };
46
47 int is_vhost_user_by_type(const char *path);
48 int virtio_user_start_device(struct virtio_user_dev *dev);
49 int virtio_user_stop_device(struct virtio_user_dev *dev);
50 int virtio_user_dev_init(struct virtio_user_dev *dev, char *path, int queues,
51                          int cq, int queue_size, const char *mac, char **ifname,
52                          int mrg_rxbuf, int in_order);
53 void virtio_user_dev_uninit(struct virtio_user_dev *dev);
54 void virtio_user_handle_cq(struct virtio_user_dev *dev, uint16_t queue_idx);
55 uint8_t virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs);
56 #endif