18f555c7dSSepherosa Ziehau /*- 28f555c7dSSepherosa Ziehau * Copyright (c) 2016 Microsoft Corp. 38f555c7dSSepherosa Ziehau * All rights reserved. 48f555c7dSSepherosa Ziehau * 58f555c7dSSepherosa Ziehau * Redistribution and use in source and binary forms, with or without 68f555c7dSSepherosa Ziehau * modification, are permitted provided that the following conditions 78f555c7dSSepherosa Ziehau * are met: 88f555c7dSSepherosa Ziehau * 1. Redistributions of source code must retain the above copyright 98f555c7dSSepherosa Ziehau * notice unmodified, this list of conditions, and the following 108f555c7dSSepherosa Ziehau * disclaimer. 118f555c7dSSepherosa Ziehau * 2. Redistributions in binary form must reproduce the above copyright 128f555c7dSSepherosa Ziehau * notice, this list of conditions and the following disclaimer in the 138f555c7dSSepherosa Ziehau * documentation and/or other materials provided with the distribution. 148f555c7dSSepherosa Ziehau * 158f555c7dSSepherosa Ziehau * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 168f555c7dSSepherosa Ziehau * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 178f555c7dSSepherosa Ziehau * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 188f555c7dSSepherosa Ziehau * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 198f555c7dSSepherosa Ziehau * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 208f555c7dSSepherosa Ziehau * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 218f555c7dSSepherosa Ziehau * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 228f555c7dSSepherosa Ziehau * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 238f555c7dSSepherosa Ziehau * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 248f555c7dSSepherosa Ziehau * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 258f555c7dSSepherosa Ziehau * 268f555c7dSSepherosa Ziehau * $FreeBSD$ 278f555c7dSSepherosa Ziehau */ 288f555c7dSSepherosa Ziehau 298f555c7dSSepherosa Ziehau #ifndef _VMBUS_ICREG_H_ 308f555c7dSSepherosa Ziehau #define _VMBUS_ICREG_H_ 318f555c7dSSepherosa Ziehau 328f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_NEGOTIATE 0 338f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_HEARTBEAT 1 348f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_KVP 2 358f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_SHUTDOWN 3 368f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_TIMESYNC 4 378f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_VSS 5 388f555c7dSSepherosa Ziehau 398f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_STATUS_OK 0x00000000 408f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_STATUS_FAIL 0x80004005 418f555c7dSSepherosa Ziehau 428f555c7dSSepherosa Ziehau #define VMBUS_IC_VERSION(major, minor) ((major) | (((uint32_t)(minor)) << 16)) 438f555c7dSSepherosa Ziehau #define VMBUS_ICVER_MAJOR(ver) ((ver) & 0xffff) 448f555c7dSSepherosa Ziehau #define VMBUS_ICVER_MINOR(ver) (((ver) & 0xffff0000) >> 16) 45*5bf51473SSepherosa Ziehau #define VMBUS_ICVER_SWAP(ver) \ 46*5bf51473SSepherosa Ziehau ((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver))) 47*5bf51473SSepherosa Ziehau #define VMBUS_ICVER_LE(v1, v2) \ 48*5bf51473SSepherosa Ziehau (VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2))) 49*5bf51473SSepherosa Ziehau #define VMBUS_ICVER_GT(v1, v2) \ 50*5bf51473SSepherosa Ziehau (VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2))) 518f555c7dSSepherosa Ziehau 528f555c7dSSepherosa Ziehau struct vmbus_pipe_hdr { 538f555c7dSSepherosa Ziehau uint32_t ph_flags; 548f555c7dSSepherosa Ziehau uint32_t ph_msgsz; 558f555c7dSSepherosa Ziehau } __packed; 568f555c7dSSepherosa Ziehau 578f555c7dSSepherosa Ziehau struct vmbus_icmsg_hdr { 588f555c7dSSepherosa Ziehau struct vmbus_pipe_hdr ic_pipe; 598f555c7dSSepherosa Ziehau uint32_t ic_fwver; /* framework version */ 608f555c7dSSepherosa Ziehau uint16_t ic_type; 618f555c7dSSepherosa Ziehau uint32_t ic_msgver; /* message version */ 628f555c7dSSepherosa Ziehau uint16_t ic_dsize; /* data size */ 638f555c7dSSepherosa Ziehau uint32_t ic_status; /* VMBUS_ICMSG_STATUS_ */ 648f555c7dSSepherosa Ziehau uint8_t ic_xactid; 658f555c7dSSepherosa Ziehau uint8_t ic_flags; /* VMBUS_ICMSG_FLAG_ */ 668f555c7dSSepherosa Ziehau uint8_t ic_rsvd[2]; 678f555c7dSSepherosa Ziehau } __packed; 688f555c7dSSepherosa Ziehau 698f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_XACT 0x0001 708f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_REQ 0x0002 718f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_RESP 0x0004 728f555c7dSSepherosa Ziehau 738f555c7dSSepherosa Ziehau /* VMBUS_ICMSG_TYPE_NEGOTIATE */ 748f555c7dSSepherosa Ziehau struct vmbus_icmsg_negotiate { 758f555c7dSSepherosa Ziehau struct vmbus_icmsg_hdr ic_hdr; 768f555c7dSSepherosa Ziehau uint16_t ic_fwver_cnt; 778f555c7dSSepherosa Ziehau uint16_t ic_msgver_cnt; 788f555c7dSSepherosa Ziehau uint32_t ic_rsvd; 798f555c7dSSepherosa Ziehau /* 808f555c7dSSepherosa Ziehau * This version array contains two set of supported 818f555c7dSSepherosa Ziehau * versions: 828f555c7dSSepherosa Ziehau * - The first set consists of #ic_fwver_cnt supported framework 838f555c7dSSepherosa Ziehau * versions. 848f555c7dSSepherosa Ziehau * - The second set consists of #ic_msgver_cnt supported message 858f555c7dSSepherosa Ziehau * versions. 868f555c7dSSepherosa Ziehau */ 878f555c7dSSepherosa Ziehau uint32_t ic_ver[]; 888f555c7dSSepherosa Ziehau } __packed; 898f555c7dSSepherosa Ziehau 9002d99265SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_HEARTBEAT */ 9102d99265SSepherosa Ziehau struct vmbus_icmsg_heartbeat { 9202d99265SSepherosa Ziehau struct vmbus_icmsg_hdr ic_hdr; 9302d99265SSepherosa Ziehau uint64_t ic_seq; 9402d99265SSepherosa Ziehau uint32_t ic_rsvd[8]; 9502d99265SSepherosa Ziehau } __packed; 9602d99265SSepherosa Ziehau 9702d99265SSepherosa Ziehau #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN \ 9802d99265SSepherosa Ziehau __offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0]) 9902d99265SSepherosa Ziehau 100225c6e91SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_SHUTDOWN */ 1011feb1327SSepherosa Ziehau struct vmbus_icmsg_shutdown { 1021feb1327SSepherosa Ziehau struct vmbus_icmsg_hdr ic_hdr; 1031feb1327SSepherosa Ziehau uint32_t ic_code; 1041feb1327SSepherosa Ziehau uint32_t ic_timeo; 1051feb1327SSepherosa Ziehau uint32_t ic_haltflags; 1061feb1327SSepherosa Ziehau uint8_t ic_msg[2048]; 1071feb1327SSepherosa Ziehau } __packed; 1081feb1327SSepherosa Ziehau 1091feb1327SSepherosa Ziehau #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN \ 1101feb1327SSepherosa Ziehau __offsetof(struct vmbus_icmsg_shutdown, ic_msg[0]) 1111feb1327SSepherosa Ziehau 112225c6e91SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_TIMESYNC */ 113225c6e91SSepherosa Ziehau struct vmbus_icmsg_timesync { 114225c6e91SSepherosa Ziehau struct vmbus_icmsg_hdr ic_hdr; 115225c6e91SSepherosa Ziehau uint64_t ic_hvtime; 116225c6e91SSepherosa Ziehau uint64_t ic_vmtime; 117225c6e91SSepherosa Ziehau uint64_t ic_rtt; 118225c6e91SSepherosa Ziehau uint8_t ic_tsflags; /* VMBUS_ICMSG_TS_FLAG_ */ 119225c6e91SSepherosa Ziehau } __packed; 120225c6e91SSepherosa Ziehau 121225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_FLAG_SYNC 0x01 122225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_FLAG_SAMPLE 0x02 123225c6e91SSepherosa Ziehau 124225c6e91SSepherosa Ziehau /* XXX consolidate w/ hyperv */ 125225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_BASE 116444736000000000ULL 126225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_FACTOR 100ULL 127225c6e91SSepherosa Ziehau #ifndef NANOSEC 128225c6e91SSepherosa Ziehau #define NANOSEC 1000000000ULL 129225c6e91SSepherosa Ziehau #endif 130225c6e91SSepherosa Ziehau 1318f555c7dSSepherosa Ziehau #endif /* !_VMBUS_ICREG_H_ */ 132