]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/hyperv.h
Revert "UBUNTU: SAUCE: LSM stacking: LSM: Infrastructure management of the remaining...
[mirror_ubuntu-artful-kernel.git] / include / linux / 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
5267cf02 28#include <uapi/linux/hyperv.h>
c75efa97 29#include <uapi/asm/hyperv.h>
2939437c 30
5267cf02 31#include <linux/types.h>
8ff3e6fc
S
32#include <linux/scatterlist.h>
33#include <linux/list.h>
34#include <linux/timer.h>
8ff3e6fc
S
35#include <linux/completion.h>
36#include <linux/device.h>
2e2c1d17 37#include <linux/mod_devicetable.h>
631e63a9 38#include <linux/interrupt.h>
8ff3e6fc 39
7e5ec368 40#define MAX_PAGE_BUFFER_COUNT 32
a363bf7b
S
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
d61031ee
S
60/*
61 * Multiple-page buffer array; the pfn array is variable size:
62 * The number of entries in the PFN array is determined by
63 * "len" and "offset".
64 */
65struct hv_mpb_array {
66 /* Length and Offset determines the # of pfns in the array */
67 u32 len;
68 u32 offset;
69 u64 pfn_array[];
70};
71
a363bf7b
S
72/* 0x18 includes the proprietary packet header */
73#define MAX_PAGE_BUFFER_PACKET (0x18 + \
74 (sizeof(struct hv_page_buffer) * \
75 MAX_PAGE_BUFFER_COUNT))
76#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
77 sizeof(struct hv_multipage_buffer))
78
79
80#pragma pack(pop)
81
7effffb7
S
82struct hv_ring_buffer {
83 /* Offset in bytes from the start of ring data below */
84 u32 write_index;
85
86 /* Offset in bytes from the start of ring data below */
87 u32 read_index;
88
89 u32 interrupt_mask;
90
2416603e
S
91 /*
92 * Win8 uses some of the reserved bits to implement
93 * interrupt driven flow management. On the send side
94 * we can request that the receiver interrupt the sender
95 * when the ring transitions from being full to being able
96 * to handle a message of size "pending_send_sz".
97 *
98 * Add necessary state for this enhancement.
7effffb7 99 */
2416603e
S
100 u32 pending_send_sz;
101
102 u32 reserved1[12];
103
104 union {
105 struct {
106 u32 feat_pending_send_sz:1;
107 };
108 u32 value;
109 } feature_bits;
110
111 /* Pad it to PAGE_SIZE so that data starts on page boundary */
112 u8 reserved2[4028];
7effffb7
S
113
114 /*
115 * Ring data starts here + RingDataStartOffset
116 * !!! DO NOT place any fields below this !!!
117 */
118 u8 buffer[0];
119} __packed;
120
121struct hv_ring_buffer_info {
122 struct hv_ring_buffer *ring_buffer;
123 u32 ring_size; /* Include the shared header */
124 spinlock_t ring_lock;
125
126 u32 ring_datasize; /* < ring_size */
127 u32 ring_data_startoffset;
ab028db4
S
128 u32 priv_write_index;
129 u32 priv_read_index;
7effffb7
S
130};
131
33be96e4
HZ
132/*
133 *
134 * hv_get_ringbuffer_availbytes()
135 *
136 * Get number of bytes available to read and to write to
137 * for the specified ring buffer
138 */
139static inline void
e4165a0f
SH
140hv_get_ringbuffer_availbytes(const struct hv_ring_buffer_info *rbi,
141 u32 *read, u32 *write)
33be96e4
HZ
142{
143 u32 read_loc, write_loc, dsize;
144
33be96e4
HZ
145 /* Capture the read/write indices before they changed */
146 read_loc = rbi->ring_buffer->read_index;
147 write_loc = rbi->ring_buffer->write_index;
148 dsize = rbi->ring_datasize;
149
150 *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
151 read_loc - write_loc;
152 *read = dsize - *write;
153}
154
e4165a0f 155static inline u32 hv_get_bytes_to_read(const struct hv_ring_buffer_info *rbi)
a6341f00
S
156{
157 u32 read_loc, write_loc, dsize, read;
158
159 dsize = rbi->ring_datasize;
160 read_loc = rbi->ring_buffer->read_index;
161 write_loc = READ_ONCE(rbi->ring_buffer->write_index);
162
163 read = write_loc >= read_loc ? (write_loc - read_loc) :
164 (dsize - read_loc) + write_loc;
165
166 return read;
167}
168
e4165a0f 169static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi)
a6341f00
S
170{
171 u32 read_loc, write_loc, dsize, write;
172
173 dsize = rbi->ring_datasize;
174 read_loc = READ_ONCE(rbi->ring_buffer->read_index);
175 write_loc = rbi->ring_buffer->write_index;
176
177 write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
178 read_loc - write_loc;
179 return write;
180}
181
eafa7072
S
182/*
183 * VMBUS version is 32 bit entity broken up into
184 * two 16 bit quantities: major_number. minor_number.
185 *
186 * 0 . 13 (Windows Server 2008)
187 * 1 . 1 (Windows 7)
188 * 2 . 4 (Windows 8)
03367ef5 189 * 3 . 0 (Windows 8 R2)
6c4e5f9c 190 * 4 . 0 (Windows 10)
eafa7072
S
191 */
192
193#define VERSION_WS2008 ((0 << 16) | (13))
194#define VERSION_WIN7 ((1 << 16) | (1))
195#define VERSION_WIN8 ((2 << 16) | (4))
03367ef5 196#define VERSION_WIN8_1 ((3 << 16) | (0))
6c4e5f9c 197#define VERSION_WIN10 ((4 << 16) | (0))
eafa7072
S
198
199#define VERSION_INVAL -1
200
6c4e5f9c 201#define VERSION_CURRENT VERSION_WIN10
f7c6dfda 202
517d8dc6
S
203/* Make maximum size of pipe payload of 16K */
204#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
205
206/* Define PipeMode values. */
207#define VMBUS_PIPE_TYPE_BYTE 0x00000000
208#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
209
210/* The size of the user defined data buffer for non-pipe offers. */
211#define MAX_USER_DEFINED_BYTES 120
212
213/* The size of the user defined data buffer for pipe offers. */
214#define MAX_PIPE_USER_DEFINED_BYTES 116
215
216/*
217 * At the center of the Channel Management library is the Channel Offer. This
218 * struct contains the fundamental information about an offer.
219 */
220struct vmbus_channel_offer {
358d2ee2
S
221 uuid_le if_type;
222 uuid_le if_instance;
29423b7e
S
223
224 /*
225 * These two fields are not currently used.
226 */
227 u64 reserved1;
228 u64 reserved2;
229
517d8dc6
S
230 u16 chn_flags;
231 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
232
233 union {
234 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
235 struct {
236 unsigned char user_def[MAX_USER_DEFINED_BYTES];
237 } std;
238
239 /*
240 * Pipes:
241 * The following sructure is an integrated pipe protocol, which
242 * is implemented on top of standard user-defined data. Pipe
243 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
244 * use.
245 */
246 struct {
247 u32 pipe_mode;
248 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
249 } pipe;
250 } u;
29423b7e
S
251 /*
252 * The sub_channel_index is defined in win8.
253 */
254 u16 sub_channel_index;
255 u16 reserved3;
517d8dc6
S
256} __packed;
257
258/* Server Flags */
259#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
260#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
261#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
262#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
263#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
264#define VMBUS_CHANNEL_PARENT_OFFER 0x200
265#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
e8d6ca02 266#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000
517d8dc6 267
50ed40e0
S
268struct vmpacket_descriptor {
269 u16 type;
270 u16 offset8;
271 u16 len8;
272 u16 flags;
273 u64 trans_id;
274} __packed;
275
276struct vmpacket_header {
277 u32 prev_pkt_start_offset;
278 struct vmpacket_descriptor descriptor;
279} __packed;
280
281struct vmtransfer_page_range {
282 u32 byte_count;
283 u32 byte_offset;
284} __packed;
285
286struct vmtransfer_page_packet_header {
287 struct vmpacket_descriptor d;
288 u16 xfer_pageset_id;
1508d811 289 u8 sender_owns_set;
50ed40e0
S
290 u8 reserved;
291 u32 range_cnt;
292 struct vmtransfer_page_range ranges[1];
293} __packed;
294
295struct vmgpadl_packet_header {
296 struct vmpacket_descriptor d;
297 u32 gpadl;
298 u32 reserved;
299} __packed;
300
301struct vmadd_remove_transfer_page_set {
302 struct vmpacket_descriptor d;
303 u32 gpadl;
304 u16 xfer_pageset_id;
305 u16 reserved;
306} __packed;
307
308/*
309 * This structure defines a range in guest physical space that can be made to
310 * look virtually contiguous.
311 */
312struct gpa_range {
313 u32 byte_count;
314 u32 byte_offset;
315 u64 pfn_array[0];
316};
317
318/*
319 * This is the format for an Establish Gpadl packet, which contains a handle by
320 * which this GPADL will be known and a set of GPA ranges associated with it.
321 * This can be converted to a MDL by the guest OS. If there are multiple GPA
322 * ranges, then the resulting MDL will be "chained," representing multiple VA
323 * ranges.
324 */
325struct vmestablish_gpadl {
326 struct vmpacket_descriptor d;
327 u32 gpadl;
328 u32 range_cnt;
329 struct gpa_range range[1];
330} __packed;
331
332/*
333 * This is the format for a Teardown Gpadl packet, which indicates that the
334 * GPADL handle in the Establish Gpadl packet will never be referenced again.
335 */
336struct vmteardown_gpadl {
337 struct vmpacket_descriptor d;
338 u32 gpadl;
339 u32 reserved; /* for alignment to a 8-byte boundary */
340} __packed;
341
342/*
343 * This is the format for a GPA-Direct packet, which contains a set of GPA
344 * ranges, in addition to commands and/or data.
345 */
346struct vmdata_gpa_direct {
347 struct vmpacket_descriptor d;
348 u32 reserved;
349 u32 range_cnt;
350 struct gpa_range range[1];
351} __packed;
352
353/* This is the format for a Additional Data Packet. */
354struct vmadditional_data {
355 struct vmpacket_descriptor d;
356 u64 total_bytes;
357 u32 offset;
358 u32 byte_cnt;
359 unsigned char data[1];
360} __packed;
361
362union vmpacket_largest_possible_header {
363 struct vmpacket_descriptor simple_hdr;
364 struct vmtransfer_page_packet_header xfer_page_hdr;
365 struct vmgpadl_packet_header gpadl_hdr;
366 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
367 struct vmestablish_gpadl establish_gpadl_hdr;
368 struct vmteardown_gpadl teardown_gpadl_hdr;
369 struct vmdata_gpa_direct data_gpa_direct_hdr;
370};
371
372#define VMPACKET_DATA_START_ADDRESS(__packet) \
373 (void *)(((unsigned char *)__packet) + \
374 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
375
376#define VMPACKET_DATA_LENGTH(__packet) \
377 ((((struct vmpacket_descriptor)__packet)->len8 - \
378 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
379
380#define VMPACKET_TRANSFER_MODE(__packet) \
381 (((struct IMPACT)__packet)->type)
382
383enum vmbus_packet_type {
384 VM_PKT_INVALID = 0x0,
385 VM_PKT_SYNCH = 0x1,
386 VM_PKT_ADD_XFER_PAGESET = 0x2,
387 VM_PKT_RM_XFER_PAGESET = 0x3,
388 VM_PKT_ESTABLISH_GPADL = 0x4,
389 VM_PKT_TEARDOWN_GPADL = 0x5,
390 VM_PKT_DATA_INBAND = 0x6,
391 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
392 VM_PKT_DATA_USING_GPADL = 0x8,
393 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
394 VM_PKT_CANCEL_REQUEST = 0xa,
395 VM_PKT_COMP = 0xb,
396 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
397 VM_PKT_ADDITIONAL_DATA = 0xd
398};
399
400#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
517d8dc6 401
b56dda06 402
b56dda06
S
403/* Version 1 messages */
404enum vmbus_channel_message_type {
405 CHANNELMSG_INVALID = 0,
406 CHANNELMSG_OFFERCHANNEL = 1,
407 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
408 CHANNELMSG_REQUESTOFFERS = 3,
409 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
410 CHANNELMSG_OPENCHANNEL = 5,
411 CHANNELMSG_OPENCHANNEL_RESULT = 6,
412 CHANNELMSG_CLOSECHANNEL = 7,
413 CHANNELMSG_GPADL_HEADER = 8,
414 CHANNELMSG_GPADL_BODY = 9,
415 CHANNELMSG_GPADL_CREATED = 10,
416 CHANNELMSG_GPADL_TEARDOWN = 11,
417 CHANNELMSG_GPADL_TORNDOWN = 12,
418 CHANNELMSG_RELID_RELEASED = 13,
419 CHANNELMSG_INITIATE_CONTACT = 14,
420 CHANNELMSG_VERSION_RESPONSE = 15,
421 CHANNELMSG_UNLOAD = 16,
2db84eff 422 CHANNELMSG_UNLOAD_RESPONSE = 17,
5c23a1a5
DC
423 CHANNELMSG_18 = 18,
424 CHANNELMSG_19 = 19,
425 CHANNELMSG_20 = 20,
426 CHANNELMSG_TL_CONNECT_REQUEST = 21,
b56dda06
S
427 CHANNELMSG_COUNT
428};
429
430struct vmbus_channel_message_header {
431 enum vmbus_channel_message_type msgtype;
432 u32 padding;
433} __packed;
434
435/* Query VMBus Version parameters */
436struct vmbus_channel_query_vmbus_version {
437 struct vmbus_channel_message_header header;
438 u32 version;
439} __packed;
440
441/* VMBus Version Supported parameters */
442struct vmbus_channel_version_supported {
443 struct vmbus_channel_message_header header;
1508d811 444 u8 version_supported;
b56dda06
S
445} __packed;
446
447/* Offer Channel parameters */
448struct vmbus_channel_offer_channel {
449 struct vmbus_channel_message_header header;
450 struct vmbus_channel_offer offer;
451 u32 child_relid;
452 u8 monitorid;
29423b7e
S
453 /*
454 * win7 and beyond splits this field into a bit field.
455 */
456 u8 monitor_allocated:1;
457 u8 reserved:7;
458 /*
459 * These are new fields added in win7 and later.
460 * Do not access these fields without checking the
461 * negotiated protocol.
462 *
463 * If "is_dedicated_interrupt" is set, we must not set the
464 * associated bit in the channel bitmap while sending the
465 * interrupt to the host.
466 *
467 * connection_id is to be used in signaling the host.
468 */
469 u16 is_dedicated_interrupt:1;
470 u16 reserved1:15;
471 u32 connection_id;
b56dda06
S
472} __packed;
473
474/* Rescind Offer parameters */
475struct vmbus_channel_rescind_offer {
476 struct vmbus_channel_message_header header;
477 u32 child_relid;
478} __packed;
479
4827ee1d
SH
480static inline u32
481hv_ringbuffer_pending_size(const struct hv_ring_buffer_info *rbi)
482{
483 return rbi->ring_buffer->pending_send_sz;
484}
485
b56dda06
S
486/*
487 * Request Offer -- no parameters, SynIC message contains the partition ID
488 * Set Snoop -- no parameters, SynIC message contains the partition ID
489 * Clear Snoop -- no parameters, SynIC message contains the partition ID
490 * All Offers Delivered -- no parameters, SynIC message contains the partition
491 * ID
492 * Flush Client -- no parameters, SynIC message contains the partition ID
493 */
494
495/* Open Channel parameters */
496struct vmbus_channel_open_channel {
497 struct vmbus_channel_message_header header;
498
499 /* Identifies the specific VMBus channel that is being opened. */
500 u32 child_relid;
501
502 /* ID making a particular open request at a channel offer unique. */
503 u32 openid;
504
505 /* GPADL for the channel's ring buffer. */
506 u32 ringbuffer_gpadlhandle;
507
abbf3b2a
S
508 /*
509 * Starting with win8, this field will be used to specify
510 * the target virtual processor on which to deliver the interrupt for
511 * the host to guest communication.
512 * Prior to win8, incoming channel interrupts would only
513 * be delivered on cpu 0. Setting this value to 0 would
514 * preserve the earlier behavior.
515 */
516 u32 target_vp;
b56dda06
S
517
518 /*
2a9d7de2
SH
519 * The upstream ring buffer begins at offset zero in the memory
520 * described by RingBufferGpadlHandle. The downstream ring buffer
521 * follows it at this offset (in pages).
522 */
b56dda06
S
523 u32 downstream_ringbuffer_pageoffset;
524
525 /* User-specific data to be passed along to the server endpoint. */
526 unsigned char userdata[MAX_USER_DEFINED_BYTES];
527} __packed;
528
529/* Open Channel Result parameters */
530struct vmbus_channel_open_result {
531 struct vmbus_channel_message_header header;
532 u32 child_relid;
533 u32 openid;
534 u32 status;
535} __packed;
536
537/* Close channel parameters; */
538struct vmbus_channel_close_channel {
539 struct vmbus_channel_message_header header;
540 u32 child_relid;
541} __packed;
542
543/* Channel Message GPADL */
544#define GPADL_TYPE_RING_BUFFER 1
545#define GPADL_TYPE_SERVER_SAVE_AREA 2
546#define GPADL_TYPE_TRANSACTION 8
547
548/*
549 * The number of PFNs in a GPADL message is defined by the number of
550 * pages that would be spanned by ByteCount and ByteOffset. If the
551 * implied number of PFNs won't fit in this packet, there will be a
552 * follow-up packet that contains more.
553 */
554struct vmbus_channel_gpadl_header {
555 struct vmbus_channel_message_header header;
556 u32 child_relid;
557 u32 gpadl;
558 u16 range_buflen;
559 u16 rangecount;
560 struct gpa_range range[0];
561} __packed;
562
563/* This is the followup packet that contains more PFNs. */
564struct vmbus_channel_gpadl_body {
565 struct vmbus_channel_message_header header;
566 u32 msgnumber;
567 u32 gpadl;
568 u64 pfn[0];
569} __packed;
570
571struct vmbus_channel_gpadl_created {
572 struct vmbus_channel_message_header header;
573 u32 child_relid;
574 u32 gpadl;
575 u32 creation_status;
576} __packed;
577
578struct vmbus_channel_gpadl_teardown {
579 struct vmbus_channel_message_header header;
580 u32 child_relid;
581 u32 gpadl;
582} __packed;
583
584struct vmbus_channel_gpadl_torndown {
585 struct vmbus_channel_message_header header;
586 u32 gpadl;
587} __packed;
588
b56dda06
S
589struct vmbus_channel_relid_released {
590 struct vmbus_channel_message_header header;
591 u32 child_relid;
592} __packed;
593
594struct vmbus_channel_initiate_contact {
595 struct vmbus_channel_message_header header;
596 u32 vmbus_version_requested;
e28bab48 597 u32 target_vcpu; /* The VCPU the host should respond to */
b56dda06
S
598 u64 interrupt_page;
599 u64 monitor_page1;
600 u64 monitor_page2;
601} __packed;
602
5c23a1a5
DC
603/* Hyper-V socket: guest's connect()-ing to host */
604struct vmbus_channel_tl_connect_request {
605 struct vmbus_channel_message_header header;
606 uuid_le guest_endpoint_id;
607 uuid_le host_service_id;
608} __packed;
609
b56dda06
S
610struct vmbus_channel_version_response {
611 struct vmbus_channel_message_header header;
1508d811 612 u8 version_supported;
b56dda06
S
613} __packed;
614
615enum vmbus_channel_state {
616 CHANNEL_OFFER_STATE,
617 CHANNEL_OPENING_STATE,
618 CHANNEL_OPEN_STATE,
e68d2971 619 CHANNEL_OPENED_STATE,
b56dda06
S
620};
621
b56dda06
S
622/*
623 * Represents each channel msg on the vmbus connection This is a
624 * variable-size data structure depending on the msg type itself
625 */
626struct vmbus_channel_msginfo {
627 /* Bookkeeping stuff */
628 struct list_head msglistentry;
629
630 /* So far, this is only used to handle gpadl body message */
631 struct list_head submsglist;
632
633 /* Synchronize the request/response if needed */
634 struct completion waitevent;
ccb61f8a 635 struct vmbus_channel *waiting_channel;
b56dda06
S
636 union {
637 struct vmbus_channel_version_supported version_supported;
638 struct vmbus_channel_open_result open_result;
639 struct vmbus_channel_gpadl_torndown gpadl_torndown;
640 struct vmbus_channel_gpadl_created gpadl_created;
641 struct vmbus_channel_version_response version_response;
642 } response;
643
644 u32 msgsize;
645 /*
646 * The channel message that goes out on the "wire".
647 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
648 */
649 unsigned char msg[0];
650};
651
f9f1db83
S
652struct vmbus_close_msg {
653 struct vmbus_channel_msginfo info;
654 struct vmbus_channel_close_channel msg;
655};
656
b3bf60c7
S
657/* Define connection identifier type. */
658union hv_connection_id {
659 u32 asu32;
660 struct {
661 u32 id:24;
662 u32 reserved:8;
663 } u;
664};
665
666/* Definition of the hv_signal_event hypercall input structure. */
667struct hv_input_signal_event {
668 union hv_connection_id connectionid;
669 u16 flag_number;
670 u16 rsvdz;
671};
672
673struct hv_input_signal_event_buffer {
674 u64 align8;
675 struct hv_input_signal_event event;
676};
677
509879bd
S
678enum hv_numa_policy {
679 HV_BALANCED = 0,
680 HV_LOCALIZED,
681};
682
7047f17d
S
683enum vmbus_device_type {
684 HV_IDE = 0,
685 HV_SCSI,
686 HV_FC,
687 HV_NIC,
688 HV_ND,
689 HV_PCIE,
690 HV_FB,
691 HV_KBD,
692 HV_MOUSE,
693 HV_KVP,
694 HV_TS,
695 HV_HB,
696 HV_SHUTDOWN,
697 HV_FCOPY,
698 HV_BACKUP,
699 HV_DM,
f45be72c 700 HV_UNKNOWN,
7047f17d
S
701};
702
703struct vmbus_device {
704 u16 dev_type;
705 uuid_le guid;
706 bool perf_device;
707};
708
7d7c75cd
S
709struct vmbus_channel {
710 struct list_head listentry;
711
712 struct hv_device *device_obj;
713
7d7c75cd 714 enum vmbus_channel_state state;
7d7c75cd
S
715
716 struct vmbus_channel_offer_channel offermsg;
717 /*
718 * These are based on the OfferMsg.MonitorId.
719 * Save it here for easy access.
720 */
721 u8 monitor_grp;
722 u8 monitor_bit;
723
c3582a2c
HZ
724 bool rescind; /* got rescind msg */
725
7d7c75cd
S
726 u32 ringbuffer_gpadlhandle;
727
728 /* Allocated memory for ring buffer */
729 void *ringbuffer_pages;
730 u32 ringbuffer_pagecount;
731 struct hv_ring_buffer_info outbound; /* send to parent */
732 struct hv_ring_buffer_info inbound; /* receive from parent */
7d7c75cd 733
f9f1db83
S
734 struct vmbus_close_msg close_msg;
735
51c6ce2a 736 /* Channel callback's invoked in softirq context */
631e63a9 737 struct tasklet_struct callback_event;
7d7c75cd
S
738 void (*onchannel_callback)(void *context);
739 void *channel_callback_context;
132368bd
S
740
741 /*
b71e3282
SH
742 * A channel can be marked for one of three modes of reading:
743 * BATCHED - callback called from taslket and should read
744 * channel until empty. Interrupts from the host
745 * are masked while read is in process (default).
746 * DIRECT - callback called from tasklet (softirq).
747 * ISR - callback called in interrupt context and must
748 * invoke its own deferred processing.
749 * Host interrupts are disabled and must be re-enabled
750 * when ring is empty.
132368bd 751 */
b71e3282
SH
752 enum hv_callback_mode {
753 HV_CALL_BATCHED,
754 HV_CALL_DIRECT,
755 HV_CALL_ISR
756 } callback_mode;
b3bf60c7
S
757
758 bool is_dedicated_interrupt;
759 struct hv_input_signal_event_buffer sig_buf;
760 struct hv_input_signal_event *sig_event;
abbf3b2a
S
761
762 /*
763 * Starting with win8, this field will be used to specify
764 * the target virtual processor on which to deliver the interrupt for
765 * the host to guest communication.
766 * Prior to win8, incoming channel interrupts would only
767 * be delivered on cpu 0. Setting this value to 0 would
768 * preserve the earlier behavior.
769 */
770 u32 target_vp;
d3ba720d
S
771 /* The corresponding CPUID in the guest */
772 u32 target_cpu;
1f656ff3
S
773 /*
774 * State to manage the CPU affiliation of channels.
775 */
3b71107d 776 struct cpumask alloced_cpus_in_node;
1f656ff3 777 int numa_node;
e68d2971
S
778 /*
779 * Support for sub-channels. For high performance devices,
780 * it will be useful to have multiple sub-channels to support
781 * a scalable communication infrastructure with the host.
782 * The support for sub-channels is implemented as an extention
783 * to the current infrastructure.
784 * The initial offer is considered the primary channel and this
785 * offer message will indicate if the host supports sub-channels.
786 * The guest is free to ask for sub-channels to be offerred and can
787 * open these sub-channels as a normal "primary" channel. However,
788 * all sub-channels will have the same type and instance guids as the
789 * primary channel. Requests sent on a given channel will result in a
790 * response on the same channel.
791 */
792
793 /*
794 * Sub-channel creation callback. This callback will be called in
795 * process context when a sub-channel offer is received from the host.
796 * The guest can open the sub-channel in the context of this callback.
797 */
798 void (*sc_creation_callback)(struct vmbus_channel *new_sc);
799
499e8401
DC
800 /*
801 * Channel rescind callback. Some channels (the hvsock ones), need to
802 * register a callback which is invoked in vmbus_onoffer_rescind().
803 */
804 void (*chn_rescind_callback)(struct vmbus_channel *channel);
805
67fae053
VK
806 /*
807 * The spinlock to protect the structure. It is being used to protect
808 * test-and-set access to various attributes of the structure as well
809 * as all sc_list operations.
810 */
811 spinlock_t lock;
e68d2971
S
812 /*
813 * All Sub-channels of a primary channel are linked here.
814 */
815 struct list_head sc_list;
fea844a2
VK
816 /*
817 * Current number of sub-channels.
818 */
819 int num_sc;
820 /*
821 * Number of a sub-channel (position within sc_list) which is supposed
822 * to be used as the next outgoing channel.
823 */
824 int next_oc;
e68d2971
S
825 /*
826 * The primary channel this sub-channel belongs to.
827 * This will be NULL for the primary channel.
828 */
829 struct vmbus_channel *primary_channel;
8a7206a8
S
830 /*
831 * Support per-channel state for use by vmbus drivers.
832 */
833 void *per_channel_state;
3a28fa35
S
834 /*
835 * To support per-cpu lookup mapping of relid to channel,
836 * link up channels based on their CPU affinity.
837 */
838 struct list_head percpu_list;
8200f208
SH
839
840 /*
841 * Defer freeing channel until after all cpu's have
842 * gone through grace period.
843 */
844 struct rcu_head rcu;
845
3724287c
S
846 /*
847 * For performance critical channels (storage, networking
848 * etc,), Hyper-V has a mechanism to enhance the throughput
849 * at the expense of latency:
850 * When the host is to be signaled, we just set a bit in a shared page
851 * and this bit will be inspected by the hypervisor within a certain
852 * window and if the bit is set, the host will be signaled. The window
853 * of time is the monitor latency - currently around 100 usecs. This
854 * mechanism improves throughput by:
855 *
856 * A) Making the host more efficient - each time it wakes up,
857 * potentially it will process morev number of packets. The
858 * monitor latency allows a batch to build up.
859 * B) By deferring the hypercall to signal, we will also minimize
860 * the interrupts.
861 *
862 * Clearly, these optimizations improve throughput at the expense of
863 * latency. Furthermore, since the channel is shared for both
864 * control and data messages, control messages currently suffer
865 * unnecessary latency adversley impacting performance and boot
866 * time. To fix this issue, permit tagging the channel as being
867 * in "low latency" mode. In this mode, we will bypass the monitor
868 * mechanism.
869 */
870 bool low_latency;
fe760e4d 871
509879bd
S
872 /*
873 * NUMA distribution policy:
874 * We support teo policies:
875 * 1) Balanced: Here all performance critical channels are
876 * distributed evenly amongst all the NUMA nodes.
877 * This policy will be the default policy.
878 * 2) Localized: All channels of a given instance of a
879 * performance critical service will be assigned CPUs
880 * within a selected NUMA node.
881 */
882 enum hv_numa_policy affinity_policy;
883
2c469b1f
S
884 bool probe_done;
885
7d7c75cd 886};
b56dda06 887
e8d6ca02
DC
888static inline bool is_hvsock_channel(const struct vmbus_channel *c)
889{
890 return !!(c->offermsg.offer.chn_flags &
891 VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER);
892}
893
509879bd
S
894static inline void set_channel_affinity_state(struct vmbus_channel *c,
895 enum hv_numa_policy policy)
896{
897 c->affinity_policy = policy;
898}
899
b71e3282
SH
900static inline void set_channel_read_mode(struct vmbus_channel *c,
901 enum hv_callback_mode mode)
132368bd 902{
b71e3282 903 c->callback_mode = mode;
132368bd
S
904}
905
8a7206a8
S
906static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
907{
908 c->per_channel_state = s;
909}
910
911static inline void *get_per_channel_state(struct vmbus_channel *c)
912{
913 return c->per_channel_state;
914}
915
3c75354d
DC
916static inline void set_channel_pending_send_size(struct vmbus_channel *c,
917 u32 size)
918{
919 c->outbound.ring_buffer->pending_send_sz = size;
920}
921
3724287c
S
922static inline void set_low_latency_mode(struct vmbus_channel *c)
923{
924 c->low_latency = true;
925}
926
927static inline void clear_low_latency_mode(struct vmbus_channel *c)
928{
929 c->low_latency = false;
930}
931
b56dda06
S
932void vmbus_onmessage(void *context);
933
934int vmbus_request_offers(void);
935
e68d2971
S
936/*
937 * APIs for managing sub-channels.
938 */
939
940void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
941 void (*sc_cr_cb)(struct vmbus_channel *new_sc));
942
499e8401
DC
943void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
944 void (*chn_rescind_cb)(struct vmbus_channel *));
945
e68d2971
S
946/*
947 * Retrieve the (sub) channel on which to send an outgoing request.
948 * When a primary channel has multiple sub-channels, we choose a
949 * channel whose VCPU binding is closest to the VCPU on which
950 * this call is being made.
951 */
952struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
953
954/*
955 * Check if sub-channels have already been offerred. This API will be useful
956 * when the driver is unloaded after establishing sub-channels. In this case,
957 * when the driver is re-loaded, the driver would have to check if the
958 * subchannels have already been established before attempting to request
959 * the creation of sub-channels.
960 * This function returns TRUE to indicate that subchannels have already been
961 * created.
962 * This function should be invoked after setting the callback function for
963 * sub-channel creation.
964 */
965bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
966
c35470b2
S
967/* The format must be the same as struct vmdata_gpa_direct */
968struct vmbus_channel_packet_page_buffer {
969 u16 type;
970 u16 dataoffset8;
971 u16 length8;
972 u16 flags;
973 u64 transactionid;
974 u32 reserved;
975 u32 rangecount;
976 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
977} __packed;
978
979/* The format must be the same as struct vmdata_gpa_direct */
980struct vmbus_channel_packet_multipage_buffer {
981 u16 type;
982 u16 dataoffset8;
983 u16 length8;
984 u16 flags;
985 u64 transactionid;
986 u32 reserved;
987 u32 rangecount; /* Always 1 in this case */
988 struct hv_multipage_buffer range;
989} __packed;
990
d61031ee
S
991/* The format must be the same as struct vmdata_gpa_direct */
992struct vmbus_packet_mpb_array {
993 u16 type;
994 u16 dataoffset8;
995 u16 length8;
996 u16 flags;
997 u64 transactionid;
998 u32 reserved;
999 u32 rangecount; /* Always 1 in this case */
1000 struct hv_mpb_array range;
1001} __packed;
1002
c35470b2
S
1003
1004extern int vmbus_open(struct vmbus_channel *channel,
1005 u32 send_ringbuffersize,
1006 u32 recv_ringbuffersize,
1007 void *userdata,
1008 u32 userdatalen,
2a9d7de2 1009 void (*onchannel_callback)(void *context),
c35470b2
S
1010 void *context);
1011
1012extern void vmbus_close(struct vmbus_channel *channel);
1013
1014extern int vmbus_sendpacket(struct vmbus_channel *channel,
011a7c3c 1015 void *buffer,
c35470b2
S
1016 u32 bufferLen,
1017 u64 requestid,
1018 enum vmbus_packet_type type,
1019 u32 flags);
1020
e9395e3f
S
1021extern int vmbus_sendpacket_ctl(struct vmbus_channel *channel,
1022 void *buffer,
1023 u32 bufferLen,
1024 u64 requestid,
1025 enum vmbus_packet_type type,
3454323c 1026 u32 flags);
e9395e3f 1027
c35470b2
S
1028extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
1029 struct hv_page_buffer pagebuffers[],
1030 u32 pagecount,
1031 void *buffer,
1032 u32 bufferlen,
1033 u64 requestid);
1034
87e93d61
S
1035extern int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel,
1036 struct hv_page_buffer pagebuffers[],
1037 u32 pagecount,
1038 void *buffer,
1039 u32 bufferlen,
1040 u64 requestid,
3454323c 1041 u32 flags);
87e93d61 1042
c35470b2
S
1043extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
1044 struct hv_multipage_buffer *mpb,
1045 void *buffer,
1046 u32 bufferlen,
1047 u64 requestid);
1048
d61031ee
S
1049extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
1050 struct vmbus_packet_mpb_array *mpb,
1051 u32 desc_size,
1052 void *buffer,
1053 u32 bufferlen,
1054 u64 requestid);
1055
c35470b2
S
1056extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
1057 void *kbuffer,
1058 u32 size,
1059 u32 *gpadl_handle);
1060
1061extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
1062 u32 gpadl_handle);
1063
1064extern int vmbus_recvpacket(struct vmbus_channel *channel,
1065 void *buffer,
1066 u32 bufferlen,
1067 u32 *buffer_actual_len,
1068 u64 *requestid);
1069
1070extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
1071 void *buffer,
1072 u32 bufferlen,
1073 u32 *buffer_actual_len,
1074 u64 *requestid);
1075
c35470b2 1076
c35470b2
S
1077extern void vmbus_ontimer(unsigned long data);
1078
35ea09c3
S
1079/* Base driver object */
1080struct hv_driver {
1081 const char *name;
1082
8981da32
DC
1083 /*
1084 * A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER
1085 * channel flag, actually doesn't mean a synthetic device because the
1086 * offer's if_type/if_instance can change for every new hvsock
1087 * connection.
1088 *
1089 * However, to facilitate the notification of new-offer/rescind-offer
1090 * from vmbus driver to hvsock driver, we can handle hvsock offer as
1091 * a special vmbus device, and hence we need the below flag to
1092 * indicate if the driver is the hvsock driver or not: we need to
1093 * specially treat the hvosck offer & driver in vmbus_match().
1094 */
1095 bool hvsock;
1096
35ea09c3 1097 /* the device type supported by this driver */
358d2ee2 1098 uuid_le dev_type;
2e2c1d17 1099 const struct hv_vmbus_device_id *id_table;
35ea09c3
S
1100
1101 struct device_driver driver;
1102
fc76936d
SH
1103 /* dynamic device GUID's */
1104 struct {
1105 spinlock_t lock;
1106 struct list_head list;
1107 } dynids;
1108
84946899 1109 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
35ea09c3
S
1110 int (*remove)(struct hv_device *);
1111 void (*shutdown)(struct hv_device *);
1112
1113};
1114
1115/* Base device object */
1116struct hv_device {
1117 /* the device type id of this device */
358d2ee2 1118 uuid_le dev_type;
35ea09c3
S
1119
1120 /* the device instance id of this device */
358d2ee2 1121 uuid_le dev_instance;
7047f17d
S
1122 u16 vendor_id;
1123 u16 device_id;
35ea09c3
S
1124
1125 struct device device;
1126
1127 struct vmbus_channel *channel;
35ea09c3
S
1128};
1129
27b5b3ca
S
1130
1131static inline struct hv_device *device_to_hv_device(struct device *d)
1132{
1133 return container_of(d, struct hv_device, device);
1134}
1135
1136static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1137{
1138 return container_of(d, struct hv_driver, driver);
1139}
1140
ab101e86
S
1141static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1142{
1143 dev_set_drvdata(&dev->device, data);
1144}
1145
1146static inline void *hv_get_drvdata(struct hv_device *dev)
1147{
1148 return dev_get_drvdata(&dev->device);
1149}
27b5b3ca 1150
4827ee1d
SH
1151struct hv_ring_buffer_debug_info {
1152 u32 current_interrupt_mask;
1153 u32 current_read_index;
1154 u32 current_write_index;
1155 u32 bytes_avail_toread;
1156 u32 bytes_avail_towrite;
1157};
1158
1159void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
1160 struct hv_ring_buffer_debug_info *debug_info);
1161
27b5b3ca 1162/* Vmbus interface */
768fa219
GKH
1163#define vmbus_driver_register(driver) \
1164 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1165int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1166 struct module *owner,
1167 const char *mod_name);
1168void vmbus_driver_unregister(struct hv_driver *hv_driver);
27b5b3ca 1169
85d9aa70
DC
1170void vmbus_hvsock_device_unregister(struct vmbus_channel *channel);
1171
35464483
JO
1172int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
1173 resource_size_t min, resource_size_t max,
1174 resource_size_t size, resource_size_t align,
1175 bool fb_overlap_ok);
97fb77dc 1176void vmbus_free_mmio(resource_size_t start, resource_size_t size);
619848bd 1177int vmbus_cpu_number_to_vp_number(int cpu_number);
a108393d 1178u64 hv_do_hypercall(u64 control, void *input, void *output);
619848bd 1179
7fb96565
S
1180/*
1181 * GUID definitions of various offer types - services offered to the guest.
1182 */
1183
1184/*
1185 * Network GUID
1186 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1187 */
1188#define HV_NIC_GUID \
af3ff643
S
1189 .guid = UUID_LE(0xf8615163, 0xdf3e, 0x46c5, 0x91, 0x3f, \
1190 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e)
7fb96565
S
1191
1192/*
1193 * IDE GUID
1194 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1195 */
1196#define HV_IDE_GUID \
af3ff643
S
1197 .guid = UUID_LE(0x32412632, 0x86cb, 0x44a2, 0x9b, 0x5c, \
1198 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
7fb96565
S
1199
1200/*
1201 * SCSI GUID
1202 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1203 */
1204#define HV_SCSI_GUID \
af3ff643
S
1205 .guid = UUID_LE(0xba6163d9, 0x04a1, 0x4d29, 0xb6, 0x05, \
1206 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
7fb96565
S
1207
1208/*
1209 * Shutdown GUID
1210 * {0e0b6031-5213-4934-818b-38d90ced39db}
1211 */
1212#define HV_SHUTDOWN_GUID \
af3ff643
S
1213 .guid = UUID_LE(0x0e0b6031, 0x5213, 0x4934, 0x81, 0x8b, \
1214 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb)
7fb96565
S
1215
1216/*
1217 * Time Synch GUID
1218 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1219 */
1220#define HV_TS_GUID \
af3ff643
S
1221 .guid = UUID_LE(0x9527e630, 0xd0ae, 0x497b, 0xad, 0xce, \
1222 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf)
7fb96565
S
1223
1224/*
1225 * Heartbeat GUID
1226 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1227 */
1228#define HV_HEART_BEAT_GUID \
af3ff643
S
1229 .guid = UUID_LE(0x57164f39, 0x9115, 0x4e78, 0xab, 0x55, \
1230 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d)
7fb96565
S
1231
1232/*
1233 * KVP GUID
1234 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1235 */
1236#define HV_KVP_GUID \
af3ff643
S
1237 .guid = UUID_LE(0xa9a0f4e7, 0x5a45, 0x4d96, 0xb8, 0x27, \
1238 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6)
7fb96565
S
1239
1240/*
1241 * Dynamic memory GUID
1242 * {525074dc-8985-46e2-8057-a307dc18a502}
1243 */
1244#define HV_DM_GUID \
af3ff643
S
1245 .guid = UUID_LE(0x525074dc, 0x8985, 0x46e2, 0x80, 0x57, \
1246 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02)
7fb96565
S
1247
1248/*
1249 * Mouse GUID
1250 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1251 */
1252#define HV_MOUSE_GUID \
af3ff643
S
1253 .guid = UUID_LE(0xcfa8b69e, 0x5b4a, 0x4cc0, 0xb9, 0x8b, \
1254 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a)
7fb96565 1255
2048157a
DC
1256/*
1257 * Keyboard GUID
1258 * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
1259 */
1260#define HV_KBD_GUID \
1261 .guid = UUID_LE(0xf912ad6d, 0x2b17, 0x48ea, 0xbd, 0x65, \
1262 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84)
1263
96dd86fa
S
1264/*
1265 * VSS (Backup/Restore) GUID
1266 */
1267#define HV_VSS_GUID \
af3ff643
S
1268 .guid = UUID_LE(0x35fa2e29, 0xea23, 0x4236, 0x96, 0xae, \
1269 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40)
68a2d20b
HZ
1270/*
1271 * Synthetic Video GUID
1272 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1273 */
1274#define HV_SYNTHVID_GUID \
af3ff643
S
1275 .guid = UUID_LE(0xda0a7802, 0xe377, 0x4aac, 0x8e, 0x77, \
1276 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8)
68a2d20b 1277
98b80d89
S
1278/*
1279 * Synthetic FC GUID
1280 * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
1281 */
1282#define HV_SYNTHFC_GUID \
af3ff643
S
1283 .guid = UUID_LE(0x2f9bcc4a, 0x0069, 0x4af3, 0xb7, 0x6b, \
1284 0x6f, 0xd0, 0xbe, 0x52, 0x8c, 0xda)
98b80d89 1285
01325476
S
1286/*
1287 * Guest File Copy Service
1288 * {34D14BE3-DEE4-41c8-9AE7-6B174977C192}
1289 */
1290
1291#define HV_FCOPY_GUID \
af3ff643
S
1292 .guid = UUID_LE(0x34d14be3, 0xdee4, 0x41c8, 0x9a, 0xe7, \
1293 0x6b, 0x17, 0x49, 0x77, 0xc1, 0x92)
01325476 1294
04653a00
S
1295/*
1296 * NetworkDirect. This is the guest RDMA service.
1297 * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}
1298 */
1299#define HV_ND_GUID \
af3ff643
S
1300 .guid = UUID_LE(0x8c2eaf3d, 0x32a7, 0x4b09, 0xab, 0x99, \
1301 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01)
04653a00 1302
3053c762
JO
1303/*
1304 * PCI Express Pass Through
1305 * {44C4F61D-4444-4400-9D52-802E27EDE19F}
1306 */
1307
1308#define HV_PCIE_GUID \
af3ff643
S
1309 .guid = UUID_LE(0x44c4f61d, 0x4444, 0x4400, 0x9d, 0x52, \
1310 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f)
3053c762 1311
0f98829a
DC
1312/*
1313 * Linux doesn't support the 3 devices: the first two are for
1314 * Automatic Virtual Machine Activation, and the third is for
1315 * Remote Desktop Virtualization.
1316 * {f8e65716-3cb3-4a06-9a60-1889c5cccab5}
1317 * {3375baf4-9e15-4b30-b765-67acb10d607b}
1318 * {276aacf4-ac15-426c-98dd-7521ad3f01fe}
1319 */
1320
1321#define HV_AVMA1_GUID \
1322 .guid = UUID_LE(0xf8e65716, 0x3cb3, 0x4a06, 0x9a, 0x60, \
1323 0x18, 0x89, 0xc5, 0xcc, 0xca, 0xb5)
1324
1325#define HV_AVMA2_GUID \
1326 .guid = UUID_LE(0x3375baf4, 0x9e15, 0x4b30, 0xb7, 0x65, \
1327 0x67, 0xac, 0xb1, 0x0d, 0x60, 0x7b)
1328
1329#define HV_RDV_GUID \
1330 .guid = UUID_LE(0x276aacf4, 0xac15, 0x426c, 0x98, 0xdd, \
1331 0x75, 0x21, 0xad, 0x3f, 0x01, 0xfe)
1332
b189702d
S
1333/*
1334 * Common header for Hyper-V ICs
1335 */
1336
1337#define ICMSGTYPE_NEGOTIATE 0
1338#define ICMSGTYPE_HEARTBEAT 1
1339#define ICMSGTYPE_KVPEXCHANGE 2
1340#define ICMSGTYPE_SHUTDOWN 3
1341#define ICMSGTYPE_TIMESYNC 4
1342#define ICMSGTYPE_VSS 5
1343
1344#define ICMSGHDRFLAG_TRANSACTION 1
1345#define ICMSGHDRFLAG_REQUEST 2
1346#define ICMSGHDRFLAG_RESPONSE 4
1347
b189702d 1348
a29b643c
S
1349/*
1350 * While we want to handle util services as regular devices,
1351 * there is only one instance of each of these services; so
1352 * we statically allocate the service specific state.
1353 */
1354
1355struct hv_util_service {
1356 u8 *recv_buffer;
b9830d12 1357 void *channel;
a29b643c
S
1358 void (*util_cb)(void *);
1359 int (*util_init)(struct hv_util_service *);
1360 void (*util_deinit)(void);
1361};
1362
b189702d
S
1363struct vmbuspipe_hdr {
1364 u32 flags;
1365 u32 msgsize;
1366} __packed;
1367
1368struct ic_version {
1369 u16 major;
1370 u16 minor;
1371} __packed;
1372
1373struct icmsg_hdr {
1374 struct ic_version icverframe;
1375 u16 icmsgtype;
1376 struct ic_version icvermsg;
1377 u16 icmsgsize;
1378 u32 status;
1379 u8 ictransaction_id;
1380 u8 icflags;
1381 u8 reserved[2];
1382} __packed;
1383
1384struct icmsg_negotiate {
1385 u16 icframe_vercnt;
1386 u16 icmsg_vercnt;
1387 u32 reserved;
1388 struct ic_version icversion_data[1]; /* any size array */
1389} __packed;
1390
1391struct shutdown_msg_data {
1392 u32 reason_code;
1393 u32 timeout_seconds;
1394 u32 flags;
1395 u8 display_message[2048];
1396} __packed;
1397
1398struct heartbeat_msg_data {
1399 u64 seq_num;
1400 u32 reserved[8];
1401} __packed;
1402
1403/* Time Sync IC defs */
1404#define ICTIMESYNCFLAG_PROBE 0
1405#define ICTIMESYNCFLAG_SYNC 1
1406#define ICTIMESYNCFLAG_SAMPLE 2
1407
1408#ifdef __x86_64__
1409#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1410#else
1411#define WLTIMEDELTA 116444736000000000LL
1412#endif
1413
1414struct ictimesync_data {
1415 u64 parenttime;
1416 u64 childtime;
1417 u64 roundtriptime;
1418 u8 flags;
1419} __packed;
1420
8e1d2607
AN
1421struct ictimesync_ref_data {
1422 u64 parenttime;
1423 u64 vmreferencetime;
1424 u8 flags;
1425 char leapflags;
1426 char stratum;
1427 u8 reserved[3];
1428} __packed;
1429
b189702d
S
1430struct hyperv_service_callback {
1431 u8 msg_type;
1432 char *log_msg;
358d2ee2 1433 uuid_le data;
b189702d 1434 struct vmbus_channel *channel;
2a9d7de2 1435 void (*callback)(void *context);
b189702d
S
1436};
1437
c836d0ab 1438#define MAX_SRV_VER 0x7ffffff
a1656454
AN
1439extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf,
1440 const int *fw_version, int fw_vercnt,
1441 const int *srv_version, int srv_vercnt,
1442 int *nego_fw_version, int *nego_srv_version);
b189702d 1443
a92ebc9e 1444void hv_process_channel_removal(u32 relid);
96dd86fa 1445
1f6ee4e7 1446void vmbus_setevent(struct vmbus_channel *channel);
37f7278b
S
1447/*
1448 * Negotiated version with the Host.
1449 */
1450
1451extern __u32 vmbus_proto_version;
1452
5c23a1a5
DC
1453int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
1454 const uuid_le *shv_host_servie_id);
5cc47247 1455void vmbus_set_event(struct vmbus_channel *channel);
687f32e6
S
1456
1457/* Get the start of the ring buffer. */
1458static inline void *
e4165a0f 1459hv_get_ring_buffer(const struct hv_ring_buffer_info *ring_info)
687f32e6 1460{
e4165a0f 1461 return ring_info->ring_buffer->buffer;
687f32e6
S
1462}
1463
6e47dd3e
SH
1464/*
1465 * Mask off host interrupt callback notifications
1466 */
1467static inline void hv_begin_read(struct hv_ring_buffer_info *rbi)
1468{
1469 rbi->ring_buffer->interrupt_mask = 1;
1470
1471 /* make sure mask update is not reordered */
1472 virt_mb();
1473}
1474
1475/*
1476 * Re-enable host callback and return number of outstanding bytes
1477 */
1478static inline u32 hv_end_read(struct hv_ring_buffer_info *rbi)
1479{
1480
1481 rbi->ring_buffer->interrupt_mask = 0;
1482
1483 /* make sure mask update is not reordered */
1484 virt_mb();
1485
1486 /*
1487 * Now check to see if the ring buffer is still empty.
1488 * If it is not, we raced and we need to process new
1489 * incoming messages.
1490 */
1491 return hv_get_bytes_to_read(rbi);
1492}
1493
ab028db4
S
1494/*
1495 * An API to support in-place processing of incoming VMBUS packets.
1496 */
ab028db4 1497
f3dd3f47 1498/* Get data payload associated with descriptor */
1499static inline void *hv_pkt_data(const struct vmpacket_descriptor *desc)
ab028db4 1500{
f3dd3f47 1501 return (void *)((unsigned long)desc + (desc->offset8 << 3));
ab028db4
S
1502}
1503
f3dd3f47 1504/* Get data size associated with descriptor */
1505static inline u32 hv_pkt_datalen(const struct vmpacket_descriptor *desc)
ab028db4 1506{
f3dd3f47 1507 return (desc->len8 << 3) - (desc->offset8 << 3);
ab028db4
S
1508}
1509
f3dd3f47 1510
1511struct vmpacket_descriptor *
1512hv_pkt_iter_first(struct vmbus_channel *channel);
1513
1514struct vmpacket_descriptor *
1515__hv_pkt_iter_next(struct vmbus_channel *channel,
1516 const struct vmpacket_descriptor *pkt);
1517
1518void hv_pkt_iter_close(struct vmbus_channel *channel);
1519
ab028db4 1520/*
f3dd3f47 1521 * Get next packet descriptor from iterator
1522 * If at end of list, return NULL and update host.
ab028db4 1523 */
f3dd3f47 1524static inline struct vmpacket_descriptor *
1525hv_pkt_iter_next(struct vmbus_channel *channel,
1526 const struct vmpacket_descriptor *pkt)
ab028db4 1527{
f3dd3f47 1528 struct vmpacket_descriptor *nxt;
1529
1530 nxt = __hv_pkt_iter_next(channel, pkt);
1531 if (!nxt)
1532 hv_pkt_iter_close(channel);
ab028db4 1533
f3dd3f47 1534 return nxt;
ab028db4
S
1535}
1536
f3dd3f47 1537#define foreach_vmbus_pkt(pkt, channel) \
1538 for (pkt = hv_pkt_iter_first(channel); pkt; \
1539 pkt = hv_pkt_iter_next(channel, pkt))
ab028db4 1540
3f335ea2 1541#endif /* _HYPERV_H */