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.
34 #define UTIL_FW_MAJOR 3
35 #define UTIL_FW_MINOR 0
36 #define UTIL_FW_MAJOR_MINOR (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
40 * Implementation of host controlled snapshot of the guest.
43 #define VSS_OP_REGISTER 128
52 * Following operations are only supported with IC version >= 5.0
54 VSS_OP_FREEZE
, /* Freeze the file systems in the VM */
55 VSS_OP_THAW
, /* Unfreeze the file systems */
57 VSS_OP_COUNT
/* Number of operations, must be last */
62 * Header for all VSS messages.
67 } __attribute__((packed
));
71 * Flag values for the hv_vss_check_feature. Linux supports only
74 #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
76 struct hv_vss_check_feature
{
78 } __attribute__((packed
));
80 struct hv_vss_check_dm_info
{
82 } __attribute__((packed
));
86 struct hv_vss_hdr vss_hdr
;
90 struct hv_vss_check_feature vss_cf
;
91 struct hv_vss_check_dm_info dm_info
;
93 } __attribute__((packed
));
96 * An implementation of HyperV key value pair (KVP) functionality for Linux.
99 * Copyright (C) 2010, Novell, Inc.
100 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
105 * Maximum value size - used for both key names and value data, and includes
106 * any applicable NULL terminators.
108 * Note: This limit is somewhat arbitrary, but falls easily within what is
109 * supported for all native guests (back to Win 2000) and what is reasonable
110 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
111 * limited to 255 character key names.
113 * MSDN recommends not storing data values larger than 2048 bytes in the
116 * Note: This value is used in defining the KVP exchange message - this value
117 * cannot be modified without affecting the message size and compatibility.
121 * bytes, including any null terminators
123 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
127 * Maximum key size - the registry limit for the length of an entry name
128 * is 256 characters, including the null terminator
131 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
134 * In Linux, we implement the KVP functionality in two components:
135 * 1) The kernel component which is packaged as part of the hv_utils driver
136 * is responsible for communicating with the host and responsible for
137 * implementing the host/guest protocol. 2) A user level daemon that is
138 * responsible for data gathering.
140 * Host/Guest Protocol: The host iterates over an index and expects the guest
141 * to assign a key name to the index and also return the value corresponding to
142 * the key. The host will have atmost one KVP transaction outstanding at any
143 * given point in time. The host side iteration stops when the guest returns
144 * an error. Microsoft has specified the following mapping of key names to
145 * host specified index:
148 * 0 FullyQualifiedDomainName
149 * 1 IntegrationServicesVersion
150 * 2 NetworkAddressIPv4
151 * 3 NetworkAddressIPv6
157 * 9 ProcessorArchitecture
159 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
161 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
162 * data gathering functionality in a user mode daemon. The user level daemon
163 * is also responsible for binding the key name to the index as well. The
164 * kernel and user-level daemon communicate using a connector channel.
166 * The user mode component first registers with the
167 * the kernel component. Subsequently, the kernel component requests, data
168 * for the specified keys. In response to this message the user mode component
169 * fills in the value corresponding to the specified key. We overload the
170 * sequence field in the cn_msg header to define our KVP message types.
173 * The kernel component simply acts as a conduit for communication between the
174 * Windows host and the user-level daemon. The kernel component passes up the
175 * index received from the Host to the user-level daemon. If the index is
176 * valid (supported), the corresponding key as well as its
177 * value (both are strings) is returned. If the index is invalid
178 * (not supported), a NULL key string is returned.
183 * Registry value types.
191 * As we look at expanding the KVP functionality to include
192 * IP injection functionality, we need to maintain binary
193 * compatibility with older daemons.
195 * The KVP opcodes are defined by the host and it was unfortunate
196 * that I chose to treat the registration operation as part of the
197 * KVP operations defined by the host.
198 * Here is the level of compatibility
199 * (between the user level daemon and the kernel KVP driver) that we
202 * An older daemon will always be supported on a newer driver.
203 * A given user level daemon will require a minimal version of the
205 * If we cannot handle the version differences, we will fail gracefully
206 * (this can happen when we have a user level daemon that is more
207 * advanced than the KVP driver.
209 * We will use values used in this handshake for determining if we have
210 * workable user level daemon and the kernel driver. We begin by taking the
211 * registration opcode out of the KVP opcode namespace. We will however,
212 * maintain compatibility with the existing user-level daemon code.
216 * Daemon code not supporting IP injection (legacy daemon).
219 #define KVP_OP_REGISTER 4
222 * Daemon code supporting IP injection.
223 * The KVP opcode field is used to communicate the
224 * registration information; so define a namespace that
225 * will be distinct from the host defined KVP opcode.
228 #define KVP_OP_REGISTER1 100
230 enum hv_kvp_exchg_op
{
237 KVP_OP_COUNT
/* Number of operations, must be last. */
240 enum hv_kvp_exchg_pool
{
241 KVP_POOL_EXTERNAL
= 0,
244 KVP_POOL_AUTO_EXTERNAL
,
245 KVP_POOL_AUTO_INTERNAL
,
246 KVP_POOL_COUNT
/* Number of pools, must be last. */
250 * Some Hyper-V status codes.
253 #define HV_S_OK 0x00000000
254 #define HV_E_FAIL 0x80004005
255 #define HV_S_CONT 0x80070103
256 #define HV_ERROR_NOT_SUPPORTED 0x80070032
257 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
258 #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
259 #define HV_INVALIDARG 0x80070057
260 #define HV_GUID_NOTFOUND 0x80041002
262 #define ADDR_FAMILY_NONE 0x00
263 #define ADDR_FAMILY_IPV4 0x01
264 #define ADDR_FAMILY_IPV6 0x02
266 #define MAX_ADAPTER_ID_SIZE 128
267 #define MAX_IP_ADDR_SIZE 1024
268 #define MAX_GATEWAY_SIZE 512
271 struct hv_kvp_ipaddr_value
{
272 __u16 adapter_id
[MAX_ADAPTER_ID_SIZE
];
275 __u16 ip_addr
[MAX_IP_ADDR_SIZE
];
276 __u16 sub_net
[MAX_IP_ADDR_SIZE
];
277 __u16 gate_way
[MAX_GATEWAY_SIZE
];
278 __u16 dns_addr
[MAX_IP_ADDR_SIZE
];
279 } __attribute__((packed
));
286 } __attribute__((packed
));
288 struct hv_kvp_exchg_msg_value
{
292 __u8 key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
294 __u8 value
[HV_KVP_EXCHANGE_MAX_VALUE_SIZE
];
298 } __attribute__((packed
));
300 struct hv_kvp_msg_enumerate
{
302 struct hv_kvp_exchg_msg_value data
;
303 } __attribute__((packed
));
305 struct hv_kvp_msg_get
{
306 struct hv_kvp_exchg_msg_value data
;
309 struct hv_kvp_msg_set
{
310 struct hv_kvp_exchg_msg_value data
;
313 struct hv_kvp_msg_delete
{
315 __u8 key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
318 struct hv_kvp_register
{
319 __u8 version
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
324 struct hv_kvp_hdr kvp_hdr
;
328 struct hv_kvp_msg_get kvp_get
;
329 struct hv_kvp_msg_set kvp_set
;
330 struct hv_kvp_msg_delete kvp_delete
;
331 struct hv_kvp_msg_enumerate kvp_enum_data
;
332 struct hv_kvp_ipaddr_value kvp_ip_val
;
333 struct hv_kvp_register kvp_register
;
335 } __attribute__((packed
));
337 struct hv_kvp_ip_msg
{
340 struct hv_kvp_ipaddr_value kvp_ip_val
;
341 } __attribute__((packed
));
344 #include <linux/scatterlist.h>
345 #include <linux/list.h>
346 #include <linux/uuid.h>
347 #include <linux/timer.h>
348 #include <linux/workqueue.h>
349 #include <linux/completion.h>
350 #include <linux/device.h>
351 #include <linux/mod_devicetable.h>
354 #define MAX_PAGE_BUFFER_COUNT 19
355 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
357 #pragma pack(push, 1)
359 /* Single-page buffer */
360 struct hv_page_buffer
{
366 /* Multiple-page buffer */
367 struct hv_multipage_buffer
{
368 /* Length and Offset determines the # of pfns in the array */
371 u64 pfn_array
[MAX_MULTIPAGE_BUFFER_COUNT
];
374 /* 0x18 includes the proprietary packet header */
375 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
376 (sizeof(struct hv_page_buffer) * \
377 MAX_PAGE_BUFFER_COUNT))
378 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
379 sizeof(struct hv_multipage_buffer))
384 struct hv_ring_buffer
{
385 /* Offset in bytes from the start of ring data below */
388 /* Offset in bytes from the start of ring data below */
394 * Win8 uses some of the reserved bits to implement
395 * interrupt driven flow management. On the send side
396 * we can request that the receiver interrupt the sender
397 * when the ring transitions from being full to being able
398 * to handle a message of size "pending_send_sz".
400 * Add necessary state for this enhancement.
408 u32 feat_pending_send_sz
:1;
413 /* Pad it to PAGE_SIZE so that data starts on page boundary */
417 * Ring data starts here + RingDataStartOffset
418 * !!! DO NOT place any fields below this !!!
423 struct hv_ring_buffer_info
{
424 struct hv_ring_buffer
*ring_buffer
;
425 u32 ring_size
; /* Include the shared header */
426 spinlock_t ring_lock
;
428 u32 ring_datasize
; /* < ring_size */
429 u32 ring_data_startoffset
;
432 struct hv_ring_buffer_debug_info
{
433 u32 current_interrupt_mask
;
434 u32 current_read_index
;
435 u32 current_write_index
;
436 u32 bytes_avail_toread
;
437 u32 bytes_avail_towrite
;
443 * hv_get_ringbuffer_availbytes()
445 * Get number of bytes available to read and to write to
446 * for the specified ring buffer
449 hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info
*rbi
,
450 u32
*read
, u32
*write
)
452 u32 read_loc
, write_loc
, dsize
;
454 smp_read_barrier_depends();
456 /* Capture the read/write indices before they changed */
457 read_loc
= rbi
->ring_buffer
->read_index
;
458 write_loc
= rbi
->ring_buffer
->write_index
;
459 dsize
= rbi
->ring_datasize
;
461 *write
= write_loc
>= read_loc
? dsize
- (write_loc
- read_loc
) :
462 read_loc
- write_loc
;
463 *read
= dsize
- *write
;
467 * VMBUS version is 32 bit entity broken up into
468 * two 16 bit quantities: major_number. minor_number.
470 * 0 . 13 (Windows Server 2008)
475 #define VERSION_WS2008 ((0 << 16) | (13))
476 #define VERSION_WIN7 ((1 << 16) | (1))
477 #define VERSION_WIN8 ((2 << 16) | (4))
479 #define VERSION_INVAL -1
481 #define VERSION_CURRENT VERSION_WIN8
483 /* Make maximum size of pipe payload of 16K */
484 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
486 /* Define PipeMode values. */
487 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
488 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
490 /* The size of the user defined data buffer for non-pipe offers. */
491 #define MAX_USER_DEFINED_BYTES 120
493 /* The size of the user defined data buffer for pipe offers. */
494 #define MAX_PIPE_USER_DEFINED_BYTES 116
497 * At the center of the Channel Management library is the Channel Offer. This
498 * struct contains the fundamental information about an offer.
500 struct vmbus_channel_offer
{
505 * These two fields are not currently used.
511 u16 mmio_megabytes
; /* in bytes * 1024 * 1024 */
514 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
516 unsigned char user_def
[MAX_USER_DEFINED_BYTES
];
521 * The following sructure is an integrated pipe protocol, which
522 * is implemented on top of standard user-defined data. Pipe
523 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
528 unsigned char user_def
[MAX_PIPE_USER_DEFINED_BYTES
];
532 * The sub_channel_index is defined in win8.
534 u16 sub_channel_index
;
539 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
540 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
541 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
542 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
543 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
544 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
545 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
547 struct vmpacket_descriptor
{
555 struct vmpacket_header
{
556 u32 prev_pkt_start_offset
;
557 struct vmpacket_descriptor descriptor
;
560 struct vmtransfer_page_range
{
565 struct vmtransfer_page_packet_header
{
566 struct vmpacket_descriptor d
;
571 struct vmtransfer_page_range ranges
[1];
574 struct vmgpadl_packet_header
{
575 struct vmpacket_descriptor d
;
580 struct vmadd_remove_transfer_page_set
{
581 struct vmpacket_descriptor d
;
588 * This structure defines a range in guest physical space that can be made to
589 * look virtually contiguous.
598 * This is the format for an Establish Gpadl packet, which contains a handle by
599 * which this GPADL will be known and a set of GPA ranges associated with it.
600 * This can be converted to a MDL by the guest OS. If there are multiple GPA
601 * ranges, then the resulting MDL will be "chained," representing multiple VA
604 struct vmestablish_gpadl
{
605 struct vmpacket_descriptor d
;
608 struct gpa_range range
[1];
612 * This is the format for a Teardown Gpadl packet, which indicates that the
613 * GPADL handle in the Establish Gpadl packet will never be referenced again.
615 struct vmteardown_gpadl
{
616 struct vmpacket_descriptor d
;
618 u32 reserved
; /* for alignment to a 8-byte boundary */
622 * This is the format for a GPA-Direct packet, which contains a set of GPA
623 * ranges, in addition to commands and/or data.
625 struct vmdata_gpa_direct
{
626 struct vmpacket_descriptor d
;
629 struct gpa_range range
[1];
632 /* This is the format for a Additional Data Packet. */
633 struct vmadditional_data
{
634 struct vmpacket_descriptor d
;
638 unsigned char data
[1];
641 union vmpacket_largest_possible_header
{
642 struct vmpacket_descriptor simple_hdr
;
643 struct vmtransfer_page_packet_header xfer_page_hdr
;
644 struct vmgpadl_packet_header gpadl_hdr
;
645 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr
;
646 struct vmestablish_gpadl establish_gpadl_hdr
;
647 struct vmteardown_gpadl teardown_gpadl_hdr
;
648 struct vmdata_gpa_direct data_gpa_direct_hdr
;
651 #define VMPACKET_DATA_START_ADDRESS(__packet) \
652 (void *)(((unsigned char *)__packet) + \
653 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
655 #define VMPACKET_DATA_LENGTH(__packet) \
656 ((((struct vmpacket_descriptor)__packet)->len8 - \
657 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
659 #define VMPACKET_TRANSFER_MODE(__packet) \
660 (((struct IMPACT)__packet)->type)
662 enum vmbus_packet_type
{
663 VM_PKT_INVALID
= 0x0,
665 VM_PKT_ADD_XFER_PAGESET
= 0x2,
666 VM_PKT_RM_XFER_PAGESET
= 0x3,
667 VM_PKT_ESTABLISH_GPADL
= 0x4,
668 VM_PKT_TEARDOWN_GPADL
= 0x5,
669 VM_PKT_DATA_INBAND
= 0x6,
670 VM_PKT_DATA_USING_XFER_PAGES
= 0x7,
671 VM_PKT_DATA_USING_GPADL
= 0x8,
672 VM_PKT_DATA_USING_GPA_DIRECT
= 0x9,
673 VM_PKT_CANCEL_REQUEST
= 0xa,
675 VM_PKT_DATA_USING_ADDITIONAL_PKT
= 0xc,
676 VM_PKT_ADDITIONAL_DATA
= 0xd
679 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
682 /* Version 1 messages */
683 enum vmbus_channel_message_type
{
684 CHANNELMSG_INVALID
= 0,
685 CHANNELMSG_OFFERCHANNEL
= 1,
686 CHANNELMSG_RESCIND_CHANNELOFFER
= 2,
687 CHANNELMSG_REQUESTOFFERS
= 3,
688 CHANNELMSG_ALLOFFERS_DELIVERED
= 4,
689 CHANNELMSG_OPENCHANNEL
= 5,
690 CHANNELMSG_OPENCHANNEL_RESULT
= 6,
691 CHANNELMSG_CLOSECHANNEL
= 7,
692 CHANNELMSG_GPADL_HEADER
= 8,
693 CHANNELMSG_GPADL_BODY
= 9,
694 CHANNELMSG_GPADL_CREATED
= 10,
695 CHANNELMSG_GPADL_TEARDOWN
= 11,
696 CHANNELMSG_GPADL_TORNDOWN
= 12,
697 CHANNELMSG_RELID_RELEASED
= 13,
698 CHANNELMSG_INITIATE_CONTACT
= 14,
699 CHANNELMSG_VERSION_RESPONSE
= 15,
700 CHANNELMSG_UNLOAD
= 16,
701 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
702 CHANNELMSG_VIEWRANGE_ADD
= 17,
703 CHANNELMSG_VIEWRANGE_REMOVE
= 18,
708 struct vmbus_channel_message_header
{
709 enum vmbus_channel_message_type msgtype
;
713 /* Query VMBus Version parameters */
714 struct vmbus_channel_query_vmbus_version
{
715 struct vmbus_channel_message_header header
;
719 /* VMBus Version Supported parameters */
720 struct vmbus_channel_version_supported
{
721 struct vmbus_channel_message_header header
;
722 u8 version_supported
;
725 /* Offer Channel parameters */
726 struct vmbus_channel_offer_channel
{
727 struct vmbus_channel_message_header header
;
728 struct vmbus_channel_offer offer
;
732 * win7 and beyond splits this field into a bit field.
734 u8 monitor_allocated
:1;
737 * These are new fields added in win7 and later.
738 * Do not access these fields without checking the
739 * negotiated protocol.
741 * If "is_dedicated_interrupt" is set, we must not set the
742 * associated bit in the channel bitmap while sending the
743 * interrupt to the host.
745 * connection_id is to be used in signaling the host.
747 u16 is_dedicated_interrupt
:1;
752 /* Rescind Offer parameters */
753 struct vmbus_channel_rescind_offer
{
754 struct vmbus_channel_message_header header
;
759 * Request Offer -- no parameters, SynIC message contains the partition ID
760 * Set Snoop -- no parameters, SynIC message contains the partition ID
761 * Clear Snoop -- no parameters, SynIC message contains the partition ID
762 * All Offers Delivered -- no parameters, SynIC message contains the partition
764 * Flush Client -- no parameters, SynIC message contains the partition ID
767 /* Open Channel parameters */
768 struct vmbus_channel_open_channel
{
769 struct vmbus_channel_message_header header
;
771 /* Identifies the specific VMBus channel that is being opened. */
774 /* ID making a particular open request at a channel offer unique. */
777 /* GPADL for the channel's ring buffer. */
778 u32 ringbuffer_gpadlhandle
;
781 * Starting with win8, this field will be used to specify
782 * the target virtual processor on which to deliver the interrupt for
783 * the host to guest communication.
784 * Prior to win8, incoming channel interrupts would only
785 * be delivered on cpu 0. Setting this value to 0 would
786 * preserve the earlier behavior.
791 * The upstream ring buffer begins at offset zero in the memory
792 * described by RingBufferGpadlHandle. The downstream ring buffer
793 * follows it at this offset (in pages).
795 u32 downstream_ringbuffer_pageoffset
;
797 /* User-specific data to be passed along to the server endpoint. */
798 unsigned char userdata
[MAX_USER_DEFINED_BYTES
];
801 /* Open Channel Result parameters */
802 struct vmbus_channel_open_result
{
803 struct vmbus_channel_message_header header
;
809 /* Close channel parameters; */
810 struct vmbus_channel_close_channel
{
811 struct vmbus_channel_message_header header
;
815 /* Channel Message GPADL */
816 #define GPADL_TYPE_RING_BUFFER 1
817 #define GPADL_TYPE_SERVER_SAVE_AREA 2
818 #define GPADL_TYPE_TRANSACTION 8
821 * The number of PFNs in a GPADL message is defined by the number of
822 * pages that would be spanned by ByteCount and ByteOffset. If the
823 * implied number of PFNs won't fit in this packet, there will be a
824 * follow-up packet that contains more.
826 struct vmbus_channel_gpadl_header
{
827 struct vmbus_channel_message_header header
;
832 struct gpa_range range
[0];
835 /* This is the followup packet that contains more PFNs. */
836 struct vmbus_channel_gpadl_body
{
837 struct vmbus_channel_message_header header
;
843 struct vmbus_channel_gpadl_created
{
844 struct vmbus_channel_message_header header
;
850 struct vmbus_channel_gpadl_teardown
{
851 struct vmbus_channel_message_header header
;
856 struct vmbus_channel_gpadl_torndown
{
857 struct vmbus_channel_message_header header
;
861 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
862 struct vmbus_channel_view_range_add
{
863 struct vmbus_channel_message_header header
;
864 PHYSICAL_ADDRESS viewrange_base
;
865 u64 viewrange_length
;
869 struct vmbus_channel_view_range_remove
{
870 struct vmbus_channel_message_header header
;
871 PHYSICAL_ADDRESS viewrange_base
;
876 struct vmbus_channel_relid_released
{
877 struct vmbus_channel_message_header header
;
881 struct vmbus_channel_initiate_contact
{
882 struct vmbus_channel_message_header header
;
883 u32 vmbus_version_requested
;
890 struct vmbus_channel_version_response
{
891 struct vmbus_channel_message_header header
;
892 u8 version_supported
;
895 enum vmbus_channel_state
{
897 CHANNEL_OPENING_STATE
,
899 CHANNEL_OPENED_STATE
,
902 struct vmbus_channel_debug_info
{
904 enum vmbus_channel_state state
;
905 uuid_le interfacetype
;
906 uuid_le interface_instance
;
908 u32 servermonitor_pending
;
909 u32 servermonitor_latency
;
910 u32 servermonitor_connectionid
;
911 u32 clientmonitor_pending
;
912 u32 clientmonitor_latency
;
913 u32 clientmonitor_connectionid
;
915 struct hv_ring_buffer_debug_info inbound
;
916 struct hv_ring_buffer_debug_info outbound
;
920 * Represents each channel msg on the vmbus connection This is a
921 * variable-size data structure depending on the msg type itself
923 struct vmbus_channel_msginfo
{
924 /* Bookkeeping stuff */
925 struct list_head msglistentry
;
927 /* So far, this is only used to handle gpadl body message */
928 struct list_head submsglist
;
930 /* Synchronize the request/response if needed */
931 struct completion waitevent
;
933 struct vmbus_channel_version_supported version_supported
;
934 struct vmbus_channel_open_result open_result
;
935 struct vmbus_channel_gpadl_torndown gpadl_torndown
;
936 struct vmbus_channel_gpadl_created gpadl_created
;
937 struct vmbus_channel_version_response version_response
;
942 * The channel message that goes out on the "wire".
943 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
945 unsigned char msg
[0];
948 struct vmbus_close_msg
{
949 struct vmbus_channel_msginfo info
;
950 struct vmbus_channel_close_channel msg
;
953 /* Define connection identifier type. */
954 union hv_connection_id
{
962 /* Definition of the hv_signal_event hypercall input structure. */
963 struct hv_input_signal_event
{
964 union hv_connection_id connectionid
;
969 struct hv_input_signal_event_buffer
{
971 struct hv_input_signal_event event
;
974 struct vmbus_channel
{
975 struct list_head listentry
;
977 struct hv_device
*device_obj
;
979 struct work_struct work
;
981 enum vmbus_channel_state state
;
983 struct vmbus_channel_offer_channel offermsg
;
985 * These are based on the OfferMsg.MonitorId.
986 * Save it here for easy access.
991 u32 ringbuffer_gpadlhandle
;
993 /* Allocated memory for ring buffer */
994 void *ringbuffer_pages
;
995 u32 ringbuffer_pagecount
;
996 struct hv_ring_buffer_info outbound
; /* send to parent */
997 struct hv_ring_buffer_info inbound
; /* receive from parent */
998 spinlock_t inbound_lock
;
999 struct workqueue_struct
*controlwq
;
1001 struct vmbus_close_msg close_msg
;
1003 /* Channel callback are invoked in this workqueue context */
1004 /* HANDLE dataWorkQueue; */
1006 void (*onchannel_callback
)(void *context
);
1007 void *channel_callback_context
;
1010 * A channel can be marked for efficient (batched)
1012 * If batched_reading is set to "true", we read until the
1013 * channel is empty and hold off interrupts from the host
1014 * during the entire read process.
1015 * If batched_reading is set to "false", the client is not
1016 * going to perform batched reading.
1018 * By default we will enable batched reading; specific
1019 * drivers that don't want this behavior can turn it off.
1022 bool batched_reading
;
1024 bool is_dedicated_interrupt
;
1025 struct hv_input_signal_event_buffer sig_buf
;
1026 struct hv_input_signal_event
*sig_event
;
1029 * Starting with win8, this field will be used to specify
1030 * the target virtual processor on which to deliver the interrupt for
1031 * the host to guest communication.
1032 * Prior to win8, incoming channel interrupts would only
1033 * be delivered on cpu 0. Setting this value to 0 would
1034 * preserve the earlier behavior.
1038 * Support for sub-channels. For high performance devices,
1039 * it will be useful to have multiple sub-channels to support
1040 * a scalable communication infrastructure with the host.
1041 * The support for sub-channels is implemented as an extention
1042 * to the current infrastructure.
1043 * The initial offer is considered the primary channel and this
1044 * offer message will indicate if the host supports sub-channels.
1045 * The guest is free to ask for sub-channels to be offerred and can
1046 * open these sub-channels as a normal "primary" channel. However,
1047 * all sub-channels will have the same type and instance guids as the
1048 * primary channel. Requests sent on a given channel will result in a
1049 * response on the same channel.
1053 * Sub-channel creation callback. This callback will be called in
1054 * process context when a sub-channel offer is received from the host.
1055 * The guest can open the sub-channel in the context of this callback.
1057 void (*sc_creation_callback
)(struct vmbus_channel
*new_sc
);
1061 * All Sub-channels of a primary channel are linked here.
1063 struct list_head sc_list
;
1065 * The primary channel this sub-channel belongs to.
1066 * This will be NULL for the primary channel.
1068 struct vmbus_channel
*primary_channel
;
1071 static inline void set_channel_read_state(struct vmbus_channel
*c
, bool state
)
1073 c
->batched_reading
= state
;
1076 void vmbus_onmessage(void *context
);
1078 int vmbus_request_offers(void);
1081 * APIs for managing sub-channels.
1084 void vmbus_set_sc_create_callback(struct vmbus_channel
*primary_channel
,
1085 void (*sc_cr_cb
)(struct vmbus_channel
*new_sc
));
1088 * Retrieve the (sub) channel on which to send an outgoing request.
1089 * When a primary channel has multiple sub-channels, we choose a
1090 * channel whose VCPU binding is closest to the VCPU on which
1091 * this call is being made.
1093 struct vmbus_channel
*vmbus_get_outgoing_channel(struct vmbus_channel
*primary
);
1096 * Check if sub-channels have already been offerred. This API will be useful
1097 * when the driver is unloaded after establishing sub-channels. In this case,
1098 * when the driver is re-loaded, the driver would have to check if the
1099 * subchannels have already been established before attempting to request
1100 * the creation of sub-channels.
1101 * This function returns TRUE to indicate that subchannels have already been
1103 * This function should be invoked after setting the callback function for
1104 * sub-channel creation.
1106 bool vmbus_are_subchannels_present(struct vmbus_channel
*primary
);
1108 /* The format must be the same as struct vmdata_gpa_direct */
1109 struct vmbus_channel_packet_page_buffer
{
1117 struct hv_page_buffer range
[MAX_PAGE_BUFFER_COUNT
];
1120 /* The format must be the same as struct vmdata_gpa_direct */
1121 struct vmbus_channel_packet_multipage_buffer
{
1128 u32 rangecount
; /* Always 1 in this case */
1129 struct hv_multipage_buffer range
;
1133 extern int vmbus_open(struct vmbus_channel
*channel
,
1134 u32 send_ringbuffersize
,
1135 u32 recv_ringbuffersize
,
1138 void(*onchannel_callback
)(void *context
),
1141 extern void vmbus_close(struct vmbus_channel
*channel
);
1143 extern int vmbus_sendpacket(struct vmbus_channel
*channel
,
1147 enum vmbus_packet_type type
,
1150 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel
*channel
,
1151 struct hv_page_buffer pagebuffers
[],
1157 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel
*channel
,
1158 struct hv_multipage_buffer
*mpb
,
1163 extern int vmbus_establish_gpadl(struct vmbus_channel
*channel
,
1168 extern int vmbus_teardown_gpadl(struct vmbus_channel
*channel
,
1171 extern int vmbus_recvpacket(struct vmbus_channel
*channel
,
1174 u32
*buffer_actual_len
,
1177 extern int vmbus_recvpacket_raw(struct vmbus_channel
*channel
,
1180 u32
*buffer_actual_len
,
1184 extern void vmbus_get_debug_info(struct vmbus_channel
*channel
,
1185 struct vmbus_channel_debug_info
*debug
);
1187 extern void vmbus_ontimer(unsigned long data
);
1189 struct hv_dev_port_info
{
1193 u32 bytes_avail_toread
;
1194 u32 bytes_avail_towrite
;
1197 /* Base driver object */
1201 /* the device type supported by this driver */
1203 const struct hv_vmbus_device_id
*id_table
;
1205 struct device_driver driver
;
1207 int (*probe
)(struct hv_device
*, const struct hv_vmbus_device_id
*);
1208 int (*remove
)(struct hv_device
*);
1209 void (*shutdown
)(struct hv_device
*);
1213 /* Base device object */
1215 /* the device type id of this device */
1218 /* the device instance id of this device */
1219 uuid_le dev_instance
;
1221 struct device device
;
1223 struct vmbus_channel
*channel
;
1227 static inline struct hv_device
*device_to_hv_device(struct device
*d
)
1229 return container_of(d
, struct hv_device
, device
);
1232 static inline struct hv_driver
*drv_to_hv_drv(struct device_driver
*d
)
1234 return container_of(d
, struct hv_driver
, driver
);
1237 static inline void hv_set_drvdata(struct hv_device
*dev
, void *data
)
1239 dev_set_drvdata(&dev
->device
, data
);
1242 static inline void *hv_get_drvdata(struct hv_device
*dev
)
1244 return dev_get_drvdata(&dev
->device
);
1247 /* Vmbus interface */
1248 #define vmbus_driver_register(driver) \
1249 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1250 int __must_check
__vmbus_driver_register(struct hv_driver
*hv_driver
,
1251 struct module
*owner
,
1252 const char *mod_name
);
1253 void vmbus_driver_unregister(struct hv_driver
*hv_driver
);
1256 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1258 * This macro is used to create a struct hv_vmbus_device_id that matches a
1261 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1262 g8, g9, ga, gb, gc, gd, ge, gf) \
1263 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1264 g8, g9, ga, gb, gc, gd, ge, gf },
1267 * GUID definitions of various offer types - services offered to the guest.
1272 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1274 #define HV_NIC_GUID \
1276 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1277 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1282 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1284 #define HV_IDE_GUID \
1286 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1287 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1292 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1294 #define HV_SCSI_GUID \
1296 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1297 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1302 * {0e0b6031-5213-4934-818b-38d90ced39db}
1304 #define HV_SHUTDOWN_GUID \
1306 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1307 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1312 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1314 #define HV_TS_GUID \
1316 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1317 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1322 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1324 #define HV_HEART_BEAT_GUID \
1326 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1327 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1332 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1334 #define HV_KVP_GUID \
1336 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1337 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1341 * Dynamic memory GUID
1342 * {525074dc-8985-46e2-8057-a307dc18a502}
1344 #define HV_DM_GUID \
1346 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1347 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1352 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1354 #define HV_MOUSE_GUID \
1356 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1357 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1361 * VSS (Backup/Restore) GUID
1363 #define HV_VSS_GUID \
1365 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1366 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1369 * Synthetic Video GUID
1370 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1372 #define HV_SYNTHVID_GUID \
1374 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
1375 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
1380 * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
1382 #define HV_SYNTHFC_GUID \
1384 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
1385 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
1389 * Common header for Hyper-V ICs
1392 #define ICMSGTYPE_NEGOTIATE 0
1393 #define ICMSGTYPE_HEARTBEAT 1
1394 #define ICMSGTYPE_KVPEXCHANGE 2
1395 #define ICMSGTYPE_SHUTDOWN 3
1396 #define ICMSGTYPE_TIMESYNC 4
1397 #define ICMSGTYPE_VSS 5
1399 #define ICMSGHDRFLAG_TRANSACTION 1
1400 #define ICMSGHDRFLAG_REQUEST 2
1401 #define ICMSGHDRFLAG_RESPONSE 4
1405 * While we want to handle util services as regular devices,
1406 * there is only one instance of each of these services; so
1407 * we statically allocate the service specific state.
1410 struct hv_util_service
{
1412 void (*util_cb
)(void *);
1413 int (*util_init
)(struct hv_util_service
*);
1414 void (*util_deinit
)(void);
1417 struct vmbuspipe_hdr
{
1428 struct ic_version icverframe
;
1430 struct ic_version icvermsg
;
1433 u8 ictransaction_id
;
1438 struct icmsg_negotiate
{
1442 struct ic_version icversion_data
[1]; /* any size array */
1445 struct shutdown_msg_data
{
1447 u32 timeout_seconds
;
1449 u8 display_message
[2048];
1452 struct heartbeat_msg_data
{
1457 /* Time Sync IC defs */
1458 #define ICTIMESYNCFLAG_PROBE 0
1459 #define ICTIMESYNCFLAG_SYNC 1
1460 #define ICTIMESYNCFLAG_SAMPLE 2
1463 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1465 #define WLTIMEDELTA 116444736000000000LL
1468 struct ictimesync_data
{
1475 struct hyperv_service_callback
{
1479 struct vmbus_channel
*channel
;
1480 void (*callback
) (void *context
);
1483 #define MAX_SRV_VER 0x7ffffff
1484 extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr
*,
1485 struct icmsg_negotiate
*, u8
*, int,
1488 int hv_kvp_init(struct hv_util_service
*);
1489 void hv_kvp_deinit(void);
1490 void hv_kvp_onchannelcallback(void *);
1492 int hv_vss_init(struct hv_util_service
*);
1493 void hv_vss_deinit(void);
1494 void hv_vss_onchannelcallback(void *);
1497 * Negotiated version with the Host.
1500 extern __u32 vmbus_proto_version
;
1502 #endif /* __KERNEL__ */
1503 #endif /* _HYPERV_H */