xref: /openbmc/linux/arch/um/drivers/vhost_user.h (revision f6e8c474)
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)
927eca5c4SJohannes Berg #define VHOST_USER_FLAG_NEED_REPLY	BIT(3)
105d38f324SErel Geron /* Feature bits */
115d38f324SErel Geron #define VHOST_USER_F_PROTOCOL_FEATURES	30
125d38f324SErel Geron /* Protocol feature bits */
1327eca5c4SJohannes Berg #define VHOST_USER_PROTOCOL_F_REPLY_ACK			3
142cd097baSJohannes Berg #define VHOST_USER_PROTOCOL_F_SLAVE_REQ			5
155d38f324SErel Geron #define VHOST_USER_PROTOCOL_F_CONFIG			9
16dd9ada56SJohannes Berg #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS	14
175d38f324SErel Geron /* Vring state index masks */
185d38f324SErel Geron #define VHOST_USER_VRING_INDEX_MASK	0xff
195d38f324SErel Geron #define VHOST_USER_VRING_POLL_MASK	BIT(8)
205d38f324SErel Geron 
215d38f324SErel Geron /* Supported version */
225d38f324SErel Geron #define VHOST_USER_VERSION		1
235d38f324SErel Geron /* Supported transport features */
245d38f324SErel Geron #define VHOST_USER_SUPPORTED_F		BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
255d38f324SErel Geron /* Supported protocol features */
2627eca5c4SJohannes Berg #define VHOST_USER_SUPPORTED_PROTOCOL_F	(BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
2727eca5c4SJohannes Berg 					 BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
28dd9ada56SJohannes Berg 					 BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \
29dd9ada56SJohannes Berg 					 BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS))
305d38f324SErel Geron 
315d38f324SErel Geron enum vhost_user_request {
325d38f324SErel Geron 	VHOST_USER_GET_FEATURES = 1,
335d38f324SErel Geron 	VHOST_USER_SET_FEATURES = 2,
345d38f324SErel Geron 	VHOST_USER_SET_OWNER = 3,
355d38f324SErel Geron 	VHOST_USER_RESET_OWNER = 4,
365d38f324SErel Geron 	VHOST_USER_SET_MEM_TABLE = 5,
375d38f324SErel Geron 	VHOST_USER_SET_LOG_BASE = 6,
385d38f324SErel Geron 	VHOST_USER_SET_LOG_FD = 7,
395d38f324SErel Geron 	VHOST_USER_SET_VRING_NUM = 8,
405d38f324SErel Geron 	VHOST_USER_SET_VRING_ADDR = 9,
415d38f324SErel Geron 	VHOST_USER_SET_VRING_BASE = 10,
425d38f324SErel Geron 	VHOST_USER_GET_VRING_BASE = 11,
435d38f324SErel Geron 	VHOST_USER_SET_VRING_KICK = 12,
445d38f324SErel Geron 	VHOST_USER_SET_VRING_CALL = 13,
455d38f324SErel Geron 	VHOST_USER_SET_VRING_ERR = 14,
465d38f324SErel Geron 	VHOST_USER_GET_PROTOCOL_FEATURES = 15,
475d38f324SErel Geron 	VHOST_USER_SET_PROTOCOL_FEATURES = 16,
485d38f324SErel Geron 	VHOST_USER_GET_QUEUE_NUM = 17,
495d38f324SErel Geron 	VHOST_USER_SET_VRING_ENABLE = 18,
505d38f324SErel Geron 	VHOST_USER_SEND_RARP = 19,
515d38f324SErel Geron 	VHOST_USER_NET_SEND_MTU = 20,
525d38f324SErel Geron 	VHOST_USER_SET_SLAVE_REQ_FD = 21,
535d38f324SErel Geron 	VHOST_USER_IOTLB_MSG = 22,
545d38f324SErel Geron 	VHOST_USER_SET_VRING_ENDIAN = 23,
555d38f324SErel Geron 	VHOST_USER_GET_CONFIG = 24,
565d38f324SErel Geron 	VHOST_USER_SET_CONFIG = 25,
57dd9ada56SJohannes Berg 	VHOST_USER_VRING_KICK = 35,
585d38f324SErel Geron };
595d38f324SErel Geron 
602cd097baSJohannes Berg enum vhost_user_slave_request {
612cd097baSJohannes Berg 	VHOST_USER_SLAVE_IOTLB_MSG = 1,
622cd097baSJohannes Berg 	VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
632cd097baSJohannes Berg 	VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
64dd9ada56SJohannes Berg 	VHOST_USER_SLAVE_VRING_CALL = 4,
652cd097baSJohannes Berg };
662cd097baSJohannes Berg 
675d38f324SErel Geron struct vhost_user_header {
682cd097baSJohannes Berg 	/*
692cd097baSJohannes Berg 	 * Use enum vhost_user_request for outgoing messages,
702cd097baSJohannes Berg 	 * uses enum vhost_user_slave_request for incoming ones.
712cd097baSJohannes Berg 	 */
722cd097baSJohannes Berg 	u32 request;
735d38f324SErel Geron 	u32 flags;
745d38f324SErel Geron 	u32 size;
755d38f324SErel Geron } __packed;
765d38f324SErel Geron 
775d38f324SErel Geron struct vhost_user_config {
785d38f324SErel Geron 	u32 offset;
795d38f324SErel Geron 	u32 size;
805d38f324SErel Geron 	u32 flags;
81f6e8c474SGustavo A. R. Silva 	u8 payload[]; /* Variable length */
825d38f324SErel Geron } __packed;
835d38f324SErel Geron 
845d38f324SErel Geron struct vhost_user_vring_state {
855d38f324SErel Geron 	u32 index;
865d38f324SErel Geron 	u32 num;
875d38f324SErel Geron } __packed;
885d38f324SErel Geron 
895d38f324SErel Geron struct vhost_user_vring_addr {
905d38f324SErel Geron 	u32 index;
915d38f324SErel Geron 	u32 flags;
925d38f324SErel Geron 	u64 desc, used, avail, log;
935d38f324SErel Geron } __packed;
945d38f324SErel Geron 
955d38f324SErel Geron struct vhost_user_mem_region {
965d38f324SErel Geron 	u64 guest_addr;
975d38f324SErel Geron 	u64 size;
985d38f324SErel Geron 	u64 user_addr;
995d38f324SErel Geron 	u64 mmap_offset;
1005d38f324SErel Geron } __packed;
1015d38f324SErel Geron 
1025d38f324SErel Geron struct vhost_user_mem_regions {
1035d38f324SErel Geron 	u32 num;
1045d38f324SErel Geron 	u32 padding;
1055d38f324SErel Geron 	struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */
1065d38f324SErel Geron } __packed;
1075d38f324SErel Geron 
1085d38f324SErel Geron union vhost_user_payload {
1095d38f324SErel Geron 	u64 integer;
1105d38f324SErel Geron 	struct vhost_user_config config;
1115d38f324SErel Geron 	struct vhost_user_vring_state vring_state;
1125d38f324SErel Geron 	struct vhost_user_vring_addr vring_addr;
1135d38f324SErel Geron 	struct vhost_user_mem_regions mem_regions;
1145d38f324SErel Geron };
1155d38f324SErel Geron 
1165d38f324SErel Geron struct vhost_user_msg {
1175d38f324SErel Geron 	struct vhost_user_header header;
1185d38f324SErel Geron 	union vhost_user_payload payload;
1195d38f324SErel Geron } __packed;
1205d38f324SErel Geron 
1215d38f324SErel Geron #endif
122