nlm: Ensure callback code also checks that the files match
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / hyperv.h
CommitLineData
5c473400
S
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 */
3f335ea2
S
24
25#ifndef _HYPERV_H
26#define _HYPERV_H
27
2939437c
S
28#include <linux/types.h>
29
96dd86fa
S
30
31/*
32 * Implementation of host controlled snapshot of the guest.
33 */
34
35#define VSS_OP_REGISTER 128
36
37enum 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 */
56struct 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
68struct hv_vss_check_feature {
69 __u32 flags;
70} __attribute__((packed));
71
72struct hv_vss_check_dm_info {
73 __u32 flags;
74} __attribute__((packed));
75
76struct 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
2939437c
S
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
2939437c
S
173
174/*
175 * Registry value types.
176 */
177
178#define REG_SZ 1
fa3d5b85
S
179#define REG_U32 4
180#define REG_U64 8
2939437c 181
9b595780
S
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
2939437c
S
222enum hv_kvp_exchg_op {
223 KVP_OP_GET = 0,
224 KVP_OP_SET,
225 KVP_OP_DELETE,
226 KVP_OP_ENUMERATE,
9b595780
S
227 KVP_OP_GET_IP_INFO,
228 KVP_OP_SET_IP_INFO,
2939437c
S
229 KVP_OP_COUNT /* Number of operations, must be last. */
230};
231
232enum 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
b47a81dc
S
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
32061b4d
S
251#define HV_INVALIDARG 0x80070057
252#define HV_GUID_NOTFOUND 0x80041002
b47a81dc 253
9b595780
S
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
263struct 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
2939437c 274struct hv_kvp_hdr {
59a084a7
S
275 __u8 operation;
276 __u8 pool;
277 __u16 pad;
278} __attribute__((packed));
2939437c
S
279
280struct hv_kvp_exchg_msg_value {
59a084a7
S
281 __u32 value_type;
282 __u32 key_size;
283 __u32 value_size;
284 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
e485ceac
S
285 union {
286 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
287 __u32 value_u32;
288 __u64 value_u64;
289 };
59a084a7 290} __attribute__((packed));
2939437c
S
291
292struct hv_kvp_msg_enumerate {
59a084a7 293 __u32 index;
2939437c 294 struct hv_kvp_exchg_msg_value data;
59a084a7 295} __attribute__((packed));
2939437c 296
e485ceac
S
297struct hv_kvp_msg_get {
298 struct hv_kvp_exchg_msg_value data;
299};
300
301struct hv_kvp_msg_set {
302 struct hv_kvp_exchg_msg_value data;
303};
304
305struct hv_kvp_msg_delete {
306 __u32 key_size;
307 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
308};
309
310struct hv_kvp_register {
311 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
312};
313
2939437c 314struct hv_kvp_msg {
9b595780
S
315 union {
316 struct hv_kvp_hdr kvp_hdr;
317 int error;
318 };
26403354 319 union {
e485ceac
S
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;
9b595780 324 struct hv_kvp_ipaddr_value kvp_ip_val;
e485ceac 325 struct hv_kvp_register kvp_register;
26403354 326 } body;
59a084a7 327} __attribute__((packed));
2939437c 328
9b595780
S
329struct hv_kvp_ip_msg {
330 __u8 operation;
331 __u8 pool;
332 struct hv_kvp_ipaddr_value kvp_ip_val;
333} __attribute__((packed));
334
59a084a7 335#ifdef __KERNEL__
8ff3e6fc
S
336#include <linux/scatterlist.h>
337#include <linux/list.h>
358d2ee2 338#include <linux/uuid.h>
8ff3e6fc
S
339#include <linux/timer.h>
340#include <linux/workqueue.h>
341#include <linux/completion.h>
342#include <linux/device.h>
2e2c1d17 343#include <linux/mod_devicetable.h>
8ff3e6fc
S
344
345
c31c151b 346#define MAX_PAGE_BUFFER_COUNT 19
a363bf7b
S
347#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
348
349#pragma pack(push, 1)
350
351/* Single-page buffer */
352struct hv_page_buffer {
353 u32 len;
354 u32 offset;
355 u64 pfn;
356};
357
358/* Multiple-page buffer */
359struct 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
7effffb7
S
376struct 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
2416603e
S
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.
7effffb7 393 */
2416603e
S
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];
7effffb7
S
407
408 /*
409 * Ring data starts here + RingDataStartOffset
410 * !!! DO NOT place any fields below this !!!
411 */
412 u8 buffer[0];
413} __packed;
414
415struct 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
424struct 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};
3f335ea2 431
33be96e4
HZ
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 */
440static inline void
441hv_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
f7c6dfda
S
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
eafa7072
S
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)
863a9212 486 * 3 . 0 (Windows 8 R2)
eafa7072
S
487 */
488
489#define VERSION_WS2008 ((0 << 16) | (13))
490#define VERSION_WIN7 ((1 << 16) | (1))
491#define VERSION_WIN8 ((2 << 16) | (4))
863a9212
S
492#define VERSION_WIN8_1 ((3 << 16) | (0))
493
eafa7072
S
494
495#define VERSION_INVAL -1
496
863a9212 497#define VERSION_CURRENT VERSION_WIN8_1
f7c6dfda 498
517d8dc6
S
499/* Make maximum size of pipe payload of 16K */
500#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
501
502/* Define PipeMode values. */
503#define VMBUS_PIPE_TYPE_BYTE 0x00000000
504#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
505
506/* The size of the user defined data buffer for non-pipe offers. */
507#define MAX_USER_DEFINED_BYTES 120
508
509/* The size of the user defined data buffer for pipe offers. */
510#define MAX_PIPE_USER_DEFINED_BYTES 116
511
512/*
513 * At the center of the Channel Management library is the Channel Offer. This
514 * struct contains the fundamental information about an offer.
515 */
516struct vmbus_channel_offer {
358d2ee2
S
517 uuid_le if_type;
518 uuid_le if_instance;
29423b7e
S
519
520 /*
521 * These two fields are not currently used.
522 */
523 u64 reserved1;
524 u64 reserved2;
525
517d8dc6
S
526 u16 chn_flags;
527 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
528
529 union {
530 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
531 struct {
532 unsigned char user_def[MAX_USER_DEFINED_BYTES];
533 } std;
534
535 /*
536 * Pipes:
537 * The following sructure is an integrated pipe protocol, which
538 * is implemented on top of standard user-defined data. Pipe
539 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
540 * use.
541 */
542 struct {
543 u32 pipe_mode;
544 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
545 } pipe;
546 } u;
29423b7e
S
547 /*
548 * The sub_channel_index is defined in win8.
549 */
550 u16 sub_channel_index;
551 u16 reserved3;
517d8dc6
S
552} __packed;
553
554/* Server Flags */
555#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
556#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
557#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
558#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
559#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
560#define VMBUS_CHANNEL_PARENT_OFFER 0x200
561#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
562
50ed40e0
S
563struct vmpacket_descriptor {
564 u16 type;
565 u16 offset8;
566 u16 len8;
567 u16 flags;
568 u64 trans_id;
569} __packed;
570
571struct vmpacket_header {
572 u32 prev_pkt_start_offset;
573 struct vmpacket_descriptor descriptor;
574} __packed;
575
576struct vmtransfer_page_range {
577 u32 byte_count;
578 u32 byte_offset;
579} __packed;
580
581struct vmtransfer_page_packet_header {
582 struct vmpacket_descriptor d;
583 u16 xfer_pageset_id;
1508d811 584 u8 sender_owns_set;
50ed40e0
S
585 u8 reserved;
586 u32 range_cnt;
587 struct vmtransfer_page_range ranges[1];
588} __packed;
589
590struct vmgpadl_packet_header {
591 struct vmpacket_descriptor d;
592 u32 gpadl;
593 u32 reserved;
594} __packed;
595
596struct vmadd_remove_transfer_page_set {
597 struct vmpacket_descriptor d;
598 u32 gpadl;
599 u16 xfer_pageset_id;
600 u16 reserved;
601} __packed;
602
603/*
604 * This structure defines a range in guest physical space that can be made to
605 * look virtually contiguous.
606 */
607struct gpa_range {
608 u32 byte_count;
609 u32 byte_offset;
610 u64 pfn_array[0];
611};
612
613/*
614 * This is the format for an Establish Gpadl packet, which contains a handle by
615 * which this GPADL will be known and a set of GPA ranges associated with it.
616 * This can be converted to a MDL by the guest OS. If there are multiple GPA
617 * ranges, then the resulting MDL will be "chained," representing multiple VA
618 * ranges.
619 */
620struct vmestablish_gpadl {
621 struct vmpacket_descriptor d;
622 u32 gpadl;
623 u32 range_cnt;
624 struct gpa_range range[1];
625} __packed;
626
627/*
628 * This is the format for a Teardown Gpadl packet, which indicates that the
629 * GPADL handle in the Establish Gpadl packet will never be referenced again.
630 */
631struct vmteardown_gpadl {
632 struct vmpacket_descriptor d;
633 u32 gpadl;
634 u32 reserved; /* for alignment to a 8-byte boundary */
635} __packed;
636
637/*
638 * This is the format for a GPA-Direct packet, which contains a set of GPA
639 * ranges, in addition to commands and/or data.
640 */
641struct vmdata_gpa_direct {
642 struct vmpacket_descriptor d;
643 u32 reserved;
644 u32 range_cnt;
645 struct gpa_range range[1];
646} __packed;
647
648/* This is the format for a Additional Data Packet. */
649struct vmadditional_data {
650 struct vmpacket_descriptor d;
651 u64 total_bytes;
652 u32 offset;
653 u32 byte_cnt;
654 unsigned char data[1];
655} __packed;
656
657union vmpacket_largest_possible_header {
658 struct vmpacket_descriptor simple_hdr;
659 struct vmtransfer_page_packet_header xfer_page_hdr;
660 struct vmgpadl_packet_header gpadl_hdr;
661 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
662 struct vmestablish_gpadl establish_gpadl_hdr;
663 struct vmteardown_gpadl teardown_gpadl_hdr;
664 struct vmdata_gpa_direct data_gpa_direct_hdr;
665};
666
667#define VMPACKET_DATA_START_ADDRESS(__packet) \
668 (void *)(((unsigned char *)__packet) + \
669 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
670
671#define VMPACKET_DATA_LENGTH(__packet) \
672 ((((struct vmpacket_descriptor)__packet)->len8 - \
673 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
674
675#define VMPACKET_TRANSFER_MODE(__packet) \
676 (((struct IMPACT)__packet)->type)
677
678enum vmbus_packet_type {
679 VM_PKT_INVALID = 0x0,
680 VM_PKT_SYNCH = 0x1,
681 VM_PKT_ADD_XFER_PAGESET = 0x2,
682 VM_PKT_RM_XFER_PAGESET = 0x3,
683 VM_PKT_ESTABLISH_GPADL = 0x4,
684 VM_PKT_TEARDOWN_GPADL = 0x5,
685 VM_PKT_DATA_INBAND = 0x6,
686 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
687 VM_PKT_DATA_USING_GPADL = 0x8,
688 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
689 VM_PKT_CANCEL_REQUEST = 0xa,
690 VM_PKT_COMP = 0xb,
691 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
692 VM_PKT_ADDITIONAL_DATA = 0xd
693};
694
695#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
517d8dc6 696
b56dda06 697
b56dda06
S
698/* Version 1 messages */
699enum vmbus_channel_message_type {
700 CHANNELMSG_INVALID = 0,
701 CHANNELMSG_OFFERCHANNEL = 1,
702 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
703 CHANNELMSG_REQUESTOFFERS = 3,
704 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
705 CHANNELMSG_OPENCHANNEL = 5,
706 CHANNELMSG_OPENCHANNEL_RESULT = 6,
707 CHANNELMSG_CLOSECHANNEL = 7,
708 CHANNELMSG_GPADL_HEADER = 8,
709 CHANNELMSG_GPADL_BODY = 9,
710 CHANNELMSG_GPADL_CREATED = 10,
711 CHANNELMSG_GPADL_TEARDOWN = 11,
712 CHANNELMSG_GPADL_TORNDOWN = 12,
713 CHANNELMSG_RELID_RELEASED = 13,
714 CHANNELMSG_INITIATE_CONTACT = 14,
715 CHANNELMSG_VERSION_RESPONSE = 15,
716 CHANNELMSG_UNLOAD = 16,
717#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
718 CHANNELMSG_VIEWRANGE_ADD = 17,
719 CHANNELMSG_VIEWRANGE_REMOVE = 18,
720#endif
721 CHANNELMSG_COUNT
722};
723
724struct vmbus_channel_message_header {
725 enum vmbus_channel_message_type msgtype;
726 u32 padding;
727} __packed;
728
729/* Query VMBus Version parameters */
730struct vmbus_channel_query_vmbus_version {
731 struct vmbus_channel_message_header header;
732 u32 version;
733} __packed;
734
735/* VMBus Version Supported parameters */
736struct vmbus_channel_version_supported {
737 struct vmbus_channel_message_header header;
1508d811 738 u8 version_supported;
b56dda06
S
739} __packed;
740
741/* Offer Channel parameters */
742struct vmbus_channel_offer_channel {
743 struct vmbus_channel_message_header header;
744 struct vmbus_channel_offer offer;
745 u32 child_relid;
746 u8 monitorid;
29423b7e
S
747 /*
748 * win7 and beyond splits this field into a bit field.
749 */
750 u8 monitor_allocated:1;
751 u8 reserved:7;
752 /*
753 * These are new fields added in win7 and later.
754 * Do not access these fields without checking the
755 * negotiated protocol.
756 *
757 * If "is_dedicated_interrupt" is set, we must not set the
758 * associated bit in the channel bitmap while sending the
759 * interrupt to the host.
760 *
761 * connection_id is to be used in signaling the host.
762 */
763 u16 is_dedicated_interrupt:1;
764 u16 reserved1:15;
765 u32 connection_id;
b56dda06
S
766} __packed;
767
768/* Rescind Offer parameters */
769struct vmbus_channel_rescind_offer {
770 struct vmbus_channel_message_header header;
771 u32 child_relid;
772} __packed;
773
774/*
775 * Request Offer -- no parameters, SynIC message contains the partition ID
776 * Set Snoop -- no parameters, SynIC message contains the partition ID
777 * Clear Snoop -- no parameters, SynIC message contains the partition ID
778 * All Offers Delivered -- no parameters, SynIC message contains the partition
779 * ID
780 * Flush Client -- no parameters, SynIC message contains the partition ID
781 */
782
783/* Open Channel parameters */
784struct vmbus_channel_open_channel {
785 struct vmbus_channel_message_header header;
786
787 /* Identifies the specific VMBus channel that is being opened. */
788 u32 child_relid;
789
790 /* ID making a particular open request at a channel offer unique. */
791 u32 openid;
792
793 /* GPADL for the channel's ring buffer. */
794 u32 ringbuffer_gpadlhandle;
795
abbf3b2a
S
796 /*
797 * Starting with win8, this field will be used to specify
798 * the target virtual processor on which to deliver the interrupt for
799 * the host to guest communication.
800 * Prior to win8, incoming channel interrupts would only
801 * be delivered on cpu 0. Setting this value to 0 would
802 * preserve the earlier behavior.
803 */
804 u32 target_vp;
b56dda06
S
805
806 /*
807 * The upstream ring buffer begins at offset zero in the memory
808 * described by RingBufferGpadlHandle. The downstream ring buffer
809 * follows it at this offset (in pages).
810 */
811 u32 downstream_ringbuffer_pageoffset;
812
813 /* User-specific data to be passed along to the server endpoint. */
814 unsigned char userdata[MAX_USER_DEFINED_BYTES];
815} __packed;
816
817/* Open Channel Result parameters */
818struct vmbus_channel_open_result {
819 struct vmbus_channel_message_header header;
820 u32 child_relid;
821 u32 openid;
822 u32 status;
823} __packed;
824
825/* Close channel parameters; */
826struct vmbus_channel_close_channel {
827 struct vmbus_channel_message_header header;
828 u32 child_relid;
829} __packed;
830
831/* Channel Message GPADL */
832#define GPADL_TYPE_RING_BUFFER 1
833#define GPADL_TYPE_SERVER_SAVE_AREA 2
834#define GPADL_TYPE_TRANSACTION 8
835
836/*
837 * The number of PFNs in a GPADL message is defined by the number of
838 * pages that would be spanned by ByteCount and ByteOffset. If the
839 * implied number of PFNs won't fit in this packet, there will be a
840 * follow-up packet that contains more.
841 */
842struct vmbus_channel_gpadl_header {
843 struct vmbus_channel_message_header header;
844 u32 child_relid;
845 u32 gpadl;
846 u16 range_buflen;
847 u16 rangecount;
848 struct gpa_range range[0];
849} __packed;
850
851/* This is the followup packet that contains more PFNs. */
852struct vmbus_channel_gpadl_body {
853 struct vmbus_channel_message_header header;
854 u32 msgnumber;
855 u32 gpadl;
856 u64 pfn[0];
857} __packed;
858
859struct vmbus_channel_gpadl_created {
860 struct vmbus_channel_message_header header;
861 u32 child_relid;
862 u32 gpadl;
863 u32 creation_status;
864} __packed;
865
866struct vmbus_channel_gpadl_teardown {
867 struct vmbus_channel_message_header header;
868 u32 child_relid;
869 u32 gpadl;
870} __packed;
871
872struct vmbus_channel_gpadl_torndown {
873 struct vmbus_channel_message_header header;
874 u32 gpadl;
875} __packed;
876
877#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
878struct vmbus_channel_view_range_add {
879 struct vmbus_channel_message_header header;
880 PHYSICAL_ADDRESS viewrange_base;
881 u64 viewrange_length;
882 u32 child_relid;
883} __packed;
884
885struct vmbus_channel_view_range_remove {
886 struct vmbus_channel_message_header header;
887 PHYSICAL_ADDRESS viewrange_base;
888 u32 child_relid;
889} __packed;
890#endif
891
892struct vmbus_channel_relid_released {
893 struct vmbus_channel_message_header header;
894 u32 child_relid;
895} __packed;
896
897struct vmbus_channel_initiate_contact {
898 struct vmbus_channel_message_header header;
899 u32 vmbus_version_requested;
863a9212 900 u32 target_vcpu; /* The VCPU the host should respond to */
b56dda06
S
901 u64 interrupt_page;
902 u64 monitor_page1;
903 u64 monitor_page2;
904} __packed;
905
906struct vmbus_channel_version_response {
907 struct vmbus_channel_message_header header;
1508d811 908 u8 version_supported;
b56dda06
S
909} __packed;
910
911enum vmbus_channel_state {
912 CHANNEL_OFFER_STATE,
913 CHANNEL_OPENING_STATE,
914 CHANNEL_OPEN_STATE,
915};
916
b56dda06
S
917struct vmbus_channel_debug_info {
918 u32 relid;
919 enum vmbus_channel_state state;
358d2ee2
S
920 uuid_le interfacetype;
921 uuid_le interface_instance;
b56dda06
S
922 u32 monitorid;
923 u32 servermonitor_pending;
924 u32 servermonitor_latency;
925 u32 servermonitor_connectionid;
926 u32 clientmonitor_pending;
927 u32 clientmonitor_latency;
928 u32 clientmonitor_connectionid;
929
930 struct hv_ring_buffer_debug_info inbound;
931 struct hv_ring_buffer_debug_info outbound;
932};
933
934/*
935 * Represents each channel msg on the vmbus connection This is a
936 * variable-size data structure depending on the msg type itself
937 */
938struct vmbus_channel_msginfo {
939 /* Bookkeeping stuff */
940 struct list_head msglistentry;
941
942 /* So far, this is only used to handle gpadl body message */
943 struct list_head submsglist;
944
945 /* Synchronize the request/response if needed */
946 struct completion waitevent;
947 union {
948 struct vmbus_channel_version_supported version_supported;
949 struct vmbus_channel_open_result open_result;
950 struct vmbus_channel_gpadl_torndown gpadl_torndown;
951 struct vmbus_channel_gpadl_created gpadl_created;
952 struct vmbus_channel_version_response version_response;
953 } response;
954
955 u32 msgsize;
956 /*
957 * The channel message that goes out on the "wire".
958 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
959 */
960 unsigned char msg[0];
961};
962
f9f1db83
S
963struct vmbus_close_msg {
964 struct vmbus_channel_msginfo info;
965 struct vmbus_channel_close_channel msg;
966};
967
b3bf60c7
S
968/* Define connection identifier type. */
969union hv_connection_id {
970 u32 asu32;
971 struct {
972 u32 id:24;
973 u32 reserved:8;
974 } u;
975};
976
977/* Definition of the hv_signal_event hypercall input structure. */
978struct hv_input_signal_event {
979 union hv_connection_id connectionid;
980 u16 flag_number;
981 u16 rsvdz;
982};
983
984struct hv_input_signal_event_buffer {
985 u64 align8;
986 struct hv_input_signal_event event;
987};
988
7d7c75cd
S
989struct vmbus_channel {
990 struct list_head listentry;
991
992 struct hv_device *device_obj;
993
994 struct work_struct work;
995
996 enum vmbus_channel_state state;
7d7c75cd
S
997
998 struct vmbus_channel_offer_channel offermsg;
999 /*
1000 * These are based on the OfferMsg.MonitorId.
1001 * Save it here for easy access.
1002 */
1003 u8 monitor_grp;
1004 u8 monitor_bit;
1005
1006 u32 ringbuffer_gpadlhandle;
1007
1008 /* Allocated memory for ring buffer */
1009 void *ringbuffer_pages;
1010 u32 ringbuffer_pagecount;
1011 struct hv_ring_buffer_info outbound; /* send to parent */
1012 struct hv_ring_buffer_info inbound; /* receive from parent */
1013 spinlock_t inbound_lock;
1014 struct workqueue_struct *controlwq;
1015
f9f1db83
S
1016 struct vmbus_close_msg close_msg;
1017
7d7c75cd
S
1018 /* Channel callback are invoked in this workqueue context */
1019 /* HANDLE dataWorkQueue; */
1020
1021 void (*onchannel_callback)(void *context);
1022 void *channel_callback_context;
132368bd
S
1023
1024 /*
1025 * A channel can be marked for efficient (batched)
1026 * reading:
1027 * If batched_reading is set to "true", we read until the
1028 * channel is empty and hold off interrupts from the host
1029 * during the entire read process.
1030 * If batched_reading is set to "false", the client is not
1031 * going to perform batched reading.
1032 *
1033 * By default we will enable batched reading; specific
1034 * drivers that don't want this behavior can turn it off.
1035 */
1036
1037 bool batched_reading;
b3bf60c7
S
1038
1039 bool is_dedicated_interrupt;
1040 struct hv_input_signal_event_buffer sig_buf;
1041 struct hv_input_signal_event *sig_event;
abbf3b2a
S
1042
1043 /*
1044 * Starting with win8, this field will be used to specify
1045 * the target virtual processor on which to deliver the interrupt for
1046 * the host to guest communication.
1047 * Prior to win8, incoming channel interrupts would only
1048 * be delivered on cpu 0. Setting this value to 0 would
1049 * preserve the earlier behavior.
1050 */
1051 u32 target_vp;
7d7c75cd 1052};
b56dda06 1053
132368bd
S
1054static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
1055{
1056 c->batched_reading = state;
1057}
1058
b56dda06
S
1059void vmbus_onmessage(void *context);
1060
1061int vmbus_request_offers(void);
1062
c35470b2
S
1063/* The format must be the same as struct vmdata_gpa_direct */
1064struct vmbus_channel_packet_page_buffer {
1065 u16 type;
1066 u16 dataoffset8;
1067 u16 length8;
1068 u16 flags;
1069 u64 transactionid;
1070 u32 reserved;
1071 u32 rangecount;
1072 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
1073} __packed;
1074
1075/* The format must be the same as struct vmdata_gpa_direct */
1076struct vmbus_channel_packet_multipage_buffer {
1077 u16 type;
1078 u16 dataoffset8;
1079 u16 length8;
1080 u16 flags;
1081 u64 transactionid;
1082 u32 reserved;
1083 u32 rangecount; /* Always 1 in this case */
1084 struct hv_multipage_buffer range;
1085} __packed;
1086
1087
1088extern int vmbus_open(struct vmbus_channel *channel,
1089 u32 send_ringbuffersize,
1090 u32 recv_ringbuffersize,
1091 void *userdata,
1092 u32 userdatalen,
1093 void(*onchannel_callback)(void *context),
1094 void *context);
1095
1096extern void vmbus_close(struct vmbus_channel *channel);
1097
1098extern int vmbus_sendpacket(struct vmbus_channel *channel,
1099 const void *buffer,
1100 u32 bufferLen,
1101 u64 requestid,
1102 enum vmbus_packet_type type,
1103 u32 flags);
1104
1105extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
1106 struct hv_page_buffer pagebuffers[],
1107 u32 pagecount,
1108 void *buffer,
1109 u32 bufferlen,
1110 u64 requestid);
1111
1112extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
1113 struct hv_multipage_buffer *mpb,
1114 void *buffer,
1115 u32 bufferlen,
1116 u64 requestid);
1117
1118extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
1119 void *kbuffer,
1120 u32 size,
1121 u32 *gpadl_handle);
1122
1123extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
1124 u32 gpadl_handle);
1125
1126extern int vmbus_recvpacket(struct vmbus_channel *channel,
1127 void *buffer,
1128 u32 bufferlen,
1129 u32 *buffer_actual_len,
1130 u64 *requestid);
1131
1132extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
1133 void *buffer,
1134 u32 bufferlen,
1135 u32 *buffer_actual_len,
1136 u64 *requestid);
1137
c35470b2
S
1138
1139extern void vmbus_get_debug_info(struct vmbus_channel *channel,
1140 struct vmbus_channel_debug_info *debug);
1141
1142extern void vmbus_ontimer(unsigned long data);
1143
35ea09c3
S
1144struct hv_dev_port_info {
1145 u32 int_mask;
1146 u32 read_idx;
1147 u32 write_idx;
1148 u32 bytes_avail_toread;
1149 u32 bytes_avail_towrite;
1150};
1151
35ea09c3
S
1152/* Base driver object */
1153struct hv_driver {
1154 const char *name;
1155
1156 /* the device type supported by this driver */
358d2ee2 1157 uuid_le dev_type;
2e2c1d17 1158 const struct hv_vmbus_device_id *id_table;
35ea09c3
S
1159
1160 struct device_driver driver;
1161
84946899 1162 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
35ea09c3
S
1163 int (*remove)(struct hv_device *);
1164 void (*shutdown)(struct hv_device *);
1165
1166};
1167
1168/* Base device object */
1169struct hv_device {
1170 /* the device type id of this device */
358d2ee2 1171 uuid_le dev_type;
35ea09c3
S
1172
1173 /* the device instance id of this device */
358d2ee2 1174 uuid_le dev_instance;
35ea09c3
S
1175
1176 struct device device;
1177
1178 struct vmbus_channel *channel;
35ea09c3
S
1179};
1180
27b5b3ca
S
1181
1182static inline struct hv_device *device_to_hv_device(struct device *d)
1183{
1184 return container_of(d, struct hv_device, device);
1185}
1186
1187static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1188{
1189 return container_of(d, struct hv_driver, driver);
1190}
1191
ab101e86
S
1192static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1193{
1194 dev_set_drvdata(&dev->device, data);
1195}
1196
1197static inline void *hv_get_drvdata(struct hv_device *dev)
1198{
1199 return dev_get_drvdata(&dev->device);
1200}
27b5b3ca
S
1201
1202/* Vmbus interface */
768fa219
GKH
1203#define vmbus_driver_register(driver) \
1204 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1205int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1206 struct module *owner,
1207 const char *mod_name);
1208void vmbus_driver_unregister(struct hv_driver *hv_driver);
27b5b3ca 1209
c45cf2d4
GKH
1210/**
1211 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1212 *
1213 * This macro is used to create a struct hv_vmbus_device_id that matches a
1214 * specific device.
1215 */
1216#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1217 g8, g9, ga, gb, gc, gd, ge, gf) \
1218 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1219 g8, g9, ga, gb, gc, gd, ge, gf },
1220
7fb96565
S
1221/*
1222 * GUID definitions of various offer types - services offered to the guest.
1223 */
1224
1225/*
1226 * Network GUID
1227 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1228 */
1229#define HV_NIC_GUID \
1230 .guid = { \
1231 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1232 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1233 }
1234
1235/*
1236 * IDE GUID
1237 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1238 */
1239#define HV_IDE_GUID \
1240 .guid = { \
1241 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1242 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1243 }
1244
1245/*
1246 * SCSI GUID
1247 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1248 */
1249#define HV_SCSI_GUID \
1250 .guid = { \
1251 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1252 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1253 }
1254
1255/*
1256 * Shutdown GUID
1257 * {0e0b6031-5213-4934-818b-38d90ced39db}
1258 */
1259#define HV_SHUTDOWN_GUID \
1260 .guid = { \
1261 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1262 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1263 }
1264
1265/*
1266 * Time Synch GUID
1267 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1268 */
1269#define HV_TS_GUID \
1270 .guid = { \
1271 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1272 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1273 }
1274
1275/*
1276 * Heartbeat GUID
1277 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1278 */
1279#define HV_HEART_BEAT_GUID \
1280 .guid = { \
1281 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1282 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1283 }
1284
1285/*
1286 * KVP GUID
1287 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1288 */
1289#define HV_KVP_GUID \
1290 .guid = { \
1291 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1292 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1293 }
1294
1295/*
1296 * Dynamic memory GUID
1297 * {525074dc-8985-46e2-8057-a307dc18a502}
1298 */
1299#define HV_DM_GUID \
1300 .guid = { \
1301 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1302 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1303 }
1304
1305/*
1306 * Mouse GUID
1307 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1308 */
1309#define HV_MOUSE_GUID \
1310 .guid = { \
1311 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1312 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1313 }
1314
96dd86fa
S
1315/*
1316 * VSS (Backup/Restore) GUID
1317 */
1318#define HV_VSS_GUID \
1319 .guid = { \
1320 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1321 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1322 }
68a2d20b
HZ
1323/*
1324 * Synthetic Video GUID
1325 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1326 */
1327#define HV_SYNTHVID_GUID \
1328 .guid = { \
1329 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
1330 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
1331 }
1332
1333
b189702d
S
1334/*
1335 * Common header for Hyper-V ICs
1336 */
1337
1338#define ICMSGTYPE_NEGOTIATE 0
1339#define ICMSGTYPE_HEARTBEAT 1
1340#define ICMSGTYPE_KVPEXCHANGE 2
1341#define ICMSGTYPE_SHUTDOWN 3
1342#define ICMSGTYPE_TIMESYNC 4
1343#define ICMSGTYPE_VSS 5
1344
1345#define ICMSGHDRFLAG_TRANSACTION 1
1346#define ICMSGHDRFLAG_REQUEST 2
1347#define ICMSGHDRFLAG_RESPONSE 4
1348
b189702d 1349
a29b643c
S
1350/*
1351 * While we want to handle util services as regular devices,
1352 * there is only one instance of each of these services; so
1353 * we statically allocate the service specific state.
1354 */
1355
1356struct hv_util_service {
1357 u8 *recv_buffer;
1358 void (*util_cb)(void *);
1359 int (*util_init)(struct hv_util_service *);
1360 void (*util_deinit)(void);
1361};
1362
b189702d
S
1363struct vmbuspipe_hdr {
1364 u32 flags;
1365 u32 msgsize;
1366} __packed;
1367
1368struct ic_version {
1369 u16 major;
1370 u16 minor;
1371} __packed;
1372
1373struct icmsg_hdr {
1374 struct ic_version icverframe;
1375 u16 icmsgtype;
1376 struct ic_version icvermsg;
1377 u16 icmsgsize;
1378 u32 status;
1379 u8 ictransaction_id;
1380 u8 icflags;
1381 u8 reserved[2];
1382} __packed;
1383
1384struct icmsg_negotiate {
1385 u16 icframe_vercnt;
1386 u16 icmsg_vercnt;
1387 u32 reserved;
1388 struct ic_version icversion_data[1]; /* any size array */
1389} __packed;
1390
1391struct shutdown_msg_data {
1392 u32 reason_code;
1393 u32 timeout_seconds;
1394 u32 flags;
1395 u8 display_message[2048];
1396} __packed;
1397
1398struct heartbeat_msg_data {
1399 u64 seq_num;
1400 u32 reserved[8];
1401} __packed;
1402
1403/* Time Sync IC defs */
1404#define ICTIMESYNCFLAG_PROBE 0
1405#define ICTIMESYNCFLAG_SYNC 1
1406#define ICTIMESYNCFLAG_SAMPLE 2
1407
1408#ifdef __x86_64__
1409#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1410#else
1411#define WLTIMEDELTA 116444736000000000LL
1412#endif
1413
1414struct ictimesync_data {
1415 u64 parenttime;
1416 u64 childtime;
1417 u64 roundtriptime;
1418 u8 flags;
1419} __packed;
1420
b189702d
S
1421struct hyperv_service_callback {
1422 u8 msg_type;
1423 char *log_msg;
358d2ee2 1424 uuid_le data;
b189702d
S
1425 struct vmbus_channel *channel;
1426 void (*callback) (void *context);
1427};
1428
c836d0ab 1429#define MAX_SRV_VER 0x7ffffff
da0e9631 1430extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
c836d0ab
S
1431 struct icmsg_negotiate *, u8 *, int,
1432 int);
b189702d 1433
2939437c
S
1434int hv_kvp_init(struct hv_util_service *);
1435void hv_kvp_deinit(void);
1436void hv_kvp_onchannelcallback(void *);
1437
96dd86fa
S
1438int hv_vss_init(struct hv_util_service *);
1439void hv_vss_deinit(void);
1440void hv_vss_onchannelcallback(void *);
1441
37f7278b
S
1442/*
1443 * Negotiated version with the Host.
1444 */
1445
1446extern __u32 vmbus_proto_version;
1447
2939437c 1448#endif /* __KERNEL__ */
3f335ea2 1449#endif /* _HYPERV_H */