hyperv.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. * Registry value types.
  108. */
  109. #define REG_SZ 1
  110. #define REG_U32 4
  111. #define REG_U64 8
  112. /*
  113. * As we look at expanding the KVP functionality to include
  114. * IP injection functionality, we need to maintain binary
  115. * compatibility with older daemons.
  116. *
  117. * The KVP opcodes are defined by the host and it was unfortunate
  118. * that I chose to treat the registration operation as part of the
  119. * KVP operations defined by the host.
  120. * Here is the level of compatibility
  121. * (between the user level daemon and the kernel KVP driver) that we
  122. * will implement:
  123. *
  124. * An older daemon will always be supported on a newer driver.
  125. * A given user level daemon will require a minimal version of the
  126. * kernel driver.
  127. * If we cannot handle the version differences, we will fail gracefully
  128. * (this can happen when we have a user level daemon that is more
  129. * advanced than the KVP driver.
  130. *
  131. * We will use values used in this handshake for determining if we have
  132. * workable user level daemon and the kernel driver. We begin by taking the
  133. * registration opcode out of the KVP opcode namespace. We will however,
  134. * maintain compatibility with the existing user-level daemon code.
  135. */
  136. /*
  137. * Daemon code not supporting IP injection (legacy daemon).
  138. */
  139. #define KVP_OP_REGISTER 4
  140. /*
  141. * Daemon code supporting IP injection.
  142. * The KVP opcode field is used to communicate the
  143. * registration information; so define a namespace that
  144. * will be distinct from the host defined KVP opcode.
  145. */
  146. #define KVP_OP_REGISTER1 100
  147. enum hv_kvp_exchg_op {
  148. KVP_OP_GET = 0,
  149. KVP_OP_SET,
  150. KVP_OP_DELETE,
  151. KVP_OP_ENUMERATE,
  152. KVP_OP_GET_IP_INFO,
  153. KVP_OP_SET_IP_INFO,
  154. KVP_OP_COUNT /* Number of operations, must be last. */
  155. };
  156. enum hv_kvp_exchg_pool {
  157. KVP_POOL_EXTERNAL = 0,
  158. KVP_POOL_GUEST,
  159. KVP_POOL_AUTO,
  160. KVP_POOL_AUTO_EXTERNAL,
  161. KVP_POOL_AUTO_INTERNAL,
  162. KVP_POOL_COUNT /* Number of pools, must be last. */
  163. };
  164. /*
  165. * Some Hyper-V status codes.
  166. */
  167. #define HV_S_OK 0x00000000
  168. #define HV_E_FAIL 0x80004005
  169. #define HV_S_CONT 0x80070103
  170. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  171. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  172. #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
  173. #define HV_INVALIDARG 0x80070057
  174. #define HV_GUID_NOTFOUND 0x80041002
  175. #define ADDR_FAMILY_NONE 0x00
  176. #define ADDR_FAMILY_IPV4 0x01
  177. #define ADDR_FAMILY_IPV6 0x02
  178. #define MAX_ADAPTER_ID_SIZE 128
  179. #define MAX_IP_ADDR_SIZE 1024
  180. #define MAX_GATEWAY_SIZE 512
  181. struct hv_kvp_ipaddr_value {
  182. __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
  183. __u8 addr_family;
  184. __u8 dhcp_enabled;
  185. __u16 ip_addr[MAX_IP_ADDR_SIZE];
  186. __u16 sub_net[MAX_IP_ADDR_SIZE];
  187. __u16 gate_way[MAX_GATEWAY_SIZE];
  188. __u16 dns_addr[MAX_IP_ADDR_SIZE];
  189. } __attribute__((packed));
  190. struct hv_kvp_hdr {
  191. __u8 operation;
  192. __u8 pool;
  193. __u16 pad;
  194. } __attribute__((packed));
  195. struct hv_kvp_exchg_msg_value {
  196. __u32 value_type;
  197. __u32 key_size;
  198. __u32 value_size;
  199. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  200. union {
  201. __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  202. __u32 value_u32;
  203. __u64 value_u64;
  204. };
  205. } __attribute__((packed));
  206. struct hv_kvp_msg_enumerate {
  207. __u32 index;
  208. struct hv_kvp_exchg_msg_value data;
  209. } __attribute__((packed));
  210. struct hv_kvp_msg_get {
  211. struct hv_kvp_exchg_msg_value data;
  212. };
  213. struct hv_kvp_msg_set {
  214. struct hv_kvp_exchg_msg_value data;
  215. };
  216. struct hv_kvp_msg_delete {
  217. __u32 key_size;
  218. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  219. };
  220. struct hv_kvp_register {
  221. __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  222. };
  223. struct hv_kvp_msg {
  224. union {
  225. struct hv_kvp_hdr kvp_hdr;
  226. int error;
  227. };
  228. union {
  229. struct hv_kvp_msg_get kvp_get;
  230. struct hv_kvp_msg_set kvp_set;
  231. struct hv_kvp_msg_delete kvp_delete;
  232. struct hv_kvp_msg_enumerate kvp_enum_data;
  233. struct hv_kvp_ipaddr_value kvp_ip_val;
  234. struct hv_kvp_register kvp_register;
  235. } body;
  236. } __attribute__((packed));
  237. struct hv_kvp_ip_msg {
  238. __u8 operation;
  239. __u8 pool;
  240. struct hv_kvp_ipaddr_value kvp_ip_val;
  241. } __attribute__((packed));
  242. #ifdef __KERNEL__
  243. #include <linux/scatterlist.h>
  244. #include <linux/list.h>
  245. #include <linux/uuid.h>
  246. #include <linux/timer.h>
  247. #include <linux/workqueue.h>
  248. #include <linux/completion.h>
  249. #include <linux/device.h>
  250. #include <linux/mod_devicetable.h>
  251. #define MAX_PAGE_BUFFER_COUNT 19
  252. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  253. #pragma pack(push, 1)
  254. /* Single-page buffer */
  255. struct hv_page_buffer {
  256. u32 len;
  257. u32 offset;
  258. u64 pfn;
  259. };
  260. /* Multiple-page buffer */
  261. struct hv_multipage_buffer {
  262. /* Length and Offset determines the # of pfns in the array */
  263. u32 len;
  264. u32 offset;
  265. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  266. };
  267. /* 0x18 includes the proprietary packet header */
  268. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  269. (sizeof(struct hv_page_buffer) * \
  270. MAX_PAGE_BUFFER_COUNT))
  271. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  272. sizeof(struct hv_multipage_buffer))
  273. #pragma pack(pop)
  274. struct hv_ring_buffer {
  275. /* Offset in bytes from the start of ring data below */
  276. u32 write_index;
  277. /* Offset in bytes from the start of ring data below */
  278. u32 read_index;
  279. u32 interrupt_mask;
  280. /*
  281. * Win8 uses some of the reserved bits to implement
  282. * interrupt driven flow management. On the send side
  283. * we can request that the receiver interrupt the sender
  284. * when the ring transitions from being full to being able
  285. * to handle a message of size "pending_send_sz".
  286. *
  287. * Add necessary state for this enhancement.
  288. */
  289. u32 pending_send_sz;
  290. u32 reserved1[12];
  291. union {
  292. struct {
  293. u32 feat_pending_send_sz:1;
  294. };
  295. u32 value;
  296. } feature_bits;
  297. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  298. u8 reserved2[4028];
  299. /*
  300. * Ring data starts here + RingDataStartOffset
  301. * !!! DO NOT place any fields below this !!!
  302. */
  303. u8 buffer[0];
  304. } __packed;
  305. struct hv_ring_buffer_info {
  306. struct hv_ring_buffer *ring_buffer;
  307. u32 ring_size; /* Include the shared header */
  308. spinlock_t ring_lock;
  309. u32 ring_datasize; /* < ring_size */
  310. u32 ring_data_startoffset;
  311. };
  312. struct hv_ring_buffer_debug_info {
  313. u32 current_interrupt_mask;
  314. u32 current_read_index;
  315. u32 current_write_index;
  316. u32 bytes_avail_toread;
  317. u32 bytes_avail_towrite;
  318. };
  319. /*
  320. *
  321. * hv_get_ringbuffer_availbytes()
  322. *
  323. * Get number of bytes available to read and to write to
  324. * for the specified ring buffer
  325. */
  326. static inline void
  327. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  328. u32 *read, u32 *write)
  329. {
  330. u32 read_loc, write_loc, dsize;
  331. smp_read_barrier_depends();
  332. /* Capture the read/write indices before they changed */
  333. read_loc = rbi->ring_buffer->read_index;
  334. write_loc = rbi->ring_buffer->write_index;
  335. dsize = rbi->ring_datasize;
  336. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  337. read_loc - write_loc;
  338. *read = dsize - *write;
  339. }
  340. /*
  341. * We use the same version numbering for all Hyper-V modules.
  342. *
  343. * Definition of versioning is as follows;
  344. *
  345. * Major Number Changes for these scenarios;
  346. * 1. When a new version of Windows Hyper-V
  347. * is released.
  348. * 2. A Major change has occurred in the
  349. * Linux IC's.
  350. * (For example the merge for the first time
  351. * into the kernel) Every time the Major Number
  352. * changes, the Revision number is reset to 0.
  353. * Minor Number Changes when new functionality is added
  354. * to the Linux IC's that is not a bug fix.
  355. *
  356. * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  357. */
  358. #define HV_DRV_VERSION "3.1"
  359. /*
  360. * VMBUS version is 32 bit entity broken up into
  361. * two 16 bit quantities: major_number. minor_number.
  362. *
  363. * 0 . 13 (Windows Server 2008)
  364. * 1 . 1 (Windows 7)
  365. * 2 . 4 (Windows 8)
  366. */
  367. #define VERSION_WS2008 ((0 << 16) | (13))
  368. #define VERSION_WIN7 ((1 << 16) | (1))
  369. #define VERSION_WIN8 ((2 << 16) | (4))
  370. #define VERSION_INVAL -1
  371. #define VERSION_CURRENT VERSION_WIN8
  372. /* Make maximum size of pipe payload of 16K */
  373. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  374. /* Define PipeMode values. */
  375. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  376. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  377. /* The size of the user defined data buffer for non-pipe offers. */
  378. #define MAX_USER_DEFINED_BYTES 120
  379. /* The size of the user defined data buffer for pipe offers. */
  380. #define MAX_PIPE_USER_DEFINED_BYTES 116
  381. /*
  382. * At the center of the Channel Management library is the Channel Offer. This
  383. * struct contains the fundamental information about an offer.
  384. */
  385. struct vmbus_channel_offer {
  386. uuid_le if_type;
  387. uuid_le if_instance;
  388. /*
  389. * These two fields are not currently used.
  390. */
  391. u64 reserved1;
  392. u64 reserved2;
  393. u16 chn_flags;
  394. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  395. union {
  396. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  397. struct {
  398. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  399. } std;
  400. /*
  401. * Pipes:
  402. * The following sructure is an integrated pipe protocol, which
  403. * is implemented on top of standard user-defined data. Pipe
  404. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  405. * use.
  406. */
  407. struct {
  408. u32 pipe_mode;
  409. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  410. } pipe;
  411. } u;
  412. /*
  413. * The sub_channel_index is defined in win8.
  414. */
  415. u16 sub_channel_index;
  416. u16 reserved3;
  417. } __packed;
  418. /* Server Flags */
  419. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  420. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  421. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  422. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  423. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  424. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  425. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  426. struct vmpacket_descriptor {
  427. u16 type;
  428. u16 offset8;
  429. u16 len8;
  430. u16 flags;
  431. u64 trans_id;
  432. } __packed;
  433. struct vmpacket_header {
  434. u32 prev_pkt_start_offset;
  435. struct vmpacket_descriptor descriptor;
  436. } __packed;
  437. struct vmtransfer_page_range {
  438. u32 byte_count;
  439. u32 byte_offset;
  440. } __packed;
  441. struct vmtransfer_page_packet_header {
  442. struct vmpacket_descriptor d;
  443. u16 xfer_pageset_id;
  444. u8 sender_owns_set;
  445. u8 reserved;
  446. u32 range_cnt;
  447. struct vmtransfer_page_range ranges[1];
  448. } __packed;
  449. struct vmgpadl_packet_header {
  450. struct vmpacket_descriptor d;
  451. u32 gpadl;
  452. u32 reserved;
  453. } __packed;
  454. struct vmadd_remove_transfer_page_set {
  455. struct vmpacket_descriptor d;
  456. u32 gpadl;
  457. u16 xfer_pageset_id;
  458. u16 reserved;
  459. } __packed;
  460. /*
  461. * This structure defines a range in guest physical space that can be made to
  462. * look virtually contiguous.
  463. */
  464. struct gpa_range {
  465. u32 byte_count;
  466. u32 byte_offset;
  467. u64 pfn_array[0];
  468. };
  469. /*
  470. * This is the format for an Establish Gpadl packet, which contains a handle by
  471. * which this GPADL will be known and a set of GPA ranges associated with it.
  472. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  473. * ranges, then the resulting MDL will be "chained," representing multiple VA
  474. * ranges.
  475. */
  476. struct vmestablish_gpadl {
  477. struct vmpacket_descriptor d;
  478. u32 gpadl;
  479. u32 range_cnt;
  480. struct gpa_range range[1];
  481. } __packed;
  482. /*
  483. * This is the format for a Teardown Gpadl packet, which indicates that the
  484. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  485. */
  486. struct vmteardown_gpadl {
  487. struct vmpacket_descriptor d;
  488. u32 gpadl;
  489. u32 reserved; /* for alignment to a 8-byte boundary */
  490. } __packed;
  491. /*
  492. * This is the format for a GPA-Direct packet, which contains a set of GPA
  493. * ranges, in addition to commands and/or data.
  494. */
  495. struct vmdata_gpa_direct {
  496. struct vmpacket_descriptor d;
  497. u32 reserved;
  498. u32 range_cnt;
  499. struct gpa_range range[1];
  500. } __packed;
  501. /* This is the format for a Additional Data Packet. */
  502. struct vmadditional_data {
  503. struct vmpacket_descriptor d;
  504. u64 total_bytes;
  505. u32 offset;
  506. u32 byte_cnt;
  507. unsigned char data[1];
  508. } __packed;
  509. union vmpacket_largest_possible_header {
  510. struct vmpacket_descriptor simple_hdr;
  511. struct vmtransfer_page_packet_header xfer_page_hdr;
  512. struct vmgpadl_packet_header gpadl_hdr;
  513. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  514. struct vmestablish_gpadl establish_gpadl_hdr;
  515. struct vmteardown_gpadl teardown_gpadl_hdr;
  516. struct vmdata_gpa_direct data_gpa_direct_hdr;
  517. };
  518. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  519. (void *)(((unsigned char *)__packet) + \
  520. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  521. #define VMPACKET_DATA_LENGTH(__packet) \
  522. ((((struct vmpacket_descriptor)__packet)->len8 - \
  523. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  524. #define VMPACKET_TRANSFER_MODE(__packet) \
  525. (((struct IMPACT)__packet)->type)
  526. enum vmbus_packet_type {
  527. VM_PKT_INVALID = 0x0,
  528. VM_PKT_SYNCH = 0x1,
  529. VM_PKT_ADD_XFER_PAGESET = 0x2,
  530. VM_PKT_RM_XFER_PAGESET = 0x3,
  531. VM_PKT_ESTABLISH_GPADL = 0x4,
  532. VM_PKT_TEARDOWN_GPADL = 0x5,
  533. VM_PKT_DATA_INBAND = 0x6,
  534. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  535. VM_PKT_DATA_USING_GPADL = 0x8,
  536. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  537. VM_PKT_CANCEL_REQUEST = 0xa,
  538. VM_PKT_COMP = 0xb,
  539. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  540. VM_PKT_ADDITIONAL_DATA = 0xd
  541. };
  542. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  543. /* Version 1 messages */
  544. enum vmbus_channel_message_type {
  545. CHANNELMSG_INVALID = 0,
  546. CHANNELMSG_OFFERCHANNEL = 1,
  547. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  548. CHANNELMSG_REQUESTOFFERS = 3,
  549. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  550. CHANNELMSG_OPENCHANNEL = 5,
  551. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  552. CHANNELMSG_CLOSECHANNEL = 7,
  553. CHANNELMSG_GPADL_HEADER = 8,
  554. CHANNELMSG_GPADL_BODY = 9,
  555. CHANNELMSG_GPADL_CREATED = 10,
  556. CHANNELMSG_GPADL_TEARDOWN = 11,
  557. CHANNELMSG_GPADL_TORNDOWN = 12,
  558. CHANNELMSG_RELID_RELEASED = 13,
  559. CHANNELMSG_INITIATE_CONTACT = 14,
  560. CHANNELMSG_VERSION_RESPONSE = 15,
  561. CHANNELMSG_UNLOAD = 16,
  562. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  563. CHANNELMSG_VIEWRANGE_ADD = 17,
  564. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  565. #endif
  566. CHANNELMSG_COUNT
  567. };
  568. struct vmbus_channel_message_header {
  569. enum vmbus_channel_message_type msgtype;
  570. u32 padding;
  571. } __packed;
  572. /* Query VMBus Version parameters */
  573. struct vmbus_channel_query_vmbus_version {
  574. struct vmbus_channel_message_header header;
  575. u32 version;
  576. } __packed;
  577. /* VMBus Version Supported parameters */
  578. struct vmbus_channel_version_supported {
  579. struct vmbus_channel_message_header header;
  580. u8 version_supported;
  581. } __packed;
  582. /* Offer Channel parameters */
  583. struct vmbus_channel_offer_channel {
  584. struct vmbus_channel_message_header header;
  585. struct vmbus_channel_offer offer;
  586. u32 child_relid;
  587. u8 monitorid;
  588. /*
  589. * win7 and beyond splits this field into a bit field.
  590. */
  591. u8 monitor_allocated:1;
  592. u8 reserved:7;
  593. /*
  594. * These are new fields added in win7 and later.
  595. * Do not access these fields without checking the
  596. * negotiated protocol.
  597. *
  598. * If "is_dedicated_interrupt" is set, we must not set the
  599. * associated bit in the channel bitmap while sending the
  600. * interrupt to the host.
  601. *
  602. * connection_id is to be used in signaling the host.
  603. */
  604. u16 is_dedicated_interrupt:1;
  605. u16 reserved1:15;
  606. u32 connection_id;
  607. } __packed;
  608. /* Rescind Offer parameters */
  609. struct vmbus_channel_rescind_offer {
  610. struct vmbus_channel_message_header header;
  611. u32 child_relid;
  612. } __packed;
  613. /*
  614. * Request Offer -- no parameters, SynIC message contains the partition ID
  615. * Set Snoop -- no parameters, SynIC message contains the partition ID
  616. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  617. * All Offers Delivered -- no parameters, SynIC message contains the partition
  618. * ID
  619. * Flush Client -- no parameters, SynIC message contains the partition ID
  620. */
  621. /* Open Channel parameters */
  622. struct vmbus_channel_open_channel {
  623. struct vmbus_channel_message_header header;
  624. /* Identifies the specific VMBus channel that is being opened. */
  625. u32 child_relid;
  626. /* ID making a particular open request at a channel offer unique. */
  627. u32 openid;
  628. /* GPADL for the channel's ring buffer. */
  629. u32 ringbuffer_gpadlhandle;
  630. /*
  631. * Starting with win8, this field will be used to specify
  632. * the target virtual processor on which to deliver the interrupt for
  633. * the host to guest communication.
  634. * Prior to win8, incoming channel interrupts would only
  635. * be delivered on cpu 0. Setting this value to 0 would
  636. * preserve the earlier behavior.
  637. */
  638. u32 target_vp;
  639. /*
  640. * The upstream ring buffer begins at offset zero in the memory
  641. * described by RingBufferGpadlHandle. The downstream ring buffer
  642. * follows it at this offset (in pages).
  643. */
  644. u32 downstream_ringbuffer_pageoffset;
  645. /* User-specific data to be passed along to the server endpoint. */
  646. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  647. } __packed;
  648. /* Open Channel Result parameters */
  649. struct vmbus_channel_open_result {
  650. struct vmbus_channel_message_header header;
  651. u32 child_relid;
  652. u32 openid;
  653. u32 status;
  654. } __packed;
  655. /* Close channel parameters; */
  656. struct vmbus_channel_close_channel {
  657. struct vmbus_channel_message_header header;
  658. u32 child_relid;
  659. } __packed;
  660. /* Channel Message GPADL */
  661. #define GPADL_TYPE_RING_BUFFER 1
  662. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  663. #define GPADL_TYPE_TRANSACTION 8
  664. /*
  665. * The number of PFNs in a GPADL message is defined by the number of
  666. * pages that would be spanned by ByteCount and ByteOffset. If the
  667. * implied number of PFNs won't fit in this packet, there will be a
  668. * follow-up packet that contains more.
  669. */
  670. struct vmbus_channel_gpadl_header {
  671. struct vmbus_channel_message_header header;
  672. u32 child_relid;
  673. u32 gpadl;
  674. u16 range_buflen;
  675. u16 rangecount;
  676. struct gpa_range range[0];
  677. } __packed;
  678. /* This is the followup packet that contains more PFNs. */
  679. struct vmbus_channel_gpadl_body {
  680. struct vmbus_channel_message_header header;
  681. u32 msgnumber;
  682. u32 gpadl;
  683. u64 pfn[0];
  684. } __packed;
  685. struct vmbus_channel_gpadl_created {
  686. struct vmbus_channel_message_header header;
  687. u32 child_relid;
  688. u32 gpadl;
  689. u32 creation_status;
  690. } __packed;
  691. struct vmbus_channel_gpadl_teardown {
  692. struct vmbus_channel_message_header header;
  693. u32 child_relid;
  694. u32 gpadl;
  695. } __packed;
  696. struct vmbus_channel_gpadl_torndown {
  697. struct vmbus_channel_message_header header;
  698. u32 gpadl;
  699. } __packed;
  700. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  701. struct vmbus_channel_view_range_add {
  702. struct vmbus_channel_message_header header;
  703. PHYSICAL_ADDRESS viewrange_base;
  704. u64 viewrange_length;
  705. u32 child_relid;
  706. } __packed;
  707. struct vmbus_channel_view_range_remove {
  708. struct vmbus_channel_message_header header;
  709. PHYSICAL_ADDRESS viewrange_base;
  710. u32 child_relid;
  711. } __packed;
  712. #endif
  713. struct vmbus_channel_relid_released {
  714. struct vmbus_channel_message_header header;
  715. u32 child_relid;
  716. } __packed;
  717. struct vmbus_channel_initiate_contact {
  718. struct vmbus_channel_message_header header;
  719. u32 vmbus_version_requested;
  720. u32 padding2;
  721. u64 interrupt_page;
  722. u64 monitor_page1;
  723. u64 monitor_page2;
  724. } __packed;
  725. struct vmbus_channel_version_response {
  726. struct vmbus_channel_message_header header;
  727. u8 version_supported;
  728. } __packed;
  729. enum vmbus_channel_state {
  730. CHANNEL_OFFER_STATE,
  731. CHANNEL_OPENING_STATE,
  732. CHANNEL_OPEN_STATE,
  733. };
  734. struct vmbus_channel_debug_info {
  735. u32 relid;
  736. enum vmbus_channel_state state;
  737. uuid_le interfacetype;
  738. uuid_le interface_instance;
  739. u32 monitorid;
  740. u32 servermonitor_pending;
  741. u32 servermonitor_latency;
  742. u32 servermonitor_connectionid;
  743. u32 clientmonitor_pending;
  744. u32 clientmonitor_latency;
  745. u32 clientmonitor_connectionid;
  746. struct hv_ring_buffer_debug_info inbound;
  747. struct hv_ring_buffer_debug_info outbound;
  748. };
  749. /*
  750. * Represents each channel msg on the vmbus connection This is a
  751. * variable-size data structure depending on the msg type itself
  752. */
  753. struct vmbus_channel_msginfo {
  754. /* Bookkeeping stuff */
  755. struct list_head msglistentry;
  756. /* So far, this is only used to handle gpadl body message */
  757. struct list_head submsglist;
  758. /* Synchronize the request/response if needed */
  759. struct completion waitevent;
  760. union {
  761. struct vmbus_channel_version_supported version_supported;
  762. struct vmbus_channel_open_result open_result;
  763. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  764. struct vmbus_channel_gpadl_created gpadl_created;
  765. struct vmbus_channel_version_response version_response;
  766. } response;
  767. u32 msgsize;
  768. /*
  769. * The channel message that goes out on the "wire".
  770. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  771. */
  772. unsigned char msg[0];
  773. };
  774. struct vmbus_close_msg {
  775. struct vmbus_channel_msginfo info;
  776. struct vmbus_channel_close_channel msg;
  777. };
  778. /* Define connection identifier type. */
  779. union hv_connection_id {
  780. u32 asu32;
  781. struct {
  782. u32 id:24;
  783. u32 reserved:8;
  784. } u;
  785. };
  786. /* Definition of the hv_signal_event hypercall input structure. */
  787. struct hv_input_signal_event {
  788. union hv_connection_id connectionid;
  789. u16 flag_number;
  790. u16 rsvdz;
  791. };
  792. struct hv_input_signal_event_buffer {
  793. u64 align8;
  794. struct hv_input_signal_event event;
  795. };
  796. struct vmbus_channel {
  797. struct list_head listentry;
  798. struct hv_device *device_obj;
  799. struct work_struct work;
  800. enum vmbus_channel_state state;
  801. struct vmbus_channel_offer_channel offermsg;
  802. /*
  803. * These are based on the OfferMsg.MonitorId.
  804. * Save it here for easy access.
  805. */
  806. u8 monitor_grp;
  807. u8 monitor_bit;
  808. u32 ringbuffer_gpadlhandle;
  809. /* Allocated memory for ring buffer */
  810. void *ringbuffer_pages;
  811. u32 ringbuffer_pagecount;
  812. struct hv_ring_buffer_info outbound; /* send to parent */
  813. struct hv_ring_buffer_info inbound; /* receive from parent */
  814. spinlock_t inbound_lock;
  815. struct workqueue_struct *controlwq;
  816. struct vmbus_close_msg close_msg;
  817. /* Channel callback are invoked in this workqueue context */
  818. /* HANDLE dataWorkQueue; */
  819. void (*onchannel_callback)(void *context);
  820. void *channel_callback_context;
  821. /*
  822. * A channel can be marked for efficient (batched)
  823. * reading:
  824. * If batched_reading is set to "true", we read until the
  825. * channel is empty and hold off interrupts from the host
  826. * during the entire read process.
  827. * If batched_reading is set to "false", the client is not
  828. * going to perform batched reading.
  829. *
  830. * By default we will enable batched reading; specific
  831. * drivers that don't want this behavior can turn it off.
  832. */
  833. bool batched_reading;
  834. bool is_dedicated_interrupt;
  835. struct hv_input_signal_event_buffer sig_buf;
  836. struct hv_input_signal_event *sig_event;
  837. /*
  838. * Starting with win8, this field will be used to specify
  839. * the target virtual processor on which to deliver the interrupt for
  840. * the host to guest communication.
  841. * Prior to win8, incoming channel interrupts would only
  842. * be delivered on cpu 0. Setting this value to 0 would
  843. * preserve the earlier behavior.
  844. */
  845. u32 target_vp;
  846. };
  847. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  848. {
  849. c->batched_reading = state;
  850. }
  851. void vmbus_onmessage(void *context);
  852. int vmbus_request_offers(void);
  853. /* The format must be the same as struct vmdata_gpa_direct */
  854. struct vmbus_channel_packet_page_buffer {
  855. u16 type;
  856. u16 dataoffset8;
  857. u16 length8;
  858. u16 flags;
  859. u64 transactionid;
  860. u32 reserved;
  861. u32 rangecount;
  862. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  863. } __packed;
  864. /* The format must be the same as struct vmdata_gpa_direct */
  865. struct vmbus_channel_packet_multipage_buffer {
  866. u16 type;
  867. u16 dataoffset8;
  868. u16 length8;
  869. u16 flags;
  870. u64 transactionid;
  871. u32 reserved;
  872. u32 rangecount; /* Always 1 in this case */
  873. struct hv_multipage_buffer range;
  874. } __packed;
  875. extern int vmbus_open(struct vmbus_channel *channel,
  876. u32 send_ringbuffersize,
  877. u32 recv_ringbuffersize,
  878. void *userdata,
  879. u32 userdatalen,
  880. void(*onchannel_callback)(void *context),
  881. void *context);
  882. extern void vmbus_close(struct vmbus_channel *channel);
  883. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  884. const void *buffer,
  885. u32 bufferLen,
  886. u64 requestid,
  887. enum vmbus_packet_type type,
  888. u32 flags);
  889. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  890. struct hv_page_buffer pagebuffers[],
  891. u32 pagecount,
  892. void *buffer,
  893. u32 bufferlen,
  894. u64 requestid);
  895. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  896. struct hv_multipage_buffer *mpb,
  897. void *buffer,
  898. u32 bufferlen,
  899. u64 requestid);
  900. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  901. void *kbuffer,
  902. u32 size,
  903. u32 *gpadl_handle);
  904. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  905. u32 gpadl_handle);
  906. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  907. void *buffer,
  908. u32 bufferlen,
  909. u32 *buffer_actual_len,
  910. u64 *requestid);
  911. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  912. void *buffer,
  913. u32 bufferlen,
  914. u32 *buffer_actual_len,
  915. u64 *requestid);
  916. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  917. struct vmbus_channel_debug_info *debug);
  918. extern void vmbus_ontimer(unsigned long data);
  919. struct hv_dev_port_info {
  920. u32 int_mask;
  921. u32 read_idx;
  922. u32 write_idx;
  923. u32 bytes_avail_toread;
  924. u32 bytes_avail_towrite;
  925. };
  926. /* Base driver object */
  927. struct hv_driver {
  928. const char *name;
  929. /* the device type supported by this driver */
  930. uuid_le dev_type;
  931. const struct hv_vmbus_device_id *id_table;
  932. struct device_driver driver;
  933. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  934. int (*remove)(struct hv_device *);
  935. void (*shutdown)(struct hv_device *);
  936. };
  937. /* Base device object */
  938. struct hv_device {
  939. /* the device type id of this device */
  940. uuid_le dev_type;
  941. /* the device instance id of this device */
  942. uuid_le dev_instance;
  943. struct device device;
  944. struct vmbus_channel *channel;
  945. };
  946. static inline struct hv_device *device_to_hv_device(struct device *d)
  947. {
  948. return container_of(d, struct hv_device, device);
  949. }
  950. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  951. {
  952. return container_of(d, struct hv_driver, driver);
  953. }
  954. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  955. {
  956. dev_set_drvdata(&dev->device, data);
  957. }
  958. static inline void *hv_get_drvdata(struct hv_device *dev)
  959. {
  960. return dev_get_drvdata(&dev->device);
  961. }
  962. /* Vmbus interface */
  963. #define vmbus_driver_register(driver) \
  964. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  965. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  966. struct module *owner,
  967. const char *mod_name);
  968. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  969. /**
  970. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  971. *
  972. * This macro is used to create a struct hv_vmbus_device_id that matches a
  973. * specific device.
  974. */
  975. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  976. g8, g9, ga, gb, gc, gd, ge, gf) \
  977. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  978. g8, g9, ga, gb, gc, gd, ge, gf },
  979. /*
  980. * GUID definitions of various offer types - services offered to the guest.
  981. */
  982. /*
  983. * Network GUID
  984. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  985. */
  986. #define HV_NIC_GUID \
  987. .guid = { \
  988. 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
  989. 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
  990. }
  991. /*
  992. * IDE GUID
  993. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  994. */
  995. #define HV_IDE_GUID \
  996. .guid = { \
  997. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
  998. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
  999. }
  1000. /*
  1001. * SCSI GUID
  1002. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  1003. */
  1004. #define HV_SCSI_GUID \
  1005. .guid = { \
  1006. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
  1007. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
  1008. }
  1009. /*
  1010. * Shutdown GUID
  1011. * {0e0b6031-5213-4934-818b-38d90ced39db}
  1012. */
  1013. #define HV_SHUTDOWN_GUID \
  1014. .guid = { \
  1015. 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
  1016. 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
  1017. }
  1018. /*
  1019. * Time Synch GUID
  1020. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  1021. */
  1022. #define HV_TS_GUID \
  1023. .guid = { \
  1024. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
  1025. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
  1026. }
  1027. /*
  1028. * Heartbeat GUID
  1029. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  1030. */
  1031. #define HV_HEART_BEAT_GUID \
  1032. .guid = { \
  1033. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
  1034. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
  1035. }
  1036. /*
  1037. * KVP GUID
  1038. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1039. */
  1040. #define HV_KVP_GUID \
  1041. .guid = { \
  1042. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
  1043. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
  1044. }
  1045. /*
  1046. * Dynamic memory GUID
  1047. * {525074dc-8985-46e2-8057-a307dc18a502}
  1048. */
  1049. #define HV_DM_GUID \
  1050. .guid = { \
  1051. 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
  1052. 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
  1053. }
  1054. /*
  1055. * Mouse GUID
  1056. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1057. */
  1058. #define HV_MOUSE_GUID \
  1059. .guid = { \
  1060. 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
  1061. 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
  1062. }
  1063. /*
  1064. * Common header for Hyper-V ICs
  1065. */
  1066. #define ICMSGTYPE_NEGOTIATE 0
  1067. #define ICMSGTYPE_HEARTBEAT 1
  1068. #define ICMSGTYPE_KVPEXCHANGE 2
  1069. #define ICMSGTYPE_SHUTDOWN 3
  1070. #define ICMSGTYPE_TIMESYNC 4
  1071. #define ICMSGTYPE_VSS 5
  1072. #define ICMSGHDRFLAG_TRANSACTION 1
  1073. #define ICMSGHDRFLAG_REQUEST 2
  1074. #define ICMSGHDRFLAG_RESPONSE 4
  1075. /*
  1076. * While we want to handle util services as regular devices,
  1077. * there is only one instance of each of these services; so
  1078. * we statically allocate the service specific state.
  1079. */
  1080. struct hv_util_service {
  1081. u8 *recv_buffer;
  1082. void (*util_cb)(void *);
  1083. int (*util_init)(struct hv_util_service *);
  1084. void (*util_deinit)(void);
  1085. };
  1086. struct vmbuspipe_hdr {
  1087. u32 flags;
  1088. u32 msgsize;
  1089. } __packed;
  1090. struct ic_version {
  1091. u16 major;
  1092. u16 minor;
  1093. } __packed;
  1094. struct icmsg_hdr {
  1095. struct ic_version icverframe;
  1096. u16 icmsgtype;
  1097. struct ic_version icvermsg;
  1098. u16 icmsgsize;
  1099. u32 status;
  1100. u8 ictransaction_id;
  1101. u8 icflags;
  1102. u8 reserved[2];
  1103. } __packed;
  1104. struct icmsg_negotiate {
  1105. u16 icframe_vercnt;
  1106. u16 icmsg_vercnt;
  1107. u32 reserved;
  1108. struct ic_version icversion_data[1]; /* any size array */
  1109. } __packed;
  1110. struct shutdown_msg_data {
  1111. u32 reason_code;
  1112. u32 timeout_seconds;
  1113. u32 flags;
  1114. u8 display_message[2048];
  1115. } __packed;
  1116. struct heartbeat_msg_data {
  1117. u64 seq_num;
  1118. u32 reserved[8];
  1119. } __packed;
  1120. /* Time Sync IC defs */
  1121. #define ICTIMESYNCFLAG_PROBE 0
  1122. #define ICTIMESYNCFLAG_SYNC 1
  1123. #define ICTIMESYNCFLAG_SAMPLE 2
  1124. #ifdef __x86_64__
  1125. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1126. #else
  1127. #define WLTIMEDELTA 116444736000000000LL
  1128. #endif
  1129. struct ictimesync_data {
  1130. u64 parenttime;
  1131. u64 childtime;
  1132. u64 roundtriptime;
  1133. u8 flags;
  1134. } __packed;
  1135. struct hyperv_service_callback {
  1136. u8 msg_type;
  1137. char *log_msg;
  1138. uuid_le data;
  1139. struct vmbus_channel *channel;
  1140. void (*callback) (void *context);
  1141. };
  1142. #define MAX_SRV_VER 0x7ffffff
  1143. extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1144. struct icmsg_negotiate *, u8 *, int,
  1145. int);
  1146. int hv_kvp_init(struct hv_util_service *);
  1147. void hv_kvp_deinit(void);
  1148. void hv_kvp_onchannelcallback(void *);
  1149. /*
  1150. * Negotiated version with the Host.
  1151. */
  1152. extern __u32 vmbus_proto_version;
  1153. #endif /* __KERNEL__ */
  1154. #endif /* _HYPERV_H */