Commit fd8b85ea authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Staging: hv: coding style cleanups for Connection.c

Everything is clean except for some very long lines that
need a bit more code rework to resolve.  That will have to be done by
someone that can test the code.

Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 7dd03fc4
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
* Hank Janssen <hjanssen@microsoft.com> * Hank Janssen <hjanssen@microsoft.com>
* *
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/vmalloc.h> #include <linux/vmalloc.h>
...@@ -29,27 +27,18 @@ ...@@ -29,27 +27,18 @@
#include "logging.h" #include "logging.h"
#include "VmbusPrivate.h" #include "VmbusPrivate.h"
/* Globals */
struct VMBUS_CONNECTION gVmbusConnection = { struct VMBUS_CONNECTION gVmbusConnection = {
.ConnectState = Disconnected, .ConnectState = Disconnected,
.NextGpadlHandle = ATOMIC_INIT(0xE1E10), .NextGpadlHandle = ATOMIC_INIT(0xE1E10),
}; };
/**
/*++ * VmbusConnect - Sends a connect request on the partition service connection
*/
Name:
VmbusConnect()
Description:
Sends a connect request on the partition service connection
--*/
int VmbusConnect(void) int VmbusConnect(void)
{ {
int ret=0; int ret = 0;
struct vmbus_channel_msginfo *msgInfo = NULL; struct vmbus_channel_msginfo *msgInfo = NULL;
struct vmbus_channel_initiate_contact *msg; struct vmbus_channel_initiate_contact *msg;
unsigned long flags; unsigned long flags;
...@@ -63,8 +52,7 @@ int VmbusConnect(void) ...@@ -63,8 +52,7 @@ int VmbusConnect(void)
/* Initialize the vmbus connection */ /* Initialize the vmbus connection */
gVmbusConnection.ConnectState = Connecting; gVmbusConnection.ConnectState = Connecting;
gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con"); gVmbusConnection.WorkQueue = create_workqueue("hv_vmbus_con");
if (!gVmbusConnection.WorkQueue) if (!gVmbusConnection.WorkQueue) {
{
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
...@@ -80,29 +68,30 @@ int VmbusConnect(void) ...@@ -80,29 +68,30 @@ int VmbusConnect(void)
* abstraction stuff * abstraction stuff
*/ */
gVmbusConnection.InterruptPage = osd_PageAlloc(1); gVmbusConnection.InterruptPage = osd_PageAlloc(1);
if (gVmbusConnection.InterruptPage == NULL) if (gVmbusConnection.InterruptPage == NULL) {
{
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
gVmbusConnection.RecvInterruptPage = gVmbusConnection.InterruptPage; 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 * Setup the monitor notification facility. The 1st page for
* the 2nd page for child->parent * parent->child and the 2nd page for child->parent
*/ */
gVmbusConnection.MonitorPages = osd_PageAlloc(2); gVmbusConnection.MonitorPages = osd_PageAlloc(2);
if (gVmbusConnection.MonitorPages == NULL) if (gVmbusConnection.MonitorPages == NULL) {
{
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
msgInfo = kzalloc(sizeof(*msgInfo) + sizeof(struct vmbus_channel_initiate_contact), GFP_KERNEL); msgInfo = kzalloc(sizeof(*msgInfo) +
if (msgInfo == NULL) sizeof(struct vmbus_channel_initiate_contact),
{ GFP_KERNEL);
if (msgInfo == NULL) {
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
...@@ -114,24 +103,27 @@ int VmbusConnect(void) ...@@ -114,24 +103,27 @@ int VmbusConnect(void)
msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER; msg->VMBusVersionRequested = VMBUS_REVISION_NUMBER;
msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage); msg->InterruptPage = virt_to_phys(gVmbusConnection.InterruptPage);
msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages); msg->MonitorPage1 = virt_to_phys(gVmbusConnection.MonitorPages);
msg->MonitorPage2 = virt_to_phys((void *)((unsigned long)gVmbusConnection.MonitorPages + PAGE_SIZE)); msg->MonitorPage2 = virt_to_phys(
(void *)((unsigned long)gVmbusConnection.MonitorPages +
PAGE_SIZE));
/* /*
* Add to list before we send the request since we may * Add to list before we send the request since we may
* receive the response before returning from this routine * receive the response before returning from this routine
*/ */
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 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); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, monitor1 pfn %llx,, monitor2 pfn %llx", DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, "
"monitor1 pfn %llx,, monitor2 pfn %llx",
msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2); msg->InterruptPage, msg->MonitorPage1, msg->MonitorPage2);
DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); DPRINT_DBG(VMBUS, "Sending channel initiate msg...");
ret = VmbusPostMessage(msg,
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_initiate_contact)); sizeof(struct vmbus_channel_initiate_contact));
if (ret != 0) if (ret != 0) {
{
REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
goto Cleanup; goto Cleanup;
} }
...@@ -142,21 +134,18 @@ int VmbusConnect(void) ...@@ -142,21 +134,18 @@ int VmbusConnect(void)
REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry); REMOVE_ENTRY_LIST(&msgInfo->MsgListEntry);
/* Check if successful */ /* Check if successful */
if (msgInfo->Response.VersionResponse.VersionSupported) if (msgInfo->Response.VersionResponse.VersionSupported) {
{
DPRINT_INFO(VMBUS, "Vmbus connected!!"); DPRINT_INFO(VMBUS, "Vmbus connected!!");
gVmbusConnection.ConnectState = Connected; gVmbusConnection.ConnectState = Connected;
} } else {
else DPRINT_ERR(VMBUS, "Vmbus connection failed!!..."
{ "current version (%d) not supported",
DPRINT_ERR(VMBUS, "Vmbus connection failed!!...current version (%d) not supported", VMBUS_REVISION_NUMBER); VMBUS_REVISION_NUMBER);
ret = -1; ret = -1;
goto Cleanup; goto Cleanup;
} }
kfree(msgInfo->WaitEvent); kfree(msgInfo->WaitEvent);
kfree(msgInfo); kfree(msgInfo);
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
...@@ -164,29 +153,23 @@ int VmbusConnect(void) ...@@ -164,29 +153,23 @@ int VmbusConnect(void)
return 0; return 0;
Cleanup: Cleanup:
gVmbusConnection.ConnectState = Disconnected; gVmbusConnection.ConnectState = Disconnected;
if (gVmbusConnection.WorkQueue) if (gVmbusConnection.WorkQueue)
destroy_workqueue(gVmbusConnection.WorkQueue); destroy_workqueue(gVmbusConnection.WorkQueue);
if (gVmbusConnection.InterruptPage) if (gVmbusConnection.InterruptPage) {
{
osd_PageFree(gVmbusConnection.InterruptPage, 1); osd_PageFree(gVmbusConnection.InterruptPage, 1);
gVmbusConnection.InterruptPage = NULL; gVmbusConnection.InterruptPage = NULL;
} }
if (gVmbusConnection.MonitorPages) if (gVmbusConnection.MonitorPages) {
{
osd_PageFree(gVmbusConnection.MonitorPages, 2); osd_PageFree(gVmbusConnection.MonitorPages, 2);
gVmbusConnection.MonitorPages = NULL; gVmbusConnection.MonitorPages = NULL;
} }
if (msgInfo) if (msgInfo) {
{
if (msgInfo->WaitEvent)
kfree(msgInfo->WaitEvent); kfree(msgInfo->WaitEvent);
kfree(msgInfo); kfree(msgInfo);
} }
...@@ -195,19 +178,12 @@ Cleanup: ...@@ -195,19 +178,12 @@ Cleanup:
return ret; return ret;
} }
/**
/*++ * VmbusDisconnect - Sends a disconnect request on the partition service connection
*/
Name:
VmbusDisconnect()
Description:
Sends a disconnect request on the partition service connection
--*/
int VmbusDisconnect(void) int VmbusDisconnect(void)
{ {
int ret=0; int ret = 0;
struct vmbus_channel_message_header *msg; struct vmbus_channel_message_header *msg;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
...@@ -220,17 +196,14 @@ int VmbusDisconnect(void) ...@@ -220,17 +196,14 @@ int VmbusDisconnect(void)
msg->MessageType = ChannelMessageUnload; msg->MessageType = ChannelMessageUnload;
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_message_header)); ret = VmbusPostMessage(msg,
sizeof(struct vmbus_channel_message_header));
if (ret != 0) if (ret != 0)
{
goto Cleanup; goto Cleanup;
}
osd_PageFree(gVmbusConnection.InterruptPage, 1); osd_PageFree(gVmbusConnection.InterruptPage, 1);
/* TODO: iterate thru the msg list and free up */ /* TODO: iterate thru the msg list and free up */
destroy_workqueue(gVmbusConnection.WorkQueue); destroy_workqueue(gVmbusConnection.WorkQueue);
gVmbusConnection.ConnectState = Disconnected; gVmbusConnection.ConnectState = Disconnected;
...@@ -238,41 +211,28 @@ int VmbusDisconnect(void) ...@@ -238,41 +211,28 @@ int VmbusDisconnect(void)
DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); DPRINT_INFO(VMBUS, "Vmbus disconnected!!");
Cleanup: Cleanup:
if (msg)
{
kfree(msg); kfree(msg);
}
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
return ret; return ret;
} }
/**
/*++ * GetChannelFromRelId - Get the channel object given its child relative id (ie channel id)
*/
Name:
GetChannelFromRelId()
Description:
Get the channel object given its child relative id (ie channel id)
--*/
struct vmbus_channel *GetChannelFromRelId(u32 relId) struct vmbus_channel *GetChannelFromRelId(u32 relId)
{ {
struct vmbus_channel *channel; struct vmbus_channel *channel;
struct vmbus_channel *foundChannel = NULL; struct vmbus_channel *foundChannel = NULL;
LIST_ENTRY* anchor; LIST_ENTRY *anchor;
LIST_ENTRY* curr; LIST_ENTRY *curr;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&gVmbusConnection.channel_lock, 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, struct vmbus_channel,
channel = CONTAINING_RECORD(curr, struct vmbus_channel, ListEntry); ListEntry);
if (channel->OfferMsg.ChildRelId == relId) if (channel->OfferMsg.ChildRelId == relId) {
{
foundChannel = channel; foundChannel = channel;
break; break;
} }
...@@ -282,21 +242,10 @@ struct vmbus_channel *GetChannelFromRelId(u32 relId) ...@@ -282,21 +242,10 @@ struct vmbus_channel *GetChannelFromRelId(u32 relId)
return foundChannel; return foundChannel;
} }
/**
* VmbusProcessChannelEvent - Process a channel event notification
/*++ */
static void VmbusProcessChannelEvent(void *context)
Name:
VmbusProcessChannelEvent()
Description:
Process a channel event notification
--*/
static void
VmbusProcessChannelEvent(
void * context
)
{ {
struct vmbus_channel *channel; struct vmbus_channel *channel;
u32 relId = (u32)(unsigned long)context; u32 relId = (u32)(unsigned long)context;
...@@ -309,64 +258,48 @@ VmbusProcessChannelEvent( ...@@ -309,64 +258,48 @@ VmbusProcessChannelEvent(
*/ */
channel = GetChannelFromRelId(relId); channel = GetChannelFromRelId(relId);
if (channel) if (channel) {
{
VmbusChannelOnChannelEvent(channel); VmbusChannelOnChannelEvent(channel);
/* WorkQueueQueueWorkItem(channel->dataWorkQueue, VmbusChannelOnChannelEvent, (void*)channel); */ /*
} * WorkQueueQueueWorkItem(channel->dataWorkQueue,
else * VmbusChannelOnChannelEvent,
{ * (void*)channel);
*/
} else {
DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId); DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relId);
} }
} }
/**
/*++ * VmbusOnEvents - Handler for events
*/
Name:
VmbusOnEvents()
Description:
Handler for events
--*/
void VmbusOnEvents(void) void VmbusOnEvents(void)
{ {
int dword; 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 maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5;
int bit; int bit;
int relid; int relid;
u32* recvInterruptPage = gVmbusConnection.RecvInterruptPage; u32 *recvInterruptPage = gVmbusConnection.RecvInterruptPage;
/* VMBUS_CHANNEL_MESSAGE* receiveMsg; */
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
/* Check events */ /* Check events */
if (recvInterruptPage) if (recvInterruptPage) {
{ for (dword = 0; dword < maxdword; dword++) {
for (dword = 0; dword < maxdword; dword++) if (recvInterruptPage[dword]) {
{ for (bit = 0; bit < 32; bit++) {
if (recvInterruptPage[dword]) if (test_and_clear_bit(bit, (unsigned long *)&recvInterruptPage[dword])) {
{
for (bit = 0; bit < 32; bit++)
{
if (test_and_clear_bit(bit, (unsigned long *) &recvInterruptPage[dword]))
{
relid = (dword << 5) + 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 */ if (relid == 0) {
{ /* special case - vmbus channel protocol msg */
DPRINT_DBG(VMBUS, "invalid relid - %d", relid); DPRINT_DBG(VMBUS, "invalid relid - %d", relid);
continue;
continue; } } else {
else
{
/* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */
/* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */
VmbusProcessChannelEvent((void*)(unsigned long)relid); VmbusProcessChannelEvent((void *)(unsigned long)relid);
} }
} }
} }
...@@ -378,50 +311,31 @@ void VmbusOnEvents(void) ...@@ -378,50 +311,31 @@ void VmbusOnEvents(void)
return; return;
} }
/*++ /**
* VmbusPostMessage - Send a msg on the vmbus's message connection
Name: */
VmbusPostMessage()
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;
union hv_connection_id connId; union hv_connection_id connId;
connId.Asu32 = 0;
connId.Asu32 =0;
connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID; connId.u.Id = VMBUS_MESSAGE_CONNECTION_ID;
ret = HvPostMessage( return HvPostMessage(connId, 1, buffer, bufferLen);
connId,
1,
buffer,
bufferLen);
return ret;
} }
/*++ /**
* VmbusSetEvent - Send an event notification to the parent
Name: */
VmbusSetEvent()
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); DPRINT_ENTER(VMBUS);
/* Each u32 represents 32 channels */ /* Each u32 represents 32 channels */
set_bit(childRelId & 31, set_bit(childRelId & 31,
(unsigned long *) gVmbusConnection.SendInterruptPage + (childRelId >> 5)); (unsigned long *)gVmbusConnection.SendInterruptPage +
(childRelId >> 5));
ret = HvSignalEvent(); ret = HvSignalEvent();
...@@ -429,5 +343,3 @@ int VmbusSetEvent(u32 childRelId) ...@@ -429,5 +343,3 @@ int VmbusSetEvent(u32 childRelId)
return ret; return ret;
} }
/* EOF */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment