hyperv.h 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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 servermonitor_latency;
  770. u32 servermonitor_connectionid;
  771. u32 clientmonitor_latency;
  772. u32 clientmonitor_connectionid;
  773. struct hv_ring_buffer_debug_info inbound;
  774. struct hv_ring_buffer_debug_info outbound;
  775. };
  776. /*
  777. * Represents each channel msg on the vmbus connection This is a
  778. * variable-size data structure depending on the msg type itself
  779. */
  780. struct vmbus_channel_msginfo {
  781. /* Bookkeeping stuff */
  782. struct list_head msglistentry;
  783. /* So far, this is only used to handle gpadl body message */
  784. struct list_head submsglist;
  785. /* Synchronize the request/response if needed */
  786. struct completion waitevent;
  787. union {
  788. struct vmbus_channel_version_supported version_supported;
  789. struct vmbus_channel_open_result open_result;
  790. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  791. struct vmbus_channel_gpadl_created gpadl_created;
  792. struct vmbus_channel_version_response version_response;
  793. } response;
  794. u32 msgsize;
  795. /*
  796. * The channel message that goes out on the "wire".
  797. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  798. */
  799. unsigned char msg[0];
  800. };
  801. struct vmbus_close_msg {
  802. struct vmbus_channel_msginfo info;
  803. struct vmbus_channel_close_channel msg;
  804. };
  805. /* Define connection identifier type. */
  806. union hv_connection_id {
  807. u32 asu32;
  808. struct {
  809. u32 id:24;
  810. u32 reserved:8;
  811. } u;
  812. };
  813. /* Definition of the hv_signal_event hypercall input structure. */
  814. struct hv_input_signal_event {
  815. union hv_connection_id connectionid;
  816. u16 flag_number;
  817. u16 rsvdz;
  818. };
  819. struct hv_input_signal_event_buffer {
  820. u64 align8;
  821. struct hv_input_signal_event event;
  822. };
  823. struct vmbus_channel {
  824. struct list_head listentry;
  825. struct hv_device *device_obj;
  826. struct work_struct work;
  827. enum vmbus_channel_state state;
  828. struct vmbus_channel_offer_channel offermsg;
  829. /*
  830. * These are based on the OfferMsg.MonitorId.
  831. * Save it here for easy access.
  832. */
  833. u8 monitor_grp;
  834. u8 monitor_bit;
  835. u32 ringbuffer_gpadlhandle;
  836. /* Allocated memory for ring buffer */
  837. void *ringbuffer_pages;
  838. u32 ringbuffer_pagecount;
  839. struct hv_ring_buffer_info outbound; /* send to parent */
  840. struct hv_ring_buffer_info inbound; /* receive from parent */
  841. spinlock_t inbound_lock;
  842. struct workqueue_struct *controlwq;
  843. struct vmbus_close_msg close_msg;
  844. /* Channel callback are invoked in this workqueue context */
  845. /* HANDLE dataWorkQueue; */
  846. void (*onchannel_callback)(void *context);
  847. void *channel_callback_context;
  848. /*
  849. * A channel can be marked for efficient (batched)
  850. * reading:
  851. * If batched_reading is set to "true", we read until the
  852. * channel is empty and hold off interrupts from the host
  853. * during the entire read process.
  854. * If batched_reading is set to "false", the client is not
  855. * going to perform batched reading.
  856. *
  857. * By default we will enable batched reading; specific
  858. * drivers that don't want this behavior can turn it off.
  859. */
  860. bool batched_reading;
  861. bool is_dedicated_interrupt;
  862. struct hv_input_signal_event_buffer sig_buf;
  863. struct hv_input_signal_event *sig_event;
  864. /*
  865. * Starting with win8, this field will be used to specify
  866. * the target virtual processor on which to deliver the interrupt for
  867. * the host to guest communication.
  868. * Prior to win8, incoming channel interrupts would only
  869. * be delivered on cpu 0. Setting this value to 0 would
  870. * preserve the earlier behavior.
  871. */
  872. u32 target_vp;
  873. /*
  874. * Support for sub-channels. For high performance devices,
  875. * it will be useful to have multiple sub-channels to support
  876. * a scalable communication infrastructure with the host.
  877. * The support for sub-channels is implemented as an extention
  878. * to the current infrastructure.
  879. * The initial offer is considered the primary channel and this
  880. * offer message will indicate if the host supports sub-channels.
  881. * The guest is free to ask for sub-channels to be offerred and can
  882. * open these sub-channels as a normal "primary" channel. However,
  883. * all sub-channels will have the same type and instance guids as the
  884. * primary channel. Requests sent on a given channel will result in a
  885. * response on the same channel.
  886. */
  887. /*
  888. * Sub-channel creation callback. This callback will be called in
  889. * process context when a sub-channel offer is received from the host.
  890. * The guest can open the sub-channel in the context of this callback.
  891. */
  892. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  893. spinlock_t sc_lock;
  894. /*
  895. * All Sub-channels of a primary channel are linked here.
  896. */
  897. struct list_head sc_list;
  898. /*
  899. * The primary channel this sub-channel belongs to.
  900. * This will be NULL for the primary channel.
  901. */
  902. struct vmbus_channel *primary_channel;
  903. };
  904. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  905. {
  906. c->batched_reading = state;
  907. }
  908. void vmbus_onmessage(void *context);
  909. int vmbus_request_offers(void);
  910. /*
  911. * APIs for managing sub-channels.
  912. */
  913. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  914. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  915. /*
  916. * Retrieve the (sub) channel on which to send an outgoing request.
  917. * When a primary channel has multiple sub-channels, we choose a
  918. * channel whose VCPU binding is closest to the VCPU on which
  919. * this call is being made.
  920. */
  921. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  922. /*
  923. * Check if sub-channels have already been offerred. This API will be useful
  924. * when the driver is unloaded after establishing sub-channels. In this case,
  925. * when the driver is re-loaded, the driver would have to check if the
  926. * subchannels have already been established before attempting to request
  927. * the creation of sub-channels.
  928. * This function returns TRUE to indicate that subchannels have already been
  929. * created.
  930. * This function should be invoked after setting the callback function for
  931. * sub-channel creation.
  932. */
  933. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  934. /* The format must be the same as struct vmdata_gpa_direct */
  935. struct vmbus_channel_packet_page_buffer {
  936. u16 type;
  937. u16 dataoffset8;
  938. u16 length8;
  939. u16 flags;
  940. u64 transactionid;
  941. u32 reserved;
  942. u32 rangecount;
  943. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  944. } __packed;
  945. /* The format must be the same as struct vmdata_gpa_direct */
  946. struct vmbus_channel_packet_multipage_buffer {
  947. u16 type;
  948. u16 dataoffset8;
  949. u16 length8;
  950. u16 flags;
  951. u64 transactionid;
  952. u32 reserved;
  953. u32 rangecount; /* Always 1 in this case */
  954. struct hv_multipage_buffer range;
  955. } __packed;
  956. extern int vmbus_open(struct vmbus_channel *channel,
  957. u32 send_ringbuffersize,
  958. u32 recv_ringbuffersize,
  959. void *userdata,
  960. u32 userdatalen,
  961. void(*onchannel_callback)(void *context),
  962. void *context);
  963. extern void vmbus_close(struct vmbus_channel *channel);
  964. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  965. const void *buffer,
  966. u32 bufferLen,
  967. u64 requestid,
  968. enum vmbus_packet_type type,
  969. u32 flags);
  970. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  971. struct hv_page_buffer pagebuffers[],
  972. u32 pagecount,
  973. void *buffer,
  974. u32 bufferlen,
  975. u64 requestid);
  976. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  977. struct hv_multipage_buffer *mpb,
  978. void *buffer,
  979. u32 bufferlen,
  980. u64 requestid);
  981. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  982. void *kbuffer,
  983. u32 size,
  984. u32 *gpadl_handle);
  985. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  986. u32 gpadl_handle);
  987. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  988. void *buffer,
  989. u32 bufferlen,
  990. u32 *buffer_actual_len,
  991. u64 *requestid);
  992. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  993. void *buffer,
  994. u32 bufferlen,
  995. u32 *buffer_actual_len,
  996. u64 *requestid);
  997. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  998. struct vmbus_channel_debug_info *debug);
  999. extern void vmbus_ontimer(unsigned long data);
  1000. struct hv_dev_port_info {
  1001. u32 int_mask;
  1002. u32 read_idx;
  1003. u32 write_idx;
  1004. u32 bytes_avail_toread;
  1005. u32 bytes_avail_towrite;
  1006. };
  1007. /* Base driver object */
  1008. struct hv_driver {
  1009. const char *name;
  1010. /* the device type supported by this driver */
  1011. uuid_le dev_type;
  1012. const struct hv_vmbus_device_id *id_table;
  1013. struct device_driver driver;
  1014. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  1015. int (*remove)(struct hv_device *);
  1016. void (*shutdown)(struct hv_device *);
  1017. };
  1018. /* Base device object */
  1019. struct hv_device {
  1020. /* the device type id of this device */
  1021. uuid_le dev_type;
  1022. /* the device instance id of this device */
  1023. uuid_le dev_instance;
  1024. struct device device;
  1025. struct vmbus_channel *channel;
  1026. };
  1027. static inline struct hv_device *device_to_hv_device(struct device *d)
  1028. {
  1029. return container_of(d, struct hv_device, device);
  1030. }
  1031. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  1032. {
  1033. return container_of(d, struct hv_driver, driver);
  1034. }
  1035. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  1036. {
  1037. dev_set_drvdata(&dev->device, data);
  1038. }
  1039. static inline void *hv_get_drvdata(struct hv_device *dev)
  1040. {
  1041. return dev_get_drvdata(&dev->device);
  1042. }
  1043. /* Vmbus interface */
  1044. #define vmbus_driver_register(driver) \
  1045. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  1046. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  1047. struct module *owner,
  1048. const char *mod_name);
  1049. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  1050. /**
  1051. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  1052. *
  1053. * This macro is used to create a struct hv_vmbus_device_id that matches a
  1054. * specific device.
  1055. */
  1056. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  1057. g8, g9, ga, gb, gc, gd, ge, gf) \
  1058. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  1059. g8, g9, ga, gb, gc, gd, ge, gf },
  1060. /*
  1061. * GUID definitions of various offer types - services offered to the guest.
  1062. */
  1063. /*
  1064. * Network GUID
  1065. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  1066. */
  1067. #define HV_NIC_GUID \
  1068. .guid = { \
  1069. 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
  1070. 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
  1071. }
  1072. /*
  1073. * IDE GUID
  1074. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  1075. */
  1076. #define HV_IDE_GUID \
  1077. .guid = { \
  1078. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
  1079. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
  1080. }
  1081. /*
  1082. * SCSI GUID
  1083. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  1084. */
  1085. #define HV_SCSI_GUID \
  1086. .guid = { \
  1087. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
  1088. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
  1089. }
  1090. /*
  1091. * Shutdown GUID
  1092. * {0e0b6031-5213-4934-818b-38d90ced39db}
  1093. */
  1094. #define HV_SHUTDOWN_GUID \
  1095. .guid = { \
  1096. 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
  1097. 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
  1098. }
  1099. /*
  1100. * Time Synch GUID
  1101. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  1102. */
  1103. #define HV_TS_GUID \
  1104. .guid = { \
  1105. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
  1106. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
  1107. }
  1108. /*
  1109. * Heartbeat GUID
  1110. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  1111. */
  1112. #define HV_HEART_BEAT_GUID \
  1113. .guid = { \
  1114. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
  1115. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
  1116. }
  1117. /*
  1118. * KVP GUID
  1119. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1120. */
  1121. #define HV_KVP_GUID \
  1122. .guid = { \
  1123. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
  1124. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
  1125. }
  1126. /*
  1127. * Dynamic memory GUID
  1128. * {525074dc-8985-46e2-8057-a307dc18a502}
  1129. */
  1130. #define HV_DM_GUID \
  1131. .guid = { \
  1132. 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
  1133. 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
  1134. }
  1135. /*
  1136. * Mouse GUID
  1137. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1138. */
  1139. #define HV_MOUSE_GUID \
  1140. .guid = { \
  1141. 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
  1142. 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
  1143. }
  1144. /*
  1145. * VSS (Backup/Restore) GUID
  1146. */
  1147. #define HV_VSS_GUID \
  1148. .guid = { \
  1149. 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
  1150. 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
  1151. }
  1152. /*
  1153. * Synthetic Video GUID
  1154. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1155. */
  1156. #define HV_SYNTHVID_GUID \
  1157. .guid = { \
  1158. 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
  1159. 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
  1160. }
  1161. /*
  1162. * Synthetic FC GUID
  1163. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1164. */
  1165. #define HV_SYNTHFC_GUID \
  1166. .guid = { \
  1167. 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
  1168. 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
  1169. }
  1170. /*
  1171. * Common header for Hyper-V ICs
  1172. */
  1173. #define ICMSGTYPE_NEGOTIATE 0
  1174. #define ICMSGTYPE_HEARTBEAT 1
  1175. #define ICMSGTYPE_KVPEXCHANGE 2
  1176. #define ICMSGTYPE_SHUTDOWN 3
  1177. #define ICMSGTYPE_TIMESYNC 4
  1178. #define ICMSGTYPE_VSS 5
  1179. #define ICMSGHDRFLAG_TRANSACTION 1
  1180. #define ICMSGHDRFLAG_REQUEST 2
  1181. #define ICMSGHDRFLAG_RESPONSE 4
  1182. /*
  1183. * While we want to handle util services as regular devices,
  1184. * there is only one instance of each of these services; so
  1185. * we statically allocate the service specific state.
  1186. */
  1187. struct hv_util_service {
  1188. u8 *recv_buffer;
  1189. void (*util_cb)(void *);
  1190. int (*util_init)(struct hv_util_service *);
  1191. void (*util_deinit)(void);
  1192. };
  1193. struct vmbuspipe_hdr {
  1194. u32 flags;
  1195. u32 msgsize;
  1196. } __packed;
  1197. struct ic_version {
  1198. u16 major;
  1199. u16 minor;
  1200. } __packed;
  1201. struct icmsg_hdr {
  1202. struct ic_version icverframe;
  1203. u16 icmsgtype;
  1204. struct ic_version icvermsg;
  1205. u16 icmsgsize;
  1206. u32 status;
  1207. u8 ictransaction_id;
  1208. u8 icflags;
  1209. u8 reserved[2];
  1210. } __packed;
  1211. struct icmsg_negotiate {
  1212. u16 icframe_vercnt;
  1213. u16 icmsg_vercnt;
  1214. u32 reserved;
  1215. struct ic_version icversion_data[1]; /* any size array */
  1216. } __packed;
  1217. struct shutdown_msg_data {
  1218. u32 reason_code;
  1219. u32 timeout_seconds;
  1220. u32 flags;
  1221. u8 display_message[2048];
  1222. } __packed;
  1223. struct heartbeat_msg_data {
  1224. u64 seq_num;
  1225. u32 reserved[8];
  1226. } __packed;
  1227. /* Time Sync IC defs */
  1228. #define ICTIMESYNCFLAG_PROBE 0
  1229. #define ICTIMESYNCFLAG_SYNC 1
  1230. #define ICTIMESYNCFLAG_SAMPLE 2
  1231. #ifdef __x86_64__
  1232. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1233. #else
  1234. #define WLTIMEDELTA 116444736000000000LL
  1235. #endif
  1236. struct ictimesync_data {
  1237. u64 parenttime;
  1238. u64 childtime;
  1239. u64 roundtriptime;
  1240. u8 flags;
  1241. } __packed;
  1242. struct hyperv_service_callback {
  1243. u8 msg_type;
  1244. char *log_msg;
  1245. uuid_le data;
  1246. struct vmbus_channel *channel;
  1247. void (*callback) (void *context);
  1248. };
  1249. #define MAX_SRV_VER 0x7ffffff
  1250. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1251. struct icmsg_negotiate *, u8 *, int,
  1252. int);
  1253. int hv_kvp_init(struct hv_util_service *);
  1254. void hv_kvp_deinit(void);
  1255. void hv_kvp_onchannelcallback(void *);
  1256. int hv_vss_init(struct hv_util_service *);
  1257. void hv_vss_deinit(void);
  1258. void hv_vss_onchannelcallback(void *);
  1259. /*
  1260. * Negotiated version with the Host.
  1261. */
  1262. extern __u32 vmbus_proto_version;
  1263. #endif /* __KERNEL__ */
  1264. #endif /* _HYPERV_H */