Staging: hv: vmbus: Get rid of the ext field in struct hv_device
[linux-2.6/kvm.git] / drivers / staging / hv / hyperv.h
blob76e2ddd437d95077cd91f3fb950d1e52009150b1
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/uuid.h>
31 #include <linux/timer.h>
32 #include <linux/workqueue.h>
33 #include <linux/completion.h>
34 #include <linux/device.h>
35 #include <linux/mod_devicetable.h>
38 #include <asm/hyperv.h>
41 #define MAX_PAGE_BUFFER_COUNT 16
42 #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
44 #pragma pack(push, 1)
46 /* Single-page buffer */
47 struct hv_page_buffer {
48 u32 len;
49 u32 offset;
50 u64 pfn;
53 /* Multiple-page buffer */
54 struct hv_multipage_buffer {
55 /* Length and Offset determines the # of pfns in the array */
56 u32 len;
57 u32 offset;
58 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
61 /* 0x18 includes the proprietary packet header */
62 #define MAX_PAGE_BUFFER_PACKET (0x18 + \
63 (sizeof(struct hv_page_buffer) * \
64 MAX_PAGE_BUFFER_COUNT))
65 #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
66 sizeof(struct hv_multipage_buffer))
69 #pragma pack(pop)
71 struct hv_ring_buffer {
72 /* Offset in bytes from the start of ring data below */
73 u32 write_index;
75 /* Offset in bytes from the start of ring data below */
76 u32 read_index;
78 u32 interrupt_mask;
80 /* Pad it to PAGE_SIZE so that data starts on page boundary */
81 u8 reserved[4084];
83 /* NOTE:
84 * The interrupt_mask field is used only for channels but since our
85 * vmbus connection also uses this data structure and its data starts
86 * here, we commented out this field.
90 * Ring data starts here + RingDataStartOffset
91 * !!! DO NOT place any fields below this !!!
93 u8 buffer[0];
94 } __packed;
96 struct hv_ring_buffer_info {
97 struct hv_ring_buffer *ring_buffer;
98 u32 ring_size; /* Include the shared header */
99 spinlock_t ring_lock;
101 u32 ring_datasize; /* < ring_size */
102 u32 ring_data_startoffset;
105 struct hv_ring_buffer_debug_info {
106 u32 current_interrupt_mask;
107 u32 current_read_index;
108 u32 current_write_index;
109 u32 bytes_avail_toread;
110 u32 bytes_avail_towrite;
114 * We use the same version numbering for all Hyper-V modules.
116 * Definition of versioning is as follows;
118 * Major Number Changes for these scenarios;
119 * 1. When a new version of Windows Hyper-V
120 * is released.
121 * 2. A Major change has occurred in the
122 * Linux IC's.
123 * (For example the merge for the first time
124 * into the kernel) Every time the Major Number
125 * changes, the Revision number is reset to 0.
126 * Minor Number Changes when new functionality is added
127 * to the Linux IC's that is not a bug fix.
129 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
131 #define HV_DRV_VERSION "3.1"
135 * A revision number of vmbus that is used for ensuring both ends on a
136 * partition are using compatible versions.
138 #define VMBUS_REVISION_NUMBER 13
140 /* Make maximum size of pipe payload of 16K */
141 #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
143 /* Define PipeMode values. */
144 #define VMBUS_PIPE_TYPE_BYTE 0x00000000
145 #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
147 /* The size of the user defined data buffer for non-pipe offers. */
148 #define MAX_USER_DEFINED_BYTES 120
150 /* The size of the user defined data buffer for pipe offers. */
151 #define MAX_PIPE_USER_DEFINED_BYTES 116
154 * At the center of the Channel Management library is the Channel Offer. This
155 * struct contains the fundamental information about an offer.
157 struct vmbus_channel_offer {
158 uuid_le if_type;
159 uuid_le if_instance;
160 u64 int_latency; /* in 100ns units */
161 u32 if_revision;
162 u32 server_ctx_size; /* in bytes */
163 u16 chn_flags;
164 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
166 union {
167 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
168 struct {
169 unsigned char user_def[MAX_USER_DEFINED_BYTES];
170 } std;
173 * Pipes:
174 * The following sructure is an integrated pipe protocol, which
175 * is implemented on top of standard user-defined data. Pipe
176 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
177 * use.
179 struct {
180 u32 pipe_mode;
181 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
182 } pipe;
183 } u;
184 u32 padding;
185 } __packed;
187 /* Server Flags */
188 #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
189 #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
190 #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
191 #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
192 #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
193 #define VMBUS_CHANNEL_PARENT_OFFER 0x200
194 #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
196 struct vmpacket_descriptor {
197 u16 type;
198 u16 offset8;
199 u16 len8;
200 u16 flags;
201 u64 trans_id;
202 } __packed;
204 struct vmpacket_header {
205 u32 prev_pkt_start_offset;
206 struct vmpacket_descriptor descriptor;
207 } __packed;
209 struct vmtransfer_page_range {
210 u32 byte_count;
211 u32 byte_offset;
212 } __packed;
214 struct vmtransfer_page_packet_header {
215 struct vmpacket_descriptor d;
216 u16 xfer_pageset_id;
217 bool sender_owns_set;
218 u8 reserved;
219 u32 range_cnt;
220 struct vmtransfer_page_range ranges[1];
221 } __packed;
223 struct vmgpadl_packet_header {
224 struct vmpacket_descriptor d;
225 u32 gpadl;
226 u32 reserved;
227 } __packed;
229 struct vmadd_remove_transfer_page_set {
230 struct vmpacket_descriptor d;
231 u32 gpadl;
232 u16 xfer_pageset_id;
233 u16 reserved;
234 } __packed;
237 * This structure defines a range in guest physical space that can be made to
238 * look virtually contiguous.
240 struct gpa_range {
241 u32 byte_count;
242 u32 byte_offset;
243 u64 pfn_array[0];
247 * This is the format for an Establish Gpadl packet, which contains a handle by
248 * which this GPADL will be known and a set of GPA ranges associated with it.
249 * This can be converted to a MDL by the guest OS. If there are multiple GPA
250 * ranges, then the resulting MDL will be "chained," representing multiple VA
251 * ranges.
253 struct vmestablish_gpadl {
254 struct vmpacket_descriptor d;
255 u32 gpadl;
256 u32 range_cnt;
257 struct gpa_range range[1];
258 } __packed;
261 * This is the format for a Teardown Gpadl packet, which indicates that the
262 * GPADL handle in the Establish Gpadl packet will never be referenced again.
264 struct vmteardown_gpadl {
265 struct vmpacket_descriptor d;
266 u32 gpadl;
267 u32 reserved; /* for alignment to a 8-byte boundary */
268 } __packed;
271 * This is the format for a GPA-Direct packet, which contains a set of GPA
272 * ranges, in addition to commands and/or data.
274 struct vmdata_gpa_direct {
275 struct vmpacket_descriptor d;
276 u32 reserved;
277 u32 range_cnt;
278 struct gpa_range range[1];
279 } __packed;
281 /* This is the format for a Additional Data Packet. */
282 struct vmadditional_data {
283 struct vmpacket_descriptor d;
284 u64 total_bytes;
285 u32 offset;
286 u32 byte_cnt;
287 unsigned char data[1];
288 } __packed;
290 union vmpacket_largest_possible_header {
291 struct vmpacket_descriptor simple_hdr;
292 struct vmtransfer_page_packet_header xfer_page_hdr;
293 struct vmgpadl_packet_header gpadl_hdr;
294 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
295 struct vmestablish_gpadl establish_gpadl_hdr;
296 struct vmteardown_gpadl teardown_gpadl_hdr;
297 struct vmdata_gpa_direct data_gpa_direct_hdr;
300 #define VMPACKET_DATA_START_ADDRESS(__packet) \
301 (void *)(((unsigned char *)__packet) + \
302 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
304 #define VMPACKET_DATA_LENGTH(__packet) \
305 ((((struct vmpacket_descriptor)__packet)->len8 - \
306 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
308 #define VMPACKET_TRANSFER_MODE(__packet) \
309 (((struct IMPACT)__packet)->type)
311 enum vmbus_packet_type {
312 VM_PKT_INVALID = 0x0,
313 VM_PKT_SYNCH = 0x1,
314 VM_PKT_ADD_XFER_PAGESET = 0x2,
315 VM_PKT_RM_XFER_PAGESET = 0x3,
316 VM_PKT_ESTABLISH_GPADL = 0x4,
317 VM_PKT_TEARDOWN_GPADL = 0x5,
318 VM_PKT_DATA_INBAND = 0x6,
319 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
320 VM_PKT_DATA_USING_GPADL = 0x8,
321 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
322 VM_PKT_CANCEL_REQUEST = 0xa,
323 VM_PKT_COMP = 0xb,
324 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
325 VM_PKT_ADDITIONAL_DATA = 0xd
328 #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
331 /* Version 1 messages */
332 enum vmbus_channel_message_type {
333 CHANNELMSG_INVALID = 0,
334 CHANNELMSG_OFFERCHANNEL = 1,
335 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
336 CHANNELMSG_REQUESTOFFERS = 3,
337 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
338 CHANNELMSG_OPENCHANNEL = 5,
339 CHANNELMSG_OPENCHANNEL_RESULT = 6,
340 CHANNELMSG_CLOSECHANNEL = 7,
341 CHANNELMSG_GPADL_HEADER = 8,
342 CHANNELMSG_GPADL_BODY = 9,
343 CHANNELMSG_GPADL_CREATED = 10,
344 CHANNELMSG_GPADL_TEARDOWN = 11,
345 CHANNELMSG_GPADL_TORNDOWN = 12,
346 CHANNELMSG_RELID_RELEASED = 13,
347 CHANNELMSG_INITIATE_CONTACT = 14,
348 CHANNELMSG_VERSION_RESPONSE = 15,
349 CHANNELMSG_UNLOAD = 16,
350 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
351 CHANNELMSG_VIEWRANGE_ADD = 17,
352 CHANNELMSG_VIEWRANGE_REMOVE = 18,
353 #endif
354 CHANNELMSG_COUNT
357 struct vmbus_channel_message_header {
358 enum vmbus_channel_message_type msgtype;
359 u32 padding;
360 } __packed;
362 /* Query VMBus Version parameters */
363 struct vmbus_channel_query_vmbus_version {
364 struct vmbus_channel_message_header header;
365 u32 version;
366 } __packed;
368 /* VMBus Version Supported parameters */
369 struct vmbus_channel_version_supported {
370 struct vmbus_channel_message_header header;
371 bool version_supported;
372 } __packed;
374 /* Offer Channel parameters */
375 struct vmbus_channel_offer_channel {
376 struct vmbus_channel_message_header header;
377 struct vmbus_channel_offer offer;
378 u32 child_relid;
379 u8 monitorid;
380 bool monitor_allocated;
381 } __packed;
383 /* Rescind Offer parameters */
384 struct vmbus_channel_rescind_offer {
385 struct vmbus_channel_message_header header;
386 u32 child_relid;
387 } __packed;
390 * Request Offer -- no parameters, SynIC message contains the partition ID
391 * Set Snoop -- no parameters, SynIC message contains the partition ID
392 * Clear Snoop -- no parameters, SynIC message contains the partition ID
393 * All Offers Delivered -- no parameters, SynIC message contains the partition
394 * ID
395 * Flush Client -- no parameters, SynIC message contains the partition ID
398 /* Open Channel parameters */
399 struct vmbus_channel_open_channel {
400 struct vmbus_channel_message_header header;
402 /* Identifies the specific VMBus channel that is being opened. */
403 u32 child_relid;
405 /* ID making a particular open request at a channel offer unique. */
406 u32 openid;
408 /* GPADL for the channel's ring buffer. */
409 u32 ringbuffer_gpadlhandle;
411 /* GPADL for the channel's server context save area. */
412 u32 server_contextarea_gpadlhandle;
415 * The upstream ring buffer begins at offset zero in the memory
416 * described by RingBufferGpadlHandle. The downstream ring buffer
417 * follows it at this offset (in pages).
419 u32 downstream_ringbuffer_pageoffset;
421 /* User-specific data to be passed along to the server endpoint. */
422 unsigned char userdata[MAX_USER_DEFINED_BYTES];
423 } __packed;
425 /* Open Channel Result parameters */
426 struct vmbus_channel_open_result {
427 struct vmbus_channel_message_header header;
428 u32 child_relid;
429 u32 openid;
430 u32 status;
431 } __packed;
433 /* Close channel parameters; */
434 struct vmbus_channel_close_channel {
435 struct vmbus_channel_message_header header;
436 u32 child_relid;
437 } __packed;
439 /* Channel Message GPADL */
440 #define GPADL_TYPE_RING_BUFFER 1
441 #define GPADL_TYPE_SERVER_SAVE_AREA 2
442 #define GPADL_TYPE_TRANSACTION 8
445 * The number of PFNs in a GPADL message is defined by the number of
446 * pages that would be spanned by ByteCount and ByteOffset. If the
447 * implied number of PFNs won't fit in this packet, there will be a
448 * follow-up packet that contains more.
450 struct vmbus_channel_gpadl_header {
451 struct vmbus_channel_message_header header;
452 u32 child_relid;
453 u32 gpadl;
454 u16 range_buflen;
455 u16 rangecount;
456 struct gpa_range range[0];
457 } __packed;
459 /* This is the followup packet that contains more PFNs. */
460 struct vmbus_channel_gpadl_body {
461 struct vmbus_channel_message_header header;
462 u32 msgnumber;
463 u32 gpadl;
464 u64 pfn[0];
465 } __packed;
467 struct vmbus_channel_gpadl_created {
468 struct vmbus_channel_message_header header;
469 u32 child_relid;
470 u32 gpadl;
471 u32 creation_status;
472 } __packed;
474 struct vmbus_channel_gpadl_teardown {
475 struct vmbus_channel_message_header header;
476 u32 child_relid;
477 u32 gpadl;
478 } __packed;
480 struct vmbus_channel_gpadl_torndown {
481 struct vmbus_channel_message_header header;
482 u32 gpadl;
483 } __packed;
485 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
486 struct vmbus_channel_view_range_add {
487 struct vmbus_channel_message_header header;
488 PHYSICAL_ADDRESS viewrange_base;
489 u64 viewrange_length;
490 u32 child_relid;
491 } __packed;
493 struct vmbus_channel_view_range_remove {
494 struct vmbus_channel_message_header header;
495 PHYSICAL_ADDRESS viewrange_base;
496 u32 child_relid;
497 } __packed;
498 #endif
500 struct vmbus_channel_relid_released {
501 struct vmbus_channel_message_header header;
502 u32 child_relid;
503 } __packed;
505 struct vmbus_channel_initiate_contact {
506 struct vmbus_channel_message_header header;
507 u32 vmbus_version_requested;
508 u32 padding2;
509 u64 interrupt_page;
510 u64 monitor_page1;
511 u64 monitor_page2;
512 } __packed;
514 struct vmbus_channel_version_response {
515 struct vmbus_channel_message_header header;
516 bool version_supported;
517 } __packed;
519 enum vmbus_channel_state {
520 CHANNEL_OFFER_STATE,
521 CHANNEL_OPENING_STATE,
522 CHANNEL_OPEN_STATE,
525 struct vmbus_channel_debug_info {
526 u32 relid;
527 enum vmbus_channel_state state;
528 uuid_le interfacetype;
529 uuid_le interface_instance;
530 u32 monitorid;
531 u32 servermonitor_pending;
532 u32 servermonitor_latency;
533 u32 servermonitor_connectionid;
534 u32 clientmonitor_pending;
535 u32 clientmonitor_latency;
536 u32 clientmonitor_connectionid;
538 struct hv_ring_buffer_debug_info inbound;
539 struct hv_ring_buffer_debug_info outbound;
543 * Represents each channel msg on the vmbus connection This is a
544 * variable-size data structure depending on the msg type itself
546 struct vmbus_channel_msginfo {
547 /* Bookkeeping stuff */
548 struct list_head msglistentry;
550 /* So far, this is only used to handle gpadl body message */
551 struct list_head submsglist;
553 /* Synchronize the request/response if needed */
554 struct completion waitevent;
555 union {
556 struct vmbus_channel_version_supported version_supported;
557 struct vmbus_channel_open_result open_result;
558 struct vmbus_channel_gpadl_torndown gpadl_torndown;
559 struct vmbus_channel_gpadl_created gpadl_created;
560 struct vmbus_channel_version_response version_response;
561 } response;
563 u32 msgsize;
565 * The channel message that goes out on the "wire".
566 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
568 unsigned char msg[0];
571 struct vmbus_close_msg {
572 struct vmbus_channel_msginfo info;
573 struct vmbus_channel_close_channel msg;
576 struct vmbus_channel {
577 struct list_head listentry;
579 struct hv_device *device_obj;
581 struct work_struct work;
583 enum vmbus_channel_state state;
585 * For util channels, stash the
586 * the service index for easy access.
588 s8 util_index;
590 struct vmbus_channel_offer_channel offermsg;
592 * These are based on the OfferMsg.MonitorId.
593 * Save it here for easy access.
595 u8 monitor_grp;
596 u8 monitor_bit;
598 u32 ringbuffer_gpadlhandle;
600 /* Allocated memory for ring buffer */
601 void *ringbuffer_pages;
602 u32 ringbuffer_pagecount;
603 struct hv_ring_buffer_info outbound; /* send to parent */
604 struct hv_ring_buffer_info inbound; /* receive from parent */
605 spinlock_t inbound_lock;
606 struct workqueue_struct *controlwq;
608 struct vmbus_close_msg close_msg;
610 /* Channel callback are invoked in this workqueue context */
611 /* HANDLE dataWorkQueue; */
613 void (*onchannel_callback)(void *context);
614 void *channel_callback_context;
617 void free_channel(struct vmbus_channel *channel);
619 void vmbus_onmessage(void *context);
621 int vmbus_request_offers(void);
623 /* The format must be the same as struct vmdata_gpa_direct */
624 struct vmbus_channel_packet_page_buffer {
625 u16 type;
626 u16 dataoffset8;
627 u16 length8;
628 u16 flags;
629 u64 transactionid;
630 u32 reserved;
631 u32 rangecount;
632 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
633 } __packed;
635 /* The format must be the same as struct vmdata_gpa_direct */
636 struct vmbus_channel_packet_multipage_buffer {
637 u16 type;
638 u16 dataoffset8;
639 u16 length8;
640 u16 flags;
641 u64 transactionid;
642 u32 reserved;
643 u32 rangecount; /* Always 1 in this case */
644 struct hv_multipage_buffer range;
645 } __packed;
648 extern int vmbus_open(struct vmbus_channel *channel,
649 u32 send_ringbuffersize,
650 u32 recv_ringbuffersize,
651 void *userdata,
652 u32 userdatalen,
653 void(*onchannel_callback)(void *context),
654 void *context);
656 extern void vmbus_close(struct vmbus_channel *channel);
658 extern int vmbus_sendpacket(struct vmbus_channel *channel,
659 const void *buffer,
660 u32 bufferLen,
661 u64 requestid,
662 enum vmbus_packet_type type,
663 u32 flags);
665 extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
666 struct hv_page_buffer pagebuffers[],
667 u32 pagecount,
668 void *buffer,
669 u32 bufferlen,
670 u64 requestid);
672 extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
673 struct hv_multipage_buffer *mpb,
674 void *buffer,
675 u32 bufferlen,
676 u64 requestid);
678 extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
679 void *kbuffer,
680 u32 size,
681 u32 *gpadl_handle);
683 extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
684 u32 gpadl_handle);
686 extern int vmbus_recvpacket(struct vmbus_channel *channel,
687 void *buffer,
688 u32 bufferlen,
689 u32 *buffer_actual_len,
690 u64 *requestid);
692 extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
693 void *buffer,
694 u32 bufferlen,
695 u32 *buffer_actual_len,
696 u64 *requestid);
699 extern void vmbus_get_debug_info(struct vmbus_channel *channel,
700 struct vmbus_channel_debug_info *debug);
702 extern void vmbus_ontimer(unsigned long data);
705 #define LOWORD(dw) ((unsigned short)(dw))
706 #define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF))
709 #define VMBUS 0x0001
710 #define STORVSC 0x0002
711 #define NETVSC 0x0004
712 #define INPUTVSC 0x0008
713 #define BLKVSC 0x0010
714 #define VMBUS_DRV 0x0100
715 #define STORVSC_DRV 0x0200
716 #define NETVSC_DRV 0x0400
717 #define INPUTVSC_DRV 0x0800
718 #define BLKVSC_DRV 0x1000
720 #define ALL_MODULES (VMBUS |\
721 STORVSC |\
722 NETVSC |\
723 INPUTVSC |\
724 BLKVSC |\
725 VMBUS_DRV |\
726 STORVSC_DRV |\
727 NETVSC_DRV |\
728 INPUTVSC_DRV|\
729 BLKVSC_DRV)
731 /* Logging Level */
732 #define ERROR_LVL 3
733 #define WARNING_LVL 4
734 #define INFO_LVL 6
735 #define DEBUG_LVL 7
736 #define DEBUG_LVL_ENTEREXIT 8
737 #define DEBUG_RING_LVL 9
739 extern unsigned int vmbus_loglevel;
741 #define DPRINT(mod, lvl, fmt, args...) do {\
742 if ((mod & (HIWORD(vmbus_loglevel))) && \
743 (lvl <= LOWORD(vmbus_loglevel))) \
744 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
745 } while (0)
747 #define DPRINT_DBG(mod, fmt, args...) do {\
748 if ((mod & (HIWORD(vmbus_loglevel))) && \
749 (DEBUG_LVL <= LOWORD(vmbus_loglevel))) \
750 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\
751 } while (0)
753 #define DPRINT_INFO(mod, fmt, args...) do {\
754 if ((mod & (HIWORD(vmbus_loglevel))) && \
755 (INFO_LVL <= LOWORD(vmbus_loglevel))) \
756 printk(KERN_INFO #mod": " fmt "\n", ## args);\
757 } while (0)
759 #define DPRINT_WARN(mod, fmt, args...) do {\
760 if ((mod & (HIWORD(vmbus_loglevel))) && \
761 (WARNING_LVL <= LOWORD(vmbus_loglevel))) \
762 printk(KERN_WARNING #mod": WARNING! " fmt "\n", ## args);\
763 } while (0)
765 #define DPRINT_ERR(mod, fmt, args...) do {\
766 if ((mod & (HIWORD(vmbus_loglevel))) && \
767 (ERROR_LVL <= LOWORD(vmbus_loglevel))) \
768 printk(KERN_ERR #mod": %s() ERROR!! " fmt "\n", \
769 __func__, ## args);\
770 } while (0)
774 struct hv_driver;
775 struct hv_device;
777 struct hv_dev_port_info {
778 u32 int_mask;
779 u32 read_idx;
780 u32 write_idx;
781 u32 bytes_avail_toread;
782 u32 bytes_avail_towrite;
785 struct hv_device_info {
786 u32 chn_id;
787 u32 chn_state;
788 uuid_le chn_type;
789 uuid_le chn_instance;
791 u32 monitor_id;
792 u32 server_monitor_pending;
793 u32 server_monitor_latency;
794 u32 server_monitor_conn_id;
795 u32 client_monitor_pending;
796 u32 client_monitor_latency;
797 u32 client_monitor_conn_id;
799 struct hv_dev_port_info inbound;
800 struct hv_dev_port_info outbound;
803 /* Base driver object */
804 struct hv_driver {
805 const char *name;
807 /* the device type supported by this driver */
808 uuid_le dev_type;
809 const struct hv_vmbus_device_id *id_table;
811 struct device_driver driver;
813 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
814 int (*remove)(struct hv_device *);
815 void (*shutdown)(struct hv_device *);
819 /* Base device object */
820 struct hv_device {
821 /* the device type id of this device */
822 uuid_le dev_type;
824 /* the device instance id of this device */
825 uuid_le dev_instance;
827 struct device device;
829 struct vmbus_channel *channel;
833 static inline struct hv_device *device_to_hv_device(struct device *d)
835 return container_of(d, struct hv_device, device);
838 static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
840 return container_of(d, struct hv_driver, driver);
843 static inline void hv_set_drvdata(struct hv_device *dev, void *data)
845 dev_set_drvdata(&dev->device, data);
848 static inline void *hv_get_drvdata(struct hv_device *dev)
850 return dev_get_drvdata(&dev->device);
853 /* Vmbus interface */
854 #define vmbus_driver_register(driver) \
855 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
856 int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
857 struct module *owner,
858 const char *mod_name);
859 void vmbus_driver_unregister(struct hv_driver *hv_driver);
862 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
864 * This macro is used to create a struct hv_vmbus_device_id that matches a
865 * specific device.
867 #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
868 g8, g9, ga, gb, gc, gd, ge, gf) \
869 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
870 g8, g9, ga, gb, gc, gd, ge, gf },
873 * Common header for Hyper-V ICs
876 #define ICMSGTYPE_NEGOTIATE 0
877 #define ICMSGTYPE_HEARTBEAT 1
878 #define ICMSGTYPE_KVPEXCHANGE 2
879 #define ICMSGTYPE_SHUTDOWN 3
880 #define ICMSGTYPE_TIMESYNC 4
881 #define ICMSGTYPE_VSS 5
883 #define ICMSGHDRFLAG_TRANSACTION 1
884 #define ICMSGHDRFLAG_REQUEST 2
885 #define ICMSGHDRFLAG_RESPONSE 4
887 #define HV_S_OK 0x00000000
888 #define HV_E_FAIL 0x80004005
889 #define HV_ERROR_NOT_SUPPORTED 0x80070032
890 #define HV_ERROR_MACHINE_LOCKED 0x800704F7
892 struct vmbuspipe_hdr {
893 u32 flags;
894 u32 msgsize;
895 } __packed;
897 struct ic_version {
898 u16 major;
899 u16 minor;
900 } __packed;
902 struct icmsg_hdr {
903 struct ic_version icverframe;
904 u16 icmsgtype;
905 struct ic_version icvermsg;
906 u16 icmsgsize;
907 u32 status;
908 u8 ictransaction_id;
909 u8 icflags;
910 u8 reserved[2];
911 } __packed;
913 struct icmsg_negotiate {
914 u16 icframe_vercnt;
915 u16 icmsg_vercnt;
916 u32 reserved;
917 struct ic_version icversion_data[1]; /* any size array */
918 } __packed;
920 struct shutdown_msg_data {
921 u32 reason_code;
922 u32 timeout_seconds;
923 u32 flags;
924 u8 display_message[2048];
925 } __packed;
927 struct heartbeat_msg_data {
928 u64 seq_num;
929 u32 reserved[8];
930 } __packed;
932 /* Time Sync IC defs */
933 #define ICTIMESYNCFLAG_PROBE 0
934 #define ICTIMESYNCFLAG_SYNC 1
935 #define ICTIMESYNCFLAG_SAMPLE 2
937 #ifdef __x86_64__
938 #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
939 #else
940 #define WLTIMEDELTA 116444736000000000LL
941 #endif
943 struct ictimesync_data {
944 u64 parenttime;
945 u64 childtime;
946 u64 roundtriptime;
947 u8 flags;
948 } __packed;
950 /* Index for each IC struct in array hv_cb_utils[] */
951 #define HV_SHUTDOWN_MSG 0
952 #define HV_TIMESYNC_MSG 1
953 #define HV_HEARTBEAT_MSG 2
954 #define HV_KVP_MSG 3
956 struct hyperv_service_callback {
957 u8 msg_type;
958 char *log_msg;
959 uuid_le data;
960 struct vmbus_channel *channel;
961 void (*callback) (void *context);
964 extern void prep_negotiate_resp(struct icmsg_hdr *,
965 struct icmsg_negotiate *, u8 *);
966 extern void chn_cb_negotiate(void *);
967 extern struct hyperv_service_callback hv_cb_utils[];
969 #endif /* _HYPERV_H */