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 */
328 /* Pad it to PAGE_SIZE so that data starts on page boundary */
332 * The interrupt_mask field is used only for channels but since our
333 * vmbus connection also uses this data structure and its data starts
334 * here, we commented out this field.
338 * Ring data starts here + RingDataStartOffset
339 * !!! DO NOT place any fields below this !!!
344 struct hv_ring_buffer_info
{
345 struct hv_ring_buffer
*ring_buffer
;
346 u32 ring_size
; /* Include the shared header */
347 spinlock_t ring_lock
;
349 u32 ring_datasize
; /* < ring_size */
350 u32 ring_data_startoffset
;
353 struct hv_ring_buffer_debug_info
{
354 u32 current_interrupt_mask
;
355 u32 current_read_index
;
356 u32 current_write_index
;
357 u32 bytes_avail_toread
;
358 u32 bytes_avail_towrite
;
364 * hv_get_ringbuffer_availbytes()
366 * Get number of bytes available to read and to write to
367 * for the specified ring buffer
370 hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info
*rbi
,
371 u32
*read
, u32
*write
)
373 u32 read_loc
, write_loc
, dsize
;
375 smp_read_barrier_depends();
377 /* Capture the read/write indices before they changed */
378 read_loc
= rbi
->ring_buffer
->read_index
;
379 write_loc
= rbi
->ring_buffer
->write_index
;
380 dsize
= rbi
->ring_datasize
;
382 *write
= write_loc
>= read_loc
? dsize
- (write_loc
- read_loc
) :
383 read_loc
- write_loc
;
384 *read
= dsize
- *write
;
389 * We use the same version numbering for all Hyper-V modules.
391 * Definition of versioning is as follows;
393 * Major Number Changes for these scenarios;
394 * 1. When a new version of Windows Hyper-V
396 * 2. A Major change has occurred in the
398 * (For example the merge for the first time
399 * into the kernel) Every time the Major Number
400 * changes, the Revision number is reset to 0.
401 * Minor Number Changes when new functionality is added
402 * to the Linux IC's that is not a bug fix.
404 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
406 #define HV_DRV_VERSION "3.1"
410 * A revision number of vmbus that is used for ensuring both ends on a
411 * partition are using compatible versions.
413 #define VMBUS_REVISION_NUMBER 13
415 /* Make maximum size of pipe payload of 16K */
416 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
418 /* Define PipeMode values. */
419 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
420 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
422 /* The size of the user defined data buffer for non-pipe offers. */
423 #define MAX_USER_DEFINED_BYTES 120
425 /* The size of the user defined data buffer for pipe offers. */
426 #define MAX_PIPE_USER_DEFINED_BYTES 116
429 * At the center of the Channel Management library is the Channel Offer. This
430 * struct contains the fundamental information about an offer.
432 struct vmbus_channel_offer
{
435 u64 int_latency
; /* in 100ns units */
437 u32 server_ctx_size
; /* in bytes */
439 u16 mmio_megabytes
; /* in bytes * 1024 * 1024 */
442 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
444 unsigned char user_def
[MAX_USER_DEFINED_BYTES
];
449 * The following sructure is an integrated pipe protocol, which
450 * is implemented on top of standard user-defined data. Pipe
451 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
456 unsigned char user_def
[MAX_PIPE_USER_DEFINED_BYTES
];
463 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
464 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
465 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
466 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
467 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
468 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
469 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
471 struct vmpacket_descriptor
{
479 struct vmpacket_header
{
480 u32 prev_pkt_start_offset
;
481 struct vmpacket_descriptor descriptor
;
484 struct vmtransfer_page_range
{
489 struct vmtransfer_page_packet_header
{
490 struct vmpacket_descriptor d
;
495 struct vmtransfer_page_range ranges
[1];
498 struct vmgpadl_packet_header
{
499 struct vmpacket_descriptor d
;
504 struct vmadd_remove_transfer_page_set
{
505 struct vmpacket_descriptor d
;
512 * This structure defines a range in guest physical space that can be made to
513 * look virtually contiguous.
522 * This is the format for an Establish Gpadl packet, which contains a handle by
523 * which this GPADL will be known and a set of GPA ranges associated with it.
524 * This can be converted to a MDL by the guest OS. If there are multiple GPA
525 * ranges, then the resulting MDL will be "chained," representing multiple VA
528 struct vmestablish_gpadl
{
529 struct vmpacket_descriptor d
;
532 struct gpa_range range
[1];
536 * This is the format for a Teardown Gpadl packet, which indicates that the
537 * GPADL handle in the Establish Gpadl packet will never be referenced again.
539 struct vmteardown_gpadl
{
540 struct vmpacket_descriptor d
;
542 u32 reserved
; /* for alignment to a 8-byte boundary */
546 * This is the format for a GPA-Direct packet, which contains a set of GPA
547 * ranges, in addition to commands and/or data.
549 struct vmdata_gpa_direct
{
550 struct vmpacket_descriptor d
;
553 struct gpa_range range
[1];
556 /* This is the format for a Additional Data Packet. */
557 struct vmadditional_data
{
558 struct vmpacket_descriptor d
;
562 unsigned char data
[1];
565 union vmpacket_largest_possible_header
{
566 struct vmpacket_descriptor simple_hdr
;
567 struct vmtransfer_page_packet_header xfer_page_hdr
;
568 struct vmgpadl_packet_header gpadl_hdr
;
569 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr
;
570 struct vmestablish_gpadl establish_gpadl_hdr
;
571 struct vmteardown_gpadl teardown_gpadl_hdr
;
572 struct vmdata_gpa_direct data_gpa_direct_hdr
;
575 #define VMPACKET_DATA_START_ADDRESS(__packet) \
576 (void *)(((unsigned char *)__packet) + \
577 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
579 #define VMPACKET_DATA_LENGTH(__packet) \
580 ((((struct vmpacket_descriptor)__packet)->len8 - \
581 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
583 #define VMPACKET_TRANSFER_MODE(__packet) \
584 (((struct IMPACT)__packet)->type)
586 enum vmbus_packet_type
{
587 VM_PKT_INVALID
= 0x0,
589 VM_PKT_ADD_XFER_PAGESET
= 0x2,
590 VM_PKT_RM_XFER_PAGESET
= 0x3,
591 VM_PKT_ESTABLISH_GPADL
= 0x4,
592 VM_PKT_TEARDOWN_GPADL
= 0x5,
593 VM_PKT_DATA_INBAND
= 0x6,
594 VM_PKT_DATA_USING_XFER_PAGES
= 0x7,
595 VM_PKT_DATA_USING_GPADL
= 0x8,
596 VM_PKT_DATA_USING_GPA_DIRECT
= 0x9,
597 VM_PKT_CANCEL_REQUEST
= 0xa,
599 VM_PKT_DATA_USING_ADDITIONAL_PKT
= 0xc,
600 VM_PKT_ADDITIONAL_DATA
= 0xd
603 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
606 /* Version 1 messages */
607 enum vmbus_channel_message_type
{
608 CHANNELMSG_INVALID
= 0,
609 CHANNELMSG_OFFERCHANNEL
= 1,
610 CHANNELMSG_RESCIND_CHANNELOFFER
= 2,
611 CHANNELMSG_REQUESTOFFERS
= 3,
612 CHANNELMSG_ALLOFFERS_DELIVERED
= 4,
613 CHANNELMSG_OPENCHANNEL
= 5,
614 CHANNELMSG_OPENCHANNEL_RESULT
= 6,
615 CHANNELMSG_CLOSECHANNEL
= 7,
616 CHANNELMSG_GPADL_HEADER
= 8,
617 CHANNELMSG_GPADL_BODY
= 9,
618 CHANNELMSG_GPADL_CREATED
= 10,
619 CHANNELMSG_GPADL_TEARDOWN
= 11,
620 CHANNELMSG_GPADL_TORNDOWN
= 12,
621 CHANNELMSG_RELID_RELEASED
= 13,
622 CHANNELMSG_INITIATE_CONTACT
= 14,
623 CHANNELMSG_VERSION_RESPONSE
= 15,
624 CHANNELMSG_UNLOAD
= 16,
625 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
626 CHANNELMSG_VIEWRANGE_ADD
= 17,
627 CHANNELMSG_VIEWRANGE_REMOVE
= 18,
632 struct vmbus_channel_message_header
{
633 enum vmbus_channel_message_type msgtype
;
637 /* Query VMBus Version parameters */
638 struct vmbus_channel_query_vmbus_version
{
639 struct vmbus_channel_message_header header
;
643 /* VMBus Version Supported parameters */
644 struct vmbus_channel_version_supported
{
645 struct vmbus_channel_message_header header
;
646 u8 version_supported
;
649 /* Offer Channel parameters */
650 struct vmbus_channel_offer_channel
{
651 struct vmbus_channel_message_header header
;
652 struct vmbus_channel_offer offer
;
655 u8 monitor_allocated
;
658 /* Rescind Offer parameters */
659 struct vmbus_channel_rescind_offer
{
660 struct vmbus_channel_message_header header
;
665 * Request Offer -- no parameters, SynIC message contains the partition ID
666 * Set Snoop -- no parameters, SynIC message contains the partition ID
667 * Clear Snoop -- no parameters, SynIC message contains the partition ID
668 * All Offers Delivered -- no parameters, SynIC message contains the partition
670 * Flush Client -- no parameters, SynIC message contains the partition ID
673 /* Open Channel parameters */
674 struct vmbus_channel_open_channel
{
675 struct vmbus_channel_message_header header
;
677 /* Identifies the specific VMBus channel that is being opened. */
680 /* ID making a particular open request at a channel offer unique. */
683 /* GPADL for the channel's ring buffer. */
684 u32 ringbuffer_gpadlhandle
;
686 /* GPADL for the channel's server context save area. */
687 u32 server_contextarea_gpadlhandle
;
690 * The upstream ring buffer begins at offset zero in the memory
691 * described by RingBufferGpadlHandle. The downstream ring buffer
692 * follows it at this offset (in pages).
694 u32 downstream_ringbuffer_pageoffset
;
696 /* User-specific data to be passed along to the server endpoint. */
697 unsigned char userdata
[MAX_USER_DEFINED_BYTES
];
700 /* Open Channel Result parameters */
701 struct vmbus_channel_open_result
{
702 struct vmbus_channel_message_header header
;
708 /* Close channel parameters; */
709 struct vmbus_channel_close_channel
{
710 struct vmbus_channel_message_header header
;
714 /* Channel Message GPADL */
715 #define GPADL_TYPE_RING_BUFFER 1
716 #define GPADL_TYPE_SERVER_SAVE_AREA 2
717 #define GPADL_TYPE_TRANSACTION 8
720 * The number of PFNs in a GPADL message is defined by the number of
721 * pages that would be spanned by ByteCount and ByteOffset. If the
722 * implied number of PFNs won't fit in this packet, there will be a
723 * follow-up packet that contains more.
725 struct vmbus_channel_gpadl_header
{
726 struct vmbus_channel_message_header header
;
731 struct gpa_range range
[0];
734 /* This is the followup packet that contains more PFNs. */
735 struct vmbus_channel_gpadl_body
{
736 struct vmbus_channel_message_header header
;
742 struct vmbus_channel_gpadl_created
{
743 struct vmbus_channel_message_header header
;
749 struct vmbus_channel_gpadl_teardown
{
750 struct vmbus_channel_message_header header
;
755 struct vmbus_channel_gpadl_torndown
{
756 struct vmbus_channel_message_header header
;
760 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
761 struct vmbus_channel_view_range_add
{
762 struct vmbus_channel_message_header header
;
763 PHYSICAL_ADDRESS viewrange_base
;
764 u64 viewrange_length
;
768 struct vmbus_channel_view_range_remove
{
769 struct vmbus_channel_message_header header
;
770 PHYSICAL_ADDRESS viewrange_base
;
775 struct vmbus_channel_relid_released
{
776 struct vmbus_channel_message_header header
;
780 struct vmbus_channel_initiate_contact
{
781 struct vmbus_channel_message_header header
;
782 u32 vmbus_version_requested
;
789 struct vmbus_channel_version_response
{
790 struct vmbus_channel_message_header header
;
791 u8 version_supported
;
794 enum vmbus_channel_state
{
796 CHANNEL_OPENING_STATE
,
800 struct vmbus_channel_debug_info
{
802 enum vmbus_channel_state state
;
803 uuid_le interfacetype
;
804 uuid_le interface_instance
;
806 u32 servermonitor_pending
;
807 u32 servermonitor_latency
;
808 u32 servermonitor_connectionid
;
809 u32 clientmonitor_pending
;
810 u32 clientmonitor_latency
;
811 u32 clientmonitor_connectionid
;
813 struct hv_ring_buffer_debug_info inbound
;
814 struct hv_ring_buffer_debug_info outbound
;
818 * Represents each channel msg on the vmbus connection This is a
819 * variable-size data structure depending on the msg type itself
821 struct vmbus_channel_msginfo
{
822 /* Bookkeeping stuff */
823 struct list_head msglistentry
;
825 /* So far, this is only used to handle gpadl body message */
826 struct list_head submsglist
;
828 /* Synchronize the request/response if needed */
829 struct completion waitevent
;
831 struct vmbus_channel_version_supported version_supported
;
832 struct vmbus_channel_open_result open_result
;
833 struct vmbus_channel_gpadl_torndown gpadl_torndown
;
834 struct vmbus_channel_gpadl_created gpadl_created
;
835 struct vmbus_channel_version_response version_response
;
840 * The channel message that goes out on the "wire".
841 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
843 unsigned char msg
[0];
846 struct vmbus_close_msg
{
847 struct vmbus_channel_msginfo info
;
848 struct vmbus_channel_close_channel msg
;
851 struct vmbus_channel
{
852 struct list_head listentry
;
854 struct hv_device
*device_obj
;
856 struct work_struct work
;
858 enum vmbus_channel_state state
;
860 struct vmbus_channel_offer_channel offermsg
;
862 * These are based on the OfferMsg.MonitorId.
863 * Save it here for easy access.
868 u32 ringbuffer_gpadlhandle
;
870 /* Allocated memory for ring buffer */
871 void *ringbuffer_pages
;
872 u32 ringbuffer_pagecount
;
873 struct hv_ring_buffer_info outbound
; /* send to parent */
874 struct hv_ring_buffer_info inbound
; /* receive from parent */
875 spinlock_t inbound_lock
;
876 struct workqueue_struct
*controlwq
;
878 struct vmbus_close_msg close_msg
;
880 /* Channel callback are invoked in this workqueue context */
881 /* HANDLE dataWorkQueue; */
883 void (*onchannel_callback
)(void *context
);
884 void *channel_callback_context
;
887 void vmbus_onmessage(void *context
);
889 int vmbus_request_offers(void);
891 /* The format must be the same as struct vmdata_gpa_direct */
892 struct vmbus_channel_packet_page_buffer
{
900 struct hv_page_buffer range
[MAX_PAGE_BUFFER_COUNT
];
903 /* The format must be the same as struct vmdata_gpa_direct */
904 struct vmbus_channel_packet_multipage_buffer
{
911 u32 rangecount
; /* Always 1 in this case */
912 struct hv_multipage_buffer range
;
916 extern int vmbus_open(struct vmbus_channel
*channel
,
917 u32 send_ringbuffersize
,
918 u32 recv_ringbuffersize
,
921 void(*onchannel_callback
)(void *context
),
924 extern void vmbus_close(struct vmbus_channel
*channel
);
926 extern int vmbus_sendpacket(struct vmbus_channel
*channel
,
930 enum vmbus_packet_type type
,
933 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel
*channel
,
934 struct hv_page_buffer pagebuffers
[],
940 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel
*channel
,
941 struct hv_multipage_buffer
*mpb
,
946 extern int vmbus_establish_gpadl(struct vmbus_channel
*channel
,
951 extern int vmbus_teardown_gpadl(struct vmbus_channel
*channel
,
954 extern int vmbus_recvpacket(struct vmbus_channel
*channel
,
957 u32
*buffer_actual_len
,
960 extern int vmbus_recvpacket_raw(struct vmbus_channel
*channel
,
963 u32
*buffer_actual_len
,
967 extern void vmbus_get_debug_info(struct vmbus_channel
*channel
,
968 struct vmbus_channel_debug_info
*debug
);
970 extern void vmbus_ontimer(unsigned long data
);
972 struct hv_dev_port_info
{
976 u32 bytes_avail_toread
;
977 u32 bytes_avail_towrite
;
980 /* Base driver object */
984 /* the device type supported by this driver */
986 const struct hv_vmbus_device_id
*id_table
;
988 struct device_driver driver
;
990 int (*probe
)(struct hv_device
*, const struct hv_vmbus_device_id
*);
991 int (*remove
)(struct hv_device
*);
992 void (*shutdown
)(struct hv_device
*);
996 /* Base device object */
998 /* the device type id of this device */
1001 /* the device instance id of this device */
1002 uuid_le dev_instance
;
1004 struct device device
;
1006 struct vmbus_channel
*channel
;
1010 static inline struct hv_device
*device_to_hv_device(struct device
*d
)
1012 return container_of(d
, struct hv_device
, device
);
1015 static inline struct hv_driver
*drv_to_hv_drv(struct device_driver
*d
)
1017 return container_of(d
, struct hv_driver
, driver
);
1020 static inline void hv_set_drvdata(struct hv_device
*dev
, void *data
)
1022 dev_set_drvdata(&dev
->device
, data
);
1025 static inline void *hv_get_drvdata(struct hv_device
*dev
)
1027 return dev_get_drvdata(&dev
->device
);
1030 /* Vmbus interface */
1031 #define vmbus_driver_register(driver) \
1032 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1033 int __must_check
__vmbus_driver_register(struct hv_driver
*hv_driver
,
1034 struct module
*owner
,
1035 const char *mod_name
);
1036 void vmbus_driver_unregister(struct hv_driver
*hv_driver
);
1039 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1041 * This macro is used to create a struct hv_vmbus_device_id that matches a
1044 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1045 g8, g9, ga, gb, gc, gd, ge, gf) \
1046 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1047 g8, g9, ga, gb, gc, gd, ge, gf },
1050 * Common header for Hyper-V ICs
1053 #define ICMSGTYPE_NEGOTIATE 0
1054 #define ICMSGTYPE_HEARTBEAT 1
1055 #define ICMSGTYPE_KVPEXCHANGE 2
1056 #define ICMSGTYPE_SHUTDOWN 3
1057 #define ICMSGTYPE_TIMESYNC 4
1058 #define ICMSGTYPE_VSS 5
1060 #define ICMSGHDRFLAG_TRANSACTION 1
1061 #define ICMSGHDRFLAG_REQUEST 2
1062 #define ICMSGHDRFLAG_RESPONSE 4
1066 * While we want to handle util services as regular devices,
1067 * there is only one instance of each of these services; so
1068 * we statically allocate the service specific state.
1071 struct hv_util_service
{
1073 void (*util_cb
)(void *);
1074 int (*util_init
)(struct hv_util_service
*);
1075 void (*util_deinit
)(void);
1078 struct vmbuspipe_hdr
{
1089 struct ic_version icverframe
;
1091 struct ic_version icvermsg
;
1094 u8 ictransaction_id
;
1099 struct icmsg_negotiate
{
1103 struct ic_version icversion_data
[1]; /* any size array */
1106 struct shutdown_msg_data
{
1108 u32 timeout_seconds
;
1110 u8 display_message
[2048];
1113 struct heartbeat_msg_data
{
1118 /* Time Sync IC defs */
1119 #define ICTIMESYNCFLAG_PROBE 0
1120 #define ICTIMESYNCFLAG_SYNC 1
1121 #define ICTIMESYNCFLAG_SAMPLE 2
1124 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1126 #define WLTIMEDELTA 116444736000000000LL
1129 struct ictimesync_data
{
1136 struct hyperv_service_callback
{
1140 struct vmbus_channel
*channel
;
1141 void (*callback
) (void *context
);
1144 #define MAX_SRV_VER 0x7ffffff
1145 extern void vmbus_prep_negotiate_resp(struct icmsg_hdr
*,
1146 struct icmsg_negotiate
*, u8
*, int,
1149 int hv_kvp_init(struct hv_util_service
*);
1150 void hv_kvp_deinit(void);
1151 void hv_kvp_onchannelcallback(void *);
1153 #endif /* __KERNEL__ */
1154 #endif /* _HYPERV_H */