PageRenderTime 4798ms CodeModel.GetById 26ms RepoModel.GetById 3ms app.codeStats 0ms

/drivers/staging/hv/channel_mgmt.h

https://github.com/devpress-xx/linux-2.6
C Header | 320 lines | 192 code | 54 blank | 74 comment | 0 complexity | c12bf09aec393dccb40749f6dd5b3a28 MD5 | raw file
  1. /*
  2. *
  3. * Copyright (c) 2009, 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. *
  22. */
  23. #ifndef _CHANNEL_MGMT_H_
  24. #define _CHANNEL_MGMT_H_
  25. #include <linux/list.h>
  26. #include <linux/timer.h>
  27. #include "ring_buffer.h"
  28. #include "vmbus_channel_interface.h"
  29. #include "vmbus_packet_format.h"
  30. /* Version 1 messages */
  31. enum vmbus_channel_message_type {
  32. ChannelMessageInvalid = 0,
  33. ChannelMessageOfferChannel = 1,
  34. ChannelMessageRescindChannelOffer = 2,
  35. ChannelMessageRequestOffers = 3,
  36. ChannelMessageAllOffersDelivered = 4,
  37. ChannelMessageOpenChannel = 5,
  38. ChannelMessageOpenChannelResult = 6,
  39. ChannelMessageCloseChannel = 7,
  40. ChannelMessageGpadlHeader = 8,
  41. ChannelMessageGpadlBody = 9,
  42. ChannelMessageGpadlCreated = 10,
  43. ChannelMessageGpadlTeardown = 11,
  44. ChannelMessageGpadlTorndown = 12,
  45. ChannelMessageRelIdReleased = 13,
  46. ChannelMessageInitiateContact = 14,
  47. ChannelMessageVersionResponse = 15,
  48. ChannelMessageUnload = 16,
  49. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  50. ChannelMessageViewRangeAdd = 17,
  51. ChannelMessageViewRangeRemove = 18,
  52. #endif
  53. ChannelMessageCount
  54. };
  55. struct vmbus_channel_message_header {
  56. enum vmbus_channel_message_type MessageType;
  57. u32 Padding;
  58. } __attribute__((packed));
  59. /* Query VMBus Version parameters */
  60. struct vmbus_channel_query_vmbus_version {
  61. struct vmbus_channel_message_header Header;
  62. u32 Version;
  63. } __attribute__((packed));
  64. /* VMBus Version Supported parameters */
  65. struct vmbus_channel_version_supported {
  66. struct vmbus_channel_message_header Header;
  67. bool VersionSupported;
  68. } __attribute__((packed));
  69. /* Offer Channel parameters */
  70. struct vmbus_channel_offer_channel {
  71. struct vmbus_channel_message_header Header;
  72. struct vmbus_channel_offer Offer;
  73. u32 ChildRelId;
  74. u8 MonitorId;
  75. bool MonitorAllocated;
  76. } __attribute__((packed));
  77. /* Rescind Offer parameters */
  78. struct vmbus_channel_rescind_offer {
  79. struct vmbus_channel_message_header Header;
  80. u32 ChildRelId;
  81. } __attribute__((packed));
  82. /*
  83. * Request Offer -- no parameters, SynIC message contains the partition ID
  84. * Set Snoop -- no parameters, SynIC message contains the partition ID
  85. * Clear Snoop -- no parameters, SynIC message contains the partition ID
  86. * All Offers Delivered -- no parameters, SynIC message contains the partition
  87. * ID
  88. * Flush Client -- no parameters, SynIC message contains the partition ID
  89. */
  90. /* Open Channel parameters */
  91. struct vmbus_channel_open_channel {
  92. struct vmbus_channel_message_header Header;
  93. /* Identifies the specific VMBus channel that is being opened. */
  94. u32 ChildRelId;
  95. /* ID making a particular open request at a channel offer unique. */
  96. u32 OpenId;
  97. /* GPADL for the channel's ring buffer. */
  98. u32 RingBufferGpadlHandle;
  99. /* GPADL for the channel's server context save area. */
  100. u32 ServerContextAreaGpadlHandle;
  101. /*
  102. * The upstream ring buffer begins at offset zero in the memory
  103. * described by RingBufferGpadlHandle. The downstream ring buffer
  104. * follows it at this offset (in pages).
  105. */
  106. u32 DownstreamRingBufferPageOffset;
  107. /* User-specific data to be passed along to the server endpoint. */
  108. unsigned char UserData[MAX_USER_DEFINED_BYTES];
  109. } __attribute__((packed));
  110. /* Open Channel Result parameters */
  111. struct vmbus_channel_open_result {
  112. struct vmbus_channel_message_header Header;
  113. u32 ChildRelId;
  114. u32 OpenId;
  115. u32 Status;
  116. } __attribute__((packed));
  117. /* Close channel parameters; */
  118. struct vmbus_channel_close_channel {
  119. struct vmbus_channel_message_header Header;
  120. u32 ChildRelId;
  121. } __attribute__((packed));
  122. /* Channel Message GPADL */
  123. #define GPADL_TYPE_RING_BUFFER 1
  124. #define GPADL_TYPE_SERVER_SAVE_AREA 2
  125. #define GPADL_TYPE_TRANSACTION 8
  126. /*
  127. * The number of PFNs in a GPADL message is defined by the number of
  128. * pages that would be spanned by ByteCount and ByteOffset. If the
  129. * implied number of PFNs won't fit in this packet, there will be a
  130. * follow-up packet that contains more.
  131. */
  132. struct vmbus_channel_gpadl_header {
  133. struct vmbus_channel_message_header Header;
  134. u32 ChildRelId;
  135. u32 Gpadl;
  136. u16 RangeBufLen;
  137. u16 RangeCount;
  138. struct gpa_range Range[0];
  139. } __attribute__((packed));
  140. /* This is the followup packet that contains more PFNs. */
  141. struct vmbus_channel_gpadl_body {
  142. struct vmbus_channel_message_header Header;
  143. u32 MessageNumber;
  144. u32 Gpadl;
  145. u64 Pfn[0];
  146. } __attribute__((packed));
  147. struct vmbus_channel_gpadl_created {
  148. struct vmbus_channel_message_header Header;
  149. u32 ChildRelId;
  150. u32 Gpadl;
  151. u32 CreationStatus;
  152. } __attribute__((packed));
  153. struct vmbus_channel_gpadl_teardown {
  154. struct vmbus_channel_message_header Header;
  155. u32 ChildRelId;
  156. u32 Gpadl;
  157. } __attribute__((packed));
  158. struct vmbus_channel_gpadl_torndown {
  159. struct vmbus_channel_message_header Header;
  160. u32 Gpadl;
  161. } __attribute__((packed));
  162. #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
  163. struct vmbus_channel_view_range_add {
  164. struct vmbus_channel_message_header Header;
  165. PHYSICAL_ADDRESS ViewRangeBase;
  166. u64 ViewRangeLength;
  167. u32 ChildRelId;
  168. } __attribute__((packed));
  169. struct vmbus_channel_view_range_remove {
  170. struct vmbus_channel_message_header Header;
  171. PHYSICAL_ADDRESS ViewRangeBase;
  172. u32 ChildRelId;
  173. } __attribute__((packed));
  174. #endif
  175. struct vmbus_channel_relid_released {
  176. struct vmbus_channel_message_header Header;
  177. u32 ChildRelId;
  178. } __attribute__((packed));
  179. struct vmbus_channel_initiate_contact {
  180. struct vmbus_channel_message_header Header;
  181. u32 VMBusVersionRequested;
  182. u32 Padding2;
  183. u64 InterruptPage;
  184. u64 MonitorPage1;
  185. u64 MonitorPage2;
  186. } __attribute__((packed));
  187. struct vmbus_channel_version_response {
  188. struct vmbus_channel_message_header Header;
  189. bool VersionSupported;
  190. } __attribute__((packed));
  191. enum vmbus_channel_state {
  192. CHANNEL_OFFER_STATE,
  193. CHANNEL_OPENING_STATE,
  194. CHANNEL_OPEN_STATE,
  195. };
  196. struct vmbus_channel {
  197. struct list_head ListEntry;
  198. struct hv_device *DeviceObject;
  199. struct timer_list poll_timer; /* SA-111 workaround */
  200. enum vmbus_channel_state State;
  201. struct vmbus_channel_offer_channel OfferMsg;
  202. /*
  203. * These are based on the OfferMsg.MonitorId.
  204. * Save it here for easy access.
  205. */
  206. u8 MonitorGroup;
  207. u8 MonitorBit;
  208. u32 RingBufferGpadlHandle;
  209. /* Allocated memory for ring buffer */
  210. void *RingBufferPages;
  211. u32 RingBufferPageCount;
  212. struct hv_ring_buffer_info Outbound; /* send to parent */
  213. struct hv_ring_buffer_info Inbound; /* receive from parent */
  214. spinlock_t inbound_lock;
  215. struct workqueue_struct *ControlWQ;
  216. /* Channel callback are invoked in this workqueue context */
  217. /* HANDLE dataWorkQueue; */
  218. void (*OnChannelCallback)(void *context);
  219. void *ChannelCallbackContext;
  220. };
  221. struct vmbus_channel_debug_info {
  222. u32 RelId;
  223. enum vmbus_channel_state State;
  224. struct hv_guid InterfaceType;
  225. struct hv_guid InterfaceInstance;
  226. u32 MonitorId;
  227. u32 ServerMonitorPending;
  228. u32 ServerMonitorLatency;
  229. u32 ServerMonitorConnectionId;
  230. u32 ClientMonitorPending;
  231. u32 ClientMonitorLatency;
  232. u32 ClientMonitorConnectionId;
  233. struct hv_ring_buffer_debug_info Inbound;
  234. struct hv_ring_buffer_debug_info Outbound;
  235. };
  236. /*
  237. * Represents each channel msg on the vmbus connection This is a
  238. * variable-size data structure depending on the msg type itself
  239. */
  240. struct vmbus_channel_msginfo {
  241. /* Bookkeeping stuff */
  242. struct list_head MsgListEntry;
  243. /* So far, this is only used to handle gpadl body message */
  244. struct list_head SubMsgList;
  245. /* Synchronize the request/response if needed */
  246. struct osd_waitevent *WaitEvent;
  247. union {
  248. struct vmbus_channel_version_supported VersionSupported;
  249. struct vmbus_channel_open_result OpenResult;
  250. struct vmbus_channel_gpadl_torndown GpadlTorndown;
  251. struct vmbus_channel_gpadl_created GpadlCreated;
  252. struct vmbus_channel_version_response VersionResponse;
  253. } Response;
  254. u32 MessageSize;
  255. /*
  256. * The channel message that goes out on the "wire".
  257. * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
  258. */
  259. unsigned char Msg[0];
  260. };
  261. struct vmbus_channel *AllocVmbusChannel(void);
  262. void FreeVmbusChannel(struct vmbus_channel *Channel);
  263. void VmbusOnChannelMessage(void *Context);
  264. int VmbusChannelRequestOffers(void);
  265. void VmbusChannelReleaseUnattachedChannels(void);
  266. #endif /* _CHANNEL_MGMT_H_ */