diff options
author | Greg Kroah-Hartman <gregkh@suse.de> | 2009-09-02 10:33:05 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-09-15 12:02:03 -0700 |
commit | 21a8082043aa474107f4ed62fb62651ffad8e2f6 (patch) | |
tree | c86c8b80b7867b15d61e805ec4c5b25d270717bd | |
parent | 0120ee0d77014eb0f10b25591fcc3fa286720239 (diff) |
Staging: hv: coding style cleanup for NetVsc.c
Still a lot of long lines, but that's nothing I can fix up at this time
Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/staging/hv/NetVsc.c | 1194 |
1 files changed, 539 insertions, 655 deletions
diff --git a/drivers/staging/hv/NetVsc.c b/drivers/staging/hv/NetVsc.c index fb1cbf02ce5a..13f36a7798dc 100644 --- a/drivers/staging/hv/NetVsc.c +++ b/drivers/staging/hv/NetVsc.c @@ -1,5 +1,4 @@ /* - * * Copyright (c) 2009, Microsoft Corporation. * * This program is free software; you can redistribute it and/or modify it @@ -17,13 +16,11 @@ * * Authors: * Hank Janssen <hjanssen@microsoft.com> - * */ - #include <linux/kernel.h> #include <linux/mm.h> #include <linux/delay.h> -#include <asm/io.h> +#include <linux/io.h> #include "osd.h" #include "logging.h" #include "NetVsc.h" @@ -31,7 +28,7 @@ /* Globals */ -static const char* gDriverName="netvsc"; +static const char *gDriverName = "netvsc"; /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ static const struct hv_guid gNetVscDeviceType = { @@ -41,84 +38,40 @@ static const struct hv_guid gNetVscDeviceType = { } }; +static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); + +static int NetVscOnDeviceRemove(struct hv_device *Device); + +static void NetVscOnCleanup(struct hv_driver *Driver); + +static void NetVscOnChannelCallback(void *context); + +static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device); + +static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device); + +static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice); + +static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice); + +static int NetVscConnectToVsp(struct hv_device *Device); + +static void NetVscOnSendCompletion(struct hv_device *Device, + struct vmpacket_descriptor *Packet); + +static int NetVscOnSend(struct hv_device *Device, + struct hv_netvsc_packet *Packet); + +static void NetVscOnReceive(struct hv_device *Device, + struct vmpacket_descriptor *Packet); + +static void NetVscOnReceiveCompletion(void *Context); + +static void NetVscSendReceiveCompletion(struct hv_device *Device, + u64 TransactionId); + -/* Internal routines */ -static int -NetVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); - -static int -NetVscOnDeviceRemove( - struct hv_device *Device - ); - -static void -NetVscOnCleanup( - struct hv_driver *Driver - ); - -static void -NetVscOnChannelCallback( - void * context - ); - -static int -NetVscInitializeSendBufferWithNetVsp( - struct hv_device *Device - ); - -static int -NetVscInitializeReceiveBufferWithNetVsp( - struct hv_device *Device - ); - -static int -NetVscDestroySendBuffer( - struct NETVSC_DEVICE *NetDevice - ); - -static int -NetVscDestroyReceiveBuffer( - struct NETVSC_DEVICE *NetDevice - ); - -static int -NetVscConnectToVsp( - struct hv_device *Device - ); - -static void -NetVscOnSendCompletion( - struct hv_device *Device, - struct vmpacket_descriptor *Packet - ); - -static int -NetVscOnSend( - struct hv_device *Device, - struct hv_netvsc_packet *Packet - ); - -static void -NetVscOnReceive( - struct hv_device *Device, - struct vmpacket_descriptor *Packet - ); - -static void -NetVscOnReceiveCompletion( - void * Context - ); - -static void -NetVscSendReceiveCompletion( - struct hv_device *Device, - u64 TransactionId - ); - -static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) +static struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; @@ -135,7 +88,7 @@ static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) return netDevice; } -static inline void FreeNetDevice(struct NETVSC_DEVICE *Device) +static void FreeNetDevice(struct NETVSC_DEVICE *Device) { ASSERT(atomic_read(&Device->RefCount) == 0); Device->Device->Extension = NULL; @@ -144,11 +97,11 @@ static inline void FreeNetDevice(struct NETVSC_DEVICE *Device) /* Get the net device object iff exists and its refcount > 1 */ -static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device) +static struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = Device->Extension; if (netDevice && atomic_read(&netDevice->RefCount) > 1) atomic_inc(&netDevice->RefCount); else @@ -158,11 +111,11 @@ static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *Devic } /* Get the net device object iff exists and its refcount > 0 */ -static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device) +static struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = Device->Extension; if (netDevice && atomic_read(&netDevice->RefCount)) atomic_inc(&netDevice->RefCount); else @@ -171,73 +124,62 @@ static inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device *Device return netDevice; } -static inline void PutNetDevice(struct hv_device *Device) +static void PutNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = Device->Extension; ASSERT(netDevice); atomic_dec(&netDevice->RefCount); } -static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device) +static struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = Device->Extension; if (netDevice == NULL) return NULL; /* Busy wait until the ref drop to 2, then set it to 1 */ while (atomic_cmpxchg(&netDevice->RefCount, 2, 1) != 2) - { udelay(100); - } return netDevice; } -static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device) +static struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = Device->Extension; if (netDevice == NULL) return NULL; /* Busy wait until the ref drop to 1, then set it to 0 */ while (atomic_cmpxchg(&netDevice->RefCount, 1, 0) != 1) - { udelay(100); - } Device->Extension = NULL; return netDevice; } -/*++; - - -Name: - NetVscInitialize() - -Description: - Main entry point - ---*/ -int -NetVscInitialize( - struct hv_driver *drv - ) +/** + * NetVscInitialize - Main entry point + */ +int NetVscInitialize(struct hv_driver *drv) { struct netvsc_driver *driver = (struct netvsc_driver *)drv; - int ret=0; DPRINT_ENTER(NETVSC); - 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)); + 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)); @@ -250,48 +192,50 @@ NetVscInitialize( ASSERT(driver->OnLinkStatusChanged); /* Setup the dispatch table */ - driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; - driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; - driver->Base.OnCleanup = NetVscOnCleanup; + driver->Base.OnDeviceAdd = NetVscOnDeviceAdd; + driver->Base.OnDeviceRemove = NetVscOnDeviceRemove; + driver->Base.OnCleanup = NetVscOnCleanup; - driver->OnSend = NetVscOnSend; + driver->OnSend = NetVscOnSend; RndisFilterInit(driver); DPRINT_EXIT(NETVSC); - return ret; + return 0; } -static int -NetVscInitializeReceiveBufferWithNetVsp( - struct hv_device *Device - ) +static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) { - int ret=0; + int ret = 0; struct NETVSC_DEVICE *netDevice; struct nvsp_message *initPacket; DPRINT_ENTER(NETVSC); netDevice = GetOutboundNetDevice(Device); - if (!netDevice) - { - DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?"); + if (!netDevice) { + DPRINT_ERR(NETVSC, "unable to get net device..." + "device being destroyed?"); DPRINT_EXIT(NETVSC); return -1; } ASSERT(netDevice->ReceiveBufferSize > 0); - ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE-1)) == 0); /* page-size grandularity */ + /* page-size grandularity */ + ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); - netDevice->ReceiveBuffer = osd_PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT); - if (!netDevice->ReceiveBuffer) - { - DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", netDevice->ReceiveBufferSize); + 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 */ + /* page-aligned buffer */ + ASSERT(((unsigned long)netDevice->ReceiveBuffer & (PAGE_SIZE - 1)) == + 0); DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL..."); @@ -301,13 +245,12 @@ NetVscInitializeReceiveBufferWithNetVsp( * than the channel to establish the gpadl handle. */ ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, - netDevice->ReceiveBuffer, - netDevice->ReceiveBufferSize, - &netDevice->ReceiveBufferGpadlHandle); - - if (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to establish receive buffer's gpadl"); + netDevice->ReceiveBuffer, + netDevice->ReceiveBufferSize, + &netDevice->ReceiveBufferGpadlHandle); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to establish receive buffer's gpadl"); goto Cleanup; } @@ -320,31 +263,30 @@ NetVscInitializeReceiveBufferWithNetVsp( 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; + 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 */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); + initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to send receive buffer's gpadl to netvsp"); goto Cleanup; } osd_WaitEventWait(netDevice->ChannelInitEvent); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) - { - DPRINT_ERR(NETVSC, - "Unable to complete receive buffer initialzation with NetVsp - status %d", - initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status); + if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) { + DPRINT_ERR(NETVSC, "Unable to complete receive buffer " + "initialzation with NetVsp - status %d", + initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status); ret = -1; goto Cleanup; } @@ -356,8 +298,7 @@ NetVscInitializeReceiveBufferWithNetVsp( netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections; netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(struct nvsp_1_receive_buffer_section), GFP_KERNEL); - if (netDevice->ReceiveSections == NULL) - { + if (netDevice->ReceiveSections == NULL) { ret = -1; goto Cleanup; } @@ -366,16 +307,20 @@ NetVscInitializeReceiveBufferWithNetVsp( initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections, 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)", - netDevice->ReceiveSectionCount, netDevice->ReceiveSections[0].Offset, netDevice->ReceiveSections[0].EndOffset, - netDevice->ReceiveSections[0].SubAllocationSize, netDevice->ReceiveSections[0].NumSubAllocations); - + DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, " + "endoffset %d, suballoc size %d, num suballocs %d)", + netDevice->ReceiveSectionCount, + netDevice->ReceiveSections[0].Offset, + netDevice->ReceiveSections[0].EndOffset, + 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 ) - { + netDevice->ReceiveSections->Offset != 0) { ret = -1; goto Cleanup; } @@ -391,36 +336,35 @@ Exit: return ret; } - -static int -NetVscInitializeSendBufferWithNetVsp( - struct hv_device *Device - ) +static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device) { - int ret=0; + int ret = 0; struct NETVSC_DEVICE *netDevice; struct nvsp_message *initPacket; DPRINT_ENTER(NETVSC); netDevice = GetOutboundNetDevice(Device); - if (!netDevice) - { - DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?"); + if (!netDevice) { + DPRINT_ERR(NETVSC, "unable to get net device..." + "device being destroyed?"); DPRINT_EXIT(NETVSC); return -1; } ASSERT(netDevice->SendBufferSize > 0); - ASSERT((netDevice->SendBufferSize & (PAGE_SIZE-1)) == 0); /* page-size grandularity */ - - netDevice->SendBuffer = osd_PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT); - if (!netDevice->SendBuffer) - { - DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", netDevice->SendBufferSize); + /* page-size grandularity */ + ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); + + 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 */ + /* page-aligned buffer */ + ASSERT(((unsigned long)netDevice->SendBuffer & (PAGE_SIZE - 1)) == 0); DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL..."); @@ -430,12 +374,10 @@ NetVscInitializeSendBufferWithNetVsp( * than the channel to establish the gpadl handle. */ ret = Device->Driver->VmbusChannelInterface.EstablishGpadl(Device, - netDevice->SendBuffer, - netDevice->SendBufferSize, - &netDevice->SendBufferGpadlHandle); - - if (ret != 0) - { + netDevice->SendBuffer, + netDevice->SendBufferSize, + &netDevice->SendBufferGpadlHandle); + if (ret != 0) { DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); goto Cleanup; } @@ -449,31 +391,29 @@ NetVscInitializeSendBufferWithNetVsp( 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; + 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 */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); + initPacket, sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to send receive buffer's gpadl to netvsp"); goto Cleanup; } osd_WaitEventWait(netDevice->ChannelInitEvent); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) - { - DPRINT_ERR(NETVSC, - "Unable to complete send buffer initialzation with NetVsp - status %d", - initPacket->Messages.Version1Messages.SendSendBufferComplete.Status); + if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) { + DPRINT_ERR(NETVSC, "Unable to complete send buffer " + "initialzation with NetVsp - status %d", + initPacket->Messages.Version1Messages.SendSendBufferComplete.Status); ret = -1; goto Cleanup; } @@ -491,14 +431,10 @@ Exit: return ret; } -static int -NetVscDestroyReceiveBuffer( - struct NETVSC_DEVICE *NetDevice - ) +static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice) { struct nvsp_message *revokePacket; - int ret=0; - + int ret = 0; DPRINT_ENTER(NETVSC); @@ -508,9 +444,9 @@ NetVscDestroyReceiveBuffer( * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need * to send a revoke msg here */ - if (NetDevice->ReceiveSectionCount) - { - DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeReceiveBuffer..."); + if (NetDevice->ReceiveSectionCount) { + DPRINT_INFO(NETVSC, + "Sending NvspMessage1TypeRevokeReceiveBuffer..."); /* Send the revoke receive buffer */ revokePacket = &NetDevice->RevokePacket; @@ -519,56 +455,55 @@ NetVscDestroyReceiveBuffer( revokePacket->Header.MessageType = NvspMessage1TypeRevokeReceiveBuffer; revokePacket->Messages.Version1Messages.RevokeReceiveBuffer.Id = NETVSC_RECEIVE_BUFFER_ID; - ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device, - revokePacket, - sizeof(struct nvsp_message), - (unsigned long)revokePacket, - VmbusPacketTypeDataInBand, - 0); + ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket( + NetDevice->Device, + revokePacket, + 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 (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send revoke receive buffer to netvsp"); + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to send revoke receive " + "buffer to netvsp"); DPRINT_EXIT(NETVSC); return -1; } } /* Teardown the gpadl on the vsp end */ - if (NetDevice->ReceiveBufferGpadlHandle) - { + if (NetDevice->ReceiveBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); - ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, - NetDevice->ReceiveBufferGpadlHandle); + 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 (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to teardown receive buffer's gpadl"); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to teardown receive buffer's gpadl"); DPRINT_EXIT(NETVSC); return -1; } NetDevice->ReceiveBufferGpadlHandle = 0; } - if (NetDevice->ReceiveBuffer) - { + if (NetDevice->ReceiveBuffer) { DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); /* Free up the receive buffer */ - osd_PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT); + osd_PageFree(NetDevice->ReceiveBuffer, + NetDevice->ReceiveBufferSize >> PAGE_SHIFT); NetDevice->ReceiveBuffer = NULL; } - if (NetDevice->ReceiveSections) - { + if (NetDevice->ReceiveSections) { + NetDevice->ReceiveSectionCount = 0; kfree(NetDevice->ReceiveSections); NetDevice->ReceiveSections = NULL; - NetDevice->ReceiveSectionCount = 0; } DPRINT_EXIT(NETVSC); @@ -576,17 +511,10 @@ NetVscDestroyReceiveBuffer( return ret; } - - - -static int -NetVscDestroySendBuffer( - struct NETVSC_DEVICE *NetDevice - ) +static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice) { struct nvsp_message *revokePacket; - int ret=0; - + int ret = 0; DPRINT_ENTER(NETVSC); @@ -596,9 +524,9 @@ NetVscDestroySendBuffer( * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need * to send a revoke msg here */ - if (NetDevice->SendSectionSize) - { - DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeRevokeSendBuffer..."); + if (NetDevice->SendSectionSize) { + DPRINT_INFO(NETVSC, + "Sending NvspMessage1TypeRevokeSendBuffer..."); /* Send the revoke send buffer */ revokePacket = &NetDevice->RevokePacket; @@ -608,44 +536,47 @@ NetVscDestroySendBuffer( revokePacket->Messages.Version1Messages.RevokeSendBuffer.Id = NETVSC_SEND_BUFFER_ID; ret = NetDevice->Device->Driver->VmbusChannelInterface.SendPacket(NetDevice->Device, - revokePacket, - 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 (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send revoke send buffer to netvsp"); + revokePacket, + 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 (ret != 0) { + DPRINT_ERR(NETVSC, "unable to send revoke send buffer " + "to netvsp"); DPRINT_EXIT(NETVSC); return -1; } } /* Teardown the gpadl on the vsp end */ - if (NetDevice->SendBufferGpadlHandle) - { + if (NetDevice->SendBufferGpadlHandle) { DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); - ret = NetDevice->Device->Driver->VmbusChannelInterface.TeardownGpadl(NetDevice->Device, - NetDevice->SendBufferGpadlHandle); + 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 (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to teardown send buffer's gpadl"); + /* + * 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"); DPRINT_EXIT(NETVSC); return -1; } NetDevice->SendBufferGpadlHandle = 0; } - if (NetDevice->SendBuffer) - { + if (NetDevice->SendBuffer) { DPRINT_INFO(NETVSC, "Freeing up send buffer..."); /* Free up the receive buffer */ - osd_PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT); + osd_PageFree(NetDevice->SendBuffer, + NetDevice->SendBufferSize >> PAGE_SHIFT); NetDevice->SendBuffer = NULL; } @@ -655,13 +586,9 @@ NetVscDestroySendBuffer( } - -static int -NetVscConnectToVsp( - struct hv_device *Device - ) +static int NetVscConnectToVsp(struct hv_device *Device) { - int ret=0; + int ret; struct NETVSC_DEVICE *netDevice; struct nvsp_message *initPacket; int ndisVersion; @@ -669,9 +596,9 @@ NetVscConnectToVsp( DPRINT_ENTER(NETVSC); netDevice = GetOutboundNetDevice(Device); - if (!netDevice) - { - DPRINT_ERR(NETVSC, "unable to get net device...device being destroyed?"); + if (!netDevice) { + DPRINT_ERR(NETVSC, "unable to get net device..." + "device being destroyed?"); DPRINT_EXIT(NETVSC); return -1; } @@ -680,21 +607,20 @@ NetVscConnectToVsp( 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; + 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 */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - - if( ret != 0) - { + initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + + if (ret != 0) { DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit"); goto Cleanup; } @@ -707,17 +633,19 @@ NetVscConnectToVsp( initPacket->Messages.InitMessages.InitComplete.Status, initPacket->Messages.InitMessages.InitComplete.MaximumMdlChainLength); - if (initPacket->Messages.InitMessages.InitComplete.Status != NvspStatusSuccess) - { - DPRINT_ERR(NETVSC, "unable to initialize with netvsp (status 0x%x)", initPacket->Messages.InitMessages.InitComplete.Status); + if (initPacket->Messages.InitMessages.InitComplete.Status != + NvspStatusSuccess) { + DPRINT_ERR(NETVSC, + "unable to initialize with netvsp (status 0x%x)", + initPacket->Messages.InitMessages.InitComplete.Status); ret = -1; goto Cleanup; } - if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) - { - DPRINT_ERR(NETVSC, "unable to initialize with netvsp (version expected 1 got %d)", - initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion); + if (initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion != NVSP_PROTOCOL_VERSION_1) { + DPRINT_ERR(NETVSC, "unable to initialize with netvsp " + "(version expected 1 got %d)", + initPacket->Messages.InitMessages.InitComplete.NegotiatedProtocolVersion); ret = -1; goto Cleanup; } @@ -726,22 +654,23 @@ NetVscConnectToVsp( /* Send the ndis version */ memset(initPacket, 0, sizeof(struct nvsp_message)); - ndisVersion = 0x00050000; + ndisVersion = 0x00050000; - initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion; - initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = (ndisVersion & 0xFFFF0000) >> 16; - initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = ndisVersion & 0xFFFF; + initPacket->Header.MessageType = NvspMessage1TypeSendNdisVersion; + initPacket->Messages.Version1Messages.SendNdisVersion.NdisMajorVersion = + (ndisVersion & 0xFFFF0000) >> 16; + initPacket->Messages.Version1Messages.SendNdisVersion.NdisMinorVersion = + ndisVersion & 0xFFFF; /* Send the init request */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - initPacket, - sizeof(struct nvsp_message), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - 0); - if (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send NvspMessage1TypeSendNdisVersion"); + initPacket, + sizeof(struct nvsp_message), + (unsigned long)initPacket, + VmbusPacketTypeDataInBand, 0); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to send NvspMessage1TypeSendNdisVersion"); ret = -1; goto Cleanup; } @@ -756,9 +685,7 @@ NetVscConnectToVsp( /* Post the big receive buffer to NetVSP */ ret = NetVscInitializeReceiveBufferWithNetVsp(Device); if (ret == 0) - { ret = NetVscInitializeSendBufferWithNetVsp(Device); - } Cleanup: PutNetDevice(Device); @@ -766,10 +693,7 @@ Cleanup: return ret; } -static void -NetVscDisconnectFromVsp( - struct NETVSC_DEVICE *NetDevice - ) +static void NetVscDisconnectFromVsp(struct NETVSC_DEVICE *NetDevice) { DPRINT_ENTER(NETVSC); @@ -779,36 +703,23 @@ NetVscDisconnectFromVsp( DPRINT_EXIT(NETVSC); } - -/*++ - -Name: - NetVscOnDeviceAdd() - -Description: - Callback when the device belonging to this driver is added - ---*/ -static int -NetVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ) +/** + * NetVscOnDeviceAdd - Callback when the device belonging to this driver is added + */ +static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { - int ret=0; + int ret = 0; int i; - struct NETVSC_DEVICE *netDevice; struct hv_netvsc_packet *packet; LIST_ENTRY *entry; - - struct netvsc_driver *netDriver = (struct netvsc_driver *)Device->Driver; + struct netvsc_driver *netDriver = + (struct netvsc_driver *)Device->Driver; DPRINT_ENTER(NETVSC); netDevice = AllocNetDevice(Device); - if (!netDevice) - { + if (!netDevice) { ret = -1; goto Cleanup; } @@ -823,30 +734,31 @@ NetVscOnDeviceAdd( INITIALIZE_LIST_HEAD(&netDevice->ReceivePacketList); - for (i=0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) - { - 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); + for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { + 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); break; } - INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->ListEntry); + INSERT_TAIL_LIST(&netDevice->ReceivePacketList, + &packet->ListEntry); } netDevice->ChannelInitEvent = osd_WaitEventCreate(); /* 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) - { + if (ret != 0) { DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); ret = -1; goto Cleanup; @@ -857,14 +769,14 @@ NetVscOnDeviceAdd( /* Connect with the NetVsp */ ret = NetVscConnectToVsp(Device); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); ret = -1; goto Close; } - DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", ret); + DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", + ret); DPRINT_EXIT(NETVSC); return ret; @@ -875,14 +787,14 @@ Close: Cleanup: - if (netDevice) - { + if (netDevice) { kfree(netDevice->ChannelInitEvent); - while (!IsListEmpty(&netDevice->ReceivePacketList)) - { + while (!IsListEmpty(&netDevice->ReceivePacketList)) { entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList); - packet = CONTAINING_RECORD(entry, struct hv_netvsc_packet, ListEntry); + packet = CONTAINING_RECORD(entry, + struct hv_netvsc_packet, + ListEntry); kfree(packet); } @@ -896,43 +808,31 @@ Cleanup: return ret; } - -/*++ - -Name: - NetVscOnDeviceRemove() - -Description: - Callback when the root bus device is removed - ---*/ -static int -NetVscOnDeviceRemove( - struct hv_device *Device - ) +/** + * NetVscOnDeviceRemove - Callback when the root bus device is removed + */ +static int NetVscOnDeviceRemove(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; struct hv_netvsc_packet *netvscPacket; - int ret=0; LIST_ENTRY *entry; DPRINT_ENTER(NETVSC); - DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", Device->Extension); + DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", + Device->Extension); /* Stop outbound traffic ie sends and receives completions */ netDevice = ReleaseOutboundNetDevice(Device); - if (!netDevice) - { + if (!netDevice) { DPRINT_ERR(NETVSC, "No net device present!!"); return -1; } /* Wait for all send completions */ - while (atomic_read(&netDevice->NumOutstandingSends)) - { - DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", atomic_read(&netDevice->NumOutstandingSends)); - + while (atomic_read(&netDevice->NumOutstandingSends)) { + DPRINT_INFO(NETVSC, "waiting for %d reque |