1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. 3 * All rights reserved. 4 */ 5 6 /** \file 7 * Structures defined in the vhost-user specification 8 */ 9 10 #ifndef SPDK_VHOST_USER_H 11 #define SPDK_VHOST_USER_H 12 13 #include "spdk/stdinc.h" 14 15 #include <linux/vhost.h> 16 17 #ifndef VHOST_USER_MEMORY_MAX_NREGIONS 18 #define VHOST_USER_MEMORY_MAX_NREGIONS 8 19 #endif 20 21 #ifndef VHOST_USER_MAX_CONFIG_SIZE 22 #define VHOST_USER_MAX_CONFIG_SIZE 256 23 #endif 24 25 #ifndef VHOST_USER_PROTOCOL_F_MQ 26 #define VHOST_USER_PROTOCOL_F_MQ 0 27 #endif 28 29 #ifndef VHOST_USER_PROTOCOL_F_CONFIG 30 #define VHOST_USER_PROTOCOL_F_CONFIG 9 31 #endif 32 33 #ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 34 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 35 #endif 36 37 #ifndef VHOST_USER_F_PROTOCOL_FEATURES 38 #define VHOST_USER_F_PROTOCOL_FEATURES 30 39 #endif 40 41 enum vhost_user_request { 42 VHOST_USER_NONE = 0, 43 VHOST_USER_GET_FEATURES = 1, 44 VHOST_USER_SET_FEATURES = 2, 45 VHOST_USER_SET_OWNER = 3, 46 VHOST_USER_RESET_OWNER = 4, 47 VHOST_USER_SET_MEM_TABLE = 5, 48 VHOST_USER_SET_LOG_BASE = 6, 49 VHOST_USER_SET_LOG_FD = 7, 50 VHOST_USER_SET_VRING_NUM = 8, 51 VHOST_USER_SET_VRING_ADDR = 9, 52 VHOST_USER_SET_VRING_BASE = 10, 53 VHOST_USER_GET_VRING_BASE = 11, 54 VHOST_USER_SET_VRING_KICK = 12, 55 VHOST_USER_SET_VRING_CALL = 13, 56 VHOST_USER_SET_VRING_ERR = 14, 57 VHOST_USER_GET_PROTOCOL_FEATURES = 15, 58 VHOST_USER_SET_PROTOCOL_FEATURES = 16, 59 VHOST_USER_GET_QUEUE_NUM = 17, 60 VHOST_USER_SET_VRING_ENABLE = 18, 61 VHOST_USER_SEND_RARP = 19, 62 VHOST_USER_NET_SET_MTU = 20, 63 VHOST_USER_SET_SLAVE_REQ_FD = 21, 64 VHOST_USER_IOTLB_MSG = 22, 65 VHOST_USER_GET_CONFIG = 24, 66 VHOST_USER_SET_CONFIG = 25, 67 VHOST_USER_CRYPTO_CREATE_SESS = 26, 68 VHOST_USER_CRYPTO_CLOSE_SESS = 27, 69 VHOST_USER_POSTCOPY_ADVISE = 28, 70 VHOST_USER_POSTCOPY_LISTEN = 29, 71 VHOST_USER_POSTCOPY_END = 30, 72 VHOST_USER_MAX 73 }; 74 75 /** Get/set config msg payload */ 76 struct vhost_user_config { 77 uint32_t offset; 78 uint32_t size; 79 uint32_t flags; 80 uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; 81 }; 82 83 /** Fixed-size vhost_memory struct */ 84 struct vhost_memory_padded { 85 uint32_t nregions; 86 uint32_t padding; 87 struct vhost_memory_region regions[VHOST_USER_MEMORY_MAX_NREGIONS]; 88 }; 89 90 struct vhost_user_msg { 91 enum vhost_user_request request; 92 93 #define VHOST_USER_VERSION_MASK 0x3 94 #define VHOST_USER_REPLY_MASK (0x1 << 2) 95 uint32_t flags; 96 uint32_t size; /**< the following payload size */ 97 union { 98 #define VHOST_USER_VRING_IDX_MASK 0xff 99 #define VHOST_USER_VRING_NOFD_MASK (0x1 << 8) 100 uint64_t u64; 101 struct vhost_vring_state state; 102 struct vhost_vring_addr addr; 103 struct vhost_memory_padded memory; 104 struct vhost_user_config cfg; 105 } payload; 106 } __attribute((packed)); 107 108 #define VHOST_USER_HDR_SIZE offsetof(struct vhost_user_msg, payload.u64) 109 #define VHOST_USER_PAYLOAD_SIZE \ 110 (sizeof(struct vhost_user_msg) - VHOST_USER_HDR_SIZE) 111 112 #endif /* SPDK_VHOST_USER_H */ 113