3 * Copyright (c) 2011, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 * K. Y. Srinivasan <kys@microsoft.com>
28 #include <linux/types.h>
31 * Framework version for util services.
33 #define UTIL_FW_MINOR 0
35 #define UTIL_WS2K8_FW_MAJOR 1
36 #define UTIL_WS2K8_FW_VERSION (UTIL_WS2K8_FW_MAJOR << 16 | UTIL_FW_MINOR)
38 #define UTIL_FW_MAJOR 3
39 #define UTIL_FW_VERSION (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
43 * Implementation of host controlled snapshot of the guest.
46 #define VSS_OP_REGISTER 128
55 * Following operations are only supported with IC version >= 5.0
57 VSS_OP_FREEZE, /* Freeze the file systems in the VM */
58 VSS_OP_THAW, /* Unfreeze the file systems */
60 VSS_OP_COUNT /* Number of operations, must be last */
65 * Header for all VSS messages.
70 } __attribute__((packed));
74 * Flag values for the hv_vss_check_feature. Linux supports only
77 #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
79 struct hv_vss_check_feature {
81 } __attribute__((packed));
83 struct hv_vss_check_dm_info {
85 } __attribute__((packed));
89 struct hv_vss_hdr vss_hdr;
93 struct hv_vss_check_feature vss_cf;
94 struct hv_vss_check_dm_info dm_info;
96 } __attribute__((packed));
99 * An implementation of HyperV key value pair (KVP) functionality for Linux.
102 * Copyright (C) 2010, Novell, Inc.
103 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
108 * Maximum value size - used for both key names and value data, and includes
109 * any applicable NULL terminators.
111 * Note: This limit is somewhat arbitrary, but falls easily within what is
112 * supported for all native guests (back to Win 2000) and what is reasonable
113 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
114 * limited to 255 character key names.
116 * MSDN recommends not storing data values larger than 2048 bytes in the
119 * Note: This value is used in defining the KVP exchange message - this value
120 * cannot be modified without affecting the message size and compatibility.
124 * bytes, including any null terminators
126 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
130 * Maximum key size - the registry limit for the length of an entry name
131 * is 256 characters, including the null terminator
134 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
137 * In Linux, we implement the KVP functionality in two components:
138 * 1) The kernel component which is packaged as part of the hv_utils driver
139 * is responsible for communicating with the host and responsible for
140 * implementing the host/guest protocol. 2) A user level daemon that is
141 * responsible for data gathering.
143 * Host/Guest Protocol: The host iterates over an index and expects the guest
144 * to assign a key name to the index and also return the value corresponding to
145 * the key. The host will have atmost one KVP transaction outstanding at any
146 * given point in time. The host side iteration stops when the guest returns
147 * an error. Microsoft has specified the following mapping of key names to
148 * host specified index:
151 * 0 FullyQualifiedDomainName
152 * 1 IntegrationServicesVersion
153 * 2 NetworkAddressIPv4
154 * 3 NetworkAddressIPv6
160 * 9 ProcessorArchitecture
162 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
164 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
165 * data gathering functionality in a user mode daemon. The user level daemon
166 * is also responsible for binding the key name to the index as well. The
167 * kernel and user-level daemon communicate using a connector channel.
169 * The user mode component first registers with the
170 * the kernel component. Subsequently, the kernel component requests, data
171 * for the specified keys. In response to this message the user mode component
172 * fills in the value corresponding to the specified key. We overload the
173 * sequence field in the cn_msg header to define our KVP message types.
176 * The kernel component simply acts as a conduit for communication between the
177 * Windows host and the user-level daemon. The kernel component passes up the
178 * index received from the Host to the user-level daemon. If the index is
179 * valid (supported), the corresponding key as well as its
180 * value (both are strings) is returned. If the index is invalid
181 * (not supported), a NULL key string is returned.
186 * Registry value types.
194 * As we look at expanding the KVP functionality to include
195 * IP injection functionality, we need to maintain binary
196 * compatibility with older daemons.
198 * The KVP opcodes are defined by the host and it was unfortunate
199 * that I chose to treat the registration operation as part of the
200 * KVP operations defined by the host.
201 * Here is the level of compatibility
202 * (between the user level daemon and the kernel KVP driver) that we
205 * An older daemon will always be supported on a newer driver.
206 * A given user level daemon will require a minimal version of the
208 * If we cannot handle the version differences, we will fail gracefully
209 * (this can happen when we have a user level daemon that is more
210 * advanced than the KVP driver.
212 * We will use values used in this handshake for determining if we have
213 * workable user level daemon and the kernel driver. We begin by taking the
214 * registration opcode out of the KVP opcode namespace. We will however,
215 * maintain compatibility with the existing user-level daemon code.
219 * Daemon code not supporting IP injection (legacy daemon).
222 #define KVP_OP_REGISTER 4
225 * Daemon code supporting IP injection.
226 * The KVP opcode field is used to communicate the
227 * registration information; so define a namespace that
228 * will be distinct from the host defined KVP opcode.
231 #define KVP_OP_REGISTER1 100
233 enum hv_kvp_exchg_op {
240 KVP_OP_COUNT /* Number of operations, must be last. */
243 enum hv_kvp_exchg_pool {
244 KVP_POOL_EXTERNAL = 0,
247 KVP_POOL_AUTO_EXTERNAL,
248 KVP_POOL_AUTO_INTERNAL,
249 KVP_POOL_COUNT /* Number of pools, must be last. */
253 * Some Hyper-V status codes.
256 #define HV_S_OK 0x00000000
257 #define HV_E_FAIL 0x80004005
258 #define HV_S_CONT 0x80070103
259 #define HV_ERROR_NOT_SUPPORTED 0x80070032
260 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
261 #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
262 #define HV_INVALIDARG 0x80070057
263 #define HV_GUID_NOTFOUND 0x80041002
265 #define ADDR_FAMILY_NONE 0x00
266 #define ADDR_FAMILY_IPV4 0x01
267 #define ADDR_FAMILY_IPV6 0x02
269 #define MAX_ADAPTER_ID_SIZE 128
270 #define MAX_IP_ADDR_SIZE 1024
271 #define MAX_GATEWAY_SIZE 512
274 struct hv_kvp_ipaddr_value {
275 __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
278 __u16 ip_addr[MAX_IP_ADDR_SIZE];
279 __u16 sub_net[MAX_IP_ADDR_SIZE];
280 __u16 gate_way[MAX_GATEWAY_SIZE];
281 __u16 dns_addr[MAX_IP_ADDR_SIZE];
282 } __attribute__((packed));
289 } __attribute__((packed));
291 struct hv_kvp_exchg_msg_value {
295 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
297 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
301 } __attribute__((packed));
303 struct hv_kvp_msg_enumerate {
305 struct hv_kvp_exchg_msg_value data;
306 } __attribute__((packed));
308 struct hv_kvp_msg_get {
309 struct hv_kvp_exchg_msg_value data;
312 struct hv_kvp_msg_set {
313 struct hv_kvp_exchg_msg_value data;
316 struct hv_kvp_msg_delete {
318 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
321 struct hv_kvp_register {
322 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
327 struct hv_kvp_hdr kvp_hdr;
331 struct hv_kvp_msg_get kvp_get;
332 struct hv_kvp_msg_set kvp_set;
333 struct hv_kvp_msg_delete kvp_delete;
334 struct hv_kvp_msg_enumerate kvp_enum_data;
335 struct hv_kvp_ipaddr_value kvp_ip_val;
336 struct hv_kvp_register kvp_register;
338 } __attribute__((packed));
340 struct hv_kvp_ip_msg {
343 struct hv_kvp_ipaddr_value kvp_ip_val;
344 } __attribute__((packed));
347 #include <linux/scatterlist.h>
348 #include <linux/list.h>
349 #include <linux/uuid.h>
350 #include <linux/timer.h>
351 #include <linux/workqueue.h>
352 #include <linux/completion.h>
353 #include <linux/device.h>
354 #include <linux/mod_devicetable.h>
357 #define MAX_PAGE_BUFFER_COUNT 19
358 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
360 #pragma pack(push, 1)
362 /* Single-page buffer */
363 struct hv_page_buffer {
369 /* Multiple-page buffer */
370 struct hv_multipage_buffer {
371 /* Length and Offset determines the # of pfns in the array */
374 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
377 /* 0x18 includes the proprietary packet header */
378 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
379 (sizeof(struct hv_page_buffer) * \
380 MAX_PAGE_BUFFER_COUNT))
381 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
382 sizeof(struct hv_multipage_buffer))
387 struct hv_ring_buffer {
388 /* Offset in bytes from the start of ring data below */
391 /* Offset in bytes from the start of ring data below */
397 * Win8 uses some of the reserved bits to implement
398 * interrupt driven flow management. On the send side
399 * we can request that the receiver interrupt the sender
400 * when the ring transitions from being full to being able
401 * to handle a message of size "pending_send_sz".
403 * Add necessary state for this enhancement.
411 u32 feat_pending_send_sz:1;
416 /* Pad it to PAGE_SIZE so that data starts on page boundary */
420 * Ring data starts here + RingDataStartOffset
421 * !!! DO NOT place any fields below this !!!
426 struct hv_ring_buffer_info {
427 struct hv_ring_buffer *ring_buffer;
428 u32 ring_size; /* Include the shared header */
429 spinlock_t ring_lock;
431 u32 ring_datasize; /* < ring_size */
432 u32 ring_data_startoffset;
437 * hv_get_ringbuffer_availbytes()
439 * Get number of bytes available to read and to write to
440 * for the specified ring buffer
443 hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
444 u32 *read, u32 *write)
446 u32 read_loc, write_loc, dsize;
448 smp_read_barrier_depends();
450 /* Capture the read/write indices before they changed */
451 read_loc = rbi->ring_buffer->read_index;
452 write_loc = rbi->ring_buffer->write_index;
453 dsize = rbi->ring_datasize;
455 *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
456 read_loc - write_loc;
457 *read = dsize - *write;
461 * VMBUS version is 32 bit entity broken up into
462 * two 16 bit quantities: major_number. minor_number.
464 * 0 . 13 (Windows Server 2008)
467 * 3 . 0 (Windows 8 R2)
470 #define VERSION_WS2008 ((0 << 16) | (13))
471 #define VERSION_WIN7 ((1 << 16) | (1))
472 #define VERSION_WIN8 ((2 << 16) | (4))
473 #define VERSION_WIN8_1 ((3 << 16) | (0))
475 #define VERSION_INVAL -1
477 #define VERSION_CURRENT VERSION_WIN8_1
479 /* Make maximum size of pipe payload of 16K */
480 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
482 /* Define PipeMode values. */
483 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
484 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
486 /* The size of the user defined data buffer for non-pipe offers. */
487 #define MAX_USER_DEFINED_BYTES 120
489 /* The size of the user defined data buffer for pipe offers. */
490 #define MAX_PIPE_USER_DEFINED_BYTES 116
493 * At the center of the Channel Management library is the Channel Offer. This
494 * struct contains the fundamental information about an offer.
496 struct vmbus_channel_offer {
501 * These two fields are not currently used.
507 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
510 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
512 unsigned char user_def[MAX_USER_DEFINED_BYTES];
517 * The following sructure is an integrated pipe protocol, which
518 * is implemented on top of standard user-defined data. Pipe
519 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
524 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
528 * The sub_channel_index is defined in win8.
530 u16 sub_channel_index;
535 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
536 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
537 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
538 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
539 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
540 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
541 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
543 struct vmpacket_descriptor {
551 struct vmpacket_header {
552 u32 prev_pkt_start_offset;
553 struct vmpacket_descriptor descriptor;
556 struct vmtransfer_page_range {
561 struct vmtransfer_page_packet_header {
562 struct vmpacket_descriptor d;
567 struct vmtransfer_page_range ranges[1];
570 struct vmgpadl_packet_header {
571 struct vmpacket_descriptor d;
576 struct vmadd_remove_transfer_page_set {
577 struct vmpacket_descriptor d;
584 * This structure defines a range in guest physical space that can be made to
585 * look virtually contiguous.
594 * This is the format for an Establish Gpadl packet, which contains a handle by
595 * which this GPADL will be known and a set of GPA ranges associated with it.
596 * This can be converted to a MDL by the guest OS. If there are multiple GPA
597 * ranges, then the resulting MDL will be "chained," representing multiple VA
600 struct vmestablish_gpadl {
601 struct vmpacket_descriptor d;
604 struct gpa_range range[1];
608 * This is the format for a Teardown Gpadl packet, which indicates that the
609 * GPADL handle in the Establish Gpadl packet will never be referenced again.
611 struct vmteardown_gpadl {
612 struct vmpacket_descriptor d;
614 u32 reserved; /* for alignment to a 8-byte boundary */
618 * This is the format for a GPA-Direct packet, which contains a set of GPA
619 * ranges, in addition to commands and/or data.
621 struct vmdata_gpa_direct {
622 struct vmpacket_descriptor d;
625 struct gpa_range range[1];
628 /* This is the format for a Additional Data Packet. */
629 struct vmadditional_data {
630 struct vmpacket_descriptor d;
634 unsigned char data[1];
637 union vmpacket_largest_possible_header {
638 struct vmpacket_descriptor simple_hdr;
639 struct vmtransfer_page_packet_header xfer_page_hdr;
640 struct vmgpadl_packet_header gpadl_hdr;
641 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
642 struct vmestablish_gpadl establish_gpadl_hdr;
643 struct vmteardown_gpadl teardown_gpadl_hdr;
644 struct vmdata_gpa_direct data_gpa_direct_hdr;
647 #define VMPACKET_DATA_START_ADDRESS(__packet) \
648 (void *)(((unsigned char *)__packet) + \
649 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
651 #define VMPACKET_DATA_LENGTH(__packet) \
652 ((((struct vmpacket_descriptor)__packet)->len8 - \
653 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
655 #define VMPACKET_TRANSFER_MODE(__packet) \
656 (((struct IMPACT)__packet)->type)
658 enum vmbus_packet_type {
659 VM_PKT_INVALID = 0x0,
661 VM_PKT_ADD_XFER_PAGESET = 0x2,
662 VM_PKT_RM_XFER_PAGESET = 0x3,
663 VM_PKT_ESTABLISH_GPADL = 0x4,
664 VM_PKT_TEARDOWN_GPADL = 0x5,
665 VM_PKT_DATA_INBAND = 0x6,
666 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
667 VM_PKT_DATA_USING_GPADL = 0x8,
668 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
669 VM_PKT_CANCEL_REQUEST = 0xa,
671 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
672 VM_PKT_ADDITIONAL_DATA = 0xd
675 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
678 /* Version 1 messages */
679 enum vmbus_channel_message_type {
680 CHANNELMSG_INVALID = 0,
681 CHANNELMSG_OFFERCHANNEL = 1,
682 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
683 CHANNELMSG_REQUESTOFFERS = 3,
684 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
685 CHANNELMSG_OPENCHANNEL = 5,
686 CHANNELMSG_OPENCHANNEL_RESULT = 6,
687 CHANNELMSG_CLOSECHANNEL = 7,
688 CHANNELMSG_GPADL_HEADER = 8,
689 CHANNELMSG_GPADL_BODY = 9,
690 CHANNELMSG_GPADL_CREATED = 10,
691 CHANNELMSG_GPADL_TEARDOWN = 11,
692 CHANNELMSG_GPADL_TORNDOWN = 12,
693 CHANNELMSG_RELID_RELEASED = 13,
694 CHANNELMSG_INITIATE_CONTACT = 14,
695 CHANNELMSG_VERSION_RESPONSE = 15,
696 CHANNELMSG_UNLOAD = 16,
697 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
698 CHANNELMSG_VIEWRANGE_ADD = 17,
699 CHANNELMSG_VIEWRANGE_REMOVE = 18,
704 struct vmbus_channel_message_header {
705 enum vmbus_channel_message_type msgtype;
709 /* Query VMBus Version parameters */
710 struct vmbus_channel_query_vmbus_version {
711 struct vmbus_channel_message_header header;
715 /* VMBus Version Supported parameters */
716 struct vmbus_channel_version_supported {
717 struct vmbus_channel_message_header header;
718 u8 version_supported;
721 /* Offer Channel parameters */
722 struct vmbus_channel_offer_channel {
723 struct vmbus_channel_message_header header;
724 struct vmbus_channel_offer offer;
728 * win7 and beyond splits this field into a bit field.
730 u8 monitor_allocated:1;
733 * These are new fields added in win7 and later.
734 * Do not access these fields without checking the
735 * negotiated protocol.
737 * If "is_dedicated_interrupt" is set, we must not set the
738 * associated bit in the channel bitmap while sending the
739 * interrupt to the host.
741 * connection_id is to be used in signaling the host.
743 u16 is_dedicated_interrupt:1;
748 /* Rescind Offer parameters */
749 struct vmbus_channel_rescind_offer {
750 struct vmbus_channel_message_header header;
755 * Request Offer -- no parameters, SynIC message contains the partition ID
756 * Set Snoop -- no parameters, SynIC message contains the partition ID
757 * Clear Snoop -- no parameters, SynIC message contains the partition ID
758 * All Offers Delivered -- no parameters, SynIC message contains the partition
760 * Flush Client -- no parameters, SynIC message contains the partition ID
763 /* Open Channel parameters */
764 struct vmbus_channel_open_channel {
765 struct vmbus_channel_message_header header;
767 /* Identifies the specific VMBus channel that is being opened. */
770 /* ID making a particular open request at a channel offer unique. */
773 /* GPADL for the channel's ring buffer. */
774 u32 ringbuffer_gpadlhandle;
777 * Starting with win8, this field will be used to specify
778 * the target virtual processor on which to deliver the interrupt for
779 * the host to guest communication.
780 * Prior to win8, incoming channel interrupts would only
781 * be delivered on cpu 0. Setting this value to 0 would
782 * preserve the earlier behavior.
787 * The upstream ring buffer begins at offset zero in the memory
788 * described by RingBufferGpadlHandle. The downstream ring buffer
789 * follows it at this offset (in pages).
791 u32 downstream_ringbuffer_pageoffset;
793 /* User-specific data to be passed along to the server endpoint. */
794 unsigned char userdata[MAX_USER_DEFINED_BYTES];
797 /* Open Channel Result parameters */
798 struct vmbus_channel_open_result {
799 struct vmbus_channel_message_header header;
805 /* Close channel parameters; */
806 struct vmbus_channel_close_channel {
807 struct vmbus_channel_message_header header;
811 /* Channel Message GPADL */
812 #define GPADL_TYPE_RING_BUFFER 1
813 #define GPADL_TYPE_SERVER_SAVE_AREA 2
814 #define GPADL_TYPE_TRANSACTION 8
817 * The number of PFNs in a GPADL message is defined by the number of
818 * pages that would be spanned by ByteCount and ByteOffset. If the
819 * implied number of PFNs won't fit in this packet, there will be a
820 * follow-up packet that contains more.
822 struct vmbus_channel_gpadl_header {
823 struct vmbus_channel_message_header header;
828 struct gpa_range range[0];
831 /* This is the followup packet that contains more PFNs. */
832 struct vmbus_channel_gpadl_body {
833 struct vmbus_channel_message_header header;
839 struct vmbus_channel_gpadl_created {
840 struct vmbus_channel_message_header header;
846 struct vmbus_channel_gpadl_teardown {
847 struct vmbus_channel_message_header header;
852 struct vmbus_channel_gpadl_torndown {
853 struct vmbus_channel_message_header header;
857 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
858 struct vmbus_channel_view_range_add {
859 struct vmbus_channel_message_header header;
860 PHYSICAL_ADDRESS viewrange_base;
861 u64 viewrange_length;
865 struct vmbus_channel_view_range_remove {
866 struct vmbus_channel_message_header header;
867 PHYSICAL_ADDRESS viewrange_base;
872 struct vmbus_channel_relid_released {
873 struct vmbus_channel_message_header header;
877 struct vmbus_channel_initiate_contact {
878 struct vmbus_channel_message_header header;
879 u32 vmbus_version_requested;
880 u32 target_vcpu; /* The VCPU the host should respond to */
886 struct vmbus_channel_version_response {
887 struct vmbus_channel_message_header header;
888 u8 version_supported;
891 enum vmbus_channel_state {
893 CHANNEL_OPENING_STATE,
895 CHANNEL_OPENED_STATE,
899 * Represents each channel msg on the vmbus connection This is a
900 * variable-size data structure depending on the msg type itself
902 struct vmbus_channel_msginfo {
903 /* Bookkeeping stuff */
904 struct list_head msglistentry;
906 /* So far, this is only used to handle gpadl body message */
907 struct list_head submsglist;
909 /* Synchronize the request/response if needed */
910 struct completion waitevent;
912 struct vmbus_channel_version_supported version_supported;
913 struct vmbus_channel_open_result open_result;
914 struct vmbus_channel_gpadl_torndown gpadl_torndown;
915 struct vmbus_channel_gpadl_created gpadl_created;
916 struct vmbus_channel_version_response version_response;
921 * The channel message that goes out on the "wire".
922 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
924 unsigned char msg[0];
927 struct vmbus_close_msg {
928 struct vmbus_channel_msginfo info;
929 struct vmbus_channel_close_channel msg;
932 /* Define connection identifier type. */
933 union hv_connection_id {
941 /* Definition of the hv_signal_event hypercall input structure. */
942 struct hv_input_signal_event {
943 union hv_connection_id connectionid;
948 struct hv_input_signal_event_buffer {
950 struct hv_input_signal_event event;
953 struct vmbus_channel {
954 struct list_head listentry;
956 struct hv_device *device_obj;
958 struct work_struct work;
960 enum vmbus_channel_state state;
962 struct vmbus_channel_offer_channel offermsg;
964 * These are based on the OfferMsg.MonitorId.
965 * Save it here for easy access.
970 u32 ringbuffer_gpadlhandle;
972 /* Allocated memory for ring buffer */
973 void *ringbuffer_pages;
974 u32 ringbuffer_pagecount;
975 struct hv_ring_buffer_info outbound; /* send to parent */
976 struct hv_ring_buffer_info inbound; /* receive from parent */
977 spinlock_t inbound_lock;
978 struct workqueue_struct *controlwq;
980 struct vmbus_close_msg close_msg;
982 /* Channel callback are invoked in this workqueue context */
983 /* HANDLE dataWorkQueue; */
985 void (*onchannel_callback)(void *context);
986 void *channel_callback_context;
989 * A channel can be marked for efficient (batched)
991 * If batched_reading is set to "true", we read until the
992 * channel is empty and hold off interrupts from the host
993 * during the entire read process.
994 * If batched_reading is set to "false", the client is not
995 * going to perform batched reading.
997 * By default we will enable batched reading; specific
998 * drivers that don't want this behavior can turn it off.
1001 bool batched_reading;
1003 bool is_dedicated_interrupt;
1004 struct hv_input_signal_event_buffer sig_buf;
1005 struct hv_input_signal_event *sig_event;
1008 * Starting with win8, this field will be used to specify
1009 * the target virtual processor on which to deliver the interrupt for
1010 * the host to guest communication.
1011 * Prior to win8, incoming channel interrupts would only
1012 * be delivered on cpu 0. Setting this value to 0 would
1013 * preserve the earlier behavior.
1017 * Support for sub-channels. For high performance devices,
1018 * it will be useful to have multiple sub-channels to support
1019 * a scalable communication infrastructure with the host.
1020 * The support for sub-channels is implemented as an extention
1021 * to the current infrastructure.
1022 * The initial offer is considered the primary channel and this
1023 * offer message will indicate if the host supports sub-channels.
1024 * The guest is free to ask for sub-channels to be offerred and can
1025 * open these sub-channels as a normal "primary" channel. However,
1026 * all sub-channels will have the same type and instance guids as the
1027 * primary channel. Requests sent on a given channel will result in a
1028 * response on the same channel.
1032 * Sub-channel creation callback. This callback will be called in
1033 * process context when a sub-channel offer is received from the host.
1034 * The guest can open the sub-channel in the context of this callback.
1036 void (*sc_creation_callback)(struct vmbus_channel *new_sc);
1040 * All Sub-channels of a primary channel are linked here.
1042 struct list_head sc_list;
1044 * The primary channel this sub-channel belongs to.
1045 * This will be NULL for the primary channel.
1047 struct vmbus_channel *primary_channel;
1050 static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
1052 c->batched_reading = state;
1055 void vmbus_onmessage(void *context);
1057 int vmbus_request_offers(void);
1060 * APIs for managing sub-channels.
1063 void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
1064 void (*sc_cr_cb)(struct vmbus_channel *new_sc));
1067 * Retrieve the (sub) channel on which to send an outgoing request.
1068 * When a primary channel has multiple sub-channels, we choose a
1069 * channel whose VCPU binding is closest to the VCPU on which
1070 * this call is being made.
1072 struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
1075 * Check if sub-channels have already been offerred. This API will be useful
1076 * when the driver is unloaded after establishing sub-channels. In this case,
1077 * when the driver is re-loaded, the driver would have to check if the
1078 * subchannels have already been established before attempting to request
1079 * the creation of sub-channels.
1080 * This function returns TRUE to indicate that subchannels have already been
1082 * This function should be invoked after setting the callback function for
1083 * sub-channel creation.
1085 bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
1087 /* The format must be the same as struct vmdata_gpa_direct */
1088 struct vmbus_channel_packet_page_buffer {
1096 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
1099 /* The format must be the same as struct vmdata_gpa_direct */
1100 struct vmbus_channel_packet_multipage_buffer {
1107 u32 rangecount; /* Always 1 in this case */
1108 struct hv_multipage_buffer range;
1112 extern int vmbus_open(struct vmbus_channel *channel,
1113 u32 send_ringbuffersize,
1114 u32 recv_ringbuffersize,
1117 void(*onchannel_callback)(void *context),
1120 extern void vmbus_close(struct vmbus_channel *channel);
1122 extern int vmbus_sendpacket(struct vmbus_channel *channel,
1126 enum vmbus_packet_type type,
1129 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
1130 struct hv_page_buffer pagebuffers[],
1136 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
1137 struct hv_multipage_buffer *mpb,
1142 extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
1147 extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
1150 extern int vmbus_recvpacket(struct vmbus_channel *channel,
1153 u32 *buffer_actual_len,
1156 extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
1159 u32 *buffer_actual_len,
1163 extern void vmbus_ontimer(unsigned long data);
1165 /* Base driver object */
1169 /* the device type supported by this driver */
1171 const struct hv_vmbus_device_id *id_table;
1173 struct device_driver driver;
1175 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
1176 int (*remove)(struct hv_device *);
1177 void (*shutdown)(struct hv_device *);
1181 /* Base device object */
1183 /* the device type id of this device */
1186 /* the device instance id of this device */
1187 uuid_le dev_instance;
1189 struct device device;
1191 struct vmbus_channel *channel;
1195 static inline struct hv_device *device_to_hv_device(struct device *d)
1197 return container_of(d, struct hv_device, device);
1200 static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1202 return container_of(d, struct hv_driver, driver);
1205 static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1207 dev_set_drvdata(&dev->device, data);
1210 static inline void *hv_get_drvdata(struct hv_device *dev)
1212 return dev_get_drvdata(&dev->device);
1215 /* Vmbus interface */
1216 #define vmbus_driver_register(driver) \
1217 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1218 int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1219 struct module *owner,
1220 const char *mod_name);
1221 void vmbus_driver_unregister(struct hv_driver *hv_driver);
1224 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1226 * This macro is used to create a struct hv_vmbus_device_id that matches a
1229 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1230 g8, g9, ga, gb, gc, gd, ge, gf) \
1231 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1232 g8, g9, ga, gb, gc, gd, ge, gf },
1235 * GUID definitions of various offer types - services offered to the guest.
1240 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1242 #define HV_NIC_GUID \
1244 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1245 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1250 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1252 #define HV_IDE_GUID \
1254 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1255 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1260 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1262 #define HV_SCSI_GUID \
1264 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1265 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1270 * {0e0b6031-5213-4934-818b-38d90ced39db}
1272 #define HV_SHUTDOWN_GUID \
1274 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1275 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1280 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1282 #define HV_TS_GUID \
1284 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1285 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1290 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1292 #define HV_HEART_BEAT_GUID \
1294 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1295 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1300 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1302 #define HV_KVP_GUID \
1304 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1305 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1309 * Dynamic memory GUID
1310 * {525074dc-8985-46e2-8057-a307dc18a502}
1312 #define HV_DM_GUID \
1314 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1315 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1320 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1322 #define HV_MOUSE_GUID \
1324 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1325 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1329 * VSS (Backup/Restore) GUID
1331 #define HV_VSS_GUID \
1333 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1334 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1337 * Synthetic Video GUID
1338 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1340 #define HV_SYNTHVID_GUID \
1342 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
1343 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
1348 * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
1350 #define HV_SYNTHFC_GUID \
1352 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
1353 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
1357 * Common header for Hyper-V ICs
1360 #define ICMSGTYPE_NEGOTIATE 0
1361 #define ICMSGTYPE_HEARTBEAT 1
1362 #define ICMSGTYPE_KVPEXCHANGE 2
1363 #define ICMSGTYPE_SHUTDOWN 3
1364 #define ICMSGTYPE_TIMESYNC 4
1365 #define ICMSGTYPE_VSS 5
1367 #define ICMSGHDRFLAG_TRANSACTION 1
1368 #define ICMSGHDRFLAG_REQUEST 2
1369 #define ICMSGHDRFLAG_RESPONSE 4
1373 * While we want to handle util services as regular devices,
1374 * there is only one instance of each of these services; so
1375 * we statically allocate the service specific state.
1378 struct hv_util_service {
1380 void (*util_cb)(void *);
1381 int (*util_init)(struct hv_util_service *);
1382 void (*util_deinit)(void);
1385 struct vmbuspipe_hdr {
1396 struct ic_version icverframe;
1398 struct ic_version icvermsg;
1401 u8 ictransaction_id;
1406 struct icmsg_negotiate {
1410 struct ic_version icversion_data[1]; /* any size array */
1413 struct shutdown_msg_data {
1415 u32 timeout_seconds;
1417 u8 display_message[2048];
1420 struct heartbeat_msg_data {
1425 /* Time Sync IC defs */
1426 #define ICTIMESYNCFLAG_PROBE 0
1427 #define ICTIMESYNCFLAG_SYNC 1
1428 #define ICTIMESYNCFLAG_SAMPLE 2
1431 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1433 #define WLTIMEDELTA 116444736000000000LL
1436 struct ictimesync_data {
1443 struct hyperv_service_callback {
1447 struct vmbus_channel *channel;
1448 void (*callback) (void *context);
1451 #define MAX_SRV_VER 0x7ffffff
1452 extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
1453 struct icmsg_negotiate *, u8 *, int,
1456 int hv_kvp_init(struct hv_util_service *);
1457 void hv_kvp_deinit(void);
1458 void hv_kvp_onchannelcallback(void *);
1460 int hv_vss_init(struct hv_util_service *);
1461 void hv_vss_deinit(void);
1462 void hv_vss_onchannelcallback(void *);
1465 * Negotiated version with the Host.
1468 extern __u32 vmbus_proto_version;
1470 #endif /* __KERNEL__ */
1471 #endif /* _HYPERV_H */