Signed-off-by: Joe Perches <joe at perches.com> --- drivers/staging/hv/BlkVsc.c | 68 +- drivers/staging/hv/Channel.c | 755 ++++++++++----------- drivers/staging/hv/Channel.h | 145 ++--- drivers/staging/hv/ChannelInterface.c | 258 +++---- drivers/staging/hv/ChannelInterface.h | 12 +- drivers/staging/hv/ChannelMgmt.c | 524 +++++++-------- drivers/staging/hv/ChannelMgmt.h | 117 ++-- drivers/staging/hv/Connection.c | 200 +++---- drivers/staging/hv/Hv.c | 476 ++++++------- drivers/staging/hv/Hv.h | 77 +-- drivers/staging/hv/NetVsc.c | 1184 ++++++++++++++++----------------- drivers/staging/hv/NetVsc.h | 40 +- drivers/staging/hv/RingBuffer.c | 242 +++----- drivers/staging/hv/RingBuffer.h | 90 +-- drivers/staging/hv/RndisFilter.c | 760 +++++++++------------ drivers/staging/hv/RndisFilter.h | 10 +- drivers/staging/hv/StorVsc.c | 677 +++++++++---------- drivers/staging/hv/VersionInfo.h | 7 +- drivers/staging/hv/Vmbus.c | 247 +++----- drivers/staging/hv/VmbusPrivate.h | 93 +-- drivers/staging/hv/blkvsc_drv.c | 1001 ++++++++++++++-------------- drivers/staging/hv/netvsc_drv.c | 310 +++++---- drivers/staging/hv/osd.c | 107 ++-- drivers/staging/hv/storvsc_drv.c | 767 +++++++++++---------- drivers/staging/hv/vmbus_drv.c | 554 ++++++++-------- 25 files changed, 4045 insertions(+), 4676 deletions(-) diff --git a/drivers/staging/hv/BlkVsc.c b/drivers/staging/hv/BlkVsc.c index 059b134..1042477 100644 --- a/drivers/staging/hv/BlkVsc.c +++ b/drivers/staging/hv/BlkVsc.c @@ -24,28 +24,22 @@ #include <linux/mm.h> #include "StorVsc.c" -static const char* gBlkDriverName="blkvsc"; +static const char *gBlkDriverName = "blkvsc"; /* {32412632-86cb-44a2-9b5c-50d1417354f5} */ -static const GUID gBlkVscDeviceType={ - .Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5} +static const GUID gBlkVscDeviceType = { + .Data = + {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, + 0xd1, 0x41, 0x73, 0x54, 0xf5} }; /* Static routines */ -static int -BlkVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); +static int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); - -int -BlkVscInitialize( - DRIVER_OBJECT *Driver - ) +int BlkVscInitialize(DRIVER_OBJECT * Driver) { - STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver; - int ret=0; + STORVSC_DRIVER_OBJECT *storDriver = (STORVSC_DRIVER_OBJECT *) Driver; + int ret = 0; DPRINT_ENTER(BLKVSC); @@ -55,41 +49,41 @@ BlkVscInitialize( Driver->name = gBlkDriverName; memcpy(&Driver->deviceType, &gBlkVscDeviceType, sizeof(GUID)); - storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION); + storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION); /* Divide the ring buffer data size (which is 1 page less than the ring buffer size since that page is reserved for the ring buffer indices) */ /* by the max request size (which is VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + u64) */ storDriver->MaxOutstandingRequestsPerChannel = - ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(u64),sizeof(u64))); + ((storDriver->RingBufferSize - + PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + + sizeof(VSTOR_PACKET) + sizeof(u64), + sizeof(u64))); - DPRINT_INFO(BLKVSC, "max io outstd %u", storDriver->MaxOutstandingRequestsPerChannel); + DPRINT_INFO(BLKVSC, "max io outstd %u", + storDriver->MaxOutstandingRequestsPerChannel); /* Setup the dispatch table */ - storDriver->Base.OnDeviceAdd = BlkVscOnDeviceAdd; - storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; - storDriver->Base.OnCleanup = StorVscOnCleanup; + storDriver->Base.OnDeviceAdd = BlkVscOnDeviceAdd; + storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; + storDriver->Base.OnCleanup = StorVscOnCleanup; - storDriver->OnIORequest = StorVscOnIORequest; + storDriver->OnIORequest = StorVscOnIORequest; DPRINT_EXIT(BLKVSC); return ret; } -int -BlkVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ) +int BlkVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { - int ret=0; - STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo; + int ret = 0; + STORVSC_DEVICE_INFO *deviceInfo = + (STORVSC_DEVICE_INFO *) AdditionalInfo; DPRINT_ENTER(BLKVSC); ret = StorVscOnDeviceAdd(Device, AdditionalInfo); - if (ret != 0) - { + if (ret != 0) { DPRINT_EXIT(BLKVSC); return ret; @@ -97,10 +91,14 @@ BlkVscOnDeviceAdd( /* We need to use the device instance guid to set the path and target id. For IDE devices, the */ /* device instance id is formatted as <bus id> - <device id> - 8899 - 000000000000. */ - deviceInfo->PathId = Device->deviceInstance.Data[3] << 24 | Device->deviceInstance.Data[2] << 16 | - Device->deviceInstance.Data[1] << 8 |Device->deviceInstance.Data[0]; - - deviceInfo->TargetId = Device->deviceInstance.Data[5] << 8 | Device->deviceInstance.Data[4]; + deviceInfo->PathId = + Device->deviceInstance.Data[3] << 24 | Device->deviceInstance. + Data[2] << 16 | Device->deviceInstance.Data[1] << 8 | Device-> + deviceInstance.Data[0]; + + deviceInfo->TargetId = + Device->deviceInstance.Data[5] << 8 | Device->deviceInstance. + Data[4]; DPRINT_EXIT(BLKVSC); diff --git a/drivers/staging/hv/Channel.c b/drivers/staging/hv/Channel.c index 68f3442..18fbd0e 100644 --- a/drivers/staging/hv/Channel.c +++ b/drivers/staging/hv/Channel.c @@ -28,55 +28,42 @@ #include "VmbusPrivate.h" /* Internal routines */ -static int -VmbusChannelCreateGpadlHeader( - void * Kbuffer, /* must be phys and virt contiguous */ - u32 Size, /* page-size multiple */ - VMBUS_CHANNEL_MSGINFO **msgInfo, - u32 *MessageCount - ); +static int VmbusChannelCreateGpadlHeader(void *Kbuffer, /* must be phys and virt contiguous */ + u32 Size, /* page-size multiple */ + VMBUS_CHANNEL_MSGINFO ** msgInfo, + u32 * MessageCount); -static void -DumpVmbusChannel( - VMBUS_CHANNEL *Channel - ); - - -static void -VmbusChannelSetEvent( - VMBUS_CHANNEL *Channel - ); +static void DumpVmbusChannel(VMBUS_CHANNEL * Channel); +static void VmbusChannelSetEvent(VMBUS_CHANNEL * Channel); #if 0 -static void -DumpMonitorPage( - HV_MONITOR_PAGE *MonitorPage - ) +static void DumpMonitorPage(HV_MONITOR_PAGE * MonitorPage) { - int i=0; - int j=0; + int i = 0; + int j = 0; - DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, MonitorPage->TriggerState); + DPRINT_DBG(VMBUS, "monitorPage - %p, trigger state - %d", MonitorPage, + MonitorPage->TriggerState); - for (i=0; i<4; i++) - { - DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64); + for (i = 0; i < 4; i++) { + DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, + MonitorPage->TriggerGroup[i].AsUINT64); } - for (i=0; i<4; i++) - { - for (j=0; j<32; j++) - { - DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]); + for (i = 0; i < 4; i++) { + for (j = 0; j < 32; j++) { + DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, + MonitorPage->Latency[i][j]); } } - for (i=0; i<4; i++) - { - for (j=0; j<32; j++) - { - DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32); - DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber); + for (i = 0; i < 4; i++) { + for (j = 0; j < 32; j++) { + DPRINT_DBG(VMBUS, "param-conn id (%d)(%d) - %d", i, j, + MonitorPage->Parameter[i][j].ConnectionId. + Asu32); + DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, + MonitorPage->Parameter[i][j].FlagNumber); } } @@ -92,27 +79,25 @@ Description: Trigger an event notification on the specified channel. --*/ -static void -VmbusChannelSetEvent( - VMBUS_CHANNEL *Channel - ) +static void VmbusChannelSetEvent(VMBUS_CHANNEL * Channel) { HV_MONITOR_PAGE *monitorPage; DPRINT_ENTER(VMBUS); - if (Channel->OfferMsg.MonitorAllocated) - { + if (Channel->OfferMsg.MonitorAllocated) { /* Each u32 represents 32 channels */ - BitSet((u32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31); + BitSet((u32 *) gVmbusConnection.SendInterruptPage + + (Channel->OfferMsg.ChildRelId >> 5), + Channel->OfferMsg.ChildRelId & 31); - monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages; - monitorPage++; /* Get the child to parent monitor page */ + monitorPage = (HV_MONITOR_PAGE *) gVmbusConnection.MonitorPages; + monitorPage++; /* Get the child to parent monitor page */ - BitSet((u32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit); - } - else - { + BitSet((u32 *) & monitorPage-> + TriggerGroup[Channel->MonitorGroup].Pending, + Channel->MonitorBit); + } else { VmbusSetEvent(Channel->OfferMsg.ChildRelId); } @@ -120,24 +105,24 @@ VmbusChannelSetEvent( } #if 0 -static void -VmbusChannelClearEvent( - VMBUS_CHANNEL *Channel - ) +static void VmbusChannelClearEvent(VMBUS_CHANNEL * Channel) { HV_MONITOR_PAGE *monitorPage; DPRINT_ENTER(VMBUS); - if (Channel->OfferMsg.MonitorAllocated) - { + if (Channel->OfferMsg.MonitorAllocated) { /* Each u32 represents 32 channels */ - BitClear((u32*)gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5), Channel->OfferMsg.ChildRelId & 31); + BitClear((u32 *) gVmbusConnection.SendInterruptPage + + (Channel->OfferMsg.ChildRelId >> 5), + Channel->OfferMsg.ChildRelId & 31); - monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages; - monitorPage++; /* Get the child to parent monitor page */ + monitorPage = (HV_MONITOR_PAGE *) gVmbusConnection.MonitorPages; + monitorPage++; /* Get the child to parent monitor page */ - BitClear((u32*) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending, Channel->MonitorBit); + BitClear((u32 *) & monitorPage-> + TriggerGroup[Channel->MonitorGroup].Pending, + Channel->MonitorBit); } DPRINT_EXIT(VMBUS); @@ -154,40 +139,47 @@ Description: --*/ void -VmbusChannelGetDebugInfo( - VMBUS_CHANNEL *Channel, - VMBUS_CHANNEL_DEBUG_INFO *DebugInfo - ) +VmbusChannelGetDebugInfo(VMBUS_CHANNEL * Channel, + VMBUS_CHANNEL_DEBUG_INFO * DebugInfo) { HV_MONITOR_PAGE *monitorPage; - u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32; - u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32; - /* u32 monitorBit = 1 << monitorOffset; */ + u8 monitorGroup = (u8) Channel->OfferMsg.MonitorId / 32; + u8 monitorOffset = (u8) Channel->OfferMsg.MonitorId % 32; + /* u32 monitorBit = 1 << monitorOffset; */ DebugInfo->RelId = Channel->OfferMsg.ChildRelId; DebugInfo->State = Channel->State; - memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(GUID)); - memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)); + memcpy(&DebugInfo->InterfaceType, + &Channel->OfferMsg.Offer.InterfaceType, sizeof(GUID)); + memcpy(&DebugInfo->InterfaceInstance, + &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID)); - monitorPage = (HV_MONITOR_PAGE*)gVmbusConnection.MonitorPages; + monitorPage = (HV_MONITOR_PAGE *) gVmbusConnection.MonitorPages; DebugInfo->MonitorId = Channel->OfferMsg.MonitorId; - DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending; - DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset]; - DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id; + DebugInfo->ServerMonitorPending = + monitorPage->TriggerGroup[monitorGroup].Pending; + DebugInfo->ServerMonitorLatency = + monitorPage->Latency[monitorGroup][monitorOffset]; + DebugInfo->ServerMonitorConnectionId = + monitorPage->Parameter[monitorGroup][monitorOffset].ConnectionId.u. + Id; monitorPage++; - DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending; - DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset]; - DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id; + DebugInfo->ClientMonitorPending = + monitorPage->TriggerGroup[monitorGroup].Pending; + DebugInfo->ClientMonitorLatency = + monitorPage->Latency[monitorGroup][monitorOffset]; + DebugInfo->ClientMonitorConnectionId = + monitorPage->Parameter[monitorGroup][monitorOffset].ConnectionId.u. + Id; RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound); RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound); } - /*++; Name: @@ -198,96 +190,98 @@ Description: --*/ int -VmbusChannelOpen( - VMBUS_CHANNEL *NewChannel, - u32 SendRingBufferSize, - u32 RecvRingBufferSize, - void * UserData, - u32 UserDataLen, - PFN_CHANNEL_CALLBACK pfnOnChannelCallback, - void * Context - ) +VmbusChannelOpen(VMBUS_CHANNEL * NewChannel, + u32 SendRingBufferSize, + u32 RecvRingBufferSize, + void *UserData, + u32 UserDataLen, + PFN_CHANNEL_CALLBACK pfnOnChannelCallback, void *Context) { - int ret=0; - VMBUS_CHANNEL_OPEN_CHANNEL* openMsg; - VMBUS_CHANNEL_MSGINFO* openInfo; + int ret = 0; + VMBUS_CHANNEL_OPEN_CHANNEL *openMsg; + VMBUS_CHANNEL_MSGINFO *openInfo; void *in, *out; unsigned long flags; DPRINT_ENTER(VMBUS); /* Aligned to page size */ - ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1))); - ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1))); + ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1))); + ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1))); NewChannel->OnChannelCallback = pfnOnChannelCallback; NewChannel->ChannelCallbackContext = Context; /* Allocate the ring buffer */ - out = PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT); + out = + PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT); /* out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL); */ ASSERT(out); - ASSERT(((unsigned long)out & (PAGE_SIZE-1)) == 0); + ASSERT(((unsigned long)out & (PAGE_SIZE - 1)) == 0); - in = (void*)((unsigned long)out + SendRingBufferSize); + in = (void *)((unsigned long)out + SendRingBufferSize); NewChannel->RingBufferPages = out; - NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT; + NewChannel->RingBufferPageCount = + (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT; RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize); RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize); /* Establish the gpadl for the ring buffer */ - DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", NewChannel); + DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", + NewChannel); NewChannel->RingBufferGpadlHandle = 0; ret = VmbusChannelEstablishGpadl(NewChannel, - NewChannel->Outbound.RingBuffer, - SendRingBufferSize + RecvRingBufferSize, - &NewChannel->RingBufferGpadlHandle); - - DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>", - NewChannel, - NewChannel->OfferMsg.ChildRelId, - NewChannel->RingBufferGpadlHandle, - NewChannel->Outbound.RingBuffer, - NewChannel->Outbound.RingSize, - NewChannel->Inbound.RingBuffer, - NewChannel->Inbound.RingSize, - SendRingBufferSize); + NewChannel->Outbound.RingBuffer, + SendRingBufferSize + + RecvRingBufferSize, + &NewChannel->RingBufferGpadlHandle); + + DPRINT_DBG(VMBUS, + "channel %p <relid %d gpadl 0x%x send ring %p size %d recv ring %p size %d, downstreamoffset %d>", + NewChannel, NewChannel->OfferMsg.ChildRelId, + NewChannel->RingBufferGpadlHandle, + NewChannel->Outbound.RingBuffer, + NewChannel->Outbound.RingSize, + NewChannel->Inbound.RingBuffer, NewChannel->Inbound.RingSize, + SendRingBufferSize); /* Create and init the channel open message */ - openInfo = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL), GFP_KERNEL); + openInfo = + kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_OPEN_CHANNEL), GFP_KERNEL); ASSERT(openInfo != NULL); openInfo->WaitEvent = WaitEventCreate(); - openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)openInfo->Msg; - openMsg->Header.MessageType = ChannelMessageOpenChannel; - openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */ - openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId; - openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle; - ASSERT(openMsg->RingBufferGpadlHandle); - openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> PAGE_SHIFT; - openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ + openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL *) openInfo->Msg; + openMsg->Header.MessageType = ChannelMessageOpenChannel; + openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */ + openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId; + openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle; + ASSERT(openMsg->RingBufferGpadlHandle); + openMsg->DownstreamRingBufferPageOffset = + SendRingBufferSize >> PAGE_SHIFT; + openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES); - if (UserDataLen) - { + if (UserDataLen) { memcpy(openMsg->UserData, UserData, UserDataLen); } spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &openInfo->MsgListEntry); + INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, + &openInfo->MsgListEntry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); DPRINT_DBG(VMBUS, "Sending channel open msg..."); ret = VmbusPostMessage(openMsg, sizeof(VMBUS_CHANNEL_OPEN_CHANNEL)); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(VMBUS, "unable to open channel - %d", ret); goto Cleanup; } @@ -295,13 +289,11 @@ VmbusChannelOpen( /* FIXME: Need to time-out here */ WaitEventWait(openInfo->WaitEvent); - if (openInfo->Response.OpenResult.Status == 0) - { + if (openInfo->Response.OpenResult.Status == 0) { DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel); - } - else - { - DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status); + } else { + DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", + NewChannel, openInfo->Response.OpenResult.Status); } Cleanup: @@ -326,23 +318,20 @@ Description: Dump the gpadl body message to the console for debugging purposes. --*/ -static void DumpGpadlBody( - VMBUS_CHANNEL_GPADL_BODY *Gpadl, - u32 Len) +static void DumpGpadlBody(VMBUS_CHANNEL_GPADL_BODY * Gpadl, u32 Len) { - int i=0; - int pfnCount=0; + int i = 0; + int pfnCount = 0; - pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY))/ sizeof(u64); + pfnCount = (Len - sizeof(VMBUS_CHANNEL_GPADL_BODY)) / sizeof(u64); DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount); - for (i=0; i< pfnCount; i++) - { - DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, Gpadl->Pfn[i]); + for (i = 0; i < pfnCount; i++) { + DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, + Gpadl->Pfn[i]); } } - /*++; Name: @@ -352,29 +341,26 @@ Description: Dump the gpadl header message to the console for debugging purposes. --*/ -static void DumpGpadlHeader( - VMBUS_CHANNEL_GPADL_HEADER *Gpadl - ) +static void DumpGpadlHeader(VMBUS_CHANNEL_GPADL_HEADER * Gpadl) { - int i=0,j=0; - int pageCount=0; + int i = 0, j = 0; + int pageCount = 0; - - DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d", - Gpadl->ChildRelId, - Gpadl->RangeCount, - Gpadl->RangeBufLen); - for (i=0; i< Gpadl->RangeCount; i++) - { + DPRINT_DBG(VMBUS, + "gpadl header - relid %d, range count %d, range buflen %d", + Gpadl->ChildRelId, Gpadl->RangeCount, Gpadl->RangeBufLen); + for (i = 0; i < Gpadl->RangeCount; i++) { pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT; - pageCount = (pageCount > 26)? 26 : pageCount; + pageCount = (pageCount > 26) ? 26 : pageCount; - DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d page count %d", - i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount); + DPRINT_DBG(VMBUS, + "gpadl range %d - len %d offset %d page count %d", i, + Gpadl->Range[i].ByteCount, + Gpadl->Range[i].ByteOffset, pageCount); - for (j=0; j< pageCount; j++) - { - DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]); + for (j = 0; j < pageCount; j++) { + DPRINT_DBG(VMBUS, "%d) pfn %llu", j, + Gpadl->Range[i].PfnArray[j]); } } } @@ -388,51 +374,53 @@ Description: Creates a gpadl for the specified buffer --*/ -static int -VmbusChannelCreateGpadlHeader( - void * Kbuffer, /* from kmalloc() */ - u32 Size, /* page-size multiple */ - VMBUS_CHANNEL_MSGINFO **MsgInfo, - u32 *MessageCount) +static int VmbusChannelCreateGpadlHeader(void *Kbuffer, /* from kmalloc() */ + u32 Size, /* page-size multiple */ + VMBUS_CHANNEL_MSGINFO ** MsgInfo, + u32 * MessageCount) { int i; int pageCount; - unsigned long long pfn; - VMBUS_CHANNEL_GPADL_HEADER* gpaHeader; - VMBUS_CHANNEL_GPADL_BODY* gpadlBody; - VMBUS_CHANNEL_MSGINFO* msgHeader; - VMBUS_CHANNEL_MSGINFO* msgBody; - u32 msgSize; + unsigned long long pfn; + VMBUS_CHANNEL_GPADL_HEADER *gpaHeader; + VMBUS_CHANNEL_GPADL_BODY *gpadlBody; + VMBUS_CHANNEL_MSGINFO *msgHeader; + VMBUS_CHANNEL_MSGINFO *msgBody; + u32 msgSize; int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize; /* ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0); */ - ASSERT( (Size & (PAGE_SIZE-1)) == 0); + ASSERT((Size & (PAGE_SIZE - 1)) == 0); pageCount = Size >> PAGE_SHIFT; pfn = GetPhysicalAddress(Kbuffer) >> PAGE_SHIFT; /* do we need a gpadl body msg */ - pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_HEADER) - sizeof(GPA_RANGE); + pfnSize = + MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_HEADER) - + sizeof(GPA_RANGE); pfnCount = pfnSize / sizeof(u64); - if (pageCount > pfnCount) /* we need a gpadl body */ - { + if (pageCount > pfnCount) { /* we need a gpadl body */ /* fill in the header */ - msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pfnCount*sizeof(u64); - msgHeader = kzalloc(msgSize, GFP_KERNEL); + msgSize = + sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + + pfnCount * sizeof(u64); + msgHeader = kzalloc(msgSize, GFP_KERNEL); INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList); - msgHeader->MessageSize=msgSize; + msgHeader->MessageSize = msgSize; - gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg; + gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER *) msgHeader->Msg; gpaHeader->RangeCount = 1; - gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64); + gpaHeader->RangeBufLen = + sizeof(GPA_RANGE) + pageCount * sizeof(u64); gpaHeader->Range[0].ByteOffset = 0; gpaHeader->Range[0].ByteCount = Size; - for (i=0; i<pfnCount; i++) - { - gpaHeader->Range[0].PfnArray[i] = pfn+i; + for (i = 0; i < pfnCount; i++) { + gpaHeader->Range[0].PfnArray[i] = pfn + i; } *MsgInfo = msgHeader; *MessageCount = 1; @@ -441,56 +429,57 @@ VmbusChannelCreateGpadlHeader( pfnLeft = pageCount - pfnCount; /* how many pfns can we fit */ - pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_BODY); + pfnSize = + MAX_SIZE_CHANNEL_MESSAGE - sizeof(VMBUS_CHANNEL_GPADL_BODY); pfnCount = pfnSize / sizeof(u64); /* fill in the body */ - while (pfnLeft) - { - if (pfnLeft > pfnCount) - { + while (pfnLeft) { + if (pfnLeft > pfnCount) { pfnCurr = pfnCount; - } - else - { + } else { pfnCurr = pfnLeft; } - msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_BODY) + pfnCurr*sizeof(u64); + msgSize = + sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_GPADL_BODY) + + pfnCurr * sizeof(u64); msgBody = kzalloc(msgSize, GFP_KERNEL); ASSERT(msgBody); msgBody->MessageSize = msgSize; (*MessageCount)++; - gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)msgBody->Msg; + gpadlBody = (VMBUS_CHANNEL_GPADL_BODY *) msgBody->Msg; /* FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit */ /* gpadlBody->Gpadl = kbuffer; */ - for (i=0; i<pfnCurr; i++) - { + for (i = 0; i < pfnCurr; i++) { gpadlBody->Pfn[i] = pfn + pfnSum + i; } /* add to msg header */ - INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry); + INSERT_TAIL_LIST(&msgHeader->SubMsgList, + &msgBody->MsgListEntry); pfnSum += pfnCurr; pfnLeft -= pfnCurr; } - } - else - { + } else { /* everything fits in a header */ - msgSize = sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + pageCount*sizeof(u64); + msgSize = + sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_GPADL_HEADER) + sizeof(GPA_RANGE) + + pageCount * sizeof(u64); msgHeader = kzalloc(msgSize, GFP_KERNEL); - msgHeader->MessageSize=msgSize; + msgHeader->MessageSize = msgSize; - gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER*)msgHeader->Msg; + gpaHeader = (VMBUS_CHANNEL_GPADL_HEADER *) msgHeader->Msg; gpaHeader->RangeCount = 1; - gpaHeader->RangeBufLen = sizeof(GPA_RANGE) + pageCount*sizeof(u64); + gpaHeader->RangeBufLen = + sizeof(GPA_RANGE) + pageCount * sizeof(u64); gpaHeader->Range[0].ByteOffset = 0; gpaHeader->Range[0].ByteCount = Size; - for (i=0; i<pageCount; i++) - { - gpaHeader->Range[0].PfnArray[i] = pfn+i; + for (i = 0; i < pageCount; i++) { + gpaHeader->Range[0].PfnArray[i] = pfn + i; } *MsgInfo = msgHeader; @@ -500,7 +489,6 @@ VmbusChannelCreateGpadlHeader( return 0; } - /*++; Name: @@ -510,39 +498,35 @@ Description: Estabish a GPADL for the specified buffer --*/ -int -VmbusChannelEstablishGpadl( - VMBUS_CHANNEL *Channel, - void * Kbuffer, /* from kmalloc() */ - u32 Size, /* page-size multiple */ - u32 *GpadlHandle - ) +int VmbusChannelEstablishGpadl(VMBUS_CHANNEL * Channel, void *Kbuffer, /* from kmalloc() */ + u32 Size, /* page-size multiple */ + u32 * GpadlHandle) { - int ret=0; - VMBUS_CHANNEL_GPADL_HEADER* gpadlMsg; - VMBUS_CHANNEL_GPADL_BODY* gpadlBody; + int ret = 0; + VMBUS_CHANNEL_GPADL_HEADER *gpadlMsg; + VMBUS_CHANNEL_GPADL_BODY *gpadlBody; /* VMBUS_CHANNEL_GPADL_CREATED* gpadlCreated; */ VMBUS_CHANNEL_MSGINFO *msgInfo; VMBUS_CHANNEL_MSGINFO *subMsgInfo; u32 msgCount; - LIST_ENTRY* anchor; - LIST_ENTRY* curr; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; u32 nextGpadlHandle; unsigned long flags; DPRINT_ENTER(VMBUS); nextGpadlHandle = gVmbusConnection.NextGpadlHandle; - InterlockedIncrement((int*)&gVmbusConnection.NextGpadlHandle); + InterlockedIncrement((int *)&gVmbusConnection.NextGpadlHandle); VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount); ASSERT(msgInfo != NULL); - ASSERT(msgCount >0); + ASSERT(msgCount > 0); msgInfo->WaitEvent = WaitEventCreate(); - gpadlMsg = (VMBUS_CHANNEL_GPADL_HEADER*)msgInfo->Msg; + gpadlMsg = (VMBUS_CHANNEL_GPADL_HEADER *) msgInfo->Msg; gpadlMsg->Header.MessageType = ChannelMessageGpadlHeader; gpadlMsg->ChildRelId = Channel->OfferMsg.ChildRelId; gpadlMsg->Gpadl = nextGpadlHandle; @@ -550,44 +534,56 @@ VmbusChannelEstablishGpadl( DumpGpadlHeader(gpadlMsg); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry); + INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, + &msgInfo->MsgListEntry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, msgCount); + DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", Kbuffer, Size, + msgCount); - DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); + DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", + msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); - ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); - if (ret != 0) - { + ret = + VmbusPostMessage(gpadlMsg, + msgInfo->MessageSize - + sizeof(VMBUS_CHANNEL_MSGINFO)); + if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); goto Cleanup; } - if (msgCount>1) - { - ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList) - { - subMsgInfo = (VMBUS_CHANNEL_MSGINFO*) curr; - gpadlBody = (VMBUS_CHANNEL_GPADL_BODY*)subMsgInfo->Msg; + if (msgCount > 1) { + ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList) { + subMsgInfo = (VMBUS_CHANNEL_MSGINFO *) curr; + gpadlBody = + (VMBUS_CHANNEL_GPADL_BODY *) subMsgInfo->Msg; gpadlBody->Header.MessageType = ChannelMessageGpadlBody; gpadlBody->Gpadl = nextGpadlHandle; - DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); - - DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); - ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(VMBUS_CHANNEL_MSGINFO)); + DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", + subMsgInfo->MessageSize - + sizeof(VMBUS_CHANNEL_MSGINFO)); + + DumpGpadlBody(gpadlBody, + subMsgInfo->MessageSize - + sizeof(VMBUS_CHANNEL_MSGINFO)); + ret = + VmbusPostMessage(gpadlBody, + subMsgInfo->MessageSize - + sizeof(VMBUS_CHANNEL_MSGINFO)); ASSERT(ret == 0); } } WaitEventWait(msgInfo->WaitEvent); /* At this point, we received the gpadl created msg */ - DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)", - Channel->OfferMsg.ChildRelId, - msgInfo->Response.GpadlCreated.CreationStatus, - gpadlMsg->Gpadl); + DPRINT_DBG(VMBUS, + "Received GPADL created (relid %d, status %d handle %x)", + Channel->OfferMsg.ChildRelId, + msgInfo->Response.GpadlCreated.CreationStatus, + gpadlMsg->Gpadl); *GpadlHandle = gpadlMsg->Gpadl; @@ -604,8 +600,6 @@ Cleanup: return ret; } - - /*++; Name: @@ -615,39 +609,36 @@ Description: Teardown the specified GPADL handle --*/ -int -VmbusChannelTeardownGpadl( - VMBUS_CHANNEL *Channel, - u32 GpadlHandle - ) +int VmbusChannelTeardownGpadl(VMBUS_CHANNEL * Channel, u32 GpadlHandle) { - int ret=0; + int ret = 0; VMBUS_CHANNEL_GPADL_TEARDOWN *msg; - VMBUS_CHANNEL_MSGINFO* info; + VMBUS_CHANNEL_MSGINFO *info; unsigned long flags; DPRINT_ENTER(VMBUS); ASSERT(GpadlHandle != 0); - info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN), GFP_KERNEL); + info = + kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN), GFP_KERNEL); ASSERT(info != NULL); info->WaitEvent = WaitEventCreate(); - msg = (VMBUS_CHANNEL_GPADL_TEARDOWN*)info->Msg; + msg = (VMBUS_CHANNEL_GPADL_TEARDOWN *) info->Msg; msg->Header.MessageType = ChannelMessageGpadlTeardown; - msg->ChildRelId = Channel->OfferMsg.ChildRelId; - msg->Gpadl = GpadlHandle; + msg->ChildRelId = Channel->OfferMsg.ChildRelId; + msg->Gpadl = GpadlHandle; spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_GPADL_TEARDOWN)); - if (ret != 0) - { + if (ret != 0) { /* TODO: */ } @@ -666,7 +657,6 @@ VmbusChannelTeardownGpadl( return ret; } - /*++ Name: @@ -676,14 +666,11 @@ Description: Close the specified channel --*/ -void -VmbusChannelClose( - VMBUS_CHANNEL *Channel - ) +void VmbusChannelClose(VMBUS_CHANNEL * Channel) { - int ret=0; - VMBUS_CHANNEL_CLOSE_CHANNEL* msg; - VMBUS_CHANNEL_MSGINFO* info; + int ret = 0; + VMBUS_CHANNEL_CLOSE_CHANNEL *msg; + VMBUS_CHANNEL_MSGINFO *info; unsigned long flags; DPRINT_ENTER(VMBUS); @@ -693,25 +680,26 @@ VmbusChannelClose( TimerStop(Channel->PollTimer); /* Send a closing message */ - info = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL), GFP_KERNEL); + info = + kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL), GFP_KERNEL); ASSERT(info != NULL); /* info->waitEvent = WaitEventCreate(); */ - msg = (VMBUS_CHANNEL_CLOSE_CHANNEL*)info->Msg; - msg->Header.MessageType = ChannelMessageCloseChannel; - msg->ChildRelId = Channel->OfferMsg.ChildRelId; + msg = (VMBUS_CHANNEL_CLOSE_CHANNEL *) info->Msg; + msg->Header.MessageType = ChannelMessageCloseChannel; + msg->ChildRelId = Channel->OfferMsg.ChildRelId; ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_CLOSE_CHANNEL)); - if (ret != 0) - { + if (ret != 0) { /* TODO: */ } /* Tear down the gpadl for the channel's ring buffer */ - if (Channel->RingBufferGpadlHandle) - { - VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle); + if (Channel->RingBufferGpadlHandle) { + VmbusChannelTeardownGpadl(Channel, + Channel->RingBufferGpadlHandle); } /* TODO: Send a msg to release the childRelId */ @@ -724,15 +712,13 @@ VmbusChannelClose( kfree(info); - /* * If we are closing the channel during an error path in * opening the channel, don't free the channel since the * caller will free the channel */ - if (Channel->State == CHANNEL_OPEN_STATE) - { + if (Channel->State == CHANNEL_OPEN_STATE) { spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); REMOVE_ENTRY_LIST(&Channel->ListEntry); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); @@ -743,7 +729,6 @@ VmbusChannelClose( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -754,34 +739,31 @@ Description: --*/ int -VmbusChannelSendPacket( - VMBUS_CHANNEL *Channel, - const void * Buffer, - u32 BufferLen, - u64 RequestId, - VMBUS_PACKET_TYPE Type, - u32 Flags -) +VmbusChannelSendPacket(VMBUS_CHANNEL * Channel, + const void *Buffer, + u32 BufferLen, + u64 RequestId, VMBUS_PACKET_TYPE Type, u32 Flags) { - int ret=0; + int ret = 0; VMPACKET_DESCRIPTOR desc; u32 packetLen = sizeof(VMPACKET_DESCRIPTOR) + BufferLen; u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); SG_BUFFER_LIST bufferList[3]; - u64 alignedData=0; + u64 alignedData = 0; DPRINT_ENTER(VMBUS); - DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, BufferLen); + DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", Channel, Buffer, + BufferLen); DumpVmbusChannel(Channel); ASSERT((packetLenAligned - packetLen) < sizeof(u64)); /* Setup the descriptor */ - desc.Type = Type; /* VmbusPacketTypeDataInBand; */ - desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ - desc.DataOffset8 = sizeof(VMPACKET_DESCRIPTOR) >> 3; /* in 8-bytes granularity */ - desc.Length8 = (u16)(packetLenAligned >> 3); + desc.Type = Type; /* VmbusPacketTypeDataInBand; */ + desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ + desc.DataOffset8 = sizeof(VMPACKET_DESCRIPTOR) >> 3; /* in 8-bytes granularity */ + desc.Length8 = (u16) (packetLenAligned >> 3); desc.TransactionId = RequestId; bufferList[0].Data = &desc; @@ -793,14 +775,10 @@ VmbusChannelSendPacket( bufferList[2].Data = &alignedData; bufferList[2].Length = packetLenAligned - packetLen; - ret = RingBufferWrite( - &Channel->Outbound, - bufferList, - 3); + ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - { + if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) { VmbusChannelSetEvent(Channel); } @@ -809,7 +787,6 @@ VmbusChannelSendPacket( return ret; } - /*++ Name: @@ -820,23 +797,19 @@ Description: --*/ int -VmbusChannelSendPacketPageBuffer( - VMBUS_CHANNEL *Channel, - PAGE_BUFFER PageBuffers[], - u32 PageCount, - void * Buffer, - u32 BufferLen, - u64 RequestId -) +VmbusChannelSendPacketPageBuffer(VMBUS_CHANNEL * Channel, + PAGE_BUFFER PageBuffers[], + u32 PageCount, + void *Buffer, u32 BufferLen, u64 RequestId) { - int ret=0; - int i=0; + int ret = 0; + int i = 0; struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc; u32 descSize; u32 packetLen; u32 packetLenAligned; SG_BUFFER_LIST bufferList[3]; - u64 alignedData=0; + u64 alignedData = 0; DPRINT_ENTER(VMBUS); @@ -845,7 +818,9 @@ VmbusChannelSendPacketPageBuffer( DumpVmbusChannel(Channel); /* Adjust the size down since VMBUS_CHANNEL_PACKET_PAGE_BUFFER is the largest size we support */ - descSize = sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - ((MAX_PAGE_BUFFER_COUNT - PageCount)*sizeof(PAGE_BUFFER)); + descSize = + sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER) - + ((MAX_PAGE_BUFFER_COUNT - PageCount) * sizeof(PAGE_BUFFER)); packetLen = descSize + BufferLen; packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); @@ -854,16 +829,15 @@ VmbusChannelSendPacketPageBuffer( /* Setup the descriptor */ desc.Type = VmbusPacketTypeDataUsingGpaDirect; desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; - desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ - desc.Length8 = (u16)(packetLenAligned >> 3); + desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ + desc.Length8 = (u16) (packetLenAligned >> 3); desc.TransactionId = RequestId; desc.RangeCount = PageCount; - for (i=0; i<PageCount; i++) - { + for (i = 0; i < PageCount; i++) { desc.Range[i].Length = PageBuffers[i].Length; desc.Range[i].Offset = PageBuffers[i].Offset; - desc.Range[i].Pfn = PageBuffers[i].Pfn; + desc.Range[i].Pfn = PageBuffers[i].Pfn; } bufferList[0].Data = &desc; @@ -875,14 +849,10 @@ VmbusChannelSendPacketPageBuffer( bufferList[2].Data = &alignedData; bufferList[2].Length = packetLenAligned - packetLen; - ret = RingBufferWrite( - &Channel->Outbound, - bufferList, - 3); + ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - { + if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) { VmbusChannelSetEvent(Channel); } @@ -891,8 +861,6 @@ VmbusChannelSendPacketPageBuffer( return ret; } - - /*++ Name: @@ -903,34 +871,35 @@ Description: --*/ int -VmbusChannelSendPacketMultiPageBuffer( - VMBUS_CHANNEL *Channel, - MULTIPAGE_BUFFER *MultiPageBuffer, - void * Buffer, - u32 BufferLen, - u64 RequestId -) +VmbusChannelSendPacketMultiPageBuffer(VMBUS_CHANNEL * Channel, + MULTIPAGE_BUFFER * MultiPageBuffer, + void *Buffer, + u32 BufferLen, u64 RequestId) { - int ret=0; + int ret = 0; struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc; u32 descSize; u32 packetLen; u32 packetLenAligned; SG_BUFFER_LIST bufferList[3]; - u64 alignedData=0; - u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length); + u64 alignedData = 0; + u32 PfnCount = + NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length); DPRINT_ENTER(VMBUS); DumpVmbusChannel(Channel); - DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount); + DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", + MultiPageBuffer->Offset, MultiPageBuffer->Length, PfnCount); ASSERT(PfnCount > 0); ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT); /* Adjust the size down since VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER is the largest size we support */ - descSize = sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount)*sizeof(u64)); + descSize = + sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER) - + ((MAX_MULTIPAGE_BUFFER_COUNT - PfnCount) * sizeof(u64)); packetLen = descSize + BufferLen; packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); @@ -939,15 +908,16 @@ VmbusChannelSendPacketMultiPageBuffer( /* Setup the descriptor */ desc.Type = VmbusPacketTypeDataUsingGpaDirect; desc.Flags = VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; - desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ - desc.Length8 = (u16)(packetLenAligned >> 3); + desc.DataOffset8 = descSize >> 3; /* in 8-bytes grandularity */ + desc.Length8 = (u16) (packetLenAligned >> 3); desc.TransactionId = RequestId; desc.RangeCount = 1; desc.Range.Length = MultiPageBuffer->Length; desc.Range.Offset = MultiPageBuffer->Offset; - memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64)); + memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, + PfnCount * sizeof(u64)); bufferList[0].Data = &desc; bufferList[0].Length = descSize; @@ -958,14 +928,10 @@ VmbusChannelSendPacketMultiPageBuffer( bufferList[2].Data = &alignedData; bufferList[2].Length = packetLenAligned - packetLen; - ret = RingBufferWrite( - &Channel->Outbound, - bufferList, - 3); + ret = RingBufferWrite(&Channel->Outbound, bufferList, 3); /* TODO: We should determine if this is optional */ - if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) - { + if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) { VmbusChannelSetEvent(Channel); } @@ -974,7 +940,6 @@ VmbusChannelSendPacketMultiPageBuffer( return ret; } - /*++ Name: @@ -986,13 +951,9 @@ Description: --*/ /* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */ int -VmbusChannelRecvPacket( - VMBUS_CHANNEL *Channel, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ) +VmbusChannelRecvPacket(VMBUS_CHANNEL * Channel, + void *Buffer, + u32 BufferLen, u32 * BufferActualLen, u64 * RequestId) { VMPACKET_DESCRIPTOR desc; u32 packetLen; @@ -1007,9 +968,10 @@ VmbusChannelRecvPacket( spin_lock_irqsave(&Channel->inbound_lock, flags); - ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR)); - if (ret != 0) - { + ret = + RingBufferPeek(&Channel->Inbound, &desc, + sizeof(VMPACKET_DESCRIPTOR)); + if (ret != 0) { spin_unlock_irqrestore(&Channel->inbound_lock, flags); /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ @@ -1023,20 +985,18 @@ VmbusChannelRecvPacket( userLen = packetLen - (desc.DataOffset8 << 3); /* ASSERT(userLen > 0); */ - DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ", - Channel, - Channel->OfferMsg.ChildRelId, - desc.Type, - desc.Flags, - desc.TransactionId, packetLen, userLen); + DPRINT_DBG(VMBUS, + "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ", + Channel, Channel->OfferMsg.ChildRelId, desc.Type, desc.Flags, + desc.TransactionId, packetLen, userLen); *BufferActualLen = userLen; - if (userLen > BufferLen) - { + if (userLen > BufferLen) { spin_unlock_irqrestore(&Channel->inbound_lock, flags); - DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", BufferLen, userLen); + DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", + BufferLen, userLen); DPRINT_EXIT(VMBUS); return -1; @@ -1045,7 +1005,9 @@ VmbusChannelRecvPacket( *RequestId = desc.TransactionId; /* Copy over the packet to the user buffer */ - ret = RingBufferRead(&Channel->Inbound, Buffer, userLen, (desc.DataOffset8 << 3)); + ret = + RingBufferRead(&Channel->Inbound, Buffer, userLen, + (desc.DataOffset8 << 3)); spin_unlock_irqrestore(&Channel->inbound_lock, flags); @@ -1064,13 +1026,9 @@ Description: --*/ int -VmbusChannelRecvPacketRaw( - VMBUS_CHANNEL *Channel, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ) +VmbusChannelRecvPacketRaw(VMBUS_CHANNEL * Channel, + void *Buffer, + u32 BufferLen, u32 * BufferActualLen, u64 * RequestId) { VMPACKET_DESCRIPTOR desc; u32 packetLen; @@ -1085,9 +1043,10 @@ VmbusChannelRecvPacketRaw( spin_lock_irqsave(&Channel->inbound_lock, flags); - ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(VMPACKET_DESCRIPTOR)); - if (ret != 0) - { + ret = + RingBufferPeek(&Channel->Inbound, &desc, + sizeof(VMPACKET_DESCRIPTOR)); + if (ret != 0) { spin_unlock_irqrestore(&Channel->inbound_lock, flags); /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ @@ -1100,20 +1059,19 @@ VmbusChannelRecvPacketRaw( packetLen = desc.Length8 << 3; userLen = packetLen - (desc.DataOffset8 << 3); - DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ", - Channel, - Channel->OfferMsg.ChildRelId, - desc.Type, - desc.Flags, - desc.TransactionId, packetLen, userLen); + DPRINT_DBG(VMBUS, + "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ", + Channel, Channel->OfferMsg.ChildRelId, desc.Type, desc.Flags, + desc.TransactionId, packetLen, userLen); *BufferActualLen = packetLen; - if (packetLen > BufferLen) - { + if (packetLen > BufferLen) { spin_unlock_irqrestore(&Channel->inbound_lock, flags); - DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but got space for only %d bytes", packetLen, BufferLen); + DPRINT_ERR(VMBUS, + "buffer too small - needed %d bytes but got space for only %d bytes", + packetLen, BufferLen); DPRINT_EXIT(VMBUS); return -2; } @@ -1130,7 +1088,6 @@ VmbusChannelRecvPacketRaw( return 0; } - /*++ Name: @@ -1140,17 +1097,14 @@ Description: Channel event callback --*/ -void -VmbusChannelOnChannelEvent( - VMBUS_CHANNEL *Channel - ) +void VmbusChannelOnChannelEvent(VMBUS_CHANNEL * Channel) { DumpVmbusChannel(Channel); ASSERT(Channel->OnChannelCallback); #ifdef ENABLE_POLLING TimerStop(Channel->PollTimer); Channel->OnChannelCallback(Channel->ChannelCallbackContext); - TimerStart(Channel->PollTimer, 100 /* 100us */); + TimerStart(Channel->PollTimer, 100 /* 100us */ ); #else Channel->OnChannelCallback(Channel->ChannelCallbackContext); #endif @@ -1165,23 +1119,18 @@ Description: Timer event callback --*/ -void -VmbusChannelOnTimer( - void *Context - ) +void VmbusChannelOnTimer(void *Context) { - VMBUS_CHANNEL *channel = (VMBUS_CHANNEL*)Context; + VMBUS_CHANNEL *channel = (VMBUS_CHANNEL *) Context; - if (channel->OnChannelCallback) - { + if (channel->OnChannelCallback) { channel->OnChannelCallback(channel->ChannelCallbackContext); #ifdef ENABLE_POLLING - TimerStart(channel->PollTimer, 100 /* 100us */); + TimerStart(channel->PollTimer, 100 /* 100us */ ); #endif } } - /*++ Name: @@ -1191,15 +1140,11 @@ Description: Dump vmbus channel info to the console --*/ -static void -DumpVmbusChannel( - VMBUS_CHANNEL *Channel - ) +static void DumpVmbusChannel(VMBUS_CHANNEL * Channel) { DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId); DumpRingInfo(&Channel->Outbound, "Outbound "); DumpRingInfo(&Channel->Inbound, "Inbound "); } - /* eof */ diff --git a/drivers/staging/hv/Channel.h b/drivers/staging/hv/Channel.h index 5dac07b..891ecbd 100644 --- a/drivers/staging/hv/Channel.h +++ b/drivers/staging/hv/Channel.h @@ -21,7 +21,6 @@ * */ - #ifndef _CHANNEL_H_ #define _CHANNEL_H_ @@ -30,128 +29,84 @@ #pragma pack(push,1) - /* The format must be the same as VMDATA_GPA_DIRECT */ struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER { - u16 Type; - u16 DataOffset8; - u16 Length8; - u16 Flags; - u64 TransactionId; - u32 Reserved; - u32 RangeCount; - PAGE_BUFFER Range[MAX_PAGE_BUFFER_COUNT]; + u16 Type; + u16 DataOffset8; + u16 Length8; + u16 Flags; + u64 TransactionId; + u32 Reserved; + u32 RangeCount; + PAGE_BUFFER Range[MAX_PAGE_BUFFER_COUNT]; }; - /* The format must be the same as VMDATA_GPA_DIRECT */ struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER { - u16 Type; - u16 DataOffset8; - u16 Length8; - u16 Flags; - u64 TransactionId; - u32 Reserved; - u32 RangeCount; /* Always 1 in this case */ - MULTIPAGE_BUFFER Range; + u16 Type; + u16 DataOffset8; + u16 Length8; + u16 Flags; + u64 TransactionId; + u32 Reserved; + u32 RangeCount; /* Always 1 in this case */ + MULTIPAGE_BUFFER Range; }; #pragma pack(pop) - /* Routines */ - static int -VmbusChannelOpen( - VMBUS_CHANNEL *Channel, - u32 SendRingBufferSize, - u32 RecvRingBufferSize, - void * UserData, - u32 UserDataLen, - PFN_CHANNEL_CALLBACK pfnOnChannelCallback, - void * Context - ); +VmbusChannelOpen(VMBUS_CHANNEL * Channel, + u32 SendRingBufferSize, + u32 RecvRingBufferSize, + void *UserData, + u32 UserDataLen, + PFN_CHANNEL_CALLBACK pfnOnChannelCallback, void *Context); -static void -VmbusChannelClose( - VMBUS_CHANNEL *Channel - ); +static void VmbusChannelClose(VMBUS_CHANNEL * Channel); static int -VmbusChannelSendPacket( - VMBUS_CHANNEL *Channel, - const void * Buffer, - u32 BufferLen, - u64 RequestId, - VMBUS_PACKET_TYPE Type, - u32 Flags -); +VmbusChannelSendPacket(VMBUS_CHANNEL * Channel, + const void *Buffer, + u32 BufferLen, + u64 RequestId, VMBUS_PACKET_TYPE Type, u32 Flags); static int -VmbusChannelSendPacketPageBuffer( - VMBUS_CHANNEL *Channel, - PAGE_BUFFER PageBuffers[], - u32 PageCount, - void * Buffer, - u32 BufferLen, - u64 RequestId - ); +VmbusChannelSendPacketPageBuffer(VMBUS_CHANNEL * Channel, + PAGE_BUFFER PageBuffers[], + u32 PageCount, + void *Buffer, u32 BufferLen, u64 RequestId); static int -VmbusChannelSendPacketMultiPageBuffer( - VMBUS_CHANNEL *Channel, - MULTIPAGE_BUFFER *MultiPageBuffer, - void * Buffer, - u32 BufferLen, - u64 RequestId -); +VmbusChannelSendPacketMultiPageBuffer(VMBUS_CHANNEL * Channel, + MULTIPAGE_BUFFER * MultiPageBuffer, + void *Buffer, + u32 BufferLen, u64 RequestId); -static int -VmbusChannelEstablishGpadl( - VMBUS_CHANNEL *Channel, - void * Kbuffer, /* from kmalloc() */ - u32 Size, /* page-size multiple */ - u32 *GpadlHandle - ); +static int VmbusChannelEstablishGpadl(VMBUS_CHANNEL * Channel, void *Kbuffer, /* from kmalloc() */ + u32 Size, /* page-size multiple */ + u32 * GpadlHandle); -static int -VmbusChannelTeardownGpadl( - VMBUS_CHANNEL *Channel, - u32 GpadlHandle - ); +static int VmbusChannelTeardownGpadl(VMBUS_CHANNEL * Channel, u32 GpadlHandle); static int -VmbusChannelRecvPacket( - VMBUS_CHANNEL *Channel, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ); +VmbusChannelRecvPacket(VMBUS_CHANNEL * Channel, + void *Buffer, + u32 BufferLen, u32 * BufferActualLen, u64 * RequestId); static int -VmbusChannelRecvPacketRaw( - VMBUS_CHANNEL *Channel, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ); +VmbusChannelRecvPacketRaw(VMBUS_CHANNEL * Channel, + void *Buffer, + u32 BufferLen, + u32 * BufferActualLen, u64 * RequestId); -static void -VmbusChannelOnChannelEvent( - VMBUS_CHANNEL *Channel - ); +static void VmbusChannelOnChannelEvent(VMBUS_CHANNEL * Channel); static void -VmbusChannelGetDebugInfo( - VMBUS_CHANNEL *Channel, - VMBUS_CHANNEL_DEBUG_INFO *DebugInfo - ); +VmbusChannelGetDebugInfo(VMBUS_CHANNEL * Channel, + VMBUS_CHANNEL_DEBUG_INFO * DebugInfo); -static void -VmbusChannelOnTimer( - void *Context - ); +static void VmbusChannelOnTimer(void *Context); #endif /* _CHANNEL_H_ */ diff --git a/drivers/staging/hv/ChannelInterface.c b/drivers/staging/hv/ChannelInterface.c index 2a58015..13773a2 100644 --- a/drivers/staging/hv/ChannelInterface.c +++ b/drivers/staging/hv/ChannelInterface.c @@ -24,199 +24,161 @@ #include "VmbusPrivate.h" static int -IVmbusChannelOpen( - struct hv_device *Device, - u32 SendBufferSize, - u32 RecvRingBufferSize, - void * UserData, - u32 UserDataLen, - VMBUS_CHANNEL_CALLBACK ChannelCallback, - void * Context - ) +IVmbusChannelOpen(struct hv_device *Device, + u32 SendBufferSize, + u32 RecvRingBufferSize, + void *UserData, + u32 UserDataLen, + VMBUS_CHANNEL_CALLBACK ChannelCallback, void *Context) { - return VmbusChannelOpen( (VMBUS_CHANNEL*)Device->context, - SendBufferSize, - RecvRingBufferSize, - UserData, - UserDataLen, - ChannelCallback, - Context); + return VmbusChannelOpen((VMBUS_CHANNEL *) Device->context, + SendBufferSize, + RecvRingBufferSize, + UserData, + UserDataLen, ChannelCallback, Context); } - -static void -IVmbusChannelClose( - struct hv_device *Device - ) +static void IVmbusChannelClose(struct hv_device *Device) { - VmbusChannelClose((VMBUS_CHANNEL*)Device->context); + VmbusChannelClose((VMBUS_CHANNEL *) Device->context); } - static int -IVmbusChannelSendPacket( - struct hv_device *Device, - const void * Buffer, - u32 BufferLen, - u64 RequestId, - u32 Type, - u32 Flags - ) +IVmbusChannelSendPacket(struct hv_device *Device, + const void *Buffer, + u32 BufferLen, u64 RequestId, u32 Type, u32 Flags) { - return VmbusChannelSendPacket((VMBUS_CHANNEL*)Device->context, - Buffer, - BufferLen, - RequestId, - Type, - Flags); + return VmbusChannelSendPacket((VMBUS_CHANNEL *) Device->context, + Buffer, + BufferLen, RequestId, Type, Flags); } static int -IVmbusChannelSendPacketPageBuffer( - struct hv_device *Device, - PAGE_BUFFER PageBuffers[], - u32 PageCount, - void * Buffer, - u32 BufferLen, - u64 RequestId - ) +IVmbusChannelSendPacketPageBuffer(struct hv_device *Device, + PAGE_BUFFER PageBuffers[], + u32 PageCount, + void *Buffer, u32 BufferLen, u64 RequestId) { - return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL*)Device->context, - PageBuffers, - PageCount, - Buffer, - BufferLen, - RequestId); + return VmbusChannelSendPacketPageBuffer((VMBUS_CHANNEL *) Device-> + context, PageBuffers, PageCount, + Buffer, BufferLen, RequestId); } static int -IVmbusChannelSendPacketMultiPageBuffer( - struct hv_device *Device, - MULTIPAGE_BUFFER *MultiPageBuffer, - void * Buffer, - u32 BufferLen, - u64 RequestId - ) +IVmbusChannelSendPacketMultiPageBuffer(struct hv_device *Device, + MULTIPAGE_BUFFER * MultiPageBuffer, + void *Buffer, + u32 BufferLen, u64 RequestId) { - return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL*)Device->context, - MultiPageBuffer, - Buffer, - BufferLen, - RequestId); + return VmbusChannelSendPacketMultiPageBuffer((VMBUS_CHANNEL *) Device-> + context, MultiPageBuffer, + Buffer, BufferLen, + RequestId); } static int -IVmbusChannelRecvPacket ( - struct hv_device *Device, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ) +IVmbusChannelRecvPacket(struct hv_device *Device, + void *Buffer, + u32 BufferLen, u32 * BufferActualLen, u64 * RequestId) { - return VmbusChannelRecvPacket((VMBUS_CHANNEL*)Device->context, - Buffer, - BufferLen, - BufferActualLen, - RequestId); + return VmbusChannelRecvPacket((VMBUS_CHANNEL *) Device->context, + Buffer, + BufferLen, BufferActualLen, RequestId); } static int -IVmbusChannelRecvPacketRaw( - struct hv_device *Device, - void * Buffer, - u32 BufferLen, - u32* BufferActualLen, - u64* RequestId - ) +IVmbusChannelRecvPacketRaw(struct hv_device *Device, + void *Buffer, + u32 BufferLen, + u32 * BufferActualLen, u64 * RequestId) { - return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL*)Device->context, - Buffer, - BufferLen, - BufferActualLen, - RequestId); + return VmbusChannelRecvPacketRaw((VMBUS_CHANNEL *) Device->context, + Buffer, + BufferLen, BufferActualLen, RequestId); } static int -IVmbusChannelEstablishGpadl( - struct hv_device *Device, - void * Buffer, - u32 BufferLen, - u32* GpadlHandle - ) +IVmbusChannelEstablishGpadl(struct hv_device *Device, + void *Buffer, u32 BufferLen, u32 * GpadlHandle) { - return VmbusChannelEstablishGpadl((VMBUS_CHANNEL*)Device->context, - Buffer, - BufferLen, - GpadlHandle); + return VmbusChannelEstablishGpadl((VMBUS_CHANNEL *) Device->context, + Buffer, BufferLen, GpadlHandle); } -static int -IVmbusChannelTeardownGpadl( - struct hv_device *Device, - u32 GpadlHandle - ) +static int IVmbusChannelTeardownGpadl(struct hv_device *Device, u32 GpadlHandle) { - return VmbusChannelTeardownGpadl((VMBUS_CHANNEL*)Device->context, - GpadlHandle); + return VmbusChannelTeardownGpadl((VMBUS_CHANNEL *) Device->context, + GpadlHandle); } -static void -GetChannelInterface( - VMBUS_CHANNEL_INTERFACE *ChannelInterface - ) +static void GetChannelInterface(VMBUS_CHANNEL_INTERFACE * ChannelInterface) { - ChannelInterface->Open = IVmbusChannelOpen; - ChannelInterface->Close = IVmbusChannelClose; - ChannelInterface->SendPacket = IVmbusChannelSendPacket; - ChannelInterface->SendPacketPageBuffer = IVmbusChannelSendPacketPageBuffer; - ChannelInterface->SendPacketMultiPageBuffer = IVmbusChannelSendPacketMultiPageBuffer; - ChannelInterface->RecvPacket = IVmbusChannelRecvPacket; - ChannelInterface->RecvPacketRaw = IVmbusChannelRecvPacketRaw; - ChannelInterface->EstablishGpadl = IVmbusChannelEstablishGpadl; - ChannelInterface->TeardownGpadl = IVmbusChannelTeardownGpadl; - ChannelInterface->GetInfo = GetChannelInfo; + ChannelInterface->Open = IVmbusChannelOpen; + ChannelInterface->Close = IVmbusChannelClose; + ChannelInterface->SendPacket = IVmbusChannelSendPacket; + ChannelInterface->SendPacketPageBuffer = + IVmbusChannelSendPacketPageBuffer; + ChannelInterface->SendPacketMultiPageBuffer = + IVmbusChannelSendPacketMultiPageBuffer; + ChannelInterface->RecvPacket = IVmbusChannelRecvPacket; + ChannelInterface->RecvPacketRaw = IVmbusChannelRecvPacketRaw; + ChannelInterface->EstablishGpadl = IVmbusChannelEstablishGpadl; + ChannelInterface->TeardownGpadl = IVmbusChannelTeardownGpadl; + ChannelInterface->GetInfo = GetChannelInfo; } - -static void -GetChannelInfo( - struct hv_device *Device, - DEVICE_INFO *DeviceInfo - ) +static void GetChannelInfo(struct hv_device *Device, DEVICE_INFO * DeviceInfo) { VMBUS_CHANNEL_DEBUG_INFO debugInfo; - if (Device->context) - { - VmbusChannelGetDebugInfo((VMBUS_CHANNEL*)Device->context, &debugInfo); + if (Device->context) { + VmbusChannelGetDebugInfo((VMBUS_CHANNEL *) Device->context, + &debugInfo); DeviceInfo->ChannelId = debugInfo.RelId; DeviceInfo->ChannelState = debugInfo.State; - memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, sizeof(GUID)); - memcpy(&DeviceInfo->ChannelInstance, &debugInfo.InterfaceInstance, sizeof(GUID)); + memcpy(&DeviceInfo->ChannelType, &debugInfo.InterfaceType, + sizeof(GUID)); + memcpy(&DeviceInfo->ChannelInstance, + &debugInfo.InterfaceInstance, sizeof(GUID)); DeviceInfo->MonitorId = debugInfo.MonitorId; - DeviceInfo->ServerMonitorPending = debugInfo.ServerMonitorPending; - DeviceInfo->ServerMonitorLatency = debugInfo.ServerMonitorLatency; - DeviceInfo->ServerMonitorConnectionId = debugInfo.ServerMonitorConnectionId; - - DeviceInfo->ClientMonitorPending = debugInfo.ClientMonitorPending; - DeviceInfo->ClientMonitorLatency = debugInfo.ClientMonitorLatency; - DeviceInfo->ClientMonitorConnectionId = debugInfo.ClientMonitorConnectionId; - - DeviceInfo->Inbound.InterruptMask = debugInfo.Inbound.CurrentInterruptMask; - DeviceInfo->Inbound.ReadIndex = debugInfo.Inbound.CurrentReadIndex; - DeviceInfo->Inbound.WriteIndex = debugInfo.Inbound.CurrentWriteIndex; - DeviceInfo->Inbound.BytesAvailToRead = debugInfo.Inbound.BytesAvailToRead; - DeviceInfo->Inbound.BytesAvailToWrite = debugInfo.Inbound.BytesAvailToWrite; - - DeviceInfo->Outbound.InterruptMask = debugInfo.Outbound.CurrentInterruptMask; - DeviceInfo->Outbound.ReadIndex = debugInfo.Outbound.CurrentReadIndex; - DeviceInfo->Outbound.WriteIndex = debugInfo.Outbound.CurrentWriteIndex; - DeviceInfo->Outbound.BytesAvailToRead = debugInfo.Outbound.BytesAvailToRead; - DeviceInfo->Outbound.BytesAvailToWrite = debugInfo.Outbound.BytesAvailToWrite; + DeviceInfo->ServerMonitorPending = + debugInfo.ServerMonitorPending; + DeviceInfo->ServerMonitorLatency = + debugInfo.ServerMonitorLatency; + DeviceInfo->ServerMonitorConnectionId = + debugInfo.ServerMonitorConnectionId; + + DeviceInfo->ClientMonitorPending = + debugInfo.ClientMonitorPending; + DeviceInfo->ClientMonitorLatency = + debugInfo.ClientMonitorLatency; + DeviceInfo->ClientMonitorConnectionId = + debugInfo.ClientMonitorConnectionId; + + DeviceInfo->Inbound.InterruptMask = + debugInfo.Inbound.CurrentInterruptMask; + DeviceInfo->Inbound.ReadIndex = + debugInfo.Inbound.CurrentReadIndex; + DeviceInfo->Inbound.WriteIndex = + debugInfo.Inbound.CurrentWriteIndex; + DeviceInfo->Inbound.BytesAvailToRead = + debugInfo.Inbound.BytesAvailToRead; + DeviceInfo->Inbound.BytesAvailToWrite = + debugInfo.Inbound.BytesAvailToWrite; + + DeviceInfo->Outbound.InterruptMask = + debugInfo.Outbound.CurrentInterruptMask; + DeviceInfo->Outbound.ReadIndex = + debugInfo.Outbound.CurrentReadIndex; + DeviceInfo->Outbound.WriteIndex = + debugInfo.Outbound.CurrentWriteIndex; + DeviceInfo->Outbound.BytesAvailToRead = + debugInfo.Outbound.BytesAvailToRead; + DeviceInfo->Outbound.BytesAvailToWrite = + debugInfo.Outbound.BytesAvailToWrite; } } diff --git a/drivers/staging/hv/ChannelInterface.h b/drivers/staging/hv/ChannelInterface.h index 3385914..ea9f84c 100644 --- a/drivers/staging/hv/ChannelInterface.h +++ b/drivers/staging/hv/ChannelInterface.h @@ -21,21 +21,13 @@ * */ - #ifndef _CHANNEL_INTERFACE_H_ #define _CHANNEL_INTERFACE_H_ #include "include/VmbusApi.h" -static void -GetChannelInterface( - VMBUS_CHANNEL_INTERFACE *ChannelInterface - ); +static void GetChannelInterface(VMBUS_CHANNEL_INTERFACE * ChannelInterface); -static void -GetChannelInfo( - struct hv_device *Device, - DEVICE_INFO *DeviceInfo - ); +static void GetChannelInfo(struct hv_device *Device, DEVICE_INFO * DeviceInfo); #endif /* _CHANNEL_INTERFACE_H_ */ diff --git a/drivers/staging/hv/ChannelMgmt.c b/drivers/staging/hv/ChannelMgmt.c index 9da5740..1abae82 100644 --- a/drivers/staging/hv/ChannelMgmt.c +++ b/drivers/staging/hv/ChannelMgmt.c @@ -21,7 +21,6 @@ * */ - #include "include/osd.h" #include "include/logging.h" @@ -29,95 +28,68 @@ /* Data types */ -typedef void (*PFN_CHANNEL_MESSAGE_HANDLER)(VMBUS_CHANNEL_MESSAGE_HEADER* msg); +typedef void (*PFN_CHANNEL_MESSAGE_HANDLER) (VMBUS_CHANNEL_MESSAGE_HEADER * + msg); typedef struct _VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY { - VMBUS_CHANNEL_MESSAGE_TYPE messageType; + VMBUS_CHANNEL_MESSAGE_TYPE messageType; PFN_CHANNEL_MESSAGE_HANDLER messageHandler; } VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY; /* Internal routines */ -static void -VmbusChannelOnOffer( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); -static void -VmbusChannelOnOpenResult( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelOnOfferRescind( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelOnGpadlCreated( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelOnGpadlTorndown( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelOnOffersDelivered( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelOnVersionResponse( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ); - -static void -VmbusChannelProcessOffer( - void * context - ); - -static void -VmbusChannelProcessRescindOffer( - void * context - ); +static void VmbusChannelOnOffer(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); +static void VmbusChannelOnOpenResult(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); + +static void VmbusChannelOnOfferRescind(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); + +static void VmbusChannelOnGpadlCreated(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); + +static void VmbusChannelOnGpadlTorndown(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); + +static void VmbusChannelOnOffersDelivered(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); +static void VmbusChannelOnVersionResponse(PVMBUS_CHANNEL_MESSAGE_HEADER hdr); + +static void VmbusChannelProcessOffer(void *context); + +static void VmbusChannelProcessRescindOffer(void *context); /* Globals */ #define MAX_NUM_DEVICE_CLASSES_SUPPORTED 4 -const GUID gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED]= { +const GUID gSupportedDeviceClasses[MAX_NUM_DEVICE_CLASSES_SUPPORTED] = { /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ - {.Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}},/* Storage - SCSI */ + {.Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f}}, /* Storage - SCSI */ /* {F8615163-DF3E-46c5-913F-F2D2F965ED0E} */ {.Data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}}, /* Network */ /* {CFA8B69E-5B4A-4cc0-B98B-8BA1A1F3F95A} */ - {.Data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}}, /* Input */ + {.Data = {0x9E, 0xB6, 0xA8, 0xCF, 0x4A, 0x5B, 0xc0, 0x4c, 0xB9, 0x8B, 0x8B, 0xA1, 0xA1, 0xF3, 0xF9, 0x5A}}, /* Input */ /* {32412632-86cb-44a2-9b5c-50d1417354f5} */ - {.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}}, /* IDE */ + {.Data = {0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5}}, /* IDE */ }; /* Channel message dispatch table */ -VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount]= { - {ChannelMessageInvalid, NULL}, - {ChannelMessageOfferChannel, VmbusChannelOnOffer}, - {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind}, - {ChannelMessageRequestOffers, NULL}, - {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered}, - {ChannelMessageOpenChannel, NULL}, - {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult}, - {ChannelMessageCloseChannel, NULL}, - {ChannelMessageGpadlHeader, NULL}, - {ChannelMessageGpadlBody, NULL}, - {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated}, - {ChannelMessageGpadlTeardown, NULL}, - {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown}, - {ChannelMessageRelIdReleased, NULL}, - {ChannelMessageInitiateContact, NULL}, - {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse}, - {ChannelMessageUnload, NULL}, +VMBUS_CHANNEL_MESSAGE_TABLE_ENTRY gChannelMessageTable[ChannelMessageCount] = { + {ChannelMessageInvalid, NULL}, + {ChannelMessageOfferChannel, VmbusChannelOnOffer}, + {ChannelMessageRescindChannelOffer, VmbusChannelOnOfferRescind}, + {ChannelMessageRequestOffers, NULL}, + {ChannelMessageAllOffersDelivered, VmbusChannelOnOffersDelivered}, + {ChannelMessageOpenChannel, NULL}, + {ChannelMessageOpenChannelResult, VmbusChannelOnOpenResult}, + {ChannelMessageCloseChannel, NULL}, + {ChannelMessageGpadlHeader, NULL}, + {ChannelMessageGpadlBody, NULL}, + {ChannelMessageGpadlCreated, VmbusChannelOnGpadlCreated}, + {ChannelMessageGpadlTeardown, NULL}, + {ChannelMessageGpadlTorndown, VmbusChannelOnGpadlTorndown}, + {ChannelMessageRelIdReleased, NULL}, + {ChannelMessageInitiateContact, NULL}, + {ChannelMessageVersionResponse, VmbusChannelOnVersionResponse}, + {ChannelMessageUnload, NULL}, }; /*++ @@ -129,29 +101,26 @@ Description: Allocate and initialize a vmbus channel object --*/ -VMBUS_CHANNEL* AllocVmbusChannel(void) +VMBUS_CHANNEL *AllocVmbusChannel(void) { - VMBUS_CHANNEL* channel; + VMBUS_CHANNEL *channel; channel = kzalloc(sizeof(VMBUS_CHANNEL), GFP_ATOMIC); - if (!channel) - { + if (!channel) { return NULL; } spin_lock_init(&channel->inbound_lock); channel->PollTimer = TimerCreate(VmbusChannelOnTimer, channel); - if (!channel->PollTimer) - { + if (!channel->PollTimer) { kfree(channel); return NULL; } /* channel->dataWorkQueue = WorkQueueCreate("data"); */ channel->ControlWQ = WorkQueueCreate("control"); - if (!channel->ControlWQ) - { + if (!channel->ControlWQ) { TimerClose(channel->PollTimer); kfree(channel); return NULL; @@ -169,9 +138,9 @@ Description: Release the vmbus channel object itself --*/ -static inline void ReleaseVmbusChannel(void* Context) +static inline void ReleaseVmbusChannel(void *Context) { - VMBUS_CHANNEL* channel = (VMBUS_CHANNEL*)Context; + VMBUS_CHANNEL *channel = (VMBUS_CHANNEL *) Context; DPRINT_ENTER(VMBUS); @@ -193,16 +162,16 @@ Description: Release the resources used by the vmbus channel object --*/ -void FreeVmbusChannel(VMBUS_CHANNEL* Channel) +void FreeVmbusChannel(VMBUS_CHANNEL * Channel) { TimerClose(Channel->PollTimer); /* We have to release the channel's workqueue/thread in the vmbus's workqueue/thread context */ /* ie we can't destroy ourselves. */ - WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, (void*)Channel); + WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, ReleaseVmbusChannel, + (void *)Channel); } - /*++ Name: @@ -212,17 +181,14 @@ Description: Process the offer by creating a channel/device associated with this offer --*/ -static void -VmbusChannelProcessOffer( - void * context - ) +static void VmbusChannelProcessOffer(void *context) { - int ret=0; - VMBUS_CHANNEL* newChannel=(VMBUS_CHANNEL*)context; - LIST_ENTRY* anchor; - LIST_ENTRY* curr; + int ret = 0; + VMBUS_CHANNEL *newChannel = (VMBUS_CHANNEL *) context; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; bool fNew = true; - VMBUS_CHANNEL* channel; + VMBUS_CHANNEL *channel; unsigned long flags; DPRINT_ENTER(VMBUS); @@ -230,27 +196,29 @@ VmbusChannelProcessOffer( /* Make sure this is a new offer */ spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList) - { + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList) { channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry); - if (!memcmp(&channel->OfferMsg.Offer.InterfaceType, &newChannel->OfferMsg.Offer.InterfaceType,sizeof(GUID)) && - !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, &newChannel->OfferMsg.Offer.InterfaceInstance, sizeof(GUID))) - { + if (!memcmp + (&channel->OfferMsg.Offer.InterfaceType, + &newChannel->OfferMsg.Offer.InterfaceType, sizeof(GUID)) + && !memcmp(&channel->OfferMsg.Offer.InterfaceInstance, + &newChannel->OfferMsg.Offer.InterfaceInstance, + sizeof(GUID))) { fNew = false; break; } } - if (fNew) - { - INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, &newChannel->ListEntry); + if (fNew) { + INSERT_TAIL_LIST(&gVmbusConnection.ChannelList, + &newChannel->ListEntry); } spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); - if (!fNew) - { - DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", newChannel->OfferMsg.ChildRelId); + if (!fNew) { + DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", + newChannel->OfferMsg.ChildRelId); FreeVmbusChannel(newChannel); DPRINT_EXIT(VMBUS); return; @@ -258,12 +226,13 @@ VmbusChannelProcessOffer( /* Start the process of binding this offer to the driver */ /* We need to set the DeviceObject field before calling VmbusChildDeviceAdd() */ - newChannel->DeviceObject = VmbusChildDeviceCreate( - newChannel->OfferMsg.Offer.InterfaceType, - newChannel->OfferMsg.Offer.InterfaceInstance, - newChannel); + newChannel->DeviceObject = + VmbusChildDeviceCreate(newChannel->OfferMsg.Offer.InterfaceType, + newChannel->OfferMsg.Offer.InterfaceInstance, + newChannel); - DPRINT_DBG(VMBUS, "child device object allocated - %p", newChannel->DeviceObject); + DPRINT_DBG(VMBUS, "child device object allocated - %p", + newChannel->DeviceObject); /* * Add the new device to the bus. This will kick off device-driver @@ -272,19 +241,17 @@ VmbusChannelProcessOffer( */ ret = VmbusChildDeviceAdd(newChannel->DeviceObject); - if (ret != 0) - { - DPRINT_ERR(VMBUS, "unable to add child device object (relid %d)", - newChannel->OfferMsg.ChildRelId); + if (ret != 0) { + DPRINT_ERR(VMBUS, + "unable to add child device object (relid %d)", + newChannel->OfferMsg.ChildRelId); spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); REMOVE_ENTRY_LIST(&newChannel->ListEntry); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); FreeVmbusChannel(newChannel); - } - else - { + } else { /* * This state is used to indicate a successful open * so that when we do close the channel normally, we @@ -304,12 +271,9 @@ Description: Rescind the offer by initiating a device removal --*/ -static void -VmbusChannelProcessRescindOffer( - void * context - ) +static void VmbusChannelProcessRescindOffer(void *context) { - VMBUS_CHANNEL* channel=(VMBUS_CHANNEL*)context; + VMBUS_CHANNEL *channel = (VMBUS_CHANNEL *) context; DPRINT_ENTER(VMBUS); @@ -318,7 +282,6 @@ VmbusChannelProcessRescindOffer( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -330,33 +293,32 @@ Description: and queue a work item to the channel object to process the offer synchronously --*/ -static void -VmbusChannelOnOffer( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnOffer(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - VMBUS_CHANNEL_OFFER_CHANNEL* offer = (VMBUS_CHANNEL_OFFER_CHANNEL*)hdr; - VMBUS_CHANNEL* newChannel; + VMBUS_CHANNEL_OFFER_CHANNEL *offer = + (VMBUS_CHANNEL_OFFER_CHANNEL *) hdr; + VMBUS_CHANNEL *newChannel; GUID *guidType; GUID *guidInstance; int i; - int fSupported=0; + int fSupported = 0; DPRINT_ENTER(VMBUS); - for (i=0; i<MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) - { - if (memcmp(&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], sizeof(GUID)) == 0) - { + for (i = 0; i < MAX_NUM_DEVICE_CLASSES_SUPPORTED; i++) { + if (memcmp + (&offer->Offer.InterfaceType, &gSupportedDeviceClasses[i], + sizeof(GUID)) == 0) { fSupported = 1; break; } } - if (!fSupported) - { - DPRINT_DBG(VMBUS, "Ignoring channel offer notification for child relid %d", offer->ChildRelId); + if (!fSupported) { + DPRINT_DBG(VMBUS, + "Ignoring channel offer notification for child relid %d", + offer->ChildRelId); DPRINT_EXIT(VMBUS); return; @@ -365,36 +327,47 @@ VmbusChannelOnOffer( guidType = &offer->Offer.InterfaceType; guidInstance = &offer->Offer.InterfaceInstance; - DPRINT_INFO(VMBUS, "Channel offer notification - child relid %d monitor id %d allocated %d, " - "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x} " - "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", - offer->ChildRelId, - offer->MonitorId, - offer->MonitorAllocated, - guidType->Data[3], guidType->Data[2], guidType->Data[1], guidType->Data[0], guidType->Data[5], guidType->Data[4], guidType->Data[7], guidType->Data[6], guidType->Data[8], guidType->Data[9], guidType->Data[10], guidType->Data[11], guidType->Data[12], guidType->Data[13], guidType->Data[14], guidType->Data[15], - guidInstance->Data[3], guidInstance->Data[2], guidInstance->Data[1], guidInstance->Data[0], guidInstance->Data[5], guidInstance->Data[4], guidInstance->Data[7], guidInstance->Data[6], guidInstance->Data[8], guidInstance->Data[9], guidInstance->Data[10], guidInstance->Data[11], guidInstance->Data[12], guidInstance->Data[13], guidInstance->Data[14], guidInstance->Data[15]); + DPRINT_INFO(VMBUS, + "Channel offer notification - child relid %d monitor id %d allocated %d, " + "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x} " + "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", + offer->ChildRelId, offer->MonitorId, + offer->MonitorAllocated, guidType->Data[3], + guidType->Data[2], guidType->Data[1], guidType->Data[0], + guidType->Data[5], guidType->Data[4], guidType->Data[7], + guidType->Data[6], guidType->Data[8], guidType->Data[9], + guidType->Data[10], guidType->Data[11], guidType->Data[12], + guidType->Data[13], guidType->Data[14], guidType->Data[15], + guidInstance->Data[3], guidInstance->Data[2], + guidInstance->Data[1], guidInstance->Data[0], + guidInstance->Data[5], guidInstance->Data[4], + guidInstance->Data[7], guidInstance->Data[6], + guidInstance->Data[8], guidInstance->Data[9], + guidInstance->Data[10], guidInstance->Data[11], + guidInstance->Data[12], guidInstance->Data[13], + guidInstance->Data[14], guidInstance->Data[15]); /* Allocate the channel object and save this offer. */ newChannel = AllocVmbusChannel(); - if (!newChannel) - { + if (!newChannel) { DPRINT_ERR(VMBUS, "unable to allocate channel object"); return; } DPRINT_DBG(VMBUS, "channel object allocated - %p", newChannel); - memcpy(&newChannel->OfferMsg, offer, sizeof(VMBUS_CHANNEL_OFFER_CHANNEL)); - newChannel->MonitorGroup = (u8)offer->MonitorId / 32; - newChannel->MonitorBit = (u8)offer->MonitorId % 32; + memcpy(&newChannel->OfferMsg, offer, + sizeof(VMBUS_CHANNEL_OFFER_CHANNEL)); + newChannel->MonitorGroup = (u8) offer->MonitorId / 32; + newChannel->MonitorBit = (u8) offer->MonitorId % 32; /* TODO: Make sure the offer comes from our parent partition */ - WorkQueueQueueWorkItem(newChannel->ControlWQ, VmbusChannelProcessOffer, newChannel); + WorkQueueQueueWorkItem(newChannel->ControlWQ, VmbusChannelProcessOffer, + newChannel); DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -405,29 +378,27 @@ Description: synchronously --*/ -static void -VmbusChannelOnOfferRescind( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnOfferRescind(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - VMBUS_CHANNEL_RESCIND_OFFER* rescind = (VMBUS_CHANNEL_RESCIND_OFFER*)hdr; - VMBUS_CHANNEL* channel; + VMBUS_CHANNEL_RESCIND_OFFER *rescind = + (VMBUS_CHANNEL_RESCIND_OFFER *) hdr; + VMBUS_CHANNEL *channel; DPRINT_ENTER(VMBUS); channel = GetChannelFromRelId(rescind->ChildRelId); - if (channel == NULL) - { - DPRINT_DBG(VMBUS, "channel not found for relId %d", rescind->ChildRelId); + if (channel == NULL) { + DPRINT_DBG(VMBUS, "channel not found for relId %d", + rescind->ChildRelId); return; } - WorkQueueQueueWorkItem(channel->ControlWQ, VmbusChannelProcessRescindOffer, channel); + WorkQueueQueueWorkItem(channel->ControlWQ, + VmbusChannelProcessRescindOffer, channel); DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -438,16 +409,12 @@ Description: Nothing to do here. --*/ -static void -VmbusChannelOnOffersDelivered( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnOffersDelivered(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { DPRINT_ENTER(VMBUS); DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -459,17 +426,14 @@ Description: response and signal the requesting thread. --*/ -static void -VmbusChannelOnOpenResult( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnOpenResult(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - VMBUS_CHANNEL_OPEN_RESULT* result = (VMBUS_CHANNEL_OPEN_RESULT*)hdr; - LIST_ENTRY* anchor; - LIST_ENTRY* curr; - VMBUS_CHANNEL_MSGINFO* msgInfo; - VMBUS_CHANNEL_MESSAGE_HEADER* requestHeader; - VMBUS_CHANNEL_OPEN_CHANNEL* openMsg; + VMBUS_CHANNEL_OPEN_RESULT *result = (VMBUS_CHANNEL_OPEN_RESULT *) hdr; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; + VMBUS_CHANNEL_MSGINFO *msgInfo; + VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader; + VMBUS_CHANNEL_OPEN_CHANNEL *openMsg; unsigned long flags; DPRINT_ENTER(VMBUS); @@ -479,18 +443,16 @@ VmbusChannelOnOpenResult( /* Find the open msg, copy the result and signal/unblock the wait event */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) - { - msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr; - requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg; + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) { + msgInfo = (VMBUS_CHANNEL_MSGINFO *) curr; + requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER *) msgInfo->Msg; - if (requestHeader->MessageType == ChannelMessageOpenChannel) - { - openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL*)msgInfo->Msg; + if (requestHeader->MessageType == ChannelMessageOpenChannel) { + openMsg = (VMBUS_CHANNEL_OPEN_CHANNEL *) msgInfo->Msg; if (openMsg->ChildRelId == result->ChildRelId && - openMsg->OpenId == result->OpenId) - { - memcpy(&msgInfo->Response.OpenResult, result, sizeof(VMBUS_CHANNEL_OPEN_RESULT)); + openMsg->OpenId == result->OpenId) { + memcpy(&msgInfo->Response.OpenResult, result, + sizeof(VMBUS_CHANNEL_OPEN_RESULT)); WaitEventSet(msgInfo->WaitEvent); break; } @@ -501,7 +463,6 @@ VmbusChannelOnOpenResult( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -513,12 +474,10 @@ Description: response and signal the requesting thread. --*/ -static void -VmbusChannelOnGpadlCreated( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnGpadlCreated(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - VMBUS_CHANNEL_GPADL_CREATED *gpadlCreated = (VMBUS_CHANNEL_GPADL_CREATED*)hdr; + VMBUS_CHANNEL_GPADL_CREATED *gpadlCreated = + (VMBUS_CHANNEL_GPADL_CREATED *) hdr; LIST_ENTRY *anchor; LIST_ENTRY *curr; VMBUS_CHANNEL_MSGINFO *msgInfo; @@ -528,24 +487,26 @@ VmbusChannelOnGpadlCreated( DPRINT_ENTER(VMBUS); - DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", gpadlCreated->CreationStatus); + DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", + gpadlCreated->CreationStatus); /* Find the establish msg, copy the result and signal/unblock the wait event */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) - { - msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr; - requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg; + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) { + msgInfo = (VMBUS_CHANNEL_MSGINFO *) curr; + requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER *) msgInfo->Msg; - if (requestHeader->MessageType == ChannelMessageGpadlHeader) - { - gpadlHeader = (VMBUS_CHANNEL_GPADL_HEADER*)requestHeader; + if (requestHeader->MessageType == ChannelMessageGpadlHeader) { + gpadlHeader = + (VMBUS_CHANNEL_GPADL_HEADER *) requestHeader; - if ((gpadlCreated->ChildRelId == gpadlHeader->ChildRelId) && - (gpadlCreated->Gpadl == gpadlHeader->Gpadl)) - { - memcpy(&msgInfo->Response.GpadlCreated, gpadlCreated, sizeof(VMBUS_CHANNEL_GPADL_CREATED)); + if ((gpadlCreated->ChildRelId == + gpadlHeader->ChildRelId) + && (gpadlCreated->Gpadl == gpadlHeader->Gpadl)) { + memcpy(&msgInfo->Response.GpadlCreated, + gpadlCreated, + sizeof(VMBUS_CHANNEL_GPADL_CREATED)); WaitEventSet(msgInfo->WaitEvent); break; } @@ -556,7 +517,6 @@ VmbusChannelOnGpadlCreated( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -568,15 +528,13 @@ Description: response and signal the requesting thread. --*/ -static void -VmbusChannelOnGpadlTorndown( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnGpadlTorndown(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - VMBUS_CHANNEL_GPADL_TORNDOWN* gpadlTorndown = (VMBUS_CHANNEL_GPADL_TORNDOWN*)hdr; - LIST_ENTRY* anchor; - LIST_ENTRY* curr; - VMBUS_CHANNEL_MSGINFO* msgInfo; + VMBUS_CHANNEL_GPADL_TORNDOWN *gpadlTorndown = + (VMBUS_CHANNEL_GPADL_TORNDOWN *) hdr; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; + VMBUS_CHANNEL_MSGINFO *msgInfo; VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader; VMBUS_CHANNEL_GPADL_TEARDOWN *gpadlTeardown; unsigned long flags; @@ -586,18 +544,18 @@ VmbusChannelOnGpadlTorndown( /* Find the open msg, copy the result and signal/unblock the wait event */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) - { - msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr; - requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg; + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) { + msgInfo = (VMBUS_CHANNEL_MSGINFO *) curr; + requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER *) msgInfo->Msg; - if (requestHeader->MessageType == ChannelMessageGpadlTeardown) - { - gpadlTeardown = (VMBUS_CHANNEL_GPADL_TEARDOWN*)requestHeader; + if (requestHeader->MessageType == ChannelMessageGpadlTeardown) { + gpadlTeardown = + (VMBUS_CHANNEL_GPADL_TEARDOWN *) requestHeader; - if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl) - { - memcpy(&msgInfo->Response.GpadlTorndown, gpadlTorndown, sizeof(VMBUS_CHANNEL_GPADL_TORNDOWN)); + if (gpadlTorndown->Gpadl == gpadlTeardown->Gpadl) { + memcpy(&msgInfo->Response.GpadlTorndown, + gpadlTorndown, + sizeof(VMBUS_CHANNEL_GPADL_TORNDOWN)); WaitEventSet(msgInfo->WaitEvent); break; } @@ -608,7 +566,6 @@ VmbusChannelOnGpadlTorndown( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -620,32 +577,31 @@ Description: response and signal the requesting thread. --*/ -static void -VmbusChannelOnVersionResponse( - PVMBUS_CHANNEL_MESSAGE_HEADER hdr - ) +static void VmbusChannelOnVersionResponse(PVMBUS_CHANNEL_MESSAGE_HEADER hdr) { - LIST_ENTRY* anchor; - LIST_ENTRY* curr; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; VMBUS_CHANNEL_MSGINFO *msgInfo; VMBUS_CHANNEL_MESSAGE_HEADER *requestHeader; VMBUS_CHANNEL_INITIATE_CONTACT *initiate; - VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse = (VMBUS_CHANNEL_VERSION_RESPONSE*)hdr; + VMBUS_CHANNEL_VERSION_RESPONSE *versionResponse = + (VMBUS_CHANNEL_VERSION_RESPONSE *) hdr; unsigned long flags; DPRINT_ENTER(VMBUS); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) - { - msgInfo = (VMBUS_CHANNEL_MSGINFO*) curr; - requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg; + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelMsgList) { + msgInfo = (VMBUS_CHANNEL_MSGINFO *) curr; + requestHeader = (VMBUS_CHANNEL_MESSAGE_HEADER *) msgInfo->Msg; - if (requestHeader->MessageType == ChannelMessageInitiateContact) - { - initiate = (VMBUS_CHANNEL_INITIATE_CONTACT*)requestHeader; - memcpy(&msgInfo->Response.VersionResponse, versionResponse, sizeof(VMBUS_CHANNEL_VERSION_RESPONSE)); + if (requestHeader->MessageType == ChannelMessageInitiateContact) { + initiate = + (VMBUS_CHANNEL_INITIATE_CONTACT *) requestHeader; + memcpy(&msgInfo->Response.VersionResponse, + versionResponse, + sizeof(VMBUS_CHANNEL_VERSION_RESPONSE)); WaitEventSet(msgInfo->WaitEvent); } } @@ -654,7 +610,6 @@ VmbusChannelOnVersionResponse( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -665,38 +620,34 @@ Description: This is invoked in the vmbus worker thread context. --*/ -void -VmbusOnChannelMessage( - void *Context - ) +void VmbusOnChannelMessage(void *Context) { - HV_MESSAGE *msg=(HV_MESSAGE*)Context; - VMBUS_CHANNEL_MESSAGE_HEADER* hdr; + HV_MESSAGE *msg = (HV_MESSAGE *) Context; + VMBUS_CHANNEL_MESSAGE_HEADER *hdr; int size; DPRINT_ENTER(VMBUS); - hdr = (VMBUS_CHANNEL_MESSAGE_HEADER*)msg->u.Payload; - size=msg->Header.PayloadSize; + hdr = (VMBUS_CHANNEL_MESSAGE_HEADER *) msg->u.Payload; + size = msg->Header.PayloadSize; DPRINT_DBG(VMBUS, "message type %d size %d", hdr->MessageType, size); - if (hdr->MessageType >= ChannelMessageCount) - { - DPRINT_ERR(VMBUS, "Received invalid channel message type %d size %d", hdr->MessageType, size); + if (hdr->MessageType >= ChannelMessageCount) { + DPRINT_ERR(VMBUS, + "Received invalid channel message type %d size %d", + hdr->MessageType, size); print_hex_dump_bytes("", DUMP_PREFIX_NONE, (unsigned char *)msg->u.Payload, size); kfree(msg); return; } - if (gChannelMessageTable[hdr->MessageType].messageHandler) - { + if (gChannelMessageTable[hdr->MessageType].messageHandler) { gChannelMessageTable[hdr->MessageType].messageHandler(hdr); - } - else - { - DPRINT_ERR(VMBUS, "Unhandled channel message type %d", hdr->MessageType); + } else { + DPRINT_ERR(VMBUS, "Unhandled channel message type %d", + hdr->MessageType); } /* Free the msg that was allocated in VmbusOnMsgDPC() */ @@ -704,7 +655,6 @@ VmbusOnChannelMessage( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -714,50 +664,47 @@ Description: Send a request to get all our pending offers. --*/ -int -VmbusChannelRequestOffers( - void - ) +int VmbusChannelRequestOffers(void + ) { - int ret=0; - VMBUS_CHANNEL_MESSAGE_HEADER* msg; - VMBUS_CHANNEL_MSGINFO* msgInfo; + int ret = 0; + VMBUS_CHANNEL_MESSAGE_HEADER *msg; + VMBUS_CHANNEL_MSGINFO *msgInfo; DPRINT_ENTER(VMBUS); - msgInfo = kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER), GFP_KERNEL); + msgInfo = + kmalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_MESSAGE_HEADER), GFP_KERNEL); ASSERT(msgInfo != NULL); msgInfo->WaitEvent = WaitEventCreate(); - msg = (VMBUS_CHANNEL_MESSAGE_HEADER*)msgInfo->Msg; + msg = (VMBUS_CHANNEL_MESSAGE_HEADER *) msgInfo->Msg; msg->MessageType = ChannelMessageRequestOffers; /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ + INSERT_TAIL_LIST(&gVmbusConnection.channelMsgList, &msgInfo->msgListEntry); + SpinlockRelease(gVmbusConnection.channelMsgLock); */ ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_MESSAGE_HEADER)); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret); /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ + REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); + SpinlockRelease(gVmbusConnection.channelMsgLock); */ goto Cleanup; } /* WaitEventWait(msgInfo->waitEvent); */ /*SpinlockAcquire(gVmbusConnection.channelMsgLock); - REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); - SpinlockRelease(gVmbusConnection.channelMsgLock);*/ - + REMOVE_ENTRY_LIST(&msgInfo->msgListEntry); + SpinlockRelease(gVmbusConnection.channelMsgLock); */ Cleanup: - if (msgInfo) - { + if (msgInfo) { WaitEventClose(msgInfo->WaitEvent); kfree(msgInfo); } @@ -776,38 +723,33 @@ Description: Release channels that are unattached/unconnected ie (no drivers associated) --*/ -void -VmbusChannelReleaseUnattachedChannels( - void - ) +void VmbusChannelReleaseUnattachedChannels(void + ) { LIST_ENTRY *entry; VMBUS_CHANNEL *channel; - VMBUS_CHANNEL *start=NULL; + VMBUS_CHANNEL *start = NULL; unsigned long flags; spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - while (!IsListEmpty(&gVmbusConnection.ChannelList)) - { + while (!IsListEmpty(&gVmbusConnection.ChannelList)) { entry = TOP_LIST_ENTRY(&gVmbusConnection.ChannelList); channel = CONTAINING_RECORD(entry, VMBUS_CHANNEL, ListEntry); if (channel == start) break; - if (!channel->DeviceObject->Driver) - { + if (!channel->DeviceObject->Driver) { REMOVE_ENTRY_LIST(&channel->ListEntry); - DPRINT_INFO(VMBUS, "Releasing unattached device object %p", channel->DeviceObject); + DPRINT_INFO(VMBUS, + "Releasing unattached device object %p", + channel->DeviceObject); VmbusChildDeviceRemove(channel->DeviceObject); FreeVmbusChannel(channel); - } - else - { - if (!start) - { + } else { + if (!start) { start = channel; } } diff --git a/drivers/staging/hv/ChannelMgmt.h b/drivers/staging/hv/ChannelMgmt.h index 71173d0..ab2191e 100644 --- a/drivers/staging/hv/ChannelMgmt.h +++ b/drivers/staging/hv/ChannelMgmt.h @@ -21,7 +21,6 @@ * */ - #ifndef _CHANNEL_MGMT_H_ #define _CHANNEL_MGMT_H_ @@ -32,9 +31,7 @@ #include "include/VmbusChannelInterface.h" #include "include/ChannelMessages.h" - - -typedef void (*PFN_CHANNEL_CALLBACK)(void * context); +typedef void (*PFN_CHANNEL_CALLBACK) (void *context); typedef enum { CHANNEL_OFFER_STATE, @@ -43,65 +40,62 @@ typedef enum { } VMBUS_CHANNEL_STATE; typedef struct _VMBUS_CHANNEL { - LIST_ENTRY ListEntry; + LIST_ENTRY ListEntry; struct hv_device *DeviceObject; - struct osd_timer *PollTimer; /* SA-111 workaround */ + struct osd_timer *PollTimer; /* SA-111 workaround */ - VMBUS_CHANNEL_STATE State; + VMBUS_CHANNEL_STATE State; VMBUS_CHANNEL_OFFER_CHANNEL OfferMsg; /* These are based on the OfferMsg.MonitorId. Save it here for easy access. */ - u8 MonitorGroup; - u8 MonitorBit; + u8 MonitorGroup; + u8 MonitorBit; - u32 RingBufferGpadlHandle; + u32 RingBufferGpadlHandle; /* Allocated memory for ring buffer */ - void * RingBufferPages; - u32 RingBufferPageCount; - RING_BUFFER_INFO Outbound; /* send to parent */ - RING_BUFFER_INFO Inbound; /* receive from parent */ + void *RingBufferPages; + u32 RingBufferPageCount; + RING_BUFFER_INFO Outbound; /* send to parent */ + RING_BUFFER_INFO Inbound; /* receive from parent */ spinlock_t inbound_lock; struct workqueue_struct *ControlWQ; /* Channel callback are invoked in this workqueue context */ - /* HANDLE dataWorkQueue; */ + /* HANDLE dataWorkQueue; */ - PFN_CHANNEL_CALLBACK OnChannelCallback; - void * ChannelCallbackContext; + PFN_CHANNEL_CALLBACK OnChannelCallback; + void *ChannelCallbackContext; } VMBUS_CHANNEL; - typedef struct _VMBUS_CHANNEL_DEBUG_INFO { - u32 RelId; - VMBUS_CHANNEL_STATE State; - GUID InterfaceType; - GUID InterfaceInstance; - u32 MonitorId; - u32 ServerMonitorPending; - u32 ServerMonitorLatency; - u32 ServerMonitorConnectionId; - u32 ClientMonitorPending; - u32 ClientMonitorLatency; - u32 ClientMonitorConnectionId; - - RING_BUFFER_DEBUG_INFO Inbound; - RING_BUFFER_DEBUG_INFO Outbound; + u32 RelId; + VMBUS_CHANNEL_STATE State; + GUID InterfaceType; + GUID InterfaceInstance; + u32 MonitorId; + u32 ServerMonitorPending; + u32 ServerMonitorLatency; + u32 ServerMonitorConnectionId; + u32 ClientMonitorPending; + u32 ClientMonitorLatency; + u32 ClientMonitorConnectionId; + + RING_BUFFER_DEBUG_INFO Inbound; + RING_BUFFER_DEBUG_INFO Outbound; } VMBUS_CHANNEL_DEBUG_INFO; - typedef union { - VMBUS_CHANNEL_VERSION_SUPPORTED VersionSupported; - VMBUS_CHANNEL_OPEN_RESULT OpenResult; - VMBUS_CHANNEL_GPADL_TORNDOWN GpadlTorndown; - VMBUS_CHANNEL_GPADL_CREATED GpadlCreated; - VMBUS_CHANNEL_VERSION_RESPONSE VersionResponse; + VMBUS_CHANNEL_VERSION_SUPPORTED VersionSupported; + VMBUS_CHANNEL_OPEN_RESULT OpenResult; + VMBUS_CHANNEL_GPADL_TORNDOWN GpadlTorndown; + VMBUS_CHANNEL_GPADL_CREATED GpadlCreated; + VMBUS_CHANNEL_VERSION_RESPONSE VersionResponse; } VMBUS_CHANNEL_MESSAGE_RESPONSE; - /* * Represents each channel msg on the vmbus connection This is a * variable-size data structure depending on the msg type itself @@ -109,48 +103,35 @@ typedef union { typedef struct _VMBUS_CHANNEL_MSGINFO { /* Bookkeeping stuff */ - LIST_ENTRY MsgListEntry; + LIST_ENTRY MsgListEntry; /* So far, this is only used to handle gpadl body message */ - LIST_ENTRY SubMsgList; + LIST_ENTRY SubMsgList; /* Synchronize the request/response if needed */ struct osd_waitevent *WaitEvent; VMBUS_CHANNEL_MESSAGE_RESPONSE Response; - u32 MessageSize; + u32 MessageSize; /* The channel message that goes out on the "wire". */ /* It will contain at minimum the VMBUS_CHANNEL_MESSAGE_HEADER header */ - unsigned char Msg[0]; + unsigned char Msg[0]; } VMBUS_CHANNEL_MSGINFO; - /* Routines */ -static VMBUS_CHANNEL* -AllocVmbusChannel( - void - ); - -static void -FreeVmbusChannel( - VMBUS_CHANNEL *Channel - ); - -static void -VmbusOnChannelMessage( - void *Context - ); - -static int -VmbusChannelRequestOffers( - void - ); - -static void -VmbusChannelReleaseUnattachedChannels( - void - ); +static VMBUS_CHANNEL *AllocVmbusChannel(void + ); + +static void FreeVmbusChannel(VMBUS_CHANNEL * Channel); + +static void VmbusOnChannelMessage(void *Context); + +static int VmbusChannelRequestOffers(void + ); + +static void VmbusChannelReleaseUnattachedChannels(void + ); #endif /* _CHANNEL_MGMT_H_ */ diff --git a/drivers/staging/hv/Connection.c b/drivers/staging/hv/Connection.c index 7b480f0..a2fb7e6 100644 --- a/drivers/staging/hv/Connection.c +++ b/drivers/staging/hv/Connection.c @@ -21,20 +21,17 @@ * */ - #include "include/logging.h" #include "VmbusPrivate.h" /* Globals */ - struct VMBUS_CONNECTION gVmbusConnection = { - .ConnectState = Disconnected, - .NextGpadlHandle = 0xE1E10, + .ConnectState = Disconnected, + .NextGpadlHandle = 0xE1E10, }; - /*++ Name: @@ -44,12 +41,10 @@ Description: Sends a connect request on the partition service connection --*/ -int -VmbusConnect( - ) +int VmbusConnect() { - int ret=0; - VMBUS_CHANNEL_MSGINFO *msgInfo=NULL; + int ret = 0; + VMBUS_CHANNEL_MSGINFO *msgInfo = NULL; VMBUS_CHANNEL_INITIATE_CONTACT *msg; unsigned long flags; @@ -74,58 +69,62 @@ VmbusConnect( * abstraction stuff */ gVmbusConnection.InterruptPage = PageAlloc(1); - if (gVmbusConnection.InterruptPage == NULL) - { + if (gVmbusConnection.InterruptPage == NULL) { ret = -1; goto Cleanup; } gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage; - gVmbusConnection.SendInterruptPage = (void*)((unsigned long)gVmbusConnection.InterruptPage + (PAGE_SIZE >> 1)); + gVmbusConnection.SendInterruptPage = + (void *)((unsigned long)gVmbusConnection.InterruptPage + + (PAGE_SIZE >> 1)); /* Setup the monitor * notification facility. The 1st page for parent->child and * the 2nd page for child->parent */ gVmbusConnection.MonitorPages = PageAlloc(2); - if (gVmbusConnection.MonitorPages == NULL) - { + if (gVmbusConnection.MonitorPages == NULL) { ret = -1; goto Cleanup; } - msgInfo = kzalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT), GFP_KERNEL); - if (msgInfo == NULL) - { + msgInfo = + kzalloc(sizeof(VMBUS_CHANNEL_MSGINFO) + + sizeof(VMBUS_CHANNEL_INITIATE_CONTACT), GFP_KERNEL); + if (msgInfo == NULL) { ret = -1; goto Cleanup; } msgInfo->WaitEvent = WaitEventCreate(); - msg = (VMBUS_CHANNEL_INITIATE_CONTACT*)msgInfo->Msg; + msg = (VMBUS_CHANNEL_INITIATE_CONTACT *) msgInfo->Msg; msg->Header.MessageType = ChannelMessageInitiateContact; msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; msg->InterruptPage = GetPhysicalAddress(gVmbusConnection.InterruptPage); msg->MonitorPage1 = GetPhysicalAddress(gVmbusConnection.MonitorPages); - msg->MonitorPage2 = GetPhysicalAddress((void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE)); + msg->MonitorPage2 = + GetPhysicalAddress((void *)((unsigned long)gVmbusConnection. + MonitorPages + PAGE_SIZE)); /* * Add to list before we send the request since we may * receive the response before returning from this routine */ spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); - INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &msgInfo->MsgListEntry); + INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, + &msgInfo->MsgListEntry); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); - DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx", - msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); + DPRINT_DBG(VMBUS, + "Vmbus connection - interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx", + msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_INITIATE_CONTACT)); - if (ret != 0) - { + if (ret != 0) { REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); goto Cleanup; } @@ -136,21 +135,19 @@ VmbusConnect( REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); /* Check if successful */ - if (msgInfo->Response.VersionResponse.VersionSupported) - { + if (msgInfo->Response.VersionResponse.VersionSupported) { DPRINT_INFO(VMBUS, "Vmbus connected!!"); gVmbusConnection.ConnectState = Connected; - } - else - { - DPRINT_ERR(VMBUS, "Vmbus connection failed!!...current version (%d) not supported", VMBUS_REVISION_NUMBER); + } else { + DPRINT_ERR(VMBUS, + "Vmbus connection failed!!...current version (%d) not supported", + VMBUS_REVISION_NUMBER); ret = -1; goto Cleanup; } - WaitEventClose(msgInfo->WaitEvent); kfree(msgInfo); DPRINT_EXIT(VMBUS); @@ -163,20 +160,17 @@ Cleanup: WorkQueueClose(gVmbusConnection.WorkQueue); - if (gVmbusConnection.InterruptPage) - { + if (gVmbusConnection.InterruptPage) { PageFree(gVmbusConnection.InterruptPage, 1); gVmbusConnection.InterruptPage = NULL; } - if (gVmbusConnection.MonitorPages) - { + if (gVmbusConnection.MonitorPages) { PageFree(gVmbusConnection.MonitorPages, 2); gVmbusConnection.MonitorPages = NULL; } - if (msgInfo) - { + if (msgInfo) { if (msgInfo->WaitEvent) WaitEventClose(msgInfo->WaitEvent); @@ -188,7 +182,6 @@ Cleanup: return ret; } - /*++ Name: @@ -198,12 +191,10 @@ Description: Sends a disconnect request on the partition service connection --*/ -int -VmbusDisconnect( - void - ) +int VmbusDisconnect(void + ) { - int ret=0; + int ret = 0; VMBUS_CHANNEL_UNLOAD *msg; DPRINT_ENTER(VMBUS); @@ -218,8 +209,7 @@ VmbusDisconnect( ret = VmbusPostMessage(msg, sizeof(VMBUS_CHANNEL_UNLOAD)); - if (ret != 0) - { + if (ret != 0) { goto Cleanup; } @@ -234,8 +224,7 @@ VmbusDisconnect( DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); Cleanup: - if (msg) - { + if (msg) { kfree(msg); } @@ -244,7 +233,6 @@ Cleanup: return ret; } - /*++ Name: @@ -254,24 +242,19 @@ Description: Get the channel object given its child relative id (ie channel id) --*/ -VMBUS_CHANNEL* -GetChannelFromRelId( - u32 relId - ) +VMBUS_CHANNEL *GetChannelFromRelId(u32 relId) { - VMBUS_CHANNEL* channel; - VMBUS_CHANNEL* foundChannel=NULL; - LIST_ENTRY* anchor; - LIST_ENTRY* curr; + VMBUS_CHANNEL *channel; + VMBUS_CHANNEL *foundChannel = NULL; + LIST_ENTRY *anchor; + LIST_ENTRY *curr; unsigned long flags; spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList) - { + ITERATE_LIST_ENTRIES(anchor, curr, &gVmbusConnection.ChannelList) { channel = CONTAINING_RECORD(curr, VMBUS_CHANNEL, ListEntry); - if (channel->OfferMsg.ChildRelId == relId) - { + if (channel->OfferMsg.ChildRelId == relId) { foundChannel = channel; break; } @@ -281,8 +264,6 @@ GetChannelFromRelId( return foundChannel; } - - /*++ Name: @@ -292,13 +273,10 @@ Description: Process a channel event notification --*/ -static void -VmbusProcessChannelEvent( - void * context - ) +static void VmbusProcessChannelEvent(void *context) { - VMBUS_CHANNEL* channel; - u32 relId = (u32)(unsigned long)context; + VMBUS_CHANNEL *channel; + u32 relId = (u32) (unsigned long)context; ASSERT(relId > 0); @@ -308,18 +286,14 @@ VmbusProcessChannelEvent( */ channel = GetChannelFromRelId(relId); - if (channel) - { + if (channel) { VmbusChannelOnChannelEvent(channel); /* WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel); */ - } - else - { - DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); + } else { + DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); } } - /*++ Name: @@ -329,51 +303,50 @@ Description: Handler for events --*/ -void -VmbusOnEvents( - void - ) +void VmbusOnEvents(void + ) { int dword; /* int maxdword = PAGE_SIZE >> 3; // receive size is 1/2 page and divide that by 4 bytes */ int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; int bit; int relid; - u32* recvInterruptPage = gVmbusConnection.RecvInterruptPage; + u32 *recvInterruptPage = gVmbusConnection.RecvInterruptPage; /* VMBUS_CHANNEL_MESSAGE* receiveMsg; */ DPRINT_ENTER(VMBUS); /* Check events */ - if (recvInterruptPage) - { - for (dword = 0; dword < maxdword; dword++) - { - if (recvInterruptPage[dword]) - { - for (bit = 0; bit < 32; bit++) - { - if (BitTestAndClear(&recvInterruptPage[dword], bit)) - { + if (recvInterruptPage) { + for (dword = 0; dword < maxdword; dword++) { + if (recvInterruptPage[dword]) { + for (bit = 0; bit < 32; bit++) { + if (BitTestAndClear + (&recvInterruptPage[dword], bit)) { relid = (dword << 5) + bit; - DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); + DPRINT_DBG(VMBUS, + "event detected for relid - %d", + relid); - if (relid == 0) /* special case - vmbus channel protocol msg */ - { - DPRINT_DBG(VMBUS, "invalid relid - %d", relid); + if (relid == 0) { /* special case - vmbus channel protocol msg */ + DPRINT_DBG(VMBUS, + "invalid relid - %d", + relid); - continue; } - else - { + continue; + } else { /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ - VmbusProcessChannelEvent((void*)(unsigned long)relid); + VmbusProcessChannelEvent + ((void *)(unsigned + long) + relid); } } } } - } + } } DPRINT_EXIT(VMBUS); @@ -389,25 +362,16 @@ Description: Send a msg on the vmbus's message connection --*/ -int -VmbusPostMessage( - void * buffer, - size_t bufferLen - ) +int VmbusPostMessage(void *buffer, size_t bufferLen) { - int ret=0; + int ret = 0; HV_CONNECTION_ID connId; - - connId.Asu32 =0; + connId.Asu32 = 0; connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; - ret = HvPostMessage( - connId, - 1, - buffer, - bufferLen); + ret = HvPostMessage(connId, 1, buffer, bufferLen); - return ret; + return ret; } /*++ @@ -419,15 +383,15 @@ Description: Send an event notification to the parent --*/ -int -VmbusSetEvent(u32 childRelId) +int VmbusSetEvent(u32 childRelId) { - int ret=0; + int ret = 0; DPRINT_ENTER(VMBUS); /* Each u32 represents 32 channels */ - BitSet((u32*)gVmbusConnection.SendInterruptPage + (childRelId >> 5), childRelId & 31); + BitSet((u32 *) gVmbusConnection.SendInterruptPage + (childRelId >> 5), + childRelId & 31); ret = HvSignalEvent(); DPRINT_EXIT(VMBUS); diff --git a/drivers/staging/hv/Hv.c b/drivers/staging/hv/Hv.c index 0883179..2cb8250 100644 --- a/drivers/staging/hv/Hv.c +++ b/drivers/staging/hv/Hv.c @@ -21,21 +21,19 @@ * */ - #include "include/logging.h" #include "VmbusPrivate.h" /* Globals */ /* The one and only */ -HV_CONTEXT gHvContext={ +HV_CONTEXT gHvContext = { .SynICInitialized = false, .HypercallPage = NULL, .SignalEventParam = NULL, .SignalEventBuffer = NULL, }; - /*++ Name: @@ -45,28 +43,25 @@ Description: Query the cpuid for presense of windows hypervisor --*/ -static int -HvQueryHypervisorPresence ( - void +static int HvQueryHypervisorPresence(void ) { - unsigned int eax; - unsigned int ebx; - unsigned int ecx; - unsigned int edx; - unsigned int op; - - eax = 0; - ebx = 0; - ecx = 0; - edx = 0; - op = HvCpuIdFunctionVersionAndFeatures; - do_cpuid(op, &eax, &ebx, &ecx, &edx); + unsigned int eax; + unsigned int ebx; + unsigned int ecx; + unsigned int edx; + unsigned int op; + + eax = 0; + ebx = 0; + ecx = 0; + edx = 0; + op = HvCpuIdFunctionVersionAndFeatures; + do_cpuid(op, &eax, &ebx, &ecx, &edx); return (ecx & HV_PRESENT_BIT); } - /*++ Name: @@ -76,77 +71,68 @@ Description: Get version info of the windows hypervisor --*/ -static int -HvQueryHypervisorInfo ( - void +static int HvQueryHypervisorInfo(void ) { - unsigned int eax; - unsigned int ebx; - unsigned int ecx; - unsigned int edx; - unsigned int maxLeaf; - unsigned int op; - - /* - * Its assumed that this is called after confirming that Viridian - * is present. Query id and revision. - */ - - - eax = 0; - ebx = 0; - ecx = 0; - edx = 0; - op = HvCpuIdFunctionHvVendorAndMaxFunction; - do_cpuid(op, &eax, &ebx, &ecx, &edx); - - DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", - (ebx & 0xFF), - ((ebx >> 8) & 0xFF), - ((ebx >> 16) & 0xFF), - ((ebx >> 24) & 0xFF), - (ecx & 0xFF), - ((ecx >> 8) & 0xFF), - ((ecx >> 16) & 0xFF), - ((ecx >> 24) & 0xFF), - (edx & 0xFF), - ((edx >> 8) & 0xFF), - ((edx >> 16) & 0xFF), - ((edx >> 24) & 0xFF)); - - maxLeaf = eax; - eax = 0; - ebx = 0; - ecx = 0; - edx = 0; - op = HvCpuIdFunctionHvInterface; - do_cpuid(op, &eax, &ebx, &ecx, &edx); - - DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", - (eax & 0xFF), - ((eax >> 8) & 0xFF), - ((eax >> 16) & 0xFF), - ((eax >> 24) & 0xFF)); - - if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { + unsigned int eax; + unsigned int ebx; + unsigned int ecx; + unsigned int edx; + unsigned int maxLeaf; + unsigned int op; + + /* + * Its assumed that this is called after confirming that Viridian + * is present. Query id and revision. + */ + eax = 0; ebx = 0; ecx = 0; edx = 0; - op = HvCpuIdFunctionMsHvVersion; + op = HvCpuIdFunctionHvVendorAndMaxFunction; + do_cpuid(op, &eax, &ebx, &ecx, &edx); + + DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", + (ebx & 0xFF), + ((ebx >> 8) & 0xFF), + ((ebx >> 16) & 0xFF), + ((ebx >> 24) & 0xFF), + (ecx & 0xFF), + ((ecx >> 8) & 0xFF), + ((ecx >> 16) & 0xFF), + ((ecx >> 24) & 0xFF), + (edx & 0xFF), + ((edx >> 8) & 0xFF), + ((edx >> 16) & 0xFF), ((edx >> 24) & 0xFF)); + + maxLeaf = eax; + eax = 0; + ebx = 0; + ecx = 0; + edx = 0; + op = HvCpuIdFunctionHvInterface; do_cpuid(op, &eax, &ebx, &ecx, &edx); - DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d", - eax, - ebx >> 16, - ebx & 0xFFFF, - ecx, - edx >> 24, - edx & 0xFFFFFF); - } - return maxLeaf; -} + DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", + (eax & 0xFF), + ((eax >> 8) & 0xFF), + ((eax >> 16) & 0xFF), ((eax >> 24) & 0xFF)); + + if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { + eax = 0; + ebx = 0; + ecx = 0; + edx = 0; + op = HvCpuIdFunctionMsHvVersion; + do_cpuid(op, &eax, &ebx, &ecx, &edx); + DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d", + eax, + ebx >> 16, + ebx & 0xFFFF, ecx, edx >> 24, edx & 0xFFFFFF); + } + return maxLeaf; +} /*++ @@ -157,59 +143,54 @@ Description: Invoke the specified hypercall --*/ -static u64 -HvDoHypercall ( - u64 Control, - void* Input, - void* Output - ) +static u64 HvDoHypercall(u64 Control, void *Input, void *Output) { #ifdef CONFIG_X86_64 - u64 hvStatus=0; - u64 inputAddress = (Input)? GetPhysicalAddress(Input) : 0; - u64 outputAddress = (Output)? GetPhysicalAddress(Output) : 0; - volatile void* hypercallPage = gHvContext.HypercallPage; + u64 hvStatus = 0; + u64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0; + u64 outputAddress = (Output) ? GetPhysicalAddress(Output) : 0; + volatile void *hypercallPage = gHvContext.HypercallPage; - DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p output phys %llx virt %p hypercall %p>", - Control, - inputAddress, - Input, - outputAddress, - Output, - hypercallPage); + DPRINT_DBG(VMBUS, + "Hypercall <control %llx input phys %llx virt %p output phys %llx virt %p hypercall %p>", + Control, inputAddress, Input, outputAddress, Output, + hypercallPage); - __asm__ __volatile__ ("mov %0, %%r8" : : "r" (outputAddress): "r8"); - __asm__ __volatile__ ("call *%3" : "=a"(hvStatus): "c" (Control), "d" (inputAddress), "m" (hypercallPage)); + __asm__ __volatile__("mov %0, %%r8"::"r"(outputAddress):"r8"); + __asm__ __volatile__("call *%3":"=a"(hvStatus):"c"(Control), + "d"(inputAddress), "m"(hypercallPage)); - DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); + DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); - return hvStatus; + return hvStatus; #else - u32 controlHi = Control >> 32; - u32 controlLo = Control & 0xFFFFFFFF; - u32 hvStatusHi = 1; - u32 hvStatusLo = 1; - u64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0; - u32 inputAddressHi = inputAddress >> 32; - u32 inputAddressLo = inputAddress & 0xFFFFFFFF; - u64 outputAddress = (Output) ?GetPhysicalAddress(Output) : 0; - u32 outputAddressHi = outputAddress >> 32; - u32 outputAddressLo = outputAddress & 0xFFFFFFFF; - volatile void* hypercallPage = gHvContext.HypercallPage; - - DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", - Control, - Input, - Output); - - __asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), "=a"(hvStatusLo) : "d" (controlHi), "a" (controlLo), "b" (inputAddressHi), "c" (inputAddressLo), "D"(outputAddressHi), "S"(outputAddressLo), "m" (hypercallPage)); - - - DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatusLo | ((u64)hvStatusHi << 32)); - - return (hvStatusLo | ((u64)hvStatusHi << 32)); + u32 controlHi = Control >> 32; + u32 controlLo = Control & 0xFFFFFFFF; + u32 hvStatusHi = 1; + u32 hvStatusLo = 1; + u64 inputAddress = (Input) ? GetPhysicalAddress(Input) : 0; + u32 inputAddressHi = inputAddress >> 32; + u32 inputAddressLo = inputAddress & 0xFFFFFFFF; + u64 outputAddress = (Output) ? GetPhysicalAddress(Output) : 0; + u32 outputAddressHi = outputAddress >> 32; + u32 outputAddressLo = outputAddress & 0xFFFFFFFF; + volatile void *hypercallPage = gHvContext.HypercallPage; + + DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", + Control, Input, Output); + + __asm__ __volatile__("call *%8":"=d"(hvStatusHi), + "=a"(hvStatusLo):"d"(controlHi), "a"(controlLo), + "b"(inputAddressHi), "c"(inputAddressLo), + "D"(outputAddressHi), "S"(outputAddressLo), + "m"(hypercallPage)); + + DPRINT_DBG(VMBUS, "Hypercall <return %llx>", + hvStatusLo | ((u64) hvStatusHi << 32)); + + return (hvStatusLo | ((u64) hvStatusHi << 32)); #endif /* x86_64 */ } @@ -223,37 +204,34 @@ Description: before any other routines in here are called --*/ -static int -HvInit ( - void +static int HvInit(void ) { - int ret=0; - int maxLeaf; + int ret = 0; + int maxLeaf; HV_X64_MSR_HYPERCALL_CONTENTS hypercallMsr; - void* virtAddr=0; + void *virtAddr = 0; DPRINT_ENTER(VMBUS); memset(gHvContext.synICEventPage, 0, sizeof(void *) * MAX_NUM_CPUS); memset(gHvContext.synICMessagePage, 0, sizeof(void *) * MAX_NUM_CPUS); - if (!HvQueryHypervisorPresence()) - { + if (!HvQueryHypervisorPresence()) { DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); goto Cleanup; } - DPRINT_INFO(VMBUS, "Windows hypervisor detected! Retrieving more info..."); + DPRINT_INFO(VMBUS, + "Windows hypervisor detected! Retrieving more info..."); - maxLeaf = HvQueryHypervisorInfo(); - /* HvQueryHypervisorFeatures(maxLeaf); */ + maxLeaf = HvQueryHypervisorInfo(); + /* HvQueryHypervisorFeatures(maxLeaf); */ /* Determine if we are running on xenlinux (ie x2v shim) or native linux */ gHvContext.GuestId = ReadMsr(HV_X64_MSR_GUEST_OS_ID); - if (gHvContext.GuestId == 0) - { + if (gHvContext.GuestId == 0) { /* Write our OS info */ WriteMsr(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); @@ -263,69 +241,70 @@ HvInit ( /* See if the hypercall page is already set */ hypercallMsr.AsUINT64 = ReadMsr(HV_X64_MSR_HYPERCALL); - if (gHvContext.GuestId == HV_LINUX_GUEST_ID) - { + if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { /* Allocate the hypercall page memory */ /* virtAddr = PageAlloc(1); */ virtAddr = VirtualAllocExec(PAGE_SIZE); - if (!virtAddr) - { - DPRINT_ERR(VMBUS, "unable to allocate hypercall page!!"); + if (!virtAddr) { + DPRINT_ERR(VMBUS, + "unable to allocate hypercall page!!"); goto Cleanup; } hypercallMsr.Enable = 1; /* hypercallMsr.GuestPhysicalAddress = Logical2PhysicalAddr(virtAddr) >> PAGE_SHIFT; */ - hypercallMsr.GuestPhysicalAddress = Virtual2Physical(virtAddr) >> PAGE_SHIFT; + hypercallMsr.GuestPhysicalAddress = + Virtual2Physical(virtAddr) >> PAGE_SHIFT; WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); - /* Confirm that hypercall page did get setup. */ + /* Confirm that hypercall page did get setup. */ hypercallMsr.AsUINT64 = 0; hypercallMsr.AsUINT64 = ReadMsr(HV_X64_MSR_HYPERCALL); - if (!hypercallMsr.Enable) - { + if (!hypercallMsr.Enable) { DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); goto Cleanup; } gHvContext.HypercallPage = virtAddr; - } - else - { - DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", gHvContext.GuestId); + } else { + DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", + gHvContext.GuestId); goto Cleanup; } DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", gHvContext.HypercallPage, - (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); + (u64) hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); /* Setup the global signal event param for the signal event hypercall */ - gHvContext.SignalEventBuffer = kmalloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER), GFP_KERNEL); - if (!gHvContext.SignalEventBuffer) - { + gHvContext.SignalEventBuffer = + kmalloc(sizeof(HV_INPUT_SIGNAL_EVENT_BUFFER), GFP_KERNEL); + if (!gHvContext.SignalEventBuffer) { goto Cleanup; } - gHvContext.SignalEventParam = (PHV_INPUT_SIGNAL_EVENT)(ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, HV_HYPERCALL_PARAM_ALIGN)); + gHvContext.SignalEventParam = + (PHV_INPUT_SIGNAL_EVENT) (ALIGN_UP + ((unsigned long)gHvContext. + SignalEventBuffer, + HV_HYPERCALL_PARAM_ALIGN)); gHvContext.SignalEventParam->ConnectionId.Asu32 = 0; - gHvContext.SignalEventParam->ConnectionId.u.Id = VMBUS_EVENT_CONNECTION_ID; + gHvContext.SignalEventParam->ConnectionId.u.Id = + VMBUS_EVENT_CONNECTION_ID; gHvContext.SignalEventParam->FlagNumber = 0; gHvContext.SignalEventParam->RsvdZ = 0; - /* DPRINT_DBG(VMBUS, "My id %llu", HvGetCurrentPartitionId()); */ + /* DPRINT_DBG(VMBUS, "My id %llu", HvGetCurrentPartitionId()); */ DPRINT_EXIT(VMBUS); - return ret; + return ret; Cleanup: - if (virtAddr) - { - if (hypercallMsr.Enable) - { + if (virtAddr) { + if (hypercallMsr.Enable) { hypercallMsr.AsUINT64 = 0; WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); } @@ -338,7 +317,6 @@ Cleanup: return ret; } - /*++ Name: @@ -348,26 +326,21 @@ Description: Cleanup routine. This routine is called normally during driver unloading or exiting. --*/ -void -HvCleanup ( - void +void HvCleanup(void ) { HV_X64_MSR_HYPERCALL_CONTENTS hypercallMsr; DPRINT_ENTER(VMBUS); - if (gHvContext.SignalEventBuffer) - { + if (gHvContext.SignalEventBuffer) { kfree(gHvContext.SignalEventBuffer); gHvContext.SignalEventBuffer = NULL; gHvContext.SignalEventParam = NULL; } - if (gHvContext.GuestId == HV_LINUX_GUEST_ID) - { - if (gHvContext.HypercallPage) - { + if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { + if (gHvContext.HypercallPage) { hypercallMsr.AsUINT64 = 0; WriteMsr(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); VirtualFree(gHvContext.HypercallPage); @@ -379,7 +352,6 @@ HvCleanup ( } - /*++ Name: @@ -391,49 +363,43 @@ Description: --*/ HV_STATUS -HvPostMessage( - HV_CONNECTION_ID connectionId, - HV_MESSAGE_TYPE messageType, - void * payload, - size_t payloadSize - ) +HvPostMessage(HV_CONNECTION_ID connectionId, + HV_MESSAGE_TYPE messageType, void *payload, size_t payloadSize) { struct alignedInput { - u64 alignment8; - HV_INPUT_POST_MESSAGE msg; + u64 alignment8; + HV_INPUT_POST_MESSAGE msg; }; PHV_INPUT_POST_MESSAGE alignedMsg; HV_STATUS status; unsigned long addr; - if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) - { + if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) { return -1; } addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC); - if (!addr) - { + if (!addr) { return -1; } - alignedMsg = (PHV_INPUT_POST_MESSAGE)(ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); + alignedMsg = + (PHV_INPUT_POST_MESSAGE) (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); alignedMsg->ConnectionId = connectionId; alignedMsg->MessageType = messageType; alignedMsg->PayloadSize = payloadSize; - memcpy((void*)alignedMsg->Payload, payload, payloadSize); + memcpy((void *)alignedMsg->Payload, payload, payloadSize); status = HvDoHypercall(HvCallPostMessage, alignedMsg, 0) & 0xFFFF; - kfree((void*)addr); + kfree((void *)addr); return status; } - /*++ Name: @@ -444,18 +410,17 @@ Description: involves a hypercall. --*/ -HV_STATUS -HvSignalEvent( - ) +HV_STATUS HvSignalEvent() { HV_STATUS status; - status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, 0) & 0xFFFF; + status = + HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, + 0) & 0xFFFF; return status; } - /*++ Name: @@ -467,23 +432,19 @@ Description: Otherwise, we create and initialize the message and event pages. --*/ -int -HvSynicInit ( - u32 irqVector - ) +int HvSynicInit(u32 irqVector) { - u64 version; - HV_SYNIC_SIMP simp; - HV_SYNIC_SIEFP siefp; - HV_SYNIC_SINT sharedSint; + u64 version; + HV_SYNIC_SIMP simp; + HV_SYNIC_SIEFP siefp; + HV_SYNIC_SINT sharedSint; HV_SYNIC_SCONTROL sctrl; - u64 guestID; - int ret=0; + u64 guestID; + int ret = 0; DPRINT_ENTER(VMBUS); - if (!gHvContext.HypercallPage) - { + if (!gHvContext.HypercallPage) { DPRINT_EXIT(VMBUS); return ret; } @@ -494,77 +455,84 @@ HvSynicInit ( DPRINT_INFO(VMBUS, "SynIC version: %llx", version); /* TODO: Handle SMP */ - if (gHvContext.GuestId == HV_XENLINUX_GUEST_ID) - { - DPRINT_INFO(VMBUS, "Skipping SIMP and SIEFP setup since it is already set."); + if (gHvContext.GuestId == HV_XENLINUX_GUEST_ID) { + DPRINT_INFO(VMBUS, + "Skipping SIMP and SIEFP setup since it is already set."); simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP); siefp.AsUINT64 = ReadMsr(HV_X64_MSR_SIEFP); - DPRINT_DBG(VMBUS, "Simp: %llx, Sifep: %llx", simp.AsUINT64, siefp.AsUINT64); + DPRINT_DBG(VMBUS, "Simp: %llx, Sifep: %llx", simp.AsUINT64, + siefp.AsUINT64); /* Determine if we are running on xenlinux (ie x2v shim) or native linux */ guestID = ReadMsr(HV_X64_MSR_GUEST_OS_ID); - if (guestID == HV_LINUX_GUEST_ID) - { - gHvContext.synICMessagePage[0] = GetVirtualAddress(simp.BaseSimpGpa << PAGE_SHIFT); - gHvContext.synICEventPage[0] = GetVirtualAddress(siefp.BaseSiefpGpa << PAGE_SHIFT); - } - else - { + if (guestID == HV_LINUX_GUEST_ID) { + gHvContext.synICMessagePage[0] = + GetVirtualAddress(simp.BaseSimpGpa << PAGE_SHIFT); + gHvContext.synICEventPage[0] = + GetVirtualAddress(siefp.BaseSiefpGpa << PAGE_SHIFT); + } else { DPRINT_ERR(VMBUS, "unknown guest id!!"); goto Cleanup; } - DPRINT_DBG(VMBUS, "MAPPED: Simp: %p, Sifep: %p", gHvContext.synICMessagePage[0], gHvContext.synICEventPage[0]); - } - else - { + DPRINT_DBG(VMBUS, "MAPPED: Simp: %p, Sifep: %p", + gHvContext.synICMessagePage[0], + gHvContext.synICEventPage[0]); + } else { gHvContext.synICMessagePage[0] = PageAlloc(1); - if (gHvContext.synICMessagePage[0] == NULL) - { - DPRINT_ERR(VMBUS, "unable to allocate SYNIC message page!!"); + if (gHvContext.synICMessagePage[0] == NULL) { + DPRINT_ERR(VMBUS, + "unable to allocate SYNIC message page!!"); goto Cleanup; } gHvContext.synICEventPage[0] = PageAlloc(1); - if (gHvContext.synICEventPage[0] == NULL) - { - DPRINT_ERR(VMBUS, "unable to allocate SYNIC event page!!"); + if (gHvContext.synICEventPage[0] == NULL) { + DPRINT_ERR(VMBUS, + "unable to allocate SYNIC event page!!"); goto Cleanup; } /* Setup the Synic's message page */ simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP); simp.SimpEnabled = 1; - simp.BaseSimpGpa = GetPhysicalAddress(gHvContext.synICMessagePage[0]) >> PAGE_SHIFT; + simp.BaseSimpGpa = + GetPhysicalAddress(gHvContext. + synICMessagePage[0]) >> PAGE_SHIFT; - DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.AsUINT64); + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", + simp.AsUINT64); WriteMsr(HV_X64_MSR_SIMP, simp.AsUINT64); /* Setup the Synic's event page */ siefp.AsUINT64 = ReadMsr(HV_X64_MSR_SIEFP); siefp.SiefpEnabled = 1; - siefp.BaseSiefpGpa = GetPhysicalAddress(gHvContext.synICEventPage[0]) >> PAGE_SHIFT; + siefp.BaseSiefpGpa = + GetPhysicalAddress(gHvContext. + synICEventPage[0]) >> PAGE_SHIFT; - DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.AsUINT64); + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", + siefp.AsUINT64); WriteMsr(HV_X64_MSR_SIEFP, siefp.AsUINT64); } - /* Setup the interception SINT. */ + /* Setup the interception SINT. */ /* WriteMsr((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ - /* interceptionSint.AsUINT64); */ + /* interceptionSint.AsUINT64); */ - /* Setup the shared SINT. */ + /* Setup the shared SINT. */ sharedSint.AsUINT64 = ReadMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT); sharedSint.AsUINT64 = 0; - sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ + sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ sharedSint.Masked = false; sharedSint.AutoEoi = true; - DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", sharedSint.AsUINT64); + DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", + sharedSint.AsUINT64); WriteMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); @@ -583,15 +551,12 @@ HvSynicInit ( Cleanup: ret = -1; - if (gHvContext.GuestId == HV_LINUX_GUEST_ID) - { - if (gHvContext.synICEventPage[0]) - { - PageFree(gHvContext.synICEventPage[0],1); + if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { + if (gHvContext.synICEventPage[0]) { + PageFree(gHvContext.synICEventPage[0], 1); } - if (gHvContext.synICMessagePage[0]) - { + if (gHvContext.synICMessagePage[0]) { PageFree(gHvContext.synICMessagePage[0], 1); } } @@ -611,19 +576,16 @@ Description: Cleanup routine for HvSynicInit(). --*/ -void -HvSynicCleanup( - void - ) +void HvSynicCleanup(void + ) { - HV_SYNIC_SINT sharedSint; - HV_SYNIC_SIMP simp; - HV_SYNIC_SIEFP siefp; + HV_SYNIC_SINT sharedSint; + HV_SYNIC_SIMP simp; + HV_SYNIC_SIEFP siefp; DPRINT_ENTER(VMBUS); - if (!gHvContext.SynICInitialized) - { + if (!gHvContext.SynICInitialized) { DPRINT_EXIT(VMBUS); return; } @@ -633,15 +595,14 @@ HvSynicCleanup( sharedSint.Masked = 1; /* Disable the interrupt */ - WriteMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); + WriteMsr(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); /* * Disable and free the resources only if we are running as * native linux since in xenlinux, we are sharing the * resources with the x2v shim */ - if (gHvContext.GuestId == HV_LINUX_GUEST_ID) - { + if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { simp.AsUINT64 = ReadMsr(HV_X64_MSR_SIMP); simp.SimpEnabled = 0; simp.BaseSimpGpa = 0; @@ -661,5 +622,4 @@ HvSynicCleanup( DPRINT_EXIT(VMBUS); } - /* eof */ diff --git a/drivers/staging/hv/Hv.h b/drivers/staging/hv/Hv.h index b5ea3dc..2346336 100644 --- a/drivers/staging/hv/Hv.h +++ b/drivers/staging/hv/Hv.h @@ -21,7 +21,6 @@ * */ - #ifndef __HV_H__ #define __HV_H__ @@ -43,15 +42,14 @@ #include "include/HvHcApi.h" #include "include/HvPtApi.h" -enum -{ - VMBUS_MESSAGE_CONNECTION_ID = 1, - VMBUS_MESSAGE_PORT_ID = 1, - VMBUS_EVENT_CONNECTION_ID = 2, - VMBUS_EVENT_PORT_ID = 2, - VMBUS_MONITOR_CONNECTION_ID = 3, - VMBUS_MONITOR_PORT_ID = 3, - VMBUS_MESSAGE_SINT = 2 +enum { + VMBUS_MESSAGE_CONNECTION_ID = 1, + VMBUS_MESSAGE_PORT_ID = 1, + VMBUS_EVENT_CONNECTION_ID = 2, + VMBUS_EVENT_PORT_ID = 2, + VMBUS_MONITOR_CONNECTION_ID = 3, + VMBUS_MONITOR_PORT_ID = 3, + VMBUS_MESSAGE_SINT = 2 }; /* #defines */ @@ -72,10 +70,8 @@ enum #define HV_X64_MAX 5 #define HV_CAPS_MAX 8 - #define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) - /* Service definitions */ #define HV_SERVICE_PARENT_PORT (0) @@ -99,25 +95,26 @@ enum /* #define VMBUS_PORT_ID 11 // Our local vmbus's port and connection id. Anything >0 is fine */ /* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */ -static const GUID VMBUS_SERVICE_ID = {.Data = {0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4} }; +static const GUID VMBUS_SERVICE_ID = {.Data = + {0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, 0xb7, 0xdb, 0x1b, + 0xeb, 0x62, 0xe6, 0x2e, 0xf4} }; #define MAX_NUM_CPUS 1 - typedef struct { - u64 Align8; - HV_INPUT_SIGNAL_EVENT Event; + u64 Align8; + HV_INPUT_SIGNAL_EVENT Event; } HV_INPUT_SIGNAL_EVENT_BUFFER; typedef struct { - u64 GuestId; /* XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized */ - void* HypercallPage; + u64 GuestId; /* XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized */ + void *HypercallPage; - bool SynICInitialized; + bool SynICInitialized; /* This is used as an input param to HvCallSignalEvent hypercall. The input param is immutable */ /* in our usage and must be dynamic mem (vs stack or global). */ HV_INPUT_SIGNAL_EVENT_BUFFER *SignalEventBuffer; - HV_INPUT_SIGNAL_EVENT *SignalEventParam; /* 8-bytes aligned of the buffer above */ + HV_INPUT_SIGNAL_EVENT *SignalEventParam; /* 8-bytes aligned of the buffer above */ void *synICMessagePage[MAX_NUM_CPUS]; void *synICEventPage[MAX_NUM_CPUS]; @@ -125,8 +122,6 @@ typedef struct { extern HV_CONTEXT gHvContext; - - /* Inline routines */ static inline unsigned long long ReadMsr(int msr) @@ -145,40 +140,24 @@ static inline void WriteMsr(int msr, u64 val) return; } - /* Hv Interface */ -static int -HvInit( - void +static int HvInit(void ); -static void -HvCleanup( - void +static void HvCleanup(void ); static HV_STATUS -HvPostMessage( - HV_CONNECTION_ID connectionId, - HV_MESSAGE_TYPE messageType, - void * payload, - size_t payloadSize - ); +HvPostMessage(HV_CONNECTION_ID connectionId, + HV_MESSAGE_TYPE messageType, void *payload, size_t payloadSize); -static HV_STATUS -HvSignalEvent( - void - ); - -static int -HvSynicInit( - u32 irqVector - ); - -static void -HvSynicCleanup( - void - ); +static HV_STATUS HvSignalEvent(void + ); + +static int HvSynicInit(u32 irqVector); + +static void HvSynicCleanup(void + ); #endif /* __HV_H__ */ diff --git a/drivers/staging/hv/NetVsc.c b/drivers/staging/hv/NetVsc.c index e2a75ce..aa65587 100644 --- a/drivers/staging/hv/NetVsc.c +++ b/drivers/staging/hv/NetVsc.c @@ -27,91 +27,47 @@ #include "NetVsc.h" #include "RndisFilter.h" - /* Globals */ -static const char* gDriverName="netvsc"; +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 GUID gNetVscDeviceType = { + .Data = + {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, 0x91, 0x3F, 0xF2, + 0xD2, 0xF9, 0x65, 0xED, 0x0E} }; - /* Internal routines */ -static int -NetVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); +static int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); -static int -NetVscOnDeviceRemove( - struct hv_device *Device - ); +static int NetVscOnDeviceRemove(struct hv_device *Device); -static void -NetVscOnCleanup( - DRIVER_OBJECT *Driver - ); +static void NetVscOnCleanup(DRIVER_OBJECT * 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 NetVscOnChannelCallback(void *context); -static void -NetVscOnSendCompletion( - struct hv_device *Device, - VMPACKET_DESCRIPTOR *Packet - ); +static int NetVscInitializeSendBufferWithNetVsp(struct hv_device *Device); + +static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device); -static int -NetVscOnSend( - struct hv_device *Device, - NETVSC_PACKET *Packet - ); +static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice); + +static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice); + +static int NetVscConnectToVsp(struct hv_device *Device); static void -NetVscOnReceive( - struct hv_device *Device, - VMPACKET_DESCRIPTOR *Packet - ); +NetVscOnSendCompletion(struct hv_device *Device, VMPACKET_DESCRIPTOR * Packet); + +static int NetVscOnSend(struct hv_device *Device, NETVSC_PACKET * Packet); static void -NetVscOnReceiveCompletion( - void * Context - ); +NetVscOnReceive(struct hv_device *Device, VMPACKET_DESCRIPTOR * Packet); + +static void NetVscOnReceiveCompletion(void *Context); static void -NetVscSendReceiveCompletion( - struct hv_device *Device, - u64 TransactionId - ); +NetVscSendReceiveCompletion(struct hv_device *Device, u64 TransactionId); static inline struct NETVSC_DEVICE *AllocNetDevice(struct hv_device *Device) { @@ -137,19 +93,16 @@ static inline void FreeNetDevice(struct NETVSC_DEVICE *Device) kfree(Device); } - /* Get the net device object iff exists and its refcount > 1 */ -static inline struct NETVSC_DEVICE *GetOutboundNetDevice(struct hv_device *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) - { + netDevice = (struct NETVSC_DEVICE *)Device->Extension; + if (netDevice && netDevice->RefCount > 1) { InterlockedIncrement(&netDevice->RefCount); - } - else - { + } else { netDevice = NULL; } @@ -157,17 +110,15 @@ 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 inline struct NETVSC_DEVICE *GetInboundNetDevice(struct hv_device + *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; - if (netDevice && netDevice->RefCount) - { + netDevice = (struct NETVSC_DEVICE *)Device->Extension; + if (netDevice && netDevice->RefCount) { InterlockedIncrement(&netDevice->RefCount); - } - else - { + } else { netDevice = NULL; } @@ -178,40 +129,40 @@ static inline void PutNetDevice(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = (struct NETVSC_DEVICE *)Device->Extension; ASSERT(netDevice); InterlockedDecrement(&netDevice->RefCount); } -static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device *Device) +static inline struct NETVSC_DEVICE *ReleaseOutboundNetDevice(struct hv_device + *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct 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) - { + while (InterlockedCompareExchange(&netDevice->RefCount, 1, 2) != 2) { udelay(100); } return netDevice; } -static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *Device) +static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device + *Device) { struct NETVSC_DEVICE *netDevice; - netDevice = (struct 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) - { + while (InterlockedCompareExchange(&netDevice->RefCount, 0, 1) != 1) { udelay(100); } @@ -221,7 +172,6 @@ static inline struct NETVSC_DEVICE *ReleaseInboundNetDevice(struct hv_device *De /*++; - Name: NetVscInitialize() @@ -229,18 +179,17 @@ Description: Main entry point --*/ -int -NetVscInitialize( - DRIVER_OBJECT *drv - ) +int NetVscInitialize(DRIVER_OBJECT * drv) { - NETVSC_DRIVER_OBJECT* driver = (NETVSC_DRIVER_OBJECT*)drv; - int ret=0; + NETVSC_DRIVER_OBJECT *driver = (NETVSC_DRIVER_OBJECT *) drv; + int ret = 0; DPRINT_ENTER(NETVSC); - DPRINT_DBG(NETVSC, "sizeof(NETVSC_PACKET)=%zd, sizeof(NVSP_MESSAGE)=%zd, sizeof(VMTRANSFER_PAGE_PACKET_HEADER)=%zd", - sizeof(NETVSC_PACKET), sizeof(NVSP_MESSAGE), sizeof(VMTRANSFER_PAGE_PACKET_HEADER)); + DPRINT_DBG(NETVSC, + "sizeof(NETVSC_PACKET)=%zd, sizeof(NVSP_MESSAGE)=%zd, sizeof(VMTRANSFER_PAGE_PACKET_HEADER)=%zd", + sizeof(NETVSC_PACKET), sizeof(NVSP_MESSAGE), + sizeof(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)); @@ -253,11 +202,11 @@ 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); @@ -266,35 +215,34 @@ NetVscInitialize( return ret; } -static int -NetVscInitializeReceiveBufferWithNetVsp( - struct hv_device *Device - ) +static int NetVscInitializeReceiveBufferWithNetVsp(struct hv_device *Device) { - int ret=0; + int ret = 0; struct NETVSC_DEVICE *netDevice; 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 */ + ASSERT((netDevice->ReceiveBufferSize & (PAGE_SIZE - 1)) == 0); /* page-size grandularity */ - netDevice->ReceiveBuffer = PageAlloc(netDevice->ReceiveBufferSize >> PAGE_SHIFT); - if (!netDevice->ReceiveBuffer) - { - DPRINT_ERR(NETVSC, "unable to allocate receive buffer of size %d", netDevice->ReceiveBufferSize); + netDevice->ReceiveBuffer = + 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..."); @@ -304,13 +252,16 @@ 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; } @@ -323,31 +274,36 @@ NetVscInitializeReceiveBufferWithNetVsp( memset(initPacket, 0, sizeof(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(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 + (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; } WaitEventWait(netDevice->ChannelInitEvent); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Status != NvspStatusSuccess) - { + 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); + "Unable to complete receive buffer initialzation with NetVsp - status %d", + initPacket->Messages.Version1Messages. + SendReceiveBufferComplete.Status); ret = -1; goto Cleanup; } @@ -356,29 +312,35 @@ NetVscInitializeReceiveBufferWithNetVsp( ASSERT(netDevice->ReceiveSectionCount == 0); ASSERT(netDevice->ReceiveSections == NULL); - netDevice->ReceiveSectionCount = initPacket->Messages.Version1Messages.SendReceiveBufferComplete.NumSections; + netDevice->ReceiveSectionCount = + initPacket->Messages.Version1Messages.SendReceiveBufferComplete. + NumSections; - netDevice->ReceiveSections = kmalloc(netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION), GFP_KERNEL); - if (netDevice->ReceiveSections == NULL) - { + netDevice->ReceiveSections = + kmalloc(netDevice->ReceiveSectionCount * + sizeof(NVSP_1_RECEIVE_BUFFER_SECTION), GFP_KERNEL); + if (netDevice->ReceiveSections == NULL) { ret = -1; goto Cleanup; } memcpy(netDevice->ReceiveSections, - initPacket->Messages.Version1Messages.SendReceiveBufferComplete.Sections, - netDevice->ReceiveSectionCount * sizeof(NVSP_1_RECEIVE_BUFFER_SECTION)); + initPacket->Messages.Version1Messages.SendReceiveBufferComplete. + Sections, + netDevice->ReceiveSectionCount * + sizeof(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); - + "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 */ if (netDevice->ReceiveSectionCount != 1 || - netDevice->ReceiveSections->Offset != 0 ) - { + netDevice->ReceiveSections->Offset != 0) { ret = -1; goto Cleanup; } @@ -394,36 +356,33 @@ 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; 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 */ + ASSERT((netDevice->SendBufferSize & (PAGE_SIZE - 1)) == 0); /* page-size grandularity */ - netDevice->SendBuffer = PageAlloc(netDevice->SendBufferSize >> PAGE_SHIFT); - if (!netDevice->SendBuffer) - { - DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", netDevice->SendBufferSize); + netDevice->SendBuffer = + 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..."); @@ -433,12 +392,14 @@ 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; } @@ -452,36 +413,43 @@ NetVscInitializeSendBufferWithNetVsp( memset(initPacket, 0, sizeof(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(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 + (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; } WaitEventWait(netDevice->ChannelInitEvent); /* Check the response */ - if (initPacket->Messages.Version1Messages.SendSendBufferComplete.Status != NvspStatusSuccess) - { + 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); + "Unable to complete send buffer initialzation with NetVsp - status %d", + initPacket->Messages.Version1Messages. + SendSendBufferComplete.Status); ret = -1; goto Cleanup; } - netDevice->SendSectionSize = initPacket->Messages.Version1Messages.SendSendBufferComplete.SectionSize; + netDevice->SendSectionSize = + initPacket->Messages.Version1Messages.SendSendBufferComplete. + SectionSize; goto Exit; @@ -494,14 +462,10 @@ Exit: return ret; } -static int -NetVscDestroyReceiveBuffer( - struct NETVSC_DEVICE *NetDevice - ) +static int NetVscDestroyReceiveBuffer(struct NETVSC_DEVICE *NetDevice) { NVSP_MESSAGE *revokePacket; - int ret=0; - + int ret = 0; DPRINT_ENTER(NETVSC); @@ -511,64 +475,66 @@ 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; memset(revokePacket, 0, sizeof(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), - (unsigned long)revokePacket, - VmbusPacketTypeDataInBand, - 0); + 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), + (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 */ - PageFree(NetDevice->ReceiveBuffer, NetDevice->ReceiveBufferSize >> PAGE_SHIFT); + PageFree(NetDevice->ReceiveBuffer, + NetDevice->ReceiveBufferSize >> PAGE_SHIFT); NetDevice->ReceiveBuffer = NULL; } - if (NetDevice->ReceiveSections) - { + if (NetDevice->ReceiveSections) { kfree(NetDevice->ReceiveSections); NetDevice->ReceiveSections = NULL; NetDevice->ReceiveSectionCount = 0; @@ -579,17 +545,10 @@ NetVscDestroyReceiveBuffer( return ret; } - - - -static int -NetVscDestroySendBuffer( - struct NETVSC_DEVICE *NetDevice - ) +static int NetVscDestroySendBuffer(struct NETVSC_DEVICE *NetDevice) { NVSP_MESSAGE *revokePacket; - int ret=0; - + int ret = 0; DPRINT_ENTER(NETVSC); @@ -599,56 +558,59 @@ 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; memset(revokePacket, 0, sizeof(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), - (unsigned long)revokePacket, - VmbusPacketTypeDataInBand, - 0); + 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), + (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"); + 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 (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 */ - PageFree(NetDevice->SendBuffer, NetDevice->SendBufferSize >> PAGE_SHIFT); + PageFree(NetDevice->SendBuffer, + NetDevice->SendBufferSize >> PAGE_SHIFT); NetDevice->SendBuffer = NULL; } @@ -657,14 +619,9 @@ NetVscDestroySendBuffer( return ret; } - - -static int -NetVscConnectToVsp( - struct hv_device *Device - ) +static int NetVscConnectToVsp(struct hv_device *Device) { - int ret=0; + int ret = 0; struct NETVSC_DEVICE *netDevice; NVSP_MESSAGE *initPacket; int ndisVersion; @@ -672,9 +629,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; } @@ -683,21 +640,24 @@ NetVscConnectToVsp( memset(initPacket, 0, sizeof(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(NVSP_MESSAGE), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - - if( ret != 0) - { + initPacket, + sizeof + (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,20 +667,26 @@ NetVscConnectToVsp( /* 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); + 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; } @@ -729,22 +695,26 @@ NetVscConnectToVsp( /* Send the ndis version */ memset(initPacket, 0, sizeof(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(NVSP_MESSAGE), - (unsigned long)initPacket, - VmbusPacketTypeDataInBand, - 0); - if (ret != 0) - { - DPRINT_ERR(NETVSC, "unable to send NvspMessage1TypeSendNdisVersion"); + initPacket, + sizeof + (NVSP_MESSAGE), + (unsigned long) + initPacket, + VmbusPacketTypeDataInBand, + 0); + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to send NvspMessage1TypeSendNdisVersion"); ret = -1; goto Cleanup; } @@ -754,12 +724,11 @@ NetVscConnectToVsp( * packet) since our Vmbus always set the * VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED flag */ - /* WaitEventWait(NetVscChannel->ChannelInitEvent); */ + /* WaitEventWait(NetVscChannel->ChannelInitEvent); */ /* Post the big receive buffer to NetVSP */ ret = NetVscInitializeReceiveBufferWithNetVsp(Device); - if (ret == 0) - { + if (ret == 0) { ret = NetVscInitializeSendBufferWithNetVsp(Device); } @@ -769,10 +738,7 @@ Cleanup: return ret; } -static void -NetVscDisconnectFromVsp( - struct NETVSC_DEVICE *NetDevice - ) +static void NetVscDisconnectFromVsp(struct NETVSC_DEVICE *NetDevice) { DPRINT_ENTER(NETVSC); @@ -782,7 +748,6 @@ NetVscDisconnectFromVsp( DPRINT_EXIT(NETVSC); } - /*++ Name: @@ -792,26 +757,22 @@ Description: Callback when the device belonging to this driver is added --*/ -int -NetVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ) +int NetVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { - int ret=0; + int ret = 0; int i; struct NETVSC_DEVICE *netDevice; - NETVSC_PACKET* packet; + NETVSC_PACKET *packet; LIST_ENTRY *entry; - NETVSC_DRIVER_OBJECT *netDriver = (NETVSC_DRIVER_OBJECT*) Device->Driver;; + NETVSC_DRIVER_OBJECT *netDriver = + (NETVSC_DRIVER_OBJECT *) Device->Driver;; DPRINT_ENTER(NETVSC); netDevice = AllocNetDevice(Device); - if (!netDevice) - { + if (!netDevice) { ret = -1; goto Cleanup; } @@ -826,30 +787,34 @@ NetVscOnDeviceAdd( INITIALIZE_LIST_HEAD(&netDevice->ReceivePacketList); - for (i=0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) - { - packet = kzalloc(sizeof(NETVSC_PACKET) + (NETVSC_RECEIVE_SG_COUNT* sizeof(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(NETVSC_PACKET) + + (NETVSC_RECEIVE_SG_COUNT * sizeof(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 = WaitEventCreate(); /* Open the channel */ ret = Device->Driver->VmbusChannelInterface.Open(Device, - netDriver->RingBufferSize, - netDriver->RingBufferSize, - NULL, 0, + netDriver-> + RingBufferSize, + netDriver-> + RingBufferSize, NULL, + 0, NetVscOnChannelCallback, - Device - ); + Device); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); ret = -1; goto Cleanup; @@ -860,14 +825,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; @@ -878,14 +843,13 @@ Close: Cleanup: - if (netDevice) - { + if (netDevice) { WaitEventClose(netDevice->ChannelInitEvent); - while (!IsListEmpty(&netDevice->ReceivePacketList)) - { + while (!IsListEmpty(&netDevice->ReceivePacketList)) { entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList); - packet = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); + packet = + CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); kfree(packet); } @@ -899,7 +863,6 @@ Cleanup: return ret; } - /*++ Name: @@ -909,32 +872,29 @@ Description: Callback when the root bus device is removed --*/ -int -NetVscOnDeviceRemove( - struct hv_device *Device - ) +int NetVscOnDeviceRemove(struct hv_device *Device) { struct NETVSC_DEVICE *netDevice; NETVSC_PACKET *netvscPacket; - int ret=0; + 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 (netDevice->NumOutstandingSends) - { - DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", netDevice->NumOutstandingSends); + while (netDevice->NumOutstandingSends) { + DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", + netDevice->NumOutstandingSends); udelay(100); } @@ -943,7 +903,8 @@ NetVscOnDeviceRemove( NetVscDisconnectFromVsp(netDevice); - DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", Device->Extension); + DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", + Device->Extension); /* Stop inbound traffic ie receives and sends completions */ netDevice = ReleaseInboundNetDevice(Device); @@ -955,10 +916,10 @@ NetVscOnDeviceRemove( Device->Driver->VmbusChannelInterface.Close(Device); /* Release all resources */ - while (!IsListEmpty(&netDevice->ReceivePacketList)) - { + while (!IsListEmpty(&netDevice->ReceivePacketList)) { entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList); - netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); + netvscPacket = + CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); kfree(netvscPacket); } @@ -970,8 +931,6 @@ NetVscOnDeviceRemove( return ret; } - - /*++ Name: @@ -981,10 +940,7 @@ Description: Perform any cleanup when the driver is removed --*/ -void -NetVscOnCleanup( - DRIVER_OBJECT *drv - ) +void NetVscOnCleanup(DRIVER_OBJECT * drv) { DPRINT_ENTER(NETVSC); @@ -992,10 +948,7 @@ NetVscOnCleanup( } static void -NetVscOnSendCompletion( - struct hv_device *Device, - VMPACKET_DESCRIPTOR *Packet - ) +NetVscOnSendCompletion(struct hv_device *Device, VMPACKET_DESCRIPTOR * Packet) { struct NETVSC_DEVICE *netDevice; NVSP_MESSAGE *nvspPacket; @@ -1004,101 +957,105 @@ NetVscOnSendCompletion( DPRINT_ENTER(NETVSC); netDevice = GetInboundNetDevice(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; } - nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3)); + nvspPacket = + (NVSP_MESSAGE *) ((unsigned long)Packet + + (Packet->DataOffset8 << 3)); - DPRINT_DBG(NETVSC, "send completion packet - type %d", nvspPacket->Header.MessageType); + DPRINT_DBG(NETVSC, "send completion packet - type %d", + nvspPacket->Header.MessageType); if (nvspPacket->Header.MessageType == NvspMessageTypeInitComplete || - nvspPacket->Header.MessageType == NvspMessage1TypeSendReceiveBufferComplete || - nvspPacket->Header.MessageType == NvspMessage1TypeSendSendBufferComplete) - { + nvspPacket->Header.MessageType == + NvspMessage1TypeSendReceiveBufferComplete + || nvspPacket->Header.MessageType == + NvspMessage1TypeSendSendBufferComplete) { /* Copy the response back */ - memcpy(&netDevice->ChannelInitPacket, nvspPacket, sizeof(NVSP_MESSAGE)); + memcpy(&netDevice->ChannelInitPacket, nvspPacket, + sizeof(NVSP_MESSAGE)); WaitEventSet(netDevice->ChannelInitEvent); - } - else if (nvspPacket->Header.MessageType == NvspMessage1TypeSendRNDISPacketComplete) - { + } else if (nvspPacket->Header.MessageType == + NvspMessage1TypeSendRNDISPacketComplete) { /* Get the send context */ - nvscPacket = (NETVSC_PACKET *)(unsigned long)Packet->TransactionId; + nvscPacket = + (NETVSC_PACKET *) (unsigned long)Packet->TransactionId; ASSERT(nvscPacket); /* Notify the layer above us */ - nvscPacket->Completion.Send.OnSendCompletion(nvscPacket->Completion.Send.SendCompletionContext); + nvscPacket->Completion.Send.OnSendCompletion(nvscPacket-> + Completion.Send. + SendCompletionContext); InterlockedDecrement(&netDevice->NumOutstandingSends); - } - else - { - DPRINT_ERR(NETVSC, "Unknown send completion packet type - %d received!!", nvspPacket->Header.MessageType); + } else { + DPRINT_ERR(NETVSC, + "Unknown send completion packet type - %d received!!", + nvspPacket->Header.MessageType); } PutNetDevice(Device); DPRINT_EXIT(NETVSC); } - - -static int -NetVscOnSend( - struct hv_device *Device, - NETVSC_PACKET *Packet - ) +static int NetVscOnSend(struct hv_device *Device, NETVSC_PACKET * Packet) { struct NETVSC_DEVICE *netDevice; - int ret=0; + int ret = 0; NVSP_MESSAGE sendMessage; DPRINT_ENTER(NETVSC); netDevice = GetOutboundNetDevice(Device); - if (!netDevice) - { - DPRINT_ERR(NETVSC, "net device (%p) shutting down...ignoring outbound packets", netDevice); + if (!netDevice) { + DPRINT_ERR(NETVSC, + "net device (%p) shutting down...ignoring outbound packets", + netDevice); DPRINT_EXIT(NETVSC); return -2; } 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 */ - sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionIndex = 0xFFFFFFFF; - sendMessage.Messages.Version1Messages.SendRNDISPacket.SendBufferSectionSize = 0; - - if (Packet->PageBufferCount) - { - ret = Device->Driver->VmbusChannelInterface.SendPacketPageBuffer(Device, - Packet->PageBuffers, - Packet->PageBufferCount, - &sendMessage, - sizeof(NVSP_MESSAGE), - (unsigned long)Packet); - } - else - { + sendMessage.Messages.Version1Messages.SendRNDISPacket. + SendBufferSectionIndex = 0xFFFFFFFF; + sendMessage.Messages.Version1Messages.SendRNDISPacket. + SendBufferSectionSize = 0; + + if (Packet->PageBufferCount) { + ret = + Device->Driver->VmbusChannelInterface. + SendPacketPageBuffer(Device, Packet->PageBuffers, + Packet->PageBufferCount, &sendMessage, + sizeof(NVSP_MESSAGE), + (unsigned long)Packet); + } else { ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - &sendMessage, - sizeof(NVSP_MESSAGE), - (unsigned long)Packet, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + &sendMessage, + sizeof + (NVSP_MESSAGE), + (unsigned + long) + Packet, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } - if (ret != 0) - { - DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, ret); + if (ret != 0) { + DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", Packet, + ret); } InterlockedIncrement(&netDevice->NumOutstandingSends); @@ -1108,68 +1065,70 @@ NetVscOnSend( return ret; } - static void -NetVscOnReceive( - struct hv_device *Device, - VMPACKET_DESCRIPTOR *Packet - ) +NetVscOnReceive(struct hv_device *Device, VMPACKET_DESCRIPTOR * Packet) { struct NETVSC_DEVICE *netDevice; VMTRANSFER_PAGE_PACKET_HEADER *vmxferpagePacket; NVSP_MESSAGE *nvspPacket; - NETVSC_PACKET *netvscPacket=NULL; - LIST_ENTRY* entry; + NETVSC_PACKET *netvscPacket = NULL; + LIST_ENTRY *entry; unsigned long start; unsigned long end, endVirtual; /* NETVSC_DRIVER_OBJECT *netvscDriver; */ - XFERPAGE_PACKET *xferpagePacket=NULL; + XFERPAGE_PACKET *xferpagePacket = NULL; LIST_ENTRY listHead; - int i=0, j=0; - int count=0, bytesRemain=0; + int i = 0, j = 0; + int count = 0, bytesRemain = 0; unsigned long flags; DPRINT_ENTER(NETVSC); netDevice = GetInboundNetDevice(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; } /* 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); + if (Packet->Type != VmbusPacketTypeDataUsingTransferPages) { + DPRINT_ERR(NETVSC, "Unknown packet type received - %d", + Packet->Type); PutNetDevice(Device); return; } - nvspPacket = (NVSP_MESSAGE*)((unsigned long)Packet + (Packet->DataOffset8 << 3)); + nvspPacket = + (NVSP_MESSAGE *) ((unsigned long)Packet + + (Packet->DataOffset8 << 3)); /* 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); + if (nvspPacket->Header.MessageType != NvspMessage1TypeSendRNDISPacket) { + DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", + nvspPacket->Header.MessageType); PutNetDevice(Device); return; } - DPRINT_DBG(NETVSC, "NVSP packet received - type %d", nvspPacket->Header.MessageType); + DPRINT_DBG(NETVSC, "NVSP packet received - type %d", + nvspPacket->Header.MessageType); - vmxferpagePacket = (VMTRANSFER_PAGE_PACKET_HEADER*)Packet; + vmxferpagePacket = (VMTRANSFER_PAGE_PACKET_HEADER *) Packet; - if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) - { - DPRINT_ERR(NETVSC, "Invalid xfer page set id - expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, vmxferpagePacket->TransferPageSetId); + if (vmxferpagePacket->TransferPageSetId != NETVSC_RECEIVE_BUFFER_ID) { + DPRINT_ERR(NETVSC, + "Invalid xfer page set id - expecting %x got %x", + NETVSC_RECEIVE_BUFFER_ID, + vmxferpagePacket->TransferPageSetId); PutNetDevice(Device); return; } - DPRINT_DBG(NETVSC, "xfer page - range count %d", vmxferpagePacket->RangeCount); + DPRINT_DBG(NETVSC, "xfer page - range count %d", + vmxferpagePacket->RangeCount); INITIALIZE_LIST_HEAD(&listHead); @@ -1180,10 +1139,10 @@ NetVscOnReceive( * fulfil */ spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); - while (!IsListEmpty(&netDevice->ReceivePacketList)) - { + while (!IsListEmpty(&netDevice->ReceivePacketList)) { entry = REMOVE_HEAD_LIST(&netDevice->ReceivePacketList); - netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); + netvscPacket = + CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); INSERT_TAIL_LIST(&listHead, &netvscPacket->ListEntry); @@ -1197,22 +1156,26 @@ NetVscOnReceive( * 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); + 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 */ spin_lock_irqsave(&netDevice->receive_packet_list_lock, flags); - for (i=count; i != 0; i--) - { + for (i = count; i != 0; i--) { entry = REMOVE_HEAD_LIST(&listHead); - netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); + netvscPacket = + CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); - INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &netvscPacket->ListEntry); + INSERT_TAIL_LIST(&netDevice->ReceivePacketList, + &netvscPacket->ListEntry); } - spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); + spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, + flags); - NetVscSendReceiveCompletion(Device, vmxferpagePacket->d.TransactionId); + NetVscSendReceiveCompletion(Device, + vmxferpagePacket->d.TransactionId); PutNetDevice(Device); return; @@ -1221,78 +1184,101 @@ 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->Count = count - 1; /* This is how much we can satisfy */ - ASSERT(xferpagePacket->Count > 0 && xferpagePacket->Count <= vmxferpagePacket->RangeCount); - - if (xferpagePacket->Count != vmxferpagePacket->RangeCount) - { - DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer page...got %d", vmxferpagePacket->RangeCount, xferpagePacket->Count); + xferpagePacket->Count = count - 1; /* This is how much we can satisfy */ + ASSERT(xferpagePacket->Count > 0 + && xferpagePacket->Count <= vmxferpagePacket->RangeCount); + + if (xferpagePacket->Count != vmxferpagePacket->RangeCount) { + 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 */ - for (i=0; i < (count - 1); i++) - { + for (i = 0; i < (count - 1); i++) { entry = REMOVE_HEAD_LIST(&listHead); - netvscPacket = CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); + netvscPacket = + CONTAINING_RECORD(entry, NETVSC_PACKET, ListEntry); /* Initialize the netvsc packet */ netvscPacket->XferPagePacket = xferpagePacket; - netvscPacket->Completion.Recv.OnReceiveCompletion = NetVscOnReceiveCompletion; - netvscPacket->Completion.Recv.ReceiveCompletionContext = netvscPacket; + 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->TotalDataBufferLength = + vmxferpagePacket->Ranges[i].ByteCount; netvscPacket->PageBufferCount = 1; - ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + vmxferpagePacket->Ranges[i].ByteCount < netDevice->ReceiveBufferSize); + ASSERT(vmxferpagePacket->Ranges[i].ByteOffset + + vmxferpagePacket->Ranges[i].ByteCount < + netDevice->ReceiveBufferSize); - netvscPacket->PageBuffers[0].Length = vmxferpagePacket->Ranges[i].ByteCount; + netvscPacket->PageBuffers[0].Length = + vmxferpagePacket->Ranges[i].ByteCount; - start = GetPhysicalAddress((void*)((unsigned long)netDevice->ReceiveBuffer + vmxferpagePacket->Ranges[i].ByteOffset)); + start = + GetPhysicalAddress((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); + + vmxferpagePacket->Ranges[i].ByteCount - 1; + end = GetPhysicalAddress((void *)endVirtual); /* 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: */ - netvscPacket->PageBuffers[0].Length = - (netvscPacket->PageBuffers[0].Pfn <<PAGE_SHIFT) + PAGE_SIZE - start; - bytesRemain = netvscPacket->TotalDataBufferLength - netvscPacket->PageBuffers[0].Length; - for (j=1; j<NETVSC_PACKET_MAXPAGE; j++) { - netvscPacket->PageBuffers[j].Offset = 0; - if (bytesRemain <= PAGE_SIZE) { - netvscPacket->PageBuffers[j].Length = bytesRemain; - bytesRemain = 0; - } else { - netvscPacket->PageBuffers[j].Length = PAGE_SIZE; - bytesRemain -= PAGE_SIZE; + netvscPacket->PageBuffers[0].Offset = + vmxferpagePacket->Ranges[i].ByteOffset & (PAGE_SIZE - 1); + if ((end >> PAGE_SHIFT) != (start >> PAGE_SHIFT)) { + /* Handle frame across multiple pages: */ + netvscPacket->PageBuffers[0].Length = + (netvscPacket->PageBuffers[0].Pfn << PAGE_SHIFT) + + PAGE_SIZE - start; + bytesRemain = + netvscPacket->TotalDataBufferLength - + netvscPacket->PageBuffers[0].Length; + for (j = 1; j < NETVSC_PACKET_MAXPAGE; j++) { + netvscPacket->PageBuffers[j].Offset = 0; + if (bytesRemain <= PAGE_SIZE) { + netvscPacket->PageBuffers[j].Length = + bytesRemain; + bytesRemain = 0; + } else { + netvscPacket->PageBuffers[j].Length = + PAGE_SIZE; + bytesRemain -= PAGE_SIZE; + } + netvscPacket->PageBuffers[j].Pfn = + GetPhysicalAddress((void *)(endVirtual - + bytesRemain)) >> + PAGE_SHIFT; + netvscPacket->PageBufferCount++; + if (bytesRemain == 0) + break; } - netvscPacket->PageBuffers[j].Pfn = - GetPhysicalAddress((void*)(endVirtual - bytesRemain)) >> PAGE_SHIFT; - netvscPacket->PageBufferCount++; - if (bytesRemain == 0) - break; - } - ASSERT(bytesRemain == 0); + ASSERT(bytesRemain == 0); } - DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => (pfn %llx, offset %u, len %u)", - i, - vmxferpagePacket->Ranges[i].ByteOffset, - vmxferpagePacket->Ranges[i].ByteCount, - netvscPacket->PageBuffers[0].Pfn, - netvscPacket->PageBuffers[0].Offset, - netvscPacket->PageBuffers[0].Length); + DPRINT_DBG(NETVSC, + "[%d] - (abs offset %u len %u) => (pfn %llx, offset %u, len %u)", + i, vmxferpagePacket->Ranges[i].ByteOffset, + vmxferpagePacket->Ranges[i].ByteCount, + netvscPacket->PageBuffers[0].Pfn, + netvscPacket->PageBuffers[0].Offset, + netvscPacket->PageBuffers[0].Length); /* Pass it to the upper layer */ - ((NETVSC_DRIVER_OBJECT*)Device->Driver)->OnReceiveCallback(Device, netvscPacket); + ((NETVSC_DRIVER_OBJECT *) Device->Driver)-> + OnReceiveCallback(Device, netvscPacket); - NetVscOnReceiveCompletion(netvscPacket->Completion.Recv.ReceiveCompletionContext); + NetVscOnReceiveCompletion(netvscPacket->Completion.Recv. + ReceiveCompletionContext); } ASSERT(IsListEmpty(&listHead)); @@ -1301,66 +1287,62 @@ NetVscOnReceive( DPRINT_EXIT(NETVSC); } - static void -NetVscSendReceiveCompletion( - struct hv_device *Device, - u64 TransactionId - ) +NetVscSendReceiveCompletion(struct hv_device *Device, u64 TransactionId) { NVSP_MESSAGE recvcompMessage; - int retries=0; - int ret=0; + int retries = 0; + int ret = 0; - DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", TransactionId); + DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", + TransactionId); - recvcompMessage.Header.MessageType = NvspMessage1TypeSendRNDISPacketComplete; + recvcompMessage.Header.MessageType = + NvspMessage1TypeSendRNDISPacketComplete; /* FIXME: Pass in the status */ - recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete.Status = NvspStatusSuccess; + recvcompMessage.Messages.Version1Messages.SendRNDISPacketComplete. + Status = NvspStatusSuccess; retry_send_cmplt: /* Send the completion */ ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - &recvcompMessage, - sizeof(NVSP_MESSAGE), - TransactionId, - VmbusPacketTypeCompletion, - 0); - if (ret == 0) /* success */ - { + &recvcompMessage, + sizeof + (NVSP_MESSAGE), + TransactionId, + VmbusPacketTypeCompletion, + 0); + if (ret == 0) { /* success */ /* 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); + DPRINT_ERR(NETVSC, + "unable to send receive completion pkt (tid %llx)...retrying %d", + TransactionId, retries); - if (retries < 4) - { + if (retries < 4) { udelay(100); goto retry_send_cmplt; + } else { + DPRINT_ERR(NETVSC, + "unable to send receive completion pkt (tid %llx)...give up retrying", + TransactionId); } - else - { - DPRINT_ERR(NETVSC, "unable to send receive completion pkt (tid %llx)...give up retrying", TransactionId); - } - } - else - { - DPRINT_ERR(NETVSC, "unable to send receive completion pkt - %llx", TransactionId); + } else { + DPRINT_ERR(NETVSC, + "unable to send receive completion pkt - %llx", + TransactionId); } } /* Send a receive completion packet to RNDIS device (ie NetVsp) */ -static void -NetVscOnReceiveCompletion( - void * Context) +static void NetVscOnReceiveCompletion(void *Context) { - NETVSC_PACKET *packet = (NETVSC_PACKET*)Context; - struct hv_device *device = (struct hv_device*)packet->Device; + NETVSC_PACKET *packet = (NETVSC_PACKET *) Context; + struct hv_device *device = (struct hv_device *)packet->Device; struct NETVSC_DEVICE *netDevice; - u64 transactionId=0; + u64 transactionId = 0; bool fSendReceiveComp = false; unsigned long flags; @@ -1371,9 +1353,9 @@ NetVscOnReceiveCompletion( /* 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) - { - 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; } @@ -1386,12 +1368,12 @@ NetVscOnReceiveCompletion( /* 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) - { + if (packet->XferPagePacket->Count == 0) { fSendReceiveComp = true; transactionId = packet->Completion.Recv.ReceiveCompletionTid; - INSERT_TAIL_LIST(&netDevice->ReceivePacketList, &packet->XferPagePacket->ListEntry); + INSERT_TAIL_LIST(&netDevice->ReceivePacketList, + &packet->XferPagePacket->ListEntry); } /* Put the packet back */ @@ -1399,8 +1381,7 @@ NetVscOnReceiveCompletion( spin_unlock_irqrestore(&netDevice->receive_packet_list_lock, flags); /* Send a receive completion for the xfer page packet */ - if (fSendReceiveComp) - { + if (fSendReceiveComp) { NetVscSendReceiveCompletion(device, transactionId); } @@ -1408,84 +1389,76 @@ NetVscOnReceiveCompletion( DPRINT_EXIT(NETVSC); } - - -void -NetVscOnChannelCallback( - void * Context - ) +void NetVscOnChannelCallback(void *Context) { - const int netPacketSize=2048; - int ret=0; - struct hv_device *device=(struct hv_device*)Context; + const int netPacketSize = 2048; + int ret = 0; + struct hv_device *device = (struct hv_device *)Context; struct NETVSC_DEVICE *netDevice; u32 bytesRecvd; u64 requestId; unsigned char packet[netPacketSize]; VMPACKET_DESCRIPTOR *desc; - unsigned char *buffer=packet; - int bufferlen=netPacketSize; - + unsigned char *buffer = packet; + int bufferlen = netPacketSize; DPRINT_ENTER(NETVSC); ASSERT(device); netDevice = GetInboundNetDevice(device); - if (!netDevice) - { - DPRINT_ERR(NETVSC, "net device (%p) shutting down...ignoring inbound packets", netDevice); + if (!netDevice) { + DPRINT_ERR(NETVSC, + "net device (%p) shutting down...ignoring inbound packets", + netDevice); DPRINT_EXIT(NETVSC); return; } - do - { - ret = device->Driver->VmbusChannelInterface.RecvPacketRaw(device, - buffer, - bufferlen, - &bytesRecvd, - &requestId); - - if (ret == 0) - { - if (bytesRecvd > 0) - { - DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", bytesRecvd, requestId); - - desc = (VMPACKET_DESCRIPTOR*)buffer; - switch (desc->Type) - { - case VmbusPacketTypeCompletion: - NetVscOnSendCompletion(device, desc); - break; - - case VmbusPacketTypeDataUsingTransferPages: - NetVscOnReceive(device, desc); - break; - - default: - DPRINT_ERR(NETVSC, "unhandled packet type %d, tid %llx len %d\n", desc->Type, requestId, bytesRecvd); - break; + do { + ret = + device->Driver->VmbusChannelInterface.RecvPacketRaw(device, + buffer, + bufferlen, + &bytesRecvd, + &requestId); + + if (ret == 0) { + if (bytesRecvd > 0) { + DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", + bytesRecvd, requestId); + + desc = (VMPACKET_DESCRIPTOR *) buffer; + switch (desc->Type) { + case VmbusPacketTypeCompletion: + NetVscOnSendCompletion(device, desc); + break; + + case VmbusPacketTypeDataUsingTransferPages: + NetVscOnReceive(device, desc); + break; + + default: + DPRINT_ERR(NETVSC, + "unhandled packet type %d, tid %llx len %d\n", + desc->Type, requestId, + bytesRecvd); + break; } /* reset */ - if (bufferlen > netPacketSize) - { + if (bufferlen > netPacketSize) { kfree(buffer); buffer = packet; bufferlen = netPacketSize; } - } - else - { + } else { /* DPRINT_DBG(NETVSC, "nothing else to read..."); */ /* reset */ - if (bufferlen > netPacketSize) - { + if (bufferlen > netPacketSize) { kfree(buffer); buffer = packet; @@ -1494,21 +1467,18 @@ NetVscOnChannelCallback( break; } - } - else if (ret == -2) /* Handle large packet */ - { + } else if (ret == -2) { /* Handle large packet */ buffer = kmalloc(bytesRecvd, GFP_ATOMIC); - if (buffer == NULL) - { + if (buffer == NULL) { /* Try again next time around */ - DPRINT_ERR(NETVSC, "unable to allocate buffer of size (%d)!!", bytesRecvd); + DPRINT_ERR(NETVSC, + "unable to allocate buffer of size (%d)!!", + bytesRecvd); break; } bufferlen = bytesRecvd; - } - else - { + } else { ASSERT(0); } } while (1); diff --git a/drivers/staging/hv/NetVsc.h b/drivers/staging/hv/NetVsc.h index 7636654..cad15a9 100644 --- a/drivers/staging/hv/NetVsc.h +++ b/drivers/staging/hv/NetVsc.h @@ -20,7 +20,6 @@ * */ - #ifndef _NETVSC_H_ #define _NETVSC_H_ @@ -36,11 +35,10 @@ /* #define NVSC_MIN_PROTOCOL_VERSION 1 */ /* #define NVSC_MAX_PROTOCOL_VERSION 1 */ -#define NETVSC_SEND_BUFFER_SIZE 64*1024 /* 64K */ +#define NETVSC_SEND_BUFFER_SIZE 64*1024 /* 64K */ #define NETVSC_SEND_BUFFER_ID 0xface - -#define NETVSC_RECEIVE_BUFFER_SIZE 1024*1024 /* 1MB */ +#define NETVSC_RECEIVE_BUFFER_SIZE 1024*1024 /* 1MB */ #define NETVSC_RECEIVE_BUFFER_ID 0xcafe @@ -49,43 +47,41 @@ /* Preallocated receive packets */ #define NETVSC_RECEIVE_PACKETLIST_COUNT 256 - /* Data types */ - /* Per netvsc channel-specific */ struct NETVSC_DEVICE { struct hv_device *Device; - int RefCount; + int RefCount; - int NumOutstandingSends; + int NumOutstandingSends; /* List of free preallocated NETVSC_PACKET to represent receive packet */ - LIST_ENTRY ReceivePacketList; + LIST_ENTRY ReceivePacketList; spinlock_t receive_packet_list_lock; /* Send buffer allocated by us but manages by NetVSP */ - void * SendBuffer; - u32 SendBufferSize; - u32 SendBufferGpadlHandle; - u32 SendSectionSize; + void *SendBuffer; + u32 SendBufferSize; + u32 SendBufferGpadlHandle; + u32 SendSectionSize; /* Receive buffer allocated by us but manages by NetVSP */ - void * ReceiveBuffer; - u32 ReceiveBufferSize; - u32 ReceiveBufferGpadlHandle; - u32 ReceiveSectionCount; - PNVSP_1_RECEIVE_BUFFER_SECTION ReceiveSections; + void *ReceiveBuffer; + u32 ReceiveBufferSize; + u32 ReceiveBufferGpadlHandle; + u32 ReceiveSectionCount; + PNVSP_1_RECEIVE_BUFFER_SECTION ReceiveSections; /* Used for NetVSP initialization protocol */ struct osd_waitevent *ChannelInitEvent; - NVSP_MESSAGE ChannelInitPacket; + NVSP_MESSAGE ChannelInitPacket; - NVSP_MESSAGE RevokePacket; - /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ + NVSP_MESSAGE RevokePacket; + /* unsigned char HwMacAddr[HW_MACADDR_LEN]; */ /* Holds rndis device info */ - void *Extension; + void *Extension; }; #endif /* _NETVSC_H_ */ diff --git a/drivers/staging/hv/RingBuffer.c b/drivers/staging/hv/RingBuffer.c index 6a9f568..270e549 100644 --- a/drivers/staging/hv/RingBuffer.c +++ b/drivers/staging/hv/RingBuffer.c @@ -21,18 +21,14 @@ * */ - #include "include/logging.h" #include "RingBuffer.h" - /* #defines */ - /* Amount of space to write to */ #define BYTES_AVAIL_TO_WRITE(r, w, z) ((w) >= (r))?((z) - ((w) - (r))):((r) - (w)) - /*++ Name: @@ -44,9 +40,9 @@ Description: --*/ static inline void -GetRingBufferAvailBytes(RING_BUFFER_INFO *rbi, u32 *read, u32 *write) +GetRingBufferAvailBytes(RING_BUFFER_INFO * rbi, u32 * read, u32 * write) { - u32 read_loc,write_loc; + u32 read_loc, write_loc; /* Capture the read/write indices before they changed */ read_loc = rbi->RingBuffer->ReadIndex; @@ -65,8 +61,7 @@ Description: Get the next write location for the specified ring buffer --*/ -static inline u32 -GetNextWriteLocation(RING_BUFFER_INFO* RingInfo) +static inline u32 GetNextWriteLocation(RING_BUFFER_INFO * RingInfo) { u32 next = RingInfo->RingBuffer->WriteIndex; @@ -85,7 +80,7 @@ Description: --*/ static inline void -SetNextWriteLocation(RING_BUFFER_INFO* RingInfo, u32 NextWriteLocation) +SetNextWriteLocation(RING_BUFFER_INFO * RingInfo, u32 NextWriteLocation) { RingInfo->RingBuffer->WriteIndex = NextWriteLocation; } @@ -99,8 +94,7 @@ Description: Get the next read location for the specified ring buffer --*/ -static inline u32 -GetNextReadLocation(RING_BUFFER_INFO* RingInfo) +static inline u32 GetNextReadLocation(RING_BUFFER_INFO * RingInfo) { u32 next = RingInfo->RingBuffer->ReadIndex; @@ -120,7 +114,7 @@ Description: --*/ static inline u32 -GetNextReadLocationWithOffset(RING_BUFFER_INFO* RingInfo, u32 Offset) +GetNextReadLocationWithOffset(RING_BUFFER_INFO * RingInfo, u32 Offset) { u32 next = RingInfo->RingBuffer->ReadIndex; @@ -141,12 +135,11 @@ Description: --*/ static inline void -SetNextReadLocation(RING_BUFFER_INFO* RingInfo, u32 NextReadLocation) +SetNextReadLocation(RING_BUFFER_INFO * RingInfo, u32 NextReadLocation) { RingInfo->RingBuffer->ReadIndex = NextReadLocation; } - /*++ Name: @@ -156,13 +149,11 @@ Description: Get the start of the ring buffer --*/ -static inline void * -GetRingBuffer(RING_BUFFER_INFO* RingInfo) +static inline void *GetRingBuffer(RING_BUFFER_INFO * RingInfo) { return (void *)RingInfo->RingBuffer->Buffer; } - /*++ Name: @@ -172,8 +163,7 @@ Description: Get the size of the ring buffer --*/ -static inline u32 -GetRingBufferSize(RING_BUFFER_INFO* RingInfo) +static inline u32 GetRingBufferSize(RING_BUFFER_INFO * RingInfo) { return RingInfo->RingDataSize; } @@ -187,13 +177,12 @@ Description: Get the read and write indices as u64 of the specified ring buffer --*/ -static inline u64 -GetRingBufferIndices(RING_BUFFER_INFO* RingInfo) +static inline u64 GetRingBufferIndices(RING_BUFFER_INFO * RingInfo) { - return ((u64)RingInfo->RingBuffer->WriteIndex << 32) || RingInfo->RingBuffer->ReadIndex; + return ((u64) RingInfo->RingBuffer->WriteIndex << 32) + || RingInfo->RingBuffer->ReadIndex; } - /*++ Name: @@ -203,42 +192,31 @@ Description: Dump out to console the ring buffer info --*/ -void -DumpRingInfo(RING_BUFFER_INFO* RingInfo, char *Prefix) +void DumpRingInfo(RING_BUFFER_INFO * RingInfo, char *Prefix) { u32 bytesAvailToWrite; u32 bytesAvailToRead; - GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, &bytesAvailToWrite); + GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, + &bytesAvailToWrite); - DPRINT(VMBUS, DEBUG_RING_LVL, "%s <<ringinfo %p buffer %p avail write %u avail read %u read idx %u write idx %u>>", - Prefix, - RingInfo, - RingInfo->RingBuffer->Buffer, - bytesAvailToWrite, - bytesAvailToRead, - RingInfo->RingBuffer->ReadIndex, - RingInfo->RingBuffer->WriteIndex); + DPRINT(VMBUS, DEBUG_RING_LVL, + "%s <<ringinfo %p buffer %p avail write %u avail read %u read idx %u write idx %u>>", + Prefix, RingInfo, RingInfo->RingBuffer->Buffer, + bytesAvailToWrite, bytesAvailToRead, + RingInfo->RingBuffer->ReadIndex, + RingInfo->RingBuffer->WriteIndex); } - /* Internal routines */ static u32 -CopyToRingBuffer( - RING_BUFFER_INFO *RingInfo, - u32 StartWriteOffset, - void * Src, - u32 SrcLen); +CopyToRingBuffer(RING_BUFFER_INFO * RingInfo, + u32 StartWriteOffset, void *Src, u32 SrcLen); static u32 -CopyFromRingBuffer( - RING_BUFFER_INFO *RingInfo, - void * Dest, - u32 DestLen, - u32 StartReadOffset); - - +CopyFromRingBuffer(RING_BUFFER_INFO * RingInfo, + void *Dest, u32 DestLen, u32 StartReadOffset); /*++ @@ -250,28 +228,26 @@ Description: --*/ void -RingBufferGetDebugInfo( - RING_BUFFER_INFO *RingInfo, - RING_BUFFER_DEBUG_INFO *DebugInfo - ) +RingBufferGetDebugInfo(RING_BUFFER_INFO * RingInfo, + RING_BUFFER_DEBUG_INFO * DebugInfo) { u32 bytesAvailToWrite; u32 bytesAvailToRead; - if (RingInfo->RingBuffer) - { - GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, &bytesAvailToWrite); + if (RingInfo->RingBuffer) { + GetRingBufferAvailBytes(RingInfo, &bytesAvailToRead, + &bytesAvailToWrite); DebugInfo->BytesAvailToRead = bytesAvailToRead; DebugInfo->BytesAvailToWrite = bytesAvailToWrite; DebugInfo->CurrentReadIndex = RingInfo->RingBuffer->ReadIndex; DebugInfo->CurrentWriteIndex = RingInfo->RingBuffer->WriteIndex; - DebugInfo->CurrentInterruptMask = RingInfo->RingBuffer->InterruptMask; + DebugInfo->CurrentInterruptMask = + RingInfo->RingBuffer->InterruptMask; } } - /*++ Name: @@ -281,10 +257,7 @@ Description: Get the interrupt mask for the specified ring buffer --*/ -u32 -GetRingBufferInterruptMask( - RING_BUFFER_INFO *rbi - ) +u32 GetRingBufferInterruptMask(RING_BUFFER_INFO * rbi) { return rbi->RingBuffer->InterruptMask; } @@ -298,18 +271,13 @@ Description: Initialize the ring buffer --*/ -int -RingBufferInit( - RING_BUFFER_INFO *RingInfo, - void *Buffer, - u32 BufferLen - ) +int RingBufferInit(RING_BUFFER_INFO * RingInfo, void *Buffer, u32 BufferLen) { ASSERT(sizeof(RING_BUFFER) == PAGE_SIZE); memset(RingInfo, 0, sizeof(RING_BUFFER_INFO)); - RingInfo->RingBuffer = (RING_BUFFER*)Buffer; + RingInfo->RingBuffer = (RING_BUFFER *) Buffer; RingInfo->RingBuffer->ReadIndex = RingInfo->RingBuffer->WriteIndex = 0; RingInfo->RingSize = BufferLen; @@ -329,10 +297,7 @@ Description: Cleanup the ring buffer --*/ -void -RingBufferCleanup( - RING_BUFFER_INFO* RingInfo - ) +void RingBufferCleanup(RING_BUFFER_INFO * RingInfo) { } @@ -346,25 +311,21 @@ Description: --*/ int -RingBufferWrite( - RING_BUFFER_INFO* OutRingInfo, - SG_BUFFER_LIST SgBuffers[], - u32 SgBufferCount - ) +RingBufferWrite(RING_BUFFER_INFO * OutRingInfo, + SG_BUFFER_LIST SgBuffers[], u32 SgBufferCount) { - int i=0; + int i = 0; u32 byteAvailToWrite; u32 byteAvailToRead; - u32 totalBytesToWrite=0; + u32 totalBytesToWrite = 0; volatile u32 nextWriteLocation; - u64 prevIndices=0; + u64 prevIndices = 0; unsigned long flags; DPRINT_ENTER(VMBUS); - for (i=0; i < SgBufferCount; i++) - { + for (i = 0; i < SgBufferCount; i++) { totalBytesToWrite += SgBuffers[i].Length; } @@ -372,7 +333,8 @@ RingBufferWrite( spin_lock_irqsave(&OutRingInfo->ring_lock, flags); - GetRingBufferAvailBytes(OutRingInfo, &byteAvailToRead, &byteAvailToWrite); + GetRingBufferAvailBytes(OutRingInfo, &byteAvailToRead, + &byteAvailToWrite); DPRINT_DBG(VMBUS, "Writing %u bytes...", totalBytesToWrite); @@ -380,9 +342,10 @@ RingBufferWrite( /* If there is only room for the packet, assume it is full. Otherwise, the next time around, we think the ring buffer */ /* is empty since the read index == write index */ - if (byteAvailToWrite <= totalBytesToWrite) - { - DPRINT_DBG(VMBUS, "No more space left on outbound ring buffer (needed %u, avail %u)", totalBytesToWrite, byteAvailToWrite); + if (byteAvailToWrite <= totalBytesToWrite) { + DPRINT_DBG(VMBUS, + "No more space left on outbound ring buffer (needed %u, avail %u)", + totalBytesToWrite, byteAvailToWrite); spin_unlock_irqrestore(&OutRingInfo->ring_lock, flags); @@ -394,21 +357,19 @@ RingBufferWrite( /* Write to the ring buffer */ nextWriteLocation = GetNextWriteLocation(OutRingInfo); - for (i=0; i < SgBufferCount; i++) - { - nextWriteLocation = CopyToRingBuffer(OutRingInfo, - nextWriteLocation, - SgBuffers[i].Data, - SgBuffers[i].Length); + for (i = 0; i < SgBufferCount; i++) { + nextWriteLocation = CopyToRingBuffer(OutRingInfo, + nextWriteLocation, + SgBuffers[i].Data, + SgBuffers[i].Length); } /* Set previous packet start */ prevIndices = GetRingBufferIndices(OutRingInfo); nextWriteLocation = CopyToRingBuffer(OutRingInfo, - nextWriteLocation, - &prevIndices, - sizeof(u64)); + nextWriteLocation, + &prevIndices, sizeof(u64)); /* Make sure we flush all writes before updating the writeIndex */ mb(); @@ -425,7 +386,6 @@ RingBufferWrite( return 0; } - /*++ Name: @@ -435,25 +395,20 @@ Description: Read without advancing the read index --*/ -int -RingBufferPeek( - RING_BUFFER_INFO* InRingInfo, - void* Buffer, - u32 BufferLen - ) +int RingBufferPeek(RING_BUFFER_INFO * InRingInfo, void *Buffer, u32 BufferLen) { u32 bytesAvailToWrite; u32 bytesAvailToRead; - u32 nextReadLocation=0; + u32 nextReadLocation = 0; unsigned long flags; spin_lock_irqsave(&InRingInfo->ring_lock, flags); - GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite); + GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, + &bytesAvailToWrite); /* Make sure there is something to read */ - if (bytesAvailToRead < BufferLen ) - { + if (bytesAvailToRead < BufferLen) { /* DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen); */ spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); @@ -465,16 +420,14 @@ RingBufferPeek( nextReadLocation = GetNextReadLocation(InRingInfo); nextReadLocation = CopyFromRingBuffer(InRingInfo, - Buffer, - BufferLen, - nextReadLocation); + Buffer, + BufferLen, nextReadLocation); spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); return 0; } - /*++ Name: @@ -485,33 +438,31 @@ Description: --*/ int -RingBufferRead( - RING_BUFFER_INFO* InRingInfo, - void * Buffer, - u32 BufferLen, - u32 Offset - ) +RingBufferRead(RING_BUFFER_INFO * InRingInfo, + void *Buffer, u32 BufferLen, u32 Offset) { u32 bytesAvailToWrite; u32 bytesAvailToRead; - u32 nextReadLocation=0; - u64 prevIndices=0; + u32 nextReadLocation = 0; + u64 prevIndices = 0; unsigned long flags; ASSERT(BufferLen > 0); spin_lock_irqsave(&InRingInfo->ring_lock, flags); - GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, &bytesAvailToWrite); + GetRingBufferAvailBytes(InRingInfo, &bytesAvailToRead, + &bytesAvailToWrite); DPRINT_DBG(VMBUS, "Reading %u bytes...", BufferLen); /* DumpRingInfo(InRingInfo, "BEFORE "); */ /* Make sure there is something to read */ - if (bytesAvailToRead < BufferLen ) - { - DPRINT_DBG(VMBUS, "got callback but not enough to read <avail to read %d read size %d>!!", bytesAvailToRead, BufferLen); + if (bytesAvailToRead < BufferLen) { + DPRINT_DBG(VMBUS, + "got callback but not enough to read <avail to read %d read size %d>!!", + bytesAvailToRead, BufferLen); spin_unlock_irqrestore(&InRingInfo->ring_lock, flags); @@ -521,14 +472,12 @@ RingBufferRead( nextReadLocation = GetNextReadLocationWithOffset(InRingInfo, Offset); nextReadLocation = CopyFromRingBuffer(InRingInfo, - Buffer, - BufferLen, - nextReadLocation); + Buffer, + BufferLen, nextReadLocation); nextReadLocation = CopyFromRingBuffer(InRingInfo, - &prevIndices, - sizeof(u64), - nextReadLocation); + &prevIndices, + sizeof(u64), nextReadLocation); /* Make sure all reads are done before we update the read index since */ /* the writer may start writing to the read area once the read index is updated */ @@ -544,7 +493,6 @@ RingBufferRead( return 0; } - /*++ Name: @@ -556,26 +504,20 @@ Description: --*/ u32 -CopyToRingBuffer( - RING_BUFFER_INFO *RingInfo, - u32 StartWriteOffset, - void * Src, - u32 SrcLen) +CopyToRingBuffer(RING_BUFFER_INFO * RingInfo, + u32 StartWriteOffset, void *Src, u32 SrcLen) { - void * ringBuffer=GetRingBuffer(RingInfo); - u32 ringBufferSize=GetRingBufferSize(RingInfo); + void *ringBuffer = GetRingBuffer(RingInfo); + u32 ringBufferSize = GetRingBufferSize(RingInfo); u32 fragLen; - if (SrcLen > ringBufferSize - StartWriteOffset) /* wrap-around detected! */ - { + if (SrcLen > ringBufferSize - StartWriteOffset) { /* wrap-around detected! */ DPRINT_DBG(VMBUS, "wrap-around detected!"); fragLen = ringBufferSize - StartWriteOffset; memcpy(ringBuffer + StartWriteOffset, Src, fragLen); memcpy(ringBuffer, Src + fragLen, SrcLen - fragLen); - } - else - { + } else { memcpy(ringBuffer + StartWriteOffset, Src, SrcLen); } @@ -585,7 +527,6 @@ CopyToRingBuffer( return StartWriteOffset; } - /*++ Name: @@ -597,28 +538,22 @@ Description: --*/ u32 -CopyFromRingBuffer( - RING_BUFFER_INFO *RingInfo, - void * Dest, - u32 DestLen, - u32 StartReadOffset) +CopyFromRingBuffer(RING_BUFFER_INFO * RingInfo, + void *Dest, u32 DestLen, u32 StartReadOffset) { - void * ringBuffer=GetRingBuffer(RingInfo); - u32 ringBufferSize=GetRingBufferSize(RingInfo); + void *ringBuffer = GetRingBuffer(RingInfo); + u32 ringBufferSize = GetRingBufferSize(RingInfo); u32 fragLen; - if (DestLen > ringBufferSize - StartReadOffset) /* wrap-around detected at the src */ - { + if (DestLen > ringBufferSize - StartReadOffset) { /* wrap-around detected at the src */ DPRINT_DBG(VMBUS, "src wrap-around detected!"); fragLen = ringBufferSize - StartReadOffset; memcpy(Dest, ringBuffer + StartReadOffset, fragLen); memcpy(Dest + fragLen, ringBuffer, DestLen - fragLen); - } - else - { + } else { memcpy(Dest, ringBuffer + StartReadOffset, DestLen); } @@ -628,5 +563,4 @@ CopyFromRingBuffer( return StartReadOffset; } - /* eof */ diff --git a/drivers/staging/hv/RingBuffer.h b/drivers/staging/hv/RingBuffer.h index a0b6e0e..3ed3e92 100644 --- a/drivers/staging/hv/RingBuffer.h +++ b/drivers/staging/hv/RingBuffer.h @@ -21,103 +21,71 @@ * */ - #ifndef _RING_BUFFER_H_ #define _RING_BUFFER_H_ #include "include/osd.h" typedef struct _SG_BUFFER_LIST { - void * Data; - u32 Length; + void *Data; + u32 Length; } SG_BUFFER_LIST; typedef struct _RING_BUFFER { - volatile u32 WriteIndex; /* Offset in bytes from the start of ring data below */ - volatile u32 ReadIndex; /* Offset in bytes from the start of ring data below */ + volatile u32 WriteIndex; /* Offset in bytes from the start of ring data below */ + volatile u32 ReadIndex; /* Offset in bytes from the start of ring data below */ volatile u32 InterruptMask; - u8 Reserved[4084]; /* Pad it to PAGE_SIZE so that data starts on page boundary */ + u8 Reserved[4084]; /* Pad it to PAGE_SIZE so that data starts on page boundary */ /* NOTE: The InterruptMask field is used only for channels but since our vmbus connection */ /* also uses this data structure and its data starts here, we commented out this field. */ /* volatile u32 InterruptMask; */ /* Ring data starts here + RingDataStartOffset !!! DO NOT place any fields below this !!! */ - u8 Buffer[0]; -} __attribute__((packed)) RING_BUFFER; + u8 Buffer[0]; +} __attribute__ ((packed)) RING_BUFFER; typedef struct _RING_BUFFER_INFO { - RING_BUFFER* RingBuffer; - u32 RingSize; /* Include the shared header */ + RING_BUFFER *RingBuffer; + u32 RingSize; /* Include the shared header */ spinlock_t ring_lock; - u32 RingDataSize; /* < ringSize */ - u32 RingDataStartOffset; + u32 RingDataSize; /* < ringSize */ + u32 RingDataStartOffset; } RING_BUFFER_INFO; - typedef struct _RING_BUFFER_DEBUG_INFO { - u32 CurrentInterruptMask; - u32 CurrentReadIndex; - u32 CurrentWriteIndex; - u32 BytesAvailToRead; - u32 BytesAvailToWrite; -}RING_BUFFER_DEBUG_INFO; - - + u32 CurrentInterruptMask; + u32 CurrentReadIndex; + u32 CurrentWriteIndex; + u32 BytesAvailToRead; + u32 BytesAvailToWrite; +} RING_BUFFER_DEBUG_INFO; /* Interface */ - static int -RingBufferInit( - RING_BUFFER_INFO *RingInfo, - void * Buffer, - u32 BufferLen - ); +RingBufferInit(RING_BUFFER_INFO * RingInfo, void *Buffer, u32 BufferLen); -static void -RingBufferCleanup( - RING_BUFFER_INFO *RingInfo - ); +static void RingBufferCleanup(RING_BUFFER_INFO * RingInfo); static int -RingBufferWrite( - RING_BUFFER_INFO *RingInfo, - SG_BUFFER_LIST SgBuffers[], - u32 SgBufferCount - ); +RingBufferWrite(RING_BUFFER_INFO * RingInfo, + SG_BUFFER_LIST SgBuffers[], u32 SgBufferCount); static int -RingBufferPeek( - RING_BUFFER_INFO *RingInfo, - void * Buffer, - u32 BufferLen - ); +RingBufferPeek(RING_BUFFER_INFO * RingInfo, void *Buffer, u32 BufferLen); static int -RingBufferRead( - RING_BUFFER_INFO *RingInfo, - void * Buffer, - u32 BufferLen, - u32 Offset - ); - -static u32 -GetRingBufferInterruptMask( - RING_BUFFER_INFO *RingInfo - ); +RingBufferRead(RING_BUFFER_INFO * RingInfo, + void *Buffer, u32 BufferLen, u32 Offset); -static void -DumpRingInfo( - RING_BUFFER_INFO* RingInfo, - char *Prefix - ); +static u32 GetRingBufferInterruptMask(RING_BUFFER_INFO * RingInfo); + +static void DumpRingInfo(RING_BUFFER_INFO * RingInfo, char *Prefix); static void -RingBufferGetDebugInfo( - RING_BUFFER_INFO *RingInfo, - RING_BUFFER_DEBUG_INFO *DebugInfo - ); +RingBufferGetDebugInfo(RING_BUFFER_INFO * RingInfo, + RING_BUFFER_DEBUG_INFO * DebugInfo); #endif /* _RING_BUFFER_H_ */ diff --git a/drivers/staging/hv/RndisFilter.c b/drivers/staging/hv/RndisFilter.c index ddeede1..8c9bef9 100644 --- a/drivers/staging/hv/RndisFilter.c +++ b/drivers/staging/hv/RndisFilter.c @@ -28,13 +28,11 @@ #include "include/NetVscApi.h" #include "RndisFilter.h" - /* Data types */ - typedef struct _RNDIS_FILTER_DRIVER_OBJECT { /* The original driver */ - NETVSC_DRIVER_OBJECT InnerDriver; + NETVSC_DRIVER_OBJECT InnerDriver; } RNDIS_FILTER_DRIVER_OBJECT; @@ -46,171 +44,103 @@ typedef enum { } RNDIS_DEVICE_STATE; typedef struct _RNDIS_DEVICE { - struct NETVSC_DEVICE *NetDevice; + struct NETVSC_DEVICE *NetDevice; - RNDIS_DEVICE_STATE State; - u32 LinkStatus; - u32 NewRequestId; + RNDIS_DEVICE_STATE State; + u32 LinkStatus; + u32 NewRequestId; spinlock_t request_lock; - LIST_ENTRY RequestList; + LIST_ENTRY RequestList; - unsigned char HwMacAddr[HW_MACADDR_LEN]; + unsigned char HwMacAddr[HW_MACADDR_LEN]; } RNDIS_DEVICE; - typedef struct _RNDIS_REQUEST { - LIST_ENTRY ListEntry; + LIST_ENTRY ListEntry; struct osd_waitevent *WaitEvent; /* FIXME: We assumed a fixed size response here. If we do ever need to handle a bigger response, */ /* we can either define a max response message or add a response buffer variable above this field */ - RNDIS_MESSAGE ResponseMessage; + RNDIS_MESSAGE ResponseMessage; /* Simplify allocation by having a netvsc packet inline */ - NETVSC_PACKET Packet; - PAGE_BUFFER Buffer; + NETVSC_PACKET Packet; + PAGE_BUFFER Buffer; /* FIXME: We assumed a fixed size request here. */ - RNDIS_MESSAGE RequestMessage; + RNDIS_MESSAGE RequestMessage; } RNDIS_REQUEST; - typedef struct _RNDIS_FILTER_PACKET { - void *CompletionContext; - PFN_ON_SENDRECVCOMPLETION OnCompletion; + void *CompletionContext; + PFN_ON_SENDRECVCOMPLETION OnCompletion; - RNDIS_MESSAGE Message; + RNDIS_MESSAGE Message; } RNDIS_FILTER_PACKET; - /* Internal routines */ static int -RndisFilterSendRequest( - RNDIS_DEVICE *Device, - RNDIS_REQUEST *Request - ); +RndisFilterSendRequest(RNDIS_DEVICE * Device, RNDIS_REQUEST * Request); static void -RndisFilterReceiveResponse( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Response - ); +RndisFilterReceiveResponse(RNDIS_DEVICE * Device, RNDIS_MESSAGE * Response); static void -RndisFilterReceiveIndicateStatus( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Response - ); +RndisFilterReceiveIndicateStatus(RNDIS_DEVICE * Device, + RNDIS_MESSAGE * Response); static void -RndisFilterReceiveData( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Message, - NETVSC_PACKET *Packet - ); +RndisFilterReceiveData(RNDIS_DEVICE * Device, + RNDIS_MESSAGE * Message, NETVSC_PACKET * Packet); static int -RndisFilterOnReceive( - struct hv_device *Device, - NETVSC_PACKET *Packet - ); +RndisFilterOnReceive(struct hv_device *Device, NETVSC_PACKET * Packet); static int -RndisFilterQueryDevice( - RNDIS_DEVICE *Device, - u32 Oid, - void *Result, - u32 *ResultSize - ); - -static inline int -RndisFilterQueryDeviceMac( - RNDIS_DEVICE *Device - ); - -static inline int -RndisFilterQueryDeviceLinkStatus( - RNDIS_DEVICE *Device - ); +RndisFilterQueryDevice(RNDIS_DEVICE * Device, + u32 Oid, void *Result, u32 * ResultSize); -static int -RndisFilterSetPacketFilter( - RNDIS_DEVICE *Device, - u32 NewFilter - ); +static inline int RndisFilterQueryDeviceMac(RNDIS_DEVICE * Device); -static int -RndisFilterInitDevice( - RNDIS_DEVICE *Device - ); +static inline int RndisFilterQueryDeviceLinkStatus(RNDIS_DEVICE * Device); -static int -RndisFilterOpenDevice( - RNDIS_DEVICE *Device - ); +static int RndisFilterSetPacketFilter(RNDIS_DEVICE * Device, u32 NewFilter); -static int -RndisFilterCloseDevice( - RNDIS_DEVICE *Device - ); +static int RndisFilterInitDevice(RNDIS_DEVICE * Device); -static int -RndisFilterOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); +static int RndisFilterOpenDevice(RNDIS_DEVICE * Device); + +static int RndisFilterCloseDevice(RNDIS_DEVICE * Device); static int -RndisFilterOnDeviceRemove( - struct hv_device *Device - ); +RndisFilterOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); -static void -RndisFilterOnCleanup( - DRIVER_OBJECT *Driver - ); +static int RndisFilterOnDeviceRemove(struct hv_device *Device); -static int -RndisFilterOnOpen( - struct hv_device *Device - ); +static void RndisFilterOnCleanup(DRIVER_OBJECT * Driver); -static int -RndisFilterOnClose( - struct hv_device *Device - ); +static int RndisFilterOnOpen(struct hv_device *Device); -static int -RndisFilterOnSend( - struct hv_device *Device, - NETVSC_PACKET *Packet - ); +static int RndisFilterOnClose(struct hv_device *Device); -static void -RndisFilterOnSendCompletion( - void *Context - ); +static int RndisFilterOnSend(struct hv_device *Device, NETVSC_PACKET * Packet); -static void -RndisFilterOnSendRequestCompletion( - void *Context - ); +static void RndisFilterOnSendCompletion(void *Context); +static void RndisFilterOnSendRequestCompletion(void *Context); /* Global var */ - /* The one and only */ RNDIS_FILTER_DRIVER_OBJECT gRndisFilter; -static inline RNDIS_DEVICE* GetRndisDevice(void) +static inline RNDIS_DEVICE *GetRndisDevice(void) { RNDIS_DEVICE *device; device = kzalloc(sizeof(RNDIS_DEVICE), GFP_KERNEL); - if (!device) - { + if (!device) { return NULL; } @@ -223,12 +153,13 @@ static inline RNDIS_DEVICE* GetRndisDevice(void) return device; } -static inline void PutRndisDevice(RNDIS_DEVICE *Device) +static inline void PutRndisDevice(RNDIS_DEVICE * Device) { kfree(Device); } -static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageType, u32 MessageLength) +static inline RNDIS_REQUEST *GetRndisRequest(RNDIS_DEVICE * Device, + u32 MessageType, u32 MessageLength) { RNDIS_REQUEST *request; RNDIS_MESSAGE *rndisMessage; @@ -236,14 +167,12 @@ static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageTy unsigned long flags; request = kzalloc(sizeof(RNDIS_REQUEST), GFP_KERNEL); - if (!request) - { + if (!request) { return NULL; } request->WaitEvent = WaitEventCreate(); - if (!request->WaitEvent) - { + if (!request->WaitEvent) { kfree(request); return NULL; } @@ -255,7 +184,7 @@ static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageTy /* Set the request id. This field is always after the rndis header for request/response packet types so */ /* we just used the SetRequest as a template */ set = &rndisMessage->Message.SetRequest; - set->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); + set->RequestId = InterlockedIncrement((int *)&Device->NewRequestId); /* Add to the request list */ spin_lock_irqsave(&Device->request_lock, flags); @@ -265,7 +194,8 @@ static inline RNDIS_REQUEST* GetRndisRequest(RNDIS_DEVICE *Device, u32 MessageTy return request; } -static inline void PutRndisRequest(RNDIS_DEVICE *Device, RNDIS_REQUEST *Request) +static inline void PutRndisRequest(RNDIS_DEVICE * Device, + RNDIS_REQUEST * Request) { unsigned long flags; @@ -277,74 +207,84 @@ static inline void PutRndisRequest(RNDIS_DEVICE *Device, RNDIS_REQUEST *Request) kfree(Request); } -static inline void DumpRndisMessage(RNDIS_MESSAGE *RndisMessage) +static inline void DumpRndisMessage(RNDIS_MESSAGE * RndisMessage) { - switch (RndisMessage->NdisMessageType) - { + switch (RndisMessage->NdisMessageType) { case REMOTE_NDIS_PACKET_MSG: - DPRINT_DBG(NETVSC, "REMOTE_NDIS_PACKET_MSG (len %u, data offset %u data len %u, # oob %u, oob offset %u, oob len %u, pkt offset %u, pkt len %u", - RndisMessage->MessageLength, - RndisMessage->Message.Packet.DataOffset, - RndisMessage->Message.Packet.DataLength, - RndisMessage->Message.Packet.NumOOBDataElements, - RndisMessage->Message.Packet.OOBDataOffset, - RndisMessage->Message.Packet.OOBDataLength, - RndisMessage->Message.Packet.PerPacketInfoOffset, - RndisMessage->Message.Packet.PerPacketInfoLength); + DPRINT_DBG(NETVSC, + "REMOTE_NDIS_PACKET_MSG (len %u, data offset %u data len %u, # oob %u, oob offset %u, oob len %u, pkt offset %u, pkt len %u", + RndisMessage->MessageLength, + RndisMessage->Message.Packet.DataOffset, + RndisMessage->Message.Packet.DataLength, + RndisMessage->Message.Packet.NumOOBDataElements, + RndisMessage->Message.Packet.OOBDataOffset, + RndisMessage->Message.Packet.OOBDataLength, + RndisMessage->Message.Packet.PerPacketInfoOffset, + RndisMessage->Message.Packet.PerPacketInfoLength); break; case REMOTE_NDIS_INITIALIZE_CMPLT: - DPRINT_DBG(NETVSC, "REMOTE_NDIS_INITIALIZE_CMPLT (len %u, id 0x%x, status 0x%x, major %d, minor %d, device flags %d, max xfer size 0x%x, max pkts %u, pkt aligned %u)", - RndisMessage->MessageLength, - RndisMessage->Message.InitializeComplete.RequestId, - RndisMessage->Message.InitializeComplete.Status, - RndisMessage->Message.InitializeComplete.MajorVersion, - RndisMessage->Message.InitializeComplete.MinorVersion, - RndisMessage->Message.InitializeComplete.DeviceFlags, - RndisMessage->Message.InitializeComplete.MaxTransferSize, - RndisMessage->Message.InitializeComplete.MaxPacketsPerMessage, - RndisMessage->Message.InitializeComplete.PacketAlignmentFactor); + DPRINT_DBG(NETVSC, + "REMOTE_NDIS_INITIALIZE_CMPLT (len %u, id 0x%x, status 0x%x, major %d, minor %d, device flags %d, max xfer size 0x%x, max pkts %u, pkt aligned %u)", + RndisMessage->MessageLength, + RndisMessage->Message.InitializeComplete.RequestId, + RndisMessage->Message.InitializeComplete.Status, + RndisMessage->Message.InitializeComplete. + MajorVersion, + RndisMessage->Message.InitializeComplete. + MinorVersion, + RndisMessage->Message.InitializeComplete.DeviceFlags, + RndisMessage->Message.InitializeComplete. + MaxTransferSize, + RndisMessage->Message.InitializeComplete. + MaxPacketsPerMessage, + RndisMessage->Message.InitializeComplete. + PacketAlignmentFactor); break; case REMOTE_NDIS_QUERY_CMPLT: - DPRINT_DBG(NETVSC, "REMOTE_NDIS_QUERY_CMPLT (len %u, id 0x%x, status 0x%x, buf len %u, buf offset %u)", - RndisMessage->MessageLength, - RndisMessage->Message.QueryComplete.RequestId, - RndisMessage->Message.QueryComplete.Status, - RndisMessage->Message.QueryComplete.InformationBufferLength, - RndisMessage->Message.QueryComplete.InformationBufferOffset); + DPRINT_DBG(NETVSC, + "REMOTE_NDIS_QUERY_CMPLT (len %u, id 0x%x, status 0x%x, buf len %u, buf offset %u)", + RndisMessage->MessageLength, + RndisMessage->Message.QueryComplete.RequestId, + RndisMessage->Message.QueryComplete.Status, + RndisMessage->Message.QueryComplete. + InformationBufferLength, + RndisMessage->Message.QueryComplete. + InformationBufferOffset); break; case REMOTE_NDIS_SET_CMPLT: - DPRINT_DBG(NETVSC, "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", - RndisMessage->MessageLength, - RndisMessage->Message.SetComplete.RequestId, - RndisMessage->Message.SetComplete.Status); + DPRINT_DBG(NETVSC, + "REMOTE_NDIS_SET_CMPLT (len %u, id 0x%x, status 0x%x)", + RndisMessage->MessageLength, + RndisMessage->Message.SetComplete.RequestId, + RndisMessage->Message.SetComplete.Status); break; case REMOTE_NDIS_INDICATE_STATUS_MSG: - DPRINT_DBG(NETVSC, "REMOTE_NDIS_INDICATE_STATUS_MSG (len %u, status 0x%x, buf len %u, buf offset %u)", - RndisMessage->MessageLength, - RndisMessage->Message.IndicateStatus.Status, - RndisMessage->Message.IndicateStatus.StatusBufferLength, - RndisMessage->Message.IndicateStatus.StatusBufferOffset); + DPRINT_DBG(NETVSC, + "REMOTE_NDIS_INDICATE_STATUS_MSG (len %u, status 0x%x, buf len %u, buf offset %u)", + RndisMessage->MessageLength, + RndisMessage->Message.IndicateStatus.Status, + RndisMessage->Message.IndicateStatus. + StatusBufferLength, + RndisMessage->Message.IndicateStatus. + StatusBufferOffset); break; default: DPRINT_DBG(NETVSC, "0x%x (len %u)", - RndisMessage->NdisMessageType, - RndisMessage->MessageLength); + RndisMessage->NdisMessageType, + RndisMessage->MessageLength); break; } } static int -RndisFilterSendRequest( - RNDIS_DEVICE *Device, - RNDIS_REQUEST *Request - ) +RndisFilterSendRequest(RNDIS_DEVICE * Device, RNDIS_REQUEST * Request) { - int ret=0; + int ret = 0; NETVSC_PACKET *packet; DPRINT_ENTER(NETVSC); @@ -356,44 +296,48 @@ RndisFilterSendRequest( packet->TotalDataBufferLength = Request->RequestMessage.MessageLength; packet->PageBufferCount = 1; - packet->PageBuffers[0].Pfn = GetPhysicalAddress(&Request->RequestMessage) >> PAGE_SHIFT; + packet->PageBuffers[0].Pfn = + GetPhysicalAddress(&Request->RequestMessage) >> PAGE_SHIFT; packet->PageBuffers[0].Length = Request->RequestMessage.MessageLength; - packet->PageBuffers[0].Offset = (unsigned long)&Request->RequestMessage & (PAGE_SIZE -1); + packet->PageBuffers[0].Offset = + (unsigned long)&Request->RequestMessage & (PAGE_SIZE - 1); - packet->Completion.Send.SendCompletionContext = Request;/* packet; */ - packet->Completion.Send.OnSendCompletion = RndisFilterOnSendRequestCompletion; + packet->Completion.Send.SendCompletionContext = Request; /* packet; */ + packet->Completion.Send.OnSendCompletion = + RndisFilterOnSendRequestCompletion; packet->Completion.Send.SendCompletionTid = (unsigned long)Device; - ret = gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); + ret = + gRndisFilter.InnerDriver.OnSend(Device->NetDevice->Device, packet); DPRINT_EXIT(NETVSC); return ret; } - static void -RndisFilterReceiveResponse( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Response - ) +RndisFilterReceiveResponse(RNDIS_DEVICE * Device, RNDIS_MESSAGE * Response) { LIST_ENTRY *anchor; LIST_ENTRY *curr; - RNDIS_REQUEST *request=NULL; + RNDIS_REQUEST *request = NULL; bool found = false; unsigned long flags; DPRINT_ENTER(NETVSC); spin_lock_irqsave(&Device->request_lock, flags); - ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList) - { + ITERATE_LIST_ENTRIES(anchor, curr, &Device->RequestList) { request = CONTAINING_RECORD(curr, RNDIS_REQUEST, ListEntry); /* All request/response message contains RequestId as the 1st field */ - if (request->RequestMessage.Message.InitializeRequest.RequestId == Response->Message.InitializeComplete.RequestId) - { - DPRINT_DBG(NETVSC, "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)", - request->RequestMessage.Message.InitializeRequest.RequestId, request->RequestMessage.NdisMessageType, Response->NdisMessageType); + if (request->RequestMessage.Message.InitializeRequest. + RequestId == + Response->Message.InitializeComplete.RequestId) { + DPRINT_DBG(NETVSC, + "found rndis request for this response (id 0x%x req type 0x%x res type 0x%x)", + request->RequestMessage.Message. + InitializeRequest.RequestId, + request->RequestMessage.NdisMessageType, + Response->NdisMessageType); found = true; break; @@ -401,65 +345,57 @@ RndisFilterReceiveResponse( } spin_unlock_irqrestore(&Device->request_lock, flags); - if (found) - { - if (Response->MessageLength <= sizeof(RNDIS_MESSAGE)) - { - memcpy(&request->ResponseMessage, Response, Response->MessageLength); - } - else - { - DPRINT_ERR(NETVSC, "rndis response buffer overflow detected (size %u max %zu)", Response->MessageLength, sizeof(RNDIS_FILTER_PACKET)); - - if (Response->NdisMessageType == REMOTE_NDIS_RESET_CMPLT) /* does not have a request id field */ - { - request->ResponseMessage.Message.ResetComplete.Status = STATUS_BUFFER_OVERFLOW; - } - else - { - request->ResponseMessage.Message.InitializeComplete.Status = STATUS_BUFFER_OVERFLOW; + if (found) { + if (Response->MessageLength <= sizeof(RNDIS_MESSAGE)) { + memcpy(&request->ResponseMessage, Response, + Response->MessageLength); + } else { + DPRINT_ERR(NETVSC, + "rndis response buffer overflow detected (size %u max %zu)", + Response->MessageLength, + sizeof(RNDIS_FILTER_PACKET)); + + if (Response->NdisMessageType == REMOTE_NDIS_RESET_CMPLT) { /* does not have a request id field */ + request->ResponseMessage.Message.ResetComplete. + Status = STATUS_BUFFER_OVERFLOW; + } else { + request->ResponseMessage.Message. + InitializeComplete.Status = + STATUS_BUFFER_OVERFLOW; } } WaitEventSet(request->WaitEvent); - } - else - { - DPRINT_ERR(NETVSC, "no rndis request found for this response (id 0x%x res type 0x%x)", - Response->Message.InitializeComplete.RequestId, Response->NdisMessageType); + } else { + DPRINT_ERR(NETVSC, + "no rndis request found for this response (id 0x%x res type 0x%x)", + Response->Message.InitializeComplete.RequestId, + Response->NdisMessageType); } DPRINT_EXIT(NETVSC); } static void -RndisFilterReceiveIndicateStatus( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Response - ) +RndisFilterReceiveIndicateStatus(RNDIS_DEVICE * Device, + RNDIS_MESSAGE * Response) { RNDIS_INDICATE_STATUS *indicate = &Response->Message.IndicateStatus; - if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) - { - gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 1); - } - else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) - { - gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice->Device, 0); - } - else - { + if (indicate->Status == RNDIS_STATUS_MEDIA_CONNECT) { + gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice-> + Device, 1); + } else if (indicate->Status == RNDIS_STATUS_MEDIA_DISCONNECT) { + gRndisFilter.InnerDriver.OnLinkStatusChanged(Device->NetDevice-> + Device, 0); + } else { /* TODO: */ } } static void -RndisFilterReceiveData( - RNDIS_DEVICE *Device, - RNDIS_MESSAGE *Message, - NETVSC_PACKET *Packet - ) +RndisFilterReceiveData(RNDIS_DEVICE * Device, + RNDIS_MESSAGE * Message, NETVSC_PACKET * Packet) { RNDIS_PACKET *rndisPacket; u32 dataOffset; @@ -467,7 +403,8 @@ RndisFilterReceiveData( DPRINT_ENTER(NETVSC); /* empty ethernet frame ?? */ - ASSERT(Packet->PageBuffers[0].Length > RNDIS_MESSAGE_SIZE(RNDIS_PACKET)); + ASSERT(Packet->PageBuffers[0].Length > + RNDIS_MESSAGE_SIZE(RNDIS_PACKET)); rndisPacket = &Message->Message.Packet; @@ -483,18 +420,17 @@ RndisFilterReceiveData( Packet->IsDataPacket = true; - gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, Packet); + gRndisFilter.InnerDriver.OnReceiveCallback(Device->NetDevice->Device, + Packet); DPRINT_EXIT(NETVSC); } static int -RndisFilterOnReceive( - struct hv_device *Device, - NETVSC_PACKET *Packet - ) +RndisFilterOnReceive(struct hv_device *Device, NETVSC_PACKET * Packet) { - struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; + struct NETVSC_DEVICE *netDevice = + (struct NETVSC_DEVICE *)Device->Extension; RNDIS_DEVICE *rndisDevice; RNDIS_MESSAGE rndisMessage; RNDIS_MESSAGE *rndisHeader; @@ -503,54 +439,63 @@ RndisFilterOnReceive( ASSERT(netDevice); /* Make sure the rndis device state is initialized */ - if (!netDevice->Extension) - { - DPRINT_ERR(NETVSC, "got rndis message but no rndis device...dropping this message!"); + if (!netDevice->Extension) { + DPRINT_ERR(NETVSC, + "got rndis message but no rndis device...dropping this message!"); DPRINT_EXIT(NETVSC); return -1; } - rndisDevice = (RNDIS_DEVICE*)netDevice->Extension; - if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) - { - DPRINT_ERR(NETVSC, "got rndis message but rndis device uninitialized...dropping this message!"); + rndisDevice = (RNDIS_DEVICE *) netDevice->Extension; + if (rndisDevice->State == RNDIS_DEV_UNINITIALIZED) { + DPRINT_ERR(NETVSC, + "got rndis message but rndis device uninitialized...dropping this message!"); DPRINT_EXIT(NETVSC); return -1; } - rndisHeader = (RNDIS_MESSAGE*)PageMapVirtualAddress(Packet->PageBuffers[0].Pfn); + rndisHeader = + (RNDIS_MESSAGE *) PageMapVirtualAddress(Packet->PageBuffers[0].Pfn); - rndisHeader = (void*)((unsigned long)rndisHeader + Packet->PageBuffers[0].Offset); + rndisHeader = + (void *)((unsigned long)rndisHeader + + Packet->PageBuffers[0].Offset); /* Make sure we got a valid rndis message */ /* FIXME: There seems to be a bug in set completion msg where its MessageLength is 16 bytes but */ /* the ByteCount field in the xfer page range shows 52 bytes */ #if 0 - if ( Packet->TotalDataBufferLength != rndisHeader->MessageLength ) - { - PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset); - - DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u bytes got %u)...dropping this message!", - rndisHeader->MessageLength, Packet->TotalDataBufferLength); + if (Packet->TotalDataBufferLength != rndisHeader->MessageLength) { + PageUnmapVirtualAddress((void *)(unsigned long)rndisHeader - + Packet->PageBuffers[0].Offset); + + DPRINT_ERR(NETVSC, + "invalid rndis message? (expected %u bytes got %u)...dropping this message!", + rndisHeader->MessageLength, + Packet->TotalDataBufferLength); DPRINT_EXIT(NETVSC); return -1; } #endif - if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) && (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))) - { - DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow detected (got %u, max %zu)...marking it an error!", - rndisHeader->MessageLength, sizeof(RNDIS_MESSAGE)); + if ((rndisHeader->NdisMessageType != REMOTE_NDIS_PACKET_MSG) + && (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))) { + DPRINT_ERR(NETVSC, + "incoming rndis message buffer overflow detected (got %u, max %zu)...marking it an error!", + rndisHeader->MessageLength, sizeof(RNDIS_MESSAGE)); } - memcpy(&rndisMessage, rndisHeader, (rndisHeader->MessageLength > sizeof(RNDIS_MESSAGE))?sizeof(RNDIS_MESSAGE):rndisHeader->MessageLength); + memcpy(&rndisMessage, rndisHeader, + (rndisHeader->MessageLength > + sizeof(RNDIS_MESSAGE)) ? sizeof(RNDIS_MESSAGE) : rndisHeader-> + MessageLength); - PageUnmapVirtualAddress((void*)(unsigned long)rndisHeader - Packet->PageBuffers[0].Offset); + PageUnmapVirtualAddress((void *)(unsigned long)rndisHeader - + Packet->PageBuffers[0].Offset); DumpRndisMessage(&rndisMessage); - switch (rndisMessage.NdisMessageType) - { + switch (rndisMessage.NdisMessageType) { /* data msg */ case REMOTE_NDIS_PACKET_MSG: RndisFilterReceiveData(rndisDevice, &rndisMessage, Packet); @@ -560,8 +505,8 @@ RndisFilterOnReceive( case REMOTE_NDIS_INITIALIZE_CMPLT: case REMOTE_NDIS_QUERY_CMPLT: case REMOTE_NDIS_SET_CMPLT: - /* case REMOTE_NDIS_RESET_CMPLT: */ - /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ + /* case REMOTE_NDIS_RESET_CMPLT: */ + /* case REMOTE_NDIS_KEEPALIVE_CMPLT: */ RndisFilterReceiveResponse(rndisDevice, &rndisMessage); break; @@ -570,7 +515,9 @@ RndisFilterOnReceive( RndisFilterReceiveIndicateStatus(rndisDevice, &rndisMessage); break; default: - DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", rndisMessage.NdisMessageType, rndisMessage.MessageLength); + DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", + rndisMessage.NdisMessageType, + rndisMessage.MessageLength); break; } @@ -578,29 +525,25 @@ RndisFilterOnReceive( return 0; } - static int -RndisFilterQueryDevice( - RNDIS_DEVICE *Device, - u32 Oid, - void *Result, - u32 *ResultSize - ) +RndisFilterQueryDevice(RNDIS_DEVICE * Device, + u32 Oid, void *Result, u32 * ResultSize) { RNDIS_REQUEST *request; u32 inresultSize = *ResultSize; RNDIS_QUERY_REQUEST *query; RNDIS_QUERY_COMPLETE *queryComplete; - int ret=0; + int ret = 0; DPRINT_ENTER(NETVSC); ASSERT(Result); *ResultSize = 0; - request = GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, RNDIS_MESSAGE_SIZE(RNDIS_QUERY_REQUEST)); - if (!request) - { + request = + GetRndisRequest(Device, REMOTE_NDIS_QUERY_MSG, + RNDIS_MESSAGE_SIZE(RNDIS_QUERY_REQUEST)); + if (!request) { ret = -1; goto Cleanup; } @@ -613,8 +556,7 @@ RndisFilterQueryDevice( query->DeviceVcHandle = 0; ret = RndisFilterSendRequest(Device, request); - if (ret != 0) - { + if (ret != 0) { goto Cleanup; } @@ -623,21 +565,20 @@ RndisFilterQueryDevice( /* Copy the response back */ queryComplete = &request->ResponseMessage.Message.QueryComplete; - if (queryComplete->InformationBufferLength > inresultSize) - { + if (queryComplete->InformationBufferLength > inresultSize) { ret = -1; goto Cleanup; } memcpy(Result, - (void*)((unsigned long)queryComplete + queryComplete->InformationBufferOffset), - queryComplete->InformationBufferLength); + (void *)((unsigned long)queryComplete + + queryComplete->InformationBufferOffset), + queryComplete->InformationBufferLength); *ResultSize = queryComplete->InformationBufferLength; Cleanup: - if (request) - { + if (request) { PutRndisRequest(Device, request); } DPRINT_EXIT(NETVSC); @@ -645,37 +586,25 @@ Cleanup: return ret; } -static inline int -RndisFilterQueryDeviceMac( - RNDIS_DEVICE *Device - ) +static inline int RndisFilterQueryDeviceMac(RNDIS_DEVICE * Device) { - u32 size=HW_MACADDR_LEN; + u32 size = HW_MACADDR_LEN; return RndisFilterQueryDevice(Device, - RNDIS_OID_802_3_PERMANENT_ADDRESS, - Device->HwMacAddr, - &size); + RNDIS_OID_802_3_PERMANENT_ADDRESS, + Device->HwMacAddr, &size); } -static inline int -RndisFilterQueryDeviceLinkStatus( - RNDIS_DEVICE *Device - ) +static inline int RndisFilterQueryDeviceLinkStatus(RNDIS_DEVICE * Device) { - u32 size=sizeof(u32); + u32 size = sizeof(u32); return RndisFilterQueryDevice(Device, - RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, - &Device->LinkStatus, - &size); + RNDIS_OID_GEN_MEDIA_CONNECT_STATUS, + &Device->LinkStatus, &size); } -static int -RndisFilterSetPacketFilter( - RNDIS_DEVICE *Device, - u32 NewFilter - ) +static int RndisFilterSetPacketFilter(RNDIS_DEVICE * Device, u32 NewFilter) { RNDIS_REQUEST *request; RNDIS_SET_REQUEST *set; @@ -685,11 +614,14 @@ RndisFilterSetPacketFilter( DPRINT_ENTER(NETVSC); - ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32) <= sizeof(RNDIS_MESSAGE)); + ASSERT(RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32) <= + sizeof(RNDIS_MESSAGE)); - request = GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + sizeof(u32)); - if (!request) - { + request = + GetRndisRequest(Device, REMOTE_NDIS_SET_MSG, + RNDIS_MESSAGE_SIZE(RNDIS_SET_REQUEST) + + sizeof(u32)); + if (!request) { ret = -1; goto Cleanup; } @@ -700,26 +632,22 @@ RndisFilterSetPacketFilter( set->InformationBufferLength = sizeof(u32); set->InformationBufferOffset = sizeof(RNDIS_SET_REQUEST); - memcpy((void*)(unsigned long)set + sizeof(RNDIS_SET_REQUEST), &NewFilter, sizeof(u32)); + memcpy((void *)(unsigned long)set + sizeof(RNDIS_SET_REQUEST), + &NewFilter, sizeof(u32)); ret = RndisFilterSendRequest(Device, request); - if (ret != 0) - { + if (ret != 0) { goto Cleanup; } - ret = WaitEventWaitEx(request->WaitEvent, 2000/*2sec*/); - if (!ret) - { + ret = WaitEventWaitEx(request->WaitEvent, 2000 /*2sec */ ); + if (!ret) { ret = -1; DPRINT_ERR(NETVSC, "timeout before we got a set response..."); /* We cant deallocate the request since we may still receive a send completion for it. */ goto Exit; - } - else - { - if (ret > 0) - { + } else { + if (ret > 0) { ret = 0; } setComplete = &request->ResponseMessage.Message.SetComplete; @@ -727,8 +655,7 @@ RndisFilterSetPacketFilter( } Cleanup: - if (request) - { + if (request) { PutRndisRequest(Device, request); } Exit: @@ -737,17 +664,15 @@ Exit: return ret; } -int -RndisFilterInit( - NETVSC_DRIVER_OBJECT *Driver - ) +int RndisFilterInit(NETVSC_DRIVER_OBJECT * Driver) { DPRINT_ENTER(NETVSC); - DPRINT_DBG(NETVSC, "sizeof(RNDIS_FILTER_PACKET) == %zd", sizeof(RNDIS_FILTER_PACKET)); + DPRINT_DBG(NETVSC, "sizeof(RNDIS_FILTER_PACKET) == %zd", + sizeof(RNDIS_FILTER_PACKET)); Driver->RequestExtSize = sizeof(RNDIS_FILTER_PACKET); - Driver->AdditionalRequestPageBufferCount = 1; /* For rndis header */ + Driver->AdditionalRequestPageBufferCount = 1; /* For rndis header */ /* Driver->Context = rndisDriver; */ @@ -755,19 +680,21 @@ RndisFilterInit( /*rndisDriver->Driver = Driver; - ASSERT(Driver->OnLinkStatusChanged); - rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged;*/ + ASSERT(Driver->OnLinkStatusChanged); + rndisDriver->OnLinkStatusChanged = Driver->OnLinkStatusChanged; */ /* Save the original dispatch handlers before we override it */ gRndisFilter.InnerDriver.Base.OnDeviceAdd = Driver->Base.OnDeviceAdd; - gRndisFilter.InnerDriver.Base.OnDeviceRemove = Driver->Base.OnDeviceRemove; + gRndisFilter.InnerDriver.Base.OnDeviceRemove = + Driver->Base.OnDeviceRemove; gRndisFilter.InnerDriver.Base.OnCleanup = Driver->Base.OnCleanup; ASSERT(Driver->OnSend); ASSERT(Driver->OnReceiveCallback); gRndisFilter.InnerDriver.OnSend = Driver->OnSend; gRndisFilter.InnerDriver.OnReceiveCallback = Driver->OnReceiveCallback; - gRndisFilter.InnerDriver.OnLinkStatusChanged = Driver->OnLinkStatusChanged; + gRndisFilter.InnerDriver.OnLinkStatusChanged = + Driver->OnLinkStatusChanged; /* Override */ Driver->Base.OnDeviceAdd = RndisFilterOnDeviceAdd; @@ -784,10 +711,7 @@ RndisFilterInit( return 0; } -static int -RndisFilterInitDevice( - RNDIS_DEVICE *Device - ) +static int RndisFilterInitDevice(RNDIS_DEVICE * Device) { RNDIS_REQUEST *request; RNDIS_INITIALIZE_REQUEST *init; @@ -797,9 +721,10 @@ RndisFilterInitDevice( DPRINT_ENTER(NETVSC); - request = GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, RNDIS_MESSAGE_SIZE(RNDIS_INITIALIZE_REQUEST)); - if (!request) - { + request = + GetRndisRequest(Device, REMOTE_NDIS_INITIALIZE_MSG, + RNDIS_MESSAGE_SIZE(RNDIS_INITIALIZE_REQUEST)); + if (!request) { ret = -1; goto Cleanup; } @@ -808,13 +733,12 @@ RndisFilterInitDevice( init = &request->RequestMessage.Message.InitializeRequest; init->MajorVersion = RNDIS_MAJOR_VERSION; init->MinorVersion = RNDIS_MINOR_VERSION; - init->MaxTransferSize = 2048; /* FIXME: Use 1536 - rounded ethernet frame size */ + init->MaxTransferSize = 2048; /* FIXME: Use 1536 - rounded ethernet frame size */ Device->State = RNDIS_DEV_INITIALIZING; ret = RndisFilterSendRequest(Device, request); - if (ret != 0) - { + if (ret != 0) { Device->State = RNDIS_DEV_UNINITIALIZED; goto Cleanup; } @@ -823,20 +747,16 @@ RndisFilterInitDevice( initComplete = &request->ResponseMessage.Message.InitializeComplete; status = initComplete->Status; - if (status == RNDIS_STATUS_SUCCESS) - { + if (status == RNDIS_STATUS_SUCCESS) { Device->State = RNDIS_DEV_INITIALIZED; ret = 0; - } - else - { + } else { Device->State = RNDIS_DEV_UNINITIALIZED; ret = -1; } Cleanup: - if (request) - { + if (request) { PutRndisRequest(Device, request); } DPRINT_EXIT(NETVSC); @@ -844,10 +764,7 @@ Cleanup: return ret; } -static void -RndisFilterHaltDevice( - RNDIS_DEVICE *Device - ) +static void RndisFilterHaltDevice(RNDIS_DEVICE * Device) { RNDIS_REQUEST *request; RNDIS_HALT_REQUEST *halt; @@ -855,15 +772,16 @@ RndisFilterHaltDevice( DPRINT_ENTER(NETVSC); /* Attempt to do a rndis device halt */ - request = GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, RNDIS_MESSAGE_SIZE(RNDIS_HALT_REQUEST)); - if (!request) - { + request = + GetRndisRequest(Device, REMOTE_NDIS_HALT_MSG, + RNDIS_MESSAGE_SIZE(RNDIS_HALT_REQUEST)); + if (!request) { goto Cleanup; } /* Setup the rndis set */ halt = &request->RequestMessage.Message.HaltRequest; - halt->RequestId = InterlockedIncrement((int*)&Device->NewRequestId); + halt->RequestId = InterlockedIncrement((int *)&Device->NewRequestId); /* Ignore return since this msg is optional. */ RndisFilterSendRequest(Device, request); @@ -871,30 +789,27 @@ RndisFilterHaltDevice( Device->State = RNDIS_DEV_UNINITIALIZED; Cleanup: - if (request) - { + if (request) { PutRndisRequest(Device, request); } DPRINT_EXIT(NETVSC); return; } - -static int -RndisFilterOpenDevice( - RNDIS_DEVICE *Device - ) +static int RndisFilterOpenDevice(RNDIS_DEVICE * Device) { - int ret=0; + int ret = 0; DPRINT_ENTER(NETVSC); if (Device->State != RNDIS_DEV_INITIALIZED) return 0; - ret = RndisFilterSetPacketFilter(Device, NDIS_PACKET_TYPE_BROADCAST|NDIS_PACKET_TYPE_DIRECTED); - if (ret == 0) - { + ret = + RndisFilterSetPacketFilter(Device, + NDIS_PACKET_TYPE_BROADCAST | + NDIS_PACKET_TYPE_DIRECTED); + if (ret == 0) { Device->State = RNDIS_DEV_DATAINITIALIZED; } @@ -902,10 +817,7 @@ RndisFilterOpenDevice( return ret; } -static int -RndisFilterCloseDevice( - RNDIS_DEVICE *Device - ) +static int RndisFilterCloseDevice(RNDIS_DEVICE * Device) { int ret; @@ -915,8 +827,7 @@ RndisFilterCloseDevice( return 0; ret = RndisFilterSetPacketFilter(Device, 0); - if (ret == 0) - { + if (ret == 0) { Device->State = RNDIS_DEV_INITIALIZED; } @@ -925,23 +836,17 @@ RndisFilterCloseDevice( return ret; } - -int -RndisFilterOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ) +int RndisFilterOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { int ret; struct NETVSC_DEVICE *netDevice; RNDIS_DEVICE *rndisDevice; - NETVSC_DEVICE_INFO *deviceInfo = (NETVSC_DEVICE_INFO*)AdditionalInfo; + NETVSC_DEVICE_INFO *deviceInfo = (NETVSC_DEVICE_INFO *) AdditionalInfo; DPRINT_ENTER(NETVSC); rndisDevice = GetRndisDevice(); - if (!rndisDevice) - { + if (!rndisDevice) { DPRINT_EXIT(NETVSC); return -1; } @@ -952,17 +857,15 @@ RndisFilterOnDeviceAdd( /* NOTE! Once the channel is created, we may get a receive callback */ /* (RndisFilterOnReceive()) before this call is completed */ ret = gRndisFilter.InnerDriver.Base.OnDeviceAdd(Device, AdditionalInfo); - if (ret != 0) - { + if (ret != 0) { PutRndisDevice(rndisDevice); DPRINT_EXIT(NETVSC); return ret; } - /* Initialize the rndis device */ - netDevice = (struct NETVSC_DEVICE*)Device->Extension; + netDevice = (struct NETVSC_DEVICE *)Device->Extension; ASSERT(netDevice); ASSERT(netDevice->Device); @@ -971,47 +874,42 @@ RndisFilterOnDeviceAdd( /* Send the rndis initialization message */ ret = RndisFilterInitDevice(rndisDevice); - if (ret != 0) - { + if (ret != 0) { /* TODO: If rndis init failed, we will need to shut down the channel */ } /* Get the mac address */ ret = RndisFilterQueryDeviceMac(rndisDevice); - if (ret != 0) - { + if (ret != 0) { /* TODO: shutdown rndis device and the channel */ } DPRINT_INFO(NETVSC, "Device 0x%p mac addr %02x%02x%02x%02x%02x%02x", - rndisDevice, - rndisDevice->HwMacAddr[0], - rndisDevice->HwMacAddr[1], - rndisDevice->HwMacAddr[2], - rndisDevice->HwMacAddr[3], - rndisDevice->HwMacAddr[4], - rndisDevice->HwMacAddr[5]); + rndisDevice, + rndisDevice->HwMacAddr[0], + rndisDevice->HwMacAddr[1], + rndisDevice->HwMacAddr[2], + rndisDevice->HwMacAddr[3], + rndisDevice->HwMacAddr[4], rndisDevice->HwMacAddr[5]); memcpy(deviceInfo->MacAddr, rndisDevice->HwMacAddr, HW_MACADDR_LEN); RndisFilterQueryDeviceLinkStatus(rndisDevice); deviceInfo->LinkState = rndisDevice->LinkStatus; - DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, ((deviceInfo->LinkState)?("down"):("up"))); + DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, + ((deviceInfo->LinkState) ? ("down") : ("up"))); DPRINT_EXIT(NETVSC); return ret; } - -static int -RndisFilterOnDeviceRemove( - struct hv_device *Device - ) +static int RndisFilterOnDeviceRemove(struct hv_device *Device) { - struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; - RNDIS_DEVICE *rndisDevice = (RNDIS_DEVICE*)netDevice->Extension; + struct NETVSC_DEVICE *netDevice = + (struct NETVSC_DEVICE *)Device->Extension; + RNDIS_DEVICE *rndisDevice = (RNDIS_DEVICE *) netDevice->Extension; DPRINT_ENTER(NETVSC); @@ -1029,61 +927,48 @@ RndisFilterOnDeviceRemove( return 0; } - -static void -RndisFilterOnCleanup( - DRIVER_OBJECT *Driver - ) +static void RndisFilterOnCleanup(DRIVER_OBJECT * Driver) { DPRINT_ENTER(NETVSC); DPRINT_EXIT(NETVSC); } -static int -RndisFilterOnOpen( - struct hv_device *Device - ) +static int RndisFilterOnOpen(struct hv_device *Device) { int ret; - struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; + struct NETVSC_DEVICE *netDevice = + (struct NETVSC_DEVICE *)Device->Extension; DPRINT_ENTER(NETVSC); ASSERT(netDevice); - ret = RndisFilterOpenDevice((RNDIS_DEVICE*)netDevice->Extension); + ret = RndisFilterOpenDevice((RNDIS_DEVICE *) netDevice->Extension); DPRINT_EXIT(NETVSC); return ret; } -static int -RndisFilterOnClose( - struct hv_device *Device - ) +static int RndisFilterOnClose(struct hv_device *Device) { int ret; - struct NETVSC_DEVICE *netDevice = (struct NETVSC_DEVICE*)Device->Extension; + struct NETVSC_DEVICE *netDevice = + (struct NETVSC_DEVICE *)Device->Extension; DPRINT_ENTER(NETVSC); ASSERT(netDevice); - ret = RndisFilterCloseDevice((RNDIS_DEVICE*)netDevice->Extension); + ret = RndisFilterCloseDevice((RNDIS_DEVICE *) netDevice->Extension); DPRINT_EXIT(NETVSC); return ret; } - -static int -RndisFilterOnSend( - struct hv_device *Device, - NETVSC_PACKET *Packet - ) +static int RndisFilterOnSend(struct hv_device *Device, NETVSC_PACKET * Packet) { - int ret=0; + int ret = 0; RNDIS_FILTER_PACKET *filterPacket; RNDIS_MESSAGE *rndisMessage; RNDIS_PACKET *rndisPacket; @@ -1092,7 +977,7 @@ RndisFilterOnSend( DPRINT_ENTER(NETVSC); /* Add the rndis header */ - filterPacket = (RNDIS_FILTER_PACKET*)Packet->Extension; + filterPacket = (RNDIS_FILTER_PACKET *) Packet->Extension; ASSERT(filterPacket); memset(filterPacket, 0, sizeof(RNDIS_FILTER_PACKET)); @@ -1101,31 +986,36 @@ RndisFilterOnSend( rndisMessageSize = RNDIS_MESSAGE_SIZE(RNDIS_PACKET); rndisMessage->NdisMessageType = REMOTE_NDIS_PACKET_MSG; - rndisMessage->MessageLength = Packet->TotalDataBufferLength + rndisMessageSize; + rndisMessage->MessageLength = + Packet->TotalDataBufferLength + rndisMessageSize; rndisPacket = &rndisMessage->Message.Packet; rndisPacket->DataOffset = sizeof(RNDIS_PACKET); rndisPacket->DataLength = Packet->TotalDataBufferLength; Packet->IsDataPacket = true; - Packet->PageBuffers[0].Pfn = GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT; - Packet->PageBuffers[0].Offset = (unsigned long)rndisMessage & (PAGE_SIZE-1); - Packet->PageBuffers[0].Length = rndisMessageSize; + Packet->PageBuffers[0].Pfn = + GetPhysicalAddress(rndisMessage) >> PAGE_SHIFT; + Packet->PageBuffers[0].Offset = + (unsigned long)rndisMessage & (PAGE_SIZE - 1); + Packet->PageBuffers[0].Length = rndisMessageSize; /* Save the packet send completion and context */ filterPacket->OnCompletion = Packet->Completion.Send.OnSendCompletion; - filterPacket->CompletionContext = Packet->Completion.Send.SendCompletionContext; + filterPacket->CompletionContext = + Packet->Completion.Send.SendCompletionContext; /* Use ours */ Packet->Completion.Send.OnSendCompletion = RndisFilterOnSendCompletion; Packet->Completion.Send.SendCompletionContext = filterPacket; ret = gRndisFilter.InnerDriver.OnSend(Device, Packet); - if (ret != 0) - { + if (ret != 0) { /* Reset the completion to originals to allow retries from above */ - Packet->Completion.Send.OnSendCompletion = filterPacket->OnCompletion; - Packet->Completion.Send.SendCompletionContext = filterPacket->CompletionContext; + Packet->Completion.Send.OnSendCompletion = + filterPacket->OnCompletion; + Packet->Completion.Send.SendCompletionContext = + filterPacket->CompletionContext; } DPRINT_EXIT(NETVSC); @@ -1133,11 +1023,9 @@ RndisFilterOnSend( return ret; } -static void -RndisFilterOnSendCompletion( - void *Context) +static void RndisFilterOnSendCompletion(void *Context) { - RNDIS_FILTER_PACKET *filterPacket = (RNDIS_FILTER_PACKET *)Context; + RNDIS_FILTER_PACKET *filterPacket = (RNDIS_FILTER_PACKET *) Context; DPRINT_ENTER(NETVSC); @@ -1147,11 +1035,7 @@ RndisFilterOnSendCompletion( DPRINT_EXIT(NETVSC); } - -static void -RndisFilterOnSendRequestCompletion( - void *Context - ) +static void RndisFilterOnSendRequestCompletion(void *Context) { DPRINT_ENTER(NETVSC); diff --git a/drivers/staging/hv/RndisFilter.h b/drivers/staging/hv/RndisFilter.h index ebacbe0..37fb4c2 100644 --- a/drivers/staging/hv/RndisFilter.h +++ b/drivers/staging/hv/RndisFilter.h @@ -21,7 +21,6 @@ * */ - #ifndef _RNDISFILTER_H_ #define _RNDISFILTER_H_ @@ -47,15 +46,8 @@ #define NDIS_PACKET_TYPE_FUNCTIONAL 0x00000400 #define NDIS_PACKET_TYPE_MAC_FRAME 0x00000800 - - - /* Interface */ -int -RndisFilterInit( - NETVSC_DRIVER_OBJECT *Driver - ); - +int RndisFilterInit(NETVSC_DRIVER_OBJECT * Driver); #endif /* _RNDISFILTER_H_ */ diff --git a/drivers/staging/hv/StorVsc.c b/drivers/staging/hv/StorVsc.c index 4a406f0..a536a66 100644 --- a/drivers/staging/hv/StorVsc.c +++ b/drivers/staging/hv/StorVsc.c @@ -31,121 +31,88 @@ #include "include/VmbusPacketFormat.h" #include "include/vstorage.h" - - /* #defines */ - - /* Data types */ - typedef struct _STORVSC_REQUEST_EXTENSION { - /* LIST_ENTRY ListEntry; */ + /* LIST_ENTRY ListEntry; */ - STORVSC_REQUEST *Request; + STORVSC_REQUEST *Request; struct hv_device *Device; /* Synchronize the request/response if needed */ struct osd_waitevent *WaitEvent; - VSTOR_PACKET VStorPacket; + VSTOR_PACKET VStorPacket; } STORVSC_REQUEST_EXTENSION; - /* A storvsc device is a device object that contains a vmbus channel */ -typedef struct _STORVSC_DEVICE{ +typedef struct _STORVSC_DEVICE { struct hv_device *Device; - int RefCount; /* 0 indicates the device is being destroyed */ + int RefCount; /* 0 indicates the device is being destroyed */ - int NumOutstandingRequests; + int NumOutstandingRequests; /* * Each unique Port/Path/Target represents 1 channel ie scsi * controller. In reality, the pathid, targetid is always 0 * and the port is set by us */ - unsigned int PortNumber; - unsigned char PathId; - unsigned char TargetId; + unsigned int PortNumber; + unsigned char PathId; + unsigned char TargetId; - /* LIST_ENTRY OutstandingRequestList; */ - /* HANDLE OutstandingRequestLock; */ + /* LIST_ENTRY OutstandingRequestList; */ + /* HANDLE OutstandingRequestLock; */ /* Used for vsc/vsp channel reset process */ - STORVSC_REQUEST_EXTENSION InitRequest; + STORVSC_REQUEST_EXTENSION InitRequest; - STORVSC_REQUEST_EXTENSION ResetRequest; + STORVSC_REQUEST_EXTENSION ResetRequest; } STORVSC_DEVICE; - - /* Globals */ -static const char* gDriverName="storvsc"; +static const char *gDriverName = "storvsc"; /* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ -static const GUID gStorVscDeviceType={ - .Data = {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f} +static const GUID gStorVscDeviceType = { + .Data = + {0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, 0xb6, 0x05, 0x72, + 0xe2, 0xff, 0xb1, 0xdc, 0x7f} }; - /* Internal routines */ -static int -StorVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); +static int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); -static int -StorVscOnDeviceRemove( - struct hv_device *Device - ); +static int StorVscOnDeviceRemove(struct hv_device *Device); static int -StorVscOnIORequest( - struct hv_device *Device, - STORVSC_REQUEST *Request - ); +StorVscOnIORequest(struct hv_device *Device, STORVSC_REQUEST * Request); -static int -StorVscOnHostReset( - struct hv_device *Device - ); +static int StorVscOnHostReset(struct hv_device *Device); -static void -StorVscOnCleanup( - DRIVER_OBJECT *Device - ); +static void StorVscOnCleanup(DRIVER_OBJECT * Device); -static void -StorVscOnChannelCallback( - void * Context - ); +static void StorVscOnChannelCallback(void *Context); static void -StorVscOnIOCompletion( - struct hv_device *Device, - VSTOR_PACKET *VStorPacket, - STORVSC_REQUEST_EXTENSION *RequestExt - ); +StorVscOnIOCompletion(struct hv_device *Device, + VSTOR_PACKET * VStorPacket, + STORVSC_REQUEST_EXTENSION * RequestExt); static void -StorVscOnReceive( - struct hv_device *Device, - VSTOR_PACKET *VStorPacket, - STORVSC_REQUEST_EXTENSION *RequestExt - ); +StorVscOnReceive(struct hv_device *Device, + VSTOR_PACKET * VStorPacket, + STORVSC_REQUEST_EXTENSION * RequestExt); -static int -StorVscConnectToVsp( - struct hv_device *Device - ); +static int StorVscConnectToVsp(struct hv_device *Device); -static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device) +static inline STORVSC_DEVICE *AllocStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; @@ -163,24 +130,21 @@ static inline STORVSC_DEVICE* AllocStorDevice(struct hv_device *Device) return storDevice; } -static inline void FreeStorDevice(STORVSC_DEVICE *Device) +static inline void FreeStorDevice(STORVSC_DEVICE * Device) { ASSERT(Device->RefCount == 0); kfree(Device); } /* Get the stordevice object iff exists and its refcount > 1 */ -static inline STORVSC_DEVICE* GetStorDevice(struct hv_device *Device) +static inline STORVSC_DEVICE *GetStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - storDevice = (STORVSC_DEVICE*)Device->Extension; - if (storDevice && storDevice->RefCount > 1) - { + storDevice = (STORVSC_DEVICE *) Device->Extension; + if (storDevice && storDevice->RefCount > 1) { InterlockedIncrement(&storDevice->RefCount); - } - else - { + } else { storDevice = NULL; } @@ -188,17 +152,14 @@ static inline STORVSC_DEVICE* GetStorDevice(struct hv_device *Device) } /* Get the stordevice object iff exists and its refcount > 0 */ -static inline STORVSC_DEVICE* MustGetStorDevice(struct hv_device *Device) +static inline STORVSC_DEVICE *MustGetStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - storDevice = (STORVSC_DEVICE*)Device->Extension; - if (storDevice && storDevice->RefCount) - { + storDevice = (STORVSC_DEVICE *) Device->Extension; + if (storDevice && storDevice->RefCount) { InterlockedIncrement(&storDevice->RefCount); - } - else - { + } else { storDevice = NULL; } @@ -209,7 +170,7 @@ static inline void PutStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - storDevice = (STORVSC_DEVICE*)Device->Extension; + storDevice = (STORVSC_DEVICE *) Device->Extension; ASSERT(storDevice); InterlockedDecrement(&storDevice->RefCount); @@ -217,16 +178,15 @@ static inline void PutStorDevice(struct hv_device *Device) } /* Drop ref count to 1 to effectively disable GetStorDevice() */ -static inline STORVSC_DEVICE* ReleaseStorDevice(struct hv_device *Device) +static inline STORVSC_DEVICE *ReleaseStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - storDevice = (STORVSC_DEVICE*)Device->Extension; + storDevice = (STORVSC_DEVICE *) Device->Extension; ASSERT(storDevice); /* Busy wait until the ref drop to 2, then set it to 1 */ - while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2) - { + while (InterlockedCompareExchange(&storDevice->RefCount, 1, 2) != 2) { udelay(100); } @@ -234,16 +194,15 @@ static inline STORVSC_DEVICE* ReleaseStorDevice(struct hv_device *Device) } /* Drop ref count to 0. No one can use StorDevice object. */ -static inline STORVSC_DEVICE* FinalReleaseStorDevice(struct hv_device *Device) +static inline STORVSC_DEVICE *FinalReleaseStorDevice(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - storDevice = (STORVSC_DEVICE*)Device->Extension; + storDevice = (STORVSC_DEVICE *) Device->Extension; ASSERT(storDevice); /* Busy wait until the ref drop to 1, then set it to 0 */ - while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1) - { + while (InterlockedCompareExchange(&storDevice->RefCount, 0, 1) != 1) { udelay(100); } @@ -253,7 +212,6 @@ static inline STORVSC_DEVICE* FinalReleaseStorDevice(struct hv_device *Device) /*++; - Name: StorVscInitialize() @@ -261,18 +219,17 @@ Description: Main entry point --*/ -int -StorVscInitialize( - DRIVER_OBJECT *Driver - ) +int StorVscInitialize(DRIVER_OBJECT * Driver) { - STORVSC_DRIVER_OBJECT* storDriver = (STORVSC_DRIVER_OBJECT*)Driver; - int ret=0; + STORVSC_DRIVER_OBJECT *storDriver = (STORVSC_DRIVER_OBJECT *) Driver; + int ret = 0; DPRINT_ENTER(STORVSC); - DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd sizeof(STORVSC_REQUEST_EXTENSION)=%zd sizeof(VSTOR_PACKET)=%zd, sizeof(VMSCSI_REQUEST)=%zd", - sizeof(STORVSC_REQUEST), sizeof(STORVSC_REQUEST_EXTENSION), sizeof(VSTOR_PACKET), sizeof(VMSCSI_REQUEST)); + DPRINT_DBG(STORVSC, + "sizeof(STORVSC_REQUEST)=%zd sizeof(STORVSC_REQUEST_EXTENSION)=%zd sizeof(VSTOR_PACKET)=%zd, sizeof(VMSCSI_REQUEST)=%zd", + sizeof(STORVSC_REQUEST), sizeof(STORVSC_REQUEST_EXTENSION), + sizeof(VSTOR_PACKET), sizeof(VMSCSI_REQUEST)); /* Make sure we are at least 2 pages since 1 page is used for control */ ASSERT(storDriver->RingBufferSize >= (PAGE_SIZE << 1)); @@ -280,7 +237,7 @@ StorVscInitialize( Driver->name = gDriverName; memcpy(&Driver->deviceType, &gStorVscDeviceType, sizeof(GUID)); - storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION); + storDriver->RequestExtSize = sizeof(STORVSC_REQUEST_EXTENSION); /* * Divide the ring buffer data size (which is 1 page less @@ -289,17 +246,22 @@ StorVscInitialize( * VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER + VSTOR_PACKET + u64) */ storDriver->MaxOutstandingRequestsPerChannel = - ((storDriver->RingBufferSize - PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + sizeof(VSTOR_PACKET) + sizeof(u64),sizeof(u64))); + ((storDriver->RingBufferSize - + PAGE_SIZE) / ALIGN_UP(MAX_MULTIPAGE_BUFFER_PACKET + + sizeof(VSTOR_PACKET) + sizeof(u64), + sizeof(u64))); - DPRINT_INFO(STORVSC, "max io %u, currently %u\n", storDriver->MaxOutstandingRequestsPerChannel, STORVSC_MAX_IO_REQUESTS); + DPRINT_INFO(STORVSC, "max io %u, currently %u\n", + storDriver->MaxOutstandingRequestsPerChannel, + STORVSC_MAX_IO_REQUESTS); /* Setup the dispatch table */ - storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd; - storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; - storDriver->Base.OnCleanup = StorVscOnCleanup; + storDriver->Base.OnDeviceAdd = StorVscOnDeviceAdd; + storDriver->Base.OnDeviceRemove = StorVscOnDeviceRemove; + storDriver->Base.OnCleanup = StorVscOnCleanup; - storDriver->OnIORequest = StorVscOnIORequest; - storDriver->OnHostReset = StorVscOnHostReset; + storDriver->OnIORequest = StorVscOnIORequest; + storDriver->OnHostReset = StorVscOnHostReset; DPRINT_EXIT(STORVSC); @@ -315,22 +277,18 @@ Description: Callback when the device belonging to this driver is added --*/ -int -StorVscOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ) +int StorVscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { - int ret=0; + int ret = 0; STORVSC_DEVICE *storDevice; /* VMSTORAGE_CHANNEL_PROPERTIES *props; */ - STORVSC_DEVICE_INFO *deviceInfo = (STORVSC_DEVICE_INFO*)AdditionalInfo; + STORVSC_DEVICE_INFO *deviceInfo = + (STORVSC_DEVICE_INFO *) AdditionalInfo; DPRINT_ENTER(STORVSC); storDevice = AllocStorDevice(Device); - if (!storDevice) - { + if (!storDevice) { ret = -1; goto Cleanup; } @@ -346,8 +304,8 @@ StorVscOnDeviceAdd( */ /* storChannel->PortNumber = 0; - storChannel->PathId = props->PathId; - storChannel->TargetId = props->TargetId; */ + storChannel->PathId = props->PathId; + storChannel->TargetId = props->TargetId; */ storDevice->PortNumber = deviceInfo->PortNumber; /* Send it back up */ @@ -357,7 +315,9 @@ StorVscOnDeviceAdd( deviceInfo->PathId = storDevice->PathId; deviceInfo->TargetId = storDevice->TargetId; - DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", storDevice->PortNumber, storDevice->PathId, storDevice->TargetId); + DPRINT_DBG(STORVSC, "assigned port %u, path %u target %u\n", + storDevice->PortNumber, storDevice->PathId, + storDevice->TargetId); Cleanup: DPRINT_EXIT(STORVSC); @@ -367,15 +327,15 @@ Cleanup: static int StorVscChannelInit(struct hv_device *Device) { - int ret=0; + int ret = 0; STORVSC_DEVICE *storDevice; STORVSC_REQUEST_EXTENSION *request; VSTOR_PACKET *vstorPacket; storDevice = GetStorDevice(Device); - if (!storDevice) - { - DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?"); + if (!storDevice) { + DPRINT_ERR(STORVSC, + "unable to get stor device...device being destroyed?"); DPRINT_EXIT(STORVSC); return -1; } @@ -392,28 +352,32 @@ static int StorVscChannelInit(struct hv_device *Device) vstorPacket->Flags = REQUEST_COMPLETION_FLAG; /*SpinlockAcquire(gDriverExt.packetListLock); - INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); - SpinlockRelease(gDriverExt.packetListLock);*/ + INSERT_TAIL_LIST(&gDriverExt.packetList, &packet->listEntry.entry); + SpinlockRelease(gDriverExt.packetListLock); */ DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if ( ret != 0) - { - DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned long) + request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(STORVSC, + "unable to send BEGIN_INITIALIZATION_OPERATION"); goto Cleanup; } WaitEventWait(request->WaitEvent); - if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) - { - DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); + if (vstorPacket->Operation != VStorOperationCompleteIo + || vstorPacket->Status != 0) { + DPRINT_ERR(STORVSC, + "BEGIN_INITIALIZATION_OPERATION failed (op %d status 0x%x)", + vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } @@ -424,27 +388,31 @@ static int StorVscChannelInit(struct hv_device *Device) vstorPacket->Operation = VStorOperationQueryProtocolVersion; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; - FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); + vstorPacket->Version.MajorMinor = VMSTOR_PROTOCOL_VERSION_CURRENT; + FILL_VMSTOR_REVISION(vstorPacket->Version.Revision); ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if ( ret != 0) - { - DPRINT_ERR(STORVSC, "unable to send BEGIN_INITIALIZATION_OPERATION"); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned long) + request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(STORVSC, + "unable to send BEGIN_INITIALIZATION_OPERATION"); goto Cleanup; } WaitEventWait(request->WaitEvent); /* TODO: Check returned version */ - if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) - { - DPRINT_ERR(STORVSC, "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); + if (vstorPacket->Operation != VStorOperationCompleteIo + || vstorPacket->Status != 0) { + DPRINT_ERR(STORVSC, + "QUERY_PROTOCOL_VERSION_OPERATION failed (op %d status 0x%x)", + vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } @@ -452,29 +420,34 @@ static int StorVscChannelInit(struct hv_device *Device) DPRINT_INFO(STORVSC, "QUERY_PROPERTIES_OPERATION..."); memset(vstorPacket, sizeof(VSTOR_PACKET), 0); - vstorPacket->Operation = VStorOperationQueryProperties; + vstorPacket->Operation = VStorOperationQueryProperties; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - vstorPacket->StorageChannelProperties.PortNumber = storDevice->PortNumber; + vstorPacket->StorageChannelProperties.PortNumber = + storDevice->PortNumber; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - - if ( ret != 0) - { - DPRINT_ERR(STORVSC, "unable to send QUERY_PROPERTIES_OPERATION"); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned long) + request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + + if (ret != 0) { + DPRINT_ERR(STORVSC, + "unable to send QUERY_PROPERTIES_OPERATION"); goto Cleanup; } WaitEventWait(request->WaitEvent); /* TODO: Check returned version */ - if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) - { - DPRINT_ERR(STORVSC, "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); + if (vstorPacket->Operation != VStorOperationCompleteIo + || vstorPacket->Status != 0) { + DPRINT_ERR(STORVSC, + "QUERY_PROPERTIES_OPERATION failed (op %d status 0x%x)", + vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } @@ -482,40 +455,45 @@ static int StorVscChannelInit(struct hv_device *Device) storDevice->PathId = vstorPacket->StorageChannelProperties.PathId; storDevice->TargetId = vstorPacket->StorageChannelProperties.TargetId; - DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", vstorPacket->StorageChannelProperties.Flags, vstorPacket->StorageChannelProperties.MaxTransferBytes); + DPRINT_DBG(STORVSC, "channel flag 0x%x, max xfer len 0x%x", + vstorPacket->StorageChannelProperties.Flags, + vstorPacket->StorageChannelProperties.MaxTransferBytes); DPRINT_INFO(STORVSC, "END_INITIALIZATION_OPERATION..."); memset(vstorPacket, sizeof(VSTOR_PACKET), 0); - vstorPacket->Operation = VStorOperationEndInitialization; + vstorPacket->Operation = VStorOperationEndInitialization; vstorPacket->Flags = REQUEST_COMPLETION_FLAG; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)request, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - - if ( ret != 0) - { - DPRINT_ERR(STORVSC, "unable to send END_INITIALIZATION_OPERATION"); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned long) + request, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + + if (ret != 0) { + DPRINT_ERR(STORVSC, + "unable to send END_INITIALIZATION_OPERATION"); goto Cleanup; } WaitEventWait(request->WaitEvent); - if (vstorPacket->Operation != VStorOperationCompleteIo || vstorPacket->Status != 0) - { - DPRINT_ERR(STORVSC, "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", vstorPacket->Operation, vstorPacket->Status); + if (vstorPacket->Operation != VStorOperationCompleteIo + || vstorPacket->Status != 0) { + DPRINT_ERR(STORVSC, + "END_INITIALIZATION_OPERATION failed (op %d status 0x%x)", + vstorPacket->Operation, vstorPacket->Status); goto Cleanup; } DPRINT_INFO(STORVSC, "**** storage channel up and running!! ****"); Cleanup: - if (request->WaitEvent) - { + if (request->WaitEvent) { WaitEventClose(request->WaitEvent); request->WaitEvent = NULL; } @@ -526,33 +504,32 @@ Cleanup: return ret; } - -int -StorVscConnectToVsp( - struct hv_device *Device - ) +int StorVscConnectToVsp(struct hv_device *Device) { - int ret=0; - VMSTORAGE_CHANNEL_PROPERTIES props; + int ret = 0; + VMSTORAGE_CHANNEL_PROPERTIES props; - STORVSC_DRIVER_OBJECT *storDriver = (STORVSC_DRIVER_OBJECT*) Device->Driver;; + STORVSC_DRIVER_OBJECT *storDriver = + (STORVSC_DRIVER_OBJECT *) Device->Driver;; memset(&props, sizeof(VMSTORAGE_CHANNEL_PROPERTIES), 0); /* Open the channel */ ret = Device->Driver->VmbusChannelInterface.Open(Device, - storDriver->RingBufferSize, - storDriver->RingBufferSize, - (void *)&props, - sizeof(VMSTORAGE_CHANNEL_PROPERTIES), - StorVscOnChannelCallback, - Device - ); - - DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", props.PathId, props.TargetId, props.MaxTransferBytes); - - if (ret != 0) - { + storDriver-> + RingBufferSize, + storDriver-> + RingBufferSize, + (void *)&props, + sizeof + (VMSTORAGE_CHANNEL_PROPERTIES), + StorVscOnChannelCallback, + Device); + + DPRINT_DBG(STORVSC, "storage props: path id %d, tgt id %d, max xfer %d", + props.PathId, props.TargetId, props.MaxTransferBytes); + + if (ret != 0) { DPRINT_ERR(STORVSC, "unable to open channel: %d", ret); return -1; } @@ -562,7 +539,6 @@ StorVscConnectToVsp( return ret; } - /*++ Name: @@ -572,17 +548,15 @@ Description: Callback when the our device is being removed --*/ -int -StorVscOnDeviceRemove( - struct hv_device *Device - ) +int StorVscOnDeviceRemove(struct hv_device *Device) { STORVSC_DEVICE *storDevice; - int ret=0; + int ret = 0; DPRINT_ENTER(STORVSC); - DPRINT_INFO(STORVSC, "disabling storage device (%p)...", Device->Extension); + DPRINT_INFO(STORVSC, "disabling storage device (%p)...", + Device->Extension); storDevice = ReleaseStorDevice(Device); @@ -591,14 +565,15 @@ StorVscOnDeviceRemove( * only allow inbound traffic (responses) to proceed so that * outstanding requests can be completed. */ - while (storDevice->NumOutstandingRequests) - { - DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", storDevice->NumOutstandingRequests); + while (storDevice->NumOutstandingRequests) { + DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", + storDevice->NumOutstandingRequests); udelay(100); } - DPRINT_INFO(STORVSC, "removing storage device (%p)...", Device->Extension); + DPRINT_INFO(STORVSC, "removing storage device (%p)...", + Device->Extension); storDevice = FinalReleaseStorDevice(Device); @@ -631,12 +606,9 @@ DPRINT_EXIT(STORVSC); } *********** */ -int -StorVscOnHostReset( - struct hv_device *Device - ) +int StorVscOnHostReset(struct hv_device *Device) { - int ret=0; + int ret = 0; STORVSC_DEVICE *storDevice; STORVSC_REQUEST_EXTENSION *request; @@ -647,9 +619,9 @@ StorVscOnHostReset( DPRINT_INFO(STORVSC, "resetting host adapter..."); storDevice = GetStorDevice(Device); - if (!storDevice) - { - DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?"); + if (!storDevice) { + DPRINT_ERR(STORVSC, + "unable to get stor device...device being destroyed?"); DPRINT_EXIT(STORVSC); return -1; } @@ -659,19 +631,22 @@ StorVscOnHostReset( request->WaitEvent = WaitEventCreate(); - vstorPacket->Operation = VStorOperationResetBus; - vstorPacket->Flags = REQUEST_COMPLETION_FLAG; - vstorPacket->VmSrb.PathId = storDevice->PathId; + vstorPacket->Operation = VStorOperationResetBus; + vstorPacket->Flags = REQUEST_COMPLETION_FLAG; + vstorPacket->VmSrb.PathId = storDevice->PathId; ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)&storDevice->ResetRequest, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (ret != 0) - { - DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", vstorPacket, ret); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned long) + &storDevice-> + ResetRequest, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", + vstorPacket, ret); goto Cleanup; } @@ -701,30 +676,29 @@ Description: Callback to initiate an I/O request --*/ -int -StorVscOnIORequest( - struct hv_device *Device, - STORVSC_REQUEST *Request - ) +int StorVscOnIORequest(struct hv_device *Device, STORVSC_REQUEST * Request) { STORVSC_DEVICE *storDevice; - STORVSC_REQUEST_EXTENSION* requestExtension = (STORVSC_REQUEST_EXTENSION*) Request->Extension; - VSTOR_PACKET* vstorPacket =&requestExtension->VStorPacket; - int ret=0; + STORVSC_REQUEST_EXTENSION *requestExtension = + (STORVSC_REQUEST_EXTENSION *) Request->Extension; + VSTOR_PACKET *vstorPacket = &requestExtension->VStorPacket; + int ret = 0; DPRINT_ENTER(STORVSC); storDevice = GetStorDevice(Device); - DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, Extension %p", - Device, storDevice, Request, requestExtension); + DPRINT_DBG(STORVSC, + "enter - Device %p, DeviceExt %p, Request %p, Extension %p", + Device, storDevice, Request, requestExtension); DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", - Request, Request->DataBuffer.Length, Request->Bus, Request->TargetId, Request->LunId, Request->CdbLen); + Request, Request->DataBuffer.Length, Request->Bus, + Request->TargetId, Request->LunId, Request->CdbLen); - if (!storDevice) - { - DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?"); + if (!storDevice) { + DPRINT_ERR(STORVSC, + "unable to get stor device...device being destroyed?"); DPRINT_EXIT(STORVSC); return -2; } @@ -732,23 +706,23 @@ StorVscOnIORequest( /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, Request->Cdb, Request->CdbLen); */ requestExtension->Request = Request; - requestExtension->Device = Device; + requestExtension->Device = Device; - memset(vstorPacket, 0 , sizeof(VSTOR_PACKET)); + memset(vstorPacket, 0, sizeof(VSTOR_PACKET)); vstorPacket->Flags |= REQUEST_COMPLETION_FLAG; - vstorPacket->VmSrb.Length = sizeof(VMSCSI_REQUEST); + vstorPacket->VmSrb.Length = sizeof(VMSCSI_REQUEST); vstorPacket->VmSrb.PortNumber = Request->Host; - vstorPacket->VmSrb.PathId = Request->Bus; - vstorPacket->VmSrb.TargetId = Request->TargetId; - vstorPacket->VmSrb.Lun = Request->LunId; + vstorPacket->VmSrb.PathId = Request->Bus; + vstorPacket->VmSrb.TargetId = Request->TargetId; + vstorPacket->VmSrb.Lun = Request->LunId; vstorPacket->VmSrb.SenseInfoLength = SENSE_BUFFER_SIZE; /* Copy over the scsi command descriptor block */ - vstorPacket->VmSrb.CdbLength = Request->CdbLen; + vstorPacket->VmSrb.CdbLength = Request->CdbLen; memcpy(&vstorPacket->VmSrb.Cdb, Request->Cdb, Request->CdbLen); vstorPacket->VmSrb.DataIn = Request->Type; @@ -756,36 +730,36 @@ StorVscOnIORequest( vstorPacket->Operation = VStorOperationExecuteSRB; - DPRINT_DBG(STORVSC, "srb - len %d port %d, path %d, target %d, lun %d senselen %d cdblen %d", - vstorPacket->VmSrb.Length, - vstorPacket->VmSrb.PortNumber, - vstorPacket->VmSrb.PathId, - vstorPacket->VmSrb.TargetId, - vstorPacket->VmSrb.Lun, - vstorPacket->VmSrb.SenseInfoLength, - vstorPacket->VmSrb.CdbLength); - - if (requestExtension->Request->DataBuffer.Length) - { - ret = Device->Driver->VmbusChannelInterface.SendPacketMultiPageBuffer(Device, - &requestExtension->Request->DataBuffer, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)requestExtension); - } - else - { + DPRINT_DBG(STORVSC, + "srb - len %d port %d, path %d, target %d, lun %d senselen %d cdblen %d", + vstorPacket->VmSrb.Length, vstorPacket->VmSrb.PortNumber, + vstorPacket->VmSrb.PathId, vstorPacket->VmSrb.TargetId, + vstorPacket->VmSrb.Lun, vstorPacket->VmSrb.SenseInfoLength, + vstorPacket->VmSrb.CdbLength); + + if (requestExtension->Request->DataBuffer.Length) { + ret = + Device->Driver->VmbusChannelInterface. + SendPacketMultiPageBuffer(Device, + &requestExtension->Request-> + DataBuffer, vstorPacket, + sizeof(VSTOR_PACKET), + (unsigned long)requestExtension); + } else { ret = Device->Driver->VmbusChannelInterface.SendPacket(Device, - vstorPacket, - sizeof(VSTOR_PACKET), - (unsigned long)requestExtension, - VmbusPacketTypeDataInBand, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + vstorPacket, + sizeof + (VSTOR_PACKET), + (unsigned + long) + requestExtension, + VmbusPacketTypeDataInBand, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } - if (ret != 0) - { - DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", vstorPacket, ret); + if (ret != 0) { + DPRINT_DBG(STORVSC, "Unable to send packet %p ret %d", + vstorPacket, ret); } InterlockedIncrement(&storDevice->NumOutstandingRequests); @@ -805,22 +779,16 @@ Description: Perform any cleanup when the driver is removed --*/ -void -StorVscOnCleanup( - DRIVER_OBJECT *Driver - ) +void StorVscOnCleanup(DRIVER_OBJECT * Driver) { DPRINT_ENTER(STORVSC); DPRINT_EXIT(STORVSC); } - static void -StorVscOnIOCompletion( - struct hv_device *Device, - VSTOR_PACKET *VStorPacket, - STORVSC_REQUEST_EXTENSION *RequestExt - ) +StorVscOnIOCompletion(struct hv_device *Device, + VSTOR_PACKET * VStorPacket, + STORVSC_REQUEST_EXTENSION * RequestExt) { STORVSC_REQUEST *request; STORVSC_DEVICE *storDevice; @@ -828,15 +796,16 @@ StorVscOnIOCompletion( DPRINT_ENTER(STORVSC); storDevice = MustGetStorDevice(Device); - if (!storDevice) - { - DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?"); + if (!storDevice) { + DPRINT_ERR(STORVSC, + "unable to get stor device...device being destroyed?"); DPRINT_EXIT(STORVSC); return; } - DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u", - RequestExt, VStorPacket->VmSrb.DataTransferLength); + DPRINT_DBG(STORVSC, + "IO_COMPLETE_OPERATION - request extension %p completed bytes xfer %u", + RequestExt, VStorPacket->VmSrb.DataTransferLength); ASSERT(RequestExt != NULL); ASSERT(RequestExt->Request != NULL); @@ -848,27 +817,28 @@ StorVscOnIOCompletion( /* Copy over the status...etc */ request->Status = VStorPacket->VmSrb.ScsiStatus; - if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) - { - DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n", - request->Cdb[0], - VStorPacket->VmSrb.ScsiStatus, - VStorPacket->VmSrb.SrbStatus); + if (request->Status != 0 || VStorPacket->VmSrb.SrbStatus != 1) { + DPRINT_WARN(STORVSC, + "cmd 0x%x scsi status 0x%x srb status 0x%x\n", + request->Cdb[0], VStorPacket->VmSrb.ScsiStatus, + VStorPacket->VmSrb.SrbStatus); } - if ((request->Status & 0xFF) == 0x02) /* CHECK_CONDITION */ - { - if (VStorPacket->VmSrb.SrbStatus & 0x80) /* autosense data available */ - { - DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data valid - len %d\n", - RequestExt, VStorPacket->VmSrb.SenseInfoLength); + if ((request->Status & 0xFF) == 0x02) { /* CHECK_CONDITION */ + if (VStorPacket->VmSrb.SrbStatus & 0x80) { /* autosense data available */ + DPRINT_WARN(STORVSC, + "storvsc pkt %p autosense data valid - len %d\n", + RequestExt, + VStorPacket->VmSrb.SenseInfoLength); - ASSERT(VStorPacket->VmSrb.SenseInfoLength <= request->SenseBufferSize); + ASSERT(VStorPacket->VmSrb.SenseInfoLength <= + request->SenseBufferSize); memcpy(request->SenseBuffer, - VStorPacket->VmSrb.SenseData, - VStorPacket->VmSrb.SenseInfoLength); + VStorPacket->VmSrb.SenseData, + VStorPacket->VmSrb.SenseInfoLength); - request->SenseBufferSize = VStorPacket->VmSrb.SenseInfoLength; + request->SenseBufferSize = + VStorPacket->VmSrb.SenseInfoLength; } } @@ -884,21 +854,17 @@ StorVscOnIOCompletion( DPRINT_EXIT(STORVSC); } - static void -StorVscOnReceive( - struct hv_device *Device, - VSTOR_PACKET *VStorPacket, - STORVSC_REQUEST_EXTENSION *RequestExt - ) +StorVscOnReceive(struct hv_device *Device, + VSTOR_PACKET * VStorPacket, + STORVSC_REQUEST_EXTENSION * RequestExt) { - switch(VStorPacket->Operation) - { - case VStorOperationCompleteIo: + switch (VStorPacket->Operation) { + case VStorOperationCompleteIo: - DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); - StorVscOnIOCompletion(Device, VStorPacket, RequestExt); - break; + DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); + StorVscOnIOCompletion(Device, VStorPacket, RequestExt); + break; /* case ENUMERATE_DEVICE_OPERATION: */ @@ -909,27 +875,25 @@ StorVscOnReceive( case VStorOperationRemoveDevice: - DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); - /* TODO: */ - break; + DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); + /* TODO: */ + break; - default: - DPRINT_INFO(STORVSC, "Unknown operation received - %d", VStorPacket->Operation); - break; + default: + DPRINT_INFO(STORVSC, "Unknown operation received - %d", + VStorPacket->Operation); + break; } } -void -StorVscOnChannelCallback( - void * Context - ) +void StorVscOnChannelCallback(void *Context) { - int ret=0; - struct hv_device *device = (struct hv_device*)Context; + int ret = 0; + struct hv_device *device = (struct hv_device *)Context; STORVSC_DEVICE *storDevice; u32 bytesRecvd; u64 requestId; - unsigned char packet[ALIGN_UP(sizeof(VSTOR_PACKET),8)]; + unsigned char packet[ALIGN_UP(sizeof(VSTOR_PACKET), 8)]; STORVSC_REQUEST_EXTENSION *request; DPRINT_ENTER(STORVSC); @@ -937,45 +901,48 @@ StorVscOnChannelCallback( ASSERT(device); storDevice = MustGetStorDevice(device); - if (!storDevice) - { - DPRINT_ERR(STORVSC, "unable to get stor device...device being destroyed?"); + if (!storDevice) { + DPRINT_ERR(STORVSC, + "unable to get stor device...device being destroyed?"); DPRINT_EXIT(STORVSC); return; } - do - { + do { ret = device->Driver->VmbusChannelInterface.RecvPacket(device, - packet, - ALIGN_UP(sizeof(VSTOR_PACKET),8), - &bytesRecvd, - &requestId); - if (ret == 0 && bytesRecvd > 0) - { - DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytesRecvd, requestId); + packet, + ALIGN_UP + (sizeof + (VSTOR_PACKET), + 8), + &bytesRecvd, + &requestId); + if (ret == 0 && bytesRecvd > 0) { + DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", + bytesRecvd, requestId); /* ASSERT(bytesRecvd == sizeof(VSTOR_PACKET)); */ - request = (STORVSC_REQUEST_EXTENSION*)(unsigned long)requestId; + request = + (STORVSC_REQUEST_EXTENSION *) (unsigned long) + requestId; ASSERT(request); /* if (vstorPacket.Flags & SYNTHETIC_FLAG) */ - if ((request == &storDevice->InitRequest) || (request == &storDevice->ResetRequest)) - { + if ((request == &storDevice->InitRequest) + || (request == &storDevice->ResetRequest)) { /* DPRINT_INFO(STORVSC, "reset completion - operation %u status %u", vstorPacket.Operation, vstorPacket.Status); */ - memcpy(&request->VStorPacket, packet, sizeof(VSTOR_PACKET)); + memcpy(&request->VStorPacket, packet, + sizeof(VSTOR_PACKET)); WaitEventSet(request->WaitEvent); + } else { + StorVscOnReceive(device, + (VSTOR_PACKET *) packet, + request); } - else - { - StorVscOnReceive(device, (VSTOR_PACKET*)packet, request); - } - } - else - { + } else { /* DPRINT_DBG(STORVSC, "nothing else to read..."); */ break; } diff --git a/drivers/staging/hv/VersionInfo.h b/drivers/staging/hv/VersionInfo.h index a827f7f..1b1a1f5 100644 --- a/drivers/staging/hv/VersionInfo.h +++ b/drivers/staging/hv/VersionInfo.h @@ -21,9 +21,8 @@ * */ - #pragma once -const char VersionDate[]=__DATE__; -const char VersionTime[]=__TIME__; -const char VersionDesc[]= "Version 2.0"; +const char VersionDate[] = __DATE__; +const char VersionTime[] = __TIME__; +const char VersionDesc[] = "Version 2.0"; diff --git a/drivers/staging/hv/Vmbus.c b/drivers/staging/hv/Vmbus.c index f6be5b5..26c93db 100644 --- a/drivers/staging/hv/Vmbus.c +++ b/drivers/staging/hv/Vmbus.c @@ -27,78 +27,51 @@ #include "VersionInfo.h" #include "VmbusPrivate.h" - /* Globals */ -static const char* gDriverName="vmbus"; +static const char *gDriverName = "vmbus"; /* Windows vmbus does not defined this. * We defined this to be consistent with other devices */ /* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */ -static const GUID gVmbusDeviceType={ - .Data = {0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85} +static const GUID gVmbusDeviceType = { + .Data = + {0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, 0x8d, 0x1a, 0x4d, + 0xaf, 0x99, 0x9c, 0xa1, 0x85} }; /* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */ -static const GUID gVmbusDeviceId={ - .Data = {0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5} +static const GUID gVmbusDeviceId = { + .Data = + {0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, 0x94, 0x27, 0xa7, + 0x0e, 0xd6, 0xde, 0x95, 0xc5} }; -static DRIVER_OBJECT* gDriver; /* vmbus driver object */ -static struct hv_device* gDevice; /* vmbus root device */ - - +static DRIVER_OBJECT *gDriver; /* vmbus driver object */ +static struct hv_device *gDevice; /* vmbus root device */ /* Internal routines */ +static void VmbusGetChannelInterface(VMBUS_CHANNEL_INTERFACE * Interface); static void -VmbusGetChannelInterface( - VMBUS_CHANNEL_INTERFACE *Interface - ); +VmbusGetChannelInfo(struct hv_device *DeviceObject, DEVICE_INFO * DeviceInfo); -static void -VmbusGetChannelInfo( - struct hv_device *DeviceObject, - DEVICE_INFO *DeviceInfo - ); +static void VmbusGetChannelOffers(void + ); -static void -VmbusGetChannelOffers( - void - ); - -static int -VmbusOnDeviceAdd( - struct hv_device *Device, - void *AdditionalInfo - ); +static int VmbusOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo); -static int -VmbusOnDeviceRemove( - struct hv_device *dev - ); +static int VmbusOnDeviceRemove(struct hv_device *dev); -static void -VmbusOnCleanup( - DRIVER_OBJECT* drv - ); +static void VmbusOnCleanup(DRIVER_OBJECT * drv); -static int -VmbusOnISR( - DRIVER_OBJECT* drv - ); +static int VmbusOnISR(DRIVER_OBJECT * drv); -static void -VmbusOnMsgDPC( - DRIVER_OBJECT* drv - ); +static void VmbusOnMsgDPC(DRIVER_OBJECT * drv); -static void -VmbusOnEventDPC( - DRIVER_OBJECT* drv - ); +static void VmbusOnEventDPC(DRIVER_OBJECT * drv); /*++; @@ -109,44 +82,46 @@ Description: Main entry point --*/ -int -VmbusInitialize( - DRIVER_OBJECT* drv - ) +int VmbusInitialize(DRIVER_OBJECT * drv) { - VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv; - int ret=0; + VMBUS_DRIVER_OBJECT *driver = (VMBUS_DRIVER_OBJECT *) drv; + int ret = 0; DPRINT_ENTER(VMBUS); - DPRINT_INFO(VMBUS, "+++++++ Build Date=%s %s +++++++", VersionDate, VersionTime); + DPRINT_INFO(VMBUS, "+++++++ Build Date=%s %s +++++++", VersionDate, + VersionTime); DPRINT_INFO(VMBUS, "+++++++ Build Description=%s +++++++", VersionDesc); - DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", VMBUS_REVISION_NUMBER); - DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", VMBUS_MESSAGE_SINT); + DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", + VMBUS_REVISION_NUMBER); + DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", + VMBUS_MESSAGE_SINT); - DPRINT_DBG(VMBUS, "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%zd, sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd", - sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER), sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)); + DPRINT_DBG(VMBUS, + "sizeof(VMBUS_CHANNEL_PACKET_PAGE_BUFFER)=%zd, sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd", + sizeof(struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER), + sizeof(struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)); drv->name = gDriverName; memcpy(&drv->deviceType, &gVmbusDeviceType, sizeof(GUID)); /* Setup dispatch table */ - driver->Base.OnDeviceAdd = VmbusOnDeviceAdd; - driver->Base.OnDeviceRemove = VmbusOnDeviceRemove; - driver->Base.OnCleanup = VmbusOnCleanup; - driver->OnIsr = VmbusOnISR; - driver->OnMsgDpc = VmbusOnMsgDPC; - driver->OnEventDpc = VmbusOnEventDPC; - driver->GetChannelOffers = VmbusGetChannelOffers; - driver->GetChannelInterface = VmbusGetChannelInterface; - driver->GetChannelInfo = VmbusGetChannelInfo; + driver->Base.OnDeviceAdd = VmbusOnDeviceAdd; + driver->Base.OnDeviceRemove = VmbusOnDeviceRemove; + driver->Base.OnCleanup = VmbusOnCleanup; + driver->OnIsr = VmbusOnISR; + driver->OnMsgDpc = VmbusOnMsgDPC; + driver->OnEventDpc = VmbusOnEventDPC; + driver->GetChannelOffers = VmbusGetChannelOffers; + driver->GetChannelInterface = VmbusGetChannelInterface; + driver->GetChannelInfo = VmbusGetChannelInfo; /* Hypervisor initialization...setup hypercall page..etc */ ret = HvInit(); - if (ret != 0) - { - DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", ret); + if (ret != 0) { + DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", + ret); } gDriver = drv; @@ -156,7 +131,6 @@ VmbusInitialize( return ret; } - /*++; Name: @@ -167,15 +141,13 @@ Description: --*/ -static void -VmbusGetChannelOffers(void) +static void VmbusGetChannelOffers(void) { DPRINT_ENTER(VMBUS); VmbusChannelRequestOffers(); DPRINT_EXIT(VMBUS); } - /*++; Name: @@ -185,15 +157,11 @@ Description: Get the channel interface --*/ -static void -VmbusGetChannelInterface( - VMBUS_CHANNEL_INTERFACE *Interface - ) +static void VmbusGetChannelInterface(VMBUS_CHANNEL_INTERFACE * Interface) { GetChannelInterface(Interface); } - /*++; Name: @@ -204,16 +172,11 @@ Description: --*/ static void -VmbusGetChannelInfo( - struct hv_device *DeviceObject, - DEVICE_INFO *DeviceInfo - ) +VmbusGetChannelInfo(struct hv_device *DeviceObject, DEVICE_INFO * DeviceInfo) { GetChannelInfo(DeviceObject, DeviceInfo); } - - /*++ Name: @@ -224,21 +187,15 @@ Description: --*/ -struct hv_device* -VmbusChildDeviceCreate( - GUID DeviceType, - GUID DeviceInstance, - void *Context) +struct hv_device *VmbusChildDeviceCreate(GUID DeviceType, + GUID DeviceInstance, void *Context) { - VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver; + VMBUS_DRIVER_OBJECT *vmbusDriver = (VMBUS_DRIVER_OBJECT *) gDriver; - return vmbusDriver->OnChildDeviceCreate( - DeviceType, - DeviceInstance, - Context); + return vmbusDriver->OnChildDeviceCreate(DeviceType, + DeviceInstance, Context); } - /*++ Name: @@ -248,16 +205,13 @@ Description: Registers the child device with the vmbus --*/ -int -VmbusChildDeviceAdd( - struct hv_device *ChildDevice) +int VmbusChildDeviceAdd(struct hv_device *ChildDevice) { - VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver; + VMBUS_DRIVER_OBJECT *vmbusDriver = (VMBUS_DRIVER_OBJECT *) gDriver; return vmbusDriver->OnChildDeviceAdd(gDevice, ChildDevice); } - /*++ Name: @@ -267,11 +221,9 @@ Description: Unregisters the child device from the vmbus --*/ -void -VmbusChildDeviceRemove( - struct hv_device *ChildDevice) +void VmbusChildDeviceRemove(struct hv_device *ChildDevice) { - VMBUS_DRIVER_OBJECT* vmbusDriver = (VMBUS_DRIVER_OBJECT*)gDriver; + VMBUS_DRIVER_OBJECT *vmbusDriver = (VMBUS_DRIVER_OBJECT *) gDriver; vmbusDriver->OnChildDeviceRemove(ChildDevice); } @@ -307,14 +259,10 @@ Description: Callback when the root bus device is added --*/ -static int -VmbusOnDeviceAdd( - struct hv_device *dev, - void *AdditionalInfo - ) +static int VmbusOnDeviceAdd(struct hv_device *dev, void *AdditionalInfo) { - u32 *irqvector = (u32*) AdditionalInfo; - int ret=0; + u32 *irqvector = (u32 *) AdditionalInfo; + int ret = 0; DPRINT_ENTER(VMBUS); @@ -336,7 +284,6 @@ VmbusOnDeviceAdd( return ret; } - /*++ Name: @@ -346,11 +293,9 @@ Description: Callback when the root bus device is removed --*/ -int VmbusOnDeviceRemove( - struct hv_device *dev - ) +int VmbusOnDeviceRemove(struct hv_device *dev) { - int ret=0; + int ret = 0; DPRINT_ENTER(VMBUS); @@ -365,7 +310,6 @@ int VmbusOnDeviceRemove( return ret; } - /*++ Name: @@ -375,10 +319,7 @@ Description: Perform any cleanup when the driver is removed --*/ -void -VmbusOnCleanup( - DRIVER_OBJECT* drv - ) +void VmbusOnCleanup(DRIVER_OBJECT * drv) { /* VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv; */ @@ -389,7 +330,6 @@ VmbusOnCleanup( DPRINT_EXIT(VMBUS); } - /*++ Name: @@ -399,31 +339,25 @@ Description: DPC routine to handle messages from the hypervisior --*/ -void -VmbusOnMsgDPC( - DRIVER_OBJECT* drv - ) +void VmbusOnMsgDPC(DRIVER_OBJECT * drv) { void *page_addr = gHvContext.synICMessagePage[0]; - HV_MESSAGE* msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT; + HV_MESSAGE *msg = (HV_MESSAGE *) page_addr + VMBUS_MESSAGE_SINT; HV_MESSAGE *copied; - while (1) - { - if (msg->Header.MessageType == HvMessageTypeNone) /* no msg */ - { + while (1) { + if (msg->Header.MessageType == HvMessageTypeNone) { /* no msg */ break; - } - else - { + } else { copied = kmalloc(sizeof(HV_MESSAGE), GFP_ATOMIC); - if (copied == NULL) - { + if (copied == NULL) { continue; } memcpy(copied, msg, sizeof(HV_MESSAGE)); - WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, VmbusOnChannelMessage, (void*)copied); + WorkQueueQueueWorkItem(gVmbusConnection.WorkQueue, + VmbusOnChannelMessage, + (void *)copied); } msg->Header.MessageType = HvMessageTypeNone; @@ -437,8 +371,7 @@ VmbusOnMsgDPC( */ mb(); - if (msg->Header.MessageFlags.MessagePending) - { + if (msg->Header.MessageFlags.MessagePending) { /* * This will cause message queue rescan to * possibly deliver another msg from the @@ -458,16 +391,12 @@ Description: DPC routine to handle events from the hypervisior --*/ -void -VmbusOnEventDPC( - DRIVER_OBJECT* drv - ) +void VmbusOnEventDPC(DRIVER_OBJECT * drv) { /* TODO: Process any events */ VmbusOnEvents(); } - /*++ Name: @@ -477,40 +406,36 @@ Description: ISR routine --*/ -int -VmbusOnISR( - DRIVER_OBJECT* drv - ) +int VmbusOnISR(DRIVER_OBJECT * drv) { /* VMBUS_DRIVER_OBJECT* driver = (VMBUS_DRIVER_OBJECT*)drv; */ - int ret=0; + int ret = 0; /* struct page* page; */ void *page_addr; - HV_MESSAGE* msg; - HV_SYNIC_EVENT_FLAGS* event; + HV_MESSAGE *msg; + HV_SYNIC_EVENT_FLAGS *event; /* page = SynICMessagePage[0]; */ /* page_addr = page_address(page); */ page_addr = gHvContext.synICMessagePage[0]; - msg = (HV_MESSAGE*)page_addr + VMBUS_MESSAGE_SINT; + msg = (HV_MESSAGE *) page_addr + VMBUS_MESSAGE_SINT; DPRINT_ENTER(VMBUS); /* Check if there are actual msgs to be process */ - if (msg->Header.MessageType != HvMessageTypeNone) - { - DPRINT_DBG(VMBUS, "received msg type %d size %d", msg->Header.MessageType, msg->Header.PayloadSize); + if (msg->Header.MessageType != HvMessageTypeNone) { + DPRINT_DBG(VMBUS, "received msg type %d size %d", + msg->Header.MessageType, msg->Header.PayloadSize); ret |= 0x1; - } + } /* TODO: Check if there are events to be process */ page_addr = gHvContext.synICEventPage[0]; - event = (HV_SYNIC_EVENT_FLAGS*)page_addr + VMBUS_MESSAGE_SINT; + event = (HV_SYNIC_EVENT_FLAGS *) page_addr + VMBUS_MESSAGE_SINT; /* Since we are a child, we only need to check bit 0 */ - if (BitTestAndClear(&event->Flags32[0], 0)) - { + if (BitTestAndClear(&event->Flags32[0], 0)) { DPRINT_DBG(VMBUS, "received event %d", event->Flags32[0]); ret |= 0x2; } diff --git a/drivers/staging/hv/VmbusPrivate.h b/drivers/staging/hv/VmbusPrivate.h index bf47408..b73922d 100644 --- a/drivers/staging/hv/VmbusPrivate.h +++ b/drivers/staging/hv/VmbusPrivate.h @@ -21,7 +21,6 @@ * */ - #ifndef _VMBUS_PRIVATE_H_ #define _VMBUS_PRIVATE_H_ @@ -35,25 +34,21 @@ /* #include "Packet.h" */ #include "include/List.h" - /* Defines */ - /* * Maximum channels is determined by the size of the interrupt page * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt * and the other is receive endpoint interrupt */ -#define MAX_NUM_CHANNELS (PAGE_SIZE >> 1) << 3 /* 16348 channels */ +#define MAX_NUM_CHANNELS (PAGE_SIZE >> 1) << 3 /* 16348 channels */ /* The value here must be in multiple of 32 */ /* TODO: Need to make this configurable */ #define MAX_NUM_CHANNELS_SUPPORTED 256 - /* Data types */ - enum VMBUS_CONNECT_STATE { Disconnected, Connecting, @@ -65,109 +60,81 @@ enum VMBUS_CONNECT_STATE { struct VMBUS_CONNECTION { - enum VMBUS_CONNECT_STATE ConnectState; + enum VMBUS_CONNECT_STATE ConnectState; - u32 NextGpadlHandle; + u32 NextGpadlHandle; /* * Represents channel interrupts. Each bit position represents - * a channel. When a channel sends an interrupt via VMBUS, it - * finds its bit in the sendInterruptPage, set it and calls Hv - * to generate a port event. The other end receives the port - * event and parse the recvInterruptPage to see which bit is - * set + * a channel. When a channel sends an interrupt via VMBUS, it + * finds its bit in the sendInterruptPage, set it and calls Hv + * to generate a port event. The other end receives the port + * event and parse the recvInterruptPage to see which bit is + * set */ - void * InterruptPage; - void * SendInterruptPage; - void * RecvInterruptPage; + void *InterruptPage; + void *SendInterruptPage; + void *RecvInterruptPage; /* * 2 pages - 1st page for parent->child notification and 2nd * is child->parent notification */ - void * MonitorPages; - LIST_ENTRY ChannelMsgList; + void *MonitorPages; + LIST_ENTRY ChannelMsgList; spinlock_t channelmsg_lock; /* List of channels */ - LIST_ENTRY ChannelList; + LIST_ENTRY ChannelList; spinlock_t channel_lock; struct workqueue_struct *WorkQueue; }; - struct VMBUS_MSGINFO { /* Bookkeeping stuff */ - LIST_ENTRY MsgListEntry; + LIST_ENTRY MsgListEntry; /* Synchronize the request/response if needed */ struct osd_waitevent *WaitEvent; /* The message itself */ - unsigned char Msg[0]; + unsigned char Msg[0]; }; - - /* Externs */ extern struct VMBUS_CONNECTION gVmbusConnection; - /* General vmbus interface */ -static struct hv_device* -VmbusChildDeviceCreate( - GUID deviceType, - GUID deviceInstance, - void *context); +static struct hv_device *VmbusChildDeviceCreate(GUID deviceType, + GUID deviceInstance, + void *context); -static int -VmbusChildDeviceAdd( - struct hv_device *Device); +static int VmbusChildDeviceAdd(struct hv_device *Device); -static void -VmbusChildDeviceRemove( - struct hv_device *Device); +static void VmbusChildDeviceRemove(struct hv_device *Device); /* static void */ /* VmbusChildDeviceDestroy( */ /* struct hv_device *); */ -static VMBUS_CHANNEL* -GetChannelFromRelId( - u32 relId - ); - +static VMBUS_CHANNEL *GetChannelFromRelId(u32 relId); /* Connection interface */ -static int -VmbusConnect( - void - ); - -static int -VmbusDisconnect( - void - ); +static int VmbusConnect(void + ); -static int -VmbusPostMessage( - void * buffer, - size_t bufSize - ); +static int VmbusDisconnect(void + ); -static int -VmbusSetEvent( - u32 childRelId - ); +static int VmbusPostMessage(void *buffer, size_t bufSize); -static void -VmbusOnEvents( - void - ); +static int VmbusSetEvent(u32 childRelId); +static void VmbusOnEvents(void + ); #endif /* _VMBUS_PRIVATE_H_ */ diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c index c5f3ce9..efce2c9 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -38,12 +38,10 @@ #include "include/StorVscApi.h" - /* #defines */ #define BLKVSC_MINORS 64 - /* Data types */ enum blkvsc_device_type { @@ -58,65 +56,64 @@ enum blkvsc_device_type { * represented by 1 or more struct blkvsc_request */ struct blkvsc_request_group { - int outstanding; - int status; + int outstanding; + int status; - struct list_head blkvsc_req_list; /* list of blkvsc_requests */ + struct list_head blkvsc_req_list; /* list of blkvsc_requests */ }; - struct blkvsc_request { - struct list_head req_entry; /* blkvsc_request_group.blkvsc_req_list */ + struct list_head req_entry; /* blkvsc_request_group.blkvsc_req_list */ - struct list_head pend_entry; /* block_device_context.pending_list */ + struct list_head pend_entry; /* block_device_context.pending_list */ - struct request *req; /* This may be null if we generate a request internally */ - struct block_device_context *dev; - struct blkvsc_request_group *group; /* The group this request is part of. Maybe null */ + struct request *req; /* This may be null if we generate a request internally */ + struct block_device_context *dev; + struct blkvsc_request_group *group; /* The group this request is part of. Maybe null */ - wait_queue_head_t wevent; + wait_queue_head_t wevent; int cond; - int write; - sector_t sector_start; - unsigned long sector_count; + int write; + sector_t sector_start; + unsigned long sector_count; unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; unsigned char cmd_len; unsigned char cmnd[MAX_COMMAND_SIZE]; - STORVSC_REQUEST request; + STORVSC_REQUEST request; /* !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap, because - */ /* The extension buffer falls right here and is pointed to by request.Extension; */ }; /* Per device structure */ struct block_device_context { - struct device_context *device_ctx; /* point back to our device context */ - struct kmem_cache *request_pool; - spinlock_t lock; - struct gendisk *gd; - enum blkvsc_device_type device_type; - struct list_head pending_list; - - unsigned char device_id[64]; - unsigned int device_id_len; - int num_outstanding_reqs; - int shutting_down; - int media_not_present; - unsigned int sector_size; - sector_t capacity; - unsigned int port; - unsigned char path; - unsigned char target; - int users; + struct device_context *device_ctx; /* point back to our device context */ + struct kmem_cache *request_pool; + spinlock_t lock; + struct gendisk *gd; + enum blkvsc_device_type device_type; + struct list_head pending_list; + + unsigned char device_id[64]; + unsigned int device_id_len; + int num_outstanding_reqs; + int shutting_down; + int media_not_present; + unsigned int sector_size; + sector_t capacity; + unsigned int port; + unsigned char path; + unsigned char target; + int users; }; /* Per driver */ struct blkvsc_driver_context { /* !! These must be the first 2 fields !! */ - struct driver_context drv_ctx; - STORVSC_DRIVER_OBJECT drv_obj; + struct driver_context drv_ctx; + STORVSC_DRIVER_OBJECT drv_obj; }; /* Static decl */ @@ -124,7 +121,7 @@ static int blkvsc_probe(struct device *dev); static int blkvsc_remove(struct device *device); static void blkvsc_shutdown(struct device *device); -static int blkvsc_open(struct block_device *bdev, fmode_t mode); +static int blkvsc_open(struct block_device *bdev, fmode_t mode); static int blkvsc_release(struct gendisk *disk, fmode_t mode); static int blkvsc_media_changed(struct gendisk *gd); static int blkvsc_revalidate_disk(struct gendisk *gd); @@ -132,11 +129,14 @@ static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg); static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, unsigned cmd, unsigned long argument); static void blkvsc_request(struct request_queue *queue); -static void blkvsc_request_completion(STORVSC_REQUEST* request); -static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req); -static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(STORVSC_REQUEST*) ); +static void blkvsc_request_completion(STORVSC_REQUEST * request); +static int blkvsc_do_request(struct block_device_context *blkdev, + struct request *req); +static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, + void (*request_completion) (STORVSC_REQUEST + *)); static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req); -static void blkvsc_cmd_completion(STORVSC_REQUEST* request); +static void blkvsc_cmd_completion(STORVSC_REQUEST * request); static int blkvsc_do_inquiry(struct block_device_context *blkdev); static int blkvsc_do_read_capacity(struct block_device_context *blkdev); static int blkvsc_do_read_capacity16(struct block_device_context *blkdev); @@ -144,22 +144,19 @@ static int blkvsc_do_flush(struct block_device_context *blkdev); static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev); static int blkvsc_do_pending_reqs(struct block_device_context *blkdev); - static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE; /* The one and only one */ static struct blkvsc_driver_context g_blkvsc_drv; - -static struct block_device_operations block_ops = -{ +static struct block_device_operations block_ops = { .owner = THIS_MODULE, .open = blkvsc_open, .release = blkvsc_release, .media_changed = blkvsc_media_changed, .revalidate_disk = blkvsc_revalidate_disk, .getgeo = blkvsc_getgeo, - .ioctl = blkvsc_ioctl, + .ioctl = blkvsc_ioctl, }; /*++ @@ -171,9 +168,9 @@ Desc: BlkVsc driver initialization. --*/ int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) { - int ret=0; - STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx; + int ret = 0; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &g_blkvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; DPRINT_ENTER(BLKVSC_DRV); @@ -185,7 +182,8 @@ int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) pfn_drv_init(&storvsc_drv_obj->Base); drv_ctx->driver.name = storvsc_drv_obj->Base.name; - memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(GUID)); + memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, + sizeof(GUID)); drv_ctx->probe = blkvsc_probe; drv_ctx->remove = blkvsc_remove; @@ -199,12 +197,11 @@ int blkvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) return ret; } - static int blkvsc_drv_exit_cb(struct device *dev, void *data) { struct device **curr = (struct device **)data; *curr = dev; - return 1; /* stop iterating */ + return 1; /* stop iterating */ } /*++ @@ -216,27 +213,25 @@ Desc: --*/ void blkvsc_drv_exit(void) { - STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_blkvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_blkvsc_drv.drv_ctx; - struct device *current_dev=NULL; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &g_blkvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; + struct device *current_dev = NULL; int ret; DPRINT_ENTER(BLKVSC_DRV); - while (1) - { + while (1) { current_dev = NULL; /* Get the device */ ret = driver_for_each_device(&drv_ctx->driver, NULL, - (void *) ¤t_dev, + (void *)¤t_dev, blkvsc_drv_exit_cb); if (ret) DPRINT_WARN(BLKVSC_DRV, "driver_for_each_device returned %d", ret); - if (current_dev == NULL) break; @@ -263,29 +258,30 @@ Desc: Add a new device for this driver --*/ static int blkvsc_probe(struct device *device) { - int ret=0; + int ret = 0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct blkvsc_driver_context *blkvsc_drv_ctx = + (struct blkvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); struct hv_device *device_obj = &device_ctx->device_obj; - struct block_device_context *blkdev=NULL; + struct block_device_context *blkdev = NULL; STORVSC_DEVICE_INFO device_info; - int major=0; - int devnum=0; + int major = 0; + int devnum = 0; - static int ide0_registered=0; - static int ide1_registered=0; + static int ide0_registered = 0; + static int ide1_registered = 0; DPRINT_ENTER(BLKVSC_DRV); DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter"); - if (!storvsc_drv_obj->Base.OnDeviceAdd) - { + if (!storvsc_drv_obj->Base.OnDeviceAdd) { DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set"); ret = -1; @@ -293,8 +289,7 @@ static int blkvsc_probe(struct device *device) } blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL); - if (!blkdev) - { + if (!blkdev) { ret = -ENOMEM; goto Cleanup; } @@ -304,70 +299,65 @@ static int blkvsc_probe(struct device *device) /* Initialize what we can here */ spin_lock_init(&blkdev->lock); - ASSERT(sizeof(struct blkvsc_request_group) <= sizeof(struct blkvsc_request)); + ASSERT(sizeof(struct blkvsc_request_group) <= + sizeof(struct blkvsc_request)); blkdev->request_pool = kmem_cache_create(dev_name(&device_ctx->device), - sizeof(struct blkvsc_request) + storvsc_drv_obj->RequestExtSize, 0, - SLAB_HWCACHE_ALIGN, NULL); - if (!blkdev->request_pool) - { + sizeof(struct blkvsc_request) + + storvsc_drv_obj-> + RequestExtSize, 0, + SLAB_HWCACHE_ALIGN, NULL); + if (!blkdev->request_pool) { ret = -ENOMEM; goto Cleanup; } - /* Call to the vsc driver to add the device */ ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, &device_info); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device"); goto Cleanup; } blkdev->device_ctx = device_ctx; - blkdev->target = device_info.TargetId; /* this identified the device 0 or 1 */ - blkdev->path = device_info.PathId; /* this identified the ide ctrl 0 or 1 */ + blkdev->target = device_info.TargetId; /* this identified the device 0 or 1 */ + blkdev->path = device_info.PathId; /* this identified the ide ctrl 0 or 1 */ dev_set_drvdata(device, blkdev); /* Calculate the major and device num */ - if (blkdev->path == 0) - { + if (blkdev->path == 0) { major = IDE0_MAJOR; - devnum = blkdev->path + blkdev->target; /* 0 or 1 */ + devnum = blkdev->path + blkdev->target; /* 0 or 1 */ - if (!ide0_registered) - { + if (!ide0_registered) { ret = register_blkdev(major, "ide"); - if (ret != 0) - { - DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret); + if (ret != 0) { + DPRINT_ERR(BLKVSC_DRV, + "register_blkdev() failed! ret %d", + ret); goto Remove; } ide0_registered = 1; } - } - else if (blkdev->path == 1) - { + } else if (blkdev->path == 1) { major = IDE1_MAJOR; - devnum = blkdev->path + blkdev->target + 1; /* 2 or 3 */ + devnum = blkdev->path + blkdev->target + 1; /* 2 or 3 */ - if (!ide1_registered) - { + if (!ide1_registered) { ret = register_blkdev(major, "ide"); - if (ret != 0) - { - DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret); + if (ret != 0) { + DPRINT_ERR(BLKVSC_DRV, + "register_blkdev() failed! ret %d", + ret); goto Remove; } ide1_registered = 1; } - } - else - { + } else { DPRINT_ERR(BLKVSC_DRV, "invalid pathid"); ret = -1; goto Cleanup; @@ -376,8 +366,7 @@ static int blkvsc_probe(struct device *device) DPRINT_INFO(BLKVSC_DRV, "blkvsc registered for major %d!!", major); blkdev->gd = alloc_disk(BLKVSC_MINORS); - if (!blkdev->gd) - { + if (!blkdev->gd) { DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret); ret = -1; goto Cleanup; @@ -386,9 +375,11 @@ static int blkvsc_probe(struct device *device) blkdev->gd->queue = blk_init_queue(blkvsc_request, &blkdev->lock); blk_queue_max_segment_size(blkdev->gd->queue, PAGE_SIZE); - blk_queue_max_phys_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT); - blk_queue_max_hw_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT); - blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE-1); + blk_queue_max_phys_segments(blkdev->gd->queue, + MAX_MULTIPAGE_BUFFER_COUNT); + blk_queue_max_hw_segments(blkdev->gd->queue, + MAX_MULTIPAGE_BUFFER_COUNT); + blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE - 1); blk_queue_bounce_limit(blkdev->gd->queue, BLK_BOUNCE_ANY); blk_queue_dma_alignment(blkdev->gd->queue, 511); @@ -399,26 +390,26 @@ static int blkvsc_probe(struct device *device) blkdev->gd->first_minor = 0; blkdev->gd->fops = &block_ops; blkdev->gd->private_data = blkdev; - sprintf(blkdev->gd->disk_name, "hd%c", 'a'+ devnum); + sprintf(blkdev->gd->disk_name, "hd%c", 'a' + devnum); blkvsc_do_inquiry(blkdev); - if (blkdev->device_type == DVD_TYPE) - { + if (blkdev->device_type == DVD_TYPE) { set_disk_ro(blkdev->gd, 1); blkdev->gd->flags |= GENHD_FL_REMOVABLE; blkvsc_do_read_capacity(blkdev); - } - else - { + } else { blkvsc_do_read_capacity16(blkdev); } - set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512)); + set_capacity(blkdev->gd, + blkdev->capacity * (blkdev->sector_size / 512)); blk_queue_logical_block_size(blkdev->gd->queue, blkdev->sector_size); /* go! */ add_disk(blkdev->gd); - DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d", blkdev->gd->disk_name, (unsigned long) blkdev->capacity, blkdev->sector_size); + DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d", + blkdev->gd->disk_name, (unsigned long)blkdev->capacity, + blkdev->sector_size); return ret; @@ -426,10 +417,8 @@ Remove: storvsc_drv_obj->Base.OnDeviceRemove(device_obj); Cleanup: - if (blkdev) - { - if (blkdev->request_pool) - { + if (blkdev) { + if (blkdev->request_pool) { kmem_cache_destroy(blkdev->request_pool); blkdev->request_pool = NULL; } @@ -450,7 +439,8 @@ static void blkvsc_shutdown(struct device *device) if (!blkdev) return; - DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n", blkdev->users, blkdev->gd->disk_name); + DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n", + blkdev->users, blkdev->gd->disk_name); spin_lock_irqsave(&blkdev->lock, flags); @@ -460,9 +450,9 @@ static void blkvsc_shutdown(struct device *device) spin_unlock_irqrestore(&blkdev->lock, flags); - while (blkdev->num_outstanding_reqs) - { - DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs); + while (blkdev->num_outstanding_reqs) { + DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", + blkdev->num_outstanding_reqs); udelay(100); } @@ -478,7 +468,7 @@ static void blkvsc_shutdown(struct device *device) static int blkvsc_do_flush(struct block_device_context *blkdev) { - struct blkvsc_request *blkvsc_req=NULL; + struct blkvsc_request *blkvsc_req = NULL; DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_flush()\n"); @@ -486,8 +476,7 @@ static int blkvsc_do_flush(struct block_device_context *blkdev) return 0; blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); - if (!blkvsc_req) - { + if (!blkvsc_req) { return -ENOMEM; } @@ -505,7 +494,7 @@ static int blkvsc_do_flush(struct block_device_context *blkdev) blkvsc_req->cmd_len = 10; /* Set this here since the completion routine may be invoked and completed before we return */ - blkvsc_req->cond =0; + blkvsc_req->cond = 0; blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); @@ -518,7 +507,7 @@ static int blkvsc_do_flush(struct block_device_context *blkdev) /* Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd) */ static int blkvsc_do_inquiry(struct block_device_context *blkdev) { - struct blkvsc_request *blkvsc_req=NULL; + struct blkvsc_request *blkvsc_req = NULL; struct page *page_buf; unsigned char *buf; unsigned char device_type; @@ -526,15 +515,13 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_inquiry()\n"); blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); - if (!blkvsc_req) - { + if (!blkvsc_req) { return -ENOMEM; } memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); page_buf = alloc_page(GFP_KERNEL); - if (!page_buf) - { + if (!page_buf) { kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); return -ENOMEM; } @@ -549,17 +536,18 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) blkvsc_req->request.DataBuffer.Length = 64; blkvsc_req->cmnd[0] = INQUIRY; - blkvsc_req->cmnd[1] = 0x1; /* Get product data */ - blkvsc_req->cmnd[2] = 0x83; /* mode page 83 */ + blkvsc_req->cmnd[1] = 0x1; /* Get product data */ + blkvsc_req->cmnd[2] = 0x83; /* mode page 83 */ blkvsc_req->cmnd[4] = 64; blkvsc_req->cmd_len = 6; /* Set this here since the completion routine may be invoked and completed before we return */ - blkvsc_req->cond =0; + blkvsc_req->cond = 0; blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond); + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, + blkvsc_req->cond); wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); @@ -569,16 +557,11 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) /* be to le */ device_type = buf[0] & 0x1F; - if (device_type == 0x0) - { + if (device_type == 0x0) { blkdev->device_type = HARDDISK_TYPE; - } - else if (device_type == 0x5) - { + } else if (device_type == 0x5) { blkdev->device_type = DVD_TYPE; - } - else - { + } else { /* TODO: this is currently unsupported device type */ blkdev->device_type = UNKNOWN_DEV_TYPE; } @@ -605,7 +588,7 @@ static int blkvsc_do_inquiry(struct block_device_context *blkdev) /* Do a scsi READ_CAPACITY cmd here to get the size of the disk */ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) { - struct blkvsc_request *blkvsc_req=NULL; + struct blkvsc_request *blkvsc_req = NULL; struct page *page_buf; unsigned char *buf; struct scsi_sense_hdr sense_hdr; @@ -614,18 +597,16 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) blkdev->sector_size = 0; blkdev->capacity = 0; - blkdev->media_not_present = 0; /* assume a disk is present */ + blkdev->media_not_present = 0; /* assume a disk is present */ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); - if (!blkvsc_req) - { + if (!blkvsc_req) { return -ENOMEM; } memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); page_buf = alloc_page(GFP_KERNEL); - if (!page_buf) - { + if (!page_buf) { kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); return -ENOMEM; } @@ -646,21 +627,21 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) * Set this here since the completion routine may be invoked * and completed before we return */ - blkvsc_req->cond =0; + blkvsc_req->cond = 0; blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond); + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, + blkvsc_req->cond); wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); /* check error */ - if (blkvsc_req->request.Status) - { - scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr); + if (blkvsc_req->request.Status) { + scsi_normalize_sense(blkvsc_req->sense_buffer, + SCSI_SENSE_BUFFERSIZE, &sense_hdr); - if (sense_hdr.asc == 0x3A) /* Medium not present */ - { + if (sense_hdr.asc == 0x3A) { /* Medium not present */ blkdev->media_not_present = 1; } @@ -669,8 +650,10 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) buf = kmap(page_buf); /* be to le */ - blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1; - blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; + blkdev->capacity = + ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1; + blkdev->sector_size = + (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; kunmap(page_buf); @@ -681,10 +664,9 @@ static int blkvsc_do_read_capacity(struct block_device_context *blkdev) return 0; } - static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) { - struct blkvsc_request *blkvsc_req=NULL; + struct blkvsc_request *blkvsc_req = NULL; struct page *page_buf; unsigned char *buf; struct scsi_sense_hdr sense_hdr; @@ -693,18 +675,16 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) blkdev->sector_size = 0; blkdev->capacity = 0; - blkdev->media_not_present = 0; /* assume a disk is present */ + blkdev->media_not_present = 0; /* assume a disk is present */ blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); - if (!blkvsc_req) - { + if (!blkvsc_req) { return -ENOMEM; } memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); page_buf = alloc_page(GFP_KERNEL); - if (!page_buf) - { + if (!page_buf) { kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); return -ENOMEM; } @@ -718,28 +698,28 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) blkvsc_req->request.DataBuffer.Offset = 0; blkvsc_req->request.DataBuffer.Length = 12; - blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ + blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ blkvsc_req->cmd_len = 16; /* * Set this here since the completion routine may be invoked * and completed before we return */ - blkvsc_req->cond =0; + blkvsc_req->cond = 0; blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, blkvsc_req->cond); + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", blkvsc_req, + blkvsc_req->cond); wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); /* check error */ - if (blkvsc_req->request.Status) - { - scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr); + if (blkvsc_req->request.Status) { + scsi_normalize_sense(blkvsc_req->sense_buffer, + SCSI_SENSE_BUFFERSIZE, &sense_hdr); - if (sense_hdr.asc == 0x3A) /* Medium not present */ - { + if (sense_hdr.asc == 0x3A) { /* Medium not present */ blkdev->media_not_present = 1; } @@ -748,8 +728,8 @@ static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) buf = kmap(page_buf); /* be to le */ - blkdev->capacity = be64_to_cpu(*(unsigned long long*) &buf[0]) + 1; - blkdev->sector_size = be32_to_cpu(*(unsigned int*)&buf[8]); + blkdev->capacity = be64_to_cpu(*(unsigned long long *)&buf[0]) + 1; + blkdev->sector_size = be32_to_cpu(*(unsigned int *)&buf[8]); /* blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]) + 1; */ /* blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]; */ @@ -772,11 +752,13 @@ Desc: Callback when our device is removed --*/ static int blkvsc_remove(struct device *device) { - int ret=0; + int ret = 0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct blkvsc_driver_context *blkvsc_drv_ctx = + (struct blkvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); struct hv_device *device_obj = &device_ctx->device_obj; @@ -787,18 +769,17 @@ static int blkvsc_remove(struct device *device) DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n"); - if (!storvsc_drv_obj->Base.OnDeviceRemove) - { + if (!storvsc_drv_obj->Base.OnDeviceRemove) { DPRINT_EXIT(BLKVSC_DRV); return -1; } /* Call to the vsc driver to let it know that the device is being removed */ ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj); - if (ret != 0) - { + if (ret != 0) { /* TODO: */ - DPRINT_ERR(BLKVSC_DRV, "unable to remove blkvsc device (ret %d)", ret); + DPRINT_ERR(BLKVSC_DRV, + "unable to remove blkvsc device (ret %d)", ret); } /* Get to a known state */ @@ -810,9 +791,9 @@ static int blkvsc_remove(struct device *device) spin_unlock_irqrestore(&blkdev->lock, flags); - while (blkdev->num_outstanding_reqs) - { - DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", blkdev->num_outstanding_reqs); + while (blkdev->num_outstanding_reqs) { + DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", + blkdev->num_outstanding_reqs); udelay(100); } @@ -841,96 +822,92 @@ static int blkvsc_remove(struct device *device) static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req) { ASSERT(blkvsc_req->req); - ASSERT(blkvsc_req->sector_count <= (MAX_MULTIPAGE_BUFFER_COUNT*8)); + ASSERT(blkvsc_req->sector_count <= (MAX_MULTIPAGE_BUFFER_COUNT * 8)); blkvsc_req->cmd_len = 16; - if (blkvsc_req->sector_start > 0xffffffff) - { - if (rq_data_dir(blkvsc_req->req)) - { + if (blkvsc_req->sector_start > 0xffffffff) { + if (rq_data_dir(blkvsc_req->req)) { blkvsc_req->write = 1; blkvsc_req->cmnd[0] = WRITE_16; - } - else - { + } else { blkvsc_req->write = 0; blkvsc_req->cmnd[0] = READ_16; } blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0; - *(unsigned long long*)&blkvsc_req->cmnd[2] = cpu_to_be64(blkvsc_req->sector_start); - *(unsigned int*)&blkvsc_req->cmnd[10] = cpu_to_be32(blkvsc_req->sector_count); - } - else if ((blkvsc_req->sector_count > 0xff) || (blkvsc_req->sector_start > 0x1fffff)) - { - if (rq_data_dir(blkvsc_req->req)) - { + *(unsigned long long *)&blkvsc_req->cmnd[2] = + cpu_to_be64(blkvsc_req->sector_start); + *(unsigned int *)&blkvsc_req->cmnd[10] = + cpu_to_be32(blkvsc_req->sector_count); + } else if ((blkvsc_req->sector_count > 0xff) + || (blkvsc_req->sector_start > 0x1fffff)) { + if (rq_data_dir(blkvsc_req->req)) { blkvsc_req->write = 1; blkvsc_req->cmnd[0] = WRITE_10; - } - else - { + } else { blkvsc_req->write = 0; blkvsc_req->cmnd[0] = READ_10; } blkvsc_req->cmnd[1] |= blk_fua_rq(blkvsc_req->req) ? 0x8 : 0; - *(unsigned int *)&blkvsc_req->cmnd[2] = cpu_to_be32(blkvsc_req->sector_start); - *(unsigned short*)&blkvsc_req->cmnd[7] = cpu_to_be16(blkvsc_req->sector_count); - } - else - { - if (rq_data_dir(blkvsc_req->req)) - { + *(unsigned int *)&blkvsc_req->cmnd[2] = + cpu_to_be32(blkvsc_req->sector_start); + *(unsigned short *)&blkvsc_req->cmnd[7] = + cpu_to_be16(blkvsc_req->sector_count); + } else { + if (rq_data_dir(blkvsc_req->req)) { blkvsc_req->write = 1; blkvsc_req->cmnd[0] = WRITE_6; - } - else - { + } else { blkvsc_req->write = 0; blkvsc_req->cmnd[0] = READ_6; } - *(unsigned int *)&blkvsc_req->cmnd[1] = cpu_to_be32(blkvsc_req->sector_start) >> 8; + *(unsigned int *)&blkvsc_req->cmnd[1] = + cpu_to_be32(blkvsc_req->sector_start) >> 8; blkvsc_req->cmnd[1] &= 0x1f; - blkvsc_req->cmnd[4] = (unsigned char) blkvsc_req->sector_count; + blkvsc_req->cmnd[4] = (unsigned char)blkvsc_req->sector_count; } } -static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*request_completion)(STORVSC_REQUEST*) ) +static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, + void (*request_completion) (STORVSC_REQUEST *)) { struct block_device_context *blkdev = blkvsc_req->dev; - struct device_context *device_ctx=blkdev->device_ctx; - struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver); - struct blkvsc_driver_context *blkvsc_drv_ctx = (struct blkvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; - int ret =0; + struct device_context *device_ctx = blkdev->device_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(device_ctx->device.driver); + struct blkvsc_driver_context *blkvsc_drv_ctx = + (struct blkvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &blkvsc_drv_ctx->drv_obj; + int ret = 0; STORVSC_REQUEST *storvsc_req; - DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p type %s start_sector %lu count %ld offset %d len %d\n", - blkvsc_req, - (blkvsc_req->write)?"WRITE":"READ", - (unsigned long) blkvsc_req->sector_start, - blkvsc_req->sector_count, - blkvsc_req->request.DataBuffer.Offset, - blkvsc_req->request.DataBuffer.Length); + DPRINT_DBG(BLKVSC_DRV, + "blkvsc_submit_request() - req %p type %s start_sector %lu count %ld offset %d len %d\n", + blkvsc_req, (blkvsc_req->write) ? "WRITE" : "READ", + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + blkvsc_req->request.DataBuffer.Offset, + blkvsc_req->request.DataBuffer.Length); /*for (i=0; i < (blkvsc_req->request.DataBuffer.Length >> 12); i++) - { - DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p pfn[%d] %llx\n", - blkvsc_req, - i, - blkvsc_req->request.DataBuffer.PfnArray[i]); - }*/ + { + DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - req %p pfn[%d] %llx\n", + blkvsc_req, + i, + blkvsc_req->request.DataBuffer.PfnArray[i]); + } */ storvsc_req = &blkvsc_req->request; - storvsc_req->Extension = (void*)((unsigned long)blkvsc_req + sizeof(struct blkvsc_request)); + storvsc_req->Extension = + (void *)((unsigned long)blkvsc_req + sizeof(struct blkvsc_request)); - storvsc_req->Type = blkvsc_req->write? WRITE_TYPE : READ_TYPE; + storvsc_req->Type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; storvsc_req->OnIOCompletion = request_completion; storvsc_req->Context = blkvsc_req; @@ -938,7 +915,7 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*reque storvsc_req->Host = blkdev->port; storvsc_req->Bus = blkdev->path; storvsc_req->TargetId = blkdev->target; - storvsc_req->LunId = 0; /* this is not really used at all */ + storvsc_req->LunId = 0; /* this is not really used at all */ storvsc_req->CdbLen = blkvsc_req->cmd_len; storvsc_req->Cdb = blkvsc_req->cmnd; @@ -946,45 +923,49 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, void (*reque storvsc_req->SenseBuffer = blkvsc_req->sense_buffer; storvsc_req->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; - ret = storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, &blkvsc_req->request); - if (ret == 0) - { + ret = + storvsc_drv_obj->OnIORequest(&blkdev->device_ctx->device_obj, + &blkvsc_req->request); + if (ret == 0) { blkdev->num_outstanding_reqs++; } return ret; } - /* * We break the request into 1 or more blkvsc_requests and submit * them. If we cant submit them all, we put them on the * pending_list. The blkvsc_request() will work on the pending_list. */ -static int blkvsc_do_request(struct block_device_context *blkdev, struct request *req) +static int blkvsc_do_request(struct block_device_context *blkdev, + struct request *req) { - struct bio *bio=NULL; - struct bio_vec *bvec=NULL; - struct bio_vec *prev_bvec=NULL; + struct bio *bio = NULL; + struct bio_vec *bvec = NULL; + struct bio_vec *prev_bvec = NULL; - struct blkvsc_request *blkvsc_req=NULL; + struct blkvsc_request *blkvsc_req = NULL; struct blkvsc_request *tmp; - int databuf_idx=0; - int seg_idx=0; + int databuf_idx = 0; + int seg_idx = 0; sector_t start_sector; unsigned long num_sectors = 0; - int ret=0; - int pending=0; - struct blkvsc_request_group *group=NULL; + int ret = 0; + int pending = 0; + struct blkvsc_request_group *group = NULL; - DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %lu \n", blkdev, req, (unsigned long) blk_rq_pos(req)); + DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %lu \n", blkdev, req, + (unsigned long)blk_rq_pos(req)); /* Create a group to tie req to list of blkvsc_reqs */ - group = (struct blkvsc_request_group*)kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC); - if (!group) - { + group = + (struct blkvsc_request_group *)kmem_cache_alloc(blkdev-> + request_pool, + GFP_ATOMIC); + if (!group) { return -ENOMEM; } @@ -995,157 +976,194 @@ static int blkvsc_do_request(struct block_device_context *blkdev, struct request /* foreach bio in the request */ if (req->bio) - for (bio = req->bio; bio; bio = bio->bi_next) - { - /* Map this bio into an existing or new storvsc request */ - bio_for_each_segment (bvec, bio, seg_idx) - { - DPRINT_DBG(BLKVSC_DRV, "bio_for_each_segment() - req %p bio %p bvec %p seg_idx %d databuf_idx %d\n", - req, bio, bvec, seg_idx, databuf_idx); - - /* Get a new storvsc request */ - if ( (!blkvsc_req) || /* 1st-time */ - (databuf_idx >= MAX_MULTIPAGE_BUFFER_COUNT) || - (bvec->bv_offset != 0) || /* hole at the begin of page */ - (prev_bvec && (prev_bvec->bv_len != PAGE_SIZE)) ) /* hold at the end of page */ - { - /* submit the prev one */ - if (blkvsc_req) - { - blkvsc_req->sector_start = start_sector; - sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9)); - - blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9); - - blkvsc_init_rw(blkvsc_req); - } + for (bio = req->bio; bio; bio = bio->bi_next) { + /* Map this bio into an existing or new storvsc request */ + bio_for_each_segment(bvec, bio, seg_idx) { + DPRINT_DBG(BLKVSC_DRV, + "bio_for_each_segment() - req %p bio %p bvec %p seg_idx %d databuf_idx %d\n", + req, bio, bvec, seg_idx, + databuf_idx); + + /* Get a new storvsc request */ + if ((!blkvsc_req) || /* 1st-time */ + (databuf_idx >= MAX_MULTIPAGE_BUFFER_COUNT) || (bvec->bv_offset != 0) || /* hole at the begin of page */ + (prev_bvec && (prev_bvec->bv_len != PAGE_SIZE))) { /* hold at the end of page */ + /* submit the prev one */ + if (blkvsc_req) { + blkvsc_req->sector_start = + start_sector; + sector_div(blkvsc_req-> + sector_start, + (blkdev-> + sector_size >> 9)); + + blkvsc_req->sector_count = + num_sectors / + (blkdev->sector_size >> 9); + + blkvsc_init_rw(blkvsc_req); + } - /* Create new blkvsc_req to represent the current bvec */ - blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC); - if (!blkvsc_req) - { - /* free up everything */ - list_for_each_entry_safe(blkvsc_req, tmp, &group->blkvsc_req_list, req_entry) - { - list_del(&blkvsc_req->req_entry); - kmem_cache_free(blkdev->request_pool, blkvsc_req); + /* Create new blkvsc_req to represent the current bvec */ + blkvsc_req = + kmem_cache_alloc(blkdev-> + request_pool, + GFP_ATOMIC); + if (!blkvsc_req) { + /* free up everything */ + list_for_each_entry_safe + (blkvsc_req, tmp, + &group->blkvsc_req_list, + req_entry) { + list_del(&blkvsc_req-> + req_entry); + kmem_cache_free(blkdev-> + request_pool, + blkvsc_req); + } + + kmem_cache_free(blkdev-> + request_pool, + group); + return -ENOMEM; } - kmem_cache_free(blkdev->request_pool, group); - return -ENOMEM; + memset(blkvsc_req, 0, + sizeof(struct blkvsc_request)); + + blkvsc_req->dev = blkdev; + blkvsc_req->req = req; + blkvsc_req->request.DataBuffer.Offset = + bvec->bv_offset; + blkvsc_req->request.DataBuffer.Length = + 0; + + /* Add to the group */ + blkvsc_req->group = group; + blkvsc_req->group->outstanding++; + list_add_tail(&blkvsc_req->req_entry, + &blkvsc_req->group-> + blkvsc_req_list); + + start_sector += num_sectors; + num_sectors = 0; + databuf_idx = 0; } - memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); - - blkvsc_req->dev = blkdev; - blkvsc_req->req = req; - blkvsc_req->request.DataBuffer.Offset = bvec->bv_offset; - blkvsc_req->request.DataBuffer.Length = 0; + /* Add the curr bvec/segment to the curr blkvsc_req */ + blkvsc_req->request.DataBuffer. + PfnArray[databuf_idx] = + page_to_pfn(bvec->bv_page); + blkvsc_req->request.DataBuffer.Length += + bvec->bv_len; - /* Add to the group */ - blkvsc_req->group = group; - blkvsc_req->group->outstanding++; - list_add_tail(&blkvsc_req->req_entry, &blkvsc_req->group->blkvsc_req_list); - - start_sector += num_sectors; - num_sectors = 0; - databuf_idx = 0; - } + prev_bvec = bvec; - /* Add the curr bvec/segment to the curr blkvsc_req */ - blkvsc_req->request.DataBuffer.PfnArray[databuf_idx] = page_to_pfn(bvec->bv_page); - blkvsc_req->request.DataBuffer.Length += bvec->bv_len; + databuf_idx++; + num_sectors += bvec->bv_len >> 9; - prev_bvec = bvec; + } /* bio_for_each_segment */ - databuf_idx++; - num_sectors += bvec->bv_len >> 9; - - } /* bio_for_each_segment */ - - } /* rq_for_each_bio */ + } + /* rq_for_each_bio */ /* Handle the last one */ - if (blkvsc_req) - { - DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n", blkdev, req, blkvsc_req->group, blkvsc_req->group->outstanding); + if (blkvsc_req) { + DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n", + blkdev, req, blkvsc_req->group, + blkvsc_req->group->outstanding); blkvsc_req->sector_start = start_sector; - sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9)); + sector_div(blkvsc_req->sector_start, + (blkdev->sector_size >> 9)); - blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9); + blkvsc_req->sector_count = + num_sectors / (blkdev->sector_size >> 9); blkvsc_init_rw(blkvsc_req); } - list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry) - { - if (pending) - { - DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld)\n", - blkvsc_req, (unsigned long)blkvsc_req->sector_start, blkvsc_req->sector_count, (unsigned long) start_sector, (unsigned long) num_sectors); - - list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list); - } - else - { - ret = blkvsc_submit_request(blkvsc_req, blkvsc_request_completion); - if (ret == -1) - { + list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry) { + if (pending) { + DPRINT_DBG(BLKVSC_DRV, + "adding blkvsc_req to pending_list - blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld)\n", + blkvsc_req, + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + (unsigned long)start_sector, + (unsigned long)num_sectors); + + list_add_tail(&blkvsc_req->pend_entry, + &blkdev->pending_list); + } else { + ret = + blkvsc_submit_request(blkvsc_req, + blkvsc_request_completion); + if (ret == -1) { pending = 1; - list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list); + list_add_tail(&blkvsc_req->pend_entry, + &blkdev->pending_list); } - DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld) ret %d\n", - blkvsc_req, (unsigned long) blkvsc_req->sector_start, blkvsc_req->sector_count, (unsigned long) start_sector, num_sectors, ret); + DPRINT_DBG(BLKVSC_DRV, + "submitted blkvsc_req %p start_sect %lu sect_count %ld (%lu %ld) ret %d\n", + blkvsc_req, + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + (unsigned long)start_sector, num_sectors, + ret); } } return pending; } -static void blkvsc_cmd_completion(STORVSC_REQUEST* request) +static void blkvsc_cmd_completion(STORVSC_REQUEST * request) { - struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context; - struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev; + struct blkvsc_request *blkvsc_req = + (struct blkvsc_request *)request->Context; + struct block_device_context *blkdev = + (struct block_device_context *)blkvsc_req->dev; struct scsi_sense_hdr sense_hdr; - DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n", blkvsc_req); + DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n", + blkvsc_req); blkdev->num_outstanding_reqs--; - if (blkvsc_req->request.Status) - { - if (scsi_normalize_sense(blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, &sense_hdr)) - { + if (blkvsc_req->request.Status) { + if (scsi_normalize_sense + (blkvsc_req->sense_buffer, SCSI_SENSE_BUFFERSIZE, + &sense_hdr)) { scsi_print_sense_hdr("blkvsc", &sense_hdr); } } - blkvsc_req->cond =1; + blkvsc_req->cond = 1; wake_up_interruptible(&blkvsc_req->wevent); } -static void blkvsc_request_completion(STORVSC_REQUEST* request) +static void blkvsc_request_completion(STORVSC_REQUEST * request) { - struct blkvsc_request *blkvsc_req=(struct blkvsc_request*)request->Context; - struct block_device_context *blkdev = (struct block_device_context*)blkvsc_req->dev; + struct blkvsc_request *blkvsc_req = + (struct blkvsc_request *)request->Context; + struct block_device_context *blkdev = + (struct block_device_context *)blkvsc_req->dev; unsigned long flags; struct blkvsc_request *comp_req, *tmp; ASSERT(blkvsc_req->group); - DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s sect_start %lu sect_count %ld len %d group outstd %d total outstd %d\n", - blkdev, - blkvsc_req, - blkvsc_req->group, - (blkvsc_req->write)?"WRITE":"READ", - (unsigned long) blkvsc_req->sector_start, - blkvsc_req->sector_count, - blkvsc_req->request.DataBuffer.Length, - blkvsc_req->group->outstanding, - blkdev->num_outstanding_reqs); + DPRINT_DBG(BLKVSC_DRV, + "blkdev %p blkvsc_req %p group %p type %s sect_start %lu sect_count %ld len %d group outstd %d total outstd %d\n", + blkdev, blkvsc_req, blkvsc_req->group, + (blkvsc_req->write) ? "WRITE" : "READ", + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + blkvsc_req->request.DataBuffer.Length, + blkvsc_req->group->outstanding, + blkdev->num_outstanding_reqs); spin_lock_irqsave(&blkdev->lock, flags); @@ -1157,32 +1175,34 @@ static void blkvsc_request_completion(STORVSC_REQUEST* request) * completed. This guarantees no out-of-order blkvsc_req * completion when calling end_that_request_first() */ - if (blkvsc_req->group->outstanding == 0) - { - list_for_each_entry_safe(comp_req, tmp, &blkvsc_req->group->blkvsc_req_list, req_entry) - { - DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n", - comp_req, - (unsigned long) comp_req->sector_start, - comp_req->sector_count); + if (blkvsc_req->group->outstanding == 0) { + list_for_each_entry_safe(comp_req, tmp, + &blkvsc_req->group->blkvsc_req_list, + req_entry) { + DPRINT_DBG(BLKVSC_DRV, + "completing blkvsc_req %p sect_start %lu sect_count %ld \n", + comp_req, + (unsigned long)comp_req->sector_start, + comp_req->sector_count); list_del(&comp_req->req_entry); - if (!__blk_end_request( - comp_req->req, - (!comp_req->request.Status ? 0: -EIO), - comp_req->sector_count * blkdev->sector_size)) - { + if (!__blk_end_request(comp_req->req, + (!comp_req->request. + Status ? 0 : -EIO), + comp_req->sector_count * + blkdev->sector_size)) { /* All the sectors have been xferred ie the request is done */ - DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", comp_req->req); - kmem_cache_free(blkdev->request_pool, comp_req->group); + DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", + comp_req->req); + kmem_cache_free(blkdev->request_pool, + comp_req->group); } kmem_cache_free(blkdev->request_pool, comp_req); } - if (!blkdev->shutting_down) - { + if (!blkdev->shutting_down) { blkvsc_do_pending_reqs(blkdev); blk_start_queue(blkdev->gd->queue); blkvsc_request(blkdev->gd->queue); @@ -1197,59 +1217,63 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev) struct blkvsc_request *pend_req, *tmp; struct blkvsc_request *comp_req, *tmp2; - int ret=0; + int ret = 0; DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs()"); /* Flush the pending list first */ - list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry) - { + list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, + pend_entry) { /* * The pend_req could be part of a partially completed * request. If so, complete those req first until we * hit the pend_req */ - list_for_each_entry_safe(comp_req, tmp2, &pend_req->group->blkvsc_req_list, req_entry) - { - DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p sect_start %lu sect_count %ld \n", - comp_req, - (unsigned long) comp_req->sector_start, - comp_req->sector_count); + list_for_each_entry_safe(comp_req, tmp2, + &pend_req->group->blkvsc_req_list, + req_entry) { + DPRINT_DBG(BLKVSC_DRV, + "completing blkvsc_req %p sect_start %lu sect_count %ld \n", + comp_req, + (unsigned long)comp_req->sector_start, + comp_req->sector_count); if (comp_req == pend_req) break; list_del(&comp_req->req_entry); - if (comp_req->req) - { - ret = __blk_end_request( - comp_req->req, - (!comp_req->request.Status ? 0 : -EIO), - comp_req->sector_count * blkdev->sector_size); - ASSERT(ret != 0); + if (comp_req->req) { + ret = __blk_end_request(comp_req->req, + (!comp_req->request. + Status ? 0 : -EIO), + comp_req->sector_count * + blkdev->sector_size); + ASSERT(ret != 0); } kmem_cache_free(blkdev->request_pool, comp_req); } - DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n", pend_req); + DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n", + pend_req); list_del(&pend_req->pend_entry); list_del(&pend_req->req_entry); - if (comp_req->req) - { - if (!__blk_end_request( - pend_req->req, - -EIO, - pend_req->sector_count * blkdev->sector_size)) - { - /* All the sectors have been xferred ie the request is done */ - DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs() - req %p COMPLETED\n", pend_req->req); - kmem_cache_free(blkdev->request_pool, pend_req->group); - } + if (comp_req->req) { + if (!__blk_end_request(pend_req->req, + -EIO, + pend_req->sector_count * + blkdev->sector_size)) { + /* All the sectors have been xferred ie the request is done */ + DPRINT_DBG(BLKVSC_DRV, + "blkvsc_cancel_pending_reqs() - req %p COMPLETED\n", + pend_req->req); + kmem_cache_free(blkdev->request_pool, + pend_req->group); + } } kmem_cache_free(blkdev->request_pool, pend_req); @@ -1261,20 +1285,19 @@ static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev) static int blkvsc_do_pending_reqs(struct block_device_context *blkdev) { struct blkvsc_request *pend_req, *tmp; - int ret=0; + int ret = 0; /* Flush the pending list first */ - list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry) - { - DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n", pend_req); - - ret = blkvsc_submit_request(pend_req, blkvsc_request_completion); - if (ret != 0) - { + list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, + pend_entry) { + DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n", + pend_req); + + ret = + blkvsc_submit_request(pend_req, blkvsc_request_completion); + if (ret != 0) { break; - } - else - { + } else { list_del(&pend_req->pend_entry); } } @@ -1286,24 +1309,24 @@ static void blkvsc_request(struct request_queue *queue) { struct block_device_context *blkdev = NULL; struct request *req; - int ret=0; + int ret = 0; DPRINT_DBG(BLKVSC_DRV, "- enter \n"); - while ((req = blk_peek_request(queue)) != NULL) - { + while ((req = blk_peek_request(queue)) != NULL) { DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req); blkdev = req->rq_disk->private_data; - if (blkdev->shutting_down || !blk_fs_request(req) || blkdev->media_not_present) { + if (blkdev->shutting_down || !blk_fs_request(req) + || blkdev->media_not_present) { __blk_end_request_cur(req, 0); continue; } ret = blkvsc_do_pending_reqs(blkdev); - if (ret != 0) - { - DPRINT_DBG(BLKVSC_DRV, "- stop queue - pending_list not empty\n"); + if (ret != 0) { + DPRINT_DBG(BLKVSC_DRV, + "- stop queue - pending_list not empty\n"); blk_stop_queue(queue); break; } @@ -1311,14 +1334,11 @@ static void blkvsc_request(struct request_queue *queue) blk_start_request(req); ret = blkvsc_do_request(blkdev, req); - if (ret > 0) - { + if (ret > 0) { DPRINT_DBG(BLKVSC_DRV, "- stop queue - no room\n"); blk_stop_queue(queue); break; - } - else if (ret < 0) - { + } else if (ret < 0) { DPRINT_DBG(BLKVSC_DRV, "- stop queue - no mem\n"); blk_requeue_request(queue, req); blk_stop_queue(queue); @@ -1327,16 +1347,16 @@ static void blkvsc_request(struct request_queue *queue) } } -static int blkvsc_open(struct block_device *bdev, fmode_t mode) +static int blkvsc_open(struct block_device *bdev, fmode_t mode) { struct block_device_context *blkdev = bdev->bd_disk->private_data; - DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name); + DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, + blkdev->gd->disk_name); spin_lock(&blkdev->lock); - if (!blkdev->users && blkdev->device_type == DVD_TYPE) - { + if (!blkdev->users && blkdev->device_type == DVD_TYPE) { spin_unlock(&blkdev->lock); check_disk_change(bdev); spin_lock(&blkdev->lock); @@ -1352,11 +1372,11 @@ static int blkvsc_release(struct gendisk *disk, fmode_t mode) { struct block_device_context *blkdev = disk->private_data; - DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, blkdev->gd->disk_name); + DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, + blkdev->gd->disk_name); spin_lock(&blkdev->lock); - if (blkdev->users == 1) - { + if (blkdev->users == 1) { spin_unlock(&blkdev->lock); blkvsc_do_flush(blkdev); spin_lock(&blkdev->lock); @@ -1381,10 +1401,10 @@ static int blkvsc_revalidate_disk(struct gendisk *gd) DPRINT_DBG(BLKVSC_DRV, "- enter\n"); - if (blkdev->device_type == DVD_TYPE) - { + if (blkdev->device_type == DVD_TYPE) { blkvsc_do_read_capacity(blkdev); - set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512)); + set_capacity(blkdev->gd, + blkdev->capacity * (blkdev->sector_size / 512)); blk_queue_logical_block_size(gd->queue, blkdev->sector_size); } return 0; @@ -1393,90 +1413,88 @@ static int blkvsc_revalidate_disk(struct gendisk *gd) int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg) { sector_t total_sectors = get_capacity(bd->bd_disk); - sector_t cylinder_times_heads=0; - sector_t temp=0; + sector_t cylinder_times_heads = 0; + sector_t temp = 0; - int sectors_per_track=0; - int heads=0; - int cylinders=0; - int rem=0; + int sectors_per_track = 0; + int heads = 0; + int cylinders = 0; + int rem = 0; - if (total_sectors > (65535 * 16 * 255)) { - total_sectors = (65535 * 16 * 255); - } + if (total_sectors > (65535 * 16 * 255)) { + total_sectors = (65535 * 16 * 255); + } - if (total_sectors >= (65535 * 16 * 63)) { - sectors_per_track = 255; - heads = 16; + if (total_sectors >= (65535 * 16 * 63)) { + sectors_per_track = 255; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ - } - else - { - sectors_per_track = 17; + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } else { + sectors_per_track = 17; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ temp = cylinder_times_heads + 1023; rem = sector_div(temp, 1024); /* sector_div stores the quotient in temp */ heads = temp; - if (heads < 4) { - heads = 4; - } + if (heads < 4) { + heads = 4; + } - if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) { - sectors_per_track = 31; - heads = 16; + if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) { + sectors_per_track = 31; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ - } + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } - if (cylinder_times_heads >= (heads * 1024)) { - sectors_per_track = 63; - heads = 16; + if (cylinder_times_heads >= (heads * 1024)) { + sectors_per_track = 63; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } } - } temp = cylinder_times_heads; - rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */ + rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */ cylinders = temp; hg->heads = heads; - hg->sectors = sectors_per_track; - hg->cylinders = cylinders; + hg->sectors = sectors_per_track; + hg->cylinders = cylinders; - DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, sectors_per_track); + DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, + sectors_per_track); - return 0; + return 0; } static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, unsigned cmd, unsigned long argument) { /* struct block_device_context *blkdev = bd->bd_disk->private_data; */ - int ret=0; - - switch (cmd) - { - /* TODO: I think there is certain format for HDIO_GET_IDENTITY rather than just */ - /* a GUID. Commented it out for now. */ - /*case HDIO_GET_IDENTITY: - DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n"); - - if (copy_to_user((void __user *)arg, blkdev->device_id, blkdev->device_id_len)) - { - ret = -EFAULT; - } + int ret = 0; - break;*/ + switch (cmd) { + /* TODO: I think there is certain format for HDIO_GET_IDENTITY rather than just */ + /* a GUID. Commented it out for now. */ + /*case HDIO_GET_IDENTITY: + DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n"); + + if (copy_to_user((void __user *)arg, blkdev->device_id, blkdev->device_id_len)) + { + ret = -EFAULT; + } + + break; */ default: ret = -EINVAL; break; @@ -1485,14 +1503,13 @@ static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, return ret; } - MODULE_LICENSE("GPL"); static int __init blkvsc_init(void) { int ret; - ASSERT(sizeof(sector_t) == 8); /* Make sure CONFIG_LBD is set */ + ASSERT(sizeof(sector_t) == 8); /* Make sure CONFIG_LBD is set */ DPRINT_ENTER(BLKVSC_DRV); diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index 9010f0e..fc8175c 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -43,46 +43,42 @@ MODULE_LICENSE("GPL"); - /* Static decl */ static int netvsc_probe(struct device *device); static int netvsc_remove(struct device *device); static int netvsc_open(struct net_device *net); static void netvsc_xmit_completion(void *context); -static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net); -static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* Packet); +static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net); +static int netvsc_recv_callback(struct hv_device *device_obj, + NETVSC_PACKET * Packet); static int netvsc_close(struct net_device *net); static struct net_device_stats *netvsc_get_stats(struct net_device *net); -static void netvsc_linkstatus_callback(struct hv_device *device_obj, unsigned int status); - +static void netvsc_linkstatus_callback(struct hv_device *device_obj, + unsigned int status); /* Data types */ struct net_device_context { - struct device_context *device_ctx; /* point back to our device context */ + struct device_context *device_ctx; /* point back to our device context */ struct net_device_stats stats; }; struct netvsc_driver_context { /* !! These must be the first 2 fields !! */ - struct driver_context drv_ctx; - NETVSC_DRIVER_OBJECT drv_obj; + struct driver_context drv_ctx; + NETVSC_DRIVER_OBJECT drv_obj; }; - /* Globals */ - static int netvsc_ringbuffer_size = NETVSC_DEVICE_RING_BUFFER_SIZE; /* The one and only one */ static struct netvsc_driver_context g_netvsc_drv; - /* Routines */ - /*++ Name: netvsc_drv_init() @@ -92,9 +88,9 @@ Desc: NetVsc driver initialization --*/ int netvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) { - int ret=0; - NETVSC_DRIVER_OBJECT *net_drv_obj=&g_netvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_netvsc_drv.drv_ctx; + int ret = 0; + NETVSC_DRIVER_OBJECT *net_drv_obj = &g_netvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; DPRINT_ENTER(NETVSC_DRV); @@ -147,11 +143,10 @@ static void netvsc_set_multicast_list(struct net_device *net) { } - static const struct net_device_ops device_ops = { .ndo_open = netvsc_open, .ndo_stop = netvsc_close, - .ndo_start_xmit = netvsc_start_xmit, + .ndo_start_xmit = netvsc_start_xmit, .ndo_get_stats = netvsc_get_stats, .ndo_set_multicast_list = netvsc_set_multicast_list, }; @@ -165,10 +160,12 @@ Desc: Add the specified new device to this driver --*/ static int netvsc_probe(struct device *device) { - int ret=0; + int ret = 0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct netvsc_driver_context *net_drv_ctx = + (struct netvsc_driver_context *)driver_ctx; NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); @@ -180,15 +177,15 @@ static int netvsc_probe(struct device *device) DPRINT_ENTER(NETVSC_DRV); - if (!net_drv_obj->Base.OnDeviceAdd) - { + if (!net_drv_obj->Base.OnDeviceAdd) { return -1; } - net = alloc_netdev(sizeof(struct net_device_context), "seth%d", ether_setup); + net = + alloc_netdev(sizeof(struct net_device_context), "seth%d", + ether_setup); /* net = alloc_etherdev(sizeof(struct net_device_context)); */ - if (!net) - { + if (!net) { return -1; } @@ -201,22 +198,20 @@ static int netvsc_probe(struct device *device) dev_set_drvdata(device, net); /* Notify the netvsc driver of the new device */ - ret = net_drv_obj->Base.OnDeviceAdd(device_obj, (void*)&device_info); - if (ret != 0) - { + ret = net_drv_obj->Base.OnDeviceAdd(device_obj, (void *)&device_info); + if (ret != 0) { free_netdev(net); dev_set_drvdata(device, NULL); - DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", ret); + DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", + ret); return ret; } /* If carrier is still off ie we did not get a link status callback, update it if necessary */ /* FIXME: We should use a atomic or test/set instead to avoid getting out of sync with the device's link status */ - if (!netif_carrier_ok(net)) - { - if (!device_info.LinkState) - { + if (!netif_carrier_ok(net)) { + if (!device_info.LinkState) { netif_carrier_on(net); } } @@ -228,8 +223,7 @@ static int netvsc_probe(struct device *device) SET_NETDEV_DEV(net, device); ret = register_netdev(net); - if (ret != 0) - { + if (ret != 0) { /* Remove the device and release the resource */ net_drv_obj->Base.OnDeviceRemove(device_obj); free_netdev(net); @@ -242,9 +236,11 @@ static int netvsc_probe(struct device *device) static int netvsc_remove(struct device *device) { - int ret=0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx; + int ret = 0; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct netvsc_driver_context *net_drv_ctx = + (struct netvsc_driver_context *)driver_ctx; NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); @@ -253,15 +249,13 @@ static int netvsc_remove(struct device *device) DPRINT_ENTER(NETVSC_DRV); - if (net == NULL) - { + if (net == NULL) { DPRINT_INFO(NETVSC, "no net device to remove"); DPRINT_EXIT(NETVSC_DRV); return 0; } - if (!net_drv_obj->Base.OnDeviceRemove) - { + if (!net_drv_obj->Base.OnDeviceRemove) { DPRINT_EXIT(NETVSC_DRV); return -1; } @@ -274,8 +268,7 @@ static int netvsc_remove(struct device *device) /* Call to the vsc driver to let it know that the device is being removed */ ret = net_drv_obj->Base.OnDeviceRemove(device_obj); - if (ret != 0) - { + if (ret != 0) { /* TODO: */ DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); } @@ -296,32 +289,32 @@ Desc: Open the specified interface device --*/ static int netvsc_open(struct net_device *net) { - int ret=0; + int ret = 0; struct net_device_context *net_device_ctx = netdev_priv(net); - struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver); - struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(net_device_ctx->device_ctx->device.driver); + struct netvsc_driver_context *net_drv_ctx = + (struct netvsc_driver_context *)driver_ctx; NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj; struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; DPRINT_ENTER(NETVSC_DRV); - if (netif_carrier_ok(net)) - { - memset(&net_device_ctx->stats, 0 , sizeof(struct net_device_stats)); + if (netif_carrier_ok(net)) { + memset(&net_device_ctx->stats, 0, + sizeof(struct net_device_stats)); /* Open up the device */ ret = net_drv_obj->OnOpen(device_obj); - if (ret != 0) - { - DPRINT_ERR(NETVSC_DRV, "unable to open device (ret %d).", ret); + if (ret != 0) { + DPRINT_ERR(NETVSC_DRV, + "unable to open device (ret %d).", ret); return ret; } netif_start_queue(net); - } - else - { + } else { DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down."); } @@ -338,10 +331,12 @@ Desc: Close the specified interface device --*/ static int netvsc_close(struct net_device *net) { - int ret=0; + int ret = 0; struct net_device_context *net_device_ctx = netdev_priv(net); - struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver); - struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(net_device_ctx->device_ctx->device.driver); + struct netvsc_driver_context *net_drv_ctx = + (struct netvsc_driver_context *)driver_ctx; NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj; struct hv_device *device_obj = &net_device_ctx->device_ctx->device_obj; @@ -351,8 +346,7 @@ static int netvsc_close(struct net_device *net) netif_stop_queue(net); ret = net_drv_obj->OnClose(device_obj); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret); } @@ -361,7 +355,6 @@ static int netvsc_close(struct net_device *net) return ret; } - /*++ Name: netvsc_xmit_completion() @@ -371,23 +364,24 @@ Desc: Send completion processing --*/ static void netvsc_xmit_completion(void *context) { - NETVSC_PACKET *packet = (NETVSC_PACKET *)context; - struct sk_buff *skb = (struct sk_buff *)(unsigned long)packet->Completion.Send.SendCompletionTid; - struct net_device* net; + NETVSC_PACKET *packet = (NETVSC_PACKET *) context; + struct sk_buff *skb = + (struct sk_buff *)(unsigned long)packet->Completion.Send. + SendCompletionTid; + struct net_device *net; DPRINT_ENTER(NETVSC_DRV); kfree(packet); - if (skb) - { + if (skb) { net = skb->dev; dev_kfree_skb_any(skb); - if (netif_queue_stopped(net)) - { - DPRINT_INFO(NETVSC_DRV, "net device (%p) waking up...", net); + if (netif_queue_stopped(net)) { + DPRINT_INFO(NETVSC_DRV, "net device (%p) waking up...", + net); netif_wake_queue(net); } @@ -403,18 +397,20 @@ Name: netvsc_start_xmit() Desc: Start a send --*/ -static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net) +static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) { - int ret=0; + int ret = 0; struct net_device_context *net_device_ctx = netdev_priv(net); - struct driver_context *driver_ctx = driver_to_driver_context(net_device_ctx->device_ctx->device.driver); - struct netvsc_driver_context *net_drv_ctx = (struct netvsc_driver_context*)driver_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(net_device_ctx->device_ctx->device.driver); + struct netvsc_driver_context *net_drv_ctx = + (struct netvsc_driver_context *)driver_ctx; NETVSC_DRIVER_OBJECT *net_drv_obj = &net_drv_ctx->drv_obj; - int i=0; - NETVSC_PACKET* packet; + int i = 0; + NETVSC_PACKET *packet; int num_frags; - int retries=0; + int retries = 0; DPRINT_ENTER(NETVSC_DRV); @@ -422,20 +418,26 @@ static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net) ASSERT(skb_shinfo(skb)->frag_list == NULL); ASSERT(skb->dev == net); - DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d", skb->len, skb->data_len); + DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d", skb->len, + skb->data_len); /* Add 1 for skb->data and any additional ones requested */ - num_frags = skb_shinfo(skb)->nr_frags + 1 + net_drv_obj->AdditionalRequestPageBufferCount; + num_frags = + skb_shinfo(skb)->nr_frags + 1 + + net_drv_obj->AdditionalRequestPageBufferCount; /* Allocate a netvsc packet based on # of frags. */ - packet = kzalloc(sizeof(NETVSC_PACKET) + (num_frags * sizeof(PAGE_BUFFER)) + net_drv_obj->RequestExtSize, GFP_ATOMIC); - if (!packet) - { + packet = + kzalloc(sizeof(NETVSC_PACKET) + (num_frags * sizeof(PAGE_BUFFER)) + + net_drv_obj->RequestExtSize, GFP_ATOMIC); + if (!packet) { DPRINT_ERR(NETVSC_DRV, "unable to allocate NETVSC_PACKET"); return -1; } - packet->Extension = (void*)(unsigned long)packet + sizeof(NETVSC_PACKET) + (num_frags * sizeof(PAGE_BUFFER)) ; + packet->Extension = + (void *)(unsigned long)packet + sizeof(NETVSC_PACKET) + + (num_frags * sizeof(PAGE_BUFFER)); /* Setup the rndis header */ packet->PageBufferCount = num_frags; @@ -445,20 +447,36 @@ static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net) /* Initialize it from the skb */ ASSERT(skb->data); - packet->TotalDataBufferLength = skb->len; + packet->TotalDataBufferLength = skb->len; /* Start filling in the page buffers starting at AdditionalRequestPageBufferCount offset */ - packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Pfn = virt_to_phys(skb->data) >> PAGE_SHIFT; - packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Offset = (unsigned long)skb->data & (PAGE_SIZE -1); - packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Length = skb->len - skb->data_len; + packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount].Pfn = + virt_to_phys(skb->data) >> PAGE_SHIFT; + packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount]. + Offset = (unsigned long)skb->data & (PAGE_SIZE - 1); + packet->PageBuffers[net_drv_obj->AdditionalRequestPageBufferCount]. + Length = skb->len - skb->data_len; ASSERT((skb->len - skb->data_len) <= PAGE_SIZE); - for (i=net_drv_obj->AdditionalRequestPageBufferCount+1; i<num_frags; i++) - { - packet->PageBuffers[i].Pfn = page_to_pfn(skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].page); - packet->PageBuffers[i].Offset = skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].page_offset; - packet->PageBuffers[i].Length = skb_shinfo(skb)->frags[i-(net_drv_obj->AdditionalRequestPageBufferCount+1)].size; + for (i = net_drv_obj->AdditionalRequestPageBufferCount + 1; + i < num_frags; i++) { + packet->PageBuffers[i].Pfn = + page_to_pfn(skb_shinfo(skb)-> + frags[i - + (net_drv_obj-> + AdditionalRequestPageBufferCount + + 1)].page); + packet->PageBuffers[i].Offset = + skb_shinfo(skb)->frags[i - + (net_drv_obj-> + AdditionalRequestPageBufferCount + + 1)].page_offset; + packet->PageBuffers[i].Length = + skb_shinfo(skb)->frags[i - + (net_drv_obj-> + AdditionalRequestPageBufferCount + + 1)].size; } /* Set the completion routine */ @@ -467,26 +485,27 @@ static int netvsc_start_xmit (struct sk_buff *skb, struct net_device *net) packet->Completion.Send.SendCompletionTid = (unsigned long)skb; retry_send: - ret = net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, packet); + ret = + net_drv_obj->OnSend(&net_device_ctx->device_ctx->device_obj, + packet); - if (ret == 0) - { + if (ret == 0) { ret = NETDEV_TX_OK; net_device_ctx->stats.tx_bytes += skb->len; net_device_ctx->stats.tx_packets++; - } - else - { + } else { retries++; - if (retries < 4) - { - DPRINT_ERR(NETVSC_DRV, "unable to send...retrying %d...", retries); + if (retries < 4) { + DPRINT_ERR(NETVSC_DRV, + "unable to send...retrying %d...", retries); udelay(100); goto retry_send; } /* no more room or we are shutting down */ - DPRINT_ERR(NETVSC_DRV, "unable to send (%d)...marking net device (%p) busy", ret, net); + DPRINT_ERR(NETVSC_DRV, + "unable to send (%d)...marking net device (%p) busy", + ret, net); DPRINT_INFO(NETVSC_DRV, "net device (%p) stopping", net); ret = NETDEV_TX_BUSY; @@ -498,16 +517,17 @@ retry_send: packet->Completion.Send.SendCompletionTid = 0; /* Release the resources since we will not get any send completion */ - netvsc_xmit_completion((void*)packet); + netvsc_xmit_completion((void *)packet); } - DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu", net_device_ctx->stats.tx_packets, net_device_ctx->stats.tx_bytes); + DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu", + net_device_ctx->stats.tx_packets, + net_device_ctx->stats.tx_bytes); DPRINT_EXIT(NETVSC_DRV); return ret; } - /*++ Name: netvsc_linkstatus_callback() @@ -515,33 +535,30 @@ Name: netvsc_linkstatus_callback() Desc: Link up/down notification --*/ -static void netvsc_linkstatus_callback(struct hv_device *device_obj, unsigned int status) +static void netvsc_linkstatus_callback(struct hv_device *device_obj, + unsigned int status) { - struct device_context* device_ctx = to_device_context(device_obj); - struct net_device* net = dev_get_drvdata(&device_ctx->device); + struct device_context *device_ctx = to_device_context(device_obj); + struct net_device *net = dev_get_drvdata(&device_ctx->device); DPRINT_ENTER(NETVSC_DRV); - if (!net) - { - DPRINT_ERR(NETVSC_DRV, "got link status but net device not initialized yet"); + if (!net) { + DPRINT_ERR(NETVSC_DRV, + "got link status but net device not initialized yet"); return; } - if (status == 1) - { + if (status == 1) { netif_carrier_on(net); netif_wake_queue(net); - } - else - { + } else { netif_carrier_off(net); netif_stop_queue(net); } DPRINT_EXIT(NETVSC_DRV); } - /*++ Name: netvsc_recv_callback() @@ -549,23 +566,24 @@ Name: netvsc_recv_callback() Desc: Callback when we receive a packet from the "wire" on the specify device --*/ -static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* packet) +static int netvsc_recv_callback(struct hv_device *device_obj, + NETVSC_PACKET * packet) { - int ret=0; + int ret = 0; struct device_context *device_ctx = to_device_context(device_obj); struct net_device *net = dev_get_drvdata(&device_ctx->device); struct net_device_context *net_device_ctx; struct sk_buff *skb; void *data; - int i=0; + int i = 0; unsigned long flags; DPRINT_ENTER(NETVSC_DRV); - if (!net) - { - DPRINT_ERR(NETVSC_DRV, "got receive callback but net device not initialized yet"); + if (!net) { + DPRINT_ERR(NETVSC_DRV, + "got receive callback but net device not initialized yet"); return 0; } @@ -573,7 +591,7 @@ static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* pac /* Allocate a skb - TODO preallocate this */ /* skb = alloc_skb(packet->TotalDataBufferLength, GFP_ATOMIC); */ - skb = dev_alloc_skb(packet->TotalDataBufferLength + 2); /* Pad 2-bytes to align IP header to 16 bytes */ + skb = dev_alloc_skb(packet->TotalDataBufferLength + 2); /* Pad 2-bytes to align IP header to 16 bytes */ ASSERT(skb); skb_reserve(skb, 2); skb->dev = net; @@ -583,14 +601,18 @@ static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* pac /* Copy to skb. This copy is needed here since the memory pointed by NETVSC_PACKET */ /* cannot be deallocated */ - for (i=0; i<packet->PageBufferCount; i++) - { - data = kmap_atomic(pfn_to_page(packet->PageBuffers[i].Pfn), KM_IRQ1); - data = (void*)(unsigned long)data + packet->PageBuffers[i].Offset; - - memcpy(skb_put(skb, packet->PageBuffers[i].Length), data, packet->PageBuffers[i].Length); - - kunmap_atomic((void*)((unsigned long)data - packet->PageBuffers[i].Offset), KM_IRQ1); + for (i = 0; i < packet->PageBufferCount; i++) { + data = + kmap_atomic(pfn_to_page(packet->PageBuffers[i].Pfn), + KM_IRQ1); + data = + (void *)(unsigned long)data + packet->PageBuffers[i].Offset; + + memcpy(skb_put(skb, packet->PageBuffers[i].Length), data, + packet->PageBuffers[i].Length); + + kunmap_atomic((void *)((unsigned long)data - + packet->PageBuffers[i].Offset), KM_IRQ1); } local_irq_restore(flags); @@ -602,8 +624,7 @@ static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* pac /* Pass the skb back up. Network stack will deallocate the skb when it is done */ ret = netif_rx(skb); - switch (ret) - { + switch (ret) { case NET_RX_DROP: net_device_ctx->stats.rx_dropped++; break; @@ -613,7 +634,9 @@ static int netvsc_recv_callback(struct hv_device *device_obj, NETVSC_PACKET* pac break; } - DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu", net_device_ctx->stats.rx_packets, net_device_ctx->stats.rx_bytes); + DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu", + net_device_ctx->stats.rx_packets, + net_device_ctx->stats.rx_bytes); DPRINT_EXIT(NETVSC_DRV); @@ -624,7 +647,7 @@ static int netvsc_drv_exit_cb(struct device *dev, void *data) { struct device **curr = (struct device **)data; *curr = dev; - return 1; /* stop iterating */ + return 1; /* stop iterating */ } /*++ @@ -636,32 +659,31 @@ Desc: --*/ void netvsc_drv_exit(void) { - NETVSC_DRIVER_OBJECT *netvsc_drv_obj=&g_netvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_netvsc_drv.drv_ctx; - struct device *current_dev=NULL; + NETVSC_DRIVER_OBJECT *netvsc_drv_obj = &g_netvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; + struct device *current_dev = NULL; int ret; DPRINT_ENTER(NETVSC_DRV); - while (1) - { + while (1) { current_dev = NULL; /* Get the device */ ret = driver_for_each_device(&drv_ctx->driver, NULL, - (void *) ¤t_dev, + (void *)¤t_dev, netvsc_drv_exit_cb); if (ret) DPRINT_WARN(NETVSC_DRV, "driver_for_each_device returned %d", ret); - if (current_dev == NULL) break; /* Initiate removal from the top-down */ - DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...", current_dev); + DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...", + current_dev); device_unregister(current_dev); } diff --git a/drivers/staging/hv/osd.c b/drivers/staging/hv/osd.c index 35c9ac2..39bb713 100644 --- a/drivers/staging/hv/osd.c +++ b/drivers/staging/hv/osd.c @@ -46,51 +46,47 @@ #include "include/osd.h" - /* Data types */ - typedef struct _WORKITEM { struct work_struct work; PFN_WORKITEM_CALLBACK callback; - void* context; + void *context; } WORKITEM; - -void BitSet(unsigned int* addr, int bit) +void BitSet(unsigned int *addr, int bit) { - set_bit(bit, (unsigned long*)addr); + set_bit(bit, (unsigned long *)addr); } -int BitTest(unsigned int* addr, int bit) +int BitTest(unsigned int *addr, int bit) { - return test_bit(bit, (unsigned long*)addr); + return test_bit(bit, (unsigned long *)addr); } -void BitClear(unsigned int* addr, int bit) +void BitClear(unsigned int *addr, int bit) { - clear_bit(bit, (unsigned long*)addr); + clear_bit(bit, (unsigned long *)addr); } -int BitTestAndClear(unsigned int* addr, int bit) +int BitTestAndClear(unsigned int *addr, int bit) { - return test_and_clear_bit(bit, (unsigned long*)addr); + return test_and_clear_bit(bit, (unsigned long *)addr); } -int BitTestAndSet(unsigned int* addr, int bit) +int BitTestAndSet(unsigned int *addr, int bit) { - return test_and_set_bit(bit, (unsigned long*)addr); + return test_and_set_bit(bit, (unsigned long *)addr); } - int InterlockedIncrement(int *val) { - return atomic_inc_return((atomic_t*)val); + return atomic_inc_return((atomic_t *) val); } int InterlockedDecrement(int *val) { - return atomic_dec_return((atomic_t*)val); + return atomic_dec_return((atomic_t *) val); } #ifndef atomic_cmpxchg @@ -99,29 +95,31 @@ int InterlockedDecrement(int *val) int InterlockedCompareExchange(int *val, int new, int curr) { /* return ((int)cmpxchg(((atomic_t*)val), curr, new)); */ - return atomic_cmpxchg((atomic_t*)val, curr, new); + return atomic_cmpxchg((atomic_t *) val, curr, new); } -void* VirtualAllocExec(unsigned int size) +void *VirtualAllocExec(unsigned int size) { #ifdef __x86_64__ return __vmalloc(size, GFP_KERNEL, PAGE_KERNEL_EXEC); #else - return __vmalloc(size, GFP_KERNEL, __pgprot(__PAGE_KERNEL & (~_PAGE_NX))); + return __vmalloc(size, GFP_KERNEL, + __pgprot(__PAGE_KERNEL & (~_PAGE_NX))); #endif } -void VirtualFree(void* VirtAddr) +void VirtualFree(void *VirtAddr) { return vfree(VirtAddr); } -void* PageAlloc(unsigned int count) +void *PageAlloc(unsigned int count) { void *p; p = (void *)__get_free_pages(GFP_KERNEL, get_order(count * PAGE_SIZE)); - if (p) memset(p, 0, count * PAGE_SIZE); + if (p) + memset(p, 0, count * PAGE_SIZE); return p; /* struct page* page = alloc_page(GFP_KERNEL|__GFP_ZERO); */ @@ -133,27 +131,26 @@ void* PageAlloc(unsigned int count) /* return p; */ } -void PageFree(void* page, unsigned int count) +void PageFree(void *page, unsigned int count) { free_pages((unsigned long)page, get_order(count * PAGE_SIZE)); /*struct page* p = virt_to_page(page); - __free_page(p);*/ + __free_page(p); */ } - -void* PageMapVirtualAddress(unsigned long Pfn) +void *PageMapVirtualAddress(unsigned long Pfn) { return kmap_atomic(pfn_to_page(Pfn), KM_IRQ0); } -void PageUnmapVirtualAddress(void* VirtAddr) +void PageUnmapVirtualAddress(void *VirtAddr) { kunmap_atomic(VirtAddr, KM_IRQ0); } void *MemMapIO(unsigned long phys, unsigned long size) { - return (void*)GetVirtualAddress(phys); /* return ioremap_nocache(phys, size); */ + return (void *)GetVirtualAddress(phys); /* return ioremap_nocache(phys, size); */ } void MemUnmapIO(void *virt) @@ -163,16 +160,15 @@ void MemUnmapIO(void *virt) void TimerCallback(unsigned long data) { - struct osd_timer *t = (struct osd_timer *) data; + struct osd_timer *t = (struct osd_timer *)data; t->callback(t->context); } -struct osd_timer *TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context) +struct osd_timer *TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void *context) { struct osd_timer *t = kmalloc(sizeof(struct osd_timer), GFP_KERNEL); - if (!t) - { + if (!t) { return NULL; } @@ -205,9 +201,9 @@ void TimerClose(struct osd_timer *t) struct osd_waitevent *WaitEventCreate(void) { - struct osd_waitevent *wait = kmalloc(sizeof(struct osd_waitevent), GFP_KERNEL); - if (!wait) - { + struct osd_waitevent *wait = + kmalloc(sizeof(struct osd_waitevent), GFP_KERNEL); + if (!wait) { return NULL; } @@ -229,17 +225,16 @@ void WaitEventSet(struct osd_waitevent *waitEvent) int WaitEventWait(struct osd_waitevent *waitEvent) { - int ret=0; + int ret = 0; - ret = wait_event_interruptible(waitEvent->event, - waitEvent->condition); + ret = wait_event_interruptible(waitEvent->event, waitEvent->condition); waitEvent->condition = 0; return ret; } int WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs) { - int ret=0; + int ret = 0; ret = wait_event_interruptible_timeout(waitEvent->event, waitEvent->condition, @@ -248,21 +243,20 @@ int WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs) return ret; } -void* Physical2LogicalAddr(unsigned long PhysAddr) +void *Physical2LogicalAddr(unsigned long PhysAddr) { - void* logicalAddr = phys_to_virt(PhysAddr); + void *logicalAddr = phys_to_virt(PhysAddr); BUG_ON(!virt_addr_valid(logicalAddr)); return logicalAddr; } -unsigned long Logical2PhysicalAddr(void * LogicalAddr) +unsigned long Logical2PhysicalAddr(void *LogicalAddr) { BUG_ON(!virt_addr_valid(LogicalAddr)); return virt_to_phys(LogicalAddr); } - -unsigned long Virtual2Physical(void * VirtAddr) +unsigned long Virtual2Physical(void *VirtAddr) { unsigned long pfn = vmalloc_to_pfn(VirtAddr); @@ -271,7 +265,7 @@ unsigned long Virtual2Physical(void * VirtAddr) void WorkItemCallback(struct work_struct *work) { - WORKITEM* w = (WORKITEM*)work; + WORKITEM *w = (WORKITEM *) work; w->callback(w->context); @@ -294,31 +288,26 @@ void WorkQueueClose(struct workqueue_struct *hWorkQueue) } int WorkQueueQueueWorkItem(struct workqueue_struct *hWorkQueue, - PFN_WORKITEM_CALLBACK workItem, - void* context) + PFN_WORKITEM_CALLBACK workItem, void *context) { - WORKITEM* w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC); - if (!w) - { + WORKITEM *w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC); + if (!w) { return -1; } - w->callback = workItem, - w->context = context; + w->callback = workItem, w->context = context; INIT_WORK(&w->work, WorkItemCallback); return queue_work(hWorkQueue, &w->work); } -void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context) +void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void *context) { - WORKITEM* w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC); - if (!w) - { + WORKITEM *w = kmalloc(sizeof(WORKITEM), GFP_ATOMIC); + if (!w) { return; } - w->callback = workItem, - w->context = context; + w->callback = workItem, w->context = context; INIT_WORK(&w->work, WorkItemCallback); schedule_work(&w->work); } diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index 120ec52..f25db63 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -41,59 +41,65 @@ #include "include/StorVscApi.h" - /* #defines */ - - /* Data types */ struct host_device_context { - struct work_struct host_rescan_work; /* must be 1st field */ - struct device_context *device_ctx; /* point back to our device context */ - struct kmem_cache *request_pool; - unsigned int port; - unsigned char path; - unsigned char target; + struct work_struct host_rescan_work; /* must be 1st field */ + struct device_context *device_ctx; /* point back to our device context */ + struct kmem_cache *request_pool; + unsigned int port; + unsigned char path; + unsigned char target; }; struct storvsc_cmd_request { - struct list_head entry; - struct scsi_cmnd *cmd; + struct list_head entry; + struct scsi_cmnd *cmd; unsigned int bounce_sgl_count; - struct scatterlist *bounce_sgl; + struct scatterlist *bounce_sgl; - STORVSC_REQUEST request; + STORVSC_REQUEST request; /* !!!DO NOT ADD ANYTHING BELOW HERE!!! */ /* The extension buffer falls right here and is pointed to by request.Extension; */ }; struct storvsc_driver_context { /* !! These must be the first 2 fields !! */ - struct driver_context drv_ctx; - STORVSC_DRIVER_OBJECT drv_obj; + struct driver_context drv_ctx; + STORVSC_DRIVER_OBJECT drv_obj; }; /* Static decl */ static int storvsc_probe(struct device *dev); -static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scsi_cmnd *)); +static int storvsc_queuecommand(struct scsi_cmnd *scmnd, + void (*done) (struct scsi_cmnd *)); static int storvsc_device_alloc(struct scsi_device *); static int storvsc_device_configure(struct scsi_device *); static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd); static void storvsc_host_rescan_callback(struct work_struct *work); -static void storvsc_host_rescan(struct hv_device* device_obj); +static void storvsc_host_rescan(struct hv_device *device_obj); static int storvsc_remove(struct device *dev); -static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count, unsigned int len); -static void destroy_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count); +static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, + unsigned int sg_count, + unsigned int len); +static void destroy_bounce_buffer(struct scatterlist *sgl, + unsigned int sg_count); static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count); -static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count); -static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count); - -static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], unsigned int *lun_count); -static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev, sector_t capacity, int *info); - +static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, + struct scatterlist *bounce_sgl, + unsigned int orig_sgl_count); +static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, + struct scatterlist *bounce_sgl, + unsigned int orig_sgl_count); + +static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], + unsigned int *lun_count); +static int storvsc_get_chs(struct scsi_device *sdev, struct block_device *bdev, + sector_t capacity, int *info); static int storvsc_ringbuffer_size = STORVSC_RING_BUFFER_SIZE; @@ -102,27 +108,26 @@ static struct storvsc_driver_context g_storvsc_drv; /* Scsi driver */ static struct scsi_host_template scsi_driver = { - .module = THIS_MODULE, - .name = "storvsc_host_t", - .bios_param = storvsc_get_chs, - .queuecommand = storvsc_queuecommand, - .eh_host_reset_handler = storvsc_host_reset_handler, - .slave_alloc = storvsc_device_alloc, - .slave_configure = storvsc_device_configure, - .cmd_per_lun = 1, - .can_queue = STORVSC_MAX_IO_REQUESTS*STORVSC_MAX_TARGETS, /* 64 max_queue * 1 target */ - .this_id = -1, + .module = THIS_MODULE, + .name = "storvsc_host_t", + .bios_param = storvsc_get_chs, + .queuecommand = storvsc_queuecommand, + .eh_host_reset_handler = storvsc_host_reset_handler, + .slave_alloc = storvsc_device_alloc, + .slave_configure = storvsc_device_configure, + .cmd_per_lun = 1, + .can_queue = STORVSC_MAX_IO_REQUESTS * STORVSC_MAX_TARGETS, /* 64 max_queue * 1 target */ + .this_id = -1, /* no use setting to 0 since ll_blk_rw reset it to 1 */ - .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT,/* currently 32 */ + .sg_tablesize = MAX_MULTIPAGE_BUFFER_COUNT, /* currently 32 */ /* ENABLE_CLUSTERING allows mutiple physically contig bio_vecs to merge into 1 sg element. If set, we must */ /* limit the max_segment_size to PAGE_SIZE, otherwise we may get 1 sg element that represents multiple */ /* physically contig pfns (ie sg[x].length > PAGE_SIZE). */ - .use_clustering = ENABLE_CLUSTERING, + .use_clustering = ENABLE_CLUSTERING, /* Make sure we dont get a sg segment crosses a page boundary */ - .dma_boundary = PAGE_SIZE-1, + .dma_boundary = PAGE_SIZE - 1, }; - /*++ Name: storvsc_drv_init() @@ -132,9 +137,9 @@ Desc: StorVsc driver initialization. --*/ int storvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) { - int ret=0; - STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_storvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_storvsc_drv.drv_ctx; + int ret = 0; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &g_storvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; DPRINT_ENTER(STORVSC_DRV); @@ -146,17 +151,23 @@ int storvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) /* Callback to client driver to complete the initialization */ pfn_drv_init(&storvsc_drv_obj->Base); - DPRINT_INFO(STORVSC_DRV, "request extension size %u, max outstanding reqs %u", storvsc_drv_obj->RequestExtSize, storvsc_drv_obj->MaxOutstandingRequestsPerChannel); - - if (storvsc_drv_obj->MaxOutstandingRequestsPerChannel < STORVSC_MAX_IO_REQUESTS) - { - DPRINT_ERR(STORVSC_DRV, "The number of outstanding io requests (%d) is larger than that supported (%d) internally.", - STORVSC_MAX_IO_REQUESTS, storvsc_drv_obj->MaxOutstandingRequestsPerChannel); + DPRINT_INFO(STORVSC_DRV, + "request extension size %u, max outstanding reqs %u", + storvsc_drv_obj->RequestExtSize, + storvsc_drv_obj->MaxOutstandingRequestsPerChannel); + + if (storvsc_drv_obj->MaxOutstandingRequestsPerChannel < + STORVSC_MAX_IO_REQUESTS) { + DPRINT_ERR(STORVSC_DRV, + "The number of outstanding io requests (%d) is larger than that supported (%d) internally.", + STORVSC_MAX_IO_REQUESTS, + storvsc_drv_obj->MaxOutstandingRequestsPerChannel); return -1; } drv_ctx->driver.name = storvsc_drv_obj->Base.name; - memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, sizeof(GUID)); + memcpy(&drv_ctx->class_id, &storvsc_drv_obj->Base.deviceType, + sizeof(GUID)); drv_ctx->probe = storvsc_probe; drv_ctx->remove = storvsc_remove; @@ -169,12 +180,11 @@ int storvsc_drv_init(PFN_DRIVERINITIALIZE pfn_drv_init) return ret; } - static int storvsc_drv_exit_cb(struct device *dev, void *data) { struct device **curr = (struct device **)data; *curr = dev; - return 1; /* stop iterating */ + return 1; /* stop iterating */ } /*++ @@ -186,20 +196,19 @@ Desc: --*/ void storvsc_drv_exit(void) { - STORVSC_DRIVER_OBJECT *storvsc_drv_obj=&g_storvsc_drv.drv_obj; - struct driver_context *drv_ctx=&g_storvsc_drv.drv_ctx; - struct device *current_dev=NULL; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &g_storvsc_drv.drv_obj; + struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; + struct device *current_dev = NULL; int ret; DPRINT_ENTER(STORVSC_DRV); - while (1) - { + while (1) { current_dev = NULL; /* Get the device */ ret = driver_for_each_device(&drv_ctx->driver, NULL, - (void *) ¤t_dev, + (void *)¤t_dev, storvsc_drv_exit_cb); if (ret) @@ -232,11 +241,13 @@ Desc: Add a new device for this driver --*/ static int storvsc_probe(struct device *device) { - int ret=0; + int ret = 0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct storvsc_driver_context *storvsc_drv_ctx = + (struct storvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); struct hv_device *device_obj = &device_ctx->device_obj; @@ -250,32 +261,31 @@ static int storvsc_probe(struct device *device) if (!storvsc_drv_obj->Base.OnDeviceAdd) return -1; - host = scsi_host_alloc(&scsi_driver, sizeof(struct host_device_context)); - if (!host) - { + host = + scsi_host_alloc(&scsi_driver, sizeof(struct host_device_context)); + if (!host) { DPRINT_ERR(STORVSC_DRV, "unable to allocate scsi host object"); return -ENOMEM; } dev_set_drvdata(device, host); - host_device_ctx = (struct host_device_context*)host->hostdata; + host_device_ctx = (struct host_device_context *)host->hostdata; memset(host_device_ctx, 0, sizeof(struct host_device_context)); host_device_ctx->port = host->host_no; host_device_ctx->device_ctx = device_ctx; - INIT_WORK(&host_device_ctx->host_rescan_work, storvsc_host_rescan_callback); + INIT_WORK(&host_device_ctx->host_rescan_work, + storvsc_host_rescan_callback); host_device_ctx->request_pool = kmem_cache_create (dev_name(&device_ctx->device), - sizeof(struct storvsc_cmd_request) + storvsc_drv_obj->RequestExtSize, - 0, - SLAB_HWCACHE_ALIGN, NULL); + sizeof(struct storvsc_cmd_request) + + storvsc_drv_obj->RequestExtSize, 0, SLAB_HWCACHE_ALIGN, NULL); - if (!host_device_ctx->request_pool) - { + if (!host_device_ctx->request_pool) { scsi_host_put(host); DPRINT_EXIT(STORVSC_DRV); @@ -284,9 +294,9 @@ static int storvsc_probe(struct device *device) device_info.PortNumber = host->host_no; /* Call to the vsc driver to add the device */ - ret = storvsc_drv_obj->Base.OnDeviceAdd(device_obj, (void*)&device_info); - if (ret != 0) - { + ret = + storvsc_drv_obj->Base.OnDeviceAdd(device_obj, (void *)&device_info); + if (ret != 0) { DPRINT_ERR(STORVSC_DRV, "unable to add scsi vsc device"); kmem_cache_destroy(host_device_ctx->request_pool); scsi_host_put(host); @@ -300,13 +310,12 @@ static int storvsc_probe(struct device *device) host_device_ctx->target = device_info.TargetId; host->max_lun = STORVSC_MAX_LUNS_PER_TARGET; /* max # of devices per target */ - host->max_id = STORVSC_MAX_TARGETS; /* max # of targets per channel */ - host->max_channel = STORVSC_MAX_CHANNELS -1; /* max # of channels */ + host->max_id = STORVSC_MAX_TARGETS; /* max # of targets per channel */ + host->max_channel = STORVSC_MAX_CHANNELS - 1; /* max # of channels */ /* Register the HBA and start the scsi bus scan */ ret = scsi_add_host(host, device); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(STORVSC_DRV, "unable to add scsi host device"); storvsc_drv_obj->Base.OnDeviceRemove(device_obj); @@ -325,7 +334,6 @@ static int storvsc_probe(struct device *device) return ret; } - /*++ Name: storvsc_remove() @@ -335,37 +343,37 @@ Desc: Callback when our device is removed --*/ static int storvsc_remove(struct device *device) { - int ret=0; + int ret = 0; - struct driver_context *driver_ctx = driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; + struct driver_context *driver_ctx = + driver_to_driver_context(device->driver); + struct storvsc_driver_context *storvsc_drv_ctx = + (struct storvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; struct device_context *device_ctx = device_to_device_context(device); struct hv_device *device_obj = &device_ctx->device_obj; struct Scsi_Host *host = dev_get_drvdata(device); - struct host_device_context *host_device_ctx=(struct host_device_context*)host->hostdata; - + struct host_device_context *host_device_ctx = + (struct host_device_context *)host->hostdata; DPRINT_ENTER(STORVSC_DRV); - if (!storvsc_drv_obj->Base.OnDeviceRemove) - { + if (!storvsc_drv_obj->Base.OnDeviceRemove) { DPRINT_EXIT(STORVSC_DRV); return -1; } /* Call to the vsc driver to let it know that the device is being removed */ ret = storvsc_drv_obj->Base.OnDeviceRemove(device_obj); - if (ret != 0) - { + if (ret != 0) { /* TODO: */ - DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", ret); + DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", + ret); } - if (host_device_ctx->request_pool) - { + if (host_device_ctx->request_pool) { kmem_cache_destroy(host_device_ctx->request_pool); host_device_ctx->request_pool = NULL; } @@ -388,36 +396,41 @@ Name: storvsc_commmand_completion() Desc: Command completion processing --*/ -static void storvsc_commmand_completion(STORVSC_REQUEST* request) +static void storvsc_commmand_completion(STORVSC_REQUEST * request) { - struct storvsc_cmd_request *cmd_request = (struct storvsc_cmd_request*)request->Context; + struct storvsc_cmd_request *cmd_request = + (struct storvsc_cmd_request *)request->Context; struct scsi_cmnd *scmnd = cmd_request->cmd; - struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata; - void (*scsi_done_fn)(struct scsi_cmnd *); + struct host_device_context *host_device_ctx = + (struct host_device_context *)scmnd->device->host->hostdata; + void (*scsi_done_fn) (struct scsi_cmnd *); struct scsi_sense_hdr sense_hdr; ASSERT(request == &cmd_request->request); - ASSERT((unsigned long)scmnd->host_scribble == (unsigned long)cmd_request); + ASSERT((unsigned long)scmnd->host_scribble == + (unsigned long)cmd_request); ASSERT(scmnd); ASSERT(scmnd->scsi_done); DPRINT_ENTER(STORVSC_DRV); - if (cmd_request->bounce_sgl_count)/* using bounce buffer */ - { + if (cmd_request->bounce_sgl_count) { /* using bounce buffer */ /* printk("copy_from_bounce_buffer\n"); */ /* FIXME: We can optimize on writes by just skipping this */ - copy_from_bounce_buffer(scsi_sglist(scmnd), cmd_request->bounce_sgl, scsi_sg_count(scmnd)); - destroy_bounce_buffer(cmd_request->bounce_sgl, cmd_request->bounce_sgl_count); + copy_from_bounce_buffer(scsi_sglist(scmnd), + cmd_request->bounce_sgl, + scsi_sg_count(scmnd)); + destroy_bounce_buffer(cmd_request->bounce_sgl, + cmd_request->bounce_sgl_count); } scmnd->result = request->Status; - if (scmnd->result) - { - if (scsi_normalize_sense(scmnd->sense_buffer, request->SenseBufferSize, &sense_hdr)) - { + if (scmnd->result) { + if (scsi_normalize_sense + (scmnd->sense_buffer, request->SenseBufferSize, + &sense_hdr)) { scsi_print_sense_hdr("storvsc", &sense_hdr); } } @@ -440,29 +453,23 @@ static void storvsc_commmand_completion(STORVSC_REQUEST* request) static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) { - int i=0; + int i = 0; /* No need to check */ if (sg_count < 2) return -1; /* We have at least 2 sg entries */ - for ( i=0; i<sg_count; i++ ) - { - if (i == 0) /* make sure 1st one does not have hole */ - { + for (i = 0; i < sg_count; i++) { + if (i == 0) { /* make sure 1st one does not have hole */ if (sgl[i].offset + sgl[i].length != PAGE_SIZE) return i; - } - else if (i == sg_count - 1) /* make sure last one does not have hole */ - { + } else if (i == sg_count - 1) { /* make sure last one does not have hole */ if (sgl[i].offset != 0) return i; - } - else /* make sure no hole in the middle */ - { - if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0) - { + } else { /* make sure no hole in the middle */ + + if (sgl[i].length != PAGE_SIZE || sgl[i].offset != 0) { return i; } } @@ -470,26 +477,25 @@ static int do_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) return -1; } -static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count, unsigned int len) +static struct scatterlist *create_bounce_buffer(struct scatterlist *sgl, + unsigned int sg_count, + unsigned int len) { int i; - int num_pages=0; - struct scatterlist* bounce_sgl; + int num_pages = 0; + struct scatterlist *bounce_sgl; struct page *page_buf; num_pages = ALIGN_UP(len, PAGE_SIZE) >> PAGE_SHIFT; bounce_sgl = kcalloc(num_pages, sizeof(struct scatterlist), GFP_ATOMIC); - if (!bounce_sgl) - { + if (!bounce_sgl) { return NULL; } - for(i=0; i<num_pages; i++) - { + for (i = 0; i < num_pages; i++) { page_buf = alloc_page(GFP_ATOMIC); - if (!page_buf) - { + if (!page_buf) { goto cleanup; } sg_set_page(&bounce_sgl[i], page_buf, 0, 0); @@ -502,15 +508,14 @@ cleanup: return NULL; } -static void destroy_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count) +static void destroy_bounce_buffer(struct scatterlist *sgl, + unsigned int sg_count) { int i; struct page *page_buf; - for (i=0; i<sg_count; i++) - { + for (i = 0; i < sg_count; i++) { if ((page_buf = sg_page((&sgl[i]))) != NULL) - { __free_page(page_buf); } @@ -520,21 +525,24 @@ static void destroy_bounce_buffer(struct scatterlist *sgl, unsigned int sg_count } /* Assume the bounce_sgl has enough room ie using the create_bounce_buffer() */ -static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count) +static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, + struct scatterlist *bounce_sgl, + unsigned int orig_sgl_count) { - int i=0,j=0; + int i = 0, j = 0; unsigned long src, dest; unsigned int srclen, destlen, copylen; - unsigned int total_copied=0; - unsigned long bounce_addr=0; - unsigned long src_addr=0; + unsigned int total_copied = 0; + unsigned long bounce_addr = 0; + unsigned long src_addr = 0; unsigned long flags; local_irq_save(flags); - for (i=0; i<orig_sgl_count; i++) - { - src_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), KM_IRQ0) + orig_sgl[i].offset; + for (i = 0; i < orig_sgl_count; i++) { + src_addr = + (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), + KM_IRQ0) + orig_sgl[i].offset; src = src_addr; srclen = orig_sgl[i].length; @@ -543,43 +551,43 @@ static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct s ASSERT(orig_sgl[i].offset + orig_sgl[i].length <= PAGE_SIZE); - if (j == 0) - { - bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); + if (j == 0) { + bounce_addr = + (unsigned long) + kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); } - while (srclen) - { + while (srclen) { /* assume bounce offset always == 0 */ dest = bounce_addr + bounce_sgl[j].length; destlen = PAGE_SIZE - bounce_sgl[j].length; copylen = min(srclen, destlen); - memcpy((void*)dest, (void*)src, copylen); + memcpy((void *)dest, (void *)src, copylen); total_copied += copylen; bounce_sgl[j].length += copylen; srclen -= copylen; src += copylen; - if (bounce_sgl[j].length == PAGE_SIZE) /* full..move to next entry */ - { - kunmap_atomic((void*)bounce_addr, KM_IRQ0); + if (bounce_sgl[j].length == PAGE_SIZE) { /* full..move to next entry */ + kunmap_atomic((void *)bounce_addr, KM_IRQ0); j++; /* if we need to use another bounce buffer */ - if (srclen || i != orig_sgl_count -1) - { - bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); + if (srclen || i != orig_sgl_count - 1) { + bounce_addr = + (unsigned long) + kmap_atomic(sg_page + ((&bounce_sgl[j])), + KM_IRQ0); } - } - else if (srclen == 0 && i == orig_sgl_count -1) /* unmap the last bounce that is < PAGE_SIZE */ - { - kunmap_atomic((void*)bounce_addr, KM_IRQ0); + } else if (srclen == 0 && i == orig_sgl_count - 1) { /* unmap the last bounce that is < PAGE_SIZE */ + kunmap_atomic((void *)bounce_addr, KM_IRQ0); } } - kunmap_atomic((void*)(src_addr - orig_sgl[i].offset), KM_IRQ0); + kunmap_atomic((void *)(src_addr - orig_sgl[i].offset), KM_IRQ0); } local_irq_restore(flags); @@ -588,61 +596,65 @@ static unsigned int copy_to_bounce_buffer(struct scatterlist *orig_sgl, struct s } /* Assume the original sgl has enough room */ -static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, struct scatterlist *bounce_sgl, unsigned int orig_sgl_count) +static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, + struct scatterlist *bounce_sgl, + unsigned int orig_sgl_count) { - int i=0,j=0; + int i = 0, j = 0; unsigned long src, dest; unsigned int srclen, destlen, copylen; - unsigned int total_copied=0; - unsigned long bounce_addr=0; - unsigned long dest_addr=0; + unsigned int total_copied = 0; + unsigned long bounce_addr = 0; + unsigned long dest_addr = 0; unsigned long flags; local_irq_save(flags); - for (i=0; i<orig_sgl_count; i++) - { - dest_addr = (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), KM_IRQ0) + orig_sgl[i].offset; + for (i = 0; i < orig_sgl_count; i++) { + dest_addr = + (unsigned long)kmap_atomic(sg_page((&orig_sgl[i])), + KM_IRQ0) + orig_sgl[i].offset; dest = dest_addr; destlen = orig_sgl[i].length; ASSERT(orig_sgl[i].offset + orig_sgl[i].length <= PAGE_SIZE); - if (j == 0) - { - bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); + if (j == 0) { + bounce_addr = + (unsigned long) + kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); } - while (destlen) - { + while (destlen) { src = bounce_addr + bounce_sgl[j].offset; srclen = bounce_sgl[j].length - bounce_sgl[j].offset; copylen = min(srclen, destlen); - memcpy((void*)dest, (void*)src, copylen); + memcpy((void *)dest, (void *)src, copylen); total_copied += copylen; bounce_sgl[j].offset += copylen; destlen -= copylen; dest += copylen; - if (bounce_sgl[j].offset == bounce_sgl[j].length) /* full */ - { - kunmap_atomic((void*)bounce_addr, KM_IRQ0); + if (bounce_sgl[j].offset == bounce_sgl[j].length) { /* full */ + kunmap_atomic((void *)bounce_addr, KM_IRQ0); j++; /* if we need to use another bounce buffer */ - if (destlen || i != orig_sgl_count -1) - { - bounce_addr = (unsigned long)kmap_atomic(sg_page((&bounce_sgl[j])), KM_IRQ0); + if (destlen || i != orig_sgl_count - 1) { + bounce_addr = + (unsigned long) + kmap_atomic(sg_page + ((&bounce_sgl[j])), + KM_IRQ0); } - } - else if (destlen == 0 && i == orig_sgl_count -1) /* unmap the last bounce that is < PAGE_SIZE */ - { - kunmap_atomic((void*)bounce_addr, KM_IRQ0); + } else if (destlen == 0 && i == orig_sgl_count - 1) { /* unmap the last bounce that is < PAGE_SIZE */ + kunmap_atomic((void *)bounce_addr, KM_IRQ0); } } - kunmap_atomic((void*)(dest_addr - orig_sgl[i].offset), KM_IRQ0); + kunmap_atomic((void *)(dest_addr - orig_sgl[i].offset), + KM_IRQ0); } local_irq_restore(flags); @@ -650,7 +662,6 @@ static unsigned int copy_from_bounce_buffer(struct scatterlist *orig_sgl, struct return total_copied; } - /*++ Name: storvsc_queuecommand() @@ -658,39 +669,41 @@ Name: storvsc_queuecommand() Desc: Initiate command processing --*/ -static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scsi_cmnd *)) +static int storvsc_queuecommand(struct scsi_cmnd *scmnd, + void (*done) (struct scsi_cmnd *)) { - int ret=0; - struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata; - struct device_context *device_ctx=host_device_ctx->device_ctx; - struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver); - struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx; - STORVSC_DRIVER_OBJECT* storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; + int ret = 0; + struct host_device_context *host_device_ctx = + (struct host_device_context *)scmnd->device->host->hostdata; + struct device_context *device_ctx = host_device_ctx->device_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(device_ctx->device.driver); + struct storvsc_driver_context *storvsc_drv_ctx = + (struct storvsc_driver_context *)driver_ctx; + STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; STORVSC_REQUEST *request; struct storvsc_cmd_request *cmd_request; - unsigned int request_size=0; + unsigned int request_size = 0; int i; struct scatterlist *sgl; DPRINT_ENTER(STORVSC_DRV); - DPRINT_DBG(STORVSC_DRV, "scmnd %p dir %d, use_sg %d buf %p len %d queue depth %d tagged %d", - scmnd, - scmnd->sc_data_direction, - scsi_sg_count(scmnd), - scsi_sglist(scmnd), - scsi_bufflen(scmnd), - scmnd->device->queue_depth, - scmnd->device->tagged_supported); + DPRINT_DBG(STORVSC_DRV, + "scmnd %p dir %d, use_sg %d buf %p len %d queue depth %d tagged %d", + scmnd, scmnd->sc_data_direction, scsi_sg_count(scmnd), + scsi_sglist(scmnd), scsi_bufflen(scmnd), + scmnd->device->queue_depth, scmnd->device->tagged_supported); /* If retrying, no need to prep the cmd */ - if (scmnd->host_scribble) - { + if (scmnd->host_scribble) { ASSERT(scmnd->scsi_done != NULL); - cmd_request = (struct storvsc_cmd_request* )scmnd->host_scribble; - DPRINT_INFO(STORVSC_DRV, "retrying scmnd %p cmd_request %p", scmnd, cmd_request); + cmd_request = + (struct storvsc_cmd_request *)scmnd->host_scribble; + DPRINT_INFO(STORVSC_DRV, "retrying scmnd %p cmd_request %p", + scmnd, cmd_request); goto retry_request; } @@ -702,10 +715,12 @@ static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scs request_size = sizeof(struct storvsc_cmd_request); - cmd_request = kmem_cache_alloc(host_device_ctx->request_pool, GFP_ATOMIC); - if (!cmd_request) - { - DPRINT_ERR(STORVSC_DRV, "scmnd (%p) - unable to allocate storvsc_cmd_request...marking queue busy", scmnd); + cmd_request = + kmem_cache_alloc(host_device_ctx->request_pool, GFP_ATOMIC); + if (!cmd_request) { + DPRINT_ERR(STORVSC_DRV, + "scmnd (%p) - unable to allocate storvsc_cmd_request...marking queue busy", + scmnd); scmnd->scsi_done = NULL; return SCSI_MLQUEUE_DEVICE_BUSY; @@ -716,16 +731,17 @@ static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scs cmd_request->bounce_sgl = NULL; cmd_request->cmd = scmnd; - scmnd->host_scribble = (unsigned char*)cmd_request; + scmnd->host_scribble = (unsigned char *)cmd_request; request = &cmd_request->request; - request->Extension = (void*)((unsigned long)cmd_request + request_size); - DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, storvsc_drv_obj->RequestExtSize); + request->Extension = + (void *)((unsigned long)cmd_request + request_size); + DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, + storvsc_drv_obj->RequestExtSize); /* Build the SRB */ - switch(scmnd->sc_data_direction) - { + switch (scmnd->sc_data_direction) { case DMA_TO_DEVICE: request->Type = WRITE_TYPE; break; @@ -738,7 +754,7 @@ static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scs } request->OnIOCompletion = storvsc_commmand_completion; - request->Context = cmd_request;/* scmnd; */ + request->Context = cmd_request; /* scmnd; */ /* request->PortId = scmnd->device->channel; */ request->Host = host_device_ctx->port; @@ -753,71 +769,82 @@ static int storvsc_queuecommand(struct scsi_cmnd *scmnd, void (*done)(struct scs request->SenseBuffer = scmnd->sense_buffer; request->SenseBufferSize = SCSI_SENSE_BUFFERSIZE; - request->DataBuffer.Length = scsi_bufflen(scmnd); - if (scsi_sg_count(scmnd)) - { - sgl = (struct scatterlist*)scsi_sglist(scmnd); + if (scsi_sg_count(scmnd)) { + sgl = (struct scatterlist *)scsi_sglist(scmnd); /* check if we need to bounce the sgl */ - if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) - { - DPRINT_INFO(STORVSC_DRV, "need to bounce buffer for this scmnd %p", scmnd); - cmd_request->bounce_sgl = create_bounce_buffer(sgl, scsi_sg_count(scmnd), scsi_bufflen(scmnd)); - if (!cmd_request->bounce_sgl) - { - DPRINT_ERR(STORVSC_DRV, "unable to create bounce buffer for this scmnd %p", scmnd); + if (do_bounce_buffer(sgl, scsi_sg_count(scmnd)) != -1) { + DPRINT_INFO(STORVSC_DRV, + "need to bounce buffer for this scmnd %p", + scmnd); + cmd_request->bounce_sgl = + create_bounce_buffer(sgl, scsi_sg_count(scmnd), + scsi_bufflen(scmnd)); + if (!cmd_request->bounce_sgl) { + DPRINT_ERR(STORVSC_DRV, + "unable to create bounce buffer for this scmnd %p", + scmnd); scmnd->scsi_done = NULL; scmnd->host_scribble = NULL; - kmem_cache_free(host_device_ctx->request_pool, cmd_request); + kmem_cache_free(host_device_ctx->request_pool, + cmd_request); return SCSI_MLQUEUE_HOST_BUSY; } - cmd_request->bounce_sgl_count = ALIGN_UP(scsi_bufflen(scmnd), PAGE_SIZE) >> PAGE_SHIFT; + cmd_request->bounce_sgl_count = + ALIGN_UP(scsi_bufflen(scmnd), + PAGE_SIZE) >> PAGE_SHIFT; /* printk("bouncing buffer allocated %p original buffer %p\n", bounce_sgl, sgl); */ /* printk("copy_to_bounce_buffer\n"); */ /* FIXME: We can optimize on reads by just skipping this */ - copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl, scsi_sg_count(scmnd)); + copy_to_bounce_buffer(sgl, cmd_request->bounce_sgl, + scsi_sg_count(scmnd)); sgl = cmd_request->bounce_sgl; } request->DataBuffer.Offset = sgl[0].offset; - for (i = 0; i < scsi_sg_count(scmnd); i++ ) - { - DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d \n", i, sgl[i].length, sgl[i].offset); - request->DataBuffer.PfnArray[i] = page_to_pfn(sg_page((&sgl[i]))); + for (i = 0; i < scsi_sg_count(scmnd); i++) { + DPRINT_DBG(STORVSC_DRV, "sgl[%d] len %d offset %d \n", + i, sgl[i].length, sgl[i].offset); + request->DataBuffer.PfnArray[i] = + page_to_pfn(sg_page((&sgl[i]))); } } - else if (scsi_sglist(scmnd)) - { + else if (scsi_sglist(scmnd)) { ASSERT(scsi_bufflen(scmnd) <= PAGE_SIZE); - request->DataBuffer.Offset = virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE-1); - request->DataBuffer.PfnArray[0] = virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; - } - else - { + request->DataBuffer.Offset = + virt_to_phys(scsi_sglist(scmnd)) & (PAGE_SIZE - 1); + request->DataBuffer.PfnArray[0] = + virt_to_phys(scsi_sglist(scmnd)) >> PAGE_SHIFT; + } else { ASSERT(scsi_bufflen(scmnd) == 0); } retry_request: /* Invokes the vsc to start an IO */ - ret = storvsc_drv_obj->OnIORequest(&device_ctx->device_obj, &cmd_request->request); - if (ret == -1) /* no more space */ - { - DPRINT_ERR(STORVSC_DRV, "scmnd (%p) - queue FULL...marking queue busy", scmnd); - - if (cmd_request->bounce_sgl_count) - { + ret = + storvsc_drv_obj->OnIORequest(&device_ctx->device_obj, + &cmd_request->request); + if (ret == -1) { /* no more space */ + DPRINT_ERR(STORVSC_DRV, + "scmnd (%p) - queue FULL...marking queue busy", + scmnd); + + if (cmd_request->bounce_sgl_count) { /* FIXME: We can optimize on writes by just skipping this */ - copy_from_bounce_buffer(scsi_sglist(scmnd), cmd_request->bounce_sgl, scsi_sg_count(scmnd)); - destroy_bounce_buffer(cmd_request->bounce_sgl, cmd_request->bounce_sgl_count); + copy_from_bounce_buffer(scsi_sglist(scmnd), + cmd_request->bounce_sgl, + scsi_sg_count(scmnd)); + destroy_bounce_buffer(cmd_request->bounce_sgl, + cmd_request->bounce_sgl_count); } kmem_cache_free(host_device_ctx->request_pool, cmd_request); @@ -833,9 +860,10 @@ retry_request: return ret; } -static int storvsc_merge_bvec(struct request_queue *q, struct bvec_merge_data *bmd, struct bio_vec *bvec) +static int storvsc_merge_bvec(struct request_queue *q, + struct bvec_merge_data *bmd, struct bio_vec *bvec) { - return bvec->bv_len; /* checking done by caller. */ + return bvec->bv_len; /* checking done by caller. */ } /*++ @@ -847,7 +875,8 @@ Desc: Configure the specified scsi device --*/ static int storvsc_device_alloc(struct scsi_device *sdevice) { - DPRINT_DBG(STORVSC_DRV, "sdev (%p) - setting device flag to %d", sdevice, BLIST_SPARSELUN); + DPRINT_DBG(STORVSC_DRV, "sdev (%p) - setting device flag to %d", + sdevice, BLIST_SPARSELUN); /* This enables luns to be located sparsely. Otherwise, we may not discovered them. */ sdevice->sdev_bflags |= BLIST_SPARSELUN | BLIST_LARGELUN; return 0; @@ -855,15 +884,20 @@ static int storvsc_device_alloc(struct scsi_device *sdevice) static int storvsc_device_configure(struct scsi_device *sdevice) { - DPRINT_INFO(STORVSC_DRV, "sdev (%p) - curr queue depth %d", sdevice, sdevice->queue_depth); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) - curr queue depth %d", sdevice, + sdevice->queue_depth); - DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting queue depth to %d", sdevice, STORVSC_MAX_IO_REQUESTS); - scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, STORVSC_MAX_IO_REQUESTS); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting queue depth to %d", + sdevice, STORVSC_MAX_IO_REQUESTS); + scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, + STORVSC_MAX_IO_REQUESTS); - DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %ld", sdevice, PAGE_SIZE); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) - setting max segment size to %ld", + sdevice, PAGE_SIZE); blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE); - DPRINT_INFO(STORVSC_DRV, "sdev (%p) - adding merge bio vec routine", sdevice); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) - adding merge bio vec routine", + sdevice); blk_queue_merge_bvec(sdevice->request_queue, storvsc_merge_bvec); blk_queue_bounce_limit(sdevice->request_queue, BLK_BOUNCE_ANY); @@ -881,28 +915,32 @@ Desc: Reset the scsi HBA --*/ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd) { - int ret=SUCCESS; - struct host_device_context *host_device_ctx = (struct host_device_context*)scmnd->device->host->hostdata; + int ret = SUCCESS; + struct host_device_context *host_device_ctx = + (struct host_device_context *)scmnd->device->host->hostdata; struct device_context *device_ctx = host_device_ctx->device_ctx; - struct driver_context *driver_ctx = driver_to_driver_context(device_ctx->device.driver); - struct storvsc_driver_context *storvsc_drv_ctx = (struct storvsc_driver_context*)driver_ctx; + struct driver_context *driver_ctx = + driver_to_driver_context(device_ctx->device.driver); + struct storvsc_driver_context *storvsc_drv_ctx = + (struct storvsc_driver_context *)driver_ctx; STORVSC_DRIVER_OBJECT *storvsc_drv_obj = &storvsc_drv_ctx->drv_obj; DPRINT_ENTER(STORVSC_DRV); - DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host resetting...", scmnd->device, &device_ctx->device_obj); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host resetting...", + scmnd->device, &device_ctx->device_obj); /* Invokes the vsc to reset the host/bus */ ASSERT(storvsc_drv_obj->OnHostReset); ret = storvsc_drv_obj->OnHostReset(&device_ctx->device_obj); - if (ret != 0) - { + if (ret != 0) { DPRINT_EXIT(STORVSC_DRV); return ret; } - DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host reseted", scmnd->device, &device_ctx->device_obj); + DPRINT_INFO(STORVSC_DRV, "sdev (%p) dev obj (%p) - host reseted", + scmnd->device, &device_ctx->device_obj); DPRINT_EXIT(STORVSC_DRV); @@ -919,31 +957,32 @@ Desc: Rescan the scsi HBA static void storvsc_host_rescan_callback(struct work_struct *work) { struct hv_device *device_obj = - &((struct host_device_context*)work)->device_ctx->device_obj; - struct device_context* device_ctx = to_device_context(device_obj); + &((struct host_device_context *)work)->device_ctx->device_obj; + struct device_context *device_ctx = to_device_context(device_obj); struct Scsi_Host *host = dev_get_drvdata(&device_ctx->device); struct scsi_device *sdev; struct host_device_context *host_device_ctx; struct scsi_device **sdevs_remove_list; - unsigned int sdevs_count=0; + unsigned int sdevs_count = 0; unsigned int found; unsigned int i; - unsigned int lun_count=0; + unsigned int lun_count = 0; unsigned int *lun_list; DPRINT_ENTER(STORVSC_DRV); - host_device_ctx = (struct host_device_context*)host->hostdata; - lun_list = kcalloc(STORVSC_MAX_LUNS_PER_TARGET, sizeof(unsigned int), GFP_ATOMIC); - if (!lun_list) - { + host_device_ctx = (struct host_device_context *)host->hostdata; + lun_list = + kcalloc(STORVSC_MAX_LUNS_PER_TARGET, sizeof(unsigned int), + GFP_ATOMIC); + if (!lun_list) { DPRINT_ERR(STORVSC_DRV, "unable to allocate lun list"); return; } - sdevs_remove_list = kcalloc(STORVSC_MAX_LUNS_PER_TARGET, sizeof(void *), GFP_ATOMIC); - if (!sdevs_remove_list) - { + sdevs_remove_list = + kcalloc(STORVSC_MAX_LUNS_PER_TARGET, sizeof(void *), GFP_ATOMIC); + if (!sdevs_remove_list) { kfree(lun_list); DPRINT_ERR(STORVSC_DRV, "unable to allocate lun remove list"); return; @@ -952,65 +991,66 @@ static void storvsc_host_rescan_callback(struct work_struct *work) DPRINT_INFO(STORVSC_DRV, "rescanning host for new scsi devices..."); /* Rescan for new device */ - scsi_scan_target(&host->shost_gendev, host_device_ctx->path, host_device_ctx->target, SCAN_WILD_CARD, 1); + scsi_scan_target(&host->shost_gendev, host_device_ctx->path, + host_device_ctx->target, SCAN_WILD_CARD, 1); DPRINT_INFO(STORVSC_DRV, "rescanning host for removed scsi device..."); /* Use the 1st device to send the report luns cmd */ - shost_for_each_device(sdev, host) - { - lun_count=STORVSC_MAX_LUNS_PER_TARGET; + shost_for_each_device(sdev, host) { + lun_count = STORVSC_MAX_LUNS_PER_TARGET; storvsc_report_luns(sdev, lun_list, &lun_count); - DPRINT_INFO(STORVSC_DRV, "report luns on scsi device (%p) found %u luns ", sdev, lun_count); - DPRINT_INFO(STORVSC_DRV, "existing luns on scsi device (%p) host (%d)", sdev, host->host_no); + DPRINT_INFO(STORVSC_DRV, + "report luns on scsi device (%p) found %u luns ", + sdev, lun_count); + DPRINT_INFO(STORVSC_DRV, + "existing luns on scsi device (%p) host (%d)", sdev, + host->host_no); scsi_device_put(sdev); break; } - for (i=0; i<lun_count; i++) - { + for (i = 0; i < lun_count; i++) { DPRINT_INFO(STORVSC_DRV, "%d) lun %u", i, lun_list[i]); } /* Rescan for devices that may have been removed. */ /* We do not have to worry that new devices may have been added since */ /* this callback is serialized by the workqueue ie add/remove are done here. */ - shost_for_each_device(sdev, host) - { + shost_for_each_device(sdev, host) { /* See if this device is still here */ found = 0; - for (i=0; i<lun_count; i++) - { - if (sdev->lun == lun_list[i]) - { + for (i = 0; i < lun_count; i++) { + if (sdev->lun == lun_list[i]) { found = 1; break; } } - if (!found) - { - DPRINT_INFO(STORVSC_DRV, "lun (%u) does not exists", sdev->lun); + if (!found) { + DPRINT_INFO(STORVSC_DRV, "lun (%u) does not exists", + sdev->lun); sdevs_remove_list[sdevs_count++] = sdev; } } /* Now remove the devices */ - for (i=0; i< sdevs_count; i++) - { - DPRINT_INFO(STORVSC_DRV, "removing scsi device (%p) lun (%u)...", - sdevs_remove_list[i], sdevs_remove_list[i]->lun); + for (i = 0; i < sdevs_count; i++) { + DPRINT_INFO(STORVSC_DRV, + "removing scsi device (%p) lun (%u)...", + sdevs_remove_list[i], sdevs_remove_list[i]->lun); /* make sure it is not removed from underneath us */ - if (!scsi_device_get(sdevs_remove_list[i])) - { + if (!scsi_device_get(sdevs_remove_list[i])) { scsi_remove_device(sdevs_remove_list[i]); scsi_device_put(sdevs_remove_list[i]); } } - DPRINT_INFO(STORVSC_DRV, "rescan completed on dev obj (%p) target (%u) bus (%u)", device_obj, host_device_ctx->target, host_device_ctx->path); + DPRINT_INFO(STORVSC_DRV, + "rescan completed on dev obj (%p) target (%u) bus (%u)", + device_obj, host_device_ctx->target, host_device_ctx->path); kfree(lun_list); kfree(sdevs_remove_list); @@ -1018,64 +1058,65 @@ static void storvsc_host_rescan_callback(struct work_struct *work) DPRINT_EXIT(STORVSC_DRV); } -static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], unsigned int *lun_count) +static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], + unsigned int *lun_count) { - int i,j; - unsigned int lun=0; + int i, j; + unsigned int lun = 0; unsigned int num_luns; int result; unsigned char *data; struct scsi_sense_hdr sshdr; - unsigned char cmd[16]={0}; - unsigned int report_len = 8*(STORVSC_MAX_LUNS_PER_TARGET+1); /* Add 1 to cover the report_lun header */ + unsigned char cmd[16] = { 0 }; + unsigned int report_len = 8 * (STORVSC_MAX_LUNS_PER_TARGET + 1); /* Add 1 to cover the report_lun header */ unsigned long long *report_luns; const unsigned int in_lun_count = *lun_count; *lun_count = 0; report_luns = kzalloc(report_len, GFP_ATOMIC); - if (!report_luns) - { + if (!report_luns) { return -ENOMEM; } cmd[0] = REPORT_LUNS; /* cmd length */ - *(unsigned int*)&cmd[6] = cpu_to_be32(report_len); + *(unsigned int *)&cmd[6] = cpu_to_be32(report_len); - result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, (unsigned char*)report_luns, report_len, &sshdr, 30*HZ, 3, NULL); - if (result != 0) - { + result = + scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, + (unsigned char *)report_luns, report_len, &sshdr, + 30 * HZ, 3, NULL); + if (result != 0) { kfree(report_luns); return -EBUSY; } /* get the length from the first four bytes */ - report_len = be32_to_cpu(*(unsigned int*)&report_luns[0]); + report_len = be32_to_cpu(*(unsigned int *)&report_luns[0]); num_luns = (report_len / sizeof(unsigned long long)); - if (num_luns > in_lun_count) - { + if (num_luns > in_lun_count) { kfree(report_luns); return -EINVAL; } *lun_count = num_luns; - DPRINT_DBG(STORVSC_DRV, "report luns on scsi device (%p) found %u luns ", sdev, num_luns); + DPRINT_DBG(STORVSC_DRV, + "report luns on scsi device (%p) found %u luns ", sdev, + num_luns); /* lun id starts at 1 */ - for (i=1; i< num_luns+1; i++) - { + for (i = 1; i < num_luns + 1; i++) { lun = 0; - data = (unsigned char*)&report_luns[i]; - for (j = 0; j < sizeof(lun); j += 2) - { - lun = lun | (((data[j] << 8) | data[j + 1]) << (j * 8)); - } + data = (unsigned char *)&report_luns[i]; + for (j = 0; j < sizeof(lun); j += 2) { + lun = lun | (((data[j] << 8) | data[j + 1]) << (j * 8)); + } - luns[i-1] = lun; + luns[i - 1] = lun; } kfree(report_luns); @@ -1084,15 +1125,17 @@ static int storvsc_report_luns(struct scsi_device *sdev, unsigned int luns[], un static void storvsc_host_rescan(struct hv_device *device_obj) { - struct device_context* device_ctx = to_device_context(device_obj); + struct device_context *device_ctx = to_device_context(device_obj); struct Scsi_Host *host = dev_get_drvdata(&device_ctx->device); struct host_device_context *host_device_ctx; DPRINT_ENTER(STORVSC_DRV); - host_device_ctx = (struct host_device_context*)host->hostdata; + host_device_ctx = (struct host_device_context *)host->hostdata; - DPRINT_INFO(STORVSC_DRV, "initiating rescan on dev obj (%p) target (%u) bus (%u)...", device_obj, host_device_ctx->target, host_device_ctx->path); + DPRINT_INFO(STORVSC_DRV, + "initiating rescan on dev obj (%p) target (%u) bus (%u)...", + device_obj, host_device_ctx->target, host_device_ctx->path); /* We need to queue this since the scanning may block and the caller may be in an intr context */ /* scsi_queue_work(host, &host_device_ctx->host_rescan_work); */ @@ -1100,72 +1143,72 @@ static void storvsc_host_rescan(struct hv_device *device_obj) DPRINT_EXIT(STORVSC_DRV); } -static int storvsc_get_chs(struct scsi_device *sdev, struct block_device * bdev, sector_t capacity, int *info) +static int storvsc_get_chs(struct scsi_device *sdev, struct block_device *bdev, + sector_t capacity, int *info) { sector_t total_sectors = capacity; - sector_t cylinder_times_heads=0; - sector_t temp=0; + sector_t cylinder_times_heads = 0; + sector_t temp = 0; - int sectors_per_track=0; - int heads=0; - int cylinders=0; - int rem=0; + int sectors_per_track = 0; + int heads = 0; + int cylinders = 0; + int rem = 0; - if (total_sectors > (65535 * 16 * 255)) { - total_sectors = (65535 * 16 * 255); - } + if (total_sectors > (65535 * 16 * 255)) { + total_sectors = (65535 * 16 * 255); + } - if (total_sectors >= (65535 * 16 * 63)) { - sectors_per_track = 255; - heads = 16; + if (total_sectors >= (65535 * 16 * 63)) { + sectors_per_track = 255; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ - } - else - { - sectors_per_track = 17; + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } else { + sectors_per_track = 17; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ temp = cylinder_times_heads + 1023; - rem = sector_div(temp, 1024); /* sector_div stores the quotient in temp */ + rem = sector_div(temp, 1024); /* sector_div stores the quotient in temp */ heads = temp; - if (heads < 4) { - heads = 4; - } + if (heads < 4) { + heads = 4; + } - if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) { - sectors_per_track = 31; - heads = 16; + if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) { + sectors_per_track = 31; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ - } + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } - if (cylinder_times_heads >= (heads * 1024)) { - sectors_per_track = 63; - heads = 16; + if (cylinder_times_heads >= (heads * 1024)) { + sectors_per_track = 63; + heads = 16; cylinder_times_heads = total_sectors; - rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ - } - } + rem = sector_div(cylinder_times_heads, sectors_per_track); /* sector_div stores the quotient in cylinder_times_heads */ + } + } temp = cylinder_times_heads; - rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */ + rem = sector_div(temp, heads); /* sector_div stores the quotient in temp */ cylinders = temp; info[0] = heads; - info[1] = sectors_per_track; - info[2] = cylinders; + info[1] = sectors_per_track; + info[2] = cylinders; - DPRINT_INFO(STORVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, sectors_per_track); + DPRINT_INFO(STORVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, + sectors_per_track); - return 0; + return 0; } MODULE_LICENSE("GPL"); diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 32ae68c..506a50c 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -21,7 +21,6 @@ * */ - #include <linux/init.h> #include <linux/module.h> #include <linux/device.h> @@ -32,34 +31,30 @@ #include "include/logging.h" #include "include/vmbus.h" - /* Defines */ - /* FIXME! We need to do this dynamically for PIC and APIC system */ #define VMBUS_IRQ 0x5 #define VMBUS_IRQ_VECTOR IRQ5_VECTOR /* Data types */ - /* Main vmbus driver data structure */ struct vmbus_driver_context { /* !! These must be the first 2 fields !! */ /* The driver field is not used in here. Instead, the bus field is */ /* used to represent the driver */ - struct driver_context drv_ctx; - VMBUS_DRIVER_OBJECT drv_obj; + struct driver_context drv_ctx; + VMBUS_DRIVER_OBJECT drv_obj; - struct bus_type bus; - struct tasklet_struct msg_dpc; - struct tasklet_struct event_dpc; + struct bus_type bus; + struct tasklet_struct msg_dpc; + struct tasklet_struct event_dpc; /* The bus root device */ - struct device_context device_ctx; + struct device_context device_ctx; }; - /* Static decl */ static int vmbus_match(struct device *device, struct device_driver *driver); @@ -70,31 +65,34 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env); static void vmbus_msg_dpc(unsigned long data); static void vmbus_event_dpc(unsigned long data); -static irqreturn_t vmbus_isr(int irq, void* dev_id); +static irqreturn_t vmbus_isr(int irq, void *dev_id); static void vmbus_device_release(struct device *device); static void vmbus_bus_release(struct device *device); -static struct hv_device *vmbus_child_device_create(GUID type, GUID instance, void* context); +static struct hv_device *vmbus_child_device_create(GUID type, GUID instance, + void *context); static void vmbus_child_device_destroy(struct hv_device *device_obj); -static int vmbus_child_device_register(struct hv_device *root_device_obj, struct hv_device *child_device_obj); +static int vmbus_child_device_register(struct hv_device *root_device_obj, + struct hv_device *child_device_obj); static void vmbus_child_device_unregister(struct hv_device *child_device_obj); -static void vmbus_child_device_get_info(struct hv_device *device_obj, DEVICE_INFO *device_info); +static void vmbus_child_device_get_info(struct hv_device *device_obj, + DEVICE_INFO * device_info); /* static ssize_t vmbus_show_class_id(struct device *dev, struct device_attribute *attr, char *buf); */ /* static ssize_t vmbus_show_device_id(struct device *dev, struct device_attribute *attr, char *buf); */ -static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf); - +static ssize_t vmbus_show_device_attr(struct device *dev, + struct device_attribute *dev_attr, + char *buf); /* Global */ - /* Global logging setting */ /* unsigned int vmbus_loglevel= (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ /* unsigned int vmbus_loglevel= (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ -unsigned int vmbus_loglevel= (ALL_MODULES << 16 | INFO_LVL); +unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL); EXPORT_SYMBOL(vmbus_loglevel); static int vmbus_irq = VMBUS_IRQ; @@ -134,21 +132,18 @@ static struct device_attribute vmbus_device_attrs[] = { }; /* The one and only one */ -static struct vmbus_driver_context g_vmbus_drv={ - .bus.name = "vmbus", - .bus.match = vmbus_match, +static struct vmbus_driver_context g_vmbus_drv = { + .bus.name = "vmbus", + .bus.match = vmbus_match, .bus.shutdown = vmbus_shutdown, .bus.remove = vmbus_remove, - .bus.probe = vmbus_probe, + .bus.probe = vmbus_probe, .bus.uevent = vmbus_uevent, .bus.dev_attrs = vmbus_device_attrs, }; - /* Routines */ - - /*++ Name: vmbus_show_device_attr() @@ -156,7 +151,9 @@ Name: vmbus_show_device_attr() Desc: Show the device attribute in sysfs. This is invoked when user does a "cat /sys/bus/vmbus/devices/<bus device>/<attr name>" --*/ -static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, char *buf) +static ssize_t vmbus_show_device_attr(struct device *dev, + struct device_attribute *dev_attr, + char *buf) { struct device_context *device_ctx = device_to_device_context(dev); DEVICE_INFO device_info; @@ -165,101 +162,90 @@ static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribut vmbus_child_device_get_info(&device_ctx->device_obj, &device_info); - if (!strcmp(dev_attr->attr.name, "class_id")) - { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.ChannelType.Data[3], device_info.ChannelType.Data[2], device_info.ChannelType.Data[1], device_info.ChannelType.Data[0], - device_info.ChannelType.Data[5], device_info.ChannelType.Data[4], - device_info.ChannelType.Data[7], device_info.ChannelType.Data[6], - device_info.ChannelType.Data[8], device_info.ChannelType.Data[9], device_info.ChannelType.Data[10], device_info.ChannelType.Data[11], device_info.ChannelType.Data[12], device_info.ChannelType.Data[13], device_info.ChannelType.Data[14], device_info.ChannelType.Data[15]); - - } - else if (!strcmp(dev_attr->attr.name, "device_id")) - { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.ChannelInstance.Data[3], device_info.ChannelInstance.Data[2], device_info.ChannelInstance.Data[1], device_info.ChannelInstance.Data[0], - device_info.ChannelInstance.Data[5], device_info.ChannelInstance.Data[4], - device_info.ChannelInstance.Data[7], device_info.ChannelInstance.Data[6], - device_info.ChannelInstance.Data[8], device_info.ChannelInstance.Data[9], device_info.ChannelInstance.Data[10], device_info.ChannelInstance.Data[11], device_info.ChannelInstance.Data[12], device_info.ChannelInstance.Data[13], device_info.ChannelInstance.Data[14], device_info.ChannelInstance.Data[15]); - } - else if (!strcmp(dev_attr->attr.name, "state")) - { + if (!strcmp(dev_attr->attr.name, "class_id")) { + return sprintf(buf, + "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", + device_info.ChannelType.Data[3], + device_info.ChannelType.Data[2], + device_info.ChannelType.Data[1], + device_info.ChannelType.Data[0], + device_info.ChannelType.Data[5], + device_info.ChannelType.Data[4], + device_info.ChannelType.Data[7], + device_info.ChannelType.Data[6], + device_info.ChannelType.Data[8], + device_info.ChannelType.Data[9], + device_info.ChannelType.Data[10], + device_info.ChannelType.Data[11], + device_info.ChannelType.Data[12], + device_info.ChannelType.Data[13], + device_info.ChannelType.Data[14], + device_info.ChannelType.Data[15]); + + } else if (!strcmp(dev_attr->attr.name, "device_id")) { + return sprintf(buf, + "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}\n", + device_info.ChannelInstance.Data[3], + device_info.ChannelInstance.Data[2], + device_info.ChannelInstance.Data[1], + device_info.ChannelInstance.Data[0], + device_info.ChannelInstance.Data[5], + device_info.ChannelInstance.Data[4], + device_info.ChannelInstance.Data[7], + device_info.ChannelInstance.Data[6], + device_info.ChannelInstance.Data[8], + device_info.ChannelInstance.Data[9], + device_info.ChannelInstance.Data[10], + device_info.ChannelInstance.Data[11], + device_info.ChannelInstance.Data[12], + device_info.ChannelInstance.Data[13], + device_info.ChannelInstance.Data[14], + device_info.ChannelInstance.Data[15]); + } else if (!strcmp(dev_attr->attr.name, "state")) { return sprintf(buf, "%d\n", device_info.ChannelState); - } - else if (!strcmp(dev_attr->attr.name, "id")) - { + } else if (!strcmp(dev_attr->attr.name, "id")) { return sprintf(buf, "%d\n", device_info.ChannelId); - } - else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) - { + } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { return sprintf(buf, "%d\n", device_info.Outbound.InterruptMask); - } - else if (!strcmp(dev_attr->attr.name, "out_read_index")) - { + } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { return sprintf(buf, "%d\n", device_info.Outbound.ReadIndex); - } - else if (!strcmp(dev_attr->attr.name, "out_write_index")) - { + } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { return sprintf(buf, "%d\n", device_info.Outbound.WriteIndex); - } - else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) - { - return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToRead); - } - else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) - { - return sprintf(buf, "%d\n", device_info.Outbound.BytesAvailToWrite); - } - else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) - { + } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.Outbound.BytesAvailToRead); + } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.Outbound.BytesAvailToWrite); + } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { return sprintf(buf, "%d\n", device_info.Inbound.InterruptMask); - } - else if (!strcmp(dev_attr->attr.name, "in_read_index")) - { + } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { return sprintf(buf, "%d\n", device_info.Inbound.ReadIndex); - } - else if (!strcmp(dev_attr->attr.name, "in_write_index")) - { + } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { return sprintf(buf, "%d\n", device_info.Inbound.WriteIndex); - } - else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) - { - return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToRead); - } - else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) - { - return sprintf(buf, "%d\n", device_info.Inbound.BytesAvailToWrite); - } - else if (!strcmp(dev_attr->attr.name, "monitor_id")) - { + } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.Inbound.BytesAvailToRead); + } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.Inbound.BytesAvailToWrite); + } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { return sprintf(buf, "%d\n", device_info.MonitorId); - } - else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) - { + } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { return sprintf(buf, "%d\n", device_info.ServerMonitorPending); - } - else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) - { + } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { return sprintf(buf, "%d\n", device_info.ServerMonitorLatency); - } - else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) - { - return sprintf(buf, "%d\n", device_info.ServerMonitorConnectionId); - } - else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) - { + } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { + return sprintf(buf, "%d\n", + device_info.ServerMonitorConnectionId); + } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { return sprintf(buf, "%d\n", device_info.ClientMonitorPending); - } - else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) - { + } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { return sprintf(buf, "%d\n", device_info.ClientMonitorLatency); - } - else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) - { - return sprintf(buf, "%d\n", device_info.ClientMonitorConnectionId); - } - else - { + } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { + return sprintf(buf, "%d\n", + device_info.ClientMonitorConnectionId); + } else { return 0; } } @@ -313,13 +299,13 @@ Desc: Main vmbus driver initialization routine. Here, we --*/ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) { - int ret=0; - unsigned int vector=0; + int ret = 0; + unsigned int vector = 0; - struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; - VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; + struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = &g_vmbus_drv.drv_obj; - struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; + struct device_context *dev_ctx = &g_vmbus_drv.device_ctx; DPRINT_ENTER(VMBUS_DRV); @@ -331,15 +317,13 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) /* Call to bus driver to initialize */ ret = pfn_drv_init(&vmbus_drv_obj->Base); - if (ret != 0) - { + if (ret != 0) { DPRINT_ERR(VMBUS_DRV, "Unable to initialize vmbus (%d)", ret); goto cleanup; } /* Sanity checks */ - if (!vmbus_drv_obj->Base.OnDeviceAdd) - { + if (!vmbus_drv_obj->Base.OnDeviceAdd) { DPRINT_ERR(VMBUS_DRV, "OnDeviceAdd() routine not set"); ret = -1; goto cleanup; @@ -348,13 +332,14 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) vmbus_drv_ctx->bus.name = vmbus_drv_obj->Base.name; /* Initialize the bus context */ - tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, (unsigned long)vmbus_drv_obj); - tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, (unsigned long)vmbus_drv_obj); + tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_msg_dpc, + (unsigned long)vmbus_drv_obj); + tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_event_dpc, + (unsigned long)vmbus_drv_obj); /* Now, register the bus driver with LDM */ ret = bus_register(&vmbus_drv_ctx->bus); - if (ret) - { + if (ret) { ret = -1; goto cleanup; } @@ -362,13 +347,11 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) /* Get the interrupt resource */ ret = request_irq(vmbus_irq, vmbus_isr, - IRQF_SAMPLE_RANDOM, - vmbus_drv_obj->Base.name, - NULL); + IRQF_SAMPLE_RANDOM, vmbus_drv_obj->Base.name, NULL); - if (ret != 0) - { - DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", vmbus_irq); + if (ret != 0) { + DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", + vmbus_irq); bus_unregister(&vmbus_drv_ctx->bus); @@ -383,9 +366,9 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) memset(dev_ctx, 0, sizeof(struct device_context)); ret = vmbus_drv_obj->Base.OnDeviceAdd(&dev_ctx->device_obj, &vector); - if (ret != 0) - { - DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to add vmbus root device"); + if (ret != 0) { + DPRINT_ERR(VMBUS_DRV, + "ERROR - Unable to add vmbus root device"); free_irq(vmbus_irq, NULL); @@ -396,21 +379,23 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) } /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ dev_set_name(&dev_ctx->device, "vmbus_0_0"); - memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, sizeof(GUID)); - memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, sizeof(GUID)); + memcpy(&dev_ctx->class_id, &dev_ctx->device_obj.deviceType, + sizeof(GUID)); + memcpy(&dev_ctx->device_id, &dev_ctx->device_obj.deviceInstance, + sizeof(GUID)); /* No need to bind a driver to the root device. */ dev_ctx->device.parent = NULL; - dev_ctx->device.bus = &vmbus_drv_ctx->bus; /* NULL; vmbus_remove() does not get invoked */ + dev_ctx->device.bus = &vmbus_drv_ctx->bus; /* NULL; vmbus_remove() does not get invoked */ /* Setup the device dispatch table */ dev_ctx->device.release = vmbus_bus_release; /* Setup the bus as root device */ ret = device_register(&dev_ctx->device); - if (ret) - { - DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to register vmbus root device"); + if (ret) { + DPRINT_ERR(VMBUS_DRV, + "ERROR - Unable to register vmbus root device"); free_irq(vmbus_irq, NULL); bus_unregister(&vmbus_drv_ctx->bus); @@ -419,7 +404,6 @@ int vmbus_bus_init(PFN_DRIVERINITIALIZE pfn_drv_init) goto cleanup; } - vmbus_drv_obj->GetChannelOffers(); cleanup: @@ -428,7 +412,6 @@ cleanup: return ret; } - /*++ Name: vmbus_bus_exit() @@ -438,10 +421,10 @@ Desc: Terminate the vmbus driver. This routine is opposite of vmbus_bus_init() --*/ void vmbus_bus_exit(void) { - VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; - struct vmbus_driver_context *vmbus_drv_ctx=&g_vmbus_drv; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = &g_vmbus_drv.drv_obj; + struct vmbus_driver_context *vmbus_drv_ctx = &g_vmbus_drv; - struct device_context *dev_ctx=&g_vmbus_drv.device_ctx; + struct device_context *dev_ctx = &g_vmbus_drv.device_ctx; DPRINT_ENTER(VMBUS_DRV); @@ -474,14 +457,15 @@ Name: vmbus_child_driver_register() Desc: Register a vmbus's child driver --*/ -int vmbus_child_driver_register(struct driver_context* driver_ctx) +int vmbus_child_driver_register(struct driver_context *driver_ctx) { - VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = &g_vmbus_drv.drv_obj; int ret; DPRINT_ENTER(VMBUS_DRV); - DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", driver_ctx, driver_ctx->driver.name); + DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", + driver_ctx, driver_ctx->driver.name); /* The child driver on this vmbus */ driver_ctx->driver.bus = &g_vmbus_drv.bus; @@ -504,11 +488,12 @@ Name: vmbus_child_driver_unregister() Desc: Unregister a vmbus's child driver --*/ -void vmbus_child_driver_unregister(struct driver_context* driver_ctx) +void vmbus_child_driver_unregister(struct driver_context *driver_ctx) { DPRINT_ENTER(VMBUS_DRV); - DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", driver_ctx, driver_ctx->driver.name); + DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", + driver_ctx, driver_ctx->driver.name); driver_unregister(&driver_ctx->driver); @@ -526,30 +511,29 @@ Name: vmbus_get_interface() Desc: Get the vmbus channel interface. This is invoked by child/client driver that sits above vmbus --*/ -void vmbus_get_interface(VMBUS_CHANNEL_INTERFACE *interface) +void vmbus_get_interface(VMBUS_CHANNEL_INTERFACE * interface) { - VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = &g_vmbus_drv.drv_obj; vmbus_drv_obj->GetChannelInterface(interface); } EXPORT_SYMBOL(vmbus_get_interface); - /*++ Name: vmbus_child_device_get_info() Desc: Get the vmbus child device info. This is invoked to display various device attributes in sysfs. --*/ -static void vmbus_child_device_get_info(struct hv_device *device_obj, DEVICE_INFO *device_info) +static void vmbus_child_device_get_info(struct hv_device *device_obj, + DEVICE_INFO * device_info) { - VMBUS_DRIVER_OBJECT *vmbus_drv_obj=&g_vmbus_drv.drv_obj; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = &g_vmbus_drv.drv_obj; vmbus_drv_obj->GetChannelInfo(device_obj, device_info); } - /*++ Name: vmbus_child_device_create() @@ -557,7 +541,8 @@ Name: vmbus_child_device_create() Desc: Creates and registers a new child device on the vmbus. --*/ -static struct hv_device *vmbus_child_device_create(GUID type, GUID instance, void* context) +static struct hv_device *vmbus_child_device_create(GUID type, GUID instance, + void *context) { struct device_context *child_device_ctx; struct hv_device *child_device_obj; @@ -566,20 +551,28 @@ static struct hv_device *vmbus_child_device_create(GUID type, GUID instance, voi /* Allocate the new child device */ child_device_ctx = kzalloc(sizeof(struct device_context), GFP_KERNEL); - if (!child_device_ctx) - { - DPRINT_ERR(VMBUS_DRV, "unable to allocate device_context for child device"); + if (!child_device_ctx) { + DPRINT_ERR(VMBUS_DRV, + "unable to allocate device_context for child device"); DPRINT_EXIT(VMBUS_DRV); return NULL; } DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - " - "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}," - "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", - &child_device_ctx->device, - type.Data[3], type.Data[2], type.Data[1], type.Data[0], type.Data[5], type.Data[4], type.Data[7], type.Data[6], type.Data[8], type.Data[9], type.Data[10], type.Data[11], type.Data[12], type.Data[13], type.Data[14], type.Data[15], - instance.Data[3], instance.Data[2], instance.Data[1], instance.Data[0], instance.Data[5], instance.Data[4], instance.Data[7], instance.Data[6], instance.Data[8], instance.Data[9], instance.Data[10], instance.Data[11], instance.Data[12], instance.Data[13], instance.Data[14], instance.Data[15]); + "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}," + "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", + &child_device_ctx->device, + type.Data[3], type.Data[2], type.Data[1], type.Data[0], + type.Data[5], type.Data[4], type.Data[7], type.Data[6], + type.Data[8], type.Data[9], type.Data[10], type.Data[11], + type.Data[12], type.Data[13], type.Data[14], type.Data[15], + instance.Data[3], instance.Data[2], instance.Data[1], + instance.Data[0], instance.Data[5], instance.Data[4], + instance.Data[7], instance.Data[6], instance.Data[8], + instance.Data[9], instance.Data[10], instance.Data[11], + instance.Data[12], instance.Data[13], instance.Data[14], + instance.Data[15]); child_device_obj = &child_device_ctx->device_obj; child_device_obj->context = context; @@ -601,32 +594,39 @@ Name: vmbus_child_device_register() Desc: Register the child device on the specified bus --*/ -static int vmbus_child_device_register(struct hv_device *root_device_obj, struct hv_device *child_device_obj) +static int vmbus_child_device_register(struct hv_device *root_device_obj, + struct hv_device *child_device_obj) { - int ret=0; - struct device_context *root_device_ctx = to_device_context(root_device_obj); - struct device_context *child_device_ctx = to_device_context(child_device_obj); - static int device_num=0; + int ret = 0; + struct device_context *root_device_ctx = + to_device_context(root_device_obj); + struct device_context *child_device_ctx = + to_device_context(child_device_obj); + static int device_num = 0; DPRINT_ENTER(VMBUS_DRV); - DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", child_device_ctx); + DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", + child_device_ctx); /* Make sure we are not registered already */ - if (strlen(dev_name(&child_device_ctx->device)) != 0) - { - DPRINT_ERR(VMBUS_DRV, "child device (%p) already registered - busid %s", child_device_ctx, dev_name(&child_device_ctx->device)); + if (strlen(dev_name(&child_device_ctx->device)) != 0) { + DPRINT_ERR(VMBUS_DRV, + "child device (%p) already registered - busid %s", + child_device_ctx, + dev_name(&child_device_ctx->device)); ret = -1; goto Cleanup; } /* Set the device bus id. Otherwise, device_register()will fail. */ - dev_set_name(&child_device_ctx->device, "vmbus_0_%d", InterlockedIncrement(&device_num)); + dev_set_name(&child_device_ctx->device, "vmbus_0_%d", + InterlockedIncrement(&device_num)); /* The new device belongs to this bus */ - child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ + child_device_ctx->device.bus = &g_vmbus_drv.bus; /* device->dev.bus; */ child_device_ctx->device.parent = &root_device_ctx->device; child_device_ctx->device.release = vmbus_device_release; @@ -638,9 +638,11 @@ static int vmbus_child_device_register(struct hv_device *root_device_obj, struct ret = child_device_ctx->probe_error; if (ret) - DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", &child_device_ctx->device); + DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", + &child_device_ctx->device); else - DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", &child_device_ctx->device); + DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", + &child_device_ctx->device); Cleanup: DPRINT_EXIT(VMBUS_DRV); @@ -661,18 +663,19 @@ static void vmbus_child_device_unregister(struct hv_device *device_obj) DPRINT_ENTER(VMBUS_DRV); - DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", &device_ctx->device); + DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", + &device_ctx->device); /* Kick off the process of unregistering the device. */ /* This will call vmbus_remove() and eventually vmbus_device_release() */ device_unregister(&device_ctx->device); - DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", &device_ctx->device); + DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", + &device_ctx->device); DPRINT_EXIT(VMBUS_DRV); } - /*++ Name: vmbus_child_device_destroy() @@ -698,44 +701,71 @@ Desc: This routine is invoked when a device is added or removed on the vmbus to static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) { struct device_context *device_ctx = device_to_device_context(device); - int i=0; - int len=0; + int i = 0; + int len = 0; int ret; DPRINT_ENTER(VMBUS_DRV); - DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0], - device_ctx->class_id.Data[5], device_ctx->class_id.Data[4], - device_ctx->class_id.Data[7], device_ctx->class_id.Data[6], - device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11], - device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]); + DPRINT_INFO(VMBUS_DRV, + "generating uevent - VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", + device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], + device_ctx->class_id.Data[1], device_ctx->class_id.Data[0], + device_ctx->class_id.Data[5], device_ctx->class_id.Data[4], + device_ctx->class_id.Data[7], device_ctx->class_id.Data[6], + device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], + device_ctx->class_id.Data[10], + device_ctx->class_id.Data[11], + device_ctx->class_id.Data[12], + device_ctx->class_id.Data[13], + device_ctx->class_id.Data[14], + device_ctx->class_id.Data[15]); env->envp_idx = i; env->buflen = len; ret = add_uevent_var(env, - "VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->class_id.Data[3], device_ctx->class_id.Data[2], device_ctx->class_id.Data[1], device_ctx->class_id.Data[0], - device_ctx->class_id.Data[5], device_ctx->class_id.Data[4], - device_ctx->class_id.Data[7], device_ctx->class_id.Data[6], - device_ctx->class_id.Data[8], device_ctx->class_id.Data[9], device_ctx->class_id.Data[10], device_ctx->class_id.Data[11], - device_ctx->class_id.Data[12], device_ctx->class_id.Data[13], device_ctx->class_id.Data[14], device_ctx->class_id.Data[15]); - - if (ret) - { + "VMBUS_DEVICE_CLASS_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", + device_ctx->class_id.Data[3], + device_ctx->class_id.Data[2], + device_ctx->class_id.Data[1], + device_ctx->class_id.Data[0], + device_ctx->class_id.Data[5], + device_ctx->class_id.Data[4], + device_ctx->class_id.Data[7], + device_ctx->class_id.Data[6], + device_ctx->class_id.Data[8], + device_ctx->class_id.Data[9], + device_ctx->class_id.Data[10], + device_ctx->class_id.Data[11], + device_ctx->class_id.Data[12], + device_ctx->class_id.Data[13], + device_ctx->class_id.Data[14], + device_ctx->class_id.Data[15]); + + if (ret) { return ret; } ret = add_uevent_var(env, - "VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", - device_ctx->device_id.Data[3], device_ctx->device_id.Data[2], device_ctx->device_id.Data[1], device_ctx->device_id.Data[0], - device_ctx->device_id.Data[5], device_ctx->device_id.Data[4], - device_ctx->device_id.Data[7], device_ctx->device_id.Data[6], - device_ctx->device_id.Data[8], device_ctx->device_id.Data[9], device_ctx->device_id.Data[10], device_ctx->device_id.Data[11], - device_ctx->device_id.Data[12], device_ctx->device_id.Data[13], device_ctx->device_id.Data[14], device_ctx->device_id.Data[15]); - - if (ret) - { + "VMBUS_DEVICE_DEVICE_GUID={%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%02x%02x}", + device_ctx->device_id.Data[3], + device_ctx->device_id.Data[2], + device_ctx->device_id.Data[1], + device_ctx->device_id.Data[0], + device_ctx->device_id.Data[5], + device_ctx->device_id.Data[4], + device_ctx->device_id.Data[7], + device_ctx->device_id.Data[6], + device_ctx->device_id.Data[8], + device_ctx->device_id.Data[9], + device_ctx->device_id.Data[10], + device_ctx->device_id.Data[11], + device_ctx->device_id.Data[12], + device_ctx->device_id.Data[13], + device_ctx->device_id.Data[14], + device_ctx->device_id.Data[15]); + + if (ret) { return ret; } @@ -755,20 +785,24 @@ Desc: Attempt to match the specified device to the specified driver --*/ static int vmbus_match(struct device *device, struct device_driver *driver) { - int match=0; + int match = 0; struct driver_context *driver_ctx = driver_to_driver_context(driver); struct device_context *device_ctx = device_to_device_context(device); DPRINT_ENTER(VMBUS_DRV); /* We found our driver ? */ - if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(GUID)) == 0) - { + if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(GUID)) + == 0) { /* !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast it here to access the */ /* DRIVER_OBJECT field */ - struct vmbus_driver_context *vmbus_drv_ctx = (struct vmbus_driver_context*)driver_ctx; + struct vmbus_driver_context *vmbus_drv_ctx = + (struct vmbus_driver_context *)driver_ctx; device_ctx->device_obj.Driver = &vmbus_drv_ctx->drv_obj.Base; - DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, device_ctx->device_obj.Driver); + DPRINT_INFO(VMBUS_DRV, + "device object (%p) set to driver object (%p)", + &device_ctx->device_obj, + device_ctx->device_obj.Driver); match = 1; } @@ -778,7 +812,6 @@ static int vmbus_match(struct device *device, struct device_driver *driver) return match; } - /*++ Name: vmbus_probe_failed_cb() @@ -790,8 +823,7 @@ Desc: Callback when a driver probe failed in vmbus_probe(). We need a callback b --*/ static void vmbus_probe_failed_cb(struct work_struct *context) { - struct device_context *device_ctx = (struct device_context*)context; - + struct device_context *device_ctx = (struct device_context *)context; DPRINT_ENTER(VMBUS_DRV); @@ -803,7 +835,6 @@ static void vmbus_probe_failed_cb(struct work_struct *context) DPRINT_EXIT(VMBUS_DRV); } - /*++ Name: vmbus_probe() @@ -813,27 +844,30 @@ Desc: Add the new vmbus's child device --*/ static int vmbus_probe(struct device *child_device) { - int ret=0; - struct driver_context *driver_ctx = driver_to_driver_context(child_device->driver); - struct device_context *device_ctx = device_to_device_context(child_device); + int ret = 0; + struct driver_context *driver_ctx = + driver_to_driver_context(child_device->driver); + struct device_context *device_ctx = + device_to_device_context(child_device); DPRINT_ENTER(VMBUS_DRV); /* Let the specific open-source driver handles the probe if it can */ - if (driver_ctx->probe) - { + if (driver_ctx->probe) { ret = device_ctx->probe_error = driver_ctx->probe(child_device); - if (ret != 0) - { - DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s (%p) on driver %s (%d)...", dev_name(child_device), child_device, child_device->driver->name, ret); - - INIT_WORK(&device_ctx->probe_failed_work_item, vmbus_probe_failed_cb); + if (ret != 0) { + DPRINT_ERR(VMBUS_DRV, + "probe() failed for device %s (%p) on driver %s (%d)...", + dev_name(child_device), child_device, + child_device->driver->name, ret); + + INIT_WORK(&device_ctx->probe_failed_work_item, + vmbus_probe_failed_cb); schedule_work(&device_ctx->probe_failed_work_item); } - } - else - { - DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", child_device->driver->name); + } else { + DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", + child_device->driver->name); ret = -1; } @@ -841,7 +875,6 @@ static int vmbus_probe(struct device *child_device) return ret; } - /*++ Name: vmbus_remove() @@ -851,36 +884,31 @@ Desc: Remove a vmbus device --*/ static int vmbus_remove(struct device *child_device) { - int ret=0; + int ret = 0; struct driver_context *driver_ctx; DPRINT_ENTER(VMBUS_DRV); /* Special case root bus device */ - if (child_device->parent == NULL) - { + if (child_device->parent == NULL) { /* No-op since it is statically defined and handle in vmbus_bus_exit() */ DPRINT_EXIT(VMBUS_DRV); return 0; } - if (child_device->driver) - { + if (child_device->driver) { driver_ctx = driver_to_driver_context(child_device->driver); /* Let the specific open-source driver handles the removal if it can */ - if (driver_ctx->remove) - { + if (driver_ctx->remove) { ret = driver_ctx->remove(child_device); - } - else - { - DPRINT_ERR(VMBUS_DRV, "remove() method not set for driver - %s", child_device->driver->name); + } else { + DPRINT_ERR(VMBUS_DRV, + "remove() method not set for driver - %s", + child_device->driver->name); ret = -1; } - } - else - { + } else { } @@ -903,16 +931,14 @@ static void vmbus_shutdown(struct device *child_device) DPRINT_ENTER(VMBUS_DRV); /* Special case root bus device */ - if (child_device->parent == NULL) - { + if (child_device->parent == NULL) { /* No-op since it is statically defined and handle in vmbus_bus_exit() */ DPRINT_EXIT(VMBUS_DRV); return; } /* The device may not be attached yet */ - if (!child_device->driver) - { + if (!child_device->driver) { DPRINT_EXIT(VMBUS_DRV); return; } @@ -920,8 +946,7 @@ static void vmbus_shutdown(struct device *child_device) driver_ctx = driver_to_driver_context(child_device->driver); /* Let the specific open-source driver handles the removal if it can */ - if (driver_ctx->shutdown) - { + if (driver_ctx->shutdown) { driver_ctx->shutdown(child_device); } @@ -975,7 +1000,7 @@ Desc: Tasklet routine to handle hypervisor messages --*/ static void vmbus_msg_dpc(unsigned long data) { - VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)data; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = (VMBUS_DRIVER_OBJECT *) data; DPRINT_ENTER(VMBUS_DRV); @@ -996,7 +1021,7 @@ Desc: Tasklet routine to handle hypervisor events --*/ static void vmbus_event_dpc(unsigned long data) { - VMBUS_DRIVER_OBJECT* vmbus_drv_obj = (VMBUS_DRIVER_OBJECT*)data; + VMBUS_DRIVER_OBJECT *vmbus_drv_obj = (VMBUS_DRIVER_OBJECT *) data; DPRINT_ENTER(VMBUS_DRV); @@ -1015,10 +1040,10 @@ Name: vmbus_msg_dpc() Desc: ISR routine --*/ -static irqreturn_t vmbus_isr(int irq, void* dev_id) +static irqreturn_t vmbus_isr(int irq, void *dev_id) { - int ret=0; - VMBUS_DRIVER_OBJECT* vmbus_driver_obj = &g_vmbus_drv.drv_obj; + int ret = 0; + VMBUS_DRIVER_OBJECT *vmbus_driver_obj = &g_vmbus_drv.drv_obj; DPRINT_ENTER(VMBUS_DRV); @@ -1028,23 +1053,18 @@ static irqreturn_t vmbus_isr(int irq, void* dev_id) ret = vmbus_driver_obj->OnIsr(&vmbus_driver_obj->Base); /* Schedules a dpc if necessary */ - if (ret > 0) - { - if (test_bit(0, (unsigned long*)&ret)) - { + if (ret > 0) { + if (test_bit(0, (unsigned long *)&ret)) { tasklet_schedule(&g_vmbus_drv.msg_dpc); } - if (test_bit(1, (unsigned long*)&ret)) - { + if (test_bit(1, (unsigned long *)&ret)) { tasklet_schedule(&g_vmbus_drv.event_dpc); } DPRINT_EXIT(VMBUS_DRV); return IRQ_HANDLED; - } - else - { + } else { DPRINT_EXIT(VMBUS_DRV); return IRQ_NONE; } @@ -1052,7 +1072,6 @@ static irqreturn_t vmbus_isr(int irq, void* dev_id) MODULE_LICENSE("GPL"); - /*++ Name: vmbus_init() @@ -1062,13 +1081,14 @@ Desc: Main vmbus driver entry routine --*/ static int __init vmbus_init(void) { - int ret=0; + int ret = 0; DPRINT_ENTER(VMBUS_DRV); DPRINT_INFO(VMBUS_DRV, - "Vmbus initializing.... current log level 0x%x (%x,%x)", - vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel)); + "Vmbus initializing.... current log level 0x%x (%x,%x)", + vmbus_loglevel, HIWORD(vmbus_loglevel), + LOWORD(vmbus_loglevel)); /* Todo: it is used for loglevel, to be ported to new kernel. */ ret = vmbus_bus_init(VmbusInitialize); @@ -1077,8 +1097,6 @@ static int __init vmbus_init(void) return ret; } - - /*++ Name: vmbus_init() -- 1.6.3.1.10.g659a0.dirty