aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bus/vmbus/rte_vmbus_reg.h
blob: f5a0693dcbe75b4f9eac752a4289ad1ab809e2e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2018, Microsoft Corporation.
 * All Rights Reserved.
 */

#ifndef _VMBUS_REG_H_
#define _VMBUS_REG_H_

/*
 * Hyper-V SynIC message format.
 */
#define VMBUS_MSG_DSIZE_MAX		240
#define VMBUS_MSG_SIZE			256

struct vmbus_message {
	uint32_t	type;	/* HYPERV_MSGTYPE_ */
	uint8_t		dsize;	/* data size */
	uint8_t		flags;	/* VMBUS_MSGFLAG_ */
	uint16_t	rsvd;
	uint64_t	id;
	uint8_t		data[VMBUS_MSG_DSIZE_MAX];
} __rte_packed;

#define VMBUS_MSGFLAG_PENDING		0x01

/*
 * Hyper-V Monitor Notification Facility
 */

struct vmbus_mon_trig {
	uint32_t	pending;
	uint32_t	armed;
} __rte_packed;

#define VMBUS_MONTRIGS_MAX	4
#define VMBUS_MONTRIG_LEN	32

/*
 * Hyper-V Monitor Notification Facility
 */
struct hyperv_mon_param {
	uint32_t	connid;
	uint16_t	evtflag_ofs;
	uint16_t	rsvd;
} __rte_packed;

struct vmbus_mon_page {
	uint32_t	state;
	uint32_t	rsvd1;

	struct vmbus_mon_trig trigs[VMBUS_MONTRIGS_MAX];
	uint8_t		rsvd2[536];

	uint16_t	lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
	uint8_t		rsvd3[256];

	struct hyperv_mon_param
			param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
	uint8_t		rsvd4[1984];
} __rte_packed;

/*
 * Buffer ring
 */

struct vmbus_bufring {
	volatile uint32_t windex;
	volatile uint32_t rindex;

	/*
	 * Interrupt mask {0,1}
	 *
	 * For TX bufring, host set this to 1, when it is processing
	 * the TX bufring, so that we can safely skip the TX event
	 * notification to host.
	 *
	 * For RX bufring, once this is set to 1 by us, host will not
	 * further dispatch interrupts to us, even if there are data
	 * pending on the RX bufring.  This effectively disables the
	 * interrupt of the channel to which this RX bufring is attached.
	 */
	volatile uint32_t imask;

	/*
	 * Win8 uses some of the reserved bits to implement
	 * interrupt driven flow management. On the send side
	 * we can request that the receiver interrupt the sender
	 * when the ring transitions from being full to being able
	 * to handle a message of size "pending_send_sz".
	 *
	 * Add necessary state for this enhancement.
	 */
	volatile uint32_t pending_send;
	uint32_t reserved1[12];

	union {
		struct {
			uint32_t feat_pending_send_sz:1;
		};
		uint32_t value;
	} feature_bits;

	/* Pad it to PAGE_SIZE so that data starts on page boundary */
	uint8_t	reserved2[4028];

	/*
	 * Ring data starts here + RingDataStartOffset
	 * !!! DO NOT place any fields below this !!!
	 */
	uint8_t data[0];
} __rte_packed;

/*
 * Channel packets
 */

/* Channel packet flags */
#define VMBUS_CHANPKT_TYPE_INBAND      0x0006
#define VMBUS_CHANPKT_TYPE_RXBUF       0x0007
#define VMBUS_CHANPKT_TYPE_GPA         0x0009
#define VMBUS_CHANPKT_TYPE_COMP        0x000b

#define VMBUS_CHANPKT_FLAG_NONE        0
#define VMBUS_CHANPKT_FLAG_RC          0x0001  /* report completion */

#define VMBUS_CHANPKT_SIZE_SHIFT	3
#define VMBUS_CHANPKT_SIZE_ALIGN	(1 << VMBUS_CHANPKT_SIZE_SHIFT)
#define VMBUS_CHANPKT_HLEN_MIN		\
	(sizeof(struct vmbus_chanpkt_hdr) >> VMBUS_CHANPKT_SIZE_SHIFT)

static inline uint32_t
vmbus_chanpkt_getlen(uint16_t pktlen)
{
	return (uint32_t)pktlen << VMBUS_CHANPKT_SIZE_SHIFT;
}

/*
 * GPA stuffs.
 */
struct vmbus_gpa_range {
	uint32_t       len;
	uint32_t       ofs;
	uint64_t       page[0];
} __rte_packed;

/* This is actually vmbus_gpa_range.gpa_page[1] */
struct vmbus_gpa {
	uint32_t	len;
	uint32_t	ofs;
	uint64_t	page;
} __rte_packed;

struct vmbus_chanpkt_hdr {
	uint16_t	type;	/* VMBUS_CHANPKT_TYPE_ */
	uint16_t	hlen;	/* header len, in 8 bytes */
	uint16_t	tlen;	/* total len, in 8 bytes */
	uint16_t	flags;	/* VMBUS_CHANPKT_FLAG_ */
	uint64_t	xactid;
} __rte_packed;

static inline uint32_t
vmbus_chanpkt_datalen(const struct vmbus_chanpkt_hdr *pkt)
{
	return vmbus_chanpkt_getlen(pkt->tlen)
		- vmbus_chanpkt_getlen(pkt->hlen);
}

