hyperv.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  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 <linux/scatterlist.h>
  27. #include <linux/list.h>
  28. #include <linux/uuid.h>
  29. #include <linux/timer.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/completion.h>
  32. #include <linux/device.h>
  33. #include <linux/mod_devicetable.h>
  34. #define MAX_PAGE_BUFFER_COUNT 16
  35. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  36. #pragma pack(push, 1)
  37. /* Single-page buffer */
  38. struct hv_page_buffer {
  39. u32 len;
  40. u32 offset;
  41. u64 pfn;
  42. };
  43. /* Multiple-page buffer */
  44. struct hv_multipage_buffer {
  45. /* Length and Offset determines the # of pfns in the array */
  46. u32 len;
  47. u32 offset;
  48. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  49. };
  50. /* 0x18 includes the proprietary packet header */
  51. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  52. (sizeof(struct hv_page_buffer) * \
  53. MAX_PAGE_BUFFER_COUNT))
  54. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  55. sizeof(struct hv_multipage_buffer))
  56. #pragma pack(pop)
  57. struct hv_ring_buffer {
  58. /* Offset in bytes from the start of ring data below */
  59. u32 write_index;
  60. /* Offset in bytes from the start of ring data below */
  61. u32 read_index;
  62. u32 interrupt_mask;
  63. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  64. u8 reserved[4084];
  65. /* NOTE:
  66. * The interrupt_mask field is used only for channels but since our
  67. * vmbus connection also uses this data structure and its data starts
  68. * here, we commented out this field.
  69. */
  70. /*
  71. * Ring data starts here + RingDataStartOffset
  72. * !!! DO NOT place any fields below this !!!
  73. */
  74. u8 buffer[0];
  75. } __packed;
  76. struct hv_ring_buffer_info {
  77. struct hv_ring_buffer *ring_buffer;
  78. u32 ring_size; /* Include the shared header */
  79. spinlock_t ring_lock;
  80. u32 ring_datasize; /* < ring_size */
  81. u32 ring_data_startoffset;
  82. };
  83. struct hv_ring_buffer_debug_info {
  84. u32 current_interrupt_mask;
  85. u32 current_read_index;
  86. u32 current_write_index;
  87. u32 bytes_avail_toread;
  88. u32 bytes_avail_towrite;
  89. };
  90. /*
  91. * We use the same version numbering for all Hyper-V modules.
  92. *
  93. * Definition of versioning is as follows;
  94. *
  95. * Major Number Changes for these scenarios;
  96. * 1. When a new version of Windows Hyper-V
  97. * is released.
  98. * 2. A Major change has occurred in the
  99. * Linux IC's.
  100. * (For example the merge for the first time
  101. * into the kernel) Every time the Major Number
  102. * changes, the Revision number is reset to 0.
  103. * Minor Number Changes when new functionality is added
  104. * to the Linux IC's that is not a bug fix.
  105. *
  106. * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  107. */
  108. #define HV_DRV_VERSION "3.1"
  109. /*
  110. * A revision number of vmbus that is used for ensuring both ends on a
  111. * partition are using compatible versions.
  112. */
  113. #define VMBUS_REVISION_NUMBER 13
  114. /* Make maximum size of pipe payload of 16K */
  115. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  116. /* Define PipeMode values. */
  117. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  118. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  119. /* The size of the user defined data buffer for non-pipe offers. */
  120. #define MAX_USER_DEFINED_BYTES 120
  121. /* The size of the user defined data buffer for pipe offers. */
  122. #define MAX_PIPE_USER_DEFINED_BYTES 116
  123. /*
  124. * At the center of the Channel Management library is the Channel Offer. This
  125. * struct contains the fundamental information about an offer.
  126. */
  127. struct vmbus_channel_offer {
  128. uuid_le if_type;
  129. uuid_le if_instance;
  130. u64 int_latency; /* in 100ns units */
  131. u32 if_revision;
  132. u32 server_ctx_size; /* in bytes */
  133. u16 chn_flags;
  134. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  135. union {
  136. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  137. struct {
  138. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  139. } std;
  140. /*
  141. * Pipes:
  142. * The following sructure is an integrated pipe protocol, which
  143. * is implemented on top of standard user-defined data. Pipe
  144. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  145. * use.
  146. */
  147. struct {
  148. u32 pipe_mode;
  149. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  150. } pipe;
  151. } u;
  152. u32 padding;
  153. } __packed;
  154. /* Server Flags */
  155. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  156. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  157. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  158. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  159. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  160. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  161. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  162. struct vmpacket_descriptor {
  163. u16 type;
  164. u16 offset8;
  165. u16 len8;
  166. u16 flags;
  167. u64 trans_id;
  168. } __packed;
  169. struct vmpacket_header {
  170. u32 prev_pkt_start_offset;
  171. struct vmpacket_descriptor descriptor;
  172. } __packed;
  173. struct vmtransfer_page_range {
  174. u32 byte_count;
  175. u32 byte_offset;
  176. } __packed;
  177. struct vmtransfer_page_packet_header {
  178. struct vmpacket_descriptor d;
  179. u16 xfer_pageset_id;
  180. bool sender_owns_set;
  181. u8 reserved;
  182. u32 range_cnt;
  183. struct vmtransfer_page_range ranges[1];
  184. } __packed;
  185. struct vmgpadl_packet_header {
  186. struct vmpacket_descriptor d;
  187. u32 gpadl;
  188. u32 reserved;
  189. } __packed;
  190. struct vmadd_remove_transfer_page_set {
  191. struct vmpacket_descriptor d;
  192. u32 gpadl;
  193. u16 xfer_pageset_id;
  194. u16 reserved;
  195. } __packed;
  196. /*
  197. * This structure defines a range in guest physical space that can be made to
  198. * look virtually contiguous.
  199. */
  200. struct gpa_range {
  201. u32 byte_count;
  202. u32 byte_offset;
  203. u64 pfn_array[0];
  204. };
  205. /*
  206. * This is the format for an Establish Gpadl packet, which contains a handle by
  207. * which this GPADL will be known and a set of GPA ranges associated with it.
  208. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  209. * ranges, then the resulting MDL will be "chained," representing multiple VA
  210. * ranges.
  211. */
  212. struct vmestablish_gpadl {
  213. struct vmpacket_descriptor d;
  214. u32 gpadl;
  215. u32 range_cnt;
  216. struct gpa_range range[1];
  217. } __packed;
  218. /*
  219. * This is the format for a Teardown Gpadl packet, which indicates that the
  220. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  221. */
  222. struct vmteardown_gpadl {
  223. struct vmpacket_descriptor d;
  224. u32 gpadl;
  225. u32 reserved; /* for alignment to a 8-byte boundary */
  226. } __packed;
  227. /*
  228. * This is the format for a GPA-Direct packet, which contains a set of GPA
  229. * ranges, in addition to commands and/or data.
  230. */
  231. struct vmdata_gpa_direct {
  232. struct vmpacket_descriptor d;
  233. u32 reserved;
  234. u32 range_cnt;
  235. struct gpa_range range[1];
  236. } __packed;
  237. /* This is the format for a Additional Data Packet. */
  238. struct vmadditional_data {
  239. struct vmpacket_descriptor d;
  240. u64 total_bytes;
  241. u32 offset;
  242. u32 byte_cnt;
  243. unsigned char data[1];
  244. } __packed;
  245. union vmpacket_largest_possible_header {
  246. struct vmpacket_descriptor simple_hdr;
  247. struct vmtransfer_page_packet_header xfer_page_hdr;
  248. struct vmgpadl_packet_header gpadl_hdr;
  249. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  250. struct vmestablish_gpadl establish_gpadl_hdr;
  251. struct vmteardown_gpadl teardown_gpadl_hdr;
  252. struct vmdata_gpa_direct data_gpa_direct_hdr;
  253. };
  254. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  255. (void *)(((unsigned char *)__packet) + \
  256. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  257. #define VMPACKET_DATA_LENGTH(__packet) \
  258. ((((struct vmpacket_descriptor)__packet)->len8 - \
  259. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  260. #define VMPACKET_TRANSFER_MODE(__packet) \
  261. (((struct IMPACT)__packet)->type)
  262. enum vmbus_packet_type {
  263. VM_PKT_INVALID = 0x0,
  264. VM_PKT_SYNCH = 0x1,
  265. VM_PKT_ADD_XFER_PAGESET = 0x2,
  266. VM_PKT_RM_XFER_PAGESET = 0x3,
  267. VM_PKT_ESTABLISH_GPADL = 0x4,
  268. VM_PKT_TEARDOWN_GPADL = 0x5,
  269. VM_PKT_DATA_INBAND = 0x6,
  270. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  271. VM_PKT_DATA_USING_GPADL = 0x8,
  272. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  273. VM_PKT_CANCEL_REQUEST = 0xa,
  274. VM_PKT_COMP = 0xb,
  275. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  276. VM_PKT_ADDITIONAL_DATA = 0xd
  277. };
  278. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  279. /* Version 1 messages */
  280. enum vmbus_channel_message_type {
  281. CHANNELMSG_INVALID = 0,
  282. CHANNELMSG_OFFERCHANNEL = 1,
  283. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  284. CHANNELMSG_REQUESTOFFERS = 3,
  285. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  286. CHANNELMSG_OPENCHANNEL = 5,
  287. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  288. CHANNELMSG_CLOSECHANNEL = 7,
  289. CHANNELMSG_GPADL_HEADER = 8,
  290. CHANNELMSG_GPADL_BODY = 9,
  291. CHANNELMSG_GPADL_CREATED = 10,
  292. CHANNELMSG_GPADL_TEARDOWN = 11,
  293. CHANNELMSG_GPADL_TORNDOWN = 12,
  294. CHANNELMSG_RELID_RELEASED = 13,
  295. CHANNELMSG_INITIATE_CONTACT = 14,
  296. CHANNELMSG_VERSION_RESPONSE = 15,
  297. CHANNELMSG_UNLOAD = 16,
  298. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  299. CHANNELMSG_VIEWRANGE_ADD = 17,
  300. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  301. #endif
  302. CHANNELMSG_COUNT
  303. };
  304. struct vmbus_channel_message_header {
  305. enum vmbus_channel_message_type msgtype;
  306. u32 padding;
  307. } __packed;
  308. /* Query VMBus Version parameters */
  309. struct vmbus_channel_query_vmbus_version {
  310. struct vmbus_channel_message_header header;
  311. u32 version;
  312. } __packed;
  313. /* VMBus Version Supported parameters */
  314. struct vmbus_channel_version_supported {
  315. struct vmbus_channel_message_header header;
  316. bool version_supported;
  317. } __packed;
  318. /* Offer Channel parameters */
  319. struct vmbus_channel_offer_channel {
  320. struct vmbus_channel_message_header header;
  321. struct vmbus_channel_offer offer;
  322. u32 child_relid;
  323. u8 monitorid;
  324. bool monitor_allocated;
  325. } __packed;
  326. /* Rescind Offer parameters */
  327. struct vmbus_channel_rescind_offer {
  328. struct vmbus_channel_message_header header;
  329. u32 child_relid;
  330. } __packed;
  331. /*
  332. * Request Offer -- no parameters, SynIC message contains the partition ID
  333. * Set Snoop -- no parameters, SynIC message contains the partition ID
  334. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  335. * All Offers Delivered -- no parameters, SynIC message contains the partition
  336. * ID
  337. * Flush Client -- no parameters, SynIC message contains the partition ID
  338. */
  339. /* Open Channel parameters */
  340. struct vmbus_channel_open_channel {
  341. struct vmbus_channel_message_header header;
  342. /* Identifies the specific VMBus channel that is being opened. */
  343. u32 child_relid;
  344. /* ID making a particular open request at a channel offer unique. */
  345. u32 openid;
  346. /* GPADL for the channel's ring buffer. */
  347. u32 ringbuffer_gpadlhandle;
  348. /* GPADL for the channel's server context save area. */
  349. u32 server_contextarea_gpadlhandle;
  350. /*
  351. * The upstream ring buffer begins at offset zero in the memory
  352. * described by RingBufferGpadlHandle. The downstream ring buffer
  353. * follows it at this offset (in pages).
  354. */
  355. u32 downstream_ringbuffer_pageoffset;
  356. /* User-specific data to be passed along to the server endpoint. */
  357. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  358. } __packed;
  359. /* Open Channel Result parameters */
  360. struct vmbus_channel_open_result {
  361. struct vmbus_channel_message_header header;
  362. u32 child_relid;
  363. u32 openid;
  364. u32 status;
  365. } __packed;
  366. /* Close channel parameters; */
  367. struct vmbus_channel_close_channel {
  368. struct vmbus_channel_message_header header;
  369. u32 child_relid;
  370. } __packed;
  371. /* Channel Message GPADL */
  372. #define GPADL_TYPE_RING_BUFFER 1
  373. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  374. #define GPADL_TYPE_TRANSACTION 8
  375. /*
  376. * The number of PFNs in a GPADL message is defined by the number of
  377. * pages that would be spanned by ByteCount and ByteOffset. If the
  378. * implied number of PFNs won't fit in this packet, there will be a
  379. * follow-up packet that contains more.
  380. */
  381. struct vmbus_channel_gpadl_header {
  382. struct vmbus_channel_message_header header;
  383. u32 child_relid;
  384. u32 gpadl;
  385. u16 range_buflen;
  386. u16 rangecount;
  387. struct gpa_range range[0];
  388. } __packed;
  389. /* This is the followup packet that contains more PFNs. */
  390. struct vmbus_channel_gpadl_body {
  391. struct vmbus_channel_message_header header;
  392. u32 msgnumber;
  393. u32 gpadl;
  394. u64 pfn[0];
  395. } __packed;
  396. struct vmbus_channel_gpadl_created {
  397. struct vmbus_channel_message_header header;
  398. u32 child_relid;
  399. u32 gpadl;
  400. u32 creation_status;
  401. } __packed;
  402. struct vmbus_channel_gpadl_teardown {
  403. struct vmbus_channel_message_header header;
  404. u32 child_relid;
  405. u32 gpadl;
  406. } __packed;
  407. struct vmbus_channel_gpadl_torndown {
  408. struct vmbus_channel_message_header header;
  409. u32 gpadl;
  410. } __packed;
  411. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  412. struct vmbus_channel_view_range_add {
  413. struct vmbus_channel_message_header header;
  414. PHYSICAL_ADDRESS viewrange_base;
  415. u64 viewrange_length;
  416. u32 child_relid;
  417. } __packed;
  418. struct vmbus_channel_view_range_remove {
  419. struct vmbus_channel_message_header header;
  420. PHYSICAL_ADDRESS viewrange_base;
  421. u32 child_relid;
  422. } __packed;
  423. #endif
  424. struct vmbus_channel_relid_released {
  425. struct vmbus_channel_message_header header;
  426. u32 child_relid;
  427. } __packed;
  428. struct vmbus_channel_initiate_contact {
  429. struct vmbus_channel_message_header header;
  430. u32 vmbus_version_requested;
  431. u32 padding2;
  432. u64 interrupt_page;
  433. u64 monitor_page1;
  434. u64 monitor_page2;
  435. } __packed;
  436. struct vmbus_channel_version_response {
  437. struct vmbus_channel_message_header header;
  438. bool version_supported;
  439. } __packed;
  440. enum vmbus_channel_state {
  441. CHANNEL_OFFER_STATE,
  442. CHANNEL_OPENING_STATE,
  443. CHANNEL_OPEN_STATE,
  444. };
  445. struct vmbus_channel_debug_info {
  446. u32 relid;
  447. enum vmbus_channel_state state;
  448. uuid_le interfacetype;
  449. uuid_le interface_instance;
  450. u32 monitorid;
  451. u32 servermonitor_pending;
  452. u32 servermonitor_latency;
  453. u32 servermonitor_connectionid;
  454. u32 clientmonitor_pending;
  455. u32 clientmonitor_latency;
  456. u32 clientmonitor_connectionid;
  457. struct hv_ring_buffer_debug_info inbound;
  458. struct hv_ring_buffer_debug_info outbound;
  459. };
  460. /*
  461. * Represents each channel msg on the vmbus connection This is a
  462. * variable-size data structure depending on the msg type itself
  463. */
  464. struct vmbus_channel_msginfo {
  465. /* Bookkeeping stuff */
  466. struct list_head msglistentry;
  467. /* So far, this is only used to handle gpadl body message */
  468. struct list_head submsglist;
  469. /* Synchronize the request/response if needed */
  470. struct completion waitevent;
  471. union {
  472. struct vmbus_channel_version_supported version_supported;
  473. struct vmbus_channel_open_result open_result;
  474. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  475. struct vmbus_channel_gpadl_created gpadl_created;
  476. struct vmbus_channel_version_response version_response;
  477. } response;
  478. u32 msgsize;
  479. /*
  480. * The channel message that goes out on the "wire".
  481. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  482. */
  483. unsigned char msg[0];
  484. };
  485. struct vmbus_close_msg {
  486. struct vmbus_channel_msginfo info;
  487. struct vmbus_channel_close_channel msg;
  488. };
  489. struct vmbus_channel {
  490. struct list_head listentry;
  491. struct hv_device *device_obj;
  492. struct work_struct work;
  493. enum vmbus_channel_state state;
  494. struct vmbus_channel_offer_channel offermsg;
  495. /*
  496. * These are based on the OfferMsg.MonitorId.
  497. * Save it here for easy access.
  498. */
  499. u8 monitor_grp;
  500. u8 monitor_bit;
  501. u32 ringbuffer_gpadlhandle;
  502. /* Allocated memory for ring buffer */
  503. void *ringbuffer_pages;
  504. u32 ringbuffer_pagecount;
  505. struct hv_ring_buffer_info outbound; /* send to parent */
  506. struct hv_ring_buffer_info inbound; /* receive from parent */
  507. spinlock_t inbound_lock;
  508. struct workqueue_struct *controlwq;
  509. struct vmbus_close_msg close_msg;
  510. /* Channel callback are invoked in this workqueue context */
  511. /* HANDLE dataWorkQueue; */
  512. void (*onchannel_callback)(void *context);
  513. void *channel_callback_context;
  514. };
  515. void free_channel(struct vmbus_channel *channel);
  516. void vmbus_onmessage(void *context);
  517. int vmbus_request_offers(void);
  518. /* The format must be the same as struct vmdata_gpa_direct */
  519. struct vmbus_channel_packet_page_buffer {
  520. u16 type;
  521. u16 dataoffset8;
  522. u16 length8;
  523. u16 flags;
  524. u64 transactionid;
  525. u32 reserved;
  526. u32 rangecount;
  527. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  528. } __packed;
  529. /* The format must be the same as struct vmdata_gpa_direct */
  530. struct vmbus_channel_packet_multipage_buffer {
  531. u16 type;
  532. u16 dataoffset8;
  533. u16 length8;
  534. u16 flags;
  535. u64 transactionid;
  536. u32 reserved;
  537. u32 rangecount; /* Always 1 in this case */
  538. struct hv_multipage_buffer range;
  539. } __packed;
  540. extern int vmbus_open(struct vmbus_channel *channel,
  541. u32 send_ringbuffersize,
  542. u32 recv_ringbuffersize,
  543. void *userdata,
  544. u32 userdatalen,
  545. void(*onchannel_callback)(void *context),
  546. void *context);
  547. extern void vmbus_close(struct vmbus_channel *channel);
  548. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  549. const void *buffer,
  550. u32 bufferLen,
  551. u64 requestid,
  552. enum vmbus_packet_type type,
  553. u32 flags);
  554. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  555. struct hv_page_buffer pagebuffers[],
  556. u32 pagecount,
  557. void *buffer,
  558. u32 bufferlen,
  559. u64 requestid);
  560. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  561. struct hv_multipage_buffer *mpb,
  562. void *buffer,
  563. u32 bufferlen,
  564. u64 requestid);
  565. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  566. void *kbuffer,
  567. u32 size,
  568. u32 *gpadl_handle);
  569. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  570. u32 gpadl_handle);
  571. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  572. void *buffer,
  573. u32 bufferlen,
  574. u32 *buffer_actual_len,
  575. u64 *requestid);
  576. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  577. void *buffer,
  578. u32 bufferlen,
  579. u32 *buffer_actual_len,
  580. u64 *requestid);
  581. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  582. struct vmbus_channel_debug_info *debug);
  583. extern void vmbus_ontimer(unsigned long data);
  584. #define LOWORD(dw) ((unsigned short)(dw))
  585. #define HIWORD(dw) ((unsigned short)(((unsigned int) (dw) >> 16) & 0xFFFF))
  586. #define VMBUS 0x0001
  587. #define STORVSC 0x0002
  588. #define NETVSC 0x0004
  589. #define INPUTVSC 0x0008
  590. #define BLKVSC 0x0010
  591. #define VMBUS_DRV 0x0100
  592. #define STORVSC_DRV 0x0200
  593. #define NETVSC_DRV 0x0400
  594. #define INPUTVSC_DRV 0x0800
  595. #define BLKVSC_DRV 0x1000
  596. #define ALL_MODULES (VMBUS |\
  597. STORVSC |\
  598. NETVSC |\
  599. INPUTVSC |\
  600. BLKVSC |\
  601. VMBUS_DRV |\
  602. STORVSC_DRV |\
  603. NETVSC_DRV |\
  604. INPUTVSC_DRV|\
  605. BLKVSC_DRV)
  606. /* Logging Level */
  607. #define INFO_LVL 6
  608. extern unsigned int vmbus_loglevel;
  609. struct hv_driver;
  610. struct hv_device;
  611. struct hv_dev_port_info {
  612. u32 int_mask;
  613. u32 read_idx;
  614. u32 write_idx;
  615. u32 bytes_avail_toread;
  616. u32 bytes_avail_towrite;
  617. };
  618. struct hv_device_info {
  619. u32 chn_id;
  620. u32 chn_state;
  621. uuid_le chn_type;
  622. uuid_le chn_instance;
  623. u32 monitor_id;
  624. u32 server_monitor_pending;
  625. u32 server_monitor_latency;
  626. u32 server_monitor_conn_id;
  627. u32 client_monitor_pending;
  628. u32 client_monitor_latency;
  629. u32 client_monitor_conn_id;
  630. struct hv_dev_port_info inbound;
  631. struct hv_dev_port_info outbound;
  632. };
  633. /* Base driver object */
  634. struct hv_driver {
  635. const char *name;
  636. /* the device type supported by this driver */
  637. uuid_le dev_type;
  638. const struct hv_vmbus_device_id *id_table;
  639. struct device_driver driver;
  640. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  641. int (*remove)(struct hv_device *);
  642. void (*shutdown)(struct hv_device *);
  643. };
  644. /* Base device object */
  645. struct hv_device {
  646. /* the device type id of this device */
  647. uuid_le dev_type;
  648. /* the device instance id of this device */
  649. uuid_le dev_instance;
  650. struct device device;
  651. struct vmbus_channel *channel;
  652. };
  653. static inline struct hv_device *device_to_hv_device(struct device *d)
  654. {
  655. return container_of(d, struct hv_device, device);
  656. }
  657. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  658. {
  659. return container_of(d, struct hv_driver, driver);
  660. }
  661. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  662. {
  663. dev_set_drvdata(&dev->device, data);
  664. }
  665. static inline void *hv_get_drvdata(struct hv_device *dev)
  666. {
  667. return dev_get_drvdata(&dev->device);
  668. }
  669. /* Vmbus interface */
  670. #define vmbus_driver_register(driver) \
  671. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  672. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  673. struct module *owner,
  674. const char *mod_name);
  675. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  676. /**
  677. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  678. *
  679. * This macro is used to create a struct hv_vmbus_device_id that matches a
  680. * specific device.
  681. */
  682. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  683. g8, g9, ga, gb, gc, gd, ge, gf) \
  684. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  685. g8, g9, ga, gb, gc, gd, ge, gf },
  686. /*
  687. * Common header for Hyper-V ICs
  688. */
  689. #define ICMSGTYPE_NEGOTIATE 0
  690. #define ICMSGTYPE_HEARTBEAT 1
  691. #define ICMSGTYPE_KVPEXCHANGE 2
  692. #define ICMSGTYPE_SHUTDOWN 3
  693. #define ICMSGTYPE_TIMESYNC 4
  694. #define ICMSGTYPE_VSS 5
  695. #define ICMSGHDRFLAG_TRANSACTION 1
  696. #define ICMSGHDRFLAG_REQUEST 2
  697. #define ICMSGHDRFLAG_RESPONSE 4
  698. #define HV_S_OK 0x00000000
  699. #define HV_E_FAIL 0x80004005
  700. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  701. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  702. /*
  703. * While we want to handle util services as regular devices,
  704. * there is only one instance of each of these services; so
  705. * we statically allocate the service specific state.
  706. */
  707. struct hv_util_service {
  708. u8 *recv_buffer;
  709. void (*util_cb)(void *);
  710. int (*util_init)(struct hv_util_service *);
  711. void (*util_deinit)(void);
  712. };
  713. struct vmbuspipe_hdr {
  714. u32 flags;
  715. u32 msgsize;
  716. } __packed;
  717. struct ic_version {
  718. u16 major;
  719. u16 minor;
  720. } __packed;
  721. struct icmsg_hdr {
  722. struct ic_version icverframe;
  723. u16 icmsgtype;
  724. struct ic_version icvermsg;
  725. u16 icmsgsize;
  726. u32 status;
  727. u8 ictransaction_id;
  728. u8 icflags;
  729. u8 reserved[2];
  730. } __packed;
  731. struct icmsg_negotiate {
  732. u16 icframe_vercnt;
  733. u16 icmsg_vercnt;
  734. u32 reserved;
  735. struct ic_version icversion_data[1]; /* any size array */
  736. } __packed;
  737. struct shutdown_msg_data {
  738. u32 reason_code;
  739. u32 timeout_seconds;
  740. u32 flags;
  741. u8 display_message[2048];
  742. } __packed;
  743. struct heartbeat_msg_data {
  744. u64 seq_num;
  745. u32 reserved[8];
  746. } __packed;
  747. /* Time Sync IC defs */
  748. #define ICTIMESYNCFLAG_PROBE 0
  749. #define ICTIMESYNCFLAG_SYNC 1
  750. #define ICTIMESYNCFLAG_SAMPLE 2
  751. #ifdef __x86_64__
  752. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  753. #else
  754. #define WLTIMEDELTA 116444736000000000LL
  755. #endif
  756. struct ictimesync_data {
  757. u64 parenttime;
  758. u64 childtime;
  759. u64 roundtriptime;
  760. u8 flags;
  761. } __packed;
  762. struct hyperv_service_callback {
  763. u8 msg_type;
  764. char *log_msg;
  765. uuid_le data;
  766. struct vmbus_channel *channel;
  767. void (*callback) (void *context);
  768. };
  769. extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  770. struct icmsg_negotiate *, u8 *);
  771. #endif /* _HYPERV_H */