]> Pileus Git - ~andy/linux/blobdiff - drivers/staging/hv/NetVsc.c
Staging: hv: coding style cleanups of ChannelInterface.c
[~andy/linux] / drivers / staging / hv / NetVsc.c
index c0d5dc39ccd1cf2c5761a849e92e0ec471ed5cb1..fb1cbf02ce5a2416d8f8bff72baad7f51784afb2 100644 (file)
@@ -23,7 +23,9 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/delay.h>
-#include "include/logging.h"
+#include <asm/io.h>
+#include "osd.h"
+#include "logging.h"
 #include "NetVsc.h"
 #include "RndisFilter.h"
 
 static const char* gDriverName="netvsc";
 
 /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */
-static const GUID gNetVscDeviceType={
-       .Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}
+static const struct hv_guid gNetVscDeviceType = {
+       .data = {
+               0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46,
+               0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E
+       }
 };
 
 
 /* Internal routines */
 static int
 NetVscOnDeviceAdd(
-       DEVICE_OBJECT   *Device,
+       struct hv_device *Device,
        void                    *AdditionalInfo
        );
 
 static int
 NetVscOnDeviceRemove(
-       DEVICE_OBJECT *Device
+       struct hv_device *Device
        );
 
 static void
 NetVscOnCleanup(
-       DRIVER_OBJECT *Driver
+       struct hv_driver *Driver
        );
 
 static void
@@ -61,12 +66,12 @@ NetVscOnChannelCallback(
 
 static int
 NetVscInitializeSendBufferWithNetVsp(
-       DEVICE_OBJECT                   *Device
+       struct hv_device *Device
        );
 
 static int
 NetVscInitializeReceiveBufferWithNetVsp(
-       DEVICE_OBJECT                   *Device
+       struct hv_device *Device
        );
 
 static int
@@ -81,25 +86,25 @@ NetVscDestroyReceiveBuffer(
 
 static int
 NetVscConnectToVsp(
-       DEVICE_OBJECT           *Device
+       struct hv_device *Device
        );
 
 static void
 NetVscOnSendCompletion(
-       DEVICE_OBJECT           *Device,
-       VMPACKET_DESCRIPTOR *Packet
+       struct hv_device *Device,
+       struct vmpacket_descriptor *Packet
        );
 
 static int
 NetVscOnSend(
-       DEVICE_OBJECT   *Device,
-       NETVSC_PACKET   *Packet
+       struct hv_device *Device,
+       struct hv_netvsc_packet *Packet
        );
 
 static void
 NetVscOnReceive(
-       DEVICE_OBJECT           *Device,
-       VMPACKET_DESCRIPTOR *Packet
+       struct hv_device *Device,
+       struct vmpacket_descriptor *Packet
        );
 
 static void
@@ -109,11 +114,11 @@ NetVscOnReceiveCompletion(
 
 static void
 NetVscSendReceiveCompletion(
-       DEVICE_OBJECT   *Device,
+       struct hv_device *Device,
        u64                     TransactionId
        );
 
-static inline struct NETVSC_DEVICE *AllocNetDevice(DEVICE_OBJECT *Device)
+static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
@@ -122,7 +127,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(DEVICE_OBJECT *Device)
                return NULL;
 
        /* Set to 2 to allow both inbound and outbound traffic */
-       InterlockedCompareExchange(&netDevice->RefCount, 2, 0);
+       atomic_cmpxchg(&netDevice->RefCount, 0, 2);
 
        netDevice->Device = Device;
        Device->Extension = netDevice;
@@ -132,59 +137,51 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(DEVICE_OBJECT *Device)
 
 static inline void FreeNetDevice(struct NETVSC_DEVICE *Device)
 {
-       ASSERT(Device->RefCount == 0);
+       ASSERT(atomic_read(&Device->RefCount) == 0);
        Device->Device->Extension = NULL;
        kfree(Device);
 }
 
 
 /* Get the net device object iff exists and its refcount > 1 */
-static inline struct NETVSC_DEVICE *GetOutboundNetDevice(DEVICE_OBJECT *Device)
+static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
        netDevice = (struct NETVSC_DEVICE*)Device->Extension;
-       if (netDevice && netDevice->RefCount > 1)
-       {
-               InterlockedIncrement(&netDevice->RefCount);
-       }
+       if (netDevice && atomic_read(&netDevice->RefCount) > 1)
+               atomic_inc(&netDevice->RefCount);
        else
-       {
                netDevice = NULL;
-       }
 
        return netDevice;
 }
 
 /* Get the net device object iff exists and its refcount > 0 */
-static inline struct NETVSC_DEVICE *GetInboundNetDevice(DEVICE_OBJECT  *Device)
+static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
        netDevice = (struct NETVSC_DEVICE*)Device->Extension;
-       if (netDevice && netDevice->RefCount)
-       {
-               InterlockedIncrement(&netDevice->RefCount);
-       }
+       if (netDevice && atomic_read(&netDevice->RefCount))
+               atomic_inc(&netDevice->RefCount);
        else
-       {
                netDevice = NULL;
-       }
 
        return netDevice;
 }
 
-static inline void PutNetDevice(DEVICE_OBJECT *Device)
+static inline void PutNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
        netDevice = (struct NETVSC_DEVICE*)Device->Extension;
        ASSERT(netDevice);
 
-       InterlockedDecrement(&netDevice->RefCount);
+       atomic_dec(&netDevice->RefCount);
 }
 
