K. Y. Srinivasan | 5c47340 | 2011-05-12 19:34:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2011, Microsoft Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 16 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 17 | * |
| 18 | * Authors: |
| 19 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 20 | * Hank Janssen <hjanssen@microsoft.com> |
| 21 | * K. Y. Srinivasan <kys@microsoft.com> |
| 22 | * |
| 23 | */ |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 24 | |
| 25 | #ifndef _HYPERV_H |
| 26 | #define _HYPERV_H |
| 27 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 28 | #include <linux/types.h> |
| 29 | |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 30 | /* |
| 31 | * Framework version for util services. |
| 32 | */ |
K. Y. Srinivasan | 3a49160 | 2013-09-06 11:49:56 -0700 | [diff] [blame] | 33 | #define UTIL_FW_MINOR 0 |
| 34 | |
| 35 | #define UTIL_WS2K8_FW_MAJOR 1 |
| 36 | #define UTIL_WS2K8_FW_VERSION (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR) |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 37 | |
| 38 | #define UTIL_FW_MAJOR 3 |
K. Y. Srinivasan | 3a49160 | 2013-09-06 11:49:56 -0700 | [diff] [blame] | 39 | #define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR) |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 40 | |
K. Y. Srinivasan | 96dd86f | 2013-03-15 12:30:06 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Implementation of host controlled snapshot of the guest. |
| 44 | */ |
| 45 | |
| 46 | #define VSS_OP_REGISTER 128 |
| 47 | |
| 48 | enum hv_vss_op { |
| 49 | VSS_OP_CREATE = 0, |
| 50 | VSS_OP_DELETE, |
| 51 | VSS_OP_HOT_BACKUP, |
| 52 | VSS_OP_GET_DM_INFO, |
| 53 | VSS_OP_BU_COMPLETE, |
| 54 | /* |
| 55 | * Following operations are only supported with IC version >= 5.0 |
| 56 | */ |
| 57 | VSS_OP_FREEZE, /* Freeze the file systems in the VM */ |
| 58 | VSS_OP_THAW, /* Unfreeze the file systems */ |
| 59 | VSS_OP_AUTO_RECOVER, |
| 60 | VSS_OP_COUNT /* Number of operations, must be last */ |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | * Header for all VSS messages. |
| 66 | */ |
| 67 | struct hv_vss_hdr { |
| 68 | __u8 operation; |
| 69 | __u8 reserved[7]; |
| 70 | } __attribute__((packed)); |
| 71 | |
| 72 | |
| 73 | /* |
| 74 | * Flag values for the hv_vss_check_feature. Linux supports only |
| 75 | * one value. |
| 76 | */ |
| 77 | #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005 |
| 78 | |
| 79 | struct hv_vss_check_feature { |
| 80 | __u32 flags; |
| 81 | } __attribute__((packed)); |
| 82 | |
| 83 | struct hv_vss_check_dm_info { |
| 84 | __u32 flags; |
| 85 | } __attribute__((packed)); |
| 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 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 98 | /* |
| 99 | * An implementation of HyperV key value pair (KVP) functionality for Linux. |
| 100 | * |
| 101 | * |
| 102 | * Copyright (C) 2010, Novell, Inc. |
| 103 | * Author : K. Y. Srinivasan <ksrinivasan@novell.com> |
| 104 | * |
| 105 | */ |
| 106 | |
| 107 | /* |
| 108 | * Maximum value size - used for both key names and value data, and includes |
| 109 | * any applicable NULL terminators. |
| 110 | * |
| 111 | * Note: This limit is somewhat arbitrary, but falls easily within what is |
| 112 | * supported for all native guests (back to Win 2000) and what is reasonable |
| 113 | * for the IC KVP exchange functionality. Note that Windows Me/98/95 are |
| 114 | * limited to 255 character key names. |
| 115 | * |
| 116 | * MSDN recommends not storing data values larger than 2048 bytes in the |
| 117 | * registry. |
| 118 | * |
| 119 | * Note: This value is used in defining the KVP exchange message - this value |
| 120 | * cannot be modified without affecting the message size and compatibility. |
| 121 | */ |
| 122 | |
| 123 | /* |
| 124 | * bytes, including any null terminators |
| 125 | */ |
| 126 | #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048) |
| 127 | |
| 128 | |
| 129 | /* |
| 130 | * Maximum key size - the registry limit for the length of an entry name |
| 131 | * is 256 characters, including the null terminator |
| 132 | */ |
| 133 | |
| 134 | #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512) |
| 135 | |
| 136 | /* |
| 137 | * In Linux, we implement the KVP functionality in two components: |
| 138 | * 1) The kernel component which is packaged as part of the hv_utils driver |
| 139 | * is responsible for communicating with the host and responsible for |
| 140 | * implementing the host/guest protocol. 2) A user level daemon that is |
| 141 | * responsible for data gathering. |
| 142 | * |
| 143 | * Host/Guest Protocol: The host iterates over an index and expects the guest |
| 144 | * to assign a key name to the index and also return the value corresponding to |
| 145 | * the key. The host will have atmost one KVP transaction outstanding at any |
| 146 | * given point in time. The host side iteration stops when the guest returns |
| 147 | * an error. Microsoft has specified the following mapping of key names to |
| 148 | * host specified index: |
| 149 | * |
| 150 | * Index Key Name |
| 151 | * 0 FullyQualifiedDomainName |
| 152 | * 1 IntegrationServicesVersion |
| 153 | * 2 NetworkAddressIPv4 |
| 154 | * 3 NetworkAddressIPv6 |
| 155 | * 4 OSBuildNumber |
| 156 | * 5 OSName |
| 157 | * 6 OSMajorVersion |
| 158 | * 7 OSMinorVersion |
| 159 | * 8 OSVersion |
| 160 | * 9 ProcessorArchitecture |
| 161 | * |
| 162 | * The Windows host expects the Key Name and Key Value to be encoded in utf16. |
| 163 | * |
| 164 | * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the |
| 165 | * data gathering functionality in a user mode daemon. The user level daemon |
| 166 | * is also responsible for binding the key name to the index as well. The |
| 167 | * kernel and user-level daemon communicate using a connector channel. |
| 168 | * |
| 169 | * The user mode component first registers with the |
| 170 | * the kernel component. Subsequently, the kernel component requests, data |
| 171 | * for the specified keys. In response to this message the user mode component |
| 172 | * fills in the value corresponding to the specified key. We overload the |
| 173 | * sequence field in the cn_msg header to define our KVP message types. |
| 174 | * |
| 175 | * |
| 176 | * The kernel component simply acts as a conduit for communication between the |
| 177 | * Windows host and the user-level daemon. The kernel component passes up the |
| 178 | * index received from the Host to the user-level daemon. If the index is |
| 179 | * valid (supported), the corresponding key as well as its |
| 180 | * value (both are strings) is returned. If the index is invalid |
| 181 | * (not supported), a NULL key string is returned. |
| 182 | */ |
| 183 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Registry value types. |
| 187 | */ |
| 188 | |
| 189 | #define REG_SZ 1 |
K. Y. Srinivasan | fa3d5b8 | 2012-03-16 08:02:25 -0700 | [diff] [blame] | 190 | #define REG_U32 4 |
| 191 | #define REG_U64 8 |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 192 | |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 193 | /* |
| 194 | * As we look at expanding the KVP functionality to include |
| 195 | * IP injection functionality, we need to maintain binary |
| 196 | * compatibility with older daemons. |
| 197 | * |
| 198 | * The KVP opcodes are defined by the host and it was unfortunate |
| 199 | * that I chose to treat the registration operation as part of the |
| 200 | * KVP operations defined by the host. |
| 201 | * Here is the level of compatibility |
| 202 | * (between the user level daemon and the kernel KVP driver) that we |
| 203 | * will implement: |
| 204 | * |
| 205 | * An older daemon will always be supported on a newer driver. |
| 206 | * A given user level daemon will require a minimal version of the |
| 207 | * kernel driver. |
| 208 | * If we cannot handle the version differences, we will fail gracefully |
| 209 | * (this can happen when we have a user level daemon that is more |
| 210 | * advanced than the KVP driver. |
| 211 | * |
| 212 | * We will use values used in this handshake for determining if we have |
| 213 | * workable user level daemon and the kernel driver. We begin by taking the |
| 214 | * registration opcode out of the KVP opcode namespace. We will however, |
| 215 | * maintain compatibility with the existing user-level daemon code. |
| 216 | */ |
| 217 | |
| 218 | /* |
| 219 | * Daemon code not supporting IP injection (legacy daemon). |
| 220 | */ |
| 221 | |
| 222 | #define KVP_OP_REGISTER 4 |
| 223 | |
| 224 | /* |
| 225 | * Daemon code supporting IP injection. |
| 226 | * The KVP opcode field is used to communicate the |
| 227 | * registration information; so define a namespace that |
| 228 | * will be distinct from the host defined KVP opcode. |
| 229 | */ |
| 230 | |
| 231 | #define KVP_OP_REGISTER1 100 |
| 232 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 233 | enum hv_kvp_exchg_op { |
| 234 | KVP_OP_GET = 0, |
| 235 | KVP_OP_SET, |
| 236 | KVP_OP_DELETE, |
| 237 | KVP_OP_ENUMERATE, |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 238 | KVP_OP_GET_IP_INFO, |
| 239 | KVP_OP_SET_IP_INFO, |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 240 | KVP_OP_COUNT /* Number of operations, must be last. */ |
| 241 | }; |
| 242 | |
| 243 | enum hv_kvp_exchg_pool { |
| 244 | KVP_POOL_EXTERNAL = 0, |
| 245 | KVP_POOL_GUEST, |
| 246 | KVP_POOL_AUTO, |
| 247 | KVP_POOL_AUTO_EXTERNAL, |
| 248 | KVP_POOL_AUTO_INTERNAL, |
| 249 | KVP_POOL_COUNT /* Number of pools, must be last. */ |
| 250 | }; |
| 251 | |
K. Y. Srinivasan | b47a81d | 2012-08-13 10:06:52 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Some Hyper-V status codes. |
| 254 | */ |
| 255 | |
| 256 | #define HV_S_OK 0x00000000 |
| 257 | #define HV_E_FAIL 0x80004005 |
| 258 | #define HV_S_CONT 0x80070103 |
| 259 | #define HV_ERROR_NOT_SUPPORTED 0x80070032 |
| 260 | #define HV_ERROR_MACHINE_LOCKED 0x800704F7 |
| 261 | #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F |
K. Y. Srinivasan | 32061b4 | 2012-09-05 13:50:13 -0700 | [diff] [blame] | 262 | #define HV_INVALIDARG 0x80070057 |
| 263 | #define HV_GUID_NOTFOUND 0x80041002 |
K. Y. Srinivasan | b47a81d | 2012-08-13 10:06:52 -0700 | [diff] [blame] | 264 | |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 265 | #define ADDR_FAMILY_NONE 0x00 |
| 266 | #define ADDR_FAMILY_IPV4 0x01 |
| 267 | #define ADDR_FAMILY_IPV6 0x02 |
| 268 | |
| 269 | #define MAX_ADAPTER_ID_SIZE 128 |
| 270 | #define MAX_IP_ADDR_SIZE 1024 |
| 271 | #define MAX_GATEWAY_SIZE 512 |
| 272 | |
| 273 | |
| 274 | struct hv_kvp_ipaddr_value { |
| 275 | __u16 adapter_id[MAX_ADAPTER_ID_SIZE]; |
| 276 | __u8 addr_family; |
| 277 | __u8 dhcp_enabled; |
| 278 | __u16 ip_addr[MAX_IP_ADDR_SIZE]; |
| 279 | __u16 sub_net[MAX_IP_ADDR_SIZE]; |
| 280 | __u16 gate_way[MAX_GATEWAY_SIZE]; |
| 281 | __u16 dns_addr[MAX_IP_ADDR_SIZE]; |
| 282 | } __attribute__((packed)); |
| 283 | |
| 284 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 285 | struct hv_kvp_hdr { |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 286 | __u8 operation; |
| 287 | __u8 pool; |
| 288 | __u16 pad; |
| 289 | } __attribute__((packed)); |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 290 | |
| 291 | struct hv_kvp_exchg_msg_value { |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 292 | __u32 value_type; |
| 293 | __u32 key_size; |
| 294 | __u32 value_size; |
| 295 | __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; |
K. Y. Srinivasan | e485ceac | 2012-03-10 15:32:08 -0800 | [diff] [blame] | 296 | union { |
| 297 | __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; |
| 298 | __u32 value_u32; |
| 299 | __u64 value_u64; |
| 300 | }; |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 301 | } __attribute__((packed)); |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 302 | |
| 303 | struct hv_kvp_msg_enumerate { |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 304 | __u32 index; |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 305 | struct hv_kvp_exchg_msg_value data; |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 306 | } __attribute__((packed)); |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 307 | |
K. Y. Srinivasan | e485ceac | 2012-03-10 15:32:08 -0800 | [diff] [blame] | 308 | struct hv_kvp_msg_get { |
| 309 | struct hv_kvp_exchg_msg_value data; |
| 310 | }; |
| 311 | |
| 312 | struct hv_kvp_msg_set { |
| 313 | struct hv_kvp_exchg_msg_value data; |
| 314 | }; |
| 315 | |
| 316 | struct hv_kvp_msg_delete { |
| 317 | __u32 key_size; |
| 318 | __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; |
| 319 | }; |
| 320 | |
| 321 | struct hv_kvp_register { |
| 322 | __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; |
| 323 | }; |
| 324 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 325 | struct hv_kvp_msg { |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 326 | union { |
| 327 | struct hv_kvp_hdr kvp_hdr; |
| 328 | int error; |
| 329 | }; |
K. Y. Srinivasan | 264033543 | 2012-02-02 16:56:50 -0800 | [diff] [blame] | 330 | union { |
K. Y. Srinivasan | e485ceac | 2012-03-10 15:32:08 -0800 | [diff] [blame] | 331 | struct hv_kvp_msg_get kvp_get; |
| 332 | struct hv_kvp_msg_set kvp_set; |
| 333 | struct hv_kvp_msg_delete kvp_delete; |
| 334 | struct hv_kvp_msg_enumerate kvp_enum_data; |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 335 | struct hv_kvp_ipaddr_value kvp_ip_val; |
K. Y. Srinivasan | e485ceac | 2012-03-10 15:32:08 -0800 | [diff] [blame] | 336 | struct hv_kvp_register kvp_register; |
K. Y. Srinivasan | 264033543 | 2012-02-02 16:56:50 -0800 | [diff] [blame] | 337 | } body; |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 338 | } __attribute__((packed)); |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 339 | |
K. Y. Srinivasan | 9b59578 | 2012-08-13 10:06:51 -0700 | [diff] [blame] | 340 | struct hv_kvp_ip_msg { |
| 341 | __u8 operation; |
| 342 | __u8 pool; |
| 343 | struct hv_kvp_ipaddr_value kvp_ip_val; |
| 344 | } __attribute__((packed)); |
| 345 | |
K. Y. Srinivasan | 59a084a | 2012-02-02 16:56:48 -0800 | [diff] [blame] | 346 | #ifdef __KERNEL__ |
K. Y. Srinivasan | 8ff3e6f | 2011-05-12 19:34:27 -0700 | [diff] [blame] | 347 | #include <linux/scatterlist.h> |
| 348 | #include <linux/list.h> |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 349 | #include <linux/uuid.h> |
K. Y. Srinivasan | 8ff3e6f | 2011-05-12 19:34:27 -0700 | [diff] [blame] | 350 | #include <linux/timer.h> |
| 351 | #include <linux/workqueue.h> |
| 352 | #include <linux/completion.h> |
| 353 | #include <linux/device.h> |
K. Y. Srinivasan | 2e2c1d1 | 2011-08-25 09:48:31 -0700 | [diff] [blame] | 354 | #include <linux/mod_devicetable.h> |
K. Y. Srinivasan | 8ff3e6f | 2011-05-12 19:34:27 -0700 | [diff] [blame] | 355 | |
| 356 | |
Haiyang Zhang | c31c151 | 2012-02-02 07:18:00 +0000 | [diff] [blame] | 357 | #define MAX_PAGE_BUFFER_COUNT 19 |
K. Y. Srinivasan | a363bf7 | 2011-05-12 19:34:16 -0700 | [diff] [blame] | 358 | #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */ |
| 359 | |
| 360 | #pragma pack(push, 1) |
| 361 | |
| 362 | /* Single-page buffer */ |
| 363 | struct hv_page_buffer { |
| 364 | u32 len; |
| 365 | u32 offset; |
| 366 | u64 pfn; |
| 367 | }; |
| 368 | |
| 369 | /* Multiple-page buffer */ |
| 370 | struct hv_multipage_buffer { |
| 371 | /* Length and Offset determines the # of pfns in the array */ |
| 372 | u32 len; |
| 373 | u32 offset; |
| 374 | u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT]; |
| 375 | }; |
| 376 | |
| 377 | /* 0x18 includes the proprietary packet header */ |
| 378 | #define MAX_PAGE_BUFFER_PACKET (0x18 + \ |
| 379 | (sizeof(struct hv_page_buffer) * \ |
| 380 | MAX_PAGE_BUFFER_COUNT)) |
| 381 | #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \ |
| 382 | sizeof(struct hv_multipage_buffer)) |
| 383 | |
| 384 | |
| 385 | #pragma pack(pop) |
| 386 | |
K. Y. Srinivasan | 7effffb | 2011-05-12 19:34:17 -0700 | [diff] [blame] | 387 | struct hv_ring_buffer { |
| 388 | /* Offset in bytes from the start of ring data below */ |
| 389 | u32 write_index; |
| 390 | |
| 391 | /* Offset in bytes from the start of ring data below */ |
| 392 | u32 read_index; |
| 393 | |
| 394 | u32 interrupt_mask; |
| 395 | |
K. Y. Srinivasan | 2416603 | 2012-12-01 06:46:39 -0800 | [diff] [blame] | 396 | /* |
| 397 | * Win8 uses some of the reserved bits to implement |
| 398 | * interrupt driven flow management. On the send side |
| 399 | * we can request that the receiver interrupt the sender |
| 400 | * when the ring transitions from being full to being able |
| 401 | * to handle a message of size "pending_send_sz". |
| 402 | * |
| 403 | * Add necessary state for this enhancement. |
K. Y. Srinivasan | 7effffb | 2011-05-12 19:34:17 -0700 | [diff] [blame] | 404 | */ |
K. Y. Srinivasan | 2416603 | 2012-12-01 06:46:39 -0800 | [diff] [blame] | 405 | u32 pending_send_sz; |
| 406 | |
| 407 | u32 reserved1[12]; |
| 408 | |
| 409 | union { |
| 410 | struct { |
| 411 | u32 feat_pending_send_sz:1; |
| 412 | }; |
| 413 | u32 value; |
| 414 | } feature_bits; |
| 415 | |
| 416 | /* Pad it to PAGE_SIZE so that data starts on page boundary */ |
| 417 | u8 reserved2[4028]; |
K. Y. Srinivasan | 7effffb | 2011-05-12 19:34:17 -0700 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * Ring data starts here + RingDataStartOffset |
| 421 | * !!! DO NOT place any fields below this !!! |
| 422 | */ |
| 423 | u8 buffer[0]; |
| 424 | } __packed; |
| 425 | |
| 426 | struct hv_ring_buffer_info { |
| 427 | struct hv_ring_buffer *ring_buffer; |
| 428 | u32 ring_size; /* Include the shared header */ |
| 429 | spinlock_t ring_lock; |
| 430 | |
| 431 | u32 ring_datasize; /* < ring_size */ |
| 432 | u32 ring_data_startoffset; |
| 433 | }; |
| 434 | |
Haiyang Zhang | 33be96e | 2012-03-27 13:20:45 +0000 | [diff] [blame] | 435 | /* |
| 436 | * |
| 437 | * hv_get_ringbuffer_availbytes() |
| 438 | * |
| 439 | * Get number of bytes available to read and to write to |
| 440 | * for the specified ring buffer |
| 441 | */ |
| 442 | static inline void |
| 443 | hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi, |
| 444 | u32 *read, u32 *write) |
| 445 | { |
| 446 | u32 read_loc, write_loc, dsize; |
| 447 | |
| 448 | smp_read_barrier_depends(); |
| 449 | |
| 450 | /* Capture the read/write indices before they changed */ |
| 451 | read_loc = rbi->ring_buffer->read_index; |
| 452 | write_loc = rbi->ring_buffer->write_index; |
| 453 | dsize = rbi->ring_datasize; |
| 454 | |
| 455 | *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) : |
| 456 | read_loc - write_loc; |
| 457 | *read = dsize - *write; |
| 458 | } |
| 459 | |
K. Y. Srinivasan | eafa707 | 2012-12-01 06:46:44 -0800 | [diff] [blame] | 460 | /* |
| 461 | * VMBUS version is 32 bit entity broken up into |
| 462 | * two 16 bit quantities: major_number. minor_number. |
| 463 | * |
| 464 | * 0 . 13 (Windows Server 2008) |
| 465 | * 1 . 1 (Windows 7) |
| 466 | * 2 . 4 (Windows 8) |
| 467 | */ |
| 468 | |
| 469 | #define VERSION_WS2008 ((0 << 16) | (13)) |
| 470 | #define VERSION_WIN7 ((1 << 16) | (1)) |
| 471 | #define VERSION_WIN8 ((2 << 16) | (4)) |
| 472 | |
| 473 | #define VERSION_INVAL -1 |
| 474 | |
K. Y. Srinivasan | 2a5c43a | 2012-12-01 06:46:56 -0800 | [diff] [blame] | 475 | #define VERSION_CURRENT VERSION_WIN8 |
K. Y. Srinivasan | f7c6dfd | 2011-05-12 19:34:18 -0700 | [diff] [blame] | 476 | |
K. Y. Srinivasan | 517d8dc | 2011-05-12 19:34:19 -0700 | [diff] [blame] | 477 | /* Make maximum size of pipe payload of 16K */ |
| 478 | #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) |
| 479 | |
| 480 | /* Define PipeMode values. */ |
| 481 | #define VMBUS_PIPE_TYPE_BYTE 0x00000000 |
| 482 | #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004 |
| 483 | |
| 484 | /* The size of the user defined data buffer for non-pipe offers. */ |
| 485 | #define MAX_USER_DEFINED_BYTES 120 |
| 486 | |
| 487 | /* The size of the user defined data buffer for pipe offers. */ |
| 488 | #define MAX_PIPE_USER_DEFINED_BYTES 116 |
| 489 | |
| 490 | /* |
| 491 | * At the center of the Channel Management library is the Channel Offer. This |
| 492 | * struct contains the fundamental information about an offer. |
| 493 | */ |
| 494 | struct vmbus_channel_offer { |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 495 | uuid_le if_type; |
| 496 | uuid_le if_instance; |
K. Y. Srinivasan | 29423b7 | 2012-12-01 06:46:40 -0800 | [diff] [blame] | 497 | |
| 498 | /* |
| 499 | * These two fields are not currently used. |
| 500 | */ |
| 501 | u64 reserved1; |
| 502 | u64 reserved2; |
| 503 | |
K. Y. Srinivasan | 517d8dc | 2011-05-12 19:34:19 -0700 | [diff] [blame] | 504 | u16 chn_flags; |
| 505 | u16 mmio_megabytes; /* in bytes * 1024 * 1024 */ |
| 506 | |
| 507 | union { |
| 508 | /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */ |
| 509 | struct { |
| 510 | unsigned char user_def[MAX_USER_DEFINED_BYTES]; |
| 511 | } std; |
| 512 | |
| 513 | /* |
| 514 | * Pipes: |
| 515 | * The following sructure is an integrated pipe protocol, which |
| 516 | * is implemented on top of standard user-defined data. Pipe |
| 517 | * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own |
| 518 | * use. |
| 519 | */ |
| 520 | struct { |
| 521 | u32 pipe_mode; |
| 522 | unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES]; |
| 523 | } pipe; |
| 524 | } u; |
K. Y. Srinivasan | 29423b7 | 2012-12-01 06:46:40 -0800 | [diff] [blame] | 525 | /* |
| 526 | * The sub_channel_index is defined in win8. |
| 527 | */ |
| 528 | u16 sub_channel_index; |
| 529 | u16 reserved3; |
K. Y. Srinivasan | 517d8dc | 2011-05-12 19:34:19 -0700 | [diff] [blame] | 530 | } __packed; |
| 531 | |
| 532 | /* Server Flags */ |
| 533 | #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1 |
| 534 | #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2 |
| 535 | #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4 |
| 536 | #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10 |
| 537 | #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100 |
| 538 | #define VMBUS_CHANNEL_PARENT_OFFER 0x200 |
| 539 | #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400 |
| 540 | |
K. Y. Srinivasan | 50ed40e | 2011-05-12 19:34:20 -0700 | [diff] [blame] | 541 | struct vmpacket_descriptor { |
| 542 | u16 type; |
| 543 | u16 offset8; |
| 544 | u16 len8; |
| 545 | u16 flags; |
| 546 | u64 trans_id; |
| 547 | } __packed; |
| 548 | |
| 549 | struct vmpacket_header { |
| 550 | u32 prev_pkt_start_offset; |
| 551 | struct vmpacket_descriptor descriptor; |
| 552 | } __packed; |
| 553 | |
| 554 | struct vmtransfer_page_range { |
| 555 | u32 byte_count; |
| 556 | u32 byte_offset; |
| 557 | } __packed; |
| 558 | |
| 559 | struct vmtransfer_page_packet_header { |
| 560 | struct vmpacket_descriptor d; |
| 561 | u16 xfer_pageset_id; |
K. Y. Srinivasan | 1508d81 | 2012-08-16 08:23:20 -0700 | [diff] [blame] | 562 | u8 sender_owns_set; |
K. Y. Srinivasan | 50ed40e | 2011-05-12 19:34:20 -0700 | [diff] [blame] | 563 | u8 reserved; |
| 564 | u32 range_cnt; |
| 565 | struct vmtransfer_page_range ranges[1]; |
| 566 | } __packed; |
| 567 | |
| 568 | struct vmgpadl_packet_header { |
| 569 | struct vmpacket_descriptor d; |
| 570 | u32 gpadl; |
| 571 | u32 reserved; |
| 572 | } __packed; |
| 573 | |
| 574 | struct vmadd_remove_transfer_page_set { |
| 575 | struct vmpacket_descriptor d; |
| 576 | u32 gpadl; |
| 577 | u16 xfer_pageset_id; |
| 578 | u16 reserved; |
| 579 | } __packed; |
| 580 | |
| 581 | /* |
| 582 | * This structure defines a range in guest physical space that can be made to |
| 583 | * look virtually contiguous. |
| 584 | */ |
| 585 | struct gpa_range { |
| 586 | u32 byte_count; |
| 587 | u32 byte_offset; |
| 588 | u64 pfn_array[0]; |
| 589 | }; |
| 590 | |
| 591 | /* |
| 592 | * This is the format for an Establish Gpadl packet, which contains a handle by |
| 593 | * which this GPADL will be known and a set of GPA ranges associated with it. |
| 594 | * This can be converted to a MDL by the guest OS. If there are multiple GPA |
| 595 | * ranges, then the resulting MDL will be "chained," representing multiple VA |
| 596 | * ranges. |
| 597 | */ |
| 598 | struct vmestablish_gpadl { |
| 599 | struct vmpacket_descriptor d; |
| 600 | u32 gpadl; |
| 601 | u32 range_cnt; |
| 602 | struct gpa_range range[1]; |
| 603 | } __packed; |
| 604 | |
| 605 | /* |
| 606 | * This is the format for a Teardown Gpadl packet, which indicates that the |
| 607 | * GPADL handle in the Establish Gpadl packet will never be referenced again. |
| 608 | */ |
| 609 | struct vmteardown_gpadl { |
| 610 | struct vmpacket_descriptor d; |
| 611 | u32 gpadl; |
| 612 | u32 reserved; /* for alignment to a 8-byte boundary */ |
| 613 | } __packed; |
| 614 | |
| 615 | /* |
| 616 | * This is the format for a GPA-Direct packet, which contains a set of GPA |
| 617 | * ranges, in addition to commands and/or data. |
| 618 | */ |
| 619 | struct vmdata_gpa_direct { |
| 620 | struct vmpacket_descriptor d; |
| 621 | u32 reserved; |
| 622 | u32 range_cnt; |
| 623 | struct gpa_range range[1]; |
| 624 | } __packed; |
| 625 | |
| 626 | /* This is the format for a Additional Data Packet. */ |
| 627 | struct vmadditional_data { |
| 628 | struct vmpacket_descriptor d; |
| 629 | u64 total_bytes; |
| 630 | u32 offset; |
| 631 | u32 byte_cnt; |
| 632 | unsigned char data[1]; |
| 633 | } __packed; |
| 634 | |
| 635 | union vmpacket_largest_possible_header { |
| 636 | struct vmpacket_descriptor simple_hdr; |
| 637 | struct vmtransfer_page_packet_header xfer_page_hdr; |
| 638 | struct vmgpadl_packet_header gpadl_hdr; |
| 639 | struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr; |
| 640 | struct vmestablish_gpadl establish_gpadl_hdr; |
| 641 | struct vmteardown_gpadl teardown_gpadl_hdr; |
| 642 | struct vmdata_gpa_direct data_gpa_direct_hdr; |
| 643 | }; |
| 644 | |
| 645 | #define VMPACKET_DATA_START_ADDRESS(__packet) \ |
| 646 | (void *)(((unsigned char *)__packet) + \ |
| 647 | ((struct vmpacket_descriptor)__packet)->offset8 * 8) |
| 648 | |
| 649 | #define VMPACKET_DATA_LENGTH(__packet) \ |
| 650 | ((((struct vmpacket_descriptor)__packet)->len8 - \ |
| 651 | ((struct vmpacket_descriptor)__packet)->offset8) * 8) |
| 652 | |
| 653 | #define VMPACKET_TRANSFER_MODE(__packet) \ |
| 654 | (((struct IMPACT)__packet)->type) |
| 655 | |
| 656 | enum vmbus_packet_type { |
| 657 | VM_PKT_INVALID = 0x0, |
| 658 | VM_PKT_SYNCH = 0x1, |
| 659 | VM_PKT_ADD_XFER_PAGESET = 0x2, |
| 660 | VM_PKT_RM_XFER_PAGESET = 0x3, |
| 661 | VM_PKT_ESTABLISH_GPADL = 0x4, |
| 662 | VM_PKT_TEARDOWN_GPADL = 0x5, |
| 663 | VM_PKT_DATA_INBAND = 0x6, |
| 664 | VM_PKT_DATA_USING_XFER_PAGES = 0x7, |
| 665 | VM_PKT_DATA_USING_GPADL = 0x8, |
| 666 | VM_PKT_DATA_USING_GPA_DIRECT = 0x9, |
| 667 | VM_PKT_CANCEL_REQUEST = 0xa, |
| 668 | VM_PKT_COMP = 0xb, |
| 669 | VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc, |
| 670 | VM_PKT_ADDITIONAL_DATA = 0xd |
| 671 | }; |
| 672 | |
| 673 | #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1 |
K. Y. Srinivasan | 517d8dc | 2011-05-12 19:34:19 -0700 | [diff] [blame] | 674 | |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 675 | |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 676 | /* Version 1 messages */ |
| 677 | enum vmbus_channel_message_type { |
| 678 | CHANNELMSG_INVALID = 0, |
| 679 | CHANNELMSG_OFFERCHANNEL = 1, |
| 680 | CHANNELMSG_RESCIND_CHANNELOFFER = 2, |
| 681 | CHANNELMSG_REQUESTOFFERS = 3, |
| 682 | CHANNELMSG_ALLOFFERS_DELIVERED = 4, |
| 683 | CHANNELMSG_OPENCHANNEL = 5, |
| 684 | CHANNELMSG_OPENCHANNEL_RESULT = 6, |
| 685 | CHANNELMSG_CLOSECHANNEL = 7, |
| 686 | CHANNELMSG_GPADL_HEADER = 8, |
| 687 | CHANNELMSG_GPADL_BODY = 9, |
| 688 | CHANNELMSG_GPADL_CREATED = 10, |
| 689 | CHANNELMSG_GPADL_TEARDOWN = 11, |
| 690 | CHANNELMSG_GPADL_TORNDOWN = 12, |
| 691 | CHANNELMSG_RELID_RELEASED = 13, |
| 692 | CHANNELMSG_INITIATE_CONTACT = 14, |
| 693 | CHANNELMSG_VERSION_RESPONSE = 15, |
| 694 | CHANNELMSG_UNLOAD = 16, |
| 695 | #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD |
| 696 | CHANNELMSG_VIEWRANGE_ADD = 17, |
| 697 | CHANNELMSG_VIEWRANGE_REMOVE = 18, |
| 698 | #endif |
| 699 | CHANNELMSG_COUNT |
| 700 | }; |
| 701 | |
| 702 | struct vmbus_channel_message_header { |
| 703 | enum vmbus_channel_message_type msgtype; |
| 704 | u32 padding; |
| 705 | } __packed; |
| 706 | |
| 707 | /* Query VMBus Version parameters */ |
| 708 | struct vmbus_channel_query_vmbus_version { |
| 709 | struct vmbus_channel_message_header header; |
| 710 | u32 version; |
| 711 | } __packed; |
| 712 | |
| 713 | /* VMBus Version Supported parameters */ |
| 714 | struct vmbus_channel_version_supported { |
| 715 | struct vmbus_channel_message_header header; |
K. Y. Srinivasan | 1508d81 | 2012-08-16 08:23:20 -0700 | [diff] [blame] | 716 | u8 version_supported; |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 717 | } __packed; |
| 718 | |
| 719 | /* Offer Channel parameters */ |
| 720 | struct vmbus_channel_offer_channel { |
| 721 | struct vmbus_channel_message_header header; |
| 722 | struct vmbus_channel_offer offer; |
| 723 | u32 child_relid; |
| 724 | u8 monitorid; |
K. Y. Srinivasan | 29423b7 | 2012-12-01 06:46:40 -0800 | [diff] [blame] | 725 | /* |
| 726 | * win7 and beyond splits this field into a bit field. |
| 727 | */ |
| 728 | u8 monitor_allocated:1; |
| 729 | u8 reserved:7; |
| 730 | /* |
| 731 | * These are new fields added in win7 and later. |
| 732 | * Do not access these fields without checking the |
| 733 | * negotiated protocol. |
| 734 | * |
| 735 | * If "is_dedicated_interrupt" is set, we must not set the |
| 736 | * associated bit in the channel bitmap while sending the |
| 737 | * interrupt to the host. |
| 738 | * |
| 739 | * connection_id is to be used in signaling the host. |
| 740 | */ |
| 741 | u16 is_dedicated_interrupt:1; |
| 742 | u16 reserved1:15; |
| 743 | u32 connection_id; |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 744 | } __packed; |
| 745 | |
| 746 | /* Rescind Offer parameters */ |
| 747 | struct vmbus_channel_rescind_offer { |
| 748 | struct vmbus_channel_message_header header; |
| 749 | u32 child_relid; |
| 750 | } __packed; |
| 751 | |
| 752 | /* |
| 753 | * Request Offer -- no parameters, SynIC message contains the partition ID |
| 754 | * Set Snoop -- no parameters, SynIC message contains the partition ID |
| 755 | * Clear Snoop -- no parameters, SynIC message contains the partition ID |
| 756 | * All Offers Delivered -- no parameters, SynIC message contains the partition |
| 757 | * ID |
| 758 | * Flush Client -- no parameters, SynIC message contains the partition ID |
| 759 | */ |
| 760 | |
| 761 | /* Open Channel parameters */ |
| 762 | struct vmbus_channel_open_channel { |
| 763 | struct vmbus_channel_message_header header; |
| 764 | |
| 765 | /* Identifies the specific VMBus channel that is being opened. */ |
| 766 | u32 child_relid; |
| 767 | |
| 768 | /* ID making a particular open request at a channel offer unique. */ |
| 769 | u32 openid; |
| 770 | |
| 771 | /* GPADL for the channel's ring buffer. */ |
| 772 | u32 ringbuffer_gpadlhandle; |
| 773 | |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 774 | /* |
| 775 | * Starting with win8, this field will be used to specify |
| 776 | * the target virtual processor on which to deliver the interrupt for |
| 777 | * the host to guest communication. |
| 778 | * Prior to win8, incoming channel interrupts would only |
| 779 | * be delivered on cpu 0. Setting this value to 0 would |
| 780 | * preserve the earlier behavior. |
| 781 | */ |
| 782 | u32 target_vp; |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * The upstream ring buffer begins at offset zero in the memory |
| 786 | * described by RingBufferGpadlHandle. The downstream ring buffer |
| 787 | * follows it at this offset (in pages). |
| 788 | */ |
| 789 | u32 downstream_ringbuffer_pageoffset; |
| 790 | |
| 791 | /* User-specific data to be passed along to the server endpoint. */ |
| 792 | unsigned char userdata[MAX_USER_DEFINED_BYTES]; |
| 793 | } __packed; |
| 794 | |
| 795 | /* Open Channel Result parameters */ |
| 796 | struct vmbus_channel_open_result { |
| 797 | struct vmbus_channel_message_header header; |
| 798 | u32 child_relid; |
| 799 | u32 openid; |
| 800 | u32 status; |
| 801 | } __packed; |
| 802 | |
| 803 | /* Close channel parameters; */ |
| 804 | struct vmbus_channel_close_channel { |
| 805 | struct vmbus_channel_message_header header; |
| 806 | u32 child_relid; |
| 807 | } __packed; |
| 808 | |
| 809 | /* Channel Message GPADL */ |
| 810 | #define GPADL_TYPE_RING_BUFFER 1 |
| 811 | #define GPADL_TYPE_SERVER_SAVE_AREA 2 |
| 812 | #define GPADL_TYPE_TRANSACTION 8 |
| 813 | |
| 814 | /* |
| 815 | * The number of PFNs in a GPADL message is defined by the number of |
| 816 | * pages that would be spanned by ByteCount and ByteOffset. If the |
| 817 | * implied number of PFNs won't fit in this packet, there will be a |
| 818 | * follow-up packet that contains more. |
| 819 | */ |
| 820 | struct vmbus_channel_gpadl_header { |
| 821 | struct vmbus_channel_message_header header; |
| 822 | u32 child_relid; |
| 823 | u32 gpadl; |
| 824 | u16 range_buflen; |
| 825 | u16 rangecount; |
| 826 | struct gpa_range range[0]; |
| 827 | } __packed; |
| 828 | |
| 829 | /* This is the followup packet that contains more PFNs. */ |
| 830 | struct vmbus_channel_gpadl_body { |
| 831 | struct vmbus_channel_message_header header; |
| 832 | u32 msgnumber; |
| 833 | u32 gpadl; |
| 834 | u64 pfn[0]; |
| 835 | } __packed; |
| 836 | |
| 837 | struct vmbus_channel_gpadl_created { |
| 838 | struct vmbus_channel_message_header header; |
| 839 | u32 child_relid; |
| 840 | u32 gpadl; |
| 841 | u32 creation_status; |
| 842 | } __packed; |
| 843 | |
| 844 | struct vmbus_channel_gpadl_teardown { |
| 845 | struct vmbus_channel_message_header header; |
| 846 | u32 child_relid; |
| 847 | u32 gpadl; |
| 848 | } __packed; |
| 849 | |
| 850 | struct vmbus_channel_gpadl_torndown { |
| 851 | struct vmbus_channel_message_header header; |
| 852 | u32 gpadl; |
| 853 | } __packed; |
| 854 | |
| 855 | #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD |
| 856 | struct vmbus_channel_view_range_add { |
| 857 | struct vmbus_channel_message_header header; |
| 858 | PHYSICAL_ADDRESS viewrange_base; |
| 859 | u64 viewrange_length; |
| 860 | u32 child_relid; |
| 861 | } __packed; |
| 862 | |
| 863 | struct vmbus_channel_view_range_remove { |
| 864 | struct vmbus_channel_message_header header; |
| 865 | PHYSICAL_ADDRESS viewrange_base; |
| 866 | u32 child_relid; |
| 867 | } __packed; |
| 868 | #endif |
| 869 | |
| 870 | struct vmbus_channel_relid_released { |
| 871 | struct vmbus_channel_message_header header; |
| 872 | u32 child_relid; |
| 873 | } __packed; |
| 874 | |
| 875 | struct vmbus_channel_initiate_contact { |
| 876 | struct vmbus_channel_message_header header; |
| 877 | u32 vmbus_version_requested; |
| 878 | u32 padding2; |
| 879 | u64 interrupt_page; |
| 880 | u64 monitor_page1; |
| 881 | u64 monitor_page2; |
| 882 | } __packed; |
| 883 | |
| 884 | struct vmbus_channel_version_response { |
| 885 | struct vmbus_channel_message_header header; |
K. Y. Srinivasan | 1508d81 | 2012-08-16 08:23:20 -0700 | [diff] [blame] | 886 | u8 version_supported; |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 887 | } __packed; |
| 888 | |
| 889 | enum vmbus_channel_state { |
| 890 | CHANNEL_OFFER_STATE, |
| 891 | CHANNEL_OPENING_STATE, |
| 892 | CHANNEL_OPEN_STATE, |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 893 | CHANNEL_OPENED_STATE, |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 894 | }; |
| 895 | |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 896 | /* |
| 897 | * Represents each channel msg on the vmbus connection This is a |
| 898 | * variable-size data structure depending on the msg type itself |
| 899 | */ |
| 900 | struct vmbus_channel_msginfo { |
| 901 | /* Bookkeeping stuff */ |
| 902 | struct list_head msglistentry; |
| 903 | |
| 904 | /* So far, this is only used to handle gpadl body message */ |
| 905 | struct list_head submsglist; |
| 906 | |
| 907 | /* Synchronize the request/response if needed */ |
| 908 | struct completion waitevent; |
| 909 | union { |
| 910 | struct vmbus_channel_version_supported version_supported; |
| 911 | struct vmbus_channel_open_result open_result; |
| 912 | struct vmbus_channel_gpadl_torndown gpadl_torndown; |
| 913 | struct vmbus_channel_gpadl_created gpadl_created; |
| 914 | struct vmbus_channel_version_response version_response; |
| 915 | } response; |
| 916 | |
| 917 | u32 msgsize; |
| 918 | /* |
| 919 | * The channel message that goes out on the "wire". |
| 920 | * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header |
| 921 | */ |
| 922 | unsigned char msg[0]; |
| 923 | }; |
| 924 | |
K. Y. Srinivasan | f9f1db8 | 2011-06-06 15:49:58 -0700 | [diff] [blame] | 925 | struct vmbus_close_msg { |
| 926 | struct vmbus_channel_msginfo info; |
| 927 | struct vmbus_channel_close_channel msg; |
| 928 | }; |
| 929 | |
K. Y. Srinivasan | b3bf60c | 2012-12-01 06:46:45 -0800 | [diff] [blame] | 930 | /* Define connection identifier type. */ |
| 931 | union hv_connection_id { |
| 932 | u32 asu32; |
| 933 | struct { |
| 934 | u32 id:24; |
| 935 | u32 reserved:8; |
| 936 | } u; |
| 937 | }; |
| 938 | |
| 939 | /* Definition of the hv_signal_event hypercall input structure. */ |
| 940 | struct hv_input_signal_event { |
| 941 | union hv_connection_id connectionid; |
| 942 | u16 flag_number; |
| 943 | u16 rsvdz; |
| 944 | }; |
| 945 | |
| 946 | struct hv_input_signal_event_buffer { |
| 947 | u64 align8; |
| 948 | struct hv_input_signal_event event; |
| 949 | }; |
| 950 | |
K. Y. Srinivasan | 7d7c75c | 2011-06-06 15:49:57 -0700 | [diff] [blame] | 951 | struct vmbus_channel { |
| 952 | struct list_head listentry; |
| 953 | |
| 954 | struct hv_device *device_obj; |
| 955 | |
| 956 | struct work_struct work; |
| 957 | |
| 958 | enum vmbus_channel_state state; |
K. Y. Srinivasan | 7d7c75c | 2011-06-06 15:49:57 -0700 | [diff] [blame] | 959 | |
| 960 | struct vmbus_channel_offer_channel offermsg; |
| 961 | /* |
| 962 | * These are based on the OfferMsg.MonitorId. |
| 963 | * Save it here for easy access. |
| 964 | */ |
| 965 | u8 monitor_grp; |
| 966 | u8 monitor_bit; |
| 967 | |
| 968 | u32 ringbuffer_gpadlhandle; |
| 969 | |
| 970 | /* Allocated memory for ring buffer */ |
| 971 | void *ringbuffer_pages; |
| 972 | u32 ringbuffer_pagecount; |
| 973 | struct hv_ring_buffer_info outbound; /* send to parent */ |
| 974 | struct hv_ring_buffer_info inbound; /* receive from parent */ |
| 975 | spinlock_t inbound_lock; |
| 976 | struct workqueue_struct *controlwq; |
| 977 | |
K. Y. Srinivasan | f9f1db8 | 2011-06-06 15:49:58 -0700 | [diff] [blame] | 978 | struct vmbus_close_msg close_msg; |
| 979 | |
K. Y. Srinivasan | 7d7c75c | 2011-06-06 15:49:57 -0700 | [diff] [blame] | 980 | /* Channel callback are invoked in this workqueue context */ |
| 981 | /* HANDLE dataWorkQueue; */ |
| 982 | |
| 983 | void (*onchannel_callback)(void *context); |
| 984 | void *channel_callback_context; |
K. Y. Srinivasan | 132368b | 2012-12-01 06:46:33 -0800 | [diff] [blame] | 985 | |
| 986 | /* |
| 987 | * A channel can be marked for efficient (batched) |
| 988 | * reading: |
| 989 | * If batched_reading is set to "true", we read until the |
| 990 | * channel is empty and hold off interrupts from the host |
| 991 | * during the entire read process. |
| 992 | * If batched_reading is set to "false", the client is not |
| 993 | * going to perform batched reading. |
| 994 | * |
| 995 | * By default we will enable batched reading; specific |
| 996 | * drivers that don't want this behavior can turn it off. |
| 997 | */ |
| 998 | |
| 999 | bool batched_reading; |
K. Y. Srinivasan | b3bf60c | 2012-12-01 06:46:45 -0800 | [diff] [blame] | 1000 | |
| 1001 | bool is_dedicated_interrupt; |
| 1002 | struct hv_input_signal_event_buffer sig_buf; |
| 1003 | struct hv_input_signal_event *sig_event; |
K. Y. Srinivasan | abbf3b2 | 2012-12-01 06:46:48 -0800 | [diff] [blame] | 1004 | |
| 1005 | /* |
| 1006 | * Starting with win8, this field will be used to specify |
| 1007 | * the target virtual processor on which to deliver the interrupt for |
| 1008 | * the host to guest communication. |
| 1009 | * Prior to win8, incoming channel interrupts would only |
| 1010 | * be delivered on cpu 0. Setting this value to 0 would |
| 1011 | * preserve the earlier behavior. |
| 1012 | */ |
| 1013 | u32 target_vp; |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1014 | /* |
| 1015 | * Support for sub-channels. For high performance devices, |
| 1016 | * it will be useful to have multiple sub-channels to support |
| 1017 | * a scalable communication infrastructure with the host. |
| 1018 | * The support for sub-channels is implemented as an extention |
| 1019 | * to the current infrastructure. |
| 1020 | * The initial offer is considered the primary channel and this |
| 1021 | * offer message will indicate if the host supports sub-channels. |
| 1022 | * The guest is free to ask for sub-channels to be offerred and can |
| 1023 | * open these sub-channels as a normal "primary" channel. However, |
| 1024 | * all sub-channels will have the same type and instance guids as the |
| 1025 | * primary channel. Requests sent on a given channel will result in a |
| 1026 | * response on the same channel. |
| 1027 | */ |
| 1028 | |
| 1029 | /* |
| 1030 | * Sub-channel creation callback. This callback will be called in |
| 1031 | * process context when a sub-channel offer is received from the host. |
| 1032 | * The guest can open the sub-channel in the context of this callback. |
| 1033 | */ |
| 1034 | void (*sc_creation_callback)(struct vmbus_channel *new_sc); |
| 1035 | |
| 1036 | spinlock_t sc_lock; |
| 1037 | /* |
| 1038 | * All Sub-channels of a primary channel are linked here. |
| 1039 | */ |
| 1040 | struct list_head sc_list; |
| 1041 | /* |
| 1042 | * The primary channel this sub-channel belongs to. |
| 1043 | * This will be NULL for the primary channel. |
| 1044 | */ |
| 1045 | struct vmbus_channel *primary_channel; |
K. Y. Srinivasan | 7d7c75c | 2011-06-06 15:49:57 -0700 | [diff] [blame] | 1046 | }; |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 1047 | |
K. Y. Srinivasan | 132368b | 2012-12-01 06:46:33 -0800 | [diff] [blame] | 1048 | static inline void set_channel_read_state(struct vmbus_channel *c, bool state) |
| 1049 | { |
| 1050 | c->batched_reading = state; |
| 1051 | } |
| 1052 | |
K. Y. Srinivasan | b56dda0 | 2011-05-12 19:34:21 -0700 | [diff] [blame] | 1053 | void vmbus_onmessage(void *context); |
| 1054 | |
| 1055 | int vmbus_request_offers(void); |
| 1056 | |
K. Y. Srinivasan | e68d297 | 2013-05-23 12:02:32 -0700 | [diff] [blame] | 1057 | /* |
| 1058 | * APIs for managing sub-channels. |
| 1059 | */ |
| 1060 | |
| 1061 | void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel, |
| 1062 | void (*sc_cr_cb)(struct vmbus_channel *new_sc)); |
| 1063 | |
| 1064 | /* |
| 1065 | * Retrieve the (sub) channel on which to send an outgoing request. |
| 1066 | * When a primary channel has multiple sub-channels, we choose a |
| 1067 | * channel whose VCPU binding is closest to the VCPU on which |
| 1068 | * this call is being made. |
| 1069 | */ |
| 1070 | struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary); |
| 1071 | |
| 1072 | /* |
| 1073 | * Check if sub-channels have already been offerred. This API will be useful |
| 1074 | * when the driver is unloaded after establishing sub-channels. In this case, |
| 1075 | * when the driver is re-loaded, the driver would have to check if the |
| 1076 | * subchannels have already been established before attempting to request |
| 1077 | * the creation of sub-channels. |
| 1078 | * This function returns TRUE to indicate that subchannels have already been |
| 1079 | * created. |
| 1080 | * This function should be invoked after setting the callback function for |
| 1081 | * sub-channel creation. |
| 1082 | */ |
| 1083 | bool vmbus_are_subchannels_present(struct vmbus_channel *primary); |
| 1084 | |
K. Y. Srinivasan | c35470b | 2011-05-12 19:34:22 -0700 | [diff] [blame] | 1085 | /* The format must be the same as struct vmdata_gpa_direct */ |
| 1086 | struct vmbus_channel_packet_page_buffer { |
| 1087 | u16 type; |
| 1088 | u16 dataoffset8; |
| 1089 | u16 length8; |
| 1090 | u16 flags; |
| 1091 | u64 transactionid; |
| 1092 | u32 reserved; |
| 1093 | u32 rangecount; |
| 1094 | struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT]; |
| 1095 | } __packed; |
| 1096 | |
| 1097 | /* The format must be the same as struct vmdata_gpa_direct */ |
| 1098 | struct vmbus_channel_packet_multipage_buffer { |
| 1099 | u16 type; |
| 1100 | u16 dataoffset8; |
| 1101 | u16 length8; |
| 1102 | u16 flags; |
| 1103 | u64 transactionid; |
| 1104 | u32 reserved; |
| 1105 | u32 rangecount; /* Always 1 in this case */ |
| 1106 | struct hv_multipage_buffer range; |
| 1107 | } __packed; |
| 1108 | |
| 1109 | |
| 1110 | extern int vmbus_open(struct vmbus_channel *channel, |
| 1111 | u32 send_ringbuffersize, |
| 1112 | u32 recv_ringbuffersize, |
| 1113 | void *userdata, |
| 1114 | u32 userdatalen, |
| 1115 | void(*onchannel_callback)(void *context), |
| 1116 | void *context); |
| 1117 | |
| 1118 | extern void vmbus_close(struct vmbus_channel *channel); |
| 1119 | |
| 1120 | extern int vmbus_sendpacket(struct vmbus_channel *channel, |
| 1121 | const void *buffer, |
| 1122 | u32 bufferLen, |
| 1123 | u64 requestid, |
| 1124 | enum vmbus_packet_type type, |
| 1125 | u32 flags); |
| 1126 | |
| 1127 | extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, |
| 1128 | struct hv_page_buffer pagebuffers[], |
| 1129 | u32 pagecount, |
| 1130 | void *buffer, |
| 1131 | u32 bufferlen, |
| 1132 | u64 requestid); |
| 1133 | |
| 1134 | extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, |
| 1135 | struct hv_multipage_buffer *mpb, |
| 1136 | void *buffer, |
| 1137 | u32 bufferlen, |
| 1138 | u64 requestid); |
| 1139 | |
| 1140 | extern int vmbus_establish_gpadl(struct vmbus_channel *channel, |
| 1141 | void *kbuffer, |
| 1142 | u32 size, |
| 1143 | u32 *gpadl_handle); |
| 1144 | |
| 1145 | extern int vmbus_teardown_gpadl(struct vmbus_channel *channel, |
| 1146 | u32 gpadl_handle); |
| 1147 | |
| 1148 | extern int vmbus_recvpacket(struct vmbus_channel *channel, |
| 1149 | void *buffer, |
| 1150 | u32 bufferlen, |
| 1151 | u32 *buffer_actual_len, |
| 1152 | u64 *requestid); |
| 1153 | |
| 1154 | extern int vmbus_recvpacket_raw(struct vmbus_channel *channel, |
| 1155 | void *buffer, |
| 1156 | u32 bufferlen, |
| 1157 | u32 *buffer_actual_len, |
| 1158 | u64 *requestid); |
| 1159 | |
K. Y. Srinivasan | c35470b | 2011-05-12 19:34:22 -0700 | [diff] [blame] | 1160 | |
K. Y. Srinivasan | c35470b | 2011-05-12 19:34:22 -0700 | [diff] [blame] | 1161 | extern void vmbus_ontimer(unsigned long data); |
| 1162 | |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1163 | /* Base driver object */ |
| 1164 | struct hv_driver { |
| 1165 | const char *name; |
| 1166 | |
| 1167 | /* the device type supported by this driver */ |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 1168 | uuid_le dev_type; |
K. Y. Srinivasan | 2e2c1d1 | 2011-08-25 09:48:31 -0700 | [diff] [blame] | 1169 | const struct hv_vmbus_device_id *id_table; |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1170 | |
| 1171 | struct device_driver driver; |
| 1172 | |
K. Y. Srinivasan | 8494689 | 2011-09-13 10:59:38 -0700 | [diff] [blame] | 1173 | int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *); |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1174 | int (*remove)(struct hv_device *); |
| 1175 | void (*shutdown)(struct hv_device *); |
| 1176 | |
| 1177 | }; |
| 1178 | |
| 1179 | /* Base device object */ |
| 1180 | struct hv_device { |
| 1181 | /* the device type id of this device */ |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 1182 | uuid_le dev_type; |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1183 | |
| 1184 | /* the device instance id of this device */ |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 1185 | uuid_le dev_instance; |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1186 | |
| 1187 | struct device device; |
| 1188 | |
| 1189 | struct vmbus_channel *channel; |
K. Y. Srinivasan | 35ea09c | 2011-05-12 19:34:24 -0700 | [diff] [blame] | 1190 | }; |
| 1191 | |
K. Y. Srinivasan | 27b5b3c | 2011-05-12 19:34:25 -0700 | [diff] [blame] | 1192 | |
| 1193 | static inline struct hv_device *device_to_hv_device(struct device *d) |
| 1194 | { |
| 1195 | return container_of(d, struct hv_device, device); |
| 1196 | } |
| 1197 | |
| 1198 | static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d) |
| 1199 | { |
| 1200 | return container_of(d, struct hv_driver, driver); |
| 1201 | } |
| 1202 | |
K. Y. Srinivasan | ab101e8 | 2011-09-13 10:59:40 -0700 | [diff] [blame] | 1203 | static inline void hv_set_drvdata(struct hv_device *dev, void *data) |
| 1204 | { |
| 1205 | dev_set_drvdata(&dev->device, data); |
| 1206 | } |
| 1207 | |
| 1208 | static inline void *hv_get_drvdata(struct hv_device *dev) |
| 1209 | { |
| 1210 | return dev_get_drvdata(&dev->device); |
| 1211 | } |
K. Y. Srinivasan | 27b5b3c | 2011-05-12 19:34:25 -0700 | [diff] [blame] | 1212 | |
| 1213 | /* Vmbus interface */ |
Greg Kroah-Hartman | 768fa21 | 2011-08-25 15:07:32 -0700 | [diff] [blame] | 1214 | #define vmbus_driver_register(driver) \ |
| 1215 | __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) |
| 1216 | int __must_check __vmbus_driver_register(struct hv_driver *hv_driver, |
| 1217 | struct module *owner, |
| 1218 | const char *mod_name); |
| 1219 | void vmbus_driver_unregister(struct hv_driver *hv_driver); |
K. Y. Srinivasan | 27b5b3c | 2011-05-12 19:34:25 -0700 | [diff] [blame] | 1220 | |
Greg Kroah-Hartman | c45cf2d | 2011-08-25 11:41:33 -0700 | [diff] [blame] | 1221 | /** |
| 1222 | * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device |
| 1223 | * |
| 1224 | * This macro is used to create a struct hv_vmbus_device_id that matches a |
| 1225 | * specific device. |
| 1226 | */ |
| 1227 | #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \ |
| 1228 | g8, g9, ga, gb, gc, gd, ge, gf) \ |
| 1229 | .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \ |
| 1230 | g8, g9, ga, gb, gc, gd, ge, gf }, |
| 1231 | |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1232 | /* |
K. Y. Srinivasan | 7fb9656 | 2013-01-23 17:42:40 -0800 | [diff] [blame] | 1233 | * GUID definitions of various offer types - services offered to the guest. |
| 1234 | */ |
| 1235 | |
| 1236 | /* |
| 1237 | * Network GUID |
| 1238 | * {f8615163-df3e-46c5-913f-f2d2f965ed0e} |
| 1239 | */ |
| 1240 | #define HV_NIC_GUID \ |
| 1241 | .guid = { \ |
| 1242 | 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \ |
| 1243 | 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \ |
| 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * IDE GUID |
| 1248 | * {32412632-86cb-44a2-9b5c-50d1417354f5} |
| 1249 | */ |
| 1250 | #define HV_IDE_GUID \ |
| 1251 | .guid = { \ |
| 1252 | 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \ |
| 1253 | 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \ |
| 1254 | } |
| 1255 | |
| 1256 | /* |
| 1257 | * SCSI GUID |
| 1258 | * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} |
| 1259 | */ |
| 1260 | #define HV_SCSI_GUID \ |
| 1261 | .guid = { \ |
| 1262 | 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \ |
| 1263 | 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \ |
| 1264 | } |
| 1265 | |
| 1266 | /* |
| 1267 | * Shutdown GUID |
| 1268 | * {0e0b6031-5213-4934-818b-38d90ced39db} |
| 1269 | */ |
| 1270 | #define HV_SHUTDOWN_GUID \ |
| 1271 | .guid = { \ |
| 1272 | 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \ |
| 1273 | 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \ |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * Time Synch GUID |
| 1278 | * {9527E630-D0AE-497b-ADCE-E80AB0175CAF} |
| 1279 | */ |
| 1280 | #define HV_TS_GUID \ |
| 1281 | .guid = { \ |
| 1282 | 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \ |
| 1283 | 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \ |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * Heartbeat GUID |
| 1288 | * {57164f39-9115-4e78-ab55-382f3bd5422d} |
| 1289 | */ |
| 1290 | #define HV_HEART_BEAT_GUID \ |
| 1291 | .guid = { \ |
| 1292 | 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \ |
| 1293 | 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \ |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | * KVP GUID |
| 1298 | * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6} |
| 1299 | */ |
| 1300 | #define HV_KVP_GUID \ |
| 1301 | .guid = { \ |
| 1302 | 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \ |
| 1303 | 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \ |
| 1304 | } |
| 1305 | |
| 1306 | /* |
| 1307 | * Dynamic memory GUID |
| 1308 | * {525074dc-8985-46e2-8057-a307dc18a502} |
| 1309 | */ |
| 1310 | #define HV_DM_GUID \ |
| 1311 | .guid = { \ |
| 1312 | 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \ |
| 1313 | 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \ |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | * Mouse GUID |
| 1318 | * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a} |
| 1319 | */ |
| 1320 | #define HV_MOUSE_GUID \ |
| 1321 | .guid = { \ |
| 1322 | 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \ |
| 1323 | 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \ |
| 1324 | } |
| 1325 | |
| 1326 | /* |
K. Y. Srinivasan | 96dd86f | 2013-03-15 12:30:06 -0700 | [diff] [blame] | 1327 | * VSS (Backup/Restore) GUID |
| 1328 | */ |
| 1329 | #define HV_VSS_GUID \ |
| 1330 | .guid = { \ |
| 1331 | 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \ |
| 1332 | 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \ |
| 1333 | } |
| 1334 | /* |
Haiyang Zhang | 68a2d20b | 2013-04-29 15:05:42 -0700 | [diff] [blame] | 1335 | * Synthetic Video GUID |
| 1336 | * {DA0A7802-E377-4aac-8E77-0558EB1073F8} |
| 1337 | */ |
| 1338 | #define HV_SYNTHVID_GUID \ |
| 1339 | .guid = { \ |
| 1340 | 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \ |
| 1341 | 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \ |
| 1342 | } |
| 1343 | |
Haiyang Zhang | 68a2d20b | 2013-04-29 15:05:42 -0700 | [diff] [blame] | 1344 | /* |
K. Y. Srinivasan | 98b80d8 | 2013-05-23 12:02:33 -0700 | [diff] [blame] | 1345 | * Synthetic FC GUID |
| 1346 | * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda} |
| 1347 | */ |
| 1348 | #define HV_SYNTHFC_GUID \ |
| 1349 | .guid = { \ |
| 1350 | 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \ |
| 1351 | 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \ |
| 1352 | } |
| 1353 | |
| 1354 | /* |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1355 | * Common header for Hyper-V ICs |
| 1356 | */ |
| 1357 | |
| 1358 | #define ICMSGTYPE_NEGOTIATE 0 |
| 1359 | #define ICMSGTYPE_HEARTBEAT 1 |
| 1360 | #define ICMSGTYPE_KVPEXCHANGE 2 |
| 1361 | #define ICMSGTYPE_SHUTDOWN 3 |
| 1362 | #define ICMSGTYPE_TIMESYNC 4 |
| 1363 | #define ICMSGTYPE_VSS 5 |
| 1364 | |
| 1365 | #define ICMSGHDRFLAG_TRANSACTION 1 |
| 1366 | #define ICMSGHDRFLAG_REQUEST 2 |
| 1367 | #define ICMSGHDRFLAG_RESPONSE 4 |
| 1368 | |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1369 | |
K. Y. Srinivasan | a29b643 | 2011-09-18 10:31:33 -0700 | [diff] [blame] | 1370 | /* |
| 1371 | * While we want to handle util services as regular devices, |
| 1372 | * there is only one instance of each of these services; so |
| 1373 | * we statically allocate the service specific state. |
| 1374 | */ |
| 1375 | |
| 1376 | struct hv_util_service { |
| 1377 | u8 *recv_buffer; |
| 1378 | void (*util_cb)(void *); |
| 1379 | int (*util_init)(struct hv_util_service *); |
| 1380 | void (*util_deinit)(void); |
| 1381 | }; |
| 1382 | |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1383 | struct vmbuspipe_hdr { |
| 1384 | u32 flags; |
| 1385 | u32 msgsize; |
| 1386 | } __packed; |
| 1387 | |
| 1388 | struct ic_version { |
| 1389 | u16 major; |
| 1390 | u16 minor; |
| 1391 | } __packed; |
| 1392 | |
| 1393 | struct icmsg_hdr { |
| 1394 | struct ic_version icverframe; |
| 1395 | u16 icmsgtype; |
| 1396 | struct ic_version icvermsg; |
| 1397 | u16 icmsgsize; |
| 1398 | u32 status; |
| 1399 | u8 ictransaction_id; |
| 1400 | u8 icflags; |
| 1401 | u8 reserved[2]; |
| 1402 | } __packed; |
| 1403 | |
| 1404 | struct icmsg_negotiate { |
| 1405 | u16 icframe_vercnt; |
| 1406 | u16 icmsg_vercnt; |
| 1407 | u32 reserved; |
| 1408 | struct ic_version icversion_data[1]; /* any size array */ |
| 1409 | } __packed; |
| 1410 | |
| 1411 | struct shutdown_msg_data { |
| 1412 | u32 reason_code; |
| 1413 | u32 timeout_seconds; |
| 1414 | u32 flags; |
| 1415 | u8 display_message[2048]; |
| 1416 | } __packed; |
| 1417 | |
| 1418 | struct heartbeat_msg_data { |
| 1419 | u64 seq_num; |
| 1420 | u32 reserved[8]; |
| 1421 | } __packed; |
| 1422 | |
| 1423 | /* Time Sync IC defs */ |
| 1424 | #define ICTIMESYNCFLAG_PROBE 0 |
| 1425 | #define ICTIMESYNCFLAG_SYNC 1 |
| 1426 | #define ICTIMESYNCFLAG_SAMPLE 2 |
| 1427 | |
| 1428 | #ifdef __x86_64__ |
| 1429 | #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */ |
| 1430 | #else |
| 1431 | #define WLTIMEDELTA 116444736000000000LL |
| 1432 | #endif |
| 1433 | |
| 1434 | struct ictimesync_data { |
| 1435 | u64 parenttime; |
| 1436 | u64 childtime; |
| 1437 | u64 roundtriptime; |
| 1438 | u8 flags; |
| 1439 | } __packed; |
| 1440 | |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1441 | struct hyperv_service_callback { |
| 1442 | u8 msg_type; |
| 1443 | char *log_msg; |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 1444 | uuid_le data; |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1445 | struct vmbus_channel *channel; |
| 1446 | void (*callback) (void *context); |
| 1447 | }; |
| 1448 | |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 1449 | #define MAX_SRV_VER 0x7ffffff |
K. Y. Srinivasan | 6741335 | 2013-07-02 10:31:30 -0700 | [diff] [blame] | 1450 | extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *, |
K. Y. Srinivasan | c836d0a | 2012-05-12 13:44:58 -0700 | [diff] [blame] | 1451 | struct icmsg_negotiate *, u8 *, int, |
| 1452 | int); |
K. Y. Srinivasan | b189702 | 2011-05-12 19:34:26 -0700 | [diff] [blame] | 1453 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 1454 | int hv_kvp_init(struct hv_util_service *); |
| 1455 | void hv_kvp_deinit(void); |
| 1456 | void hv_kvp_onchannelcallback(void *); |
| 1457 | |
K. Y. Srinivasan | 96dd86f | 2013-03-15 12:30:06 -0700 | [diff] [blame] | 1458 | int hv_vss_init(struct hv_util_service *); |
| 1459 | void hv_vss_deinit(void); |
| 1460 | void hv_vss_onchannelcallback(void *); |
| 1461 | |
K. Y. Srinivasan | 37f7278 | 2012-12-01 06:46:41 -0800 | [diff] [blame] | 1462 | /* |
| 1463 | * Negotiated version with the Host. |
| 1464 | */ |
| 1465 | |
| 1466 | extern __u32 vmbus_proto_version; |
| 1467 | |
K. Y. Srinivasan | 2939437 | 2012-01-27 15:55:58 -0800 | [diff] [blame] | 1468 | #endif /* __KERNEL__ */ |
K. Y. Srinivasan | 3f335ea | 2011-05-12 19:34:15 -0700 | [diff] [blame] | 1469 | #endif /* _HYPERV_H */ |