1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * Copyright (c) 2011, Microsoft Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 17 * Place - Suite 330, Boston, MA 02111-1307 USA. 18 * 19 * Authors: 20 * Haiyang Zhang <haiyangz@microsoft.com> 21 * Hank Janssen <hjanssen@microsoft.com> 22 * K. Y. Srinivasan <kys@microsoft.com> 23 * 24 */ 25 26 #ifndef _UAPI_HYPERV_H 27 #define _UAPI_HYPERV_H 28 29 #include <linux/types.h> 30 31 /* 32 * Framework version for util services. 33 */ 34 #define UTIL_FW_MINOR 0 35 36 #define UTIL_WS2K8_FW_MAJOR 1 37 #define UTIL_WS2K8_FW_VERSION (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR) 38 39 #define UTIL_FW_MAJOR 3 40 #define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR) 41 42 43 /* 44 * Implementation of host controlled snapshot of the guest. 45 */ 46 47 #define VSS_OP_REGISTER 128 48 49 /* 50 Daemon code with full handshake support. 51 */ 52 #define VSS_OP_REGISTER1 129 53 54 enum hv_vss_op { 55 VSS_OP_CREATE = 0, 56 VSS_OP_DELETE, 57 VSS_OP_HOT_BACKUP, 58 VSS_OP_GET_DM_INFO, 59 VSS_OP_BU_COMPLETE, 60 /* 61 * Following operations are only supported with IC version >= 5.0 62 */ 63 VSS_OP_FREEZE, /* Freeze the file systems in the VM */ 64 VSS_OP_THAW, /* Unfreeze the file systems */ 65 VSS_OP_AUTO_RECOVER, 66 VSS_OP_COUNT /* Number of operations, must be last */ 67 }; 68 69 70 /* 71 * Header for all VSS messages. 72 */ 73 struct hv_vss_hdr { 74 __u8 operation; 75 __u8 reserved[7]; 76 } __attribute__((packed)); 77 78 79 /* 80 * Flag values for the hv_vss_check_feature. Linux supports only 81 * one value. 82 */ 83 #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005 84 85 struct hv_vss_check_feature { 86 __u32 flags; 87 } __attribute__((packed)); 88 89 struct hv_vss_check_dm_info { 90 __u32 flags; 91 } __attribute__((packed)); 92 93 /* 94 * struct hv_vss_msg encodes the fields that the Linux VSS 95 * driver accesses. However, FREEZE messages from Hyper-V contain 96 * additional LUN information that Linux doesn't use and are not 97 * represented in struct hv_vss_msg. A received FREEZE message may 98 * be as large as 6,260 bytes, so the driver must allocate at least 99 * that much space, not sizeof(struct hv_vss_msg). Other messages 100 * such as AUTO_RECOVER may be as large as 12,500 bytes. However, 101 * because the Linux VSS driver responds that it doesn't support 102 * auto-recovery, it should not receive such messages. 103 */ 104 struct hv_vss_msg { 105 union { 106 struct hv_vss_hdr vss_hdr; 107 int error; 108 }; 109 union { 110 struct hv_vss_check_feature vss_cf; 111 struct hv_vss_check_dm_info dm_info; 112 }; 113 } __attribute__((packed)); 114 115 /* 116 * Implementation of a host to guest copy facility. 117 */ 118 119 #define FCOPY_VERSION_0 0 120 #define FCOPY_VERSION_1 1 121 #define FCOPY_CURRENT_VERSION FCOPY_VERSION_1 122 #define W_MAX_PATH 260 123 124 enum hv_fcopy_op { 125 START_FILE_COPY = 0, 126 WRITE_TO_FILE, 127 COMPLETE_FCOPY, 128 CANCEL_FCOPY, 129 }; 130 131 struct hv_fcopy_hdr { 132 __u32 operation; 133 __u8 service_id0[16]; /* currently unused */ 134 __u8 service_id1[16]; /* currently unused */ 135 } __attribute__((packed)); 136 137 #define OVER_WRITE 0x1 138 #define CREATE_PATH 0x2 139 140 struct hv_start_fcopy { 141 struct hv_fcopy_hdr hdr; 142 __u16 file_name[W_MAX_PATH]; 143 __u16 path_name[W_MAX_PATH]; 144 __u32 copy_flags; 145 __u64 file_size; 146 } __attribute__((packed)); 147 148 /* 149 * The file is chunked into fragments. 150 */ 151 #define DATA_FRAGMENT (6 * 1024) 152 153 struct hv_do_fcopy { 154 struct hv_fcopy_hdr hdr; 155 __u32 pad; 156 __u64 offset; 157 __u32 size; 158 __u8 data[DATA_FRAGMENT]; 159 } __attribute__((packed)); 160 161 /* 162 * An implementation of HyperV key value pair (KVP) functionality for Linux. 163 * 164 * 165 * Copyright (C) 2010, Novell, Inc. 166 * Author : K. Y. Srinivasan <ksrinivasan@novell.com> 167 * 168 */ 169 170 /* 171 * Maximum value size - used for both key names and value data, and includes 172 * any applicable NULL terminators. 173 * 174 * Note: This limit is somewhat arbitrary, but falls easily within what is 175 * supported for all native guests (back to Win 2000) and what is reasonable 176 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are 177 * limited to 255 character key names. 178 * 179 * MSDN recommends not storing data values larger than 2048 bytes in the 180 * registry. 181 * 182 * Note: This value is used in defining the KVP exchange message - this value 183 * cannot be modified without affecting the message size and compatibility. 184 */ 185 186 /* 187 * bytes, including any null terminators 188 */ 189 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048) 190 191 192 /* 193 * Maximum key size - the registry limit for the length of an entry name 194 * is 256 characters, including the null terminator 195 */ 196 197 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512) 198 199 /* 200 * In Linux, we implement the KVP functionality in two components: 201 * 1) The kernel component which is packaged as part of the hv_utils driver 202 * is responsible for communicating with the host and responsible for 203 * implementing the host/guest protocol. 2) A user level daemon that is 204 * responsible for data gathering. 205 * 206 * Host/Guest Protocol: The host iterates over an index and expects the guest 207 * to assign a key name to the index and also return the value corresponding to 208 * the key. The host will have atmost one KVP transaction outstanding at any 209 * given point in time. The host side iteration stops when the guest returns 210 * an error. Microsoft has specified the following mapping of key names to 211 * host specified index: 212 * 213 * Index Key Name 214 * 0 FullyQualifiedDomainName 215 * 1 IntegrationServicesVersion 216 * 2 NetworkAddressIPv4 217 * 3 NetworkAddressIPv6 218 * 4 OSBuildNumber 219 * 5 OSName 220 * 6 OSMajorVersion 221 * 7 OSMinorVersion 222 * 8 OSVersion 223 * 9 ProcessorArchitecture 224 * 225 * The Windows host expects the Key Name and Key Value to be encoded in utf16. 226 * 227 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the 228 * data gathering functionality in a user mode daemon. The user level daemon 229 * is also responsible for binding the key name to the index as well. The 230 * kernel and user-level daemon communicate using a connector channel. 231 * 232 * The user mode component first registers with the 233 * kernel component. Subsequently, the kernel component requests, data 234 * for the specified keys. In response to this message the user mode component 235 * fills in the value corresponding to the specified key. We overload the 236 * sequence field in the cn_msg header to define our KVP message types. 237 * 238 * 239 * The kernel component simply acts as a conduit for communication between the 240 * Windows host and the user-level daemon. The kernel component passes up the 241 * index received from the Host to the user-level daemon. If the index is 242 * valid (supported), the corresponding key as well as its 243 * value (both are strings) is returned. If the index is invalid 244 * (not supported), a NULL key string is returned. 245 */ 246 247 248 /* 249 * Registry value types. 250 */ 251 252 #define REG_SZ 1 253 #define REG_U32 4 254 #define REG_U64 8 255 256 /* 257 * As we look at expanding the KVP functionality to include 258 * IP injection functionality, we need to maintain binary 259 * compatibility with older daemons. 260 * 261 * The KVP opcodes are defined by the host and it was unfortunate 262 * that I chose to treat the registration operation as part of the 263 * KVP operations defined by the host. 264 * Here is the level of compatibility 265 * (between the user level daemon and the kernel KVP driver) that we 266 * will implement: 267 * 268 * An older daemon will always be supported on a newer driver. 269 * A given user level daemon will require a minimal version of the 270 * kernel driver. 271 * If we cannot handle the version differences, we will fail gracefully 272 * (this can happen when we have a user level daemon that is more 273 * advanced than the KVP driver. 274 * 275 * We will use values used in this handshake for determining if we have 276 * workable user level daemon and the kernel driver. We begin by taking the 277 * registration opcode out of the KVP opcode namespace. We will however, 278 * maintain compatibility with the existing user-level daemon code. 279 */ 280 281 /* 282 * Daemon code not supporting IP injection (legacy daemon). 283 */ 284 285 #define KVP_OP_REGISTER 4 286 287 /* 288 * Daemon code supporting IP injection. 289 * The KVP opcode field is used to communicate the 290 * registration information; so define a namespace that 291 * will be distinct from the host defined KVP opcode. 292 */ 293 294 #define KVP_OP_REGISTER1 100 295 296 enum hv_kvp_exchg_op { 297 KVP_OP_GET = 0, 298 KVP_OP_SET, 299 KVP_OP_DELETE, 300 KVP_OP_ENUMERATE, 301 KVP_OP_GET_IP_INFO, 302 KVP_OP_SET_IP_INFO, 303 KVP_OP_COUNT /* Number of operations, must be last. */ 304 }; 305 306 enum hv_kvp_exchg_pool { 307 KVP_POOL_EXTERNAL = 0, 308 KVP_POOL_GUEST, 309 KVP_POOL_AUTO, 310 KVP_POOL_AUTO_EXTERNAL, 311 KVP_POOL_AUTO_INTERNAL, 312 KVP_POOL_COUNT /* Number of pools, must be last. */ 313 }; 314 315 /* 316 * Some Hyper-V status codes. 317 */ 318 319 #define HV_S_OK 0x00000000 320 #define HV_E_FAIL 0x80004005 321 #define HV_S_CONT 0x80070103 322 #define HV_ERROR_NOT_SUPPORTED 0x80070032 323 #define HV_ERROR_MACHINE_LOCKED 0x800704F7 324 #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F 325 #define HV_INVALIDARG 0x80070057 326 #define HV_GUID_NOTFOUND 0x80041002 327 #define HV_ERROR_ALREADY_EXISTS 0x80070050 328 #define HV_ERROR_DISK_FULL 0x80070070 329 330 #define ADDR_FAMILY_NONE 0x00 331 #define ADDR_FAMILY_IPV4 0x01 332 #define ADDR_FAMILY_IPV6 0x02 333 334 #define MAX_ADAPTER_ID_SIZE 128 335 #define MAX_IP_ADDR_SIZE 1024 336 #define MAX_GATEWAY_SIZE 512 337 338 339 struct hv_kvp_ipaddr_value { 340 __u16 adapter_id[MAX_ADAPTER_ID_SIZE]; 341 __u8 addr_family; 342 __u8 dhcp_enabled; 343 __u16 ip_addr[MAX_IP_ADDR_SIZE]; 344 __u16 sub_net[MAX_IP_ADDR_SIZE]; 345 __u16 gate_way[MAX_GATEWAY_SIZE]; 346 __u16 dns_addr[MAX_IP_ADDR_SIZE]; 347 } __attribute__((packed)); 348 349 350 struct hv_kvp_hdr { 351 __u8 operation; 352 __u8 pool; 353 __u16 pad; 354 } __attribute__((packed)); 355 356 struct hv_kvp_exchg_msg_value { 357 __u32 value_type; 358 __u32 key_size; 359 __u32 value_size; 360 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; 361 union { 362 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; 363 __u32 value_u32; 364 __u64 value_u64; 365 }; 366 } __attribute__((packed)); 367 368 struct hv_kvp_msg_enumerate { 369 __u32 index; 370 struct hv_kvp_exchg_msg_value data; 371 } __attribute__((packed)); 372 373 struct hv_kvp_msg_get { 374 struct hv_kvp_exchg_msg_value data; 375 }; 376 377 struct hv_kvp_msg_set { 378 struct hv_kvp_exchg_msg_value data; 379 }; 380 381 struct hv_kvp_msg_delete { 382 __u32 key_size; 383 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; 384 }; 385 386 struct hv_kvp_register { 387 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; 388 }; 389 390 struct hv_kvp_msg { 391 union { 392 struct hv_kvp_hdr kvp_hdr; 393 int error; 394 }; 395 union { 396 struct hv_kvp_msg_get kvp_get; 397 struct hv_kvp_msg_set kvp_set; 398 struct hv_kvp_msg_delete kvp_delete; 399 struct hv_kvp_msg_enumerate kvp_enum_data; 400 struct hv_kvp_ipaddr_value kvp_ip_val; 401 struct hv_kvp_register kvp_register; 402 } body; 403 } __attribute__((packed)); 404 405 struct hv_kvp_ip_msg { 406 __u8 operation; 407 __u8 pool; 408 struct hv_kvp_ipaddr_value kvp_ip_val; 409 } __attribute__((packed)); 410 411 #endif /* _UAPI_HYPERV_H */ 412
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.