hyperv.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491
  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/completion.h>
  33. #include <linux/device.h>
  34. #include <linux/mod_devicetable.h>
  35. #include <linux/interrupt.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 priv_read_index;
  107. };
  108. static inline u32 hv_get_bytes_to_read(const struct hv_ring_buffer_info *rbi)
  109. {
  110. u32 read_loc, write_loc, dsize, read;
  111. dsize = rbi->ring_datasize;
  112. read_loc = rbi->ring_buffer->read_index;
  113. write_loc = READ_ONCE(rbi->ring_buffer->write_index);
  114. read = write_loc >= read_loc ? (write_loc - read_loc) :
  115. (dsize - read_loc) + write_loc;
  116. return read;
  117. }
  118. static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi)
  119. {
  120. u32 read_loc, write_loc, dsize, write;
  121. dsize = rbi->ring_datasize;
  122. read_loc = READ_ONCE(rbi->ring_buffer->read_index);
  123. write_loc = rbi->ring_buffer->write_index;
  124. write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  125. read_loc - write_loc;
  126. return 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. static inline u32
  389. hv_ringbuffer_pending_size(const struct hv_ring_buffer_info *rbi)
  390. {
  391. return rbi->ring_buffer->pending_send_sz;
  392. }
  393. /*
  394. * Request Offer -- no parameters, SynIC message contains the partition ID
  395. * Set Snoop -- no parameters, SynIC message contains the partition ID
  396. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  397. * All Offers Delivered -- no parameters, SynIC message contains the partition
  398. * ID
  399. * Flush Client -- no parameters, SynIC message contains the partition ID
  400. */
  401. /* Open Channel parameters */
  402. struct vmbus_channel_open_channel {
  403. struct vmbus_channel_message_header header;
  404. /* Identifies the specific VMBus channel that is being opened. */
  405. u32 child_relid;
  406. /* ID making a particular open request at a channel offer unique. */
  407. u32 openid;
  408. /* GPADL for the channel's ring buffer. */
  409. u32 ringbuffer_gpadlhandle;
  410. /*
  411. * Starting with win8, this field will be used to specify
  412. * the target virtual processor on which to deliver the interrupt for
  413. * the host to guest communication.
  414. * Prior to win8, incoming channel interrupts would only
  415. * be delivered on cpu 0. Setting this value to 0 would
  416. * preserve the earlier behavior.
  417. */
  418. u32 target_vp;
  419. /*
  420. * The upstream ring buffer begins at offset zero in the memory
  421. * described by RingBufferGpadlHandle. The downstream ring buffer
  422. * follows it at this offset (in pages).
  423. */
  424. u32 downstream_ringbuffer_pageoffset;
  425. /* User-specific data to be passed along to the server endpoint. */
  426. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  427. } __packed;
  428. /* Open Channel Result parameters */
  429. struct vmbus_channel_open_result {
  430. struct vmbus_channel_message_header header;
  431. u32 child_relid;
  432. u32 openid;
  433. u32 status;
  434. } __packed;
  435. /* Close channel parameters; */
  436. struct vmbus_channel_close_channel {
  437. struct vmbus_channel_message_header header;
  438. u32 child_relid;
  439. } __packed;
  440. /* Channel Message GPADL */
  441. #define GPADL_TYPE_RING_BUFFER 1
  442. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  443. #define GPADL_TYPE_TRANSACTION 8
  444. /*
  445. * The number of PFNs in a GPADL message is defined by the number of
  446. * pages that would be spanned by ByteCount and ByteOffset. If the
  447. * implied number of PFNs won't fit in this packet, there will be a
  448. * follow-up packet that contains more.
  449. */
  450. struct vmbus_channel_gpadl_header {
  451. struct vmbus_channel_message_header header;
  452. u32 child_relid;
  453. u32 gpadl;
  454. u16 range_buflen;
  455. u16 rangecount;
  456. struct gpa_range range[0];
  457. } __packed;
  458. /* This is the followup packet that contains more PFNs. */
  459. struct vmbus_channel_gpadl_body {
  460. struct vmbus_channel_message_header header;
  461. u32 msgnumber;
  462. u32 gpadl;
  463. u64 pfn[0];
  464. } __packed;
  465. struct vmbus_channel_gpadl_created {
  466. struct vmbus_channel_message_header header;
  467. u32 child_relid;
  468. u32 gpadl;
  469. u32 creation_status;
  470. } __packed;
  471. struct vmbus_channel_gpadl_teardown {
  472. struct vmbus_channel_message_header header;
  473. u32 child_relid;
  474. u32 gpadl;
  475. } __packed;
  476. struct vmbus_channel_gpadl_torndown {
  477. struct vmbus_channel_message_header header;
  478. u32 gpadl;
  479. } __packed;
  480. struct vmbus_channel_relid_released {
  481. struct vmbus_channel_message_header header;
  482. u32 child_relid;
  483. } __packed;
  484. struct vmbus_channel_initiate_contact {
  485. struct vmbus_channel_message_header header;
  486. u32 vmbus_version_requested;
  487. u32 target_vcpu; /* The VCPU the host should respond to */
  488. u64 interrupt_page;
  489. u64 monitor_page1;
  490. u64 monitor_page2;
  491. } __packed;
  492. /* Hyper-V socket: guest's connect()-ing to host */
  493. struct vmbus_channel_tl_connect_request {
  494. struct vmbus_channel_message_header header;
  495. uuid_le guest_endpoint_id;
  496. uuid_le host_service_id;
  497. } __packed;
  498. struct vmbus_channel_version_response {
  499. struct vmbus_channel_message_header header;
  500. u8 version_supported;
  501. } __packed;
  502. enum vmbus_channel_state {
  503. CHANNEL_OFFER_STATE,
  504. CHANNEL_OPENING_STATE,
  505. CHANNEL_OPEN_STATE,
  506. CHANNEL_OPENED_STATE,
  507. };
  508. /*
  509. * Represents each channel msg on the vmbus connection This is a
  510. * variable-size data structure depending on the msg type itself
  511. */
  512. struct vmbus_channel_msginfo {
  513. /* Bookkeeping stuff */
  514. struct list_head msglistentry;
  515. /* So far, this is only used to handle gpadl body message */
  516. struct list_head submsglist;
  517. /* Synchronize the request/response if needed */
  518. struct completion waitevent;
  519. struct vmbus_channel *waiting_channel;
  520. union {
  521. struct vmbus_channel_version_supported version_supported;
  522. struct vmbus_channel_open_result open_result;
  523. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  524. struct vmbus_channel_gpadl_created gpadl_created;
  525. struct vmbus_channel_version_response version_response;
  526. } response;
  527. u32 msgsize;
  528. /*
  529. * The channel message that goes out on the "wire".
  530. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  531. */
  532. unsigned char msg[0];
  533. };
  534. struct vmbus_close_msg {
  535. struct vmbus_channel_msginfo info;
  536. struct vmbus_channel_close_channel msg;
  537. };
  538. /* Define connection identifier type. */
  539. union hv_connection_id {
  540. u32 asu32;
  541. struct {
  542. u32 id:24;
  543. u32 reserved:8;
  544. } u;
  545. };
  546. enum hv_numa_policy {
  547. HV_BALANCED = 0,
  548. HV_LOCALIZED,
  549. };
  550. enum vmbus_device_type {
  551. HV_IDE = 0,
  552. HV_SCSI,
  553. HV_FC,
  554. HV_NIC,
  555. HV_ND,
  556. HV_PCIE,
  557. HV_FB,
  558. HV_KBD,
  559. HV_MOUSE,
  560. HV_KVP,
  561. HV_TS,
  562. HV_HB,
  563. HV_SHUTDOWN,
  564. HV_FCOPY,
  565. HV_BACKUP,
  566. HV_DM,
  567. HV_UNKNOWN,
  568. };
  569. struct vmbus_device {
  570. u16 dev_type;
  571. uuid_le guid;
  572. bool perf_device;
  573. };
  574. struct vmbus_channel {
  575. struct list_head listentry;
  576. struct hv_device *device_obj;
  577. enum vmbus_channel_state state;
  578. struct vmbus_channel_offer_channel offermsg;
  579. /*
  580. * These are based on the OfferMsg.MonitorId.
  581. * Save it here for easy access.
  582. */
  583. u8 monitor_grp;
  584. u8 monitor_bit;
  585. bool rescind; /* got rescind msg */
  586. u32 ringbuffer_gpadlhandle;
  587. /* Allocated memory for ring buffer */
  588. void *ringbuffer_pages;
  589. u32 ringbuffer_pagecount;
  590. struct hv_ring_buffer_info outbound; /* send to parent */
  591. struct hv_ring_buffer_info inbound; /* receive from parent */
  592. struct vmbus_close_msg close_msg;
  593. /* Statistics */
  594. u64 interrupts; /* Host to Guest interrupts */
  595. u64 sig_events; /* Guest to Host events */
  596. /* Channel callback's invoked in softirq context */
  597. struct tasklet_struct callback_event;
  598. void (*onchannel_callback)(void *context);
  599. void *channel_callback_context;
  600. /*
  601. * A channel can be marked for one of three modes of reading:
  602. * BATCHED - callback called from taslket and should read
  603. * channel until empty. Interrupts from the host
  604. * are masked while read is in process (default).
  605. * DIRECT - callback called from tasklet (softirq).
  606. * ISR - callback called in interrupt context and must
  607. * invoke its own deferred processing.
  608. * Host interrupts are disabled and must be re-enabled
  609. * when ring is empty.
  610. */
  611. enum hv_callback_mode {
  612. HV_CALL_BATCHED,
  613. HV_CALL_DIRECT,
  614. HV_CALL_ISR
  615. } callback_mode;
  616. bool is_dedicated_interrupt;
  617. u64 sig_event;
  618. /*
  619. * Starting with win8, this field will be used to specify
  620. * the target virtual processor on which to deliver the interrupt for
  621. * the host to guest communication.
  622. * Prior to win8, incoming channel interrupts would only
  623. * be delivered on cpu 0. Setting this value to 0 would
  624. * preserve the earlier behavior.
  625. */
  626. u32 target_vp;
  627. /* The corresponding CPUID in the guest */
  628. u32 target_cpu;
  629. /*
  630. * State to manage the CPU affiliation of channels.
  631. */
  632. struct cpumask alloced_cpus_in_node;
  633. int numa_node;
  634. /*
  635. * Support for sub-channels. For high performance devices,
  636. * it will be useful to have multiple sub-channels to support
  637. * a scalable communication infrastructure with the host.
  638. * The support for sub-channels is implemented as an extention
  639. * to the current infrastructure.
  640. * The initial offer is considered the primary channel and this
  641. * offer message will indicate if the host supports sub-channels.
  642. * The guest is free to ask for sub-channels to be offerred and can
  643. * open these sub-channels as a normal "primary" channel. However,
  644. * all sub-channels will have the same type and instance guids as the
  645. * primary channel. Requests sent on a given channel will result in a
  646. * response on the same channel.
  647. */
  648. /*
  649. * Sub-channel creation callback. This callback will be called in
  650. * process context when a sub-channel offer is received from the host.
  651. * The guest can open the sub-channel in the context of this callback.
  652. */
  653. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  654. /*
  655. * Channel rescind callback. Some channels (the hvsock ones), need to
  656. * register a callback which is invoked in vmbus_onoffer_rescind().
  657. */
  658. void (*chn_rescind_callback)(struct vmbus_channel *channel);
  659. /*
  660. * The spinlock to protect the structure. It is being used to protect
  661. * test-and-set access to various attributes of the structure as well
  662. * as all sc_list operations.
  663. */
  664. spinlock_t lock;
  665. /*
  666. * All Sub-channels of a primary channel are linked here.
  667. */
  668. struct list_head sc_list;
  669. /*
  670. * Current number of sub-channels.
  671. */
  672. int num_sc;
  673. /*
  674. * Number of a sub-channel (position within sc_list) which is supposed
  675. * to be used as the next outgoing channel.
  676. */
  677. int next_oc;
  678. /*
  679. * The primary channel this sub-channel belongs to.
  680. * This will be NULL for the primary channel.
  681. */
  682. struct vmbus_channel *primary_channel;
  683. /*
  684. * Support per-channel state for use by vmbus drivers.
  685. */
  686. void *per_channel_state;
  687. /*
  688. * To support per-cpu lookup mapping of relid to channel,
  689. * link up channels based on their CPU affinity.
  690. */
  691. struct list_head percpu_list;
  692. /*
  693. * Defer freeing channel until after all cpu's have
  694. * gone through grace period.
  695. */
  696. struct rcu_head rcu;
  697. /*
  698. * For sysfs per-channel properties.
  699. */
  700. struct kobject kobj;
  701. /*
  702. * For performance critical channels (storage, networking
  703. * etc,), Hyper-V has a mechanism to enhance the throughput
  704. * at the expense of latency:
  705. * When the host is to be signaled, we just set a bit in a shared page
  706. * and this bit will be inspected by the hypervisor within a certain
  707. * window and if the bit is set, the host will be signaled. The window
  708. * of time is the monitor latency - currently around 100 usecs. This
  709. * mechanism improves throughput by:
  710. *
  711. * A) Making the host more efficient - each time it wakes up,
  712. * potentially it will process morev number of packets. The
  713. * monitor latency allows a batch to build up.
  714. * B) By deferring the hypercall to signal, we will also minimize
  715. * the interrupts.
  716. *
  717. * Clearly, these optimizations improve throughput at the expense of
  718. * latency. Furthermore, since the channel is shared for both
  719. * control and data messages, control messages currently suffer
  720. * unnecessary latency adversley impacting performance and boot
  721. * time. To fix this issue, permit tagging the channel as being
  722. * in "low latency" mode. In this mode, we will bypass the monitor
  723. * mechanism.
  724. */
  725. bool low_latency;
  726. /*
  727. * NUMA distribution policy:
  728. * We support teo policies:
  729. * 1) Balanced: Here all performance critical channels are
  730. * distributed evenly amongst all the NUMA nodes.
  731. * This policy will be the default policy.
  732. * 2) Localized: All channels of a given instance of a
  733. * performance critical service will be assigned CPUs
  734. * within a selected NUMA node.
  735. */
  736. enum hv_numa_policy affinity_policy;
  737. bool probe_done;
  738. };
  739. static inline bool is_hvsock_channel(const struct vmbus_channel *c)
  740. {
  741. return !!(c->offermsg.offer.chn_flags &
  742. VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER);
  743. }
  744. static inline void set_channel_affinity_state(struct vmbus_channel *c,
  745. enum hv_numa_policy policy)
  746. {
  747. c->affinity_policy = policy;
  748. }
  749. static inline void set_channel_read_mode(struct vmbus_channel *c,
  750. enum hv_callback_mode mode)
  751. {
  752. c->callback_mode = mode;
  753. }
  754. static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
  755. {
  756. c->per_channel_state = s;
  757. }
  758. static inline void *get_per_channel_state(struct vmbus_channel *c)
  759. {
  760. return c->per_channel_state;
  761. }
  762. static inline void set_channel_pending_send_size(struct vmbus_channel *c,
  763. u32 size)
  764. {
  765. c->outbound.ring_buffer->pending_send_sz = size;
  766. }
  767. static inline void set_low_latency_mode(struct vmbus_channel *c)
  768. {
  769. c->low_latency = true;
  770. }
  771. static inline void clear_low_latency_mode(struct vmbus_channel *c)
  772. {
  773. c->low_latency = false;
  774. }
  775. void vmbus_onmessage(void *context);
  776. int vmbus_request_offers(void);
  777. /*
  778. * APIs for managing sub-channels.
  779. */
  780. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  781. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  782. void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
  783. void (*chn_rescind_cb)(struct vmbus_channel *));
  784. /*
  785. * Retrieve the (sub) channel on which to send an outgoing request.
  786. * When a primary channel has multiple sub-channels, we choose a
  787. * channel whose VCPU binding is closest to the VCPU on which
  788. * this call is being made.
  789. */
  790. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  791. /*
  792. * Check if sub-channels have already been offerred. This API will be useful
  793. * when the driver is unloaded after establishing sub-channels. In this case,
  794. * when the driver is re-loaded, the driver would have to check if the
  795. * subchannels have already been established before attempting to request
  796. * the creation of sub-channels.
  797. * This function returns TRUE to indicate that subchannels have already been
  798. * created.
  799. * This function should be invoked after setting the callback function for
  800. * sub-channel creation.
  801. */
  802. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  803. /* The format must be the same as struct vmdata_gpa_direct */
  804. struct vmbus_channel_packet_page_buffer {
  805. u16 type;
  806. u16 dataoffset8;
  807. u16 length8;
  808. u16 flags;
  809. u64 transactionid;
  810. u32 reserved;
  811. u32 rangecount;
  812. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  813. } __packed;
  814. /* The format must be the same as struct vmdata_gpa_direct */
  815. struct vmbus_channel_packet_multipage_buffer {
  816. u16 type;
  817. u16 dataoffset8;
  818. u16 length8;
  819. u16 flags;
  820. u64 transactionid;
  821. u32 reserved;
  822. u32 rangecount; /* Always 1 in this case */
  823. struct hv_multipage_buffer range;
  824. } __packed;
  825. /* The format must be the same as struct vmdata_gpa_direct */
  826. struct vmbus_packet_mpb_array {
  827. u16 type;
  828. u16 dataoffset8;
  829. u16 length8;
  830. u16 flags;
  831. u64 transactionid;
  832. u32 reserved;
  833. u32 rangecount; /* Always 1 in this case */
  834. struct hv_mpb_array range;
  835. } __packed;
  836. extern int vmbus_open(struct vmbus_channel *channel,
  837. u32 send_ringbuffersize,
  838. u32 recv_ringbuffersize,
  839. void *userdata,
  840. u32 userdatalen,
  841. void (*onchannel_callback)(void *context),
  842. void *context);
  843. extern void vmbus_close(struct vmbus_channel *channel);
  844. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  845. void *buffer,
  846. u32 bufferLen,
  847. u64 requestid,
  848. enum vmbus_packet_type type,
  849. u32 flags);
  850. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  851. struct hv_page_buffer pagebuffers[],
  852. u32 pagecount,
  853. void *buffer,
  854. u32 bufferlen,
  855. u64 requestid);
  856. extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
  857. struct vmbus_packet_mpb_array *mpb,
  858. u32 desc_size,
  859. void *buffer,
  860. u32 bufferlen,
  861. u64 requestid);
  862. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  863. void *kbuffer,
  864. u32 size,
  865. u32 *gpadl_handle);
  866. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  867. u32 gpadl_handle);
  868. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  869. void *buffer,
  870. u32 bufferlen,
  871. u32 *buffer_actual_len,
  872. u64 *requestid);
  873. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  874. void *buffer,
  875. u32 bufferlen,
  876. u32 *buffer_actual_len,
  877. u64 *requestid);
  878. extern void vmbus_ontimer(unsigned long data);
  879. /* Base driver object */
  880. struct hv_driver {
  881. const char *name;
  882. /*
  883. * A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER
  884. * channel flag, actually doesn't mean a synthetic device because the
  885. * offer's if_type/if_instance can change for every new hvsock
  886. * connection.
  887. *
  888. * However, to facilitate the notification of new-offer/rescind-offer
  889. * from vmbus driver to hvsock driver, we can handle hvsock offer as
  890. * a special vmbus device, and hence we need the below flag to
  891. * indicate if the driver is the hvsock driver or not: we need to
  892. * specially treat the hvosck offer & driver in vmbus_match().
  893. */
  894. bool hvsock;
  895. /* the device type supported by this driver */
  896. uuid_le dev_type;
  897. const struct hv_vmbus_device_id *id_table;
  898. struct device_driver driver;
  899. /* dynamic device GUID's */
  900. struct {
  901. spinlock_t lock;
  902. struct list_head list;
  903. } dynids;
  904. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  905. int (*remove)(struct hv_device *);
  906. void (*shutdown)(struct hv_device *);
  907. };
  908. /* Base device object */
  909. struct hv_device {
  910. /* the device type id of this device */
  911. uuid_le dev_type;
  912. /* the device instance id of this device */
  913. uuid_le dev_instance;
  914. u16 vendor_id;
  915. u16 device_id;
  916. struct device device;
  917. struct vmbus_channel *channel;
  918. struct kset *channels_kset;
  919. };
  920. static inline struct hv_device *device_to_hv_device(struct device *d)
  921. {
  922. return container_of(d, struct hv_device, device);
  923. }
  924. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  925. {
  926. return container_of(d, struct hv_driver, driver);
  927. }
  928. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  929. {
  930. dev_set_drvdata(&dev->device, data);
  931. }
  932. static inline void *hv_get_drvdata(struct hv_device *dev)
  933. {
  934. return dev_get_drvdata(&dev->device);
  935. }
  936. struct hv_ring_buffer_debug_info {
  937. u32 current_interrupt_mask;
  938. u32 current_read_index;
  939. u32 current_write_index;
  940. u32 bytes_avail_toread;
  941. u32 bytes_avail_towrite;
  942. };
  943. void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
  944. struct hv_ring_buffer_debug_info *debug_info);
  945. /* Vmbus interface */
  946. #define vmbus_driver_register(driver) \
  947. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  948. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  949. struct module *owner,
  950. const char *mod_name);
  951. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  952. void vmbus_hvsock_device_unregister(struct vmbus_channel *channel);
  953. int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
  954. resource_size_t min, resource_size_t max,
  955. resource_size_t size, resource_size_t align,
  956. bool fb_overlap_ok);
  957. void vmbus_free_mmio(resource_size_t start, resource_size_t size);
  958. /*
  959. * GUID definitions of various offer types - services offered to the guest.
  960. */
  961. /*
  962. * Network GUID
  963. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  964. */
  965. #define HV_NIC_GUID \
  966. .guid = UUID_LE(0xf8615163, 0xdf3e, 0x46c5, 0x91, 0x3f, \
  967. 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e)
  968. /*
  969. * IDE GUID
  970. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  971. */
  972. #define HV_IDE_GUID \
  973. .guid = UUID_LE(0x32412632, 0x86cb, 0x44a2, 0x9b, 0x5c, \
  974. 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
  975. /*
  976. * SCSI GUID
  977. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  978. */
  979. #define HV_SCSI_GUID \
  980. .guid = UUID_LE(0xba6163d9, 0x04a1, 0x4d29, 0xb6, 0x05, \
  981. 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
  982. /*
  983. * Shutdown GUID
  984. * {0e0b6031-5213-4934-818b-38d90ced39db}
  985. */
  986. #define HV_SHUTDOWN_GUID \
  987. .guid = UUID_LE(0x0e0b6031, 0x5213, 0x4934, 0x81, 0x8b, \
  988. 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb)
  989. /*
  990. * Time Synch GUID
  991. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  992. */
  993. #define HV_TS_GUID \
  994. .guid = UUID_LE(0x9527e630, 0xd0ae, 0x497b, 0xad, 0xce, \
  995. 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf)
  996. /*
  997. * Heartbeat GUID
  998. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  999. */
  1000. #define HV_HEART_BEAT_GUID \
  1001. .guid = UUID_LE(0x57164f39, 0x9115, 0x4e78, 0xab, 0x55, \
  1002. 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d)
  1003. /*
  1004. * KVP GUID
  1005. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1006. */
  1007. #define HV_KVP_GUID \
  1008. .guid = UUID_LE(0xa9a0f4e7, 0x5a45, 0x4d96, 0xb8, 0x27, \
  1009. 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6)
  1010. /*
  1011. * Dynamic memory GUID
  1012. * {525074dc-8985-46e2-8057-a307dc18a502}
  1013. */
  1014. #define HV_DM_GUID \
  1015. .guid = UUID_LE(0x525074dc, 0x8985, 0x46e2, 0x80, 0x57, \
  1016. 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02)
  1017. /*
  1018. * Mouse GUID
  1019. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1020. */
  1021. #define HV_MOUSE_GUID \
  1022. .guid = UUID_LE(0xcfa8b69e, 0x5b4a, 0x4cc0, 0xb9, 0x8b, \
  1023. 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a)
  1024. /*
  1025. * Keyboard GUID
  1026. * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
  1027. */
  1028. #define HV_KBD_GUID \
  1029. .guid = UUID_LE(0xf912ad6d, 0x2b17, 0x48ea, 0xbd, 0x65, \
  1030. 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84)
  1031. /*
  1032. * VSS (Backup/Restore) GUID
  1033. */
  1034. #define HV_VSS_GUID \
  1035. .guid = UUID_LE(0x35fa2e29, 0xea23, 0x4236, 0x96, 0xae, \
  1036. 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40)
  1037. /*
  1038. * Synthetic Video GUID
  1039. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1040. */
  1041. #define HV_SYNTHVID_GUID \
  1042. .guid = UUID_LE(0xda0a7802, 0xe377, 0x4aac, 0x8e, 0x77, \
  1043. 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8)
  1044. /*
  1045. * Synthetic FC GUID
  1046. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1047. */
  1048. #define HV_SYNTHFC_GUID \
  1049. .guid = UUID_LE(0x2f9bcc4a, 0x0069, 0x4af3, 0xb7, 0x6b, \
  1050. 0x6f, 0xd0, 0xbe, 0x52, 0x8c, 0xda)
  1051. /*
  1052. * Guest File Copy Service
  1053. * {34D14BE3-DEE4-41c8-9AE7-6B174977C192}
  1054. */
  1055. #define HV_FCOPY_GUID \
  1056. .guid = UUID_LE(0x34d14be3, 0xdee4, 0x41c8, 0x9a, 0xe7, \
  1057. 0x6b, 0x17, 0x49, 0x77, 0xc1, 0x92)
  1058. /*
  1059. * NetworkDirect. This is the guest RDMA service.
  1060. * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}
  1061. */
  1062. #define HV_ND_GUID \
  1063. .guid = UUID_LE(0x8c2eaf3d, 0x32a7, 0x4b09, 0xab, 0x99, \
  1064. 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01)
  1065. /*
  1066. * PCI Express Pass Through
  1067. * {44C4F61D-4444-4400-9D52-802E27EDE19F}
  1068. */
  1069. #define HV_PCIE_GUID \
  1070. .guid = UUID_LE(0x44c4f61d, 0x4444, 0x4400, 0x9d, 0x52, \
  1071. 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f)
  1072. /*
  1073. * Linux doesn't support the 3 devices: the first two are for
  1074. * Automatic Virtual Machine Activation, and the third is for
  1075. * Remote Desktop Virtualization.
  1076. * {f8e65716-3cb3-4a06-9a60-1889c5cccab5}
  1077. * {3375baf4-9e15-4b30-b765-67acb10d607b}
  1078. * {276aacf4-ac15-426c-98dd-7521ad3f01fe}
  1079. */
  1080. #define HV_AVMA1_GUID \
  1081. .guid = UUID_LE(0xf8e65716, 0x3cb3, 0x4a06, 0x9a, 0x60, \
  1082. 0x18, 0x89, 0xc5, 0xcc, 0xca, 0xb5)
  1083. #define HV_AVMA2_GUID \
  1084. .guid = UUID_LE(0x3375baf4, 0x9e15, 0x4b30, 0xb7, 0x65, \
  1085. 0x67, 0xac, 0xb1, 0x0d, 0x60, 0x7b)
  1086. #define HV_RDV_GUID \
  1087. .guid = UUID_LE(0x276aacf4, 0xac15, 0x426c, 0x98, 0xdd, \
  1088. 0x75, 0x21, 0xad, 0x3f, 0x01, 0xfe)
  1089. /*
  1090. * Common header for Hyper-V ICs
  1091. */
  1092. #define ICMSGTYPE_NEGOTIATE 0
  1093. #define ICMSGTYPE_HEARTBEAT 1
  1094. #define ICMSGTYPE_KVPEXCHANGE 2
  1095. #define ICMSGTYPE_SHUTDOWN 3
  1096. #define ICMSGTYPE_TIMESYNC 4
  1097. #define ICMSGTYPE_VSS 5
  1098. #define ICMSGHDRFLAG_TRANSACTION 1
  1099. #define ICMSGHDRFLAG_REQUEST 2
  1100. #define ICMSGHDRFLAG_RESPONSE 4
  1101. /*
  1102. * While we want to handle util services as regular devices,
  1103. * there is only one instance of each of these services; so
  1104. * we statically allocate the service specific state.
  1105. */
  1106. struct hv_util_service {
  1107. u8 *recv_buffer;
  1108. void *channel;
  1109. void (*util_cb)(void *);
  1110. int (*util_init)(struct hv_util_service *);
  1111. void (*util_deinit)(void);
  1112. };
  1113. struct vmbuspipe_hdr {
  1114. u32 flags;
  1115. u32 msgsize;
  1116. } __packed;
  1117. struct ic_version {
  1118. u16 major;
  1119. u16 minor;
  1120. } __packed;
  1121. struct icmsg_hdr {
  1122. struct ic_version icverframe;
  1123. u16 icmsgtype;
  1124. struct ic_version icvermsg;
  1125. u16 icmsgsize;
  1126. u32 status;
  1127. u8 ictransaction_id;
  1128. u8 icflags;
  1129. u8 reserved[2];
  1130. } __packed;
  1131. struct icmsg_negotiate {
  1132. u16 icframe_vercnt;
  1133. u16 icmsg_vercnt;
  1134. u32 reserved;
  1135. struct ic_version icversion_data[1]; /* any size array */
  1136. } __packed;
  1137. struct shutdown_msg_data {
  1138. u32 reason_code;
  1139. u32 timeout_seconds;
  1140. u32 flags;
  1141. u8 display_message[2048];
  1142. } __packed;
  1143. struct heartbeat_msg_data {
  1144. u64 seq_num;
  1145. u32 reserved[8];
  1146. } __packed;
  1147. /* Time Sync IC defs */
  1148. #define ICTIMESYNCFLAG_PROBE 0
  1149. #define ICTIMESYNCFLAG_SYNC 1
  1150. #define ICTIMESYNCFLAG_SAMPLE 2
  1151. #ifdef __x86_64__
  1152. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1153. #else
  1154. #define WLTIMEDELTA 116444736000000000LL
  1155. #endif
  1156. struct ictimesync_data {
  1157. u64 parenttime;
  1158. u64 childtime;
  1159. u64 roundtriptime;
  1160. u8 flags;
  1161. } __packed;
  1162. struct ictimesync_ref_data {
  1163. u64 parenttime;
  1164. u64 vmreferencetime;
  1165. u8 flags;
  1166. char leapflags;
  1167. char stratum;
  1168. u8 reserved[3];
  1169. } __packed;
  1170. struct hyperv_service_callback {
  1171. u8 msg_type;
  1172. char *log_msg;
  1173. uuid_le data;
  1174. struct vmbus_channel *channel;
  1175. void (*callback)(void *context);
  1176. };
  1177. #define MAX_SRV_VER 0x7ffffff
  1178. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf,
  1179. const int *fw_version, int fw_vercnt,
  1180. const int *srv_version, int srv_vercnt,
  1181. int *nego_fw_version, int *nego_srv_version);
  1182. void hv_process_channel_removal(u32 relid);
  1183. void vmbus_setevent(struct vmbus_channel *channel);
  1184. /*
  1185. * Negotiated version with the Host.
  1186. */
  1187. extern __u32 vmbus_proto_version;
  1188. int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  1189. const uuid_le *shv_host_servie_id);
  1190. void vmbus_set_event(struct vmbus_channel *channel);
  1191. /* Get the start of the ring buffer. */
  1192. static inline void *
  1193. hv_get_ring_buffer(const struct hv_ring_buffer_info *ring_info)
  1194. {
  1195. return ring_info->ring_buffer->buffer;
  1196. }
  1197. /*
  1198. * Mask off host interrupt callback notifications
  1199. */
  1200. static inline void hv_begin_read(struct hv_ring_buffer_info *rbi)
  1201. {
  1202. rbi->ring_buffer->interrupt_mask = 1;
  1203. /* make sure mask update is not reordered */
  1204. virt_mb();
  1205. }
  1206. /*
  1207. * Re-enable host callback and return number of outstanding bytes
  1208. */
  1209. static inline u32 hv_end_read(struct hv_ring_buffer_info *rbi)
  1210. {
  1211. rbi->ring_buffer->interrupt_mask = 0;
  1212. /* make sure mask update is not reordered */
  1213. virt_mb();
  1214. /*
  1215. * Now check to see if the ring buffer is still empty.
  1216. * If it is not, we raced and we need to process new
  1217. * incoming messages.
  1218. */
  1219. return hv_get_bytes_to_read(rbi);
  1220. }
  1221. /*
  1222. * An API to support in-place processing of incoming VMBUS packets.
  1223. */
  1224. /* Get data payload associated with descriptor */
  1225. static inline void *hv_pkt_data(const struct vmpacket_descriptor *desc)
  1226. {
  1227. return (void *)((unsigned long)desc + (desc->offset8 << 3));
  1228. }
  1229. /* Get data size associated with descriptor */
  1230. static inline u32 hv_pkt_datalen(const struct vmpacket_descriptor *desc)
  1231. {
  1232. return (desc->len8 << 3) - (desc->offset8 << 3);
  1233. }
  1234. struct vmpacket_descriptor *
  1235. hv_pkt_iter_first(struct vmbus_channel *channel);
  1236. struct vmpacket_descriptor *
  1237. __hv_pkt_iter_next(struct vmbus_channel *channel,
  1238. const struct vmpacket_descriptor *pkt);
  1239. void hv_pkt_iter_close(struct vmbus_channel *channel);
  1240. /*
  1241. * Get next packet descriptor from iterator
  1242. * If at end of list, return NULL and update host.
  1243. */
  1244. static inline struct vmpacket_descriptor *
  1245. hv_pkt_iter_next(struct vmbus_channel *channel,
  1246. const struct vmpacket_descriptor *pkt)
  1247. {
  1248. struct vmpacket_descriptor *nxt;
  1249. nxt = __hv_pkt_iter_next(channel, pkt);
  1250. if (!nxt)
  1251. hv_pkt_iter_close(channel);
  1252. return nxt;
  1253. }
  1254. #define foreach_vmbus_pkt(pkt, channel) \
  1255. for (pkt = hv_pkt_iter_first(channel); pkt; \
  1256. pkt = hv_pkt_iter_next(channel, pkt))
  1257. #endif /* _HYPERV_H */