blob: 6f147cd3c9f76a81995a8229c6eac01c1f8c5227 [file] [log] [blame]
Erel Geron5d38f322019-09-11 14:51:20 +02001// 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)
Johannes Berg27eca5c2019-09-11 14:51:22 +02009#define VHOST_USER_FLAG_NEED_REPLY BIT(3)
Erel Geron5d38f322019-09-11 14:51:20 +020010/* Feature bits */
11#define VHOST_USER_F_PROTOCOL_FEATURES 30
12/* Protocol feature bits */
Johannes Bergdd9ada52020-02-13 14:26:46 +010013#define VHOST_USER_PROTOCOL_F_REPLY_ACK 3
14#define VHOST_USER_PROTOCOL_F_SLAVE_REQ 5
15#define VHOST_USER_PROTOCOL_F_CONFIG 9
16#define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14
Erel Geron5d38f322019-09-11 14:51:20 +020017/* Vring state index masks */
18#define VHOST_USER_VRING_INDEX_MASK 0xff
19#define VHOST_USER_VRING_POLL_MASK BIT(8)
20
21/* Supported version */
22#define VHOST_USER_VERSION 1
23/* Supported transport features */
24#define VHOST_USER_SUPPORTED_F BIT_ULL(VHOST_USER_F_PROTOCOL_FEATURES)
25/* Supported protocol features */
Johannes Berg27eca5c2019-09-11 14:51:22 +020026#define VHOST_USER_SUPPORTED_PROTOCOL_F (BIT_ULL(VHOST_USER_PROTOCOL_F_REPLY_ACK) | \
27 BIT_ULL(VHOST_USER_PROTOCOL_F_SLAVE_REQ) | \
Johannes Bergdd9ada52020-02-13 14:26:46 +010028 BIT_ULL(VHOST_USER_PROTOCOL_F_CONFIG) | \
29 BIT_ULL(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS))
Erel Geron5d38f322019-09-11 14:51:20 +020030
31enum vhost_user_request {
32 VHOST_USER_GET_FEATURES = 1,
33 VHOST_USER_SET_FEATURES = 2,
34 VHOST_USER_SET_OWNER = 3,
35 VHOST_USER_RESET_OWNER = 4,
36 VHOST_USER_SET_MEM_TABLE = 5,
37 VHOST_USER_SET_LOG_BASE = 6,
38 VHOST_USER_SET_LOG_FD = 7,
39 VHOST_USER_SET_VRING_NUM = 8,
40 VHOST_USER_SET_VRING_ADDR = 9,
41 VHOST_USER_SET_VRING_BASE = 10,
42 VHOST_USER_GET_VRING_BASE = 11,
43 VHOST_USER_SET_VRING_KICK = 12,
44 VHOST_USER_SET_VRING_CALL = 13,
45 VHOST_USER_SET_VRING_ERR = 14,
46 VHOST_USER_GET_PROTOCOL_FEATURES = 15,
47 VHOST_USER_SET_PROTOCOL_FEATURES = 16,
48 VHOST_USER_GET_QUEUE_NUM = 17,
49 VHOST_USER_SET_VRING_ENABLE = 18,
50 VHOST_USER_SEND_RARP = 19,
51 VHOST_USER_NET_SEND_MTU = 20,
52 VHOST_USER_SET_SLAVE_REQ_FD = 21,
53 VHOST_USER_IOTLB_MSG = 22,
54 VHOST_USER_SET_VRING_ENDIAN = 23,
55 VHOST_USER_GET_CONFIG = 24,
56 VHOST_USER_SET_CONFIG = 25,
Johannes Bergdd9ada52020-02-13 14:26:46 +010057 VHOST_USER_VRING_KICK = 35,
Erel Geron5d38f322019-09-11 14:51:20 +020058};
59
Johannes Berg2cd097b2019-09-11 14:51:21 +020060enum vhost_user_slave_request {
61 VHOST_USER_SLAVE_IOTLB_MSG = 1,
62 VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2,
63 VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3,
Johannes Bergdd9ada52020-02-13 14:26:46 +010064 VHOST_USER_SLAVE_VRING_CALL = 4,
Johannes Berg2cd097b2019-09-11 14:51:21 +020065};
66
Erel Geron5d38f322019-09-11 14:51:20 +020067struct vhost_user_header {
Johannes Berg2cd097b2019-09-11 14:51:21 +020068 /*
69 * Use enum vhost_user_request for outgoing messages,
70 * uses enum vhost_user_slave_request for incoming ones.
71 */
72 u32 request;
Erel Geron5d38f322019-09-11 14:51:20 +020073 u32 flags;
74 u32 size;
75} __packed;
76
77struct vhost_user_config {
78 u32 offset;
79 u32 size;
80 u32 flags;
Gustavo A. R. Silvaf6e8c472020-05-07 14:26:52 -050081 u8 payload[]; /* Variable length */
Erel Geron5d38f322019-09-11 14:51:20 +020082} __packed;
83
84struct vhost_user_vring_state {
85 u32 index;
86 u32 num;
87} __packed;
88
89struct vhost_user_vring_addr {
90 u32 index;
91 u32 flags;
92 u64 desc, used, avail, log;
93} __packed;
94
95struct vhost_user_mem_region {
96 u64 guest_addr;
97 u64 size;
98 u64 user_addr;
99 u64 mmap_offset;
100} __packed;
101
102struct vhost_user_mem_regions {
103 u32 num;
104 u32 padding;
105 struct vhost_user_mem_region regions[2]; /* Currently supporting 2 */
106} __packed;
107
108union vhost_user_payload {
109 u64 integer;
110 struct vhost_user_config config;
111 struct vhost_user_vring_state vring_state;
112 struct vhost_user_vring_addr vring_addr;
113 struct vhost_user_mem_regions mem_regions;
114};
115
116struct vhost_user_msg {
117 struct vhost_user_header header;
118 union vhost_user_payload payload;
119} __packed;
120
121#endif