-static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(DEVICE_OBJECT *Device)
+static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
@@ -193,7 +190,7 @@ static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(DEVICE_OBJECT *Devi
                return NULL;
 
        /* Busy wait until the ref drop to 2, then set it to 1 */
-       while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2)
+       while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2)
        {
                udelay(100);
        }
@@ -201,7 +198,7 @@ static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(DEVICE_OBJECT *Devi
        return netDevice;
 }
 
-static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(DEVICE_OBJECT *Device)
+static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device)
 {
        struct NETVSC_DEVICE *netDevice;
 
@@ -210,7 +207,7 @@ static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(DEVICE_OBJECT *Devic
                return NULL;
 
        /* Busy wait until the ref drop to 1, then set it to 0 */
-       while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1)
+       while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1)
        {
                udelay(100);
        }
@@ -231,22 +228,22 @@ Description:
 --*/
 int
 NetVscInitialize(
-       DRIVER_OBJECT *drv
+       struct hv_driver *drv
        )
 {
-       NETVSC_DRIVER_OBJECT* driver = (NETVSC_DRIVER_OBJECT*)drv;
+       struct netvsc_driver *driver = (struct netvsc_driver *)drv;
        int ret=0;
 
        DPRINT_ENTER(NETVSC);
 
-       DPRINT_DBG(NETVSC, "sizeof(NETVSC_PACKET)=%ld, sizeof(NVSP_MESSAGE)=%ld, sizeof(VMTRANSFER_PAGE_PACKET_HEADER)=%ld",
-               sizeof(NETVSC_PACKET), sizeof(NVSP_MESSAGE), sizeof(VMTRANSFER_PAGE_PACKET_HEADER));
+       DPRINT_DBG(NETVSC, "sizeof(struct hv_netvsc_packet)=%zd, sizeof(struct nvsp_message)=%zd, sizeof(struct vmtransfer_page_packet_header)=%zd",
+               sizeof(struct hv_netvsc_packet), sizeof(struct nvsp_message), sizeof(struct vmtransfer_page_packet_header));
 
        /* Make sure we are at least 2 pages since 1 page is used for control */
        ASSERT(driver->RingBufferSize >= (PAGE_SIZE << 1));
 
        drv->name = gDriverName;
-       memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(GUID));
+       memcpy(&drv->deviceType, &gNetVscDeviceType, sizeof(struct hv_guid));
 
        /* Make sure it is set by the caller */
        ASSERT(driver->OnReceiveCallback);
