Home | History | Annotate | Line # | Download | only in hyperv
vmbusicreg.h revision 1.1
      1 /*	$NetBSD: vmbusicreg.h,v 1.1 2019/02/15 08:54:02 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_IC_BUFRINGSIZE		(4 * PAGE_SIZE)
     36 
     37 #define VMBUS_ICMSG_TYPE_NEGOTIATE	0
     38 #define VMBUS_ICMSG_TYPE_HEARTBEAT	1
     39 #define VMBUS_ICMSG_TYPE_KVP		2
     40 #define VMBUS_ICMSG_TYPE_SHUTDOWN	3
     41 #define VMBUS_ICMSG_TYPE_TIMESYNC	4
     42 #define VMBUS_ICMSG_TYPE_VSS		5
     43 
     44 #define VMBUS_ICMSG_STATUS_OK		0x00000000
     45 #define VMBUS_ICMSG_STATUS_FAIL		0x80004005
     46 
     47 #define VMBUS_IC_VERSION(major, minor)	((major) | (((uint32_t)(minor)) << 16))
     48 #define VMBUS_ICVER_MAJOR(ver)		((ver) & 0xffff)
     49 #define VMBUS_ICVER_MINOR(ver)		(((ver) & 0xffff0000) >> 16)
     50 #define VMBUS_ICVER_SWAP(ver)		\
     51             ((VMBUS_ICVER_MAJOR((ver)) << 16) | VMBUS_ICVER_MINOR((ver)))
     52 #define VMBUS_ICVER_LE(v1, v2)		\
     53             (VMBUS_ICVER_SWAP((v1)) <= VMBUS_ICVER_SWAP((v2)))
     54 #define VMBUS_ICVER_GT(v1, v2)		\
     55             (VMBUS_ICVER_SWAP((v1)) > VMBUS_ICVER_SWAP((v2)))
     56 
     57 struct vmbus_pipe_hdr {
     58 	uint32_t		ph_flags;
     59 	uint32_t		ph_msgsz;
     60 } __packed;
     61 
     62 struct vmbus_icmsg_hdr {
     63 	struct vmbus_pipe_hdr	ic_pipe;
     64 	uint32_t		ic_fwver;	/* framework version */
     65 	uint16_t		ic_type;
     66 	uint32_t		ic_msgver;	/* message version */
     67 	uint16_t		ic_dsize;	/* data size */
     68 	uint32_t		ic_status;	/* VMBUS_ICMSG_STATUS_ */
     69 	uint8_t			ic_tid;
     70 	uint8_t			ic_flags;	/* VMBUS_ICMSG_FLAG_ */
     71 	uint8_t			ic_rsvd[2];
     72 } __packed;
     73 
     74 #define VMBUS_ICMSG_FLAG_TRANSACTION	1
     75 #define VMBUS_ICMSG_FLAG_REQUEST	2
     76 #define VMBUS_ICMSG_FLAG_RESPONSE	4
     77 
     78 /* VMBUS_ICMSG_TYPE_NEGOTIATE */
     79 struct vmbus_icmsg_negotiate {
     80 	struct vmbus_icmsg_hdr	ic_hdr;
     81 	uint16_t		ic_fwver_cnt;
     82 	uint16_t		ic_msgver_cnt;
     83 	uint32_t		ic_rsvd;
     84 	/*
     85 	 * This version array contains two set of supported
     86 	 * versions:
     87 	 * - The first set consists of #ic_fwver_cnt supported framework
     88 	 *   versions.
     89 	 * - The second set consists of #ic_msgver_cnt supported message
     90 	 *   versions.
     91 	 */
     92 	uint32_t		ic_ver[0];
     93 } __packed;
     94 
     95 /* VMBUS_ICMSG_TYPE_HEARTBEAT */
     96 struct vmbus_icmsg_heartbeat {
     97 	struct vmbus_icmsg_hdr	ic_hdr;
     98 	uint64_t		ic_seq;
     99 	uint32_t		ic_rsvd[8];
    100 } __packed;
    101 
    102 #define VMBUS_ICMSG_HEARTBEAT_SIZE_MIN	\
    103 	    offsetof(struct vmbus_icmsg_heartbeat, ic_rsvd[0])
    104 
    105 /* VMBUS_ICMSG_TYPE_SHUTDOWN */
    106 struct vmbus_icmsg_shutdown {
    107 	struct vmbus_icmsg_hdr	ic_hdr;
    108 	uint32_t		ic_code;
    109 	uint32_t		ic_timeo;
    110 	uint32_t 		ic_haltflags;
    111 	uint8_t			ic_msg[2048];
    112 } __packed;
    113 
    114 #define VMBUS_ICMSG_SHUTDOWN_SIZE_MIN	\
    115 	    offsetof(struct vmbus_icmsg_shutdown, ic_msg[0])
    116 
    117 /* VMBUS_ICMSG_TYPE_TIMESYNC */
    118 struct vmbus_icmsg_timesync {
    119 	struct vmbus_icmsg_hdr	ic_hdr;
    120 	uint64_t		ic_hvtime;
    121 	uint64_t		ic_vmtime;
    122 	uint64_t		ic_rtt;
    123 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
    124 } __packed;
    125 
    126 /* VMBUS_ICMSG_TYPE_TIMESYNC, MSGVER4 */
    127 struct vmbus_icmsg_timesync4 {
    128 	struct vmbus_icmsg_hdr	ic_hdr;
    129 	uint64_t		ic_hvtime;
    130 	uint64_t		ic_sent_tc;
    131 	uint8_t			ic_tsflags;	/* VMBUS_ICMSG_TS_FLAG_ */
    132 	uint8_t			ic_rsvd[5];
    133 } __packed;
    134 
    135 #define VMBUS_ICMSG_TS_FLAG_SYNC	0x01
    136 #define VMBUS_ICMSG_TS_FLAG_SAMPLE	0x02
    137 
    138 #define VMBUS_ICMSG_TS_BASE		116444736000000000ULL
    139 
    140 /* Registry value types */
    141 #define VMBUS_KVP_REG_SZ		1
    142 #define VMBUS_KVP_REG_U32		4
    143 #define VMBUS_KVP_REG_U64		8
    144 
    145 /* Hyper-V status codes */
    146 #define VMBUS_KVP_S_OK			0x00000000
    147 #define VMBUS_KVP_E_FAIL		0x80004005
    148 #define VMBUS_KVP_S_CONT		0x80070103
    149 
    150 #define VMBUS_KVP_MAX_VAL_SIZE		2048
    151 #define VMBUS_KVP_MAX_KEY_SIZE		512
    152 
    153 enum vmbus_kvp_op {
    154 	VMBUS_KVP_OP_GET = 0,
    155 	VMBUS_KVP_OP_SET,
    156 	VMBUS_KVP_OP_DELETE,
    157 	VMBUS_KVP_OP_ENUMERATE,
    158 	VMBUS_KVP_OP_GET_IP_INFO,
    159 	VMBUS_KVP_OP_SET_IP_INFO,
    160 	VMBUS_KVP_OP_COUNT
    161 };
    162 
    163 enum vmbus_kvp_pool {
    164 	VMBUS_KVP_POOL_EXTERNAL = 0,
    165 	VMBUS_KVP_POOL_GUEST,
    166 	VMBUS_KVP_POOL_AUTO,
    167 	VMBUS_KVP_POOL_AUTO_EXTERNAL,
    168 	VMBUS_KVP_POOL_COUNT
    169 };
    170 
    171 union vmbus_kvp_hdr {
    172 	struct {
    173 		uint8_t		kvu_op;
    174 		uint8_t		kvu_pool;
    175 		uint16_t	kvu_pad;
    176 	} req;
    177 	struct {
    178 		uint32_t	kvu_err;
    179 	} rsp;
    180 #define kvh_op			req.kvu_op
    181 #define kvh_pool		req.kvu_pool
    182 #define kvh_err			rsp.kvu_err
    183 } __packed;
    184 
    185 struct vmbus_kvp_msg_val {
    186 	uint32_t		kvm_valtype;
    187 	uint32_t		kvm_keylen;
    188 	uint32_t		kvm_vallen;
    189 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    190 	uint8_t			kvm_val[VMBUS_KVP_MAX_VAL_SIZE];
    191 } __packed;
    192 
    193 struct vmbus_kvp_msg_enum {
    194 	uint32_t		kvm_index;
    195 	uint32_t		kvm_valtype;
    196 	uint32_t		kvm_keylen;
    197 	uint32_t		kvm_vallen;
    198 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    199 	uint8_t			kvm_val[VMBUS_KVP_MAX_VAL_SIZE];
    200 } __packed;
    201 
    202 struct vmbus_kvp_msg_del {
    203 	uint32_t		kvm_keylen;
    204 	uint8_t			kvm_key[VMBUS_KVP_MAX_KEY_SIZE];
    205 } __packed;
    206 
    207 #define ADDR_FAMILY_NONE	0x00
    208 #define ADDR_FAMILY_IPV4	0x01
    209 #define ADDR_FAMILY_IPV6	0x02
    210 
    211 #define MAX_MAC_ADDR_SIZE	256
    212 #define MAX_IP_ADDR_SIZE	2048
    213 #define MAX_GATEWAY_SIZE	1024
    214 
    215 struct vmbus_kvp_msg_addr {
    216 	uint8_t			kvm_mac[MAX_MAC_ADDR_SIZE];
    217 	uint8_t			kvm_family;
    218 	uint8_t			kvm_dhcp;
    219 	uint8_t			kvm_addr[MAX_IP_ADDR_SIZE];
    220 	uint8_t			kvm_netmask[MAX_IP_ADDR_SIZE];
    221 	uint8_t			kvm_gateway[MAX_GATEWAY_SIZE];
    222 	uint8_t			kvm_dns[MAX_IP_ADDR_SIZE];
    223 } __packed;
    224 
    225 union vmbus_kvp_msg {
    226 	struct vmbus_kvp_msg_val	kvm_val;
    227 	struct vmbus_kvp_msg_enum	kvm_enum;
    228 	struct vmbus_kvp_msg_del	kvm_del;
    229 };
    230 
    231 struct vmbus_icmsg_kvp {
    232 	struct vmbus_icmsg_hdr	ic_hdr;
    233 	union vmbus_kvp_hdr	ic_kvh;
    234 	union vmbus_kvp_msg	ic_kvm;
    235 } __packed;
    236 
    237 struct vmbus_icmsg_kvp_addr {
    238 	struct vmbus_icmsg_hdr	ic_hdr;
    239 	struct {
    240 		struct {
    241 			uint8_t	kvu_op;
    242 			uint8_t	kvu_pool;
    243 		} req;
    244 	}			ic_kvh;
    245 	struct vmbus_kvp_msg_addr ic_kvm;
    246 } __packed;
    247 
    248 #endif	/* _VMBUSICREG_H_ */
    249