Staging: hv: move osd.h
[linux-2.6/mini2440.git] / drivers / staging / hv / ChannelMgmt.c
blob86ce05b4b14cb91aed0d8ed5d7d75c8be8460564
1 /*
3 * Copyright (c) 2009, Microsoft Corporation.
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.
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.
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.
18 * Authors:
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
25 #include <linux/kernel.h>
26 #include <linux/mm.h>
27 #include "osd.h"
28 #include "include/logging.h"
30 #include "VmbusPrivate.h"
32 /* Data types */
34 typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(VMBUS_CHANNEL_MESSAGE_HEADER* msg);
36 typedef struct _VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY {
37 VMBUS_CHANNEL_MESSAGE_TYPE messageType;
38 PFN_CHANNEL_MESSAGE_HANDLER messageHandler;
39 } VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY;
41 /* Internal routines */
43 static void
44 VmbusChannelOnOffer(
45 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
47 static void
48 VmbusChannelOnOpenResult(
49 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
52 static void
53 VmbusChannelOnOfferRescind(
54 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
57 static void
58 VmbusChannelOnGpadlCreated(
59 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
62 static void
63 VmbusChannelOnGpadlTorndown(
64 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
67 static void
68 VmbusChannelOnOffersDelivered(
69 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
72 static void
73 VmbusChannelOnVersionResponse(
74 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
77 static void
78 VmbusChannelProcessOffer(
79 void * context
82 static void
83 VmbusChannelProcessRescindOffer(
84 void * context
88 /* Globals */
90 #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4
92 static const GUID gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED]= {
93 /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
94 {.Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}},/* Storage - SCSI */
95 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
96 {.Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}}, /* Network */
97 /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
98 {.Data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}}, /* Input */
99 /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
100 {.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}}, /* IDE */
104 /* Channel message dispatch table */
105 static VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= {
106 {ChannelMessageInvalid, NULL},
107 {ChannelMessageOfferChannel, VmbusChannelOnOffer},
108 {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind},
109 {ChannelMessageRequestOffers, NULL},
110 {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered},
111 {ChannelMessageOpenChannel, NULL},
112 {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult},
113 {ChannelMessageCloseChannel, NULL},
114 {ChannelMessageGpadlHeader, NULL},
115 {ChannelMessageGpadlBody, NULL},
116 {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated},
117 {ChannelMessageGpadlTeardown, NULL},
118 {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown},
119 {ChannelMessageRelIdReleased, NULL},
120 {ChannelMessageInitiateContact, NULL},
121 {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse},
122 {ChannelMessageUnload, NULL},
125 /*++
127 Name:
128 AllocVmbusChannel()
130 Description:
131 Allocate and initialize a vmbus channel object
133 --*/
134 struct vmbus_channel *AllocVmbusChannel(void)
136 struct vmbus_channel *channel;
138 channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
139 if (!channel)
141 return NULL;
144 spin_lock_init(&channel->inbound_lock);
146 init_timer(&channel->poll_timer);
147 channel->poll_timer.data = (unsigned long)channel;
148 channel->poll_timer.function = VmbusChannelOnTimer;
150 /* channel->dataWorkQueue = WorkQueueCreate("data"); */
151 channel->ControlWQ = create_workqueue("hv_vmbus_ctl");
152 if (!channel->ControlWQ)
154 kfree(channel);
155 return NULL;
158 return channel;
161 /*++
163 Name:
164 ReleaseVmbusChannel()
166 Description:
167 Release the vmbus channel object itself
169 --*/
170 static inline void ReleaseVmbusChannel(void* Context)
172 struct vmbus_channel *channel = Context;
174 DPRINT_ENTER(VMBUS);
176 DPRINT_DBG(VMBUS, "releasing channel (%p)", channel);
177 destroy_workqueue(channel->ControlWQ);
178 DPRINT_DBG(VMBUS, "channel released (%p)", channel);
180 kfree(channel);
182 DPRINT_EXIT(VMBUS);
185 /*++
187 Name:
188 FreeVmbusChannel()
190 Description:
191 Release the resources used by the vmbus channel object
193 --*/
194 void FreeVmbusChannel(struct vmbus_channel *Channel)
196 del_timer(&Channel->poll_timer);
198 /* We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context */
199 /* ie we can't destroy ourselves. */
200 osd_schedule_callback(gVmbusConnection.WorkQueue, ReleaseVmbusChannel,
201 (void *)Channel);
205 /*++
207 Name:
208 VmbusChannelProcessOffer()
210 Description:
211 Process the offer by creating a channel/device associated with this offer
213 --*/
214 static void
215 VmbusChannelProcessOffer(
216 void * context
219 int ret=0;
220 struct vmbus_channel *newChannel = context;
221 struct vmbus_channel *channel;
222 LIST_ENTRY* anchor;
223 LIST_ENTRY* curr;
224 bool fNew = true;
225 unsigned long flags;
227 DPRINT_ENTER(VMBUS);
229 /* Make sure this is a new offer */
230 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
232 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
234 channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry);
236 if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(GUID)) &&
237 !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)))
239 fNew = false;
240 break;
244 if (fNew)
246 INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry);
248 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
250 if (!fNew)
252 DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", newChannel->OfferMsg.ChildRelId);
253 FreeVmbusChannel(newChannel);
254 DPRINT_EXIT(VMBUS);
255 return;
258 /* Start the process of binding this offer to the driver */
259 /* We need to set the DeviceObject field before calling VmbusChildDeviceAdd() */
260 newChannel->DeviceObject = VmbusChildDeviceCreate(
261 newChannel->OfferMsg.Offer.InterfaceType,
262 newChannel->OfferMsg.Offer.InterfaceInstance,
263 newChannel);
265 DPRINT_DBG(VMBUS, "child device object allocated - %p", newChannel->DeviceObject);
268 * Add the new device to the bus. This will kick off device-driver
269 * binding which eventually invokes the device driver's AddDevice()
270 * method.
273 ret = VmbusChildDeviceAdd(newChannel->DeviceObject);
274 if (ret != 0)
276 DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)",
277 newChannel->OfferMsg.ChildRelId);
279 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
280 REMOVE_ENTRY_LIST(&newChannel->ListEntry);
281 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
283 FreeVmbusChannel(newChannel);
285 else
288 * This state is used to indicate a successful open
289 * so that when we do close the channel normally, we
290 * can cleanup properly
292 newChannel->State = CHANNEL_OPEN_STATE;
294 DPRINT_EXIT(VMBUS);
297 /*++
299 Name:
300 VmbusChannelProcessRescindOffer()
302 Description:
303 Rescind the offer by initiating a device removal
305 --*/
306 static void
307 VmbusChannelProcessRescindOffer(
308 void * context
311 struct vmbus_channel *channel = context;
313 DPRINT_ENTER(VMBUS);
315 VmbusChildDeviceRemove(channel->DeviceObject);
317 DPRINT_EXIT(VMBUS);
321 /*++
323 Name:
324 VmbusChannelOnOffer()
326 Description:
327 Handler for channel offers from vmbus in parent partition. We ignore all offers except
328 network and storage offers. For each network and storage offers, we create a channel object
329 and queue a work item to the channel object to process the offer synchronously
331 --*/
332 static void
333 VmbusChannelOnOffer(
334 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
337 VMBUS_CHANNEL_OFFER_CHANNEL* offer = (VMBUS_CHANNEL_OFFER_CHANNEL*)hdr;
338 struct vmbus_channel *newChannel;
340 GUID *guidType;
341 GUID *guidInstance;
342 int i;
343 int fSupported=0;
345 DPRINT_ENTER(VMBUS);
347 for (i=0; i<MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++)
349 if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(GUID)) == 0)
351 fSupported = 1;
352 break;
356 if (!fSupported)
358 DPRINT_DBG(VMBUS, "Ignoring channel offer notification for child relid %d", offer->ChildRelId);
359 DPRINT_EXIT(VMBUS);
361 return;
364 guidType = &offer->Offer.InterfaceType;
365 guidInstance = &offer->Offer.InterfaceInstance;
367 DPRINT_INFO(VMBUS, "Channel offer notification - child relid %d monitor id %d allocated %d, "
368 "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x} "
369 "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}",
370 offer->ChildRelId,
371 offer->MonitorId,
372 offer->MonitorAllocated,
373 guidType->Data[3], guidType->Data[2], guidType->Data[1], guidType->Data[0], guidType->Data[5], guidType->Data[4], guidType->Data[7], guidType->Data[6], guidType->Data[8], guidType->Data[9], guidType->Data[10], guidType->Data[11], guidType->Data[12], guidType->Data[13], guidType->Data[14], guidType->Data[15],
374 guidInstance->Data[3], guidInstance->Data[2], guidInstance->Data[1], guidInstance->Data[0], guidInstance->Data[5], guidInstance->Data[4], guidInstance->Data[7], guidInstance->Data[6], guidInstance->Data[8], guidInstance->Data[9], guidInstance->Data[10], guidInstance->Data[11], guidInstance->Data[12], guidInstance->Data[13], guidInstance->Data[14], guidInstance->Data[15]);
376 /* Allocate the channel object and save this offer. */
377 newChannel = AllocVmbusChannel();
378 if (!newChannel)
380 DPRINT_ERR(VMBUS, "unable to allocate channel object");
381 return;
384 DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel);
386 memcpy(&newChannel->OfferMsg, offer, sizeof(VMBUS_CHANNEL_OFFER_CHANNEL));
387 newChannel->MonitorGroup = (u8)offer->MonitorId / 32;
388 newChannel->MonitorBit = (u8)offer->MonitorId % 32;
390 /* TODO: Make sure the offer comes from our parent partition */
391 osd_schedule_callback(newChannel->ControlWQ, VmbusChannelProcessOffer,
392 newChannel);
394 DPRINT_EXIT(VMBUS);
398 /*++
400 Name:
401 VmbusChannelOnOfferRescind()
403 Description:
404 Rescind offer handler. We queue a work item to process this offer
405 synchronously
407 --*/
408 static void
409 VmbusChannelOnOfferRescind(
410 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
413 VMBUS_CHANNEL_RESCIND_OFFER* rescind = (VMBUS_CHANNEL_RESCIND_OFFER*)hdr;
414 struct vmbus_channel *channel;
416 DPRINT_ENTER(VMBUS);
418 channel = GetChannelFromRelId(rescind->ChildRelId);
419 if (channel == NULL)
421 DPRINT_DBG(VMBUS, "channel not found for relId %d", rescind->ChildRelId);
422 return;
425 osd_schedule_callback(channel->ControlWQ,
426 VmbusChannelProcessRescindOffer,
427 channel);
429 DPRINT_EXIT(VMBUS);
433 /*++
435 Name:
436 VmbusChannelOnOffersDelivered()
438 Description:
439 This is invoked when all offers have been delivered.
440 Nothing to do here.
442 --*/
443 static void
444 VmbusChannelOnOffersDelivered(
445 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
448 DPRINT_ENTER(VMBUS);
449 DPRINT_EXIT(VMBUS);
453 /*++
455 Name:
456 VmbusChannelOnOpenResult()
458 Description:
459 Open result handler. This is invoked when we received a response
460 to our channel open request. Find the matching request, copy the
461 response and signal the requesting thread.
463 --*/
464 static void
465 VmbusChannelOnOpenResult(
466 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
469 VMBUS_CHANNEL_OPEN_RESULT* result = (VMBUS_CHANNEL_OPEN_RESULT*)hdr;
470 LIST_ENTRY* anchor;
471 LIST_ENTRY* curr;
472 struct vmbus_channel_msginfo *msgInfo;
473 VMBUS_CHANNEL_MESSAGE_HEADER* requestHeader;
474 VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
475 unsigned long flags;
477 DPRINT_ENTER(VMBUS);
479 DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status);
481 /* Find the open msg, copy the result and signal/unblock the wait event */
482 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
484 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
486 msgInfo = (struct vmbus_channel_msginfo *)curr;
487 requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
489 if (requestHeader->MessageType == ChannelMessageOpenChannel)
491 openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)msgInfo->Msg;
492 if (openMsg->ChildRelId == result->ChildRelId &&
493 openMsg->OpenId == result->OpenId)
495 memcpy(&msgInfo->Response.OpenResult, result, sizeof(VMBUS_CHANNEL_OPEN_RESULT));
496 osd_WaitEventSet(msgInfo->WaitEvent);
497 break;
501 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
503 DPRINT_EXIT(VMBUS);
507 /*++
509 Name:
510 VmbusChannelOnGpadlCreated()
512 Description:
513 GPADL created handler. This is invoked when we received a response
514 to our gpadl create request. Find the matching request, copy the
515 response and signal the requesting thread.
517 --*/
518 static void
519 VmbusChannelOnGpadlCreated(
520 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
523 VMBUS_CHANNEL_GPADL_CREATED *gpadlCreated = (VMBUS_CHANNEL_GPADL_CREATED*)hdr;
524 LIST_ENTRY *anchor;
525 LIST_ENTRY *curr;
526 struct vmbus_channel_msginfo *msgInfo;
527 VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
528 VMBUS_CHANNEL_GPADL_HEADER *gpadlHeader;
529 unsigned long flags;
531 DPRINT_ENTER(VMBUS);
533 DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus);
535 /* Find the establish msg, copy the result and signal/unblock the wait event */
536 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
538 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
540 msgInfo = (struct vmbus_channel_msginfo *)curr;
541 requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
543 if (requestHeader->MessageType == ChannelMessageGpadlHeader)
545 gpadlHeader = (VMBUS_CHANNEL_GPADL_HEADER*)requestHeader;
547 if ((gpadlCreated->ChildRelId == gpadlHeader->ChildRelId) &&
548 (gpadlCreated->Gpadl == gpadlHeader->Gpadl))
550 memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(VMBUS_CHANNEL_GPADL_CREATED));
551 osd_WaitEventSet(msgInfo->WaitEvent);
552 break;
556 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
558 DPRINT_EXIT(VMBUS);
562 /*++
564 Name:
565 VmbusChannelOnGpadlTorndown()
567 Description:
568 GPADL torndown handler. This is invoked when we received a response
569 to our gpadl teardown request. Find the matching request, copy the
570 response and signal the requesting thread.
572 --*/
573 static void
574 VmbusChannelOnGpadlTorndown(
575 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
578 VMBUS_CHANNEL_GPADL_TORNDOWN* gpadlTorndown = (VMBUS_CHANNEL_GPADL_TORNDOWN*)hdr;
579 LIST_ENTRY* anchor;
580 LIST_ENTRY* curr;
581 struct vmbus_channel_msginfo *msgInfo;
582 VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
583 VMBUS_CHANNEL_GPADL_TEARDOWN *gpadlTeardown;
584 unsigned long flags;
586 DPRINT_ENTER(VMBUS);
588 /* Find the open msg, copy the result and signal/unblock the wait event */
589 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
591 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
593 msgInfo = (struct vmbus_channel_msginfo *)curr;
594 requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
596 if (requestHeader->MessageType == ChannelMessageGpadlTeardown)
598 gpadlTeardown = (VMBUS_CHANNEL_GPADL_TEARDOWN*)requestHeader;
600 if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl)
602 memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(VMBUS_CHANNEL_GPADL_TORNDOWN));
603 osd_WaitEventSet(msgInfo->WaitEvent);
604 break;
608 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
610 DPRINT_EXIT(VMBUS);
614 /*++
616 Name:
617 VmbusChannelOnVersionResponse()
619 Description:
620 Version response handler. This is invoked when we received a response
621 to our initiate contact request. Find the matching request, copy the
622 response and signal the requesting thread.
624 --*/
625 static void
626 VmbusChannelOnVersionResponse(
627 PVMBUS_CHANNEL_MESSAGE_HEADER hdr
630 LIST_ENTRY* anchor;
631 LIST_ENTRY* curr;
632 struct vmbus_channel_msginfo *msgInfo;
633 VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
634 VMBUS_CHANNEL_INITIATE_CONTACT *initiate;
635 VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse = (VMBUS_CHANNEL_VERSION_RESPONSE*)hdr;
636 unsigned long flags;
638 DPRINT_ENTER(VMBUS);
640 spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
642 ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
644 msgInfo = (struct vmbus_channel_msginfo *)curr;
645 requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
647 if (requestHeader->MessageType == ChannelMessageInitiateContact)
649 initiate = (VMBUS_CHANNEL_INITIATE_CONTACT*)requestHeader;
650 memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(VMBUS_CHANNEL_VERSION_RESPONSE));
651 osd_WaitEventSet(msgInfo->WaitEvent);
654 spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
656 DPRINT_EXIT(VMBUS);
660 /*++
662 Name:
663 VmbusOnChannelMessage()
665 Description:
666 Handler for channel protocol messages.
667 This is invoked in the vmbus worker thread context.
669 --*/
670 void VmbusOnChannelMessage(void *Context)
672 HV_MESSAGE *msg=(HV_MESSAGE*)Context;
673 VMBUS_CHANNEL_MESSAGE_HEADER* hdr;
674 int size;
676 DPRINT_ENTER(VMBUS);
678 hdr = (VMBUS_CHANNEL_MESSAGE_HEADER*)msg->u.Payload;
679 size=msg->Header.PayloadSize;
681 DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size);
683 if (hdr->MessageType >= ChannelMessageCount)
685 DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
686 print_hex_dump_bytes("", DUMP_PREFIX_NONE,
687 (unsigned char *)msg->u.Payload, size);
688 kfree(msg);
689 return;
692 if (gChannelMessageTable[hdr->MessageType].messageHandler)
694 gChannelMessageTable[hdr->MessageType].messageHandler(hdr);
696 else
698 DPRINT_ERR(VMBUS, "Unhandled channel message type %d", hdr->MessageType);
701 /* Free the msg that was allocated in VmbusOnMsgDPC() */
702 kfree(msg);
703 DPRINT_EXIT(VMBUS);
707 /*++
709 Name:
710 VmbusChannelRequestOffers()
712 Description:
713 Send a request to get all our pending offers.
715 --*/
716 int VmbusChannelRequestOffers(void)
718 int ret=0;
719 VMBUS_CHANNEL_MESSAGE_HEADER* msg;
720 struct vmbus_channel_msginfo *msgInfo;
722 DPRINT_ENTER(VMBUS);
724 msgInfo = kmalloc(sizeof(*msgInfo) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER), GFP_KERNEL);
725 ASSERT(msgInfo != NULL);
727 msgInfo->WaitEvent = osd_WaitEventCreate();
728 msg = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
730 msg->MessageType = ChannelMessageRequestOffers;
732 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
733 INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry);
734 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
736 ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_MESSAGE_HEADER));
737 if (ret != 0)
739 DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret);
741 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
742 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
743 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
745 goto Cleanup;
747 /* osd_WaitEventWait(msgInfo->waitEvent); */
749 /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
750 REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
751 SpinlockRelease(gVmbusConnection.channelMsgLock);*/
754 Cleanup:
755 if (msgInfo)
757 kfree(msgInfo->WaitEvent);
758 kfree(msgInfo);
761 DPRINT_EXIT(VMBUS);
763 return ret;
766 /*++
768 Name:
769 VmbusChannelReleaseUnattachedChannels()
771 Description:
772 Release channels that are unattached/unconnected ie (no drivers associated)
774 --*/
775 void VmbusChannelReleaseUnattachedChannels(void)
777 LIST_ENTRY *entry;
778 struct vmbus_channel *channel;
779 struct vmbus_channel *start = NULL;
780 unsigned long flags;
782 spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
784 while (!IsListEmpty(&gVmbusConnection.ChannelList))
786 entry = TOP_LIST_ENTRY(&gVmbusConnection.ChannelList);
787 channel = CONTAINING_RECORD(entry, struct vmbus_channel, ListEntry);
789 if (channel == start)
790 break;
792 if (!channel->DeviceObject->Driver)
794 REMOVE_ENTRY_LIST(&channel->ListEntry);
795 DPRINT_INFO(VMBUS, "Releasing unattached device object %p", channel->DeviceObject);
797 VmbusChildDeviceRemove(channel->DeviceObject);
798 FreeVmbusChannel(channel);
800 else
802 if (!start)
804 start = channel;
809 spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
812 /* eof */