@@ -268,12 +265,12 @@ NetVscInitialize(
 
 static int
 NetVscInitializeReceiveBufferWithNetVsp(
-       DEVICE_OBJECT   *Device
+       struct hv_device *Device
        )
 {
        int ret=0;
        struct NETVSC_DEVICE *netDevice;
-       NVSP_MESSAGE *initPacket;
+       struct nvsp_message *initPacket;
 
        DPRINT_ENTER(NETVSC);
 
@@ -287,7 +284,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
        ASSERT(netDevice->ReceiveBufferSize > 0);
        ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE-1)) == 0); /* page-size grandularity */
 
-       netDevice->ReceiveBuffer = PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT);
+       netDevice->ReceiveBuffer = osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT);
        if (!netDevice->ReceiveBuffer)
        {
                DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", netDevice->ReceiveBufferSize);
@@ -314,14 +311,14 @@ NetVscInitializeReceiveBufferWithNetVsp(
                goto Cleanup;
        }
 
-       /* WaitEventWait(ext->ChannelInitEvent); */
+       /* osd_WaitEventWait(ext->ChannelInitEvent); */
 
        /* Notify the NetVsp of the gpadl handle */
        DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer...");
 
        initPacket = &netDevice->ChannelInitPacket;
 
-       memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+       memset(initPacket, 0, sizeof(struct nvsp_message));
 
     initPacket->Header.MessageType = NvspMessage1TypeSendReceiveBuffer;
     initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->ReceiveBufferGpadlHandle;
@@ -330,7 +327,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
        /* Send the gpadl notification request */
        ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                        initPacket,
-                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                        (unsigned long)initPacket,
                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                        VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -340,7 +337,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
                goto Cleanup;
        }
 
-       WaitEventWait(netDevice->ChannelInitEvent);
+       osd_WaitEventWait(netDevice->ChannelInitEvent);
 
        /* Check the response */
        if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess)
@@ -358,7 +355,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
 
        netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections;
 
