xref: /freebsd/sys/dev/hyperv/utilities/vmbus_icreg.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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_ICREG_H_
28 #define _VMBUS_ICREG_H_
29 
30 #define VMBUS_ICMSG_TYPE_NEGOTIATE	0
31 #define VMBUS_ICMSG_TYPE_HEARTBEAT	1
32 #define VMBUS_ICMSG_TYPE_KVP		2
33 #define VMBUS_ICMSG_TYPE_SHUTDOWN	3
34 #define VMBUS_ICMSG_TYPE_TIMESYNC	4
35 #define VMBUS_ICMSG_TYPE_VSS		5
36 
37 #define VMBUS_ICMSG_STATUS_OK		0x00000000
38 #define VMBUS_ICMSG_STATUS_FAIL		0x80004005
39 
40 #define VMBUS_IC_VERSION(major, minor)	((major) | (((uint32_t)(minor)) << 16))
41 #define VMBUS_ICVER_MAJOR(ver)		((ver) & 0xffff)
42 #define VMBUS_ICVER_MINOR(ver)		(((ver) & 0xffff0000) >> 16)
43 #define VMBUS_ICVER_SWAP(ver)		\
44 	((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver)))
45 #define VMBUS_ICVER_LE(v1, v2)		\
46 	(VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2)))
47 #define VMBUS_ICVER_GT(v1, v2)		\
48 	(VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2)))
49 
50 struct vmbus_pipe_hdr {
51 	uint32_t		ph_flags;
52 	uint32_t		ph_msgsz;
53 } __packed;
54 
55 struct vmbus_icmsg_hdr {
56 	struct vmbus_pipe_hdr	ic_pipe;
57 	uint32_t		ic_fwver;	/* framework version */
58 	uint16_t		ic_type;
59 	uint32_t		ic_msgver;	/* message version */
60 	uint16_t		ic_dsize;	/* data size */
61 	uint32_t		ic_status;	/* VMBUS_ICMSG_STATUS_ */
62 	uint8_t			ic_xactid;
63 	uint8_t			ic_flags;	/* VMBUS_ICMSG_FLAG_ */
64 	uint8_t			ic_rsvd[2];
65 } __packed;
66 
67 #define VMBUS_ICMSG_FLAG_XACT		0x0001
68 #define VMBUS_ICMSG_FLAG_REQ		0x0002
69 #define VMBUS_ICMSG_FLAG_RESP		0x0004
70 
71 /* VMBUS_ICMSG_TYPE_NEGOTIATE */
72 struct vmbus_icmsg_negotiate {
73 	struct vmbus_icmsg_hdr	ic_hdr;
74 	uint16_t		ic_fwver_cnt;
75 	uint16_t		ic_msgver_cnt;
76 	uint32_t		ic_rsvd;
77 	/*
78 	 * This version array contains two set of supported
79 	 * versions:
80 	 * - The first set consists of #ic_fwver_cnt supported framework
81 	 *   versions.
82 	 * - The second set consists of #ic_msgver_cnt supported message
83 	 *   versions.
84 	 */
85 	uint32_t		ic_ver[];
86 } __packed;
87 
88 /* VMBUS_ICMSG_TYPE_HEARTBEAT */
89 struct vmbus_icmsg_heartbeat {
90 	struct vmbus_icmsg_hdr	ic_hdr;
91 	uint64_t		ic_seq;
92 	uint32_t		ic_rsvd[8];
93 } __packed;
94 
95 #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN	\
96 	__offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0])
97 
98 /* VMBUS_ICMSG_TYPE_SHUTDOWN */
99 struct vmbus_icmsg_shutdown {
100 	struct vmbus_icmsg_hdr	ic_hdr;
101 	uint32_t		ic_code;
102 	uint32_t		ic_timeo;
103 	uint32_t 		ic_haltflags;
104 	uint8_t			ic_msg[2048];
105 } __packed;
106 
107 #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN	\
108 	__offsetof(struct vmbus_icmsg_shutdown, ic_msg[0])
109 
110 /* VMBUS_ICMSG_TYPE_TIMESYNC */
111 struct vmbus_icmsg_timesync {
112 	struct vmbus_icmsg_hdr	ic_hdr;
113 	uint64_t		ic_hvtime;
114 	uint64_t		ic_vmtime;
115 	uint64_t		ic_rtt;
116 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
117 } __packed;
118 
119 /* VMBUS_ICMSG_TYPE_TIMESYNC, MSGVER4 */
120 struct vmbus_icmsg_timesync4 {
121 	struct vmbus_icmsg_hdr	ic_hdr;
122 	uint64_t		ic_hvtime;
123 	uint64_t		ic_sent_tc;
124 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
125 	uint8_t			ic_rsvd[5];
126 } __packed;
127 
128 #define VMBUS_ICMSG_TS_FLAG_SYNC	0x01
129 #define VMBUS_ICMSG_TS_FLAG_SAMPLE	0x02
130 
131 #define VMBUS_ICMSG_TS_BASE		116444736000000000ULL
132 
133 #endif	/* !_VMBUS_ICREG_H_ */
134