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 * An implementation of HyperV key value pair (KVP) functionality for Linux.
34 * Copyright (C) 2010, Novell, Inc.
35 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
40 * Maximum value size - used for both key names and value data, and includes
41 * any applicable NULL terminators.
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.
48 * MSDN recommends not storing data values larger than 2048 bytes in the
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.
56 * bytes, including any null terminators
58 #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
62 * Maximum key size - the registry limit for the length of an entry name
63 * is 256 characters, including the null terminator
66 #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
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.
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:
83 * 0 FullyQualifiedDomainName
84 * 1 IntegrationServicesVersion
85 * 2 NetworkAddressIPv4
86 * 3 NetworkAddressIPv6
92 * 9 ProcessorArchitecture
94 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
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.
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.
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.
118 * Registry value types.
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.
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
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
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.
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.
151 * Daemon code not supporting IP injection (legacy daemon).
154 #define KVP_OP_REGISTER 4
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.
163 #define KVP_OP_REGISTER1 100
165 enum hv_kvp_exchg_op
{
172 KVP_OP_COUNT
/* Number of operations, must be last. */
175 enum hv_kvp_exchg_pool
{
176 KVP_POOL_EXTERNAL
= 0,
179 KVP_POOL_AUTO_EXTERNAL
,
180 KVP_POOL_AUTO_INTERNAL
,
181 KVP_POOL_COUNT
/* Number of pools, must be last. */
185 * Some Hyper-V status codes.
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 #define HV_INVALIDARG 0x80070057
195 #define HV_GUID_NOTFOUND 0x80041002
197 #define ADDR_FAMILY_NONE 0x00
198 #define ADDR_FAMILY_IPV4 0x01
199 #define ADDR_FAMILY_IPV6 0x02
201 #define MAX_ADAPTER_ID_SIZE 128
202 #define MAX_IP_ADDR_SIZE 1024
203 #define MAX_GATEWAY_SIZE 512
206 struct hv_kvp_ipaddr_value
{
207 __u16 adapter_id
[MAX_ADAPTER_ID_SIZE
];
210 __u16 ip_addr
[MAX_IP_ADDR_SIZE
];
211 __u16 sub_net
[MAX_IP_ADDR_SIZE
];
212 __u16 gate_way
[MAX_GATEWAY_SIZE
];
213 __u16 dns_addr
[MAX_IP_ADDR_SIZE
];
214 } __attribute__((packed
));
221 } __attribute__((packed
));
223 struct hv_kvp_exchg_msg_value
{
227 __u8 key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
229 __u8 value
[HV_KVP_EXCHANGE_MAX_VALUE_SIZE
];
233 } __attribute__((packed
));
235 struct hv_kvp_msg_enumerate
{
237 struct hv_kvp_exchg_msg_value data
;
238 } __attribute__((packed
));
240 struct hv_kvp_msg_get
{
241 struct hv_kvp_exchg_msg_value data
;
244 struct hv_kvp_msg_set
{
245 struct hv_kvp_exchg_msg_value data
;
248 struct hv_kvp_msg_delete
{
250 __u8 key
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
253 struct hv_kvp_register
{
254 __u8 version
[HV_KVP_EXCHANGE_MAX_KEY_SIZE
];
259 struct hv_kvp_hdr kvp_hdr
;
263 struct hv_kvp_msg_get kvp_get
;
264 struct hv_kvp_msg_set kvp_set
;
265 struct hv_kvp_msg_delete kvp_delete
;
266 struct hv_kvp_msg_enumerate kvp_enum_data
;
267 struct hv_kvp_ipaddr_value kvp_ip_val
;
268 struct hv_kvp_register kvp_register
;
270 } __attribute__((packed
));
272 struct hv_kvp_ip_msg
{
275 struct hv_kvp_ipaddr_value kvp_ip_val
;
276 } __attribute__((packed
));
279 #include <linux/scatterlist.h>
280 #include <linux/list.h>
281 #include <linux/uuid.h>
282 #include <linux/timer.h>
283 #include <linux/workqueue.h>
284 #include <linux/completion.h>
285 #include <linux/device.h>
286 #include <linux/mod_devicetable.h>
289 #define MAX_PAGE_BUFFER_COUNT 19
290 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
292 #pragma pack(push, 1)
294 /* Single-page buffer */
295 struct hv_page_buffer
{
301 /* Multiple-page buffer */
302 struct hv_multipage_buffer
{
303 /* Length and Offset determines the # of pfns in the array */
306 u64 pfn_array
[MAX_MULTIPAGE_BUFFER_COUNT
];
309 /* 0x18 includes the proprietary packet header */
310 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
311 (sizeof(struct hv_page_buffer) * \
312 MAX_PAGE_BUFFER_COUNT))
313 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
314 sizeof(struct hv_multipage_buffer))
319 struct hv_ring_buffer
{
320 /* Offset in bytes from the start of ring data below */
323 /* Offset in bytes from the start of ring data below */
329 * Win8 uses some of the reserved bits to implement
330 * interrupt driven flow management. On the send side
331 * we can request that the receiver interrupt the sender
332 * when the ring transitions from being full to being able
333 * to handle a message of size "pending_send_sz".
335 * Add necessary state for this enhancement.
343 u32 feat_pending_send_sz
:1;
348 /* Pad it to PAGE_SIZE so that data starts on page boundary */
352 * Ring data starts here + RingDataStartOffset
353 * !!! DO NOT place any fields below this !!!
358 struct hv_ring_buffer_info
{
359 struct hv_ring_buffer
*ring_buffer
;
360 u32 ring_size
; /* Include the shared header */
361 spinlock_t ring_lock
;
363 u32 ring_datasize
; /* < ring_size */
364 u32 ring_data_startoffset
;
367 struct hv_ring_buffer_debug_info
{
368 u32 current_interrupt_mask
;
369 u32 current_read_index
;
370 u32 current_write_index
;
371 u32 bytes_avail_toread
;
372 u32 bytes_avail_towrite
;
378 * hv_get_ringbuffer_availbytes()
380 * Get number of bytes available to read and to write to
381 * for the specified ring buffer
384 hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info
*rbi
,
385 u32
*read
, u32
*write
)
387 u32 read_loc
, write_loc
, dsize
;
389 smp_read_barrier_depends();
391 /* Capture the read/write indices before they changed */
392 read_loc
= rbi
->ring_buffer
->read_index
;
393 write_loc
= rbi
->ring_buffer
->write_index
;
394 dsize
= rbi
->ring_datasize
;
396 *write
= write_loc
>= read_loc
? dsize
- (write_loc
- read_loc
) :
397 read_loc
- write_loc
;
398 *read
= dsize
- *write
;
403 * We use the same version numbering for all Hyper-V modules.
405 * Definition of versioning is as follows;
407 * Major Number Changes for these scenarios;
408 * 1. When a new version of Windows Hyper-V
410 * 2. A Major change has occurred in the
412 * (For example the merge for the first time
413 * into the kernel) Every time the Major Number
414 * changes, the Revision number is reset to 0.
415 * Minor Number Changes when new functionality is added
416 * to the Linux IC's that is not a bug fix.
418 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
420 #define HV_DRV_VERSION "3.1"
423 * VMBUS version is 32 bit entity broken up into
424 * two 16 bit quantities: major_number. minor_number.
426 * 0 . 13 (Windows Server 2008)
431 #define VERSION_WS2008 ((0 << 16) | (13))
432 #define VERSION_WIN7 ((1 << 16) | (1))
433 #define VERSION_WIN8 ((2 << 16) | (4))
435 #define VERSION_INVAL -1
437 #define VERSION_CURRENT VERSION_WIN8
439 /* Make maximum size of pipe payload of 16K */
440 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
442 /* Define PipeMode values. */
443 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
444 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
446 /* The size of the user defined data buffer for non-pipe offers. */
447 #define MAX_USER_DEFINED_BYTES 120
449 /* The size of the user defined data buffer for pipe offers. */
450 #define MAX_PIPE_USER_DEFINED_BYTES 116
453 * At the center of the Channel Management library is the Channel Offer. This
454 * struct contains the fundamental information about an offer.
456 struct vmbus_channel_offer
{
461 * These two fields are not currently used.
467 u16 mmio_megabytes
; /* in bytes * 1024 * 1024 */
470 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
472 unsigned char user_def
[MAX_USER_DEFINED_BYTES
];
477 * The following sructure is an integrated pipe protocol, which
478 * is implemented on top of standard user-defined data. Pipe
479 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
484 unsigned char user_def
[MAX_PIPE_USER_DEFINED_BYTES
];
488 * The sub_channel_index is defined in win8.
490 u16 sub_channel_index
;
495 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
496 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
497 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
498 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
499 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
500 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
501 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
503 struct vmpacket_descriptor
{
511 struct vmpacket_header
{
512 u32 prev_pkt_start_offset
;
513 struct vmpacket_descriptor descriptor
;
516 struct vmtransfer_page_range
{
521 struct vmtransfer_page_packet_header
{
522 struct vmpacket_descriptor d
;
527 struct vmtransfer_page_range ranges
[1];
530 struct vmgpadl_packet_header
{
531 struct vmpacket_descriptor d
;
536 struct vmadd_remove_transfer_page_set
{
537 struct vmpacket_descriptor d
;
544 * This structure defines a range in guest physical space that can be made to
545 * look virtually contiguous.
554 * This is the format for an Establish Gpadl packet, which contains a handle by
555 * which this GPADL will be known and a set of GPA ranges associated with it.
556 * This can be converted to a MDL by the guest OS. If there are multiple GPA
557 * ranges, then the resulting MDL will be "chained," representing multiple VA
560 struct vmestablish_gpadl
{
561 struct vmpacket_descriptor d
;
564 struct gpa_range range
[1];
568 * This is the format for a Teardown Gpadl packet, which indicates that the
569 * GPADL handle in the Establish Gpadl packet will never be referenced again.
571 struct vmteardown_gpadl
{
572 struct vmpacket_descriptor d
;
574 u32 reserved
; /* for alignment to a 8-byte boundary */
578 * This is the format for a GPA-Direct packet, which contains a set of GPA
579 * ranges, in addition to commands and/or data.
581 struct vmdata_gpa_direct
{
582 struct vmpacket_descriptor d
;
585 struct gpa_range range
[1];
588 /* This is the format for a Additional Data Packet. */
589 struct vmadditional_data
{
590 struct vmpacket_descriptor d
;
594 unsigned char data
[1];
597 union vmpacket_largest_possible_header
{
598 struct vmpacket_descriptor simple_hdr
;
599 struct vmtransfer_page_packet_header xfer_page_hdr
;
600 struct vmgpadl_packet_header gpadl_hdr
;
601 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr
;
602 struct vmestablish_gpadl establish_gpadl_hdr
;
603 struct vmteardown_gpadl teardown_gpadl_hdr
;
604 struct vmdata_gpa_direct data_gpa_direct_hdr
;
607 #define VMPACKET_DATA_START_ADDRESS(__packet) \
608 (void *)(((unsigned char *)__packet) + \
609 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
611 #define VMPACKET_DATA_LENGTH(__packet) \
612 ((((struct vmpacket_descriptor)__packet)->len8 - \
613 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
615 #define VMPACKET_TRANSFER_MODE(__packet) \
616 (((struct IMPACT)__packet)->type)
618 enum vmbus_packet_type
{
619 VM_PKT_INVALID
= 0x0,
621 VM_PKT_ADD_XFER_PAGESET
= 0x2,
622 VM_PKT_RM_XFER_PAGESET
= 0x3,
623 VM_PKT_ESTABLISH_GPADL
= 0x4,
624 VM_PKT_TEARDOWN_GPADL
= 0x5,
625 VM_PKT_DATA_INBAND
= 0x6,
626 VM_PKT_DATA_USING_XFER_PAGES
= 0x7,
627 VM_PKT_DATA_USING_GPADL
= 0x8,
628 VM_PKT_DATA_USING_GPA_DIRECT
= 0x9,
629 VM_PKT_CANCEL_REQUEST
= 0xa,
631 VM_PKT_DATA_USING_ADDITIONAL_PKT
= 0xc,
632 VM_PKT_ADDITIONAL_DATA
= 0xd
635 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
638 /* Version 1 messages */
639 enum vmbus_channel_message_type
{
640 CHANNELMSG_INVALID
= 0,
641 CHANNELMSG_OFFERCHANNEL
= 1,
642 CHANNELMSG_RESCIND_CHANNELOFFER
= 2,
643 CHANNELMSG_REQUESTOFFERS
= 3,
644 CHANNELMSG_ALLOFFERS_DELIVERED
= 4,
645 CHANNELMSG_OPENCHANNEL
= 5,
646 CHANNELMSG_OPENCHANNEL_RESULT
= 6,
647 CHANNELMSG_CLOSECHANNEL
= 7,
648 CHANNELMSG_GPADL_HEADER
= 8,
649 CHANNELMSG_GPADL_BODY
= 9,
650 CHANNELMSG_GPADL_CREATED
= 10,
651 CHANNELMSG_GPADL_TEARDOWN
= 11,
652 CHANNELMSG_GPADL_TORNDOWN
= 12,
653 CHANNELMSG_RELID_RELEASED
= 13,
654 CHANNELMSG_INITIATE_CONTACT
= 14,
655 CHANNELMSG_VERSION_RESPONSE
= 15,
656 CHANNELMSG_UNLOAD
= 16,
657 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
658 CHANNELMSG_VIEWRANGE_ADD
= 17,
659 CHANNELMSG_VIEWRANGE_REMOVE
= 18,
664 struct vmbus_channel_message_header
{
665 enum vmbus_channel_message_type msgtype
;
669 /* Query VMBus Version parameters */
670 struct vmbus_channel_query_vmbus_version
{
671 struct vmbus_channel_message_header header
;
675 /* VMBus Version Supported parameters */
676 struct vmbus_channel_version_supported
{
677 struct vmbus_channel_message_header header
;
678 u8 version_supported
;
681 /* Offer Channel parameters */
682 struct vmbus_channel_offer_channel
{
683 struct vmbus_channel_message_header header
;
684 struct vmbus_channel_offer offer
;
688 * win7 and beyond splits this field into a bit field.
690 u8 monitor_allocated
:1;
693 * These are new fields added in win7 and later.
694 * Do not access these fields without checking the
695 * negotiated protocol.
697 * If "is_dedicated_interrupt" is set, we must not set the
698 * associated bit in the channel bitmap while sending the
699 * interrupt to the host.
701 * connection_id is to be used in signaling the host.
703 u16 is_dedicated_interrupt
:1;
708 /* Rescind Offer parameters */
709 struct vmbus_channel_rescind_offer
{
710 struct vmbus_channel_message_header header
;
715 * Request Offer -- no parameters, SynIC message contains the partition ID
716 * Set Snoop -- no parameters, SynIC message contains the partition ID
717 * Clear Snoop -- no parameters, SynIC message contains the partition ID
718 * All Offers Delivered -- no parameters, SynIC message contains the partition
720 * Flush Client -- no parameters, SynIC message contains the partition ID
723 /* Open Channel parameters */
724 struct vmbus_channel_open_channel
{
725 struct vmbus_channel_message_header header
;
727 /* Identifies the specific VMBus channel that is being opened. */
730 /* ID making a particular open request at a channel offer unique. */
733 /* GPADL for the channel's ring buffer. */
734 u32 ringbuffer_gpadlhandle
;
737 * Starting with win8, this field will be used to specify
738 * the target virtual processor on which to deliver the interrupt for
739 * the host to guest communication.
740 * Prior to win8, incoming channel interrupts would only
741 * be delivered on cpu 0. Setting this value to 0 would
742 * preserve the earlier behavior.
747 * The upstream ring buffer begins at offset zero in the memory
748 * described by RingBufferGpadlHandle. The downstream ring buffer
749 * follows it at this offset (in pages).
751 u32 downstream_ringbuffer_pageoffset
;
753 /* User-specific data to be passed along to the server endpoint. */
754 unsigned char userdata
[MAX_USER_DEFINED_BYTES
];
757 /* Open Channel Result parameters */
758 struct vmbus_channel_open_result
{
759 struct vmbus_channel_message_header header
;
765 /* Close channel parameters; */
766 struct vmbus_channel_close_channel
{
767 struct vmbus_channel_message_header header
;
771 /* Channel Message GPADL */
772 #define GPADL_TYPE_RING_BUFFER 1
773 #define GPADL_TYPE_SERVER_SAVE_AREA 2
774 #define GPADL_TYPE_TRANSACTION 8
777 * The number of PFNs in a GPADL message is defined by the number of
778 * pages that would be spanned by ByteCount and ByteOffset. If the
779 * implied number of PFNs won't fit in this packet, there will be a
780 * follow-up packet that contains more.
782 struct vmbus_channel_gpadl_header
{
783 struct vmbus_channel_message_header header
;
788 struct gpa_range range
[0];
791 /* This is the followup packet that contains more PFNs. */
792 struct vmbus_channel_gpadl_body
{
793 struct vmbus_channel_message_header header
;
799 struct vmbus_channel_gpadl_created
{
800 struct vmbus_channel_message_header header
;
806 struct vmbus_channel_gpadl_teardown
{
807 struct vmbus_channel_message_header header
;
812 struct vmbus_channel_gpadl_torndown
{
813 struct vmbus_channel_message_header header
;
817 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
818 struct vmbus_channel_view_range_add
{
819 struct vmbus_channel_message_header header
;
820 PHYSICAL_ADDRESS viewrange_base
;
821 u64 viewrange_length
;
825 struct vmbus_channel_view_range_remove
{
826 struct vmbus_channel_message_header header
;
827 PHYSICAL_ADDRESS viewrange_base
;
832 struct vmbus_channel_relid_released
{
833 struct vmbus_channel_message_header header
;
837 struct vmbus_channel_initiate_contact
{
838 struct vmbus_channel_message_header header
;
839 u32 vmbus_version_requested
;
846 struct vmbus_channel_version_response
{
847 struct vmbus_channel_message_header header
;
848 u8 version_supported
;
851 enum vmbus_channel_state
{
853 CHANNEL_OPENING_STATE
,
857 struct vmbus_channel_debug_info
{
859 enum vmbus_channel_state state
;
860 uuid_le interfacetype
;
861 uuid_le interface_instance
;
863 u32 servermonitor_pending
;
864 u32 servermonitor_latency
;
865 u32 servermonitor_connectionid
;
866 u32 clientmonitor_pending
;
867 u32 clientmonitor_latency
;
868 u32 clientmonitor_connectionid
;
870 struct hv_ring_buffer_debug_info inbound
;
871 struct hv_ring_buffer_debug_info outbound
;
875 * Represents each channel msg on the vmbus connection This is a
876 * variable-size data structure depending on the msg type itself
878 struct vmbus_channel_msginfo
{
879 /* Bookkeeping stuff */
880 struct list_head msglistentry
;
882 /* So far, this is only used to handle gpadl body message */
883 struct list_head submsglist
;
885 /* Synchronize the request/response if needed */
886 struct completion waitevent
;
888 struct vmbus_channel_version_supported version_supported
;
889 struct vmbus_channel_open_result open_result
;
890 struct vmbus_channel_gpadl_torndown gpadl_torndown
;
891 struct vmbus_channel_gpadl_created gpadl_created
;
892 struct vmbus_channel_version_response version_response
;
897 * The channel message that goes out on the "wire".
898 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
900 unsigned char msg
[0];
903 struct vmbus_close_msg
{
904 struct vmbus_channel_msginfo info
;
905 struct vmbus_channel_close_channel msg
;
908 /* Define connection identifier type. */
909 union hv_connection_id
{
917 /* Definition of the hv_signal_event hypercall input structure. */
918 struct hv_input_signal_event
{
919 union hv_connection_id connectionid
;
924 struct hv_input_signal_event_buffer
{
926 struct hv_input_signal_event event
;
929 struct vmbus_channel
{
930 struct list_head listentry
;
932 struct hv_device
*device_obj
;
934 struct work_struct work
;
936 enum vmbus_channel_state state
;
938 struct vmbus_channel_offer_channel offermsg
;
940 * These are based on the OfferMsg.MonitorId.
941 * Save it here for easy access.
946 u32 ringbuffer_gpadlhandle
;
948 /* Allocated memory for ring buffer */
949 void *ringbuffer_pages
;
950 u32 ringbuffer_pagecount
;
951 struct hv_ring_buffer_info outbound
; /* send to parent */
952 struct hv_ring_buffer_info inbound
; /* receive from parent */
953 spinlock_t inbound_lock
;
954 struct workqueue_struct
*controlwq
;
956 struct vmbus_close_msg close_msg
;
958 /* Channel callback are invoked in this workqueue context */
959 /* HANDLE dataWorkQueue; */
961 void (*onchannel_callback
)(void *context
);
962 void *channel_callback_context
;
965 * A channel can be marked for efficient (batched)
967 * If batched_reading is set to "true", we read until the
968 * channel is empty and hold off interrupts from the host
969 * during the entire read process.
970 * If batched_reading is set to "false", the client is not
971 * going to perform batched reading.
973 * By default we will enable batched reading; specific
974 * drivers that don't want this behavior can turn it off.
977 bool batched_reading
;
979 bool is_dedicated_interrupt
;
980 struct hv_input_signal_event_buffer sig_buf
;
981 struct hv_input_signal_event
*sig_event
;
984 * Starting with win8, this field will be used to specify
985 * the target virtual processor on which to deliver the interrupt for
986 * the host to guest communication.
987 * Prior to win8, incoming channel interrupts would only
988 * be delivered on cpu 0. Setting this value to 0 would
989 * preserve the earlier behavior.
994 static inline void set_channel_read_state(struct vmbus_channel
*c
, bool state
)
996 c
->batched_reading
= state
;
999 void vmbus_onmessage(void *context
);
1001 int vmbus_request_offers(void);
1003 /* The format must be the same as struct vmdata_gpa_direct */
1004 struct vmbus_channel_packet_page_buffer
{
1012 struct hv_page_buffer range
[MAX_PAGE_BUFFER_COUNT
];
1015 /* The format must be the same as struct vmdata_gpa_direct */
1016 struct vmbus_channel_packet_multipage_buffer
{
1023 u32 rangecount
; /* Always 1 in this case */
1024 struct hv_multipage_buffer range
;
1028 extern int vmbus_open(struct vmbus_channel
*channel
,
1029 u32 send_ringbuffersize
,
1030 u32 recv_ringbuffersize
,
1033 void(*onchannel_callback
)(void *context
),
1036 extern void vmbus_close(struct vmbus_channel
*channel
);
1038 extern int vmbus_sendpacket(struct vmbus_channel
*channel
,
1042 enum vmbus_packet_type type
,
1045 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel
*channel
,
1046 struct hv_page_buffer pagebuffers
[],
1052 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel
*channel
,
1053 struct hv_multipage_buffer
*mpb
,
1058 extern int vmbus_establish_gpadl(struct vmbus_channel
*channel
,
1063 extern int vmbus_teardown_gpadl(struct vmbus_channel
*channel
,
1066 extern int vmbus_recvpacket(struct vmbus_channel
*channel
,
1069 u32
*buffer_actual_len
,
1072 extern int vmbus_recvpacket_raw(struct vmbus_channel
*channel
,
1075 u32
*buffer_actual_len
,
1079 extern void vmbus_get_debug_info(struct vmbus_channel
*channel
,
1080 struct vmbus_channel_debug_info
*debug
);
1082 extern void vmbus_ontimer(unsigned long data
);
1084 struct hv_dev_port_info
{
1088 u32 bytes_avail_toread
;
1089 u32 bytes_avail_towrite
;
1092 /* Base driver object */
1096 /* the device type supported by this driver */
1098 const struct hv_vmbus_device_id
*id_table
;
1100 struct device_driver driver
;
1102 int (*probe
)(struct hv_device
*, const struct hv_vmbus_device_id
*);
1103 int (*remove
)(struct hv_device
*);
1104 void (*shutdown
)(struct hv_device
*);
1108 /* Base device object */
1110 /* the device type id of this device */
1113 /* the device instance id of this device */
1114 uuid_le dev_instance
;
1116 struct device device
;
1118 struct vmbus_channel
*channel
;
1122 static inline struct hv_device
*device_to_hv_device(struct device
*d
)
1124 return container_of(d
, struct hv_device
, device
);
1127 static inline struct hv_driver
*drv_to_hv_drv(struct device_driver
*d
)
1129 return container_of(d
, struct hv_driver
, driver
);
1132 static inline void hv_set_drvdata(struct hv_device
*dev
, void *data
)
1134 dev_set_drvdata(&dev
->device
, data
);
1137 static inline void *hv_get_drvdata(struct hv_device
*dev
)
1139 return dev_get_drvdata(&dev
->device
);
1142 /* Vmbus interface */
1143 #define vmbus_driver_register(driver) \
1144 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1145 int __must_check
__vmbus_driver_register(struct hv_driver
*hv_driver
,
1146 struct module
*owner
,
1147 const char *mod_name
);
1148 void vmbus_driver_unregister(struct hv_driver
*hv_driver
);
1151 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1153 * This macro is used to create a struct hv_vmbus_device_id that matches a
1156 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1157 g8, g9, ga, gb, gc, gd, ge, gf) \
1158 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1159 g8, g9, ga, gb, gc, gd, ge, gf },
1162 * GUID definitions of various offer types - services offered to the guest.
1167 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1169 #define HV_NIC_GUID \
1171 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1172 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1177 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1179 #define HV_IDE_GUID \
1181 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1182 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1187 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1189 #define HV_SCSI_GUID \
1191 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1192 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1197 * {0e0b6031-5213-4934-818b-38d90ced39db}
1199 #define HV_SHUTDOWN_GUID \
1201 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1202 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1207 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1209 #define HV_TS_GUID \
1211 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1212 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1217 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1219 #define HV_HEART_BEAT_GUID \
1221 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1222 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1227 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1229 #define HV_KVP_GUID \
1231 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1232 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1236 * Dynamic memory GUID
1237 * {525074dc-8985-46e2-8057-a307dc18a502}
1239 #define HV_DM_GUID \
1241 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1242 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1247 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1249 #define HV_MOUSE_GUID \
1251 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1252 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1256 * Common header for Hyper-V ICs
1259 #define ICMSGTYPE_NEGOTIATE 0
1260 #define ICMSGTYPE_HEARTBEAT 1
1261 #define ICMSGTYPE_KVPEXCHANGE 2
1262 #define ICMSGTYPE_SHUTDOWN 3
1263 #define ICMSGTYPE_TIMESYNC 4
1264 #define ICMSGTYPE_VSS 5
1266 #define ICMSGHDRFLAG_TRANSACTION 1
1267 #define ICMSGHDRFLAG_REQUEST 2
1268 #define ICMSGHDRFLAG_RESPONSE 4
1272 * While we want to handle util services as regular devices,
1273 * there is only one instance of each of these services; so
1274 * we statically allocate the service specific state.
1277 struct hv_util_service
{
1279 void (*util_cb
)(void *);
1280 int (*util_init
)(struct hv_util_service
*);
1281 void (*util_deinit
)(void);
1284 struct vmbuspipe_hdr
{
1295 struct ic_version icverframe
;
1297 struct ic_version icvermsg
;
1300 u8 ictransaction_id
;
1305 struct icmsg_negotiate
{
1309 struct ic_version icversion_data
[1]; /* any size array */
1312 struct shutdown_msg_data
{
1314 u32 timeout_seconds
;
1316 u8 display_message
[2048];
1319 struct heartbeat_msg_data
{
1324 /* Time Sync IC defs */
1325 #define ICTIMESYNCFLAG_PROBE 0
1326 #define ICTIMESYNCFLAG_SYNC 1
1327 #define ICTIMESYNCFLAG_SAMPLE 2
1330 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1332 #define WLTIMEDELTA 116444736000000000LL
1335 struct ictimesync_data
{
1342 struct hyperv_service_callback
{
1346 struct vmbus_channel
*channel
;
1347 void (*callback
) (void *context
);
1350 #define MAX_SRV_VER 0x7ffffff
1351 extern void vmbus_prep_negotiate_resp(struct icmsg_hdr
*,
1352 struct icmsg_negotiate
*, u8
*, int,
1355 int hv_kvp_init(struct hv_util_service
*);
1356 void hv_kvp_deinit(void);
1357 void hv_kvp_onchannelcallback(void *);
1360 * Negotiated version with the Host.
1363 extern __u32 vmbus_proto_version
;
1365 #endif /* __KERNEL__ */
1366 #endif /* _HYPERV_H */