hyperv.h 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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 <linux/types.h>
  28. #include <linux/scatterlist.h>
  29. #include <linux/list.h>
  30. #include <linux/uuid.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 19
  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. /* 0x18 includes the proprietary packet header */
  53. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  54. (sizeof(struct hv_page_buffer) * \
  55. MAX_PAGE_BUFFER_COUNT))
  56. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  57. sizeof(struct hv_multipage_buffer))
  58. #pragma pack(pop)
  59. struct hv_ring_buffer {
  60. /* Offset in bytes from the start of ring data below */
  61. u32 write_index;
  62. /* Offset in bytes from the start of ring data below */
  63. u32 read_index;
  64. u32 interrupt_mask;
  65. /*
  66. * Win8 uses some of the reserved bits to implement
  67. * interrupt driven flow management. On the send side
  68. * we can request that the receiver interrupt the sender
  69. * when the ring transitions from being full to being able
  70. * to handle a message of size "pending_send_sz".
  71. *
  72. * Add necessary state for this enhancement.
  73. */
  74. u32 pending_send_sz;
  75. u32 reserved1[12];
  76. union {
  77. struct {
  78. u32 feat_pending_send_sz:1;
  79. };
  80. u32 value;
  81. } feature_bits;
  82. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  83. u8 reserved2[4028];
  84. /*
  85. * Ring data starts here + RingDataStartOffset
  86. * !!! DO NOT place any fields below this !!!
  87. */
  88. u8 buffer[0];
  89. } __packed;
  90. struct hv_ring_buffer_info {
  91. struct hv_ring_buffer *ring_buffer;
  92. u32 ring_size; /* Include the shared header */
  93. spinlock_t ring_lock;
  94. u32 ring_datasize; /* < ring_size */
  95. u32 ring_data_startoffset;
  96. };
  97. /*
  98. *
  99. * hv_get_ringbuffer_availbytes()
  100. *
  101. * Get number of bytes available to read and to write to
  102. * for the specified ring buffer
  103. */
  104. static inline void
  105. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  106. u32 *read, u32 *write)
  107. {
  108. u32 read_loc, write_loc, dsize;
  109. smp_read_barrier_depends();
  110. /* Capture the read/write indices before they changed */
  111. read_loc = rbi->ring_buffer->read_index;
  112. write_loc = rbi->ring_buffer->write_index;
  113. dsize = rbi->ring_datasize;
  114. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  115. read_loc - write_loc;
  116. *read = dsize - *write;
  117. }
  118. /*
  119. * VMBUS version is 32 bit entity broken up into
  120. * two 16 bit quantities: major_number. minor_number.
  121. *
  122. * 0 . 13 (Windows Server 2008)
  123. * 1 . 1 (Windows 7)
  124. * 2 . 4 (Windows 8)
  125. */
  126. #define VERSION_WS2008 ((0 << 16) | (13))
  127. #define VERSION_WIN7 ((1 << 16) | (1))
  128. #define VERSION_WIN8 ((2 << 16) | (4))
  129. #define VERSION_INVAL -1
  130. #define VERSION_CURRENT VERSION_WIN8
  131. /* Make maximum size of pipe payload of 16K */
  132. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  133. /* Define PipeMode values. */
  134. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  135. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  136. /* The size of the user defined data buffer for non-pipe offers. */
  137. #define MAX_USER_DEFINED_BYTES 120
  138. /* The size of the user defined data buffer for pipe offers. */
  139. #define MAX_PIPE_USER_DEFINED_BYTES 116
  140. /*
  141. * At the center of the Channel Management library is the Channel Offer. This
  142. * struct contains the fundamental information about an offer.
  143. */
  144. struct vmbus_channel_offer {
  145. uuid_le if_type;
  146. uuid_le if_instance;
  147. /*
  148. * These two fields are not currently used.
  149. */
  150. u64 reserved1;
  151. u64 reserved2;
  152. u16 chn_flags;
  153. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  154. union {
  155. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  156. struct {
  157. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  158. } std;
  159. /*
  160. * Pipes:
  161. * The following sructure is an integrated pipe protocol, which
  162. * is implemented on top of standard user-defined data. Pipe
  163. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  164. * use.
  165. */
  166. struct {
  167. u32 pipe_mode;
  168. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  169. } pipe;
  170. } u;
  171. /*
  172. * The sub_channel_index is defined in win8.
  173. */
  174. u16 sub_channel_index;
  175. u16 reserved3;
  176. } __packed;
  177. /* Server Flags */
  178. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  179. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  180. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  181. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  182. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  183. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  184. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  185. struct vmpacket_descriptor {
  186. u16 type;
  187. u16 offset8;
  188. u16 len8;
  189. u16 flags;
  190. u64 trans_id;
  191. } __packed;
  192. struct vmpacket_header {
  193. u32 prev_pkt_start_offset;
  194. struct vmpacket_descriptor descriptor;
  195. } __packed;
  196. struct vmtransfer_page_range {
  197. u32 byte_count;
  198. u32 byte_offset;
  199. } __packed;
  200. struct vmtransfer_page_packet_header {
  201. struct vmpacket_descriptor d;
  202. u16 xfer_pageset_id;
  203. u8 sender_owns_set;
  204. u8 reserved;
  205. u32 range_cnt;
  206. struct vmtransfer_page_range ranges[1];
  207. } __packed;
  208. struct vmgpadl_packet_header {
  209. struct vmpacket_descriptor d;
  210. u32 gpadl;
  211. u32 reserved;
  212. } __packed;
  213. struct vmadd_remove_transfer_page_set {
  214. struct vmpacket_descriptor d;
  215. u32 gpadl;
  216. u16 xfer_pageset_id;
  217. u16 reserved;
  218. } __packed;
  219. /*
  220. * This structure defines a range in guest physical space that can be made to
  221. * look virtually contiguous.
  222. */
  223. struct gpa_range {
  224. u32 byte_count;
  225. u32 byte_offset;
  226. u64 pfn_array[0];
  227. };
  228. /*
  229. * This is the format for an Establish Gpadl packet, which contains a handle by
  230. * which this GPADL will be known and a set of GPA ranges associated with it.
  231. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  232. * ranges, then the resulting MDL will be "chained," representing multiple VA
  233. * ranges.
  234. */
  235. struct vmestablish_gpadl {
  236. struct vmpacket_descriptor d;
  237. u32 gpadl;
  238. u32 range_cnt;
  239. struct gpa_range range[1];
  240. } __packed;
  241. /*
  242. * This is the format for a Teardown Gpadl packet, which indicates that the
  243. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  244. */
  245. struct vmteardown_gpadl {
  246. struct vmpacket_descriptor d;
  247. u32 gpadl;
  248. u32 reserved; /* for alignment to a 8-byte boundary */
  249. } __packed;
  250. /*
  251. * This is the format for a GPA-Direct packet, which contains a set of GPA
  252. * ranges, in addition to commands and/or data.
  253. */
  254. struct vmdata_gpa_direct {
  255. struct vmpacket_descriptor d;
  256. u32 reserved;
  257. u32 range_cnt;
  258. struct gpa_range range[1];
  259. } __packed;
  260. /* This is the format for a Additional Data Packet. */
  261. struct vmadditional_data {
  262. struct vmpacket_descriptor d;
  263. u64 total_bytes;
  264. u32 offset;
  265. u32 byte_cnt;
  266. unsigned char data[1];
  267. } __packed;
  268. union vmpacket_largest_possible_header {
  269. struct vmpacket_descriptor simple_hdr;
  270. struct vmtransfer_page_packet_header xfer_page_hdr;
  271. struct vmgpadl_packet_header gpadl_hdr;
  272. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  273. struct vmestablish_gpadl establish_gpadl_hdr;
  274. struct vmteardown_gpadl teardown_gpadl_hdr;
  275. struct vmdata_gpa_direct data_gpa_direct_hdr;
  276. };
  277. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  278. (void *)(((unsigned char *)__packet) + \
  279. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  280. #define VMPACKET_DATA_LENGTH(__packet) \
  281. ((((struct vmpacket_descriptor)__packet)->len8 - \
  282. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  283. #define VMPACKET_TRANSFER_MODE(__packet) \
  284. (((struct IMPACT)__packet)->type)
  285. enum vmbus_packet_type {
  286. VM_PKT_INVALID = 0x0,
  287. VM_PKT_SYNCH = 0x1,
  288. VM_PKT_ADD_XFER_PAGESET = 0x2,
  289. VM_PKT_RM_XFER_PAGESET = 0x3,
  290. VM_PKT_ESTABLISH_GPADL = 0x4,
  291. VM_PKT_TEARDOWN_GPADL = 0x5,
  292. VM_PKT_DATA_INBAND = 0x6,
  293. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  294. VM_PKT_DATA_USING_GPADL = 0x8,
  295. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  296. VM_PKT_CANCEL_REQUEST = 0xa,
  297. VM_PKT_COMP = 0xb,
  298. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  299. VM_PKT_ADDITIONAL_DATA = 0xd
  300. };
  301. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  302. /* Version 1 messages */
  303. enum vmbus_channel_message_type {
  304. CHANNELMSG_INVALID = 0,
  305. CHANNELMSG_OFFERCHANNEL = 1,
  306. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  307. CHANNELMSG_REQUESTOFFERS = 3,
  308. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  309. CHANNELMSG_OPENCHANNEL = 5,
  310. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  311. CHANNELMSG_CLOSECHANNEL = 7,
  312. CHANNELMSG_GPADL_HEADER = 8,
  313. CHANNELMSG_GPADL_BODY = 9,
  314. CHANNELMSG_GPADL_CREATED = 10,
  315. CHANNELMSG_GPADL_TEARDOWN = 11,
  316. CHANNELMSG_GPADL_TORNDOWN = 12,
  317. CHANNELMSG_RELID_RELEASED = 13,
  318. CHANNELMSG_INITIATE_CONTACT = 14,
  319. CHANNELMSG_VERSION_RESPONSE = 15,
  320. CHANNELMSG_UNLOAD = 16,
  321. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  322. CHANNELMSG_VIEWRANGE_ADD = 17,
  323. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  324. #endif
  325. CHANNELMSG_COUNT
  326. };
  327. struct vmbus_channel_message_header {
  328. enum vmbus_channel_message_type msgtype;
  329. u32 padding;
  330. } __packed;
  331. /* Query VMBus Version parameters */
  332. struct vmbus_channel_query_vmbus_version {
  333. struct vmbus_channel_message_header header;
  334. u32 version;
  335. } __packed;
  336. /* VMBus Version Supported parameters */
  337. struct vmbus_channel_version_supported {
  338. struct vmbus_channel_message_header header;
  339. u8 version_supported;
  340. } __packed;
  341. /* Offer Channel parameters */
  342. struct vmbus_channel_offer_channel {
  343. struct vmbus_channel_message_header header;
  344. struct vmbus_channel_offer offer;
  345. u32 child_relid;
  346. u8 monitorid;
  347. /*
  348. * win7 and beyond splits this field into a bit field.
  349. */
  350. u8 monitor_allocated:1;
  351. u8 reserved:7;
  352. /*
  353. * These are new fields added in win7 and later.
  354. * Do not access these fields without checking the
  355. * negotiated protocol.
  356. *
  357. * If "is_dedicated_interrupt" is set, we must not set the
  358. * associated bit in the channel bitmap while sending the
  359. * interrupt to the host.
  360. *
  361. * connection_id is to be used in signaling the host.
  362. */
  363. u16 is_dedicated_interrupt:1;
  364. u16 reserved1:15;
  365. u32 connection_id;
  366. } __packed;
  367. /* Rescind Offer parameters */
  368. struct vmbus_channel_rescind_offer {
  369. struct vmbus_channel_message_header header;
  370. u32 child_relid;
  371. } __packed;
  372. /*
  373. * Request Offer -- no parameters, SynIC message contains the partition ID
  374. * Set Snoop -- no parameters, SynIC message contains the partition ID
  375. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  376. * All Offers Delivered -- no parameters, SynIC message contains the partition
  377. * ID
  378. * Flush Client -- no parameters, SynIC message contains the partition ID
  379. */
  380. /* Open Channel parameters */
  381. struct vmbus_channel_open_channel {
  382. struct vmbus_channel_message_header header;
  383. /* Identifies the specific VMBus channel that is being opened. */
  384. u32 child_relid;
  385. /* ID making a particular open request at a channel offer unique. */
  386. u32 openid;
  387. /* GPADL for the channel's ring buffer. */
  388. u32 ringbuffer_gpadlhandle;
  389. /*
  390. * Starting with win8, this field will be used to specify
  391. * the target virtual processor on which to deliver the interrupt for
  392. * the host to guest communication.
  393. * Prior to win8, incoming channel interrupts would only
  394. * be delivered on cpu 0. Setting this value to 0 would
  395. * preserve the earlier behavior.
  396. */
  397. u32 target_vp;
  398. /*
  399. * The upstream ring buffer begins at offset zero in the memory
  400. * described by RingBufferGpadlHandle. The downstream ring buffer
  401. * follows it at this offset (in pages).
  402. */
  403. u32 downstream_ringbuffer_pageoffset;
  404. /* User-specific data to be passed along to the server endpoint. */
  405. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  406. } __packed;
  407. /* Open Channel Result parameters */
  408. struct vmbus_channel_open_result {
  409. struct vmbus_channel_message_header header;
  410. u32 child_relid;
  411. u32 openid;
  412. u32 status;
  413. } __packed;
  414. /* Close channel parameters; */
  415. struct vmbus_channel_close_channel {
  416. struct vmbus_channel_message_header header;
  417. u32 child_relid;
  418. } __packed;
  419. /* Channel Message GPADL */
  420. #define GPADL_TYPE_RING_BUFFER 1
  421. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  422. #define GPADL_TYPE_TRANSACTION 8
  423. /*
  424. * The number of PFNs in a GPADL message is defined by the number of
  425. * pages that would be spanned by ByteCount and ByteOffset. If the
  426. * implied number of PFNs won't fit in this packet, there will be a
  427. * follow-up packet that contains more.
  428. */
  429. struct vmbus_channel_gpadl_header {
  430. struct vmbus_channel_message_header header;
  431. u32 child_relid;
  432. u32 gpadl;
  433. u16 range_buflen;
  434. u16 rangecount;
  435. struct gpa_range range[0];
  436. } __packed;
  437. /* This is the followup packet that contains more PFNs. */
  438. struct vmbus_channel_gpadl_body {
  439. struct vmbus_channel_message_header header;
  440. u32 msgnumber;
  441. u32 gpadl;
  442. u64 pfn[0];
  443. } __packed;
  444. struct vmbus_channel_gpadl_created {
  445. struct vmbus_channel_message_header header;
  446. u32 child_relid;
  447. u32 gpadl;
  448. u32 creation_status;
  449. } __packed;
  450. struct vmbus_channel_gpadl_teardown {
  451. struct vmbus_channel_message_header header;
  452. u32 child_relid;
  453. u32 gpadl;
  454. } __packed;
  455. struct vmbus_channel_gpadl_torndown {
  456. struct vmbus_channel_message_header header;
  457. u32 gpadl;
  458. } __packed;
  459. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  460. struct vmbus_channel_view_range_add {
  461. struct vmbus_channel_message_header header;
  462. PHYSICAL_ADDRESS viewrange_base;
  463. u64 viewrange_length;
  464. u32 child_relid;
  465. } __packed;
  466. struct vmbus_channel_view_range_remove {
  467. struct vmbus_channel_message_header header;
  468. PHYSICAL_ADDRESS viewrange_base;
  469. u32 child_relid;
  470. } __packed;
  471. #endif
  472. struct vmbus_channel_relid_released {
  473. struct vmbus_channel_message_header header;
  474. u32 child_relid;
  475. } __packed;
  476. struct vmbus_channel_initiate_contact {
  477. struct vmbus_channel_message_header header;
  478. u32 vmbus_version_requested;
  479. u32 padding2;
  480. u64 interrupt_page;
  481. u64 monitor_page1;
  482. u64 monitor_page2;
  483. } __packed;
  484. struct vmbus_channel_version_response {
  485. struct vmbus_channel_message_header header;
  486. u8 version_supported;
  487. } __packed;
  488. enum vmbus_channel_state {
  489. CHANNEL_OFFER_STATE,
  490. CHANNEL_OPENING_STATE,
  491. CHANNEL_OPEN_STATE,
  492. CHANNEL_OPENED_STATE,
  493. };
  494. /*
  495. * Represents each channel msg on the vmbus connection This is a
  496. * variable-size data structure depending on the msg type itself
  497. */
  498. struct vmbus_channel_msginfo {
  499. /* Bookkeeping stuff */
  500. struct list_head msglistentry;
  501. /* So far, this is only used to handle gpadl body message */
  502. struct list_head submsglist;
  503. /* Synchronize the request/response if needed */
  504. struct completion waitevent;
  505. union {
  506. struct vmbus_channel_version_supported version_supported;
  507. struct vmbus_channel_open_result open_result;
  508. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  509. struct vmbus_channel_gpadl_created gpadl_created;
  510. struct vmbus_channel_version_response version_response;
  511. } response;
  512. u32 msgsize;
  513. /*
  514. * The channel message that goes out on the "wire".
  515. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  516. */
  517. unsigned char msg[0];
  518. };
  519. struct vmbus_close_msg {
  520. struct vmbus_channel_msginfo info;
  521. struct vmbus_channel_close_channel msg;
  522. };
  523. /* Define connection identifier type. */
  524. union hv_connection_id {
  525. u32 asu32;
  526. struct {
  527. u32 id:24;
  528. u32 reserved:8;
  529. } u;
  530. };
  531. /* Definition of the hv_signal_event hypercall input structure. */
  532. struct hv_input_signal_event {
  533. union hv_connection_id connectionid;
  534. u16 flag_number;
  535. u16 rsvdz;
  536. };
  537. struct hv_input_signal_event_buffer {
  538. u64 align8;
  539. struct hv_input_signal_event event;
  540. };
  541. struct vmbus_channel {
  542. struct list_head listentry;
  543. struct hv_device *device_obj;
  544. struct work_struct work;
  545. enum vmbus_channel_state state;
  546. struct vmbus_channel_offer_channel offermsg;
  547. /*
  548. * These are based on the OfferMsg.MonitorId.
  549. * Save it here for easy access.
  550. */
  551. u8 monitor_grp;
  552. u8 monitor_bit;
  553. u32 ringbuffer_gpadlhandle;
  554. /* Allocated memory for ring buffer */
  555. void *ringbuffer_pages;
  556. u32 ringbuffer_pagecount;
  557. struct hv_ring_buffer_info outbound; /* send to parent */
  558. struct hv_ring_buffer_info inbound; /* receive from parent */
  559. spinlock_t inbound_lock;
  560. struct workqueue_struct *controlwq;
  561. struct vmbus_close_msg close_msg;
  562. /* Channel callback are invoked in this workqueue context */
  563. /* HANDLE dataWorkQueue; */
  564. void (*onchannel_callback)(void *context);
  565. void *channel_callback_context;
  566. /*
  567. * A channel can be marked for efficient (batched)
  568. * reading:
  569. * If batched_reading is set to "true", we read until the
  570. * channel is empty and hold off interrupts from the host
  571. * during the entire read process.
  572. * If batched_reading is set to "false", the client is not
  573. * going to perform batched reading.
  574. *
  575. * By default we will enable batched reading; specific
  576. * drivers that don't want this behavior can turn it off.
  577. */
  578. bool batched_reading;
  579. bool is_dedicated_interrupt;
  580. struct hv_input_signal_event_buffer sig_buf;
  581. struct hv_input_signal_event *sig_event;
  582. /*
  583. * Starting with win8, this field will be used to specify
  584. * the target virtual processor on which to deliver the interrupt for
  585. * the host to guest communication.
  586. * Prior to win8, incoming channel interrupts would only
  587. * be delivered on cpu 0. Setting this value to 0 would
  588. * preserve the earlier behavior.
  589. */
  590. u32 target_vp;
  591. /*
  592. * Support for sub-channels. For high performance devices,
  593. * it will be useful to have multiple sub-channels to support
  594. * a scalable communication infrastructure with the host.
  595. * The support for sub-channels is implemented as an extention
  596. * to the current infrastructure.
  597. * The initial offer is considered the primary channel and this
  598. * offer message will indicate if the host supports sub-channels.
  599. * The guest is free to ask for sub-channels to be offerred and can
  600. * open these sub-channels as a normal "primary" channel. However,
  601. * all sub-channels will have the same type and instance guids as the
  602. * primary channel. Requests sent on a given channel will result in a
  603. * response on the same channel.
  604. */
  605. /*
  606. * Sub-channel creation callback. This callback will be called in
  607. * process context when a sub-channel offer is received from the host.
  608. * The guest can open the sub-channel in the context of this callback.
  609. */
  610. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  611. spinlock_t sc_lock;
  612. /*
  613. * All Sub-channels of a primary channel are linked here.
  614. */
  615. struct list_head sc_list;
  616. /*
  617. * The primary channel this sub-channel belongs to.
  618. * This will be NULL for the primary channel.
  619. */
  620. struct vmbus_channel *primary_channel;
  621. /*
  622. * Support per-channel state for use by vmbus drivers.
  623. */
  624. void *per_channel_state;
  625. };
  626. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  627. {
  628. c->batched_reading = state;
  629. }
  630. static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
  631. {
  632. c->per_channel_state = s;
  633. }
  634. static inline void *get_per_channel_state(struct vmbus_channel *c)
  635. {
  636. return c->per_channel_state;
  637. }
  638. void vmbus_onmessage(void *context);
  639. int vmbus_request_offers(void);
  640. /*
  641. * APIs for managing sub-channels.
  642. */
  643. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  644. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  645. /*
  646. * Retrieve the (sub) channel on which to send an outgoing request.
  647. * When a primary channel has multiple sub-channels, we choose a
  648. * channel whose VCPU binding is closest to the VCPU on which
  649. * this call is being made.
  650. */
  651. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  652. /*
  653. * Check if sub-channels have already been offerred. This API will be useful
  654. * when the driver is unloaded after establishing sub-channels. In this case,
  655. * when the driver is re-loaded, the driver would have to check if the
  656. * subchannels have already been established before attempting to request
  657. * the creation of sub-channels.
  658. * This function returns TRUE to indicate that subchannels have already been
  659. * created.
  660. * This function should be invoked after setting the callback function for
  661. * sub-channel creation.
  662. */
  663. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  664. /* The format must be the same as struct vmdata_gpa_direct */
  665. struct vmbus_channel_packet_page_buffer {
  666. u16 type;
  667. u16 dataoffset8;
  668. u16 length8;
  669. u16 flags;
  670. u64 transactionid;
  671. u32 reserved;
  672. u32 rangecount;
  673. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  674. } __packed;
  675. /* The format must be the same as struct vmdata_gpa_direct */
  676. struct vmbus_channel_packet_multipage_buffer {
  677. u16 type;
  678. u16 dataoffset8;
  679. u16 length8;
  680. u16 flags;
  681. u64 transactionid;
  682. u32 reserved;
  683. u32 rangecount; /* Always 1 in this case */
  684. struct hv_multipage_buffer range;
  685. } __packed;
  686. extern int vmbus_open(struct vmbus_channel *channel,
  687. u32 send_ringbuffersize,
  688. u32 recv_ringbuffersize,
  689. void *userdata,
  690. u32 userdatalen,
  691. void(*onchannel_callback)(void *context),
  692. void *context);
  693. extern void vmbus_close(struct vmbus_channel *channel);
  694. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  695. void *buffer,
  696. u32 bufferLen,
  697. u64 requestid,
  698. enum vmbus_packet_type type,
  699. u32 flags);
  700. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  701. struct hv_page_buffer pagebuffers[],
  702. u32 pagecount,
  703. void *buffer,
  704. u32 bufferlen,
  705. u64 requestid);
  706. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  707. struct hv_multipage_buffer *mpb,
  708. void *buffer,
  709. u32 bufferlen,
  710. u64 requestid);
  711. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  712. void *kbuffer,
  713. u32 size,
  714. u32 *gpadl_handle);
  715. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  716. u32 gpadl_handle);
  717. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  718. void *buffer,
  719. u32 bufferlen,
  720. u32 *buffer_actual_len,
  721. u64 *requestid);
  722. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  723. void *buffer,
  724. u32 bufferlen,
  725. u32 *buffer_actual_len,
  726. u64 *requestid);
  727. extern void vmbus_ontimer(unsigned long data);
  728. /* Base driver object */
  729. struct hv_driver {
  730. const char *name;
  731. /* the device type supported by this driver */
  732. uuid_le dev_type;
  733. const struct hv_vmbus_device_id *id_table;
  734. struct device_driver driver;
  735. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  736. int (*remove)(struct hv_device *);
  737. void (*shutdown)(struct hv_device *);
  738. };
  739. /* Base device object */
  740. struct hv_device {
  741. /* the device type id of this device */
  742. uuid_le dev_type;
  743. /* the device instance id of this device */
  744. uuid_le dev_instance;
  745. struct device device;
  746. struct vmbus_channel *channel;
  747. };
  748. static inline struct hv_device *device_to_hv_device(struct device *d)
  749. {
  750. return container_of(d, struct hv_device, device);
  751. }
  752. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  753. {
  754. return container_of(d, struct hv_driver, driver);
  755. }
  756. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  757. {
  758. dev_set_drvdata(&dev->device, data);
  759. }
  760. static inline void *hv_get_drvdata(struct hv_device *dev)
  761. {
  762. return dev_get_drvdata(&dev->device);
  763. }
  764. /* Vmbus interface */
  765. #define vmbus_driver_register(driver) \
  766. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  767. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  768. struct module *owner,
  769. const char *mod_name);
  770. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  771. /**
  772. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  773. *
  774. * This macro is used to create a struct hv_vmbus_device_id that matches a
  775. * specific device.
  776. */
  777. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  778. g8, g9, ga, gb, gc, gd, ge, gf) \
  779. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  780. g8, g9, ga, gb, gc, gd, ge, gf },
  781. /*
  782. * GUID definitions of various offer types - services offered to the guest.
  783. */
  784. /*
  785. * Network GUID
  786. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  787. */
  788. #define HV_NIC_GUID \
  789. .guid = { \
  790. 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
  791. 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
  792. }
  793. /*
  794. * IDE GUID
  795. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  796. */
  797. #define HV_IDE_GUID \
  798. .guid = { \
  799. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
  800. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
  801. }
  802. /*
  803. * SCSI GUID
  804. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  805. */
  806. #define HV_SCSI_GUID \
  807. .guid = { \
  808. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
  809. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
  810. }
  811. /*
  812. * Shutdown GUID
  813. * {0e0b6031-5213-4934-818b-38d90ced39db}
  814. */
  815. #define HV_SHUTDOWN_GUID \
  816. .guid = { \
  817. 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
  818. 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
  819. }
  820. /*
  821. * Time Synch GUID
  822. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  823. */
  824. #define HV_TS_GUID \
  825. .guid = { \
  826. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
  827. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
  828. }
  829. /*
  830. * Heartbeat GUID
  831. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  832. */
  833. #define HV_HEART_BEAT_GUID \
  834. .guid = { \
  835. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
  836. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
  837. }
  838. /*
  839. * KVP GUID
  840. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  841. */
  842. #define HV_KVP_GUID \
  843. .guid = { \
  844. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
  845. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
  846. }
  847. /*
  848. * Dynamic memory GUID
  849. * {525074dc-8985-46e2-8057-a307dc18a502}
  850. */
  851. #define HV_DM_GUID \
  852. .guid = { \
  853. 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
  854. 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
  855. }
  856. /*
  857. * Mouse GUID
  858. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  859. */
  860. #define HV_MOUSE_GUID \
  861. .guid = { \
  862. 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
  863. 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
  864. }
  865. /*
  866. * VSS (Backup/Restore) GUID
  867. */
  868. #define HV_VSS_GUID \
  869. .guid = { \
  870. 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
  871. 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
  872. }
  873. /*
  874. * Synthetic Video GUID
  875. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  876. */
  877. #define HV_SYNTHVID_GUID \
  878. .guid = { \
  879. 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
  880. 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
  881. }
  882. /*
  883. * Synthetic FC GUID
  884. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  885. */
  886. #define HV_SYNTHFC_GUID \
  887. .guid = { \
  888. 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
  889. 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
  890. }
  891. /*
  892. * Common header for Hyper-V ICs
  893. */
  894. #define ICMSGTYPE_NEGOTIATE 0
  895. #define ICMSGTYPE_HEARTBEAT 1
  896. #define ICMSGTYPE_KVPEXCHANGE 2
  897. #define ICMSGTYPE_SHUTDOWN 3
  898. #define ICMSGTYPE_TIMESYNC 4
  899. #define ICMSGTYPE_VSS 5
  900. #define ICMSGHDRFLAG_TRANSACTION 1
  901. #define ICMSGHDRFLAG_REQUEST 2
  902. #define ICMSGHDRFLAG_RESPONSE 4
  903. /*
  904. * While we want to handle util services as regular devices,
  905. * there is only one instance of each of these services; so
  906. * we statically allocate the service specific state.
  907. */
  908. struct hv_util_service {
  909. u8 *recv_buffer;
  910. void (*util_cb)(void *);
  911. int (*util_init)(struct hv_util_service *);
  912. void (*util_deinit)(void);
  913. };
  914. struct vmbuspipe_hdr {
  915. u32 flags;
  916. u32 msgsize;
  917. } __packed;
  918. struct ic_version {
  919. u16 major;
  920. u16 minor;
  921. } __packed;
  922. struct icmsg_hdr {
  923. struct ic_version icverframe;
  924. u16 icmsgtype;
  925. struct ic_version icvermsg;
  926. u16 icmsgsize;
  927. u32 status;
  928. u8 ictransaction_id;
  929. u8 icflags;
  930. u8 reserved[2];
  931. } __packed;
  932. struct icmsg_negotiate {
  933. u16 icframe_vercnt;
  934. u16 icmsg_vercnt;
  935. u32 reserved;
  936. struct ic_version icversion_data[1]; /* any size array */
  937. } __packed;
  938. struct shutdown_msg_data {
  939. u32 reason_code;
  940. u32 timeout_seconds;
  941. u32 flags;
  942. u8 display_message[2048];
  943. } __packed;
  944. struct heartbeat_msg_data {
  945. u64 seq_num;
  946. u32 reserved[8];
  947. } __packed;
  948. /* Time Sync IC defs */
  949. #define ICTIMESYNCFLAG_PROBE 0
  950. #define ICTIMESYNCFLAG_SYNC 1
  951. #define ICTIMESYNCFLAG_SAMPLE 2
  952. #ifdef __x86_64__
  953. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  954. #else
  955. #define WLTIMEDELTA 116444736000000000LL
  956. #endif
  957. struct ictimesync_data {
  958. u64 parenttime;
  959. u64 childtime;
  960. u64 roundtriptime;
  961. u8 flags;
  962. } __packed;
  963. struct hyperv_service_callback {
  964. u8 msg_type;
  965. char *log_msg;
  966. uuid_le data;
  967. struct vmbus_channel *channel;
  968. void (*callback) (void *context);
  969. };
  970. #define MAX_SRV_VER 0x7ffffff
  971. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  972. struct icmsg_negotiate *, u8 *, int,
  973. int);
  974. int hv_kvp_init(struct hv_util_service *);
  975. void hv_kvp_deinit(void);
  976. void hv_kvp_onchannelcallback(void *);
  977. int hv_vss_init(struct hv_util_service *);
  978. void hv_vss_deinit(void);
  979. void hv_vss_onchannelcallback(void *);
  980. extern u64 hyperv_mmio_start;
  981. extern u64 hyperv_mmio_size;
  982. /*
  983. * Negotiated version with the Host.
  984. */
  985. extern __u32 vmbus_proto_version;
  986. #endif /* _HYPERV_H */