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