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