net/virtio-user: support reply-ack
[dpdk.git] / drivers / net / virtio / virtio_user / vhost.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2016 Intel Corporation
3  */
4
5 #ifndef _VIRTIO_USER_VHOST_H
6 #define _VIRTIO_USER_VHOST_H
7
8 #include <stdint.h>
9 #include <linux/types.h>
10 #include <linux/ioctl.h>
11
12 #include "../virtio_pci.h"
13 #include "../virtio_logs.h"
14 #include "../virtqueue.h"
15
16 struct vhost_vring_state {
17         unsigned int index;
18         unsigned int num;
19 };
20
21 struct vhost_vring_file {
22         unsigned int index;
23         int fd;
24 };
25
26 struct vhost_vring_addr {
27         unsigned int index;
28         /* Option flags. */
29         unsigned int flags;
30         /* Flag values: */
31         /* Whether log address is valid. If set enables logging. */
32 #define VHOST_VRING_F_LOG 0
33
34         /* Start of array of descriptors (virtually contiguous) */
35         uint64_t desc_user_addr;
36         /* Used structure address. Must be 32 bit aligned */
37         uint64_t used_user_addr;
38         /* Available structure address. Must be 16 bit aligned */
39         uint64_t avail_user_addr;
40         /* Logging support. */
41         /* Log writes to used structure, at offset calculated from specified
42          * address. Address must be 32 bit aligned.
43          */
44         uint64_t log_guest_addr;
45 };
46
47 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
48 #define VHOST_USER_F_PROTOCOL_FEATURES 30
49 #endif
50
51 /** Protocol features. */
52 #ifndef VHOST_USER_PROTOCOL_F_MQ
53 #define VHOST_USER_PROTOCOL_F_MQ 0
54 #endif
55
56 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
57 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
58 #endif
59
60 enum vhost_user_request {
61         VHOST_USER_NONE = 0,
62         VHOST_USER_GET_FEATURES = 1,
63         VHOST_USER_SET_FEATURES = 2,
64         VHOST_USER_SET_OWNER = 3,
65         VHOST_USER_RESET_OWNER = 4,
66         VHOST_USER_SET_MEM_TABLE = 5,
67         VHOST_USER_SET_LOG_BASE = 6,
68         VHOST_USER_SET_LOG_FD = 7,
69         VHOST_USER_SET_VRING_NUM = 8,
70         VHOST_USER_SET_VRING_ADDR = 9,
71         VHOST_USER_SET_VRING_BASE = 10,
72         VHOST_USER_GET_VRING_BASE = 11,
73         VHOST_USER_SET_VRING_KICK = 12,
74         VHOST_USER_SET_VRING_CALL = 13,
75         VHOST_USER_SET_VRING_ERR = 14,
76         VHOST_USER_GET_PROTOCOL_FEATURES = 15,
77         VHOST_USER_SET_PROTOCOL_FEATURES = 16,
78         VHOST_USER_GET_QUEUE_NUM = 17,
79         VHOST_USER_SET_VRING_ENABLE = 18,
80         VHOST_USER_MAX
81 };
82
83 extern const char * const vhost_msg_strings[VHOST_USER_MAX];
84
85 struct vhost_memory_region {
86         uint64_t guest_phys_addr;
87         uint64_t memory_size; /* bytes */
88         uint64_t userspace_addr;
89         uint64_t mmap_offset;
90 };
91
92 struct virtio_user_dev;
93
94 struct virtio_user_backend_ops {
95         int (*setup)(struct virtio_user_dev *dev);
96         int (*send_request)(struct virtio_user_dev *dev,
97                             enum vhost_user_request req,
98                             void *arg);
99         int (*enable_qp)(struct virtio_user_dev *dev,
100                          uint16_t pair_idx,
101                          int enable);
102 };
103
104 extern struct virtio_user_backend_ops virtio_ops_user;
105 extern struct virtio_user_backend_ops virtio_ops_kernel;
106
107 #endif