blob: d98503bde7e9bc7ace0e2c3ddc5f2ae019f527ff [file] [log] [blame]
K. Y. Srinivasan5c473402011-05-12 19:34:14 -07001/*
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. Srinivasan3f335ea2011-05-12 19:34:15 -070024
25#ifndef _HYPERV_H
26#define _HYPERV_H
27
K. Y. Srinivasan29394372012-01-27 15:55:58 -080028#include <linux/types.h>
29
K. Y. Srinivasan67413352013-07-02 10:31:30 -070030/*
31 * Framework version for util services.
32 */
K. Y. Srinivasan3a491602013-09-06 11:49:56 -070033#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. Srinivasan67413352013-07-02 10:31:30 -070037
38#define UTIL_FW_MAJOR 3
K. Y. Srinivasan3a491602013-09-06 11:49:56 -070039#define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
K. Y. Srinivasan67413352013-07-02 10:31:30 -070040
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -070041
42/*
43 * Implementation of host controlled snapshot of the guest.
44 */
45
46#define VSS_OP_REGISTER 128
47
48enum 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 */
67struct 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
79struct hv_vss_check_feature {
80 __u32 flags;
81} __attribute__((packed));
82
83struct hv_vss_check_dm_info {
84 __u32 flags;
85} __attribute__((packed));
86
87struct 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. Srinivasan29394372012-01-27 15:55:58 -080098/*
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. Srinivasan29394372012-01-27 15:55:58 -0800184
185/*
186 * Registry value types.
187 */
188
189#define REG_SZ 1
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700190#define REG_U32 4
191#define REG_U64 8
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800192
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700193/*
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. Srinivasan29394372012-01-27 15:55:58 -0800233enum hv_kvp_exchg_op {
234 KVP_OP_GET = 0,
235 KVP_OP_SET,
236 KVP_OP_DELETE,
237 KVP_OP_ENUMERATE,
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700238 KVP_OP_GET_IP_INFO,
239 KVP_OP_SET_IP_INFO,
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800240 KVP_OP_COUNT /* Number of operations, must be last. */
241};
242
243enum 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. Srinivasanb47a81d2012-08-13 10:06:52 -0700252/*
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. Srinivasan32061b42012-09-05 13:50:13 -0700262#define HV_INVALIDARG 0x80070057
263#define HV_GUID_NOTFOUND 0x80041002
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700264
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700265#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
274struct 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. Srinivasan29394372012-01-27 15:55:58 -0800285struct hv_kvp_hdr {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800286 __u8 operation;
287 __u8 pool;
288 __u16 pad;
289} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800290
291struct hv_kvp_exchg_msg_value {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800292 __u32 value_type;
293 __u32 key_size;
294 __u32 value_size;
295 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800296 union {
297 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
298 __u32 value_u32;
299 __u64 value_u64;
300 };
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800301} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800302
303struct hv_kvp_msg_enumerate {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800304 __u32 index;
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800305 struct hv_kvp_exchg_msg_value data;
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800306} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800307
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800308struct hv_kvp_msg_get {
309 struct hv_kvp_exchg_msg_value data;
310};
311
312struct hv_kvp_msg_set {
313 struct hv_kvp_exchg_msg_value data;
314};
315
316struct hv_kvp_msg_delete {
317 __u32 key_size;
318 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
319};
320
321struct hv_kvp_register {
322 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
323};
324
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800325struct hv_kvp_msg {
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700326 union {
327 struct hv_kvp_hdr kvp_hdr;
328 int error;
329 };
K. Y. Srinivasan26403352012-02-02 16:56:50 -0800330 union {
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800331 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. Srinivasan9b595782012-08-13 10:06:51 -0700335 struct hv_kvp_ipaddr_value kvp_ip_val;
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800336 struct hv_kvp_register kvp_register;
K. Y. Srinivasan26403352012-02-02 16:56:50 -0800337 } body;
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800338} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800339
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700340struct 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. Srinivasan59a084a2012-02-02 16:56:48 -0800346#ifdef __KERNEL__
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700347#include <linux/scatterlist.h>
348#include <linux/list.h>
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700349#include <linux/uuid.h>
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700350#include <linux/timer.h>
351#include <linux/workqueue.h>
352#include <linux/completion.h>
353#include <linux/device.h>
K. Y. Srinivasan2e2c1d12011-08-25 09:48:31 -0700354#include <linux/mod_devicetable.h>
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700355
356
Haiyang Zhangc31c1512012-02-02 07:18:00 +0000357#define MAX_PAGE_BUFFER_COUNT 19
K. Y. Srinivasana363bf72011-05-12 19:34:16 -0700358#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
359
360#pragma pack(push, 1)
361
362/* Single-page buffer */
363struct hv_page_buffer {
364 u32 len;
365 u32 offset;
366 u64 pfn;
367};
368
369/* Multiple-page buffer */
370struct 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. Srinivasan7effffb2011-05-12 19:34:17 -0700387struct 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. Srinivasan24166032012-12-01 06:46:39 -0800396 /*
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. Srinivasan7effffb2011-05-12 19:34:17 -0700404 */
K. Y. Srinivasan24166032012-12-01 06:46:39 -0800405 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. Srinivasan7effffb2011-05-12 19:34:17 -0700418
419 /*
420 * Ring data starts here + RingDataStartOffset
421 * !!! DO NOT place any fields below this !!!
422 */
423 u8 buffer[0];
424} __packed;
425
426struct 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
435struct hv_ring_buffer_debug_info {
436 u32 current_interrupt_mask;
437 u32 current_read_index;
438 u32 current_write_index;
439 u32 bytes_avail_toread;
440 u32 bytes_avail_towrite;
441};
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -0700442
Haiyang Zhang33be96e2012-03-27 13:20:45 +0000443
444/*
445 *
446 * hv_get_ringbuffer_availbytes()
447 *
448 * Get number of bytes available to read and to write to
449 * for the specified ring buffer
450 */
451static inline void
452hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
453 u32 *read, u32 *write)
454{
455 u32 read_loc, write_loc, dsize;
456
457 smp_read_barrier_depends();
458
459 /* Capture the read/write indices before they changed */
460 read_loc = rbi->ring_buffer->read_index;
461 write_loc = rbi->ring_buffer->write_index;
462 dsize = rbi->ring_datasize;
463
464 *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
465 read_loc - write_loc;
466 *read = dsize - *write;
467}
468
K. Y. Srinivasaneafa7072012-12-01 06:46:44 -0800469/*
470 * VMBUS version is 32 bit entity broken up into
471 * two 16 bit quantities: major_number. minor_number.
472 *
473 * 0 . 13 (Windows Server 2008)
474 * 1 . 1 (Windows 7)
475 * 2 . 4 (Windows 8)
476 */
477
478#define VERSION_WS2008 ((0 << 16) | (13))
479#define VERSION_WIN7 ((1 << 16) | (1))
480#define VERSION_WIN8 ((2 << 16) | (4))
481
482#define VERSION_INVAL -1
483
K. Y. Srinivasan2a5c43a2012-12-01 06:46:56 -0800484#define VERSION_CURRENT VERSION_WIN8
K. Y. Srinivasanf7c6dfd2011-05-12 19:34:18 -0700485
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700486/* Make maximum size of pipe payload of 16K */
487#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
488
489/* Define PipeMode values. */
490#define VMBUS_PIPE_TYPE_BYTE 0x00000000
491#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
492
493/* The size of the user defined data buffer for non-pipe offers. */
494#define MAX_USER_DEFINED_BYTES 120
495
496/* The size of the user defined data buffer for pipe offers. */
497#define MAX_PIPE_USER_DEFINED_BYTES 116
498
499/*
500 * At the center of the Channel Management library is the Channel Offer. This
501 * struct contains the fundamental information about an offer.
502 */
503struct vmbus_channel_offer {
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700504 uuid_le if_type;
505 uuid_le if_instance;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800506
507 /*
508 * These two fields are not currently used.
509 */
510 u64 reserved1;
511 u64 reserved2;
512
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700513 u16 chn_flags;
514 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
515
516 union {
517 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
518 struct {
519 unsigned char user_def[MAX_USER_DEFINED_BYTES];
520 } std;
521
522 /*
523 * Pipes:
524 * The following sructure is an integrated pipe protocol, which
525 * is implemented on top of standard user-defined data. Pipe
526 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
527 * use.
528 */
529 struct {
530 u32 pipe_mode;
531 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
532 } pipe;
533 } u;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800534 /*
535 * The sub_channel_index is defined in win8.
536 */
537 u16 sub_channel_index;
538 u16 reserved3;
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700539} __packed;
540
541/* Server Flags */
542#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
543#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
544#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
545#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
546#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
547#define VMBUS_CHANNEL_PARENT_OFFER 0x200
548#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
549
K. Y. Srinivasan50ed40e2011-05-12 19:34:20 -0700550struct vmpacket_descriptor {
551 u16 type;
552 u16 offset8;
553 u16 len8;
554 u16 flags;
555 u64 trans_id;
556} __packed;
557
558struct vmpacket_header {
559 u32 prev_pkt_start_offset;
560 struct vmpacket_descriptor descriptor;
561} __packed;
562
563struct vmtransfer_page_range {
564 u32 byte_count;
565 u32 byte_offset;
566} __packed;
567
568struct vmtransfer_page_packet_header {
569 struct vmpacket_descriptor d;
570 u16 xfer_pageset_id;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700571 u8 sender_owns_set;
K. Y. Srinivasan50ed40e2011-05-12 19:34:20 -0700572 u8 reserved;
573 u32 range_cnt;
574 struct vmtransfer_page_range ranges[1];
575} __packed;
576
577struct vmgpadl_packet_header {
578 struct vmpacket_descriptor d;
579 u32 gpadl;
580 u32 reserved;
581} __packed;
582
583struct vmadd_remove_transfer_page_set {
584 struct vmpacket_descriptor d;
585 u32 gpadl;
586 u16 xfer_pageset_id;
587 u16 reserved;
588} __packed;
589
590/*
591 * This structure defines a range in guest physical space that can be made to
592 * look virtually contiguous.
593 */
594struct gpa_range {
595 u32 byte_count;
596 u32 byte_offset;
597 u64 pfn_array[0];
598};
599
600/*
601 * This is the format for an Establish Gpadl packet, which contains a handle by
602 * which this GPADL will be known and a set of GPA ranges associated with it.
603 * This can be converted to a MDL by the guest OS. If there are multiple GPA
604 * ranges, then the resulting MDL will be "chained," representing multiple VA
605 * ranges.
606 */
607struct vmestablish_gpadl {
608 struct vmpacket_descriptor d;
609 u32 gpadl;
610 u32 range_cnt;
611 struct gpa_range range[1];
612} __packed;
613
614/*
615 * This is the format for a Teardown Gpadl packet, which indicates that the
616 * GPADL handle in the Establish Gpadl packet will never be referenced again.
617 */
618struct vmteardown_gpadl {
619 struct vmpacket_descriptor d;
620 u32 gpadl;
621 u32 reserved; /* for alignment to a 8-byte boundary */
622} __packed;
623
624/*
625 * This is the format for a GPA-Direct packet, which contains a set of GPA
626 * ranges, in addition to commands and/or data.
627 */
628struct vmdata_gpa_direct {
629 struct vmpacket_descriptor d;
630 u32 reserved;
631 u32 range_cnt;
632 struct gpa_range range[1];
633} __packed;
634
635/* This is the format for a Additional Data Packet. */
636struct vmadditional_data {
637 struct vmpacket_descriptor d;
638 u64 total_bytes;
639 u32 offset;
640 u32 byte_cnt;
641 unsigned char data[1];
642} __packed;
643
644union vmpacket_largest_possible_header {
645 struct vmpacket_descriptor simple_hdr;
646 struct vmtransfer_page_packet_header xfer_page_hdr;
647 struct vmgpadl_packet_header gpadl_hdr;
648 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
649 struct vmestablish_gpadl establish_gpadl_hdr;
650 struct vmteardown_gpadl teardown_gpadl_hdr;
651 struct vmdata_gpa_direct data_gpa_direct_hdr;
652};
653
654#define VMPACKET_DATA_START_ADDRESS(__packet) \
655 (void *)(((unsigned char *)__packet) + \
656 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
657
658#define VMPACKET_DATA_LENGTH(__packet) \
659 ((((struct vmpacket_descriptor)__packet)->len8 - \
660 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
661
662#define VMPACKET_TRANSFER_MODE(__packet) \
663 (((struct IMPACT)__packet)->type)
664
665enum vmbus_packet_type {
666 VM_PKT_INVALID = 0x0,
667 VM_PKT_SYNCH = 0x1,
668 VM_PKT_ADD_XFER_PAGESET = 0x2,
669 VM_PKT_RM_XFER_PAGESET = 0x3,
670 VM_PKT_ESTABLISH_GPADL = 0x4,
671 VM_PKT_TEARDOWN_GPADL = 0x5,
672 VM_PKT_DATA_INBAND = 0x6,
673 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
674 VM_PKT_DATA_USING_GPADL = 0x8,
675 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
676 VM_PKT_CANCEL_REQUEST = 0xa,
677 VM_PKT_COMP = 0xb,
678 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
679 VM_PKT_ADDITIONAL_DATA = 0xd
680};
681
682#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700683
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700684
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700685/* Version 1 messages */
686enum vmbus_channel_message_type {
687 CHANNELMSG_INVALID = 0,
688 CHANNELMSG_OFFERCHANNEL = 1,
689 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
690 CHANNELMSG_REQUESTOFFERS = 3,
691 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
692 CHANNELMSG_OPENCHANNEL = 5,
693 CHANNELMSG_OPENCHANNEL_RESULT = 6,
694 CHANNELMSG_CLOSECHANNEL = 7,
695 CHANNELMSG_GPADL_HEADER = 8,
696 CHANNELMSG_GPADL_BODY = 9,
697 CHANNELMSG_GPADL_CREATED = 10,
698 CHANNELMSG_GPADL_TEARDOWN = 11,
699 CHANNELMSG_GPADL_TORNDOWN = 12,
700 CHANNELMSG_RELID_RELEASED = 13,
701 CHANNELMSG_INITIATE_CONTACT = 14,
702 CHANNELMSG_VERSION_RESPONSE = 15,
703 CHANNELMSG_UNLOAD = 16,
704#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
705 CHANNELMSG_VIEWRANGE_ADD = 17,
706 CHANNELMSG_VIEWRANGE_REMOVE = 18,
707#endif
708 CHANNELMSG_COUNT
709};
710
711struct vmbus_channel_message_header {
712 enum vmbus_channel_message_type msgtype;
713 u32 padding;
714} __packed;
715
716/* Query VMBus Version parameters */
717struct vmbus_channel_query_vmbus_version {
718 struct vmbus_channel_message_header header;
719 u32 version;
720} __packed;
721
722/* VMBus Version Supported parameters */
723struct vmbus_channel_version_supported {
724 struct vmbus_channel_message_header header;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700725 u8 version_supported;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700726} __packed;
727
728/* Offer Channel parameters */
729struct vmbus_channel_offer_channel {
730 struct vmbus_channel_message_header header;
731 struct vmbus_channel_offer offer;
732 u32 child_relid;
733 u8 monitorid;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800734 /*
735 * win7 and beyond splits this field into a bit field.
736 */
737 u8 monitor_allocated:1;
738 u8 reserved:7;
739 /*
740 * These are new fields added in win7 and later.
741 * Do not access these fields without checking the
742 * negotiated protocol.
743 *
744 * If "is_dedicated_interrupt" is set, we must not set the
745 * associated bit in the channel bitmap while sending the
746 * interrupt to the host.
747 *
748 * connection_id is to be used in signaling the host.
749 */
750 u16 is_dedicated_interrupt:1;
751 u16 reserved1:15;
752 u32 connection_id;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700753} __packed;
754
755/* Rescind Offer parameters */
756struct vmbus_channel_rescind_offer {
757 struct vmbus_channel_message_header header;
758 u32 child_relid;
759} __packed;
760
761/*
762 * Request Offer -- no parameters, SynIC message contains the partition ID
763 * Set Snoop -- no parameters, SynIC message contains the partition ID
764 * Clear Snoop -- no parameters, SynIC message contains the partition ID
765 * All Offers Delivered -- no parameters, SynIC message contains the partition
766 * ID
767 * Flush Client -- no parameters, SynIC message contains the partition ID
768 */
769
770/* Open Channel parameters */
771struct vmbus_channel_open_channel {
772 struct vmbus_channel_message_header header;
773
774 /* Identifies the specific VMBus channel that is being opened. */
775 u32 child_relid;
776
777 /* ID making a particular open request at a channel offer unique. */
778 u32 openid;
779
780 /* GPADL for the channel's ring buffer. */
781 u32 ringbuffer_gpadlhandle;
782
K. Y. Srinivasanabbf3b22012-12-01 06:46:48 -0800783 /*
784 * Starting with win8, this field will be used to specify
785 * the target virtual processor on which to deliver the interrupt for
786 * the host to guest communication.
787 * Prior to win8, incoming channel interrupts would only
788 * be delivered on cpu 0. Setting this value to 0 would
789 * preserve the earlier behavior.
790 */
791 u32 target_vp;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700792
793 /*
794 * The upstream ring buffer begins at offset zero in the memory
795 * described by RingBufferGpadlHandle. The downstream ring buffer
796 * follows it at this offset (in pages).
797 */
798 u32 downstream_ringbuffer_pageoffset;
799
800 /* User-specific data to be passed along to the server endpoint. */
801 unsigned char userdata[MAX_USER_DEFINED_BYTES];
802} __packed;
803
804/* Open Channel Result parameters */
805struct vmbus_channel_open_result {
806 struct vmbus_channel_message_header header;
807 u32 child_relid;
808 u32 openid;
809 u32 status;
810} __packed;
811
812/* Close channel parameters; */
813struct vmbus_channel_close_channel {
814 struct vmbus_channel_message_header header;
815 u32 child_relid;
816} __packed;
817
818/* Channel Message GPADL */
819#define GPADL_TYPE_RING_BUFFER 1
820#define GPADL_TYPE_SERVER_SAVE_AREA 2
821#define GPADL_TYPE_TRANSACTION 8
822
823/*
824 * The number of PFNs in a GPADL message is defined by the number of
825 * pages that would be spanned by ByteCount and ByteOffset. If the
826 * implied number of PFNs won't fit in this packet, there will be a
827 * follow-up packet that contains more.
828 */
829struct vmbus_channel_gpadl_header {
830 struct vmbus_channel_message_header header;
831 u32 child_relid;
832 u32 gpadl;
833 u16 range_buflen;
834 u16 rangecount;
835 struct gpa_range range[0];
836} __packed;
837
838/* This is the followup packet that contains more PFNs. */
839struct vmbus_channel_gpadl_body {
840 struct vmbus_channel_message_header header;
841 u32 msgnumber;
842 u32 gpadl;
843 u64 pfn[0];
844} __packed;
845
846struct vmbus_channel_gpadl_created {
847 struct vmbus_channel_message_header header;
848 u32 child_relid;
849 u32 gpadl;
850 u32 creation_status;
851} __packed;
852
853struct vmbus_channel_gpadl_teardown {
854 struct vmbus_channel_message_header header;
855 u32 child_relid;
856 u32 gpadl;
857} __packed;
858
859struct vmbus_channel_gpadl_torndown {
860 struct vmbus_channel_message_header header;
861 u32 gpadl;
862} __packed;
863
864#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
865struct vmbus_channel_view_range_add {
866 struct vmbus_channel_message_header header;
867 PHYSICAL_ADDRESS viewrange_base;
868 u64 viewrange_length;
869 u32 child_relid;
870} __packed;
871
872struct vmbus_channel_view_range_remove {
873 struct vmbus_channel_message_header header;
874 PHYSICAL_ADDRESS viewrange_base;
875 u32 child_relid;
876} __packed;
877#endif
878
879struct vmbus_channel_relid_released {
880 struct vmbus_channel_message_header header;
881 u32 child_relid;
882} __packed;
883
884struct vmbus_channel_initiate_contact {
885 struct vmbus_channel_message_header header;
886 u32 vmbus_version_requested;
887 u32 padding2;
888 u64 interrupt_page;
889 u64 monitor_page1;
890 u64 monitor_page2;
891} __packed;
892
893struct vmbus_channel_version_response {
894 struct vmbus_channel_message_header header;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700895 u8 version_supported;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700896} __packed;
897
898enum vmbus_channel_state {
899 CHANNEL_OFFER_STATE,
900 CHANNEL_OPENING_STATE,
901 CHANNEL_OPEN_STATE,
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700902 CHANNEL_OPENED_STATE,
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700903};
904
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700905struct vmbus_channel_debug_info {
906 u32 relid;
907 enum vmbus_channel_state state;
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700908 uuid_le interfacetype;
909 uuid_le interface_instance;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700910 u32 monitorid;
911 u32 servermonitor_pending;
912 u32 servermonitor_latency;
913 u32 servermonitor_connectionid;
914 u32 clientmonitor_pending;
915 u32 clientmonitor_latency;
916 u32 clientmonitor_connectionid;
917
918 struct hv_ring_buffer_debug_info inbound;
919 struct hv_ring_buffer_debug_info outbound;
920};
921
922/*
923 * Represents each channel msg on the vmbus connection This is a
924 * variable-size data structure depending on the msg type itself
925 */
926struct vmbus_channel_msginfo {
927 /* Bookkeeping stuff */
928 struct list_head msglistentry;
929
930 /* So far, this is only used to handle gpadl body message */
931 struct list_head submsglist;
932
933 /* Synchronize the request/response if needed */
934 struct completion waitevent;
935 union {
936 struct vmbus_channel_version_supported version_supported;
937 struct vmbus_channel_open_result open_result;
938 struct vmbus_channel_gpadl_torndown gpadl_torndown;
939 struct vmbus_channel_gpadl_created gpadl_created;
940 struct vmbus_channel_version_response version_response;
941 } response;
942
943 u32 msgsize;
944 /*
945 * The channel message that goes out on the "wire".
946 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
947 */
948 unsigned char msg[0];
949};
950
K. Y. Srinivasanf9f1db82011-06-06 15:49:58 -0700951struct vmbus_close_msg {
952 struct vmbus_channel_msginfo info;
953 struct vmbus_channel_close_channel msg;
954};
955
K. Y. Srinivasanb3bf60c2012-12-01 06:46:45 -0800956/* Define connection identifier type. */
957union hv_connection_id {
958 u32 asu32;
959 struct {
960 u32 id:24;
961 u32 reserved:8;
962 } u;
963};
964
965/* Definition of the hv_signal_event hypercall input structure. */
966struct hv_input_signal_event {
967 union hv_connection_id connectionid;
968 u16 flag_number;
969 u16 rsvdz;
970};
971
972struct hv_input_signal_event_buffer {
973 u64 align8;
974 struct hv_input_signal_event event;
975};
976
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -0700977struct vmbus_channel {
978 struct list_head listentry;
979
980 struct hv_device *device_obj;
981
982 struct work_struct work;
983
984 enum vmbus_channel_state state;
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -0700985
986 struct vmbus_channel_offer_channel offermsg;
987 /*
988 * These are based on the OfferMsg.MonitorId.
989 * Save it here for easy access.
990 */
991 u8 monitor_grp;
992 u8 monitor_bit;
993
994 u32 ringbuffer_gpadlhandle;
995
996 /* Allocated memory for ring buffer */
997 void *ringbuffer_pages;
998 u32 ringbuffer_pagecount;
999 struct hv_ring_buffer_info outbound; /* send to parent */
1000 struct hv_ring_buffer_info inbound; /* receive from parent */
1001 spinlock_t inbound_lock;
1002 struct workqueue_struct *controlwq;
1003
K. Y. Srinivasanf9f1db82011-06-06 15:49:58 -07001004 struct vmbus_close_msg close_msg;
1005
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -07001006 /* Channel callback are invoked in this workqueue context */
1007 /* HANDLE dataWorkQueue; */
1008
1009 void (*onchannel_callback)(void *context);
1010 void *channel_callback_context;
K. Y. Srinivasan132368b2012-12-01 06:46:33 -08001011
1012 /*
1013 * A channel can be marked for efficient (batched)
1014 * reading:
1015 * If batched_reading is set to "true", we read until the
1016 * channel is empty and hold off interrupts from the host
1017 * during the entire read process.
1018 * If batched_reading is set to "false", the client is not
1019 * going to perform batched reading.
1020 *
1021 * By default we will enable batched reading; specific
1022 * drivers that don't want this behavior can turn it off.
1023 */
1024
1025 bool batched_reading;
K. Y. Srinivasanb3bf60c2012-12-01 06:46:45 -08001026
1027 bool is_dedicated_interrupt;
1028 struct hv_input_signal_event_buffer sig_buf;
1029 struct hv_input_signal_event *sig_event;
K. Y. Srinivasanabbf3b22012-12-01 06:46:48 -08001030
1031 /*
1032 * Starting with win8, this field will be used to specify
1033 * the target virtual processor on which to deliver the interrupt for
1034 * the host to guest communication.
1035 * Prior to win8, incoming channel interrupts would only
1036 * be delivered on cpu 0. Setting this value to 0 would
1037 * preserve the earlier behavior.
1038 */
1039 u32 target_vp;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001040 /*
1041 * Support for sub-channels. For high performance devices,
1042 * it will be useful to have multiple sub-channels to support
1043 * a scalable communication infrastructure with the host.
1044 * The support for sub-channels is implemented as an extention
1045 * to the current infrastructure.
1046 * The initial offer is considered the primary channel and this
1047 * offer message will indicate if the host supports sub-channels.
1048 * The guest is free to ask for sub-channels to be offerred and can
1049 * open these sub-channels as a normal "primary" channel. However,
1050 * all sub-channels will have the same type and instance guids as the
1051 * primary channel. Requests sent on a given channel will result in a
1052 * response on the same channel.
1053 */
1054
1055 /*
1056 * Sub-channel creation callback. This callback will be called in
1057 * process context when a sub-channel offer is received from the host.
1058 * The guest can open the sub-channel in the context of this callback.
1059 */
1060 void (*sc_creation_callback)(struct vmbus_channel *new_sc);
1061
1062 spinlock_t sc_lock;
1063 /*
1064 * All Sub-channels of a primary channel are linked here.
1065 */
1066 struct list_head sc_list;
1067 /*
1068 * The primary channel this sub-channel belongs to.
1069 * This will be NULL for the primary channel.
1070 */
1071 struct vmbus_channel *primary_channel;
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -07001072};
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -07001073
K. Y. Srinivasan132368b2012-12-01 06:46:33 -08001074static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
1075{
1076 c->batched_reading = state;
1077}
1078
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -07001079void vmbus_onmessage(void *context);
1080
1081int vmbus_request_offers(void);
1082
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001083/*
1084 * APIs for managing sub-channels.
1085 */
1086
1087void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
1088 void (*sc_cr_cb)(struct vmbus_channel *new_sc));
1089
1090/*
1091 * Retrieve the (sub) channel on which to send an outgoing request.
1092 * When a primary channel has multiple sub-channels, we choose a
1093 * channel whose VCPU binding is closest to the VCPU on which
1094 * this call is being made.
1095 */
1096struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
1097
1098/*
1099 * Check if sub-channels have already been offerred. This API will be useful
1100 * when the driver is unloaded after establishing sub-channels. In this case,
1101 * when the driver is re-loaded, the driver would have to check if the
1102 * subchannels have already been established before attempting to request
1103 * the creation of sub-channels.
1104 * This function returns TRUE to indicate that subchannels have already been
1105 * created.
1106 * This function should be invoked after setting the callback function for
1107 * sub-channel creation.
1108 */
1109bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
1110
K. Y. Srinivasanc35470b2011-05-12 19:34:22 -07001111/* The format must be the same as struct vmdata_gpa_direct */
1112struct vmbus_channel_packet_page_buffer {
1113 u16 type;
1114 u16 dataoffset8;
1115 u16 length8;
1116 u16 flags;
1117 u64 transactionid;
1118 u32 reserved;
1119 u32 rangecount;
1120 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
1121} __packed;
1122
1123/* The format must be the same as struct vmdata_gpa_direct */
1124struct vmbus_channel_packet_multipage_buffer {
1125 u16 type;
1126 u16 dataoffset8;
1127 u16 length8;
1128 u16 flags;
1129 u64 transactionid;
1130 u32 reserved;
1131 u32 rangecount; /* Always 1 in this case */
1132 struct hv_multipage_buffer range;
1133} __packed;
1134
1135
1136extern int vmbus_open(struct vmbus_channel *channel,
1137 u32 send_ringbuffersize,
1138 u32 recv_ringbuffersize,
1139 void *userdata,
1140 u32 userdatalen,
1141 void(*onchannel_callback)(void *context),
1142 void *context);
1143
1144extern void vmbus_close(struct vmbus_channel *channel);
1145
1146extern int vmbus_sendpacket(struct vmbus_channel *channel,
1147 const void *buffer,
1148 u32 bufferLen,
1149 u64 requestid,
1150 enum vmbus_packet_type type,
1151 u32 flags);
1152
1153extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
1154 struct hv_page_buffer pagebuffers[],
1155 u32 pagecount,
1156 void *buffer,
1157 u32 bufferlen,
1158 u64 requestid);
1159
1160extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
1161 struct hv_multipage_buffer *mpb,
1162 void *buffer,
1163 u32 bufferlen,
1164 u64 requestid);
1165
1166extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
1167 void *kbuffer,
1168 u32 size,
1169 u32 *gpadl_handle);
1170
1171extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
1172 u32 gpadl_handle);
1173
1174extern int vmbus_recvpacket(struct vmbus_channel *channel,
1175 void *buffer,
1176 u32 bufferlen,
1177 u32 *buffer_actual_len,
1178 u64 *requestid);
1179
1180extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
1181 void *buffer,
1182 u32 bufferlen,
1183 u32 *buffer_actual_len,
1184 u64 *requestid);
1185
K. Y. Srinivasanc35470b2011-05-12 19:34:22 -07001186
1187extern void vmbus_get_debug_info(struct vmbus_channel *channel,
1188 struct vmbus_channel_debug_info *debug);
1189
1190extern void vmbus_ontimer(unsigned long data);
1191
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001192struct hv_dev_port_info {
1193 u32 int_mask;
1194 u32 read_idx;
1195 u32 write_idx;
1196 u32 bytes_avail_toread;
1197 u32 bytes_avail_towrite;
1198};
1199
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001200/* Base driver object */
1201struct hv_driver {
1202 const char *name;
1203
1204 /* the device type supported by this driver */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001205 uuid_le dev_type;
K. Y. Srinivasan2e2c1d12011-08-25 09:48:31 -07001206 const struct hv_vmbus_device_id *id_table;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001207
1208 struct device_driver driver;
1209
K. Y. Srinivasan84946892011-09-13 10:59:38 -07001210 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001211 int (*remove)(struct hv_device *);
1212 void (*shutdown)(struct hv_device *);
1213
1214};
1215
1216/* Base device object */
1217struct hv_device {
1218 /* the device type id of this device */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001219 uuid_le dev_type;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001220
1221 /* the device instance id of this device */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001222 uuid_le dev_instance;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001223
1224 struct device device;
1225
1226 struct vmbus_channel *channel;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001227};
1228
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001229
1230static inline struct hv_device *device_to_hv_device(struct device *d)
1231{
1232 return container_of(d, struct hv_device, device);
1233}
1234
1235static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1236{
1237 return container_of(d, struct hv_driver, driver);
1238}
1239
K. Y. Srinivasanab101e82011-09-13 10:59:40 -07001240static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1241{
1242 dev_set_drvdata(&dev->device, data);
1243}
1244
1245static inline void *hv_get_drvdata(struct hv_device *dev)
1246{
1247 return dev_get_drvdata(&dev->device);
1248}
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001249
1250/* Vmbus interface */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001251#define vmbus_driver_register(driver) \
1252 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1253int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1254 struct module *owner,
1255 const char *mod_name);
1256void vmbus_driver_unregister(struct hv_driver *hv_driver);
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001257
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001258/**
1259 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1260 *
1261 * This macro is used to create a struct hv_vmbus_device_id that matches a
1262 * specific device.
1263 */
1264#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1265 g8, g9, ga, gb, gc, gd, ge, gf) \
1266 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1267 g8, g9, ga, gb, gc, gd, ge, gf },
1268
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001269/*
K. Y. Srinivasan7fb96562013-01-23 17:42:40 -08001270 * GUID definitions of various offer types - services offered to the guest.
1271 */
1272
1273/*
1274 * Network GUID
1275 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1276 */
1277#define HV_NIC_GUID \
1278 .guid = { \
1279 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1280 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1281 }
1282
1283/*
1284 * IDE GUID
1285 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1286 */
1287#define HV_IDE_GUID \
1288 .guid = { \
1289 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1290 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1291 }
1292
1293/*
1294 * SCSI GUID
1295 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1296 */
1297#define HV_SCSI_GUID \
1298 .guid = { \
1299 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1300 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1301 }
1302
1303/*
1304 * Shutdown GUID
1305 * {0e0b6031-5213-4934-818b-38d90ced39db}
1306 */
1307#define HV_SHUTDOWN_GUID \
1308 .guid = { \
1309 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1310 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1311 }
1312
1313/*
1314 * Time Synch GUID
1315 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1316 */
1317#define HV_TS_GUID \
1318 .guid = { \
1319 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1320 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1321 }
1322
1323/*
1324 * Heartbeat GUID
1325 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1326 */
1327#define HV_HEART_BEAT_GUID \
1328 .guid = { \
1329 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1330 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1331 }
1332
1333/*
1334 * KVP GUID
1335 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1336 */
1337#define HV_KVP_GUID \
1338 .guid = { \
1339 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1340 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1341 }
1342
1343/*
1344 * Dynamic memory GUID
1345 * {525074dc-8985-46e2-8057-a307dc18a502}
1346 */
1347#define HV_DM_GUID \
1348 .guid = { \
1349 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1350 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1351 }
1352
1353/*
1354 * Mouse GUID
1355 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1356 */
1357#define HV_MOUSE_GUID \
1358 .guid = { \
1359 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1360 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1361 }
1362
1363/*
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -07001364 * VSS (Backup/Restore) GUID
1365 */
1366#define HV_VSS_GUID \
1367 .guid = { \
1368 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1369 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1370 }
1371/*
Haiyang Zhang68a2d20b2013-04-29 15:05:42 -07001372 * Synthetic Video GUID
1373 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1374 */
1375#define HV_SYNTHVID_GUID \
1376 .guid = { \
1377 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
1378 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
1379 }
1380
Haiyang Zhang68a2d20b2013-04-29 15:05:42 -07001381/*
K. Y. Srinivasan98b80d82013-05-23 12:02:33 -07001382 * Synthetic FC GUID
1383 * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
1384 */
1385#define HV_SYNTHFC_GUID \
1386 .guid = { \
1387 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
1388 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
1389 }
1390
1391/*
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001392 * Common header for Hyper-V ICs
1393 */
1394
1395#define ICMSGTYPE_NEGOTIATE 0
1396#define ICMSGTYPE_HEARTBEAT 1
1397#define ICMSGTYPE_KVPEXCHANGE 2
1398#define ICMSGTYPE_SHUTDOWN 3
1399#define ICMSGTYPE_TIMESYNC 4
1400#define ICMSGTYPE_VSS 5
1401
1402#define ICMSGHDRFLAG_TRANSACTION 1
1403#define ICMSGHDRFLAG_REQUEST 2
1404#define ICMSGHDRFLAG_RESPONSE 4
1405
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001406
K. Y. Srinivasana29b6432011-09-18 10:31:33 -07001407/*
1408 * While we want to handle util services as regular devices,
1409 * there is only one instance of each of these services; so
1410 * we statically allocate the service specific state.
1411 */
1412
1413struct hv_util_service {
1414 u8 *recv_buffer;
1415 void (*util_cb)(void *);
1416 int (*util_init)(struct hv_util_service *);
1417 void (*util_deinit)(void);
1418};
1419
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001420struct vmbuspipe_hdr {
1421 u32 flags;
1422 u32 msgsize;
1423} __packed;
1424
1425struct ic_version {
1426 u16 major;
1427 u16 minor;
1428} __packed;
1429
1430struct icmsg_hdr {
1431 struct ic_version icverframe;
1432 u16 icmsgtype;
1433 struct ic_version icvermsg;
1434 u16 icmsgsize;
1435 u32 status;
1436 u8 ictransaction_id;
1437 u8 icflags;
1438 u8 reserved[2];
1439} __packed;
1440
1441struct icmsg_negotiate {
1442 u16 icframe_vercnt;
1443 u16 icmsg_vercnt;
1444 u32 reserved;
1445 struct ic_version icversion_data[1]; /* any size array */
1446} __packed;
1447
1448struct shutdown_msg_data {
1449 u32 reason_code;
1450 u32 timeout_seconds;
1451 u32 flags;
1452 u8 display_message[2048];
1453} __packed;
1454
1455struct heartbeat_msg_data {
1456 u64 seq_num;
1457 u32 reserved[8];
1458} __packed;
1459
1460/* Time Sync IC defs */
1461#define ICTIMESYNCFLAG_PROBE 0
1462#define ICTIMESYNCFLAG_SYNC 1
1463#define ICTIMESYNCFLAG_SAMPLE 2
1464
1465#ifdef __x86_64__
1466#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1467#else
1468#define WLTIMEDELTA 116444736000000000LL
1469#endif
1470
1471struct ictimesync_data {
1472 u64 parenttime;
1473 u64 childtime;
1474 u64 roundtriptime;
1475 u8 flags;
1476} __packed;
1477
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001478struct hyperv_service_callback {
1479 u8 msg_type;
1480 char *log_msg;
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001481 uuid_le data;
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001482 struct vmbus_channel *channel;
1483 void (*callback) (void *context);
1484};
1485
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -07001486#define MAX_SRV_VER 0x7ffffff
K. Y. Srinivasan67413352013-07-02 10:31:30 -07001487extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -07001488 struct icmsg_negotiate *, u8 *, int,
1489 int);
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001490
K. Y. Srinivasan29394372012-01-27 15:55:58 -08001491int hv_kvp_init(struct hv_util_service *);
1492void hv_kvp_deinit(void);
1493void hv_kvp_onchannelcallback(void *);
1494
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -07001495int hv_vss_init(struct hv_util_service *);
1496void hv_vss_deinit(void);
1497void hv_vss_onchannelcallback(void *);
1498
K. Y. Srinivasan37f72782012-12-01 06:46:41 -08001499/*
1500 * Negotiated version with the Host.
1501 */
1502
1503extern __u32 vmbus_proto_version;
1504
K. Y. Srinivasan29394372012-01-27 15:55:58 -08001505#endif /* __KERNEL__ */
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -07001506#endif /* _HYPERV_H */