1*5d38f324SErel Geron // SPDX-License-Identifier: GPL-2.0-or-later 2*5d38f324SErel Geron /* Vhost-user protocol */ 3*5d38f324SErel Geron 4*5d38f324SErel Geron #ifndef __VHOST_USER_H__ 5*5d38f324SErel Geron #define __VHOST_USER_H__ 6*5d38f324SErel Geron 7*5d38f324SErel Geron /* Message flags */ 8*5d38f324SErel Geron #define VHOST_USER_FLAG_REPLY BIT(2) 9*5d38f324SErel Geron /* Feature bits */ 10*5d38f324SErel Geron #define VHOST_USER_F_PROTOCOL_FEATURES 30 11*5d38f324SErel Geron /* Protocol feature bits */ 12*5d38f324SErel Geron #define VHOST_USER_PROTOCOL_F_CONFIG 9 13*5d38f324SErel Geron /* Vring state index masks */ 14*5d38f324SErel Geron #define VHOST_USER_VRING_INDEX_MASK 0xff 15*5d38f324SErel Geron #define VHOST_USER_VRING_POLL_MASK BIT(8) 16*5d38f324SErel Geron 17*5d38f324SErel Geron /* Supported version */ 18*5d38f324SErel Geron #define VHOST_USER_VERSION 1 19*5d38f324SErel Geron /* Supported transport features */ 20*5d38f324SErel Geron #define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES) 21*5d38f324SErel Geron /* Supported protocol features */ 22*5d38f324SErel Geron #define VHOST_USER_SUPPORTED_PROTOCOL_F BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) 23*5d38f324SErel Geron 24*5d38f324SErel Geron enum vhost_user_request { 25*5d38f324SErel Geron VHOST_USER_GET_FEATURES = 1, 26*5d38f324SErel Geron VHOST_USER_SET_FEATURES = 2, 27*5d38f324SErel Geron VHOST_USER_SET_OWNER = 3, 28*5d38f324SErel Geron VHOST_USER_RESET_OWNER = 4, 29*5d38f324SErel Geron VHOST_USER_SET_MEM_TABLE = 5, 30*5d38f324SErel Geron VHOST_USER_SET_LOG_BASE = 6, 31*5d38f324SErel Geron VHOST_USER_SET_LOG_FD = 7, 32*5d38f324SErel Geron VHOST_USER_SET_VRING_NUM = 8, 33*5d38f324SErel Geron VHOST_USER_SET_VRING_ADDR = 9, 34*5d38f324SErel Geron VHOST_USER_SET_VRING_BASE = 10, 35*5d38f324SErel Geron VHOST_USER_GET_VRING_BASE = 11, 36*5d38f324SErel Geron VHOST_USER_SET_VRING_KICK = 12, 37*5d38f324SErel Geron VHOST_USER_SET_VRING_CALL = 13, 38*5d38f324SErel Geron VHOST_USER_SET_VRING_ERR = 14, 39*5d38f324SErel Geron VHOST_USER_GET_PROTOCOL_FEATURES = 15, 40*5d38f324SErel Geron VHOST_USER_SET_PROTOCOL_FEATURES = 16, 41*5d38f324SErel Geron VHOST_USER_GET_QUEUE_NUM = 17, 42*5d38f324SErel Geron VHOST_USER_SET_VRING_ENABLE = 18, 43*5d38f324SErel Geron VHOST_USER_SEND_RARP = 19, 44*5d38f324SErel Geron VHOST_USER_NET_SEND_MTU = 20, 45*5d38f324SErel Geron VHOST_USER_SET_SLAVE_REQ_FD = 21, 46*5d38f324SErel Geron VHOST_USER_IOTLB_MSG = 22, 47*5d38f324SErel Geron VHOST_USER_SET_VRING_ENDIAN = 23, 48*5d38f324SErel Geron VHOST_USER_GET_CONFIG = 24, 49*5d38f324SErel Geron VHOST_USER_SET_CONFIG = 25, 50*5d38f324SErel Geron }; 51*5d38f324SErel Geron 52*5d38f324SErel Geron struct vhost_user_header { 53*5d38f324SErel Geron u32 request; /* Use enum vhost_user_request */ 54*5d38f324SErel Geron u32 flags; 55*5d38f324SErel Geron u32 size; 56*5d38f324SErel Geron } __packed; 57*5d38f324SErel Geron 58*5d38f324SErel Geron struct vhost_user_config { 59*5d38f324SErel Geron u32 offset; 60*5d38f324SErel Geron u32 size; 61*5d38f324SErel Geron u32 flags; 62*5d38f324SErel Geron u8 payload[0]; /* Variable length */ 63*5d38f324SErel Geron } __packed; 64*5d38f324SErel Geron 65*5d38f324SErel Geron struct vhost_user_vring_state { 66*5d38f324SErel Geron u32 index; 67*5d38f324SErel Geron u32 num; 68*5d38f324SErel Geron } __packed; 69*5d38f324SErel Geron 70*5d38f324SErel Geron struct vhost_user_vring_addr { 71*5d38f324SErel Geron u32 index; 72*5d38f324SErel Geron u32 flags; 73*5d38f324SErel Geron u64 desc, used, avail, log; 74*5d38f324SErel Geron } __packed; 75*5d38f324SErel Geron 76*5d38f324SErel Geron struct vhost_user_mem_region { 77*5d38f324SErel Geron u64 guest_addr; 78*5d38f324SErel Geron u64 size; 79*5d38f324SErel Geron u64 user_addr; 80*5d38f324SErel Geron u64 mmap_offset; 81*5d38f324SErel Geron } __packed; 82*5d38f324SErel Geron 83*5d38f324SErel Geron struct vhost_user_mem_regions { 84*5d38f324SErel Geron u32 num; 85*5d38f324SErel Geron u32 padding; 86*5d38f324SErel Geron struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */ 87*5d38f324SErel Geron } __packed; 88*5d38f324SErel Geron 89*5d38f324SErel Geron union vhost_user_payload { 90*5d38f324SErel Geron u64 integer; 91*5d38f324SErel Geron struct vhost_user_config config; 92*5d38f324SErel Geron struct vhost_user_vring_state vring_state; 93*5d38f324SErel Geron struct vhost_user_vring_addr vring_addr; 94*5d38f324SErel Geron struct vhost_user_mem_regions mem_regions; 95*5d38f324SErel Geron }; 96*5d38f324SErel Geron 97*5d38f324SErel Geron struct vhost_user_msg { 98*5d38f324SErel Geron struct vhost_user_header header; 99*5d38f324SErel Geron union vhost_user_payload payload; 100*5d38f324SErel Geron } __packed; 101*5d38f324SErel Geron 102*5d38f324SErel Geron #endif 103