build: use static deps for pkg-config libs.private
[dpdk.git] / lib / librte_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
28 typedef enum VhostUserRequest {
29         VHOST_USER_NONE = 0,
30         VHOST_USER_GET_FEATURES = 1,
31         VHOST_USER_SET_FEATURES = 2,
32         VHOST_USER_SET_OWNER = 3,
33         VHOST_USER_RESET_OWNER = 4,
34         VHOST_USER_SET_MEM_TABLE = 5,
35         VHOST_USER_SET_LOG_BASE = 6,
36         VHOST_USER_SET_LOG_FD = 7,
37         VHOST_USER_SET_VRING_NUM = 8,
38         VHOST_USER_SET_VRING_ADDR = 9,
39         VHOST_USER_SET_VRING_BASE = 10,
40         VHOST_USER_GET_VRING_BASE = 11,
41         VHOST_USER_SET_VRING_KICK = 12,
42         VHOST_USER_SET_VRING_CALL = 13,
43         VHOST_USER_SET_VRING_ERR = 14,
44         VHOST_USER_GET_PROTOCOL_FEATURES = 15,
45         VHOST_USER_SET_PROTOCOL_FEATURES = 16,
46         VHOST_USER_GET_QUEUE_NUM = 17,
47         VHOST_USER_SET_VRING_ENABLE = 18,
48         VHOST_USER_SEND_RARP = 19,
49         VHOST_USER_NET_SET_MTU = 20,
50         VHOST_USER_SET_SLAVE_REQ_FD = 21,
51         VHOST_USER_IOTLB_MSG = 22,
52         VHOST_USER_CRYPTO_CREATE_SESS = 26,
53         VHOST_USER_CRYPTO_CLOSE_SESS = 27,
54         VHOST_USER_POSTCOPY_ADVISE = 28,
55         VHOST_USER_POSTCOPY_LISTEN = 29,
56         VHOST_USER_POSTCOPY_END = 30,
57         VHOST_USER_MAX = 31
58 } VhostUserRequest;
59
60 typedef enum VhostUserSlaveRequest {
61         VHOST_USER_SLAVE_NONE = 0,
62         VHOST_USER_SLAVE_IOTLB_MSG = 1,
63         VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
64         VHOST_USER_SLAVE_MAX
65 } VhostUserSlaveRequest;
66
67 typedef struct VhostUserMemoryRegion {
68         uint64_t guest_phys_addr;
69         uint64_t memory_size;
70         uint64_t userspace_addr;
71         uint64_t mmap_offset;
72 } VhostUserMemoryRegion;
73
74 typedef struct VhostUserMemory {
75         uint32_t nregions;
76         uint32_t padding;
77         VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
78 } VhostUserMemory;
79
80 typedef struct VhostUserLog {
81         uint64_t mmap_size;
82         uint64_t mmap_offset;
83 } VhostUserLog;
84
85 /* Comply with Cryptodev-Linux */
86 #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH   512
87 #define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64
88
89 /* Same structure as vhost-user backend session info */
90 typedef struct VhostUserCryptoSessionParam {
91         int64_t session_id;
92         uint32_t op_code;
93         uint32_t cipher_algo;
94         uint32_t cipher_key_len;
95         uint32_t hash_algo;
96         uint32_t digest_len;
97         uint32_t auth_key_len;
98         uint32_t aad_len;
99         uint8_t op_type;
100         uint8_t dir;
101         uint8_t hash_mode;
102         uint8_t chaining_dir;
103         uint8_t *ciphe_key;
104         uint8_t *auth_key;
105         uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH];
106         uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH];
107 } VhostUserCryptoSessionParam;
108
109 typedef struct VhostUserVringArea {
110         uint64_t u64;
111         uint64_t size;
112         uint64_t offset;
113 } VhostUserVringArea;
114
115 typedef struct VhostUserMsg {
116         union {
117                 uint32_t master; /* a VhostUserRequest value */
118                 uint32_t slave;  /* a VhostUserSlaveRequest value*/
119         } request;
120
121 #define VHOST_USER_VERSION_MASK     0x3
122 #define VHOST_USER_REPLY_MASK       (0x1 << 2)
123 #define VHOST_USER_NEED_REPLY           (0x1 << 3)
124         uint32_t flags;
125         uint32_t size; /* the following payload size */
126         union {
127 #define VHOST_USER_VRING_IDX_MASK   0xff
128 #define VHOST_USER_VRING_NOFD_MASK  (0x1<<8)
129                 uint64_t u64;
130                 struct vhost_vring_state state;
131                 struct vhost_vring_addr addr;
132                 VhostUserMemory memory;
133                 VhostUserLog    log;
134                 struct vhost_iotlb_msg iotlb;
135                 VhostUserCryptoSessionParam crypto_session;
136                 VhostUserVringArea area;
137         } payload;
138         int fds[VHOST_MEMORY_MAX_NREGIONS];
139         int fd_num;
140 } __attribute((packed)) VhostUserMsg;
141
142 #define VHOST_USER_HDR_SIZE offsetof(VhostUserMsg, payload.u64)
143
144 /* The version of the protocol we support */
145 #define VHOST_USER_VERSION    0x1
146
147
148 /* vhost_user.c */
149 int vhost_user_msg_handler(int vid, int fd);
150 int vhost_user_iotlb_miss(struct virtio_net *dev, uint64_t iova, uint8_t perm);
151 int vhost_user_host_notifier_ctrl(int vid, bool enable);
152
153 /* socket.c */
154 int read_fd_message(int sockfd, char *buf, int buflen, int *fds, int max_fds,
155                 int *fd_num);
156 int send_fd_message(int sockfd, char *buf, int buflen, int *fds, int fd_num);
157
158 #endif