xref: /freebsd/sys/dev/hyperv/utilities/vmbus_icreg.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
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 
278f555c7dSSepherosa Ziehau #ifndef _VMBUS_ICREG_H_
288f555c7dSSepherosa Ziehau #define _VMBUS_ICREG_H_
298f555c7dSSepherosa Ziehau 
308f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_NEGOTIATE	0
318f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_HEARTBEAT	1
328f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_KVP		2
338f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_SHUTDOWN	3
348f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_TIMESYNC	4
358f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_TYPE_VSS		5
368f555c7dSSepherosa Ziehau 
378f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_STATUS_OK		0x00000000
388f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_STATUS_FAIL		0x80004005
398f555c7dSSepherosa Ziehau 
408f555c7dSSepherosa Ziehau #define VMBUS_IC_VERSION(major, minor)	((major) | (((uint32_t)(minor)) << 16))
418f555c7dSSepherosa Ziehau #define VMBUS_ICVER_MAJOR(ver)		((ver) & 0xffff)
428f555c7dSSepherosa Ziehau #define VMBUS_ICVER_MINOR(ver)		(((ver) & 0xffff0000) >> 16)
435bf51473SSepherosa Ziehau #define VMBUS_ICVER_SWAP(ver)		\
445bf51473SSepherosa Ziehau 	((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver)))
455bf51473SSepherosa Ziehau #define VMBUS_ICVER_LE(v1, v2)		\
465bf51473SSepherosa Ziehau 	(VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2)))
475bf51473SSepherosa Ziehau #define VMBUS_ICVER_GT(v1, v2)		\
485bf51473SSepherosa Ziehau 	(VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2)))
498f555c7dSSepherosa Ziehau 
508f555c7dSSepherosa Ziehau struct vmbus_pipe_hdr {
518f555c7dSSepherosa Ziehau 	uint32_t		ph_flags;
528f555c7dSSepherosa Ziehau 	uint32_t		ph_msgsz;
538f555c7dSSepherosa Ziehau } __packed;
548f555c7dSSepherosa Ziehau 
558f555c7dSSepherosa Ziehau struct vmbus_icmsg_hdr {
568f555c7dSSepherosa Ziehau 	struct vmbus_pipe_hdr	ic_pipe;
578f555c7dSSepherosa Ziehau 	uint32_t		ic_fwver;	/* framework version */
588f555c7dSSepherosa Ziehau 	uint16_t		ic_type;
598f555c7dSSepherosa Ziehau 	uint32_t		ic_msgver;	/* message version */
608f555c7dSSepherosa Ziehau 	uint16_t		ic_dsize;	/* data size */
618f555c7dSSepherosa Ziehau 	uint32_t		ic_status;	/* VMBUS_ICMSG_STATUS_ */
628f555c7dSSepherosa Ziehau 	uint8_t			ic_xactid;
638f555c7dSSepherosa Ziehau 	uint8_t			ic_flags;	/* VMBUS_ICMSG_FLAG_ */
648f555c7dSSepherosa Ziehau 	uint8_t			ic_rsvd[2];
658f555c7dSSepherosa Ziehau } __packed;
668f555c7dSSepherosa Ziehau 
678f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_XACT		0x0001
688f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_REQ		0x0002
698f555c7dSSepherosa Ziehau #define VMBUS_ICMSG_FLAG_RESP		0x0004
708f555c7dSSepherosa Ziehau 
718f555c7dSSepherosa Ziehau /* VMBUS_ICMSG_TYPE_NEGOTIATE */
728f555c7dSSepherosa Ziehau struct vmbus_icmsg_negotiate {
738f555c7dSSepherosa Ziehau 	struct vmbus_icmsg_hdr	ic_hdr;
748f555c7dSSepherosa Ziehau 	uint16_t		ic_fwver_cnt;
758f555c7dSSepherosa Ziehau 	uint16_t		ic_msgver_cnt;
768f555c7dSSepherosa Ziehau 	uint32_t		ic_rsvd;
778f555c7dSSepherosa Ziehau 	/*
788f555c7dSSepherosa Ziehau 	 * This version array contains two set of supported
798f555c7dSSepherosa Ziehau 	 * versions:
808f555c7dSSepherosa Ziehau 	 * - The first set consists of #ic_fwver_cnt supported framework
818f555c7dSSepherosa Ziehau 	 *   versions.
828f555c7dSSepherosa Ziehau 	 * - The second set consists of #ic_msgver_cnt supported message
838f555c7dSSepherosa Ziehau 	 *   versions.
848f555c7dSSepherosa Ziehau 	 */
858f555c7dSSepherosa Ziehau 	uint32_t		ic_ver[];
868f555c7dSSepherosa Ziehau } __packed;
878f555c7dSSepherosa Ziehau 
8802d99265SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_HEARTBEAT */
8902d99265SSepherosa Ziehau struct vmbus_icmsg_heartbeat {
9002d99265SSepherosa Ziehau 	struct vmbus_icmsg_hdr	ic_hdr;
9102d99265SSepherosa Ziehau 	uint64_t		ic_seq;
9202d99265SSepherosa Ziehau 	uint32_t		ic_rsvd[8];
9302d99265SSepherosa Ziehau } __packed;
9402d99265SSepherosa Ziehau 
9502d99265SSepherosa Ziehau #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN	\
9602d99265SSepherosa Ziehau 	__offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0])
9702d99265SSepherosa Ziehau 
98225c6e91SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_SHUTDOWN */
991feb1327SSepherosa Ziehau struct vmbus_icmsg_shutdown {
1001feb1327SSepherosa Ziehau 	struct vmbus_icmsg_hdr	ic_hdr;
1011feb1327SSepherosa Ziehau 	uint32_t		ic_code;
1021feb1327SSepherosa Ziehau 	uint32_t		ic_timeo;
1031feb1327SSepherosa Ziehau 	uint32_t 		ic_haltflags;
1041feb1327SSepherosa Ziehau 	uint8_t			ic_msg[2048];
1051feb1327SSepherosa Ziehau } __packed;
1061feb1327SSepherosa Ziehau 
1071feb1327SSepherosa Ziehau #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN	\
1081feb1327SSepherosa Ziehau 	__offsetof(struct vmbus_icmsg_shutdown, ic_msg[0])
1091feb1327SSepherosa Ziehau 
110225c6e91SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_TIMESYNC */
111225c6e91SSepherosa Ziehau struct vmbus_icmsg_timesync {
112225c6e91SSepherosa Ziehau 	struct vmbus_icmsg_hdr	ic_hdr;
113225c6e91SSepherosa Ziehau 	uint64_t		ic_hvtime;
114225c6e91SSepherosa Ziehau 	uint64_t		ic_vmtime;
115*69b12e53SSepherosa Ziehau 	uint64_t		ic_rtt;
116*69b12e53SSepherosa Ziehau 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
117*69b12e53SSepherosa Ziehau } __packed;
118*69b12e53SSepherosa Ziehau 
119*69b12e53SSepherosa Ziehau /* VMBUS_ICMSG_TYPE_TIMESYNC, MSGVER4 */
120*69b12e53SSepherosa Ziehau struct vmbus_icmsg_timesync4 {
121*69b12e53SSepherosa Ziehau 	struct vmbus_icmsg_hdr	ic_hdr;
122*69b12e53SSepherosa Ziehau 	uint64_t		ic_hvtime;
123096d83feSSepherosa Ziehau 	uint64_t		ic_sent_tc;
124225c6e91SSepherosa Ziehau 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
125*69b12e53SSepherosa Ziehau 	uint8_t			ic_rsvd[5];
126225c6e91SSepherosa Ziehau } __packed;
127225c6e91SSepherosa Ziehau 
128225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_FLAG_SYNC	0x01
129225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_FLAG_SAMPLE	0x02
130225c6e91SSepherosa Ziehau 
131225c6e91SSepherosa Ziehau #define VMBUS_ICMSG_TS_BASE		116444736000000000ULL
132225c6e91SSepherosa Ziehau 
1338f555c7dSSepherosa Ziehau #endif	/* !_VMBUS_ICREG_H_ */
134