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