Staging: hv: fix typedefs in nvspprotocol.h
[safe/jmp/linux-2.6] / drivers / staging / hv / ChannelMgmt.c
index ff9c9d0..d526390 100644 (file)
  */
 
 
-#include "include/osd.h"
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include "osd.h"
 #include "include/logging.h"
 
 #include "VmbusPrivate.h"
 
-//
-// Defines
-//
+/* Data types */
 
-//
-// Data types
-//
-
-typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(VMBUS_CHANNEL_MESSAGE_HEADER* msg);
+typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(struct vmbus_channel_message_header *msg);
 
 typedef struct _VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY {
-       VMBUS_CHANNEL_MESSAGE_TYPE      messageType;
+       enum vmbus_channel_message_type messageType;
        PFN_CHANNEL_MESSAGE_HANDLER messageHandler;
 } VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY;
 
-//
-// Internal routines
-//
-
-static void
-VmbusChannelOnOffer(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-static void
-VmbusChannelOnOpenResult(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-
-static void
-VmbusChannelOnOfferRescind(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-
-static void
-VmbusChannelOnGpadlCreated(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-
-static void
-VmbusChannelOnGpadlTorndown(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-
-static void
-VmbusChannelOnOffersDelivered(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
-
-static void
-VmbusChannelOnVersionResponse(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       );
+/* Internal routines */
+static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnGpadlTorndown(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnOffersDelivered(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelOnVersionResponse(struct vmbus_channel_message_header *hdr);
+static void VmbusChannelProcessOffer(void * context);
+static void VmbusChannelProcessRescindOffer(void * context);
 
-static void
-VmbusChannelProcessOffer(
-       void * context
-       );
 
-static void
-VmbusChannelProcessRescindOffer(
-       void * context
-       );
+/* Globals */
 
+#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4
 
-//
-// Globals
-//
+static const struct hv_guid gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = {
+       /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */
+       /* Storage - SCSI */
+       {
+               .data  = {
+                       0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d,
+                       0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f
+               }
+       },
 
-#define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4
+       /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
+       /* Network */
+       {
+               .data = {
+                       0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
+                       0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
+               }
+       },
 
-const GUID gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED]= {
-       //{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}
-       {.Data  = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}},// Storage - SCSI
-       //{F8615163-DF3E-46c5-913F-F2D2F965ED0E}
-       {.Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}},     // Network
-       //{CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A}
-       {.Data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}}, // Input
-       //{32412632-86cb-44a2-9b5c-50d1417354f5}
-       {.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}}, // IDE
+       /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */
+       /* Input */
+       {
+               .data = {
+                       0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c,
+                       0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A
+               }
+       },
 
+       /* {32412632-86cb-44a2-9b5c-50d1417354f5} */
+       /* IDE */
+       {
+               .data = {
+                       0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44,
+                       0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5
+               }
+       },
 };
 
-// Channel message dispatch table
-VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= {
+/* Channel message dispatch table */
+static VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= {
     {ChannelMessageInvalid,                                    NULL},
     {ChannelMessageOfferChannel,            VmbusChannelOnOffer},
     {ChannelMessageRescindChannelOffer,     VmbusChannelOnOfferRescind},
@@ -139,39 +122,27 @@ Description:
        Allocate and initialize a vmbus channel object
 
 --*/
-VMBUS_CHANNEL* AllocVmbusChannel(void)
+struct vmbus_channel *AllocVmbusChannel(void)
 {
-       VMBUS_CHANNEL* channel;
+       struct vmbus_channel *channel;
 
-       channel = (VMBUS_CHANNEL*) MemAllocAtomic(sizeof(VMBUS_CHANNEL));
+       channel = kzalloc(sizeof(*channel), GFP_ATOMIC);
        if (!channel)
        {
                return NULL;
        }
 
-       memset(channel, 0,sizeof(VMBUS_CHANNEL));
-       channel->InboundLock = SpinlockCreate();
-       if (!channel->InboundLock)
-       {
-               MemFree(channel);
-               return NULL;
-       }
+       spin_lock_init(&channel->inbound_lock);
 
-       channel->PollTimer = TimerCreate(VmbusChannelOnTimer, channel);
-       if (!channel->PollTimer)
-       {
-               SpinlockClose(channel->InboundLock);
-               MemFree(channel);
-               return NULL;
-       }
+       init_timer(&channel->poll_timer);
+       channel->poll_timer.data = (unsigned long)channel;
+       channel->poll_timer.function = VmbusChannelOnTimer;
 
-       //channel->dataWorkQueue = WorkQueueCreate("data");
-       channel->ControlWQ = WorkQueueCreate("control");
+       /* channel->dataWorkQueue = WorkQueueCreate("data"); */
+       channel->ControlWQ = create_workqueue("hv_vmbus_ctl");
        if (!channel->ControlWQ)
        {
-               TimerClose(channel->PollTimer);
-               SpinlockClose(channel->InboundLock);
-               MemFree(channel);
+               kfree(channel);
                return NULL;
        }
 
@@ -189,15 +160,15 @@ Description:
 --*/
 static inline void ReleaseVmbusChannel(void* Context)
 {
-       VMBUS_CHANNEL* channel = (VMBUS_CHANNEL*)Context;
+       struct vmbus_channel *channel = Context;
 
        DPRINT_ENTER(VMBUS);
 
        DPRINT_DBG(VMBUS, "releasing channel (%p)", channel);
-       WorkQueueClose(channel->ControlWQ);
+       destroy_workqueue(channel->ControlWQ);
        DPRINT_DBG(VMBUS, "channel released (%p)", channel);
 
-       MemFree(channel);
+       kfree(channel);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -211,14 +182,14 @@ Description:
        Release the resources used by the vmbus channel object
 
 --*/
-void FreeVmbusChannel(VMBUS_CHANNEL* Channel)
+void FreeVmbusChannel(struct vmbus_channel *Channel)
 {
-       SpinlockClose(Channel->InboundLock);
-       TimerClose(Channel->PollTimer);
+       del_timer(&Channel->poll_timer);
 
-       // We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context
-       // ie we can't destroy ourselves.
-       WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, (void*)Channel);
+       /* We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context */
+       /* ie we can't destroy ourselves. */
+       osd_schedule_callback(gVmbusConnection.WorkQueue, ReleaseVmbusChannel,
+                             (void *)Channel);
 }
 
 
@@ -237,23 +208,24 @@ VmbusChannelProcessOffer(
        )
 {
        int ret=0;
-       VMBUS_CHANNEL* newChannel=(VMBUS_CHANNEL*)context;
+       struct vmbus_channel *newChannel = context;
+       struct vmbus_channel *channel;
        LIST_ENTRY* anchor;
        LIST_ENTRY* curr;
        bool fNew = true;
-       VMBUS_CHANNEL* channel;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
-       // Make sure this is a new offer
-       SpinlockAcquire(gVmbusConnection.ChannelLock);
+       /* Make sure this is a new offer */
+       spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 
        ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList)
        {
-               channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry);
+               channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry);
 
-               if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(GUID)) &&
-                       !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)))
+               if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(struct hv_guid)) &&
+                       !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid)))
                {
                        fNew = false;
                        break;
@@ -264,7 +236,7 @@ VmbusChannelProcessOffer(
        {
                INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry);
        }
-       SpinlockRelease(gVmbusConnection.ChannelLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
        if (!fNew)
        {
@@ -274,33 +246,40 @@ VmbusChannelProcessOffer(
                return;
        }
 
-       // Start the process of binding this offer to the driver
-       // We need to set the DeviceObject field before calling VmbusChildDeviceAdd()
+       /* Start the process of binding this offer to the driver */
+       /* We need to set the DeviceObject field before calling VmbusChildDeviceAdd() */
        newChannel->DeviceObject = VmbusChildDeviceCreate(
-               newChannel->OfferMsg.Offer.InterfaceType,
-               newChannel->OfferMsg.Offer.InterfaceInstance,
+               &newChannel->OfferMsg.Offer.InterfaceType,
+               &newChannel->OfferMsg.Offer.InterfaceInstance,
                newChannel);
 
        DPRINT_DBG(VMBUS, "child device object allocated - %p", newChannel->DeviceObject);
 
-       // Add the new device to the bus. This will kick off device-driver binding
-       // which eventually invokes the device driver's AddDevice() method.
+       /*
+        * Add the new device to the bus. This will kick off device-driver
+        * binding which eventually invokes the device driver's AddDevice()
+        * method.
+        */
+
        ret = VmbusChildDeviceAdd(newChannel->DeviceObject);
        if (ret != 0)
        {
                DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)",
                        newChannel->OfferMsg.ChildRelId);
 
-               SpinlockAcquire(gVmbusConnection.ChannelLock);
+               spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
                REMOVE_ENTRY_LIST(&newChannel->ListEntry);
-               SpinlockRelease(gVmbusConnection.ChannelLock);
+               spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 
                FreeVmbusChannel(newChannel);
        }
        else
        {
-               // This state is used to indicate a successful open so that when we do close the channel normally,
-               // we can cleanup properly
+               /*
+                * This state is used to indicate a successful open
+                * so that when we do close the channel normally, we
+                * can cleanup properly
+                */
                newChannel->State = CHANNEL_OPEN_STATE;
        }
        DPRINT_EXIT(VMBUS);
@@ -320,7 +299,7 @@ VmbusChannelProcessRescindOffer(
        void * context
        )
 {
-       VMBUS_CHANNEL* channel=(VMBUS_CHANNEL*)context;
+       struct vmbus_channel *channel = context;
 
        DPRINT_ENTER(VMBUS);
 
@@ -341,16 +320,13 @@ Description:
        and queue a work item to the channel object to process the offer synchronously
 
 --*/
-static void
-VmbusChannelOnOffer(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnOffer(struct vmbus_channel_message_header *hdr)
 {
-       VMBUS_CHANNEL_OFFER_CHANNEL* offer = (VMBUS_CHANNEL_OFFER_CHANNEL*)hdr;
-       VMBUS_CHANNEL* newChannel;
+       struct vmbus_channel_offer_channel *offer = (struct vmbus_channel_offer_channel *)hdr;
+       struct vmbus_channel *newChannel;
 
-       GUID *guidType;
-       GUID *guidInstance;
+       struct hv_guid *guidType;
+       struct hv_guid *guidInstance;
        int i;
        int fSupported=0;
 
@@ -358,7 +334,7 @@ VmbusChannelOnOffer(
 
        for (i=0; i<MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++)
        {
-               if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(GUID)) == 0)
+               if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(struct hv_guid)) == 0)
                {
                        fSupported = 1;
                        break;
@@ -382,10 +358,16 @@ VmbusChannelOnOffer(
                offer->ChildRelId,
                offer->MonitorId,
                offer->MonitorAllocated,
-               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],
-               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]);
-
-       // Allocate the channel object and save this offer.
+               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],
+               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]);
+
+       /* Allocate the channel object and save this offer. */
        newChannel = AllocVmbusChannel();
        if (!newChannel)
        {
@@ -395,12 +377,13 @@ VmbusChannelOnOffer(
 
        DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel);
 
-       memcpy(&newChannel->OfferMsg, offer, sizeof(VMBUS_CHANNEL_OFFER_CHANNEL));
+       memcpy(&newChannel->OfferMsg, offer, sizeof(struct vmbus_channel_offer_channel));
        newChannel->MonitorGroup = (u8)offer->MonitorId / 32;
        newChannel->MonitorBit = (u8)offer->MonitorId % 32;
 
-       // TODO: Make sure the offer comes from our parent partition
-       WorkQueueQueueWorkItem(newChannel->ControlWQ, VmbusChannelProcessOffer, newChannel);
+       /* TODO: Make sure the offer comes from our parent partition */
+       osd_schedule_callback(newChannel->ControlWQ, VmbusChannelProcessOffer,
+                             newChannel);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -416,13 +399,10 @@ Description:
        synchronously
 
 --*/
-static void
-VmbusChannelOnOfferRescind(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnOfferRescind(struct vmbus_channel_message_header *hdr)
 {
-       VMBUS_CHANNEL_RESCIND_OFFER* rescind = (VMBUS_CHANNEL_RESCIND_OFFER*)hdr;
-       VMBUS_CHANNEL* channel;
+       struct vmbus_channel_rescind_offer *rescind = (struct vmbus_channel_rescind_offer *)hdr;
+       struct vmbus_channel *channel;
 
        DPRINT_ENTER(VMBUS);
 
@@ -433,7 +413,9 @@ VmbusChannelOnOfferRescind(
                return;
        }
 
-       WorkQueueQueueWorkItem(channel->ControlWQ, VmbusChannelProcessRescindOffer, channel);
+       osd_schedule_callback(channel->ControlWQ,
+                             VmbusChannelProcessRescindOffer,
+                             channel);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -449,10 +431,7 @@ Description:
        Nothing to do here.
 
 --*/
-static void
-VmbusChannelOnOffersDelivered(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnOffersDelivered(struct vmbus_channel_message_header *hdr)
 {
        DPRINT_ENTER(VMBUS);
        DPRINT_EXIT(VMBUS);
@@ -470,43 +449,41 @@ Description:
        response and signal the requesting thread.
 
 --*/
-static void
-VmbusChannelOnOpenResult(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnOpenResult(struct vmbus_channel_message_header *hdr)
 {
-       VMBUS_CHANNEL_OPEN_RESULT* result = (VMBUS_CHANNEL_OPEN_RESULT*)hdr;
+       struct vmbus_channel_open_result *result = (struct vmbus_channel_open_result *)hdr;
        LIST_ENTRY* anchor;
        LIST_ENTRY* curr;
-       VMBUS_CHANNEL_MSGINFO* msgInfo;
-       VMBUS_CHANNEL_MESSAGE_HEADER* requestHeader;
-       VMBUS_CHANNEL_OPEN_CHANNEL* openMsg;
+       struct vmbus_channel_msginfo *msgInfo;
+       struct vmbus_channel_message_header *requestHeader;
+       struct vmbus_channel_open_channel *openMsg;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
        DPRINT_DBG(VMBUS, "vmbus open result - %d", result->Status);
 
-       // Find the open msg, copy the result and signal/unblock the wait event
-       SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+       /* Find the open msg, copy the result and signal/unblock the wait event */
+       spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
        ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
        {
-               msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
-               requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+               msgInfo = (struct vmbus_channel_msginfo *)curr;
+               requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
 
                if (requestHeader->MessageType == ChannelMessageOpenChannel)
                {
-                       openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)msgInfo->Msg;
+                       openMsg = (struct vmbus_channel_open_channel *)msgInfo->Msg;
                        if (openMsg->ChildRelId == result->ChildRelId &&
                                openMsg->OpenId == result->OpenId)
                        {
-                               memcpy(&msgInfo->Response.OpenResult, result, sizeof(VMBUS_CHANNEL_OPEN_RESULT));
-                               WaitEventSet(msgInfo->WaitEvent);
+                               memcpy(&msgInfo->Response.OpenResult, result, sizeof(struct vmbus_channel_open_result));
+                               osd_WaitEventSet(msgInfo->WaitEvent);
                                break;
                        }
                }
        }
-       SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -523,44 +500,42 @@ Description:
        response and signal the requesting thread.
 
 --*/
-static void
-VmbusChannelOnGpadlCreated(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnGpadlCreated(struct vmbus_channel_message_header *hdr)
 {
-       VMBUS_CHANNEL_GPADL_CREATED *gpadlCreated = (VMBUS_CHANNEL_GPADL_CREATED*)hdr;
+       struct vmbus_channel_gpadl_created *gpadlCreated = (struct vmbus_channel_gpadl_created *)hdr;
        LIST_ENTRY *anchor;
        LIST_ENTRY *curr;
-       VMBUS_CHANNEL_MSGINFO *msgInfo;
-       VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
-       VMBUS_CHANNEL_GPADL_HEADER *gpadlHeader;
+       struct vmbus_channel_msginfo *msgInfo;
+       struct vmbus_channel_message_header *requestHeader;
+       struct vmbus_channel_gpadl_header *gpadlHeader;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
        DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus);
 
-       // Find the establish msg, copy the result and signal/unblock the wait event
-       SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+       /* Find the establish msg, copy the result and signal/unblock the wait event */
+       spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
        ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
        {
-               msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
-               requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+               msgInfo = (struct vmbus_channel_msginfo *)curr;
+               requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
 
                if (requestHeader->MessageType == ChannelMessageGpadlHeader)
                {
-                       gpadlHeader = (VMBUS_CHANNEL_GPADL_HEADER*)requestHeader;
+                       gpadlHeader = (struct vmbus_channel_gpadl_header *)requestHeader;
 
                        if ((gpadlCreated->ChildRelId == gpadlHeader->ChildRelId) &&
                                        (gpadlCreated->Gpadl == gpadlHeader->Gpadl))
                        {
-                               memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(VMBUS_CHANNEL_GPADL_CREATED));
-                               WaitEventSet(msgInfo->WaitEvent);
+                               memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(struct vmbus_channel_gpadl_created));
+                               osd_WaitEventSet(msgInfo->WaitEvent);
                                break;
                        }
                }
        }
-       SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -577,41 +552,39 @@ Description:
        response and signal the requesting thread.
 
 --*/
-static void
-VmbusChannelOnGpadlTorndown(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnGpadlTorndown(struct vmbus_channel_message_header *hdr)
 {
-       VMBUS_CHANNEL_GPADL_TORNDOWN* gpadlTorndown  = (VMBUS_CHANNEL_GPADL_TORNDOWN*)hdr;
+       struct vmbus_channel_gpadl_torndown* gpadlTorndown  = (struct vmbus_channel_gpadl_torndown *)hdr;
        LIST_ENTRY* anchor;
        LIST_ENTRY* curr;
-       VMBUS_CHANNEL_MSGINFO* msgInfo;
-       VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
-       VMBUS_CHANNEL_GPADL_TEARDOWN *gpadlTeardown;
+       struct vmbus_channel_msginfo *msgInfo;
+       struct vmbus_channel_message_header *requestHeader;
+       struct vmbus_channel_gpadl_teardown *gpadlTeardown;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
-       // Find the open msg, copy the result and signal/unblock the wait event
-       SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+       /* Find the open msg, copy the result and signal/unblock the wait event */
+       spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
        ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
        {
-               msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
-               requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+               msgInfo = (struct vmbus_channel_msginfo *)curr;
+               requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
 
                if (requestHeader->MessageType == ChannelMessageGpadlTeardown)
                {
-                       gpadlTeardown = (VMBUS_CHANNEL_GPADL_TEARDOWN*)requestHeader;
+                       gpadlTeardown = (struct vmbus_channel_gpadl_teardown *)requestHeader;
 
                        if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl)
                        {
-                               memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(VMBUS_CHANNEL_GPADL_TORNDOWN));
-                               WaitEventSet(msgInfo->WaitEvent);
+                               memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(struct vmbus_channel_gpadl_torndown));
+                               osd_WaitEventSet(msgInfo->WaitEvent);
                                break;
                        }
                }
        }
-       SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -628,35 +601,33 @@ Description:
        response and signal the requesting thread.
 
 --*/
-static void
-VmbusChannelOnVersionResponse(
-       PVMBUS_CHANNEL_MESSAGE_HEADER hdr
-       )
+static void VmbusChannelOnVersionResponse(struct vmbus_channel_message_header *hdr)
 {
        LIST_ENTRY* anchor;
        LIST_ENTRY* curr;
-       VMBUS_CHANNEL_MSGINFO *msgInfo;
-       VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader;
-       VMBUS_CHANNEL_INITIATE_CONTACT *initiate;
-       VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse  = (VMBUS_CHANNEL_VERSION_RESPONSE*)hdr;
+       struct vmbus_channel_msginfo *msgInfo;
+       struct vmbus_channel_message_header *requestHeader;
+       struct vmbus_channel_initiate_contact *initiate;
+       struct vmbus_channel_version_response *versionResponse  = (struct vmbus_channel_version_response *)hdr;
+       unsigned long flags;
 
        DPRINT_ENTER(VMBUS);
 
-       SpinlockAcquire(gVmbusConnection.ChannelMsgLock);
+       spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
 
        ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList)
        {
-               msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr;
-               requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+               msgInfo = (struct vmbus_channel_msginfo *)curr;
+               requestHeader = (struct vmbus_channel_message_header *)msgInfo->Msg;
 
                if (requestHeader->MessageType == ChannelMessageInitiateContact)
                {
-                       initiate = (VMBUS_CHANNEL_INITIATE_CONTACT*)requestHeader;
-                       memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(VMBUS_CHANNEL_VERSION_RESPONSE));
-                       WaitEventSet(msgInfo->WaitEvent);
+                       initiate = (struct vmbus_channel_initiate_contact *)requestHeader;
+                       memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(struct vmbus_channel_version_response));
+                       osd_WaitEventSet(msgInfo->WaitEvent);
                }
        }
-       SpinlockRelease(gVmbusConnection.ChannelMsgLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
 
        DPRINT_EXIT(VMBUS);
 }
@@ -672,18 +643,15 @@ Description:
        This is invoked in the vmbus worker thread context.
 
 --*/
-void
-VmbusOnChannelMessage(
-       void *Context
-       )
+void VmbusOnChannelMessage(void *Context)
 {
-       HV_MESSAGE *msg=(HV_MESSAGE*)Context;
-       VMBUS_CHANNEL_MESSAGE_HEADER* hdr;
+       struct hv_message *msg = Context;
+       struct vmbus_channel_message_header *hdr;
        int size;
 
        DPRINT_ENTER(VMBUS);
 
-       hdr = (VMBUS_CHANNEL_MESSAGE_HEADER*)msg->u.Payload;
+       hdr = (struct vmbus_channel_message_header *)msg->u.Payload;
        size=msg->Header.PayloadSize;
 
        DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size);
@@ -691,8 +659,9 @@ VmbusOnChannelMessage(
        if (hdr->MessageType >= ChannelMessageCount)
        {
                DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size);
-               PrintBytes((unsigned char *)msg->u.Payload, size);
-               MemFree(msg);
+               print_hex_dump_bytes("", DUMP_PREFIX_NONE,
+                                    (unsigned char *)msg->u.Payload, size);
+               kfree(msg);
                return;
        }
 
@@ -705,8 +674,8 @@ VmbusOnChannelMessage(
                DPRINT_ERR(VMBUS, "Unhandled channel message type %d", hdr->MessageType);
        }
 
-       // Free the msg that was allocated in VmbusOnMsgDPC()
-       MemFree(msg);
+       /* Free the msg that was allocated in VmbusOnMsgDPC() */
+       kfree(msg);
        DPRINT_EXIT(VMBUS);
 }
 
@@ -720,23 +689,19 @@ Description:
        Send a request to get all our pending offers.
 
 --*/
-int
-VmbusChannelRequestOffers(
-       void
-       )
+int VmbusChannelRequestOffers(void)
 {
        int ret=0;
-       VMBUS_CHANNEL_MESSAGE_HEADER* msg;
-       VMBUS_CHANNEL_MSGINFO* msgInfo;
+       struct vmbus_channel_message_header *msg;
+       struct vmbus_channel_msginfo *msgInfo;
 
        DPRINT_ENTER(VMBUS);
 
-       msgInfo =
-               (VMBUS_CHANNEL_MSGINFO*)MemAlloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER));
+       msgInfo = kmalloc(sizeof(*msgInfo) + sizeof(struct vmbus_channel_message_header), GFP_KERNEL);
        ASSERT(msgInfo != NULL);
 