-       netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION), GFP_KERNEL);
+       netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL);
        if (netDevice->ReceiveSections == NULL)
        {
                ret = -1;
@@ -367,7 +364,7 @@ NetVscInitializeReceiveBufferWithNetVsp(
 
        memcpy(netDevice->ReceiveSections,
                initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections,
-               netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION));
+               netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section));
 
        DPRINT_INFO(NETVSC,
                "Receive sections info (count %d, offset %d, endoffset %d, suballoc size %d, num suballocs %d)",
@@ -397,12 +394,12 @@ Exit:
 
 static int
 NetVscInitializeSendBufferWithNetVsp(
-       DEVICE_OBJECT   *Device
+       struct hv_device *Device
        )
 {
        int ret=0;
        struct NETVSC_DEVICE *netDevice;
-       NVSP_MESSAGE *initPacket;
+       struct nvsp_message *initPacket;
 
        DPRINT_ENTER(NETVSC);
 
@@ -416,7 +413,7 @@ NetVscInitializeSendBufferWithNetVsp(
        ASSERT(netDevice->SendBufferSize > 0);
        ASSERT((netDevice->SendBufferSize & (PAGE_SIZE-1)) == 0); /* page-size grandularity */
 
-       netDevice->SendBuffer = PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT);
+       netDevice->SendBuffer = osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT);
        if (!netDevice->SendBuffer)
        {
                DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", netDevice->SendBufferSize);
@@ -443,14 +440,14 @@ NetVscInitializeSendBufferWithNetVsp(
                goto Cleanup;
        }
 
-       /* WaitEventWait(ext->ChannelInitEvent); */
+       /* osd_WaitEventWait(ext->ChannelInitEvent); */
 
        /* Notify the NetVsp of the gpadl handle */
        DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer...");
 
        initPacket = &netDevice->ChannelInitPacket;
 
-       memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+       memset(initPacket, 0, sizeof(struct nvsp_message));
 
     initPacket->Header.MessageType = NvspMessage1TypeSendSendBuffer;
     initPacket->Messages.Version1Messages.SendReceiveBuffer.GpadlHandle = netDevice->SendBufferGpadlHandle;
@@ -459,7 +456,7 @@ NetVscInitializeSendBufferWithNetVsp(
        /* Send the gpadl notification request */
        ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                        initPacket,
-                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                        (unsigned long)initPacket,
                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                        VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -469,7 +466,7 @@ NetVscInitializeSendBufferWithNetVsp(
                goto Cleanup;
        }
 
-       WaitEventWait(netDevice->ChannelInitEvent);
+       osd_WaitEventWait(netDevice->ChannelInitEvent);
 
        /* Check the response */
        if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess)
@@ -499,7 +496,7 @@ NetVscDestroyReceiveBuffer(
        struct NETVSC_DEVICE    *NetDevice
        )
 {
-       NVSP_MESSAGE *revokePacket;
+       struct nvsp_message *revokePacket;
        int ret=0;
 
 
@@ -517,14 +514,14 @@ NetVscDestroyReceiveBuffer(
 
                /* Send the revoke receive buffer */
                revokePacket = &NetDevice->RevokePacket;
-               memset(revokePacket, 0, sizeof(NVSP_MESSAGE));
+               memset(revokePacket, 0, sizeof(struct nvsp_message));
 
                revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer;
                revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID;
 
                ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
                                                                                                                                                        revokePacket,
-                                                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                                                        (unsigned long)revokePacket,
                                                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                                                        0);
@@ -563,7 +560,7 @@ NetVscDestroyReceiveBuffer(
                DPRINT_INFO(NETVSC, "Freeing up receive buffer...");
 
                /* Free up the receive buffer */
-               PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT);
+               osd_PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT);
                NetDevice->ReceiveBuffer = NULL;
        }
 
@@ -587,7 +584,7 @@ NetVscDestroySendBuffer(
        struct NETVSC_DEVICE    *NetDevice
        )
 {
-       NVSP_MESSAGE *revokePacket;
+       struct nvsp_message *revokePacket;
        int ret=0;
 
 
@@ -605,14 +602,14 @@ NetVscDestroySendBuffer(
 
                /* Send the revoke send buffer */
                revokePacket = &NetDevice->RevokePacket;
-               memset(revokePacket, 0, sizeof(NVSP_MESSAGE));
+               memset(revokePacket, 0, sizeof(struct nvsp_message));
 
                revokePacket->Header.MessageType = NvspMessage1TypeRevokeSendBuffer;
                revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID;
 
                ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device,
                                                                                                                                                        revokePacket,
-                                                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                                                        (unsigned long)revokePacket,
                                                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                                                        0);
@@ -648,7 +645,7 @@ NetVscDestroySendBuffer(
                DPRINT_INFO(NETVSC, "Freeing up send buffer...");
 
                /* Free up the receive buffer */
-               PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT);
+               osd_PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT);
                NetDevice->SendBuffer = NULL;
        }
 
