net/virtio: add virtio-user vring address ops
[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 <rte_errno.h>
13
14 #include "../virtio.h"
15 #include "../virtio_logs.h"
16 #include "../virtqueue.h"
17
18 struct vhost_vring_state {
19         unsigned int index;
20         unsigned int num;
21 };
22
23 struct vhost_vring_file {
24         unsigned int index;
25         int fd;
26 };
27
28 struct vhost_vring_addr {
29         unsigned int index;
30         /* Option flags. */
31         unsigned int flags;
32         /* Flag values: */
33         /* Whether log address is valid. If set enables logging. */
34 #define VHOST_VRING_F_LOG 0
35
36         /* Start of array of descriptors (virtually contiguous) */
37         uint64_t desc_user_addr;
38         /* Used structure address. Must be 32 bit aligned */
39         uint64_t used_user_addr;
40         /* Available structure address. Must be 16 bit aligned */
41         uint64_t avail_user_addr;
42         /* Logging support. */
43         /* Log writes to used structure, at offset calculated from specified
44          * address. Address must be 32 bit aligned.
45          */
46         uint64_t log_guest_addr;
47 };
48
49 #ifndef VHOST_USER_F_PROTOCOL_FEATURES
50 #define VHOST_USER_F_PROTOCOL_FEATURES 30
51 #endif
52
53 /** Protocol features. */
54 #ifndef VHOST_USER_PROTOCOL_F_MQ
55 #define VHOST_USER_PROTOCOL_F_MQ 0
56 #endif
57
58 #ifndef VHOST_USER_PROTOCOL_F_REPLY_ACK
59 #define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
60 #endif
61
62 #ifndef VHOST_USER_PROTOCOL_F_STATUS
63 #define VHOST_USER_PROTOCOL_F_STATUS 16
64 #endif
65
66 enum vhost_user_request {
67         VHOST_USER_NONE = 0,
68         VHOST_USER_GET_FEATURES = 1,
69         VHOST_USER_SET_FEATURES = 2,
70         VHOST_USER_SET_OWNER = 3,
71         VHOST_USER_RESET_OWNER = 4,
72         VHOST_USER_SET_MEM_TABLE = 5,
73         VHOST_USER_SET_LOG_BASE = 6,
74         VHOST_USER_SET_LOG_FD = 7,
75         VHOST_USER_SET_VRING_NUM = 8,
76         VHOST_USER_SET_VRING_ADDR = 9,
77         VHOST_USER_SET_VRING_BASE = 10,
78         VHOST_USER_GET_VRING_BASE = 11,
79         VHOST_USER_SET_VRING_KICK = 12,
80         VHOST_USER_SET_VRING_CALL = 13,
81         VHOST_USER_SET_VRING_ERR = 14,
82         VHOST_USER_GET_PROTOCOL_FEATURES = 15,
83         VHOST_USER_SET_PROTOCOL_FEATURES = 16,
84         VHOST_USER_GET_QUEUE_NUM = 17,
85         VHOST_USER_SET_VRING_ENABLE = 18,
86         VHOST_USER_SET_STATUS = 39,
87         VHOST_USER_GET_STATUS = 40,
88         VHOST_USER_MAX
89 };
90
91 #ifndef VHOST_BACKEND_F_IOTLB_MSG_V2
92 #define VHOST_BACKEND_F_IOTLB_MSG_V2 1
93 #endif
94
95 #ifndef VHOST_BACKEND_F_IOTLB_BATCH
96 #define VHOST_BACKEND_F_IOTLB_BATCH 2
97 #endif
98
99 extern const char * const vhost_msg_strings[VHOST_USER_MAX];
100
101 struct vhost_memory_region {
102         uint64_t guest_phys_addr;
103         uint64_t memory_size; /* bytes */
104         uint64_t userspace_addr;
105         uint64_t mmap_offset;
106 };
107
108 struct virtio_user_dev;
109
110 struct virtio_user_backend_ops {
111         int (*setup)(struct virtio_user_dev *dev);
112         int (*set_owner)(struct virtio_user_dev *dev);
113         int (*get_features)(struct virtio_user_dev *dev, uint64_t *features);
114         int (*set_features)(struct virtio_user_dev *dev, uint64_t features);
115         int (*get_protocol_features)(struct virtio_user_dev *dev, uint64_t *features);
116         int (*set_protocol_features)(struct virtio_user_dev *dev, uint64_t features);
117         int (*set_memory_table)(struct virtio_user_dev *dev);
118         int (*set_vring_num)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
119         int (*set_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
120         int (*get_vring_base)(struct virtio_user_dev *dev, struct vhost_vring_state *state);
121         int (*set_vring_call)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
122         int (*set_vring_kick)(struct virtio_user_dev *dev, struct vhost_vring_file *file);
123         int (*set_vring_addr)(struct virtio_user_dev *dev, struct vhost_vring_addr *addr);
124         int (*send_request)(struct virtio_user_dev *dev,
125                             enum vhost_user_request req,
126                             void *arg);
127         int (*enable_qp)(struct virtio_user_dev *dev,
128                          uint16_t pair_idx,
129                          int enable);
130         int (*dma_map)(struct virtio_user_dev *dev, void *addr,
131                                   uint64_t iova, size_t len);
132         int (*dma_unmap)(struct virtio_user_dev *dev, void *addr,
133                                   uint64_t iova, size_t len);
134 };
135
136 extern struct virtio_user_backend_ops virtio_ops_user;
137 extern struct virtio_user_backend_ops virtio_ops_kernel;
138 extern struct virtio_user_backend_ops virtio_ops_vdpa;
139
140 #endif