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