Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[sfrench/cifs-2.6.git] / 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 <linux/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 enum vmbus_channel_state {
222         CHANNEL_OFFER_STATE,
223         CHANNEL_OPENING_STATE,
224         CHANNEL_OPEN_STATE,
225 };
226
227 struct vmbus_channel {
228         struct list_head ListEntry;
229
230         struct hv_device *DeviceObject;
231
232         struct timer_list poll_timer; /* SA-111 workaround */
233
234         enum vmbus_channel_state State;
235
236         struct vmbus_channel_offer_channel OfferMsg;
237         /*
238          * These are based on the OfferMsg.MonitorId.
239          * Save it here for easy access.
240          */
241         u8 MonitorGroup;
242         u8 MonitorBit;
243
244         u32 RingBufferGpadlHandle;
245
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;
253
254         /* Channel callback are invoked in this workqueue context */
255         /* HANDLE dataWorkQueue; */
256
257         void (*OnChannelCallback)(void *context);
258         void *ChannelCallbackContext;
259 };
260
261 struct vmbus_channel_debug_info {
262         u32 RelId;
263         enum vmbus_channel_state State;
264         struct hv_guid InterfaceType;
265         struct hv_guid InterfaceInstance;
266         u32 MonitorId;
267         u32 ServerMonitorPending;
268         u32 ServerMonitorLatency;
269         u32 ServerMonitorConnectionId;
270         u32 ClientMonitorPending;
271         u32 ClientMonitorLatency;
272         u32 ClientMonitorConnectionId;
273
274         RING_BUFFER_DEBUG_INFO Inbound;
275         RING_BUFFER_DEBUG_INFO Outbound;
276 };
277
278 /*
279  * Represents each channel msg on the vmbus connection This is a
280  * variable-size data structure depending on the msg type itself
281  */
282 struct vmbus_channel_msginfo {
283         /* Bookkeeping stuff */
284         struct list_head MsgListEntry;
285
286         /* So far, this is only used to handle gpadl body message */
287         struct list_head SubMsgList;
288
289         /* Synchronize the request/response if needed */
290         struct osd_waitevent *WaitEvent;
291
292         union {
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;
298         } Response;
299
300         u32 MessageSize;
301         /*
302          * The channel message that goes out on the "wire".
303          * It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header
304          */
305         unsigned char Msg[0];
306 };
307
308
309 struct vmbus_channel *AllocVmbusChannel(void);
310
311 void FreeVmbusChannel(struct vmbus_channel *Channel);
312
313 void VmbusOnChannelMessage(void *Context);
314
315 int VmbusChannelRequestOffers(void);
316
317 void VmbusChannelReleaseUnattachedChannels(void);
318
319 #endif /* _CHANNEL_MGMT_H_ */