hyperv.h 11 KB

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