at v3.1 948 lines 24 kB view raw
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 */ 24 25#ifndef _HYPERV_H 26#define _HYPERV_H 27 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> 34 35 36#include <asm/hyperv.h> 37 38struct hv_guid { 39 unsigned char data[16]; 40}; 41 42#define MAX_PAGE_BUFFER_COUNT 16 43#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */ 44 45#pragma pack(push, 1) 46 47/* Single-page buffer */ 48struct hv_page_buffer { 49 u32 len; 50 u32 offset; 51 u64 pfn; 52}; 53 54/* Multiple-page buffer */ 55struct 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]; 60}; 61 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)) 68 69 70#pragma pack(pop) 71 72struct hv_ring_buffer { 73 /* Offset in bytes from the start of ring data below */ 74 u32 write_index; 75 76 /* Offset in bytes from the start of ring data below */ 77 u32 read_index; 78 79 u32 interrupt_mask; 80 81 /* Pad it to PAGE_SIZE so that data starts on page boundary */ 82 u8 reserved[4084]; 83 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. 88 */ 89 90 /* 91 * Ring data starts here + RingDataStartOffset 92 * !!! DO NOT place any fields below this !!! 93 */ 94 u8 buffer[0]; 95} __packed; 96 97struct hv_ring_buffer_info { 98 struct hv_ring_buffer *ring_buffer; 99 u32 ring_size; /* Include the shared header */ 100 spinlock_t ring_lock; 101 102 u32 ring_datasize; /* < ring_size */ 103 u32 ring_data_startoffset; 104}; 105 106struct 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; 112}; 113 114/* 115 * We use the same version numbering for all Hyper-V modules. 116 * 117 * Definition of versioning is as follows; 118 * 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. 129 * 130 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync 131 */ 132#define HV_DRV_VERSION "3.1" 133 134 135/* 136 * A revision number of vmbus that is used for ensuring both ends on a 137 * partition are using compatible versions. 138 */ 139#define VMBUS_REVISION_NUMBER 13 140 141/* Make maximum size of pipe payload of 16K */ 142#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) 143 144/* Define PipeMode values. */ 145#define VMBUS_PIPE_TYPE_BYTE 0x00000000 146#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004 147 148/* The size of the user defined data buffer for non-pipe offers. */ 149#define MAX_USER_DEFINED_BYTES 120 150 151/* The size of the user defined data buffer for pipe offers. */ 152#define MAX_PIPE_USER_DEFINED_BYTES 116 153 154/* 155 * At the center of the Channel Management library is the Channel Offer. This 156 * struct contains the fundamental information about an offer. 157 */ 158struct 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 */ 166 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; 172 173 /* 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. 179 */ 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; 187 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 196 197struct vmpacket_descriptor { 198 u16 type; 199 u16 offset8; 200 u16 len8; 201 u16 flags; 202 u64 trans_id; 203} __packed; 204 205struct vmpacket_header { 206 u32 prev_pkt_start_offset; 207 struct vmpacket_descriptor descriptor; 208} __packed; 209 210struct vmtransfer_page_range { 211 u32 byte_count; 212 u32 byte_offset; 213} __packed; 214 215struct 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; 223 224struct vmgpadl_packet_header { 225 struct vmpacket_descriptor d; 226 u32 gpadl; 227 u32 reserved; 228} __packed; 229 230struct vmadd_remove_transfer_page_set { 231 struct vmpacket_descriptor d; 232 u32 gpadl; 233 u16 xfer_pageset_id; 234 u16 reserved; 235} __packed; 236 237/* 238 * This structure defines a range in guest physical space that can be made to 239 * look virtually contiguous. 240 */ 241struct gpa_range { 242 u32 byte_count; 243 u32 byte_offset; 244 u64 pfn_array[0]; 245}; 246 247/* 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. 253 */ 254struct vmestablish_gpadl { 255 struct vmpacket_descriptor d; 256 u32 gpadl; 257 u32 range_cnt; 258 struct gpa_range range[1]; 259} __packed; 260 261/* 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. 264 */ 265struct vmteardown_gpadl { 266 struct vmpacket_descriptor d; 267 u32 gpadl; 268 u32 reserved; /* for alignment to a 8-byte boundary */ 269} __packed; 270 271/* 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. 274 */ 275struct vmdata_gpa_direct { 276 struct vmpacket_descriptor d; 277 u32 reserved; 278 u32 range_cnt; 279 struct gpa_range range[1]; 280} __packed; 281 282/* This is the format for a Additional Data Packet. */ 283struct 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; 290 291union 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; 299}; 300 301#define VMPACKET_DATA_START_ADDRESS(__packet) \ 302 (void *)(((unsigned char *)__packet) + \ 303 ((struct vmpacket_descriptor)__packet)->offset8 * 8) 304 305#define VMPACKET_DATA_LENGTH(__packet) \ 306 ((((struct vmpacket_descriptor)__packet)->len8 - \ 307 ((struct vmpacket_descriptor)__packet)->offset8) * 8) 308 309#define VMPACKET_TRANSFER_MODE(__packet) \ 310 (((struct IMPACT)__packet)->type) 311 312enum 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 327}; 328 329#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1 330 331 332/* Version 1 messages */ 333enum 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 356}; 357 358struct vmbus_channel_message_header { 359 enum vmbus_channel_message_type msgtype; 360 u32 padding; 361} __packed; 362 363/* Query VMBus Version parameters */ 364struct vmbus_channel_query_vmbus_version { 365 struct vmbus_channel_message_header header; 366 u32 version; 367} __packed; 368 369/* VMBus Version Supported parameters */ 370struct vmbus_channel_version_supported { 371 struct vmbus_channel_message_header header; 372 bool version_supported; 373} __packed; 374 375/* Offer Channel parameters */ 376struct 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; 383 384/* Rescind Offer parameters */ 385struct vmbus_channel_rescind_offer { 386 struct vmbus_channel_message_header header; 387 u32 child_relid; 388} __packed; 389 390/* 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 397 */ 398 399/* Open Channel parameters */ 400struct vmbus_channel_open_channel { 401 struct vmbus_channel_message_header header; 402 403 /* Identifies the specific VMBus channel that is being opened. */ 404 u32 child_relid; 405 406 /* ID making a particular open request at a channel offer unique. */ 407 u32 openid; 408 409 /* GPADL for the channel's ring buffer. */ 410 u32 ringbuffer_gpadlhandle; 411 412 /* GPADL for the channel's server context save area. */ 413 u32 server_contextarea_gpadlhandle; 414 415 /* 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). 419 */ 420 u32 downstream_ringbuffer_pageoffset; 421 422 /* User-specific data to be passed along to the server endpoint. */ 423 unsigned char userdata[MAX_USER_DEFINED_BYTES]; 424} __packed; 425 426/* Open Channel Result parameters */ 427struct vmbus_channel_open_result { 428 struct vmbus_channel_message_header header; 429 u32 child_relid; 430 u32 openid; 431 u32 status; 432} __packed; 433 434/* Close channel parameters; */ 435struct vmbus_channel_close_channel { 436 struct vmbus_channel_message_header header; 437 u32 child_relid; 438} __packed; 439 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 444 445/* 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. 450 */ 451struct 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; 459 460/* This is the followup packet that contains more PFNs. */ 461struct vmbus_channel_gpadl_body { 462 struct vmbus_channel_message_header header; 463 u32 msgnumber; 464 u32 gpadl; 465 u64 pfn[0]; 466} __packed; 467 468struct vmbus_channel_gpadl_created { 469 struct vmbus_channel_message_header header; 470 u32 child_relid; 471 u32 gpadl; 472 u32 creation_status; 473} __packed; 474 475struct vmbus_channel_gpadl_teardown { 476 struct vmbus_channel_message_header header; 477 u32 child_relid; 478 u32 gpadl; 479} __packed; 480 481struct vmbus_channel_gpadl_torndown { 482 struct vmbus_channel_message_header header; 483 u32 gpadl; 484} __packed; 485 486#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD 487struct 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; 493 494struct 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 500 501struct vmbus_channel_relid_released { 502 struct vmbus_channel_message_header header; 503 u32 child_relid; 504} __packed; 505 506struct 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; 514 515struct vmbus_channel_version_response { 516 struct vmbus_channel_message_header header; 517 bool version_supported; 518} __packed; 519 520enum vmbus_channel_state { 521 CHANNEL_OFFER_STATE, 522 CHANNEL_OPENING_STATE, 523 CHANNEL_OPEN_STATE, 524}; 525 526struct vmbus_channel_debug_info { 527 u32 relid; 528 enum vmbus_channel_state state; 529 struct hv_guid interfacetype; 530 struct hv_guid interface_instance; 531 u32 monitorid; 532 u32 servermonitor_pending; 533 u32 servermonitor_latency; 534 u32 servermonitor_connectionid; 535 u32 clientmonitor_pending; 536 u32 clientmonitor_latency; 537 u32 clientmonitor_connectionid; 538 539 struct hv_ring_buffer_debug_info inbound; 540 struct hv_ring_buffer_debug_info outbound; 541}; 542 543/* 544 * Represents each channel msg on the vmbus connection This is a 545 * variable-size data structure depending on the msg type itself 546 */ 547struct vmbus_channel_msginfo { 548 /* Bookkeeping stuff */ 549 struct list_head msglistentry; 550 551 /* So far, this is only used to handle gpadl body message */ 552 struct list_head submsglist; 553 554 /* Synchronize the request/response if needed */ 555 struct completion waitevent; 556 union { 557 struct vmbus_channel_version_supported version_supported; 558 struct vmbus_channel_open_result open_result; 559 struct vmbus_channel_gpadl_torndown gpadl_torndown; 560 struct vmbus_channel_gpadl_created gpadl_created; 561 struct vmbus_channel_version_response version_response; 562 } response; 563 564 u32 msgsize; 565 /* 566 * The channel message that goes out on the "wire". 567 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header 568 */ 569 unsigned char msg[0]; 570}; 571 572struct vmbus_close_msg { 573 struct vmbus_channel_msginfo info; 574 struct vmbus_channel_close_channel msg; 575}; 576 577struct vmbus_channel { 578 struct list_head listentry; 579 580 struct hv_device *device_obj; 581 582 struct work_struct work; 583 584 enum vmbus_channel_state state; 585 /* 586 * For util channels, stash the 587 * the service index for easy access. 588 */ 589 s8 util_index; 590 591 struct vmbus_channel_offer_channel offermsg; 592 /* 593 * These are based on the OfferMsg.MonitorId. 594 * Save it here for easy access. 595 */ 596 u8 monitor_grp; 597 u8 monitor_bit; 598 599 u32 ringbuffer_gpadlhandle; 600 601 /* Allocated memory for ring buffer */ 602 void *ringbuffer_pages; 603 u32 ringbuffer_pagecount; 604 struct hv_ring_buffer_info outbound; /* send to parent */ 605 struct hv_ring_buffer_info inbound; /* receive from parent */ 606 spinlock_t inbound_lock; 607 struct workqueue_struct *controlwq; 608 609 struct vmbus_close_msg close_msg; 610 611 /* Channel callback are invoked in this workqueue context */ 612 /* HANDLE dataWorkQueue; */ 613 614 void (*onchannel_callback)(void *context); 615 void *channel_callback_context; 616}; 617 618void free_channel(struct vmbus_channel *channel); 619 620void vmbus_onmessage(void *context); 621 622int vmbus_request_offers(void); 623 624/* The format must be the same as struct vmdata_gpa_direct */ 625struct vmbus_channel_packet_page_buffer { 626 u16 type; 627 u16 dataoffset8; 628 u16 length8; 629 u16 flags; 630 u64 transactionid; 631 u32 reserved; 632 u32 rangecount; 633 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT]; 634} __packed; 635 636/* The format must be the same as struct vmdata_gpa_direct */ 637struct vmbus_channel_packet_multipage_buffer { 638 u16 type; 639 u16 dataoffset8; 640 u16 length8; 641 u16 flags; 642 u64 transactionid; 643 u32 reserved; 644 u32 rangecount; /* Always 1 in this case */ 645 struct hv_multipage_buffer range; 646} __packed; 647 648 649extern int vmbus_open(struct vmbus_channel *channel, 650 u32 send_ringbuffersize, 651 u32 recv_ringbuffersize, 652 void *userdata, 653 u32 userdatalen, 654 void(*onchannel_callback)(void *context), 655 void *context); 656 657extern void vmbus_close(struct vmbus_channel *channel); 658 659extern int vmbus_sendpacket(struct vmbus_channel *channel, 660 const void *buffer, 661 u32 bufferLen, 662 u64 requestid, 663 enum vmbus_packet_type type, 664 u32 flags); 665 666extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel, 667 struct hv_page_buffer pagebuffers[], 668 u32 pagecount, 669 void *buffer, 670 u32 bufferlen, 671 u64 requestid); 672 673extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, 674 struct hv_multipage_buffer *mpb, 675 void *buffer, 676 u32 bufferlen, 677 u64 requestid); 678 679extern int vmbus_establish_gpadl(struct vmbus_channel *channel, 680 void *kbuffer, 681 u32 size, 682 u32 *gpadl_handle); 683 684extern int vmbus_teardown_gpadl(struct vmbus_channel *channel, 685 u32 gpadl_handle); 686 687extern int vmbus_recvpacket(struct vmbus_channel *channel, 688 void *buffer, 689 u32 bufferlen, 690 u32 *buffer_actual_len, 691 u64 *requestid); 692 693extern int vmbus_recvpacket_raw(struct vmbus_channel *channel, 694 void *buffer, 695 u32 bufferlen, 696 u32 *buffer_actual_len, 697 u64 *requestid); 698 699 700extern void vmbus_get_debug_info(struct vmbus_channel *channel, 701 struct vmbus_channel_debug_info *debug); 702 703extern void vmbus_ontimer(unsigned long data); 704 705 706#define LOWORD(dw) ((unsigned short)(dw)) 707#define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF)) 708 709 710#define VMBUS 0x0001 711#define STORVSC 0x0002 712#define NETVSC 0x0004 713#define INPUTVSC 0x0008 714#define BLKVSC 0x0010 715#define VMBUS_DRV 0x0100 716#define STORVSC_DRV 0x0200 717#define NETVSC_DRV 0x0400 718#define INPUTVSC_DRV 0x0800 719#define BLKVSC_DRV 0x1000 720 721#define ALL_MODULES (VMBUS |\ 722 STORVSC |\ 723 NETVSC |\ 724 INPUTVSC |\ 725 BLKVSC |\ 726 VMBUS_DRV |\ 727 STORVSC_DRV |\ 728 NETVSC_DRV |\ 729 INPUTVSC_DRV|\ 730 BLKVSC_DRV) 731 732/* Logging Level */ 733#define ERROR_LVL 3 734#define WARNING_LVL 4 735#define INFO_LVL 6 736#define DEBUG_LVL 7 737#define DEBUG_LVL_ENTEREXIT 8 738#define DEBUG_RING_LVL 9 739 740extern unsigned int vmbus_loglevel; 741 742#define DPRINT(mod, lvl, fmt, args...) do {\ 743 if ((mod & (HIWORD(vmbus_loglevel))) && \ 744 (lvl <= LOWORD(vmbus_loglevel))) \ 745 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\ 746 } while (0) 747 748#define DPRINT_DBG(mod, fmt, args...) do {\ 749 if ((mod & (HIWORD(vmbus_loglevel))) && \ 750 (DEBUG_LVL <= LOWORD(vmbus_loglevel))) \ 751 printk(KERN_DEBUG #mod": %s() " fmt "\n", __func__, ## args);\ 752 } while (0) 753 754#define DPRINT_INFO(mod, fmt, args...) do {\ 755 if ((mod & (HIWORD(vmbus_loglevel))) && \ 756 (INFO_LVL <= LOWORD(vmbus_loglevel))) \ 757 printk(KERN_INFO #mod": " fmt "\n", ## args);\ 758 } while (0) 759 760#define DPRINT_WARN(mod, fmt, args...) do {\ 761 if ((mod & (HIWORD(vmbus_loglevel))) && \ 762 (WARNING_LVL <= LOWORD(vmbus_loglevel))) \ 763 printk(KERN_WARNING #mod": WARNING! " fmt "\n", ## args);\ 764 } while (0) 765 766#define DPRINT_ERR(mod, fmt, args...) do {\ 767 if ((mod & (HIWORD(vmbus_loglevel))) && \ 768 (ERROR_LVL <= LOWORD(vmbus_loglevel))) \ 769 printk(KERN_ERR #mod": %s() ERROR!! " fmt "\n", \ 770 __func__, ## args);\ 771 } while (0) 772 773 774 775struct hv_driver; 776struct hv_device; 777 778struct hv_dev_port_info { 779 u32 int_mask; 780 u32 read_idx; 781 u32 write_idx; 782 u32 bytes_avail_toread; 783 u32 bytes_avail_towrite; 784}; 785 786struct hv_device_info { 787 u32 chn_id; 788 u32 chn_state; 789 struct hv_guid chn_type; 790 struct hv_guid chn_instance; 791 792 u32 monitor_id; 793 u32 server_monitor_pending; 794 u32 server_monitor_latency; 795 u32 server_monitor_conn_id; 796 u32 client_monitor_pending; 797 u32 client_monitor_latency; 798 u32 client_monitor_conn_id; 799 800 struct hv_dev_port_info inbound; 801 struct hv_dev_port_info outbound; 802}; 803 804/* Base driver object */ 805struct hv_driver { 806 const char *name; 807 808 /* the device type supported by this driver */ 809 struct hv_guid dev_type; 810 811 struct device_driver driver; 812 813 int (*probe)(struct hv_device *); 814 int (*remove)(struct hv_device *); 815 void (*shutdown)(struct hv_device *); 816 817}; 818 819/* Base device object */ 820struct hv_device { 821 /* the device type id of this device */ 822 struct hv_guid dev_type; 823 824 /* the device instance id of this device */ 825 struct hv_guid dev_instance; 826 827 struct device device; 828 829 struct vmbus_channel *channel; 830 831 /* Device extension; */ 832 void *ext; 833}; 834 835 836static inline struct hv_device *device_to_hv_device(struct device *d) 837{ 838 return container_of(d, struct hv_device, device); 839} 840 841static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d) 842{ 843 return container_of(d, struct hv_driver, driver); 844} 845 846 847/* Vmbus interface */ 848int vmbus_child_driver_register(struct device_driver *drv); 849void vmbus_child_driver_unregister(struct device_driver *drv); 850 851/* 852 * Common header for Hyper-V ICs 853 */ 854 855#define ICMSGTYPE_NEGOTIATE 0 856#define ICMSGTYPE_HEARTBEAT 1 857#define ICMSGTYPE_KVPEXCHANGE 2 858#define ICMSGTYPE_SHUTDOWN 3 859#define ICMSGTYPE_TIMESYNC 4 860#define ICMSGTYPE_VSS 5 861 862#define ICMSGHDRFLAG_TRANSACTION 1 863#define ICMSGHDRFLAG_REQUEST 2 864#define ICMSGHDRFLAG_RESPONSE 4 865 866#define HV_S_OK 0x00000000 867#define HV_E_FAIL 0x80004005 868#define HV_ERROR_NOT_SUPPORTED 0x80070032 869#define HV_ERROR_MACHINE_LOCKED 0x800704F7 870 871struct vmbuspipe_hdr { 872 u32 flags; 873 u32 msgsize; 874} __packed; 875 876struct ic_version { 877 u16 major; 878 u16 minor; 879} __packed; 880 881struct icmsg_hdr { 882 struct ic_version icverframe; 883 u16 icmsgtype; 884 struct ic_version icvermsg; 885 u16 icmsgsize; 886 u32 status; 887 u8 ictransaction_id; 888 u8 icflags; 889 u8 reserved[2]; 890} __packed; 891 892struct icmsg_negotiate { 893 u16 icframe_vercnt; 894 u16 icmsg_vercnt; 895 u32 reserved; 896 struct ic_version icversion_data[1]; /* any size array */ 897} __packed; 898 899struct shutdown_msg_data { 900 u32 reason_code; 901 u32 timeout_seconds; 902 u32 flags; 903 u8 display_message[2048]; 904} __packed; 905 906struct heartbeat_msg_data { 907 u64 seq_num; 908 u32 reserved[8]; 909} __packed; 910 911/* Time Sync IC defs */ 912#define ICTIMESYNCFLAG_PROBE 0 913#define ICTIMESYNCFLAG_SYNC 1 914#define ICTIMESYNCFLAG_SAMPLE 2 915 916#ifdef __x86_64__ 917#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */ 918#else 919#define WLTIMEDELTA 116444736000000000LL 920#endif 921 922struct ictimesync_data { 923 u64 parenttime; 924 u64 childtime; 925 u64 roundtriptime; 926 u8 flags; 927} __packed; 928 929/* Index for each IC struct in array hv_cb_utils[] */ 930#define HV_SHUTDOWN_MSG 0 931#define HV_TIMESYNC_MSG 1 932#define HV_HEARTBEAT_MSG 2 933#define HV_KVP_MSG 3 934 935struct hyperv_service_callback { 936 u8 msg_type; 937 char *log_msg; 938 unsigned char data[16]; 939 struct vmbus_channel *channel; 940 void (*callback) (void *context); 941}; 942 943extern void prep_negotiate_resp(struct icmsg_hdr *, 944 struct icmsg_negotiate *, u8 *); 945extern void chn_cb_negotiate(void *); 946extern struct hyperv_service_callback hv_cb_utils[]; 947 948#endif /* _HYPERV_H */