]>
Commit | Line | Data |
---|---|---|
3e7ee490 | 1 | /* |
3e7ee490 HJ |
2 | * Copyright (c) 2009, Microsoft Corporation. |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms and conditions of the GNU General Public License, | |
6 | * version 2, as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
11 | * more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public License along with | |
14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
15 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
16 | * | |
17 | * Authors: | |
18 | * Haiyang Zhang <[email protected]> | |
19 | * Hank Janssen <[email protected]> | |
3e7ee490 | 20 | */ |
a0086dc5 GKH |
21 | #include <linux/kernel.h> |
22 | #include <linux/mm.h> | |
5a0e3ad6 | 23 | #include <linux/slab.h> |
53af545b | 24 | #include <linux/list.h> |
4983b39a | 25 | #include "osd.h" |
645954c5 | 26 | #include "logging.h" |
3e7ee490 HJ |
27 | #include "VmbusPrivate.h" |
28 | ||
1d7e907f | 29 | struct vmbus_channel_message_table_entry { |
c8212f04 GKH |
30 | enum vmbus_channel_message_type messageType; |
31 | void (*messageHandler)(struct vmbus_channel_message_header *msg); | |
1d7e907f | 32 | }; |
3e7ee490 | 33 | |
3e7ee490 | 34 | #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4 |
bd60c33e GKH |
35 | static const struct hv_guid |
36 | gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = { | |
454f18a9 | 37 | /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ |
caf26a31 GKH |
38 | /* Storage - SCSI */ |
39 | { | |
40 | .data = { | |
41 | 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, | |
42 | 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f | |
43 | } | |
44 | }, | |
45 | ||
454f18a9 | 46 | /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ |
caf26a31 GKH |
47 | /* Network */ |
48 | { | |
49 | .data = { | |
50 | 0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, | |
51 | 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E | |
52 | } | |
53 | }, | |
54 | ||
454f18a9 | 55 | /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */ |
caf26a31 GKH |
56 | /* Input */ |
57 | { | |
58 | .data = { | |
59 | 0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, | |
60 | 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A | |
61 | } | |
62 | }, | |
3e7ee490 | 63 | |
caf26a31 GKH |
64 | /* {32412632-86cb-44a2-9b5c-50d1417354f5} */ |
65 | /* IDE */ | |
66 | { | |
67 | .data = { | |
68 | 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, | |
69 | 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 | |
70 | } | |
71 | }, | |
3e7ee490 HJ |
72 | }; |
73 | ||
bd60c33e GKH |
74 | /** |
75 | * AllocVmbusChannel - Allocate and initialize a vmbus channel object | |
76 | */ | |
aded7165 | 77 | struct vmbus_channel *AllocVmbusChannel(void) |
3e7ee490 | 78 | { |
aded7165 | 79 | struct vmbus_channel *channel; |
3e7ee490 | 80 | |
aded7165 | 81 | channel = kzalloc(sizeof(*channel), GFP_ATOMIC); |
3e7ee490 | 82 | if (!channel) |
3e7ee490 | 83 | return NULL; |
3e7ee490 | 84 | |
54411c42 | 85 | spin_lock_init(&channel->inbound_lock); |
3e7ee490 | 86 | |
c8a429a4 GKH |
87 | init_timer(&channel->poll_timer); |
88 | channel->poll_timer.data = (unsigned long)channel; | |
89 | channel->poll_timer.function = VmbusChannelOnTimer; | |
3e7ee490 | 90 | |
de65a384 | 91 | channel->ControlWQ = create_workqueue("hv_vmbus_ctl"); |
bd60c33e | 92 | if (!channel->ControlWQ) { |
8c69f52a | 93 | kfree(channel); |
3e7ee490 HJ |
94 | return NULL; |
95 | } | |
96 | ||
97 | return channel; | |
98 | } | |
99 | ||
bd60c33e GKH |
100 | /** |
101 | * ReleaseVmbusChannel - Release the vmbus channel object itself | |
102 | */ | |
103 | static inline void ReleaseVmbusChannel(void *context) | |
3e7ee490 | 104 | { |
bd60c33e | 105 | struct vmbus_channel *channel = context; |
3e7ee490 HJ |
106 | |
107 | DPRINT_ENTER(VMBUS); | |
108 | ||
109 | DPRINT_DBG(VMBUS, "releasing channel (%p)", channel); | |
de65a384 | 110 | destroy_workqueue(channel->ControlWQ); |
3e7ee490 HJ |
111 | DPRINT_DBG(VMBUS, "channel released (%p)", channel); |
112 | ||
8c69f52a | 113 | kfree(channel); |
3e7ee490 HJ |
114 | |
115 | DPRINT_EXIT(VMBUS); | |
116 | } | |
117 | ||
bd60c33e GKH |
118 | /** |
119 | * FreeVmbusChannel - Release the resources used by the vmbus channel object | |
120 | */ | |
aded7165 | 121 | void FreeVmbusChannel(struct vmbus_channel *Channel) |
3e7ee490 | 122 | { |
5996b3dd | 123 | del_timer_sync(&Channel->poll_timer); |
3e7ee490 | 124 | |
bd60c33e GKH |
125 | /* |
126 | * We have to release the channel's workqueue/thread in the vmbus's | |
127 | * workqueue/thread context | |
128 | * ie we can't destroy ourselves. | |
129 | */ | |
de65a384 | 130 | osd_schedule_callback(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, |
bd60c33e | 131 | Channel); |
3e7ee490 HJ |
132 | } |
133 | ||
bd60c33e GKH |
134 | /** |
135 | * VmbusChannelProcessOffer - Process the offer by creating a channel/device associated with this offer | |
136 | */ | |
137 | static void VmbusChannelProcessOffer(void *context) | |
3e7ee490 | 138 | { |
aded7165 GKH |
139 | struct vmbus_channel *newChannel = context; |
140 | struct vmbus_channel *channel; | |
0e727613 | 141 | bool fNew = true; |
bd60c33e | 142 | int ret; |
0f5e44ca | 143 | unsigned long flags; |
3e7ee490 HJ |
144 | |
145 | DPRINT_ENTER(VMBUS); | |
146 | ||
454f18a9 | 147 | /* Make sure this is a new offer */ |
0f5e44ca | 148 | spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); |
3e7ee490 | 149 | |
53af545b | 150 | list_for_each_entry(channel, &gVmbusConnection.ChannelList, ListEntry) { |
bd60c33e GKH |
151 | if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, |
152 | &newChannel->OfferMsg.Offer.InterfaceType, | |
153 | sizeof(struct hv_guid)) && | |
154 | !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, | |
155 | &newChannel->OfferMsg.Offer.InterfaceInstance, | |
156 | sizeof(struct hv_guid))) { | |
0e727613 | 157 | fNew = false; |
3e7ee490 HJ |
158 | break; |
159 | } | |
160 | } | |
161 | ||
162 | if (fNew) | |
53af545b BP |
163 | list_add_tail(&newChannel->ListEntry, |
164 | &gVmbusConnection.ChannelList); | |
bd60c33e | 165 | |
0f5e44ca | 166 | spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); |
3e7ee490 | 167 | |
bd60c33e GKH |
168 | if (!fNew) { |
169 | DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", | |
170 | newChannel->OfferMsg.ChildRelId); | |
3e7ee490 HJ |
171 | FreeVmbusChannel(newChannel); |
172 | DPRINT_EXIT(VMBUS); | |
173 | return; | |
174 | } | |
175 | ||
bd60c33e GKH |
176 | /* |
177 | * Start the process of binding this offer to the driver | |
178 | * We need to set the DeviceObject field before calling | |
179 | * VmbusChildDeviceAdd() | |
180 | */ | |
3e7ee490 | 181 | newChannel->DeviceObject = VmbusChildDeviceCreate( |
daaa8cc3 GKH |
182 | &newChannel->OfferMsg.Offer.InterfaceType, |
183 | &newChannel->OfferMsg.Offer.InterfaceInstance, | |
3e7ee490 HJ |
184 | newChannel); |
185 | ||
bd60c33e GKH |
186 | DPRINT_DBG(VMBUS, "child device object allocated - %p", |
187 | newChannel->DeviceObject); | |
3e7ee490 | 188 | |
454f18a9 BP |
189 | /* |
190 | * Add the new device to the bus. This will kick off device-driver | |
191 | * binding which eventually invokes the device driver's AddDevice() | |
192 | * method. | |
193 | */ | |
3e7ee490 | 194 | ret = VmbusChildDeviceAdd(newChannel->DeviceObject); |
bd60c33e GKH |
195 | if (ret != 0) { |
196 | DPRINT_ERR(VMBUS, | |
197 | "unable to add child device object (relid %d)", | |
198 | newChannel->OfferMsg.ChildRelId); | |
3e7ee490 | 199 | |
0f5e44ca | 200 | spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); |
53af545b | 201 | list_del(&newChannel->ListEntry); |
0f5e44ca | 202 | spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); |
3e7ee490 HJ |
203 | |
204 | FreeVmbusChannel(newChannel); | |
bd60c33e | 205 | } else { |
454f18a9 BP |
206 | /* |
207 | * This state is used to indicate a successful open | |
208 | * so that when we do close the channel normally, we | |
209 | * can cleanup properly | |
210 | */ | |
3e7ee490 HJ |
211 | newChannel->State = CHANNEL_OPEN_STATE; |
212 | } | |
213 | DPRINT_EXIT(VMBUS); | |
214 | } | |
215 | ||
bd60c33e GKH |
216 | /** |
217 | * VmbusChannelProcessRescindOffer - Rescind the offer by initiating a device removal | |
218 | */ | |
219 | static void VmbusChannelProcessRescindOffer(void *context) | |
3e7ee490 | 220 | { |
aded7165 | 221 | struct vmbus_channel *channel = context; |
3e7ee490 HJ |
222 | |
223 | DPRINT_ENTER(VMBUS); | |
3e7ee490 | 224 | VmbusChildDeviceRemove(channel->DeviceObject); |
3e7ee490 HJ |
225 | DPRINT_EXIT(VMBUS); |
226 | } | |
227 | ||
bd60c33e GKH |
228 | /** |
229 | * VmbusChannelOnOffer - Handler for channel offers from vmbus in parent partition. | |
230 | * | |
231 | * We ignore all offers except network and storage offers. For each network and | |
232 | * storage offers, we create a channel object and queue a work item to the | |
233 | * channel object to process the offer synchronously | |
234 | */ | |
82250213 | 235 | static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr) |
3e7ee490 | 236 | { |
bd60c33e | 237 | struct vmbus_channel_offer_channel *offer; |
aded7165 | 238 | struct vmbus_channel *newChannel; |
caf26a31 GKH |
239 | struct hv_guid *guidType; |
240 | struct hv_guid *guidInstance; | |
3e7ee490 | 241 | int i; |
bd60c33e | 242 | int fSupported = 0; |
3e7ee490 HJ |
243 | |
244 | DPRINT_ENTER(VMBUS); | |
245 | ||
bd60c33e GKH |
246 | offer = (struct vmbus_channel_offer_channel *)hdr; |
247 | for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { | |
248 | if (memcmp(&offer->Offer.InterfaceType, | |
249 | &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0) { | |
3e7ee490 HJ |
250 | fSupported = 1; |
251 | break; | |
252 | } | |
253 | } | |
254 | ||
bd60c33e GKH |
255 | if (!fSupported) { |
256 | DPRINT_DBG(VMBUS, "Ignoring channel offer notification for " | |
257 | "child relid %d", offer->ChildRelId); | |
3e7ee490 | 258 | DPRINT_EXIT(VMBUS); |
3e7ee490 HJ |
259 | return; |
260 | } | |
261 | ||
262 | guidType = &offer->Offer.InterfaceType; | |
263 | guidInstance = &offer->Offer.InterfaceInstance; | |
264 | ||
bd60c33e GKH |
265 | DPRINT_INFO(VMBUS, "Channel offer notification - " |
266 | "child relid %d monitor id %d allocated %d, " | |
267 | "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-" | |
268 | "%02x%02x%02x%02x%02x%02x%02x%02x} " | |
269 | "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-" | |
270 | "%02x%02x%02x%02x%02x%02x%02x%02x}", | |
271 | offer->ChildRelId, offer->MonitorId, | |
272 | offer->MonitorAllocated, | |
273 | guidType->data[3], guidType->data[2], | |
274 | guidType->data[1], guidType->data[0], | |
275 | guidType->data[5], guidType->data[4], | |
276 | guidType->data[7], guidType->data[6], | |
277 | guidType->data[8], guidType->data[9], | |
278 | guidType->data[10], guidType->data[11], | |
279 | guidType->data[12], guidType->data[13], | |
280 | guidType->data[14], guidType->data[15], | |
281 | guidInstance->data[3], guidInstance->data[2], | |
282 | guidInstance->data[1], guidInstance->data[0], | |
283 | guidInstance->data[5], guidInstance->data[4], | |
284 | guidInstance->data[7], guidInstance->data[6], | |
285 | guidInstance->data[8], guidInstance->data[9], | |
286 | guidInstance->data[10], guidInstance->data[11], | |
287 | guidInstance->data[12], guidInstance->data[13], | |
288 | guidInstance->data[14], guidInstance->data[15]); | |
3e7ee490 | 289 | |
454f18a9 | 290 | /* Allocate the channel object and save this offer. */ |
3e7ee490 | 291 | newChannel = AllocVmbusChannel(); |
bd60c33e | 292 | if (!newChannel) { |
3e7ee490 HJ |
293 | DPRINT_ERR(VMBUS, "unable to allocate channel object"); |
294 | return; | |
295 | } | |
296 | ||
297 | DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel); | |
298 | ||
bd60c33e GKH |
299 | memcpy(&newChannel->OfferMsg, offer, |
300 | sizeof(struct vmbus_channel_offer_channel)); | |
5654e932 GKH |
301 | newChannel->MonitorGroup = (u8)offer->MonitorId / 32; |
302 | newChannel->MonitorBit = (u8)offer->MonitorId % 32; | |
3e7ee490 | 303 | |
454f18a9 | 304 | /* TODO: Make sure the offer comes from our parent partition */ |
de65a384 BP |
305 | osd_schedule_callback(newChannel->ControlWQ, VmbusChannelProcessOffer, |
306 | newChannel); | |
3e7ee490 HJ |
307 | |
308 | DPRINT_EXIT(VMBUS); | |
309 | } | |
310 | ||
bd60c33e GKH |
311 | /** |
312 | * VmbusChannelOnOfferRescind - Rescind offer handler. | |
313 | * | |
314 | * We queue a work item to process this offer synchronously | |
315 | */ | |
82250213 | 316 | static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr) |
3e7ee490 | 317 | { |
bd60c33e | 318 | struct vmbus_channel_rescind_offer *rescind; |
aded7165 | 319 | struct vmbus_channel *channel; |
3e7ee490 HJ |
320 | |
321 | DPRINT_ENTER(VMBUS); | |
322 | ||
bd60c33e | 323 | rescind = (struct vmbus_channel_rescind_offer *)hdr; |
3e7ee490 | 324 | channel = GetChannelFromRelId(rescind->ChildRelId); |
bd60c33e GKH |
325 | if (channel == NULL) { |
326 | DPRINT_DBG(VMBUS, "channel not found for relId %d", | |
327 | rescind->ChildRelId); | |
3e7ee490 HJ |
328 | return; |
329 | } | |
330 | ||
de65a384 BP |
331 | osd_schedule_callback(channel->ControlWQ, |
332 | VmbusChannelProcessRescindOffer, | |
333 | channel); | |
3e7ee490 HJ |
334 | |
335 | DPRINT_EXIT(VMBUS); | |
336 | } | |
337 | ||
bd60c33e GKH |
338 | /** |
339 | * VmbusChannelOnOffersDelivered - This is invoked when all offers have been delivered. | |
340 | * | |
341 | * Nothing to do here. | |
342 | */ | |
343 | static void VmbusChannelOnOffersDelivered( | |
344 | struct vmbus_channel_message_header *hdr) | |
3e7ee490 HJ |
345 | { |
346 | DPRINT_ENTER(VMBUS); | |
347 | DPRINT_EXIT(VMBUS); | |
348 | } | |
349 | ||
bd60c33e GKH |
350 | /** |
351 | * VmbusChannelOnOpenResult - Open result handler. | |
352 | * | |
353 | * This is invoked when we received a response to our channel open request. | |
354 | * Find the matching request, copy the response and signal the requesting | |
355 | * thread. | |
356 | */ | |
82250213 | 357 | static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr) |
3e7ee490 | 358 | { |
bd60c33e | 359 | struct vmbus_channel_open_result *result; |
53af545b | 360 | struct list_head *curr; |
aded7165 | 361 | struct vmbus_channel_msginfo *msgInfo; |
82250213 GKH |
362 | struct vmbus_channel_message_header *requestHeader; |
363 | struct vmbus_channel_open_channel *openMsg; | |
dd0813b6 | 364 | unsigned long flags; |
3e7ee490 HJ |
365 | |
366 | DPRINT_ENTER(VMBUS); | |
367 | ||
bd60c33e | 368 | result = (struct vmbus_channel_open_result *)hdr; |
3e7ee490 HJ |
369 | DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status); |
370 | ||
bd60c33e GKH |
371 | /* |
372 | * Find the open msg, copy the result and signal/unblock the wait event | |
373 | */ | |
dd0813b6 | 374 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 | 375 | |
53af545b BP |
376 | list_for_each(curr, &gVmbusConnection.ChannelMsgList) { |
377 | /* FIXME: this should probably use list_entry() instead */ | |
aded7165 | 378 | msgInfo = (struct vmbus_channel_msginfo *)curr; |
82250213 | 379 | requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; |
3e7ee490 | 380 | |
bd60c33e | 381 | if (requestHeader->MessageType == ChannelMessageOpenChannel) { |
82250213 | 382 | openMsg = (struct vmbus_channel_open_channel *)msgInfo->Msg; |
3e7ee490 | 383 | if (openMsg->ChildRelId == result->ChildRelId && |
bd60c33e GKH |
384 | openMsg->OpenId == result->OpenId) { |
385 | memcpy(&msgInfo->Response.OpenResult, | |
386 | result, | |
387 | sizeof(struct vmbus_channel_open_result)); | |
bfc30aae | 388 | osd_WaitEventSet(msgInfo->WaitEvent); |
3e7ee490 HJ |
389 | break; |
390 | } | |
391 | } | |
392 | } | |
dd0813b6 | 393 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 HJ |
394 | |
395 | DPRINT_EXIT(VMBUS); | |
396 | } | |
397 | ||
bd60c33e GKH |
398 | /** |
399 | * VmbusChannelOnGpadlCreated - GPADL created handler. | |
400 | * | |
401 | * This is invoked when we received a response to our gpadl create request. | |
402 | * Find the matching request, copy the response and signal the requesting | |
403 | * thread. | |
404 | */ | |
82250213 | 405 | static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr) |
3e7ee490 | 406 | { |
bd60c33e | 407 | struct vmbus_channel_gpadl_created *gpadlCreated; |
53af545b | 408 | struct list_head *curr; |
aded7165 | 409 | struct vmbus_channel_msginfo *msgInfo; |
82250213 GKH |
410 | struct vmbus_channel_message_header *requestHeader; |
411 | struct vmbus_channel_gpadl_header *gpadlHeader; | |
dd0813b6 | 412 | unsigned long flags; |
3e7ee490 HJ |
413 | |
414 | DPRINT_ENTER(VMBUS); | |
415 | ||
bd60c33e GKH |
416 | gpadlCreated = (struct vmbus_channel_gpadl_created *)hdr; |
417 | DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", | |
418 | gpadlCreated->CreationStatus); | |
3e7ee490 | 419 | |
bd60c33e GKH |
420 | /* |
421 | * Find the establish msg, copy the result and signal/unblock the wait | |
422 | * event | |
423 | */ | |
dd0813b6 | 424 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 | 425 | |
53af545b BP |
426 | list_for_each(curr, &gVmbusConnection.ChannelMsgList) { |
427 | /* FIXME: this should probably use list_entry() instead */ | |
aded7165 | 428 | msgInfo = (struct vmbus_channel_msginfo *)curr; |
82250213 | 429 | requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; |
3e7ee490 | 430 | |
bd60c33e | 431 | if (requestHeader->MessageType == ChannelMessageGpadlHeader) { |
82250213 | 432 | gpadlHeader = (struct vmbus_channel_gpadl_header *)requestHeader; |
3e7ee490 | 433 | |
bd60c33e GKH |
434 | if ((gpadlCreated->ChildRelId == |
435 | gpadlHeader->ChildRelId) && | |
436 | (gpadlCreated->Gpadl == gpadlHeader->Gpadl)) { | |
437 | memcpy(&msgInfo->Response.GpadlCreated, | |
438 | gpadlCreated, | |
439 | sizeof(struct vmbus_channel_gpadl_created)); | |
bfc30aae | 440 | osd_WaitEventSet(msgInfo->WaitEvent); |
3e7ee490 HJ |
441 | break; |
442 | } | |
443 | } | |
444 | } | |
dd0813b6 | 445 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 HJ |
446 | |
447 | DPRINT_EXIT(VMBUS); | |
448 | } | |
449 | ||
bd60c33e GKH |
450 | /** |
451 | * VmbusChannelOnGpadlTorndown - GPADL torndown handler. | |
452 | * | |
453 | * This is invoked when we received a response to our gpadl teardown request. | |
454 | * Find the matching request, copy the response and signal the requesting | |
455 | * thread. | |
456 | */ | |
457 | static void VmbusChannelOnGpadlTorndown( | |
458 | struct vmbus_channel_message_header *hdr) | |
3e7ee490 | 459 | { |
bd60c33e | 460 | struct vmbus_channel_gpadl_torndown *gpadlTorndown; |
53af545b | 461 | struct list_head *curr; |
aded7165 | 462 | struct vmbus_channel_msginfo *msgInfo; |
82250213 GKH |
463 | struct vmbus_channel_message_header *requestHeader; |
464 | struct vmbus_channel_gpadl_teardown *gpadlTeardown; | |
dd0813b6 | 465 | unsigned long flags; |
3e7ee490 HJ |
466 | |
467 | DPRINT_ENTER(VMBUS); | |
468 | ||
bd60c33e GKH |
469 | gpadlTorndown = (struct vmbus_channel_gpadl_torndown *)hdr; |
470 | ||
471 | /* | |
472 | * Find the open msg, copy the result and signal/unblock the wait event | |
473 | */ | |
dd0813b6 | 474 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 | 475 | |
53af545b BP |
476 | list_for_each(curr, &gVmbusConnection.ChannelMsgList) { |
477 | /* FIXME: this should probably use list_entry() instead */ | |
aded7165 | 478 | msgInfo = (struct vmbus_channel_msginfo *)curr; |
82250213 | 479 | requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; |
3e7ee490 | 480 | |
bd60c33e | 481 | if (requestHeader->MessageType == ChannelMessageGpadlTeardown) { |
82250213 | 482 | gpadlTeardown = (struct vmbus_channel_gpadl_teardown *)requestHeader; |
3e7ee490 | 483 | |
bd60c33e GKH |
484 | if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl) { |
485 | memcpy(&msgInfo->Response.GpadlTorndown, | |
486 | gpadlTorndown, | |
487 | sizeof(struct vmbus_channel_gpadl_torndown)); | |
bfc30aae | 488 | osd_WaitEventSet(msgInfo->WaitEvent); |
3e7ee490 HJ |
489 | break; |
490 | } | |
491 | } | |
492 | } | |
dd0813b6 | 493 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 HJ |
494 | |
495 | DPRINT_EXIT(VMBUS); | |
496 | } | |
497 | ||
bd60c33e GKH |
498 | /** |
499 | * VmbusChannelOnVersionResponse - Version response handler | |
500 | * | |
501 | * This is invoked when we received a response to our initiate contact request. | |
502 | * Find the matching request, copy the response and signal the requesting | |
503 | * thread. | |
504 | */ | |
505 | static void VmbusChannelOnVersionResponse( | |
506 | struct vmbus_channel_message_header *hdr) | |
3e7ee490 | 507 | { |
53af545b | 508 | struct list_head *curr; |
aded7165 | 509 | struct vmbus_channel_msginfo *msgInfo; |
82250213 GKH |
510 | struct vmbus_channel_message_header *requestHeader; |
511 | struct vmbus_channel_initiate_contact *initiate; | |
bd60c33e | 512 | struct vmbus_channel_version_response *versionResponse; |
dd0813b6 | 513 | unsigned long flags; |
3e7ee490 HJ |
514 | |
515 | DPRINT_ENTER(VMBUS); | |
516 | ||
bd60c33e | 517 | versionResponse = (struct vmbus_channel_version_response *)hdr; |
dd0813b6 | 518 | spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 | 519 | |
53af545b BP |
520 | list_for_each(curr, &gVmbusConnection.ChannelMsgList) { |
521 | /* FIXME: this should probably use list_entry() instead */ | |
aded7165 | 522 | msgInfo = (struct vmbus_channel_msginfo *)curr; |
82250213 | 523 | requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg; |
3e7ee490 | 524 | |
bd60c33e GKH |
525 | if (requestHeader->MessageType == |
526 | ChannelMessageInitiateContact) { | |
82250213 | 527 | initiate = (struct vmbus_channel_initiate_contact *)requestHeader; |
bd60c33e GKH |
528 | memcpy(&msgInfo->Response.VersionResponse, |
529 | versionResponse, | |
530 | sizeof(struct vmbus_channel_version_response)); | |
bfc30aae | 531 | osd_WaitEventSet(msgInfo->WaitEvent); |
3e7ee490 HJ |
532 | } |
533 | } | |
dd0813b6 | 534 | spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); |
3e7ee490 HJ |
535 | |
536 | DPRINT_EXIT(VMBUS); | |
537 | } | |
538 | ||
c8212f04 GKH |
539 | /* Channel message dispatch table */ |
540 | static struct vmbus_channel_message_table_entry | |
541 | gChannelMessageTable[ChannelMessageCount] = { | |
542 | {ChannelMessageInvalid, NULL}, | |
543 | {ChannelMessageOfferChannel, VmbusChannelOnOffer}, | |
544 | {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind}, | |
545 | {ChannelMessageRequestOffers, NULL}, | |
546 | {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered}, | |
547 | {ChannelMessageOpenChannel, NULL}, | |
548 | {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult}, | |
549 | {ChannelMessageCloseChannel, NULL}, | |
550 | {ChannelMessageGpadlHeader, NULL}, | |
551 | {ChannelMessageGpadlBody, NULL}, | |
552 | {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated}, | |
553 | {ChannelMessageGpadlTeardown, NULL}, | |
554 | {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown}, | |
555 | {ChannelMessageRelIdReleased, NULL}, | |
556 | {ChannelMessageInitiateContact, NULL}, | |
557 | {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse}, | |
558 | {ChannelMessageUnload, NULL}, | |
559 | }; | |
560 | ||
bd60c33e GKH |
561 | /** |
562 | * VmbusOnChannelMessage - Handler for channel protocol messages. | |
563 | * | |
564 | * This is invoked in the vmbus worker thread context. | |
565 | */ | |
b239549c | 566 | void VmbusOnChannelMessage(void *Context) |
3e7ee490 | 567 | { |
eacb1b4d | 568 | struct hv_message *msg = Context; |
82250213 | 569 | struct vmbus_channel_message_header *hdr; |
3e7ee490 HJ |
570 | int size; |
571 | ||
572 | DPRINT_ENTER(VMBUS); | |
573 | ||
82250213 | 574 | hdr = (struct vmbus_channel_message_header *)msg->u.Payload; |
bd60c33e | 575 | size = msg->Header.PayloadSize; |
3e7ee490 HJ |
576 | |
577 | DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size); | |
578 | ||
bd60c33e GKH |
579 | if (hdr->MessageType >= ChannelMessageCount) { |
580 | DPRINT_ERR(VMBUS, | |
581 | "Received invalid channel message type %d size %d", | |
582 | hdr->MessageType, size); | |
04f50c4d GKH |
583 | print_hex_dump_bytes("", DUMP_PREFIX_NONE, |
584 | (unsigned char *)msg->u.Payload, size); | |
8c69f52a | 585 | kfree(msg); |
3e7ee490 HJ |
586 | return; |
587 | } | |
588 | ||
589 | if (gChannelMessageTable[hdr->MessageType].messageHandler) | |
3e7ee490 | 590 | gChannelMessageTable[hdr->MessageType].messageHandler(hdr); |
3e7ee490 | 591 | else |
bd60c33e GKH |
592 | DPRINT_ERR(VMBUS, "Unhandled channel message type %d", |
593 | hdr->MessageType); | |
3e7ee490 | 594 | |
454f18a9 | 595 | /* Free the msg that was allocated in VmbusOnMsgDPC() */ |
8c69f52a | 596 | kfree(msg); |
3e7ee490 HJ |
597 | DPRINT_EXIT(VMBUS); |
598 | } | |
599 | ||
bd60c33e GKH |
600 | /** |
601 | * VmbusChannelRequestOffers - Send a request to get all our pending offers. | |
602 | */ | |
b239549c | 603 | int VmbusChannelRequestOffers(void) |
3e7ee490 | 604 | { |
82250213 | 605 | struct vmbus_channel_message_header *msg; |
aded7165 | 606 | struct vmbus_channel_msginfo *msgInfo; |
bd60c33e | 607 | int ret; |
3e7ee490 HJ |
608 | |
609 | DPRINT_ENTER(VMBUS); | |
610 | ||
bd60c33e GKH |
611 | msgInfo = kmalloc(sizeof(*msgInfo) + |
612 | sizeof(struct vmbus_channel_message_header), | |
613 | GFP_KERNEL); | |
3e7ee490 HJ |
614 | ASSERT(msgInfo != NULL); |
615 | ||
bfc30aae | 616 | msgInfo->WaitEvent = osd_WaitEventCreate(); |
82250213 | 617 | msg = (struct vmbus_channel_message_header *)msgInfo->Msg; |
3e7ee490 HJ |
618 | |
619 | msg->MessageType = ChannelMessageRequestOffers; | |
620 | ||
621 | /*SpinlockAcquire(gVmbusConnection.channelMsgLock); | |
bd60c33e GKH |
622 | INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, |
623 | &msgInfo->msgListEntry); | |
3e7ee490 HJ |
624 | SpinlockRelease(gVmbusConnection.channelMsgLock);*/ |
625 | ||
bd60c33e GKH |
626 | ret = VmbusPostMessage(msg, |
627 | sizeof(struct vmbus_channel_message_header)); | |
628 | if (ret != 0) { | |
3e7ee490 HJ |
629 | DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret); |
630 | ||
631 | /*SpinlockAcquire(gVmbusConnection.channelMsgLock); | |
632 | REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); | |
633 | SpinlockRelease(gVmbusConnection.channelMsgLock);*/ | |
634 | ||
635 | goto Cleanup; | |
636 | } | |
bfc30aae | 637 | /* osd_WaitEventWait(msgInfo->waitEvent); */ |
3e7ee490 HJ |
638 | |
639 | /*SpinlockAcquire(gVmbusConnection.channelMsgLock); | |
640 | REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); | |
641 | SpinlockRelease(gVmbusConnection.channelMsgLock);*/ | |
642 | ||
643 | ||
644 | Cleanup: | |
bd60c33e | 645 | if (msgInfo) { |
420beac4 | 646 | kfree(msgInfo->WaitEvent); |
8c69f52a | 647 | kfree(msgInfo); |
3e7ee490 HJ |
648 | } |
649 | ||
650 | DPRINT_EXIT(VMBUS); | |
3e7ee490 HJ |
651 | return ret; |
652 | } | |
653 | ||
bd60c33e GKH |
654 | /** |
655 | * VmbusChannelReleaseUnattachedChannels - Release channels that are unattached/unconnected ie (no drivers associated) | |
656 | */ | |
b239549c | 657 | void VmbusChannelReleaseUnattachedChannels(void) |
3e7ee490 | 658 | { |
53af545b | 659 | struct vmbus_channel *channel, *pos; |
aded7165 | 660 | struct vmbus_channel *start = NULL; |
0f5e44ca | 661 | unsigned long flags; |
3e7ee490 | 662 | |
0f5e44ca | 663 | spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); |
3e7ee490 | 664 | |
53af545b BP |
665 | list_for_each_entry_safe(channel, pos, &gVmbusConnection.ChannelList, |
666 | ListEntry) { | |
3e7ee490 HJ |
667 | if (channel == start) |
668 | break; | |
669 | ||
bd60c33e | 670 | if (!channel->DeviceObject->Driver) { |
53af545b | 671 | list_del(&channel->ListEntry); |
bd60c33e GKH |
672 | DPRINT_INFO(VMBUS, |
673 | "Releasing unattached device object %p", | |
674 | channel->DeviceObject); | |
3e7ee490 HJ |
675 | |
676 | VmbusChildDeviceRemove(channel->DeviceObject); | |
677 | FreeVmbusChannel(channel); | |
bd60c33e | 678 | } else { |
3e7ee490 | 679 | if (!start) |
3e7ee490 | 680 | start = channel; |
3e7ee490 HJ |
681 | } |
682 | } | |
683 | ||
0f5e44ca | 684 | spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); |
3e7ee490 HJ |
685 | } |
686 | ||
454f18a9 | 687 | /* eof */ |