blob: 49949079cf47d0e0ac29f727f59fbb23a011b9f7 [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. Srinivasan29394372012-01-27 15:55:58 -080028#include <linux/types.h>
29
K. Y. Srinivasan67413352013-07-02 10:31:30 -070030/*
31 * Framework version for util services.
32 */
33
34#define UTIL_FW_MAJOR 3
35#define UTIL_FW_MINOR 0
36#define UTIL_FW_MAJOR_MINOR (UTIL_FW_MAJOR << 16 | UTIL_FW_MINOR)
37
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -070038
39/*
40 * Implementation of host controlled snapshot of the guest.
41 */
42
43#define VSS_OP_REGISTER 128
44
45enum hv_vss_op {
46 VSS_OP_CREATE = 0,
47 VSS_OP_DELETE,
48 VSS_OP_HOT_BACKUP,
49 VSS_OP_GET_DM_INFO,
50 VSS_OP_BU_COMPLETE,
51 /*
52 * Following operations are only supported with IC version >= 5.0
53 */
54 VSS_OP_FREEZE, /* Freeze the file systems in the VM */
55 VSS_OP_THAW, /* Unfreeze the file systems */
56 VSS_OP_AUTO_RECOVER,
57 VSS_OP_COUNT /* Number of operations, must be last */
58};
59
60
61/*
62 * Header for all VSS messages.
63 */
64struct hv_vss_hdr {
65 __u8 operation;
66 __u8 reserved[7];
67} __attribute__((packed));
68
69
70/*
71 * Flag values for the hv_vss_check_feature. Linux supports only
72 * one value.
73 */
74#define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
75
76struct hv_vss_check_feature {
77 __u32 flags;
78} __attribute__((packed));
79
80struct hv_vss_check_dm_info {
81 __u32 flags;
82} __attribute__((packed));
83
84struct hv_vss_msg {
85 union {
86 struct hv_vss_hdr vss_hdr;
87 int error;
88 };
89 union {
90 struct hv_vss_check_feature vss_cf;
91 struct hv_vss_check_dm_info dm_info;
92 };
93} __attribute__((packed));
94
K. Y. Srinivasan29394372012-01-27 15:55:58 -080095/*
96 * An implementation of HyperV key value pair (KVP) functionality for Linux.
97 *
98 *
99 * Copyright (C) 2010, Novell, Inc.
100 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
101 *
102 */
103
104/*
105 * Maximum value size - used for both key names and value data, and includes
106 * any applicable NULL terminators.
107 *
108 * Note: This limit is somewhat arbitrary, but falls easily within what is
109 * supported for all native guests (back to Win 2000) and what is reasonable
110 * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
111 * limited to 255 character key names.
112 *
113 * MSDN recommends not storing data values larger than 2048 bytes in the
114 * registry.
115 *
116 * Note: This value is used in defining the KVP exchange message - this value
117 * cannot be modified without affecting the message size and compatibility.
118 */
119
120/*
121 * bytes, including any null terminators
122 */
123#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
124
125
126/*
127 * Maximum key size - the registry limit for the length of an entry name
128 * is 256 characters, including the null terminator
129 */
130
131#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
132
133/*
134 * In Linux, we implement the KVP functionality in two components:
135 * 1) The kernel component which is packaged as part of the hv_utils driver
136 * is responsible for communicating with the host and responsible for
137 * implementing the host/guest protocol. 2) A user level daemon that is
138 * responsible for data gathering.
139 *
140 * Host/Guest Protocol: The host iterates over an index and expects the guest
141 * to assign a key name to the index and also return the value corresponding to
142 * the key. The host will have atmost one KVP transaction outstanding at any
143 * given point in time. The host side iteration stops when the guest returns
144 * an error. Microsoft has specified the following mapping of key names to
145 * host specified index:
146 *
147 * Index Key Name
148 * 0 FullyQualifiedDomainName
149 * 1 IntegrationServicesVersion
150 * 2 NetworkAddressIPv4
151 * 3 NetworkAddressIPv6
152 * 4 OSBuildNumber
153 * 5 OSName
154 * 6 OSMajorVersion
155 * 7 OSMinorVersion
156 * 8 OSVersion
157 * 9 ProcessorArchitecture
158 *
159 * The Windows host expects the Key Name and Key Value to be encoded in utf16.
160 *
161 * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
162 * data gathering functionality in a user mode daemon. The user level daemon
163 * is also responsible for binding the key name to the index as well. The
164 * kernel and user-level daemon communicate using a connector channel.
165 *
166 * The user mode component first registers with the
167 * the kernel component. Subsequently, the kernel component requests, data
168 * for the specified keys. In response to this message the user mode component
169 * fills in the value corresponding to the specified key. We overload the
170 * sequence field in the cn_msg header to define our KVP message types.
171 *
172 *
173 * The kernel component simply acts as a conduit for communication between the
174 * Windows host and the user-level daemon. The kernel component passes up the
175 * index received from the Host to the user-level daemon. If the index is
176 * valid (supported), the corresponding key as well as its
177 * value (both are strings) is returned. If the index is invalid
178 * (not supported), a NULL key string is returned.
179 */
180
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800181
182/*
183 * Registry value types.
184 */
185
186#define REG_SZ 1
K. Y. Srinivasanfa3d5b82012-03-16 08:02:25 -0700187#define REG_U32 4
188#define REG_U64 8
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800189
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700190/*
191 * As we look at expanding the KVP functionality to include
192 * IP injection functionality, we need to maintain binary
193 * compatibility with older daemons.
194 *
195 * The KVP opcodes are defined by the host and it was unfortunate
196 * that I chose to treat the registration operation as part of the
197 * KVP operations defined by the host.
198 * Here is the level of compatibility
199 * (between the user level daemon and the kernel KVP driver) that we
200 * will implement:
201 *
202 * An older daemon will always be supported on a newer driver.
203 * A given user level daemon will require a minimal version of the
204 * kernel driver.
205 * If we cannot handle the version differences, we will fail gracefully
206 * (this can happen when we have a user level daemon that is more
207 * advanced than the KVP driver.
208 *
209 * We will use values used in this handshake for determining if we have
210 * workable user level daemon and the kernel driver. We begin by taking the
211 * registration opcode out of the KVP opcode namespace. We will however,
212 * maintain compatibility with the existing user-level daemon code.
213 */
214
215/*
216 * Daemon code not supporting IP injection (legacy daemon).
217 */
218
219#define KVP_OP_REGISTER 4
220
221/*
222 * Daemon code supporting IP injection.
223 * The KVP opcode field is used to communicate the
224 * registration information; so define a namespace that
225 * will be distinct from the host defined KVP opcode.
226 */
227
228#define KVP_OP_REGISTER1 100
229
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800230enum hv_kvp_exchg_op {
231 KVP_OP_GET = 0,
232 KVP_OP_SET,
233 KVP_OP_DELETE,
234 KVP_OP_ENUMERATE,
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700235 KVP_OP_GET_IP_INFO,
236 KVP_OP_SET_IP_INFO,
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800237 KVP_OP_COUNT /* Number of operations, must be last. */
238};
239
240enum hv_kvp_exchg_pool {
241 KVP_POOL_EXTERNAL = 0,
242 KVP_POOL_GUEST,
243 KVP_POOL_AUTO,
244 KVP_POOL_AUTO_EXTERNAL,
245 KVP_POOL_AUTO_INTERNAL,
246 KVP_POOL_COUNT /* Number of pools, must be last. */
247};
248
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700249/*
250 * Some Hyper-V status codes.
251 */
252
253#define HV_S_OK 0x00000000
254#define HV_E_FAIL 0x80004005
255#define HV_S_CONT 0x80070103
256#define HV_ERROR_NOT_SUPPORTED 0x80070032
257#define HV_ERROR_MACHINE_LOCKED 0x800704F7
258#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
K. Y. Srinivasan32061b42012-09-05 13:50:13 -0700259#define HV_INVALIDARG 0x80070057
260#define HV_GUID_NOTFOUND 0x80041002
K. Y. Srinivasanb47a81d2012-08-13 10:06:52 -0700261
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700262#define ADDR_FAMILY_NONE 0x00
263#define ADDR_FAMILY_IPV4 0x01
264#define ADDR_FAMILY_IPV6 0x02
265
266#define MAX_ADAPTER_ID_SIZE 128
267#define MAX_IP_ADDR_SIZE 1024
268#define MAX_GATEWAY_SIZE 512
269
270
271struct hv_kvp_ipaddr_value {
272 __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
273 __u8 addr_family;
274 __u8 dhcp_enabled;
275 __u16 ip_addr[MAX_IP_ADDR_SIZE];
276 __u16 sub_net[MAX_IP_ADDR_SIZE];
277 __u16 gate_way[MAX_GATEWAY_SIZE];
278 __u16 dns_addr[MAX_IP_ADDR_SIZE];
279} __attribute__((packed));
280
281
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800282struct hv_kvp_hdr {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800283 __u8 operation;
284 __u8 pool;
285 __u16 pad;
286} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800287
288struct hv_kvp_exchg_msg_value {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800289 __u32 value_type;
290 __u32 key_size;
291 __u32 value_size;
292 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800293 union {
294 __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
295 __u32 value_u32;
296 __u64 value_u64;
297 };
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800298} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800299
300struct hv_kvp_msg_enumerate {
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800301 __u32 index;
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800302 struct hv_kvp_exchg_msg_value data;
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800303} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800304
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800305struct hv_kvp_msg_get {
306 struct hv_kvp_exchg_msg_value data;
307};
308
309struct hv_kvp_msg_set {
310 struct hv_kvp_exchg_msg_value data;
311};
312
313struct hv_kvp_msg_delete {
314 __u32 key_size;
315 __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
316};
317
318struct hv_kvp_register {
319 __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
320};
321
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800322struct hv_kvp_msg {
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700323 union {
324 struct hv_kvp_hdr kvp_hdr;
325 int error;
326 };
K. Y. Srinivasan26403352012-02-02 16:56:50 -0800327 union {
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800328 struct hv_kvp_msg_get kvp_get;
329 struct hv_kvp_msg_set kvp_set;
330 struct hv_kvp_msg_delete kvp_delete;
331 struct hv_kvp_msg_enumerate kvp_enum_data;
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700332 struct hv_kvp_ipaddr_value kvp_ip_val;
K. Y. Srinivasane485ceac2012-03-10 15:32:08 -0800333 struct hv_kvp_register kvp_register;
K. Y. Srinivasan26403352012-02-02 16:56:50 -0800334 } body;
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800335} __attribute__((packed));
K. Y. Srinivasan29394372012-01-27 15:55:58 -0800336
K. Y. Srinivasan9b595782012-08-13 10:06:51 -0700337struct hv_kvp_ip_msg {
338 __u8 operation;
339 __u8 pool;
340 struct hv_kvp_ipaddr_value kvp_ip_val;
341} __attribute__((packed));
342
K. Y. Srinivasan59a084a2012-02-02 16:56:48 -0800343#ifdef __KERNEL__
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700344#include <linux/scatterlist.h>
345#include <linux/list.h>
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700346#include <linux/uuid.h>
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700347#include <linux/timer.h>
348#include <linux/workqueue.h>
349#include <linux/completion.h>
350#include <linux/device.h>
K. Y. Srinivasan2e2c1d12011-08-25 09:48:31 -0700351#include <linux/mod_devicetable.h>
K. Y. Srinivasan8ff3e6f2011-05-12 19:34:27 -0700352
353
Haiyang Zhangc31c1512012-02-02 07:18:00 +0000354#define MAX_PAGE_BUFFER_COUNT 19
K. Y. Srinivasana363bf72011-05-12 19:34:16 -0700355#define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
356
357#pragma pack(push, 1)
358
359/* Single-page buffer */
360struct hv_page_buffer {
361 u32 len;
362 u32 offset;
363 u64 pfn;
364};
365
366/* Multiple-page buffer */
367struct hv_multipage_buffer {
368 /* Length and Offset determines the # of pfns in the array */
369 u32 len;
370 u32 offset;
371 u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
372};
373
374/* 0x18 includes the proprietary packet header */
375#define MAX_PAGE_BUFFER_PACKET (0x18 + \
376 (sizeof(struct hv_page_buffer) * \
377 MAX_PAGE_BUFFER_COUNT))
378#define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
379 sizeof(struct hv_multipage_buffer))
380
381
382#pragma pack(pop)
383
K. Y. Srinivasan7effffb2011-05-12 19:34:17 -0700384struct hv_ring_buffer {
385 /* Offset in bytes from the start of ring data below */
386 u32 write_index;
387
388 /* Offset in bytes from the start of ring data below */
389 u32 read_index;
390
391 u32 interrupt_mask;
392
K. Y. Srinivasan24166032012-12-01 06:46:39 -0800393 /*
394 * Win8 uses some of the reserved bits to implement
395 * interrupt driven flow management. On the send side
396 * we can request that the receiver interrupt the sender
397 * when the ring transitions from being full to being able
398 * to handle a message of size "pending_send_sz".
399 *
400 * Add necessary state for this enhancement.
K. Y. Srinivasan7effffb2011-05-12 19:34:17 -0700401 */
K. Y. Srinivasan24166032012-12-01 06:46:39 -0800402 u32 pending_send_sz;
403
404 u32 reserved1[12];
405
406 union {
407 struct {
408 u32 feat_pending_send_sz:1;
409 };
410 u32 value;
411 } feature_bits;
412
413 /* Pad it to PAGE_SIZE so that data starts on page boundary */
414 u8 reserved2[4028];
K. Y. Srinivasan7effffb2011-05-12 19:34:17 -0700415
416 /*
417 * Ring data starts here + RingDataStartOffset
418 * !!! DO NOT place any fields below this !!!
419 */
420 u8 buffer[0];
421} __packed;
422
423struct hv_ring_buffer_info {
424 struct hv_ring_buffer *ring_buffer;
425 u32 ring_size; /* Include the shared header */
426 spinlock_t ring_lock;
427
428 u32 ring_datasize; /* < ring_size */
429 u32 ring_data_startoffset;
430};
431
432struct hv_ring_buffer_debug_info {
433 u32 current_interrupt_mask;
434 u32 current_read_index;
435 u32 current_write_index;
436 u32 bytes_avail_toread;
437 u32 bytes_avail_towrite;
438};
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -0700439
Haiyang Zhang33be96e2012-03-27 13:20:45 +0000440
441/*
442 *
443 * hv_get_ringbuffer_availbytes()
444 *
445 * Get number of bytes available to read and to write to
446 * for the specified ring buffer
447 */
448static inline void
449hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
450 u32 *read, u32 *write)
451{
452 u32 read_loc, write_loc, dsize;
453
454 smp_read_barrier_depends();
455
456 /* Capture the read/write indices before they changed */
457 read_loc = rbi->ring_buffer->read_index;
458 write_loc = rbi->ring_buffer->write_index;
459 dsize = rbi->ring_datasize;
460
461 *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
462 read_loc - write_loc;
463 *read = dsize - *write;
464}
465
466
K. Y. Srinivasanf7c6dfd2011-05-12 19:34:18 -0700467/*
468 * We use the same version numbering for all Hyper-V modules.
469 *
470 * Definition of versioning is as follows;
471 *
472 * Major Number Changes for these scenarios;
473 * 1. When a new version of Windows Hyper-V
474 * is released.
475 * 2. A Major change has occurred in the
476 * Linux IC's.
477 * (For example the merge for the first time
478 * into the kernel) Every time the Major Number
479 * changes, the Revision number is reset to 0.
480 * Minor Number Changes when new functionality is added
481 * to the Linux IC's that is not a bug fix.
482 *
483 * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
484 */
485#define HV_DRV_VERSION "3.1"
486
K. Y. Srinivasaneafa7072012-12-01 06:46:44 -0800487/*
488 * VMBUS version is 32 bit entity broken up into
489 * two 16 bit quantities: major_number. minor_number.
490 *
491 * 0 . 13 (Windows Server 2008)
492 * 1 . 1 (Windows 7)
493 * 2 . 4 (Windows 8)
494 */
495
496#define VERSION_WS2008 ((0 << 16) | (13))
497#define VERSION_WIN7 ((1 << 16) | (1))
498#define VERSION_WIN8 ((2 << 16) | (4))
499
500#define VERSION_INVAL -1
501
K. Y. Srinivasan2a5c43a2012-12-01 06:46:56 -0800502#define VERSION_CURRENT VERSION_WIN8
K. Y. Srinivasanf7c6dfd2011-05-12 19:34:18 -0700503
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700504/* Make maximum size of pipe payload of 16K */
505#define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
506
507/* Define PipeMode values. */
508#define VMBUS_PIPE_TYPE_BYTE 0x00000000
509#define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
510
511/* The size of the user defined data buffer for non-pipe offers. */
512#define MAX_USER_DEFINED_BYTES 120
513
514/* The size of the user defined data buffer for pipe offers. */
515#define MAX_PIPE_USER_DEFINED_BYTES 116
516
517/*
518 * At the center of the Channel Management library is the Channel Offer. This
519 * struct contains the fundamental information about an offer.
520 */
521struct vmbus_channel_offer {
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700522 uuid_le if_type;
523 uuid_le if_instance;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800524
525 /*
526 * These two fields are not currently used.
527 */
528 u64 reserved1;
529 u64 reserved2;
530
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700531 u16 chn_flags;
532 u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
533
534 union {
535 /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
536 struct {
537 unsigned char user_def[MAX_USER_DEFINED_BYTES];
538 } std;
539
540 /*
541 * Pipes:
542 * The following sructure is an integrated pipe protocol, which
543 * is implemented on top of standard user-defined data. Pipe
544 * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
545 * use.
546 */
547 struct {
548 u32 pipe_mode;
549 unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
550 } pipe;
551 } u;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800552 /*
553 * The sub_channel_index is defined in win8.
554 */
555 u16 sub_channel_index;
556 u16 reserved3;
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700557} __packed;
558
559/* Server Flags */
560#define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
561#define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
562#define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
563#define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
564#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
565#define VMBUS_CHANNEL_PARENT_OFFER 0x200
566#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
567
K. Y. Srinivasan50ed40e2011-05-12 19:34:20 -0700568struct vmpacket_descriptor {
569 u16 type;
570 u16 offset8;
571 u16 len8;
572 u16 flags;
573 u64 trans_id;
574} __packed;
575
576struct vmpacket_header {
577 u32 prev_pkt_start_offset;
578 struct vmpacket_descriptor descriptor;
579} __packed;
580
581struct vmtransfer_page_range {
582 u32 byte_count;
583 u32 byte_offset;
584} __packed;
585
586struct vmtransfer_page_packet_header {
587 struct vmpacket_descriptor d;
588 u16 xfer_pageset_id;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700589 u8 sender_owns_set;
K. Y. Srinivasan50ed40e2011-05-12 19:34:20 -0700590 u8 reserved;
591 u32 range_cnt;
592 struct vmtransfer_page_range ranges[1];
593} __packed;
594
595struct vmgpadl_packet_header {
596 struct vmpacket_descriptor d;
597 u32 gpadl;
598 u32 reserved;
599} __packed;
600
601struct vmadd_remove_transfer_page_set {
602 struct vmpacket_descriptor d;
603 u32 gpadl;
604 u16 xfer_pageset_id;
605 u16 reserved;
606} __packed;
607
608/*
609 * This structure defines a range in guest physical space that can be made to
610 * look virtually contiguous.
611 */
612struct gpa_range {
613 u32 byte_count;
614 u32 byte_offset;
615 u64 pfn_array[0];
616};
617
618/*
619 * This is the format for an Establish Gpadl packet, which contains a handle by
620 * which this GPADL will be known and a set of GPA ranges associated with it.
621 * This can be converted to a MDL by the guest OS. If there are multiple GPA
622 * ranges, then the resulting MDL will be "chained," representing multiple VA
623 * ranges.
624 */
625struct vmestablish_gpadl {
626 struct vmpacket_descriptor d;
627 u32 gpadl;
628 u32 range_cnt;
629 struct gpa_range range[1];
630} __packed;
631
632/*
633 * This is the format for a Teardown Gpadl packet, which indicates that the
634 * GPADL handle in the Establish Gpadl packet will never be referenced again.
635 */
636struct vmteardown_gpadl {
637 struct vmpacket_descriptor d;
638 u32 gpadl;
639 u32 reserved; /* for alignment to a 8-byte boundary */
640} __packed;
641
642/*
643 * This is the format for a GPA-Direct packet, which contains a set of GPA
644 * ranges, in addition to commands and/or data.
645 */
646struct vmdata_gpa_direct {
647 struct vmpacket_descriptor d;
648 u32 reserved;
649 u32 range_cnt;
650 struct gpa_range range[1];
651} __packed;
652
653/* This is the format for a Additional Data Packet. */
654struct vmadditional_data {
655 struct vmpacket_descriptor d;
656 u64 total_bytes;
657 u32 offset;
658 u32 byte_cnt;
659 unsigned char data[1];
660} __packed;
661
662union vmpacket_largest_possible_header {
663 struct vmpacket_descriptor simple_hdr;
664 struct vmtransfer_page_packet_header xfer_page_hdr;
665 struct vmgpadl_packet_header gpadl_hdr;
666 struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
667 struct vmestablish_gpadl establish_gpadl_hdr;
668 struct vmteardown_gpadl teardown_gpadl_hdr;
669 struct vmdata_gpa_direct data_gpa_direct_hdr;
670};
671
672#define VMPACKET_DATA_START_ADDRESS(__packet) \
673 (void *)(((unsigned char *)__packet) + \
674 ((struct vmpacket_descriptor)__packet)->offset8 * 8)
675
676#define VMPACKET_DATA_LENGTH(__packet) \
677 ((((struct vmpacket_descriptor)__packet)->len8 - \
678 ((struct vmpacket_descriptor)__packet)->offset8) * 8)
679
680#define VMPACKET_TRANSFER_MODE(__packet) \
681 (((struct IMPACT)__packet)->type)
682
683enum vmbus_packet_type {
684 VM_PKT_INVALID = 0x0,
685 VM_PKT_SYNCH = 0x1,
686 VM_PKT_ADD_XFER_PAGESET = 0x2,
687 VM_PKT_RM_XFER_PAGESET = 0x3,
688 VM_PKT_ESTABLISH_GPADL = 0x4,
689 VM_PKT_TEARDOWN_GPADL = 0x5,
690 VM_PKT_DATA_INBAND = 0x6,
691 VM_PKT_DATA_USING_XFER_PAGES = 0x7,
692 VM_PKT_DATA_USING_GPADL = 0x8,
693 VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
694 VM_PKT_CANCEL_REQUEST = 0xa,
695 VM_PKT_COMP = 0xb,
696 VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
697 VM_PKT_ADDITIONAL_DATA = 0xd
698};
699
700#define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
K. Y. Srinivasan517d8dc2011-05-12 19:34:19 -0700701
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700702
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700703/* Version 1 messages */
704enum vmbus_channel_message_type {
705 CHANNELMSG_INVALID = 0,
706 CHANNELMSG_OFFERCHANNEL = 1,
707 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
708 CHANNELMSG_REQUESTOFFERS = 3,
709 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
710 CHANNELMSG_OPENCHANNEL = 5,
711 CHANNELMSG_OPENCHANNEL_RESULT = 6,
712 CHANNELMSG_CLOSECHANNEL = 7,
713 CHANNELMSG_GPADL_HEADER = 8,
714 CHANNELMSG_GPADL_BODY = 9,
715 CHANNELMSG_GPADL_CREATED = 10,
716 CHANNELMSG_GPADL_TEARDOWN = 11,
717 CHANNELMSG_GPADL_TORNDOWN = 12,
718 CHANNELMSG_RELID_RELEASED = 13,
719 CHANNELMSG_INITIATE_CONTACT = 14,
720 CHANNELMSG_VERSION_RESPONSE = 15,
721 CHANNELMSG_UNLOAD = 16,
722#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
723 CHANNELMSG_VIEWRANGE_ADD = 17,
724 CHANNELMSG_VIEWRANGE_REMOVE = 18,
725#endif
726 CHANNELMSG_COUNT
727};
728
729struct vmbus_channel_message_header {
730 enum vmbus_channel_message_type msgtype;
731 u32 padding;
732} __packed;
733
734/* Query VMBus Version parameters */
735struct vmbus_channel_query_vmbus_version {
736 struct vmbus_channel_message_header header;
737 u32 version;
738} __packed;
739
740/* VMBus Version Supported parameters */
741struct vmbus_channel_version_supported {
742 struct vmbus_channel_message_header header;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700743 u8 version_supported;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700744} __packed;
745
746/* Offer Channel parameters */
747struct vmbus_channel_offer_channel {
748 struct vmbus_channel_message_header header;
749 struct vmbus_channel_offer offer;
750 u32 child_relid;
751 u8 monitorid;
K. Y. Srinivasan29423b72012-12-01 06:46:40 -0800752 /*
753 * win7 and beyond splits this field into a bit field.
754 */
755 u8 monitor_allocated:1;
756 u8 reserved:7;
757 /*
758 * These are new fields added in win7 and later.
759 * Do not access these fields without checking the
760 * negotiated protocol.
761 *
762 * If "is_dedicated_interrupt" is set, we must not set the
763 * associated bit in the channel bitmap while sending the
764 * interrupt to the host.
765 *
766 * connection_id is to be used in signaling the host.
767 */
768 u16 is_dedicated_interrupt:1;
769 u16 reserved1:15;
770 u32 connection_id;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700771} __packed;
772
773/* Rescind Offer parameters */
774struct vmbus_channel_rescind_offer {
775 struct vmbus_channel_message_header header;
776 u32 child_relid;
777} __packed;
778
779/*
780 * Request Offer -- no parameters, SynIC message contains the partition ID
781 * Set Snoop -- no parameters, SynIC message contains the partition ID
782 * Clear Snoop -- no parameters, SynIC message contains the partition ID
783 * All Offers Delivered -- no parameters, SynIC message contains the partition
784 * ID
785 * Flush Client -- no parameters, SynIC message contains the partition ID
786 */
787
788/* Open Channel parameters */
789struct vmbus_channel_open_channel {
790 struct vmbus_channel_message_header header;
791
792 /* Identifies the specific VMBus channel that is being opened. */
793 u32 child_relid;
794
795 /* ID making a particular open request at a channel offer unique. */
796 u32 openid;
797
798 /* GPADL for the channel's ring buffer. */
799 u32 ringbuffer_gpadlhandle;
800
K. Y. Srinivasanabbf3b22012-12-01 06:46:48 -0800801 /*
802 * Starting with win8, this field will be used to specify
803 * the target virtual processor on which to deliver the interrupt for
804 * the host to guest communication.
805 * Prior to win8, incoming channel interrupts would only
806 * be delivered on cpu 0. Setting this value to 0 would
807 * preserve the earlier behavior.
808 */
809 u32 target_vp;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700810
811 /*
812 * The upstream ring buffer begins at offset zero in the memory
813 * described by RingBufferGpadlHandle. The downstream ring buffer
814 * follows it at this offset (in pages).
815 */
816 u32 downstream_ringbuffer_pageoffset;
817
818 /* User-specific data to be passed along to the server endpoint. */
819 unsigned char userdata[MAX_USER_DEFINED_BYTES];
820} __packed;
821
822/* Open Channel Result parameters */
823struct vmbus_channel_open_result {
824 struct vmbus_channel_message_header header;
825 u32 child_relid;
826 u32 openid;
827 u32 status;
828} __packed;
829
830/* Close channel parameters; */
831struct vmbus_channel_close_channel {
832 struct vmbus_channel_message_header header;
833 u32 child_relid;
834} __packed;
835
836/* Channel Message GPADL */
837#define GPADL_TYPE_RING_BUFFER 1
838#define GPADL_TYPE_SERVER_SAVE_AREA 2
839#define GPADL_TYPE_TRANSACTION 8
840
841/*
842 * The number of PFNs in a GPADL message is defined by the number of
843 * pages that would be spanned by ByteCount and ByteOffset. If the
844 * implied number of PFNs won't fit in this packet, there will be a
845 * follow-up packet that contains more.
846 */
847struct vmbus_channel_gpadl_header {
848 struct vmbus_channel_message_header header;
849 u32 child_relid;
850 u32 gpadl;
851 u16 range_buflen;
852 u16 rangecount;
853 struct gpa_range range[0];
854} __packed;
855
856/* This is the followup packet that contains more PFNs. */
857struct vmbus_channel_gpadl_body {
858 struct vmbus_channel_message_header header;
859 u32 msgnumber;
860 u32 gpadl;
861 u64 pfn[0];
862} __packed;
863
864struct vmbus_channel_gpadl_created {
865 struct vmbus_channel_message_header header;
866 u32 child_relid;
867 u32 gpadl;
868 u32 creation_status;
869} __packed;
870
871struct vmbus_channel_gpadl_teardown {
872 struct vmbus_channel_message_header header;
873 u32 child_relid;
874 u32 gpadl;
875} __packed;
876
877struct vmbus_channel_gpadl_torndown {
878 struct vmbus_channel_message_header header;
879 u32 gpadl;
880} __packed;
881
882#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
883struct vmbus_channel_view_range_add {
884 struct vmbus_channel_message_header header;
885 PHYSICAL_ADDRESS viewrange_base;
886 u64 viewrange_length;
887 u32 child_relid;
888} __packed;
889
890struct vmbus_channel_view_range_remove {
891 struct vmbus_channel_message_header header;
892 PHYSICAL_ADDRESS viewrange_base;
893 u32 child_relid;
894} __packed;
895#endif
896
897struct vmbus_channel_relid_released {
898 struct vmbus_channel_message_header header;
899 u32 child_relid;
900} __packed;
901
902struct vmbus_channel_initiate_contact {
903 struct vmbus_channel_message_header header;
904 u32 vmbus_version_requested;
905 u32 padding2;
906 u64 interrupt_page;
907 u64 monitor_page1;
908 u64 monitor_page2;
909} __packed;
910
911struct vmbus_channel_version_response {
912 struct vmbus_channel_message_header header;
K. Y. Srinivasan1508d812012-08-16 08:23:20 -0700913 u8 version_supported;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700914} __packed;
915
916enum vmbus_channel_state {
917 CHANNEL_OFFER_STATE,
918 CHANNEL_OPENING_STATE,
919 CHANNEL_OPEN_STATE,
K. Y. Srinivasane68d2972013-05-23 12:02:32 -0700920 CHANNEL_OPENED_STATE,
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700921};
922
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700923struct vmbus_channel_debug_info {
924 u32 relid;
925 enum vmbus_channel_state state;
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -0700926 uuid_le interfacetype;
927 uuid_le interface_instance;
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -0700928 u32 monitorid;
929 u32 servermonitor_pending;
930 u32 servermonitor_latency;
931 u32 servermonitor_connectionid;
932 u32 clientmonitor_pending;
933 u32 clientmonitor_latency;
934 u32 clientmonitor_connectionid;
935
936 struct hv_ring_buffer_debug_info inbound;
937 struct hv_ring_buffer_debug_info outbound;
938};
939
940/*
941 * Represents each channel msg on the vmbus connection This is a
942 * variable-size data structure depending on the msg type itself
943 */
944struct vmbus_channel_msginfo {
945 /* Bookkeeping stuff */
946 struct list_head msglistentry;
947
948 /* So far, this is only used to handle gpadl body message */
949 struct list_head submsglist;
950
951 /* Synchronize the request/response if needed */
952 struct completion waitevent;
953 union {
954 struct vmbus_channel_version_supported version_supported;
955 struct vmbus_channel_open_result open_result;
956 struct vmbus_channel_gpadl_torndown gpadl_torndown;
957 struct vmbus_channel_gpadl_created gpadl_created;
958 struct vmbus_channel_version_response version_response;
959 } response;
960
961 u32 msgsize;
962 /*
963 * The channel message that goes out on the "wire".
964 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
965 */
966 unsigned char msg[0];
967};
968
K. Y. Srinivasanf9f1db82011-06-06 15:49:58 -0700969struct vmbus_close_msg {
970 struct vmbus_channel_msginfo info;
971 struct vmbus_channel_close_channel msg;
972};
973
K. Y. Srinivasanb3bf60c2012-12-01 06:46:45 -0800974/* Define connection identifier type. */
975union hv_connection_id {
976 u32 asu32;
977 struct {
978 u32 id:24;
979 u32 reserved:8;
980 } u;
981};
982
983/* Definition of the hv_signal_event hypercall input structure. */
984struct hv_input_signal_event {
985 union hv_connection_id connectionid;
986 u16 flag_number;
987 u16 rsvdz;
988};
989
990struct hv_input_signal_event_buffer {
991 u64 align8;
992 struct hv_input_signal_event event;
993};
994
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -0700995struct vmbus_channel {
996 struct list_head listentry;
997
998 struct hv_device *device_obj;
999
1000 struct work_struct work;
1001
1002 enum vmbus_channel_state state;
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -07001003
1004 struct vmbus_channel_offer_channel offermsg;
1005 /*
1006 * These are based on the OfferMsg.MonitorId.
1007 * Save it here for easy access.
1008 */
1009 u8 monitor_grp;
1010 u8 monitor_bit;
1011
1012 u32 ringbuffer_gpadlhandle;
1013
1014 /* Allocated memory for ring buffer */
1015 void *ringbuffer_pages;
1016 u32 ringbuffer_pagecount;
1017 struct hv_ring_buffer_info outbound; /* send to parent */
1018 struct hv_ring_buffer_info inbound; /* receive from parent */
1019 spinlock_t inbound_lock;
1020 struct workqueue_struct *controlwq;
1021
K. Y. Srinivasanf9f1db82011-06-06 15:49:58 -07001022 struct vmbus_close_msg close_msg;
1023
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -07001024 /* Channel callback are invoked in this workqueue context */
1025 /* HANDLE dataWorkQueue; */
1026
1027 void (*onchannel_callback)(void *context);
1028 void *channel_callback_context;
K. Y. Srinivasan132368b2012-12-01 06:46:33 -08001029
1030 /*
1031 * A channel can be marked for efficient (batched)
1032 * reading:
1033 * If batched_reading is set to "true", we read until the
1034 * channel is empty and hold off interrupts from the host
1035 * during the entire read process.
1036 * If batched_reading is set to "false", the client is not
1037 * going to perform batched reading.
1038 *
1039 * By default we will enable batched reading; specific
1040 * drivers that don't want this behavior can turn it off.
1041 */
1042
1043 bool batched_reading;
K. Y. Srinivasanb3bf60c2012-12-01 06:46:45 -08001044
1045 bool is_dedicated_interrupt;
1046 struct hv_input_signal_event_buffer sig_buf;
1047 struct hv_input_signal_event *sig_event;
K. Y. Srinivasanabbf3b22012-12-01 06:46:48 -08001048
1049 /*
1050 * Starting with win8, this field will be used to specify
1051 * the target virtual processor on which to deliver the interrupt for
1052 * the host to guest communication.
1053 * Prior to win8, incoming channel interrupts would only
1054 * be delivered on cpu 0. Setting this value to 0 would
1055 * preserve the earlier behavior.
1056 */
1057 u32 target_vp;
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001058 /*
1059 * Support for sub-channels. For high performance devices,
1060 * it will be useful to have multiple sub-channels to support
1061 * a scalable communication infrastructure with the host.
1062 * The support for sub-channels is implemented as an extention
1063 * to the current infrastructure.
1064 * The initial offer is considered the primary channel and this
1065 * offer message will indicate if the host supports sub-channels.
1066 * The guest is free to ask for sub-channels to be offerred and can
1067 * open these sub-channels as a normal "primary" channel. However,
1068 * all sub-channels will have the same type and instance guids as the
1069 * primary channel. Requests sent on a given channel will result in a
1070 * response on the same channel.
1071 */
1072
1073 /*
1074 * Sub-channel creation callback. This callback will be called in
1075 * process context when a sub-channel offer is received from the host.
1076 * The guest can open the sub-channel in the context of this callback.
1077 */
1078 void (*sc_creation_callback)(struct vmbus_channel *new_sc);
1079
1080 spinlock_t sc_lock;
1081 /*
1082 * All Sub-channels of a primary channel are linked here.
1083 */
1084 struct list_head sc_list;
1085 /*
1086 * The primary channel this sub-channel belongs to.
1087 * This will be NULL for the primary channel.
1088 */
1089 struct vmbus_channel *primary_channel;
K. Y. Srinivasan7d7c75c2011-06-06 15:49:57 -07001090};
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -07001091
K. Y. Srinivasan132368b2012-12-01 06:46:33 -08001092static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
1093{
1094 c->batched_reading = state;
1095}
1096
K. Y. Srinivasanb56dda02011-05-12 19:34:21 -07001097void vmbus_onmessage(void *context);
1098
1099int vmbus_request_offers(void);
1100
K. Y. Srinivasane68d2972013-05-23 12:02:32 -07001101/*
1102 * APIs for managing sub-channels.
1103 */
1104
1105void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
1106 void (*sc_cr_cb)(struct vmbus_channel *new_sc));
1107
1108/*
1109 * Retrieve the (sub) channel on which to send an outgoing request.
1110 * When a primary channel has multiple sub-channels, we choose a
1111 * channel whose VCPU binding is closest to the VCPU on which
1112 * this call is being made.
1113 */
1114struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
1115
1116/*
1117 * Check if sub-channels have already been offerred. This API will be useful
1118 * when the driver is unloaded after establishing sub-channels. In this case,
1119 * when the driver is re-loaded, the driver would have to check if the
1120 * subchannels have already been established before attempting to request
1121 * the creation of sub-channels.
1122 * This function returns TRUE to indicate that subchannels have already been
1123 * created.
1124 * This function should be invoked after setting the callback function for
1125 * sub-channel creation.
1126 */
1127bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
1128
K. Y. Srinivasanc35470b2011-05-12 19:34:22 -07001129/* The format must be the same as struct vmdata_gpa_direct */
1130struct vmbus_channel_packet_page_buffer {
1131 u16 type;
1132 u16 dataoffset8;
1133 u16 length8;
1134 u16 flags;
1135 u64 transactionid;
1136 u32 reserved;
1137 u32 rangecount;
1138 struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
1139} __packed;
1140
1141/* The format must be the same as struct vmdata_gpa_direct */
1142struct vmbus_channel_packet_multipage_buffer {
1143 u16 type;
1144 u16 dataoffset8;
1145 u16 length8;
1146 u16 flags;
1147 u64 transactionid;
1148 u32 reserved;
1149 u32 rangecount; /* Always 1 in this case */
1150 struct hv_multipage_buffer range;
1151} __packed;
1152
1153
1154extern int vmbus_open(struct vmbus_channel *channel,
1155 u32 send_ringbuffersize,
1156 u32 recv_ringbuffersize,
1157 void *userdata,
1158 u32 userdatalen,
1159 void(*onchannel_callback)(void *context),
1160 void *context);
1161
1162extern void vmbus_close(struct vmbus_channel *channel);
1163
1164extern int vmbus_sendpacket(struct vmbus_channel *channel,
1165 const void *buffer,
1166 u32 bufferLen,
1167 u64 requestid,
1168 enum vmbus_packet_type type,
1169 u32 flags);
1170
1171extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
1172 struct hv_page_buffer pagebuffers[],
1173 u32 pagecount,
1174 void *buffer,
1175 u32 bufferlen,
1176 u64 requestid);
1177
1178extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
1179 struct hv_multipage_buffer *mpb,
1180 void *buffer,
1181 u32 bufferlen,
1182 u64 requestid);
1183
1184extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
1185 void *kbuffer,
1186 u32 size,
1187 u32 *gpadl_handle);
1188
1189extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
1190 u32 gpadl_handle);
1191
1192extern int vmbus_recvpacket(struct vmbus_channel *channel,
1193 void *buffer,
1194 u32 bufferlen,
1195 u32 *buffer_actual_len,
1196 u64 *requestid);
1197
1198extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
1199 void *buffer,
1200 u32 bufferlen,
1201 u32 *buffer_actual_len,
1202 u64 *requestid);
1203
K. Y. Srinivasanc35470b2011-05-12 19:34:22 -07001204
1205extern void vmbus_get_debug_info(struct vmbus_channel *channel,
1206 struct vmbus_channel_debug_info *debug);
1207
1208extern void vmbus_ontimer(unsigned long data);
1209
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001210struct hv_dev_port_info {
1211 u32 int_mask;
1212 u32 read_idx;
1213 u32 write_idx;
1214 u32 bytes_avail_toread;
1215 u32 bytes_avail_towrite;
1216};
1217
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001218/* Base driver object */
1219struct hv_driver {
1220 const char *name;
1221
1222 /* the device type supported by this driver */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001223 uuid_le dev_type;
K. Y. Srinivasan2e2c1d12011-08-25 09:48:31 -07001224 const struct hv_vmbus_device_id *id_table;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001225
1226 struct device_driver driver;
1227
K. Y. Srinivasan84946892011-09-13 10:59:38 -07001228 int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001229 int (*remove)(struct hv_device *);
1230 void (*shutdown)(struct hv_device *);
1231
1232};
1233
1234/* Base device object */
1235struct hv_device {
1236 /* the device type id of this device */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001237 uuid_le dev_type;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001238
1239 /* the device instance id of this device */
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001240 uuid_le dev_instance;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001241
1242 struct device device;
1243
1244 struct vmbus_channel *channel;
K. Y. Srinivasan35ea09c2011-05-12 19:34:24 -07001245};
1246
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001247
1248static inline struct hv_device *device_to_hv_device(struct device *d)
1249{
1250 return container_of(d, struct hv_device, device);
1251}
1252
1253static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
1254{
1255 return container_of(d, struct hv_driver, driver);
1256}
1257
K. Y. Srinivasanab101e82011-09-13 10:59:40 -07001258static inline void hv_set_drvdata(struct hv_device *dev, void *data)
1259{
1260 dev_set_drvdata(&dev->device, data);
1261}
1262
1263static inline void *hv_get_drvdata(struct hv_device *dev)
1264{
1265 return dev_get_drvdata(&dev->device);
1266}
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001267
1268/* Vmbus interface */
Greg Kroah-Hartman768fa212011-08-25 15:07:32 -07001269#define vmbus_driver_register(driver) \
1270 __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
1271int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
1272 struct module *owner,
1273 const char *mod_name);
1274void vmbus_driver_unregister(struct hv_driver *hv_driver);
K. Y. Srinivasan27b5b3c2011-05-12 19:34:25 -07001275
Greg Kroah-Hartmanc45cf2d2011-08-25 11:41:33 -07001276/**
1277 * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
1278 *
1279 * This macro is used to create a struct hv_vmbus_device_id that matches a
1280 * specific device.
1281 */
1282#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
1283 g8, g9, ga, gb, gc, gd, ge, gf) \
1284 .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
1285 g8, g9, ga, gb, gc, gd, ge, gf },
1286
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001287/*
K. Y. Srinivasan7fb96562013-01-23 17:42:40 -08001288 * GUID definitions of various offer types - services offered to the guest.
1289 */
1290
1291/*
1292 * Network GUID
1293 * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
1294 */
1295#define HV_NIC_GUID \
1296 .guid = { \
1297 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
1298 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
1299 }
1300
1301/*
1302 * IDE GUID
1303 * {32412632-86cb-44a2-9b5c-50d1417354f5}
1304 */
1305#define HV_IDE_GUID \
1306 .guid = { \
1307 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
1308 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
1309 }
1310
1311/*
1312 * SCSI GUID
1313 * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
1314 */
1315#define HV_SCSI_GUID \
1316 .guid = { \
1317 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
1318 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
1319 }
1320
1321/*
1322 * Shutdown GUID
1323 * {0e0b6031-5213-4934-818b-38d90ced39db}
1324 */
1325#define HV_SHUTDOWN_GUID \
1326 .guid = { \
1327 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
1328 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
1329 }
1330
1331/*
1332 * Time Synch GUID
1333 * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
1334 */
1335#define HV_TS_GUID \
1336 .guid = { \
1337 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
1338 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
1339 }
1340
1341/*
1342 * Heartbeat GUID
1343 * {57164f39-9115-4e78-ab55-382f3bd5422d}
1344 */
1345#define HV_HEART_BEAT_GUID \
1346 .guid = { \
1347 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
1348 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
1349 }
1350
1351/*
1352 * KVP GUID
1353 * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
1354 */
1355#define HV_KVP_GUID \
1356 .guid = { \
1357 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
1358 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
1359 }
1360
1361/*
1362 * Dynamic memory GUID
1363 * {525074dc-8985-46e2-8057-a307dc18a502}
1364 */
1365#define HV_DM_GUID \
1366 .guid = { \
1367 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
1368 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
1369 }
1370
1371/*
1372 * Mouse GUID
1373 * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
1374 */
1375#define HV_MOUSE_GUID \
1376 .guid = { \
1377 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
1378 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
1379 }
1380
1381/*
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -07001382 * VSS (Backup/Restore) GUID
1383 */
1384#define HV_VSS_GUID \
1385 .guid = { \
1386 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
1387 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
1388 }
1389/*
Haiyang Zhang68a2d20b2013-04-29 15:05:42 -07001390 * Synthetic Video GUID
1391 * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
1392 */
1393#define HV_SYNTHVID_GUID \
1394 .guid = { \
1395 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
1396 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
1397 }
1398
Haiyang Zhang68a2d20b2013-04-29 15:05:42 -07001399/*
K. Y. Srinivasan98b80d82013-05-23 12:02:33 -07001400 * Synthetic FC GUID
1401 * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
1402 */
1403#define HV_SYNTHFC_GUID \
1404 .guid = { \
1405 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
1406 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
1407 }
1408
1409/*
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001410 * Common header for Hyper-V ICs
1411 */
1412
1413#define ICMSGTYPE_NEGOTIATE 0
1414#define ICMSGTYPE_HEARTBEAT 1
1415#define ICMSGTYPE_KVPEXCHANGE 2
1416#define ICMSGTYPE_SHUTDOWN 3
1417#define ICMSGTYPE_TIMESYNC 4
1418#define ICMSGTYPE_VSS 5
1419
1420#define ICMSGHDRFLAG_TRANSACTION 1
1421#define ICMSGHDRFLAG_REQUEST 2
1422#define ICMSGHDRFLAG_RESPONSE 4
1423
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001424
K. Y. Srinivasana29b6432011-09-18 10:31:33 -07001425/*
1426 * While we want to handle util services as regular devices,
1427 * there is only one instance of each of these services; so
1428 * we statically allocate the service specific state.
1429 */
1430
1431struct hv_util_service {
1432 u8 *recv_buffer;
1433 void (*util_cb)(void *);
1434 int (*util_init)(struct hv_util_service *);
1435 void (*util_deinit)(void);
1436};
1437
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001438struct vmbuspipe_hdr {
1439 u32 flags;
1440 u32 msgsize;
1441} __packed;
1442
1443struct ic_version {
1444 u16 major;
1445 u16 minor;
1446} __packed;
1447
1448struct icmsg_hdr {
1449 struct ic_version icverframe;
1450 u16 icmsgtype;
1451 struct ic_version icvermsg;
1452 u16 icmsgsize;
1453 u32 status;
1454 u8 ictransaction_id;
1455 u8 icflags;
1456 u8 reserved[2];
1457} __packed;
1458
1459struct icmsg_negotiate {
1460 u16 icframe_vercnt;
1461 u16 icmsg_vercnt;
1462 u32 reserved;
1463 struct ic_version icversion_data[1]; /* any size array */
1464} __packed;
1465
1466struct shutdown_msg_data {
1467 u32 reason_code;
1468 u32 timeout_seconds;
1469 u32 flags;
1470 u8 display_message[2048];
1471} __packed;
1472
1473struct heartbeat_msg_data {
1474 u64 seq_num;
1475 u32 reserved[8];
1476} __packed;
1477
1478/* Time Sync IC defs */
1479#define ICTIMESYNCFLAG_PROBE 0
1480#define ICTIMESYNCFLAG_SYNC 1
1481#define ICTIMESYNCFLAG_SAMPLE 2
1482
1483#ifdef __x86_64__
1484#define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
1485#else
1486#define WLTIMEDELTA 116444736000000000LL
1487#endif
1488
1489struct ictimesync_data {
1490 u64 parenttime;
1491 u64 childtime;
1492 u64 roundtriptime;
1493 u8 flags;
1494} __packed;
1495
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001496struct hyperv_service_callback {
1497 u8 msg_type;
1498 char *log_msg;
K. Y. Srinivasan358d2ee2011-08-25 09:48:28 -07001499 uuid_le data;
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001500 struct vmbus_channel *channel;
1501 void (*callback) (void *context);
1502};
1503
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -07001504#define MAX_SRV_VER 0x7ffffff
K. Y. Srinivasan67413352013-07-02 10:31:30 -07001505extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
K. Y. Srinivasanc836d0a2012-05-12 13:44:58 -07001506 struct icmsg_negotiate *, u8 *, int,
1507 int);
K. Y. Srinivasanb1897022011-05-12 19:34:26 -07001508
K. Y. Srinivasan29394372012-01-27 15:55:58 -08001509int hv_kvp_init(struct hv_util_service *);
1510void hv_kvp_deinit(void);
1511void hv_kvp_onchannelcallback(void *);
1512
K. Y. Srinivasan96dd86f2013-03-15 12:30:06 -07001513int hv_vss_init(struct hv_util_service *);
1514void hv_vss_deinit(void);
1515void hv_vss_onchannelcallback(void *);
1516
K. Y. Srinivasan37f72782012-12-01 06:46:41 -08001517/*
1518 * Negotiated version with the Host.
1519 */
1520
1521extern __u32 vmbus_proto_version;
1522
K. Y. Srinivasan29394372012-01-27 15:55:58 -08001523#endif /* __KERNEL__ */
K. Y. Srinivasan3f335ea2011-05-12 19:34:15 -07001524#endif /* _HYPERV_H */