1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2019 Intel Corporation 3 */ 4 5 #ifndef _BLK_SPEC_H 6 #define _BLK_SPEC_H 7 8 #include <stdint.h> 9 10 #ifndef VHOST_USER_MEMORY_MAX_NREGIONS 11 #define VHOST_USER_MEMORY_MAX_NREGIONS 8 12 #endif 13 14 #ifndef VHOST_USER_MAX_CONFIG_SIZE 15 #define VHOST_USER_MAX_CONFIG_SIZE 256 16 #endif 17 18 #ifndef VHOST_USER_PROTOCOL_F_CONFIG 19 #define VHOST_USER_PROTOCOL_F_CONFIG 9 20 #endif 21 22 #ifndef VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 23 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD 12 24 #endif 25 26 #define VIRTIO_BLK_ID_BYTES 20 /* ID string length */ 27 28 #define VIRTIO_BLK_T_IN 0 29 #define VIRTIO_BLK_T_OUT 1 30 #define VIRTIO_BLK_T_FLUSH 4 31 #define VIRTIO_BLK_T_GET_ID 8 32 #define VIRTIO_BLK_T_DISCARD 11 33 #define VIRTIO_BLK_T_WRITE_ZEROES 13 34 35 #define VIRTIO_BLK_S_OK 0 36 #define VIRTIO_BLK_S_IOERR 1 37 #define VIRTIO_BLK_S_UNSUPP 2 38 39 enum vhost_user_request { 40 VHOST_USER_NONE = 0, 41 VHOST_USER_GET_FEATURES = 1, 42 VHOST_USER_SET_FEATURES = 2, 43 VHOST_USER_SET_OWNER = 3, 44 VHOST_USER_RESET_OWNER = 4, 45 VHOST_USER_SET_MEM_TABLE = 5, 46 VHOST_USER_SET_LOG_BASE = 6, 47 VHOST_USER_SET_LOG_FD = 7, 48 VHOST_USER_SET_VRING_NUM = 8, 49 VHOST_USER_SET_VRING_ADDR = 9, 50 VHOST_USER_SET_VRING_BASE = 10, 51 VHOST_USER_GET_VRING_BASE = 11, 52 VHOST_USER_SET_VRING_KICK = 12, 53 VHOST_USER_SET_VRING_CALL = 13, 54 VHOST_USER_SET_VRING_ERR = 14, 55 VHOST_USER_GET_PROTOCOL_FEATURES = 15, 56 VHOST_USER_SET_PROTOCOL_FEATURES = 16, 57 VHOST_USER_GET_QUEUE_NUM = 17, 58 VHOST_USER_SET_VRING_ENABLE = 18, 59 VHOST_USER_MAX 60 }; 61 62 /** Get/set config msg payload */ 63 struct vhost_user_config { 64 uint32_t offset; 65 uint32_t size; 66 uint32_t flags; 67 uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; 68 }; 69 70 /** Fixed-size vhost_memory struct */ 71 struct vhost_memory_padded { 72 uint32_t nregions; 73 uint32_t padding; 74 struct vhost_memory_region regions[VHOST_USER_MEMORY_MAX_NREGIONS]; 75 }; 76 77 struct vhost_user_msg { 78 enum vhost_user_request request; 79 80 #define VHOST_USER_VERSION_MASK 0x3 81 #define VHOST_USER_REPLY_MASK (0x1 << 2) 82 uint32_t flags; 83 uint32_t size; /**< the following payload size */ 84 union { 85 #define VHOST_USER_VRING_IDX_MASK 0xff 86 #define VHOST_USER_VRING_NOFD_MASK (0x1 << 8) 87 uint64_t u64; 88 struct vhost_vring_state state; 89 struct vhost_vring_addr addr; 90 struct vhost_memory_padded memory; 91 struct vhost_user_config cfg; 92 } payload; 93 } __rte_packed; 94 95 #endif 96