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