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