-       msgInfo->WaitEvent = WaitEventCreate();
-       msg = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg;
+       msgInfo->WaitEvent = osd_WaitEventCreate();
+       msg = (struct vmbus_channel_message_header *)msgInfo->Msg;
 
        msg->MessageType = ChannelMessageRequestOffers;
 
@@ -744,7 +709,7 @@ VmbusChannelRequestOffers(
        INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry);
        SpinlockRelease(gVmbusConnection.channelMsgLock);*/
 
-       ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_MESSAGE_HEADER));
+       ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header));
        if (ret != 0)
        {
                DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret);
@@ -755,7 +720,7 @@ VmbusChannelRequestOffers(
 
                goto Cleanup;
        }
-       //WaitEventWait(msgInfo->waitEvent);
+       /* osd_WaitEventWait(msgInfo->waitEvent); */
 
        /*SpinlockAcquire(gVmbusConnection.channelMsgLock);
        REMOVE_ENTRY_LIST(&msgInfo->msgListEntry);
@@ -765,8 +730,8 @@ VmbusChannelRequestOffers(
 Cleanup:
        if (msgInfo)
        {
-               WaitEventClose(msgInfo->WaitEvent);
-               MemFree(msgInfo);
+               kfree(msgInfo->WaitEvent);
+               kfree(msgInfo);
        }
 
        DPRINT_EXIT(VMBUS);
@@ -783,21 +748,19 @@ Description:
        Release channels that are unattached/unconnected ie (no drivers associated)
 
 --*/
-void
-VmbusChannelReleaseUnattachedChannels(
-       void
-       )
+void VmbusChannelReleaseUnattachedChannels(void)
 {
        LIST_ENTRY *entry;
-       VMBUS_CHANNEL *channel;
-       VMBUS_CHANNEL *start=NULL;
+       struct vmbus_channel *channel;
+       struct vmbus_channel *start = NULL;
+       unsigned long flags;
 
-       SpinlockAcquire(gVmbusConnection.ChannelLock);
+       spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
 
        while (!IsListEmpty(&gVmbusConnection.ChannelList))
        {
                entry = TOP_LIST_ENTRY(&gVmbusConnection.ChannelList);
-               channel = CONTAINING_RECORD(entry, VMBUS_CHANNEL, ListEntry);
+               channel = CONTAINING_RECORD(entry, struct vmbus_channel, ListEntry);
 
                if (channel == start)
                        break;
@@ -819,8 +782,7 @@ VmbusChannelReleaseUnattachedChannels(
                }
        }
 
-       SpinlockRelease(gVmbusConnection.ChannelLock);
+       spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
 }
 
-// eof
-
+/* eof */