Tools: hv: Add an example script to configure an interface
[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
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
2939437c
S
116
117/*
118 * Registry value types.
119 */
120
121#define REG_SZ 1
fa3d5b85
S
122#define REG_U32 4
123#define REG_U64 8
2939437c 124
9b595780
S
125/*
126 * As we look at expanding the KVP functionality to include
127 * IP injection functionality, we need to maintain binary
128 * compatibility with older daemons.
129 *
130 * The KVP opcodes are defined by the host and it was unfortunate
131 * that I chose to treat the registration operation as part of the
132 * KVP operations defined by the host.
133 * Here is the level of compatibility
134 * (between the user level daemon and the kernel KVP driver) that we
135 * will implement:
136 *
137 * An older daemon will always be supported on a newer driver.
138 * A given user level daemon will require a minimal version of the
139 * kernel driver.
140 * If we cannot handle the version differences, we will fail gracefully
141 * (this can happen when we have a user level daemon that is more
142 * advanced than the KVP driver.
143 *
144 * We will use values used in this handshake for determining if we have
145 * workable user level daemon and the kernel driver. We begin by taking the
146 * registration opcode out of the KVP opcode namespace. We will however,
147 * maintain compatibility with the existing user-level daemon code.
148 */
149
150/*
151 * Daemon code not supporting IP injection (legacy daemon).
152 */
153
154#define KVP_OP_REGISTER 4
155
156/*
157 * Daemon code supporting IP injection.
158 * The KVP opcode field is used to communicate the
159 * registration information; so define a namespace that
160 * will be distinct from the host defined KVP opcode.
161 */
162
163#define KVP_OP_REGISTER1 100
164
2939437c
S
165enum hv_kvp_exchg_op {
166 KVP_OP_GET = 0,
167 KVP_OP_SET,
168 KVP_OP_DELETE,
169 KVP_OP_ENUMERATE,
9b595780
S
170 KVP_OP_GET_IP_INFO,
171 KVP_OP_SET_IP_INFO,
2939437c
S
172 KVP_OP_COUNT /* Number of operations, must be last. */
173};
174
175enum hv_kvp_exchg_pool {
176 KVP_POOL_EXTERNAL = 0,
177 KVP_POOL_GUEST,
178 KVP_POOL_AUTO,
179 KVP_POOL_AUTO_EXTERNAL,
180 KVP_POOL_AUTO_INTERNAL,
181 KVP_POOL_COUNT /* Number of pools, must be last. */
182};
183
b47a81dc
S
184/*
185 * Some Hyper-V status codes.
186 */
187
188#define HV_S_OK 0x00000000
189#define HV_E_FAIL 0x80004005
190#define HV_S_CONT 0x80070103
191#define HV_ERROR_NOT_SUPPORTED 0x80070032
192#define HV_ERROR_MACHINE_LOCKED 0x800704F7
193#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
194
9b595780
S
195#define ADDR_FAMILY_NONE 0x00
196#define ADDR_FAMILY_IPV4 0x01
197#define ADDR_FAMILY_IPV6 0x02
198
199#define MAX_ADAPTER_ID_SIZE 128
200#define MAX_IP_ADDR_SIZE 1024
201#define MAX_GATEWAY_SIZE 512
202
203
204struct hv_kvp_ipaddr_value {
205 __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
206 __u8 addr_family;
207 __u8 dhcp_enabled;
208 __u16 ip_addr[MAX_IP_ADDR_SIZE];
209 __u16 sub_net[MAX_IP_ADDR_SIZE];
210 __u16 gate_way[MAX_GATEWAY_SIZE];
211 __u16 dns_addr[MAX_IP_ADDR_SIZE];
212} __attribute__((packed));
213
214
2939437c 215struct hv_kvp_hdr {
59a084a7
S
216 __u8 operation;
217 __u8 pool;
218 __u16 pad;
219} __attribute__((packed));
2939437c
S
220
221struct hv_kvp_exchg_msg_value {
59a084a7
S
222 __u32 value_type;
223 __u32 key_size;
224 __u32 value_size;
225 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
e485ceac
S
226 union {
227 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
228 __u32 value_u32;
229 __u64 value_u64;
230 };
59a084a7 231} __attribute__((packed));
2939437c
S
232
233struct hv_kvp_msg_enumerate {
59a084a7 234 __u32 index;
2939437c 235 struct hv_kvp_exchg_msg_value data;
59a084a7 236} __attribute__((packed));
2939437c 237
e485ceac
S
238struct hv_kvp_msg_get {
239 struct hv_kvp_exchg_msg_value data;
240};
241
242struct hv_kvp_msg_set {
243 struct hv_kvp_exchg_msg_value data;
244};
245
246struct hv_kvp_msg_delete {
247 __u32 key_size;
248 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
249};
250
251struct hv_kvp_register {
252 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
253};
254
2939437c 255struct hv_kvp_msg {
9b595780
S
256 union {
257 struct hv_kvp_hdr kvp_hdr;
258 int error;
259 };
26403354 260 union {
e485ceac
S
261 struct hv_kvp_msg_get kvp_get;
262 struct hv_kvp_msg_set kvp_set;
263 struct hv_kvp_msg_delete kvp_delete;
264 struct hv_kvp_msg_enumerate kvp_enum_data;
9b595780 265 struct hv_kvp_ipaddr_value kvp_ip_val;
e485ceac 266 struct hv_kvp_register kvp_register;
26403354 267 } body;
59a084a7 268} __attribute__((packed));
2939437c 269
9b595780
S
270struct hv_kvp_ip_msg {
271 __u8 operation;
272 __u8 pool;
273 struct hv_kvp_ipaddr_value kvp_ip_val;
274} __attribute__((packed));
275
59a084a7 276#ifdef __KERNEL__
8ff3e6fc
S
277#include <linux/scatterlist.h>
278#include <linux/list.h>
358d2ee2 279#include <linux/uuid.h>
8ff3e6fc
S
280#include <linux/timer.h>
281#include <linux/workqueue.h>
282#include <linux/completion.h>
283#include <linux/device.h>
2e2c1d17 284#include <linux/mod_devicetable.h>
8ff3e6fc
S
285
286
c31c151b 287#define MAX_PAGE_BUFFER_COUNT 19
a363bf7b
S
288#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
289
290#pragma pack(push, 1)
291
292/* Single-page buffer */
293struct hv_page_buffer {
294 u32 len;
295 u32 offset;
296 u64 pfn;
297};
298
299/* Multiple-page buffer */
300struct hv_multipage_buffer {
301 /* Length and Offset determines the # of pfns in the array */
302 u32 len;
303 u32 offset;
304 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
305};
306
307/* 0x18 includes the proprietary packet header */
308#define MAX_PAGE_BUFFER_PACKET (0x18 + \
309 (sizeof(struct hv_page_buffer) * \
310 MAX_PAGE_BUFFER_COUNT))
311#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
312 sizeof(struct hv_multipage_buffer))
313
314
315#pragma pack(pop)
316
7effffb7
S
317struct hv_ring_buffer {
318 /* Offset in bytes from the start of ring data below */
319 u32 write_index;
320
321 /* Offset in bytes from the start of ring data below */
322 u32 read_index;
323
324 u32 interrupt_mask;
325
326 /* Pad it to PAGE_SIZE so that data starts on page boundary */
327 u8 reserved[4084];
328
329 /* NOTE:
330 * The interrupt_mask field is used only for channels but since our
331 * vmbus connection also uses this data structure and its data starts
332 * here, we commented out this field.
333 */
334
335 /*
336 * Ring data starts here + RingDataStartOffset
337 * !!! DO NOT place any fields below this !!!
338 */
339 u8 buffer[0];
340} __packed;
341
342struct hv_ring_buffer_info {
343 struct hv_ring_buffer *ring_buffer;
344 u32 ring_size; /* Include the shared header */
345 spinlock_t ring_lock;
346
347 u32 ring_datasize; /* < ring_size */
348 u32 ring_data_startoffset;
349};
350
351struct hv_ring_buffer_debug_info {
352 u32 current_interrupt_mask;
353 u32 current_read_index;
354 u32 current_write_index;
355 u32 bytes_avail_toread;
356 u32 bytes_avail_towrite;
357};
3f335ea2 358
33be96e4
HZ
359
360/*
361 *
362 * hv_get_ringbuffer_availbytes()
363 *
364 * Get number of bytes available to read and to write to
365 * for the specified ring buffer
366 */
367static inline void
368hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
369 u32 *read, u32 *write)
370{
371 u32 read_loc, write_loc, dsize;
372
373 smp_read_barrier_depends();
374
375 /* Capture the read/write indices before they changed */
376 read_loc = rbi->ring_buffer->read_index;
377 write_loc = rbi->ring_buffer->write_index;
378 dsize = rbi->ring_datasize;
379
380 *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
381 read_loc - write_loc;
382 *read = dsize - *write;
383}
384
385
f7c6dfda
S
386/*
387 * We use the same version numbering for all Hyper-V modules.
388 *
389 * Definition of versioning is as follows;
390 *
391 * Major Number Changes for these scenarios;
392 * 1. When a new version of Windows Hyper-V
393 * is released.
394 * 2. A Major change has occurred in the
395 * Linux IC's.
396 * (For example the merge for the first time
397 * into the kernel) Every time the Major Number
398 * changes, the Revision number is reset to 0.
399 * Minor Number Changes when new functionality is added
400 * to the Linux IC's that is not a bug fix.
401 *
402 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
403 */
404#define HV_DRV_VERSION "3.1"
405
406
517d8dc6
S
407/*
408 * A revision number of vmbus that is used for ensuring both ends on a
409 * partition are using compatible versions.
410 */
411#define VMBUS_REVISION_NUMBER 13
412
413/* Make maximum size of pipe payload of 16K */
414#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
415
416/* Define PipeMode values. */
417#define VMBUS_PIPE_TYPE_BYTE 0x00000000
418#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
419
420/* The size of the user defined data buffer for non-pipe offers. */
421#define MAX_USER_DEFINED_BYTES 120
422
423/* The size of the user defined data buffer for pipe offers. */
424#define MAX_PIPE_USER_DEFINED_BYTES 116
425
426/*
427 * At the center of the Channel Management library is the Channel Offer. This
428 * struct contains the fundamental information about an offer.
429 */
430struct vmbus_channel_offer {
358d2ee2
S
431 uuid_le if_type;
432 uuid_le if_instance;
517d8dc6
S
433 u64 int_latency; /* in 100ns units */
434 u32 if_revision;
435 u32 server_ctx_size; /* in bytes */
436 u16 chn_flags;
437 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
438
439 union {
440 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
441 struct {
442 unsigned char user_def[MAX_USER_DEFINED_BYTES];
443 } std;
444
445 /*
446 * Pipes:
447 * The following sructure is an integrated pipe protocol, which
448 * is implemented on top of standard user-defined data. Pipe
449 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
450 * use.
451 */
452 struct {
453 u32 pipe_mode;
454 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
455 } pipe;
456 } u;
457 u32 padding;
458} __packed;
459
460/* Server Flags */
461#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
462#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
463#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
464#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
465#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
466#define VMBUS_CHANNEL_PARENT_OFFER 0x200
467#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
468
50ed40e0
S
469struct vmpacket_descriptor {
470 u16 type;
471 u16 offset8;
472 u16 len8;
473 u16 flags;
474 u64 trans_id;
475} __packed;
476
477struct vmpacket_header {
478 u32 prev_pkt_start_offset;
479 struct vmpacket_descriptor descriptor;
480} __packed;
481
482struct vmtransfer_page_range {
483 u32 byte_count;
484 u32 byte_offset;
485} __packed;
486
487struct vmtransfer_page_packet_header {
488 struct vmpacket_descriptor d;
489 u16 xfer_pageset_id;
1508d811 490 u8 sender_owns_set;
50ed40e0
S
491 u8 reserved;
492 u32 range_cnt;
493 struct vmtransfer_page_range ranges[1];
494} __packed;
495
496struct vmgpadl_packet_header {
497 struct vmpacket_descriptor d;
498 u32 gpadl;
499 u32 reserved;
500} __packed;
501
502struct vmadd_remove_transfer_page_set {
503 struct vmpacket_descriptor d;
504 u32 gpadl;
505 u16 xfer_pageset_id;
506 u16 reserved;
507} __packed;
508
509/*
510 * This structure defines a range in guest physical space that can be made to
511 * look virtually contiguous.
512 */
513struct gpa_range {
514 u32 byte_count;
515 u32 byte_offset;
516 u64 pfn_array[0];
517};
518
519/*
520 * This is the format for an Establish Gpadl packet, which contains a handle by
521 * which this GPADL will be known and a set of GPA ranges associated with it.
522 * This can be converted to a MDL by the guest OS. If there are multiple GPA
523 * ranges, then the resulting MDL will be "chained," representing multiple VA
524 * ranges.
525 */
526struct vmestablish_gpadl {
527 struct vmpacket_descriptor d;
528 u32 gpadl;
529 u32 range_cnt;
530 struct gpa_range range[1];
531} __packed;
532
533/*
534 * This is the format for a Teardown Gpadl packet, which indicates that the
535 * GPADL handle in the Establish Gpadl packet will never be referenced again.
536 */
537struct vmteardown_gpadl {
538 struct vmpacket_descriptor d;
539 u32 gpadl;
540 u32 reserved; /* for alignment to a 8-byte boundary */
541} __packed;
542
543/*
544 * This is the format for a GPA-Direct packet, which contains a set of GPA
545 * ranges, in addition to commands and/or data.
546 */
547struct vmdata_gpa_direct {
548 struct vmpacket_descriptor d;
549 u32 reserved;
550 u32 range_cnt;
551 struct gpa_range range[1];
552} __packed;
553
554/* This is the format for a Additional Data Packet. */
555struct vmadditional_data {
556 struct vmpacket_descriptor d;
557 u64 total_bytes;
558 u32 offset;
559 u32 byte_cnt;
560 unsigned char data[1];
561} __packed;
562
563union vmpacket_largest_possible_header {
564 struct vmpacket_descriptor simple_hdr;
565 struct vmtransfer_page_packet_header xfer_page_hdr;
566 struct vmgpadl_packet_header gpadl_hdr;
567 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
568 struct vmestablish_gpadl establish_gpadl_hdr;
569 struct vmteardown_gpadl teardown_gpadl_hdr;
570 struct vmdata_gpa_direct data_gpa_direct_hdr;
571};
572
573#define VMPACKET_DATA_START_ADDRESS(__packet) \
574 (void *)(((unsigned char *)__packet) + \
575 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
576
577#define VMPACKET_DATA_LENGTH(__packet) \
578 ((((struct vmpacket_descriptor)__packet)->len8 - \
579 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
580
581#define VMPACKET_TRANSFER_MODE(__packet) \
582 (((struct IMPACT)__packet)->type)
583
584enum vmbus_packet_type {
585 VM_PKT_INVALID = 0x0,
586 VM_PKT_SYNCH = 0x1,
587 VM_PKT_ADD_XFER_PAGESET = 0x2,
588 VM_PKT_RM_XFER_PAGESET = 0x3,
589 VM_PKT_ESTABLISH_GPADL = 0x4,
590 VM_PKT_TEARDOWN_GPADL = 0x5,
591 VM_PKT_DATA_INBAND = 0x6,
592 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
593 VM_PKT_DATA_USING_GPADL = 0x8,
594 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
595 VM_PKT_CANCEL_REQUEST = 0xa,
596 VM_PKT_COMP = 0xb,
597 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
598 VM_PKT_ADDITIONAL_DATA = 0xd
599};
600
601#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
517d8dc6 602
b56dda06 603
b56dda06
S
604/* Version 1 messages */
605enum vmbus_channel_message_type {
606 CHANNELMSG_INVALID = 0,
607 CHANNELMSG_OFFERCHANNEL = 1,
608 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
609 CHANNELMSG_REQUESTOFFERS = 3,
610 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
611 CHANNELMSG_OPENCHANNEL = 5,
612 CHANNELMSG_OPENCHANNEL_RESULT = 6,
613 CHANNELMSG_CLOSECHANNEL = 7,
614 CHANNELMSG_GPADL_HEADER = 8,
615 CHANNELMSG_GPADL_BODY = 9,
616 CHANNELMSG_GPADL_CREATED = 10,
617 CHANNELMSG_GPADL_TEARDOWN = 11,
618 CHANNELMSG_GPADL_TORNDOWN = 12,
619 CHANNELMSG_RELID_RELEASED = 13,
620 CHANNELMSG_INITIATE_CONTACT = 14,
621 CHANNELMSG_VERSION_RESPONSE = 15,
622 CHANNELMSG_UNLOAD = 16,
623#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
624 CHANNELMSG_VIEWRANGE_ADD = 17,
625 CHANNELMSG_VIEWRANGE_REMOVE = 18,
626#endif
627 CHANNELMSG_COUNT
628};
629
630struct vmbus_channel_message_header {
631 enum vmbus_channel_message_type msgtype;
632 u32 padding;
633} __packed;
634
635/* Query VMBus Version parameters */
636struct vmbus_channel_query_vmbus_version {
637 struct vmbus_channel_message_header header;
638 u32 version;
639} __packed;
640
641/* VMBus Version Supported parameters */
642struct vmbus_channel_version_supported {
643 struct vmbus_channel_message_header header;
1508d811 644 u8 version_supported;
b56dda06
S
645} __packed;
646
647/* Offer Channel parameters */
648struct vmbus_channel_offer_channel {
649 struct vmbus_channel_message_header header;
650 struct vmbus_channel_offer offer;
651 u32 child_relid;
652 u8 monitorid;
1508d811 653 u8 monitor_allocated;
b56dda06
S
654} __packed;
655
656/* Rescind Offer parameters */
657struct vmbus_channel_rescind_offer {
658 struct vmbus_channel_message_header header;
659 u32 child_relid;
660} __packed;
661
662/*
663 * Request Offer -- no parameters, SynIC message contains the partition ID
664 * Set Snoop -- no parameters, SynIC message contains the partition ID
665 * Clear Snoop -- no parameters, SynIC message contains the partition ID
666 * All Offers Delivered -- no parameters, SynIC message contains the partition
667 * ID
668 * Flush Client -- no parameters, SynIC message contains the partition ID
669 */
670
671/* Open Channel parameters */
672struct vmbus_channel_open_channel {
673 struct vmbus_channel_message_header header;
674
675 /* Identifies the specific VMBus channel that is being opened. */
676 u32 child_relid;
677
678 /* ID making a particular open request at a channel offer unique. */
679 u32 openid;
680
681 /* GPADL for the channel's ring buffer. */
682 u32 ringbuffer_gpadlhandle;
683
684 /* GPADL for the channel's server context save area. */
685 u32 server_contextarea_gpadlhandle;
686
687 /*
688 * The upstream ring buffer begins at offset zero in the memory
689 * described by RingBufferGpadlHandle. The downstream ring buffer
690 * follows it at this offset (in pages).
691 */
692 u32 downstream_ringbuffer_pageoffset;
693
694 /* User-specific data to be passed along to the server endpoint. */
695 unsigned char userdata[MAX_USER_DEFINED_BYTES];
696} __packed;
697
698/* Open Channel Result parameters */
699struct vmbus_channel_open_result {
700 struct vmbus_channel_message_header header;
701 u32 child_relid;
702 u32 openid;
703 u32 status;
704} __packed;
705
706/* Close channel parameters; */
707struct vmbus_channel_close_channel {
708 struct vmbus_channel_message_header header;
709 u32 child_relid;
710} __packed;
711
712/* Channel Message GPADL */
713#define GPADL_TYPE_RING_BUFFER 1
714#define GPADL_TYPE_SERVER_SAVE_AREA 2
715#define GPADL_TYPE_TRANSACTION 8
716
717/*
718 * The number of PFNs in a GPADL message is defined by the number of
719 * pages that would be spanned by ByteCount and ByteOffset. If the
720 * implied number of PFNs won't fit in this packet, there will be a
721 * follow-up packet that contains more.
722 */
723struct vmbus_channel_gpadl_header {
724 struct vmbus_channel_message_header header;
725 u32 child_relid;
726 u32 gpadl;
727 u16 range_buflen;
728 u16 rangecount;
729 struct gpa_range range[0];
730} __packed;
731
732/* This is the followup packet that contains more PFNs. */
733struct vmbus_channel_gpadl_body {
734 struct vmbus_channel_message_header header;
735 u32 msgnumber;
736 u32 gpadl;
737 u64 pfn[0];
738} __packed;
739
740struct vmbus_channel_gpadl_created {
741 struct vmbus_channel_message_header header;
742 u32 child_relid;
743 u32 gpadl;
744 u32 creation_status;
745} __packed;
746
747struct vmbus_channel_gpadl_teardown {
748 struct vmbus_channel_message_header header;
749 u32 child_relid;
750 u32 gpadl;
751} __packed;
752
753struct vmbus_channel_gpadl_torndown {
754 struct vmbus_channel_message_header header;
755 u32 gpadl;
756} __packed;
757
758#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
759struct vmbus_channel_view_range_add {
760 struct vmbus_channel_message_header header;
761 PHYSICAL_ADDRESS viewrange_base;
762 u64 viewrange_length;
763 u32 child_relid;
764} __packed;
765
766struct vmbus_channel_view_range_remove {
767 struct vmbus_channel_message_header header;
768 PHYSICAL_ADDRESS viewrange_base;
769 u32 child_relid;
770} __packed;
771#endif
772
773struct vmbus_channel_relid_released {
774 struct vmbus_channel_message_header header;
775 u32 child_relid;
776} __packed;
777
778struct vmbus_channel_initiate_contact {
779 struct vmbus_channel_message_header header;
780 u32 vmbus_version_requested;
781 u32 padding2;
782 u64 interrupt_page;
783 u64 monitor_page1;
784 u64 monitor_page2;
785} __packed;
786
787struct vmbus_channel_version_response {
788 struct vmbus_channel_message_header header;
1508d811 789 u8 version_supported;
b56dda06
S
790} __packed;
791
792enum vmbus_channel_state {
793 CHANNEL_OFFER_STATE,
794 CHANNEL_OPENING_STATE,
795 CHANNEL_OPEN_STATE,
796};
797
b56dda06
S
798struct vmbus_channel_debug_info {
799 u32 relid;
800 enum vmbus_channel_state state;
358d2ee2
S
801 uuid_le interfacetype;
802 uuid_le interface_instance;
b56dda06
S
803 u32 monitorid;
804 u32 servermonitor_pending;
805 u32 servermonitor_latency;
806 u32 servermonitor_connectionid;
807 u32 clientmonitor_pending;
808 u32 clientmonitor_latency;
809 u32 clientmonitor_connectionid;
810
811 struct hv_ring_buffer_debug_info inbound;
812 struct hv_ring_buffer_debug_info outbound;
813};
814
815/*
816 * Represents each channel msg on the vmbus connection This is a
817 * variable-size data structure depending on the msg type itself
818 */
819struct vmbus_channel_msginfo {
820 /* Bookkeeping stuff */
821 struct list_head msglistentry;
822
823 /* So far, this is only used to handle gpadl body message */
824 struct list_head submsglist;
825
826 /* Synchronize the request/response if needed */
827 struct completion waitevent;
828 union {
829 struct vmbus_channel_version_supported version_supported;
830 struct vmbus_channel_open_result open_result;
831 struct vmbus_channel_gpadl_torndown gpadl_torndown;
832 struct vmbus_channel_gpadl_created gpadl_created;
833 struct vmbus_channel_version_response version_response;
834 } response;
835
836 u32 msgsize;
837 /*
838 * The channel message that goes out on the "wire".
839 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
840 */
841 unsigned char msg[0];
842};
843
f9f1db83
S
844struct vmbus_close_msg {
845 struct vmbus_channel_msginfo info;
846 struct vmbus_channel_close_channel msg;
847};
848
7d7c75cd
S
849struct vmbus_channel {
850 struct list_head listentry;
851
852 struct hv_device *device_obj;
853
854 struct work_struct work;
855
856 enum vmbus_channel_state state;
7d7c75cd
S
857
858 struct vmbus_channel_offer_channel offermsg;
859 /*
860 * These are based on the OfferMsg.MonitorId.
861 * Save it here for easy access.
862 */
863 u8 monitor_grp;
864 u8 monitor_bit;
865
866 u32 ringbuffer_gpadlhandle;
867
868 /* Allocated memory for ring buffer */
869 void *ringbuffer_pages;
870 u32 ringbuffer_pagecount;
871 struct hv_ring_buffer_info outbound; /* send to parent */
872 struct hv_ring_buffer_info inbound; /* receive from parent */
873 spinlock_t inbound_lock;
874 struct workqueue_struct *controlwq;
875
f9f1db83
S
876 struct vmbus_close_msg close_msg;
877
7d7c75cd
S
878 /* Channel callback are invoked in this workqueue context */
879 /* HANDLE dataWorkQueue; */
880
881 void (*onchannel_callback)(void *context);
882 void *channel_callback_context;
883};
b56dda06 884
b56dda06
S
885void vmbus_onmessage(void *context);
886
887int vmbus_request_offers(void);
888
c35470b2
S
889/* The format must be the same as struct vmdata_gpa_direct */
890struct vmbus_channel_packet_page_buffer {
891 u16 type;
892 u16 dataoffset8;
893 u16 length8;
894 u16 flags;
895 u64 transactionid;
896 u32 reserved;
897 u32 rangecount;
898 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
899} __packed;
900
901/* The format must be the same as struct vmdata_gpa_direct */
902struct vmbus_channel_packet_multipage_buffer {
903 u16 type;
904 u16 dataoffset8;
905 u16 length8;
906 u16 flags;
907 u64 transactionid;
908 u32 reserved;
909 u32 rangecount; /* Always 1 in this case */
910 struct hv_multipage_buffer range;
911} __packed;
912
913
914extern int vmbus_open(struct vmbus_channel *channel,
915 u32 send_ringbuffersize,
916 u32 recv_ringbuffersize,
917 void *userdata,
918 u32 userdatalen,
919 void(*onchannel_callback)(void *context),
920 void *context);
921
922extern void vmbus_close(struct vmbus_channel *channel);
923
924extern int vmbus_sendpacket(struct vmbus_channel *channel,
925 const void *buffer,
926 u32 bufferLen,
927 u64 requestid,
928 enum vmbus_packet_type type,
929 u32 flags);
930
931extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
932 struct hv_page_buffer pagebuffers[],
933 u32 pagecount,
934 void *buffer,
935 u32 bufferlen,
936 u64 requestid);
937
938extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
939 struct hv_multipage_buffer *mpb,
940 void *buffer,
941 u32 bufferlen,
942 u64 requestid);
943
944extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
945 void *kbuffer,
946 u32 size,
947 u32 *gpadl_handle);
948
949extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
950 u32 gpadl_handle);
951
952extern int vmbus_recvpacket(struct vmbus_channel *channel,
953 void *buffer,
954 u32 bufferlen,
955 u32 *buffer_actual_len,
956 u64 *requestid);
957
958extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
959 void *buffer,
960 u32 bufferlen,
961 u32 *buffer_actual_len,
962 u64 *requestid);
963
c35470b2
S
964
965extern void vmbus_get_debug_info(struct vmbus_channel *channel,
966 struct vmbus_channel_debug_info *debug);
967
968extern void vmbus_ontimer(unsigned long data);
969
35ea09c3
S
970struct hv_dev_port_info {
971 u32 int_mask;
972 u32 read_idx;
973 u32 write_idx;
974 u32 bytes_avail_toread;
975 u32 bytes_avail_towrite;
976};
977
35ea09c3
S
978/* Base driver object */
979struct hv_driver {
980 const char *name;
981
982 /* the device type supported by this driver */
358d2ee2 983 uuid_le dev_type;
2e2c1d17 984 const struct hv_vmbus_device_id *id_table;
35ea09c3
S
985
986 struct device_driver driver;
987
84946899 988 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
35ea09c3
S
989 int (*remove)(struct hv_device *);
990 void (*shutdown)(struct hv_device *);
991
992};
993
994/* Base device object */
995struct hv_device {
996 /* the device type id of this device */
358d2ee2 997 uuid_le dev_type;
35ea09c3
S
998
999 /* the device instance id of this device */
358d2ee2 1000 uuid_le dev_instance;
35ea09c3
S
1001
1002 struct device device;
1003
1004 struct vmbus_channel *channel;
35ea09c3
S
1005};
1006
27b5b3ca
S
1007
1008static inline struct hv_device *device_to_hv_device(struct device *d)
1009{
1010 return container_of(d, struct hv_device, device);
1011}
1012
1013static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1014{
1015 return container_of(d, struct hv_driver, driver);
1016}
1017
ab101e86
S
1018static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1019{
1020 dev_set_drvdata(&dev->device, data);
1021}
1022
1023static inline void *hv_get_drvdata(struct hv_device *dev)
1024{
1025 return dev_get_drvdata(&dev->device);
1026}
27b5b3ca
S
1027
1028/* Vmbus interface */
768fa219
GKH
1029#define vmbus_driver_register(driver) \
1030 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1031int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1032 struct module *owner,
1033 const char *mod_name);
1034void vmbus_driver_unregister(struct hv_driver *hv_driver);
27b5b3ca 1035
c45cf2d4
GKH
1036/**
1037 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1038 *
1039 * This macro is used to create a struct hv_vmbus_device_id that matches a
1040 * specific device.
1041 */
1042#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1043 g8, g9, ga, gb, gc, gd, ge, gf) \
1044 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1045 g8, g9, ga, gb, gc, gd, ge, gf },
1046
b189702d
S
1047/*
1048 * Common header for Hyper-V ICs
1049 */
1050
1051#define ICMSGTYPE_NEGOTIATE 0
1052#define ICMSGTYPE_HEARTBEAT 1
1053#define ICMSGTYPE_KVPEXCHANGE 2
1054#define ICMSGTYPE_SHUTDOWN 3
1055#define ICMSGTYPE_TIMESYNC 4
1056#define ICMSGTYPE_VSS 5
1057
1058#define ICMSGHDRFLAG_TRANSACTION 1
1059#define ICMSGHDRFLAG_REQUEST 2
1060#define ICMSGHDRFLAG_RESPONSE 4
1061
b189702d 1062
a29b643c
S
1063/*
1064 * While we want to handle util services as regular devices,
1065 * there is only one instance of each of these services; so
1066 * we statically allocate the service specific state.
1067 */
1068
1069struct hv_util_service {
1070 u8 *recv_buffer;
1071 void (*util_cb)(void *);
1072 int (*util_init)(struct hv_util_service *);
1073 void (*util_deinit)(void);
1074};
1075
b189702d
S
1076struct vmbuspipe_hdr {
1077 u32 flags;
1078 u32 msgsize;
1079} __packed;
1080
1081struct ic_version {
1082 u16 major;
1083 u16 minor;
1084} __packed;
1085
1086struct icmsg_hdr {
1087 struct ic_version icverframe;
1088 u16 icmsgtype;
1089 struct ic_version icvermsg;
1090 u16 icmsgsize;
1091 u32 status;
1092 u8 ictransaction_id;
1093 u8 icflags;
1094 u8 reserved[2];
1095} __packed;
1096
1097struct icmsg_negotiate {
1098 u16 icframe_vercnt;
1099 u16 icmsg_vercnt;
1100 u32 reserved;
1101 struct ic_version icversion_data[1]; /* any size array */
1102} __packed;
1103
1104struct shutdown_msg_data {
1105 u32 reason_code;
1106 u32 timeout_seconds;
1107 u32 flags;
1108 u8 display_message[2048];
1109} __packed;
1110
1111struct heartbeat_msg_data {
1112 u64 seq_num;
1113 u32 reserved[8];
1114} __packed;
1115
1116/* Time Sync IC defs */
1117#define ICTIMESYNCFLAG_PROBE 0
1118#define ICTIMESYNCFLAG_SYNC 1
1119#define ICTIMESYNCFLAG_SAMPLE 2
1120
1121#ifdef __x86_64__
1122#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1123#else
1124#define WLTIMEDELTA 116444736000000000LL
1125#endif
1126
1127struct ictimesync_data {
1128 u64 parenttime;
1129 u64 childtime;
1130 u64 roundtriptime;
1131 u8 flags;
1132} __packed;
1133
b189702d
S
1134struct hyperv_service_callback {
1135 u8 msg_type;
1136 char *log_msg;
358d2ee2 1137 uuid_le data;
b189702d
S
1138 struct vmbus_channel *channel;
1139 void (*callback) (void *context);
1140};
1141
c836d0ab 1142#define MAX_SRV_VER 0x7ffffff
da0e9631 1143extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
c836d0ab
S
1144 struct icmsg_negotiate *, u8 *, int,
1145 int);
b189702d 1146
2939437c
S
1147int hv_kvp_init(struct hv_util_service *);
1148void hv_kvp_deinit(void);
1149void hv_kvp_onchannelcallback(void *);
1150
1151#endif /* __KERNEL__ */
3f335ea2 1152#endif /* _HYPERV_H */
This page took 0.225547 seconds and 5 git commands to generate.