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