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