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