struct vmbus_chanpkt {
	struct vmbus_chanpkt_hdr hdr;
} __rte_packed;

struct vmbus_rxbuf_desc {
	uint32_t	len;
	uint32_t	ofs;
} __rte_packed;

struct vmbus_chanpkt_rxbuf {
	struct vmbus_chanpkt_hdr hdr;
	uint16_t	rxbuf_id;
	uint16_t	rsvd;
	uint32_t	rxbuf_cnt;
	struct vmbus_rxbuf_desc rxbuf[];
} __rte_packed;

struct vmbus_chanpkt_sglist {
	struct vmbus_chanpkt_hdr hdr;
	uint32_t	rsvd;
	uint32_t	gpa_cnt;
	struct vmbus_gpa gpa[];
} __rte_packed;

/*
 * Channel messages
 * - Embedded in vmbus_message.msg_data, e.g. response and notification.
 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request.
 */

#define VMBUS_CHANMSG_TYPE_CHOFFER		1	/* NOTE */
#define VMBUS_CHANMSG_TYPE_CHRESCIND		2	/* NOTE */
#define VMBUS_CHANMSG_TYPE_CHREQUEST		3	/* REQ */
#define VMBUS_CHANMSG_TYPE_CHOFFER_DONE		4	/* NOTE */
#define VMBUS_CHANMSG_TYPE_CHOPEN		5	/* REQ */
#define VMBUS_CHANMSG_TYPE_CHOPEN_RESP		6	/* RESP */
#define VMBUS_CHANMSG_TYPE_CHCLOSE		7	/* REQ */
#define VMBUS_CHANMSG_TYPE_GPADL_CONN		8	/* REQ */
#define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN	9	/* REQ */
#define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP	10	/* RESP */
#define VMBUS_CHANMSG_TYPE_GPADL_DISCONN	11	/* REQ */
#define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP	12	/* RESP */
#define VMBUS_CHANMSG_TYPE_CHFREE		13	/* REQ */
#define VMBUS_CHANMSG_TYPE_CONNECT		14	/* REQ */
#define VMBUS_CHANMSG_TYPE_CONNECT_RESP		15	/* RESP */
#define VMBUS_CHANMSG_TYPE_DISCONNECT		16	/* REQ */
#define VMBUS_CHANMSG_TYPE_MAX			22

struct vmbus_chanmsg_hdr {
	uint32_t	type;	/* VMBUS_CHANMSG_TYPE_ */
	uint32_t	rsvd;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CONNECT */
struct vmbus_chanmsg_connect {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	ver;
	uint32_t	rsvd;
	uint64_t	evtflags;
	uint64_t	mnf1;
	uint64_t	mnf2;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CONNECT_RESP */
struct vmbus_chanmsg_connect_resp {
	struct vmbus_chanmsg_hdr hdr;
	uint8_t		done;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHREQUEST */
struct vmbus_chanmsg_chrequest {
	struct vmbus_chanmsg_hdr hdr;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_DISCONNECT */
struct vmbus_chanmsg_disconnect {
	struct vmbus_chanmsg_hdr hdr;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHOPEN */
struct vmbus_chanmsg_chopen {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
	uint32_t	openid;
	uint32_t	gpadl;
	uint32_t	vcpuid;
	uint32_t	txbr_pgcnt;
#define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE	120
	uint8_t		udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE];
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */
struct vmbus_chanmsg_chopen_resp {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
	uint32_t	openid;
	uint32_t	status;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_GPADL_CONN */
struct vmbus_chanmsg_gpadl_conn {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
	uint32_t	gpadl;
	uint16_t	range_len;
	uint16_t	range_cnt;
	struct vmbus_gpa_range range;
} __rte_packed;

#define VMBUS_CHANMSG_GPADL_CONN_PGMAX		26

/* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */
struct vmbus_chanmsg_gpadl_subconn {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	msgno;
	uint32_t	gpadl;
	uint64_t	gpa_page[];
} __rte_packed;

#define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX	28

/* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */
struct vmbus_chanmsg_gpadl_connresp {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
	uint32_t	gpadl;
	uint32_t	status;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHCLOSE */
struct vmbus_chanmsg_chclose {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */
struct vmbus_chanmsg_gpadl_disconn {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
	uint32_t	gpadl;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHFREE */
struct vmbus_chanmsg_chfree {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHRESCIND */
struct vmbus_chanmsg_chrescind {
	struct vmbus_chanmsg_hdr hdr;
	uint32_t	chanid;
} __rte_packed;

/* VMBUS_CHANMSG_TYPE_CHOFFER */
struct vmbus_chanmsg_choffer {
	struct vmbus_chanmsg_hdr hdr;
	rte_uuid_t	chtype;
	rte_uuid_t	chinst;
	uint64_t	chlat;	/* unit: 100ns */
	uint32_t	chrev;
	uint32_t	svrctx_sz;
	uint16_t	chflags;
	uint16_t	mmio_sz;	/* unit: MB */
	uint8_t		udata[120];
	uint16_t	subidx;
	uint16_t	rsvd;
	uint32_t	chanid;
	uint8_t		montrig;
	uint8_t		flags1;	/* VMBUS_CHOFFER_FLAG1_ */
	uint16_t	flags2;
	uint32_t	connid;
} __rte_packed;

#define VMBUS_CHOFFER_FLAG1_HASMNF	0x01

#endif	/* !_VMBUS_REG_H_ */