hyperv.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. * K. Y. Srinivasan <kys@microsoft.com>
  22. *
  23. */
  24. #ifndef _HYPERV_H
  25. #define _HYPERV_H
  26. #include <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. /*
  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(const 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. static inline u32 hv_get_bytes_to_read(const struct hv_ring_buffer_info *rbi)
  129. {
  130. u32 read_loc, write_loc, dsize, read;
  131. dsize = rbi->ring_datasize;
  132. read_loc = rbi->ring_buffer->read_index;
  133. write_loc = READ_ONCE(rbi->ring_buffer->write_index);
  134. read = write_loc >= read_loc ? (write_loc - read_loc) :
  135. (dsize - read_loc) + write_loc;
  136. return read;
  137. }
  138. static inline u32 hv_get_bytes_to_write(const struct hv_ring_buffer_info *rbi)
  139. {
  140. u32 read_loc, write_loc, dsize, write;
  141. dsize = rbi->ring_datasize;
  142. read_loc = READ_ONCE(rbi->ring_buffer->read_index);
  143. write_loc = rbi->ring_buffer->write_index;
  144. write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  145. read_loc - write_loc;
  146. return write;
  147. }
  148. /*
  149. * VMBUS version is 32 bit entity broken up into
  150. * two 16 bit quantities: major_number. minor_number.
  151. *
  152. * 0 . 13 (Windows Server 2008)
  153. * 1 . 1 (Windows 7)
  154. * 2 . 4 (Windows 8)
  155. * 3 . 0 (Windows 8 R2)
  156. * 4 . 0 (Windows 10)
  157. */
  158. #define VERSION_WS2008 ((0 << 16) | (13))
  159. #define VERSION_WIN7 ((1 << 16) | (1))
  160. #define VERSION_WIN8 ((2 << 16) | (4))
  161. #define VERSION_WIN8_1 ((3 << 16) | (0))
  162. #define VERSION_WIN10 ((4 << 16) | (0))
  163. #define VERSION_INVAL -1
  164. #define VERSION_CURRENT VERSION_WIN10
  165. /* Make maximum size of pipe payload of 16K */
  166. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  167. /* Define PipeMode values. */
  168. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  169. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  170. /* The size of the user defined data buffer for non-pipe offers. */
  171. #define MAX_USER_DEFINED_BYTES 120
  172. /* The size of the user defined data buffer for pipe offers. */
  173. #define MAX_PIPE_USER_DEFINED_BYTES 116
  174. /*
  175. * At the center of the Channel Management library is the Channel Offer. This
  176. * struct contains the fundamental information about an offer.
  177. */
  178. struct vmbus_channel_offer {
  179. uuid_le if_type;
  180. uuid_le if_instance;
  181. /*
  182. * These two fields are not currently used.
  183. */
  184. u64 reserved1;
  185. u64 reserved2;
  186. u16 chn_flags;
  187. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  188. union {
  189. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  190. struct {
  191. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  192. } std;
  193. /*
  194. * Pipes:
  195. * The following sructure is an integrated pipe protocol, which
  196. * is implemented on top of standard user-defined data. Pipe
  197. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  198. * use.
  199. */
  200. struct {
  201. u32 pipe_mode;
  202. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  203. } pipe;
  204. } u;
  205. /*
  206. * The sub_channel_index is defined in win8.
  207. */
  208. u16 sub_channel_index;
  209. u16 reserved3;
  210. } __packed;
  211. /* Server Flags */
  212. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  213. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  214. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  215. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  216. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  217. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  218. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  219. #define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000
  220. struct vmpacket_descriptor {
  221. u16 type;
  222. u16 offset8;
  223. u16 len8;
  224. u16 flags;
  225. u64 trans_id;
  226. } __packed;
  227. struct vmpacket_header {
  228. u32 prev_pkt_start_offset;
  229. struct vmpacket_descriptor descriptor;
  230. } __packed;
  231. struct vmtransfer_page_range {
  232. u32 byte_count;
  233. u32 byte_offset;
  234. } __packed;
  235. struct vmtransfer_page_packet_header {
  236. struct vmpacket_descriptor d;
  237. u16 xfer_pageset_id;
  238. u8 sender_owns_set;
  239. u8 reserved;
  240. u32 range_cnt;
  241. struct vmtransfer_page_range ranges[1];
  242. } __packed;
  243. struct vmgpadl_packet_header {
  244. struct vmpacket_descriptor d;
  245. u32 gpadl;
  246. u32 reserved;
  247. } __packed;
  248. struct vmadd_remove_transfer_page_set {
  249. struct vmpacket_descriptor d;
  250. u32 gpadl;
  251. u16 xfer_pageset_id;
  252. u16 reserved;
  253. } __packed;
  254. /*
  255. * This structure defines a range in guest physical space that can be made to
  256. * look virtually contiguous.
  257. */
  258. struct gpa_range {
  259. u32 byte_count;
  260. u32 byte_offset;
  261. u64 pfn_array[0];
  262. };
  263. /*
  264. * This is the format for an Establish Gpadl packet, which contains a handle by
  265. * which this GPADL will be known and a set of GPA ranges associated with it.
  266. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  267. * ranges, then the resulting MDL will be "chained," representing multiple VA
  268. * ranges.
  269. */
  270. struct vmestablish_gpadl {
  271. struct vmpacket_descriptor d;
  272. u32 gpadl;
  273. u32 range_cnt;
  274. struct gpa_range range[1];
  275. } __packed;
  276. /*
  277. * This is the format for a Teardown Gpadl packet, which indicates that the
  278. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  279. */
  280. struct vmteardown_gpadl {
  281. struct vmpacket_descriptor d;
  282. u32 gpadl;
  283. u32 reserved; /* for alignment to a 8-byte boundary */
  284. } __packed;
  285. /*
  286. * This is the format for a GPA-Direct packet, which contains a set of GPA
  287. * ranges, in addition to commands and/or data.
  288. */
  289. struct vmdata_gpa_direct {
  290. struct vmpacket_descriptor d;
  291. u32 reserved;
  292. u32 range_cnt;
  293. struct gpa_range range[1];
  294. } __packed;
  295. /* This is the format for a Additional Data Packet. */
  296. struct vmadditional_data {
  297. struct vmpacket_descriptor d;
  298. u64 total_bytes;
  299. u32 offset;
  300. u32 byte_cnt;
  301. unsigned char data[1];
  302. } __packed;
  303. union vmpacket_largest_possible_header {
  304. struct vmpacket_descriptor simple_hdr;
  305. struct vmtransfer_page_packet_header xfer_page_hdr;
  306. struct vmgpadl_packet_header gpadl_hdr;
  307. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  308. struct vmestablish_gpadl establish_gpadl_hdr;
  309. struct vmteardown_gpadl teardown_gpadl_hdr;
  310. struct vmdata_gpa_direct data_gpa_direct_hdr;
  311. };
  312. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  313. (void *)(((unsigned char *)__packet) + \
  314. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  315. #define VMPACKET_DATA_LENGTH(__packet) \
  316. ((((struct vmpacket_descriptor)__packet)->len8 - \
  317. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  318. #define VMPACKET_TRANSFER_MODE(__packet) \
  319. (((struct IMPACT)__packet)->type)
  320. enum vmbus_packet_type {
  321. VM_PKT_INVALID = 0x0,
  322. VM_PKT_SYNCH = 0x1,
  323. VM_PKT_ADD_XFER_PAGESET = 0x2,
  324. VM_PKT_RM_XFER_PAGESET = 0x3,
  325. VM_PKT_ESTABLISH_GPADL = 0x4,
  326. VM_PKT_TEARDOWN_GPADL = 0x5,
  327. VM_PKT_DATA_INBAND = 0x6,
  328. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  329. VM_PKT_DATA_USING_GPADL = 0x8,
  330. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  331. VM_PKT_CANCEL_REQUEST = 0xa,
  332. VM_PKT_COMP = 0xb,
  333. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  334. VM_PKT_ADDITIONAL_DATA = 0xd
  335. };
  336. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  337. /* Version 1 messages */
  338. enum vmbus_channel_message_type {
  339. CHANNELMSG_INVALID = 0,
  340. CHANNELMSG_OFFERCHANNEL = 1,
  341. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  342. CHANNELMSG_REQUESTOFFERS = 3,
  343. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  344. CHANNELMSG_OPENCHANNEL = 5,
  345. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  346. CHANNELMSG_CLOSECHANNEL = 7,
  347. CHANNELMSG_GPADL_HEADER = 8,
  348. CHANNELMSG_GPADL_BODY = 9,
  349. CHANNELMSG_GPADL_CREATED = 10,
  350. CHANNELMSG_GPADL_TEARDOWN = 11,
  351. CHANNELMSG_GPADL_TORNDOWN = 12,
  352. CHANNELMSG_RELID_RELEASED = 13,
  353. CHANNELMSG_INITIATE_CONTACT = 14,
  354. CHANNELMSG_VERSION_RESPONSE = 15,
  355. CHANNELMSG_UNLOAD = 16,
  356. CHANNELMSG_UNLOAD_RESPONSE = 17,
  357. CHANNELMSG_18 = 18,
  358. CHANNELMSG_19 = 19,
  359. CHANNELMSG_20 = 20,
  360. CHANNELMSG_TL_CONNECT_REQUEST = 21,
  361. CHANNELMSG_COUNT
  362. };
  363. struct vmbus_channel_message_header {
  364. enum vmbus_channel_message_type msgtype;
  365. u32 padding;
  366. } __packed;
  367. /* Query VMBus Version parameters */
  368. struct vmbus_channel_query_vmbus_version {
  369. struct vmbus_channel_message_header header;
  370. u32 version;
  371. } __packed;
  372. /* VMBus Version Supported parameters */
  373. struct vmbus_channel_version_supported {
  374. struct vmbus_channel_message_header header;
  375. u8 version_supported;
  376. } __packed;
  377. /* Offer Channel parameters */
  378. struct vmbus_channel_offer_channel {
  379. struct vmbus_channel_message_header header;
  380. struct vmbus_channel_offer offer;
  381. u32 child_relid;
  382. u8 monitorid;
  383. /*
  384. * win7 and beyond splits this field into a bit field.
  385. */
  386. u8 monitor_allocated:1;
  387. u8 reserved:7;
  388. /*
  389. * These are new fields added in win7 and later.
  390. * Do not access these fields without checking the
  391. * negotiated protocol.
  392. *
  393. * If "is_dedicated_interrupt" is set, we must not set the
  394. * associated bit in the channel bitmap while sending the
  395. * interrupt to the host.
  396. *
  397. * connection_id is to be used in signaling the host.
  398. */
  399. u16 is_dedicated_interrupt:1;
  400. u16 reserved1:15;
  401. u32 connection_id;
  402. } __packed;
  403. /* Rescind Offer parameters */
  404. struct vmbus_channel_rescind_offer {
  405. struct vmbus_channel_message_header header;
  406. u32 child_relid;
  407. } __packed;
  408. static inline u32
  409. hv_ringbuffer_pending_size(const struct hv_ring_buffer_info *rbi)
  410. {
  411. return rbi->ring_buffer->pending_send_sz;
  412. }
  413. /*
  414. * Request Offer -- no parameters, SynIC message contains the partition ID
  415. * Set Snoop -- no parameters, SynIC message contains the partition ID
  416. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  417. * All Offers Delivered -- no parameters, SynIC message contains the partition
  418. * ID
  419. * Flush Client -- no parameters, SynIC message contains the partition ID
  420. */
  421. /* Open Channel parameters */
  422. struct vmbus_channel_open_channel {
  423. struct vmbus_channel_message_header header;
  424. /* Identifies the specific VMBus channel that is being opened. */
  425. u32 child_relid;
  426. /* ID making a particular open request at a channel offer unique. */
  427. u32 openid;
  428. /* GPADL for the channel's ring buffer. */
  429. u32 ringbuffer_gpadlhandle;
  430. /*
  431. * Starting with win8, this field will be used to specify
  432. * the target virtual processor on which to deliver the interrupt for
  433. * the host to guest communication.
  434. * Prior to win8, incoming channel interrupts would only
  435. * be delivered on cpu 0. Setting this value to 0 would
  436. * preserve the earlier behavior.
  437. */
  438. u32 target_vp;
  439. /*
  440. * The upstream ring buffer begins at offset zero in the memory
  441. * described by RingBufferGpadlHandle. The downstream ring buffer
  442. * follows it at this offset (in pages).
  443. */
  444. u32 downstream_ringbuffer_pageoffset;
  445. /* User-specific data to be passed along to the server endpoint. */
  446. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  447. } __packed;
  448. /* Open Channel Result parameters */
  449. struct vmbus_channel_open_result {
  450. struct vmbus_channel_message_header header;
  451. u32 child_relid;
  452. u32 openid;
  453. u32 status;
  454. } __packed;
  455. /* Close channel parameters; */
  456. struct vmbus_channel_close_channel {
  457. struct vmbus_channel_message_header header;
  458. u32 child_relid;
  459. } __packed;
  460. /* Channel Message GPADL */
  461. #define GPADL_TYPE_RING_BUFFER 1
  462. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  463. #define GPADL_TYPE_TRANSACTION 8
  464. /*
  465. * The number of PFNs in a GPADL message is defined by the number of
  466. * pages that would be spanned by ByteCount and ByteOffset. If the
  467. * implied number of PFNs won't fit in this packet, there will be a
  468. * follow-up packet that contains more.
  469. */
  470. struct vmbus_channel_gpadl_header {
  471. struct vmbus_channel_message_header header;
  472. u32 child_relid;
  473. u32 gpadl;
  474. u16 range_buflen;
  475. u16 rangecount;
  476. struct gpa_range range[0];
  477. } __packed;
  478. /* This is the followup packet that contains more PFNs. */
  479. struct vmbus_channel_gpadl_body {
  480. struct vmbus_channel_message_header header;
  481. u32 msgnumber;
  482. u32 gpadl;
  483. u64 pfn[0];
  484. } __packed;
  485. struct vmbus_channel_gpadl_created {
  486. struct vmbus_channel_message_header header;
  487. u32 child_relid;
  488. u32 gpadl;
  489. u32 creation_status;
  490. } __packed;
  491. struct vmbus_channel_gpadl_teardown {
  492. struct vmbus_channel_message_header header;
  493. u32 child_relid;
  494. u32 gpadl;
  495. } __packed;
  496. struct vmbus_channel_gpadl_torndown {
  497. struct vmbus_channel_message_header header;
  498. u32 gpadl;
  499. } __packed;
  500. struct vmbus_channel_relid_released {
  501. struct vmbus_channel_message_header header;
  502. u32 child_relid;
  503. } __packed;
  504. struct vmbus_channel_initiate_contact {
  505. struct vmbus_channel_message_header header;
  506. u32 vmbus_version_requested;
  507. u32 target_vcpu; /* The VCPU the host should respond to */
  508. u64 interrupt_page;
  509. u64 monitor_page1;
  510. u64 monitor_page2;
  511. } __packed;
  512. /* Hyper-V socket: guest's connect()-ing to host */
  513. struct vmbus_channel_tl_connect_request {
  514. struct vmbus_channel_message_header header;
  515. uuid_le guest_endpoint_id;
  516. uuid_le host_service_id;
  517. } __packed;
  518. struct vmbus_channel_version_response {
  519. struct vmbus_channel_message_header header;
  520. u8 version_supported;
  521. } __packed;
  522. enum vmbus_channel_state {
  523. CHANNEL_OFFER_STATE,
  524. CHANNEL_OPENING_STATE,
  525. CHANNEL_OPEN_STATE,
  526. CHANNEL_OPENED_STATE,
  527. };
  528. /*
  529. * Represents each channel msg on the vmbus connection This is a
  530. * variable-size data structure depending on the msg type itself
  531. */
  532. struct vmbus_channel_msginfo {
  533. /* Bookkeeping stuff */
  534. struct list_head msglistentry;
  535. /* So far, this is only used to handle gpadl body message */
  536. struct list_head submsglist;
  537. /* Synchronize the request/response if needed */
  538. struct completion waitevent;
  539. struct vmbus_channel *waiting_channel;
  540. union {
  541. struct vmbus_channel_version_supported version_supported;
  542. struct vmbus_channel_open_result open_result;
  543. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  544. struct vmbus_channel_gpadl_created gpadl_created;
  545. struct vmbus_channel_version_response version_response;
  546. } response;
  547. u32 msgsize;
  548. /*
  549. * The channel message that goes out on the "wire".
  550. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  551. */
  552. unsigned char msg[0];
  553. };
  554. struct vmbus_close_msg {
  555. struct vmbus_channel_msginfo info;
  556. struct vmbus_channel_close_channel msg;
  557. };
  558. /* Define connection identifier type. */
  559. union hv_connection_id {
  560. u32 asu32;
  561. struct {
  562. u32 id:24;
  563. u32 reserved:8;
  564. } u;
  565. };
  566. enum hv_numa_policy {
  567. HV_BALANCED = 0,
  568. HV_LOCALIZED,
  569. };
  570. enum vmbus_device_type {
  571. HV_IDE = 0,
  572. HV_SCSI,
  573. HV_FC,
  574. HV_NIC,
  575. HV_ND,
  576. HV_PCIE,
  577. HV_FB,
  578. HV_KBD,
  579. HV_MOUSE,
  580. HV_KVP,
  581. HV_TS,
  582. HV_HB,
  583. HV_SHUTDOWN,
  584. HV_FCOPY,
  585. HV_BACKUP,
  586. HV_DM,
  587. HV_UNKNOWN,
  588. };
  589. struct vmbus_device {
  590. u16 dev_type;
  591. uuid_le guid;
  592. bool perf_device;
  593. };
  594. struct vmbus_channel {
  595. struct list_head listentry;
  596. struct hv_device *device_obj;
  597. enum vmbus_channel_state state;
  598. struct vmbus_channel_offer_channel offermsg;
  599. /*
  600. * These are based on the OfferMsg.MonitorId.
  601. * Save it here for easy access.
  602. */
  603. u8 monitor_grp;
  604. u8 monitor_bit;
  605. bool rescind; /* got rescind msg */
  606. u32 ringbuffer_gpadlhandle;
  607. /* Allocated memory for ring buffer */
  608. void *ringbuffer_pages;
  609. u32 ringbuffer_pagecount;
  610. struct hv_ring_buffer_info outbound; /* send to parent */
  611. struct hv_ring_buffer_info inbound; /* receive from parent */
  612. struct vmbus_close_msg close_msg;
  613. /* Channel callback's invoked in softirq context */
  614. struct tasklet_struct callback_event;
  615. void (*onchannel_callback)(void *context);
  616. void *channel_callback_context;
  617. /*
  618. * A channel can be marked for one of three modes of reading:
  619. * BATCHED - callback called from taslket and should read
  620. * channel until empty. Interrupts from the host
  621. * are masked while read is in process (default).
  622. * DIRECT - callback called from tasklet (softirq).
  623. * ISR - callback called in interrupt context and must
  624. * invoke its own deferred processing.
  625. * Host interrupts are disabled and must be re-enabled
  626. * when ring is empty.
  627. */
  628. enum hv_callback_mode {
  629. HV_CALL_BATCHED,
  630. HV_CALL_DIRECT,
  631. HV_CALL_ISR
  632. } callback_mode;
  633. bool is_dedicated_interrupt;
  634. u64 sig_event;
  635. /*
  636. * Starting with win8, this field will be used to specify
  637. * the target virtual processor on which to deliver the interrupt for
  638. * the host to guest communication.
  639. * Prior to win8, incoming channel interrupts would only
  640. * be delivered on cpu 0. Setting this value to 0 would
  641. * preserve the earlier behavior.
  642. */
  643. u32 target_vp;
  644. /* The corresponding CPUID in the guest */
  645. u32 target_cpu;
  646. /*
  647. * State to manage the CPU affiliation of channels.
  648. */
  649. struct cpumask alloced_cpus_in_node;
  650. int numa_node;
  651. /*
  652. * Support for sub-channels. For high performance devices,
  653. * it will be useful to have multiple sub-channels to support
  654. * a scalable communication infrastructure with the host.
  655. * The support for sub-channels is implemented as an extention
  656. * to the current infrastructure.
  657. * The initial offer is considered the primary channel and this
  658. * offer message will indicate if the host supports sub-channels.
  659. * The guest is free to ask for sub-channels to be offerred and can
  660. * open these sub-channels as a normal "primary" channel. However,
  661. * all sub-channels will have the same type and instance guids as the
  662. * primary channel. Requests sent on a given channel will result in a
  663. * response on the same channel.
  664. */
  665. /*
  666. * Sub-channel creation callback. This callback will be called in
  667. * process context when a sub-channel offer is received from the host.
  668. * The guest can open the sub-channel in the context of this callback.
  669. */
  670. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  671. /*
  672. * Channel rescind callback. Some channels (the hvsock ones), need to
  673. * register a callback which is invoked in vmbus_onoffer_rescind().
  674. */
  675. void (*chn_rescind_callback)(struct vmbus_channel *channel);
  676. /*
  677. * The spinlock to protect the structure. It is being used to protect
  678. * test-and-set access to various attributes of the structure as well
  679. * as all sc_list operations.
  680. */
  681. spinlock_t lock;
  682. /*
  683. * All Sub-channels of a primary channel are linked here.
  684. */
  685. struct list_head sc_list;
  686. /*
  687. * Current number of sub-channels.
  688. */
  689. int num_sc;
  690. /*
  691. * Number of a sub-channel (position within sc_list) which is supposed
  692. * to be used as the next outgoing channel.
  693. */
  694. int next_oc;
  695. /*
  696. * The primary channel this sub-channel belongs to.
  697. * This will be NULL for the primary channel.
  698. */
  699. struct vmbus_channel *primary_channel;
  700. /*
  701. * Support per-channel state for use by vmbus drivers.
  702. */
  703. void *per_channel_state;
  704. /*
  705. * To support per-cpu lookup mapping of relid to channel,
  706. * link up channels based on their CPU affinity.
  707. */
  708. struct list_head percpu_list;
  709. /*
  710. * Defer freeing channel until after all cpu's have
  711. * gone through grace period.
  712. */
  713. struct rcu_head rcu;
  714. /*
  715. * For performance critical channels (storage, networking
  716. * etc,), Hyper-V has a mechanism to enhance the throughput
  717. * at the expense of latency:
  718. * When the host is to be signaled, we just set a bit in a shared page
  719. * and this bit will be inspected by the hypervisor within a certain
  720. * window and if the bit is set, the host will be signaled. The window
  721. * of time is the monitor latency - currently around 100 usecs. This
  722. * mechanism improves throughput by:
  723. *
  724. * A) Making the host more efficient - each time it wakes up,
  725. * potentially it will process morev number of packets. The
  726. * monitor latency allows a batch to build up.
  727. * B) By deferring the hypercall to signal, we will also minimize
  728. * the interrupts.
  729. *
  730. * Clearly, these optimizations improve throughput at the expense of
  731. * latency. Furthermore, since the channel is shared for both
  732. * control and data messages, control messages currently suffer
  733. * unnecessary latency adversley impacting performance and boot
  734. * time. To fix this issue, permit tagging the channel as being
  735. * in "low latency" mode. In this mode, we will bypass the monitor
  736. * mechanism.
  737. */
  738. bool low_latency;
  739. /*
  740. * NUMA distribution policy:
  741. * We support teo policies:
  742. * 1) Balanced: Here all performance critical channels are
  743. * distributed evenly amongst all the NUMA nodes.
  744. * This policy will be the default policy.
  745. * 2) Localized: All channels of a given instance of a
  746. * performance critical service will be assigned CPUs
  747. * within a selected NUMA node.
  748. */
  749. enum hv_numa_policy affinity_policy;
  750. bool probe_done;
  751. };
  752. static inline bool is_hvsock_channel(const struct vmbus_channel *c)
  753. {
  754. return !!(c->offermsg.offer.chn_flags &
  755. VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER);
  756. }
  757. static inline void set_channel_affinity_state(struct vmbus_channel *c,
  758. enum hv_numa_policy policy)
  759. {
  760. c->affinity_policy = policy;
  761. }
  762. static inline void set_channel_read_mode(struct vmbus_channel *c,
  763. enum hv_callback_mode mode)
  764. {
  765. c->callback_mode = mode;
  766. }
  767. static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
  768. {
  769. c->per_channel_state = s;
  770. }
  771. static inline void *get_per_channel_state(struct vmbus_channel *c)
  772. {
  773. return c->per_channel_state;
  774. }
  775. static inline void set_channel_pending_send_size(struct vmbus_channel *c,
  776. u32 size)
  777. {
  778. c->outbound.ring_buffer->pending_send_sz = size;
  779. }
  780. static inline void set_low_latency_mode(struct vmbus_channel *c)
  781. {
  782. c->low_latency = true;
  783. }
  784. static inline void clear_low_latency_mode(struct vmbus_channel *c)
  785. {
  786. c->low_latency = false;
  787. }
  788. void vmbus_onmessage(void *context);
  789. int vmbus_request_offers(void);
  790. /*
  791. * APIs for managing sub-channels.
  792. */
  793. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  794. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  795. void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
  796. void (*chn_rescind_cb)(struct vmbus_channel *));
  797. /*
  798. * Retrieve the (sub) channel on which to send an outgoing request.
  799. * When a primary channel has multiple sub-channels, we choose a
  800. * channel whose VCPU binding is closest to the VCPU on which
  801. * this call is being made.
  802. */
  803. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  804. /*
  805. * Check if sub-channels have already been offerred. This API will be useful
  806. * when the driver is unloaded after establishing sub-channels. In this case,
  807. * when the driver is re-loaded, the driver would have to check if the
  808. * subchannels have already been established before attempting to request
  809. * the creation of sub-channels.
  810. * This function returns TRUE to indicate that subchannels have already been
  811. * created.
  812. * This function should be invoked after setting the callback function for
  813. * sub-channel creation.
  814. */
  815. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  816. /* The format must be the same as struct vmdata_gpa_direct */
  817. struct vmbus_channel_packet_page_buffer {
  818. u16 type;
  819. u16 dataoffset8;
  820. u16 length8;
  821. u16 flags;
  822. u64 transactionid;
  823. u32 reserved;
  824. u32 rangecount;
  825. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  826. } __packed;
  827. /* The format must be the same as struct vmdata_gpa_direct */
  828. struct vmbus_channel_packet_multipage_buffer {
  829. u16 type;
  830. u16 dataoffset8;
  831. u16 length8;
  832. u16 flags;
  833. u64 transactionid;
  834. u32 reserved;
  835. u32 rangecount; /* Always 1 in this case */
  836. struct hv_multipage_buffer range;
  837. } __packed;
  838. /* The format must be the same as struct vmdata_gpa_direct */
  839. struct vmbus_packet_mpb_array {
  840. u16 type;
  841. u16 dataoffset8;
  842. u16 length8;
  843. u16 flags;
  844. u64 transactionid;
  845. u32 reserved;
  846. u32 rangecount; /* Always 1 in this case */
  847. struct hv_mpb_array range;
  848. } __packed;
  849. extern int vmbus_open(struct vmbus_channel *channel,
  850. u32 send_ringbuffersize,
  851. u32 recv_ringbuffersize,
  852. void *userdata,
  853. u32 userdatalen,
  854. void (*onchannel_callback)(void *context),
  855. void *context);
  856. extern void vmbus_close(struct vmbus_channel *channel);
  857. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  858. void *buffer,
  859. u32 bufferLen,
  860. u64 requestid,
  861. enum vmbus_packet_type type,
  862. u32 flags);
  863. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  864. struct hv_page_buffer pagebuffers[],
  865. u32 pagecount,
  866. void *buffer,
  867. u32 bufferlen,
  868. u64 requestid);
  869. extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
  870. struct vmbus_packet_mpb_array *mpb,
  871. u32 desc_size,
  872. void *buffer,
  873. u32 bufferlen,
  874. u64 requestid);
  875. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  876. void *kbuffer,
  877. u32 size,
  878. u32 *gpadl_handle);
  879. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  880. u32 gpadl_handle);
  881. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  882. void *buffer,
  883. u32 bufferlen,
  884. u32 *buffer_actual_len,
  885. u64 *requestid);
  886. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  887. void *buffer,
  888. u32 bufferlen,
  889. u32 *buffer_actual_len,
  890. u64 *requestid);
  891. extern void vmbus_ontimer(unsigned long data);
  892. /* Base driver object */
  893. struct hv_driver {
  894. const char *name;
  895. /*
  896. * A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER
  897. * channel flag, actually doesn't mean a synthetic device because the
  898. * offer's if_type/if_instance can change for every new hvsock
  899. * connection.
  900. *
  901. * However, to facilitate the notification of new-offer/rescind-offer
  902. * from vmbus driver to hvsock driver, we can handle hvsock offer as
  903. * a special vmbus device, and hence we need the below flag to
  904. * indicate if the driver is the hvsock driver or not: we need to
  905. * specially treat the hvosck offer & driver in vmbus_match().
  906. */
  907. bool hvsock;
  908. /* the device type supported by this driver */
  909. uuid_le dev_type;
  910. const struct hv_vmbus_device_id *id_table;
  911. struct device_driver driver;
  912. /* dynamic device GUID's */
  913. struct {
  914. spinlock_t lock;
  915. struct list_head list;
  916. } dynids;
  917. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  918. int (*remove)(struct hv_device *);
  919. void (*shutdown)(struct hv_device *);
  920. };
  921. /* Base device object */
  922. struct hv_device {
  923. /* the device type id of this device */
  924. uuid_le dev_type;
  925. /* the device instance id of this device */
  926. uuid_le dev_instance;
  927. u16 vendor_id;
  928. u16 device_id;
  929. struct device device;
  930. struct vmbus_channel *channel;
  931. };
  932. static inline struct hv_device *device_to_hv_device(struct device *d)
  933. {
  934. return container_of(d, struct hv_device, device);
  935. }
  936. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  937. {
  938. return container_of(d, struct hv_driver, driver);
  939. }
  940. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  941. {
  942. dev_set_drvdata(&dev->device, data);
  943. }
  944. static inline void *hv_get_drvdata(struct hv_device *dev)
  945. {
  946. return dev_get_drvdata(&dev->device);
  947. }
  948. struct hv_ring_buffer_debug_info {
  949. u32 current_interrupt_mask;
  950. u32 current_read_index;
  951. u32 current_write_index;
  952. u32 bytes_avail_toread;
  953. u32 bytes_avail_towrite;
  954. };
  955. void hv_ringbuffer_get_debuginfo(const struct hv_ring_buffer_info *ring_info,
  956. struct hv_ring_buffer_debug_info *debug_info);
  957. /* Vmbus interface */
  958. #define vmbus_driver_register(driver) \
  959. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  960. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  961. struct module *owner,
  962. const char *mod_name);
  963. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  964. void vmbus_hvsock_device_unregister(struct vmbus_channel *channel);
  965. int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
  966. resource_size_t min, resource_size_t max,
  967. resource_size_t size, resource_size_t align,
  968. bool fb_overlap_ok);
  969. void vmbus_free_mmio(resource_size_t start, resource_size_t size);
  970. /*
  971. * GUID definitions of various offer types - services offered to the guest.
  972. */
  973. /*
  974. * Network GUID
  975. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  976. */
  977. #define HV_NIC_GUID \
  978. .guid = UUID_LE(0xf8615163, 0xdf3e, 0x46c5, 0x91, 0x3f, \
  979. 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e)
  980. /*
  981. * IDE GUID
  982. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  983. */
  984. #define HV_IDE_GUID \
  985. .guid = UUID_LE(0x32412632, 0x86cb, 0x44a2, 0x9b, 0x5c, \
  986. 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
  987. /*
  988. * SCSI GUID
  989. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  990. */
  991. #define HV_SCSI_GUID \
  992. .guid = UUID_LE(0xba6163d9, 0x04a1, 0x4d29, 0xb6, 0x05, \
  993. 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
  994. /*
  995. * Shutdown GUID
  996. * {0e0b6031-5213-4934-818b-38d90ced39db}
  997. */
  998. #define HV_SHUTDOWN_GUID \
  999. .guid = UUID_LE(0x0e0b6031, 0x5213, 0x4934, 0x81, 0x8b, \
  1000. 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb)
  1001. /*
  1002. * Time Synch GUID
  1003. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  1004. */
  1005. #define HV_TS_GUID \
  1006. .guid = UUID_LE(0x9527e630, 0xd0ae, 0x497b, 0xad, 0xce, \
  1007. 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf)
  1008. /*
  1009. * Heartbeat GUID
  1010. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  1011. */
  1012. #define HV_HEART_BEAT_GUID \
  1013. .guid = UUID_LE(0x57164f39, 0x9115, 0x4e78, 0xab, 0x55, \
  1014. 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d)
  1015. /*
  1016. * KVP GUID
  1017. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1018. */
  1019. #define HV_KVP_GUID \
  1020. .guid = UUID_LE(0xa9a0f4e7, 0x5a45, 0x4d96, 0xb8, 0x27, \
  1021. 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6)
  1022. /*
  1023. * Dynamic memory GUID
  1024. * {525074dc-8985-46e2-8057-a307dc18a502}
  1025. */
  1026. #define HV_DM_GUID \
  1027. .guid = UUID_LE(0x525074dc, 0x8985, 0x46e2, 0x80, 0x57, \
  1028. 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02)
  1029. /*
  1030. * Mouse GUID
  1031. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1032. */
  1033. #define HV_MOUSE_GUID \
  1034. .guid = UUID_LE(0xcfa8b69e, 0x5b4a, 0x4cc0, 0xb9, 0x8b, \
  1035. 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a)
  1036. /*
  1037. * Keyboard GUID
  1038. * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
  1039. */
  1040. #define HV_KBD_GUID \
  1041. .guid = UUID_LE(0xf912ad6d, 0x2b17, 0x48ea, 0xbd, 0x65, \
  1042. 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84)
  1043. /*
  1044. * VSS (Backup/Restore) GUID
  1045. */
  1046. #define HV_VSS_GUID \
  1047. .guid = UUID_LE(0x35fa2e29, 0xea23, 0x4236, 0x96, 0xae, \
  1048. 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40)
  1049. /*
  1050. * Synthetic Video GUID
  1051. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1052. */
  1053. #define HV_SYNTHVID_GUID \
  1054. .guid = UUID_LE(0xda0a7802, 0xe377, 0x4aac, 0x8e, 0x77, \
  1055. 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8)
  1056. /*
  1057. * Synthetic FC GUID
  1058. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1059. */
  1060. #define HV_SYNTHFC_GUID \
  1061. .guid = UUID_LE(0x2f9bcc4a, 0x0069, 0x4af3, 0xb7, 0x6b, \
  1062. 0x6f, 0xd0, 0xbe, 0x52, 0x8c, 0xda)
  1063. /*
  1064. * Guest File Copy Service
  1065. * {34D14BE3-DEE4-41c8-9AE7-6B174977C192}
  1066. */
  1067. #define HV_FCOPY_GUID \
  1068. .guid = UUID_LE(0x34d14be3, 0xdee4, 0x41c8, 0x9a, 0xe7, \
  1069. 0x6b, 0x17, 0x49, 0x77, 0xc1, 0x92)
  1070. /*
  1071. * NetworkDirect. This is the guest RDMA service.
  1072. * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}
  1073. */
  1074. #define HV_ND_GUID \
  1075. .guid = UUID_LE(0x8c2eaf3d, 0x32a7, 0x4b09, 0xab, 0x99, \
  1076. 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01)
  1077. /*
  1078. * PCI Express Pass Through
  1079. * {44C4F61D-4444-4400-9D52-802E27EDE19F}
  1080. */
  1081. #define HV_PCIE_GUID \
  1082. .guid = UUID_LE(0x44c4f61d, 0x4444, 0x4400, 0x9d, 0x52, \
  1083. 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f)
  1084. /*
  1085. * Linux doesn't support the 3 devices: the first two are for
  1086. * Automatic Virtual Machine Activation, and the third is for
  1087. * Remote Desktop Virtualization.
  1088. * {f8e65716-3cb3-4a06-9a60-1889c5cccab5}
  1089. * {3375baf4-9e15-4b30-b765-67acb10d607b}
  1090. * {276aacf4-ac15-426c-98dd-7521ad3f01fe}
  1091. */
  1092. #define HV_AVMA1_GUID \
  1093. .guid = UUID_LE(0xf8e65716, 0x3cb3, 0x4a06, 0x9a, 0x60, \
  1094. 0x18, 0x89, 0xc5, 0xcc, 0xca, 0xb5)
  1095. #define HV_AVMA2_GUID \
  1096. .guid = UUID_LE(0x3375baf4, 0x9e15, 0x4b30, 0xb7, 0x65, \
  1097. 0x67, 0xac, 0xb1, 0x0d, 0x60, 0x7b)
  1098. #define HV_RDV_GUID \
  1099. .guid = UUID_LE(0x276aacf4, 0xac15, 0x426c, 0x98, 0xdd, \
  1100. 0x75, 0x21, 0xad, 0x3f, 0x01, 0xfe)
  1101. /*
  1102. * Common header for Hyper-V ICs
  1103. */
  1104. #define ICMSGTYPE_NEGOTIATE 0
  1105. #define ICMSGTYPE_HEARTBEAT 1
  1106. #define ICMSGTYPE_KVPEXCHANGE 2
  1107. #define ICMSGTYPE_SHUTDOWN 3
  1108. #define ICMSGTYPE_TIMESYNC 4
  1109. #define ICMSGTYPE_VSS 5
  1110. #define ICMSGHDRFLAG_TRANSACTION 1
  1111. #define ICMSGHDRFLAG_REQUEST 2
  1112. #define ICMSGHDRFLAG_RESPONSE 4
  1113. /*
  1114. * While we want to handle util services as regular devices,
  1115. * there is only one instance of each of these services; so
  1116. * we statically allocate the service specific state.
  1117. */
  1118. struct hv_util_service {
  1119. u8 *recv_buffer;
  1120. void *channel;
  1121. void (*util_cb)(void *);
  1122. int (*util_init)(struct hv_util_service *);
  1123. void (*util_deinit)(void);
  1124. };
  1125. struct vmbuspipe_hdr {
  1126. u32 flags;
  1127. u32 msgsize;
  1128. } __packed;
  1129. struct ic_version {
  1130. u16 major;
  1131. u16 minor;
  1132. } __packed;
  1133. struct icmsg_hdr {
  1134. struct ic_version icverframe;
  1135. u16 icmsgtype;
  1136. struct ic_version icvermsg;
  1137. u16 icmsgsize;
  1138. u32 status;
  1139. u8 ictransaction_id;
  1140. u8 icflags;
  1141. u8 reserved[2];
  1142. } __packed;
  1143. struct icmsg_negotiate {
  1144. u16 icframe_vercnt;
  1145. u16 icmsg_vercnt;
  1146. u32 reserved;
  1147. struct ic_version icversion_data[1]; /* any size array */
  1148. } __packed;
  1149. struct shutdown_msg_data {
  1150. u32 reason_code;
  1151. u32 timeout_seconds;
  1152. u32 flags;
  1153. u8 display_message[2048];
  1154. } __packed;
  1155. struct heartbeat_msg_data {
  1156. u64 seq_num;
  1157. u32 reserved[8];
  1158. } __packed;
  1159. /* Time Sync IC defs */
  1160. #define ICTIMESYNCFLAG_PROBE 0
  1161. #define ICTIMESYNCFLAG_SYNC 1
  1162. #define ICTIMESYNCFLAG_SAMPLE 2
  1163. #ifdef __x86_64__
  1164. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1165. #else
  1166. #define WLTIMEDELTA 116444736000000000LL
  1167. #endif
  1168. struct ictimesync_data {
  1169. u64 parenttime;
  1170. u64 childtime;
  1171. u64 roundtriptime;
  1172. u8 flags;
  1173. } __packed;
  1174. struct ictimesync_ref_data {
  1175. u64 parenttime;
  1176. u64 vmreferencetime;
  1177. u8 flags;
  1178. char leapflags;
  1179. char stratum;
  1180. u8 reserved[3];
  1181. } __packed;
  1182. struct hyperv_service_callback {
  1183. u8 msg_type;
  1184. char *log_msg;
  1185. uuid_le data;
  1186. struct vmbus_channel *channel;
  1187. void (*callback)(void *context);
  1188. };
  1189. #define MAX_SRV_VER 0x7ffffff
  1190. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *icmsghdrp, u8 *buf,
  1191. const int *fw_version, int fw_vercnt,
  1192. const int *srv_version, int srv_vercnt,
  1193. int *nego_fw_version, int *nego_srv_version);
  1194. void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid);
  1195. void vmbus_setevent(struct vmbus_channel *channel);
  1196. /*
  1197. * Negotiated version with the Host.
  1198. */
  1199. extern __u32 vmbus_proto_version;
  1200. int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  1201. const uuid_le *shv_host_servie_id);
  1202. void vmbus_set_event(struct vmbus_channel *channel);
  1203. /* Get the start of the ring buffer. */
  1204. static inline void *
  1205. hv_get_ring_buffer(const struct hv_ring_buffer_info *ring_info)
  1206. {
  1207. return ring_info->ring_buffer->buffer;
  1208. }
  1209. /*
  1210. * Mask off host interrupt callback notifications
  1211. */
  1212. static inline void hv_begin_read(struct hv_ring_buffer_info *rbi)
  1213. {
  1214. rbi->ring_buffer->interrupt_mask = 1;
  1215. /* make sure mask update is not reordered */
  1216. virt_mb();
  1217. }
  1218. /*
  1219. * Re-enable host callback and return number of outstanding bytes
  1220. */
  1221. static inline u32 hv_end_read(struct hv_ring_buffer_info *rbi)
  1222. {
  1223. rbi->ring_buffer->interrupt_mask = 0;
  1224. /* make sure mask update is not reordered */
  1225. virt_mb();
  1226. /*
  1227. * Now check to see if the ring buffer is still empty.
  1228. * If it is not, we raced and we need to process new
  1229. * incoming messages.
  1230. */
  1231. return hv_get_bytes_to_read(rbi);
  1232. }
  1233. /*
  1234. * An API to support in-place processing of incoming VMBUS packets.
  1235. */
  1236. /* Get data payload associated with descriptor */
  1237. static inline void *hv_pkt_data(const struct vmpacket_descriptor *desc)
  1238. {
  1239. return (void *)((unsigned long)desc + (desc->offset8 << 3));
  1240. }
  1241. /* Get data size associated with descriptor */
  1242. static inline u32 hv_pkt_datalen(const struct vmpacket_descriptor *desc)
  1243. {
  1244. return (desc->len8 << 3) - (desc->offset8 << 3);
  1245. }
  1246. struct vmpacket_descriptor *
  1247. hv_pkt_iter_first(struct vmbus_channel *channel);
  1248. struct vmpacket_descriptor *
  1249. __hv_pkt_iter_next(struct vmbus_channel *channel,
  1250. const struct vmpacket_descriptor *pkt);
  1251. void hv_pkt_iter_close(struct vmbus_channel *channel);
  1252. /*
  1253. * Get next packet descriptor from iterator
  1254. * If at end of list, return NULL and update host.
  1255. */
  1256. static inline struct vmpacket_descriptor *
  1257. hv_pkt_iter_next(struct vmbus_channel *channel,
  1258. const struct vmpacket_descriptor *pkt)
  1259. {
  1260. struct vmpacket_descriptor *nxt;
  1261. nxt = __hv_pkt_iter_next(channel, pkt);
  1262. if (!nxt)
  1263. hv_pkt_iter_close(channel);
  1264. return nxt;
  1265. }
  1266. #define foreach_vmbus_pkt(pkt, channel) \
  1267. for (pkt = hv_pkt_iter_first(channel); pkt; \
  1268. pkt = hv_pkt_iter_next(channel, pkt))
  1269. #endif /* _HYPERV_H */