hyperv.h 38 KB

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