1 /*- 2 * Copyright (c) 2016 Microsoft Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice unmodified, this list of conditions, and the following 10 * disclaimer. 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. 14 * 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. 25 */ 26 27 #ifndef _VMBUS_REG_H_ 28 #define _VMBUS_REG_H_ 29 30 #include <sys/param.h> 31 #include <dev/hyperv/include/hyperv.h> /* XXX for hyperv_guid */ 32 #include <dev/hyperv/include/vmbus.h> 33 #if defined(__aarch64__) 34 #include <dev/hyperv/vmbus/aarch64/hyperv_reg.h> 35 #else 36 #include <dev/hyperv/vmbus/x86/hyperv_reg.h> 37 #endif 38 #include <dev/hyperv/vmbus/hyperv_common_reg.h> 39 40 /* 41 * Hyper-V SynIC message format. 42 */ 43 44 #define VMBUS_MSG_DSIZE_MAX 240 45 #define VMBUS_MSG_SIZE 256 46 47 struct vmbus_message { 48 uint32_t msg_type; /* HYPERV_MSGTYPE_ */ 49 uint8_t msg_dsize; /* data size */ 50 uint8_t msg_flags; /* VMBUS_MSGFLAG_ */ 51 uint16_t msg_rsvd; 52 uint64_t msg_id; 53 uint8_t msg_data[VMBUS_MSG_DSIZE_MAX]; 54 } __packed; 55 CTASSERT(sizeof(struct vmbus_message) == VMBUS_MSG_SIZE); 56 57 #define VMBUS_MSGFLAG_PENDING 0x01 58 59 /* 60 * Hyper-V SynIC event flags 61 */ 62 63 #ifdef __LP64__ 64 #define VMBUS_EVTFLAGS_MAX 32 65 #define VMBUS_EVTFLAG_SHIFT 6 66 #else 67 #define VMBUS_EVTFLAGS_MAX 64 68 #define VMBUS_EVTFLAG_SHIFT 5 69 #endif 70 #define VMBUS_EVTFLAG_LEN (1 << VMBUS_EVTFLAG_SHIFT) 71 #define VMBUS_EVTFLAG_MASK (VMBUS_EVTFLAG_LEN - 1) 72 #define VMBUS_EVTFLAGS_SIZE 256 73 74 struct vmbus_evtflags { 75 u_long evt_flags[VMBUS_EVTFLAGS_MAX]; 76 } __packed; 77 CTASSERT(sizeof(struct vmbus_evtflags) == VMBUS_EVTFLAGS_SIZE); 78 79 /* 80 * Hyper-V Monitor Notification Facility 81 */ 82 83 struct vmbus_mon_trig { 84 uint32_t mt_pending; 85 uint32_t mt_armed; 86 } __packed; 87 88 #define VMBUS_MONTRIGS_MAX 4 89 #define VMBUS_MONTRIG_LEN 32 90 91 struct vmbus_mnf { 92 uint32_t mnf_state; 93 uint32_t mnf_rsvd1; 94 95 struct vmbus_mon_trig mnf_trigs[VMBUS_MONTRIGS_MAX]; 96 uint8_t mnf_rsvd2[536]; 97 98 uint16_t mnf_lat[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 99 uint8_t mnf_rsvd3[256]; 100 101 struct hyperv_mon_param 102 mnf_param[VMBUS_MONTRIGS_MAX][VMBUS_MONTRIG_LEN]; 103 uint8_t mnf_rsvd4[1984]; 104 } __packed; 105 CTASSERT(sizeof(struct vmbus_mnf) == PAGE_SIZE); 106 107 /* 108 * Buffer ring 109 */ 110 struct vmbus_bufring { 111 /* 112 * If br_windex == br_rindex, this bufring is empty; this 113 * means we can _not_ write data to the bufring, if the 114 * write is going to make br_windex same as br_rindex. 115 */ 116 volatile uint32_t br_windex; 117 volatile uint32_t br_rindex; 118 119 /* 120 * Interrupt mask {0,1} 121 * 122 * For TX bufring, host set this to 1, when it is processing 123 * the TX bufring, so that we can safely skip the TX event 124 * notification to host. 125 * 126 * For RX bufring, once this is set to 1 by us, host will not 127 * further dispatch interrupts to us, even if there are data 128 * pending on the RX bufring. This effectively disables the 129 * interrupt of the channel to which this RX bufring is attached. 130 */ 131 volatile uint32_t br_imask; 132 133 /* 134 * WS2012/Win8 and later versions of Hyper-V implement interrupt 135 * driven flow management. The feature bit feat_pending_snd_sz 136 * is set by the host on the host->guest buffer ring, and by the 137 * guest on the guest->host buffer ring. 138 * 139 * The meaning of the feature bit is a bit complex in that it has 140 * semantics that apply to both buffer rings. If the guest sets 141 * the feature bit in the guest->host buffer ring, the guest is 142 * telling the host that: 143 * 1) It will set the br_pending_snd_sz field in the guest->host buffer 144 * ring when it is waiting for space to become available, and 145 * 2) It will read the pending_send_sz field in the host->guest 146 * ring buffer and interrupt the host when it frees enough space 147 * 148 * Similarly, if the host sets the feature bit in the host->guest 149 * ring buffer, the host is telling the guest that: 150 * 1) It will set the pending_send_sz field in the host->guest ring 151 * buffer when it is waiting for space to become available, and 152 * 2) It will read the pending_send_sz field in the guest->host 153 * ring buffer and interrupt the guest when it frees enough space 154 * 155 * If either the guest or host does not set the feature bit that it 156 * owns, that guest or host must do polling if it encounters a full 157 * ring buffer, and not signal the other end with an interrupt. 158 */ 159 volatile uint32_t br_pending_snd_sz; 160 uint32_t br_rsvd1[12]; 161 union { 162 struct { 163 uint32_t feat_pending_snd_sz:1; 164 }; 165 uint32_t value; 166 } br_feature_bits; 167 168 /* Padding to PAGE_SIZE */ 169 uint8_t br_rsvd2[4020]; 170 171 /* 172 * Total guest to host interrupt count 173 * - For rx ring, this counts the guest signaling host when this rx 174 * ring changing from full to not full. 175 * 176 * - For tx ring, this counts the guest signaling host when this tx 177 * ring changing from empty to non empty. 178 */ 179 uint64_t br_g2h_intr_cnt; 180 181 uint8_t br_data[]; 182 } __packed; 183 CTASSERT(sizeof(struct vmbus_bufring) == PAGE_SIZE); 184 185 /* 186 * Channel 187 */ 188 189 #define VMBUS_CHAN_MAX_COMPAT 256 190 #define VMBUS_CHAN_MAX (VMBUS_EVTFLAG_LEN * VMBUS_EVTFLAGS_MAX) 191 192 /* 193 * Channel packets 194 */ 195 196 #define VMBUS_CHANPKT_SIZE_ALIGN (1 << VMBUS_CHANPKT_SIZE_SHIFT) 197 198 #define VMBUS_CHANPKT_SETLEN(pktlen, len) \ 199 do { \ 200 (pktlen) = (len) >> VMBUS_CHANPKT_SIZE_SHIFT; \ 201 } while (0) 202 203 #define VMBUS_CHANPKT_TOTLEN(tlen) \ 204 roundup2((tlen), VMBUS_CHANPKT_SIZE_ALIGN) 205 206 #define VMBUS_CHANPKT_HLEN_MIN \ 207 (sizeof(struct vmbus_chanpkt_hdr) >> VMBUS_CHANPKT_SIZE_SHIFT) 208 209 struct vmbus_chanpkt { 210 struct vmbus_chanpkt_hdr cp_hdr; 211 } __packed; 212 213 struct vmbus_chanpkt_sglist { 214 struct vmbus_chanpkt_hdr cp_hdr; 215 uint32_t cp_rsvd; 216 uint32_t cp_gpa_cnt; 217 struct vmbus_gpa cp_gpa[]; 218 } __packed; 219 220 struct vmbus_chanpkt_prplist { 221 struct vmbus_chanpkt_hdr cp_hdr; 222 uint32_t cp_rsvd; 223 uint32_t cp_range_cnt; 224 struct vmbus_gpa_range cp_range[]; 225 } __packed; 226 227 /* 228 * Channel messages 229 * - Embedded in vmbus_message.msg_data, e.g. response and notification. 230 * - Embedded in hypercall_postmsg_in.hc_data, e.g. request. 231 */ 232 233 #define VMBUS_CHANMSG_TYPE_CHOFFER 1 /* NOTE */ 234 #define VMBUS_CHANMSG_TYPE_CHRESCIND 2 /* NOTE */ 235 #define VMBUS_CHANMSG_TYPE_CHREQUEST 3 /* REQ */ 236 #define VMBUS_CHANMSG_TYPE_CHOFFER_DONE 4 /* NOTE */ 237 #define VMBUS_CHANMSG_TYPE_CHOPEN 5 /* REQ */ 238 #define VMBUS_CHANMSG_TYPE_CHOPEN_RESP 6 /* RESP */ 239 #define VMBUS_CHANMSG_TYPE_CHCLOSE 7 /* REQ */ 240 #define VMBUS_CHANMSG_TYPE_GPADL_CONN 8 /* REQ */ 241 #define VMBUS_CHANMSG_TYPE_GPADL_SUBCONN 9 /* REQ */ 242 #define VMBUS_CHANMSG_TYPE_GPADL_CONNRESP 10 /* RESP */ 243 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONN 11 /* REQ */ 244 #define VMBUS_CHANMSG_TYPE_GPADL_DISCONNRESP 12 /* RESP */ 245 #define VMBUS_CHANMSG_TYPE_CHFREE 13 /* REQ */ 246 #define VMBUS_CHANMSG_TYPE_CONNECT 14 /* REQ */ 247 #define VMBUS_CHANMSG_TYPE_CONNECT_RESP 15 /* RESP */ 248 #define VMBUS_CHANMSG_TYPE_DISCONNECT 16 /* REQ */ 249 #define VMBUS_CHANMSG_TYPE_17 17 250 #define VMBUS_CHANMSG_TYPE_18 18 251 #define VMBUS_CHANMSG_TYPE_19 19 252 #define VMBUS_CHANMSG_TYPE_20 20 253 #define VMBUS_CHANMSG_TYPE_TL_CONN 21 /* REQ */ 254 #define VMBUS_CHANMSG_TYPE_22 22 255 #define VMBUS_CHANMSG_TYPE_TL_RESULT 23 /* RESP */ 256 #define VMBUS_CHANMSG_TYPE_MAX 24 257 258 struct vmbus_chanmsg_hdr { 259 uint32_t chm_type; /* VMBUS_CHANMSG_TYPE_ */ 260 uint32_t chm_rsvd; 261 } __packed; 262 263 /* VMBUS_CHANMSG_TYPE_CONNECT */ 264 struct vmbus_chanmsg_connect { 265 struct vmbus_chanmsg_hdr chm_hdr; 266 uint32_t chm_ver; 267 uint32_t chm_rsvd; 268 uint64_t chm_evtflags; 269 uint64_t chm_mnf1; 270 uint64_t chm_mnf2; 271 } __packed; 272 273 /* VMBUS_CHANMSG_TYPE_CONNECT_RESP */ 274 struct vmbus_chanmsg_connect_resp { 275 struct vmbus_chanmsg_hdr chm_hdr; 276 uint8_t chm_done; 277 } __packed; 278 279 /* VMBUS_CHANMSG_TYPE_CHREQUEST */ 280 struct vmbus_chanmsg_chrequest { 281 struct vmbus_chanmsg_hdr chm_hdr; 282 } __packed; 283 284 /* VMBUS_CHANMSG_TYPE_DISCONNECT */ 285 struct vmbus_chanmsg_disconnect { 286 struct vmbus_chanmsg_hdr chm_hdr; 287 } __packed; 288 289 /* VMBUS_CHANMSG_TYPE_TL_CONN */ 290 /* Hyper-V socket guest connect request */ 291 struct vmbus_chanmsg_tl_connect { 292 struct vmbus_chanmsg_hdr chm_hdr; 293 struct hyperv_guid guest_endpoint_id; 294 struct hyperv_guid host_service_id; 295 } __packed; 296 297 298 /* VMBUS_CHANMSG_TYPE_CHOPEN */ 299 struct vmbus_chanmsg_chopen { 300 struct vmbus_chanmsg_hdr chm_hdr; 301 uint32_t chm_chanid; 302 uint32_t chm_openid; 303 uint32_t chm_gpadl; 304 uint32_t chm_vcpuid; 305 uint32_t chm_txbr_pgcnt; 306 #define VMBUS_CHANMSG_CHOPEN_UDATA_SIZE 120 307 uint8_t chm_udata[VMBUS_CHANMSG_CHOPEN_UDATA_SIZE]; 308 } __packed; 309 310 /* VMBUS_CHANMSG_TYPE_CHOPEN_RESP */ 311 struct vmbus_chanmsg_chopen_resp { 312 struct vmbus_chanmsg_hdr chm_hdr; 313 uint32_t chm_chanid; 314 uint32_t chm_openid; 315 uint32_t chm_status; 316 } __packed; 317 318 /* VMBUS_CHANMSG_TYPE_GPADL_CONN */ 319 struct vmbus_chanmsg_gpadl_conn { 320 struct vmbus_chanmsg_hdr chm_hdr; 321 uint32_t chm_chanid; 322 uint32_t chm_gpadl; 323 uint16_t chm_range_len; 324 uint16_t chm_range_cnt; 325 struct vmbus_gpa_range chm_range; 326 } __packed; 327 328 #define VMBUS_CHANMSG_GPADL_CONN_PGMAX 26 329 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_conn, 330 chm_range.gpa_page[VMBUS_CHANMSG_GPADL_CONN_PGMAX]) <= 331 HYPERCALL_POSTMSGIN_DSIZE_MAX); 332 333 /* VMBUS_CHANMSG_TYPE_GPADL_SUBCONN */ 334 struct vmbus_chanmsg_gpadl_subconn { 335 struct vmbus_chanmsg_hdr chm_hdr; 336 uint32_t chm_msgno; 337 uint32_t chm_gpadl; 338 uint64_t chm_gpa_page[]; 339 } __packed; 340 341 #define VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX 28 342 CTASSERT(__offsetof(struct vmbus_chanmsg_gpadl_subconn, 343 chm_gpa_page[VMBUS_CHANMSG_GPADL_SUBCONN_PGMAX]) <= 344 HYPERCALL_POSTMSGIN_DSIZE_MAX); 345 346 /* VMBUS_CHANMSG_TYPE_GPADL_CONNRESP */ 347 struct vmbus_chanmsg_gpadl_connresp { 348 struct vmbus_chanmsg_hdr chm_hdr; 349 uint32_t chm_chanid; 350 uint32_t chm_gpadl; 351 uint32_t chm_status; 352 } __packed; 353 354 /* VMBUS_CHANMSG_TYPE_CHCLOSE */ 355 struct vmbus_chanmsg_chclose { 356 struct vmbus_chanmsg_hdr chm_hdr; 357 uint32_t chm_chanid; 358 } __packed; 359 360 /* VMBUS_CHANMSG_TYPE_GPADL_DISCONN */ 361 struct vmbus_chanmsg_gpadl_disconn { 362 struct vmbus_chanmsg_hdr chm_hdr; 363 uint32_t chm_chanid; 364 uint32_t chm_gpadl; 365 } __packed; 366 367 /* VMBUS_CHANMSG_TYPE_CHFREE */ 368 struct vmbus_chanmsg_chfree { 369 struct vmbus_chanmsg_hdr chm_hdr; 370 uint32_t chm_chanid; 371 } __packed; 372 373 /* VMBUS_CHANMSG_TYPE_CHRESCIND */ 374 struct vmbus_chanmsg_chrescind { 375 struct vmbus_chanmsg_hdr chm_hdr; 376 uint32_t chm_chanid; 377 } __packed; 378 379 /* Size of the user defined data buffer for non-pipe offers */ 380 #define VMBUS_CHANMSG_CHOFFER_UDATA_SIZE 120 381 382 /* Size of the user defined data buffer for pipe offers. */ 383 #define VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE 116 384 385 /* VMBUS_CHANMSG_TYPE_CHOFFER */ 386 struct vmbus_chanmsg_choffer { 387 struct vmbus_chanmsg_hdr chm_hdr; 388 struct hyperv_guid chm_chtype; 389 struct hyperv_guid chm_chinst; 390 uint64_t chm_chlat; /* unit: 100ns */ 391 uint32_t chm_chrev; 392 uint32_t chm_svrctx_sz; 393 uint16_t chm_chflags; 394 uint16_t chm_mmio_sz; /* unit: MB */ 395 396 union { 397 /* Non-pipes */ 398 struct { 399 uint8_t user_def[VMBUS_CHANMSG_CHOFFER_UDATA_SIZE]; 400 } std; 401 /* 402 * Pipes: 403 * For integrated pipe protocol, which is implemented on 404 * top of standard user-defined data. Pipe clients have 405 * VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE bytes left for 406 * their own user. 407 */ 408 struct { 409 uint32_t pipe_mode; 410 uint8_t 411 user_def[VMBUS_CHANMSG_CHOFFER_UDATA_PIPE_SIZE]; 412 } pipe; 413 } chm_udata; 414 415 uint16_t chm_subidx; 416 uint16_t chm_rsvd; 417 uint32_t chm_chanid; 418 uint8_t chm_montrig; 419 uint8_t chm_flags1; /* VMBUS_CHOFFER_FLAG1_ */ 420 uint16_t chm_flags2; 421 uint32_t chm_connid; 422 } __packed; 423 CTASSERT(sizeof(struct vmbus_chanmsg_choffer) <= VMBUS_MSG_DSIZE_MAX); 424 425 /* Server Flag */ 426 #define VMBUS_CHAN_TLNPI_PROVIDER_OFFER 0x2000 427 428 #define VMBUS_CHOFFER_FLAG1_HASMNF 0x01 429 430 #endif /* !_VMBUS_REG_H_ */ 431