lib: remove librte_ prefix from directory names
[dpdk.git] / lib / vhost / vhost_user.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _VHOST_NET_USER_H
6 #define _VHOST_NET_USER_H
7
8 #include <stdint.h>
9 #include <linux/vhost.h>
10
11 #include "rte_vhost.h"
12
13 /* refer to hw/virtio/vhost-user.c */
14
15 #define VHOST_MEMORY_MAX_NREGIONS 8
16
17 #define VHOST_USER_PROTOCOL_FEATURES    ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
18                                          (1ULL << VHOST_USER_PROTOCOL_F_LOG_SHMFD) |\
19                                          (1ULL << VHOST_USER_PROTOCOL_F_RARP) | \
20                                          (1ULL << VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
21                                          (1ULL << VHOST_USER_PROTOCOL_F_NET_MTU) | \
22                                          (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
23                                          (1ULL << VHOST_USER_PROTOCOL_F_CRYPTO_SESSION) | \
24                                          (1ULL << VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD) | \
25                                          (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER) | \
26                                          (1ULL << VHOST_USER_PROTOCOL_F_PAGEFAULT) | \
27                                          (1ULL << VHOST_USER_PROTOCOL_F_STATUS))
28
29 typedef enum VhostUserRequest {
30         VHOST_USER_NONE = 0,
31         VHOST_USER_GET_FEATURES = 1,
32         VHOST_USER_SET_FEATURES = 2,
33         VHOST_USER_SET_OWNER = 3,
34         VHOST_USER_RESET_OWNER = 4,
35         VHOST_USER_SET_MEM_TABLE = 5,
36         VHOST_USER_SET_LOG_BASE = 6,
37         VHOST_USER_SET_LOG_FD = 7,
38         VHOST_USER_SET_VRING_NUM = 8,
39         VHOST_USER_SET_VRING_ADDR = 9,
40         VHOST_USER_SET_VRING_BASE = 10,
41         VHOST_USER_GET_VRING_BASE = 11,
42         VHOST_USER_SET_VRING_KICK = 12,
43         VHOST_USER_SET_VRING_CALL = 13,
44         VHOST_USER_SET_VRING_ERR = 14,
45         VHOST_USER_GET_PROTOCOL_FEATURES = 15,
46         VHOST_USER_SET_PROTOCOL_FEATURES = 16,
47         VHOST_USER_GET_QUEUE_NUM = 17,
48         VHOST_USER_SET_VRING_ENABLE = 18,
49         VHOST_USER_SEND_RARP = 19,
50         VHOST_USER_NET_SET_MTU = 20,
51         VHOST_USER_SET_SLAVE_REQ_FD = 21,
52         VHOST_USER_IOTLB_MSG = 22,
53         VHOST_USER_CRYPTO_CREATE_SESS = 26,
54         VHOST_USER_CRYPTO_CLOSE_SESS = 27,
55         VHOST_USER_POSTCOPY_ADVISE = 28,
56         VHOST_USER_POSTCOPY_LISTEN = 29,
57         VHOST_USER_POSTCOPY_END = 30,
58         VHOST_USER_GET_INFLIGHT_FD = 31,
59         VHOST_USER_SET_INFLIGHT_FD = 32,
60         VHOST_USER_SET_STATUS = 39,
61         VHOST_USER_GET_STATUS = 40,
62         VHOST_USER_MAX = 41
63 } VhostUserRequest;
64
65 typedef enum VhostUserSlaveRequest {
66         VHOST_USER_SLAVE_NONE = 0,
67         VHOST_USER_SLAVE_IOTLB_MSG = 1,
68         VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
69         VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
70         VHOST_USER_SLAVE_MAX
71 } VhostUserSlaveRequest;
72
73 typedef struct VhostUserMemoryRegion {
74         uint64_t guest_phys_addr;
75         uint64_t memory_size;
76         uint64_t userspace_addr;
77         uint64_t mmap_offset;
78 } VhostUserMemoryRegion;
79
80 typedef struct VhostUserMemory {
81         uint32_t nregions;
82         uint32_t padding;
83         VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
84 } VhostUserMemory;
85
86 typedef struct VhostUserLog {
87         uint64_t mmap_size;
88         uint64_t mmap_offset;
89 } VhostUserLog;
90
91 /* Comply with Cryptodev-Linux */
92 #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH   512
93 #define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64
94
95 /* Same structure as vhost-user backend session info */
96 typedef struct VhostUserCryptoSessionParam {
97         int64_t session_id;
98         uint32_t op_code;
99         uint32_t cipher_algo;
100         uint32_t cipher_key_len;
101         uint32_t hash_algo;
102         uint32_t digest_len;
103         uint32_t auth_key_len;
104         uint32_t aad_len;
105         uint8_t op_type;
106         uint8_t dir;
107         uint8_t hash_mode;
108         uint8_t chaining_dir;
109         uint8_t *ciphe_key;
110         uint8_t *auth_key;
111         uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH];
112         uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH];
113 } VhostUserCryptoSessionParam;
114
115 typedef struct VhostUserVringArea {
116         uint64_t u64;
117         uint64_t size;
118         uint64_t offset;
119 } VhostUserVringArea;
120
121 typedef struct VhostUserInflight {
122         uint64_t mmap_size;
123         uint64_t mmap_offset;
124         uint16_t num_queues;
125         uint16_t queue_size;
126 } VhostUserInflight;
127
128 typedef struct VhostUserMsg {
129         union {
130                 uint32_t master; /* a VhostUserRequest value */
131                 uint32_t slave;  /* a VhostUserSlaveRequest value*/
132         } request;
133
134 #define VHOST_USER_VERSION_MASK     0x3
135 #define VHOST_USER_REPLY_MASK       (0x1 << 2)
136 #define VHOST_USER_NEED_REPLY           (0x1 << 3)
137         uint32_t flags;
138         uint32_t size; /* the following payload size */
139         union {
140 #define VHOST_USER_VRING_IDX_MASK   0xff
141 #define VHOST_USER_VRING_NOFD_MASK  (0x1<<8)
142                 uint64_t u64;
143                 struct vhost_vring_state state;
144                 struct vhost_vring_addr addr;
145                 VhostUserMemory memory;
146                 VhostUserLog    log;
147                 struct vhost_iotlb_msg iotlb;
148                 VhostUserCryptoSessionParam crypto_session;
149                 VhostUserVringArea area;
150                 VhostUserInflight inflight;
151         } payload;
152         int fds[VHOST_MEMORY_MAX_NREGIONS];
153         int fd_num;
154 } __rte_packed VhostUserMsg;
155
156 #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64)
157
158 /* The version of the protocol we support */
159 #define VHOST_USER_VERSION    0x1
160
161
162 /* vhost_user.c */
163 int vhost_user_msg_handler(int vid, int fd);
164 int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
165
166 /* socket.c */
167 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
168                 int *fd_num);
169 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
170
171 #endif