Staging: hv: vmbus: Get rid of the unused wrapper - vmbus_onchannel_event()
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / hv / hyperv.h
blobe881cfe29fabc14613c9bf5ceba0f004e238fb20
1 /*
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
12 * more details.
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.
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
21 * K. Y. Srinivasan <kys@microsoft.com>
25 #ifndef _HYPERV_H
26 #define _HYPERV_H
28 #include <linux/scatterlist.h>
29 #include <linux/list.h>
30 #include <linux/timer.h>
31 #include <linux/workqueue.h>
32 #include <linux/completion.h>
33 #include <linux/device.h>
36 #include <asm/hyperv.h>
38 struct hv_guid {
39 unsigned char data[16];
42 #define MAX_PAGE_BUFFER_COUNT 16
43 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
45 #pragma pack(push, 1)
47 /* Single-page buffer */
48 struct hv_page_buffer {
49 u32 len;
50 u32 offset;
51 u64 pfn;
54 /* Multiple-page buffer */
55 struct hv_multipage_buffer {
56 /* Length and Offset determines the # of pfns in the array */
57 u32 len;
58 u32 offset;
59 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
62 /* 0x18 includes the proprietary packet header */
63 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
64 (sizeof(struct hv_page_buffer) * \
65 MAX_PAGE_BUFFER_COUNT))
66 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
67 sizeof(struct hv_multipage_buffer))
70 #pragma pack(pop)
72 struct hv_ring_buffer {
73 /* Offset in bytes from the start of ring data below */
74 u32 write_index;
76 /* Offset in bytes from the start of ring data below */
77 u32 read_index;
79 u32 interrupt_mask;
81 /* Pad it to PAGE_SIZE so that data starts on page boundary */
82 u8 reserved[4084];
84 /* NOTE:
85 * The interrupt_mask field is used only for channels but since our
86 * vmbus connection also uses this data structure and its data starts
87 * here, we commented out this field.
91 * Ring data starts here + RingDataStartOffset
92 * !!! DO NOT place any fields below this !!!
94 u8 buffer[0];
95 } __packed;
97 struct hv_ring_buffer_info {
98 struct hv_ring_buffer *ring_buffer;
99 u32 ring_size; /* Include the shared header */
100 spinlock_t ring_lock;
102 u32 ring_datasize; /* < ring_size */
103 u32 ring_data_startoffset;
106 struct hv_ring_buffer_debug_info {
107 u32 current_interrupt_mask;
108 u32 current_read_index;
109 u32 current_write_index;
110 u32 bytes_avail_toread;
111 u32 bytes_avail_towrite;
115 * We use the same version numbering for all Hyper-V modules.
117 * Definition of versioning is as follows;
119 * Major Number Changes for these scenarios;
120 * 1. When a new version of Windows Hyper-V
121 * is released.
122 * 2. A Major change has occurred in the
123 * Linux IC's.
124 * (For example the merge for the first time
125 * into the kernel) Every time the Major Number
126 * changes, the Revision number is reset to 0.
127 * Minor Number Changes when new functionality is added
128 * to the Linux IC's that is not a bug fix.
130 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
132 #define HV_DRV_VERSION "3.1"
136 * A revision number of vmbus that is used for ensuring both ends on a
137 * partition are using compatible versions.
139 #define VMBUS_REVISION_NUMBER 13
141 /* Make maximum size of pipe payload of 16K */
142 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
144 /* Define PipeMode values. */
145 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
146 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
148 /* The size of the user defined data buffer for non-pipe offers. */
149 #define MAX_USER_DEFINED_BYTES 120
151 /* The size of the user defined data buffer for pipe offers. */
152 #define MAX_PIPE_USER_DEFINED_BYTES 116
155 * At the center of the Channel Management library is the Channel Offer. This
156 * struct contains the fundamental information about an offer.
158 struct vmbus_channel_offer {
159 struct hv_guid if_type;
160 struct hv_guid if_instance;
161 u64 int_latency; /* in 100ns units */
162 u32 if_revision;
163 u32 server_ctx_size; /* in bytes */
164 u16 chn_flags;
165 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
167 union {
168 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
169 struct {
170 unsigned char user_def[MAX_USER_DEFINED_BYTES];
171 } std;
174 * Pipes:
175 * The following sructure is an integrated pipe protocol, which
176 * is implemented on top of standard user-defined data. Pipe
177 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
178 * use.
180 struct {
181 u32 pipe_mode;
182 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
183 } pipe;
184 } u;
185 u32 padding;
186 } __packed;
188 /* Server Flags */
189 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
190 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
191 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
192 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
193 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
194 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
195 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
197 struct vmpacket_descriptor {
198 u16 type;
199 u16 offset8;
200 u16 len8;
201 u16 flags;
202 u64 trans_id;
203 } __packed;
205 struct vmpacket_header {
206 u32 prev_pkt_start_offset;
207 struct vmpacket_descriptor descriptor;
208 } __packed;
210 struct vmtransfer_page_range {
211 u32 byte_count;
212 u32 byte_offset;
213 } __packed;
215 struct vmtransfer_page_packet_header {
216 struct vmpacket_descriptor d;
217 u16 xfer_pageset_id;
218 bool sender_owns_set;
219 u8 reserved;
220 u32 range_cnt;
221 struct vmtransfer_page_range ranges[1];
222 } __packed;
224 struct vmgpadl_packet_header {
225 struct vmpacket_descriptor d;
226 u32 gpadl;
227 u32 reserved;
228 } __packed;
230 struct vmadd_remove_transfer_page_set {
231 struct vmpacket_descriptor d;
232 u32 gpadl;
233 u16 xfer_pageset_id;
234 u16 reserved;
235 } __packed;
238 * This structure defines a range in guest physical space that can be made to
239 * look virtually contiguous.
241 struct gpa_range {
242 u32 byte_count;
243 u32 byte_offset;
244 u64 pfn_array[0];
248 * This is the format for an Establish Gpadl packet, which contains a handle by
249 * which this GPADL will be known and a set of GPA ranges associated with it.
250 * This can be converted to a MDL by the guest OS. If there are multiple GPA
251 * ranges, then the resulting MDL will be "chained," representing multiple VA
252 * ranges.
254 struct vmestablish_gpadl {
255 struct vmpacket_descriptor d;
256 u32 gpadl;
257 u32 range_cnt;
258 struct gpa_range range[1];
259 } __packed;
262 * This is the format for a Teardown Gpadl packet, which indicates that the
263 * GPADL handle in the Establish Gpadl packet will never be referenced again.
265 struct vmteardown_gpadl {
266 struct vmpacket_descriptor d;
267 u32 gpadl;
268 u32 reserved; /* for alignment to a 8-byte boundary */
269 } __packed;
272 * This is the format for a GPA-Direct packet, which contains a set of GPA
273 * ranges, in addition to commands and/or data.
275 struct vmdata_gpa_direct {
276 struct vmpacket_descriptor d;
277 u32 reserved;
278 u32 range_cnt;
279 struct gpa_range range[1];
280 } __packed;
282 /* This is the format for a Additional Data Packet. */
283 struct vmadditional_data {
284 struct vmpacket_descriptor d;
285 u64 total_bytes;
286 u32 offset;
287 u32 byte_cnt;
288 unsigned char data[1];
289 } __packed;
291 union vmpacket_largest_possible_header {
292 struct vmpacket_descriptor simple_hdr;
293 struct vmtransfer_page_packet_header xfer_page_hdr;
294 struct vmgpadl_packet_header gpadl_hdr;
295 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
296 struct vmestablish_gpadl establish_gpadl_hdr;
297 struct vmteardown_gpadl teardown_gpadl_hdr;
298 struct vmdata_gpa_direct data_gpa_direct_hdr;
301 #define VMPACKET_DATA_START_ADDRESS(__packet) \
302 (void *)(((unsigned char *)__packet) + \
303 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
305 #define VMPACKET_DATA_LENGTH(__packet) \
306 ((((struct vmpacket_descriptor)__packet)->len8 - \
307 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
309 #define VMPACKET_TRANSFER_MODE(__packet) \
310 (((struct IMPACT)__packet)->type)
312 enum vmbus_packet_type {
313 VM_PKT_INVALID = 0x0,
314 VM_PKT_SYNCH = 0x1,
315 VM_PKT_ADD_XFER_PAGESET = 0x2,
316 VM_PKT_RM_XFER_PAGESET = 0x3,
317 VM_PKT_ESTABLISH_GPADL = 0x4,
318 VM_PKT_TEARDOWN_GPADL = 0x5,
319 VM_PKT_DATA_INBAND = 0x6,
320 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
321 VM_PKT_DATA_USING_GPADL = 0x8,
322 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
323 VM_PKT_CANCEL_REQUEST = 0xa,
324 VM_PKT_COMP = 0xb,
325 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
326 VM_PKT_ADDITIONAL_DATA = 0xd
329 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
332 /* Version 1 messages */
333 enum vmbus_channel_message_type {
334 CHANNELMSG_INVALID = 0,
335 CHANNELMSG_OFFERCHANNEL = 1,
336 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
337 CHANNELMSG_REQUESTOFFERS = 3,
338 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
339 CHANNELMSG_OPENCHANNEL = 5,
340 CHANNELMSG_OPENCHANNEL_RESULT = 6,
341 CHANNELMSG_CLOSECHANNEL = 7,
342 CHANNELMSG_GPADL_HEADER = 8,
343 CHANNELMSG_GPADL_BODY = 9,
344 CHANNELMSG_GPADL_CREATED = 10,
345 CHANNELMSG_GPADL_TEARDOWN = 11,
346 CHANNELMSG_GPADL_TORNDOWN = 12,
347 CHANNELMSG_RELID_RELEASED = 13,
348 CHANNELMSG_INITIATE_CONTACT = 14,
349 CHANNELMSG_VERSION_RESPONSE = 15,
350 CHANNELMSG_UNLOAD = 16,
351 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
352 CHANNELMSG_VIEWRANGE_ADD = 17,
353 CHANNELMSG_VIEWRANGE_REMOVE = 18,
354 #endif
355 CHANNELMSG_COUNT
358 struct vmbus_channel_message_header {
359 enum vmbus_channel_message_type msgtype;
360 u32 padding;
361 } __packed;
363 /* Query VMBus Version parameters */
364 struct vmbus_channel_query_vmbus_version {
365 struct vmbus_channel_message_header header;
366 u32 version;
367 } __packed;
369 /* VMBus Version Supported parameters */
370 struct vmbus_channel_version_supported {
371 struct vmbus_channel_message_header header;
372 bool version_supported;
373 } __packed;
375 /* Offer Channel parameters */
376 struct vmbus_channel_offer_channel {
377 struct vmbus_channel_message_header header;
378 struct vmbus_channel_offer offer;
379 u32 child_relid;
380 u8 monitorid;
381 bool monitor_allocated;
382 } __packed;
384 /* Rescind Offer parameters */
385 struct vmbus_channel_rescind_offer {
386 struct vmbus_channel_message_header header;
387 u32 child_relid;
388 } __packed;
391 * Request Offer -- no parameters, SynIC message contains the partition ID
392 * Set Snoop -- no parameters, SynIC message contains the partition ID
393 * Clear Snoop -- no parameters, SynIC message contains the partition ID
394 * All Offers Delivered -- no parameters, SynIC message contains the partition
395 * ID
396 * Flush Client -- no parameters, SynIC message contains the partition ID
399 /* Open Channel parameters */
400 struct vmbus_channel_open_channel {
401 struct vmbus_channel_message_header header;
403 /* Identifies the specific VMBus channel that is being opened. */
404 u32 child_relid;
406 /* ID making a particular open request at a channel offer unique. */
407 u32 openid;
409 /* GPADL for the channel's ring buffer. */
410 u32 ringbuffer_gpadlhandle;
412 /* GPADL for the channel's server context save area. */
413 u32 server_contextarea_gpadlhandle;
416 * The upstream ring buffer begins at offset zero in the memory
417 * described by RingBufferGpadlHandle. The downstream ring buffer
418 * follows it at this offset (in pages).
420 u32 downstream_ringbuffer_pageoffset;
422 /* User-specific data to be passed along to the server endpoint. */
423 unsigned char userdata[MAX_USER_DEFINED_BYTES];
424 } __packed;
426 /* Open Channel Result parameters */
427 struct vmbus_channel_open_result {
428 struct vmbus_channel_message_header header;
429 u32 child_relid;
430 u32 openid;
431 u32 status;
432 } __packed;
434 /* Close channel parameters; */
435 struct vmbus_channel_close_channel {
436 struct vmbus_channel_message_header header;
437 u32 child_relid;
438 } __packed;
440 /* Channel Message GPADL */
441 #define GPADL_TYPE_RING_BUFFER 1
442 #define GPADL_TYPE_SERVER_SAVE_AREA 2
443 #define GPADL_TYPE_TRANSACTION 8
446 * The number of PFNs in a GPADL message is defined by the number of
447 * pages that would be spanned by ByteCount and ByteOffset. If the
448 * implied number of PFNs won't fit in this packet, there will be a
449 * follow-up packet that contains more.
451 struct vmbus_channel_gpadl_header {
452 struct vmbus_channel_message_header header;
453 u32 child_relid;
454 u32 gpadl;
455 u16 range_buflen;
456 u16 rangecount;
457 struct gpa_range range[0];
458 } __packed;
460 /* This is the followup packet that contains more PFNs. */
461 struct vmbus_channel_gpadl_body {
462 struct vmbus_channel_message_header header;
463 u32 msgnumber;
464 u32 gpadl;
465 u64 pfn[0];
466 } __packed;
468 struct vmbus_channel_gpadl_created {
469 struct vmbus_channel_message_header header;
470 u32 child_relid;
471 u32 gpadl;
472 u32 creation_status;
473 } __packed;
475 struct vmbus_channel_gpadl_teardown {
476 struct vmbus_channel_message_header header;
477 u32 child_relid;
478 u32 gpadl;
479 } __packed;
481 struct vmbus_channel_gpadl_torndown {
482 struct vmbus_channel_message_header header;
483 u32 gpadl;
484 } __packed;
486 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
487 struct vmbus_channel_view_range_add {
488 struct vmbus_channel_message_header header;
489 PHYSICAL_ADDRESS viewrange_base;
490 u64 viewrange_length;
491 u32 child_relid;
492 } __packed;
494 struct vmbus_channel_view_range_remove {
495 struct vmbus_channel_message_header header;
496 PHYSICAL_ADDRESS viewrange_base;
497 u32 child_relid;
498 } __packed;
499 #endif
501 struct vmbus_channel_relid_released {
502 struct vmbus_channel_message_header header;
503 u32 child_relid;
504 } __packed;
506 struct vmbus_channel_initiate_contact {
507 struct vmbus_channel_message_header header;
508 u32 vmbus_version_requested;
509 u32 padding2;
510 u64 interrupt_page;
511 u64 monitor_page1;
512 u64 monitor_page2;
513 } __packed;
515 struct vmbus_channel_version_response {
516 struct vmbus_channel_message_header header;
517 bool version_supported;
518 } __packed;
520 enum vmbus_channel_state {
521 CHANNEL_OFFER_STATE,
522 CHANNEL_OPENING_STATE,
523 CHANNEL_OPEN_STATE,
526 struct vmbus_channel {
527 struct list_head listentry;
529 struct hv_device *device_obj;
531 struct timer_list poll_timer; /* SA-111 workaround */
532 struct work_struct work;
534 enum vmbus_channel_state state;
536 * For util channels, stash the
537 * the service index for easy access.
539 s8 util_index;
541 struct vmbus_channel_offer_channel offermsg;
543 * These are based on the OfferMsg.MonitorId.
544 * Save it here for easy access.
546 u8 monitor_grp;
547 u8 monitor_bit;
549 u32 ringbuffer_gpadlhandle;
551 /* Allocated memory for ring buffer */
552 void *ringbuffer_pages;
553 u32 ringbuffer_pagecount;
554 struct hv_ring_buffer_info outbound; /* send to parent */
555 struct hv_ring_buffer_info inbound; /* receive from parent */
556 spinlock_t inbound_lock;
557 struct workqueue_struct *controlwq;
559 /* Channel callback are invoked in this workqueue context */
560 /* HANDLE dataWorkQueue; */
562 void (*onchannel_callback)(void *context);
563 void *channel_callback_context;
566 struct vmbus_channel_debug_info {
567 u32 relid;
568 enum vmbus_channel_state state;
569 struct hv_guid interfacetype;
570 struct hv_guid interface_instance;
571 u32 monitorid;
572 u32 servermonitor_pending;
573 u32 servermonitor_latency;
574 u32 servermonitor_connectionid;
575 u32 clientmonitor_pending;
576 u32 clientmonitor_latency;
577 u32 clientmonitor_connectionid;
579 struct hv_ring_buffer_debug_info inbound;
580 struct hv_ring_buffer_debug_info outbound;
584 * Represents each channel msg on the vmbus connection This is a
585 * variable-size data structure depending on the msg type itself
587 struct vmbus_channel_msginfo {
588 /* Bookkeeping stuff */
589 struct list_head msglistentry;
591 /* So far, this is only used to handle gpadl body message */
592 struct list_head submsglist;
594 /* Synchronize the request/response if needed */
595 struct completion waitevent;
596 union {
597 struct vmbus_channel_version_supported version_supported;
598 struct vmbus_channel_open_result open_result;
599 struct vmbus_channel_gpadl_torndown gpadl_torndown;
600 struct vmbus_channel_gpadl_created gpadl_created;
601 struct vmbus_channel_version_response version_response;
602 } response;
604 u32 msgsize;
606 * The channel message that goes out on the "wire".
607 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
609 unsigned char msg[0];
613 void free_channel(struct vmbus_channel *channel);
615 void vmbus_onmessage(void *context);
617 int vmbus_request_offers(void);
619 /* The format must be the same as struct vmdata_gpa_direct */
620 struct vmbus_channel_packet_page_buffer {
621 u16 type;
622 u16 dataoffset8;
623 u16 length8;
624 u16 flags;
625 u64 transactionid;
626 u32 reserved;
627 u32 rangecount;
628 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
629 } __packed;
631 /* The format must be the same as struct vmdata_gpa_direct */
632 struct vmbus_channel_packet_multipage_buffer {
633 u16 type;
634 u16 dataoffset8;
635 u16 length8;
636 u16 flags;
637 u64 transactionid;
638 u32 reserved;
639 u32 rangecount; /* Always 1 in this case */
640 struct hv_multipage_buffer range;
641 } __packed;
644 extern int vmbus_open(struct vmbus_channel *channel,
645 u32 send_ringbuffersize,
646 u32 recv_ringbuffersize,
647 void *userdata,
648 u32 userdatalen,
649 void(*onchannel_callback)(void *context),
650 void *context);
652 extern void vmbus_close(struct vmbus_channel *channel);
654 extern int vmbus_sendpacket(struct vmbus_channel *channel,
655 const void *buffer,
656 u32 bufferLen,
657 u64 requestid,
658 enum vmbus_packet_type type,
659 u32 flags);
661 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
662 struct hv_page_buffer pagebuffers[],
663 u32 pagecount,
664 void *buffer,
665 u32 bufferlen,
666 u64 requestid);
668 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
669 struct hv_multipage_buffer *mpb,
670 void *buffer,
671 u32 bufferlen,
672 u64 requestid);
674 extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
675 void *kbuffer,
676 u32 size,
677 u32 *gpadl_handle);
679 extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
680 u32 gpadl_handle);
682 extern int vmbus_recvpacket(struct vmbus_channel *channel,
683 void *buffer,
684 u32 bufferlen,
685 u32 *buffer_actual_len,
686 u64 *requestid);
688 extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
689 void *buffer,
690 u32 bufferlen,
691 u32 *buffer_actual_len,
692 u64 *requestid);
695 extern void vmbus_get_debug_info(struct vmbus_channel *channel,
696 struct vmbus_channel_debug_info *debug);
698 extern void vmbus_ontimer(unsigned long data);
701 #define LOWORD(dw) ((unsigned short)(dw))
702 #define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF))
705 #define VMBUS 0x0001
706 #define STORVSC 0x0002
707 #define NETVSC 0x0004
708 #define INPUTVSC 0x0008
709 #define BLKVSC 0x0010
710 #define VMBUS_DRV 0x0100
711 #define STORVSC_DRV 0x0200
712 #define NETVSC_DRV 0x0400
713 #define INPUTVSC_DRV 0x0800
714 #define BLKVSC_DRV 0x1000
716 #define ALL_MODULES (VMBUS |\
717 STORVSC |\
718 NETVSC |\
719 INPUTVSC |\
720 BLKVSC |\
721 VMBUS_DRV |\
722 STORVSC_DRV |\
723 NETVSC_DRV |\
724 INPUTVSC_DRV|\
725 BLKVSC_DRV)
727 /* Logging Level */
728 #define ERROR_LVL 3
729 #define WARNING_LVL 4
730 #define INFO_LVL 6
731 #define DEBUG_LVL 7
732 #define DEBUG_LVL_ENTEREXIT 8
733 #define DEBUG_RING_LVL 9
735 extern unsigned int vmbus_loglevel;
737 #define DPRINT(mod, lvl, fmt, args...) do {\
738 if ((mod & (HIWORD(vmbus_loglevel))) && \
739 (lvl <= LOWORD(vmbus_loglevel))) \
740 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
741 } while (0)
743 #define DPRINT_DBG(mod, fmt, args...) do {\
744 if ((mod & (HIWORD(vmbus_loglevel))) && \
745 (DEBUG_LVL <= LOWORD(vmbus_loglevel))) \
746 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
747 } while (0)
749 #define DPRINT_INFO(mod, fmt, args...) do {\
750 if ((mod & (HIWORD(vmbus_loglevel))) && \
751 (INFO_LVL <= LOWORD(vmbus_loglevel))) \
752 printk(KERN_INFO #mod": " fmt "\n", ## args);\
753 } while (0)
755 #define DPRINT_WARN(mod, fmt, args...) do {\
756 if ((mod & (HIWORD(vmbus_loglevel))) && \
757 (WARNING_LVL <= LOWORD(vmbus_loglevel))) \
758 printk(KERN_WARNING #mod": WARNING! " fmt "\n", ## args);\
759 } while (0)
761 #define DPRINT_ERR(mod, fmt, args...) do {\
762 if ((mod & (HIWORD(vmbus_loglevel))) && \
763 (ERROR_LVL <= LOWORD(vmbus_loglevel))) \
764 printk(KERN_ERR #mod": %s() ERROR!! " fmt "\n", \
765 __func__, ## args);\
766 } while (0)
770 struct hv_driver;
771 struct hv_device;
773 struct hv_dev_port_info {
774 u32 int_mask;
775 u32 read_idx;
776 u32 write_idx;
777 u32 bytes_avail_toread;
778 u32 bytes_avail_towrite;
781 struct hv_device_info {
782 u32 chn_id;
783 u32 chn_state;
784 struct hv_guid chn_type;
785 struct hv_guid chn_instance;
787 u32 monitor_id;
788 u32 server_monitor_pending;
789 u32 server_monitor_latency;
790 u32 server_monitor_conn_id;
791 u32 client_monitor_pending;
792 u32 client_monitor_latency;
793 u32 client_monitor_conn_id;
795 struct hv_dev_port_info inbound;
796 struct hv_dev_port_info outbound;
799 /* Base driver object */
800 struct hv_driver {
801 const char *name;
803 /* the device type supported by this driver */
804 struct hv_guid dev_type;
806 struct device_driver driver;
808 int (*probe)(struct hv_device *);
809 int (*remove)(struct hv_device *);
810 void (*shutdown)(struct hv_device *);
814 /* Base device object */
815 struct hv_device {
816 /* the device type id of this device */
817 struct hv_guid dev_type;
819 /* the device instance id of this device */
820 struct hv_guid dev_instance;
822 struct device device;
824 struct vmbus_channel *channel;
826 /* Device extension; */
827 void *ext;
831 static inline struct hv_device *device_to_hv_device(struct device *d)
833 return container_of(d, struct hv_device, device);
836 static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
838 return container_of(d, struct hv_driver, driver);
842 /* Vmbus interface */
843 int vmbus_child_driver_register(struct device_driver *drv);
844 void vmbus_child_driver_unregister(struct device_driver *drv);
847 * Common header for Hyper-V ICs
850 #define ICMSGTYPE_NEGOTIATE 0
851 #define ICMSGTYPE_HEARTBEAT 1
852 #define ICMSGTYPE_KVPEXCHANGE 2
853 #define ICMSGTYPE_SHUTDOWN 3
854 #define ICMSGTYPE_TIMESYNC 4
855 #define ICMSGTYPE_VSS 5
857 #define ICMSGHDRFLAG_TRANSACTION 1
858 #define ICMSGHDRFLAG_REQUEST 2
859 #define ICMSGHDRFLAG_RESPONSE 4
861 #define HV_S_OK 0x00000000
862 #define HV_E_FAIL 0x80004005
863 #define HV_ERROR_NOT_SUPPORTED 0x80070032
864 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
866 struct vmbuspipe_hdr {
867 u32 flags;
868 u32 msgsize;
869 } __packed;
871 struct ic_version {
872 u16 major;
873 u16 minor;
874 } __packed;
876 struct icmsg_hdr {
877 struct ic_version icverframe;
878 u16 icmsgtype;
879 struct ic_version icvermsg;
880 u16 icmsgsize;
881 u32 status;
882 u8 ictransaction_id;
883 u8 icflags;
884 u8 reserved[2];
885 } __packed;
887 struct icmsg_negotiate {
888 u16 icframe_vercnt;
889 u16 icmsg_vercnt;
890 u32 reserved;
891 struct ic_version icversion_data[1]; /* any size array */
892 } __packed;
894 struct shutdown_msg_data {
895 u32 reason_code;
896 u32 timeout_seconds;
897 u32 flags;
898 u8 display_message[2048];
899 } __packed;
901 struct heartbeat_msg_data {
902 u64 seq_num;
903 u32 reserved[8];
904 } __packed;
906 /* Time Sync IC defs */
907 #define ICTIMESYNCFLAG_PROBE 0
908 #define ICTIMESYNCFLAG_SYNC 1
909 #define ICTIMESYNCFLAG_SAMPLE 2
911 #ifdef __x86_64__
912 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
913 #else
914 #define WLTIMEDELTA 116444736000000000LL
915 #endif
917 struct ictimesync_data {
918 u64 parenttime;
919 u64 childtime;
920 u64 roundtriptime;
921 u8 flags;
922 } __packed;
924 /* Index for each IC struct in array hv_cb_utils[] */
925 #define HV_SHUTDOWN_MSG 0
926 #define HV_TIMESYNC_MSG 1
927 #define HV_HEARTBEAT_MSG 2
928 #define HV_KVP_MSG 3
930 struct hyperv_service_callback {
931 u8 msg_type;
932 char *log_msg;
933 unsigned char data[16];
934 struct vmbus_channel *channel;
935 void (*callback) (void *context);
938 extern void prep_negotiate_resp(struct icmsg_hdr *,
939 struct icmsg_negotiate *, u8 *);
940 extern void chn_cb_negotiate(void *);
941 extern struct hyperv_service_callback hv_cb_utils[];
943 #endif /* _HYPERV_H */