hyperv.h 38 KB

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