xref: /openbmc/linux/arch/um/drivers/vhost_user.h (revision 27eca5c474f8c669fec3079db652df7533d83b55)
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)
9*27eca5c4SJohannes 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 */
13*27eca5c4SJohannes 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
165d38f324SErel Geron /* Vring state index masks */
175d38f324SErel Geron #define VHOST_USER_VRING_INDEX_MASK	0xff
185d38f324SErel Geron #define VHOST_USER_VRING_POLL_MASK	BIT(8)
195d38f324SErel Geron 
205d38f324SErel Geron /* Supported version */
215d38f324SErel Geron #define VHOST_USER_VERSION		1
225d38f324SErel Geron /* Supported transport features */
235d38f324SErel Geron #define VHOST_USER_SUPPORTED_F		BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
245d38f324SErel Geron /* Supported protocol features */
25*27eca5c4SJohannes Berg #define VHOST_USER_SUPPORTED_PROTOCOL_F	(BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
26*27eca5c4SJohannes Berg 					 BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
272cd097baSJohannes Berg 					 BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG))
285d38f324SErel Geron 
295d38f324SErel Geron enum vhost_user_request {
305d38f324SErel Geron 	VHOST_USER_GET_FEATURES = 1,
315d38f324SErel Geron 	VHOST_USER_SET_FEATURES = 2,
325d38f324SErel Geron 	VHOST_USER_SET_OWNER = 3,
335d38f324SErel Geron 	VHOST_USER_RESET_OWNER = 4,
345d38f324SErel Geron 	VHOST_USER_SET_MEM_TABLE = 5,
355d38f324SErel Geron 	VHOST_USER_SET_LOG_BASE = 6,
365d38f324SErel Geron 	VHOST_USER_SET_LOG_FD = 7,
375d38f324SErel Geron 	VHOST_USER_SET_VRING_NUM = 8,
385d38f324SErel Geron 	VHOST_USER_SET_VRING_ADDR = 9,
395d38f324SErel Geron 	VHOST_USER_SET_VRING_BASE = 10,
405d38f324SErel Geron 	VHOST_USER_GET_VRING_BASE = 11,
415d38f324SErel Geron 	VHOST_USER_SET_VRING_KICK = 12,
425d38f324SErel Geron 	VHOST_USER_SET_VRING_CALL = 13,
435d38f324SErel Geron 	VHOST_USER_SET_VRING_ERR = 14,
445d38f324SErel Geron 	VHOST_USER_GET_PROTOCOL_FEATURES = 15,
455d38f324SErel Geron 	VHOST_USER_SET_PROTOCOL_FEATURES = 16,
465d38f324SErel Geron 	VHOST_USER_GET_QUEUE_NUM = 17,
475d38f324SErel Geron 	VHOST_USER_SET_VRING_ENABLE = 18,
485d38f324SErel Geron 	VHOST_USER_SEND_RARP = 19,
495d38f324SErel Geron 	VHOST_USER_NET_SEND_MTU = 20,
505d38f324SErel Geron 	VHOST_USER_SET_SLAVE_REQ_FD = 21,
515d38f324SErel Geron 	VHOST_USER_IOTLB_MSG = 22,
525d38f324SErel Geron 	VHOST_USER_SET_VRING_ENDIAN = 23,
535d38f324SErel Geron 	VHOST_USER_GET_CONFIG = 24,
545d38f324SErel Geron 	VHOST_USER_SET_CONFIG = 25,
555d38f324SErel Geron };
565d38f324SErel Geron 
572cd097baSJohannes Berg enum vhost_user_slave_request {
582cd097baSJohannes Berg 	VHOST_USER_SLAVE_IOTLB_MSG = 1,
592cd097baSJohannes Berg 	VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
602cd097baSJohannes Berg 	VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
612cd097baSJohannes Berg };
622cd097baSJohannes Berg 
635d38f324SErel Geron struct vhost_user_header {
642cd097baSJohannes Berg 	/*
652cd097baSJohannes Berg 	 * Use enum vhost_user_request for outgoing messages,
662cd097baSJohannes Berg 	 * uses enum vhost_user_slave_request for incoming ones.
672cd097baSJohannes Berg 	 */
682cd097baSJohannes Berg 	u32 request;
695d38f324SErel Geron 	u32 flags;
705d38f324SErel Geron 	u32 size;
715d38f324SErel Geron } __packed;
725d38f324SErel Geron 
735d38f324SErel Geron struct vhost_user_config {
745d38f324SErel Geron 	u32 offset;
755d38f324SErel Geron 	u32 size;
765d38f324SErel Geron 	u32 flags;
775d38f324SErel Geron 	u8 payload[0]; /* Variable length */
785d38f324SErel Geron } __packed;
795d38f324SErel Geron 
805d38f324SErel Geron struct vhost_user_vring_state {
815d38f324SErel Geron 	u32 index;
825d38f324SErel Geron 	u32 num;
835d38f324SErel Geron } __packed;
845d38f324SErel Geron 
855d38f324SErel Geron struct vhost_user_vring_addr {
865d38f324SErel Geron 	u32 index;
875d38f324SErel Geron 	u32 flags;
885d38f324SErel Geron 	u64 desc, used, avail, log;
895d38f324SErel Geron } __packed;
905d38f324SErel Geron 
915d38f324SErel Geron struct vhost_user_mem_region {
925d38f324SErel Geron 	u64 guest_addr;
935d38f324SErel Geron 	u64 size;
945d38f324SErel Geron 	u64 user_addr;
955d38f324SErel Geron 	u64 mmap_offset;
965d38f324SErel Geron } __packed;
975d38f324SErel Geron 
985d38f324SErel Geron struct vhost_user_mem_regions {
995d38f324SErel Geron 	u32 num;
1005d38f324SErel Geron 	u32 padding;
1015d38f324SErel Geron 	struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */
1025d38f324SErel Geron } __packed;
1035d38f324SErel Geron 
1045d38f324SErel Geron union vhost_user_payload {
1055d38f324SErel Geron 	u64 integer;
1065d38f324SErel Geron 	struct vhost_user_config config;
1075d38f324SErel Geron 	struct vhost_user_vring_state vring_state;
1085d38f324SErel Geron 	struct vhost_user_vring_addr vring_addr;
1095d38f324SErel Geron 	struct vhost_user_mem_regions mem_regions;
1105d38f324SErel Geron };
1115d38f324SErel Geron 
1125d38f324SErel Geron struct vhost_user_msg {
1135d38f324SErel Geron 	struct vhost_user_header header;
1145d38f324SErel Geron 	union vhost_user_payload payload;
1155d38f324SErel Geron } __packed;
1165d38f324SErel Geron 
1175d38f324SErel Geron #endif
118