ACPI: remove duplicated lines of merging problems with acpi_processor_start
[linux-block.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
30/*
31 * An implementation of HyperV key value pair (KVP) functionality for Linux.
32 *
33 *
34 * Copyright (C) 2010, Novell, Inc.
35 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
36 *
37 */
38
39/*
40 * Maximum value size - used for both key names and value data, and includes
41 * any applicable NULL terminators.
42 *
43 * Note: This limit is somewhat arbitrary, but falls easily within what is
44 * supported for all native guests (back to Win 2000) and what is reasonable
45 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
46 * limited to 255 character key names.
47 *
48 * MSDN recommends not storing data values larger than 2048 bytes in the
49 * registry.
50 *
51 * Note: This value is used in defining the KVP exchange message - this value
52 * cannot be modified without affecting the message size and compatibility.
53 */
54
55/*
56 * bytes, including any null terminators
57 */
58#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
59
60
61/*
62 * Maximum key size - the registry limit for the length of an entry name
63 * is 256 characters, including the null terminator
64 */
65
66#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
67
68/*
69 * In Linux, we implement the KVP functionality in two components:
70 * 1) The kernel component which is packaged as part of the hv_utils driver
71 * is responsible for communicating with the host and responsible for
72 * implementing the host/guest protocol. 2) A user level daemon that is
73 * responsible for data gathering.
74 *
75 * Host/Guest Protocol: The host iterates over an index and expects the guest
76 * to assign a key name to the index and also return the value corresponding to
77 * the key. The host will have atmost one KVP transaction outstanding at any
78 * given point in time. The host side iteration stops when the guest returns
79 * an error. Microsoft has specified the following mapping of key names to
80 * host specified index:
81 *
82 * Index Key Name
83 * 0 FullyQualifiedDomainName
84 * 1 IntegrationServicesVersion
85 * 2 NetworkAddressIPv4
86 * 3 NetworkAddressIPv6
87 * 4 OSBuildNumber
88 * 5 OSName
89 * 6 OSMajorVersion
90 * 7 OSMinorVersion
91 * 8 OSVersion
92 * 9 ProcessorArchitecture
93 *
94 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
95 *
96 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
97 * data gathering functionality in a user mode daemon. The user level daemon
98 * is also responsible for binding the key name to the index as well. The
99 * kernel and user-level daemon communicate using a connector channel.
100 *
101 * The user mode component first registers with the
102 * the kernel component. Subsequently, the kernel component requests, data
103 * for the specified keys. In response to this message the user mode component
104 * fills in the value corresponding to the specified key. We overload the
105 * sequence field in the cn_msg header to define our KVP message types.
106 *
107 *
108 * The kernel component simply acts as a conduit for communication between the
109 * Windows host and the user-level daemon. The kernel component passes up the
110 * index received from the Host to the user-level daemon. If the index is
111 * valid (supported), the corresponding key as well as its
112 * value (both are strings) is returned. If the index is invalid
113 * (not supported), a NULL key string is returned.
114 */
115
116/*
117 *
118 * The following definitions are shared with the user-mode component; do not
119 * change any of this without making the corresponding changes in
120 * the KVP user-mode component.
121 */
122
123enum hv_ku_op {
124 KVP_REGISTER = 0, /* Register the user mode component */
125 KVP_KERNEL_GET, /* Kernel is requesting the value */
126 KVP_KERNEL_SET, /* Kernel is providing the value */
127 KVP_USER_GET, /* User is requesting the value */
128 KVP_USER_SET /* User is providing the value */
129};
130
131struct hv_ku_msg {
132 __u32 kvp_index; /* Key index */
133 __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
134 __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
135};
136
137
138
139
140#ifdef __KERNEL__
141
142/*
143 * Registry value types.
144 */
145
146#define REG_SZ 1
147
148enum hv_kvp_exchg_op {
149 KVP_OP_GET = 0,
150 KVP_OP_SET,
151 KVP_OP_DELETE,
152 KVP_OP_ENUMERATE,
153 KVP_OP_COUNT /* Number of operations, must be last. */
154};
155
156enum hv_kvp_exchg_pool {
157 KVP_POOL_EXTERNAL = 0,
158 KVP_POOL_GUEST,
159 KVP_POOL_AUTO,
160 KVP_POOL_AUTO_EXTERNAL,
161 KVP_POOL_AUTO_INTERNAL,
162 KVP_POOL_COUNT /* Number of pools, must be last. */
163};
164
165struct hv_kvp_hdr {
166 u8 operation;
167 u8 pool;
168};
169
170struct hv_kvp_exchg_msg_value {
171 u32 value_type;
172 u32 key_size;
173 u32 value_size;
174 u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
175 u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
176};
177
178struct hv_kvp_msg_enumerate {
179 u32 index;
180 struct hv_kvp_exchg_msg_value data;
181};
182
183struct hv_kvp_msg {
184 struct hv_kvp_hdr kvp_hdr;
185 struct hv_kvp_msg_enumerate kvp_data;
186};
187
8ff3e6fc
S
188#include <linux/scatterlist.h>
189#include <linux/list.h>
358d2ee2 190#include <linux/uuid.h>
8ff3e6fc
S
191#include <linux/timer.h>
192#include <linux/workqueue.h>
193#include <linux/completion.h>
194#include <linux/device.h>
2e2c1d17 195#include <linux/mod_devicetable.h>
8ff3e6fc
S
196
197
4d447c9a 198#define MAX_PAGE_BUFFER_COUNT 18
a363bf7b
S
199#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
200
201#pragma pack(push, 1)
202
203/* Single-page buffer */
204struct hv_page_buffer {
205 u32 len;
206 u32 offset;
207 u64 pfn;
208};
209
210/* Multiple-page buffer */
211struct hv_multipage_buffer {
212 /* Length and Offset determines the # of pfns in the array */
213 u32 len;
214 u32 offset;
215 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
216};
217
218/* 0x18 includes the proprietary packet header */
219#define MAX_PAGE_BUFFER_PACKET (0x18 + \
220 (sizeof(struct hv_page_buffer) * \
221 MAX_PAGE_BUFFER_COUNT))
222#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
223 sizeof(struct hv_multipage_buffer))
224
225
226#pragma pack(pop)
227
7effffb7
S
228struct hv_ring_buffer {
229 /* Offset in bytes from the start of ring data below */
230 u32 write_index;
231
232 /* Offset in bytes from the start of ring data below */
233 u32 read_index;
234
235 u32 interrupt_mask;
236
237 /* Pad it to PAGE_SIZE so that data starts on page boundary */
238 u8 reserved[4084];
239
240 /* NOTE:
241 * The interrupt_mask field is used only for channels but since our
242 * vmbus connection also uses this data structure and its data starts
243 * here, we commented out this field.
244 */
245
246 /*
247 * Ring data starts here + RingDataStartOffset
248 * !!! DO NOT place any fields below this !!!
249 */
250 u8 buffer[0];
251} __packed;
252
253struct hv_ring_buffer_info {
254 struct hv_ring_buffer *ring_buffer;
255 u32 ring_size; /* Include the shared header */
256 spinlock_t ring_lock;
257
258 u32 ring_datasize; /* < ring_size */
259 u32 ring_data_startoffset;
260};
261
262struct hv_ring_buffer_debug_info {
263 u32 current_interrupt_mask;
264 u32 current_read_index;
265 u32 current_write_index;
266 u32 bytes_avail_toread;
267 u32 bytes_avail_towrite;
268};
3f335ea2 269
f7c6dfda
S
270/*
271 * We use the same version numbering for all Hyper-V modules.
272 *
273 * Definition of versioning is as follows;
274 *
275 * Major Number Changes for these scenarios;
276 * 1. When a new version of Windows Hyper-V
277 * is released.
278 * 2. A Major change has occurred in the
279 * Linux IC's.
280 * (For example the merge for the first time
281 * into the kernel) Every time the Major Number
282 * changes, the Revision number is reset to 0.
283 * Minor Number Changes when new functionality is added
284 * to the Linux IC's that is not a bug fix.
285 *
286 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
287 */
288#define HV_DRV_VERSION "3.1"
289
290
517d8dc6
S
291/*
292 * A revision number of vmbus that is used for ensuring both ends on a
293 * partition are using compatible versions.
294 */
295#define VMBUS_REVISION_NUMBER 13
296
297/* Make maximum size of pipe payload of 16K */
298#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
299
300/* Define PipeMode values. */
301#define VMBUS_PIPE_TYPE_BYTE 0x00000000
302#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
303
304/* The size of the user defined data buffer for non-pipe offers. */
305#define MAX_USER_DEFINED_BYTES 120
306
307/* The size of the user defined data buffer for pipe offers. */
308#define MAX_PIPE_USER_DEFINED_BYTES 116
309
310/*
311 * At the center of the Channel Management library is the Channel Offer. This
312 * struct contains the fundamental information about an offer.
313 */
314struct vmbus_channel_offer {
358d2ee2
S
315 uuid_le if_type;
316 uuid_le if_instance;
517d8dc6
S
317 u64 int_latency; /* in 100ns units */
318 u32 if_revision;
319 u32 server_ctx_size; /* in bytes */
320 u16 chn_flags;
321 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
322
323 union {
324 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
325 struct {
326 unsigned char user_def[MAX_USER_DEFINED_BYTES];
327 } std;
328
329 /*
330 * Pipes:
331 * The following sructure is an integrated pipe protocol, which
332 * is implemented on top of standard user-defined data. Pipe
333 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
334 * use.
335 */
336 struct {
337 u32 pipe_mode;
338 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
339 } pipe;
340 } u;
341 u32 padding;
342} __packed;
343
344/* Server Flags */
345#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
346#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
347#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
348#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
349#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
350#define VMBUS_CHANNEL_PARENT_OFFER 0x200
351#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
352
50ed40e0
S
353struct vmpacket_descriptor {
354 u16 type;
355 u16 offset8;
356 u16 len8;
357 u16 flags;
358 u64 trans_id;
359} __packed;
360
361struct vmpacket_header {
362 u32 prev_pkt_start_offset;
363 struct vmpacket_descriptor descriptor;
364} __packed;
365
366struct vmtransfer_page_range {
367 u32 byte_count;
368 u32 byte_offset;
369} __packed;
370
371struct vmtransfer_page_packet_header {
372 struct vmpacket_descriptor d;
373 u16 xfer_pageset_id;
374 bool sender_owns_set;
375 u8 reserved;
376 u32 range_cnt;
377 struct vmtransfer_page_range ranges[1];
378} __packed;
379
380struct vmgpadl_packet_header {
381 struct vmpacket_descriptor d;
382 u32 gpadl;
383 u32 reserved;
384} __packed;
385
386struct vmadd_remove_transfer_page_set {
387 struct vmpacket_descriptor d;
388 u32 gpadl;
389 u16 xfer_pageset_id;
390 u16 reserved;
391} __packed;
392
393/*
394 * This structure defines a range in guest physical space that can be made to
395 * look virtually contiguous.
396 */
397struct gpa_range {
398 u32 byte_count;
399 u32 byte_offset;
400 u64 pfn_array[0];
401};
402
403/*
404 * This is the format for an Establish Gpadl packet, which contains a handle by
405 * which this GPADL will be known and a set of GPA ranges associated with it.
406 * This can be converted to a MDL by the guest OS. If there are multiple GPA
407 * ranges, then the resulting MDL will be "chained," representing multiple VA
408 * ranges.
409 */
410struct vmestablish_gpadl {
411 struct vmpacket_descriptor d;
412 u32 gpadl;
413 u32 range_cnt;
414 struct gpa_range range[1];
415} __packed;
416
417/*
418 * This is the format for a Teardown Gpadl packet, which indicates that the
419 * GPADL handle in the Establish Gpadl packet will never be referenced again.
420 */
421struct vmteardown_gpadl {
422 struct vmpacket_descriptor d;
423 u32 gpadl;
424 u32 reserved; /* for alignment to a 8-byte boundary */
425} __packed;
426
427/*
428 * This is the format for a GPA-Direct packet, which contains a set of GPA
429 * ranges, in addition to commands and/or data.
430 */
431struct vmdata_gpa_direct {
432 struct vmpacket_descriptor d;
433 u32 reserved;
434 u32 range_cnt;
435 struct gpa_range range[1];
436} __packed;
437
438/* This is the format for a Additional Data Packet. */
439struct vmadditional_data {
440 struct vmpacket_descriptor d;
441 u64 total_bytes;
442 u32 offset;
443 u32 byte_cnt;
444 unsigned char data[1];
445} __packed;
446
447union vmpacket_largest_possible_header {
448 struct vmpacket_descriptor simple_hdr;
449 struct vmtransfer_page_packet_header xfer_page_hdr;
450 struct vmgpadl_packet_header gpadl_hdr;
451 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
452 struct vmestablish_gpadl establish_gpadl_hdr;
453 struct vmteardown_gpadl teardown_gpadl_hdr;
454 struct vmdata_gpa_direct data_gpa_direct_hdr;
455};
456
457#define VMPACKET_DATA_START_ADDRESS(__packet) \
458 (void *)(((unsigned char *)__packet) + \
459 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
460
461#define VMPACKET_DATA_LENGTH(__packet) \
462 ((((struct vmpacket_descriptor)__packet)->len8 - \
463 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
464
465#define VMPACKET_TRANSFER_MODE(__packet) \
466 (((struct IMPACT)__packet)->type)
467
468enum vmbus_packet_type {
469 VM_PKT_INVALID = 0x0,
470 VM_PKT_SYNCH = 0x1,
471 VM_PKT_ADD_XFER_PAGESET = 0x2,
472 VM_PKT_RM_XFER_PAGESET = 0x3,
473 VM_PKT_ESTABLISH_GPADL = 0x4,
474 VM_PKT_TEARDOWN_GPADL = 0x5,
475 VM_PKT_DATA_INBAND = 0x6,
476 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
477 VM_PKT_DATA_USING_GPADL = 0x8,
478 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
479 VM_PKT_CANCEL_REQUEST = 0xa,
480 VM_PKT_COMP = 0xb,
481 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
482 VM_PKT_ADDITIONAL_DATA = 0xd
483};
484
485#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
517d8dc6 486
b56dda06 487
b56dda06
S
488/* Version 1 messages */
489enum vmbus_channel_message_type {
490 CHANNELMSG_INVALID = 0,
491 CHANNELMSG_OFFERCHANNEL = 1,
492 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
493 CHANNELMSG_REQUESTOFFERS = 3,
494 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
495 CHANNELMSG_OPENCHANNEL = 5,
496 CHANNELMSG_OPENCHANNEL_RESULT = 6,
497 CHANNELMSG_CLOSECHANNEL = 7,
498 CHANNELMSG_GPADL_HEADER = 8,
499 CHANNELMSG_GPADL_BODY = 9,
500 CHANNELMSG_GPADL_CREATED = 10,
501 CHANNELMSG_GPADL_TEARDOWN = 11,
502 CHANNELMSG_GPADL_TORNDOWN = 12,
503 CHANNELMSG_RELID_RELEASED = 13,
504 CHANNELMSG_INITIATE_CONTACT = 14,
505 CHANNELMSG_VERSION_RESPONSE = 15,
506 CHANNELMSG_UNLOAD = 16,
507#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
508 CHANNELMSG_VIEWRANGE_ADD = 17,
509 CHANNELMSG_VIEWRANGE_REMOVE = 18,
510#endif
511 CHANNELMSG_COUNT
512};
513
514struct vmbus_channel_message_header {
515 enum vmbus_channel_message_type msgtype;
516 u32 padding;
517} __packed;
518
519/* Query VMBus Version parameters */
520struct vmbus_channel_query_vmbus_version {
521 struct vmbus_channel_message_header header;
522 u32 version;
523} __packed;
524
525/* VMBus Version Supported parameters */
526struct vmbus_channel_version_supported {
527 struct vmbus_channel_message_header header;
528 bool version_supported;
529} __packed;
530
531/* Offer Channel parameters */
532struct vmbus_channel_offer_channel {
533 struct vmbus_channel_message_header header;
534 struct vmbus_channel_offer offer;
535 u32 child_relid;
536 u8 monitorid;
537 bool monitor_allocated;
538} __packed;
539
540/* Rescind Offer parameters */
541struct vmbus_channel_rescind_offer {
542 struct vmbus_channel_message_header header;
543 u32 child_relid;
544} __packed;
545
546/*
547 * Request Offer -- no parameters, SynIC message contains the partition ID
548 * Set Snoop -- no parameters, SynIC message contains the partition ID
549 * Clear Snoop -- no parameters, SynIC message contains the partition ID
550 * All Offers Delivered -- no parameters, SynIC message contains the partition
551 * ID
552 * Flush Client -- no parameters, SynIC message contains the partition ID
553 */
554
555/* Open Channel parameters */
556struct vmbus_channel_open_channel {
557 struct vmbus_channel_message_header header;
558
559 /* Identifies the specific VMBus channel that is being opened. */
560 u32 child_relid;
561
562 /* ID making a particular open request at a channel offer unique. */
563 u32 openid;
564
565 /* GPADL for the channel's ring buffer. */
566 u32 ringbuffer_gpadlhandle;
567
568 /* GPADL for the channel's server context save area. */
569 u32 server_contextarea_gpadlhandle;
570
571 /*
572 * The upstream ring buffer begins at offset zero in the memory
573 * described by RingBufferGpadlHandle. The downstream ring buffer
574 * follows it at this offset (in pages).
575 */
576 u32 downstream_ringbuffer_pageoffset;
577
578 /* User-specific data to be passed along to the server endpoint. */
579 unsigned char userdata[MAX_USER_DEFINED_BYTES];
580} __packed;
581
582/* Open Channel Result parameters */
583struct vmbus_channel_open_result {
584 struct vmbus_channel_message_header header;
585 u32 child_relid;
586 u32 openid;
587 u32 status;
588} __packed;
589
590/* Close channel parameters; */
591struct vmbus_channel_close_channel {
592 struct vmbus_channel_message_header header;
593 u32 child_relid;
594} __packed;
595
596/* Channel Message GPADL */
597#define GPADL_TYPE_RING_BUFFER 1
598#define GPADL_TYPE_SERVER_SAVE_AREA 2
599#define GPADL_TYPE_TRANSACTION 8
600
601/*
602 * The number of PFNs in a GPADL message is defined by the number of
603 * pages that would be spanned by ByteCount and ByteOffset. If the
604 * implied number of PFNs won't fit in this packet, there will be a
605 * follow-up packet that contains more.
606 */
607struct vmbus_channel_gpadl_header {
608 struct vmbus_channel_message_header header;
609 u32 child_relid;
610 u32 gpadl;
611 u16 range_buflen;
612 u16 rangecount;
613 struct gpa_range range[0];
614} __packed;
615
616/* This is the followup packet that contains more PFNs. */
617struct vmbus_channel_gpadl_body {
618 struct vmbus_channel_message_header header;
619 u32 msgnumber;
620 u32 gpadl;
621 u64 pfn[0];
622} __packed;
623
624struct vmbus_channel_gpadl_created {
625 struct vmbus_channel_message_header header;
626 u32 child_relid;
627 u32 gpadl;
628 u32 creation_status;
629} __packed;
630
631struct vmbus_channel_gpadl_teardown {
632 struct vmbus_channel_message_header header;
633 u32 child_relid;
634 u32 gpadl;
635} __packed;
636
637struct vmbus_channel_gpadl_torndown {
638 struct vmbus_channel_message_header header;
639 u32 gpadl;
640} __packed;
641
642#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
643struct vmbus_channel_view_range_add {
644 struct vmbus_channel_message_header header;
645 PHYSICAL_ADDRESS viewrange_base;
646 u64 viewrange_length;
647 u32 child_relid;
648} __packed;
649
650struct vmbus_channel_view_range_remove {
651 struct vmbus_channel_message_header header;
652 PHYSICAL_ADDRESS viewrange_base;
653 u32 child_relid;
654} __packed;
655#endif
656
657struct vmbus_channel_relid_released {
658 struct vmbus_channel_message_header header;
659 u32 child_relid;
660} __packed;
661
662struct vmbus_channel_initiate_contact {
663 struct vmbus_channel_message_header header;
664 u32 vmbus_version_requested;
665 u32 padding2;
666 u64 interrupt_page;
667 u64 monitor_page1;
668 u64 monitor_page2;
669} __packed;
670
671struct vmbus_channel_version_response {
672 struct vmbus_channel_message_header header;
673 bool version_supported;
674} __packed;
675
676enum vmbus_channel_state {
677 CHANNEL_OFFER_STATE,
678 CHANNEL_OPENING_STATE,
679 CHANNEL_OPEN_STATE,
680};
681
b56dda06
S
682struct vmbus_channel_debug_info {
683 u32 relid;
684 enum vmbus_channel_state state;
358d2ee2
S
685 uuid_le interfacetype;
686 uuid_le interface_instance;
b56dda06
S
687 u32 monitorid;
688 u32 servermonitor_pending;
689 u32 servermonitor_latency;
690 u32 servermonitor_connectionid;
691 u32 clientmonitor_pending;
692 u32 clientmonitor_latency;
693 u32 clientmonitor_connectionid;
694
695 struct hv_ring_buffer_debug_info inbound;
696 struct hv_ring_buffer_debug_info outbound;
697};
698
699/*
700 * Represents each channel msg on the vmbus connection This is a
701 * variable-size data structure depending on the msg type itself
702 */
703struct vmbus_channel_msginfo {
704 /* Bookkeeping stuff */
705 struct list_head msglistentry;
706
707 /* So far, this is only used to handle gpadl body message */
708 struct list_head submsglist;
709
710 /* Synchronize the request/response if needed */
711 struct completion waitevent;
712 union {
713 struct vmbus_channel_version_supported version_supported;
714 struct vmbus_channel_open_result open_result;
715 struct vmbus_channel_gpadl_torndown gpadl_torndown;
716 struct vmbus_channel_gpadl_created gpadl_created;
717 struct vmbus_channel_version_response version_response;
718 } response;
719
720 u32 msgsize;
721 /*
722 * The channel message that goes out on the "wire".
723 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
724 */
725 unsigned char msg[0];
726};
727
f9f1db83
S
728struct vmbus_close_msg {
729 struct vmbus_channel_msginfo info;
730 struct vmbus_channel_close_channel msg;
731};
732
7d7c75cd
S
733struct vmbus_channel {
734 struct list_head listentry;
735
736 struct hv_device *device_obj;
737
738 struct work_struct work;
739
740 enum vmbus_channel_state state;
7d7c75cd
S
741
742 struct vmbus_channel_offer_channel offermsg;
743 /*
744 * These are based on the OfferMsg.MonitorId.
745 * Save it here for easy access.
746 */
747 u8 monitor_grp;
748 u8 monitor_bit;
749
750 u32 ringbuffer_gpadlhandle;
751
752 /* Allocated memory for ring buffer */
753 void *ringbuffer_pages;
754 u32 ringbuffer_pagecount;
755 struct hv_ring_buffer_info outbound; /* send to parent */
756 struct hv_ring_buffer_info inbound; /* receive from parent */
757 spinlock_t inbound_lock;
758 struct workqueue_struct *controlwq;
759
f9f1db83
S
760 struct vmbus_close_msg close_msg;
761
7d7c75cd
S
762 /* Channel callback are invoked in this workqueue context */
763 /* HANDLE dataWorkQueue; */
764
765 void (*onchannel_callback)(void *context);
766 void *channel_callback_context;
767};
b56dda06 768
b56dda06
S
769void vmbus_onmessage(void *context);
770
771int vmbus_request_offers(void);
772
c35470b2
S
773/* The format must be the same as struct vmdata_gpa_direct */
774struct vmbus_channel_packet_page_buffer {
775 u16 type;
776 u16 dataoffset8;
777 u16 length8;
778 u16 flags;
779 u64 transactionid;
780 u32 reserved;
781 u32 rangecount;
782 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
783} __packed;
784
785/* The format must be the same as struct vmdata_gpa_direct */
786struct vmbus_channel_packet_multipage_buffer {
787 u16 type;
788 u16 dataoffset8;
789 u16 length8;
790 u16 flags;
791 u64 transactionid;
792 u32 reserved;
793 u32 rangecount; /* Always 1 in this case */
794 struct hv_multipage_buffer range;
795} __packed;
796
797
798extern int vmbus_open(struct vmbus_channel *channel,
799 u32 send_ringbuffersize,
800 u32 recv_ringbuffersize,
801 void *userdata,
802 u32 userdatalen,
803 void(*onchannel_callback)(void *context),
804 void *context);
805
806extern void vmbus_close(struct vmbus_channel *channel);
807
808extern int vmbus_sendpacket(struct vmbus_channel *channel,
809 const void *buffer,
810 u32 bufferLen,
811 u64 requestid,
812 enum vmbus_packet_type type,
813 u32 flags);
814
815extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
816 struct hv_page_buffer pagebuffers[],
817 u32 pagecount,
818 void *buffer,
819 u32 bufferlen,
820 u64 requestid);
821
822extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
823 struct hv_multipage_buffer *mpb,
824 void *buffer,
825 u32 bufferlen,
826 u64 requestid);
827
828extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
829 void *kbuffer,
830 u32 size,
831 u32 *gpadl_handle);
832
833extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
834 u32 gpadl_handle);
835
836extern int vmbus_recvpacket(struct vmbus_channel *channel,
837 void *buffer,
838 u32 bufferlen,
839 u32 *buffer_actual_len,
840 u64 *requestid);
841
842extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
843 void *buffer,
844 u32 bufferlen,
845 u32 *buffer_actual_len,
846 u64 *requestid);
847
c35470b2
S
848
849extern void vmbus_get_debug_info(struct vmbus_channel *channel,
850 struct vmbus_channel_debug_info *debug);
851
852extern void vmbus_ontimer(unsigned long data);
853
35ea09c3
S
854struct hv_dev_port_info {
855 u32 int_mask;
856 u32 read_idx;
857 u32 write_idx;
858 u32 bytes_avail_toread;
859 u32 bytes_avail_towrite;
860};
861
35ea09c3
S
862/* Base driver object */
863struct hv_driver {
864 const char *name;
865
866 /* the device type supported by this driver */
358d2ee2 867 uuid_le dev_type;
2e2c1d17 868 const struct hv_vmbus_device_id *id_table;
35ea09c3
S
869
870 struct device_driver driver;
871
84946899 872 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
35ea09c3
S
873 int (*remove)(struct hv_device *);
874 void (*shutdown)(struct hv_device *);
875
876};
877
878/* Base device object */
879struct hv_device {
880 /* the device type id of this device */
358d2ee2 881 uuid_le dev_type;
35ea09c3
S
882
883 /* the device instance id of this device */
358d2ee2 884 uuid_le dev_instance;
35ea09c3
S
885
886 struct device device;
887
888 struct vmbus_channel *channel;
35ea09c3
S
889};
890
27b5b3ca
S
891
892static inline struct hv_device *device_to_hv_device(struct device *d)
893{
894 return container_of(d, struct hv_device, device);
895}
896
897static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
898{
899 return container_of(d, struct hv_driver, driver);
900}
901
ab101e86
S
902static inline void hv_set_drvdata(struct hv_device *dev, void *data)
903{
904 dev_set_drvdata(&dev->device, data);
905}
906
907static inline void *hv_get_drvdata(struct hv_device *dev)
908{
909 return dev_get_drvdata(&dev->device);
910}
27b5b3ca
S
911
912/* Vmbus interface */
768fa219
GKH
913#define vmbus_driver_register(driver) \
914 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
915int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
916 struct module *owner,
917 const char *mod_name);
918void vmbus_driver_unregister(struct hv_driver *hv_driver);
27b5b3ca 919
c45cf2d4
GKH
920/**
921 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
922 *
923 * This macro is used to create a struct hv_vmbus_device_id that matches a
924 * specific device.
925 */
926#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
927 g8, g9, ga, gb, gc, gd, ge, gf) \
928 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
929 g8, g9, ga, gb, gc, gd, ge, gf },
930
b189702d
S
931/*
932 * Common header for Hyper-V ICs
933 */
934
935#define ICMSGTYPE_NEGOTIATE 0
936#define ICMSGTYPE_HEARTBEAT 1
937#define ICMSGTYPE_KVPEXCHANGE 2
938#define ICMSGTYPE_SHUTDOWN 3
939#define ICMSGTYPE_TIMESYNC 4
940#define ICMSGTYPE_VSS 5
941
942#define ICMSGHDRFLAG_TRANSACTION 1
943#define ICMSGHDRFLAG_REQUEST 2
944#define ICMSGHDRFLAG_RESPONSE 4
945
946#define HV_S_OK 0x00000000
947#define HV_E_FAIL 0x80004005
948#define HV_ERROR_NOT_SUPPORTED 0x80070032
949#define HV_ERROR_MACHINE_LOCKED 0x800704F7
950
a29b643c
S
951/*
952 * While we want to handle util services as regular devices,
953 * there is only one instance of each of these services; so
954 * we statically allocate the service specific state.
955 */
956
957struct hv_util_service {
958 u8 *recv_buffer;
959 void (*util_cb)(void *);
960 int (*util_init)(struct hv_util_service *);
961 void (*util_deinit)(void);
962};
963
b189702d
S
964struct vmbuspipe_hdr {
965 u32 flags;
966 u32 msgsize;
967} __packed;
968
969struct ic_version {
970 u16 major;
971 u16 minor;
972} __packed;
973
974struct icmsg_hdr {
975 struct ic_version icverframe;
976 u16 icmsgtype;
977 struct ic_version icvermsg;
978 u16 icmsgsize;
979 u32 status;
980 u8 ictransaction_id;
981 u8 icflags;
982 u8 reserved[2];
983} __packed;
984
985struct icmsg_negotiate {
986 u16 icframe_vercnt;
987 u16 icmsg_vercnt;
988 u32 reserved;
989 struct ic_version icversion_data[1]; /* any size array */
990} __packed;
991
992struct shutdown_msg_data {
993 u32 reason_code;
994 u32 timeout_seconds;
995 u32 flags;
996 u8 display_message[2048];
997} __packed;
998
999struct heartbeat_msg_data {
1000 u64 seq_num;
1001 u32 reserved[8];
1002} __packed;
1003
1004/* Time Sync IC defs */
1005#define ICTIMESYNCFLAG_PROBE 0
1006#define ICTIMESYNCFLAG_SYNC 1
1007#define ICTIMESYNCFLAG_SAMPLE 2
1008
1009#ifdef __x86_64__
1010#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1011#else
1012#define WLTIMEDELTA 116444736000000000LL
1013#endif
1014
1015struct ictimesync_data {
1016 u64 parenttime;
1017 u64 childtime;
1018 u64 roundtriptime;
1019 u8 flags;
1020} __packed;
1021
b189702d
S
1022struct hyperv_service_callback {
1023 u8 msg_type;
1024 char *log_msg;
358d2ee2 1025 uuid_le data;
b189702d
S
1026 struct vmbus_channel *channel;
1027 void (*callback) (void *context);
1028};
1029
da0e9631
GKH
1030extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
1031 struct icmsg_negotiate *, u8 *);
b189702d 1032
2939437c
S
1033int hv_kvp_init(struct hv_util_service *);
1034void hv_kvp_deinit(void);
1035void hv_kvp_onchannelcallback(void *);
1036
1037#endif /* __KERNEL__ */
3f335ea2 1038#endif /* _HYPERV_H */