18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 28c2ecf20Sopenharmony_ci/* Vhost-user protocol */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef __VHOST_USER_H__ 58c2ecf20Sopenharmony_ci#define __VHOST_USER_H__ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* Message flags */ 88c2ecf20Sopenharmony_ci#define VHOST_USER_FLAG_REPLY BIT(2) 98c2ecf20Sopenharmony_ci#define VHOST_USER_FLAG_NEED_REPLY BIT(3) 108c2ecf20Sopenharmony_ci/* Feature bits */ 118c2ecf20Sopenharmony_ci#define VHOST_USER_F_PROTOCOL_FEATURES 30 128c2ecf20Sopenharmony_ci/* Protocol feature bits */ 138c2ecf20Sopenharmony_ci#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3 148c2ecf20Sopenharmony_ci#define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 158c2ecf20Sopenharmony_ci#define VHOST_USER_PROTOCOL_F_CONFIG 9 168c2ecf20Sopenharmony_ci#define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14 178c2ecf20Sopenharmony_ci/* Vring state index masks */ 188c2ecf20Sopenharmony_ci#define VHOST_USER_VRING_INDEX_MASK 0xff 198c2ecf20Sopenharmony_ci#define VHOST_USER_VRING_POLL_MASK BIT(8) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci/* Supported version */ 228c2ecf20Sopenharmony_ci#define VHOST_USER_VERSION 1 238c2ecf20Sopenharmony_ci/* Supported transport features */ 248c2ecf20Sopenharmony_ci#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES) 258c2ecf20Sopenharmony_ci/* Supported protocol features */ 268c2ecf20Sopenharmony_ci#define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \ 278c2ecf20Sopenharmony_ci BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \ 288c2ecf20Sopenharmony_ci BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \ 298c2ecf20Sopenharmony_ci BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS)) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum vhost_user_request { 328c2ecf20Sopenharmony_ci VHOST_USER_GET_FEATURES = 1, 338c2ecf20Sopenharmony_ci VHOST_USER_SET_FEATURES = 2, 348c2ecf20Sopenharmony_ci VHOST_USER_SET_OWNER = 3, 358c2ecf20Sopenharmony_ci VHOST_USER_RESET_OWNER = 4, 368c2ecf20Sopenharmony_ci VHOST_USER_SET_MEM_TABLE = 5, 378c2ecf20Sopenharmony_ci VHOST_USER_SET_LOG_BASE = 6, 388c2ecf20Sopenharmony_ci VHOST_USER_SET_LOG_FD = 7, 398c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_NUM = 8, 408c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_ADDR = 9, 418c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_BASE = 10, 428c2ecf20Sopenharmony_ci VHOST_USER_GET_VRING_BASE = 11, 438c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_KICK = 12, 448c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_CALL = 13, 458c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_ERR = 14, 468c2ecf20Sopenharmony_ci VHOST_USER_GET_PROTOCOL_FEATURES = 15, 478c2ecf20Sopenharmony_ci VHOST_USER_SET_PROTOCOL_FEATURES = 16, 488c2ecf20Sopenharmony_ci VHOST_USER_GET_QUEUE_NUM = 17, 498c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_ENABLE = 18, 508c2ecf20Sopenharmony_ci VHOST_USER_SEND_RARP = 19, 518c2ecf20Sopenharmony_ci VHOST_USER_NET_SEND_MTU = 20, 528c2ecf20Sopenharmony_ci VHOST_USER_SET_SLAVE_REQ_FD = 21, 538c2ecf20Sopenharmony_ci VHOST_USER_IOTLB_MSG = 22, 548c2ecf20Sopenharmony_ci VHOST_USER_SET_VRING_ENDIAN = 23, 558c2ecf20Sopenharmony_ci VHOST_USER_GET_CONFIG = 24, 568c2ecf20Sopenharmony_ci VHOST_USER_SET_CONFIG = 25, 578c2ecf20Sopenharmony_ci VHOST_USER_VRING_KICK = 35, 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cienum vhost_user_slave_request { 618c2ecf20Sopenharmony_ci VHOST_USER_SLAVE_IOTLB_MSG = 1, 628c2ecf20Sopenharmony_ci VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, 638c2ecf20Sopenharmony_ci VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, 648c2ecf20Sopenharmony_ci VHOST_USER_SLAVE_VRING_CALL = 4, 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistruct vhost_user_header { 688c2ecf20Sopenharmony_ci /* 698c2ecf20Sopenharmony_ci * Use enum vhost_user_request for outgoing messages, 708c2ecf20Sopenharmony_ci * uses enum vhost_user_slave_request for incoming ones. 718c2ecf20Sopenharmony_ci */ 728c2ecf20Sopenharmony_ci u32 request; 738c2ecf20Sopenharmony_ci u32 flags; 748c2ecf20Sopenharmony_ci u32 size; 758c2ecf20Sopenharmony_ci} __packed; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistruct vhost_user_config { 788c2ecf20Sopenharmony_ci u32 offset; 798c2ecf20Sopenharmony_ci u32 size; 808c2ecf20Sopenharmony_ci u32 flags; 818c2ecf20Sopenharmony_ci u8 payload[]; /* Variable length */ 828c2ecf20Sopenharmony_ci} __packed; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_cistruct vhost_user_vring_state { 858c2ecf20Sopenharmony_ci u32 index; 868c2ecf20Sopenharmony_ci u32 num; 878c2ecf20Sopenharmony_ci} __packed; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistruct vhost_user_vring_addr { 908c2ecf20Sopenharmony_ci u32 index; 918c2ecf20Sopenharmony_ci u32 flags; 928c2ecf20Sopenharmony_ci u64 desc, used, avail, log; 938c2ecf20Sopenharmony_ci} __packed; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistruct vhost_user_mem_region { 968c2ecf20Sopenharmony_ci u64 guest_addr; 978c2ecf20Sopenharmony_ci u64 size; 988c2ecf20Sopenharmony_ci u64 user_addr; 998c2ecf20Sopenharmony_ci u64 mmap_offset; 1008c2ecf20Sopenharmony_ci} __packed; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistruct vhost_user_mem_regions { 1038c2ecf20Sopenharmony_ci u32 num; 1048c2ecf20Sopenharmony_ci u32 padding; 1058c2ecf20Sopenharmony_ci struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */ 1068c2ecf20Sopenharmony_ci} __packed; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ciunion vhost_user_payload { 1098c2ecf20Sopenharmony_ci u64 integer; 1108c2ecf20Sopenharmony_ci struct vhost_user_config config; 1118c2ecf20Sopenharmony_ci struct vhost_user_vring_state vring_state; 1128c2ecf20Sopenharmony_ci struct vhost_user_vring_addr vring_addr; 1138c2ecf20Sopenharmony_ci struct vhost_user_mem_regions mem_regions; 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistruct vhost_user_msg { 1178c2ecf20Sopenharmony_ci struct vhost_user_header header; 1188c2ecf20Sopenharmony_ci union vhost_user_payload payload; 1198c2ecf20Sopenharmony_ci} __packed; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#endif 122