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: head/sys/dev/hyperv/utilities/vmbus_icreg.h 305281 2016-09-02 06:23:28Z sephe $ 27 */ 28 29 #ifndef _DEV_PV_HYPERVIC_H_ 30 #define _DEV_PV_HYPERVIC_H_ 31 32 #define VMBUS_IC_BUFRINGSIZE (4 * PAGE_SIZE) 33 34 #define VMBUS_ICMSG_TYPE_NEGOTIATE 0 35 #define VMBUS_ICMSG_TYPE_HEARTBEAT 1 36 #define VMBUS_ICMSG_TYPE_KVP 2 37 #define VMBUS_ICMSG_TYPE_SHUTDOWN 3 38 #define VMBUS_ICMSG_TYPE_TIMESYNC 4 39 #define VMBUS_ICMSG_TYPE_VSS 5 40 41 #define VMBUS_ICMSG_STATUS_OK 0x00000000 42 #define VMBUS_ICMSG_STATUS_FAIL 0x80004005 43 44 #define VMBUS_ICMSG_FLAG_TRANSACTION 1 45 #define VMBUS_ICMSG_FLAG_REQUEST 2 46 #define VMBUS_ICMSG_FLAG_RESPONSE 4 47 48 #define VMBUS_IC_VERSION(major, minor) ((major) | (((uint32_t)(minor)) << 16)) 49 #define VMBUS_ICVER_MAJOR(ver) ((ver) & 0xffff) 50 #define VMBUS_ICVER_MINOR(ver) (((ver) & 0xffff0000) >> 16) 51 52 struct vmbus_pipe_hdr { 53 uint32_t ph_flags; 54 uint32_t ph_msgsz; 55 } __packed; 56 57 struct vmbus_icmsg_hdr { 58 struct vmbus_pipe_hdr ic_pipe; 59 uint32_t ic_fwver; /* framework version */ 60 uint16_t ic_type; 61 uint32_t ic_msgver; /* message version */ 62 uint16_t ic_dsize; /* data size */ 63 uint32_t ic_status; /* VMBUS_ICMSG_STATUS_ */ 64 uint8_t ic_tid; 65 uint8_t ic_flags; /* VMBUS_ICMSG_FLAG_ */ 66 uint8_t ic_rsvd[2]; 67 } __packed; 68 69 /* VMBUS_ICMSG_TYPE_NEGOTIATE */ 70 struct vmbus_icmsg_negotiate { 71 struct vmbus_icmsg_hdr ic_hdr; 72 uint16_t ic_fwver_cnt; 73 uint16_t ic_msgver_cnt; 74 uint32_t ic_rsvd; 75 /* 76 * This version array contains two set of supported 77 * versions: 78 * - The first set consists of #ic_fwver_cnt supported framework 79 * versions. 80 * - The second set consists of #ic_msgver_cnt supported message 81 * versions. 82 */ 83 uint32_t ic_ver[0]; 84 } __packed; 85 86 /* VMBUS_ICMSG_TYPE_HEARTBEAT */ 87 struct vmbus_icmsg_heartbeat { 88 struct vmbus_icmsg_hdr ic_hdr; 89 uint64_t ic_seq; 90 uint32_t ic_rsvd[8]; 91 } __packed; 92 93 /* VMBUS_ICMSG_TYPE_SHUTDOWN */ 94 struct vmbus_icmsg_shutdown { 95 struct vmbus_icmsg_hdr ic_hdr; 96 uint32_t ic_code; 97 uint32_t ic_timeo; 98 uint32_t ic_haltflags; 99 uint8_t ic_msg[2048]; 100 } __packed; 101 102 /* VMBUS_ICMSG_TYPE_TIMESYNC */ 103 struct vmbus_icmsg_timesync { 104 struct vmbus_icmsg_hdr ic_hdr; 105 uint64_t ic_hvtime; 106 uint64_t ic_vmtime; 107 uint64_t ic_rtt; 108 uint8_t ic_tsflags; /* VMBUS_ICMSG_TS_FLAG_ */ 109 } __packed; 110 111 #define VMBUS_ICMSG_TS_FLAG_SYNC 0x01 112 #define VMBUS_ICMSG_TS_FLAG_SAMPLE 0x02 113 114 /* Registry value types */ 115 #define HV_KVP_REG_SZ 1 116 #define HV_KVP_REG_U32 4 117 #define HV_KVP_REG_U64 8 118 119 /* Hyper-V status codes */ 120 #define HV_KVP_S_OK 0x00000000 121 #define HV_KVP_E_FAIL 0x80004005 122 #define HV_KVP_S_CONT 0x80070103 123 124 #define HV_KVP_MAX_VAL_SIZE 2048 125 #define HV_KVP_MAX_KEY_SIZE 512 126 127 enum hv_kvp_op { 128 HV_KVP_OP_GET = 0, 129 HV_KVP_OP_SET, 130 HV_KVP_OP_DELETE, 131 HV_KVP_OP_ENUMERATE, 132 HV_KVP_OP_GET_IP_INFO, 133 HV_KVP_OP_SET_IP_INFO, 134 HV_KVP_OP_COUNT 135 }; 136 137 enum hv_kvp_pool { 138 HV_KVP_POOL_EXTERNAL = 0, 139 HV_KVP_POOL_GUEST, 140 HV_KVP_POOL_AUTO, 141 HV_KVP_POOL_AUTO_EXTERNAL, 142 HV_KVP_POOL_COUNT 143 }; 144 145 union hv_kvp_hdr { 146 struct { 147 uint8_t kvu_op; 148 uint8_t kvu_pool; 149 uint16_t kvu_pad; 150 } req; 151 struct { 152 uint32_t kvu_err; 153 } rsp; 154 #define kvh_op req.kvu_op 155 #define kvh_pool req.kvu_pool 156 #define kvh_err rsp.kvu_err 157 } __packed; 158 159 struct hv_kvp_msg_val { 160 uint32_t kvm_valtype; 161 uint32_t kvm_keylen; 162 uint32_t kvm_vallen; 163 uint8_t kvm_key[HV_KVP_MAX_KEY_SIZE]; 164 uint8_t kvm_val[HV_KVP_MAX_VAL_SIZE]; 165 } __packed; 166 167 struct hv_kvp_msg_enum { 168 uint32_t kvm_index; 169 uint32_t kvm_valtype; 170 uint32_t kvm_keylen; 171 uint32_t kvm_vallen; 172 uint8_t kvm_key[HV_KVP_MAX_KEY_SIZE]; 173 uint8_t kvm_val[HV_KVP_MAX_VAL_SIZE]; 174 } __packed; 175 176 struct hv_kvp_msg_del { 177 uint32_t kvm_keylen; 178 uint8_t kvm_key[HV_KVP_MAX_KEY_SIZE]; 179 } __packed; 180 181 #define ADDR_FAMILY_NONE 0x00 182 #define ADDR_FAMILY_IPV4 0x01 183 #define ADDR_FAMILY_IPV6 0x02 184 185 #define MAX_MAC_ADDR_SIZE 256 186 #define MAX_IP_ADDR_SIZE 2048 187 #define MAX_GATEWAY_SIZE 1024 188 189 struct hv_kvp_msg_addr { 190 uint8_t kvm_mac[MAX_MAC_ADDR_SIZE]; 191 uint8_t kvm_family; 192 uint8_t kvm_dhcp; 193 uint8_t kvm_addr[MAX_IP_ADDR_SIZE]; 194 uint8_t kvm_netmask[MAX_IP_ADDR_SIZE]; 195 uint8_t kvm_gateway[MAX_GATEWAY_SIZE]; 196 uint8_t kvm_dns[MAX_IP_ADDR_SIZE]; 197 } __packed; 198 199 union hv_kvp_msg { 200 struct hv_kvp_msg_val kvm_val; 201 struct hv_kvp_msg_enum kvm_enum; 202 struct hv_kvp_msg_del kvm_del; 203 }; 204 205 struct vmbus_icmsg_kvp { 206 struct vmbus_icmsg_hdr ic_hdr; 207 union hv_kvp_hdr ic_kvh; 208 union hv_kvp_msg ic_kvm; 209 } __packed; 210 211 struct vmbus_icmsg_kvp_addr { 212 struct vmbus_icmsg_hdr ic_hdr; 213 struct { 214 struct { 215 uint8_t kvu_op; 216 uint8_t kvu_pool; 217 } req; 218 } ic_kvh; 219 struct hv_kvp_msg_addr ic_kvm; 220 } __packed; 221 222 #endif /* _DEV_PV_HYPERVIC_H_ */ 223