X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=drivers%2Fstaging%2Fhv%2FNetVsc.c;h=fb1cbf02ce5a2416d8f8bff72baad7f51784afb2;hb=490707d2aaf4b142fb2fb53d8065dbae95b41377;hp=b4b701012e94d5401ded236e92a681919bd80147;hpb=c18b5aed9d8c37db5e5835eb7d25f99f62a7f06a;p=~andy%2Flinux diff --git a/drivers/staging/hv/NetVsc.c b/drivers/staging/hv/NetVsc.c index b4b701012e9..fb1cbf02ce5 100644 --- a/drivers/staging/hv/NetVsc.c +++ b/drivers/staging/hv/NetVsc.c @@ -23,39 +23,40 @@ #include #include #include -#include "include/logging.h" +#include +#include "osd.h" +#include "logging.h" #include "NetVsc.h" #include "RndisFilter.h" -// -// Globals -// +/* Globals */ 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} +/* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ +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 -// +/* 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 @@ -65,45 +66,45 @@ NetVscOnChannelCallback( static int NetVscInitializeSendBufferWithNetVsp( - DEVICE_OBJECT *Device + struct hv_device *Device ); static int NetVscInitializeReceiveBufferWithNetVsp( - DEVICE_OBJECT *Device + struct hv_device *Device ); static int NetVscDestroySendBuffer( - NETVSC_DEVICE *NetDevice + struct NETVSC_DEVICE *NetDevice ); static int NetVscDestroyReceiveBuffer( - NETVSC_DEVICE *NetDevice + struct NETVSC_DEVICE *NetDevice ); 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 @@ -113,20 +114,20 @@ NetVscOnReceiveCompletion( static void NetVscSendReceiveCompletion( - DEVICE_OBJECT *Device, + struct hv_device *Device, u64 TransactionId ); -static inline NETVSC_DEVICE* AllocNetDevice(DEVICE_OBJECT *Device) +static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = kzalloc(sizeof(NETVSC_DEVICE), GFP_KERNEL); + netDevice = kzalloc(sizeof(struct NETVSC_DEVICE), GFP_KERNEL); if (!netDevice) return NULL; - // Set to 2 to allow both inbound and outbound traffic - InterlockedCompareExchange(&netDevice->RefCount, 2, 0); + /* Set to 2 to allow both inbound and outbound traffic */ + atomic_cmpxchg(&netDevice->RefCount, 0, 2); netDevice->Device = Device; Device->Extension = netDevice; @@ -134,70 +135,62 @@ static inline NETVSC_DEVICE* AllocNetDevice(DEVICE_OBJECT *Device) return netDevice; } -static inline void FreeNetDevice(NETVSC_DEVICE *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 NETVSC_DEVICE* GetOutboundNetDevice(DEVICE_OBJECT *Device) +/* Get the net device object iff exists and its refcount > 1 */ +static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = (NETVSC_DEVICE*)Device->Extension; - if (netDevice && netDevice->RefCount > 1) - { - InterlockedIncrement(&netDevice->RefCount); - } + netDevice = (struct NETVSC_DEVICE*)Device->Extension; + 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 NETVSC_DEVICE* GetInboundNetDevice(DEVICE_OBJECT *Device) +/* Get the net device object iff exists and its refcount > 0 */ +static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = (NETVSC_DEVICE*)Device->Extension; - if (netDevice && netDevice->RefCount) - { - InterlockedIncrement(&netDevice->RefCount); - } + netDevice = (struct NETVSC_DEVICE*)Device->Extension; + 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) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = (NETVSC_DEVICE*)Device->Extension; + netDevice = (struct NETVSC_DEVICE*)Device->Extension; ASSERT(netDevice); - InterlockedDecrement(&netDevice->RefCount); + atomic_dec(&netDevice->RefCount); } -static inline NETVSC_DEVICE* ReleaseOutboundNetDevice(DEVICE_OBJECT *Device) +static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = (NETVSC_DEVICE*)Device->Extension; + netDevice = (struct NETVSC_DEVICE*)Device->Extension; if (netDevice == NULL) return NULL; - // Busy wait until the ref drop to 2, then set it to 1 - while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2) + /* Busy wait until the ref drop to 2, then set it to 1 */ + while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2) { udelay(100); } @@ -205,16 +198,16 @@ static inline NETVSC_DEVICE* ReleaseOutboundNetDevice(DEVICE_OBJECT *Device) return netDevice; } -static inline NETVSC_DEVICE* ReleaseInboundNetDevice(DEVICE_OBJECT *Device) +static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device) { - NETVSC_DEVICE *netDevice; + struct NETVSC_DEVICE *netDevice; - netDevice = (NETVSC_DEVICE*)Device->Extension; + netDevice = (struct NETVSC_DEVICE*)Device->Extension; if (netDevice == NULL) return NULL; - // Busy wait until the ref drop to 1, then set it to 0 - while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1) + /* Busy wait until the ref drop to 1, then set it to 0 */ + while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1) { udelay(100); } @@ -235,28 +228,28 @@ 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)=%d, sizeof(NVSP_MESSAGE)=%d, sizeof(VMTRANSFER_PAGE_PACKET_HEADER)=%d", - 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 + /* 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 + /* Make sure it is set by the caller */ ASSERT(driver->OnReceiveCallback); ASSERT(driver->OnLinkStatusChanged); - // Setup the dispatch table + /* Setup the dispatch table */ driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; driver->Base.OnCleanup = NetVscOnCleanup; @@ -272,12 +265,12 @@ NetVscInitialize( static int NetVscInitializeReceiveBufferWithNetVsp( - DEVICE_OBJECT *Device + struct hv_device *Device ) { int ret=0; - NETVSC_DEVICE *netDevice; - NVSP_MESSAGE *initPacket; + struct NETVSC_DEVICE *netDevice; + struct nvsp_message *initPacket; DPRINT_ENTER(NETVSC); @@ -289,22 +282,24 @@ NetVscInitializeReceiveBufferWithNetVsp( return -1; } ASSERT(netDevice->ReceiveBufferSize > 0); - ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE-1)) == 0); // page-size grandularity + 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); ret = -1; goto Cleanup; } - ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer + ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE-1)) == 0); /* page-aligned buffer */ DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL..."); - // Establish the gpadl handle for this buffer on this channel. - // Note: This call uses the vmbus connection rather than the channel to establish - // the gpadl handle. + /* + * Establish the gpadl handle for this buffer on this + * channel. Note: This call uses the vmbus connection rather + * than the channel to establish the gpadl handle. + */ ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, netDevice->ReceiveBuffer, netDevice->ReceiveBufferSize, @@ -316,23 +311,23 @@ NetVscInitializeReceiveBufferWithNetVsp( goto Cleanup; } - //WaitEventWait(ext->ChannelInitEvent); + /* osd_WaitEventWait(ext->ChannelInitEvent); */ - // Notify the NetVsp of the gpadl handle + /* 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; initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; - // Send the gpadl notification request + /* 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); @@ -342,9 +337,9 @@ NetVscInitializeReceiveBufferWithNetVsp( goto Cleanup; } - WaitEventWait(netDevice->ChannelInitEvent); + osd_WaitEventWait(netDevice->ChannelInitEvent); - // Check the response + /* Check the response */ if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) { DPRINT_ERR(NETVSC, @@ -354,13 +349,13 @@ NetVscInitializeReceiveBufferWithNetVsp( goto Cleanup; } - // Parse the response + /* Parse the response */ ASSERT(netDevice->ReceiveSectionCount == 0); ASSERT(netDevice->ReceiveSections == NULL); 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; @@ -369,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)", @@ -377,7 +372,7 @@ NetVscInitializeReceiveBufferWithNetVsp( netDevice->ReceiveSections[0].SubAllocationSize, netDevice->ReceiveSections[0].NumSubAllocations); - //For 1st release, there should only be 1 section that represents the entire receive buffer + /* For 1st release, there should only be 1 section that represents the entire receive buffer */ if (netDevice->ReceiveSectionCount != 1 || netDevice->ReceiveSections->Offset != 0 ) { @@ -399,12 +394,12 @@ Exit: static int NetVscInitializeSendBufferWithNetVsp( - DEVICE_OBJECT *Device + struct hv_device *Device ) { int ret=0; - NETVSC_DEVICE *netDevice; - NVSP_MESSAGE *initPacket; + struct NETVSC_DEVICE *netDevice; + struct nvsp_message *initPacket; DPRINT_ENTER(NETVSC); @@ -416,26 +411,28 @@ NetVscInitializeSendBufferWithNetVsp( return -1; } ASSERT(netDevice->SendBufferSize > 0); - ASSERT((netDevice->SendBufferSize & (PAGE_SIZE-1)) == 0); // page-size grandularity + 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); ret = -1; goto Cleanup; } - ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE-1)) == 0); // page-aligned buffer + ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE-1)) == 0); /* page-aligned buffer */ DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL..."); - // Establish the gpadl handle for this buffer on this channel. - // Note: This call uses the vmbus connection rather than the channel to establish - // the gpadl handle. + /* + * Establish the gpadl handle for this buffer on this + * channel. Note: This call uses the vmbus connection rather + * than the channel to establish the gpadl handle. + */ ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, - netDevice->SendBuffer, - netDevice->SendBufferSize, - &netDevice->SendBufferGpadlHandle); + netDevice->SendBuffer, + netDevice->SendBufferSize, + &netDevice->SendBufferGpadlHandle); if (ret != 0) { @@ -443,23 +440,23 @@ NetVscInitializeSendBufferWithNetVsp( goto Cleanup; } - //WaitEventWait(ext->ChannelInitEvent); + /* osd_WaitEventWait(ext->ChannelInitEvent); */ - // Notify the NetVsp of the gpadl handle + /* 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; initPacket->Messages.Version1Messages.SendReceiveBuffer.Id = NETVSC_SEND_BUFFER_ID; - // Send the gpadl notification request + /* 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,9 +466,9 @@ NetVscInitializeSendBufferWithNetVsp( goto Cleanup; } - WaitEventWait(netDevice->ChannelInitEvent); + osd_WaitEventWait(netDevice->ChannelInitEvent); - // Check the response + /* Check the response */ if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) { DPRINT_ERR(NETVSC, @@ -496,35 +493,42 @@ Exit: static int NetVscDestroyReceiveBuffer( - NETVSC_DEVICE *NetDevice + struct NETVSC_DEVICE *NetDevice ) { - NVSP_MESSAGE *revokePacket; + struct nvsp_message *revokePacket; int ret=0; DPRINT_ENTER(NETVSC); - // If we got a section count, it means we received a SendReceiveBufferComplete msg - // (ie sent NvspMessage1TypeSendReceiveBuffer msg) therefore, we need to send a revoke msg here + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ if (NetDevice->ReceiveSectionCount) { DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeReceiveBuffer..."); - // Send the revoke receive buffer + /* 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); - // If we failed here, we might as well return and have a leak rather than continue and a bugchk + /* + * If we failed here, we might as well return and + * have a leak rather than continue and a bugchk + */ if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send revoke receive buffer to netvsp"); @@ -533,7 +537,7 @@ NetVscDestroyReceiveBuffer( } } - // Teardown the gpadl on the vsp end + /* Teardown the gpadl on the vsp end */ if (NetDevice->ReceiveBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); @@ -541,7 +545,7 @@ NetVscDestroyReceiveBuffer( ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, NetDevice->ReceiveBufferGpadlHandle); - // If we failed here, we might as well return and have a leak rather than continue and a bugchk + /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ if (ret != 0) { DPRINT_ERR(NETVSC, "unable to teardown receive buffer's gpadl"); @@ -555,8 +559,8 @@ NetVscDestroyReceiveBuffer( { DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); - // Free up the receive buffer - PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT); + /* Free up the receive buffer */ + osd_PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT); NetDevice->ReceiveBuffer = NULL; } @@ -577,35 +581,39 @@ NetVscDestroyReceiveBuffer( static int NetVscDestroySendBuffer( - NETVSC_DEVICE *NetDevice + struct NETVSC_DEVICE *NetDevice ) { - NVSP_MESSAGE *revokePacket; + struct nvsp_message *revokePacket; int ret=0; DPRINT_ENTER(NETVSC); - // If we got a section count, it means we received a SendReceiveBufferComplete msg - // (ie sent NvspMessage1TypeSendReceiveBuffer msg) therefore, we need to send a revoke msg here + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ if (NetDevice->SendSectionSize) { DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeSendBuffer..."); - // Send the revoke send buffer + /* 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); - // If we failed here, we might as well return and have a leak rather than continue and a bugchk + /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send revoke send buffer to netvsp"); @@ -614,7 +622,7 @@ NetVscDestroySendBuffer( } } - // Teardown the gpadl on the vsp end + /* Teardown the gpadl on the vsp end */ if (NetDevice->SendBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); @@ -622,7 +630,7 @@ NetVscDestroySendBuffer( ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, NetDevice->SendBufferGpadlHandle); - // If we failed here, we might as well return and have a leak rather than continue and a bugchk + /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ if (ret != 0) { DPRINT_ERR(NETVSC, "unable to teardown send buffer's gpadl"); @@ -636,8 +644,8 @@ NetVscDestroySendBuffer( { DPRINT_INFO(NETVSC, "Freeing up send buffer..."); - // Free up the receive buffer - PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT); + /* Free up the receive buffer */ + osd_PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT); NetDevice->SendBuffer = NULL; } @@ -650,12 +658,12 @@ NetVscDestroySendBuffer( static int NetVscConnectToVsp( - DEVICE_OBJECT *Device + struct hv_device *Device ) { int ret=0; - NETVSC_DEVICE *netDevice; - NVSP_MESSAGE *initPacket; + struct NETVSC_DEVICE *netDevice; + struct nvsp_message *initPacket; int ndisVersion; DPRINT_ENTER(NETVSC); @@ -670,17 +678,17 @@ 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; DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); - // Send the init request + /* 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); @@ -691,10 +699,10 @@ NetVscConnectToVsp( goto Cleanup; } - WaitEventWait(netDevice->ChannelInitEvent); + osd_WaitEventWait(netDevice->ChannelInitEvent); - // Now, check the response - //ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); + /* Now, check the response */ + /* ASSERT(initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength <= MAX_MULTIPAGE_BUFFER_COUNT); */ DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", initPacket->Messages.InitMessages.InitComplete.Status, initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength); @@ -715,8 +723,8 @@ NetVscConnectToVsp( } DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); - // Send the ndis version - memset(initPacket, 0, sizeof(NVSP_MESSAGE)); + /* Send the ndis version */ + memset(initPacket, 0, sizeof(struct nvsp_message)); ndisVersion = 0x00050000; @@ -724,10 +732,10 @@ NetVscConnectToVsp( initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = (ndisVersion & 0xFFFF0000) >> 16; initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = ndisVersion & 0xFFFF; - // Send the init request + /* Send the init request */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, initPacket, - sizeof(NVSP_MESSAGE), + sizeof(struct nvsp_message), (unsigned long)initPacket, VmbusPacketTypeDataInBand, 0); @@ -737,12 +745,15 @@ NetVscConnectToVsp( ret = -1; goto Cleanup; } - // - // BUGBUG - We have to wait for the above msg since the netvsp uses KMCL which acknowledges packet (completion packet) - // since our Vmbus always set the VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag - //WaitEventWait(NetVscChannel->ChannelInitEvent); - - // Post the big receive buffer to NetVSP + /* + * BUGBUG - We have to wait for the above msg since the + * netvsp uses KMCL which acknowledges packet (completion + * packet) since our Vmbus always set the + * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag + */ + /* osd_WaitEventWait(NetVscChannel->ChannelInitEvent); */ + + /* Post the big receive buffer to NetVSP */ ret = NetVscInitializeReceiveBufferWithNetVsp(Device); if (ret == 0) { @@ -757,7 +768,7 @@ Cleanup: static void NetVscDisconnectFromVsp( - NETVSC_DEVICE *NetDevice + struct NETVSC_DEVICE *NetDevice ) { DPRINT_ENTER(NETVSC); @@ -778,20 +789,20 @@ Description: Callback when the device belonging to this driver is added --*/ -int +static int NetVscOnDeviceAdd( - DEVICE_OBJECT *Device, + struct hv_device *Device, void *AdditionalInfo ) { int ret=0; int i; - NETVSC_DEVICE* netDevice; - NETVSC_PACKET* packet; + struct NETVSC_DEVICE *netDevice; + 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); @@ -804,7 +815,7 @@ NetVscOnDeviceAdd( DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", netDevice); - // Initialize the NetVSC channel extension + /* Initialize the NetVSC channel extension */ netDevice->ReceiveBufferSize = NETVSC_RECEIVE_BUFFER_SIZE; spin_lock_init(&netDevice->receive_packet_list_lock); @@ -814,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); @@ -823,16 +834,16 @@ NetVscOnDeviceAdd( INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry); } - netDevice->ChannelInitEvent = WaitEventCreate(); + netDevice->ChannelInitEvent = osd_WaitEventCreate(); - // Open the channel + /* Open the channel */ ret = Device->Driver->VmbusChannelInterface.Open(Device, - netDriver->RingBufferSize, - netDriver->RingBufferSize, - NULL, 0, - NetVscOnChannelCallback, - Device - ); + netDriver->RingBufferSize, + netDriver->RingBufferSize, + NULL, 0, + NetVscOnChannelCallback, + Device + ); if (ret != 0) { @@ -841,10 +852,10 @@ NetVscOnDeviceAdd( goto Cleanup; } - // Channel is opened + /* Channel is opened */ DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***"); - // Connect with the NetVsp + /* Connect with the NetVsp */ ret = NetVscConnectToVsp(Device); if (ret != 0) { @@ -859,19 +870,19 @@ NetVscOnDeviceAdd( return ret; Close: - // Now, we can close the channel safely + /* Now, we can close the channel safely */ Device->Driver->VmbusChannelInterface.Close(Device); 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); } @@ -895,13 +906,13 @@ Description: Callback when the root bus device is removed --*/ -int +static int NetVscOnDeviceRemove( - DEVICE_OBJECT *Device + struct hv_device *Device ) { - NETVSC_DEVICE *netDevice; - NETVSC_PACKET *netvscPacket; + struct NETVSC_DEVICE *netDevice; + struct hv_netvsc_packet *netvscPacket; int ret=0; LIST_ENTRY *entry; @@ -909,7 +920,7 @@ NetVscOnDeviceRemove( DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", Device->Extension); - // Stop outbound traffic ie sends and receives completions + /* Stop outbound traffic ie sends and receives completions */ netDevice = ReleaseOutboundNetDevice(Device); if (!netDevice) { @@ -917,10 +928,10 @@ NetVscOnDeviceRemove( return -1; } - // Wait for all send completions - while (netDevice->NumOutstandingSends) + /* Wait for all send completions */ + 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); } @@ -931,25 +942,25 @@ NetVscOnDeviceRemove( DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", Device->Extension); - // Stop inbound traffic ie receives and sends completions + /* Stop inbound traffic ie receives and sends completions */ netDevice = ReleaseInboundNetDevice(Device); - // At this point, no one should be accessing netDevice except in here + /* At this point, no one should be accessing netDevice except in here */ DPRINT_INFO(NETVSC, "net device (%p) safe to remove", netDevice); - // Now, we can close the channel safely + /* Now, we can close the channel safely */ Device->Driver->VmbusChannelInterface.Close(Device); - // Release all resources + /* Release all resources */ 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); @@ -967,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); @@ -979,13 +990,13 @@ NetVscOnCleanup( static void NetVscOnSendCompletion( - DEVICE_OBJECT *Device, - VMPACKET_DESCRIPTOR *Packet + struct hv_device *Device, + struct vmpacket_descriptor *Packet ) { - NETVSC_DEVICE* netDevice; - NVSP_MESSAGE *nvspPacket; - NETVSC_PACKET *nvscPacket; + struct NETVSC_DEVICE *netDevice; + struct nvsp_message *nvspPacket; + struct hv_netvsc_packet *nvscPacket; DPRINT_ENTER(NETVSC); @@ -997,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); @@ -1005,20 +1016,20 @@ NetVscOnSendCompletion( nvspPacket->Header.MessageType == NvspMessage1TypeSendReceiveBufferComplete || nvspPacket->Header.MessageType == NvspMessage1TypeSendSendBufferComplete) { - // Copy the response back - memcpy(&netDevice->ChannelInitPacket, nvspPacket, sizeof(NVSP_MESSAGE)); - WaitEventSet(netDevice->ChannelInitEvent); + /* Copy the response back */ + 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; + /* Get the send context */ + nvscPacket = (struct hv_netvsc_packet *)(unsigned long)Packet->TransactionId; ASSERT(nvscPacket); - // Notify the layer above us + /* Notify the layer above us */ nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); - InterlockedDecrement(&netDevice->NumOutstandingSends); + atomic_dec(&netDevice->NumOutstandingSends); } else { @@ -1033,14 +1044,14 @@ NetVscOnSendCompletion( static int NetVscOnSend( - DEVICE_OBJECT *Device, - NETVSC_PACKET *Packet + struct hv_device *Device, + struct hv_netvsc_packet *Packet ) { - NETVSC_DEVICE* netDevice; + struct NETVSC_DEVICE *netDevice; int ret=0; - NVSP_MESSAGE sendMessage; + struct nvsp_message sendMessage; DPRINT_ENTER(NETVSC); @@ -1054,11 +1065,11 @@ NetVscOnSend( sendMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacket; if (Packet->IsDataPacket) - sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0;// 0 is RMC_DATA; + sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 0;/* 0 is RMC_DATA; */ else - sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1;// 1 is RMC_CONTROL; + sendMessage.Messages.Version1Messages.SendRNDISPacket.ChannelType = 1;/* 1 is RMC_CONTROL; */ - // Not using send buffer section + /* Not using send buffer section */ sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF; sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; @@ -1068,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); @@ -1087,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); @@ -1097,19 +1108,19 @@ NetVscOnSend( static void NetVscOnReceive( - DEVICE_OBJECT *Device, - VMPACKET_DESCRIPTOR *Packet + struct hv_device *Device, + struct vmpacket_descriptor *Packet ) { - NETVSC_DEVICE* netDevice; - VMTRANSFER_PAGE_PACKET_HEADER *vmxferpagePacket; - NVSP_MESSAGE *nvspPacket; - NETVSC_PACKET *netvscPacket=NULL; + struct NETVSC_DEVICE *netDevice; + 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; @@ -1126,7 +1137,7 @@ NetVscOnReceive( return; } - // All inbound packets other than send completion should be xfer page packet + /* All inbound packets other than send completion should be xfer page packet */ if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) { DPRINT_ERR(NETVSC, "Unknown packet type received - %d", Packet->Type); @@ -1134,9 +1145,9 @@ 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 + /* Make sure this is a valid nvsp packet */ if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket ) { DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", nvspPacket->Header.MessageType); @@ -1146,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) { @@ -1159,13 +1170,17 @@ NetVscOnReceive( INITIALIZE_LIST_HEAD(&listHead); - // Grab free packets (range count + 1) to represent this xfer page packet. +1 to represent - // the xfer page packet itself. We grab it here so that we know exactly how many we can fulfil + /* + * Grab free packets (range count + 1) to represent this xfer + * page packet. +1 to represent the xfer page packet itself. + * We grab it here so that we know exactly how many we can + * fulfil + */ spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); 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); @@ -1174,18 +1189,21 @@ NetVscOnReceive( } spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); - // We need at least 2 netvsc pkts (1 to represent the xfer page and at least 1 for the range) - // i.e. we can handled some of the xfer page packet ranges... + /* + * We need at least 2 netvsc pkts (1 to represent the xfer + * page and at least 1 for the range) i.e. we can handled + * some of the xfer page packet ranges... + */ if (count < 2) { DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. Dropping this xfer page packet completely!", count, vmxferpagePacket->RangeCount+1); - // Return it to the freelist + /* Return it to the freelist */ spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); 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); } @@ -1197,10 +1215,10 @@ NetVscOnReceive( return; } - // Remove the 1st packet to represent the xfer page packet itself + /* Remove the 1st packet to represent the xfer page packet itself */ entry = REMOVE_HEAD_LIST(&listHead); - xferpagePacket = CONTAINING_RECORD(entry, XFERPAGE_PACKET, ListEntry); - xferpagePacket->Count = count - 1; // This is how much we can satisfy + 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); if (xferpagePacket->Count != vmxferpagePacket->RangeCount) @@ -1208,18 +1226,18 @@ NetVscOnReceive( DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer page...got %d", vmxferpagePacket->RangeCount, xferpagePacket->Count); } - // Each range represents 1 RNDIS pkt that contains 1 ethernet frame + /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ 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 + /* Initialize the netvsc packet */ netvscPacket->XferPagePacket = xferpagePacket; netvscPacket->Completion.Recv.OnReceiveCompletion = NetVscOnReceiveCompletion; netvscPacket->Completion.Recv.ReceiveCompletionContext = netvscPacket; netvscPacket->Device = Device; - netvscPacket->Completion.Recv.ReceiveCompletionTid = vmxferpagePacket->d.TransactionId; // Save this so that we can send it back + netvscPacket->Completion.Recv.ReceiveCompletionTid = vmxferpagePacket->d.TransactionId; /* Save this so that we can send it back */ netvscPacket->TotalDataBufferLength = vmxferpagePacket->Ranges[i].ByteCount; netvscPacket->PageBufferCount = 1; @@ -1228,18 +1246,18 @@ 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 + /* Calculate the page relative offset */ netvscPacket->PageBuffers[0].Offset = vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE -1); if ((end >> PAGE_SHIFT) != (start>>PAGE_SHIFT)) { - //Handle frame across multiple pages: + /* Handle frame across multiple pages: */ netvscPacket->PageBuffers[0].Length = (netvscPacket->PageBuffers[0].Pfn <TotalDataBufferLength - netvscPacket->PageBuffers[0].Length; @@ -1253,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; @@ -1268,8 +1286,8 @@ NetVscOnReceive( netvscPacket->PageBuffers[0].Offset, netvscPacket->PageBuffers[0].Length); - // Pass it to the upper layer - ((NETVSC_DRIVER_OBJECT*)Device->Driver)->OnReceiveCallback(Device, netvscPacket); + /* Pass it to the upper layer */ + ((struct netvsc_driver *)Device->Driver)->OnReceiveCallback(Device, netvscPacket); NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext); } @@ -1283,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; @@ -1295,22 +1313,22 @@ NetVscSendReceiveCompletion( recvcompMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacketComplete; - // FIXME: Pass in the status + /* FIXME: Pass in the status */ recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess; retry_send_cmplt: - // Send the completion + /* Send the completion */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, &recvcompMessage, - sizeof(NVSP_MESSAGE), + sizeof(struct nvsp_message), TransactionId, VmbusPacketTypeCompletion, 0); - if (ret == 0) // success + if (ret == 0) /* success */ { - // no-op + /* no-op */ } - else if (ret == -1) // no more room...wait a bit and attempt to retry 3 times + else if (ret == -1) /* no more room...wait a bit and attempt to retry 3 times */ { retries++; DPRINT_ERR(NETVSC, "unable to send receive completion pkt (tid %llx)...retrying %d", TransactionId, retries); @@ -1331,16 +1349,14 @@ retry_send_cmplt: } } -// -// Send a receive completion packet to RNDIS device (ie NetVsp) -// +/* Send a receive completion packet to RNDIS device (ie NetVsp) */ static void NetVscOnReceiveCompletion( void * Context) { - NETVSC_PACKET *packet = (NETVSC_PACKET*)Context; - DEVICE_OBJECT *device = (DEVICE_OBJECT*)packet->Device; - NETVSC_DEVICE* netDevice; + 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; unsigned long flags; @@ -1349,8 +1365,8 @@ NetVscOnReceiveCompletion( ASSERT(packet->XferPagePacket); - // Even though it seems logical to do a GetOutboundNetDevice() here to send out receive completion, - // we are using GetInboundNetDevice() since we may have disable outbound traffic already. + /* Even though it seems logical to do a GetOutboundNetDevice() here to send out receive completion, */ + /* we are using GetInboundNetDevice() since we may have disable outbound traffic already. */ netDevice = GetInboundNetDevice(device); if (!netDevice) { @@ -1359,14 +1375,14 @@ NetVscOnReceiveCompletion( return; } - // Overloading use of the lock. + /* Overloading use of the lock. */ spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); ASSERT(packet->XferPagePacket->Count > 0); packet->XferPagePacket->Count--; - // Last one in the line that represent 1 xfer page packet. - // Return the xfer page packet itself to the freelist + /* Last one in the line that represent 1 xfer page packet. */ + /* Return the xfer page packet itself to the freelist */ if (packet->XferPagePacket->Count == 0) { fSendReceiveComp = true; @@ -1375,11 +1391,11 @@ NetVscOnReceiveCompletion( INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->XferPagePacket->ListEntry); } - // Put the packet back + /* Put the packet back */ INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry); spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); - // Send a receive completion for the xfer page packet + /* Send a receive completion for the xfer page packet */ if (fSendReceiveComp) { NetVscSendReceiveCompletion(device, transactionId); @@ -1398,13 +1414,13 @@ NetVscOnChannelCallback( { const int netPacketSize=2048; int ret=0; - DEVICE_OBJECT *device=(DEVICE_OBJECT*)Context; - NETVSC_DEVICE *netDevice; + 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; @@ -1435,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: @@ -1451,7 +1467,7 @@ NetVscOnChannelCallback( break; } - // reset + /* reset */ if (bufferlen > netPacketSize) { kfree(buffer); @@ -1462,9 +1478,9 @@ NetVscOnChannelCallback( } else { - //DPRINT_DBG(NETVSC, "nothing else to read..."); + /* DPRINT_DBG(NETVSC, "nothing else to read..."); */ - // reset + /* reset */ if (bufferlen > netPacketSize) { kfree(buffer); @@ -1476,12 +1492,12 @@ NetVscOnChannelCallback( break; } } - else if (ret == -2) // Handle large packet + else if (ret == -2) /* Handle large packet */ { buffer = kmalloc(bytesRecvd, GFP_ATOMIC); if (buffer == NULL) { - // Try again next time around + /* Try again next time around */ DPRINT_ERR(NETVSC, "unable to allocate buffer of size (%d)!!", bytesRecvd); break; }