]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/ChannelMgmt.h
Staging: hv: move VmbusPacketFormat.h
[~andy/linux] / drivers / staging / hv / ChannelMgmt.h
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
24
25 #ifndef _CHANNEL_MGMT_H_
26 #define _CHANNEL_MGMT_H_
27
28 #include "List.h"
29 #include "RingBuffer.h"
30 #include "VmbusChannelInterface.h"
31 #include "VmbusPacketFormat.h"
32
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,
55 #endif
56         ChannelMessageCount
57 } __attribute__((packed));
58
59 struct vmbus_channel_message_header {
60         enum vmbus_channel_message_type MessageType;
61         u32 Padding;
62 } __attribute__((packed));
63
64 /* Query VMBus Version parameters */
65 struct vmbus_channel_query_vmbus_version {
66         struct vmbus_channel_message_header Header;
67         u32 Version;
68 } __attribute__((packed));
69
70 /* VMBus Version Supported parameters */
71 struct vmbus_channel_version_supported {
72         struct vmbus_channel_message_header Header;
73         bool VersionSupported;
74 } __attribute__((packed));
75
76 /* Offer Channel parameters */
77 struct vmbus_channel_offer_channel {
78         struct vmbus_channel_message_header Header;
79         struct vmbus_channel_offer Offer;
80         u32 ChildRelId;
81         u8 MonitorId;
82         bool MonitorAllocated;
83 } __attribute__((packed));
84
85 /* Rescind Offer parameters */
86 struct vmbus_channel_rescind_offer {
87         struct vmbus_channel_message_header Header;
88         u32 ChildRelId;
89 } __attribute__((packed));
90
91 /*
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
96  *                         ID
97  * Flush Client -- no parameters, SynIC message contains the partition ID
98  */
99
100 /* Open Channel parameters */
101 struct vmbus_channel_open_channel {
102         struct vmbus_channel_message_header Header;
103
104         /* Identifies the specific VMBus channel that is being opened. */
105         u32 ChildRelId;
106
107         /* ID making a particular open request at a channel offer unique. */
108         u32 OpenId;
109
110         /* GPADL for the channel's ring buffer. */
111         u32 RingBufferGpadlHandle;
112
113         /* GPADL for the channel's server context save area. */
114         u32 ServerContextAreaGpadlHandle;
115
116         /*
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).
120         */
121         u32 DownstreamRingBufferPageOffset;
122
123         /* User-specific data to be passed along to the server endpoint. */
124         unsigned char UserData[MAX_USER_DEFINED_BYTES];
125 } __attribute__((packed));
126
127 /* Open Channel Result parameters */
128 struct vmbus_channel_open_result {
129         struct vmbus_channel_message_header Header;
130         u32 ChildRelId;
131         u32 OpenId;
132         u32 Status;
133 } __attribute__((packed));
134
135 /* Close channel parameters; */
136 struct vmbus_channel_close_channel {
137         struct vmbus_channel_message_header Header;
138         u32 ChildRelId;
139 } __attribute__((packed));
140
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
145
146 /*
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.
151  */
152 struct vmbus_channel_gpadl_header {
153         struct vmbus_channel_message_header Header;
154         u32 ChildRelId;
155         u32 Gpadl;
156         u16 RangeBufLen;
157         u16 RangeCount;
158         struct gpa_range Range[0];
159 } __attribute__((packed));
160
161 /* This is the followup packet that contains more PFNs. */
162 struct vmbus_channel_gpadl_body {
163         struct vmbus_channel_message_header Header;
164         u32 MessageNumber;
165         u32 Gpadl;
166         u64 Pfn[0];
167 } __attribute__((packed));
168
169 struct vmbus_channel_gpadl_created {
170         struct vmbus_channel_message_header Header;
171         u32 ChildRelId;
172         u32 Gpadl;
173         u32 CreationStatus;
174 } __attribute__((packed));
175
176 struct vmbus_channel_gpadl_teardown {
177         struct vmbus_channel_message_header Header;
178         u32 ChildRelId;
179         u32 Gpadl;
180 } __attribute__((packed));
181
182 struct vmbus_channel_gpadl_torndown {
183         struct vmbus_channel_message_header Header;
184         u32 Gpadl;
185 } __attribute__((packed));
186
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;
191         u64 ViewRangeLength;
192         u32 ChildRelId;
193 } __attribute__((packed));
194
195 struct vmbus_channel_view_range_remove {
196         struct vmbus_channel_message_header Header;
197         PHYSICAL_ADDRESS ViewRangeBase;
198         u32 ChildRelId;
199 } __attribute__((packed));
200 #endif
201
202 struct vmbus_channel_relid_released {
203         struct vmbus_channel_message_header Header;
204         u32 ChildRelId;
205 } __attribute__((packed));
206
207 struct vmbus_channel_initiate_contact {
208         struct vmbus_channel_message_header Header;
209         u32 VMBusVersionRequested;
210         u32 Padding2;
211         u64 InterruptPage;
212         u64 MonitorPage1;
213         u64 MonitorPage2;
214 } __attribute__((packed));
215
216 struct vmbus_channel_version_response {
217         struct vmbus_channel_message_header Header;
218         bool VersionSupported;
219 } __attribute__((packed));
220
221 typedef void (*PFN_CHANNEL_CALLBACK)(void *context);
222
223 enum vmbus_channel_state {
224         CHANNEL_OFFER_STATE,
225         CHANNEL_OPENING_STATE,
226         CHANNEL_OPEN_STATE,
227 };
228
229 struct vmbus_channel {
230         LIST_ENTRY ListEntry;
231
232         struct hv_device *DeviceObject;
233
234         struct timer_list poll_timer; /* SA-111 workaround */
235
236         enum vmbus_channel_state State;
237
238         struct vmbus_channel_offer_channel OfferMsg;
239         /*
240          * These are based on the OfferMsg.MonitorId.
241          * Save it here for easy access.
242          */
243         u8 MonitorGroup;
244         u8 MonitorBit;
245
246         u32 RingBufferGpadlHandle;
247
248         /* Allocated memory for ring buffer */
249         void *RingBufferPages;
250         u32 RingBufferPageCount;
251         RING_BUFFER_INFO Outbound;      /* send to parent */
252         RING_BUFFER_INFO Inbound;       /* receive from parent */
253         spinlock_t inbound_lock;
254         struct workqueue_struct *ControlWQ;
255
256         /* Channel callback are invoked in this workqueue context */
257         /* HANDLE dataWorkQueue; */
258
259         PFN_CHANNEL_CALLBACK OnChannelCallback;
260         void *ChannelCallbackContext;
261 };
262
263 struct vmbus_channel_debug_info {
264         u32 RelId;
265         enum vmbus_channel_state State;
266         struct hv_guid InterfaceType;
267         struct hv_guid InterfaceInstance;
268         u32 MonitorId;
269         u32 ServerMonitorPending;
270         u32 ServerMonitorLatency;
271         u32 ServerMonitorConnectionId;
272         u32 ClientMonitorPending;
273         u32 ClientMonitorLatency;
274         u32 ClientMonitorConnectionId;
275
276         RING_BUFFER_DEBUG_INFO Inbound;
277         RING_BUFFER_DEBUG_INFO Outbound;
278 };
279
280 /*
281  * Represents each channel msg on the vmbus connection This is a
282  * variable-size data structure depending on the msg type itself
283  */
284 struct vmbus_channel_msginfo {
285         /* Bookkeeping stuff */
286         LIST_ENTRY MsgListEntry;
287
288         /* So far, this is only used to handle gpadl body message */
289         LIST_ENTRY SubMsgList;
290
291         /* Synchronize the request/response if needed */
292         struct osd_waitevent *WaitEvent;
293
294         union {
295                 struct vmbus_channel_version_supported VersionSupported;
296                 struct vmbus_channel_open_result OpenResult;
297                 struct vmbus_channel_gpadl_torndown GpadlTorndown;
298                 struct vmbus_channel_gpadl_created GpadlCreated;
299                 struct vmbus_channel_version_response VersionResponse;
300         } Response;
301
302         u32 MessageSize;
303         /*
304          * The channel message that goes out on the "wire".
305          * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
306          */
307         unsigned char Msg[0];
308 };
309
310
311 struct vmbus_channel *AllocVmbusChannel(void);
312
313 void FreeVmbusChannel(struct vmbus_channel *Channel);
314
315 void VmbusOnChannelMessage(void *Context);
316
317 int VmbusChannelRequestOffers(void);
318
319 void VmbusChannelReleaseUnattachedChannels(void);
320
321 #endif /* _CHANNEL_MGMT_H_ */