hyperv.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  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 <uapi/linux/hyperv.h>
  27. #include <uapi/asm/hyperv.h>
  28. #include <linux/types.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/list.h>
  31. #include <linux/timer.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/completion.h>
  34. #include <linux/device.h>
  35. #include <linux/mod_devicetable.h>
  36. #define MAX_PAGE_BUFFER_COUNT 32
  37. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  38. #pragma pack(push, 1)
  39. /* Single-page buffer */
  40. struct hv_page_buffer {
  41. u32 len;
  42. u32 offset;
  43. u64 pfn;
  44. };
  45. /* Multiple-page buffer */
  46. struct hv_multipage_buffer {
  47. /* Length and Offset determines the # of pfns in the array */
  48. u32 len;
  49. u32 offset;
  50. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  51. };
  52. /*
  53. * Multiple-page buffer array; the pfn array is variable size:
  54. * The number of entries in the PFN array is determined by
  55. * "len" and "offset".
  56. */
  57. struct hv_mpb_array {
  58. /* Length and Offset determines the # of pfns in the array */
  59. u32 len;
  60. u32 offset;
  61. u64 pfn_array[];
  62. };
  63. /* 0x18 includes the proprietary packet header */
  64. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  65. (sizeof(struct hv_page_buffer) * \
  66. MAX_PAGE_BUFFER_COUNT))
  67. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  68. sizeof(struct hv_multipage_buffer))
  69. #pragma pack(pop)
  70. struct hv_ring_buffer {
  71. /* Offset in bytes from the start of ring data below */
  72. u32 write_index;
  73. /* Offset in bytes from the start of ring data below */
  74. u32 read_index;
  75. u32 interrupt_mask;
  76. /*
  77. * Win8 uses some of the reserved bits to implement
  78. * interrupt driven flow management. On the send side
  79. * we can request that the receiver interrupt the sender
  80. * when the ring transitions from being full to being able
  81. * to handle a message of size "pending_send_sz".
  82. *
  83. * Add necessary state for this enhancement.
  84. */
  85. u32 pending_send_sz;
  86. u32 reserved1[12];
  87. union {
  88. struct {
  89. u32 feat_pending_send_sz:1;
  90. };
  91. u32 value;
  92. } feature_bits;
  93. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  94. u8 reserved2[4028];
  95. /*
  96. * Ring data starts here + RingDataStartOffset
  97. * !!! DO NOT place any fields below this !!!
  98. */
  99. u8 buffer[0];
  100. } __packed;
  101. struct hv_ring_buffer_info {
  102. struct hv_ring_buffer *ring_buffer;
  103. u32 ring_size; /* Include the shared header */
  104. spinlock_t ring_lock;
  105. u32 ring_datasize; /* < ring_size */
  106. u32 ring_data_startoffset;
  107. };
  108. /*
  109. *
  110. * hv_get_ringbuffer_availbytes()
  111. *
  112. * Get number of bytes available to read and to write to
  113. * for the specified ring buffer
  114. */
  115. static inline void
  116. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  117. u32 *read, u32 *write)
  118. {
  119. u32 read_loc, write_loc, dsize;
  120. /* Capture the read/write indices before they changed */
  121. read_loc = rbi->ring_buffer->read_index;
  122. write_loc = rbi->ring_buffer->write_index;
  123. dsize = rbi->ring_datasize;
  124. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  125. read_loc - write_loc;
  126. *read = dsize - *write;
  127. }
  128. /*
  129. * VMBUS version is 32 bit entity broken up into
  130. * two 16 bit quantities: major_number. minor_number.
  131. *
  132. * 0 . 13 (Windows Server 2008)
  133. * 1 . 1 (Windows 7)
  134. * 2 . 4 (Windows 8)
  135. * 3 . 0 (Windows 8 R2)
  136. * 4 . 0 (Windows 10)
  137. */
  138. #define VERSION_WS2008 ((0 << 16) | (13))
  139. #define VERSION_WIN7 ((1 << 16) | (1))
  140. #define VERSION_WIN8 ((2 << 16) | (4))
  141. #define VERSION_WIN8_1 ((3 << 16) | (0))
  142. #define VERSION_WIN10 ((4 << 16) | (0))
  143. #define VERSION_INVAL -1
  144. #define VERSION_CURRENT VERSION_WIN10
  145. /* Make maximum size of pipe payload of 16K */
  146. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  147. /* Define PipeMode values. */
  148. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  149. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  150. /* The size of the user defined data buffer for non-pipe offers. */
  151. #define MAX_USER_DEFINED_BYTES 120
  152. /* The size of the user defined data buffer for pipe offers. */
  153. #define MAX_PIPE_USER_DEFINED_BYTES 116
  154. /*
  155. * At the center of the Channel Management library is the Channel Offer. This
  156. * struct contains the fundamental information about an offer.
  157. */
  158. struct vmbus_channel_offer {
  159. uuid_le if_type;
  160. uuid_le if_instance;
  161. /*
  162. * These two fields are not currently used.
  163. */
  164. u64 reserved1;
  165. u64 reserved2;
  166. u16 chn_flags;
  167. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  168. union {
  169. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  170. struct {
  171. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  172. } std;
  173. /*
  174. * Pipes:
  175. * The following sructure is an integrated pipe protocol, which
  176. * is implemented on top of standard user-defined data. Pipe
  177. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  178. * use.
  179. */
  180. struct {
  181. u32 pipe_mode;
  182. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  183. } pipe;
  184. } u;
  185. /*
  186. * The sub_channel_index is defined in win8.
  187. */
  188. u16 sub_channel_index;
  189. u16 reserved3;
  190. } __packed;
  191. /* Server Flags */
  192. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  193. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  194. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  195. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  196. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  197. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  198. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  199. #define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000
  200. struct vmpacket_descriptor {
  201. u16 type;
  202. u16 offset8;
  203. u16 len8;
  204. u16 flags;
  205. u64 trans_id;
  206. } __packed;
  207. struct vmpacket_header {
  208. u32 prev_pkt_start_offset;
  209. struct vmpacket_descriptor descriptor;
  210. } __packed;
  211. struct vmtransfer_page_range {
  212. u32 byte_count;
  213. u32 byte_offset;
  214. } __packed;
  215. struct vmtransfer_page_packet_header {
  216. struct vmpacket_descriptor d;
  217. u16 xfer_pageset_id;
  218. u8 sender_owns_set;
  219. u8 reserved;
  220. u32 range_cnt;
  221. struct vmtransfer_page_range ranges[1];
  222. } __packed;
  223. struct vmgpadl_packet_header {
  224. struct vmpacket_descriptor d;
  225. u32 gpadl;
  226. u32 reserved;
  227. } __packed;
  228. struct vmadd_remove_transfer_page_set {
  229. struct vmpacket_descriptor d;
  230. u32 gpadl;
  231. u16 xfer_pageset_id;
  232. u16 reserved;
  233. } __packed;
  234. /*
  235. * This structure defines a range in guest physical space that can be made to
  236. * look virtually contiguous.
  237. */
  238. struct gpa_range {
  239. u32 byte_count;
  240. u32 byte_offset;
  241. u64 pfn_array[0];
  242. };
  243. /*
  244. * This is the format for an Establish Gpadl packet, which contains a handle by
  245. * which this GPADL will be known and a set of GPA ranges associated with it.
  246. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  247. * ranges, then the resulting MDL will be "chained," representing multiple VA
  248. * ranges.
  249. */
  250. struct vmestablish_gpadl {
  251. struct vmpacket_descriptor d;
  252. u32 gpadl;
  253. u32 range_cnt;
  254. struct gpa_range range[1];
  255. } __packed;
  256. /*
  257. * This is the format for a Teardown Gpadl packet, which indicates that the
  258. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  259. */
  260. struct vmteardown_gpadl {
  261. struct vmpacket_descriptor d;
  262. u32 gpadl;
  263. u32 reserved; /* for alignment to a 8-byte boundary */
  264. } __packed;
  265. /*
  266. * This is the format for a GPA-Direct packet, which contains a set of GPA
  267. * ranges, in addition to commands and/or data.
  268. */
  269. struct vmdata_gpa_direct {
  270. struct vmpacket_descriptor d;
  271. u32 reserved;
  272. u32 range_cnt;
  273. struct gpa_range range[1];
  274. } __packed;
  275. /* This is the format for a Additional Data Packet. */
  276. struct vmadditional_data {
  277. struct vmpacket_descriptor d;
  278. u64 total_bytes;
  279. u32 offset;
  280. u32 byte_cnt;
  281. unsigned char data[1];
  282. } __packed;
  283. union vmpacket_largest_possible_header {
  284. struct vmpacket_descriptor simple_hdr;
  285. struct vmtransfer_page_packet_header xfer_page_hdr;
  286. struct vmgpadl_packet_header gpadl_hdr;
  287. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  288. struct vmestablish_gpadl establish_gpadl_hdr;
  289. struct vmteardown_gpadl teardown_gpadl_hdr;
  290. struct vmdata_gpa_direct data_gpa_direct_hdr;
  291. };
  292. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  293. (void *)(((unsigned char *)__packet) + \
  294. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  295. #define VMPACKET_DATA_LENGTH(__packet) \
  296. ((((struct vmpacket_descriptor)__packet)->len8 - \
  297. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  298. #define VMPACKET_TRANSFER_MODE(__packet) \
  299. (((struct IMPACT)__packet)->type)
  300. enum vmbus_packet_type {
  301. VM_PKT_INVALID = 0x0,
  302. VM_PKT_SYNCH = 0x1,
  303. VM_PKT_ADD_XFER_PAGESET = 0x2,
  304. VM_PKT_RM_XFER_PAGESET = 0x3,
  305. VM_PKT_ESTABLISH_GPADL = 0x4,
  306. VM_PKT_TEARDOWN_GPADL = 0x5,
  307. VM_PKT_DATA_INBAND = 0x6,
  308. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  309. VM_PKT_DATA_USING_GPADL = 0x8,
  310. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  311. VM_PKT_CANCEL_REQUEST = 0xa,
  312. VM_PKT_COMP = 0xb,
  313. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  314. VM_PKT_ADDITIONAL_DATA = 0xd
  315. };
  316. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  317. /* Version 1 messages */
  318. enum vmbus_channel_message_type {
  319. CHANNELMSG_INVALID = 0,
  320. CHANNELMSG_OFFERCHANNEL = 1,
  321. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  322. CHANNELMSG_REQUESTOFFERS = 3,
  323. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  324. CHANNELMSG_OPENCHANNEL = 5,
  325. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  326. CHANNELMSG_CLOSECHANNEL = 7,
  327. CHANNELMSG_GPADL_HEADER = 8,
  328. CHANNELMSG_GPADL_BODY = 9,
  329. CHANNELMSG_GPADL_CREATED = 10,
  330. CHANNELMSG_GPADL_TEARDOWN = 11,
  331. CHANNELMSG_GPADL_TORNDOWN = 12,
  332. CHANNELMSG_RELID_RELEASED = 13,
  333. CHANNELMSG_INITIATE_CONTACT = 14,
  334. CHANNELMSG_VERSION_RESPONSE = 15,
  335. CHANNELMSG_UNLOAD = 16,
  336. CHANNELMSG_UNLOAD_RESPONSE = 17,
  337. CHANNELMSG_18 = 18,
  338. CHANNELMSG_19 = 19,
  339. CHANNELMSG_20 = 20,
  340. CHANNELMSG_TL_CONNECT_REQUEST = 21,
  341. CHANNELMSG_COUNT
  342. };
  343. struct vmbus_channel_message_header {
  344. enum vmbus_channel_message_type msgtype;
  345. u32 padding;
  346. } __packed;
  347. /* Query VMBus Version parameters */
  348. struct vmbus_channel_query_vmbus_version {
  349. struct vmbus_channel_message_header header;
  350. u32 version;
  351. } __packed;
  352. /* VMBus Version Supported parameters */
  353. struct vmbus_channel_version_supported {
  354. struct vmbus_channel_message_header header;
  355. u8 version_supported;
  356. } __packed;
  357. /* Offer Channel parameters */
  358. struct vmbus_channel_offer_channel {
  359. struct vmbus_channel_message_header header;
  360. struct vmbus_channel_offer offer;
  361. u32 child_relid;
  362. u8 monitorid;
  363. /*
  364. * win7 and beyond splits this field into a bit field.
  365. */
  366. u8 monitor_allocated:1;
  367. u8 reserved:7;
  368. /*
  369. * These are new fields added in win7 and later.
  370. * Do not access these fields without checking the
  371. * negotiated protocol.
  372. *
  373. * If "is_dedicated_interrupt" is set, we must not set the
  374. * associated bit in the channel bitmap while sending the
  375. * interrupt to the host.
  376. *
  377. * connection_id is to be used in signaling the host.
  378. */
  379. u16 is_dedicated_interrupt:1;
  380. u16 reserved1:15;
  381. u32 connection_id;
  382. } __packed;
  383. /* Rescind Offer parameters */
  384. struct vmbus_channel_rescind_offer {
  385. struct vmbus_channel_message_header header;
  386. u32 child_relid;
  387. } __packed;
  388. /*
  389. * Request Offer -- no parameters, SynIC message contains the partition ID
  390. * Set Snoop -- no parameters, SynIC message contains the partition ID
  391. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  392. * All Offers Delivered -- no parameters, SynIC message contains the partition
  393. * ID
  394. * Flush Client -- no parameters, SynIC message contains the partition ID
  395. */
  396. /* Open Channel parameters */
  397. struct vmbus_channel_open_channel {
  398. struct vmbus_channel_message_header header;
  399. /* Identifies the specific VMBus channel that is being opened. */
  400. u32 child_relid;
  401. /* ID making a particular open request at a channel offer unique. */
  402. u32 openid;
  403. /* GPADL for the channel's ring buffer. */
  404. u32 ringbuffer_gpadlhandle;
  405. /*
  406. * Starting with win8, this field will be used to specify
  407. * the target virtual processor on which to deliver the interrupt for
  408. * the host to guest communication.
  409. * Prior to win8, incoming channel interrupts would only
  410. * be delivered on cpu 0. Setting this value to 0 would
  411. * preserve the earlier behavior.
  412. */
  413. u32 target_vp;
  414. /*
  415. * The upstream ring buffer begins at offset zero in the memory
  416. * described by RingBufferGpadlHandle. The downstream ring buffer
  417. * follows it at this offset (in pages).
  418. */
  419. u32 downstream_ringbuffer_pageoffset;
  420. /* User-specific data to be passed along to the server endpoint. */
  421. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  422. } __packed;
  423. /* Open Channel Result parameters */
  424. struct vmbus_channel_open_result {
  425. struct vmbus_channel_message_header header;
  426. u32 child_relid;
  427. u32 openid;
  428. u32 status;
  429. } __packed;
  430. /* Close channel parameters; */
  431. struct vmbus_channel_close_channel {
  432. struct vmbus_channel_message_header header;
  433. u32 child_relid;
  434. } __packed;
  435. /* Channel Message GPADL */
  436. #define GPADL_TYPE_RING_BUFFER 1
  437. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  438. #define GPADL_TYPE_TRANSACTION 8
  439. /*
  440. * The number of PFNs in a GPADL message is defined by the number of
  441. * pages that would be spanned by ByteCount and ByteOffset. If the
  442. * implied number of PFNs won't fit in this packet, there will be a
  443. * follow-up packet that contains more.
  444. */
  445. struct vmbus_channel_gpadl_header {
  446. struct vmbus_channel_message_header header;
  447. u32 child_relid;
  448. u32 gpadl;
  449. u16 range_buflen;
  450. u16 rangecount;
  451. struct gpa_range range[0];
  452. } __packed;
  453. /* This is the followup packet that contains more PFNs. */
  454. struct vmbus_channel_gpadl_body {
  455. struct vmbus_channel_message_header header;
  456. u32 msgnumber;
  457. u32 gpadl;
  458. u64 pfn[0];
  459. } __packed;
  460. struct vmbus_channel_gpadl_created {
  461. struct vmbus_channel_message_header header;
  462. u32 child_relid;
  463. u32 gpadl;
  464. u32 creation_status;
  465. } __packed;
  466. struct vmbus_channel_gpadl_teardown {
  467. struct vmbus_channel_message_header header;
  468. u32 child_relid;
  469. u32 gpadl;
  470. } __packed;
  471. struct vmbus_channel_gpadl_torndown {
  472. struct vmbus_channel_message_header header;
  473. u32 gpadl;
  474. } __packed;
  475. struct vmbus_channel_relid_released {
  476. struct vmbus_channel_message_header header;
  477. u32 child_relid;
  478. } __packed;
  479. struct vmbus_channel_initiate_contact {
  480. struct vmbus_channel_message_header header;
  481. u32 vmbus_version_requested;
  482. u32 target_vcpu; /* The VCPU the host should respond to */
  483. u64 interrupt_page;
  484. u64 monitor_page1;
  485. u64 monitor_page2;
  486. } __packed;
  487. /* Hyper-V socket: guest's connect()-ing to host */
  488. struct vmbus_channel_tl_connect_request {
  489. struct vmbus_channel_message_header header;
  490. uuid_le guest_endpoint_id;
  491. uuid_le host_service_id;
  492. } __packed;
  493. struct vmbus_channel_version_response {
  494. struct vmbus_channel_message_header header;
  495. u8 version_supported;
  496. } __packed;
  497. enum vmbus_channel_state {
  498. CHANNEL_OFFER_STATE,
  499. CHANNEL_OPENING_STATE,
  500. CHANNEL_OPEN_STATE,
  501. CHANNEL_OPENED_STATE,
  502. };
  503. /*
  504. * Represents each channel msg on the vmbus connection This is a
  505. * variable-size data structure depending on the msg type itself
  506. */
  507. struct vmbus_channel_msginfo {
  508. /* Bookkeeping stuff */
  509. struct list_head msglistentry;
  510. /* So far, this is only used to handle gpadl body message */
  511. struct list_head submsglist;
  512. /* Synchronize the request/response if needed */
  513. struct completion waitevent;
  514. union {
  515. struct vmbus_channel_version_supported version_supported;
  516. struct vmbus_channel_open_result open_result;
  517. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  518. struct vmbus_channel_gpadl_created gpadl_created;
  519. struct vmbus_channel_version_response version_response;
  520. } response;
  521. u32 msgsize;
  522. /*
  523. * The channel message that goes out on the "wire".
  524. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  525. */
  526. unsigned char msg[0];
  527. };
  528. struct vmbus_close_msg {
  529. struct vmbus_channel_msginfo info;
  530. struct vmbus_channel_close_channel msg;
  531. };
  532. /* Define connection identifier type. */
  533. union hv_connection_id {
  534. u32 asu32;
  535. struct {
  536. u32 id:24;
  537. u32 reserved:8;
  538. } u;
  539. };
  540. /* Definition of the hv_signal_event hypercall input structure. */
  541. struct hv_input_signal_event {
  542. union hv_connection_id connectionid;
  543. u16 flag_number;
  544. u16 rsvdz;
  545. };
  546. struct hv_input_signal_event_buffer {
  547. u64 align8;
  548. struct hv_input_signal_event event;
  549. };
  550. enum hv_signal_policy {
  551. HV_SIGNAL_POLICY_DEFAULT = 0,
  552. HV_SIGNAL_POLICY_EXPLICIT,
  553. };
  554. enum vmbus_device_type {
  555. HV_IDE = 0,
  556. HV_SCSI,
  557. HV_FC,
  558. HV_NIC,
  559. HV_ND,
  560. HV_PCIE,
  561. HV_FB,
  562. HV_KBD,
  563. HV_MOUSE,
  564. HV_KVP,
  565. HV_TS,
  566. HV_HB,
  567. HV_SHUTDOWN,
  568. HV_FCOPY,
  569. HV_BACKUP,
  570. HV_DM,
  571. HV_UNKOWN,
  572. };
  573. struct vmbus_device {
  574. u16 dev_type;
  575. uuid_le guid;
  576. bool perf_device;
  577. };
  578. struct vmbus_channel {
  579. /* Unique channel id */
  580. int id;
  581. struct list_head listentry;
  582. struct hv_device *device_obj;
  583. enum vmbus_channel_state state;
  584. struct vmbus_channel_offer_channel offermsg;
  585. /*
  586. * These are based on the OfferMsg.MonitorId.
  587. * Save it here for easy access.
  588. */
  589. u8 monitor_grp;
  590. u8 monitor_bit;
  591. bool rescind; /* got rescind msg */
  592. u32 ringbuffer_gpadlhandle;
  593. /* Allocated memory for ring buffer */
  594. void *ringbuffer_pages;
  595. u32 ringbuffer_pagecount;
  596. struct hv_ring_buffer_info outbound; /* send to parent */
  597. struct hv_ring_buffer_info inbound; /* receive from parent */
  598. spinlock_t inbound_lock;
  599. struct vmbus_close_msg close_msg;
  600. /* Channel callback are invoked in this workqueue context */
  601. /* HANDLE dataWorkQueue; */
  602. void (*onchannel_callback)(void *context);
  603. void *channel_callback_context;
  604. /*
  605. * A channel can be marked for efficient (batched)
  606. * reading:
  607. * If batched_reading is set to "true", we read until the
  608. * channel is empty and hold off interrupts from the host
  609. * during the entire read process.
  610. * If batched_reading is set to "false", the client is not
  611. * going to perform batched reading.
  612. *
  613. * By default we will enable batched reading; specific
  614. * drivers that don't want this behavior can turn it off.
  615. */
  616. bool batched_reading;
  617. bool is_dedicated_interrupt;
  618. struct hv_input_signal_event_buffer sig_buf;
  619. struct hv_input_signal_event *sig_event;
  620. /*
  621. * Starting with win8, this field will be used to specify
  622. * the target virtual processor on which to deliver the interrupt for
  623. * the host to guest communication.
  624. * Prior to win8, incoming channel interrupts would only
  625. * be delivered on cpu 0. Setting this value to 0 would
  626. * preserve the earlier behavior.
  627. */
  628. u32 target_vp;
  629. /* The corresponding CPUID in the guest */
  630. u32 target_cpu;
  631. /*
  632. * State to manage the CPU affiliation of channels.
  633. */
  634. struct cpumask alloced_cpus_in_node;
  635. int numa_node;
  636. /*
  637. * Support for sub-channels. For high performance devices,
  638. * it will be useful to have multiple sub-channels to support
  639. * a scalable communication infrastructure with the host.
  640. * The support for sub-channels is implemented as an extention
  641. * to the current infrastructure.
  642. * The initial offer is considered the primary channel and this
  643. * offer message will indicate if the host supports sub-channels.
  644. * The guest is free to ask for sub-channels to be offerred and can
  645. * open these sub-channels as a normal "primary" channel. However,
  646. * all sub-channels will have the same type and instance guids as the
  647. * primary channel. Requests sent on a given channel will result in a
  648. * response on the same channel.
  649. */
  650. /*
  651. * Sub-channel creation callback. This callback will be called in
  652. * process context when a sub-channel offer is received from the host.
  653. * The guest can open the sub-channel in the context of this callback.
  654. */
  655. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  656. /*
  657. * Channel rescind callback. Some channels (the hvsock ones), need to
  658. * register a callback which is invoked in vmbus_onoffer_rescind().
  659. */
  660. void (*chn_rescind_callback)(struct vmbus_channel *channel);
  661. /*
  662. * The spinlock to protect the structure. It is being used to protect
  663. * test-and-set access to various attributes of the structure as well
  664. * as all sc_list operations.
  665. */
  666. spinlock_t lock;
  667. /*
  668. * All Sub-channels of a primary channel are linked here.
  669. */
  670. struct list_head sc_list;
  671. /*
  672. * Current number of sub-channels.
  673. */
  674. int num_sc;
  675. /*
  676. * Number of a sub-channel (position within sc_list) which is supposed
  677. * to be used as the next outgoing channel.
  678. */
  679. int next_oc;
  680. /*
  681. * The primary channel this sub-channel belongs to.
  682. * This will be NULL for the primary channel.
  683. */
  684. struct vmbus_channel *primary_channel;
  685. /*
  686. * Support per-channel state for use by vmbus drivers.
  687. */
  688. void *per_channel_state;
  689. /*
  690. * To support per-cpu lookup mapping of relid to channel,
  691. * link up channels based on their CPU affinity.
  692. */
  693. struct list_head percpu_list;
  694. /*
  695. * Host signaling policy: The default policy will be
  696. * based on the ring buffer state. We will also support
  697. * a policy where the client driver can have explicit
  698. * signaling control.
  699. */
  700. enum hv_signal_policy signal_policy;
  701. /*
  702. * On the channel send side, many of the VMBUS
  703. * device drivers explicity serialize access to the
  704. * outgoing ring buffer. Give more control to the
  705. * VMBUS device drivers in terms how to serialize
  706. * accesss to the outgoing ring buffer.
  707. * The default behavior will be to aquire the
  708. * ring lock to preserve the current behavior.
  709. */
  710. bool acquire_ring_lock;
  711. };
  712. static inline void set_channel_lock_state(struct vmbus_channel *c, bool state)
  713. {
  714. c->acquire_ring_lock = state;
  715. }
  716. static inline bool is_hvsock_channel(const struct vmbus_channel *c)
  717. {
  718. return !!(c->offermsg.offer.chn_flags &
  719. VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER);
  720. }
  721. static inline void set_channel_signal_state(struct vmbus_channel *c,
  722. enum hv_signal_policy policy)
  723. {
  724. c->signal_policy = policy;
  725. }
  726. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  727. {
  728. c->batched_reading = state;
  729. }
  730. static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
  731. {
  732. c->per_channel_state = s;
  733. }
  734. static inline void *get_per_channel_state(struct vmbus_channel *c)
  735. {
  736. return c->per_channel_state;
  737. }
  738. static inline void set_channel_pending_send_size(struct vmbus_channel *c,
  739. u32 size)
  740. {
  741. c->outbound.ring_buffer->pending_send_sz = size;
  742. }
  743. void vmbus_onmessage(void *context);
  744. int vmbus_request_offers(void);
  745. /*
  746. * APIs for managing sub-channels.
  747. */
  748. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  749. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  750. void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
  751. void (*chn_rescind_cb)(struct vmbus_channel *));
  752. /*
  753. * Retrieve the (sub) channel on which to send an outgoing request.
  754. * When a primary channel has multiple sub-channels, we choose a
  755. * channel whose VCPU binding is closest to the VCPU on which
  756. * this call is being made.
  757. */
  758. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  759. /*
  760. * Check if sub-channels have already been offerred. This API will be useful
  761. * when the driver is unloaded after establishing sub-channels. In this case,
  762. * when the driver is re-loaded, the driver would have to check if the
  763. * subchannels have already been established before attempting to request
  764. * the creation of sub-channels.
  765. * This function returns TRUE to indicate that subchannels have already been
  766. * created.
  767. * This function should be invoked after setting the callback function for
  768. * sub-channel creation.
  769. */
  770. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  771. /* The format must be the same as struct vmdata_gpa_direct */
  772. struct vmbus_channel_packet_page_buffer {
  773. u16 type;
  774. u16 dataoffset8;
  775. u16 length8;
  776. u16 flags;
  777. u64 transactionid;
  778. u32 reserved;
  779. u32 rangecount;
  780. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  781. } __packed;
  782. /* The format must be the same as struct vmdata_gpa_direct */
  783. struct vmbus_channel_packet_multipage_buffer {
  784. u16 type;
  785. u16 dataoffset8;
  786. u16 length8;
  787. u16 flags;
  788. u64 transactionid;
  789. u32 reserved;
  790. u32 rangecount; /* Always 1 in this case */
  791. struct hv_multipage_buffer range;
  792. } __packed;
  793. /* The format must be the same as struct vmdata_gpa_direct */
  794. struct vmbus_packet_mpb_array {
  795. u16 type;
  796. u16 dataoffset8;
  797. u16 length8;
  798. u16 flags;
  799. u64 transactionid;
  800. u32 reserved;
  801. u32 rangecount; /* Always 1 in this case */
  802. struct hv_mpb_array range;
  803. } __packed;
  804. extern int vmbus_open(struct vmbus_channel *channel,
  805. u32 send_ringbuffersize,
  806. u32 recv_ringbuffersize,
  807. void *userdata,
  808. u32 userdatalen,
  809. void(*onchannel_callback)(void *context),
  810. void *context);
  811. extern void vmbus_close(struct vmbus_channel *channel);
  812. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  813. void *buffer,
  814. u32 bufferLen,
  815. u64 requestid,
  816. enum vmbus_packet_type type,
  817. u32 flags);
  818. extern int vmbus_sendpacket_ctl(struct vmbus_channel *channel,
  819. void *buffer,
  820. u32 bufferLen,
  821. u64 requestid,
  822. enum vmbus_packet_type type,
  823. u32 flags,
  824. bool kick_q);
  825. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  826. struct hv_page_buffer pagebuffers[],
  827. u32 pagecount,
  828. void *buffer,
  829. u32 bufferlen,
  830. u64 requestid);
  831. extern int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel,
  832. struct hv_page_buffer pagebuffers[],
  833. u32 pagecount,
  834. void *buffer,
  835. u32 bufferlen,
  836. u64 requestid,
  837. u32 flags,
  838. bool kick_q);
  839. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  840. struct hv_multipage_buffer *mpb,
  841. void *buffer,
  842. u32 bufferlen,
  843. u64 requestid);
  844. extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
  845. struct vmbus_packet_mpb_array *mpb,
  846. u32 desc_size,
  847. void *buffer,
  848. u32 bufferlen,
  849. u64 requestid);
  850. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  851. void *kbuffer,
  852. u32 size,
  853. u32 *gpadl_handle);
  854. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  855. u32 gpadl_handle);
  856. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  857. void *buffer,
  858. u32 bufferlen,
  859. u32 *buffer_actual_len,
  860. u64 *requestid);
  861. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  862. void *buffer,
  863. u32 bufferlen,
  864. u32 *buffer_actual_len,
  865. u64 *requestid);
  866. extern void vmbus_ontimer(unsigned long data);
  867. /* Base driver object */
  868. struct hv_driver {
  869. const char *name;
  870. /*
  871. * A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER
  872. * channel flag, actually doesn't mean a synthetic device because the
  873. * offer's if_type/if_instance can change for every new hvsock
  874. * connection.
  875. *
  876. * However, to facilitate the notification of new-offer/rescind-offer
  877. * from vmbus driver to hvsock driver, we can handle hvsock offer as
  878. * a special vmbus device, and hence we need the below flag to
  879. * indicate if the driver is the hvsock driver or not: we need to
  880. * specially treat the hvosck offer & driver in vmbus_match().
  881. */
  882. bool hvsock;
  883. /* the device type supported by this driver */
  884. uuid_le dev_type;
  885. const struct hv_vmbus_device_id *id_table;
  886. struct device_driver driver;
  887. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  888. int (*remove)(struct hv_device *);
  889. void (*shutdown)(struct hv_device *);
  890. };
  891. /* Base device object */
  892. struct hv_device {
  893. /* the device type id of this device */
  894. uuid_le dev_type;
  895. /* the device instance id of this device */
  896. uuid_le dev_instance;
  897. u16 vendor_id;
  898. u16 device_id;
  899. struct device device;
  900. struct vmbus_channel *channel;
  901. };
  902. static inline struct hv_device *device_to_hv_device(struct device *d)
  903. {
  904. return container_of(d, struct hv_device, device);
  905. }
  906. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  907. {
  908. return container_of(d, struct hv_driver, driver);
  909. }
  910. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  911. {
  912. dev_set_drvdata(&dev->device, data);
  913. }
  914. static inline void *hv_get_drvdata(struct hv_device *dev)
  915. {
  916. return dev_get_drvdata(&dev->device);
  917. }
  918. /* Vmbus interface */
  919. #define vmbus_driver_register(driver) \
  920. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  921. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  922. struct module *owner,
  923. const char *mod_name);
  924. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  925. void vmbus_hvsock_device_unregister(struct vmbus_channel *channel);
  926. int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
  927. resource_size_t min, resource_size_t max,
  928. resource_size_t size, resource_size_t align,
  929. bool fb_overlap_ok);
  930. int vmbus_cpu_number_to_vp_number(int cpu_number);
  931. u64 hv_do_hypercall(u64 control, void *input, void *output);
  932. /*
  933. * GUID definitions of various offer types - services offered to the guest.
  934. */
  935. /*
  936. * Network GUID
  937. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  938. */
  939. #define HV_NIC_GUID \
  940. .guid = UUID_LE(0xf8615163, 0xdf3e, 0x46c5, 0x91, 0x3f, \
  941. 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e)
  942. /*
  943. * IDE GUID
  944. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  945. */
  946. #define HV_IDE_GUID \
  947. .guid = UUID_LE(0x32412632, 0x86cb, 0x44a2, 0x9b, 0x5c, \
  948. 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
  949. /*
  950. * SCSI GUID
  951. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  952. */
  953. #define HV_SCSI_GUID \
  954. .guid = UUID_LE(0xba6163d9, 0x04a1, 0x4d29, 0xb6, 0x05, \
  955. 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
  956. /*
  957. * Shutdown GUID
  958. * {0e0b6031-5213-4934-818b-38d90ced39db}
  959. */
  960. #define HV_SHUTDOWN_GUID \
  961. .guid = UUID_LE(0x0e0b6031, 0x5213, 0x4934, 0x81, 0x8b, \
  962. 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb)
  963. /*
  964. * Time Synch GUID
  965. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  966. */
  967. #define HV_TS_GUID \
  968. .guid = UUID_LE(0x9527e630, 0xd0ae, 0x497b, 0xad, 0xce, \
  969. 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf)
  970. /*
  971. * Heartbeat GUID
  972. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  973. */
  974. #define HV_HEART_BEAT_GUID \
  975. .guid = UUID_LE(0x57164f39, 0x9115, 0x4e78, 0xab, 0x55, \
  976. 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d)
  977. /*
  978. * KVP GUID
  979. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  980. */
  981. #define HV_KVP_GUID \
  982. .guid = UUID_LE(0xa9a0f4e7, 0x5a45, 0x4d96, 0xb8, 0x27, \
  983. 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6)
  984. /*
  985. * Dynamic memory GUID
  986. * {525074dc-8985-46e2-8057-a307dc18a502}
  987. */
  988. #define HV_DM_GUID \
  989. .guid = UUID_LE(0x525074dc, 0x8985, 0x46e2, 0x80, 0x57, \
  990. 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02)
  991. /*
  992. * Mouse GUID
  993. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  994. */
  995. #define HV_MOUSE_GUID \
  996. .guid = UUID_LE(0xcfa8b69e, 0x5b4a, 0x4cc0, 0xb9, 0x8b, \
  997. 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a)
  998. /*
  999. * Keyboard GUID
  1000. * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
  1001. */
  1002. #define HV_KBD_GUID \
  1003. .guid = UUID_LE(0xf912ad6d, 0x2b17, 0x48ea, 0xbd, 0x65, \
  1004. 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84)
  1005. /*
  1006. * VSS (Backup/Restore) GUID
  1007. */
  1008. #define HV_VSS_GUID \
  1009. .guid = UUID_LE(0x35fa2e29, 0xea23, 0x4236, 0x96, 0xae, \
  1010. 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40)
  1011. /*
  1012. * Synthetic Video GUID
  1013. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1014. */
  1015. #define HV_SYNTHVID_GUID \
  1016. .guid = UUID_LE(0xda0a7802, 0xe377, 0x4aac, 0x8e, 0x77, \
  1017. 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8)
  1018. /*
  1019. * Synthetic FC GUID
  1020. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1021. */
  1022. #define HV_SYNTHFC_GUID \
  1023. .guid = UUID_LE(0x2f9bcc4a, 0x0069, 0x4af3, 0xb7, 0x6b, \
  1024. 0x6f, 0xd0, 0xbe, 0x52, 0x8c, 0xda)
  1025. /*
  1026. * Guest File Copy Service
  1027. * {34D14BE3-DEE4-41c8-9AE7-6B174977C192}
  1028. */
  1029. #define HV_FCOPY_GUID \
  1030. .guid = UUID_LE(0x34d14be3, 0xdee4, 0x41c8, 0x9a, 0xe7, \
  1031. 0x6b, 0x17, 0x49, 0x77, 0xc1, 0x92)
  1032. /*
  1033. * NetworkDirect. This is the guest RDMA service.
  1034. * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}
  1035. */
  1036. #define HV_ND_GUID \
  1037. .guid = UUID_LE(0x8c2eaf3d, 0x32a7, 0x4b09, 0xab, 0x99, \
  1038. 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01)
  1039. /*
  1040. * PCI Express Pass Through
  1041. * {44C4F61D-4444-4400-9D52-802E27EDE19F}
  1042. */
  1043. #define HV_PCIE_GUID \
  1044. .guid = UUID_LE(0x44c4f61d, 0x4444, 0x4400, 0x9d, 0x52, \
  1045. 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f)
  1046. /*
  1047. * Common header for Hyper-V ICs
  1048. */
  1049. #define ICMSGTYPE_NEGOTIATE 0
  1050. #define ICMSGTYPE_HEARTBEAT 1
  1051. #define ICMSGTYPE_KVPEXCHANGE 2
  1052. #define ICMSGTYPE_SHUTDOWN 3
  1053. #define ICMSGTYPE_TIMESYNC 4
  1054. #define ICMSGTYPE_VSS 5
  1055. #define ICMSGHDRFLAG_TRANSACTION 1
  1056. #define ICMSGHDRFLAG_REQUEST 2
  1057. #define ICMSGHDRFLAG_RESPONSE 4
  1058. /*
  1059. * While we want to handle util services as regular devices,
  1060. * there is only one instance of each of these services; so
  1061. * we statically allocate the service specific state.
  1062. */
  1063. struct hv_util_service {
  1064. u8 *recv_buffer;
  1065. void (*util_cb)(void *);
  1066. int (*util_init)(struct hv_util_service *);
  1067. void (*util_deinit)(void);
  1068. };
  1069. struct vmbuspipe_hdr {
  1070. u32 flags;
  1071. u32 msgsize;
  1072. } __packed;
  1073. struct ic_version {
  1074. u16 major;
  1075. u16 minor;
  1076. } __packed;
  1077. struct icmsg_hdr {
  1078. struct ic_version icverframe;
  1079. u16 icmsgtype;
  1080. struct ic_version icvermsg;
  1081. u16 icmsgsize;
  1082. u32 status;
  1083. u8 ictransaction_id;
  1084. u8 icflags;
  1085. u8 reserved[2];
  1086. } __packed;
  1087. struct icmsg_negotiate {
  1088. u16 icframe_vercnt;
  1089. u16 icmsg_vercnt;
  1090. u32 reserved;
  1091. struct ic_version icversion_data[1]; /* any size array */
  1092. } __packed;
  1093. struct shutdown_msg_data {
  1094. u32 reason_code;
  1095. u32 timeout_seconds;
  1096. u32 flags;
  1097. u8 display_message[2048];
  1098. } __packed;
  1099. struct heartbeat_msg_data {
  1100. u64 seq_num;
  1101. u32 reserved[8];
  1102. } __packed;
  1103. /* Time Sync IC defs */
  1104. #define ICTIMESYNCFLAG_PROBE 0
  1105. #define ICTIMESYNCFLAG_SYNC 1
  1106. #define ICTIMESYNCFLAG_SAMPLE 2
  1107. #ifdef __x86_64__
  1108. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1109. #else
  1110. #define WLTIMEDELTA 116444736000000000LL
  1111. #endif
  1112. struct ictimesync_data {
  1113. u64 parenttime;
  1114. u64 childtime;
  1115. u64 roundtriptime;
  1116. u8 flags;
  1117. } __packed;
  1118. struct hyperv_service_callback {
  1119. u8 msg_type;
  1120. char *log_msg;
  1121. uuid_le data;
  1122. struct vmbus_channel *channel;
  1123. void (*callback) (void *context);
  1124. };
  1125. #define MAX_SRV_VER 0x7ffffff
  1126. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1127. struct icmsg_negotiate *, u8 *, int,
  1128. int);
  1129. void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid);
  1130. /*
  1131. * Negotiated version with the Host.
  1132. */
  1133. extern __u32 vmbus_proto_version;
  1134. int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  1135. const uuid_le *shv_host_servie_id);
  1136. #endif /* _HYPERV_H */