Home | History | Annotate | Line # | Download | only in hyperv
vmbusicreg.h revision 1.2
      1 /*	$NetBSD: vmbusicreg.h,v 1.2 2019/03/01 10:02:33 nonaka Exp $	*/
      2 /*	$OpenBSD: hypervicreg.h,v 1.6 2017/11/07 16:49:42 mikeb Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 2016 Microsoft Corp.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice unmodified, this list of conditions, and the following
     13  *    disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  *
     29  * $FreeBSD: head/sys/dev/hyperv/utilities/vmbus_icreg.h 305281 2016-09-02 06:23:28Z sephe $
     30  */
     31 
     32 #ifndef _VMBUSICREG_H_
     33 #define _VMBUSICREG_H_
     34 
     35 #define VMBUS_ICMSG_TYPE_NEGOTIATE	0
     36 #define VMBUS_ICMSG_TYPE_HEARTBEAT	1
     37 #define VMBUS_ICMSG_TYPE_KVP		2
     38 #define VMBUS_ICMSG_TYPE_SHUTDOWN	3
     39 #define VMBUS_ICMSG_TYPE_TIMESYNC	4
     40 #define VMBUS_ICMSG_TYPE_VSS		5
     41 
     42 #define VMBUS_ICMSG_STATUS_OK		0x00000000
     43 #define VMBUS_ICMSG_STATUS_FAIL		0x80004005
     44 
     45 #define VMBUS_IC_VERSION(major, minor)	((major) | (((uint32_t)(minor)) << 16))
     46 #define VMBUS_ICVER_MAJOR(ver)		((ver) & 0xffff)
     47 #define VMBUS_ICVER_MINOR(ver)		(((ver) & 0xffff0000) >> 16)
     48 #define VMBUS_ICVER_SWAP(ver)		\
     49             ((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver)))
     50 #define VMBUS_ICVER_LE(v1, v2)		\
     51             (VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2)))
     52 #define VMBUS_ICVER_GT(v1, v2)		\
     53             (VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2)))
     54 
     55 struct vmbus_pipe_hdr {
     56 	uint32_t		ph_flags;
     57 	uint32_t		ph_msgsz;
     58 } __packed;
     59 
     60 struct vmbus_icmsg_hdr {
     61 	struct vmbus_pipe_hdr	ic_pipe;
     62 	uint32_t		ic_fwver;	/* framework version */
     63 	uint16_t		ic_type;
     64 	uint32_t		ic_msgver;	/* message version */
     65 	uint16_t		ic_dsize;	/* data size */
     66 	uint32_t		ic_status;	/* VMBUS_ICMSG_STATUS_ */
     67 	uint8_t			ic_tid;
     68 	uint8_t			ic_flags;	/* VMBUS_ICMSG_FLAG_ */
     69 	uint8_t			ic_rsvd[2];
     70 } __packed;
     71 
     72 #define VMBUS_ICMSG_FLAG_TRANSACTION	1
     73 #define VMBUS_ICMSG_FLAG_REQUEST	2
     74 #define VMBUS_ICMSG_FLAG_RESPONSE	4
     75 
     76 /* VMBUS_ICMSG_TYPE_NEGOTIATE */
     77 struct vmbus_icmsg_negotiate {
     78 	struct vmbus_icmsg_hdr	ic_hdr;
     79 	uint16_t		ic_fwver_cnt;
     80 	uint16_t		ic_msgver_cnt;
     81 	uint32_t		ic_rsvd;
     82 	/*
     83 	 * This version array contains two set of supported
     84 	 * versions:
     85 	 * - The first set consists of #ic_fwver_cnt supported framework
     86 	 *   versions.
     87 	 * - The second set consists of #ic_msgver_cnt supported message
     88 	 *   versions.
     89 	 */
     90 	uint32_t		ic_ver[0];
     91 } __packed;
     92 
     93 /* VMBUS_ICMSG_TYPE_HEARTBEAT */
     94 struct vmbus_icmsg_heartbeat {
     95 	struct vmbus_icmsg_hdr	ic_hdr;
     96 	uint64_t		ic_seq;
     97 	uint32_t		ic_rsvd[8];
     98 } __packed;
     99 
    100 #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN	\
    101 	    offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0])
    102 
    103 /* VMBUS_ICMSG_TYPE_SHUTDOWN */
    104 struct vmbus_icmsg_shutdown {
    105 	struct vmbus_icmsg_hdr	ic_hdr;
    106 	uint32_t		ic_code;
    107 	uint32_t		ic_timeo;
    108 	uint32_t 		ic_haltflags;
    109 	uint8_t			ic_msg[2048];
    110 } __packed;
    111 
    112 #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN	\
    113 	    offsetof(struct vmbus_icmsg_shutdown, ic_msg[0])
    114 
    115 /* VMBUS_ICMSG_TYPE_TIMESYNC */
    116 struct vmbus_icmsg_timesync {
    117 	struct vmbus_icmsg_hdr	ic_hdr;
    118 	uint64_t		ic_hvtime;
    119 	uint64_t		ic_vmtime;
    120 	uint64_t		ic_rtt;
    121 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
    122 } __packed;
    123 
    124 /* VMBUS_ICMSG_TYPE_TIMESYNC, MSGVER4 */
    125 struct vmbus_icmsg_timesync4 {
    126 	struct vmbus_icmsg_hdr	ic_hdr;
    127 	uint64_t		ic_hvtime;
    128 	uint64_t		ic_sent_tc;
    129 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
    130 	uint8_t			ic_rsvd[5];
    131 } __packed;
    132 
    133 #define VMBUS_ICMSG_TS_FLAG_SYNC	0x01
    134 #define VMBUS_ICMSG_TS_FLAG_SAMPLE	0x02
    135 
    136 #define VMBUS_ICMSG_TS_BASE		116444736000000000ULL
    137 
    138 /* Registry value types */
    139 #define VMBUS_KVP_REG_SZ		1
    140 #define VMBUS_KVP_REG_U32		4
    141 #define VMBUS_KVP_REG_U64		8
    142 
    143 /* Hyper-V status codes */
    144 #define VMBUS_KVP_S_OK			0x00000000
    145 #define VMBUS_KVP_E_FAIL		0x80004005
    146 #define VMBUS_KVP_S_CONT		0x80070103
    147 
    148 #define VMBUS_KVP_MAX_VAL_SIZE		2048
    149 #define VMBUS_KVP_MAX_KEY_SIZE		512
    150 
    151 enum vmbus_kvp_op {
    152 	VMBUS_KVP_OP_GET = 0,
    153 	VMBUS_KVP_OP_SET,
    154 	VMBUS_KVP_OP_DELETE,
    155 	VMBUS_KVP_OP_ENUMERATE,
    156 	VMBUS_KVP_OP_GET_IP_INFO,
    157 	VMBUS_KVP_OP_SET_IP_INFO,
    158 	VMBUS_KVP_OP_COUNT
    159 };
    160 
    161 enum vmbus_kvp_pool {
    162 	VMBUS_KVP_POOL_EXTERNAL = 0,
    163 	VMBUS_KVP_POOL_GUEST,
    164 	VMBUS_KVP_POOL_AUTO,
    165 	VMBUS_KVP_POOL_AUTO_EXTERNAL,
    166 	VMBUS_KVP_POOL_COUNT
    167 };
    168 
    169 union vmbus_kvp_hdr {
    170 	struct {
    171 		uint8_t		kvu_op;
    172 		uint8_t		kvu_pool;
    173 		uint16_t	kvu_pad;
    174 	} req;
    175 	struct {
    176 		uint32_t	kvu_err;
    177 	} rsp;
    178 #define kvh_op			req.kvu_op
    179 #define kvh_pool		req.kvu_pool
    180 #define kvh_err			rsp.kvu_err
    181 } __packed;
    182 
    183 struct vmbus_kvp_msg_val {
    184 	uint32_t		kvm_valtype;
    185 	uint32_t		kvm_keylen;
    186 	uint32_t		kvm_vallen;
    187 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    188 	uint8_t			kvm_val[VMBUS_KVP_MAX_VAL_SIZE];
    189 } __packed;
    190 
    191 struct vmbus_kvp_msg_enum {
    192 	uint32_t		kvm_index;
    193 	uint32_t		kvm_valtype;
    194 	uint32_t		kvm_keylen;
    195 	uint32_t		kvm_vallen;
    196 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    197 	uint8_t			kvm_val[VMBUS_KVP_MAX_VAL_SIZE];
    198 } __packed;
    199 
    200 struct vmbus_kvp_msg_del {
    201 	uint32_t		kvm_keylen;
    202 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    203 } __packed;
    204 
    205 #define ADDR_FAMILY_NONE	0x00
    206 #define ADDR_FAMILY_IPV4	0x01
    207 #define ADDR_FAMILY_IPV6	0x02
    208 
    209 #define MAX_MAC_ADDR_SIZE	256
    210 #define MAX_IP_ADDR_SIZE	2048
    211 #define MAX_GATEWAY_SIZE	1024
    212 
    213 struct vmbus_kvp_msg_addr {
    214 	uint8_t			kvm_mac[MAX_MAC_ADDR_SIZE];
    215 	uint8_t			kvm_family;
    216 	uint8_t			kvm_dhcp;
    217 	uint8_t			kvm_addr[MAX_IP_ADDR_SIZE];
    218 	uint8_t			kvm_netmask[MAX_IP_ADDR_SIZE];
    219 	uint8_t			kvm_gateway[MAX_GATEWAY_SIZE];
    220 	uint8_t			kvm_dns[MAX_IP_ADDR_SIZE];
    221 } __packed;
    222 
    223 union vmbus_kvp_msg {
    224 	struct vmbus_kvp_msg_val	kvm_val;
    225 	struct vmbus_kvp_msg_enum	kvm_enum;
    226 	struct vmbus_kvp_msg_del	kvm_del;
    227 };
    228 
    229 struct vmbus_icmsg_kvp {
    230 	struct vmbus_icmsg_hdr	ic_hdr;
    231 	union vmbus_kvp_hdr	ic_kvh;
    232 	union vmbus_kvp_msg	ic_kvm;
    233 } __packed;
    234 
    235 struct vmbus_icmsg_kvp_addr {
    236 	struct vmbus_icmsg_hdr	ic_hdr;
    237 	struct {
    238 		struct {
    239 			uint8_t	kvu_op;
    240 			uint8_t	kvu_pool;
    241 		} req;
    242 	}			ic_kvh;
    243 	struct vmbus_kvp_msg_addr ic_kvm;
    244 } __packed;
    245 
    246 #endif	/* _VMBUSICREG_H_ */
    247