Staging: hv: Use native wait primitives
[deliverable/linux.git] / drivers / staging / hv / channel_mgmt.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 <linux/timer.h>
30 #include "ring_buffer.h"
31 #include "vmbus_channel_interface.h"
32 #include "vmbus_packet_format.h"
33
34 /* Version 1 messages */
35 enum vmbus_channel_message_type {
36 CHANNELMSG_INVALID = 0,
37 CHANNELMSG_OFFERCHANNEL = 1,
38 CHANNELMSG_RESCIND_CHANNELOFFER = 2,
39 CHANNELMSG_REQUESTOFFERS = 3,
40 CHANNELMSG_ALLOFFERS_DELIVERED = 4,
41 CHANNELMSG_OPENCHANNEL = 5,
42 CHANNELMSG_OPENCHANNEL_RESULT = 6,
43 CHANNELMSG_CLOSECHANNEL = 7,
44 CHANNELMSG_GPADL_HEADER = 8,
45 CHANNELMSG_GPADL_BODY = 9,
46 CHANNELMSG_GPADL_CREATED = 10,
47 CHANNELMSG_GPADL_TEARDOWN = 11,
48 CHANNELMSG_GPADL_TORNDOWN = 12,
49 CHANNELMSG_RELID_RELEASED = 13,
50 CHANNELMSG_INITIATE_CONTACT = 14,
51 CHANNELMSG_VERSION_RESPONSE = 15,
52 CHANNELMSG_UNLOAD = 16,
53 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
54 CHANNELMSG_VIEWRANGE_ADD = 17,
55 CHANNELMSG_VIEWRANGE_REMOVE = 18,
56 #endif
57 CHANNELMSG_COUNT
58 };
59
60 struct vmbus_channel_message_header {
61 enum vmbus_channel_message_type msgtype;
62 u32 padding;
63 } __packed;
64
65 /* Query VMBus Version parameters */
66 struct vmbus_channel_query_vmbus_version {
67 struct vmbus_channel_message_header header;
68 u32 version;
69 } __packed;
70
71 /* VMBus Version Supported parameters */
72 struct vmbus_channel_version_supported {
73 struct vmbus_channel_message_header header;
74 bool version_supported;
75 } __packed;
76
77 /* Offer Channel parameters */
78 struct vmbus_channel_offer_channel {
79 struct vmbus_channel_message_header header;
80 struct vmbus_channel_offer offer;
81 u32 child_relid;
82 u8 monitorid;
83 bool monitor_allocated;
84 } __packed;
85
86 /* Rescind Offer parameters */
87 struct vmbus_channel_rescind_offer {
88 struct vmbus_channel_message_header header;
89 u32 child_relid;
90 } __packed;
91
92 /*
93 * Request Offer -- no parameters, SynIC message contains the partition ID
94 * Set Snoop -- no parameters, SynIC message contains the partition ID
95 * Clear Snoop -- no parameters, SynIC message contains the partition ID
96 * All Offers Delivered -- no parameters, SynIC message contains the partition
97 * ID
98 * Flush Client -- no parameters, SynIC message contains the partition ID
99 */
100
101 /* Open Channel parameters */
102 struct vmbus_channel_open_channel {
103 struct vmbus_channel_message_header header;
104
105 /* Identifies the specific VMBus channel that is being opened. */
106 u32 child_relid;
107
108 /* ID making a particular open request at a channel offer unique. */
109 u32 openid;
110
111 /* GPADL for the channel's ring buffer. */
112 u32 ringbuffer_gpadlhandle;
113
114 /* GPADL for the channel's server context save area. */
115 u32 server_contextarea_gpadlhandle;
116
117 /*
118 * The upstream ring buffer begins at offset zero in the memory
119 * described by RingBufferGpadlHandle. The downstream ring buffer
120 * follows it at this offset (in pages).
121 */
122 u32 downstream_ringbuffer_pageoffset;
123
124 /* User-specific data to be passed along to the server endpoint. */
125 unsigned char userdata[MAX_USER_DEFINED_BYTES];
126 } __packed;
127
128 /* Open Channel Result parameters */
129 struct vmbus_channel_open_result {
130 struct vmbus_channel_message_header header;
131 u32 child_relid;
132 u32 openid;
133 u32 status;
134 } __packed;
135
136 /* Close channel parameters; */
137 struct vmbus_channel_close_channel {
138 struct vmbus_channel_message_header header;
139 u32 child_relid;
140 } __packed;
141
142 /* Channel Message GPADL */
143 #define GPADL_TYPE_RING_BUFFER 1
144 #define GPADL_TYPE_SERVER_SAVE_AREA 2
145 #define GPADL_TYPE_TRANSACTION 8
146
147 /*
148 * The number of PFNs in a GPADL message is defined by the number of
149 * pages that would be spanned by ByteCount and ByteOffset. If the
150 * implied number of PFNs won't fit in this packet, there will be a
151 * follow-up packet that contains more.
152 */
153 struct vmbus_channel_gpadl_header {
154 struct vmbus_channel_message_header header;
155 u32 child_relid;
156 u32 gpadl;
157 u16 range_buflen;
158 u16 rangecount;
159 struct gpa_range range[0];
160 } __packed;
161
162 /* This is the followup packet that contains more PFNs. */
163 struct vmbus_channel_gpadl_body {
164 struct vmbus_channel_message_header header;
165 u32 msgnumber;
166 u32 gpadl;
167 u64 pfn[0];
168 } __packed;
169
170 struct vmbus_channel_gpadl_created {
171 struct vmbus_channel_message_header header;
172 u32 child_relid;
173 u32 gpadl;
174 u32 creation_status;
175 } __packed;
176
177 struct vmbus_channel_gpadl_teardown {
178 struct vmbus_channel_message_header header;
179 u32 child_relid;
180 u32 gpadl;
181 } __packed;
182
183 struct vmbus_channel_gpadl_torndown {
184 struct vmbus_channel_message_header header;
185 u32 gpadl;
186 } __packed;
187
188 #ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD
189 struct vmbus_channel_view_range_add {
190 struct vmbus_channel_message_header header;
191 PHYSICAL_ADDRESS viewrange_base;
192 u64 viewrange_length;
193 u32 child_relid;
194 } __packed;
195
196 struct vmbus_channel_view_range_remove {
197 struct vmbus_channel_message_header header;
198 PHYSICAL_ADDRESS viewrange_base;
199 u32 child_relid;
200 } __packed;
201 #endif
202
203 struct vmbus_channel_relid_released {
204 struct vmbus_channel_message_header header;
205 u32 child_relid;
206 } __packed;
207
208 struct vmbus_channel_initiate_contact {
209 struct vmbus_channel_message_header header;
210 u32 vmbus_version_requested;
211 u32 padding2;
212 u64 interrupt_page;
213 u64 monitor_page1;
214 u64 monitor_page2;
215 } __packed;
216
217 struct vmbus_channel_version_response {
218 struct vmbus_channel_message_header header;
219 bool version_supported;
220 } __packed;
221
222 enum vmbus_channel_state {
223 CHANNEL_OFFER_STATE,
224 CHANNEL_OPENING_STATE,
225 CHANNEL_OPEN_STATE,
226 };
227
228 struct vmbus_channel {
229 struct list_head listentry;
230
231 struct hv_device *device_obj;
232
233 struct timer_list poll_timer; /* SA-111 workaround */
234 struct work_struct work;
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 monitor_grp;
244 u8 monitor_bit;
245
246 u32 ringbuffer_gpadlhandle;
247
248 /* Allocated memory for ring buffer */
249 void *ringbuffer_pages;
250 u32 ringbuffer_pagecount;
251 struct hv_ring_buffer_info outbound; /* send to parent */
252 struct hv_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 void (*onchannel_callback)(void *context);
260 void *channel_callback_context;
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 interface_instance;
268 u32 monitorid;
269 u32 servermonitor_pending;
270 u32 servermonitor_latency;
271 u32 servermonitor_connectionid;
272 u32 clientmonitor_pending;
273 u32 clientmonitor_latency;
274 u32 clientmonitor_connectionid;
275
276 struct hv_ring_buffer_debug_info inbound;
277 struct hv_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 struct list_head msglistentry;
287
288 /* So far, this is only used to handle gpadl body message */
289 struct list_head submsglist;
290
291 /* Synchronize the request/response if needed */
292 int wait_condition;
293 wait_queue_head_t waitevent;
294 union {
295 struct vmbus_channel_version_supported version_supported;
296 struct vmbus_channel_open_result open_result;
297 struct vmbus_channel_gpadl_torndown gpadl_torndown;
298 struct vmbus_channel_gpadl_created gpadl_created;
299 struct vmbus_channel_version_response version_response;
300 } response;
301
302 u32 msgsize;
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 void free_channel(struct vmbus_channel *channel);
312
313 void vmbus_onmessage(void *context);
314
315 int vmbus_request_offers(void);
316
317 void vmbus_release_unattached_channels(void);
318
319 #endif /* _CHANNEL_MGMT_H_ */
This page took 0.037654 seconds and 5 git commands to generate.