hyperv.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  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/types.h>
  27. /*
  28. * Implementation of host controlled snapshot of the guest.
  29. */
  30. #define VSS_OP_REGISTER 128
  31. enum hv_vss_op {
  32. VSS_OP_CREATE = 0,
  33. VSS_OP_DELETE,
  34. VSS_OP_HOT_BACKUP,
  35. VSS_OP_GET_DM_INFO,
  36. VSS_OP_BU_COMPLETE,
  37. /*
  38. * Following operations are only supported with IC version >= 5.0
  39. */
  40. VSS_OP_FREEZE, /* Freeze the file systems in the VM */
  41. VSS_OP_THAW, /* Unfreeze the file systems */
  42. VSS_OP_AUTO_RECOVER,
  43. VSS_OP_COUNT /* Number of operations, must be last */
  44. };
  45. /*
  46. * Header for all VSS messages.
  47. */
  48. struct hv_vss_hdr {
  49. __u8 operation;
  50. __u8 reserved[7];
  51. } __attribute__((packed));
  52. /*
  53. * Flag values for the hv_vss_check_feature. Linux supports only
  54. * one value.
  55. */
  56. #define VSS_HBU_NO_AUTO_RECOVERY 0x00000005
  57. struct hv_vss_check_feature {
  58. __u32 flags;
  59. } __attribute__((packed));
  60. struct hv_vss_check_dm_info {
  61. __u32 flags;
  62. } __attribute__((packed));
  63. struct hv_vss_msg {
  64. union {
  65. struct hv_vss_hdr vss_hdr;
  66. int error;
  67. };
  68. union {
  69. struct hv_vss_check_feature vss_cf;
  70. struct hv_vss_check_dm_info dm_info;
  71. };
  72. } __attribute__((packed));
  73. /*
  74. * An implementation of HyperV key value pair (KVP) functionality for Linux.
  75. *
  76. *
  77. * Copyright (C) 2010, Novell, Inc.
  78. * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
  79. *
  80. */
  81. /*
  82. * Maximum value size - used for both key names and value data, and includes
  83. * any applicable NULL terminators.
  84. *
  85. * Note: This limit is somewhat arbitrary, but falls easily within what is
  86. * supported for all native guests (back to Win 2000) and what is reasonable
  87. * for the IC KVP exchange functionality. Note that Windows Me/98/95 are
  88. * limited to 255 character key names.
  89. *
  90. * MSDN recommends not storing data values larger than 2048 bytes in the
  91. * registry.
  92. *
  93. * Note: This value is used in defining the KVP exchange message - this value
  94. * cannot be modified without affecting the message size and compatibility.
  95. */
  96. /*
  97. * bytes, including any null terminators
  98. */
  99. #define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
  100. /*
  101. * Maximum key size - the registry limit for the length of an entry name
  102. * is 256 characters, including the null terminator
  103. */
  104. #define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
  105. /*
  106. * In Linux, we implement the KVP functionality in two components:
  107. * 1) The kernel component which is packaged as part of the hv_utils driver
  108. * is responsible for communicating with the host and responsible for
  109. * implementing the host/guest protocol. 2) A user level daemon that is
  110. * responsible for data gathering.
  111. *
  112. * Host/Guest Protocol: The host iterates over an index and expects the guest
  113. * to assign a key name to the index and also return the value corresponding to
  114. * the key. The host will have atmost one KVP transaction outstanding at any
  115. * given point in time. The host side iteration stops when the guest returns
  116. * an error. Microsoft has specified the following mapping of key names to
  117. * host specified index:
  118. *
  119. * Index Key Name
  120. * 0 FullyQualifiedDomainName
  121. * 1 IntegrationServicesVersion
  122. * 2 NetworkAddressIPv4
  123. * 3 NetworkAddressIPv6
  124. * 4 OSBuildNumber
  125. * 5 OSName
  126. * 6 OSMajorVersion
  127. * 7 OSMinorVersion
  128. * 8 OSVersion
  129. * 9 ProcessorArchitecture
  130. *
  131. * The Windows host expects the Key Name and Key Value to be encoded in utf16.
  132. *
  133. * Guest Kernel/KVP Daemon Protocol: As noted earlier, we implement all of the
  134. * data gathering functionality in a user mode daemon. The user level daemon
  135. * is also responsible for binding the key name to the index as well. The
  136. * kernel and user-level daemon communicate using a connector channel.
  137. *
  138. * The user mode component first registers with the
  139. * the kernel component. Subsequently, the kernel component requests, data
  140. * for the specified keys. In response to this message the user mode component
  141. * fills in the value corresponding to the specified key. We overload the
  142. * sequence field in the cn_msg header to define our KVP message types.
  143. *
  144. *
  145. * The kernel component simply acts as a conduit for communication between the
  146. * Windows host and the user-level daemon. The kernel component passes up the
  147. * index received from the Host to the user-level daemon. If the index is
  148. * valid (supported), the corresponding key as well as its
  149. * value (both are strings) is returned. If the index is invalid
  150. * (not supported), a NULL key string is returned.
  151. */
  152. /*
  153. * Registry value types.
  154. */
  155. #define REG_SZ 1
  156. #define REG_U32 4
  157. #define REG_U64 8
  158. /*
  159. * As we look at expanding the KVP functionality to include
  160. * IP injection functionality, we need to maintain binary
  161. * compatibility with older daemons.
  162. *
  163. * The KVP opcodes are defined by the host and it was unfortunate
  164. * that I chose to treat the registration operation as part of the
  165. * KVP operations defined by the host.
  166. * Here is the level of compatibility
  167. * (between the user level daemon and the kernel KVP driver) that we
  168. * will implement:
  169. *
  170. * An older daemon will always be supported on a newer driver.
  171. * A given user level daemon will require a minimal version of the
  172. * kernel driver.
  173. * If we cannot handle the version differences, we will fail gracefully
  174. * (this can happen when we have a user level daemon that is more
  175. * advanced than the KVP driver.
  176. *
  177. * We will use values used in this handshake for determining if we have
  178. * workable user level daemon and the kernel driver. We begin by taking the
  179. * registration opcode out of the KVP opcode namespace. We will however,
  180. * maintain compatibility with the existing user-level daemon code.
  181. */
  182. /*
  183. * Daemon code not supporting IP injection (legacy daemon).
  184. */
  185. #define KVP_OP_REGISTER 4
  186. /*
  187. * Daemon code supporting IP injection.
  188. * The KVP opcode field is used to communicate the
  189. * registration information; so define a namespace that
  190. * will be distinct from the host defined KVP opcode.
  191. */
  192. #define KVP_OP_REGISTER1 100
  193. enum hv_kvp_exchg_op {
  194. KVP_OP_GET = 0,
  195. KVP_OP_SET,
  196. KVP_OP_DELETE,
  197. KVP_OP_ENUMERATE,
  198. KVP_OP_GET_IP_INFO,
  199. KVP_OP_SET_IP_INFO,
  200. KVP_OP_COUNT /* Number of operations, must be last. */
  201. };
  202. enum hv_kvp_exchg_pool {
  203. KVP_POOL_EXTERNAL = 0,
  204. KVP_POOL_GUEST,
  205. KVP_POOL_AUTO,
  206. KVP_POOL_AUTO_EXTERNAL,
  207. KVP_POOL_AUTO_INTERNAL,
  208. KVP_POOL_COUNT /* Number of pools, must be last. */
  209. };
  210. /*
  211. * Some Hyper-V status codes.
  212. */
  213. #define HV_S_OK 0x00000000
  214. #define HV_E_FAIL 0x80004005
  215. #define HV_S_CONT 0x80070103
  216. #define HV_ERROR_NOT_SUPPORTED 0x80070032
  217. #define HV_ERROR_MACHINE_LOCKED 0x800704F7
  218. #define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
  219. #define HV_INVALIDARG 0x80070057
  220. #define HV_GUID_NOTFOUND 0x80041002
  221. #define ADDR_FAMILY_NONE 0x00
  222. #define ADDR_FAMILY_IPV4 0x01
  223. #define ADDR_FAMILY_IPV6 0x02
  224. #define MAX_ADAPTER_ID_SIZE 128
  225. #define MAX_IP_ADDR_SIZE 1024
  226. #define MAX_GATEWAY_SIZE 512
  227. struct hv_kvp_ipaddr_value {
  228. __u16 adapter_id[MAX_ADAPTER_ID_SIZE];
  229. __u8 addr_family;
  230. __u8 dhcp_enabled;
  231. __u16 ip_addr[MAX_IP_ADDR_SIZE];
  232. __u16 sub_net[MAX_IP_ADDR_SIZE];
  233. __u16 gate_way[MAX_GATEWAY_SIZE];
  234. __u16 dns_addr[MAX_IP_ADDR_SIZE];
  235. } __attribute__((packed));
  236. struct hv_kvp_hdr {
  237. __u8 operation;
  238. __u8 pool;
  239. __u16 pad;
  240. } __attribute__((packed));
  241. struct hv_kvp_exchg_msg_value {
  242. __u32 value_type;
  243. __u32 key_size;
  244. __u32 value_size;
  245. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  246. union {
  247. __u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
  248. __u32 value_u32;
  249. __u64 value_u64;
  250. };
  251. } __attribute__((packed));
  252. struct hv_kvp_msg_enumerate {
  253. __u32 index;
  254. struct hv_kvp_exchg_msg_value data;
  255. } __attribute__((packed));
  256. struct hv_kvp_msg_get {
  257. struct hv_kvp_exchg_msg_value data;
  258. };
  259. struct hv_kvp_msg_set {
  260. struct hv_kvp_exchg_msg_value data;
  261. };
  262. struct hv_kvp_msg_delete {
  263. __u32 key_size;
  264. __u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  265. };
  266. struct hv_kvp_register {
  267. __u8 version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
  268. };
  269. struct hv_kvp_msg {
  270. union {
  271. struct hv_kvp_hdr kvp_hdr;
  272. int error;
  273. };
  274. union {
  275. struct hv_kvp_msg_get kvp_get;
  276. struct hv_kvp_msg_set kvp_set;
  277. struct hv_kvp_msg_delete kvp_delete;
  278. struct hv_kvp_msg_enumerate kvp_enum_data;
  279. struct hv_kvp_ipaddr_value kvp_ip_val;
  280. struct hv_kvp_register kvp_register;
  281. } body;
  282. } __attribute__((packed));
  283. struct hv_kvp_ip_msg {
  284. __u8 operation;
  285. __u8 pool;
  286. struct hv_kvp_ipaddr_value kvp_ip_val;
  287. } __attribute__((packed));
  288. #ifdef __KERNEL__
  289. #include <linux/scatterlist.h>
  290. #include <linux/list.h>
  291. #include <linux/uuid.h>
  292. #include <linux/timer.h>
  293. #include <linux/workqueue.h>
  294. #include <linux/completion.h>
  295. #include <linux/device.h>
  296. #include <linux/mod_devicetable.h>
  297. #define MAX_PAGE_BUFFER_COUNT 19
  298. #define MAX_MULTIPAGE_BUFFER_COUNT 32 /* 128K */
  299. #pragma pack(push, 1)
  300. /* Single-page buffer */
  301. struct hv_page_buffer {
  302. u32 len;
  303. u32 offset;
  304. u64 pfn;
  305. };
  306. /* Multiple-page buffer */
  307. struct hv_multipage_buffer {
  308. /* Length and Offset determines the # of pfns in the array */
  309. u32 len;
  310. u32 offset;
  311. u64 pfn_array[MAX_MULTIPAGE_BUFFER_COUNT];
  312. };
  313. /* 0x18 includes the proprietary packet header */
  314. #define MAX_PAGE_BUFFER_PACKET (0x18 + \
  315. (sizeof(struct hv_page_buffer) * \
  316. MAX_PAGE_BUFFER_COUNT))
  317. #define MAX_MULTIPAGE_BUFFER_PACKET (0x18 + \
  318. sizeof(struct hv_multipage_buffer))
  319. #pragma pack(pop)
  320. struct hv_ring_buffer {
  321. /* Offset in bytes from the start of ring data below */
  322. u32 write_index;
  323. /* Offset in bytes from the start of ring data below */
  324. u32 read_index;
  325. u32 interrupt_mask;
  326. /*
  327. * Win8 uses some of the reserved bits to implement
  328. * interrupt driven flow management. On the send side
  329. * we can request that the receiver interrupt the sender
  330. * when the ring transitions from being full to being able
  331. * to handle a message of size "pending_send_sz".
  332. *
  333. * Add necessary state for this enhancement.
  334. */
  335. u32 pending_send_sz;
  336. u32 reserved1[12];
  337. union {
  338. struct {
  339. u32 feat_pending_send_sz:1;
  340. };
  341. u32 value;
  342. } feature_bits;
  343. /* Pad it to PAGE_SIZE so that data starts on page boundary */
  344. u8 reserved2[4028];
  345. /*
  346. * Ring data starts here + RingDataStartOffset
  347. * !!! DO NOT place any fields below this !!!
  348. */
  349. u8 buffer[0];
  350. } __packed;
  351. struct hv_ring_buffer_info {
  352. struct hv_ring_buffer *ring_buffer;
  353. u32 ring_size; /* Include the shared header */
  354. spinlock_t ring_lock;
  355. u32 ring_datasize; /* < ring_size */
  356. u32 ring_data_startoffset;
  357. };
  358. struct hv_ring_buffer_debug_info {
  359. u32 current_interrupt_mask;
  360. u32 current_read_index;
  361. u32 current_write_index;
  362. u32 bytes_avail_toread;
  363. u32 bytes_avail_towrite;
  364. };
  365. /*
  366. *
  367. * hv_get_ringbuffer_availbytes()
  368. *
  369. * Get number of bytes available to read and to write to
  370. * for the specified ring buffer
  371. */
  372. static inline void
  373. hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
  374. u32 *read, u32 *write)
  375. {
  376. u32 read_loc, write_loc, dsize;
  377. smp_read_barrier_depends();
  378. /* Capture the read/write indices before they changed */
  379. read_loc = rbi->ring_buffer->read_index;
  380. write_loc = rbi->ring_buffer->write_index;
  381. dsize = rbi->ring_datasize;
  382. *write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
  383. read_loc - write_loc;
  384. *read = dsize - *write;
  385. }
  386. /*
  387. * We use the same version numbering for all Hyper-V modules.
  388. *
  389. * Definition of versioning is as follows;
  390. *
  391. * Major Number Changes for these scenarios;
  392. * 1. When a new version of Windows Hyper-V
  393. * is released.
  394. * 2. A Major change has occurred in the
  395. * Linux IC's.
  396. * (For example the merge for the first time
  397. * into the kernel) Every time the Major Number
  398. * changes, the Revision number is reset to 0.
  399. * Minor Number Changes when new functionality is added
  400. * to the Linux IC's that is not a bug fix.
  401. *
  402. * 3.1 - Added completed hv_utils driver. Shutdown/Heartbeat/Timesync
  403. */
  404. #define HV_DRV_VERSION "3.1"
  405. /*
  406. * VMBUS version is 32 bit entity broken up into
  407. * two 16 bit quantities: major_number. minor_number.
  408. *
  409. * 0 . 13 (Windows Server 2008)
  410. * 1 . 1 (Windows 7)
  411. * 2 . 4 (Windows 8)
  412. */
  413. #define VERSION_WS2008 ((0 << 16) | (13))
  414. #define VERSION_WIN7 ((1 << 16) | (1))
  415. #define VERSION_WIN8 ((2 << 16) | (4))
  416. #define VERSION_INVAL -1
  417. #define VERSION_CURRENT VERSION_WIN8
  418. /* Make maximum size of pipe payload of 16K */
  419. #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384)
  420. /* Define PipeMode values. */
  421. #define VMBUS_PIPE_TYPE_BYTE 0x00000000
  422. #define VMBUS_PIPE_TYPE_MESSAGE 0x00000004
  423. /* The size of the user defined data buffer for non-pipe offers. */
  424. #define MAX_USER_DEFINED_BYTES 120
  425. /* The size of the user defined data buffer for pipe offers. */
  426. #define MAX_PIPE_USER_DEFINED_BYTES 116
  427. /*
  428. * At the center of the Channel Management library is the Channel Offer. This
  429. * struct contains the fundamental information about an offer.
  430. */
  431. struct vmbus_channel_offer {
  432. uuid_le if_type;
  433. uuid_le if_instance;
  434. /*
  435. * These two fields are not currently used.
  436. */
  437. u64 reserved1;
  438. u64 reserved2;
  439. u16 chn_flags;
  440. u16 mmio_megabytes; /* in bytes * 1024 * 1024 */
  441. union {
  442. /* Non-pipes: The user has MAX_USER_DEFINED_BYTES bytes. */
  443. struct {
  444. unsigned char user_def[MAX_USER_DEFINED_BYTES];
  445. } std;
  446. /*
  447. * Pipes:
  448. * The following sructure is an integrated pipe protocol, which
  449. * is implemented on top of standard user-defined data. Pipe
  450. * clients have MAX_PIPE_USER_DEFINED_BYTES left for their own
  451. * use.
  452. */
  453. struct {
  454. u32 pipe_mode;
  455. unsigned char user_def[MAX_PIPE_USER_DEFINED_BYTES];
  456. } pipe;
  457. } u;
  458. /*
  459. * The sub_channel_index is defined in win8.
  460. */
  461. u16 sub_channel_index;
  462. u16 reserved3;
  463. } __packed;
  464. /* Server Flags */
  465. #define VMBUS_CHANNEL_ENUMERATE_DEVICE_INTERFACE 1
  466. #define VMBUS_CHANNEL_SERVER_SUPPORTS_TRANSFER_PAGES 2
  467. #define VMBUS_CHANNEL_SERVER_SUPPORTS_GPADLS 4
  468. #define VMBUS_CHANNEL_NAMED_PIPE_MODE 0x10
  469. #define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100
  470. #define VMBUS_CHANNEL_PARENT_OFFER 0x200
  471. #define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400
  472. struct vmpacket_descriptor {
  473. u16 type;
  474. u16 offset8;
  475. u16 len8;
  476. u16 flags;
  477. u64 trans_id;
  478. } __packed;
  479. struct vmpacket_header {
  480. u32 prev_pkt_start_offset;
  481. struct vmpacket_descriptor descriptor;
  482. } __packed;
  483. struct vmtransfer_page_range {
  484. u32 byte_count;
  485. u32 byte_offset;
  486. } __packed;
  487. struct vmtransfer_page_packet_header {
  488. struct vmpacket_descriptor d;
  489. u16 xfer_pageset_id;
  490. u8 sender_owns_set;
  491. u8 reserved;
  492. u32 range_cnt;
  493. struct vmtransfer_page_range ranges[1];
  494. } __packed;
  495. struct vmgpadl_packet_header {
  496. struct vmpacket_descriptor d;
  497. u32 gpadl;
  498. u32 reserved;
  499. } __packed;
  500. struct vmadd_remove_transfer_page_set {
  501. struct vmpacket_descriptor d;
  502. u32 gpadl;
  503. u16 xfer_pageset_id;
  504. u16 reserved;
  505. } __packed;
  506. /*
  507. * This structure defines a range in guest physical space that can be made to
  508. * look virtually contiguous.
  509. */
  510. struct gpa_range {
  511. u32 byte_count;
  512. u32 byte_offset;
  513. u64 pfn_array[0];
  514. };
  515. /*
  516. * This is the format for an Establish Gpadl packet, which contains a handle by
  517. * which this GPADL will be known and a set of GPA ranges associated with it.
  518. * This can be converted to a MDL by the guest OS. If there are multiple GPA
  519. * ranges, then the resulting MDL will be "chained," representing multiple VA
  520. * ranges.
  521. */
  522. struct vmestablish_gpadl {
  523. struct vmpacket_descriptor d;
  524. u32 gpadl;
  525. u32 range_cnt;
  526. struct gpa_range range[1];
  527. } __packed;
  528. /*
  529. * This is the format for a Teardown Gpadl packet, which indicates that the
  530. * GPADL handle in the Establish Gpadl packet will never be referenced again.
  531. */
  532. struct vmteardown_gpadl {
  533. struct vmpacket_descriptor d;
  534. u32 gpadl;
  535. u32 reserved; /* for alignment to a 8-byte boundary */
  536. } __packed;
  537. /*
  538. * This is the format for a GPA-Direct packet, which contains a set of GPA
  539. * ranges, in addition to commands and/or data.
  540. */
  541. struct vmdata_gpa_direct {
  542. struct vmpacket_descriptor d;
  543. u32 reserved;
  544. u32 range_cnt;
  545. struct gpa_range range[1];
  546. } __packed;
  547. /* This is the format for a Additional Data Packet. */
  548. struct vmadditional_data {
  549. struct vmpacket_descriptor d;
  550. u64 total_bytes;
  551. u32 offset;
  552. u32 byte_cnt;
  553. unsigned char data[1];
  554. } __packed;
  555. union vmpacket_largest_possible_header {
  556. struct vmpacket_descriptor simple_hdr;
  557. struct vmtransfer_page_packet_header xfer_page_hdr;
  558. struct vmgpadl_packet_header gpadl_hdr;
  559. struct vmadd_remove_transfer_page_set add_rm_xfer_page_hdr;
  560. struct vmestablish_gpadl establish_gpadl_hdr;
  561. struct vmteardown_gpadl teardown_gpadl_hdr;
  562. struct vmdata_gpa_direct data_gpa_direct_hdr;
  563. };
  564. #define VMPACKET_DATA_START_ADDRESS(__packet) \
  565. (void *)(((unsigned char *)__packet) + \
  566. ((struct vmpacket_descriptor)__packet)->offset8 * 8)
  567. #define VMPACKET_DATA_LENGTH(__packet) \
  568. ((((struct vmpacket_descriptor)__packet)->len8 - \
  569. ((struct vmpacket_descriptor)__packet)->offset8) * 8)
  570. #define VMPACKET_TRANSFER_MODE(__packet) \
  571. (((struct IMPACT)__packet)->type)
  572. enum vmbus_packet_type {
  573. VM_PKT_INVALID = 0x0,
  574. VM_PKT_SYNCH = 0x1,
  575. VM_PKT_ADD_XFER_PAGESET = 0x2,
  576. VM_PKT_RM_XFER_PAGESET = 0x3,
  577. VM_PKT_ESTABLISH_GPADL = 0x4,
  578. VM_PKT_TEARDOWN_GPADL = 0x5,
  579. VM_PKT_DATA_INBAND = 0x6,
  580. VM_PKT_DATA_USING_XFER_PAGES = 0x7,
  581. VM_PKT_DATA_USING_GPADL = 0x8,
  582. VM_PKT_DATA_USING_GPA_DIRECT = 0x9,
  583. VM_PKT_CANCEL_REQUEST = 0xa,
  584. VM_PKT_COMP = 0xb,
  585. VM_PKT_DATA_USING_ADDITIONAL_PKT = 0xc,
  586. VM_PKT_ADDITIONAL_DATA = 0xd
  587. };
  588. #define VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED 1
  589. /* Version 1 messages */
  590. enum vmbus_channel_message_type {
  591. CHANNELMSG_INVALID = 0,
  592. CHANNELMSG_OFFERCHANNEL = 1,
  593. CHANNELMSG_RESCIND_CHANNELOFFER = 2,
  594. CHANNELMSG_REQUESTOFFERS = 3,
  595. CHANNELMSG_ALLOFFERS_DELIVERED = 4,
  596. CHANNELMSG_OPENCHANNEL = 5,
  597. CHANNELMSG_OPENCHANNEL_RESULT = 6,
  598. CHANNELMSG_CLOSECHANNEL = 7,
  599. CHANNELMSG_GPADL_HEADER = 8,
  600. CHANNELMSG_GPADL_BODY = 9,
  601. CHANNELMSG_GPADL_CREATED = 10,
  602. CHANNELMSG_GPADL_TEARDOWN = 11,
  603. CHANNELMSG_GPADL_TORNDOWN = 12,
  604. CHANNELMSG_RELID_RELEASED = 13,
  605. CHANNELMSG_INITIATE_CONTACT = 14,
  606. CHANNELMSG_VERSION_RESPONSE = 15,
  607. CHANNELMSG_UNLOAD = 16,
  608. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  609. CHANNELMSG_VIEWRANGE_ADD = 17,
  610. CHANNELMSG_VIEWRANGE_REMOVE = 18,
  611. #endif
  612. CHANNELMSG_COUNT
  613. };
  614. struct vmbus_channel_message_header {
  615. enum vmbus_channel_message_type msgtype;
  616. u32 padding;
  617. } __packed;
  618. /* Query VMBus Version parameters */
  619. struct vmbus_channel_query_vmbus_version {
  620. struct vmbus_channel_message_header header;
  621. u32 version;
  622. } __packed;
  623. /* VMBus Version Supported parameters */
  624. struct vmbus_channel_version_supported {
  625. struct vmbus_channel_message_header header;
  626. u8 version_supported;
  627. } __packed;
  628. /* Offer Channel parameters */
  629. struct vmbus_channel_offer_channel {
  630. struct vmbus_channel_message_header header;
  631. struct vmbus_channel_offer offer;
  632. u32 child_relid;
  633. u8 monitorid;
  634. /*
  635. * win7 and beyond splits this field into a bit field.
  636. */
  637. u8 monitor_allocated:1;
  638. u8 reserved:7;
  639. /*
  640. * These are new fields added in win7 and later.
  641. * Do not access these fields without checking the
  642. * negotiated protocol.
  643. *
  644. * If "is_dedicated_interrupt" is set, we must not set the
  645. * associated bit in the channel bitmap while sending the
  646. * interrupt to the host.
  647. *
  648. * connection_id is to be used in signaling the host.
  649. */
  650. u16 is_dedicated_interrupt:1;
  651. u16 reserved1:15;
  652. u32 connection_id;
  653. } __packed;
  654. /* Rescind Offer parameters */
  655. struct vmbus_channel_rescind_offer {
  656. struct vmbus_channel_message_header header;
  657. u32 child_relid;
  658. } __packed;
  659. /*
  660. * Request Offer -- no parameters, SynIC message contains the partition ID
  661. * Set Snoop -- no parameters, SynIC message contains the partition ID
  662. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  663. * All Offers Delivered -- no parameters, SynIC message contains the partition
  664. * ID
  665. * Flush Client -- no parameters, SynIC message contains the partition ID
  666. */
  667. /* Open Channel parameters */
  668. struct vmbus_channel_open_channel {
  669. struct vmbus_channel_message_header header;
  670. /* Identifies the specific VMBus channel that is being opened. */
  671. u32 child_relid;
  672. /* ID making a particular open request at a channel offer unique. */
  673. u32 openid;
  674. /* GPADL for the channel's ring buffer. */
  675. u32 ringbuffer_gpadlhandle;
  676. /*
  677. * Starting with win8, this field will be used to specify
  678. * the target virtual processor on which to deliver the interrupt for
  679. * the host to guest communication.
  680. * Prior to win8, incoming channel interrupts would only
  681. * be delivered on cpu 0. Setting this value to 0 would
  682. * preserve the earlier behavior.
  683. */
  684. u32 target_vp;
  685. /*
  686. * The upstream ring buffer begins at offset zero in the memory
  687. * described by RingBufferGpadlHandle. The downstream ring buffer
  688. * follows it at this offset (in pages).
  689. */
  690. u32 downstream_ringbuffer_pageoffset;
  691. /* User-specific data to be passed along to the server endpoint. */
  692. unsigned char userdata[MAX_USER_DEFINED_BYTES];
  693. } __packed;
  694. /* Open Channel Result parameters */
  695. struct vmbus_channel_open_result {
  696. struct vmbus_channel_message_header header;
  697. u32 child_relid;
  698. u32 openid;
  699. u32 status;
  700. } __packed;
  701. /* Close channel parameters; */
  702. struct vmbus_channel_close_channel {
  703. struct vmbus_channel_message_header header;
  704. u32 child_relid;
  705. } __packed;
  706. /* Channel Message GPADL */
  707. #define GPADL_TYPE_RING_BUFFER 1
  708. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  709. #define GPADL_TYPE_TRANSACTION 8
  710. /*
  711. * The number of PFNs in a GPADL message is defined by the number of
  712. * pages that would be spanned by ByteCount and ByteOffset. If the
  713. * implied number of PFNs won't fit in this packet, there will be a
  714. * follow-up packet that contains more.
  715. */
  716. struct vmbus_channel_gpadl_header {
  717. struct vmbus_channel_message_header header;
  718. u32 child_relid;
  719. u32 gpadl;
  720. u16 range_buflen;
  721. u16 rangecount;
  722. struct gpa_range range[0];
  723. } __packed;
  724. /* This is the followup packet that contains more PFNs. */
  725. struct vmbus_channel_gpadl_body {
  726. struct vmbus_channel_message_header header;
  727. u32 msgnumber;
  728. u32 gpadl;
  729. u64 pfn[0];
  730. } __packed;
  731. struct vmbus_channel_gpadl_created {
  732. struct vmbus_channel_message_header header;
  733. u32 child_relid;
  734. u32 gpadl;
  735. u32 creation_status;
  736. } __packed;
  737. struct vmbus_channel_gpadl_teardown {
  738. struct vmbus_channel_message_header header;
  739. u32 child_relid;
  740. u32 gpadl;
  741. } __packed;
  742. struct vmbus_channel_gpadl_torndown {
  743. struct vmbus_channel_message_header header;
  744. u32 gpadl;
  745. } __packed;
  746. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  747. struct vmbus_channel_view_range_add {
  748. struct vmbus_channel_message_header header;
  749. PHYSICAL_ADDRESS viewrange_base;
  750. u64 viewrange_length;
  751. u32 child_relid;
  752. } __packed;
  753. struct vmbus_channel_view_range_remove {
  754. struct vmbus_channel_message_header header;
  755. PHYSICAL_ADDRESS viewrange_base;
  756. u32 child_relid;
  757. } __packed;
  758. #endif
  759. struct vmbus_channel_relid_released {
  760. struct vmbus_channel_message_header header;
  761. u32 child_relid;
  762. } __packed;
  763. struct vmbus_channel_initiate_contact {
  764. struct vmbus_channel_message_header header;
  765. u32 vmbus_version_requested;
  766. u32 padding2;
  767. u64 interrupt_page;
  768. u64 monitor_page1;
  769. u64 monitor_page2;
  770. } __packed;
  771. struct vmbus_channel_version_response {
  772. struct vmbus_channel_message_header header;
  773. u8 version_supported;
  774. } __packed;
  775. enum vmbus_channel_state {
  776. CHANNEL_OFFER_STATE,
  777. CHANNEL_OPENING_STATE,
  778. CHANNEL_OPEN_STATE,
  779. CHANNEL_OPENED_STATE,
  780. };
  781. struct vmbus_channel_debug_info {
  782. u32 relid;
  783. enum vmbus_channel_state state;
  784. uuid_le interfacetype;
  785. uuid_le interface_instance;
  786. u32 monitorid;
  787. u32 servermonitor_pending;
  788. u32 servermonitor_latency;
  789. u32 servermonitor_connectionid;
  790. u32 clientmonitor_pending;
  791. u32 clientmonitor_latency;
  792. u32 clientmonitor_connectionid;
  793. struct hv_ring_buffer_debug_info inbound;
  794. struct hv_ring_buffer_debug_info outbound;
  795. };
  796. /*
  797. * Represents each channel msg on the vmbus connection This is a
  798. * variable-size data structure depending on the msg type itself
  799. */
  800. struct vmbus_channel_msginfo {
  801. /* Bookkeeping stuff */
  802. struct list_head msglistentry;
  803. /* So far, this is only used to handle gpadl body message */
  804. struct list_head submsglist;
  805. /* Synchronize the request/response if needed */
  806. struct completion waitevent;
  807. union {
  808. struct vmbus_channel_version_supported version_supported;
  809. struct vmbus_channel_open_result open_result;
  810. struct vmbus_channel_gpadl_torndown gpadl_torndown;
  811. struct vmbus_channel_gpadl_created gpadl_created;
  812. struct vmbus_channel_version_response version_response;
  813. } response;
  814. u32 msgsize;
  815. /*
  816. * The channel message that goes out on the "wire".
  817. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  818. */
  819. unsigned char msg[0];
  820. };
  821. struct vmbus_close_msg {
  822. struct vmbus_channel_msginfo info;
  823. struct vmbus_channel_close_channel msg;
  824. };
  825. /* Define connection identifier type. */
  826. union hv_connection_id {
  827. u32 asu32;
  828. struct {
  829. u32 id:24;
  830. u32 reserved:8;
  831. } u;
  832. };
  833. /* Definition of the hv_signal_event hypercall input structure. */
  834. struct hv_input_signal_event {
  835. union hv_connection_id connectionid;
  836. u16 flag_number;
  837. u16 rsvdz;
  838. };
  839. struct hv_input_signal_event_buffer {
  840. u64 align8;
  841. struct hv_input_signal_event event;
  842. };
  843. struct vmbus_channel {
  844. struct list_head listentry;
  845. struct hv_device *device_obj;
  846. struct work_struct work;
  847. enum vmbus_channel_state state;
  848. struct vmbus_channel_offer_channel offermsg;
  849. /*
  850. * These are based on the OfferMsg.MonitorId.
  851. * Save it here for easy access.
  852. */
  853. u8 monitor_grp;
  854. u8 monitor_bit;
  855. u32 ringbuffer_gpadlhandle;
  856. /* Allocated memory for ring buffer */
  857. void *ringbuffer_pages;
  858. u32 ringbuffer_pagecount;
  859. struct hv_ring_buffer_info outbound; /* send to parent */
  860. struct hv_ring_buffer_info inbound; /* receive from parent */
  861. spinlock_t inbound_lock;
  862. struct workqueue_struct *controlwq;
  863. struct vmbus_close_msg close_msg;
  864. /* Channel callback are invoked in this workqueue context */
  865. /* HANDLE dataWorkQueue; */
  866. void (*onchannel_callback)(void *context);
  867. void *channel_callback_context;
  868. /*
  869. * A channel can be marked for efficient (batched)
  870. * reading:
  871. * If batched_reading is set to "true", we read until the
  872. * channel is empty and hold off interrupts from the host
  873. * during the entire read process.
  874. * If batched_reading is set to "false", the client is not
  875. * going to perform batched reading.
  876. *
  877. * By default we will enable batched reading; specific
  878. * drivers that don't want this behavior can turn it off.
  879. */
  880. bool batched_reading;
  881. bool is_dedicated_interrupt;
  882. struct hv_input_signal_event_buffer sig_buf;
  883. struct hv_input_signal_event *sig_event;
  884. /*
  885. * Starting with win8, this field will be used to specify
  886. * the target virtual processor on which to deliver the interrupt for
  887. * the host to guest communication.
  888. * Prior to win8, incoming channel interrupts would only
  889. * be delivered on cpu 0. Setting this value to 0 would
  890. * preserve the earlier behavior.
  891. */
  892. u32 target_vp;
  893. /*
  894. * Support for sub-channels. For high performance devices,
  895. * it will be useful to have multiple sub-channels to support
  896. * a scalable communication infrastructure with the host.
  897. * The support for sub-channels is implemented as an extention
  898. * to the current infrastructure.
  899. * The initial offer is considered the primary channel and this
  900. * offer message will indicate if the host supports sub-channels.
  901. * The guest is free to ask for sub-channels to be offerred and can
  902. * open these sub-channels as a normal "primary" channel. However,
  903. * all sub-channels will have the same type and instance guids as the
  904. * primary channel. Requests sent on a given channel will result in a
  905. * response on the same channel.
  906. */
  907. /*
  908. * Sub-channel creation callback. This callback will be called in
  909. * process context when a sub-channel offer is received from the host.
  910. * The guest can open the sub-channel in the context of this callback.
  911. */
  912. void (*sc_creation_callback)(struct vmbus_channel *new_sc);
  913. spinlock_t sc_lock;
  914. /*
  915. * All Sub-channels of a primary channel are linked here.
  916. */
  917. struct list_head sc_list;
  918. /*
  919. * The primary channel this sub-channel belongs to.
  920. * This will be NULL for the primary channel.
  921. */
  922. struct vmbus_channel *primary_channel;
  923. };
  924. static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
  925. {
  926. c->batched_reading = state;
  927. }
  928. void vmbus_onmessage(void *context);
  929. int vmbus_request_offers(void);
  930. /*
  931. * APIs for managing sub-channels.
  932. */
  933. void vmbus_set_sc_create_callback(struct vmbus_channel *primary_channel,
  934. void (*sc_cr_cb)(struct vmbus_channel *new_sc));
  935. /*
  936. * Retrieve the (sub) channel on which to send an outgoing request.
  937. * When a primary channel has multiple sub-channels, we choose a
  938. * channel whose VCPU binding is closest to the VCPU on which
  939. * this call is being made.
  940. */
  941. struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel *primary);
  942. /*
  943. * Check if sub-channels have already been offerred. This API will be useful
  944. * when the driver is unloaded after establishing sub-channels. In this case,
  945. * when the driver is re-loaded, the driver would have to check if the
  946. * subchannels have already been established before attempting to request
  947. * the creation of sub-channels.
  948. * This function returns TRUE to indicate that subchannels have already been
  949. * created.
  950. * This function should be invoked after setting the callback function for
  951. * sub-channel creation.
  952. */
  953. bool vmbus_are_subchannels_present(struct vmbus_channel *primary);
  954. /* The format must be the same as struct vmdata_gpa_direct */
  955. struct vmbus_channel_packet_page_buffer {
  956. u16 type;
  957. u16 dataoffset8;
  958. u16 length8;
  959. u16 flags;
  960. u64 transactionid;
  961. u32 reserved;
  962. u32 rangecount;
  963. struct hv_page_buffer range[MAX_PAGE_BUFFER_COUNT];
  964. } __packed;
  965. /* The format must be the same as struct vmdata_gpa_direct */
  966. struct vmbus_channel_packet_multipage_buffer {
  967. u16 type;
  968. u16 dataoffset8;
  969. u16 length8;
  970. u16 flags;
  971. u64 transactionid;
  972. u32 reserved;
  973. u32 rangecount; /* Always 1 in this case */
  974. struct hv_multipage_buffer range;
  975. } __packed;
  976. extern int vmbus_open(struct vmbus_channel *channel,
  977. u32 send_ringbuffersize,
  978. u32 recv_ringbuffersize,
  979. void *userdata,
  980. u32 userdatalen,
  981. void(*onchannel_callback)(void *context),
  982. void *context);
  983. extern void vmbus_close(struct vmbus_channel *channel);
  984. extern int vmbus_sendpacket(struct vmbus_channel *channel,
  985. const void *buffer,
  986. u32 bufferLen,
  987. u64 requestid,
  988. enum vmbus_packet_type type,
  989. u32 flags);
  990. extern int vmbus_sendpacket_pagebuffer(struct vmbus_channel *channel,
  991. struct hv_page_buffer pagebuffers[],
  992. u32 pagecount,
  993. void *buffer,
  994. u32 bufferlen,
  995. u64 requestid);
  996. extern int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,
  997. struct hv_multipage_buffer *mpb,
  998. void *buffer,
  999. u32 bufferlen,
  1000. u64 requestid);
  1001. extern int vmbus_establish_gpadl(struct vmbus_channel *channel,
  1002. void *kbuffer,
  1003. u32 size,
  1004. u32 *gpadl_handle);
  1005. extern int vmbus_teardown_gpadl(struct vmbus_channel *channel,
  1006. u32 gpadl_handle);
  1007. extern int vmbus_recvpacket(struct vmbus_channel *channel,
  1008. void *buffer,
  1009. u32 bufferlen,
  1010. u32 *buffer_actual_len,
  1011. u64 *requestid);
  1012. extern int vmbus_recvpacket_raw(struct vmbus_channel *channel,
  1013. void *buffer,
  1014. u32 bufferlen,
  1015. u32 *buffer_actual_len,
  1016. u64 *requestid);
  1017. extern void vmbus_get_debug_info(struct vmbus_channel *channel,
  1018. struct vmbus_channel_debug_info *debug);
  1019. extern void vmbus_ontimer(unsigned long data);
  1020. struct hv_dev_port_info {
  1021. u32 int_mask;
  1022. u32 read_idx;
  1023. u32 write_idx;
  1024. u32 bytes_avail_toread;
  1025. u32 bytes_avail_towrite;
  1026. };
  1027. /* Base driver object */
  1028. struct hv_driver {
  1029. const char *name;
  1030. /* the device type supported by this driver */
  1031. uuid_le dev_type;
  1032. const struct hv_vmbus_device_id *id_table;
  1033. struct device_driver driver;
  1034. int (*probe)(struct hv_device *, const struct hv_vmbus_device_id *);
  1035. int (*remove)(struct hv_device *);
  1036. void (*shutdown)(struct hv_device *);
  1037. };
  1038. /* Base device object */
  1039. struct hv_device {
  1040. /* the device type id of this device */
  1041. uuid_le dev_type;
  1042. /* the device instance id of this device */
  1043. uuid_le dev_instance;
  1044. struct device device;
  1045. struct vmbus_channel *channel;
  1046. };
  1047. static inline struct hv_device *device_to_hv_device(struct device *d)
  1048. {
  1049. return container_of(d, struct hv_device, device);
  1050. }
  1051. static inline struct hv_driver *drv_to_hv_drv(struct device_driver *d)
  1052. {
  1053. return container_of(d, struct hv_driver, driver);
  1054. }
  1055. static inline void hv_set_drvdata(struct hv_device *dev, void *data)
  1056. {
  1057. dev_set_drvdata(&dev->device, data);
  1058. }
  1059. static inline void *hv_get_drvdata(struct hv_device *dev)
  1060. {
  1061. return dev_get_drvdata(&dev->device);
  1062. }
  1063. /* Vmbus interface */
  1064. #define vmbus_driver_register(driver) \
  1065. __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
  1066. int __must_check __vmbus_driver_register(struct hv_driver *hv_driver,
  1067. struct module *owner,
  1068. const char *mod_name);
  1069. void vmbus_driver_unregister(struct hv_driver *hv_driver);
  1070. /**
  1071. * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  1072. *
  1073. * This macro is used to create a struct hv_vmbus_device_id that matches a
  1074. * specific device.
  1075. */
  1076. #define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7, \
  1077. g8, g9, ga, gb, gc, gd, ge, gf) \
  1078. .guid = { g0, g1, g2, g3, g4, g5, g6, g7, \
  1079. g8, g9, ga, gb, gc, gd, ge, gf },
  1080. /*
  1081. * GUID definitions of various offer types - services offered to the guest.
  1082. */
  1083. /*
  1084. * Network GUID
  1085. * {f8615163-df3e-46c5-913f-f2d2f965ed0e}
  1086. */
  1087. #define HV_NIC_GUID \
  1088. .guid = { \
  1089. 0x63, 0x51, 0x61, 0xf8, 0x3e, 0xdf, 0xc5, 0x46, \
  1090. 0x91, 0x3f, 0xf2, 0xd2, 0xf9, 0x65, 0xed, 0x0e \
  1091. }
  1092. /*
  1093. * IDE GUID
  1094. * {32412632-86cb-44a2-9b5c-50d1417354f5}
  1095. */
  1096. #define HV_IDE_GUID \
  1097. .guid = { \
  1098. 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, \
  1099. 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 \
  1100. }
  1101. /*
  1102. * SCSI GUID
  1103. * {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
  1104. */
  1105. #define HV_SCSI_GUID \
  1106. .guid = { \
  1107. 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, \
  1108. 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f \
  1109. }
  1110. /*
  1111. * Shutdown GUID
  1112. * {0e0b6031-5213-4934-818b-38d90ced39db}
  1113. */
  1114. #define HV_SHUTDOWN_GUID \
  1115. .guid = { \
  1116. 0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49, \
  1117. 0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb \
  1118. }
  1119. /*
  1120. * Time Synch GUID
  1121. * {9527E630-D0AE-497b-ADCE-E80AB0175CAF}
  1122. */
  1123. #define HV_TS_GUID \
  1124. .guid = { \
  1125. 0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49, \
  1126. 0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf \
  1127. }
  1128. /*
  1129. * Heartbeat GUID
  1130. * {57164f39-9115-4e78-ab55-382f3bd5422d}
  1131. */
  1132. #define HV_HEART_BEAT_GUID \
  1133. .guid = { \
  1134. 0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e, \
  1135. 0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d \
  1136. }
  1137. /*
  1138. * KVP GUID
  1139. * {a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}
  1140. */
  1141. #define HV_KVP_GUID \
  1142. .guid = { \
  1143. 0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d, \
  1144. 0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 \
  1145. }
  1146. /*
  1147. * Dynamic memory GUID
  1148. * {525074dc-8985-46e2-8057-a307dc18a502}
  1149. */
  1150. #define HV_DM_GUID \
  1151. .guid = { \
  1152. 0xdc, 0x74, 0x50, 0X52, 0x85, 0x89, 0xe2, 0x46, \
  1153. 0x80, 0x57, 0xa3, 0x07, 0xdc, 0x18, 0xa5, 0x02 \
  1154. }
  1155. /*
  1156. * Mouse GUID
  1157. * {cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}
  1158. */
  1159. #define HV_MOUSE_GUID \
  1160. .guid = { \
  1161. 0x9e, 0xb6, 0xa8, 0xcf, 0x4a, 0x5b, 0xc0, 0x4c, \
  1162. 0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a \
  1163. }
  1164. /*
  1165. * VSS (Backup/Restore) GUID
  1166. */
  1167. #define HV_VSS_GUID \
  1168. .guid = { \
  1169. 0x29, 0x2e, 0xfa, 0x35, 0x23, 0xea, 0x36, 0x42, \
  1170. 0x96, 0xae, 0x3a, 0x6e, 0xba, 0xcb, 0xa4, 0x40 \
  1171. }
  1172. /*
  1173. * Synthetic Video GUID
  1174. * {DA0A7802-E377-4aac-8E77-0558EB1073F8}
  1175. */
  1176. #define HV_SYNTHVID_GUID \
  1177. .guid = { \
  1178. 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a, \
  1179. 0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 \
  1180. }
  1181. /*
  1182. * Synthetic FC GUID
  1183. * {2f9bcc4a-0069-4af3-b76b-6fd0be528cda}
  1184. */
  1185. #define HV_SYNTHFC_GUID \
  1186. .guid = { \
  1187. 0x4A, 0xCC, 0x9B, 0x2F, 0x69, 0x00, 0xF3, 0x4A, \
  1188. 0xB7, 0x6B, 0x6F, 0xD0, 0xBE, 0x52, 0x8C, 0xDA \
  1189. }
  1190. /*
  1191. * Common header for Hyper-V ICs
  1192. */
  1193. #define ICMSGTYPE_NEGOTIATE 0
  1194. #define ICMSGTYPE_HEARTBEAT 1
  1195. #define ICMSGTYPE_KVPEXCHANGE 2
  1196. #define ICMSGTYPE_SHUTDOWN 3
  1197. #define ICMSGTYPE_TIMESYNC 4
  1198. #define ICMSGTYPE_VSS 5
  1199. #define ICMSGHDRFLAG_TRANSACTION 1
  1200. #define ICMSGHDRFLAG_REQUEST 2
  1201. #define ICMSGHDRFLAG_RESPONSE 4
  1202. /*
  1203. * While we want to handle util services as regular devices,
  1204. * there is only one instance of each of these services; so
  1205. * we statically allocate the service specific state.
  1206. */
  1207. struct hv_util_service {
  1208. u8 *recv_buffer;
  1209. void (*util_cb)(void *);
  1210. int (*util_init)(struct hv_util_service *);
  1211. void (*util_deinit)(void);
  1212. };
  1213. struct vmbuspipe_hdr {
  1214. u32 flags;
  1215. u32 msgsize;
  1216. } __packed;
  1217. struct ic_version {
  1218. u16 major;
  1219. u16 minor;
  1220. } __packed;
  1221. struct icmsg_hdr {
  1222. struct ic_version icverframe;
  1223. u16 icmsgtype;
  1224. struct ic_version icvermsg;
  1225. u16 icmsgsize;
  1226. u32 status;
  1227. u8 ictransaction_id;
  1228. u8 icflags;
  1229. u8 reserved[2];
  1230. } __packed;
  1231. struct icmsg_negotiate {
  1232. u16 icframe_vercnt;
  1233. u16 icmsg_vercnt;
  1234. u32 reserved;
  1235. struct ic_version icversion_data[1]; /* any size array */
  1236. } __packed;
  1237. struct shutdown_msg_data {
  1238. u32 reason_code;
  1239. u32 timeout_seconds;
  1240. u32 flags;
  1241. u8 display_message[2048];
  1242. } __packed;
  1243. struct heartbeat_msg_data {
  1244. u64 seq_num;
  1245. u32 reserved[8];
  1246. } __packed;
  1247. /* Time Sync IC defs */
  1248. #define ICTIMESYNCFLAG_PROBE 0
  1249. #define ICTIMESYNCFLAG_SYNC 1
  1250. #define ICTIMESYNCFLAG_SAMPLE 2
  1251. #ifdef __x86_64__
  1252. #define WLTIMEDELTA 116444736000000000L /* in 100ns unit */
  1253. #else
  1254. #define WLTIMEDELTA 116444736000000000LL
  1255. #endif
  1256. struct ictimesync_data {
  1257. u64 parenttime;
  1258. u64 childtime;
  1259. u64 roundtriptime;
  1260. u8 flags;
  1261. } __packed;
  1262. struct hyperv_service_callback {
  1263. u8 msg_type;
  1264. char *log_msg;
  1265. uuid_le data;
  1266. struct vmbus_channel *channel;
  1267. void (*callback) (void *context);
  1268. };
  1269. #define MAX_SRV_VER 0x7ffffff
  1270. extern void vmbus_prep_negotiate_resp(struct icmsg_hdr *,
  1271. struct icmsg_negotiate *, u8 *, int,
  1272. int);
  1273. int hv_kvp_init(struct hv_util_service *);
  1274. void hv_kvp_deinit(void);
  1275. void hv_kvp_onchannelcallback(void *);
  1276. int hv_vss_init(struct hv_util_service *);
  1277. void hv_vss_deinit(void);
  1278. void hv_vss_onchannelcallback(void *);
  1279. /*
  1280. * Negotiated version with the Host.
  1281. */
  1282. extern __u32 vmbus_proto_version;
  1283. #endif /* __KERNEL__ */
  1284. #endif /* _HYPERV_H */