hyperv.h 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. * K. Y. Srinivasan <kys@microsoft.com>
  22. *
  23. */
  24. #ifndef _HYPERV_H
  25. #define _HYPERV_H
  26. #include <linux/types.h>
  27. /*
  28. * An implementation of HyperV key value pair (KVP) functionality for Linux.
  29. *
  30. *
  31. * Copyright (C) 2010, Novell, Inc.
  32. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  33. *
  34. */
  35. /*
  36. * Maximum value size - used for both key names and value data, and includes
  37. * any applicable NULL terminators.
  38. *
  39. * Note: This limit is somewhat arbitrary, but falls easily within what is
  40. * supported for all native guests (back to Win 2000) and what is reasonable
  41. * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
  42. * limited to 255 character key names.
  43. *
  44. * MSDN recommends not storing data values larger than 2048 bytes in the
  45. * registry.
  46. *
  47. * Note: This value is used in defining the KVP exchange message - this value
  48. * cannot be modified without affecting the message size and compatibility.
  49. */
  50. /*
  51. * bytes, including any null terminators
  52. */
  53. #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
  54. /*
  55. * Maximum key size - the registry limit for the length of an entry name
  56. * is 256 characters, including the null terminator
  57. */
  58. #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
  59. /*
  60. * In Linux, we implement the KVP functionality in two components:
  61. * 1) The kernel component which is packaged as part of the hv_utils driver
  62. * is responsible for communicating with the host and responsible for
  63. * implementing the host/guest protocol. 2) A user level daemon that is
  64. * responsible for data gathering.
  65. *
  66. * Host/Guest Protocol: The host iterates over an index and expects the guest
  67. * to assign a key name to the index and also return the value corresponding to
  68. * the key. The host will have atmost one KVP transaction outstanding at any
  69. * given point in time. The host side iteration stops when the guest returns
  70. * an error. Microsoft has specified the following mapping of key names to
  71. * host specified index:
  72. *
  73. * Index Key Name
  74. * 0 FullyQualifiedDomainName
  75. * 1 IntegrationServicesVersion
  76. * 2 NetworkAddressIPv4
  77. * 3 NetworkAddressIPv6
  78. * 4 OSBuildNumber
  79. * 5 OSName
  80. * 6 OSMajorVersion
  81. * 7 OSMinorVersion
  82. * 8 OSVersion
  83. * 9 ProcessorArchitecture
  84. *
  85. * The Windows host expects the Key Name and Key Value to be encoded in utf16.
  86. *
  87. * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
  88. * data gathering functionality in a user mode daemon. The user level daemon
  89. * is also responsible for binding the key name to the index as well. The
  90. * kernel and user-level daemon communicate using a connector channel.
  91. *
  92. * The user mode component first registers with the
  93. * the kernel component. Subsequently, the kernel component requests, data
  94. * for the specified keys. In response to this message the user mode component
  95. * fills in the value corresponding to the specified key. We overload the
  96. * sequence field in the cn_msg header to define our KVP message types.
  97. *
  98. *
  99. * The kernel component simply acts as a conduit for communication between the
  100. * Windows host and the user-level daemon. The kernel component passes up the
  101. * index received from the Host to the user-level daemon. If the index is
  102. * valid (supported), the corresponding key as well as its
  103. * value (both are strings) is returned. If the index is invalid
  104. * (not supported), a NULL key string is returned.
  105. */
  106. /*
  107. *
  108. * The following definitions are shared with the user-mode component; do not
  109. * change any of this without making the corresponding changes in
  110. * the KVP user-mode component.
  111. */
  112. enum hv_ku_op {
  113. KVP_REGISTER = 0, /* Register the user mode component */
  114. KVP_KERNEL_GET, /* Kernel is requesting the value */
  115. KVP_KERNEL_SET, /* Kernel is providing the value */
  116. KVP_USER_GET, /* User is requesting the value */
  117. KVP_USER_SET /* User is providing the value */
  118. };
  119. struct hv_ku_msg {
  120. __u32 kvp_index; /* Key index */
  121. __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
  122. __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
  123. };
  124. /*
  125. * Registry value types.
  126. */
  127. #define REG_SZ 1
  128. enum hv_kvp_exchg_op {
  129. KVP_OP_GET = 0,
  130. KVP_OP_SET,
  131. KVP_OP_DELETE,
  132. KVP_OP_ENUMERATE,
  133. KVP_OP_COUNT /* Number of operations, must be last. */
  134. };
  135. enum hv_kvp_exchg_pool {
  136. KVP_POOL_EXTERNAL = 0,
  137. KVP_POOL_GUEST,
  138. KVP_POOL_AUTO,
  139. KVP_POOL_AUTO_EXTERNAL,
  140. KVP_POOL_AUTO_INTERNAL,
  141. KVP_POOL_COUNT /* Number of pools, must be last. */
  142. };
  143. struct hv_kvp_hdr {
  144. __u8 operation;
  145. __u8 pool;
  146. __u16 pad;
  147. } __attribute__((packed));
  148. struct hv_kvp_exchg_msg_value {
  149. __u32 value_type;
  150. __u32 key_size;
  151. __u32 value_size;
  152. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  153. __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  154. } __attribute__((packed));
  155. struct hv_kvp_msg_enumerate {
  156. __u32 index;
  157. struct hv_kvp_exchg_msg_value data;
  158. } __attribute__((packed));
  159. struct hv_kvp_msg {
  160. struct hv_kvp_hdr kvp_hdr;
  161. struct hv_kvp_msg_enumerate kvp_data;
  162. } __attribute__((packed));
  163. #ifdef __KERNEL__
  164. #include <linux/scatterlist.h>
  165. #include <linux/list.h>
  166. #include <linux/uuid.h>
  167. #include <linux/timer.h>
  168. #include <linux/workqueue.h>
  169. #include <linux/completion.h>
  170. #include <linux/device.h>
  171. #include <linux/mod_devicetable.h>
  172. #define MAX_PAGE_BUFFER_COUNT 18
  173. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  174. #pragma pack(push, 1)
  175. /* Single-page buffer */
  176. struct hv_page_buffer {
  177. u32 len;
  178. u32 offset;
  179. u64 pfn;
  180. };
  181. /* Multiple-page buffer */
  182. struct hv_multipage_buffer {
  183. /* Length and Offset determines the # of pfns in the array */
  184. u32 len;
  185. u32 offset;
  186. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  187. };
  188. /* 0x18 includes the proprietary packet header */
  189. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  190. (sizeof(struct hv_page_buffer) * \
  191. MAX_PAGE_BUFFER_COUNT))
  192. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  193. sizeof(struct hv_multipage_buffer))
  194. #pragma pack(pop)
  195. struct hv_ring_buffer {
  196. /* Offset in bytes from the start of ring data below */
  197. u32 write_index;
  198. /* Offset in bytes from the start of ring data below */
  199. u32 read_index;
  200. u32 interrupt_mask;
  201. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  202. u8 reserved[4084];
  203. /* NOTE:
  204. * The interrupt_mask field is used only for channels but since our
  205. * vmbus connection also uses this data structure and its data starts
  206. * here, we commented out this field.
  207. */
  208. /*
  209. * Ring data starts here + RingDataStartOffset
  210. * !!! DO NOT place any fields below this !!!
  211. */
  212. u8 buffer[0];
  213. } __packed;
  214. struct hv_ring_buffer_info {
  215. struct hv_ring_buffer *ring_buffer;
  216. u32 ring_size; /* Include the shared header */
  217. spinlock_t ring_lock;
  218. u32 ring_datasize; /* < ring_size */
  219. u32 ring_data_startoffset;
  220. };
  221. struct hv_ring_buffer_debug_info {
  222. u32 current_interrupt_mask;
  223. u32 current_read_index;
  224. u32 current_write_index;
  225. u32 bytes_avail_toread;
  226. u32 bytes_avail_towrite;
  227. };
  228. /*
  229. * We use the same version numbering for all Hyper-V modules.
  230. *
  231. * Definition of versioning is as follows;
  232. *
  233. * Major Number Changes for these scenarios;
  234. * 1. When a new version of Windows Hyper-V
  235. * is released.
  236. * 2. A Major change has occurred in the
  237. * Linux IC's.
  238. * (For example the merge for the first time
  239. * into the kernel) Every time the Major Number
  240. * changes, the Revision number is reset to 0.
  241. * Minor Number Changes when new functionality is added
  242. * to the Linux IC's that is not a bug fix.
  243. *
  244. * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  245. */
  246. #define HV_DRV_VERSION "3.1"
  247. /*
  248. * A revision number of vmbus that is used for ensuring both ends on a
  249. * partition are using compatible versions.
  250. */
  251. #define VMBUS_REVISION_NUMBER 13
  252. /* Make maximum size of pipe payload of 16K */
  253. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  254. /* Define PipeMode values. */
  255. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  256. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  257. /* The size of the user defined data buffer for non-pipe offers. */
  258. #define MAX_USER_DEFINED_BYTES 120
  259. /* The size of the user defined data buffer for pipe offers. */
  260. #define MAX_PIPE_USER_DEFINED_BYTES 116
  261. /*
  262. * At the center of the Channel Management library is the Channel Offer. This
  263. * struct contains the fundamental information about an offer.
  264. */
  265. struct vmbus_channel_offer {
  266. uuid_le if_type;
  267. uuid_le if_instance;
  268. u64 int_latency; /* in 100ns units */
  269. u32 if_revision;
  270. u32 server_ctx_size; /* in bytes */
  271. u16 chn_flags;
  272. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  273. union {
  274. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  275. struct {
  276. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  277. } std;
  278. /*
  279. * Pipes:
  280. * The following sructure is an integrated pipe protocol, which
  281. * is implemented on top of standard user-defined data. Pipe
  282. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  283. * use.
  284. */
  285. struct {
  286. u32 pipe_mode;
  287. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  288. } pipe;
  289. } u;
  290. u32 padding;
  291. } __packed;
  292. /* Server Flags */
  293. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  294. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  295. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  296. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  297. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  298. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  299. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  300. struct vmpacket_descriptor {
  301. u16 type;
  302. u16 offset8;
  303. u16 len8;
  304. u16 flags;
  305. u64 trans_id;
  306. } __packed;
  307. struct vmpacket_header {
  308. u32 prev_pkt_start_offset;
  309. struct vmpacket_descriptor descriptor;
  310. } __packed;
  311. struct vmtransfer_page_range {
  312. u32 byte_count;
  313. u32 byte_offset;
  314. } __packed;
  315. struct vmtransfer_page_packet_header {
  316. struct vmpacket_descriptor d;
  317. u16 xfer_pageset_id;
  318. bool sender_owns_set;
  319. u8 reserved;
  320. u32 range_cnt;
  321. struct vmtransfer_page_range ranges[1];
  322. } __packed;
  323. struct vmgpadl_packet_header {
  324. struct vmpacket_descriptor d;
  325. u32 gpadl;
  326. u32 reserved;
  327. } __packed;
  328. struct vmadd_remove_transfer_page_set {
  329. struct vmpacket_descriptor d;
  330. u32 gpadl;
  331. u16 xfer_pageset_id;
  332. u16 reserved;
  333. } __packed;
  334. /*
  335. * This structure defines a range in guest physical space that can be made to
  336. * look virtually contiguous.
  337. */
  338. struct gpa_range {
  339. u32 byte_count;
  340. u32 byte_offset;
  341. u64 pfn_array[0];
  342. };
  343. /*
  344. * This is the format for an Establish Gpadl packet, which contains a handle by
  345. * which this GPADL will be known and a set of GPA ranges associated with it.
  346. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  347. * ranges, then the resulting MDL will be "chained," representing multiple VA
  348. * ranges.
  349. */
  350. struct vmestablish_gpadl {
  351. struct vmpacket_descriptor d;
  352. u32 gpadl;
  353. u32 range_cnt;
  354. struct gpa_range range[1];
  355. } __packed;
  356. /*
  357. * This is the format for a Teardown Gpadl packet, which indicates that the
  358. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  359. */
  360. struct vmteardown_gpadl {
  361. struct vmpacket_descriptor d;
  362. u32 gpadl;
  363. u32 reserved; /* for alignment to a 8-byte boundary */
  364. } __packed;
  365. /*
  366. * This is the format for a GPA-Direct packet, which contains a set of GPA
  367. * ranges, in addition to commands and/or data.
  368. */
  369. struct vmdata_gpa_direct {
  370. struct vmpacket_descriptor d;
  371. u32 reserved;
  372. u32 range_cnt;
  373. struct gpa_range range[1];
  374. } __packed;
  375. /* This is the format for a Additional Data Packet. */
  376. struct vmadditional_data {
  377. struct vmpacket_descriptor d;
  378. u64 total_bytes;
  379. u32 offset;
  380. u32 byte_cnt;
  381. unsigned char data[1];
  382. } __packed;
  383. union vmpacket_largest_possible_header {
  384. struct vmpacket_descriptor simple_hdr;
  385. struct vmtransfer_page_packet_header xfer_page_hdr;
  386. struct vmgpadl_packet_header gpadl_hdr;
  387. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  388. struct vmestablish_gpadl establish_gpadl_hdr;
  389. struct vmteardown_gpadl teardown_gpadl_hdr;
  390. struct vmdata_gpa_direct data_gpa_direct_hdr;
  391. };
  392. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  393. (void *)(((unsigned char *)__packet) + \
  394. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  395. #define VMPACKET_DATA_LENGTH(__packet) \
  396. ((((struct vmpacket_descriptor)__packet)->len8 - \
  397. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  398. #define VMPACKET_TRANSFER_MODE(__packet) \
  399. (((struct IMPACT)__packet)->type)
  400. enum vmbus_packet_type {
  401. VM_PKT_INVALID = 0x0,
  402. VM_PKT_SYNCH = 0x1,
  403. VM_PKT_ADD_XFER_PAGESET = 0x2,
  404. VM_PKT_RM_XFER_PAGESET = 0x3,
  405. VM_PKT_ESTABLISH_GPADL = 0x4,
  406. VM_PKT_TEARDOWN_GPADL = 0x5,
  407. VM_PKT_DATA_INBAND = 0x6,
  408. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  409. VM_PKT_DATA_USING_GPADL = 0x8,
  410. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  411. VM_PKT_CANCEL_REQUEST = 0xa,
  412. VM_PKT_COMP = 0xb,
  413. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  414. VM_PKT_ADDITIONAL_DATA = 0xd
  415. };
  416. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  417. /* Version 1 messages */
  418. enum vmbus_channel_message_type {
  419. CHANNELMSG_INVALID = 0,
  420. CHANNELMSG_OFFERCHANNEL = 1,
  421. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  422. CHANNELMSG_REQUESTOFFERS = 3,
  423. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  424. CHANNELMSG_OPENCHANNEL = 5,
  425. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  426. CHANNELMSG_CLOSECHANNEL = 7,
  427. CHANNELMSG_GPADL_HEADER = 8,
  428. CHANNELMSG_GPADL_BODY = 9,
  429. CHANNELMSG_GPADL_CREATED = 10,
  430. CHANNELMSG_GPADL_TEARDOWN = 11,
  431. CHANNELMSG_GPADL_TORNDOWN = 12,
  432. CHANNELMSG_RELID_RELEASED = 13,
  433. CHANNELMSG_INITIATE_CONTACT = 14,
  434. CHANNELMSG_VERSION_RESPONSE = 15,
  435. CHANNELMSG_UNLOAD = 16,
  436. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  437. CHANNELMSG_VIEWRANGE_ADD = 17,
  438. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  439. #endif
  440. CHANNELMSG_COUNT
  441. };
  442. struct vmbus_channel_message_header {
  443. enum vmbus_channel_message_type msgtype;
  444. u32 padding;
  445. } __packed;
  446. /* Query VMBus Version parameters */
  447. struct vmbus_channel_query_vmbus_version {
  448. struct vmbus_channel_message_header header;
  449. u32 version;
  450. } __packed;
  451. /* VMBus Version Supported parameters */
  452. struct vmbus_channel_version_supported {
  453. struct vmbus_channel_message_header header;
  454. bool version_supported;
  455. } __packed;
  456. /* Offer Channel parameters */
  457. struct vmbus_channel_offer_channel {
  458. struct vmbus_channel_message_header header;
  459. struct vmbus_channel_offer offer;
  460. u32 child_relid;
  461. u8 monitorid;
  462. bool monitor_allocated;
  463. } __packed;
  464. /* Rescind Offer parameters */
  465. struct vmbus_channel_rescind_offer {
  466. struct vmbus_channel_message_header header;
  467. u32 child_relid;
  468. } __packed;
  469. /*
  470. * Request Offer -- no parameters, SynIC message contains the partition ID
  471. * Set Snoop -- no parameters, SynIC message contains the partition ID
  472. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  473. * All Offers Delivered -- no parameters, SynIC message contains the partition
  474. * ID
  475. * Flush Client -- no parameters, SynIC message contains the partition ID
  476. */
  477. /* Open Channel parameters */
  478. struct vmbus_channel_open_channel {
  479. struct vmbus_channel_message_header header;
  480. /* Identifies the specific VMBus channel that is being opened. */
  481. u32 child_relid;
  482. /* ID making a particular open request at a channel offer unique. */
  483. u32 openid;
  484. /* GPADL for the channel's ring buffer. */
  485. u32 ringbuffer_gpadlhandle;
  486. /* GPADL for the channel's server context save area. */
  487. u32 server_contextarea_gpadlhandle;
  488. /*
  489. * The upstream ring buffer begins at offset zero in the memory
  490. * described by RingBufferGpadlHandle. The downstream ring buffer
  491. * follows it at this offset (in pages).
  492. */
  493. u32 downstream_ringbuffer_pageoffset;
  494. /* User-specific data to be passed along to the server endpoint. */
  495. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  496. } __packed;
  497. /* Open Channel Result parameters */
  498. struct vmbus_channel_open_result {
  499. struct vmbus_channel_message_header header;
  500. u32 child_relid;
  501. u32 openid;
  502. u32 status;
  503. } __packed;
  504. /* Close channel parameters; */
  505. struct vmbus_channel_close_channel {
  506. struct vmbus_channel_message_header header;
  507. u32 child_relid;
  508. } __packed;
  509. /* Channel Message GPADL */
  510. #define GPADL_TYPE_RING_BUFFER 1
  511. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  512. #define GPADL_TYPE_TRANSACTION 8
  513. /*
  514. * The number of PFNs in a GPADL message is defined by the number of
  515. * pages that would be spanned by ByteCount and ByteOffset. If the
  516. * implied number of PFNs won't fit in this packet, there will be a
  517. * follow-up packet that contains more.
  518. */
  519. struct vmbus_channel_gpadl_header {
  520. struct vmbus_channel_message_header header;
  521. u32 child_relid;
  522. u32 gpadl;
  523. u16 range_buflen;
  524. u16 rangecount;
  525. struct gpa_range range[0];
  526. } __packed;
  527. /* This is the followup packet that contains more PFNs. */
  528. struct vmbus_channel_gpadl_body {
  529. struct vmbus_channel_message_header header;
  530. u32 msgnumber;
  531. u32 gpadl;
  532. u64 pfn[0];
  533. } __packed;
  534. struct vmbus_channel_gpadl_created {
  535. struct vmbus_channel_message_header header;
  536. u32 child_relid;
  537. u32 gpadl;
  538. u32 creation_status;
  539. } __packed;
  540. struct vmbus_channel_gpadl_teardown {
  541. struct vmbus_channel_message_header header;
  542. u32 child_relid;
  543. u32 gpadl;
  544. } __packed;
  545. struct vmbus_channel_gpadl_torndown {
  546. struct vmbus_channel_message_header header;
  547. u32 gpadl;
  548. } __packed;
  549. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  550. struct vmbus_channel_view_range_add {
  551. struct vmbus_channel_message_header header;
  552. PHYSICAL_ADDRESS viewrange_base;
  553. u64 viewrange_length;
  554. u32 child_relid;
  555. } __packed;
  556. struct vmbus_channel_view_range_remove {
  557. struct vmbus_channel_message_header header;
  558. PHYSICAL_ADDRESS viewrange_base;
  559. u32 child_relid;
  560. } __packed;
  561. #endif
  562. struct vmbus_channel_relid_released {
  563. struct vmbus_channel_message_header header;
  564. u32 child_relid;
  565. } __packed;
  566. struct vmbus_channel_initiate_contact {
  567. struct vmbus_channel_message_header header;
  568. u32 vmbus_version_requested;
  569. u32 padding2;
  570. u64 interrupt_page;
  571. u64 monitor_page1;
  572. u64 monitor_page2;
  573. } __packed;
  574. struct vmbus_channel_version_response {
  575. struct vmbus_channel_message_header header;
  576. bool version_supported;
  577. } __packed;
  578. enum vmbus_channel_state {
  579. CHANNEL_OFFER_STATE,
  580. CHANNEL_OPENING_STATE,
  581. CHANNEL_OPEN_STATE,
  582. };
  583. struct vmbus_channel_debug_info {
  584. u32 relid;
  585. enum vmbus_channel_state state;
  586. uuid_le interfacetype;
  587. uuid_le interface_instance;
  588. u32 monitorid;
  589. u32 servermonitor_pending;
  590. u32 servermonitor_latency;
  591. u32 servermonitor_connectionid;
  592. u32 clientmonitor_pending;
  593. u32 clientmonitor_latency;
  594. u32 clientmonitor_connectionid;
  595. struct hv_ring_buffer_debug_info inbound;
  596. struct hv_ring_buffer_debug_info outbound;
  597. };
  598. /*
  599. * Represents each channel msg on the vmbus connection This is a
  600. * variable-size data structure depending on the msg type itself
  601. */
  602. struct vmbus_channel_msginfo {
  603. /* Bookkeeping stuff */
  604. struct list_head msglistentry;
  605. /* So far, this is only used to handle gpadl body message */
  606. struct list_head submsglist;
  607. /* Synchronize the request/response if needed */
  608. struct completion waitevent;
  609. union {
  610. struct vmbus_channel_version_supported version_supported;
  611. struct vmbus_channel_open_result open_result;
  612. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  613. struct vmbus_channel_gpadl_created gpadl_created;
  614. struct vmbus_channel_version_response version_response;
  615. } response;
  616. u32 msgsize;
  617. /*
  618. * The channel message that goes out on the "wire".
  619. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  620. */
  621. unsigned char msg[0];
  622. };
  623. struct vmbus_close_msg {
  624. struct vmbus_channel_msginfo info;
  625. struct vmbus_channel_close_channel msg;
  626. };
  627. struct vmbus_channel {
  628. struct list_head listentry;
  629. struct hv_device *device_obj;
  630. struct work_struct work;
  631. enum vmbus_channel_state state;
  632. struct vmbus_channel_offer_channel offermsg;
  633. /*
  634. * These are based on the OfferMsg.MonitorId.
  635. * Save it here for easy access.
  636. */
  637. u8 monitor_grp;
  638. u8 monitor_bit;
  639. u32 ringbuffer_gpadlhandle;
  640. /* Allocated memory for ring buffer */
  641. void *ringbuffer_pages;
  642. u32 ringbuffer_pagecount;
  643. struct hv_ring_buffer_info outbound; /* send to parent */
  644. struct hv_ring_buffer_info inbound; /* receive from parent */
  645. spinlock_t inbound_lock;
  646. struct workqueue_struct *controlwq;
  647. struct vmbus_close_msg close_msg;
  648. /* Channel callback are invoked in this workqueue context */
  649. /* HANDLE dataWorkQueue; */
  650. void (*onchannel_callback)(void *context);
  651. void *channel_callback_context;
  652. };
  653. void vmbus_onmessage(void *context);
  654. int vmbus_request_offers(void);
  655. /* The format must be the same as struct vmdata_gpa_direct */
  656. struct vmbus_channel_packet_page_buffer {
  657. u16 type;
  658. u16 dataoffset8;
  659. u16 length8;
  660. u16 flags;
  661. u64 transactionid;
  662. u32 reserved;
  663. u32 rangecount;
  664. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  665. } __packed;
  666. /* The format must be the same as struct vmdata_gpa_direct */
  667. struct vmbus_channel_packet_multipage_buffer {
  668. u16 type;
  669. u16 dataoffset8;
  670. u16 length8;
  671. u16 flags;
  672. u64 transactionid;
  673. u32 reserved;
  674. u32 rangecount; /* Always 1 in this case */
  675. struct hv_multipage_buffer range;
  676. } __packed;
  677. extern int vmbus_open(struct vmbus_channel *channel,
  678. u32 send_ringbuffersize,
  679. u32 recv_ringbuffersize,
  680. void *userdata,
  681. u32 userdatalen,
  682. void(*onchannel_callback)(void *context),
  683. void *context);
  684. extern void vmbus_close(struct vmbus_channel *channel);
  685. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  686. const void *buffer,
  687. u32 bufferLen,
  688. u64 requestid,
  689. enum vmbus_packet_type type,
  690. u32 flags);
  691. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  692. struct hv_page_buffer pagebuffers[],
  693. u32 pagecount,
  694. void *buffer,
  695. u32 bufferlen,
  696. u64 requestid);
  697. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  698. struct hv_multipage_buffer *mpb,
  699. void *buffer,
  700. u32 bufferlen,
  701. u64 requestid);
  702. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  703. void *kbuffer,
  704. u32 size,
  705. u32 *gpadl_handle);
  706. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  707. u32 gpadl_handle);
  708. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  709. void *buffer,
  710. u32 bufferlen,
  711. u32 *buffer_actual_len,
  712. u64 *requestid);
  713. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  714. void *buffer,
  715. u32 bufferlen,
  716. u32 *buffer_actual_len,
  717. u64 *requestid);
  718. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  719. struct vmbus_channel_debug_info *debug);
  720. extern void vmbus_ontimer(unsigned long data);
  721. struct hv_dev_port_info {
  722. u32 int_mask;
  723. u32 read_idx;
  724. u32 write_idx;
  725. u32 bytes_avail_toread;
  726. u32 bytes_avail_towrite;
  727. };
  728. /* Base driver object */
  729. struct hv_driver {
  730. const char *name;
  731. /* the device type supported by this driver */
  732. uuid_le dev_type;
  733. const struct hv_vmbus_device_id *id_table;
  734. struct device_driver driver;
  735. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  736. int (*remove)(struct hv_device *);
  737. void (*shutdown)(struct hv_device *);
  738. };
  739. /* Base device object */
  740. struct hv_device {
  741. /* the device type id of this device */
  742. uuid_le dev_type;
  743. /* the device instance id of this device */
  744. uuid_le dev_instance;
  745. struct device device;
  746. struct vmbus_channel *channel;
  747. };
  748. static inline struct hv_device *device_to_hv_device(struct device *d)
  749. {
  750. return container_of(d, struct hv_device, device);
  751. }
  752. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  753. {
  754. return container_of(d, struct hv_driver, driver);
  755. }
  756. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  757. {
  758. dev_set_drvdata(&dev->device, data);
  759. }
  760. static inline void *hv_get_drvdata(struct hv_device *dev)
  761. {
  762. return dev_get_drvdata(&dev->device);
  763. }
  764. /* Vmbus interface */
  765. #define vmbus_driver_register(driver) \
  766. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  767. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  768. struct module *owner,
  769. const char *mod_name);
  770. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  771. /**
  772. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  773. *
  774. * This macro is used to create a struct hv_vmbus_device_id that matches a
  775. * specific device.
  776. */
  777. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  778. g8, g9, ga, gb, gc, gd, ge, gf) \
  779. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  780. g8, g9, ga, gb, gc, gd, ge, gf },
  781. /*
  782. * Common header for Hyper-V ICs
  783. */
  784. #define ICMSGTYPE_NEGOTIATE 0
  785. #define ICMSGTYPE_HEARTBEAT 1
  786. #define ICMSGTYPE_KVPEXCHANGE 2
  787. #define ICMSGTYPE_SHUTDOWN 3
  788. #define ICMSGTYPE_TIMESYNC 4
  789. #define ICMSGTYPE_VSS 5
  790. #define ICMSGHDRFLAG_TRANSACTION 1
  791. #define ICMSGHDRFLAG_REQUEST 2
  792. #define ICMSGHDRFLAG_RESPONSE 4
  793. #define HV_S_OK 0x00000000
  794. #define HV_E_FAIL 0x80004005
  795. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  796. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  797. /*
  798. * While we want to handle util services as regular devices,
  799. * there is only one instance of each of these services; so
  800. * we statically allocate the service specific state.
  801. */
  802. struct hv_util_service {
  803. u8 *recv_buffer;
  804. void (*util_cb)(void *);
  805. int (*util_init)(struct hv_util_service *);
  806. void (*util_deinit)(void);
  807. };
  808. struct vmbuspipe_hdr {
  809. u32 flags;
  810. u32 msgsize;
  811. } __packed;
  812. struct ic_version {
  813. u16 major;
  814. u16 minor;
  815. } __packed;
  816. struct icmsg_hdr {
  817. struct ic_version icverframe;
  818. u16 icmsgtype;
  819. struct ic_version icvermsg;
  820. u16 icmsgsize;
  821. u32 status;
  822. u8 ictransaction_id;
  823. u8 icflags;
  824. u8 reserved[2];
  825. } __packed;
  826. struct icmsg_negotiate {
  827. u16 icframe_vercnt;
  828. u16 icmsg_vercnt;
  829. u32 reserved;
  830. struct ic_version icversion_data[1]; /* any size array */
  831. } __packed;
  832. struct shutdown_msg_data {
  833. u32 reason_code;
  834. u32 timeout_seconds;
  835. u32 flags;
  836. u8 display_message[2048];
  837. } __packed;
  838. struct heartbeat_msg_data {
  839. u64 seq_num;
  840. u32 reserved[8];
  841. } __packed;
  842. /* Time Sync IC defs */
  843. #define ICTIMESYNCFLAG_PROBE 0
  844. #define ICTIMESYNCFLAG_SYNC 1
  845. #define ICTIMESYNCFLAG_SAMPLE 2
  846. #ifdef __x86_64__
  847. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  848. #else
  849. #define WLTIMEDELTA 116444736000000000LL
  850. #endif
  851. struct ictimesync_data {
  852. u64 parenttime;
  853. u64 childtime;
  854. u64 roundtriptime;
  855. u8 flags;
  856. } __packed;
  857. struct hyperv_service_callback {
  858. u8 msg_type;
  859. char *log_msg;
  860. uuid_le data;
  861. struct vmbus_channel *channel;
  862. void (*callback) (void *context);
  863. };
  864. extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  865. struct icmsg_negotiate *, u8 *);
  866. int hv_kvp_init(struct hv_util_service *);
  867. void hv_kvp_deinit(void);
  868. void hv_kvp_onchannelcallback(void *);
  869. #endif /* __KERNEL__ */
  870. #endif /* _HYPERV_H */