@@ -661,12 +658,12 @@ NetVscDestroySendBuffer(
 
 static int
 NetVscConnectToVsp(
-       DEVICE_OBJECT   *Device
+       struct hv_device *Device
        )
 {
        int ret=0;
        struct NETVSC_DEVICE *netDevice;
-       NVSP_MESSAGE *initPacket;
+       struct nvsp_message *initPacket;
        int ndisVersion;
 
        DPRINT_ENTER(NETVSC);
@@ -681,7 +678,7 @@ NetVscConnectToVsp(
 
        initPacket = &netDevice->ChannelInitPacket;
 
-       memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+       memset(initPacket, 0, sizeof(struct nvsp_message));
        initPacket->Header.MessageType = NvspMessageTypeInit;
     initPacket->Messages.InitMessages.Init.MinProtocolVersion = NVSP_MIN_PROTOCOL_VERSION;
     initPacket->Messages.InitMessages.Init.MaxProtocolVersion = NVSP_MAX_PROTOCOL_VERSION;
@@ -691,7 +688,7 @@ NetVscConnectToVsp(
        /* Send the init request */
        ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                        initPacket,
-                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                        (unsigned long)initPacket,
                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                        VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -702,7 +699,7 @@ NetVscConnectToVsp(
                goto Cleanup;
        }
 
-       WaitEventWait(netDevice->ChannelInitEvent);
+       osd_WaitEventWait(netDevice->ChannelInitEvent);
 
        /* Now, check the response */
        /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */
@@ -727,7 +724,7 @@ NetVscConnectToVsp(
        DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion...");
 
        /* Send the ndis version */
-       memset(initPacket, 0, sizeof(NVSP_MESSAGE));
+       memset(initPacket, 0, sizeof(struct nvsp_message));
 
     ndisVersion = 0x00050000;
 
@@ -738,7 +735,7 @@ NetVscConnectToVsp(
        /* Send the init request */
        ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                        initPacket,
-                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                        (unsigned long)initPacket,
                                                                                                                        VmbusPacketTypeDataInBand,
                                                                                                                        0);
@@ -754,7 +751,7 @@ NetVscConnectToVsp(
         * packet) since our Vmbus always set the
         * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag
         */
-        /* WaitEventWait(NetVscChannel->ChannelInitEvent); */
+        /* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */
 
        /* Post the big receive buffer to NetVSP */
        ret = NetVscInitializeReceiveBufferWithNetVsp(Device);
@@ -792,9 +789,9 @@ Description:
        Callback when the device belonging to this driver is added
 
 --*/
-int
+static int
 NetVscOnDeviceAdd(
-       DEVICE_OBJECT   *Device,
+       struct hv_device *Device,
        void                    *AdditionalInfo
        )
 {
@@ -802,10 +799,10 @@ NetVscOnDeviceAdd(
        int i;
 
        struct NETVSC_DEVICE *netDevice;
-       NETVSC_PACKET* packet;
+       struct hv_netvsc_packet *packet;
        LIST_ENTRY *entry;
 
-       NETVSC_DRIVER_OBJECT *netDriver = (NETVSC_DRIVER_OBJECT*) Device->Driver;;
+       struct netvsc_driver *netDriver = (struct netvsc_driver *)Device->Driver;
 
        DPRINT_ENTER(NETVSC);
 
@@ -828,7 +825,7 @@ NetVscOnDeviceAdd(
 
        for (i=0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++)
        {
-               packet = kzalloc(sizeof(NETVSC_PACKET) + (NETVSC_RECEIVE_SG_COUNT* sizeof(PAGE_BUFFER)), GFP_KERNEL);
+               packet = kzalloc(sizeof(struct hv_netvsc_packet) + (NETVSC_RECEIVE_SG_COUNT* sizeof(struct hv_page_buffer)), GFP_KERNEL);
                if (!packet)
                {
                        DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts for receive pool (wanted %d got %d)", NETVSC_RECEIVE_PACKETLIST_COUNT, i);
@@ -837,7 +834,7 @@ NetVscOnDeviceAdd(
 
                INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry);
        }
-       netDevice->ChannelInitEvent = WaitEventCreate();
+       netDevice->ChannelInitEvent = osd_WaitEventCreate();
 
        /* Open the channel */
        ret = Device->Driver->VmbusChannelInterface.Open(Device,
@@ -880,12 +877,12 @@ Cleanup:
 
        if (netDevice)
        {
-               WaitEventClose(netDevice->ChannelInitEvent);
+               kfree(netDevice->ChannelInitEvent);
 
                while (!IsListEmpty(&netDevice->ReceivePacketList))
                {
                        entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-                       packet = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+                       packet = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry);
                        kfree(packet);
                }
 
@@ -909,13 +906,13 @@ Description:
        Callback when the root bus device is removed
 
 --*/
-int
+static int
 NetVscOnDeviceRemove(
-       DEVICE_OBJECT *Device
+       struct hv_device *Device
        )
 {
        struct NETVSC_DEVICE *netDevice;
-       NETVSC_PACKET *netvscPacket;
+       struct hv_netvsc_packet *netvscPacket;
        int ret=0;
        LIST_ENTRY *entry;
 
@@ -932,9 +929,9 @@ NetVscOnDeviceRemove(
        }
 
        /* Wait for all send completions */
-       while (netDevice->NumOutstandingSends)
+       while (atomic_read(&netDevice->NumOutstandingSends))
        {
-               DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends);
+               DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", atomic_read(&netDevice->NumOutstandingSends));
 
                udelay(100);
        }
@@ -958,12 +955,12 @@ NetVscOnDeviceRemove(
        while (!IsListEmpty(&netDevice->ReceivePacketList))
        {
                entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-               netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+               netvscPacket = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry);
 
                kfree(netvscPacket);
        }
 
-       WaitEventClose(netDevice->ChannelInitEvent);
+       kfree(netDevice->ChannelInitEvent);
        FreeNetDevice(netDevice);
 
        DPRINT_EXIT(NETVSC);
@@ -981,9 +978,9 @@ Description:
        Perform any cleanup when the driver is removed
 
 --*/
-void
+static void
 NetVscOnCleanup(
-       DRIVER_OBJECT *drv
+       struct hv_driver *drv
        )
 {
        DPRINT_ENTER(NETVSC);
@@ -993,13 +990,13 @@ NetVscOnCleanup(
 
 static void
 NetVscOnSendCompletion(
-       DEVICE_OBJECT           *Device,
-       VMPACKET_DESCRIPTOR *Packet
+       struct hv_device *Device,
+       struct vmpacket_descriptor *Packet
        )
 {
        struct NETVSC_DEVICE *netDevice;
-       NVSP_MESSAGE *nvspPacket;
-       NETVSC_PACKET *nvscPacket;
+       struct nvsp_message *nvspPacket;
+       struct hv_netvsc_packet *nvscPacket;
 
        DPRINT_ENTER(NETVSC);
 
@@ -1011,7 +1008,7 @@ NetVscOnSendCompletion(
                return;
        }
 
-       nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3));
+       nvspPacket = (struct nvsp_message *)((unsigned long)Packet + (Packet->DataOffset8 << 3));
 
        DPRINT_DBG(NETVSC, "send completion packet - type %d", nvspPacket->Header.MessageType);
 
@@ -1020,19 +1017,19 @@ NetVscOnSendCompletion(
                nvspPacket->Header.MessageType == NvspMessage1TypeSendSendBufferComplete)
        {
                /* Copy the response back */
-               memcpy(&netDevice->ChannelInitPacket, nvspPacket, sizeof(NVSP_MESSAGE));
-               WaitEventSet(netDevice->ChannelInitEvent);
+               memcpy(&netDevice->ChannelInitPacket, nvspPacket, sizeof(struct nvsp_message));
+               osd_WaitEventSet(netDevice->ChannelInitEvent);
        }
        else if (nvspPacket->Header.MessageType == NvspMessage1TypeSendRNDISPacketComplete)
        {
                /* Get the send context */
-               nvscPacket = (NETVSC_PACKET *)(unsigned long)Packet->TransactionId;
+               nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId;
                ASSERT(nvscPacket);
 
                /* Notify the layer above us */
                nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext);
 
-               InterlockedDecrement(&netDevice->NumOutstandingSends);
+               atomic_dec(&netDevice->NumOutstandingSends);
        }
        else
        {
@@ -1047,14 +1044,14 @@ NetVscOnSendCompletion(
 
 static int
 NetVscOnSend(
-       DEVICE_OBJECT *Device,
-       NETVSC_PACKET *Packet
+       struct hv_device *Device,
+       struct hv_netvsc_packet *Packet
        )
 {
        struct NETVSC_DEVICE *netDevice;
        int ret=0;
 
-       NVSP_MESSAGE sendMessage;
+       struct nvsp_message sendMessage;
 
        DPRINT_ENTER(NETVSC);
 
@@ -1082,14 +1079,14 @@ NetVscOnSend(
                                                                                                                                                        Packet->PageBuffers,
                                                                                                                                                        Packet->PageBufferCount,
                                                                                                                                                        &sendMessage,
-                                                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                                                        (unsigned long)Packet);
        }
        else
        {
                ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                                &sendMessage,
-                                                                                                                               sizeof(NVSP_MESSAGE),
+                                                                                                                               sizeof(struct nvsp_message),
                                                                                                                                (unsigned long)Packet,
                                                                                                                                VmbusPacketTypeDataInBand,
                                                                                                                                VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -1101,7 +1098,7 @@ NetVscOnSend(
                DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret);
        }
 
-       InterlockedIncrement(&netDevice->NumOutstandingSends);
+       atomic_inc(&netDevice->NumOutstandingSends);
        PutNetDevice(Device);
 
        DPRINT_EXIT(NETVSC);
@@ -1111,19 +1108,19 @@ NetVscOnSend(
 
 static void
 NetVscOnReceive(
-       DEVICE_OBJECT           *Device,
-       VMPACKET_DESCRIPTOR *Packet
+       struct hv_device *Device,
+       struct vmpacket_descriptor *Packet
        )
 {
        struct NETVSC_DEVICE *netDevice;
-       VMTRANSFER_PAGE_PACKET_HEADER *vmxferpagePacket;
-       NVSP_MESSAGE *nvspPacket;
-       NETVSC_PACKET *netvscPacket=NULL;
+       struct vmtransfer_page_packet_header *vmxferpagePacket;
+       struct nvsp_message *nvspPacket;
+       struct hv_netvsc_packet *netvscPacket=NULL;
        LIST_ENTRY* entry;
        unsigned long start;
        unsigned long end, endVirtual;
-       /* NETVSC_DRIVER_OBJECT *netvscDriver; */
-       XFERPAGE_PACKET *xferpagePacket=NULL;
+       /* struct netvsc_driver *netvscDriver; */
+       struct xferpage_packet *xferpagePacket=NULL;
        LIST_ENTRY listHead;
 
        int i=0, j=0;
@@ -1148,7 +1145,7 @@ NetVscOnReceive(
                return;
        }
 
-       nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3));
+       nvspPacket = (struct nvsp_message*)((unsigned long)Packet + (Packet->DataOffset8 << 3));
 
        /* Make sure this is a valid nvsp packet */
        if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket )
@@ -1160,7 +1157,7 @@ NetVscOnReceive(
 
        DPRINT_DBG(NETVSC, "NVSP packet received - type %d", nvspPacket->Header.MessageType);
 
-       vmxferpagePacket = (VMTRANSFER_PAGE_PACKET_HEADER*)Packet;
+       vmxferpagePacket = (struct vmtransfer_page_packet_header *)Packet;
 
        if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID)
        {
@@ -1183,7 +1180,7 @@ NetVscOnReceive(
        while (!IsListEmpty(&netDevice->ReceivePacketList))
        {
                entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList);
-               netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+               netvscPacket = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry);
 
                INSERT_TAIL_LIST(&listHead, &netvscPacket->ListEntry);
 
@@ -1206,7 +1203,7 @@ NetVscOnReceive(
                for (i=count; i != 0; i--)
                {
                        entry = REMOVE_HEAD_LIST(&listHead);
-                       netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+                       netvscPacket = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry);
 
                        INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &netvscPacket->ListEntry);
                }
@@ -1220,7 +1217,7 @@ NetVscOnReceive(
 
        /* Remove the 1st packet to represent the xfer page packet itself */
        entry = REMOVE_HEAD_LIST(&listHead);
-       xferpagePacket = CONTAINING_RECORD(entry, XFERPAGE_PACKET, ListEntry);
+       xferpagePacket = CONTAINING_RECORD(entry, struct xferpage_packet, ListEntry);
        xferpagePacket->Count = count - 1; /* This is how much we can satisfy */
        ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= vmxferpagePacket->RangeCount);
 
@@ -1233,7 +1230,7 @@ NetVscOnReceive(
        for (i=0; i < (count - 1); i++)
        {
                entry = REMOVE_HEAD_LIST(&listHead);
-               netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry);
+               netvscPacket = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry);
 
                /* Initialize the netvsc packet */
                netvscPacket->XferPagePacket = xferpagePacket;
@@ -1249,13 +1246,13 @@ NetVscOnReceive(
 
                netvscPacket->PageBuffers[0].Length = vmxferpagePacket->Ranges[i].ByteCount;
 
-               start = GetPhysicalAddress((void*)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
+               start = virt_to_phys((void*)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset));
 
                netvscPacket->PageBuffers[0].Pfn = start >> PAGE_SHIFT;
                endVirtual = (unsigned long)netDevice->ReceiveBuffer
                    + vmxferpagePacket->Ranges[i].ByteOffset
                    + vmxferpagePacket->Ranges[i].ByteCount -1;
-               end = GetPhysicalAddress((void*)endVirtual);
+               end = virt_to_phys((void*)endVirtual);
 
                /* Calculate the page relative offset */
                netvscPacket->PageBuffers[0].Offset = vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE -1);
@@ -1274,7 +1271,7 @@ NetVscOnReceive(
                            bytesRemain -= PAGE_SIZE;
                        }
                        netvscPacket->PageBuffers[j].Pfn =
-                           GetPhysicalAddress((void*)(endVirtual - bytesRemain)) >> PAGE_SHIFT;
+                           virt_to_phys((void*)(endVirtual - bytesRemain)) >> PAGE_SHIFT;
                        netvscPacket->PageBufferCount++;
                        if (bytesRemain == 0)
                            break;
@@ -1290,7 +1287,7 @@ NetVscOnReceive(
                        netvscPacket->PageBuffers[0].Length);
 
                /* Pass it to the upper layer */
-               ((NETVSC_DRIVER_OBJECT*)Device->Driver)->OnReceiveCallback(Device, netvscPacket);
+               ((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket);
 
                NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext);
        }
@@ -1304,11 +1301,11 @@ NetVscOnReceive(
 
 static void
 NetVscSendReceiveCompletion(
-       DEVICE_OBJECT   *Device,
+       struct hv_device *Device,
        u64                     TransactionId
        )
 {
-       NVSP_MESSAGE recvcompMessage;
+       struct nvsp_message recvcompMessage;
        int retries=0;
        int ret=0;
 
@@ -1323,7 +1320,7 @@ retry_send_cmplt:
        /* Send the completion */
        ret = Device->Driver->VmbusChannelInterface.SendPacket(Device,
                                                                                                                        &recvcompMessage,
-                                                                                                                       sizeof(NVSP_MESSAGE),
+                                                                                                                       sizeof(struct nvsp_message),
                                                                                                                        TransactionId,
                                                                                                                        VmbusPacketTypeCompletion,
                                                                                                                        0);
@@ -1357,8 +1354,8 @@ static void
 NetVscOnReceiveCompletion(
        void * Context)
 {
-       NETVSC_PACKET *packet = (NETVSC_PACKET*)Context;
-       DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device;
+       struct hv_netvsc_packet *packet = (struct hv_netvsc_packet*)Context;
+       struct hv_device *device = (struct hv_device*)packet->Device;
        struct NETVSC_DEVICE *netDevice;
        u64     transactionId=0;
        bool fSendReceiveComp = false;
@@ -1417,13 +1414,13 @@ NetVscOnChannelCallback(
 {
        const int netPacketSize=2048;
        int ret=0;
-       DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context;
+       struct hv_device *device=(struct hv_device*)Context;
        struct NETVSC_DEVICE *netDevice;
 
        u32 bytesRecvd;
        u64 requestId;
        unsigned char packet[netPacketSize];
-       VMPACKET_DESCRIPTOR *desc;
+       struct vmpacket_descriptor *desc;
        unsigned char   *buffer=packet;
        int             bufferlen=netPacketSize;
 
@@ -1454,7 +1451,7 @@ NetVscOnChannelCallback(
                        {
                                DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", bytesRecvd, requestId);
 
-                               desc = (VMPACKET_DESCRIPTOR*)buffer;
+                               desc = (struct vmpacket_descriptor*)buffer;
                                switch (desc->Type)
                                {
                                        case VmbusPacketTypeCompletion: