提交 f4266e34 编写于 作者: G Greg Kroah-Hartman

Staging: hv: coding style cleanup for Channel.c

All clean now.

Cc: Hank Janssen <hjanssen@microsoft.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 8a280399
/* /*
*
* Copyright (c) 2009, Microsoft Corporation. * Copyright (c) 2009, Microsoft Corporation.
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
...@@ -18,9 +17,7 @@ ...@@ -18,9 +17,7 @@
* Authors: * Authors:
* Haiyang Zhang <haiyangz@microsoft.com> * Haiyang Zhang <haiyangz@microsoft.com>
* 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 "osd.h" #include "osd.h"
...@@ -29,81 +26,67 @@ ...@@ -29,81 +26,67 @@
/* Internal routines */ /* Internal routines */
static int VmbusChannelCreateGpadlHeader( static int VmbusChannelCreateGpadlHeader(
void * Kbuffer, /* must be phys and virt contiguous */ void *Kbuffer, /* must be phys and virt contiguous */
u32 Size, /* page-size multiple */ u32 Size, /* page-size multiple */
struct vmbus_channel_msginfo **msgInfo, struct vmbus_channel_msginfo **msgInfo,
u32 *MessageCount u32 *MessageCount);
);
static void DumpVmbusChannel(struct vmbus_channel *channel); static void DumpVmbusChannel(struct vmbus_channel *channel);
static void VmbusChannelSetEvent(struct vmbus_channel *channel); static void VmbusChannelSetEvent(struct vmbus_channel *channel);
#if 0 #if 0
static void static void DumpMonitorPage(struct hv_monitor_page *MonitorPage)
DumpMonitorPage(
struct hv_monitor_page *MonitorPage
)
{ {
int i=0; int i = 0;
int j=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++) for (i = 0; i < 4; i++)
{ DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i,
DPRINT_DBG(VMBUS, "trigger group (%d) - %llx", i, MonitorPage->TriggerGroup[i].AsUINT64); MonitorPage->TriggerGroup[i].AsUINT64);
}
for (i=0; i<4; i++) for (i = 0; i < 4; i++) {
{ for (j = 0; j < 32; j++) {
for (j=0; j<32; j++) DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j,
{ MonitorPage->Latency[i][j]);
DPRINT_DBG(VMBUS, "latency (%d)(%d) - %llx", i, j, MonitorPage->Latency[i][j]);
} }
} }
for (i=0; i<4; i++) for (i = 0; i < 4; i++) {
{ for (j = 0; j < 32; j++) {
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-conn id (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].ConnectionId.Asu32); DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j,
DPRINT_DBG(VMBUS, "param-flag (%d)(%d) - %d", i, j, MonitorPage->Parameter[i][j].FlagNumber); MonitorPage->Parameter[i][j].FlagNumber);
} }
} }
} }
#endif #endif
/*++ /**
* VmbusChannelSetEvent - Trigger an event notification on the specified channel.
Name: */
VmbusChannelSetEvent()
Description:
Trigger an event notification on the specified channel.
--*/
static void VmbusChannelSetEvent(struct vmbus_channel *Channel) static void VmbusChannelSetEvent(struct vmbus_channel *Channel)
{ {
struct hv_monitor_page *monitorPage; struct hv_monitor_page *monitorPage;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
if (Channel->OfferMsg.MonitorAllocated) if (Channel->OfferMsg.MonitorAllocated) {
{
/* Each u32 represents 32 channels */ /* Each u32 represents 32 channels */
set_bit(Channel->OfferMsg.ChildRelId & 31, set_bit(Channel->OfferMsg.ChildRelId & 31,
(unsigned long *) gVmbusConnection.SendInterruptPage + (unsigned long *) gVmbusConnection.SendInterruptPage +
(Channel->OfferMsg.ChildRelId >> 5) ); (Channel->OfferMsg.ChildRelId >> 5));
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; monitorPage = gVmbusConnection.MonitorPages;
monitorPage++; /* Get the child to parent monitor page */ monitorPage++; /* Get the child to parent monitor page */
set_bit(Channel->MonitorBit, set_bit(Channel->MonitorBit,
(unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending); (unsigned long *)&monitorPage->TriggerGroup
[Channel->MonitorGroup].Pending);
} } else {
else
{
VmbusSetEvent(Channel->OfferMsg.ChildRelId); VmbusSetEvent(Channel->OfferMsg.ChildRelId);
} }
...@@ -117,162 +100,162 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel) ...@@ -117,162 +100,162 @@ static void VmbusChannelClearEvent(struct vmbus_channel *channel)
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
if (Channel->OfferMsg.MonitorAllocated) if (Channel->OfferMsg.MonitorAllocated) {
{
/* Each u32 represents 32 channels */ /* Each u32 represents 32 channels */
clear_bit(Channel->OfferMsg.ChildRelId & 31, clear_bit(Channel->OfferMsg.ChildRelId & 31,
(unsigned long *) gVmbusConnection.SendInterruptPage + (Channel->OfferMsg.ChildRelId >> 5)); (unsigned long *)gVmbusConnection.SendInterruptPage +
(Channel->OfferMsg.ChildRelId >> 5));
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; monitorPage =
(struct hv_monitor_page *)gVmbusConnection.MonitorPages;
monitorPage++; /* Get the child to parent monitor page */ monitorPage++; /* Get the child to parent monitor page */
clear_bit(Channel->MonitorBit, clear_bit(Channel->MonitorBit,
(unsigned long *) &monitorPage->TriggerGroup[Channel->MonitorGroup].Pending); (unsigned long *)&monitorPage->TriggerGroup
[Channel->MonitorGroup].Pending);
} }
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
} }
#endif #endif
/*++; /**
* VmbusChannelGetDebugInfo -Retrieve various channel debug info
Name: */
VmbusChannelGetDebugInfo()
Description:
Retrieve various channel debug info
--*/
void VmbusChannelGetDebugInfo(struct vmbus_channel *Channel, void VmbusChannelGetDebugInfo(struct vmbus_channel *Channel,
struct vmbus_channel_debug_info *DebugInfo) struct vmbus_channel_debug_info *DebugInfo)
{ {
struct hv_monitor_page *monitorPage; struct hv_monitor_page *monitorPage;
u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32; u8 monitorGroup = (u8)Channel->OfferMsg.MonitorId / 32;
u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32; u8 monitorOffset = (u8)Channel->OfferMsg.MonitorId % 32;
/* u32 monitorBit = 1 << monitorOffset; */ /* u32 monitorBit = 1 << monitorOffset; */
DebugInfo->RelId = Channel->OfferMsg.ChildRelId; DebugInfo->RelId = Channel->OfferMsg.ChildRelId;
DebugInfo->State = Channel->State; DebugInfo->State = Channel->State;
memcpy(&DebugInfo->InterfaceType, &Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid)); memcpy(&DebugInfo->InterfaceType,
memcpy(&DebugInfo->InterfaceInstance, &Channel->OfferMsg.Offer.InterfaceInstance, sizeof(struct hv_guid)); &Channel->OfferMsg.Offer.InterfaceType, sizeof(struct hv_guid));
memcpy(&DebugInfo->InterfaceInstance,
&Channel->OfferMsg.Offer.InterfaceInstance,
sizeof(struct hv_guid));
monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages; monitorPage = (struct hv_monitor_page *)gVmbusConnection.MonitorPages;
DebugInfo->MonitorId = Channel->OfferMsg.MonitorId; DebugInfo->MonitorId = Channel->OfferMsg.MonitorId;
DebugInfo->ServerMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending; DebugInfo->ServerMonitorPending =
DebugInfo->ServerMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset]; monitorPage->TriggerGroup[monitorGroup].Pending;
DebugInfo->ServerMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id; DebugInfo->ServerMonitorLatency =
monitorPage->Latency[monitorGroup][monitorOffset];
DebugInfo->ServerMonitorConnectionId =
monitorPage->Parameter[monitorGroup]
[monitorOffset].ConnectionId.u.Id;
monitorPage++; monitorPage++;
DebugInfo->ClientMonitorPending = monitorPage->TriggerGroup[monitorGroup].Pending; DebugInfo->ClientMonitorPending =
DebugInfo->ClientMonitorLatency = monitorPage->Latency[monitorGroup][ monitorOffset]; monitorPage->TriggerGroup[monitorGroup].Pending;
DebugInfo->ClientMonitorConnectionId = monitorPage->Parameter[monitorGroup][ monitorOffset].ConnectionId.u.Id; DebugInfo->ClientMonitorLatency =
monitorPage->Latency[monitorGroup][monitorOffset];
DebugInfo->ClientMonitorConnectionId =
monitorPage->Parameter[monitorGroup]
[monitorOffset].ConnectionId.u.Id;
RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound); RingBufferGetDebugInfo(&Channel->Inbound, &DebugInfo->Inbound);
RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound); RingBufferGetDebugInfo(&Channel->Outbound, &DebugInfo->Outbound);
} }
/**
/*++; * VmbusChannelOpen - Open the specified channel.
*/
Name: int VmbusChannelOpen(struct vmbus_channel *NewChannel, u32 SendRingBufferSize,
VmbusChannelOpen() u32 RecvRingBufferSize, void *UserData, u32 UserDataLen,
PFN_CHANNEL_CALLBACK pfnOnChannelCallback, void *Context)
Description:
Open the specified channel.
--*/
int VmbusChannelOpen(struct vmbus_channel *NewChannel,
u32 SendRingBufferSize,
u32 RecvRingBufferSize,
void * UserData,
u32 UserDataLen,
PFN_CHANNEL_CALLBACK pfnOnChannelCallback,
void * Context
)
{ {
int ret=0;
struct vmbus_channel_open_channel *openMsg; struct vmbus_channel_open_channel *openMsg;
struct vmbus_channel_msginfo *openInfo; struct vmbus_channel_msginfo *openInfo;
void *in, *out; void *in, *out;
unsigned long flags; unsigned long flags;
int ret;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
/* Aligned to page size */ /* Aligned to page size */
ASSERT(!(SendRingBufferSize & (PAGE_SIZE -1))); ASSERT(!(SendRingBufferSize & (PAGE_SIZE - 1)));
ASSERT(!(RecvRingBufferSize & (PAGE_SIZE -1))); ASSERT(!(RecvRingBufferSize & (PAGE_SIZE - 1)));
NewChannel->OnChannelCallback = pfnOnChannelCallback; NewChannel->OnChannelCallback = pfnOnChannelCallback;
NewChannel->ChannelCallbackContext = Context; NewChannel->ChannelCallbackContext = Context;
/* Allocate the ring buffer */ /* Allocate the ring buffer */
out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT); out = osd_PageAlloc((SendRingBufferSize + RecvRingBufferSize)
/* out = kzalloc(sendRingBufferSize + recvRingBufferSize, GFP_KERNEL); */ >> PAGE_SHIFT);
ASSERT(out); 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->RingBufferPages = out;
NewChannel->RingBufferPageCount = (SendRingBufferSize + RecvRingBufferSize) >> PAGE_SHIFT; NewChannel->RingBufferPageCount = (SendRingBufferSize +
RecvRingBufferSize) >> PAGE_SHIFT;
RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize); RingBufferInit(&NewChannel->Outbound, out, SendRingBufferSize);
RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize); RingBufferInit(&NewChannel->Inbound, in, RecvRingBufferSize);
/* Establish the gpadl for the ring buffer */ /* 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; NewChannel->RingBufferGpadlHandle = 0;
ret = VmbusChannelEstablishGpadl(NewChannel, ret = VmbusChannelEstablishGpadl(NewChannel,
NewChannel->Outbound.RingBuffer, NewChannel->Outbound.RingBuffer,
SendRingBufferSize + RecvRingBufferSize, SendRingBufferSize +
&NewChannel->RingBufferGpadlHandle); 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, DPRINT_DBG(VMBUS, "channel %p <relid %d gpadl 0x%x send ring %p "
NewChannel->OfferMsg.ChildRelId, "size %d recv ring %p size %d, downstreamoffset %d>",
NewChannel->RingBufferGpadlHandle, NewChannel, NewChannel->OfferMsg.ChildRelId,
NewChannel->Outbound.RingBuffer, NewChannel->RingBufferGpadlHandle,
NewChannel->Outbound.RingSize, NewChannel->Outbound.RingBuffer,
NewChannel->Inbound.RingBuffer, NewChannel->Outbound.RingSize,
NewChannel->Inbound.RingSize, NewChannel->Inbound.RingBuffer,
SendRingBufferSize); NewChannel->Inbound.RingSize,
SendRingBufferSize);
/* Create and init the channel open message */ /* Create and init the channel open message */
openInfo = kmalloc(sizeof(*openInfo) + sizeof(struct vmbus_channel_open_channel), GFP_KERNEL); openInfo = kmalloc(sizeof(*openInfo) +
sizeof(struct vmbus_channel_open_channel),
GFP_KERNEL);
ASSERT(openInfo != NULL); ASSERT(openInfo != NULL);
openInfo->WaitEvent = osd_WaitEventCreate(); openInfo->WaitEvent = osd_WaitEventCreate();
openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg; openMsg = (struct vmbus_channel_open_channel *)openInfo->Msg;
openMsg->Header.MessageType = ChannelMessageOpenChannel; openMsg->Header.MessageType = ChannelMessageOpenChannel;
openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */ openMsg->OpenId = NewChannel->OfferMsg.ChildRelId; /* FIXME */
openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId; openMsg->ChildRelId = NewChannel->OfferMsg.ChildRelId;
openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle; openMsg->RingBufferGpadlHandle = NewChannel->RingBufferGpadlHandle;
ASSERT(openMsg->RingBufferGpadlHandle); ASSERT(openMsg->RingBufferGpadlHandle);
openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >> PAGE_SHIFT; openMsg->DownstreamRingBufferPageOffset = SendRingBufferSize >>
openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */ PAGE_SHIFT;
openMsg->ServerContextAreaGpadlHandle = 0; /* TODO */
ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES); ASSERT(UserDataLen <= MAX_USER_DEFINED_BYTES);
if (UserDataLen) if (UserDataLen)
{
memcpy(openMsg->UserData, UserData, UserDataLen); memcpy(openMsg->UserData, UserData, UserDataLen);
}
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); 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); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
DPRINT_DBG(VMBUS, "Sending channel open msg..."); DPRINT_DBG(VMBUS, "Sending channel open msg...");
ret = VmbusPostMessage(openMsg, sizeof(struct vmbus_channel_open_channel)); ret = VmbusPostMessage(openMsg,
if (ret != 0) sizeof(struct vmbus_channel_open_channel));
{ if (ret != 0) {
DPRINT_ERR(VMBUS, "unable to open channel - %d", ret); DPRINT_ERR(VMBUS, "unable to open channel - %d", ret);
goto Cleanup; goto Cleanup;
} }
...@@ -281,13 +264,10 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, ...@@ -281,13 +264,10 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel,
osd_WaitEventWait(openInfo->WaitEvent); osd_WaitEventWait(openInfo->WaitEvent);
if (openInfo->Response.OpenResult.Status == 0) if (openInfo->Response.OpenResult.Status == 0)
{
DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel); DPRINT_INFO(VMBUS, "channel <%p> open success!!", NewChannel);
}
else else
{ DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!",
DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", NewChannel, openInfo->Response.OpenResult.Status); NewChannel, openInfo->Response.OpenResult.Status);
}
Cleanup: Cleanup:
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
...@@ -302,119 +282,97 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel, ...@@ -302,119 +282,97 @@ int VmbusChannelOpen(struct vmbus_channel *NewChannel,
return 0; return 0;
} }
/*++; /**
* DumpGpadlBody - Dump the gpadl body message to the console for debugging purposes.
Name: */
DumpGpadlBody()
Description:
Dump the gpadl body message to the console for debugging purposes.
--*/
static void DumpGpadlBody(struct vmbus_channel_gpadl_body *Gpadl, u32 Len) static void DumpGpadlBody(struct vmbus_channel_gpadl_body *Gpadl, u32 Len)
{ {
int i=0; int i;
int pfnCount=0; int pfnCount;
pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body))/ sizeof(u64); pfnCount = (Len - sizeof(struct vmbus_channel_gpadl_body)) /
sizeof(u64);
DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount); DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", Len, pfnCount);
for (i=0; i< pfnCount; i++) for (i = 0; i < pfnCount; i++)
{ DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu",
DPRINT_DBG(VMBUS, "gpadl body - %d) pfn %llu", i, Gpadl->Pfn[i]); i, Gpadl->Pfn[i]);
}
} }
/**
/*++; * DumpGpadlHeader - Dump the gpadl header message to the console for debugging purposes.
*/
Name:
DumpGpadlHeader()
Description:
Dump the gpadl header message to the console for debugging purposes.
--*/
static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl) static void DumpGpadlHeader(struct vmbus_channel_gpadl_header *Gpadl)
{ {
int i=0,j=0; int i, j;
int pageCount=0; int pageCount;
DPRINT_DBG(VMBUS, "gpadl header - relid %d, range count %d, range buflen %d", DPRINT_DBG(VMBUS,
Gpadl->ChildRelId, "gpadl header - relid %d, range count %d, range buflen %d",
Gpadl->RangeCount, Gpadl->ChildRelId, Gpadl->RangeCount, Gpadl->RangeBufLen);
Gpadl->RangeBufLen); for (i = 0; i < Gpadl->RangeCount; i++) {
for (i=0; i< Gpadl->RangeCount; i++)
{
pageCount = Gpadl->Range[i].ByteCount >> PAGE_SHIFT; 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", DPRINT_DBG(VMBUS, "gpadl range %d - len %d offset %d "
i, Gpadl->Range[i].ByteCount, Gpadl->Range[i].ByteOffset, pageCount); "page count %d", i, Gpadl->Range[i].ByteCount,
Gpadl->Range[i].ByteOffset, pageCount);
for (j=0; j< pageCount; j++) for (j = 0; j < pageCount; j++)
{ DPRINT_DBG(VMBUS, "%d) pfn %llu", j,
DPRINT_DBG(VMBUS, "%d) pfn %llu", j, Gpadl->Range[i].PfnArray[j]); Gpadl->Range[i].PfnArray[j]);
}
} }
} }
/*++; /**
* VmbusChannelCreateGpadlHeader - Creates a gpadl for the specified buffer
Name: */
VmbusChannelCreateGpadlHeader() static int VmbusChannelCreateGpadlHeader(void *Kbuffer, u32 Size,
struct vmbus_channel_msginfo **MsgInfo,
Description: u32 *MessageCount)
Creates a gpadl for the specified buffer
--*/
static int
VmbusChannelCreateGpadlHeader(
void * Kbuffer, /* from kmalloc() */
u32 Size, /* page-size multiple */
struct vmbus_channel_msginfo **MsgInfo,
u32 *MessageCount)
{ {
int i; int i;
int pageCount; int pageCount;
unsigned long long pfn; unsigned long long pfn;
struct vmbus_channel_gpadl_header *gpaHeader; struct vmbus_channel_gpadl_header *gpaHeader;
struct vmbus_channel_gpadl_body *gpadlBody; struct vmbus_channel_gpadl_body *gpadlBody;
struct vmbus_channel_msginfo *msgHeader; struct vmbus_channel_msginfo *msgHeader;
struct vmbus_channel_msginfo *msgBody; struct vmbus_channel_msginfo *msgBody;
u32 msgSize; u32 msgSize;
int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize; int pfnSum, pfnCount, pfnLeft, pfnCurr, pfnSize;
/* ASSERT( (kbuffer & (PAGE_SIZE-1)) == 0); */ /* ASSERT((kbuffer & (PAGE_SIZE-1)) == 0); */
ASSERT( (Size & (PAGE_SIZE-1)) == 0); ASSERT((Size & (PAGE_SIZE-1)) == 0);
pageCount = Size >> PAGE_SHIFT; pageCount = Size >> PAGE_SHIFT;
pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT; pfn = virt_to_phys(Kbuffer) >> PAGE_SHIFT;
/* do we need a gpadl body msg */ /* do we need a gpadl body msg */
pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_header) - sizeof(struct gpa_range); pfnSize = MAX_SIZE_CHANNEL_MESSAGE -
sizeof(struct vmbus_channel_gpadl_header) -
sizeof(struct gpa_range);
pfnCount = pfnSize / sizeof(u64); pfnCount = pfnSize / sizeof(u64);
if (pageCount > pfnCount) /* we need a gpadl body */ if (pageCount > pfnCount) {
{ /* we need a gpadl body */
/* fill in the header */ /* fill in the header */
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pfnCount*sizeof(u64); msgSize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_header) +
sizeof(struct gpa_range) + pfnCount * sizeof(u64);
msgHeader = kzalloc(msgSize, GFP_KERNEL); msgHeader = kzalloc(msgSize, GFP_KERNEL);
INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList); INITIALIZE_LIST_HEAD(&msgHeader->SubMsgList);
msgHeader->MessageSize=msgSize; msgHeader->MessageSize = msgSize;
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
gpaHeader->RangeCount = 1; gpaHeader->RangeCount = 1;
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64); gpaHeader->RangeBufLen = sizeof(struct gpa_range) +
pageCount * sizeof(u64);
gpaHeader->Range[0].ByteOffset = 0; gpaHeader->Range[0].ByteOffset = 0;
gpaHeader->Range[0].ByteCount = Size; gpaHeader->Range[0].ByteCount = Size;
for (i=0; i<pfnCount; i++) for (i = 0; i < pfnCount; i++)
{
gpaHeader->Range[0].PfnArray[i] = pfn+i; gpaHeader->Range[0].PfnArray[i] = pfn+i;
}
*MsgInfo = msgHeader; *MsgInfo = msgHeader;
*MessageCount = 1; *MessageCount = 1;
...@@ -422,57 +380,58 @@ VmbusChannelCreateGpadlHeader( ...@@ -422,57 +380,58 @@ VmbusChannelCreateGpadlHeader(
pfnLeft = pageCount - pfnCount; pfnLeft = pageCount - pfnCount;
/* how many pfns can we fit */ /* how many pfns can we fit */
pfnSize = MAX_SIZE_CHANNEL_MESSAGE - sizeof(struct vmbus_channel_gpadl_body); pfnSize = MAX_SIZE_CHANNEL_MESSAGE -
sizeof(struct vmbus_channel_gpadl_body);
pfnCount = pfnSize / sizeof(u64); pfnCount = pfnSize / sizeof(u64);
/* fill in the body */ /* fill in the body */
while (pfnLeft) while (pfnLeft) {
{
if (pfnLeft > pfnCount) if (pfnLeft > pfnCount)
{
pfnCurr = pfnCount; pfnCurr = pfnCount;
}
else else
{
pfnCurr = pfnLeft; pfnCurr = pfnLeft;
}
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_body) + pfnCurr*sizeof(u64); msgSize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_body) +
pfnCurr * sizeof(u64);
msgBody = kzalloc(msgSize, GFP_KERNEL); msgBody = kzalloc(msgSize, GFP_KERNEL);
ASSERT(msgBody); ASSERT(msgBody);
msgBody->MessageSize = msgSize; msgBody->MessageSize = msgSize;
(*MessageCount)++; (*MessageCount)++;
gpadlBody = (struct vmbus_channel_gpadl_body *)msgBody->Msg; gpadlBody =
(struct vmbus_channel_gpadl_body *)msgBody->Msg;
/* FIXME: Gpadl is u32 and we are using a pointer which could be 64-bit */
/*
* FIXME:
* Gpadl is u32 and we are using a pointer which could
* be 64-bit
*/
/* gpadlBody->Gpadl = kbuffer; */ /* gpadlBody->Gpadl = kbuffer; */
for (i=0; i<pfnCurr; i++) for (i = 0; i < pfnCurr; i++)
{
gpadlBody->Pfn[i] = pfn + pfnSum + i; gpadlBody->Pfn[i] = pfn + pfnSum + i;
}
/* add to msg header */ /* add to msg header */
INSERT_TAIL_LIST(&msgHeader->SubMsgList, &msgBody->MsgListEntry); INSERT_TAIL_LIST(&msgHeader->SubMsgList,
&msgBody->MsgListEntry);
pfnSum += pfnCurr; pfnSum += pfnCurr;
pfnLeft -= pfnCurr; pfnLeft -= pfnCurr;
} }
} } else {
else
{
/* everything fits in a header */ /* everything fits in a header */
msgSize = sizeof(struct vmbus_channel_msginfo) + sizeof(struct vmbus_channel_gpadl_header) + sizeof(struct gpa_range) + pageCount*sizeof(u64); msgSize = sizeof(struct vmbus_channel_msginfo) +
sizeof(struct vmbus_channel_gpadl_header) +
sizeof(struct gpa_range) + pageCount * sizeof(u64);
msgHeader = kzalloc(msgSize, GFP_KERNEL); msgHeader = kzalloc(msgSize, GFP_KERNEL);
msgHeader->MessageSize=msgSize; msgHeader->MessageSize = msgSize;
gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg; gpaHeader = (struct vmbus_channel_gpadl_header *)msgHeader->Msg;
gpaHeader->RangeCount = 1; gpaHeader->RangeCount = 1;
gpaHeader->RangeBufLen = sizeof(struct gpa_range) + pageCount*sizeof(u64); gpaHeader->RangeBufLen = sizeof(struct gpa_range) +
pageCount * sizeof(u64);
gpaHeader->Range[0].ByteOffset = 0; gpaHeader->Range[0].ByteOffset = 0;
gpaHeader->Range[0].ByteCount = Size; gpaHeader->Range[0].ByteCount = Size;
for (i=0; i<pageCount; i++) for (i = 0; i < pageCount; i++)
{
gpaHeader->Range[0].PfnArray[i] = pfn+i; gpaHeader->Range[0].PfnArray[i] = pfn+i;
}
*MsgInfo = msgHeader; *MsgInfo = msgHeader;
*MessageCount = 1; *MessageCount = 1;
...@@ -481,35 +440,28 @@ VmbusChannelCreateGpadlHeader( ...@@ -481,35 +440,28 @@ VmbusChannelCreateGpadlHeader(
return 0; return 0;
} }
/**
/*++; * VmbusChannelEstablishGpadl - Estabish a GPADL for the specified buffer
*
Name: * @Channel: a channel
VmbusChannelEstablishGpadl() * @Kbuffer: from kmalloc
* @Size: page-size multiple
Description: * @GpadlHandle: some funky thing
Estabish a GPADL for the specified buffer */
int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, void *Kbuffer,
--*/ u32 Size, u32 *GpadlHandle)
int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
void * Kbuffer, /* from kmalloc() */
u32 Size, /* page-size multiple */
u32 *GpadlHandle
)
{ {
int ret=0;
struct vmbus_channel_gpadl_header *gpadlMsg; struct vmbus_channel_gpadl_header *gpadlMsg;
struct vmbus_channel_gpadl_body *gpadlBody; struct vmbus_channel_gpadl_body *gpadlBody;
/* struct vmbus_channel_gpadl_created *gpadlCreated; */ /* struct vmbus_channel_gpadl_created *gpadlCreated; */
struct vmbus_channel_msginfo *msgInfo; struct vmbus_channel_msginfo *msgInfo;
struct vmbus_channel_msginfo *subMsgInfo; struct vmbus_channel_msginfo *subMsgInfo;
u32 msgCount; u32 msgCount;
LIST_ENTRY* anchor; LIST_ENTRY *anchor;
LIST_ENTRY* curr; LIST_ENTRY *curr;
u32 nextGpadlHandle; u32 nextGpadlHandle;
unsigned long flags; unsigned long flags;
int ret;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
...@@ -518,7 +470,7 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, ...@@ -518,7 +470,7 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount); VmbusChannelCreateGpadlHeader(Kbuffer, Size, &msgInfo, &msgCount);
ASSERT(msgInfo != NULL); ASSERT(msgInfo != NULL);
ASSERT(msgCount >0); ASSERT(msgCount > 0);
msgInfo->WaitEvent = osd_WaitEventCreate(); msgInfo->WaitEvent = osd_WaitEventCreate();
gpadlMsg = (struct vmbus_channel_gpadl_header *)msgInfo->Msg; gpadlMsg = (struct vmbus_channel_gpadl_header *)msgInfo->Msg;
...@@ -529,44 +481,52 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, ...@@ -529,44 +481,52 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
DumpGpadlHeader(gpadlMsg); DumpGpadlHeader(gpadlMsg);
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, "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(*msgInfo)); DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd",
msgInfo->MessageSize - sizeof(*msgInfo));
ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize - sizeof(*msgInfo)); ret = VmbusPostMessage(gpadlMsg, msgInfo->MessageSize -
if (ret != 0) sizeof(*msgInfo));
{ if (ret != 0) {
DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret);
goto Cleanup; goto Cleanup;
} }
if (msgCount>1) if (msgCount > 1) {
{ ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList) {
ITERATE_LIST_ENTRIES(anchor, curr, &msgInfo->SubMsgList)
{
subMsgInfo = (struct vmbus_channel_msginfo *)curr; subMsgInfo = (struct vmbus_channel_msginfo *)curr;
gpadlBody = (struct vmbus_channel_gpadl_body *)subMsgInfo->Msg; gpadlBody =
(struct vmbus_channel_gpadl_body *)subMsgInfo->Msg;
gpadlBody->Header.MessageType = ChannelMessageGpadlBody; gpadlBody->Header.MessageType = ChannelMessageGpadlBody;
gpadlBody->Gpadl = nextGpadlHandle; gpadlBody->Gpadl = nextGpadlHandle;
DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", subMsgInfo->MessageSize - sizeof(*subMsgInfo)); DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd",
subMsgInfo->MessageSize -
sizeof(*subMsgInfo));
DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo)); DumpGpadlBody(gpadlBody, subMsgInfo->MessageSize -
ret = VmbusPostMessage(gpadlBody, subMsgInfo->MessageSize - sizeof(*subMsgInfo)); sizeof(*subMsgInfo));
ret = VmbusPostMessage(gpadlBody,
subMsgInfo->MessageSize -
sizeof(*subMsgInfo));
ASSERT(ret == 0); ASSERT(ret == 0);
} }
} }
osd_WaitEventWait(msgInfo->WaitEvent); osd_WaitEventWait(msgInfo->WaitEvent);
/* At this point, we received the gpadl created msg */ /* At this point, we received the gpadl created msg */
DPRINT_DBG(VMBUS, "Received GPADL created (relid %d, status %d handle %x)", DPRINT_DBG(VMBUS, "Received GPADL created "
Channel->OfferMsg.ChildRelId, "(relid %d, status %d handle %x)",
msgInfo->Response.GpadlCreated.CreationStatus, Channel->OfferMsg.ChildRelId,
gpadlMsg->Gpadl); msgInfo->Response.GpadlCreated.CreationStatus,
gpadlMsg->Gpadl);
*GpadlHandle = gpadlMsg->Gpadl; *GpadlHandle = gpadlMsg->Gpadl;
...@@ -583,29 +543,22 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel, ...@@ -583,29 +543,22 @@ int VmbusChannelEstablishGpadl(struct vmbus_channel *Channel,
return ret; return ret;
} }
/**
* VmbusChannelTeardownGpadl -Teardown the specified GPADL handle
/*++; */
Name:
VmbusChannelTeardownGpadl()
Description:
Teardown the specified GPADL handle
--*/
int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
{ {
int ret=0;
struct vmbus_channel_gpadl_teardown *msg; struct vmbus_channel_gpadl_teardown *msg;
struct vmbus_channel_msginfo *info; struct vmbus_channel_msginfo *info;
unsigned long flags; unsigned long flags;
int ret;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
ASSERT(GpadlHandle != 0); ASSERT(GpadlHandle != 0);
info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL); info = kmalloc(sizeof(*info) +
sizeof(struct vmbus_channel_gpadl_teardown), GFP_KERNEL);
ASSERT(info != NULL); ASSERT(info != NULL);
info->WaitEvent = osd_WaitEventCreate(); info->WaitEvent = osd_WaitEventCreate();
...@@ -613,17 +566,18 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) ...@@ -613,17 +566,18 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
msg = (struct vmbus_channel_gpadl_teardown *)info->Msg; msg = (struct vmbus_channel_gpadl_teardown *)info->Msg;
msg->Header.MessageType = ChannelMessageGpadlTeardown; msg->Header.MessageType = ChannelMessageGpadlTeardown;
msg->ChildRelId = Channel->OfferMsg.ChildRelId; msg->ChildRelId = Channel->OfferMsg.ChildRelId;
msg->Gpadl = GpadlHandle; msg->Gpadl = GpadlHandle;
spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags); spin_lock_irqsave(&gVmbusConnection.channelmsg_lock, flags);
INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry); INSERT_TAIL_LIST(&gVmbusConnection.ChannelMsgList, &info->MsgListEntry);
spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags); spin_unlock_irqrestore(&gVmbusConnection.channelmsg_lock, flags);
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_gpadl_teardown)); ret = VmbusPostMessage(msg,
if (ret != 0) sizeof(struct vmbus_channel_gpadl_teardown));
{ if (ret != 0) {
/* TODO: */ /* TODO: */
/* something... */
} }
osd_WaitEventWait(info->WaitEvent); osd_WaitEventWait(info->WaitEvent);
...@@ -641,22 +595,15 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle) ...@@ -641,22 +595,15 @@ int VmbusChannelTeardownGpadl(struct vmbus_channel *Channel, u32 GpadlHandle)
return ret; return ret;
} }
/**
/*++ * VmbusChannelClose - Close the specified channel
*/
Name:
VmbusChannelClose()
Description:
Close the specified channel
--*/
void VmbusChannelClose(struct vmbus_channel *Channel) void VmbusChannelClose(struct vmbus_channel *Channel)
{ {
int ret=0;
struct vmbus_channel_close_channel *msg; struct vmbus_channel_close_channel *msg;
struct vmbus_channel_msginfo *info; struct vmbus_channel_msginfo *info;
unsigned long flags; unsigned long flags;
int ret;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
...@@ -665,26 +612,26 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -665,26 +612,26 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
del_timer(&Channel->poll_timer); del_timer(&Channel->poll_timer);
/* Send a closing message */ /* Send a closing message */
info = kmalloc(sizeof(*info) + sizeof(struct vmbus_channel_close_channel), GFP_KERNEL); info = kmalloc(sizeof(*info) +
sizeof(struct vmbus_channel_close_channel), GFP_KERNEL);
ASSERT(info != NULL); ASSERT(info != NULL);
/* info->waitEvent = osd_WaitEventCreate(); */ /* info->waitEvent = osd_WaitEventCreate(); */
msg = (struct vmbus_channel_close_channel *)info->Msg; msg = (struct vmbus_channel_close_channel *)info->Msg;
msg->Header.MessageType = ChannelMessageCloseChannel; msg->Header.MessageType = ChannelMessageCloseChannel;
msg->ChildRelId = Channel->OfferMsg.ChildRelId; msg->ChildRelId = Channel->OfferMsg.ChildRelId;
ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel)); ret = VmbusPostMessage(msg, sizeof(struct vmbus_channel_close_channel));
if (ret != 0) if (ret != 0) {
{
/* TODO: */ /* TODO: */
/* something... */
} }
/* Tear down the gpadl for the channel's ring buffer */ /* Tear down the gpadl for the channel's ring buffer */
if (Channel->RingBufferGpadlHandle) if (Channel->RingBufferGpadlHandle)
{ VmbusChannelTeardownGpadl(Channel,
VmbusChannelTeardownGpadl(Channel, Channel->RingBufferGpadlHandle); Channel->RingBufferGpadlHandle);
}
/* TODO: Send a msg to release the childRelId */ /* TODO: Send a msg to release the childRelId */
...@@ -696,15 +643,13 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -696,15 +643,13 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
kfree(info); kfree(info);
/* /*
* If we are closing the channel during an error path in * If we are closing the channel during an error path in
* opening the channel, don't free the channel since the * opening the channel, don't free the channel since the
* caller will free the channel * caller will free the channel
*/ */
if (Channel->State == CHANNEL_OPEN_STATE) if (Channel->State == CHANNEL_OPEN_STATE) {
{
spin_lock_irqsave(&gVmbusConnection.channel_lock, flags); spin_lock_irqsave(&gVmbusConnection.channel_lock, flags);
REMOVE_ENTRY_LIST(&Channel->ListEntry); REMOVE_ENTRY_LIST(&Channel->ListEntry);
spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags); spin_unlock_irqrestore(&gVmbusConnection.channel_lock, flags);
...@@ -715,33 +660,23 @@ void VmbusChannelClose(struct vmbus_channel *Channel) ...@@ -715,33 +660,23 @@ void VmbusChannelClose(struct vmbus_channel *Channel)
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
} }
/**
/*++ * VmbusChannelSendPacket - Send the specified buffer on the given channel
*/
Name: int VmbusChannelSendPacket(struct vmbus_channel *Channel, const void *Buffer,
VmbusChannelSendPacket() u32 BufferLen, u64 RequestId,
enum vmbus_packet_type Type, u32 Flags)
Description:
Send the specified buffer on the given channel
--*/
int VmbusChannelSendPacket(struct vmbus_channel *Channel,
const void * Buffer,
u32 BufferLen,
u64 RequestId,
enum vmbus_packet_type Type,
u32 Flags
)
{ {
int ret=0;
struct vmpacket_descriptor desc; struct vmpacket_descriptor desc;
u32 packetLen = sizeof(struct vmpacket_descriptor) + BufferLen; u32 packetLen = sizeof(struct vmpacket_descriptor) + BufferLen;
u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); u32 packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
struct scatterlist bufferList[3]; struct scatterlist bufferList[3];
u64 alignedData=0; u64 alignedData = 0;
int ret;
DPRINT_ENTER(VMBUS); 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); DumpVmbusChannel(Channel);
...@@ -750,57 +685,43 @@ int VmbusChannelSendPacket(struct vmbus_channel *Channel, ...@@ -750,57 +685,43 @@ int VmbusChannelSendPacket(struct vmbus_channel *Channel,
/* Setup the descriptor */ /* Setup the descriptor */
desc.Type = Type; /* VmbusPacketTypeDataInBand; */ desc.Type = Type; /* VmbusPacketTypeDataInBand; */
desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */ desc.Flags = Flags; /* VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED; */
desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3; /* in 8-bytes granularity */ /* in 8-bytes granularity */
desc.DataOffset8 = sizeof(struct vmpacket_descriptor) >> 3;
desc.Length8 = (u16)(packetLenAligned >> 3); desc.Length8 = (u16)(packetLenAligned >> 3);
desc.TransactionId = RequestId; desc.TransactionId = RequestId;
sg_init_table(bufferList,3); sg_init_table(bufferList, 3);
sg_set_buf(&bufferList[0], &desc, sizeof(struct vmpacket_descriptor)); sg_set_buf(&bufferList[0], &desc, sizeof(struct vmpacket_descriptor));
sg_set_buf(&bufferList[1], Buffer, BufferLen); sg_set_buf(&bufferList[1], Buffer, BufferLen);
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
ret = RingBufferWrite( ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
&Channel->Outbound,
bufferList,
3);
/* TODO: We should determine if this is optional */ /* TODO: We should determine if this is optional */
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
{
VmbusChannelSetEvent(Channel); VmbusChannelSetEvent(Channel);
}
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
return ret; return ret;
} }
/**
/*++ * VmbusChannelSendPacketPageBuffer - Send a range of single-page buffer packets using a GPADL Direct packet type.
*/
Name:
VmbusChannelSendPacketPageBuffer()
Description:
Send a range of single-page buffer packets using a GPADL Direct packet type.
--*/
int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel, int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
struct hv_page_buffer PageBuffers[], struct hv_page_buffer PageBuffers[],
u32 PageCount, u32 PageCount, void *Buffer, u32 BufferLen,
void * Buffer, u64 RequestId)
u32 BufferLen,
u64 RequestId
)
{ {
int ret=0; int ret;
int i=0; int i;
struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc; struct VMBUS_CHANNEL_PACKET_PAGE_BUFFER desc;
u32 descSize; u32 descSize;
u32 packetLen; u32 packetLen;
u32 packetLenAligned; u32 packetLenAligned;
struct scatterlist bufferList[3]; struct scatterlist bufferList[3];
u64 alignedData=0; u64 alignedData = 0;
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
...@@ -808,8 +729,13 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel, ...@@ -808,8 +729,13 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
DumpVmbusChannel(Channel); 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(struct hv_page_buffer)); * 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(struct hv_page_buffer));
packetLen = descSize + BufferLen; packetLen = descSize + BufferLen;
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
...@@ -823,72 +749,62 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel, ...@@ -823,72 +749,62 @@ int VmbusChannelSendPacketPageBuffer(struct vmbus_channel *Channel,
desc.TransactionId = RequestId; desc.TransactionId = RequestId;
desc.RangeCount = PageCount; 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].Length = PageBuffers[i].Length;
desc.Range[i].Offset = PageBuffers[i].Offset; desc.Range[i].Offset = PageBuffers[i].Offset;
desc.Range[i].Pfn = PageBuffers[i].Pfn; desc.Range[i].Pfn = PageBuffers[i].Pfn;
} }
sg_init_table(bufferList,3); sg_init_table(bufferList, 3);
sg_set_buf(&bufferList[0], &desc, descSize); sg_set_buf(&bufferList[0], &desc, descSize);
sg_set_buf(&bufferList[1], Buffer, BufferLen); sg_set_buf(&bufferList[1], Buffer, BufferLen);
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
ret = RingBufferWrite( ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
&Channel->Outbound,
bufferList,
3);
/* TODO: We should determine if this is optional */ /* TODO: We should determine if this is optional */
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
{
VmbusChannelSetEvent(Channel); VmbusChannelSetEvent(Channel);
}
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
return ret; return ret;
} }
/**
* VmbusChannelSendPacketMultiPageBuffer - Send a multi-page buffer packet using a GPADL Direct packet type.
/*++ */
Name:
VmbusChannelSendPacketMultiPageBuffer()
Description:
Send a multi-page buffer packet using a GPADL Direct packet type.
--*/
int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel, int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel,
struct hv_multipage_buffer *MultiPageBuffer, struct hv_multipage_buffer *MultiPageBuffer,
void * Buffer, void *Buffer, u32 BufferLen, u64 RequestId)
u32 BufferLen,
u64 RequestId
)
{ {
int ret=0; int ret;
struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc; struct VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER desc;
u32 descSize; u32 descSize;
u32 packetLen; u32 packetLen;
u32 packetLenAligned; u32 packetLenAligned;
struct scatterlist bufferList[3]; struct scatterlist bufferList[3];
u64 alignedData=0; u64 alignedData = 0;
u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset, MultiPageBuffer->Length); u32 PfnCount = NUM_PAGES_SPANNED(MultiPageBuffer->Offset,
MultiPageBuffer->Length);
DPRINT_ENTER(VMBUS); DPRINT_ENTER(VMBUS);
DumpVmbusChannel(Channel); 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 > 0);
ASSERT(PfnCount <= MAX_MULTIPAGE_BUFFER_COUNT); 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)); * 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));
packetLen = descSize + BufferLen; packetLen = descSize + BufferLen;
packetLenAligned = ALIGN_UP(packetLen, sizeof(u64)); packetLenAligned = ALIGN_UP(packetLen, sizeof(u64));
...@@ -905,45 +821,31 @@ int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel, ...@@ -905,45 +821,31 @@ int VmbusChannelSendPacketMultiPageBuffer(struct vmbus_channel *Channel,
desc.Range.Length = MultiPageBuffer->Length; desc.Range.Length = MultiPageBuffer->Length;
desc.Range.Offset = MultiPageBuffer->Offset; desc.Range.Offset = MultiPageBuffer->Offset;
memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray, PfnCount*sizeof(u64)); memcpy(desc.Range.PfnArray, MultiPageBuffer->PfnArray,
PfnCount * sizeof(u64));
sg_init_table(bufferList,3); sg_init_table(bufferList, 3);
sg_set_buf(&bufferList[0], &desc, descSize); sg_set_buf(&bufferList[0], &desc, descSize);
sg_set_buf(&bufferList[1], Buffer, BufferLen); sg_set_buf(&bufferList[1], Buffer, BufferLen);
sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen); sg_set_buf(&bufferList[2], &alignedData, packetLenAligned - packetLen);
ret = RingBufferWrite( ret = RingBufferWrite(&Channel->Outbound, bufferList, 3);
&Channel->Outbound,
bufferList,
3);
/* TODO: We should determine if this is optional */ /* TODO: We should determine if this is optional */
if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound)) if (ret == 0 && !GetRingBufferInterruptMask(&Channel->Outbound))
{
VmbusChannelSetEvent(Channel); VmbusChannelSetEvent(Channel);
}
DPRINT_EXIT(VMBUS); DPRINT_EXIT(VMBUS);
return ret; return ret;
} }
/**
/*++ * VmbusChannelRecvPacket - Retrieve the user packet on the specified channel
*/
Name:
VmbusChannelRecvPacket()
Description:
Retrieve the user packet on the specified channel
--*/
/* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */ /* TODO: Do we ever receive a gpa direct packet other than the ones we send ? */
int VmbusChannelRecvPacket(struct vmbus_channel *Channel, int VmbusChannelRecvPacket(struct vmbus_channel *Channel, void *Buffer,
void *Buffer, u32 BufferLen, u32 *BufferActualLen, u64 *RequestId)
u32 BufferLen,
u32 *BufferActualLen,
u64 *RequestId)
{ {
struct vmpacket_descriptor desc; struct vmpacket_descriptor desc;
u32 packetLen; u32 packetLen;
...@@ -958,9 +860,9 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, ...@@ -958,9 +860,9 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
spin_lock_irqsave(&Channel->inbound_lock, flags); spin_lock_irqsave(&Channel->inbound_lock, flags);
ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor)); ret = RingBufferPeek(&Channel->Inbound, &desc,
if (ret != 0) sizeof(struct vmpacket_descriptor));
{ if (ret != 0) {
spin_unlock_irqrestore(&Channel->inbound_lock, flags); spin_unlock_irqrestore(&Channel->inbound_lock, flags);
/* DPRINT_DBG(VMBUS, "nothing to read!!"); */ /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
...@@ -974,20 +876,18 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, ...@@ -974,20 +876,18 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
userLen = packetLen - (desc.DataOffset8 << 3); userLen = packetLen - (desc.DataOffset8 << 3);
/* ASSERT(userLen > 0); */ /* ASSERT(userLen > 0); */
DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d flag %d tid %llx pktlen %d datalen %d> ", DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
Channel, "flag %d tid %llx pktlen %d datalen %d> ",
Channel->OfferMsg.ChildRelId, Channel, Channel->OfferMsg.ChildRelId, desc.Type,
desc.Type, desc.Flags, desc.TransactionId, packetLen, userLen);
desc.Flags,
desc.TransactionId, packetLen, userLen);
*BufferActualLen = userLen; *BufferActualLen = userLen;
if (userLen > BufferLen) if (userLen > BufferLen) {
{
spin_unlock_irqrestore(&Channel->inbound_lock, flags); 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); DPRINT_EXIT(VMBUS);
return -1; return -1;
...@@ -996,7 +896,8 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, ...@@ -996,7 +896,8 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
*RequestId = desc.TransactionId; *RequestId = desc.TransactionId;
/* Copy over the packet to the user buffer */ /* 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); spin_unlock_irqrestore(&Channel->inbound_lock, flags);
...@@ -1005,21 +906,12 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel, ...@@ -1005,21 +906,12 @@ int VmbusChannelRecvPacket(struct vmbus_channel *Channel,
return 0; return 0;
} }
/*++ /**
* VmbusChannelRecvPacketRaw - Retrieve the raw packet on the specified channel
Name: */
VmbusChannelRecvPacketRaw() int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, void *Buffer,
u32 BufferLen, u32 *BufferActualLen,
Description: u64 *RequestId)
Retrieve the raw packet on the specified channel
--*/
int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
void * Buffer,
u32 BufferLen,
u32* BufferActualLen,
u64* RequestId
)
{ {
struct vmpacket_descriptor desc; struct vmpacket_descriptor desc;
u32 packetLen; u32 packetLen;
...@@ -1034,9 +926,9 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, ...@@ -1034,9 +926,9 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
spin_lock_irqsave(&Channel->inbound_lock, flags); spin_lock_irqsave(&Channel->inbound_lock, flags);
ret = RingBufferPeek(&Channel->Inbound, &desc, sizeof(struct vmpacket_descriptor)); ret = RingBufferPeek(&Channel->Inbound, &desc,
if (ret != 0) sizeof(struct vmpacket_descriptor));
{ if (ret != 0) {
spin_unlock_irqrestore(&Channel->inbound_lock, flags); spin_unlock_irqrestore(&Channel->inbound_lock, flags);
/* DPRINT_DBG(VMBUS, "nothing to read!!"); */ /* DPRINT_DBG(VMBUS, "nothing to read!!"); */
...@@ -1049,20 +941,18 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, ...@@ -1049,20 +941,18 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
packetLen = desc.Length8 << 3; packetLen = desc.Length8 << 3;
userLen = packetLen - (desc.DataOffset8 << 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> ", DPRINT_DBG(VMBUS, "packet received on channel %p relid %d <type %d "
Channel, "flag %d tid %llx pktlen %d datalen %d> ",
Channel->OfferMsg.ChildRelId, Channel, Channel->OfferMsg.ChildRelId, desc.Type,
desc.Type, desc.Flags, desc.TransactionId, packetLen, userLen);
desc.Flags,
desc.TransactionId, packetLen, userLen);
*BufferActualLen = packetLen; *BufferActualLen = packetLen;
if (packetLen > BufferLen) if (packetLen > BufferLen) {
{
spin_unlock_irqrestore(&Channel->inbound_lock, flags); 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); DPRINT_EXIT(VMBUS);
return -2; return -2;
} }
...@@ -1079,16 +969,9 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel, ...@@ -1079,16 +969,9 @@ int VmbusChannelRecvPacketRaw(struct vmbus_channel *Channel,
return 0; return 0;
} }
/**
/*++ * VmbusChannelOnChannelEvent - Channel event callback
*/
Name:
VmbusChannelOnChannelEvent()
Description:
Channel event callback
--*/
void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel) void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel)
{ {
DumpVmbusChannel(Channel); DumpVmbusChannel(Channel);
...@@ -1103,21 +986,14 @@ void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel) ...@@ -1103,21 +986,14 @@ void VmbusChannelOnChannelEvent(struct vmbus_channel *Channel)
#endif #endif
} }
/*++ /**
* VmbusChannelOnTimer - Timer event callback
Name: */
VmbusChannelOnTimer()
Description:
Timer event callback
--*/
void VmbusChannelOnTimer(unsigned long data) void VmbusChannelOnTimer(unsigned long data)
{ {
struct vmbus_channel *channel = (struct vmbus_channel *)data; struct vmbus_channel *channel = (struct vmbus_channel *)data;
if (channel->OnChannelCallback) if (channel->OnChannelCallback) {
{
channel->OnChannelCallback(channel->ChannelCallbackContext); channel->OnChannelCallback(channel->ChannelCallbackContext);
#ifdef ENABLE_POLLING #ifdef ENABLE_POLLING
channel->poll_timer.expires(jiffies + usecs_to_jiffies(100); channel->poll_timer.expires(jiffies + usecs_to_jiffies(100);
...@@ -1126,22 +1002,12 @@ void VmbusChannelOnTimer(unsigned long data) ...@@ -1126,22 +1002,12 @@ void VmbusChannelOnTimer(unsigned long data)
} }
} }
/**
/*++ * DumpVmbusChannel - Dump vmbus channel info to the console
*/
Name:
DumpVmbusChannel()
Description:
Dump vmbus channel info to the console
--*/
static void DumpVmbusChannel(struct vmbus_channel *Channel) static void DumpVmbusChannel(struct vmbus_channel *Channel)
{ {
DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId); DPRINT_DBG(VMBUS, "Channel (%d)", Channel->OfferMsg.ChildRelId);
DumpRingInfo(&Channel->Outbound, "Outbound "); DumpRingInfo(&Channel->Outbound, "Outbound ");
DumpRingInfo(&Channel->Inbound, "Inbound "); DumpRingInfo(&Channel->Inbound, "Inbound ");
} }
/* eof */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册