15d38f324SErel Geron // SPDX-License-Identifier: GPL-2.0-or-later 25d38f324SErel Geron /* Vhost-user protocol */ 35d38f324SErel Geron 45d38f324SErel Geron #ifndef __VHOST_USER_H__ 55d38f324SErel Geron #define __VHOST_USER_H__ 65d38f324SErel Geron 75d38f324SErel Geron /* Message flags */ 85d38f324SErel Geron #define VHOST_USER_FLAG_REPLY BIT(2) 95d38f324SErel Geron /* Feature bits */ 105d38f324SErel Geron #define VHOST_USER_F_PROTOCOL_FEATURES 30 115d38f324SErel Geron /* Protocol feature bits */ 12*2cd097baSJohannes Berg #define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5 135d38f324SErel Geron #define VHOST_USER_PROTOCOL_F_CONFIG 9 145d38f324SErel Geron /* Vring state index masks */ 155d38f324SErel Geron #define VHOST_USER_VRING_INDEX_MASK 0xff 165d38f324SErel Geron #define VHOST_USER_VRING_POLL_MASK BIT(8) 175d38f324SErel Geron 185d38f324SErel Geron /* Supported version */ 195d38f324SErel Geron #define VHOST_USER_VERSION 1 205d38f324SErel Geron /* Supported transport features */ 215d38f324SErel Geron #define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES) 225d38f324SErel Geron /* Supported protocol features */ 23*2cd097baSJohannes Berg #define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \ 24*2cd097baSJohannes Berg BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG)) 255d38f324SErel Geron 265d38f324SErel Geron enum vhost_user_request { 275d38f324SErel Geron VHOST_USER_GET_FEATURES = 1, 285d38f324SErel Geron VHOST_USER_SET_FEATURES = 2, 295d38f324SErel Geron VHOST_USER_SET_OWNER = 3, 305d38f324SErel Geron VHOST_USER_RESET_OWNER = 4, 315d38f324SErel Geron VHOST_USER_SET_MEM_TABLE = 5, 325d38f324SErel Geron VHOST_USER_SET_LOG_BASE = 6, 335d38f324SErel Geron VHOST_USER_SET_LOG_FD = 7, 345d38f324SErel Geron VHOST_USER_SET_VRING_NUM = 8, 355d38f324SErel Geron VHOST_USER_SET_VRING_ADDR = 9, 365d38f324SErel Geron VHOST_USER_SET_VRING_BASE = 10, 375d38f324SErel Geron VHOST_USER_GET_VRING_BASE = 11, 385d38f324SErel Geron VHOST_USER_SET_VRING_KICK = 12, 395d38f324SErel Geron VHOST_USER_SET_VRING_CALL = 13, 405d38f324SErel Geron VHOST_USER_SET_VRING_ERR = 14, 415d38f324SErel Geron VHOST_USER_GET_PROTOCOL_FEATURES = 15, 425d38f324SErel Geron VHOST_USER_SET_PROTOCOL_FEATURES = 16, 435d38f324SErel Geron VHOST_USER_GET_QUEUE_NUM = 17, 445d38f324SErel Geron VHOST_USER_SET_VRING_ENABLE = 18, 455d38f324SErel Geron VHOST_USER_SEND_RARP = 19, 465d38f324SErel Geron VHOST_USER_NET_SEND_MTU = 20, 475d38f324SErel Geron VHOST_USER_SET_SLAVE_REQ_FD = 21, 485d38f324SErel Geron VHOST_USER_IOTLB_MSG = 22, 495d38f324SErel Geron VHOST_USER_SET_VRING_ENDIAN = 23, 505d38f324SErel Geron VHOST_USER_GET_CONFIG = 24, 515d38f324SErel Geron VHOST_USER_SET_CONFIG = 25, 525d38f324SErel Geron }; 535d38f324SErel Geron 54*2cd097baSJohannes Berg enum vhost_user_slave_request { 55*2cd097baSJohannes Berg VHOST_USER_SLAVE_IOTLB_MSG = 1, 56*2cd097baSJohannes Berg VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, 57*2cd097baSJohannes Berg VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, 58*2cd097baSJohannes Berg }; 59*2cd097baSJohannes Berg 605d38f324SErel Geron struct vhost_user_header { 61*2cd097baSJohannes Berg /* 62*2cd097baSJohannes Berg * Use enum vhost_user_request for outgoing messages, 63*2cd097baSJohannes Berg * uses enum vhost_user_slave_request for incoming ones. 64*2cd097baSJohannes Berg */ 65*2cd097baSJohannes Berg u32 request; 665d38f324SErel Geron u32 flags; 675d38f324SErel Geron u32 size; 685d38f324SErel Geron } __packed; 695d38f324SErel Geron 705d38f324SErel Geron struct vhost_user_config { 715d38f324SErel Geron u32 offset; 725d38f324SErel Geron u32 size; 735d38f324SErel Geron u32 flags; 745d38f324SErel Geron u8 payload[0]; /* Variable length */ 755d38f324SErel Geron } __packed; 765d38f324SErel Geron 775d38f324SErel Geron struct vhost_user_vring_state { 785d38f324SErel Geron u32 index; 795d38f324SErel Geron u32 num; 805d38f324SErel Geron } __packed; 815d38f324SErel Geron 825d38f324SErel Geron struct vhost_user_vring_addr { 835d38f324SErel Geron u32 index; 845d38f324SErel Geron u32 flags; 855d38f324SErel Geron u64 desc, used, avail, log; 865d38f324SErel Geron } __packed; 875d38f324SErel Geron 885d38f324SErel Geron struct vhost_user_mem_region { 895d38f324SErel Geron u64 guest_addr; 905d38f324SErel Geron u64 size; 915d38f324SErel Geron u64 user_addr; 925d38f324SErel Geron u64 mmap_offset; 935d38f324SErel Geron } __packed; 945d38f324SErel Geron 955d38f324SErel Geron struct vhost_user_mem_regions { 965d38f324SErel Geron u32 num; 975d38f324SErel Geron u32 padding; 985d38f324SErel Geron struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */ 995d38f324SErel Geron } __packed; 1005d38f324SErel Geron 1015d38f324SErel Geron union vhost_user_payload { 1025d38f324SErel Geron u64 integer; 1035d38f324SErel Geron struct vhost_user_config config; 1045d38f324SErel Geron struct vhost_user_vring_state vring_state; 1055d38f324SErel Geron struct vhost_user_vring_addr vring_addr; 1065d38f324SErel Geron struct vhost_user_mem_regions mem_regions; 1075d38f324SErel Geron }; 1085d38f324SErel Geron 1095d38f324SErel Geron struct vhost_user_msg { 1105d38f324SErel Geron struct vhost_user_header header; 1115d38f324SErel Geron union vhost_user_payload payload; 1125d38f324SErel Geron } __packed; 1135d38f324SErel Geron 1145d38f324SErel Geron #endif 115