2 * Copyright (c) 2016 Microsoft Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <dev/hyperv/include/hyperv.h> /* XXX for hyperv_guid */
34 #include <dev/hyperv/include/vmbus.h>
35 #include <dev/hyperv/vmbus/hyperv_reg.h>
38 * Hyper-V SynIC message format.
41 #define VMBUS_MSG_DSIZE_MAX 240
42 #define VMBUS_MSG_SIZE 256
44 struct vmbus_message {
45 uint32_t msg_type; /* HYPERV_MSGTYPE_ */
46 uint8_t msg_dsize; /* data size */
47 uint8_t msg_flags; /* VMBUS_MSGFLAG_ */
50 uint8_t msg_data[VMBUS_MSG_DSIZE_MAX];
52 CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE);
54 #define VMBUS_MSGFLAG_PENDING 0x01
57 * Hyper-V SynIC event flags
61 #define VMBUS_EVTFLAGS_MAX 32
62 #define VMBUS_EVTFLAG_SHIFT 6
64 #define VMBUS_EVTFLAGS_MAX 64
65 #define VMBUS_EVTFLAG_SHIFT 5
67 #define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT)
68 #define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1)
69 #define VMBUS_EVTFLAGS_SIZE 256
71 struct vmbus_evtflags {
72 u_long evt_flags[VMBUS_EVTFLAGS_MAX];
74 CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE);
77 * Hyper-V Monitor Notification Facility
80 struct vmbus_mon_trig {
85 #define VMBUS_MONTRIGS_MAX 4
86 #define VMBUS_MONTRIG_LEN 32
92 struct vmbus_mon_trig mnf_trigs[VMBUS_MONTRIGS_MAX];
93 uint8_t mnf_rsvd2[536];
95 uint16_t mnf_lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
96 uint8_t mnf_rsvd3[256];
98 struct hyperv_mon_param
99 mnf_param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN];
100 uint8_t mnf_rsvd4[1984];
102 CTASSERT(sizeof(struct vmbus_mnf) == PAGE_SIZE);
107 struct vmbus_bufring {
109 * If br_windex == br_rindex, this bufring is empty; this
110 * means we can _not_ write data to the bufring, if the
111 * write is going to make br_windex same as br_rindex.
113 volatile uint32_t br_windex;
114 volatile uint32_t br_rindex;
117 * Interrupt mask {0,1}
119 * For TX bufring, host set this to 1, when it is processing
120 * the TX bufring, so that we can safely skip the TX event
121 * notification to host.
123 * For RX bufring, once this is set to 1 by us, host will not
124 * further dispatch interrupts to us, even if there are data
125 * pending on the RX bufring. This effectively disables the
126 * interrupt of the channel to which this RX bufring is attached.
128 volatile uint32_t br_imask;
131 * WS2012/Win8 and later versions of Hyper-V implement interrupt
132 * driven flow management. The feature bit feat_pending_snd_sz
133 * is set by the host on the host->guest buffer ring, and by the
134 * guest on the guest->host buffer ring.
136 * The meaning of the feature bit is a bit complex in that it has
137 * semantics that apply to both buffer rings. If the guest sets
138 * the feature bit in the guest->host buffer ring, the guest is
139 * telling the host that:
140 * 1) It will set the br_pending_snd_sz field in the guest->host buffer
141 * ring when it is waiting for space to become available, and
142 * 2) It will read the pending_send_sz field in the host->guest
143 * ring buffer and interrupt the host when it frees enough space
145 * Similarly, if the host sets the feature bit in the host->guest
146 * ring buffer, the host is telling the guest that:
147 * 1) It will set the pending_send_sz field in the host->guest ring
148 * buffer when it is waiting for space to become available, and
149 * 2) It will read the pending_send_sz field in the guest->host
150 * ring buffer and interrupt the guest when it frees enough space
152 * If either the guest or host does not set the feature bit that it
153 * owns, that guest or host must do polling if it encounters a full
154 * ring buffer, and not signal the other end with an interrupt.
156 volatile uint32_t br_pending_snd_sz;
157 uint32_t br_rsvd1[12];
160 uint32_t feat_pending_snd_sz:1;
165 /* Padding to PAGE_SIZE */
166 uint8_t br_rsvd2[4020];
169 * Total guest to host interrupt count
170 * - For rx ring, this counts the guest signaling host when this rx
171 * ring changing from full to not full.
173 * - For tx ring, this counts the guest signaling host when this tx
174 * ring changing from empty to non empty.
176 uint64_t br_g2h_intr_cnt;
180 CTASSERT(sizeof(struct vmbus_bufring) == PAGE_SIZE);
186 #define VMBUS_CHAN_MAX_COMPAT 256
187 #define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX)
193 #define VMBUS_CHANPKT_SIZE_ALIGN (1 << VMBUS_CHANPKT_SIZE_SHIFT)
195 #define VMBUS_CHANPKT_SETLEN(pktlen, len) \
197 (pktlen) = (len) >> VMBUS_CHANPKT_SIZE_SHIFT; \
200 #define VMBUS_CHANPKT_TOTLEN(tlen) \
201 roundup2((tlen), VMBUS_CHANPKT_SIZE_ALIGN)
203 #define VMBUS_CHANPKT_HLEN_MIN \
204 (sizeof(struct vmbus_chanpkt_hdr) >> VMBUS_CHANPKT_SIZE_SHIFT)
206 struct vmbus_chanpkt {
207 struct vmbus_chanpkt_hdr cp_hdr;
210 struct vmbus_chanpkt_sglist {
211 struct vmbus_chanpkt_hdr cp_hdr;
214 struct vmbus_gpa cp_gpa[];
217 struct vmbus_chanpkt_prplist {
218 struct vmbus_chanpkt_hdr cp_hdr;
220 uint32_t cp_range_cnt;
221 struct vmbus_gpa_range cp_range[];
226 * - Embedded in vmbus_message.msg_data, e.g. response and notification.
227 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request.
230 #define VMBUS_CHANMSG_TYPE_CHOFFER 1 /* NOTE */
231 #define VMBUS_CHANMSG_TYPE_CHRESCIND 2 /* NOTE */
232 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */
233 #define VMBUS_CHANMSG_TYPE_CHOFFER_DONE 4 /* NOTE */
234 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */
235 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */
236 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */
237 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */
238 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */
239 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */
240 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */
241 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */
242 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */
243 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */
244 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */
245 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */
246 #define VMBUS_CHANMSG_TYPE_17 17
247 #define VMBUS_CHANMSG_TYPE_18 18
248 #define VMBUS_CHANMSG_TYPE_19 19
249 #define VMBUS_CHANMSG_TYPE_20 20
250 #define VMBUS_CHANMSG_TYPE_TL_CONN 21 /* REQ */
251 #define VMBUS_CHANMSG_TYPE_22 22
252 #define VMBUS_CHANMSG_TYPE_TL_RESULT 23 /* RESP */
253 #define VMBUS_CHANMSG_TYPE_MAX 24
255 struct vmbus_chanmsg_hdr {
256 uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */
260 /* VMBUS_CHANMSG_TYPE_CONNECT */
261 struct vmbus_chanmsg_connect {
262 struct vmbus_chanmsg_hdr chm_hdr;
265 uint64_t chm_evtflags;
270 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */
271 struct vmbus_chanmsg_connect_resp {
272 struct vmbus_chanmsg_hdr chm_hdr;
276 /* VMBUS_CHANMSG_TYPE_CHREQUEST */
277 struct vmbus_chanmsg_chrequest {
278 struct vmbus_chanmsg_hdr chm_hdr;
281 /* VMBUS_CHANMSG_TYPE_DISCONNECT */
282 struct vmbus_chanmsg_disconnect {
283 struct vmbus_chanmsg_hdr chm_hdr;
286 /* VMBUS_CHANMSG_TYPE_TL_CONN */
287 /* Hyper-V socket guest connect request */
288 struct vmbus_chanmsg_tl_connect {
289 struct vmbus_chanmsg_hdr chm_hdr;
290 struct hyperv_guid guest_endpoint_id;
291 struct hyperv_guid host_service_id;
295 /* VMBUS_CHANMSG_TYPE_CHOPEN */
296 struct vmbus_chanmsg_chopen {
297 struct vmbus_chanmsg_hdr chm_hdr;
302 uint32_t chm_txbr_pgcnt;
303 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120
304 uint8_t chm_udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE];
307 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */
308 struct vmbus_chanmsg_chopen_resp {
309 struct vmbus_chanmsg_hdr chm_hdr;
315 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */
316 struct vmbus_chanmsg_gpadl_conn {
317 struct vmbus_chanmsg_hdr chm_hdr;
320 uint16_t chm_range_len;
321 uint16_t chm_range_cnt;
322 struct vmbus_gpa_range chm_range;
325 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26
326 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_conn,
327 chm_range.gpa_page[VMBUS_CHANMSG_GPADL_CONN_PGMAX]) <=
328 HYPERCALL_POSTMSGIN_DSIZE_MAX);
330 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */
331 struct vmbus_chanmsg_gpadl_subconn {
332 struct vmbus_chanmsg_hdr chm_hdr;
335 uint64_t chm_gpa_page[];
338 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28
339 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_subconn,
340 chm_gpa_page[VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX]) <=
341 HYPERCALL_POSTMSGIN_DSIZE_MAX);
343 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */
344 struct vmbus_chanmsg_gpadl_connresp {
345 struct vmbus_chanmsg_hdr chm_hdr;
351 /* VMBUS_CHANMSG_TYPE_CHCLOSE */
352 struct vmbus_chanmsg_chclose {
353 struct vmbus_chanmsg_hdr chm_hdr;
357 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */
358 struct vmbus_chanmsg_gpadl_disconn {
359 struct vmbus_chanmsg_hdr chm_hdr;
364 /* VMBUS_CHANMSG_TYPE_CHFREE */
365 struct vmbus_chanmsg_chfree {
366 struct vmbus_chanmsg_hdr chm_hdr;
370 /* VMBUS_CHANMSG_TYPE_CHRESCIND */
371 struct vmbus_chanmsg_chrescind {
372 struct vmbus_chanmsg_hdr chm_hdr;
376 /* Size of the user defined data buffer for non-pipe offers */
377 #define VMBUS_CHANMSG_CHOFFER_UDATA_SIZE 120
379 /* Size of the user defined data buffer for pipe offers. */
380 #define VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE 116
382 /* VMBUS_CHANMSG_TYPE_CHOFFER */
383 struct vmbus_chanmsg_choffer {
384 struct vmbus_chanmsg_hdr chm_hdr;
385 struct hyperv_guid chm_chtype;
386 struct hyperv_guid chm_chinst;
387 uint64_t chm_chlat; /* unit: 100ns */
389 uint32_t chm_svrctx_sz;
390 uint16_t chm_chflags;
391 uint16_t chm_mmio_sz; /* unit: MB */
396 uint8_t user_def[VMBUS_CHANMSG_CHOFFER_UDATA_SIZE];
400 * For integrated pipe protocol, which is implemented on
401 * top of standard user-defined data. Pipe clients have
402 * VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE bytes left for
408 user_def[VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE];
416 uint8_t chm_flags1; /* VMBUS_CHOFFER_FLAG1_ */
420 CTASSERT(sizeof(struct vmbus_chanmsg_choffer) <= VMBUS_MSG_DSIZE_MAX);
423 #define VMBUS_CHAN_TLNPI_PROVIDER_OFFER 0x2000
425 #define VMBUS_CHOFFER_FLAG1_HASMNF 0x01
427 #endif /* !_VMBUS_REG_H_ */