hyperv.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /*
  2. *
  3. * Copyright (c) 2011, Microsoft Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  16. * Place - Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * Authors:
  19. * Haiyang Zhang <haiyangz@microsoft.com>
  20. * Hank Janssen <hjanssen@microsoft.com>
  21. * K. Y. Srinivasan <kys@microsoft.com>
  22. *
  23. */
  24. #ifndef _HYPERV_H
  25. #define _HYPERV_H
  26. #include <uapi/linux/hyperv.h>
  27. #include <uapi/asm/hyperv.h>
  28. #include <linux/types.h>
  29. #include <linux/scatterlist.h>
  30. #include <linux/list.h>
  31. #include <linux/timer.h>
  32. #include <linux/workqueue.h>
  33. #include <linux/completion.h>
  34. #include <linux/device.h>
  35. #include <linux/mod_devicetable.h>
  36. #define MAX_PAGE_BUFFER_COUNT 32
  37. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  38. #pragma pack(push, 1)
  39. /* Single-page buffer */
  40. struct hv_page_buffer {
  41. u32 len;
  42. u32 offset;
  43. u64 pfn;
  44. };
  45. /* Multiple-page buffer */
  46. struct hv_multipage_buffer {
  47. /* Length and Offset determines the # of pfns in the array */
  48. u32 len;
  49. u32 offset;
  50. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  51. };
  52. /*
  53. * Multiple-page buffer array; the pfn array is variable size:
  54. * The number of entries in the PFN array is determined by
  55. * "len" and "offset".
  56. */
  57. struct hv_mpb_array {
  58. /* Length and Offset determines the # of pfns in the array */
  59. u32 len;
  60. u32 offset;
  61. u64 pfn_array[];
  62. };
  63. /* 0x18 includes the proprietary packet header */
  64. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  65. (sizeof(struct hv_page_buffer) * \
  66. MAX_PAGE_BUFFER_COUNT))
  67. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  68. sizeof(struct hv_multipage_buffer))
  69. #pragma pack(pop)
  70. struct hv_ring_buffer {
  71. /* Offset in bytes from the start of ring data below */
  72. u32 write_index;
  73. /* Offset in bytes from the start of ring data below */
  74. u32 read_index;
  75. u32 interrupt_mask;
  76. /*
  77. * Win8 uses some of the reserved bits to implement
  78. * interrupt driven flow management. On the send side
  79. * we can request that the receiver interrupt the sender
  80. * when the ring transitions from being full to being able
  81. * to handle a message of size "pending_send_sz".
  82. *
  83. * Add necessary state for this enhancement.
  84. */
  85. u32 pending_send_sz;
  86. u32 reserved1[12];
  87. union {
  88. struct {
  89. u32 feat_pending_send_sz:1;
  90. };
  91. u32 value;
  92. } feature_bits;
  93. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  94. u8 reserved2[4028];
  95. /*
  96. * Ring data starts here + RingDataStartOffset
  97. * !!! DO NOT place any fields below this !!!
  98. */
  99. u8 buffer[0];
  100. } __packed;
  101. struct hv_ring_buffer_info {
  102. struct hv_ring_buffer *ring_buffer;
  103. u32 ring_size; /* Include the shared header */
  104. spinlock_t ring_lock;
  105. u32 ring_datasize; /* < ring_size */
  106. u32 ring_data_startoffset;
  107. };
  108. /*
  109. *
  110. * hv_get_ringbuffer_availbytes()
  111. *
  112. * Get number of bytes available to read and to write to
  113. * for the specified ring buffer
  114. */
  115. static inline void
  116. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  117. u32 *read, u32 *write)
  118. {
  119. u32 read_loc, write_loc, dsize;
  120. /* Capture the read/write indices before they changed */
  121. read_loc = rbi->ring_buffer->read_index;
  122. write_loc = rbi->ring_buffer->write_index;
  123. dsize = rbi->ring_datasize;
  124. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  125. read_loc - write_loc;
  126. *read = dsize - *write;
  127. }
  128. static inline u32 hv_get_bytes_to_read(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(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. /*
  409. * Request Offer -- no parameters, SynIC message contains the partition ID
  410. * Set Snoop -- no parameters, SynIC message contains the partition ID
  411. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  412. * All Offers Delivered -- no parameters, SynIC message contains the partition
  413. * ID
  414. * Flush Client -- no parameters, SynIC message contains the partition ID
  415. */
  416. /* Open Channel parameters */
  417. struct vmbus_channel_open_channel {
  418. struct vmbus_channel_message_header header;
  419. /* Identifies the specific VMBus channel that is being opened. */
  420. u32 child_relid;
  421. /* ID making a particular open request at a channel offer unique. */
  422. u32 openid;
  423. /* GPADL for the channel's ring buffer. */
  424. u32 ringbuffer_gpadlhandle;
  425. /*
  426. * Starting with win8, this field will be used to specify
  427. * the target virtual processor on which to deliver the interrupt for
  428. * the host to guest communication.
  429. * Prior to win8, incoming channel interrupts would only
  430. * be delivered on cpu 0. Setting this value to 0 would
  431. * preserve the earlier behavior.
  432. */
  433. u32 target_vp;
  434. /*
  435. * The upstream ring buffer begins at offset zero in the memory
  436. * described by RingBufferGpadlHandle. The downstream ring buffer
  437. * follows it at this offset (in pages).
  438. */
  439. u32 downstream_ringbuffer_pageoffset;
  440. /* User-specific data to be passed along to the server endpoint. */
  441. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  442. } __packed;
  443. /* Open Channel Result parameters */
  444. struct vmbus_channel_open_result {
  445. struct vmbus_channel_message_header header;
  446. u32 child_relid;
  447. u32 openid;
  448. u32 status;
  449. } __packed;
  450. /* Close channel parameters; */
  451. struct vmbus_channel_close_channel {
  452. struct vmbus_channel_message_header header;
  453. u32 child_relid;
  454. } __packed;
  455. /* Channel Message GPADL */
  456. #define GPADL_TYPE_RING_BUFFER 1
  457. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  458. #define GPADL_TYPE_TRANSACTION 8
  459. /*
  460. * The number of PFNs in a GPADL message is defined by the number of
  461. * pages that would be spanned by ByteCount and ByteOffset. If the
  462. * implied number of PFNs won't fit in this packet, there will be a
  463. * follow-up packet that contains more.
  464. */
  465. struct vmbus_channel_gpadl_header {
  466. struct vmbus_channel_message_header header;
  467. u32 child_relid;
  468. u32 gpadl;
  469. u16 range_buflen;
  470. u16 rangecount;
  471. struct gpa_range range[0];
  472. } __packed;
  473. /* This is the followup packet that contains more PFNs. */
  474. struct vmbus_channel_gpadl_body {
  475. struct vmbus_channel_message_header header;
  476. u32 msgnumber;
  477. u32 gpadl;
  478. u64 pfn[0];
  479. } __packed;
  480. struct vmbus_channel_gpadl_created {
  481. struct vmbus_channel_message_header header;
  482. u32 child_relid;
  483. u32 gpadl;
  484. u32 creation_status;
  485. } __packed;
  486. struct vmbus_channel_gpadl_teardown {
  487. struct vmbus_channel_message_header header;
  488. u32 child_relid;
  489. u32 gpadl;
  490. } __packed;
  491. struct vmbus_channel_gpadl_torndown {
  492. struct vmbus_channel_message_header header;
  493. u32 gpadl;
  494. } __packed;
  495. struct vmbus_channel_relid_released {
  496. struct vmbus_channel_message_header header;
  497. u32 child_relid;
  498. } __packed;
  499. struct vmbus_channel_initiate_contact {
  500. struct vmbus_channel_message_header header;
  501. u32 vmbus_version_requested;
  502. u32 target_vcpu; /* The VCPU the host should respond to */
  503. u64 interrupt_page;
  504. u64 monitor_page1;
  505. u64 monitor_page2;
  506. } __packed;
  507. /* Hyper-V socket: guest's connect()-ing to host */
  508. struct vmbus_channel_tl_connect_request {
  509. struct vmbus_channel_message_header header;
  510. uuid_le guest_endpoint_id;
  511. uuid_le host_service_id;
  512. } __packed;
  513. struct vmbus_channel_version_response {
  514. struct vmbus_channel_message_header header;
  515. u8 version_supported;
  516. } __packed;
  517. enum vmbus_channel_state {
  518. CHANNEL_OFFER_STATE,
  519. CHANNEL_OPENING_STATE,
  520. CHANNEL_OPEN_STATE,
  521. CHANNEL_OPENED_STATE,
  522. };
  523. /*
  524. * Represents each channel msg on the vmbus connection This is a
  525. * variable-size data structure depending on the msg type itself
  526. */
  527. struct vmbus_channel_msginfo {
  528. /* Bookkeeping stuff */
  529. struct list_head msglistentry;
  530. /* So far, this is only used to handle gpadl body message */
  531. struct list_head submsglist;
  532. /* Synchronize the request/response if needed */
  533. struct completion waitevent;
  534. union {
  535. struct vmbus_channel_version_supported version_supported;
  536. struct vmbus_channel_open_result open_result;
  537. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  538. struct vmbus_channel_gpadl_created gpadl_created;
  539. struct vmbus_channel_version_response version_response;
  540. } response;
  541. u32 msgsize;
  542. /*
  543. * The channel message that goes out on the "wire".
  544. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  545. */
  546. unsigned char msg[0];
  547. };
  548. struct vmbus_close_msg {
  549. struct vmbus_channel_msginfo info;
  550. struct vmbus_channel_close_channel msg;
  551. };
  552. /* Define connection identifier type. */
  553. union hv_connection_id {
  554. u32 asu32;
  555. struct {
  556. u32 id:24;
  557. u32 reserved:8;
  558. } u;
  559. };
  560. /* Definition of the hv_signal_event hypercall input structure. */
  561. struct hv_input_signal_event {
  562. union hv_connection_id connectionid;
  563. u16 flag_number;
  564. u16 rsvdz;
  565. };
  566. struct hv_input_signal_event_buffer {
  567. u64 align8;
  568. struct hv_input_signal_event event;
  569. };
  570. enum hv_signal_policy {
  571. HV_SIGNAL_POLICY_DEFAULT = 0,
  572. HV_SIGNAL_POLICY_EXPLICIT,
  573. };
  574. enum vmbus_device_type {
  575. HV_IDE = 0,
  576. HV_SCSI,
  577. HV_FC,
  578. HV_NIC,
  579. HV_ND,
  580. HV_PCIE,
  581. HV_FB,
  582. HV_KBD,
  583. HV_MOUSE,
  584. HV_KVP,
  585. HV_TS,
  586. HV_HB,
  587. HV_SHUTDOWN,
  588. HV_FCOPY,
  589. HV_BACKUP,
  590. HV_DM,
  591. HV_UNKOWN,
  592. };
  593. struct vmbus_device {
  594. u16 dev_type;
  595. uuid_le guid;
  596. bool perf_device;
  597. };
  598. struct vmbus_channel {
  599. /* Unique channel id */
  600. int id;
  601. struct list_head listentry;
  602. struct hv_device *device_obj;
  603. enum vmbus_channel_state state;
  604. struct vmbus_channel_offer_channel offermsg;
  605. /*
  606. * These are based on the OfferMsg.MonitorId.
  607. * Save it here for easy access.
  608. */
  609. u8 monitor_grp;
  610. u8 monitor_bit;
  611. bool rescind; /* got rescind msg */
  612. u32 ringbuffer_gpadlhandle;
  613. /* Allocated memory for ring buffer */
  614. void *ringbuffer_pages;
  615. u32 ringbuffer_pagecount;
  616. struct hv_ring_buffer_info outbound; /* send to parent */
  617. struct hv_ring_buffer_info inbound; /* receive from parent */
  618. spinlock_t inbound_lock;
  619. struct vmbus_close_msg close_msg;
  620. /* Channel callback are invoked in this workqueue context */
  621. /* HANDLE dataWorkQueue; */
  622. void (*onchannel_callback)(void *context);
  623. void *channel_callback_context;
  624. /*
  625. * A channel can be marked for efficient (batched)
  626. * reading:
  627. * If batched_reading is set to "true", we read until the
  628. * channel is empty and hold off interrupts from the host
  629. * during the entire read process.
  630. * If batched_reading is set to "false", the client is not
  631. * going to perform batched reading.
  632. *
  633. * By default we will enable batched reading; specific
  634. * drivers that don't want this behavior can turn it off.
  635. */
  636. bool batched_reading;
  637. bool is_dedicated_interrupt;
  638. struct hv_input_signal_event_buffer sig_buf;
  639. struct hv_input_signal_event *sig_event;
  640. /*
  641. * Starting with win8, this field will be used to specify
  642. * the target virtual processor on which to deliver the interrupt for
  643. * the host to guest communication.
  644. * Prior to win8, incoming channel interrupts would only
  645. * be delivered on cpu 0. Setting this value to 0 would
  646. * preserve the earlier behavior.
  647. */
  648. u32 target_vp;
  649. /* The corresponding CPUID in the guest */
  650. u32 target_cpu;
  651. /*
  652. * State to manage the CPU affiliation of channels.
  653. */
  654. struct cpumask alloced_cpus_in_node;
  655. int numa_node;
  656. /*
  657. * Support for sub-channels. For high performance devices,
  658. * it will be useful to have multiple sub-channels to support
  659. * a scalable communication infrastructure with the host.
  660. * The support for sub-channels is implemented as an extention
  661. * to the current infrastructure.
  662. * The initial offer is considered the primary channel and this
  663. * offer message will indicate if the host supports sub-channels.
  664. * The guest is free to ask for sub-channels to be offerred and can
  665. * open these sub-channels as a normal "primary" channel. However,
  666. * all sub-channels will have the same type and instance guids as the
  667. * primary channel. Requests sent on a given channel will result in a
  668. * response on the same channel.
  669. */
  670. /*
  671. * Sub-channel creation callback. This callback will be called in
  672. * process context when a sub-channel offer is received from the host.
  673. * The guest can open the sub-channel in the context of this callback.
  674. */
  675. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  676. /*
  677. * Channel rescind callback. Some channels (the hvsock ones), need to
  678. * register a callback which is invoked in vmbus_onoffer_rescind().
  679. */
  680. void (*chn_rescind_callback)(struct vmbus_channel *channel);
  681. /*
  682. * The spinlock to protect the structure. It is being used to protect
  683. * test-and-set access to various attributes of the structure as well
  684. * as all sc_list operations.
  685. */
  686. spinlock_t lock;
  687. /*
  688. * All Sub-channels of a primary channel are linked here.
  689. */
  690. struct list_head sc_list;
  691. /*
  692. * Current number of sub-channels.
  693. */
  694. int num_sc;
  695. /*
  696. * Number of a sub-channel (position within sc_list) which is supposed
  697. * to be used as the next outgoing channel.
  698. */
  699. int next_oc;
  700. /*
  701. * The primary channel this sub-channel belongs to.
  702. * This will be NULL for the primary channel.
  703. */
  704. struct vmbus_channel *primary_channel;
  705. /*
  706. * Support per-channel state for use by vmbus drivers.
  707. */
  708. void *per_channel_state;
  709. /*
  710. * To support per-cpu lookup mapping of relid to channel,
  711. * link up channels based on their CPU affinity.
  712. */
  713. struct list_head percpu_list;
  714. /*
  715. * Host signaling policy: The default policy will be
  716. * based on the ring buffer state. We will also support
  717. * a policy where the client driver can have explicit
  718. * signaling control.
  719. */
  720. enum hv_signal_policy signal_policy;
  721. /*
  722. * On the channel send side, many of the VMBUS
  723. * device drivers explicity serialize access to the
  724. * outgoing ring buffer. Give more control to the
  725. * VMBUS device drivers in terms how to serialize
  726. * accesss to the outgoing ring buffer.
  727. * The default behavior will be to aquire the
  728. * ring lock to preserve the current behavior.
  729. */
  730. bool acquire_ring_lock;
  731. };
  732. static inline void set_channel_lock_state(struct vmbus_channel *c, bool state)
  733. {
  734. c->acquire_ring_lock = state;
  735. }
  736. static inline bool is_hvsock_channel(const struct vmbus_channel *c)
  737. {
  738. return !!(c->offermsg.offer.chn_flags &
  739. VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER);
  740. }
  741. static inline void set_channel_signal_state(struct vmbus_channel *c,
  742. enum hv_signal_policy policy)
  743. {
  744. c->signal_policy = policy;
  745. }
  746. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  747. {
  748. c->batched_reading = state;
  749. }
  750. static inline void set_per_channel_state(struct vmbus_channel *c, void *s)
  751. {
  752. c->per_channel_state = s;
  753. }
  754. static inline void *get_per_channel_state(struct vmbus_channel *c)
  755. {
  756. return c->per_channel_state;
  757. }
  758. static inline void set_channel_pending_send_size(struct vmbus_channel *c,
  759. u32 size)
  760. {
  761. c->outbound.ring_buffer->pending_send_sz = size;
  762. }
  763. void vmbus_onmessage(void *context);
  764. int vmbus_request_offers(void);
  765. /*
  766. * APIs for managing sub-channels.
  767. */
  768. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  769. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  770. void vmbus_set_chn_rescind_callback(struct vmbus_channel *channel,
  771. void (*chn_rescind_cb)(struct vmbus_channel *));
  772. /*
  773. * Retrieve the (sub) channel on which to send an outgoing request.
  774. * When a primary channel has multiple sub-channels, we choose a
  775. * channel whose VCPU binding is closest to the VCPU on which
  776. * this call is being made.
  777. */
  778. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  779. /*
  780. * Check if sub-channels have already been offerred. This API will be useful
  781. * when the driver is unloaded after establishing sub-channels. In this case,
  782. * when the driver is re-loaded, the driver would have to check if the
  783. * subchannels have already been established before attempting to request
  784. * the creation of sub-channels.
  785. * This function returns TRUE to indicate that subchannels have already been
  786. * created.
  787. * This function should be invoked after setting the callback function for
  788. * sub-channel creation.
  789. */
  790. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  791. /* The format must be the same as struct vmdata_gpa_direct */
  792. struct vmbus_channel_packet_page_buffer {
  793. u16 type;
  794. u16 dataoffset8;
  795. u16 length8;
  796. u16 flags;
  797. u64 transactionid;
  798. u32 reserved;
  799. u32 rangecount;
  800. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  801. } __packed;
  802. /* The format must be the same as struct vmdata_gpa_direct */
  803. struct vmbus_channel_packet_multipage_buffer {
  804. u16 type;
  805. u16 dataoffset8;
  806. u16 length8;
  807. u16 flags;
  808. u64 transactionid;
  809. u32 reserved;
  810. u32 rangecount; /* Always 1 in this case */
  811. struct hv_multipage_buffer range;
  812. } __packed;
  813. /* The format must be the same as struct vmdata_gpa_direct */
  814. struct vmbus_packet_mpb_array {
  815. u16 type;
  816. u16 dataoffset8;
  817. u16 length8;
  818. u16 flags;
  819. u64 transactionid;
  820. u32 reserved;
  821. u32 rangecount; /* Always 1 in this case */
  822. struct hv_mpb_array range;
  823. } __packed;
  824. extern int vmbus_open(struct vmbus_channel *channel,
  825. u32 send_ringbuffersize,
  826. u32 recv_ringbuffersize,
  827. void *userdata,
  828. u32 userdatalen,
  829. void(*onchannel_callback)(void *context),
  830. void *context);
  831. extern void vmbus_close(struct vmbus_channel *channel);
  832. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  833. void *buffer,
  834. u32 bufferLen,
  835. u64 requestid,
  836. enum vmbus_packet_type type,
  837. u32 flags);
  838. extern int vmbus_sendpacket_ctl(struct vmbus_channel *channel,
  839. void *buffer,
  840. u32 bufferLen,
  841. u64 requestid,
  842. enum vmbus_packet_type type,
  843. u32 flags,
  844. bool kick_q);
  845. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  846. struct hv_page_buffer pagebuffers[],
  847. u32 pagecount,
  848. void *buffer,
  849. u32 bufferlen,
  850. u64 requestid);
  851. extern int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel,
  852. struct hv_page_buffer pagebuffers[],
  853. u32 pagecount,
  854. void *buffer,
  855. u32 bufferlen,
  856. u64 requestid,
  857. u32 flags,
  858. bool kick_q);
  859. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  860. struct hv_multipage_buffer *mpb,
  861. void *buffer,
  862. u32 bufferlen,
  863. u64 requestid);
  864. extern int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,
  865. struct vmbus_packet_mpb_array *mpb,
  866. u32 desc_size,
  867. void *buffer,
  868. u32 bufferlen,
  869. u64 requestid);
  870. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  871. void *kbuffer,
  872. u32 size,
  873. u32 *gpadl_handle);
  874. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  875. u32 gpadl_handle);
  876. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  877. void *buffer,
  878. u32 bufferlen,
  879. u32 *buffer_actual_len,
  880. u64 *requestid);
  881. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  882. void *buffer,
  883. u32 bufferlen,
  884. u32 *buffer_actual_len,
  885. u64 *requestid);
  886. extern void vmbus_ontimer(unsigned long data);
  887. /* Base driver object */
  888. struct hv_driver {
  889. const char *name;
  890. /*
  891. * A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER
  892. * channel flag, actually doesn't mean a synthetic device because the
  893. * offer's if_type/if_instance can change for every new hvsock
  894. * connection.
  895. *
  896. * However, to facilitate the notification of new-offer/rescind-offer
  897. * from vmbus driver to hvsock driver, we can handle hvsock offer as
  898. * a special vmbus device, and hence we need the below flag to
  899. * indicate if the driver is the hvsock driver or not: we need to
  900. * specially treat the hvosck offer & driver in vmbus_match().
  901. */
  902. bool hvsock;
  903. /* the device type supported by this driver */
  904. uuid_le dev_type;
  905. const struct hv_vmbus_device_id *id_table;
  906. struct device_driver driver;
  907. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  908. int (*remove)(struct hv_device *);
  909. void (*shutdown)(struct hv_device *);
  910. };
  911. /* Base device object */
  912. struct hv_device {
  913. /* the device type id of this device */
  914. uuid_le dev_type;
  915. /* the device instance id of this device */
  916. uuid_le dev_instance;
  917. u16 vendor_id;
  918. u16 device_id;
  919. struct device device;
  920. struct vmbus_channel *channel;
  921. };
  922. static inline struct hv_device *device_to_hv_device(struct device *d)
  923. {
  924. return container_of(d, struct hv_device, device);
  925. }
  926. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  927. {
  928. return container_of(d, struct hv_driver, driver);
  929. }
  930. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  931. {
  932. dev_set_drvdata(&dev->device, data);
  933. }
  934. static inline void *hv_get_drvdata(struct hv_device *dev)
  935. {
  936. return dev_get_drvdata(&dev->device);
  937. }
  938. /* Vmbus interface */
  939. #define vmbus_driver_register(driver) \
  940. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  941. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  942. struct module *owner,
  943. const char *mod_name);
  944. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  945. void vmbus_hvsock_device_unregister(struct vmbus_channel *channel);
  946. int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
  947. resource_size_t min, resource_size_t max,
  948. resource_size_t size, resource_size_t align,
  949. bool fb_overlap_ok);
  950. int vmbus_cpu_number_to_vp_number(int cpu_number);
  951. u64 hv_do_hypercall(u64 control, void *input, void *output);
  952. /*
  953. * GUID definitions of various offer types - services offered to the guest.
  954. */
  955. /*
  956. * Network GUID
  957. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  958. */
  959. #define HV_NIC_GUID \
  960. .guid = UUID_LE(0xf8615163, 0xdf3e, 0x46c5, 0x91, 0x3f, \
  961. 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e)
  962. /*
  963. * IDE GUID
  964. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  965. */
  966. #define HV_IDE_GUID \
  967. .guid = UUID_LE(0x32412632, 0x86cb, 0x44a2, 0x9b, 0x5c, \
  968. 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5)
  969. /*
  970. * SCSI GUID
  971. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  972. */
  973. #define HV_SCSI_GUID \
  974. .guid = UUID_LE(0xba6163d9, 0x04a1, 0x4d29, 0xb6, 0x05, \
  975. 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f)
  976. /*
  977. * Shutdown GUID
  978. * {0e0b6031-5213-4934-818b-38d90ced39db}
  979. */
  980. #define HV_SHUTDOWN_GUID \
  981. .guid = UUID_LE(0x0e0b6031, 0x5213, 0x4934, 0x81, 0x8b, \
  982. 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb)
  983. /*
  984. * Time Synch GUID
  985. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  986. */
  987. #define HV_TS_GUID \
  988. .guid = UUID_LE(0x9527e630, 0xd0ae, 0x497b, 0xad, 0xce, \
  989. 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf)
  990. /*
  991. * Heartbeat GUID
  992. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  993. */
  994. #define HV_HEART_BEAT_GUID \
  995. .guid = UUID_LE(0x57164f39, 0x9115, 0x4e78, 0xab, 0x55, \
  996. 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d)
  997. /*
  998. * KVP GUID
  999. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1000. */
  1001. #define HV_KVP_GUID \
  1002. .guid = UUID_LE(0xa9a0f4e7, 0x5a45, 0x4d96, 0xb8, 0x27, \
  1003. 0x8a, 0x84, 0x1e, 0x8c, 0x03, 0xe6)
  1004. /*
  1005. * Dynamic memory GUID
  1006. * {525074dc-8985-46e2-8057-a307dc18a502}
  1007. */
  1008. #define HV_DM_GUID \
  1009. .guid = UUID_LE(0x525074dc, 0x8985, 0x46e2, 0x80, 0x57, \
  1010. 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02)
  1011. /*
  1012. * Mouse GUID
  1013. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1014. */
  1015. #define HV_MOUSE_GUID \
  1016. .guid = UUID_LE(0xcfa8b69e, 0x5b4a, 0x4cc0, 0xb9, 0x8b, \
  1017. 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a)
  1018. /*
  1019. * Keyboard GUID
  1020. * {f912ad6d-2b17-48ea-bd65-f927a61c7684}
  1021. */
  1022. #define HV_KBD_GUID \
  1023. .guid = UUID_LE(0xf912ad6d, 0x2b17, 0x48ea, 0xbd, 0x65, \
  1024. 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84)
  1025. /*
  1026. * VSS (Backup/Restore) GUID
  1027. */
  1028. #define HV_VSS_GUID \
  1029. .guid = UUID_LE(0x35fa2e29, 0xea23, 0x4236, 0x96, 0xae, \
  1030. 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40)
  1031. /*
  1032. * Synthetic Video GUID
  1033. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1034. */
  1035. #define HV_SYNTHVID_GUID \
  1036. .guid = UUID_LE(0xda0a7802, 0xe377, 0x4aac, 0x8e, 0x77, \
  1037. 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8)
  1038. /*
  1039. * Synthetic FC GUID
  1040. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1041. */
  1042. #define HV_SYNTHFC_GUID \
  1043. .guid = UUID_LE(0x2f9bcc4a, 0x0069, 0x4af3, 0xb7, 0x6b, \
  1044. 0x6f, 0xd0, 0xbe, 0x52, 0x8c, 0xda)
  1045. /*
  1046. * Guest File Copy Service
  1047. * {34D14BE3-DEE4-41c8-9AE7-6B174977C192}
  1048. */
  1049. #define HV_FCOPY_GUID \
  1050. .guid = UUID_LE(0x34d14be3, 0xdee4, 0x41c8, 0x9a, 0xe7, \
  1051. 0x6b, 0x17, 0x49, 0x77, 0xc1, 0x92)
  1052. /*
  1053. * NetworkDirect. This is the guest RDMA service.
  1054. * {8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}
  1055. */
  1056. #define HV_ND_GUID \
  1057. .guid = UUID_LE(0x8c2eaf3d, 0x32a7, 0x4b09, 0xab, 0x99, \
  1058. 0xbd, 0x1f, 0x1c, 0x86, 0xb5, 0x01)
  1059. /*
  1060. * PCI Express Pass Through
  1061. * {44C4F61D-4444-4400-9D52-802E27EDE19F}
  1062. */
  1063. #define HV_PCIE_GUID \
  1064. .guid = UUID_LE(0x44c4f61d, 0x4444, 0x4400, 0x9d, 0x52, \
  1065. 0x80, 0x2e, 0x27, 0xed, 0xe1, 0x9f)
  1066. /*
  1067. * Common header for Hyper-V ICs
  1068. */
  1069. #define ICMSGTYPE_NEGOTIATE 0
  1070. #define ICMSGTYPE_HEARTBEAT 1
  1071. #define ICMSGTYPE_KVPEXCHANGE 2
  1072. #define ICMSGTYPE_SHUTDOWN 3
  1073. #define ICMSGTYPE_TIMESYNC 4
  1074. #define ICMSGTYPE_VSS 5
  1075. #define ICMSGHDRFLAG_TRANSACTION 1
  1076. #define ICMSGHDRFLAG_REQUEST 2
  1077. #define ICMSGHDRFLAG_RESPONSE 4
  1078. /*
  1079. * While we want to handle util services as regular devices,
  1080. * there is only one instance of each of these services; so
  1081. * we statically allocate the service specific state.
  1082. */
  1083. struct hv_util_service {
  1084. u8 *recv_buffer;
  1085. void *channel;
  1086. void (*util_cb)(void *);
  1087. int (*util_init)(struct hv_util_service *);
  1088. void (*util_deinit)(void);
  1089. };
  1090. struct vmbuspipe_hdr {
  1091. u32 flags;
  1092. u32 msgsize;
  1093. } __packed;
  1094. struct ic_version {
  1095. u16 major;
  1096. u16 minor;
  1097. } __packed;
  1098. struct icmsg_hdr {
  1099. struct ic_version icverframe;
  1100. u16 icmsgtype;
  1101. struct ic_version icvermsg;
  1102. u16 icmsgsize;
  1103. u32 status;
  1104. u8 ictransaction_id;
  1105. u8 icflags;
  1106. u8 reserved[2];
  1107. } __packed;
  1108. struct icmsg_negotiate {
  1109. u16 icframe_vercnt;
  1110. u16 icmsg_vercnt;
  1111. u32 reserved;
  1112. struct ic_version icversion_data[1]; /* any size array */
  1113. } __packed;
  1114. struct shutdown_msg_data {
  1115. u32 reason_code;
  1116. u32 timeout_seconds;
  1117. u32 flags;
  1118. u8 display_message[2048];
  1119. } __packed;
  1120. struct heartbeat_msg_data {
  1121. u64 seq_num;
  1122. u32 reserved[8];
  1123. } __packed;
  1124. /* Time Sync IC defs */
  1125. #define ICTIMESYNCFLAG_PROBE 0
  1126. #define ICTIMESYNCFLAG_SYNC 1
  1127. #define ICTIMESYNCFLAG_SAMPLE 2
  1128. #ifdef __x86_64__
  1129. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1130. #else
  1131. #define WLTIMEDELTA 116444736000000000LL
  1132. #endif
  1133. struct ictimesync_data {
  1134. u64 parenttime;
  1135. u64 childtime;
  1136. u64 roundtriptime;
  1137. u8 flags;
  1138. } __packed;
  1139. struct hyperv_service_callback {
  1140. u8 msg_type;
  1141. char *log_msg;
  1142. uuid_le data;
  1143. struct vmbus_channel *channel;
  1144. void (*callback) (void *context);
  1145. };
  1146. #define MAX_SRV_VER 0x7ffffff
  1147. extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1148. struct icmsg_negotiate *, u8 *, int,
  1149. int);
  1150. void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid);
  1151. /*
  1152. * Negotiated version with the Host.
  1153. */
  1154. extern __u32 vmbus_proto_version;
  1155. int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id,
  1156. const uuid_le *shv_host_servie_id);
  1157. void vmbus_set_event(struct vmbus_channel *channel);
  1158. /* Get the start of the ring buffer. */
  1159. static inline void *
  1160. hv_get_ring_buffer(struct hv_ring_buffer_info *ring_info)
  1161. {
  1162. return (void *)ring_info->ring_buffer->buffer;
  1163. }
  1164. /*
  1165. * To optimize the flow management on the send-side,
  1166. * when the sender is blocked because of lack of
  1167. * sufficient space in the ring buffer, potential the
  1168. * consumer of the ring buffer can signal the producer.
  1169. * This is controlled by the following parameters:
  1170. *
  1171. * 1. pending_send_sz: This is the size in bytes that the
  1172. * producer is trying to send.
  1173. * 2. The feature bit feat_pending_send_sz set to indicate if
  1174. * the consumer of the ring will signal when the ring
  1175. * state transitions from being full to a state where
  1176. * there is room for the producer to send the pending packet.
  1177. */
  1178. static inline bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
  1179. {
  1180. u32 cur_write_sz;
  1181. u32 pending_sz;
  1182. /*
  1183. * Issue a full memory barrier before making the signaling decision.
  1184. * Here is the reason for having this barrier:
  1185. * If the reading of the pend_sz (in this function)
  1186. * were to be reordered and read before we commit the new read
  1187. * index (in the calling function) we could
  1188. * have a problem. If the host were to set the pending_sz after we
  1189. * have sampled pending_sz and go to sleep before we commit the
  1190. * read index, we could miss sending the interrupt. Issue a full
  1191. * memory barrier to address this.
  1192. */
  1193. virt_mb();
  1194. pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
  1195. /* If the other end is not blocked on write don't bother. */
  1196. if (pending_sz == 0)
  1197. return false;
  1198. cur_write_sz = hv_get_bytes_to_write(rbi);
  1199. if (cur_write_sz >= pending_sz)
  1200. return true;
  1201. return false;
  1202. }
  1203. #endif /* _HYPERV_H */