3 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
25 #ifndef _CHANNEL_MGMT_H_
26 #define _CHANNEL_MGMT_H_
28 #include <linux/list.h>
29 #include "RingBuffer.h"
30 #include "VmbusChannelInterface.h"
31 #include "VmbusPacketFormat.h"
33 /* Version 1 messages */
34 enum vmbus_channel_message_type
{
35 ChannelMessageInvalid
= 0,
36 ChannelMessageOfferChannel
= 1,
37 ChannelMessageRescindChannelOffer
= 2,
38 ChannelMessageRequestOffers
= 3,
39 ChannelMessageAllOffersDelivered
= 4,
40 ChannelMessageOpenChannel
= 5,
41 ChannelMessageOpenChannelResult
= 6,
42 ChannelMessageCloseChannel
= 7,
43 ChannelMessageGpadlHeader
= 8,
44 ChannelMessageGpadlBody
= 9,
45 ChannelMessageGpadlCreated
= 10,
46 ChannelMessageGpadlTeardown
= 11,
47 ChannelMessageGpadlTorndown
= 12,
48 ChannelMessageRelIdReleased
= 13,
49 ChannelMessageInitiateContact
= 14,
50 ChannelMessageVersionResponse
= 15,
51 ChannelMessageUnload
= 16,
52 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
53 ChannelMessageViewRangeAdd
= 17,
54 ChannelMessageViewRangeRemove
= 18,
57 } __attribute__((packed
));
59 struct vmbus_channel_message_header
{
60 enum vmbus_channel_message_type MessageType
;
62 } __attribute__((packed
));
64 /* Query VMBus Version parameters */
65 struct vmbus_channel_query_vmbus_version
{
66 struct vmbus_channel_message_header Header
;
68 } __attribute__((packed
));
70 /* VMBus Version Supported parameters */
71 struct vmbus_channel_version_supported
{
72 struct vmbus_channel_message_header Header
;
73 bool VersionSupported
;
74 } __attribute__((packed
));
76 /* Offer Channel parameters */
77 struct vmbus_channel_offer_channel
{
78 struct vmbus_channel_message_header Header
;
79 struct vmbus_channel_offer Offer
;
82 bool MonitorAllocated
;
83 } __attribute__((packed
));
85 /* Rescind Offer parameters */
86 struct vmbus_channel_rescind_offer
{
87 struct vmbus_channel_message_header Header
;
89 } __attribute__((packed
));
92 * Request Offer -- no parameters, SynIC message contains the partition ID
93 * Set Snoop -- no parameters, SynIC message contains the partition ID
94 * Clear Snoop -- no parameters, SynIC message contains the partition ID
95 * All Offers Delivered -- no parameters, SynIC message contains the partition
97 * Flush Client -- no parameters, SynIC message contains the partition ID
100 /* Open Channel parameters */
101 struct vmbus_channel_open_channel
{
102 struct vmbus_channel_message_header Header
;
104 /* Identifies the specific VMBus channel that is being opened. */
107 /* ID making a particular open request at a channel offer unique. */
110 /* GPADL for the channel's ring buffer. */
111 u32 RingBufferGpadlHandle
;
113 /* GPADL for the channel's server context save area. */
114 u32 ServerContextAreaGpadlHandle
;
117 * The upstream ring buffer begins at offset zero in the memory
118 * described by RingBufferGpadlHandle. The downstream ring buffer
119 * follows it at this offset (in pages).
121 u32 DownstreamRingBufferPageOffset
;
123 /* User-specific data to be passed along to the server endpoint. */
124 unsigned char UserData
[MAX_USER_DEFINED_BYTES
];
125 } __attribute__((packed
));
127 /* Open Channel Result parameters */
128 struct vmbus_channel_open_result
{
129 struct vmbus_channel_message_header Header
;
133 } __attribute__((packed
));
135 /* Close channel parameters; */
136 struct vmbus_channel_close_channel
{
137 struct vmbus_channel_message_header Header
;
139 } __attribute__((packed
));
141 /* Channel Message GPADL */
142 #define GPADL_TYPE_RING_BUFFER 1
143 #define GPADL_TYPE_SERVER_SAVE_AREA 2
144 #define GPADL_TYPE_TRANSACTION 8
147 * The number of PFNs in a GPADL message is defined by the number of
148 * pages that would be spanned by ByteCount and ByteOffset. If the
149 * implied number of PFNs won't fit in this packet, there will be a
150 * follow-up packet that contains more.
152 struct vmbus_channel_gpadl_header
{
153 struct vmbus_channel_message_header Header
;
158 struct gpa_range Range
[0];
159 } __attribute__((packed
));
161 /* This is the followup packet that contains more PFNs. */
162 struct vmbus_channel_gpadl_body
{
163 struct vmbus_channel_message_header Header
;
167 } __attribute__((packed
));
169 struct vmbus_channel_gpadl_created
{
170 struct vmbus_channel_message_header Header
;
174 } __attribute__((packed
));
176 struct vmbus_channel_gpadl_teardown
{
177 struct vmbus_channel_message_header Header
;
180 } __attribute__((packed
));
182 struct vmbus_channel_gpadl_torndown
{
183 struct vmbus_channel_message_header Header
;
185 } __attribute__((packed
));
187 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
188 struct vmbus_channel_view_range_add
{
189 struct vmbus_channel_message_header Header
;
190 PHYSICAL_ADDRESS ViewRangeBase
;
193 } __attribute__((packed
));
195 struct vmbus_channel_view_range_remove
{
196 struct vmbus_channel_message_header Header
;
197 PHYSICAL_ADDRESS ViewRangeBase
;
199 } __attribute__((packed
));
202 struct vmbus_channel_relid_released
{
203 struct vmbus_channel_message_header Header
;
205 } __attribute__((packed
));
207 struct vmbus_channel_initiate_contact
{
208 struct vmbus_channel_message_header Header
;
209 u32 VMBusVersionRequested
;
214 } __attribute__((packed
));
216 struct vmbus_channel_version_response
{
217 struct vmbus_channel_message_header Header
;
218 bool VersionSupported
;
219 } __attribute__((packed
));
221 enum vmbus_channel_state
{
223 CHANNEL_OPENING_STATE
,
227 struct vmbus_channel
{
228 struct list_head ListEntry
;
230 struct hv_device
*DeviceObject
;
232 struct timer_list poll_timer
; /* SA-111 workaround */
234 enum vmbus_channel_state State
;
236 struct vmbus_channel_offer_channel OfferMsg
;
238 * These are based on the OfferMsg.MonitorId.
239 * Save it here for easy access.
244 u32 RingBufferGpadlHandle
;
246 /* Allocated memory for ring buffer */
247 void *RingBufferPages
;
248 u32 RingBufferPageCount
;
249 RING_BUFFER_INFO Outbound
; /* send to parent */
250 RING_BUFFER_INFO Inbound
; /* receive from parent */
251 spinlock_t inbound_lock
;
252 struct workqueue_struct
*ControlWQ
;
254 /* Channel callback are invoked in this workqueue context */
255 /* HANDLE dataWorkQueue; */
257 void (*OnChannelCallback
)(void *context
);
258 void *ChannelCallbackContext
;
261 struct vmbus_channel_debug_info
{
263 enum vmbus_channel_state State
;
264 struct hv_guid InterfaceType
;
265 struct hv_guid InterfaceInstance
;
267 u32 ServerMonitorPending
;
268 u32 ServerMonitorLatency
;
269 u32 ServerMonitorConnectionId
;
270 u32 ClientMonitorPending
;
271 u32 ClientMonitorLatency
;
272 u32 ClientMonitorConnectionId
;
274 RING_BUFFER_DEBUG_INFO Inbound
;
275 RING_BUFFER_DEBUG_INFO Outbound
;
279 * Represents each channel msg on the vmbus connection This is a
280 * variable-size data structure depending on the msg type itself
282 struct vmbus_channel_msginfo
{
283 /* Bookkeeping stuff */
284 struct list_head MsgListEntry
;
286 /* So far, this is only used to handle gpadl body message */
287 struct list_head SubMsgList
;
289 /* Synchronize the request/response if needed */
290 struct osd_waitevent
*WaitEvent
;
293 struct vmbus_channel_version_supported VersionSupported
;
294 struct vmbus_channel_open_result OpenResult
;
295 struct vmbus_channel_gpadl_torndown GpadlTorndown
;
296 struct vmbus_channel_gpadl_created GpadlCreated
;
297 struct vmbus_channel_version_response VersionResponse
;
302 * The channel message that goes out on the "wire".
303 * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
305 unsigned char Msg
[0];
309 struct vmbus_channel
*AllocVmbusChannel(void);
311 void FreeVmbusChannel(struct vmbus_channel
*Channel
);
313 void VmbusOnChannelMessage(void *Context
);
315 int VmbusChannelRequestOffers(void);
317 void VmbusChannelReleaseUnattachedChannels(void);
319 #endif /* _CHANNEL_MGMT_H_ */