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