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