• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 - 2020 Intel Corporation
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 #ifndef _USFSTL_VHOST_PROTO_H_
7 #define _USFSTL_VHOST_PROTO_H_
8 
9 #define MAX_REGIONS 8
10 
11 // For simplicity, we only support snapshotting a fixed number of queues. Should
12 // be equal to HWSIM_NUM_VQS.
13 #define NUM_SNAPSHOT_QUEUES 2
14 
15 /* these are from the vhost-user spec */
16 
17 struct vhost_user_msg_hdr {
18 	uint32_t request;
19 
20 #define VHOST_USER_MSG_FLAGS_VERSION	0x3
21 #define VHOST_USER_VERSION		  1
22 #define VHOST_USER_MSG_FLAGS_REPLY	0x4
23 #define VHOST_USER_MSG_FLAGS_NEED_REPLY	0x8
24 	uint32_t flags;
25 
26 	uint32_t size;
27 };
28 
29 struct vhost_user_region {
30 	uint64_t guest_phys_addr;
31 	uint64_t size;
32 	uint64_t user_addr;
33 	uint64_t mmap_offset;
34 };
35 
36 struct vring_snapshot {
37 	int8_t enabled;
38 	int8_t sleeping;
39 	int8_t triggered;
40 
41 	unsigned int num;
42 	uint64_t desc_guest_addr;
43 	uint64_t avail_guest_addr;
44 	uint64_t used_guest_addr;
45 	uint16_t last_avail_idx;
46 };
47 
48 struct vhost_user_snapshot {
49 	struct vring_snapshot vrings[NUM_SNAPSHOT_QUEUES];
50 };
51 
52 
53 struct vhost_user_msg {
54 	struct vhost_user_msg_hdr hdr;
55 	union {
56 #define VHOST_USER_U64_VRING_IDX_MSK	0x7f
57 #define VHOST_USER_U64_NO_FD		0x80
58 		int8_t i8;
59 		uint64_t u64;
60 		struct {
61 			uint32_t idx, num;
62 		} vring_state;
63 		struct {
64 			uint32_t idx, flags;
65 			uint64_t descriptor;
66 			uint64_t used;
67 			uint64_t avail;
68 			uint64_t log;
69 		} vring_addr;
70 		struct {
71 			uint32_t n_regions;
72 			uint32_t reserved;
73 			struct vhost_user_region regions[MAX_REGIONS];
74 		} mem_regions;
75 		struct {
76 			uint32_t offset;
77 			uint32_t size;
78 #define VHOST_USER_CFG_SPACE_WRITABLE	0x1
79 #define VHOST_USER_CFG_SPACE_MIGRATION	0x2
80 			uint32_t flags;
81 			uint8_t payload[0];
82 		} cfg_space;
83 		struct {
84 			uint64_t idx_flags;
85 			uint64_t size;
86 			uint64_t offset;
87 		} vring_area;
88 		struct {
89 			int8_t bool_store;
90 			struct vhost_user_snapshot snapshot;
91 		}  __attribute__((packed)) snapshot_response;
92 		struct {
93 			struct vhost_user_snapshot snapshot;
94 		} __attribute__((packed)) restore_request;
95 	} __attribute__((packed)) payload;
96 };
97 
98 #define VHOST_USER_GET_FEATURES			 1
99 #define VHOST_USER_SET_FEATURES			 2
100 #define VHOST_USER_SET_OWNER			 3
101 #define VHOST_USER_SET_MEM_TABLE		 5
102 #define VHOST_USER_SET_VRING_NUM		 8
103 #define VHOST_USER_SET_VRING_ADDR		 9
104 #define VHOST_USER_SET_VRING_BASE		10
105 #define VHOST_USER_SET_VRING_KICK		12
106 #define VHOST_USER_SET_VRING_CALL		13
107 #define VHOST_USER_GET_PROTOCOL_FEATURES	15
108 #define VHOST_USER_SET_VRING_ENABLE		18
109 #define VHOST_USER_SET_PROTOCOL_FEATURES	16
110 #define VHOST_USER_SET_SLAVE_REQ_FD		21
111 #define VHOST_USER_GET_CONFIG			24
112 #define VHOST_USER_VRING_KICK			35
113 #define VHOST_USER_SLEEP			1000
114 #define VHOST_USER_WAKE				1001
115 #define VHOST_USER_SNAPSHOT			1002
116 #define VHOST_USER_RESTORE			1003
117 #define VHOST_USER_GET_SHARED_MEMORY_REGIONS	1004
118 
119 #define VHOST_USER_SLAVE_CONFIG_CHANGE_MSG	 2
120 #define VHOST_USER_SLAVE_VRING_CALL		 4
121 
122 #define VHOST_USER_F_PROTOCOL_FEATURES 30
123 
124 #define VHOST_USER_PROTOCOL_F_MQ                    0
125 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD             1
126 #define VHOST_USER_PROTOCOL_F_RARP                  2
127 #define VHOST_USER_PROTOCOL_F_REPLY_ACK             3
128 #define VHOST_USER_PROTOCOL_F_MTU                   4
129 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ             5
130 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN          6
131 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION        7
132 #define VHOST_USER_PROTOCOL_F_PAGEFAULT             8
133 #define VHOST_USER_PROTOCOL_F_CONFIG                9
134 #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD        10
135 #define VHOST_USER_PROTOCOL_F_H_OST_NOTIFIER        11
136 #define VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD       12
137 #define VHOST_USER_PROTOCOL_F_RESET_DEVICE         13
138 #define VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS 14
139 
140 #endif // _USFSTL_VHOST_PROTO_H_
141